Software Updater 1.0 for .NET

Update your WinForms applications directly from the internet or your own intranet web server.

You create you latest killer application and is distributed to your users, and suddenly you discover that you need to make some changes. You will have to send updates via e-mail or go physically to your user’s PC and replace the installed version with the latest release. Would be nice if your application can update automatically by itself?

Software Updater 1.0 for .NET is just that. A .NET assembly with components that will allow you to do that easily and quickly. Now your users will be able to have your latest version of your software, after just publishing it at your web server’s xml application file.

Define your applications using the applications.xml file (sample)

Sample code in C#:

 

private void btnCheckUpdates_Click(object sender, System.EventArgs e)
{
	try
	{
		string url = "http://h1.ripway.com/alerine/updates/applications.xml";
		Alerine.Internet.SoftwareUpdate softwareUpdate = new
			Alerine.Internet.SoftwareUpdate(url,"","","","","");
		
		softwareUpdate.OnDownloadData += new
			Alerine.Internet.SoftwareUpdate.DownloadData(softwareUpdate_OnDownloadData);
		
		softwareUpdate.SerialNumber = "TRIAL VERSION";

		if(softwareUpdate.IsAnotherInstanceRunning())
		{
			MessageBox.Show("Another instance of this application is already running",
				"Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop);
			Application.Exit();
			return;
		}

		int updatesFound ;
		string[] downloadUrls;

		string updaterPath = Application.StartupPath + @"\SoftwareUpdater.exe";

		string engineBuild = softwareUpdate.GetAssemblyFileVersion(updaterPath);
		
		string[] engineUrls;

	

		string appBuild = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 
		
		if(softwareUpdate.IsNewVersionAvailable("TEST APP",appBuild,out updatesFound, out downloadUrls))
		{
			MessageBox.Show("New version found. Updates available: " + updatesFound);
			foreach(string download in downloadUrls)
			{
				softwareUpdate.Download(download);
			}
			softwareUpdate.ApplyUpdates(updaterPath);
		}
		else if(softwareUpdate.IsNewVersionAvailable("UPDATE ENGINE",engineBuild, out updatesFound, out engineUrls))
		{
			foreach(string engineDownload in engineUrls)
			{
				softwareUpdate.Download(engineDownload);
			}
			softwareUpdate.ApplyEngineUpdates(updaterPath);
		}
		else
		{
	
			MessageBox.Show("You have the latest version");
		}

		

	}
	catch(Exception ex)
	{
		MessageBox.Show(ex.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
	}
}

private void softwareUpdate_OnDownloadData(object sender, Alerine.Internet.SoftwareUpdateEventArgs e)
{
	int bytesRead = e.bytesReadSoFar;
	int totalBytes = e.totalDownloadSize;
	this.progressBar1.Minimum= 0;
	this.progressBar1.Maximum = totalBytes;
	this.progressBar1.Value = bytesRead;
	this.label1.Text = String.Format("Download {0} bytes of {1}",bytesRead,totalBytes);
	Application.DoEvents();
}


Опубликовал admin
2 Окт, Понедельник 2006г.



Программирование для чайников.