Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command-line tools to split and/or reassemble .fwdata files #403

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions FLExBridge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down
27 changes: 27 additions & 0 deletions src/MkFwData/.editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/MkFwData/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto whitespace=space-before-tab,tab-in-indent,blank-at-eol,tabwidth=4
28 changes: 28 additions & 0 deletions src/MkFwData/MkFwData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<Mercurial4ChorusDestDir>$(MSBuildProjectDirectory)</Mercurial4ChorusDestDir>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LfMergeBridge\LfMergeBridge.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="SIL.Chorus.LibChorus" Version="$(ChorusVersion)" />
<PackageReference Include="SIL.Chorus.Mercurial" Version="6.*" />
</ItemGroup>

<ItemGroup>
<Content Include="Mercurial\**" CopyToOutputDirectory="Always" />
<Content Include="MercurialExtensions\**" CopyToOutputDirectory="Always" />
</ItemGroup>

</Project>
95 changes: 95 additions & 0 deletions src/MkFwData/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Chorus.VcsDrivers.Mercurial;
using SIL.Progress;
using System.CommandLine;

class Program
{
static async Task<int> Main(string[] args)
{
var rootCommand = new RootCommand("Make .fwdata file");

var verboseOption = new Option<bool>(
["--verbose", "-v"],
"Display verbose output"
);
rootCommand.AddGlobalOption(verboseOption);

var quietOption = new Option<bool>(
["--quiet", "-q"],
"Suppress all output (overrides --verbose if present)"
);
rootCommand.AddGlobalOption(quietOption);

var filename = new Argument<string>(
"file",
"Name of .fwdata file to create, or directory to create it in"
);
rootCommand.Add(filename);

var hgRevOption = new Option<string>(
["--rev", "-r"],
"Revision to check out (default \"tip\")"
);
hgRevOption.SetDefaultValue("tip");
rootCommand.Add(hgRevOption);

var cleanupOption = new Option<bool>(
["--cleanup", "-c"],
"Clean repository after creating .fwdata file (deletes every other file except .fwdata)"
);
rootCommand.Add(cleanupOption);

rootCommand.SetHandler(Run, filename, verboseOption, quietOption, hgRevOption, cleanupOption);

return await rootCommand.InvokeAsync(args);
}

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<int> Run(string filename, bool verbose, bool quiet, string rev, bool cleanup)
{
IProgress progress = quiet ? new NullProgress() : new ConsoleProgress();
progress.ShowVerbose = verbose;
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.FullName, 30, progress);
if (result.ExitCode != 0)
{
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);
LfMergeBridge.LfMergeBridge.ReassembleFwdataFile(progress, writeVerbose: true, name);
progress.WriteMessage("Created {0}", name);
if (cleanup)
{
progress.WriteVerbose("Cleaning up...");
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);
}
}
27 changes: 27 additions & 0 deletions src/SplitFwData/.editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/SplitFwData/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto whitespace=space-before-tab,tab-in-indent,blank-at-eol,tabwidth=4
76 changes: 76 additions & 0 deletions src/SplitFwData/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Chorus.VcsDrivers.Mercurial;
using SIL.Progress;
using System.CommandLine;

class Program
{
static async Task<int> Main(string[] args)
{
var rootCommand = new RootCommand("Make .fwdata file");

var verboseOption = new Option<bool>(
["--verbose", "-v"],
"Display verbose output"
);
rootCommand.AddGlobalOption(verboseOption);

var quietOption = new Option<bool>(
["--quiet", "-q"],
"Suppress all output (overrides --verbose if present)"
);
rootCommand.AddGlobalOption(quietOption);

var filename = new Argument<string>(
"file",
"Name of .fwdata file to split"
);
rootCommand.Add(filename);

var cleanupOption = new Option<bool>(
["--cleanup", "-c"],
"Delete .fwdata file after splitting"
);
rootCommand.Add(cleanupOption);

rootCommand.SetHandler(Run, filename, verboseOption, quietOption, cleanupOption);

return await rootCommand.InvokeAsync(args);
}

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<int> Run(string filename, bool verbose, bool quiet, bool cleanup)
{
IProgress progress = quiet ? new NullProgress() : new ConsoleProgress();
progress.ShowVerbose = verbose;
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);
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);
}
}
28 changes: 28 additions & 0 deletions src/SplitFwData/SplitFwData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<Mercurial4ChorusDestDir>$(MSBuildProjectDirectory)</Mercurial4ChorusDestDir>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LfMergeBridge\LfMergeBridge.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="SIL.Chorus.LibChorus" Version="$(ChorusVersion)" />
<PackageReference Include="SIL.Chorus.Mercurial" Version="6.*" />
</ItemGroup>

<ItemGroup>
<Content Include="Mercurial\**" CopyToOutputDirectory="Always" />
<Content Include="MercurialExtensions\**" CopyToOutputDirectory="Always" />
</ItemGroup>

</Project>