コード例 #1
0
        private static void ReplaceProjectFiles(FileBackupTransaction transaction, string from, string to, string executableWithoutExtension)
        {
            List <Pair <string, string> > list  = new List <Pair <string, string> >();
            List <Pair <string, string> > list2 = new List <Pair <string, string> >();

            foreach (string str in Directory.GetFiles(from, "*", SearchOption.AllDirectories))
            {
                string path = str.Replace(from, to);
                if (Path.GetFileNameWithoutExtension(path).Equals(executableWithoutExtension, StringComparison.OrdinalIgnoreCase))
                {
                    list2.Add(new Pair <string, string>(str, path));
                }
                else
                {
                    list.Add(new Pair <string, string>(str, path));
                }
            }
            foreach (Pair <string, string> pair in list)
            {
                Console.WriteLine("Copy project file from " + pair.Key + " to " + pair.Value);
                transaction.ReplaceFile(pair.Key, pair.Value);
            }
            foreach (Pair <string, string> pair2 in list2)
            {
                Console.WriteLine("Copy executable file from " + pair2.Key + " to " + pair2.Value);
                transaction.ReplaceFile(pair2.Key, pair2.Value);
            }
        }
コード例 #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();
                }
            }
        }
コード例 #3
0
 private static void WaitForDropParentExecutable(FileBackupTransaction transaction, string path)
 {
     if (File.Exists(path))
     {
         int  num   = 0;
         bool flag2 = false;
         while (true)
         {
             bool flag = true;
             try
             {
                 Console.WriteLine("Try drop executable file " + path);
                 transaction.DeleteFile(path);
                 Console.WriteLine("Executable file droped");
             }
             catch (Exception)
             {
                 flag = false;
                 if (num > FILE_WAIT_TIMEOUT)
                 {
                     throw;
                 }
                 if ((num > FILE_WAIT_BEFORE_KILL_CONCURRENT_PROCESS) && !flag2)
                 {
                     flag2 = true;
                     TryKillOtherTankixProcesses();
                 }
                 num += 0x3e8;
                 Thread.Sleep(0x3e8);
             }
             if (flag)
             {
                 return;
             }
         }
     }
 }