LG Updater:
Tasks.phpCode:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Security.Cryptography; using System.Threading; using System.Diagnostics; namespace LogicalUpdater { public partial class frmMain : Form { String AppName = ""; // This is the name of the main application. String UpdateDir = ""; // The url containing files and tasks.php public frmMain() { InitializeComponent(); } private void frmMain_Load(object sender, EventArgs e) { HTTPWrapper Wrapper = new HTTPWrapper(); String[] Files = Wrapper.get(UpdateDir + "tasks.php").Split('|'); for (int i = 0; i < Files.Length; i++) { String[] Data = Files[i].Split('-'); if (File.Exists(Application.StartupPath + @"\" + Data[0]) && MD5Checksum(Application.StartupPath + @"\" + Data[0]) != Data[1] || !File.Exists(Application.StartupPath + @"\" + Data[0])) { TextWriter Handle = new StreamWriter(Data[0]); Handle.Write(Wrapper.get(UpdateDir + Data[0])); Handle.Close(); } } if (File.Exists(Application.StartupPath + @"\" + AppName)) { Process.Start(Application.StartupPath + @"\" + AppName); Environment.Exit(0); } } public String MD5Checksum(string FileName) { FileStream Handle = new FileStream(FileName, FileMode.Open); byte[] Return = new MD5CryptoServiceProvider().ComputeHash(Handle); Handle.Close(); StringBuilder SB = new StringBuilder(); for (int i = 0; i < Return.Length; i++) { SB.Append(Return[i].ToString("x2")); } return SB.ToString(); } } }
HTTPWrappers are needed for this to function, there are located here, what this does is read all the files on your webserver and either updates the current files or create new ones.Code:<?php $Handle = opendir("./"); $Dump = ""; while ($File = readdir($Handle)) { if ($File != "." && $File != ".." && $File != "tasks.php") { $Dump .= ($File . '-' . md5(file_get_contents($File)) . '|'); } } closedir($Handle); echo rtrim($Dump, '|'); ?>
This is a separate application from your main program. Something like Updater.exe, they run this program to launch or update their files.
To set it up put tasks.php on your webserver then set UpdateDir to your web url where tanks.php is located, make sure to chmod all files to 777 and that all files in that directory you want on your users pc.
Also set AppName to the exe of the main program (ex "BootyCollector.exe".)
To make your application or program automatically launch LGUpdater have it use Process.Start("Updater.exe"); then exit the program Environment.Exit(0);
For example if you want to have a user update the files "Fail.txt" and "Main.exe"
You will create a directory (ex "/fun/"),
Add tasks.php to that file along with "Fail.txt" and "Main.exe"
So in /fun/ you will have 3 files. Then set UpdateDir to your url including the file (ex http://exmaple.com/fun/) and set AppName to "Main.exe"
So for now on if you run the Updater.exe it will update all the files in their local folder to the files on your website and then run Main.exe and close.
Results 1 to 3 of 3
Thread: C# LGUpdater [Private]
- 19 Jul. 2010 12:25am #1
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
C# LGUpdater [Private]
- 19 Jul. 2010 12:51am #2
This is great and everything but can't you just have a .xml file on your server saying something like
<Program_Name>
<Version> 2.5</Version>
</Program_Name>
and have XML Reader read the information or you can use Wrappers to check the information between and if the version doesn't match it'll auto update
etc etc.
- 19 Jul. 2010 01:25am #3
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
That is what the program does it creates an md5 checksum and compares that to the one the user has in the directory. If they are different it updates them. The reason I do not use an xml is because this will be easier for the user, aka you. Tasks.php dumps a list of ALL files in the same directory (except tasks.php,) to update for the users computer.