public PatchInstruction Command_Direct_AddPatch(string path, bool isEnabled) { var targetPath = path; var fileName = Path.GetFileName(path); var hadToCopy = false; PatchingManifest manifest = null; try { Directory.CreateDirectory(_modFolder); var folder = Path.GetDirectoryName(path); var absoluteFolder = PathHelper.GetAbsolutePath(folder); var modsPath = PathHelper.GetAbsolutePath(_modFolder); if (!Preferences.DontCopyFiles && !modsPath.Equals(absoluteFolder, StringComparison.InvariantCultureIgnoreCase)) { targetPath = Path.Combine(_modFolder, fileName); File.Copy(path, targetPath, true); hadToCopy = true; } manifest = ManifestMaker.CreateManifest(PathHelper.GetAbsolutePath(targetPath)); if (manifest.PatchInfo == null) { throw new PatchDeclerationException("The patch did not have a PatchInfo class."); } var patchInstruction = new PatchInstruction { IsEnabled = isEnabled, Patch = manifest, PatchLocation = PathHelper.GetRelativePath(targetPath), AppInfo = AppInfo, PatchOriginalLocation = path }; Instructions.Add(patchInstruction); return(patchInstruction); } catch (Exception ex) { Logger.Error(ex, $"The patch located in {path} could not be loaded."); manifest?.Dispose(); if (hadToCopy) { File.Delete(targetPath); } throw; } }
private static void TryAddPatch(string assemblyPath) { var manifest = new PatchingManifest(); try { manifest = TryGetManifest(assemblyPath); } catch (PatchDeclerationException patchDeclerationException) { Logger.Error(patchDeclerationException, "Cannot load patch assembly: {0}", assemblyPath); manifest?.Dispose(); return; } AddXmlInstruction(assemblyPath, manifest); }