New logging and Irony integration
This commit is contained in:
parent
126d29313e
commit
7fe79f0300
@ -1,5 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
@ -7,15 +6,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
<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.74" />
|
||||||
</ItemGroup>
|
<PackageReference Include="DTLib" Version="1.3.0" />
|
||||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
|
||||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
|
||||||
<PackageReference Include="DTLib" Version="1.2.2" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution_files", "solution_
|
|||||||
Makefile = Makefile
|
Makefile = Makefile
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib", "..\DTLib\DTLib\DTLib.csproj", "{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "diff-text", "diff-text\diff-text.csproj", "{720D8D44-A9D3-4F58-BA1E-EA95808D1376}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "diff-text", "diff-text\diff-text.csproj", "{720D8D44-A9D3-4F58-BA1E-EA95808D1376}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
@ -29,10 +27,6 @@ Global
|
|||||||
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Release|Any CPU.Build.0 = Release|Any CPU
|
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{076BFCFF-1D3E-44FB-B434-73716B79A135}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Release|Any CPU.Build.0 = Release|Any CPU
|
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{720D8D44-A9D3-4F58-BA1E-EA95808D1376}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
|||||||
@ -14,8 +14,8 @@ public record struct ConflictingModFile(string FilePath, string[] Mods);
|
|||||||
|
|
||||||
static class Diff
|
static class Diff
|
||||||
{
|
{
|
||||||
static ConsoleLogger logger = new("logs", "diff");
|
static ContextLogger logger = new (nameof(Diff), new FileLogger("logs", "diff"));
|
||||||
static void Log(params string[] msg) => logger.Log(msg);
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
public static void DiffCommandHandler(string connected_pathes)
|
public static void DiffCommandHandler(string connected_pathes)
|
||||||
{
|
{
|
||||||
|
|||||||
79
paradox-mod-merger/IronyIntegration.cs
Normal file
79
paradox-mod-merger/IronyIntegration.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
namespace ParadoxModMerger;
|
||||||
|
|
||||||
|
public static class IronyIntegration
|
||||||
|
{
|
||||||
|
static ContextLogger logger = new(nameof(IronyIntegration), new FileLogger("logs", "irony-integration"));
|
||||||
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
|
public static void GenerateIronyCollection(string dirs_with_mods_connected, IOPath out_json_file_path)
|
||||||
|
{
|
||||||
|
IOPath[] dirs_with_mods = Program.SplitArgToPaths(dirs_with_mods_connected, true);
|
||||||
|
var mod_desc_values = new List<(string name, string steam_id)>();
|
||||||
|
foreach (var dir in dirs_with_mods)
|
||||||
|
{
|
||||||
|
foreach (var mod_dir in Directory.GetDirectories(dir))
|
||||||
|
{
|
||||||
|
IOPath descriptor_path = Path.Concat(mod_dir, "descriptor.mod");
|
||||||
|
if (!File.Exists(descriptor_path))
|
||||||
|
Log("y", "directory ", "c", mod_dir.Str, "y", " doesn't contain descriptor");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? name=null, remote_file_id=null;
|
||||||
|
var lines = System.IO.File.ReadAllLines(descriptor_path.Str);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if (line.StartsWith("name="))
|
||||||
|
{
|
||||||
|
// "name=\"".Length==6
|
||||||
|
name = line.Substring(6, line.LastIndexOf('\"')-6);
|
||||||
|
}
|
||||||
|
else if (line.StartsWith("remote_file_id="))
|
||||||
|
{
|
||||||
|
// "remote_file_id=\"".Length==16
|
||||||
|
remote_file_id = line.Substring(16, line.LastIndexOf('\"')-16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.IsNullOrEmpty())
|
||||||
|
throw new NullReferenceException("name=null");
|
||||||
|
if (remote_file_id.IsNullOrEmpty())
|
||||||
|
throw new NullReferenceException("remote_file_id=null");
|
||||||
|
mod_desc_values.Add((name,remote_file_id)!);
|
||||||
|
Log("b",$"[{mod_desc_values.Count-1}] {{ ", "c", name!, "b", $", {remote_file_id!} }}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
using var out_json_stream = File.OpenWrite(out_json_file_path);
|
||||||
|
using var stream_writer = new System.IO.StreamWriter(out_json_stream, StringConverter.UTF8);
|
||||||
|
stream_writer.WriteLine($$"""
|
||||||
|
{
|
||||||
|
"game":"stellaris",
|
||||||
|
"name":"{{out_json_file_path.LastName().AsSpan().BeforeLast('.')}}",
|
||||||
|
"mods":[
|
||||||
|
""");
|
||||||
|
|
||||||
|
for (int mod_pos = 0; mod_pos < mod_desc_values.Count; mod_pos++)
|
||||||
|
{
|
||||||
|
stream_writer.Write($$"""
|
||||||
|
{
|
||||||
|
"displayName":"{{mod_desc_values[mod_pos].name}}",
|
||||||
|
"enabled":true,
|
||||||
|
"position":{{mod_pos}},
|
||||||
|
"steamId":"{{mod_desc_values[mod_pos].steam_id}}"
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
if(mod_pos<mod_desc_values.Count-1)
|
||||||
|
stream_writer.Write(',');
|
||||||
|
stream_writer.Write('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_writer.WriteLine("""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
stream_writer.Flush();
|
||||||
|
stream_writer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
static class Localisation
|
static class Localisation
|
||||||
{
|
{
|
||||||
static ConsoleLogger logger = new("logs", "autoloc");
|
static ContextLogger logger = new(nameof(Localisation), new FileLogger("logs", "autoloc"));
|
||||||
static void Log(params string[] msg) => logger.Log(msg);
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
public static void GenerateRussian(IOPath _engDir, IOPath _rusDir)
|
public static void GenerateRussian(IOPath _engDir, IOPath _rusDir)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
static class Merge
|
static class Merge
|
||||||
{
|
{
|
||||||
static ConsoleLogger logger = new("logs", "merge");
|
static ContextLogger logger = new(nameof(Merge), new FileLogger("logs", "merge"));
|
||||||
static void Log(params string[] msg) => logger.Log(msg);
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
private const string modlist_filename = "modlist.txt";
|
private const string modlist_filename = "modlist.txt";
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,20 @@ namespace ParadoxModMerger;
|
|||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
static ConsoleLogger logger = new("logs", "main");
|
static ContextLogger logger = new ContextLogger(nameof(Program), new FileLogger("logs", "main"));
|
||||||
static void Log(params string[] msg) => logger.Log(msg);
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
|
public static void LogColored(this ContextLogger _logger, params string[] msg)
|
||||||
|
{
|
||||||
|
ColoredConsole.WriteLine(msg);
|
||||||
|
|
||||||
|
StringBuilder b = new();
|
||||||
|
if (msg.Length == 1)
|
||||||
|
b.Append(msg[0]);
|
||||||
|
else for (int i = 1; i < msg.Length; i+=2)
|
||||||
|
b.Append(msg[i]);
|
||||||
|
_logger.LogInfo(b.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
public static bool YesAll = false;
|
public static bool YesAll = false;
|
||||||
|
|
||||||
@ -30,65 +42,71 @@ public static class Program
|
|||||||
string outPath = "" ;
|
string outPath = "" ;
|
||||||
|
|
||||||
new LaunchArgumentParser(
|
new LaunchArgumentParser(
|
||||||
new LaunchArgument(new []{"o", "out"},
|
new LaunchArgument(new[] { "o", "out" },
|
||||||
"Sets output path",
|
"Sets output path",
|
||||||
p => outPath=p,
|
p => outPath = p,
|
||||||
"out_path",
|
"out_path",
|
||||||
0),
|
0),
|
||||||
new LaunchArgument(new []{"y", "yes-all"},
|
new LaunchArgument(new[] { "y", "yes-all" },
|
||||||
"Automatically answers [Y] to all questions",
|
"Automatically answers [Y] to all questions",
|
||||||
()=> YesAll=true,
|
() => YesAll = true,
|
||||||
0),
|
0),
|
||||||
new LaunchArgument(new []{"clear"},
|
new LaunchArgument(new[] { "clear" },
|
||||||
"Clear mod files and put them into separate dirs in output dir. Requires -o",
|
"Clear mod files and put them into separate dirs in output dir. Requires -o",
|
||||||
wdir=>Workshop.ClearWorkshop(wdir, outPath),
|
wdir => Workshop.ClearWorkshop(wdir, outPath),
|
||||||
"workshop_dir",
|
"workshop_dir",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"diff"},
|
new LaunchArgument(new[] { "diff" },
|
||||||
"Compares mod files by hash",
|
"Compares mod files by hash",
|
||||||
p=>Diff.DiffCommandHandler(p),
|
p => Diff.DiffCommandHandler(p),
|
||||||
"first_mod_directory:second_mod_directory:...",
|
"first_mod_directory:second_mod_directory:...",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"diff-detailed"},
|
new LaunchArgument(new[] { "diff-detailed" },
|
||||||
"reads conflicts_XXX.dtsod file and shows text diff for each file",
|
"reads conflicts_XXX.dtsod file and shows text diff for each file",
|
||||||
p=>Diff.DiffDetailedCommandHandler(p),
|
p => Diff.DiffDetailedCommandHandler(p),
|
||||||
"conflicts_dtsod_path",
|
"conflicts_dtsod_path",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"merge-subdirs"},
|
new LaunchArgument(new[] { "merge-subdirs" },
|
||||||
"Merges mods and shows conflicts. Requires -o",
|
"Merges mods and shows conflicts. Requires -o",
|
||||||
d => Merge.MergeAll(Directory.GetDirectories(d), outPath),
|
d => Merge.MergeAll(Directory.GetDirectories(d), outPath),
|
||||||
"dir_with_mods",
|
"dir_with_mods",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"merge-into", "merge-single"},
|
new LaunchArgument(new[] { "merge-into", "merge-single" },
|
||||||
"Merges one mod into output dir and shows conflicts. Requires -o",
|
"Merges one mod into output dir and shows conflicts. Requires -o",
|
||||||
mod=>Merge.MergeInto(mod, outPath),
|
mod => Merge.MergeInto(mod, outPath),
|
||||||
"mod_dir",
|
"mod_dir",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"gen-rus-locale"},
|
new LaunchArgument(new[] { "gen-rus-locale" },
|
||||||
"Creates l_russian copy of english locale in output directory. Requires -o",
|
"Creates l_russian copy of english locale in output directory. Requires -o",
|
||||||
eng=>Localisation.GenerateRussian(eng, outPath),
|
eng => Localisation.GenerateRussian(eng, outPath),
|
||||||
"english_locale_path",
|
"english_locale_path",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"desc"},
|
new LaunchArgument(new[] { "desc" },
|
||||||
"Downloads mod description from steam to new file in outDir. Requires -o",
|
"Downloads mod description from steam to new file in outDir. Requires -o",
|
||||||
id=>Workshop.CreateDescFile(id, outPath).GetAwaiter().GetResult(),
|
id => Workshop.CreateDescFile(id, outPath).GetAwaiter().GetResult(),
|
||||||
"mod_id",
|
"mod_id",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"rename"},
|
new LaunchArgument(new[] { "rename" },
|
||||||
"Renames mods in directory",
|
"Renames mods in directory",
|
||||||
(modsdir, replace_pairs)=>Merge.RenameModsCommandHandler(modsdir, replace_pairs),
|
(modsdir, replace_pairs) => Merge.RenameModsCommandHandler(modsdir, replace_pairs),
|
||||||
"dir_with_mods", "replace_pairs (old_name:new_name:...)",
|
"dir_with_mods", "replace_pairs (old_name:new_name:...)",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"update-mods"},
|
new LaunchArgument(new[] { "update-mods" },
|
||||||
"Updates mods in [outdated_dir0...outdated_dirN] to new versions if found in updated_mods_dir. " +
|
"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.",
|
"Moves old mods to backup_dir defined by -o.",
|
||||||
(updated, outdated)=>Merge.UpdateMods(updated, SplitArgToPaths(outdated, true), outPath),
|
(updated, outdated) => Merge.UpdateMods(updated, SplitArgToPaths(outdated, true), outPath),
|
||||||
"updated_mods_dir", "outdated_dir OR outdated_dir0:...:outdated_dirN",
|
"updated_mods_dir", "outdated_dir OR outdated_dir0:...:outdated_dirN",
|
||||||
1),
|
1),
|
||||||
new LaunchArgument(new []{"clean-locales"},
|
new LaunchArgument(new[] { "clean-locales" },
|
||||||
"Deletes all localisations except l_russian and l_english.",
|
"Deletes all localisations except l_russian and l_english.",
|
||||||
locdir=> Localisation.Clean(locdir),
|
locdir => Localisation.Clean(locdir),
|
||||||
"localisation_dir",
|
"localisation_dir",
|
||||||
|
1),
|
||||||
|
new LaunchArgument(new[] { "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),
|
||||||
|
"connected_dirs_with_mods",
|
||||||
1)
|
1)
|
||||||
).ParseAndHandle(args);
|
).ParseAndHandle(args);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@ namespace ParadoxModMerger;
|
|||||||
|
|
||||||
static class Workshop
|
static class Workshop
|
||||||
{
|
{
|
||||||
static ConsoleLogger logger = new("logs", "clear");
|
static ContextLogger logger = new(nameof(Workshop), new FileLogger("logs", "clear"));
|
||||||
static void Log(params string[] msg) => logger.Log(msg);
|
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||||
|
|
||||||
public static void ClearWorkshop(IOPath workshopDir, IOPath outDir)
|
public static void ClearWorkshop(IOPath workshopDir, IOPath outDir)
|
||||||
{
|
{
|
||||||
@ -17,7 +17,7 @@ static class Workshop
|
|||||||
|
|
||||||
for (int i = 0; i < moddirs.Length; i++)
|
for (int i = 0; i < moddirs.Length; i++)
|
||||||
{
|
{
|
||||||
string modId = moddirs[i].LastName().ToString();
|
string modId = moddirs[i].LastName().Str;
|
||||||
var zips = Directory.GetFiles(moddirs[i], "*.zip");
|
var zips = Directory.GetFiles(moddirs[i], "*.zip");
|
||||||
if (zips.Length > 0)
|
if (zips.Length > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,23 +5,15 @@
|
|||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<RootNamespace>ParadoxModMerger</RootNamespace>
|
<RootNamespace>ParadoxModMerger</RootNamespace>
|
||||||
<AssemblyName>paradox-mod-merger</AssemblyName>
|
<AssemblyName>paradox-mod-merger</AssemblyName>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="7z\**" CopyToOutputDirectory="PreserveNewest" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
||||||
<PackageReference Include="DTLib.Dtsod" Version="1.2.1" />
|
<PackageReference Include="DTLib.Dtsod" Version="1.3.0" />
|
||||||
|
<PackageReference Include="DTLib.Logging" Version="1.3.0" />
|
||||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
|
||||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
|
||||||
<PackageReference Include="DTLib" Version="1.2.3" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\diff-text\diff-text.csproj" />
|
<ProjectReference Include="..\diff-text\diff-text.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user