Example #1
0
        private static void updateEquineUpdater()
        {
            if (File.Exists(Application.StartupPath + "\\EquineData\\EQUINEUpdater_hash.sha"))
            {
                try
                {
                    File.Copy(Application.StartupPath + "\\EquineData\\EQUINEUpdater.exe", Application.StartupPath + "\\EquineData\\EQUINEUpdater.hash", true);

                    sha1   hash         = new sha1();
                    string fromfilehash = "";
                    string apphash      = "";

                    fromfilehash = File.ReadAllText(Application.StartupPath + "\\EquineData\\EQUINEUpdater_hash.sha");
                    apphash      = hash.CheckFileHash(Application.StartupPath + "\\EquineData\\EQUINEUpdater.hash");

                    if (fromfilehash != apphash)
                    {
                        File.Delete(Application.StartupPath + "\\EquineData\\EQUINEUpdater.hash");
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new frmUpdateEquineData());
                    }

                    File.Delete(Application.StartupPath + "\\EquineData\\EQUINEUpdater.hash");
                }
                catch
                {
                    MessageBox.Show("Unable to update EQUINEUpdater.exe");
                }
            }
            else
            {
                if (Directory.Exists(Application.StartupPath + "/EquineData"))
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                    WebClient wc = new WebClient();
                    wc.DownloadFile("https://www.sergi4ua.com/equine/EQUINEUpdater_hash.sha", Application.StartupPath + "/EquineData/EQUINEUpdater_hash.sha");
                    wc.Dispose();
                    updateEquineUpdater();
                }
            }
        }
Example #2
0
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BeginInvoke((MethodInvoker) delegate() { label3.Text = "Checking for active internet connection"; });
            if (CheckForInternetConnection() == true)
            {
                if (Directory.Exists(Application.StartupPath + "\\EquineData"))
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile("https://sergi4ua.com/equine/EQUINE_hash.sha", Application.StartupPath + "\\EquineData\\EQUINE_hash.sha");
                }
            }

            BeginInvoke((MethodInvoker) delegate() { label3.Text = "Reading config file"; });
            if (!File.Exists(Application.StartupPath + "\\EquineData\\config.json"))
            {
                if (noInit == false)
                {
                    Config defaultConfigFile = new Config();
                    defaultConfigFile.autoUpdate      = true;
                    defaultConfigFile.checkForUpdates = true;
                    File.WriteAllText(Application.StartupPath + "\\EquineData\\config.json", JsonConvert.SerializeObject(defaultConfigFile));
                }
            }

            readJsonConfig();

            //#if RELEASE

            if (config.checkForUpdates && !GlobalVariableContainer.skipUpdates)
            {
                BeginInvoke((MethodInvoker) delegate() { label3.Text = "Checking for updates"; });
                if (File.Exists(Application.StartupPath + "\\EquineData\\EQUINE_hash.sha"))
                {
                    if (noInit == false)
                    {
                        try
                        {
                            File.Copy(Application.ExecutablePath, Application.StartupPath + "\\EQUINE.hash", true);

                            sha1   hash         = new sha1();
                            string fromfilehash = "";
                            string apphash      = "";

                            fromfilehash = File.ReadAllText(Application.StartupPath + "\\EquineData\\EQUINE_hash.sha");
                            apphash      = hash.CheckFileHash(Application.StartupPath + "\\EQUINE.hash");

                            if (fromfilehash != apphash)
                            {
                                BeginInvoke((MethodInvoker) delegate() { label3.Text = "New update is out. Launching EQUINE Update Utility"; });

                                var SelfProc = new ProcessStartInfo
                                {
                                    UseShellExecute  = true,
                                    WorkingDirectory = Environment.CurrentDirectory,
                                    FileName         = Application.StartupPath + "\\EquineData\\EQUINEUpdater.exe",
                                    Arguments        = "-update",
                                };
                                File.Delete(Application.StartupPath + "\\EQUINE.hash");
                                Process.Start(SelfProc);
                                Environment.Exit(0);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Failed to check for updates!\n" + ex.Message);
                        }
                    }
                }
            }
//#endif

            if (!File.Exists(Application.StartupPath + "\\EquineData\\EQUINE_hash.sha"))
            {
                if (noInit == false)
                {
                    Form1 mainForm = new Form1();
                    BeginInvoke((MethodInvoker) delegate() { mainForm.Show(); });
                    BeginInvoke((MethodInvoker) delegate() { this.Hide(); });
                    return;
                }
            }

            if (Directory.Exists(Application.StartupPath + "/Tchernobog (64 BIT ONLY)"))
            {
                Directory.Move(Application.StartupPath + "/Tchernobog (64 BIT ONLY)", Application.StartupPath + "/Tchernobog");
            }

            BeginInvoke((MethodInvoker) delegate() { label3.Text = "Launching"; });
            Form1 mainForm2 = new Form1();

            BeginInvoke((MethodInvoker) delegate() { mainForm2.Show(); });
            BeginInvoke((MethodInvoker) delegate() { this.Hide(); });
        }