/// <exception cref="T:PatchworkLauncher.PatchingProcessException">Throws an exception when adding an instruction during the patching process</exception> private static void TryAddPatchInstruction(PatchInstruction instruction, Dictionary <string, List <PatchInstruction> > instructions) { string targetFile = string.Empty; try { IPatchInfo patchInfo = instruction.Patch.PatchInfo; string canPatch = patchInfo.CanPatch(AppContextManager.Context.Value); if (canPatch != null) { throw new PatchExecutionException(canPatch); } targetFile = patchInfo.GetTargetFile(AppContextManager.Context.Value).FullName; if (!instructions.ContainsKey(targetFile)) { instructions[targetFile] = new List <PatchInstruction>(); } instructions[targetFile].Add(instruction); } catch (Exception exception) { throw new PatchingProcessException(exception) { AssociatedInstruction = instruction, TargetFile = targetFile, Step = PatchProcessingStep.Grouping }; } }
public static XmlInstruction FromInstruction(PatchInstruction instr) { return new XmlInstruction() { IsEnabled = instr.IsEnabled, Name = instr.Patch.PatchInfo.PatchName, PatchPath = instr.PatchLocation }; }
public static XmlInstruction FromInstruction(PatchInstruction instruction) { return(new XmlInstruction { IsEnabled = instruction.IsEnabled, Name = instruction.Patch.PatchInfo.PatchName, Location = instruction.Location }); }
public static XmlInstruction FromInstruction(PatchInstruction instr) { return(new XmlInstruction() { IsEnabled = instr.IsEnabled, Name = instr.Patch.PatchInfo.PatchName, PatchPath = instr.PatchLocation }); }
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 List <PatchGroup> GroupXmlInstructions(IEnumerable <XmlInstruction> instructions) { var patchInstructions = new Dictionary <string, List <PatchInstruction> >(); foreach (XmlInstruction instruction in instructions) { using (PatchInstruction tmpInstruction = instruction.ToPatchInstruction()) { TryAddPatchInstruction(tmpInstruction, patchInstructions); } } IEnumerable <PatchGroup> groups = patchInstructions.Select(patchInstruction => new PatchGroup { Instructions = patchInstruction.Value, TargetPath = patchInstruction.Key }); return(groups.ToList()); }
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; } }