From 9c27744b6154741fa49f6b10d1c2aa0a747b736c Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 24 Feb 2023 23:34:41 +0600 Subject: [PATCH] diff-text --- diff-text/Program.cs | 63 ++++++++++++++++++ diff-text/diff-text.csproj | 20 ++++++ paradox-mod-merger.sln | 8 ++- {7z => paradox-mod-merger/7z}/7-zip.dll | Bin {7z => paradox-mod-merger/7z}/7-zip32.dll | Bin {7z => paradox-mod-merger/7z}/7z.dll | Bin {7z => paradox-mod-merger/7z}/7z.exe | Bin Diff.cs => paradox-mod-merger/Diff.cs | 0 .../Localisation.cs | 0 Merge.cs => paradox-mod-merger/Merge.cs | 0 Program.cs => paradox-mod-merger/Program.cs | 0 Workshop.cs => paradox-mod-merger/Workshop.cs | 0 .../paradox-mod-merger.csproj | 9 +-- paradox-rus-localisation-gen.csproj | 31 --------- 14 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 diff-text/Program.cs create mode 100644 diff-text/diff-text.csproj rename {7z => paradox-mod-merger/7z}/7-zip.dll (100%) rename {7z => paradox-mod-merger/7z}/7-zip32.dll (100%) rename {7z => paradox-mod-merger/7z}/7z.dll (100%) rename {7z => paradox-mod-merger/7z}/7z.exe (100%) rename Diff.cs => paradox-mod-merger/Diff.cs (100%) rename Localisation.cs => paradox-mod-merger/Localisation.cs (100%) rename Merge.cs => paradox-mod-merger/Merge.cs (100%) rename Program.cs => paradox-mod-merger/Program.cs (100%) rename Workshop.cs => paradox-mod-merger/Workshop.cs (100%) rename paradox-mod-merger.csproj => paradox-mod-merger/paradox-mod-merger.csproj (68%) delete mode 100644 paradox-rus-localisation-gen.csproj diff --git a/diff-text/Program.cs b/diff-text/Program.cs new file mode 100644 index 0000000..4584952 --- /dev/null +++ b/diff-text/Program.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DiffMatchPatch; +using DTLib.Filesystem; + +Console.InputEncoding=Encoding.UTF8; +Console.OutputEncoding=Encoding.UTF8; + +if (args.Length != 2) +{ + Console.WriteLine("usage: [file0] [file1]"); + return; +} + +var _diff=FileDiff(args[0], args[1]); +PrintDiff(_diff); + + +List FileDiff(string file0, string file1) +{ + string fileText0 = File.ReadAllText(file0); + string fileText1 = File.ReadAllText(file1); + return TextDiff(fileText0, fileText1); +} + +List TextDiff(string text0, string text1) +{ + var diff = Diff.Compute(text0, text1, checklines:true); + diff.CleanupSemantic(); + return diff; +} + +void PrintDiff(List diff, bool ignoreWhitespaces=false) +{ + foreach (var d in diff) + { + bool whitespaceOnly = d.WhitespaceOnlyDiff; + if(ignoreWhitespaces && whitespaceOnly) + continue; + + switch(d.Operation) + { + case Operation.Delete: + Console.BackgroundColor = ConsoleColor.DarkRed; + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(whitespaceOnly ? d.FormattedText : d.Text); + Console.ResetColor(); + break; + case Operation.Insert: + Console.BackgroundColor = ConsoleColor.DarkGreen; + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(whitespaceOnly ? d.FormattedText : d.Text); + Console.ResetColor(); + break; + case Operation.Equal: + Console.Write(d.Text); + break; + default: + throw new ArgumentOutOfRangeException(d.Operation.ToString()); + } + } +} \ No newline at end of file diff --git a/diff-text/diff-text.csproj b/diff-text/diff-text.csproj new file mode 100644 index 0000000..1ad72ac --- /dev/null +++ b/diff-text/diff-text.csproj @@ -0,0 +1,20 @@ + + + + Exe + net7.0 + diff_text + disable + enable + + + + + + + + + + + + diff --git a/paradox-mod-merger.sln b/paradox-mod-merger.sln index 2fa85db..f10838b 100644 --- a/paradox-mod-merger.sln +++ b/paradox-mod-merger.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30907.101 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "paradox-mod-merger", "paradox-mod-merger.csproj", "{076BFCFF-1D3E-44FB-B434-73716B79A135}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "paradox-mod-merger", "paradox-mod-merger\paradox-mod-merger.csproj", "{076BFCFF-1D3E-44FB-B434-73716B79A135}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution_files", "solution_files", "{8B5F0B90-06A8-48B6-897A-19A0A3474F51}" ProjectSection(SolutionItems) = preProject @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution_files", "solution_ 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}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Release|Any CPU = Release|Any CPU @@ -27,6 +29,10 @@ Global {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/7z/7-zip.dll b/paradox-mod-merger/7z/7-zip.dll similarity index 100% rename from 7z/7-zip.dll rename to paradox-mod-merger/7z/7-zip.dll diff --git a/7z/7-zip32.dll b/paradox-mod-merger/7z/7-zip32.dll similarity index 100% rename from 7z/7-zip32.dll rename to paradox-mod-merger/7z/7-zip32.dll diff --git a/7z/7z.dll b/paradox-mod-merger/7z/7z.dll similarity index 100% rename from 7z/7z.dll rename to paradox-mod-merger/7z/7z.dll diff --git a/7z/7z.exe b/paradox-mod-merger/7z/7z.exe similarity index 100% rename from 7z/7z.exe rename to paradox-mod-merger/7z/7z.exe diff --git a/Diff.cs b/paradox-mod-merger/Diff.cs similarity index 100% rename from Diff.cs rename to paradox-mod-merger/Diff.cs diff --git a/Localisation.cs b/paradox-mod-merger/Localisation.cs similarity index 100% rename from Localisation.cs rename to paradox-mod-merger/Localisation.cs diff --git a/Merge.cs b/paradox-mod-merger/Merge.cs similarity index 100% rename from Merge.cs rename to paradox-mod-merger/Merge.cs diff --git a/Program.cs b/paradox-mod-merger/Program.cs similarity index 100% rename from Program.cs rename to paradox-mod-merger/Program.cs diff --git a/Workshop.cs b/paradox-mod-merger/Workshop.cs similarity index 100% rename from Workshop.cs rename to paradox-mod-merger/Workshop.cs diff --git a/paradox-mod-merger.csproj b/paradox-mod-merger/paradox-mod-merger.csproj similarity index 68% rename from paradox-mod-merger.csproj rename to paradox-mod-merger/paradox-mod-merger.csproj index 57fda96..5a1c6ec 100644 --- a/paradox-mod-merger.csproj +++ b/paradox-mod-merger/paradox-mod-merger.csproj @@ -8,15 +8,16 @@ 10 - - PreserveNewest - + - + + + + \ No newline at end of file diff --git a/paradox-rus-localisation-gen.csproj b/paradox-rus-localisation-gen.csproj deleted file mode 100644 index 8ad7c2f..0000000 --- a/paradox-rus-localisation-gen.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - - - Build - AnyCPU - {839133EF-6481-498A-B70D-878404BB78A4} - Exe - v4.8 - 10 - - - AnyCPU - none - true - bin\ - TRACE - prompt - 4 - - - - - - - - - - - - \ No newline at end of file