AutoUpgrade [C#]

Version: 0.5.1
License: CC
Requirements: Win (With mono possible for Linux aswell)
Limitations: CC License (Free of use/change for personal use)
Code: Csharp

AutoUpgrade


With thAutoUpgrade 0.5.1is project, that is mearged with the main application that should be released, it will be possible to check if new upgrades are available. Upgrades will be download on a separately thread and be signalled when the actually upgrade is possible to perform.

When upgrade should be done with the new files, the main application should call the AutoUpdate.exe file as process and then self shutdown, and the files in the compressed file will be extract over the ordinary files. After the decompressing the main applications .exe file will be executed again (sent as parameter).

There are two xml files that should be used as configuration files. The one used with the AutoUpdate.exe, with name “AutoUpdate.xml”, located at the same path. And the second “update.xml” (in this example below it is called “OrdinaryApp.xml”) that is on a public server for the application to read, and look for new upgrades and where to find the upgrade files.

Below are some small example, but otherwise take a look at the example code provided with the source.

Example of AutoUpgrade.xml


<?xml version="1.0" encoding="utf-8"?>
<xml>
<upgrade>true</upgrade>
<homepage>http://www.lightsoft.se</homepage>
<upgradexml>http://www.lightsoft.se/_software_updates/OrdinaryApp.xml</upgradexml>
</xml>

 

Example of OrdinaryApp.xml (on server)


<?xml version="1.0" encoding="utf-8" ?>
<xml>
<version>1.0.3.0</version>
<urlupdate>http://www.lightsoft.se/_software_updates/UpdateTestApp/OrdinaryApp.zip</urlupdate>
<urlinstall>http://www.lightsoft.se/_software_updates/UpdateTestApp/OrdinaryApp.msi</urlinstall>
</xml>

 

Small example of code


public void checkForUpgrades(){
// Send the callers Version to the AutoUpgrader, it is used to check for upgrades.
AutoUpgrader au = new AutoUpgrader(Assembly.GetExecutingAssembly().GetName().Version);
// Check if there are upgrades against the xml file on the public server
if (au.existsUpgrades()){
// Listening on events when downloading files are done.
AutoUpgrader.PossibleToUpgradeEvent += new AutoUpgrader.PossibleToUpgrade(PossibleToUpgradeEvent);
// Start downloading file
au.startDownloadUpgrades();
}
}
private void PossibleToUpgradeEvent()
{
Console.Out.WriteLine("PossibleToUpgradeEvent");

// We should trigger a process with the AutoUpgrade.exe
ProcessStartInfo upgradeProcess = new ProcessStartInfo("AutoUpgrade.exe");
// Need to give argument of what the Main programfile is to execute after upgrade, will restart the main app when finished upgrading.
upgradeProcess.Arguments = getExecutorExeFile();
upgradeProcess.WorkingDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
// Start AutoUpgrade.exe
Process.Start(upgradeProcess);
Environment.Exit(0);
}

// Get the OrdinaryApp.exe file
public string getExecutorExeFile()
{
return System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
}


It is possible to listener to events from the AutoUpgrade.exe when using it as a instance


AutoUpgrader.NewVersionToDownloadEvent += new AutoUpgrader.NewVersionToDownload(NewVersionToDownloadEvent);
AutoUpgrader.PossibleToUpgradeEvent += new AutoUpgrader.PossibleToUpgrade(PossibleToUpgradeEvent);

Download app: AutoUpgrade_delivery_0.5.1
Download Src: AutoUpgrade_src_0.5.1

Leave a Reply