Example #1
0
 /// <summary>
 /// Main Entry Point for WPF
 /// </summary>
 public MainWindow()
 {
     // Check command line arguments
     if (!GetCommandLineArguments())
     {
         MessageBox.Show("This application is intended to be opened by its parent program.", "Updater", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         Close();
     }
     // Try grab and open the window, if we fail, exit
     try
     {
         // Query Github Releases
         var client        = new GitHubClient(new ProductHeaderValue(ApplicationName));
         var releases      = client.Repository.Release.GetAll(GithubUserName, GithubRepoName);
         var latestRelease = releases.Result[0];
         // Query File Version
         var fileInfo = FileVersionInfo.GetVersionInfo(AssemblyName);
         // Convert to Version Objects for comparison
         var currentVersion = new Version(fileInfo.FileVersion);
         var remoteVersion  = new Version(latestRelease.TagName);
         // Set Latest Release Asset
         LatestReleaseAsset = latestRelease.Assets[0];
         // Check current Version against Remote
         if (currentVersion < remoteVersion)
         {
             InitializeComponent();
             // Set Version
             LatestVersion.Content = String.Format("Update {0}", remoteVersion);
             // Set Titles
             Title = ApplicationName + " Update";
             TitleLabel.Content = ApplicationName + " Update";
             // Append change log
             Changes.AppendText(latestRelease.Body);
         }
         else
         {
             Close();
         }
     }
     catch
     {
         Close();
     }
 }
Example #2
0
        /// <summary>
        /// Main Entry Point for WPF
        /// </summary>
        public MainWindow()
        {
            // Check command line arguments
            if (!GetCommandLineArguments())
            {
                MessageBox.Show("This application is intended to be opened by its parent program.", "Updater", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Close();
            }
            // TODO: Really improve the hacky slapped in package index logic, maybe merge everything into 1 clean system
            // var result = MessageBox.Show($"{ApplicationName} can check for updates for both itself and new items from its index repo.\n\nWould you like to enable automatic updates?", "Updater", MessageBoxButton.YesNo, MessageBoxImage.Information);
            // Try grab and open the window, if we fail, exit
            try
            {
                // Query Github Releases
                Client = new GitHubClient(new ProductHeaderValue(ApplicationName));

                // Debug purposes, need higher rate limit
                if (File.Exists(@"C:\Visual Studio\Auth\OctoKitAuth.txt"))
                {
                    Client.Credentials = new Credentials(File.ReadAllText(@"C:\Visual Studio\Auth\OctoKitAuth.txt"));
                }

                try
                {
                    if (PackageIndexRequiresUpdate(Client))
                    {
                        InitializeComponent();
                        // Set Version
                        LatestVersion.Content = String.Format("Package Index Update");
                        // Set Titles
                        Title = ApplicationName + " Update";
                        TitleLabel.Content = ApplicationName + " Update";
                        // Append change log
                        Changes.AppendText("An update is available for the Package Index. This includes new hashes for content.");
                        // Set index mode
                        PackageIndexMode = true;
                    }
                }
                catch { }
                // We're updating
                if (!PackageIndexMode)
                {
                    var releases      = Client.Repository.Release.GetAll(GithubUserName, GithubRepoName);
                    var latestRelease = releases.Result[0];
                    // Query File Version
                    var fileInfo = FileVersionInfo.GetVersionInfo(AssemblyName);
                    // Convert to Version Objects for comparison
                    var currentVersion = new Version(fileInfo.FileVersion);
                    var remoteVersion  = new Version(latestRelease.TagName);
                    // Set Latest Release Asset
                    LatestReleaseAsset = latestRelease.Assets[0];
                    // Check current Version against Remote
                    if (currentVersion < remoteVersion)
                    {
                        InitializeComponent();
                        // Set Version
                        LatestVersion.Content = String.Format("Update {0}", remoteVersion);
                        // Set Titles
                        Title = ApplicationName + " Update";
                        TitleLabel.Content = ApplicationName + " Update";
                        // Append change log
                        Changes.AppendText(latestRelease.Body);
                    }
                    else
                    {
                        Close();
                    }
                }
            }
            catch
            {
                Close();
            }
        }