示例#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();
                }
            }
        }
        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));
        }
示例#3
0
        public static bool IsUpdaterRunning()
        {
            string path = ApplicationUtils.GetAppRootPath() + "/update.lock";

            if (File.Exists(path))
            {
                try
                {
                    using (File.Open(path, FileMode.Open, FileAccess.Read))
                    {
                    }
                }
                catch (Exception)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        private bool CheckUpdateReport()
        {
            bool isSuccess;

            if (!new CommandLineParser(Environment.GetCommandLineArgs()).IsExist(LauncherConstants.UPDATE_REPORT_COMMAND))
            {
                return(true);
            }
            UpdateReport report        = new UpdateReport();
            string       str           = string.Empty;
            string       updateVersion = string.Empty;

            try
            {
                using (FileStream stream = new FileStream(ApplicationUtils.GetAppRootPath() + "/" + LauncherConstants.REPORT_FILE_NAME, FileMode.Open))
                {
                    report.Read(stream);
                    isSuccess     = report.IsSuccess;
                    str           = report.Error + report.StackTrace;
                    updateVersion = report.UpdateVersion;
                }
            }
            catch (Exception exception1)
            {
                isSuccess = false;
                str       = exception1.ToString();
            }
            if (!isSuccess)
            {
                LoggerProvider.GetLogger(this).ErrorFormat("ClientUpdateError: {0}", str);
                EngineService.Engine.NewEvent <ClientUpdateErrorEvent>().Schedule();
                return(false);
            }
            if (!this.IsCurrentVersionNeedsUpdate())
            {
                return(true);
            }
            LoggerProvider.GetLogger(this).ErrorFormat("ClientUpdateError: Updated version is not correct, update version = {0}, currentVersion = {1}", report.UpdateVersion, this.currentVersion);
            EngineService.Engine.NewEvent <ClientUpdateErrorEvent>().Schedule();
            return(false);
        }