From 5a35502e5ba6aa8f4d45654734ed24bb5ef43376 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 26 Jun 2024 09:23:09 +0700 Subject: [PATCH 1/5] Add MkFwData program --- src/MkFwData/.editorconfig | 27 ++++++++++++++ src/MkFwData/.gitattributes | 1 + src/MkFwData/MkFwData.csproj | 28 ++++++++++++++ src/MkFwData/Program.cs | 72 ++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/MkFwData/.editorconfig create mode 100644 src/MkFwData/.gitattributes create mode 100644 src/MkFwData/MkFwData.csproj create mode 100644 src/MkFwData/Program.cs diff --git a/src/MkFwData/.editorconfig b/src/MkFwData/.editorconfig new file mode 100644 index 00000000..d4047b80 --- /dev/null +++ b/src/MkFwData/.editorconfig @@ -0,0 +1,27 @@ +# Copyright (c) 2016-2021 SIL International +# This software is licensed under the MIT license (http://opensource.org/licenses/MIT) + +root = false + +# Defaults +[*] +indent_style = space +indent_size = tab +tab_width = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 98 + +[*.cs] +indent_style = space +tab_width = 4 + +# Settings Visual Studio uses for the generated files +[*.{csproj,resx,settings,targets,vcxproj*,vdproj,xml,yml,props,md}] +indent_style = space +indent_size = 2 + +# Generated file +[*.sln] +end_of_line = crlf diff --git a/src/MkFwData/.gitattributes b/src/MkFwData/.gitattributes new file mode 100644 index 00000000..cf3363d0 --- /dev/null +++ b/src/MkFwData/.gitattributes @@ -0,0 +1 @@ +* text=auto whitespace=space-before-tab,tab-in-indent,blank-at-eol,tabwidth=4 diff --git a/src/MkFwData/MkFwData.csproj b/src/MkFwData/MkFwData.csproj new file mode 100644 index 00000000..e1e5cf02 --- /dev/null +++ b/src/MkFwData/MkFwData.csproj @@ -0,0 +1,28 @@ + + + + Exe + net8.0 + net8.0 + enable + enable + true + $(MSBuildProjectDirectory) + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MkFwData/Program.cs b/src/MkFwData/Program.cs new file mode 100644 index 00000000..dae97645 --- /dev/null +++ b/src/MkFwData/Program.cs @@ -0,0 +1,72 @@ +using Chorus.VcsDrivers.Mercurial; +using SIL.Progress; +using System.CommandLine; + +class Program +{ + static async Task Main(string[] args) + { + var rootCommand = new RootCommand("Make .fwdata file"); + + var verboseOption = new Option( + ["--verbose", "-v"], + "Display verbose output" + ); + rootCommand.AddGlobalOption(verboseOption); + + var quietOption = new Option( + ["--quiet", "-q"], + "Suppress all output (overrides --verbose if present)" + ); + rootCommand.AddGlobalOption(quietOption); + + var file = new Argument( + "file", + "Name of .fwdata file to create" + ); + rootCommand.Add(file); + + var hgRevOption = new Option( + ["--rev", "-r"], + "Revision to check out (default \"tip\")" + ); + hgRevOption.SetDefaultValue("tip"); + rootCommand.Add(hgRevOption); + + var cleanupOption = new Option( + ["--cleanup", "-c"], + "Clean repository after creating .fwdata file (deletes every other file except .fwdata)" + ); + rootCommand.Add(cleanupOption); + + rootCommand.SetHandler(Run, file, verboseOption, quietOption, hgRevOption, cleanupOption); + + return await rootCommand.InvokeAsync(args); + } + + static Task Run(FileSystemInfo file, bool verbose, bool quiet, string rev, bool cleanup) + { + IProgress progress = quiet ? new NullProgress() : new ConsoleProgress(); + progress.ShowVerbose = verbose; + bool isDir = file.Exists && (file.Attributes & FileAttributes.Directory) != 0; + string name = isDir ? Path.Join(file.FullName, file.Name + ".fwdata") : file.FullName; + string dir = isDir ? file.FullName : new FileInfo(file.FullName).Directory!.FullName; + progress.WriteMessage("Checking out {0}", rev); + var result = HgRunner.Run($"hg checkout {rev}", dir, 30, progress); + if (result.ExitCode != 0) + { + progress.WriteMessage("Could not find Mercurial repo; please check filename"); + return Task.FromResult(result.ExitCode); + } + progress.WriteVerbose("Creating {0} ...", name); + LfMergeBridge.LfMergeBridge.ReassembleFwdataFile(progress, writeVerbose: true, name); + progress.WriteMessage("Created {0}", name); + if (cleanup) + { + progress.WriteVerbose("Cleaning up..."); + HgRunner.Run($"hg checkout null", dir, 30, progress); + HgRunner.Run($"hg purge --no-confirm --exclude *.fwdata --exclude hgRunner.log", dir, 30, progress); + } + return Task.FromResult(0); + } +} From f7faddf9bcb859708a26bd098280bb86b8ffa88c Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 26 Jun 2024 12:47:40 +0700 Subject: [PATCH 2/5] Add SplitFwData program --- src/SplitFwData/.editorconfig | 27 ++++++++++++++ src/SplitFwData/.gitattributes | 1 + src/SplitFwData/Program.cs | 58 ++++++++++++++++++++++++++++++ src/SplitFwData/SplitFwData.csproj | 28 +++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/SplitFwData/.editorconfig create mode 100644 src/SplitFwData/.gitattributes create mode 100644 src/SplitFwData/Program.cs create mode 100644 src/SplitFwData/SplitFwData.csproj diff --git a/src/SplitFwData/.editorconfig b/src/SplitFwData/.editorconfig new file mode 100644 index 00000000..d4047b80 --- /dev/null +++ b/src/SplitFwData/.editorconfig @@ -0,0 +1,27 @@ +# Copyright (c) 2016-2021 SIL International +# This software is licensed under the MIT license (http://opensource.org/licenses/MIT) + +root = false + +# Defaults +[*] +indent_style = space +indent_size = tab +tab_width = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 98 + +[*.cs] +indent_style = space +tab_width = 4 + +# Settings Visual Studio uses for the generated files +[*.{csproj,resx,settings,targets,vcxproj*,vdproj,xml,yml,props,md}] +indent_style = space +indent_size = 2 + +# Generated file +[*.sln] +end_of_line = crlf diff --git a/src/SplitFwData/.gitattributes b/src/SplitFwData/.gitattributes new file mode 100644 index 00000000..cf3363d0 --- /dev/null +++ b/src/SplitFwData/.gitattributes @@ -0,0 +1 @@ +* text=auto whitespace=space-before-tab,tab-in-indent,blank-at-eol,tabwidth=4 diff --git a/src/SplitFwData/Program.cs b/src/SplitFwData/Program.cs new file mode 100644 index 00000000..1792cef1 --- /dev/null +++ b/src/SplitFwData/Program.cs @@ -0,0 +1,58 @@ +using Chorus.VcsDrivers.Mercurial; +using SIL.Progress; +using System.CommandLine; + +class Program +{ + static async Task Main(string[] args) + { + var rootCommand = new RootCommand("Make .fwdata file"); + + var verboseOption = new Option( + ["--verbose", "-v"], + "Display verbose output" + ); + rootCommand.AddGlobalOption(verboseOption); + + var quietOption = new Option( + ["--quiet", "-q"], + "Suppress all output (overrides --verbose if present)" + ); + rootCommand.AddGlobalOption(quietOption); + + var file = new Argument( + "file", + "Name of .fwdata file to split" + ); + rootCommand.Add(file); + + var cleanupOption = new Option( + ["--cleanup", "-c"], + "Delete .fwdata file after splitting" + ); + rootCommand.Add(cleanupOption); + + rootCommand.SetHandler(Run, file, verboseOption, quietOption, cleanupOption); + + return await rootCommand.InvokeAsync(args); + } + + static Task Run(FileSystemInfo file, bool verbose, bool quiet, bool cleanup) + { + IProgress progress = quiet ? new NullProgress() : new ConsoleProgress(); + progress.ShowVerbose = verbose; + bool isDir = file.Exists && (file.Attributes & FileAttributes.Directory) != 0; + string name = isDir ? Path.Join(file.FullName, file.Name + ".fwdata") : file.FullName; + string dir = isDir ? file.FullName : new FileInfo(file.FullName).Directory!.FullName; + progress.WriteVerbose("Splitting {0} ...", name); + LfMergeBridge.LfMergeBridge.DisassembleFwdataFile(progress, writeVerbose: true, name); + progress.WriteMessage("Finished splitting {0}", name); + if (cleanup) + { + progress.WriteVerbose("Cleaning up..."); + var fwdataFile = new FileInfo(name); + if (fwdataFile.Exists) { fwdataFile.Delete(); progress.WriteVerbose("Deleted {0}", fwdataFile.FullName); } else { progress.WriteVerbose("File not found, so not deleting: {0}", fwdataFile.FullName); } + } + return Task.FromResult(0); + } +} diff --git a/src/SplitFwData/SplitFwData.csproj b/src/SplitFwData/SplitFwData.csproj new file mode 100644 index 00000000..e1e5cf02 --- /dev/null +++ b/src/SplitFwData/SplitFwData.csproj @@ -0,0 +1,28 @@ + + + + Exe + net8.0 + net8.0 + enable + enable + true + $(MSBuildProjectDirectory) + + + + + + + + + + + + + + + + + + \ No newline at end of file From f96c444857b91a08c68327bda81c6bea6100d24c Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 26 Jun 2024 14:17:10 +0700 Subject: [PATCH 3/5] Add MkFwData and SplitFwData to .sln file --- FLExBridge.sln | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/FLExBridge.sln b/FLExBridge.sln index 78a2e43e..daa6e8a1 100644 --- a/FLExBridge.sln +++ b/FLExBridge.sln @@ -52,6 +52,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LfMergeBridgeTestApp", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LfMergeBridgeTests", "src\LfMergeBridgeTests\LfMergeBridgeTests.csproj", "{6CB1246D-956A-4759-AA13-D434CBB383FE}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MkFwData", "src\MkFwData\MkFwData.csproj", "{5CDB086A-79DE-4EF4-BB48-4AEAEEB0827B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SplitFwData", "src\SplitFwData\SplitFwData.csproj", "{23DF39D2-5C50-4832-A64E-022396430390}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiftFileCheckerApp", "src\LiftFileCheckerApp\LiftFileCheckerApp.csproj", "{30AA046B-5E14-408C-89EF-8601BB27FB32}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibTriboroughBridge-ChorusPluginTests", "src\LibTriboroughBridge-ChorusPluginTests\LibTriboroughBridge-ChorusPluginTests.csproj", "{AA6CC4E2-6FD8-4B30-99EC-A446E9CAA176}" @@ -124,6 +128,14 @@ Global {6CB1246D-956A-4759-AA13-D434CBB383FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {6CB1246D-956A-4759-AA13-D434CBB383FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {6CB1246D-956A-4759-AA13-D434CBB383FE}.Release|Any CPU.Build.0 = Release|Any CPU + {5CDB086A-79DE-4EF4-BB48-4AEAEEB0827B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CDB086A-79DE-4EF4-BB48-4AEAEEB0827B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CDB086A-79DE-4EF4-BB48-4AEAEEB0827B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CDB086A-79DE-4EF4-BB48-4AEAEEB0827B}.Release|Any CPU.Build.0 = Release|Any CPU + {23DF39D2-5C50-4832-A64E-022396430390}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23DF39D2-5C50-4832-A64E-022396430390}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23DF39D2-5C50-4832-A64E-022396430390}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23DF39D2-5C50-4832-A64E-022396430390}.Release|Any CPU.Build.0 = Release|Any CPU {30AA046B-5E14-408C-89EF-8601BB27FB32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {30AA046B-5E14-408C-89EF-8601BB27FB32}.Debug|Any CPU.Build.0 = Debug|Any CPU {30AA046B-5E14-408C-89EF-8601BB27FB32}.Release|Any CPU.ActiveCfg = Release|Any CPU From a108422f0167d1d54804d1ee23a821f37dcd28c3 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 26 Jun 2024 16:08:48 +0700 Subject: [PATCH 4/5] Better handling of .fwdata filenames --- src/MkFwData/Program.cs | 47 ++++++++++++++++++++++++++++---------- src/SplitFwData/Program.cs | 32 ++++++++++++++++++++------ 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/MkFwData/Program.cs b/src/MkFwData/Program.cs index dae97645..b7203743 100644 --- a/src/MkFwData/Program.cs +++ b/src/MkFwData/Program.cs @@ -20,11 +20,11 @@ static async Task Main(string[] args) ); rootCommand.AddGlobalOption(quietOption); - var file = new Argument( + var filename = new Argument( "file", - "Name of .fwdata file to create" + "Name of .fwdata file to create, or directory to create it in" ); - rootCommand.Add(file); + rootCommand.Add(filename); var hgRevOption = new Option( ["--rev", "-r"], @@ -39,23 +39,46 @@ static async Task Main(string[] args) ); rootCommand.Add(cleanupOption); - rootCommand.SetHandler(Run, file, verboseOption, quietOption, hgRevOption, cleanupOption); + rootCommand.SetHandler(Run, filename, verboseOption, quietOption, hgRevOption, cleanupOption); return await rootCommand.InvokeAsync(args); } - static Task Run(FileSystemInfo file, bool verbose, bool quiet, string rev, bool cleanup) + static FileInfo LocateFwDataFile(string input) + { + if (Directory.Exists(input)) { + var dirInfo = new DirectoryInfo(input); + var fname = dirInfo.Name + ".fwdata"; + return new FileInfo(Path.Join(input, fname)); + } else if (File.Exists(input)) { + return new FileInfo(input); + } else if (File.Exists(input + ".fwdata")) { + return new FileInfo(input + ".fwdata"); + } else { + if (input.EndsWith(".fwdata")) return new FileInfo(input); + return new FileInfo(input + ".fwdata"); + } + } + + static Task Run(string filename, bool verbose, bool quiet, string rev, bool cleanup) { IProgress progress = quiet ? new NullProgress() : new ConsoleProgress(); progress.ShowVerbose = verbose; - bool isDir = file.Exists && (file.Attributes & FileAttributes.Directory) != 0; - string name = isDir ? Path.Join(file.FullName, file.Name + ".fwdata") : file.FullName; - string dir = isDir ? file.FullName : new FileInfo(file.FullName).Directory!.FullName; + var file = LocateFwDataFile(filename); + if (file.Exists) { + progress.WriteWarning("File {0} already exists and will be overwritten", file.FullName); + } + var dir = file.Directory; + if (dir == null || !dir.Exists) { + progress.WriteError("Could not find directory {0}. MkFwData needs a Mercurial repo to work with.", dir?.FullName ?? "(null)"); + return Task.FromResult(1); + } + string name = file.FullName; progress.WriteMessage("Checking out {0}", rev); - var result = HgRunner.Run($"hg checkout {rev}", dir, 30, progress); + var result = HgRunner.Run($"hg checkout {rev}", dir.FullName, 30, progress); if (result.ExitCode != 0) { - progress.WriteMessage("Could not find Mercurial repo; please check filename"); + progress.WriteMessage("Could not find Mercurial repo in directory {0}. MkFwData needs a Mercurial repo to work with.", dir.FullName ?? "(null)"); return Task.FromResult(result.ExitCode); } progress.WriteVerbose("Creating {0} ...", name); @@ -64,8 +87,8 @@ static Task Run(FileSystemInfo file, bool verbose, bool quiet, string rev, if (cleanup) { progress.WriteVerbose("Cleaning up..."); - HgRunner.Run($"hg checkout null", dir, 30, progress); - HgRunner.Run($"hg purge --no-confirm --exclude *.fwdata --exclude hgRunner.log", dir, 30, progress); + HgRunner.Run($"hg checkout null", dir.FullName, 30, progress); + HgRunner.Run($"hg purge --no-confirm --exclude *.fwdata --exclude hgRunner.log", dir.FullName, 30, progress); } return Task.FromResult(0); } diff --git a/src/SplitFwData/Program.cs b/src/SplitFwData/Program.cs index 1792cef1..110a6f09 100644 --- a/src/SplitFwData/Program.cs +++ b/src/SplitFwData/Program.cs @@ -20,11 +20,11 @@ static async Task Main(string[] args) ); rootCommand.AddGlobalOption(quietOption); - var file = new Argument( + var filename = new Argument( "file", "Name of .fwdata file to split" ); - rootCommand.Add(file); + rootCommand.Add(filename); var cleanupOption = new Option( ["--cleanup", "-c"], @@ -32,18 +32,36 @@ static async Task Main(string[] args) ); rootCommand.Add(cleanupOption); - rootCommand.SetHandler(Run, file, verboseOption, quietOption, cleanupOption); + rootCommand.SetHandler(Run, filename, verboseOption, quietOption, cleanupOption); return await rootCommand.InvokeAsync(args); } - static Task Run(FileSystemInfo file, bool verbose, bool quiet, bool cleanup) + static FileInfo? LocateFwDataFile(string input) + { + if (Directory.Exists(input)) { + var dirInfo = new DirectoryInfo(input); + var fname = dirInfo.Name + ".fwdata"; + return new FileInfo(Path.Join(input, fname)); + } else if (File.Exists(input)) { + return new FileInfo(input); + } else if (File.Exists(input + ".fwdata")) { + return new FileInfo(input + ".fwdata"); + } else { + return null; + } + } + + static Task Run(string filename, bool verbose, bool quiet, bool cleanup) { IProgress progress = quiet ? new NullProgress() : new ConsoleProgress(); progress.ShowVerbose = verbose; - bool isDir = file.Exists && (file.Attributes & FileAttributes.Directory) != 0; - string name = isDir ? Path.Join(file.FullName, file.Name + ".fwdata") : file.FullName; - string dir = isDir ? file.FullName : new FileInfo(file.FullName).Directory!.FullName; + var file = LocateFwDataFile(filename); + if (file == null || !file.Exists) { + progress.WriteError("Could not find {0}", filename); + return Task.FromResult(1); + } + string name = file.FullName; progress.WriteVerbose("Splitting {0} ...", name); LfMergeBridge.LfMergeBridge.DisassembleFwdataFile(progress, writeVerbose: true, name); progress.WriteMessage("Finished splitting {0}", name); From 320794c37c1b4d8dfd1eac3aa6710677145e5e5e Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Fri, 28 Jun 2024 15:25:19 +0700 Subject: [PATCH 5/5] Bump AppVeyor build to use VS 2022 That should allow it to build .NET 8 targets. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 7ad3c8e8..fb054a7f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: '{build}' branches: only: - develop -image: Visual Studio 2019 +image: Visual Studio 2022 init: - cmd: | set GITVERSION_BUILD_NUMBER=%APPVEYOR_BUILD_NUMBER%