Exemplo n.º 1
0
 private void bgwWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         BackgroundFilePatcher.CheckForBackups();
     }
     this.OnRunWorkerCompleted(sender, e);
 }
Exemplo n.º 2
0
 private void PatchFiles()
 {
     for (int i = 0; i < this._fileList.Count; i++)
     {
         PatchInfo item = this._fileList[i];
         FileEx.Move(item.TempFile, item.DestinationFile, true);
         this.ReportProgress(BackgroundFilePatcher.States.Patching, BackgroundFilePatcher.CalculateProgress(i, this._fileList.Count));
     }
 }
Exemplo n.º 3
0
 private void RestoreBackup()
 {
     for (int i = 0; i < this._fileList.Count; i++)
     {
         PatchInfo item = this._fileList[i];
         FileEx.Move(item.DestinationFile, item.TempFile, true);
         FileEx.Move(item.BackupFile, item.DestinationFile, true);
         this.ReportProgress(BackgroundFilePatcher.States.RestoringBackup, BackgroundFilePatcher.CalculateProgress(i, this._fileList.Count));
     }
     DirectoryEx.Delete(Paths.Elsword.Media);
     DirectoryEx.Delete(Paths.Elsword.Backup);
 }
Exemplo n.º 4
0
 private void CreateBackup()
 {
     for (int i = 0; i < this._fileList.Count; i++)
     {
         PatchInfo item = this._fileList[i];
         if (item.BackupFile != null && File.Exists(item.DestinationFile))
         {
             FileEx.Move(item.DestinationFile, item.BackupFile, true);
         }
         this.ReportProgress(BackgroundFilePatcher.States.DoingBackup, BackgroundFilePatcher.CalculateProgress(i, this._fileList.Count));
     }
 }
Exemplo n.º 5
0
        public static void ClearRegistry(string keyPath)
        {
            RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(keyPath, true);

            if (registryKey == null)
            {
                return;
            }
            if (registryKey.Name.EndsWith("\\MARK_INVALID"))
            {
                string[] valueNames = registryKey.GetValueNames();
                for (int i = 0; i < (int)valueNames.Length; i++)
                {
                    registryKey.DeleteValue(valueNames[i]);
                }
            }
            string[] subKeyNames = registryKey.GetSubKeyNames();
            for (int j = 0; j < (int)subKeyNames.Length; j++)
            {
                string str = subKeyNames[j];
                BackgroundFilePatcher.ClearRegistry(string.Concat(keyPath, "\\", str));
            }
        }
Exemplo n.º 6
0
        private void bgwWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Process exeProcess;

            this._fileList.Clear();
            this._fileList.AddRange(
                from p in GlobalData.PresetsManager
                select new PatchInfo(p));
            if (this._fileList.Count == 0)
            {
                return;
            }
            this.ReportProgress(BackgroundFilePatcher.States.PreparingFilesStarted, 0);
            for (int i = 0; i < this._fileList.Count; i++)
            {
                if (this._bgwWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                PatchInfo item = this._fileList[i];
                if (!FileEx.Equals(item.ModdedFile, item.TempFile))
                {
                    File.Copy(item.ModdedFile, item.TempFile, true);
                }
                this.ReportProgress(BackgroundFilePatcher.States.PreparingFiles, BackgroundFilePatcher.CalculateProgress(i, this._fileList.Count));
            }
            BackgroundFilePatcher.BlockLogs();
            if (!Settings.Default.SkipLauncher || string.IsNullOrWhiteSpace(Settings.Default.X2Args))
            {
                BackgroundFilePatcher.RunLauncher();
                this.ReportProgress(BackgroundFilePatcher.States.WaitingForX2ToOpen, 0);
                while (!this._bgwWorker.CancellationPending)
                {
                    exeProcess = ProcessEx.GetExeProcess(Paths.Elsword.ClientExe);
                    Thread.Sleep(1000);
                    if (exeProcess != null)
                    {
                        this.ReportProgress(BackgroundFilePatcher.States.BackupStarted, 0);
                        this.CreateBackup();
                        this.ReportProgress(BackgroundFilePatcher.States.PatchingStarted, 0);
                        this.PatchFiles();
                        (new DirectoryInfo(Paths.Main.Cache)).Empty();
                        this.ReportProgress(BackgroundFilePatcher.States.WaitingForX2ToClose, 100);
                        exeProcess.WaitForExit();
                        this.ReportProgress(BackgroundFilePatcher.States.RestoringBackupStarted, 0);
                        this.RestoreBackup();
                        BackgroundFilePatcher.ClearRegistry("Software\\ElswordINT");
                        BackgroundFilePatcher.ClearRegistry("Software\\Nexon\\Elsword\\PatcherOption");
                        this.ReportProgress(BackgroundFilePatcher.States.Done, 100);
                        return;
                    }
                }
                e.Cancel = true;
                return;
            }
            else
            {
                exeProcess = Paths.Elsword.RunClient();
            }
            this.ReportProgress(BackgroundFilePatcher.States.BackupStarted, 0);
            this.CreateBackup();
            this.ReportProgress(BackgroundFilePatcher.States.PatchingStarted, 0);
            this.PatchFiles();
            (new DirectoryInfo(Paths.Main.Cache)).Empty();
            this.ReportProgress(BackgroundFilePatcher.States.WaitingForX2ToClose, 100);
            exeProcess.WaitForExit();
            this.ReportProgress(BackgroundFilePatcher.States.RestoringBackupStarted, 0);
            this.RestoreBackup();
            BackgroundFilePatcher.ClearRegistry("Software\\ElswordINT");
            BackgroundFilePatcher.ClearRegistry("Software\\Nexon\\Elsword\\PatcherOption");
            this.ReportProgress(BackgroundFilePatcher.States.Done, 100);
        }