コード例 #1
0
        public static void Update()
        {
            UpdateReport          report      = new UpdateReport();
            FileBackupTransaction transaction = new FileBackupTransaction();
            string path = null;
            string to   = null;
            string str3 = "unknown";
            string str4 = null;

            try
            {
                string            appRootPath = ApplicationUtils.GetAppRootPath();
                CommandLineParser parser      = new CommandLineParser(Environment.GetCommandLineArgs());
                int num = Convert.ToInt32(parser.GetValue(LauncherConstants.UPDATE_PROCESS_COMMAND));
                to   = parser.GetValue(LauncherConstants.PARENT_PATH_COMMAND);
                str3 = parser.GetValue(LauncherConstants.VERSION_COMMAND);
                using (File.Open(to + "/update.lock", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                {
                    string processName = Process.GetCurrentProcess().ProcessName;
                    WaitForProccessStop(Convert.ToInt32(num), PROCESS_STOP_TIMEOUT);
                    WaitForDropParentExecutable(transaction, to + "/" + ApplicationUtils.GetExecutableRelativePathByName(processName));
                    ReplaceProjectFiles(transaction, appRootPath, to, processName);
                    transaction.Commit();
                }
            }
            catch (Exception exception)
            {
                report.IsSuccess  = false;
                report.Error      = exception.Message;
                report.StackTrace = exception.StackTrace;
                transaction.Rollback();
            }
            finally
            {
                try
                {
                    report.UpdateVersion = str3;
                    WriteReport(to + "/" + LauncherConstants.REPORT_FILE_NAME, report);
                    if (!string.IsNullOrEmpty(str4) && File.Exists(str4))
                    {
                        File.Delete(str4);
                    }
                    ApplicationUtils.StartProcess(path, LauncherConstants.UPDATE_REPORT_COMMAND);
                }
                finally
                {
                    Application.Quit();
                }
            }
        }
コード例 #2
0
        private void Reboot()
        {
            EngineService.Engine.NewEvent <StartRebootEvent>().Attach(EngineService.EntityStub).Schedule();
            string appRootPath = ApplicationUtils.GetAppRootPath();
            string subLine     = new CommandLineParser(Environment.GetCommandLineArgs()).GetSubLine(LauncherConstants.PASS_THROUGH);
            string args        = $"-batchmode -nographics {LauncherConstants.UPDATE_PROCESS_COMMAND}={Process.GetCurrentProcess().Id} {LauncherConstants.VERSION_COMMAND}={this.version} {LauncherConstants.PARENT_PATH_COMMAND}={ApplicationUtils.WrapPath(appRootPath)} {subLine}";

            try
            {
                ApplicationUtils.StartProcessAsAdmin(this.updatePath + "/" + ApplicationUtils.GetExecutablePathByName(this.executable), args);
            }
            catch
            {
                ApplicationUtils.StartProcess(this.updatePath + "/" + ApplicationUtils.GetExecutablePathByName(this.executable), args);
            }
            base.StartCoroutine(this.WaitAndReboot(2f));
        }