Exemplo n.º 1
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Creates httpClient
            HttpClient httpClient = new HttpClient();
            //Uses PathStrings.cs to get the Current Version
            var result = await httpClient.GetAsync(PathStrings.VersionURL);

            var strServerVersion = await result.Content.ReadAsStringAsync();

            var serverVersion = Version.Parse(strServerVersion);
            var thisVersion   = Application.ResourceAssembly.ManifestModule.Assembly.GetName().Version;

            //Trys to Check if Server File "version.txt" has the same Version as the Assembly Version
            try
            {
                if (serverVersion > thisVersion)
                {
                    //Displaying the newest versionNumber
                    versionNumber.Content = "Downloading: V" + serverVersion;

                    //Creates WebClient
                    WebClient client = new WebClient();
                    //Uses PathStrings.cs to Create a Folder to the Desktop (\wpfautoupdater\Application\)
                    Directory.CreateDirectory(PathStrings.desktopPath + PathStrings.AppExecutablePath);
                    //Creates new private voids
                    client.DownloadProgressChanged += client_DownloadProgressChanged;
                    client.DownloadFileCompleted   += client_DownloadFileCompleted;
                    //Downloads the Actual File and Puts the file to \wpfautoupdater\Application\ and renames it to "wpfautoupdaterUpdated"
                    client.DownloadFileAsync(new Uri(PathStrings.AppExecutableURL), PathStrings.desktopPath + PathStrings.AppExecutablePath + downloadedapplicationName);
                }
                else
                {
                    //else if up to date open actual application
                    ApplicationWindow application = new ApplicationWindow();
                    application.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                //if there are Errors
                MessageBox.Show(ex.Message, "UpdateWindow.xaml.cs - WindowLoaded");
            }
        }
Exemplo n.º 2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //example (V + 1.0.0.0)
            versionNumber.Content = "V" + Application.ResourceAssembly.ManifestModule.Assembly.GetName().Version.ToString();
            //Creates httpClient
            HttpClient httpClient = new HttpClient();
            //Uses PathStrings.cs to get the Current Version
            var result = await httpClient.GetAsync(PathStrings.VersionURL);

            var strServerVersion = await result.Content.ReadAsStringAsync();

            var serverVersion = Version.Parse(strServerVersion);
            var thisVersion   = Application.ResourceAssembly.ManifestModule.Assembly.GetName().Version;

            //Trys to Check if Server File "version.txt" has the same Version as the Assembly Version
            try
            {
                if (serverVersion > thisVersion)
                {
                    //open actual downloader
                    UpdateWindow update = new UpdateWindow();
                    update.Show();
                    this.Close();
                }
                else
                {
                    //else if up to date
                    MessageBox.Show("up to date.");
                    //open Actual Application
                    ApplicationWindow application = new ApplicationWindow();
                    application.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                //if there are Errors
                MessageBox.Show(ex.Message, "CheckUpdateWindow.xaml.cs - WindowLoaded");
            }
        }