Skip to content

Commit 9a2b3c2

Browse files
committed
fixed: the merged mod will now be removed correctly when all merges have been removed
1 parent 4e36693 commit 9a2b3c2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

WitcherScriptMerger/Forms/MainForm.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,47 @@ public void DeleteMerges(IEnumerable<TreeNode> fileNodes)
747747
merge.RelativePath.EqualsIgnoreCase(node.Text)))
748748
.ToList();
749749
DeleteMerges(merges);
750+
if (Program.Inventory.Merges.Count == 0)
751+
{
752+
string gameDir = Program.Settings.Get("GameDirectory");
753+
string mergeModPath = Path.Combine(gameDir, "Mods", Paths.RetrieveMergedModName());
754+
if (!Directory.Exists(mergeModPath))
755+
{
756+
// Folder is gone - nothing to do here.
757+
return;
758+
}
759+
760+
// KDiff must've created a backup which is why the mod folder still exists.
761+
string[] filePaths = Directory.GetFiles(mergeModPath, "*", SearchOption.AllDirectories);
762+
string[] dirPaths = Directory.GetDirectories(mergeModPath, "*", SearchOption.AllDirectories)
763+
.OrderByDescending(dir => dir.Length).ToArray();
764+
string errorMsg = "Merges have been removed successfully, but we were unable to automatically "
765+
+ $"remove the generated merged mod folder: {mergeModPath}; please remove the folder manually.";
766+
Array.ForEach(filePaths, filePath =>
767+
{
768+
try
769+
{
770+
File.Delete(filePath);
771+
} catch (Exception exc)
772+
{
773+
ShowError(errorMsg);
774+
return;
775+
}
776+
});
777+
778+
Array.ForEach(dirPaths, dirPath =>
779+
{
780+
try
781+
{
782+
Directory.Delete(dirPath);
783+
}
784+
catch (Exception exc)
785+
{
786+
ShowError(errorMsg);
787+
return;
788+
}
789+
});
790+
}
750791
}
751792

752793
bool DeleteMerges(List<Merge> merges)

0 commit comments

Comments
 (0)