예제 #1
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);
        }