Пример #1
0
        public void Check()
        {
            try
            {
                try
                {
                    oausServerIP   = ConfigurationManager.AppSettings["UpdateUrl"].ToString();
                    oausServerPort = int.Parse(ConfigurationManager.AppSettings["UpdatePort"].ToString());
                }
                catch { }
                bool flag = VersionHelper.HasNewVersion(oausServerIP, oausServerPort);

                if (flag)
                {
                    bool flag2 = DialogResult.OK == MessageBox.Show("亲,有新版本哦,赶快点击“确定”升级吧!", "升级提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (flag2)
                    {
                        //string serverIP = ConfigurationManager.AppSettings["ServerIP"];
                        //int serverPort = int.Parse(ConfigurationManager.AppSettings["ServerPort"]);
                        string systemName  = ConfigurationManager.AppSettings["SystemName"];
                        string title       = "客户端系统升级";
                        string processName = systemName;// systemName.Substring(0, systemName.Length - 4);
                        bool   haveRun     = ESBasic.Helpers.ApplicationHelper.IsAppInstanceExist(processName);
                        if (haveRun)
                        {
                            MessageBox.Show(Resources.TargetIsRunning);
                            return;
                        }

                        AutoUpdaterForm auto = new AutoUpdaterForm(oausServerIP, oausServerPort, systemName, title, this);
                        auto.Show();

                        //string fileName = AppDomain.CurrentDomain.BaseDirectory + "AutoUpdater\\AutoUpdater.exe";
                        //Process process = Process.Start(fileName);
                        //Process.GetCurrentProcess().Kill();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取版本信息失败!");
                LogHelper.WriteLog(typeof(MainForm), ex.Message + "  :获取更新信息异常,请手动下载更新包!");
            }
        }
Пример #2
0
        private void btnInstall_Click(object sender, EventArgs e)
        {
            btnInstall.Enabled = false;
            // reset to display the revision note on next restart
            ConfigRepository.Instance()["general_showrevnote"] = "true";

            var tempToolkitDir  = Path.Combine(Path.GetTempPath(), "RocksmithToolkit");
            var updaterAppPath  = Path.Combine(localToolkitDir, APP_UPDATER);
            var updatingAppPath = Path.Combine(tempToolkitDir, APP_UPDATING);

            if (!File.Exists(updaterAppPath))
            {
                var errMsg = "Could not find file: " + APP_UPDATER + Environment.NewLine + "Please reinstall the toolkit manually.";
                BetterDialog2.ShowDialog(errMsg, "Toolkit Updater Error", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
                return;
            }

            // create temp process backup folder
            if (Directory.Exists(tempToolkitDir))
            {
                Directory.Delete(tempToolkitDir, true);
            }

            Directory.CreateDirectory(tempToolkitDir);

            try
            {
                // make a copy of AutoUpdater to prevent locking the process during update
                File.Copy(updaterAppPath, updatingAppPath, true);

                if (GeneralExtensions.IsInDesignMode) // allow updater to be run in design mode for developers
                {
                    var args = new string[] { localToolkitDir, tempToolkitDir };
                    using (var autoUpdater = new AutoUpdaterForm(args))
                        autoUpdater.Show();
                }
                else
                {
                    // passing args for process and backup directories to RocksmithToolkitUpdating.exe (Primary Usage Mode)
                    var cmdArgs = String.Format("\"{0}\" \"{1}\"", localToolkitDir, tempToolkitDir);

                    try // different AutoUpdater shells for MacWine testing
                    {
                        GeneralExtensions.RunExternalExecutable(updatingAppPath, arguments: cmdArgs);
                    }
                    catch (Exception ex)
                    {
                        // changed external process call for MacWine debugging
                        MessageBox.Show("Report hit updater try #2 to the developers: " + Environment.NewLine + ex.Message);

                        var startInfo = new ProcessStartInfo
                        {
                            FileName        = updatingAppPath,
                            Arguments       = cmdArgs,
                            UseShellExecute = false,
                            CreateNoWindow  = true, // hide command window
                        };

                        using (var updater = new Process())
                        {
                            updater.StartInfo = startInfo;
                            updater.Start();
                        }
                    }

                    // Kill current toolkit process now that AutoUpdater process is started
                    Environment.Exit(0);
                }
            }
            catch (ObjectDisposedException)
            {
                /* Do nothing  - user cancelled the download */
            }
            catch (Exception ex)
            {
                var errMsg = "Could not run file: " + APP_UPDATING + Environment.NewLine +
                             "Please reinstall the toolkit manually." + Environment.NewLine +
                             ex.Message;
                BetterDialog2.ShowDialog(errMsg, "Toolkit Updater Error", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
            }

            btnInstall.Enabled = true;
        }