private static void WaitForPatchCreator(PatchCreator patchCreator) { while (patchCreator.IsRunning) { Thread.Sleep(100); LogPatchCreatorToConsole(patchCreator); } LogPatchCreatorToConsole(patchCreator); }
private static void LogPatchCreatorToConsole(PatchCreator patchCreator) { string log = patchCreator.FetchLog(); while (log != null) { LogToConsole(log); log = patchCreator.FetchLog(); } }
public static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: tweavediff [path to working directory]"); Console.WriteLine("The working directory must contain:"); Console.WriteLine("- Terraria.exe (vanilla, unmodified exe)"); Console.WriteLine("- TerrariaModified.exe (your modified exe)"); Console.WriteLine("- All the required dependencies (such as Relogic.dll, CSteamWorks.dll, etc)"); Environment.Exit(0); } PatchCreator.Start(args[0]); }
public void RegisterPatch_Text_InsertAsLastChild() { // Arrange const string MovieName = "TestMovieName"; const string XPath = "descendant::OptionsScreenWidget[@Id='Options']/Children"; var patch = PatchCreator.ConstructInsertPatch(InsertType.Child, "<ValidRoot><SomeChild/></ValidRoot>", 10); PrefabComponent prefabComponent = new("TestModule"); var movieDocument = GetBaseDocument(); // Act prefabComponent.RegisterPatch(MovieName, XPath, patch); prefabComponent.ProcessMovieIfNeeded(MovieName, movieDocument); // Assert var validRootNode = movieDocument.SelectSingleNode("descendant::ValidRoot"); Assert.IsNotNull(validRootNode); Assert.AreEqual("Children", validRootNode !.ParentNode !.Name); Assert.AreEqual("SomeChild", validRootNode.FirstChild.Name); Assert.AreEqual(validRootNode, validRootNode.ParentNode.ChildNodes[validRootNode.ParentNode.ChildNodes.Count - 1], $"Last child should be ValidRoot. Was {validRootNode.ParentNode.FirstChild.Name}"); }
public void RegisterPatch_FileName_ReplaceRemoveRootNode() { // Arrange const string MovieName = "TestMovieName"; const string XPath = "descendant::OptionsScreenWidget[@Id='Options']/Children/Standard.TopPanel"; var patch = PatchCreator.ConstructInsertPatchPath(InsertType.Replace, "PrefabRemoveRootNode", 10, true); PrefabComponent prefabComponent = new("TestModule"); var movieDocument = GetBaseDocument(); // Act prefabComponent.RegisterPatch(MovieName, XPath, patch); prefabComponent.ProcessMovieIfNeeded(MovieName, movieDocument); // Assert var someChild1Node = movieDocument.SelectSingleNode("descendant::SomeChild1"); Assert.IsNotNull(someChild1Node); Assert.AreEqual("Children", someChild1Node !.ParentNode !.Name); Assert.AreEqual(4, someChild1Node !.ParentNode !.ChildNodes.Count); Assert.AreEqual("SomeChild1", someChild1Node !.ParentNode !.ChildNodes[0].Name); Assert.AreEqual("SomeChild2", someChild1Node !.ParentNode !.ChildNodes[1].Name); }
private static void CreatePatch() { string prevRoot = GetArgument("prevRoot"); PatchCreator patchCreator = new PatchCreator(GetArgument("root"), GetArgument("out"), GetArgument("name"), GetArgument("version")). LoadIgnoredPathsFromFile(GetArgument("ignoredPaths")).CreateRepairPatch(!HasArgument("dontCreateRepairPatch")). CreateIncrementalPatch(prevRoot != null, prevRoot).SilentMode(HasArgument("silent")); bool hasStarted = patchCreator.Run(); if (hasStarted) { while (patchCreator.IsRunning) { Thread.Sleep(100); string log = patchCreator.FetchLog(); while (log != null) { LogToConsole(log); log = patchCreator.FetchLog(); } } if (patchCreator.Result == PatchResult.Failed) { Console.WriteLine("\nOperation failed..."); } else { Console.WriteLine("\nOperation successful..."); } } else { Console.WriteLine("\nOperation could not be started; maybe it is already executing?"); } }
public void RegisterPatch_Remove() { var harmony = new Harmony($"{nameof(PrefabComponentPrefabs2Tests)}.{nameof(RegisterPatch_Remove)}"); harmony.Patch(SymbolExtensions.GetMethodInfo(() => TaleWorlds.Engine.Utilities.GetBasePath()), prefix: new HarmonyMethod(AccessTools.Method(typeof(PrefabComponentPrefabs2Tests), nameof(MockedGetBasePathPath)))); // Arrange const string MovieName = "TestMovieName"; const string XPath = "descendant::OptionsScreenWidget[@Id='Options']"; var patch = PatchCreator.ConstructInsertRemovePatchPath("Prefab"); PrefabComponent prefabComponent = new("TestModule"); var movieDocument = GetBaseDocument(); // Act prefabComponent.RegisterPatch(MovieName, XPath, patch); prefabComponent.ProcessMovieIfNeeded(MovieName, movieDocument); // Assert var removedNode = movieDocument.SelectSingleNode("descendant::OptionsScreenWidget[@Id='Options']"); Assert.IsNull(removedNode); }
private void DrawCreateTab() { c_RootPath = PathField("Root path: ", c_RootPath, true); c_PrevRoot = PathField("Previous version path: ", c_PrevRoot, true); c_OutputPath = PathField("Output path: ", c_OutputPath, true); c_IgnoredFiles = PathField("Ignored files holder: ", c_IgnoredFiles, false); c_Name = EditorGUILayout.TextField("Project name: ", c_Name); c_Version = EditorGUILayout.TextField("Project version: ", c_Version); c_CreateRepair = EditorGUILayout.Toggle("Create repair patch: ", c_CreateRepair); c_IgnoreOutputLog = EditorGUILayout.Toggle("Ignore output_log.txt: ", c_IgnoreOutputLog); GUILayout.Space(10f); if (GUILayout.Button("Create Patch", GUILayout.Height(35f))) { c_RootPath = c_RootPath.Trim(); c_PrevRoot = c_PrevRoot.Trim(); c_OutputPath = c_OutputPath.Trim(); c_IgnoredFiles = c_IgnoredFiles.Trim(); c_Name = c_Name.Trim(); c_Version = c_Version.Trim(); if (string.IsNullOrEmpty(c_RootPath) || string.IsNullOrEmpty(c_OutputPath) || string.IsNullOrEmpty(c_Name) || string.IsNullOrEmpty(c_Version)) { return; } patchCreator = new PatchCreator(c_RootPath, c_OutputPath, c_Name, c_Version); patchCreator.CreateIncrementalPatch(c_PrevRoot.Length > 0, c_PrevRoot).CreateRepairPatch(c_CreateRepair); if (c_IgnoredFiles.Length > 0) { patchCreator.LoadIgnoredPathsFromFile(c_IgnoredFiles); } if (c_IgnoreOutputLog) { patchCreator.AddIgnoredPath("*output_log.txt"); } if (patchCreator.Run()) { Debug.Log("<b>Patch creator started</b>"); EditorApplication.update -= OnUpdate; EditorApplication.update += OnUpdate; } else { Debug.LogWarning("<b>Couldn't start patch creator. Maybe it is already running?</b>"); } } if (GUILayout.Button("Generate Console Command", GUILayout.Height(25f))) { string command = string.Format("Patcher create -root=\"{0}\" -out=\"{1}\" -name=\"{2}\" -version=\"{3}\"", c_RootPath, c_OutputPath, c_Name, c_Version); if (c_PrevRoot.Length > 0) { command += string.Concat(" -prevRoot=\"", c_PrevRoot, "\""); } if (c_IgnoredFiles.Length > 0) { command += string.Concat(" -ignoredPaths=\"", c_IgnoredFiles, "\""); } if (!c_CreateRepair) { command += " -dontCreateRepairPatch"; } Debug.Log(command); if (c_IgnoreOutputLog) { if (c_IgnoredFiles.Length > 0) { Debug.Log(string.Concat("You have to add *output_log.txt to ", c_IgnoredFiles, " manually")); } else { Debug.Log("To ignore output_log.txt, you have to provide an Ignored files holder and add *output_log.txt to it manually"); } } } }
private static void CreatePatch() { string prevRoot = GetArgument("prevRoot"); string compRepair = GetArgument("compressionRepair"); string compInstaller = GetArgument("compressionInstaller"); string compIncremental = GetArgument("compressionIncremental"); CompressionFormat repairCompression, installerCompression, incrementalCompression; if (compRepair == "GZIP") { repairCompression = CompressionFormat.GZIP; } else if (compRepair == "NONE") { repairCompression = CompressionFormat.NONE; } else { repairCompression = CompressionFormat.LZMA; } if (compInstaller == "GZIP") { installerCompression = CompressionFormat.GZIP; } else if (compInstaller == "NONE") { installerCompression = CompressionFormat.NONE; } else { installerCompression = CompressionFormat.LZMA; } if (compIncremental == "GZIP") { incrementalCompression = CompressionFormat.GZIP; } else if (compIncremental == "NONE") { incrementalCompression = CompressionFormat.NONE; } else { incrementalCompression = CompressionFormat.LZMA; } PatchCreator patchCreator = new PatchCreator(GetArgument("root"), GetArgument("out"), GetArgument("name"), GetArgument("version")). LoadIgnoredPathsFromFile(GetArgument("ignoredPaths")).SetCompressionFormat(repairCompression, installerCompression, incrementalCompression). CreateRepairPatch(!HasArgument("dontCreateRepairPatch")).CreateIncrementalPatch(prevRoot != null, prevRoot).CreateInstallerPatch(!HasArgument("dontCreateInstallerPatch")). SetPreviousPatchFilesRoot(GetArgument("prevPatchRoot"), HasArgument("skipUnchangedPatchFiles")).SilentMode(HasArgument("silent")); bool hasStarted = patchCreator.Run(); if (hasStarted) { WaitForPatchCreator(patchCreator); if (patchCreator.Result == PatchResult.Failed) { Console.WriteLine("\nOperation failed..."); } else { Console.WriteLine("\nOperation successful..."); } } else { Console.WriteLine("\nOperation could not be started; maybe it is already executing?"); } }
private void DrawCreateTab() { c_RootPath = PathField(rootPathGUI, c_RootPath, true); c_PrevRoot = PathField(prevRootGUI, c_PrevRoot, true); c_PrevOutputPath = PathField(prevOutputPathGUI, c_PrevOutputPath, true); c_OutputPath = PathField(outputPathGUI, c_OutputPath, true); c_Name = EditorGUILayout.TextField("Project name: ", c_Name); c_Version = EditorGUILayout.TextField("Project version: ", c_Version); c_CreateRepair = EditorGUILayout.Toggle("Create repair patch: ", c_CreateRepair); c_CreateInstaller = EditorGUILayout.Toggle("Create installer patch: ", c_CreateInstaller); GUI.enabled = false; EditorGUILayout.Toggle(createIncrementalGUI, !string.IsNullOrEmpty(c_PrevRoot)); if (!string.IsNullOrEmpty(c_PrevOutputPath)) { GUI.enabled = true; } c_SkipUnchangedPatchFiles = EditorGUILayout.Toggle(skipUnchangedPatchFilesGUI, c_SkipUnchangedPatchFiles); GUI.enabled = true; c_RepairComp = (CompressionFormat)EditorGUILayout.EnumPopup("Repair patch compression: ", c_RepairComp); c_IncrementalComp = (CompressionFormat)EditorGUILayout.EnumPopup("Incremental patch compression: ", c_IncrementalComp); c_InstallerComp = (CompressionFormat)EditorGUILayout.EnumPopup("Installer patch compression: ", c_InstallerComp); GUILayout.Label("Ignored paths (one path per line): "); c_IgnoredPaths = EditorGUILayout.TextArea(c_IgnoredPaths); GUILayout.Space(10f); if (GUILayout.Button("Create Patch", GUILayout.Height(35f))) { c_RootPath = c_RootPath.Trim(); c_PrevRoot = c_PrevRoot.Trim(); c_PrevOutputPath = c_PrevOutputPath.Trim(); c_OutputPath = c_OutputPath.Trim(); c_IgnoredPaths = c_IgnoredPaths.Trim(); c_Name = c_Name.Trim(); c_Version = c_Version.Trim(); if (c_RootPath.Length == 0 || c_OutputPath.Length == 0 || c_Name.Length == 0 || c_Version.Length == 0) { return; } patchCreator = new PatchCreator(c_RootPath, c_OutputPath, c_Name, c_Version); patchCreator.CreateIncrementalPatch(c_PrevRoot.Length > 0, c_PrevRoot).CreateRepairPatch(c_CreateRepair).CreateInstallerPatch(c_CreateInstaller). SetCompressionFormat(c_RepairComp, c_InstallerComp, c_IncrementalComp).SetPreviousPatchFilesRoot(c_PrevOutputPath, c_SkipUnchangedPatchFiles); if (c_IgnoredPaths.Length > 0) { patchCreator.AddIgnoredPaths(c_IgnoredPaths.Replace("\r", "").Split('\n')); } if (!EditorUtility.DisplayDialog("Self Patcher Executable", "If this is a self patching app (i.e. this app will update itself), you'll first need to generate a self patcher executable. See README for more info.", "Got it!", "Oh, I forgot it!")) { return; } if (patchCreator.Run()) { Debug.Log("<b>Patch creator started</b>"); EditorApplication.update -= OnUpdate; EditorApplication.update += OnUpdate; } else { Debug.LogWarning("<b>Couldn't start patch creator. Maybe it is already running?</b>"); } } if (GUILayout.Button("Generate Console Command", GUILayout.Height(25f))) { string command = string.Format("Patcher create -root=\"{0}\" -out=\"{1}\" -name=\"{2}\" -version=\"{3}\" -compressionRepair=\"{4}\" -compressionIncremental=\"{5}\" -compressionInstaller=\"{6}\"", c_RootPath, c_OutputPath, c_Name, c_Version, c_RepairComp, c_IncrementalComp, c_InstallerComp); if (c_PrevRoot.Length > 0) { command += string.Concat(" -prevRoot=\"", c_PrevRoot, "\""); } if (c_PrevOutputPath.Length > 0) { command += string.Concat(" -prevPatchRoot=\"", c_PrevOutputPath, "\""); } if (c_IgnoredPaths.Length > 0) { command += string.Concat(" -ignoredPaths=\"", CONSOLE_COMMAND_IGNORED_PATHS_HOLDER, "\""); } if (!c_CreateRepair) { command += " -dontCreateRepairPatch"; } if (!c_CreateInstaller) { command += " -dontCreateInstallerPatch"; } if (c_SkipUnchangedPatchFiles) { command += " -skipUnchangedPatchFiles"; } Debug.Log(command); if (c_IgnoredPaths.Length > 0) { Debug.Log(string.Concat("You have to insert the following ignored path(s) to \"", CONSOLE_COMMAND_IGNORED_PATHS_HOLDER, "\":\n", c_IgnoredPaths)); } } if (GUILayout.Button("Help", GUILayout.Height(25f))) { Application.OpenURL("https://github.com/yasirkula/SimplePatchTool/wiki/Legacy:-Generating-Patch#via-unity-plugin"); } }
private void DrawCreateTab() { c_RootPath = PathField("Root path: ", c_RootPath, true); c_PrevRoot = PathField("Previous version path: ", c_PrevRoot, true); c_OutputPath = PathField("Output path: ", c_OutputPath, true); c_Name = EditorGUILayout.TextField("Project name: ", c_Name); c_Version = EditorGUILayout.TextField("Project version: ", c_Version); c_CreateRepair = EditorGUILayout.Toggle("Create repair patch: ", c_CreateRepair); GUILayout.Label("Ignored paths (one path per line): "); c_IgnoredPaths = EditorGUILayout.TextArea(c_IgnoredPaths); GUILayout.Space(10f); if (GUILayout.Button("Create Patch", GUILayout.Height(35f))) { c_RootPath = c_RootPath.Trim(); c_PrevRoot = c_PrevRoot.Trim(); c_OutputPath = c_OutputPath.Trim(); c_IgnoredPaths = c_IgnoredPaths.Trim(); c_Name = c_Name.Trim(); c_Version = c_Version.Trim(); if (c_RootPath.Length == 0 || c_OutputPath.Length == 0 || c_Name.Length == 0 || c_Version.Length == 0) { return; } patchCreator = new PatchCreator(c_RootPath, c_OutputPath, c_Name, c_Version); patchCreator.CreateIncrementalPatch(c_PrevRoot.Length > 0, c_PrevRoot).CreateRepairPatch(c_CreateRepair); if (c_IgnoredPaths.Length > 0) { patchCreator.AddIgnoredPaths(c_IgnoredPaths.Replace("\r", "").Split('\n')); } if (patchCreator.Run()) { Debug.Log("<b>Patch creator started</b>"); EditorApplication.update -= OnUpdate; EditorApplication.update += OnUpdate; } else { Debug.LogWarning("<b>Couldn't start patch creator. Maybe it is already running?</b>"); } } if (GUILayout.Button("Generate Console Command", GUILayout.Height(25f))) { string command = string.Format("Patcher create -root=\"{0}\" -out=\"{1}\" -name=\"{2}\" -version=\"{3}\"", c_RootPath, c_OutputPath, c_Name, c_Version); if (c_PrevRoot.Length > 0) { command += string.Concat(" -prevRoot=\"", c_PrevRoot, "\""); } if (c_IgnoredPaths.Length > 0) { command += string.Concat(" -ignoredPaths=\"", CONSOLE_COMMAND_IGNORED_PATHS_HOLDER, "\""); } if (!c_CreateRepair) { command += " -dontCreateRepairPatch"; } Debug.Log(command); if (c_IgnoredPaths.Length > 0) { Debug.Log(string.Concat("You have to insert the following ignored path(s) to \"", CONSOLE_COMMAND_IGNORED_PATHS_HOLDER, "\":\n", c_IgnoredPaths)); } } }