protected void OnValidPrepatchPrompt(ValidPrepatchPromptEventArgs e) { if (this.ValidPrepatchPrompt != null) { this.syncContext?.Send(new System.Threading.SendOrPostCallback(delegate { this.ValidPrepatchPrompt.Invoke(this, e); }), null); } }
private void BWorker_DoWork(object sender, DoWorkEventArgs e) { this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Infinite)); WorkerParams wp = e.Argument as WorkerParams; string pso2Path = wp.PSO2Path; // Check if there is any prepatch files if (!wp.IgnorePrepatch) { string prepatchFolderData = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName, "data"); if (!DirectoryHelper.IsFolderEmpty(prepatchFolderData)) { // Ignore prepatch files if it's older than the current client version PSO2Version currentVersion = PSO2Version.Parse(MySettings.PSO2Version); PSO2Version prepatchVersion = PSO2Version.Parse(MySettings.PSO2PrecedeVersion.Version); if (prepatchVersion.CompareTo(currentVersion) > 0) { this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_FoundValidPrepatch", "Found prepatch files which are ready to be used."); ValidPrepatchPromptEventArgs myEventArgs = new ValidPrepatchPromptEventArgs(); this.OnValidPrepatchPrompt(myEventArgs); if (myEventArgs.Use) { string[] filenames = Directory.GetFiles(prepatchFolderData, "*", SearchOption.AllDirectories); this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_MovingPrepatchFiles", "Applying prepatch files."); this.ProgressTotal = filenames.Length; this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent)); string str = null, maindatafolder = Path.Combine(pso2Path, "data"), targetfile = null; for (int i = 0; i < filenames.Length; i++) { str = filenames[i]; targetfile = maindatafolder + str.Remove(0, prepatchFolderData.Length); File.Delete(targetfile); File.Move(str, targetfile); this.ProgressCurrent = i + 1; } // Check if it's empty again to remove it if (DirectoryHelper.IsFolderEmpty(prepatchFolderData)) { string prepatchfolder = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName); try { Directory.Delete(prepatchfolder, true); } catch { } } } } else { this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_FoundInvalidPrepatch", "Found out-dated prepatch files which will be ignored. These files shouldn't be used and should be deleted."); InvalidPrepatchPromptEventArgs myEventArgs = new InvalidPrepatchPromptEventArgs(); this.OnInvalidPrepatchPrompt(myEventArgs); if (myEventArgs.Delete) { this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_DeletingInvalidPrepatch", "Deleting out-dated prepatch files."); string prepatchfolder = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName); try { Directory.Delete(prepatchfolder, true); } catch { } } } } } this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Infinite)); var patchinfo = this.CheckForUpdates(); if (this.GetFilesList(patchinfo)) { System.Collections.Concurrent.ConcurrentDictionary <string, PSO2File> myPSO2filesList = ParseFilelist(this.myFileList, patchinfo); if (!myPSO2filesList.IsEmpty) { this.ProgressTotal = myPSO2filesList.Count; this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent, new Forms.MyMainMenuCode.CircleProgressBarProperties(true))); string verstring = wp.NewVersionString; if (string.IsNullOrWhiteSpace(verstring)) { verstring = this.myWebClient.DownloadString(Leayal.UriHelper.URLConcat(patchinfo.PatchURL, "version.ver")); } if (!string.IsNullOrWhiteSpace(verstring)) { verstring = verstring.Trim(); } anothersmallthreadpool = new AnotherSmallThreadPool(pso2Path, myPSO2filesList); anothersmallthreadpool.StepChanged += Anothersmallthreadpool_StepChanged; anothersmallthreadpool.ProgressChanged += Anothersmallthreadpool_ProgressChanged; anothersmallthreadpool.KaboomFinished += Anothersmallthreadpool_KaboomFinished; this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_BeginFileCheckAndDownload", "Begin the file check and download..."); anothersmallthreadpool.StartWork(new WorkerParams(pso2Path, verstring, wp.Installation, wp.IgnorePrepatch)); e.Result = null; } else { e.Result = new PSO2UpdateResult(UpdateResult.Failed); } } else { e.Result = new PSO2UpdateResult(UpdateResult.Unknown); throw new PSO2UpdateException(LanguageManager.GetMessageText("PSO2UpdateManager_GetPatchListFailed", "Failed to get PSO2's file list.")); } }