diff-text
This commit is contained in:
parent
971896cacb
commit
9c27744b61
63
diff-text/Program.cs
Normal file
63
diff-text/Program.cs
Normal file
@ -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<Diff> FileDiff(string file0, string file1)
|
||||
{
|
||||
string fileText0 = File.ReadAllText(file0);
|
||||
string fileText1 = File.ReadAllText(file1);
|
||||
return TextDiff(fileText0, fileText1);
|
||||
}
|
||||
|
||||
List<Diff> TextDiff(string text0, string text1)
|
||||
{
|
||||
var diff = Diff.Compute(text0, text1, checklines:true);
|
||||
diff.CleanupSemantic();
|
||||
return diff;
|
||||
}
|
||||
|
||||
void PrintDiff(List<Diff> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
20
diff-text/diff-text.csproj
Normal file
20
diff-text/diff-text.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>diff_text</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="google-diff-match-patch" Version="1.3.70" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -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
|
||||
|
||||
@ -8,15 +8,16 @@
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="7z\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="7z\**" CopyToOutputDirectory="PreserveNewest"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.2" />
|
||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
||||
<ProjectReference Include="..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Build</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{839133EF-6481-498A-B70D-878404BB78A4}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Build|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ParadoxRusLocalisationGen.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user