20 Ocak 2016 Çarşamba

c# update

public void checkUpdates(){
    try
    {
        if (File.Exists("launcher.update") && new Version(FileVersionInfo.GetVersionInfo("launcher.update").FileVersion) > new Version(Application.ProductVersion))
        {
            Process.Start("updater.exe", "launcher.update \"" + Process.GetCurrentProcess().ProcessName + "\"");
            Process.GetCurrentProcess().CloseMainWindow();
        }
        else
        {
            if (File.Exists("launcher.update")) { File.Delete("launcher.update"); }
            Download();
        }
    }
    catch (Exception)
    {
        if (File.Exists("launcher.update")) { File.Delete("launcher.update"); }
        Download();
    }
}



private void Download()
{
    try
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(@"http://mysite/version.xml");

        remoteVersion = new Version(doc.GetElementsByTagName("version")[0].InnerText);
        localVersion = new Version(Application.ProductVersion);

        if (localVersion < remoteVersion)
        {
            if (File.Exists("launcher.update")) { File.Delete("launcher.update"); }

            WebClient client = new WebClient();
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            client.DownloadFileAsync(new Uri(@"http://mysite/launcher.exe"), "launcher.update");
        }
    }
    catch (Exception) { }
}