Compare commits
No commits in common. "d609b409f9ce6047fceb874ebcdf9d48ded6d63b" and "16d37990c0b1b658d7f370fece9266647067dda4" have entirely different histories.
d609b409f9
...
16d37990c0
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DiffMatchPatch;
|
||||
using DTLib.Ben.Demystifier;
|
||||
using DTLib.Console;
|
||||
using DTLib.Filesystem;
|
||||
|
||||
@ -25,20 +26,17 @@ public static class DiffText
|
||||
List<Diff>? diff = null;
|
||||
bool noColors = false;
|
||||
new LaunchArgumentParser(
|
||||
new LaunchArgument(["s", "string"],
|
||||
"shows difference of two strings",
|
||||
(s0, s1) => diff=TextDiff(s0, s1),
|
||||
"string0", "string1",
|
||||
1),
|
||||
new LaunchArgument(["f", "file"],
|
||||
"shows difference of two text files",
|
||||
(f0,f1) => diff=FileDiff(f0, f1),
|
||||
"file0", "file1",
|
||||
1),
|
||||
new LaunchArgument(["p", "plain-text","no-colors"],
|
||||
"print diff in plain text format",
|
||||
()=> noColors=true,
|
||||
0)
|
||||
new LaunchArgument(new[] { "s", "string" },
|
||||
"shows difference of two strings",
|
||||
(s0, s1) => diff=TextDiff(s0, s1),
|
||||
"string0", "string1", 1),
|
||||
new LaunchArgument(new[] { "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"},
|
||||
"print diff in plain text format",
|
||||
()=> noColors=true, 0)
|
||||
).ParseAndHandle(args);
|
||||
if (diff == null)
|
||||
throw new Exception("no action specified: use -s or -f");
|
||||
@ -48,7 +46,7 @@ public static class DiffText
|
||||
{ }
|
||||
catch (Exception ex)
|
||||
{
|
||||
ColoredConsole.WriteLine("r", $"{ex.Message} at {ex.Source}");
|
||||
ColoredConsole.WriteLine("r", ex.ToStringDemystified());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>diff_text</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>diff_text</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="google-diff-match-patch" Version="1.3.100" />
|
||||
<PackageReference Include="DTLib" Version="1.4.3" />
|
||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
||||
<PackageReference Include="google-diff-match-patch" Version="1.3.74" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.2.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DTLib.Demystifier;
|
||||
using DTLib.Console;
|
||||
using DTLib.Extensions;
|
||||
using File = DTLib.Filesystem.File;
|
||||
|
||||
namespace ParadoxDlcMetadataParser;
|
||||
|
||||
static class Program
|
||||
{
|
||||
private static string? GameName;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
new LaunchArgumentParser(
|
||||
new LaunchArgument(
|
||||
new[] { "f", "file" },
|
||||
"Searches for dlc id and name declarations in a dlc_metadata/* file.",
|
||||
ParseFile,
|
||||
"file_name",
|
||||
priority: 99),
|
||||
new LaunchArgument(
|
||||
new[] { "g", "game" },
|
||||
"Sets game name.",
|
||||
name => GameName = name,
|
||||
"game_name")
|
||||
).ParseAndHandle(args);
|
||||
}
|
||||
catch (LaunchArgumentParser.ExitAfterHelpException)
|
||||
{
|
||||
// this exception is thrown when the program exits after showing help message
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(ex.ToStringDemystified());
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
static void ParseFile(string filePath)
|
||||
{
|
||||
using var file = File.OpenRead(filePath);
|
||||
using var r = new StreamReader(file);
|
||||
List<string> names = new();
|
||||
List<int> ids = new();
|
||||
while (!r.EndOfStream)
|
||||
{
|
||||
string line = r.ReadLine()!;
|
||||
if (IsVarDeclaration(line, "name"))
|
||||
names.Add(line.AsSpan().After('=').After('"').Before('"').Trim().Trim('\t').ToString());
|
||||
else if (IsVarDeclaration(line, "id") || IsVarDeclaration(line, "steam_id"))
|
||||
{
|
||||
var s1 = line.AsSpan().After('=');
|
||||
if(s1.Contains('#'))
|
||||
s1 = s1.After("#"); // some ids are hidden in comments
|
||||
ids.Add(Convert.ToInt32(s1.Trim().Trim('\t').Trim('"').Trim(' ').ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (names.Count != ids.Count)
|
||||
throw new Exception("names.Count != ids.Count");
|
||||
|
||||
var ids_and_names = ids.Zip(names)
|
||||
.DistinctBy(tuple => tuple.First)
|
||||
.OrderBy(tuple => tuple.First)
|
||||
.ToList<(int id, string name)>();
|
||||
|
||||
Console.WriteLine("----------------------------------");
|
||||
foreach ((int id, string name) in ids_and_names)
|
||||
{
|
||||
Console.WriteLine($"{id} = {GameName}: {name}");
|
||||
}
|
||||
Console.WriteLine("----------------------------------");
|
||||
Console.WriteLine($"{ids_and_names.Count} DLC declarations found");
|
||||
}
|
||||
|
||||
static bool IsVarDeclaration(string line, string varName) =>
|
||||
line.StartsWith($"{varName} =") ||
|
||||
line.StartsWith($"{varName}=") ||
|
||||
line.Contains($" {varName} =") ||
|
||||
line.Contains($" {varName}=") ||
|
||||
line.Contains($"\t{varName} =") ||
|
||||
line.Contains($"\t{varName}=");
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<RootNamespace>ParadoxDlcMetadataParser</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib" Version="1.7.4" />
|
||||
<PackageReference Include="DTLib.Demystifier" Version="1.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -15,9 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution_files", "solution_
|
||||
Makefile = Makefile
|
||||
EndProjectSection
|
||||
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}") = "DTLib", "..\DTLib\DTLib\DTLib.csproj", "{67E226B7-F04B-4FB1-A9AA-E4AE3A5A8A3F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "paradox-dlc-metadata-parser", "paradox-dlc-metadata-parser\paradox-dlc-metadata-parser.csproj", "{8663EF88-08DE-4641-AAAE-9FBB54BFF66C}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "diff-text", "diff-text\diff-text.csproj", "{720D8D44-A9D3-4F58-BA1E-EA95808D1376}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -29,14 +29,14 @@ Global
|
||||
{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.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.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.Build.0 = Debug|Any CPU
|
||||
{8663EF88-08DE-4641-AAAE-9FBB54BFF66C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8663EF88-08DE-4641-AAAE-9FBB54BFF66C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8663EF88-08DE-4641-AAAE-9FBB54BFF66C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8663EF88-08DE-4641-AAAE-9FBB54BFF66C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
using diff_text;
|
||||
using System.Linq;
|
||||
using DTLib.Console;
|
||||
using DTLib.Dtsod;
|
||||
using DTLib.XXHash;
|
||||
using diff_text;
|
||||
using DTLib.Ben.Demystifier;
|
||||
|
||||
namespace ParadoxModMerger;
|
||||
|
||||
@ -15,8 +17,8 @@ public record struct ConflictingModFile(string FilePath, string[] Mods);
|
||||
|
||||
static class Diff
|
||||
{
|
||||
static ContextLogger logger = new (nameof(Diff), new FileLogger("logs", "diff"));
|
||||
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||
static ConsoleLogger logger = new($"logs", "diff");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
public static void DiffCommandHandler(string connected_pathes)
|
||||
{
|
||||
@ -71,7 +73,9 @@ static class Diff
|
||||
line_i = 0;
|
||||
for (int confl_i = 0; confl_i < conflicts.Length; confl_i++)
|
||||
{
|
||||
lines[line_i].color = confl_i == selected_confl_i ? ConsoleColor.Blue : ConsoleColor.White;
|
||||
if (confl_i == selected_confl_i)
|
||||
lines[line_i].color = ConsoleColor.Blue;
|
||||
else lines[line_i].color = ConsoleColor.White;
|
||||
line_i++;
|
||||
|
||||
for (int mod_i = 0; mod_i < conflicts[confl_i].Mods.Length; mod_i++)
|
||||
@ -176,7 +180,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, [modp.Str]);
|
||||
else all_files.Add(file.Str, new List<string>(1) { modp.Str });
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,15 +210,9 @@ static class Diff
|
||||
{
|
||||
if (filePathDiff.State == DiffState.Equal)
|
||||
{
|
||||
ulong hash0, hash1;
|
||||
using (var file0 = File.OpenRead(Path.Concat(dir0, filePathDiff.Value)))
|
||||
{
|
||||
hash0 = xxHash64.ComputeHash(file0);
|
||||
}
|
||||
using (var file1 = File.OpenRead(Path.Concat(dir1, filePathDiff.Value)))
|
||||
{
|
||||
hash1 = xxHash64.ComputeHash(file1);
|
||||
}
|
||||
Hasher hasher = new Hasher();
|
||||
string hash0=hasher.HashFile(Path.Concat(dir0, filePathDiff.Value)).HashToString();
|
||||
string hash1=hasher.HashFile(Path.Concat(dir1, filePathDiff.Value)).HashToString();
|
||||
if (hash0 != hash1)
|
||||
yield return filePathDiff with { State = DiffState.Changed };
|
||||
else yield return filePathDiff;
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
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 (string.IsNullOrEmpty(name))
|
||||
throw new NullReferenceException("name=null");
|
||||
if (string.IsNullOrEmpty(remote_file_id))
|
||||
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,108 +2,81 @@
|
||||
|
||||
static class Localisation
|
||||
{
|
||||
static ContextLogger logger = new(nameof(Localisation), new FileLogger("logs", "autoloc"));
|
||||
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||
static ConsoleLogger logger = new($"logs", "autoloc");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
public static void GenerateRussian(IOPath _engDir, IOPath _rusDir)
|
||||
public static void GenerateRussian(IOPath engDir, IOPath rusDir)
|
||||
{
|
||||
int counter = 0;
|
||||
ProcessDir(_engDir, _rusDir);
|
||||
Log("g",$"created {counter} localisation files");
|
||||
|
||||
void ProcessDir(IOPath engDir, IOPath rusDir)
|
||||
foreach (var fileName in Directory.GetAllFiles(engDir))
|
||||
{
|
||||
foreach (var fileName in Directory.GetFiles(engDir))
|
||||
if (!fileName.EndsWith("l_english.yml"))
|
||||
continue;
|
||||
|
||||
IOPath rusFileName = fileName
|
||||
.ReplaceBase(engDir, rusDir)
|
||||
.Replace("l_english", "l_russian");
|
||||
|
||||
if (!File.Exists(rusFileName))
|
||||
{
|
||||
if (!fileName.EndsWith("l_english.yml"))
|
||||
continue;
|
||||
|
||||
IOPath rusFileName = fileName
|
||||
.ReplaceBase(engDir, rusDir)
|
||||
.Replace("l_english", "l_russian");
|
||||
|
||||
if (File.Exists(rusFileName))
|
||||
{
|
||||
// Log("w", $"skipped {rusFileName.RemoveBase(rusDir)}");
|
||||
continue;
|
||||
}
|
||||
|
||||
string text = File.ReadAllText(fileName)
|
||||
.Replace("l_english:", "l_russian: ");
|
||||
byte[] bytes = StringConverter.UTF8BOM.GetBytes(text);
|
||||
File.WriteAllBytes(rusFileName, bytes);
|
||||
Log("g", $"created {rusFileName}");
|
||||
counter++;
|
||||
Log("gray", $"skipped file {rusFileName.RemoveBase(rusDir)}");
|
||||
continue;
|
||||
}
|
||||
|
||||
void ProcessSubdir(string subdirEngName, string subdirRusName)
|
||||
{
|
||||
var subdirEng = Path.Concat(engDir,subdirEngName);
|
||||
var subdirRus = Path.Concat(rusDir,subdirRusName);
|
||||
if (Directory.Exists(subdirEng))
|
||||
ProcessDir(subdirEng, subdirRus);
|
||||
}
|
||||
|
||||
ProcessSubdir("english", "russian");
|
||||
ProcessSubdir("replace", "replace");
|
||||
ProcessSubdir("name_lists", "name_lists");
|
||||
ProcessSubdir("random_names", "random_names");
|
||||
string text = File.ReadAllText(fileName)
|
||||
.Replace("l_english:", "l_russian: ");
|
||||
byte[] bytes = StringConverter.UTF8BOM.GetBytes(text);
|
||||
File.WriteAllBytes(rusFileName, bytes);
|
||||
Log("g", $"file {rusFileName} created");
|
||||
counter++;
|
||||
}
|
||||
Log("g",$"created {counter} localisation files");
|
||||
}
|
||||
|
||||
// deletes all localisations except l_russian and l_english
|
||||
public static void Clean(IOPath _loc_dir)
|
||||
{
|
||||
int deleted_files_count=0, deleted_dirs_count=0;
|
||||
DeleteUnneededDirs(_loc_dir);
|
||||
DeleteUnneededFiles(_loc_dir);
|
||||
Log("g", $"deleted {deleted_files_count} files");
|
||||
Log("g", $"deleted {deleted_dirs_count} dirs");
|
||||
Log("g", $"deleted {RemoveUnneededDirs(_loc_dir)} dirs");
|
||||
Log("g", $"deleted {RemoveUnneededFiles(_loc_dir)} files");
|
||||
|
||||
void DeleteUnneededDirs(IOPath loc_dir)
|
||||
|
||||
int RemoveUnneededDirs(IOPath loc_dir)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var subdir in Directory.GetDirectories(loc_dir))
|
||||
{
|
||||
string dir_basename = subdir.LastName().Str;
|
||||
if (dir_basename is "russian" or "english")
|
||||
if (dir_basename == "russian" || dir_basename == "english")
|
||||
continue;
|
||||
|
||||
if (dir_basename == "replace")
|
||||
{
|
||||
// Log("w",$"skipped {subdir}");
|
||||
RemoveUnneededDirs(subdir);
|
||||
RemoveUnneededFiles(subdir);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dir_basename is "replace" or "name_lists" or "random_names")
|
||||
{
|
||||
DeleteUnneededDirs(subdir);
|
||||
DeleteUnneededFiles(subdir);
|
||||
continue;
|
||||
}
|
||||
|
||||
// incorrect dirs, for example l_russian/
|
||||
if (dir_basename.ToLower().Contains("russian") || dir_basename.ToLower().Contains("english"))
|
||||
if (dir_basename.Contains("rus"))
|
||||
Log("y", $"unexpected dir: {subdir}");
|
||||
|
||||
Directory.Delete(subdir);
|
||||
Log("m", $"deleted {subdir}");
|
||||
deleted_dirs_count++;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void DeleteUnneededFiles(IOPath loc_dir)
|
||||
int RemoveUnneededFiles(IOPath loc_dir)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var file in Directory.GetFiles(loc_dir))
|
||||
{
|
||||
if(file.EndsWith("l_russian.yml") || file.EndsWith("l_english.yml"))
|
||||
{
|
||||
// Log("w",$"skipped {file}");
|
||||
if(file.EndsWith("l_russian") || file.EndsWith("l_enghish"))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!file.Contains("_l_") || !file.EndsWith(".yml"))
|
||||
Log("y",$"unexpected file: {file}");
|
||||
File.Delete(file);
|
||||
Log("m",$"deleted {file}");
|
||||
deleted_files_count++;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,12 @@
|
||||
namespace ParadoxModMerger;
|
||||
using System.Linq;
|
||||
using DTLib.Console;
|
||||
|
||||
namespace ParadoxModMerger;
|
||||
|
||||
static class Merge
|
||||
{
|
||||
static ContextLogger logger = new(nameof(Merge), new FileLogger("logs", "merge"));
|
||||
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||
static ConsoleLogger logger = new($"logs", "merge");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
private const string modlist_filename = "modlist.txt";
|
||||
|
||||
@ -15,14 +18,11 @@ static class Merge
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
string file_basename = files[i].LastName().Str;
|
||||
if (file_basename=="descriptor.mod") // skip file
|
||||
if(file_basename=="descriptor.mod") // skip file
|
||||
continue;
|
||||
|
||||
if (file_basename == modlist_filename) // append modlist
|
||||
{
|
||||
string subModlistText = File.ReadAllText(files[i]);
|
||||
File.AppendAllText(out_modlist_file, subModlistText);
|
||||
continue;
|
||||
File.AppendAllText(out_modlist_file, File.ReadAllText(files[i]));
|
||||
}
|
||||
|
||||
var newfile = files[i].ReplaceBase(srcDir, outDir);
|
||||
@ -50,31 +50,18 @@ static class Merge
|
||||
|
||||
public static void MergeInto(IOPath moddir, IOPath outDir)
|
||||
{
|
||||
HandleConflicts([moddir, outDir]);
|
||||
HandleConflicts(new[] { moddir, outDir });
|
||||
IOPath out_modlist_file = Path.Concat(outDir, modlist_filename);
|
||||
ModDirCopy(moddir, outDir, modlist_filename);
|
||||
File.AppendAllText(out_modlist_file, $"{moddir.LastName()}\n");
|
||||
ModDirCopy(moddir, outDir, out_modlist_file);
|
||||
}
|
||||
|
||||
public static void ConsoleAskYN(string question, Action? yes, Action? no)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Log("y", question + " [y/n]");
|
||||
string answ = Program.YesAll ? "y" : (ColoredConsole.Read("w") ?? "").ToLower();
|
||||
if (answ == "y")
|
||||
{
|
||||
Log("c",$"answer: {answ}");
|
||||
yes?.Invoke();
|
||||
break;
|
||||
}
|
||||
if (answ == "n") {
|
||||
Log("c",$"answer: {answ}");
|
||||
no?.Invoke();
|
||||
break;
|
||||
}
|
||||
Log("r", $"incorrect answer: {answ}");
|
||||
}
|
||||
Log("y", question + " [y/n]");
|
||||
string answ = ColoredConsole.Read("w").ToLower();
|
||||
if (answ == "y") yes?.Invoke();
|
||||
else no?.Invoke();
|
||||
}
|
||||
|
||||
static void HandleConflicts(IOPath[] moddirs)
|
||||
@ -102,9 +89,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 = [];
|
||||
List<IOPath> changed_mods = [];
|
||||
List<IOPath> unchanged_mods = [];
|
||||
List<IOPath> not_found_mods = new List<IOPath>();
|
||||
List<IOPath> changed_mods = new List<IOPath>();
|
||||
List<IOPath> unchanged_mods = new List<IOPath>();
|
||||
|
||||
foreach (IOPath outdated_mods_dir in outdated_dirs)
|
||||
foreach (var mod in Directory.GetDirectories(outdated_mods_dir))
|
||||
@ -158,8 +145,8 @@ static class Merge
|
||||
}
|
||||
|
||||
List<IOPath> added_mods = new List<IOPath>(src_dir_mods.Count - changed_mods.Count);
|
||||
var found_mods = changed_mods
|
||||
.Concat(unchanged_mods)
|
||||
var found_mods = Enumerable
|
||||
.Concat(changed_mods, unchanged_mods)
|
||||
.Select(m=>Path.Concat(updated_mods_dir, m.LastName()))
|
||||
.ToList();
|
||||
foreach (var modD in Diff.DiffCollections(found_mods, src_dir_mods))
|
||||
@ -180,17 +167,6 @@ static class Merge
|
||||
"m", not_found_mods.MergeToString('\n'));
|
||||
if (unchanged_mods.Count>0)
|
||||
Log("w", $"unchanged {unchanged_mods.Count}");
|
||||
|
||||
IOPath new_mods_copy_dir = Path.Concat(backup_dir.ParentDir(),
|
||||
$"!new_{DateTime.Now.ToString(MyTimeFormat.ForFileNames)}");
|
||||
ConsoleAskYN($"copy new mods to {new_mods_copy_dir}", () =>
|
||||
{
|
||||
foreach (var mod in added_mods)
|
||||
{
|
||||
Directory.Copy(mod, Path.Concat(new_mods_copy_dir, mod), false);
|
||||
}
|
||||
},
|
||||
null);
|
||||
}
|
||||
|
||||
public static void RenameModsCommandHandler(string dir_with_mods, string rename_pairs_str)
|
||||
|
||||
@ -1,36 +1,21 @@
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Diagnostics;
|
||||
global using System.Linq;
|
||||
global using System.Text;
|
||||
global using System.Threading.Tasks;
|
||||
global using DTLib;
|
||||
global using DTLib.Extensions;
|
||||
global using DTLib.Filesystem;
|
||||
global using DTLib.Logging;
|
||||
global using DTLib.Demystifier;
|
||||
global using DTLib.Console;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using DTLib.Console;
|
||||
|
||||
namespace ParadoxModMerger;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
static ContextLogger logger = new ContextLogger(nameof(Program), new FileLogger("logs", "main"));
|
||||
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;
|
||||
static ConsoleLogger logger = new($"logs", "main");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
static int Main(string[] args)
|
||||
{
|
||||
@ -42,71 +27,61 @@ public static class Program
|
||||
string outPath = "" ;
|
||||
|
||||
new LaunchArgumentParser(
|
||||
new LaunchArgument(["o", "out"],
|
||||
"Sets output path",
|
||||
p => outPath = p,
|
||||
new LaunchArgument(new []{"o", "out"},
|
||||
"sets output path",
|
||||
p => outPath=p,
|
||||
"out_path",
|
||||
0),
|
||||
new LaunchArgument(["y", "yes-all"],
|
||||
"Automatically answers [Y] to all questions",
|
||||
() => YesAll = true,
|
||||
0),
|
||||
new LaunchArgument(["clear"],
|
||||
new LaunchArgument(new []{"clear"},
|
||||
"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",
|
||||
1),
|
||||
new LaunchArgument(["diff"],
|
||||
new LaunchArgument(new []{"diff"},
|
||||
"Compares mod files by hash",
|
||||
p => Diff.DiffCommandHandler(p),
|
||||
p=>Diff.DiffCommandHandler(p),
|
||||
"first_mod_directory:second_mod_directory:...",
|
||||
1),
|
||||
new LaunchArgument(["diff-detailed"],
|
||||
new LaunchArgument(new []{"diff-detailed"},
|
||||
"reads conflicts_XXX.dtsod file and shows text diff for each file",
|
||||
p => Diff.DiffDetailedCommandHandler(p),
|
||||
p=>Diff.DiffDetailedCommandHandler(p),
|
||||
"conflicts_dtsod_path",
|
||||
1),
|
||||
new LaunchArgument(["merge-subdirs"],
|
||||
new LaunchArgument(new []{"merge-subdirs"},
|
||||
"Merges mods and shows conflicts. Requires -o",
|
||||
d => Merge.MergeAll(Directory.GetDirectories(d), outPath),
|
||||
"dir_with_mods",
|
||||
1),
|
||||
new LaunchArgument(["merge-into", "merge-single"],
|
||||
new LaunchArgument(new []{"merge-into", "merge-single"},
|
||||
"Merges one mod into output dir and shows conflicts. Requires -o",
|
||||
mod => Merge.MergeInto(mod, outPath),
|
||||
mod=>Merge.MergeInto(mod, outPath),
|
||||
"mod_dir",
|
||||
1),
|
||||
new LaunchArgument(["gen-rus-locale"],
|
||||
new LaunchArgument(new []{"gen-rus-locale"},
|
||||
"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",
|
||||
1),
|
||||
new LaunchArgument(["desc"],
|
||||
new LaunchArgument(new []{"desc"},
|
||||
"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",
|
||||
1),
|
||||
new LaunchArgument(["rename"],
|
||||
new LaunchArgument(new []{"rename"},
|
||||
"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:...)",
|
||||
1),
|
||||
new LaunchArgument(["update-mods"],
|
||||
new LaunchArgument(new []{"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, outdated)=>Merge.UpdateMods(updated, SplitArgToPaths(outdated, true), outPath),
|
||||
"updated_mods_dir", "outdated_dir OR outdated_dir0:...:outdated_dirN",
|
||||
1),
|
||||
new LaunchArgument(["clean-locales"],
|
||||
new LaunchArgument(new []{"clean-locales"},
|
||||
"Deletes all localisations except l_russian and l_english.",
|
||||
locdir => Localisation.Clean(locdir),
|
||||
locdir=> Localisation.Clean(locdir),
|
||||
"localisation_dir",
|
||||
1),
|
||||
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),
|
||||
"connected_dirs_with_mods",
|
||||
1)
|
||||
).ParseAndHandle(args);
|
||||
}
|
||||
@ -114,7 +89,7 @@ public static class Program
|
||||
{ }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log("r", ExceptionExtensions.ToStringDemystified(ex));
|
||||
Log("r", DTLib.Ben.Demystifier.ExceptionExtensions.ToStringDemystified(ex));
|
||||
Console.ResetColor();
|
||||
return 1;
|
||||
}
|
||||
@ -130,7 +105,7 @@ public static class Program
|
||||
else if (connected_parts.Contains(';'))
|
||||
part_sep = ';';
|
||||
else if (allow_one_part)
|
||||
return [connected_parts];
|
||||
return new []{connected_parts};
|
||||
else throw new Exception($"<{connected_parts}> doesn't contain any separators (:/;)");
|
||||
|
||||
return connected_parts.Split(part_sep);
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using Fizzler.Systems.HtmlAgilityPack;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DTLib.Ben.Demystifier;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace ParadoxModMerger;
|
||||
using Fizzler.Systems.HtmlAgilityPack;
|
||||
|
||||
static class Workshop
|
||||
{
|
||||
static ContextLogger logger = new(nameof(Workshop), new FileLogger("logs", "clear"));
|
||||
static void Log(params string[] msg) => logger.LogColored(msg);
|
||||
|
||||
static ConsoleLogger logger = new($"logs", "clear");
|
||||
static void Log(params string[] msg) => logger.Log(msg);
|
||||
|
||||
public static void ClearWorkshop(IOPath workshopDir, IOPath outDir)
|
||||
{
|
||||
@ -17,7 +22,7 @@ static class Workshop
|
||||
|
||||
for (int i = 0; i < moddirs.Length; i++)
|
||||
{
|
||||
string modId = moddirs[i].LastName().Str;
|
||||
string modId = moddirs[i].LastName().ToString();
|
||||
var zips = Directory.GetFiles(moddirs[i], "*.zip");
|
||||
if (zips.Length > 0)
|
||||
{
|
||||
|
||||
@ -2,17 +2,25 @@
|
||||
<Project Sdk="Microsoft.Net.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>ParadoxModMerger</RootNamespace>
|
||||
<AssemblyName>paradox-mod-merger</AssemblyName>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.XXHash" Version="1.0.4" />
|
||||
<None Include="7z\**" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.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.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\diff-text\diff-text.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
rm -rf publish
|
||||
mkdir publish
|
||||
dotnet publish -c debug -o publish
|
||||
dotnet publish -c debug -o publish -f net7.0
|
||||
|
||||
@ -6,16 +6,13 @@ function publish_aot() {
|
||||
echo "---------[$1]---------"
|
||||
cd "$1"
|
||||
rm -rf bin/publish
|
||||
dotnet publish -c Release -o bin/publish -p:PublishAot=true --self-contained
|
||||
sleep 0.1
|
||||
rm bin/publish/*.pdb
|
||||
dotnet publish -c Release -o bin/publish -p:PublishAot=true
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user