Ejemplo n.º 1
0
        public void Read(Stream stream)
        {
            UpdateReport report = (UpdateReport) new XmlSerializer(typeof(UpdateReport)).Deserialize(stream);

            this.UpdateVersion = report.UpdateVersion;
            this.IsSuccess     = report.IsSuccess;
            this.Error         = report.Error;
            this.StackTrace    = report.StackTrace;
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
0
 private static void WriteReport(string path, UpdateReport report)
 {
     try
     {
         using (FileStream stream = new FileStream(path, FileMode.Create))
         {
             report.Write(stream);
         }
     }
     catch (Exception exception1)
     {
         Debug.LogError(exception1);
     }
 }
Ejemplo n.º 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);
        }