public void SetMod(ModInfo mod) { Mod = mod; _modServiceGetter = _modKernelFactory.Create(mod); _cachedMsgBlockService = _modServiceGetter.Get <ICachedMsgBlockService>(); _cachedMsgBlockService.RebuildCache(); SetCurrentModule(CurrentModuleId ?? ListItems[0].ModuleId, true); RaiseAllPropertiesChanged(); }
public bool TryGetCurrentModServiceGetter(out IServiceGetter currentModServiceGetter) { if (!TryGetCurrentMod(out var currentMod)) { currentModServiceGetter = null; return(false); } currentModServiceGetter = _modServiceGetterFactory.Create(currentMod); return(true); }
private void RunPlugin(ModInfo mod, PluginInfo chosen) { try { chosen.Plugin.Run(new PluginContext(_modKernelFactory.Create(mod))); } catch (Exception e) { _dialogService.ShowMessageBox(MessageBoxArgs.Ok( title: $"Error running {chosen.Name}", message: $"An error was encountered while running the plugin {chosen.Name} (v{chosen.Version} by {chosen.Author}). Details:\n\n" + e.ToString(), type: MessageBoxType.Error )); } }
public void Patch(ModInfo modInfo, string romPath, PatchOptions patchOptions, IProgress <ProgressInfo> progress = null) { progress?.Report(new ProgressInfo(statusText: "Preparing to patch...", isIndeterminate: true)); ConcurrentBag <FileToPatch> filesToPatch = new ConcurrentBag <FileToPatch>(); Exception exception = null; try { var services = _modServiceGetterFactory.Create(modInfo); var patchers = services.Get <IEnumerable <IPatchBuilder> >(); GetFilesToPatch(patchers, filesToPatch, patchOptions); #if PATCHER_BUG_FIXING string debugOut = FileUtil.MakeUniquePath(Path.Combine(FileUtil.DesktopDirectory, "patch_debug_dump")); Directory.CreateDirectory(debugOut); foreach (var file in filesToPatch) { string dest = Path.Combine(debugOut, file.GamePath.Replace(Path.DirectorySeparatorChar, '~')); if (file.Options.HasFlag(FilePatchOptions.DeleteSourceWhenDone)) { File.Move(file.FileSystemPath, dest); } else { File.Copy(file.FileSystemPath, dest); } } return; #endif progress?.Report(new ProgressInfo(isIndeterminate: false, maxProgress: filesToPatch.Count, statusText: "Patching...")); int count = 0; using (var nds = _ndsFactory(romPath)) { foreach (var file in filesToPatch) { if (file.Options.HasFlag(FilePatchOptions.VariableLength)) { nds.InsertVariableLengthFile(file.GamePath, file.FileSystemPath); } else { nds.InsertFixedLengthFile(file.GamePath, file.FileSystemPath); } progress?.Report(new ProgressInfo(progress: ++count)); } } } catch (Exception e) { exception = e; } finally { progress?.Report(new ProgressInfo(statusText: "Cleaning up temporary files...", isIndeterminate: true)); foreach (var file in filesToPatch) { if (file.Options.HasFlag(FilePatchOptions.DeleteSourceWhenDone)) { File.Delete(file.FileSystemPath); } } } if (exception != null) { throw exception; } progress?.Report(new ProgressInfo(statusText: "Done!", isIndeterminate: false)); }