No nonsense, direct sticker code description system updates,
First, let's take a look at how the system's program entry should be written.
[STAThread]
static void Main ()
{
Control.checkforillegalcrossthreadcalls = false;
Application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault (FALSE);
BOOL Create=false;
using (Mutex mu = new Mutex (true, application.productname, out create))
{
if (create)
{
Check system files for updates and update system files if updates are available
Checkupdate.update ();
System Files Loading Entities
Localloader load = new Localloader ();
Loading the system's master boot file
Load. loadassembly (@ "Main.Forms.dll");
Get the main program entry
Form frmmain = load. Getformbyname ("Frmmain");
if (frmmain = = null)
{
Return
}
Running the main program
Application.Run (Frmmain);
Application.Run (New Frmmain ());
}
Else
{
MessageBox.Show ("program is running!");
}
}
}
Second, let's take a look at how the system files are updated
public static Class Checkupdate
{
public static void Update ()
{
string error = NULL;
BOOL Isneedupdate = false;
BOOL Isupdate = false;
Check for Updates
Dictionary<string, string> files = filebll.getappfilelist (Application.productname, out error);
if (Files! = null)
{
int i = 0;
foreach (string s in Files. Keys)
{
If the file does not exist locally, you need to update
if (! System.IO.File.Exists (Application.startuppath + "\" + s))
{
Isneedupdate = true;
}
else if ((Filecipherhelper.hash (System.IO.File.ReadAllBytes (application.startuppath + "\ \" + s), FileCipherHelper.HashFormat.MD532)) = Files[s])
{//If the hash value is different, you need to update
Isneedupdate = true;
}
if (isneedupdate)
{
i + = 1;
Isneedupdate = false;
If the file does not exist locally, you need to update
if (! System.IO.File.Exists (AppDomain.CurrentDomain.BaseDirectory + "\" + s))
{
Isneedupdate = true;
}
else if ((Filecipherhelper.hash (System.IO.File.ReadAllBytes (AppDomain.CurrentDomain.BaseDirectory + "\ \" + s), FileCipherHelper.HashFormat.MD532)) = Files[s])
{//If the hash value is different, you need to update
Isneedupdate = true;
}
if (isneedupdate)
{
byte[] FileData = Filebll.getappfile (Application.productname, S, out error);
if (fileData! = null)
{
System.IO.File.WriteAllBytes (AppDomain.CurrentDomain.BaseDirectory + S, fileData);
Isupdate = true;
}
}
}
}
}
}
}
Winform Application System Update