This commit is contained in:
Timerix22 2024-01-01 15:15:11 +06:00
parent 7fe79f0300
commit 0c2670f55a
8 changed files with 38 additions and 35 deletions

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Text;
using DiffMatchPatch;
using DTLib.Ben.Demystifier;
using DTLib.Console;
using DTLib.Filesystem;
@ -26,17 +25,17 @@ public static class DiffText
List<Diff>? diff = null;
bool noColors = false;
new LaunchArgumentParser(
new LaunchArgument(new[] { "s", "string" },
new LaunchArgument(["s", "string"],
"shows difference of two strings",
(s0, s1) => diff=TextDiff(s0, s1),
"string0", "string1",
1),
new LaunchArgument(new[] { "f", "file" },
new LaunchArgument(["f", "file"],
"shows difference of two text files",
(f0,f1) => diff=FileDiff(f0, f1),
"file0", "file1",
1),
new LaunchArgument(new []{"p", "plain-text","no-colors"},
new LaunchArgument(["p", "plain-text","no-colors"],
"print diff in plain text format",
()=> noColors=true,
0)
@ -49,7 +48,7 @@ public static class DiffText
{ }
catch (Exception ex)
{
ColoredConsole.WriteLine("r", ex.ToStringDemystified());
ColoredConsole.WriteLine("r", $"{ex.Message} at {ex.Source}");
return 1;
}

View File

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>diff_text</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>diff_text</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
<PackageReference Include="google-diff-match-patch" Version="1.3.74" />
<PackageReference Include="google-diff-match-patch" Version="1.3.98" />
<PackageReference Include="DTLib" Version="1.3.0" />
</ItemGroup>
</Project>

View File

@ -177,7 +177,7 @@ static class Diff
var file = _file.RemoveBase(modp);
if (all_files.TryGetValue(file.Str, out var associated_mods))
associated_mods.Add(modp.Str);
else all_files.Add(file.Str, new List<string>(1) { modp.Str });
else all_files.Add(file.Str, [modp.Str]);
}
}

View File

@ -50,7 +50,7 @@ static class Merge
public static void MergeInto(IOPath moddir, IOPath outDir)
{
HandleConflicts(new[] { moddir, outDir });
HandleConflicts([moddir, outDir]);
IOPath out_modlist_file = Path.Concat(outDir, modlist_filename);
File.AppendAllText(out_modlist_file, $"{moddir.LastName()}\n");
ModDirCopy(moddir, outDir, out_modlist_file);
@ -102,9 +102,9 @@ static class Merge
public static void UpdateMods(IOPath updated_mods_dir, IOPath[] outdated_dirs, IOPath backup_dir)
{
var src_dir_mods = Directory.GetDirectories(updated_mods_dir).ToList();
List<IOPath> not_found_mods = new List<IOPath>();
List<IOPath> changed_mods = new List<IOPath>();
List<IOPath> unchanged_mods = new List<IOPath>();
List<IOPath> not_found_mods = [];
List<IOPath> changed_mods = [];
List<IOPath> unchanged_mods = [];
foreach (IOPath outdated_mods_dir in outdated_dirs)
foreach (var mod in Directory.GetDirectories(outdated_mods_dir))

View File

@ -30,7 +30,7 @@ public static class Program
_logger.LogInfo(b.ToString());
}
public static bool YesAll = false;
public static bool YesAll;
static int Main(string[] args)
{
@ -42,67 +42,67 @@ public static class Program
string outPath = "" ;
new LaunchArgumentParser(
new LaunchArgument(new[] { "o", "out" },
new LaunchArgument(["o", "out"],
"Sets output path",
p => outPath = p,
"out_path",
0),
new LaunchArgument(new[] { "y", "yes-all" },
new LaunchArgument(["y", "yes-all"],
"Automatically answers [Y] to all questions",
() => YesAll = true,
0),
new LaunchArgument(new[] { "clear" },
new LaunchArgument(["clear"],
"Clear mod files and put them into separate dirs in output dir. Requires -o",
wdir => Workshop.ClearWorkshop(wdir, outPath),
"workshop_dir",
1),
new LaunchArgument(new[] { "diff" },
new LaunchArgument(["diff"],
"Compares mod files by hash",
p => Diff.DiffCommandHandler(p),
"first_mod_directory:second_mod_directory:...",
1),
new LaunchArgument(new[] { "diff-detailed" },
new LaunchArgument(["diff-detailed"],
"reads conflicts_XXX.dtsod file and shows text diff for each file",
p => Diff.DiffDetailedCommandHandler(p),
"conflicts_dtsod_path",
1),
new LaunchArgument(new[] { "merge-subdirs" },
new LaunchArgument(["merge-subdirs"],
"Merges mods and shows conflicts. Requires -o",
d => Merge.MergeAll(Directory.GetDirectories(d), outPath),
"dir_with_mods",
1),
new LaunchArgument(new[] { "merge-into", "merge-single" },
new LaunchArgument(["merge-into", "merge-single"],
"Merges one mod into output dir and shows conflicts. Requires -o",
mod => Merge.MergeInto(mod, outPath),
"mod_dir",
1),
new LaunchArgument(new[] { "gen-rus-locale" },
new LaunchArgument(["gen-rus-locale"],
"Creates l_russian copy of english locale in output directory. Requires -o",
eng => Localisation.GenerateRussian(eng, outPath),
"english_locale_path",
1),
new LaunchArgument(new[] { "desc" },
new LaunchArgument(["desc"],
"Downloads mod description from steam to new file in outDir. Requires -o",
id => Workshop.CreateDescFile(id, outPath).GetAwaiter().GetResult(),
"mod_id",
1),
new LaunchArgument(new[] { "rename" },
new LaunchArgument(["rename"],
"Renames mods in directory",
(modsdir, replace_pairs) => Merge.RenameModsCommandHandler(modsdir, replace_pairs),
"dir_with_mods", "replace_pairs (old_name:new_name:...)",
1),
new LaunchArgument(new[] { "update-mods" },
new LaunchArgument(["update-mods"],
"Updates mods in [outdated_dir0...outdated_dirN] to new versions if found in updated_mods_dir. " +
"Moves old mods to backup_dir defined by -o.",
(updated, outdated) => Merge.UpdateMods(updated, SplitArgToPaths(outdated, true), outPath),
"updated_mods_dir", "outdated_dir OR outdated_dir0:...:outdated_dirN",
1),
new LaunchArgument(new[] { "clean-locales" },
new LaunchArgument(["clean-locales"],
"Deletes all localisations except l_russian and l_english.",
locdir => Localisation.Clean(locdir),
"localisation_dir",
1),
new LaunchArgument(new[] { "gen-collection-json" },
new LaunchArgument(["gen-collection-json"],
"Generates json file representing mod collection in format readable by pdx launcher and IronyModManager." +
"Requires -o",
(connected_dirs) => IronyIntegration.GenerateIronyCollection(connected_dirs, outPath),
@ -130,7 +130,7 @@ public static class Program
else if (connected_parts.Contains(';'))
part_sep = ';';
else if (allow_one_part)
return new []{connected_parts};
return [connected_parts];
else throw new Exception($"<{connected_parts}> doesn't contain any separators (:/;)");
return connected_parts.Split(part_sep);

View File

@ -2,11 +2,12 @@
<Project Sdk="Microsoft.Net.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>ParadoxModMerger</RootNamespace>
<AssemblyName>paradox-mod-merger</AssemblyName>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />

View File

@ -1,4 +1,4 @@
#!/bin/sh
rm -rf publish
mkdir publish
dotnet publish -c debug -o publish -f net7.0
dotnet publish -c debug -o publish

View File

@ -6,13 +6,16 @@ function publish_aot() {
echo "---------[$1]---------"
cd "$1"
rm -rf bin/publish
dotnet publish -c Release -o bin/publish -p:PublishAot=true
dotnet publish -c Release -o bin/publish -p:PublishAot=true --self-contained
sleep 0.1
rm bin/publish/*.pdb
mkdir -p ../publish
cp -r bin/publish/* ../publish/
cd ..
}
rm -rf publish
# paradox-mod-merger publishes diff-text as dotnet executable
#publish_aot diff-text
publish_aot paradox-mod-merger
publish_aot diff-text
ls -lh publish