New logging and Irony integration

This commit is contained in:
timerix 2023-09-28 14:11:34 +06:00
parent 126d29313e
commit 7fe79f0300
9 changed files with 150 additions and 74 deletions

View File

@ -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>

View File

@ -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

View File

@ -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)
{ {

View 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();
}
}

View File

@ -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)
{ {

View File

@ -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";

View File

@ -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;
@ -89,6 +101,12 @@ public static class Program
"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);
} }

View File

@ -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)
{ {

View File

@ -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>