Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raghavnaphade committed Jan 4, 2024
0 parents commit 8c64482
Show file tree
Hide file tree
Showing 86 changed files with 97,989 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/lefttimeapp/v17/.suo
Binary file not shown.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
48 changes: 48 additions & 0 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

170 changes: 170 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
using System;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;

namespace lefttimeapp
{
public partial class Form1 : Form
{
private static int WM_QUERYENDSESSION = 0x11;
public Form1()
{
InitializeComponent();
this.FormClosing += Form1_FormClosing;
this.Activated += new System.EventHandler(this.Form1_Activated);
/* this.Hide();
this.Visible = false;*/
}
private void Form1_Activated(object sender, EventArgs e)
{
/*this.Hide()*/;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
this.Visible = false;
this.Opacity = 0;
btnReadFile_Click();
/* this.ShowInTaskbar = false;*/
}

private void btnReadFile_Click()
{
// Get the path of the application's startup folder
string appFolderPath = Application.StartupPath;

// Specify the filename you want to read (change it accordingly)
string filename = "userDetails.dat";

// Combine the folder path and filename to get the full file path
string filePath = Path.Combine(appFolderPath, filename);
Console.WriteLine(filePath);

try
{
// Check if the file exists
if (File.Exists(filePath))
{
// Read the contents of the file
string fileContent = File.ReadAllText(filePath);
JObject jsonObject = JObject.Parse(fileContent);

// Display the content in a MessageBox (you can use any other way to display it)
int userId = (int)jsonObject["userId"];
int tenantId = (int)jsonObject["tenantId"];

// Display the values (you can use any other way to display them)
MessageBox.Show($"User ID: {userId}\nTenant ID: {tenantId}", "JSON Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("File not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}


protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
string message = "System is shutting down or user is logging off.1 WndProc";

// Get the path to the Documents folder
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

// Specify the file path in the Documents folder
string filePath = Path.Combine(documentsPath, "shutdown_log1.txt");

// Write the message to a text file
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine($"{DateTime.Now} - {message}");
}
// MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot");

}

base.WndProc(ref m);
}

/* private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Hello");
this.Hide();
}*/
private void Form1_FormClosed(object sender, FormClosedEventArgs e)

{
Console.WriteLine("Hello Form1_FormClosed");

string message = "System is shutting down or user is logging off.1 WndProc";

// Get the path to the Documents folder
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

// Specify the file path in the Documents folder
string filePath = Path.Combine(documentsPath, "shutdown_log1.txt");

// Write the message to a text file
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine($"{DateTime.Now} - {message}");
}
// MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot");

}

private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
//In case windows is trying to shut down, don't hold the process up
if (e.CloseReason == CloseReason.UserClosing)
{
Console.WriteLine("Hello Form1_FormClosing UserClosing");

string message = "System is shutting down or user is logging off.1 WndProc";

// Get the path to the Documents folder
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

// Specify the file path in the Documents folder
string filePath = Path.Combine(documentsPath, "close_log1.txt");

// Write the message to a text file
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine($"{DateTime.Now} - {message}");
}
/* MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot UserClosing");*/
}
// Prompt user to save his data

if (e.CloseReason == CloseReason.WindowsShutDown)
{
Console.WriteLine("Hello Form1_FormClosing WindowsShutDown");

string message = "System is shutting down or user is logging off.1 WndProc";

// Get the path to the Documents folder
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

// Specify the file path in the Documents folder
string filePath = Path.Combine(documentsPath, "shutdown_log1.txt");

// Write the message to a text file
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine($"{DateTime.Now} - {message}");
}
/* MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot WindowsShutDown");*/
}
}


}
}
120 changes: 120 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
37 changes: 37 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace lefttimeapp
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form1 = new Form1();
form1.Hide();
Application.Run(form1);
Console.WriteLine("Hello");
Task.Run(() => GetLocation());
}
static void GetLocation()
{
Console.WriteLine("LeftTime: ABC");

// Keep the application running
while (true)
{
Thread.Sleep(1000);
}
}
}
}
Loading

0 comments on commit 8c64482

Please sign in to comment.