protected virtual void InstallPatchEx(RaiserPatchNotificationEventArgs myEventArgs, System.Uri url) { try { if (myEventArgs == null) { string str = this.VersionString; myEventArgs = new RaiserPatchNotificationEventArgs(true, str, str, RaiserLanguageName.English); } string filePath = Path.Combine(Infos.DefaultValues.MyInfo.Directory.Patches, Path.GetFileName(url.OriginalString)); this.OnCurrentStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("Downloading0Patch", "Downloading new {0} version"), Infos.DefaultValues.AIDA.Strings.RaiserPatchCalled))); this.OnProgressBarStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent)); this.OnCurrentTotalProgressChanged(new ProgressEventArgs(100)); this.myWebClient_ForAIDA.DownloadFileAsync(url, filePath, new WorkerInfo("InstallPatchEx_callback", myEventArgs, filePath, url, false)); } catch (Exception ex) { this.OnHandledException(new HandledExceptionEventArgs(ex)); } }
private void MyWebClient_ForAIDA_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { WorkerInfo state = e.UserState as WorkerInfo; RaiserWebClientInstallingMetaWrapper meta = null; if (state == null) { meta = e.UserState as RaiserWebClientInstallingMetaWrapper; } if (e.Error != null) { if (state != null) { switch (state.Step) { default: this.OnProgressBarStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.None)); this.OnHandledException(new HandledExceptionEventArgs(e.Error)); break; } } } else if (e.Cancelled) { if (state != null) { switch (state.Step) { default: this.OnProgressBarStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.None)); this.OnHandledException(new HandledExceptionEventArgs(new NotImplementedException())); break; } } } else { if (state != null) { switch (state.Step) { default: this.OnHandledException(new HandledExceptionEventArgs(new NotImplementedException())); break; } } else if (meta != null) { switch (meta.Step) { case 0: if (!string.IsNullOrEmpty(e.Result)) { try { string raiserURL = AIDA.FlatJsonFetch <string>(e.Result, Infos.DefaultValues.AIDA.Tweaker.TransArmThingiesOrWatever.RaiserURL); if (!string.IsNullOrWhiteSpace(raiserURL)) { this.myWebClient_ForAIDA.DownloadStringAsync(new System.Uri(raiserURL), new RaiserWebClientInstallingMetaWrapper(1, meta.Meta, meta.LanguageName)); } else { this.OnPatchInstalled(new PatchFinishedEventArgs(VersionString)); } } catch (UriFormatException uriEx) { this.OnHandledException(new HandledExceptionEventArgs(uriEx)); } } else { this.OnHandledException(new HandledExceptionEventArgs(new Exception("Failed to check for patch.\r\n"))); } break; case 1: this.OnProgressBarStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.None)); if (!string.IsNullOrEmpty(e.Result)) { try { var langcode = GetLangCode(meta.LanguageName); var obj = GetValueFromJson(e.Result, langcode.ToString()); string newverurl = obj.URL, newvermd5 = obj.MD5; if (!string.IsNullOrWhiteSpace(newverurl)) { System.Uri url = new System.Uri(newverurl); InstallingMeta asd = new InstallingMeta(meta.Meta.Backup, meta.Meta.Force, newvermd5); if (this.VersionString != newvermd5 || !this.IsInstalled) { RaiserPatchNotificationEventArgs theevent = new RaiserPatchNotificationEventArgs(true, newvermd5, VersionString, meta.LanguageName); this.OnPatchNotification(theevent); if (meta.Meta.Force || theevent.Continue) { InstallPatchEx(theevent, url); } } else { this.OnPatchInstalled(new PatchFinishedEventArgs(VersionString)); } } else { this.OnPatchInstalled(new PatchFinishedEventArgs(VersionString)); } } catch (UriFormatException uriEx) { this.OnHandledException(new HandledExceptionEventArgs(uriEx)); } } else { this.OnHandledException(new HandledExceptionEventArgs(new Exception("Failed to check for patch.\r\n"))); } break; } } } }
protected virtual void OnInstalling(object sender, DoWorkEventArgs e) { this.OnProgressBarStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent)); WorkerInfo seed = e.Argument as WorkerInfo; RaiserPatchNotificationEventArgs seedEvent = seed.Params as RaiserPatchNotificationEventArgs; string patchdestination = DefaultValues.Directory.RaiserPatchFolder; Microsoft.VisualBasic.FileIO.FileSystem.CreateDirectory(patchdestination); using (FileStream fs = File.OpenRead(seed.Path)) using (var archive = SharpCompress.Archives.ArchiveFactory.Open(fs)) { this.OnCurrentStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("Installing0Patch", "Installing {0}"), Infos.DefaultValues.AIDA.Strings.RaiserPatchCalled))); bool guuuh = false; var result = AbstractExtractor.FlatExtract(archive, patchdestination, (insender, ine) => { if (!guuuh) { guuuh = true; this.OnCurrentTotalProgressChanged(new ProgressEventArgs(ine.Total)); } this.OnCurrentProgressChanged(new ProgressEventArgs(ine.CurrentIndex + 1)); }); if (!result.IsSuccess) { System.IO.Directory.Delete(patchdestination, true); /*System.Text.StringBuilder sb = new System.Text.StringBuilder(); * bool glaihwg = true; * foreach (var item in result.FailedItems) * if (glaihwg) * { * glaihwg = false; * sb.Append(item); * } * else * sb.Append(", " + item); * System.Windows.Forms.MessageBox.Show(sb.ToString());//*/ throw new Exception("Extract failed."); } PSO2.PSO2Plugin.PSO2Plugin plugin; foreach (string str in RequiredPluginList) { if (!string.IsNullOrWhiteSpace(str)) { plugin = PSO2.PSO2Plugin.PSO2PluginManager.Instance[str]; if (plugin != null) { if (!plugin.Enabled) { this.OnCurrentStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("InstallingPatch_EnableRequiredPlugin0", "Enabling required plugin: {0}"), plugin.Name))); plugin.Enabled = true; } } else { this.OnCurrentStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("InstallingPatch_FailedEnableRequiredPlugin0", "Failed to find required plugin: {0}.\nPlease enable it as soon as possible. Otherwise the patch may not work correctly."), str))); } } } } try { File.Delete(seed.Path); } catch { } e.Result = seedEvent.NewPatchVersion; MySettings.Patches.PatchLanguage = seedEvent.Language; MySettings.Patches.RaiserVersion = seedEvent.NewPatchVersion; MySettings.Patches.RaiserEnabled = true; }