modlist
This commit is contained in:
parent
4e81f615e2
commit
3d550da77c
@ -15,6 +15,6 @@
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.1.8" />
|
||||
<PackageReference Include="DTLib" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -2,7 +2,6 @@ using System.Linq;
|
||||
using DTLib.Console;
|
||||
using DTLib.Dtsod;
|
||||
using diff_text;
|
||||
using DiffMatchPatch;
|
||||
using DTLib.Ben.Demystifier;
|
||||
|
||||
namespace ParadoxModMerger;
|
||||
@ -29,7 +28,7 @@ static class Diff
|
||||
LogModConflicts(conflicts);
|
||||
}
|
||||
|
||||
public static void DiffConflictsCommandHandler(IOPath conflicts_dtsod_path)
|
||||
public static void DiffDetailedCommandHandler(IOPath conflicts_dtsod_path)
|
||||
{
|
||||
var dtsod = new DtsodV23(File.ReadAllText(conflicts_dtsod_path));
|
||||
var conflicts = new ConflictingModFile[dtsod.Count];
|
||||
@ -233,7 +232,7 @@ static class Diff
|
||||
var dtsod = new DtsodV23();
|
||||
foreach (var cfl in conflicts)
|
||||
{
|
||||
Log("m", "file ","c", cfl.FilePath, "m", "in mods", "b", cfl.Mods.MergeToString(", "));
|
||||
Log("m", "file ","c", cfl.FilePath, "m", " in mods ", "m", cfl.Mods.MergeToString(", "));
|
||||
dtsod.Add(cfl.FilePath, cfl.Mods);
|
||||
}
|
||||
|
||||
|
||||
@ -8,22 +8,52 @@ static class Merge
|
||||
static ConsoleLogger logger = new($"logs", "merge");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
private const string modlist_filename = "modlist.txt";
|
||||
|
||||
/// analog of Directory.Copy(srcDir, outDir, true)
|
||||
/// has special behavior for some files
|
||||
private static void ModDirCopy(IOPath srcDir, IOPath outDir, IOPath out_modlist_file)
|
||||
{
|
||||
var files = Directory.GetAllFiles(srcDir);
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
string file_basename = files[i].LastName().Str;
|
||||
if(file_basename=="descriptor.mod") // skip file
|
||||
continue;
|
||||
if (file_basename == modlist_filename) // append modlist
|
||||
{
|
||||
File.AppendAllText(out_modlist_file, File.ReadAllText(files[i]));
|
||||
}
|
||||
|
||||
var newfile = files[i].ReplaceBase(srcDir, outDir);
|
||||
File.Copy(files[i], newfile, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void MergeAll(IOPath[] moddirs, IOPath outDir)
|
||||
{
|
||||
Log("b", $"found {moddirs.Length} mod dirs");
|
||||
HandleConflicts(moddirs);
|
||||
|
||||
|
||||
var modnamelist = new string[moddirs.Length];
|
||||
IOPath out_modlist_file = Path.Concat(outDir, modlist_filename);
|
||||
for (short i = 0; i < moddirs.Length; i++)
|
||||
{
|
||||
Log("b", $"[{i + 1}/{moddirs.Length}] merging mod ", "c", $"{moddirs[i]}");
|
||||
Directory.Copy(moddirs[i], outDir, true);
|
||||
ModDirCopy(moddirs[i], outDir, out_modlist_file);
|
||||
modnamelist[i]=moddirs[i].LastName().Str;
|
||||
}
|
||||
|
||||
File.AppendAllText(out_modlist_file, modnamelist.MergeToString('\n'));
|
||||
File.AppendAllText(out_modlist_file, "\n");
|
||||
}
|
||||
|
||||
public static void MergeInto(IOPath moddir, IOPath outDir)
|
||||
{
|
||||
HandleConflicts(new[] { moddir, outDir });
|
||||
Directory.Copy(moddir, outDir, true);
|
||||
IOPath out_modlist_file = Path.Concat(outDir, modlist_filename);
|
||||
ModDirCopy(moddir, outDir, modlist_filename);
|
||||
File.AppendAllText(out_modlist_file, $"{moddir.LastName()}\n");
|
||||
}
|
||||
|
||||
public static void ConsoleAskYN(string question, Action yes, Action no)
|
||||
|
||||
@ -40,9 +40,9 @@ public static class Program
|
||||
p=>Diff.DiffCommandHandler(p),
|
||||
"first_mod_directory:second_mod_directory:...",
|
||||
1),
|
||||
new LaunchArgument(new []{"diff-conflicts"},
|
||||
new LaunchArgument(new []{"diff-detailed"},
|
||||
"reads conflicts_XXX.dtsod file and shows text diff for each file",
|
||||
p=>Diff.DiffConflictsCommandHandler(p),
|
||||
p=>Diff.DiffDetailedCommandHandler(p),
|
||||
"conflicts_dtsod_path",
|
||||
1
|
||||
),
|
||||
@ -79,9 +79,14 @@ public static class Program
|
||||
|
||||
public static IOPath[] SplitStringToPaths(string connected_paths)
|
||||
{
|
||||
if (!connected_paths.Contains(':'))
|
||||
throw new Exception($"<{connected_paths}> doesn't contain any separators (:)");
|
||||
string[] split = connected_paths.Split(':');
|
||||
char part_sep;
|
||||
if (connected_paths.Contains(':'))
|
||||
part_sep = ':';
|
||||
else if (!connected_paths.Contains(':'))
|
||||
part_sep = ';';
|
||||
else throw new Exception($"<{connected_paths}> doesn't contain any separators (:/;)");
|
||||
|
||||
string[] split = connected_paths.Split(part_sep);
|
||||
IOPath[] split_iop = new IOPath[split.Length];
|
||||
for (int i = 0; i < split.Length; i++)
|
||||
split_iop[i] = new IOPath(split[i]);
|
||||
|
||||
@ -12,14 +12,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
||||
<PackageReference Include="DTLib.Dtsod" Version="1.1.4" />
|
||||
<PackageReference Include="DTLib.Dtsod" Version="1.2.0" />
|
||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.1.8" />
|
||||
<PackageReference Include="DTLib" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\diff-text\diff-text.csproj" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user