Inheritance: System.Windows.Forms.Form
 public static void PerformUpdate()
 {
     try
     {
         RegistryKey Settings = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Keppy's MIDI Converter\\Settings", true);
         if (Settings == null)
         {
             Registry.CurrentUser.CreateSubKey("SOFTWARE\\Keppy's MIDI Converter\\Settings", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
             Settings = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Keppy's MIDI Converter\\Settings", true);
         }
         if (Convert.ToInt32(Settings.GetValue("autoupdatecheck", 1)) == 1)
         {
             WebClient client = new WebClient();
             Stream stream = client.OpenRead("https://raw.githubusercontent.com/KaleidonKep99/Keppys-MIDI-Converter/master/KeppySpartanMIDIConverter/kmcupdate.txt");
             StreamReader reader = new StreamReader(stream);
             String newestversion = reader.ReadToEnd();
             FileVersionInfo Driver = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
             Version x = null;
             Version.TryParse(newestversion.ToString(), out x);
             Version y = null;
             Version.TryParse(Driver.FileVersion.ToString(), out y);
             Thread.Sleep(50);
             if (x > y)
             {
                 DialogResult dialogResult = MessageBox.Show("A new update for Keppy's MIDI Converter has been found.\n\nVersion installed: " + Driver.FileVersion.ToString() + "\nVersion available online: " + newestversion.ToString() + "\n\nWould you like to update now?\nIf you choose \"Yes\", the converter will be automatically closed.\n\n(You can disable the automatic update check through \"Options > Automatically check for updates when starting the converter\".)", "New version of Keppy's MIDI Converter found", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if (dialogResult == DialogResult.Yes)
                 {
                     UpdateDownloader frm = new UpdateDownloader(newestversion);
                     frm.StartPosition = FormStartPosition.CenterScreen;
                     frm.ShowDialog();
                 }
             }
         }
         Settings.Close();
     }
     catch
     {
         MessageBox.Show("The converter can not connect to the GitHub servers.\n\nCheck your network connection, or contact your system administrator or network service provider.\n\nPress OK to continue and open the converter's window.", "Keppy's MIDI Converter - Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#2
0
        public static void CheckForUpdates(Boolean Startup)
        {
            if (!AlreadyChecking)
            {
                new Thread(() =>
                {
                    AlreadyChecking = true;
                    Thread.CurrentThread.IsBackground = true;

                    WebClient client;
                    Stream stream;
                    try
                    {
                        client = new WebClient();
                        stream = client.OpenRead("https://raw.githubusercontent.com/KaleidonKep99/Keppys-MIDI-Converter/master/KeppyMIDIConverter/kmcupdate.txt");
                        StreamReader reader       = new StreamReader(stream);
                        String newestversion      = reader.ReadToEnd();
                        FileVersionInfo Converter = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
                        Version.TryParse(newestversion, out Version x);
                        Version.TryParse(Converter.FileVersion.ToString(), out Version y);
                        if (x > y)
                        {
                            while (Application.OpenForms.OfType <MainWindow>().Count() != 1)
                            {
                                Thread.Sleep(1);
                            }

                            MainWindow.Delegate.Invoke((MethodInvoker) delegate {
                                DialogResult dialogResult = MessageBox.Show(String.Format(Languages.Parse("UpdateFound"), Program.Who, Program.Title, Converter.FileVersion, newestversion), String.Format(Languages.Parse("UpdateFoundTitle"), Program.Who, Program.Title), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (dialogResult == DialogResult.Yes)
                                {
                                    UpdateDownloader frm = new UpdateDownloader(newestversion)
                                    {
                                        StartPosition = FormStartPosition.CenterScreen
                                    };
                                    frm.ShowDialog();
                                }
                            });
                        }
                        else
                        {
                            if (!Startup)
                            {
                                MainWindow.Delegate.Invoke((MethodInvoker) delegate {
                                    MessageBox.Show(String.Format(Languages.Parse("NoUpdatesFound"), Program.Who, Program.Title), String.Format(Languages.Parse("NoUpdatesFoundTitle"), Program.Who, Program.Title), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                });
                            }
                        }
                    }
                    catch
                    {
                        if (!Startup)
                        {
                            MainWindow.Delegate.Invoke((MethodInvoker) delegate {
                                MessageBox.Show(String.Format(Languages.Parse("NoUpdatesFound"), Program.Who, Program.Title), String.Format(Languages.Parse("NoUpdatesFoundTitle"), Program.Who, Program.Title), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            });
                        }
                    }
                    AlreadyChecking = false;
                }).Start();
            }
        }
 private void button5_Click(object sender, EventArgs e)
 {
     try
     {
         tabControl1.Enabled = false;
         button5.Enabled = false;
         WebClient client = new WebClient();
         Stream stream = client.OpenRead("https://raw.githubusercontent.com/KaleidonKep99/Keppys-MIDI-Converter/master/KeppySpartanMIDIConverter/kmcupdate.txt");
         StreamReader reader = new StreamReader(stream);
         String newestversion = reader.ReadToEnd();
         FileVersionInfo Converter = FileVersionInfo.GetVersionInfo("KeppyMIDIConverter.exe");
         LatestVersion.Text = "Checking for updates, please wait...";
         ThisVersion.Text = String.Format(res_man.GetString("CurrentVersion", cul), Converter.FileVersion.ToString());
         Version x = null;
         Version.TryParse(newestversion.ToString(), out x);
         Version y = null;
         Version.TryParse(Converter.FileVersion.ToString(), out y);
         if (x > y)
         {
             tabControl1.Enabled = true;
             button5.Enabled = true;
             LatestVersion.Text = String.Format(res_man.GetString("UpdateFoundVer", cul), newestversion.ToString());
             DialogResult dialogResult = MessageBox.Show(res_man.GetString("UpdatesFoundText", cul), res_man.GetString("UpdatesFoundTitle", cul), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
             if (dialogResult == DialogResult.Yes)
             {
                 UpdateDownloader frm = new UpdateDownloader(newestversion);
                 frm.StartPosition = FormStartPosition.CenterScreen;
                 frm.ShowDialog();
             }
         }
         else
         {
             tabControl1.Enabled = true;
             button5.Enabled = true;
             LatestVersion.Text = String.Format("{0} ({1})", res_man.GetString("NoUpdatesText", cul), y.ToString());
             MessageBox.Show(res_man.GetString("NoUpdatesText", cul), res_man.GetString("NoUpdatesTitle", cul), MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         tabControl1.Enabled = true;
         button5.Enabled = true;
         FileVersionInfo Converter = FileVersionInfo.GetVersionInfo("KeppyMIDIConverter.exe");
         ThisVersion.Text = String.Format(res_man.GetString("CurrentVersion", cul), Converter.FileVersion.ToString());
         LatestVersion.Text = res_man.GetString("CanNotCheckUpdates", cul);
         MessageBox.Show(String.Format(res_man.GetString("CanNotCheckUpdatesMsg", cul), ex.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }