Hi. Wie erstelle ich eine UpdateFunktion in c#? Würde mich sehr über eine Hilfe freuen. Ich glaube ihr wisst was ich meine^^.
Grundsätzlich will ich erstmal wissen was du Updaten möchtest. Willst du nur deine Anwendung updaten können oder nur Dateien patchen können?Quote:
Hi. Wie erstelle ich eine UpdateFunktion in c#? Würde mich sehr über eine Hilfe freuen. Ich glaube ihr wisst was ich meine^^.
Die neue Version kannst du in eine .txt Datei schreiben.Beispiel:
1.0.1
static string VERSIONS_CHECK = "http://DeineDomainOderFTP/version.txt";
static string Reply;
static string Version = "1.0.0";
static string NEW_VERSION = "http://DeineDomainOderFTP/NEW.exe";
static string UPDATE_FOUND = "Update available! \nDo you want to download the update now ?";
static string UPDATE_READY = "New version has been downloaded. \nDo you want to start the new version now ?";
private void CheckUpdate()
{
WebClient DownloadString = new WebClient();
Reply = DownloadString.DownloadString(new Uri(VERSIONS_CHECK));
if(Reply == Version)
{
return;
}
else
{
var result = MessageBox.Show(UPDATE_FOUND, "", MessageBoxButtons.OKCancel);
if (result == System.Windows.Forms.DialogResult.OK)
{
DownloadString.DownloadFileAsync(new Uri(NEW_VERSION), @Application.StartupPath + "\\" + "NEW.exe");
DownloadString.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadString_DownloadCompleted);
}
else
{
WindowState = FormWindowState.Normal;
}
}
}
private void DownloadString_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
var result = MessageBox.Show(UPDATE_READY, "", MessageBoxButtons.OKCancel);
if(result == System.Windows.Forms.DialogResult.OK)
{
Process.Start(@Application.StartupPath + "\\" + "Updater.exe");
Application.Exit();
}
else
{
Application.Exit();
}
}
CheckUpdate()
namespace Updater
{
class Program
{
static void Main(string[] args)
{
if(File.Exists("ProgrammName.exe"))
{
File.Delete("ProgrammName.exe");
File.Move("NEW.exe", "ProgrammName.exe");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Console.Write("Datei wird nun gestartet. Bitte Warten");
Process.Start("ProgrammName.exe");
}
else
{
File.Move("NEW.exe", "ProgrammName.exe");
}
}
}
}