Skip to content

Commit

Permalink
Add ordered options by updating MatthiWare.CommandLineParser to v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthiee committed Oct 24, 2020
1 parent 6986728 commit 6110c57
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,34 @@ Original repo [Metric/VCDiff](https://github.com/Metric/VCDiff)

## Requirements
- .NET Standard 2.0+ _(code)_
- .NET Core 2.1 _(CLI)_
- .NET Core 3.1 _(CLI)_

# CLI

Using the CLI for creating delta patches and applying delta

### Create delta patch

`dotnet .\VCDiff.Core.Cli create -o .\original.exe -n .\updated.exe -d .\delta -b 8`
To encode/create delta patch you need to specify `create -o [original] -n [updated] -d [output] -b [window size]`.

or
`dotnet .\VCDiff.Core.Cli create .\original.exe .\updated.exe .\delta -b 8`

`dotnet .\VCDiff.Core.Cli create --old .\original.exe --new .\updated.exe --delta .\delta --buffer 8`
`dotnet .\VCDiff.Core.Cli create -o .\original.exe -n .\updated.exe -d .\delta -b 8`

To encode/create delta patch you need to specify `create -o [original] -n [updated] -d [output] -b [window size]`.
`dotnet .\VCDiff.Core.Cli create --old .\original.exe --new .\updated.exe --delta .\delta --buffer 8`

_[Window size]: The maximum buffer size for window chunking (in megabytes)._

### Apply delta patch

`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe`
To apply delta patch you need to specify `patch [original] [delta] [output]`.

or
`dotnet .\VCDiff.Core.Cli patch .\original.exe .\delta .\updated.exe`

`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe`

`dotnet .\VCDiff.Core.Cli patch --old .\original.exe --delta .\delta --new .\updated.exe`

To apply delta patch you need to specify `apply -o [original] -d [delta] -o [output]`.

### Verify hashes in PowerShell

Expand Down
6 changes: 3 additions & 3 deletions VCDiff.Core.Cli/Options/CreateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace MatthiWare.Compression.VCDiff.Cli.Options
{
public class CreateOptions
{
[Required, Name("o", "old"), Description("Path to the old version of the file")]
[Required, Name("o", "old"), OptionOrder(1), Description("Path to the old version of the file")]
public string OldFile { get; set; }

[Required, Name("n", "new"), Description("Path to the new version of the file")]
[Required, Name("n", "new"), OptionOrder(2), Description("Path to the new version of the file")]
public string NewFile { get; set; }

[Required, Name("d", "delta"), Description("Output path of the delta patch file")]
[Required, Name("d", "delta"), OptionOrder(2), Description("Output path of the delta patch file")]
public string DeltaFile { get; set; }

[Name("b", "buffer"), Description("Optional buffer size to use"), DefaultValue(1)]
Expand Down
10 changes: 5 additions & 5 deletions VCDiff.Core.Cli/Options/PatchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace MatthiWare.Compression.VCDiff.Cli.Options
{
public class PatchOptions
{
[Required, Name("o", "old"), Description("Path to the old version of the file")]
[Required, Name("o", "old"), OptionOrder(1), Description("Path to the old version of the file")]
public string OldFile { get; set; }

[Required, Name("n", "new"), Description("Output path of the patched file")]
public string NewFile { get; set; }

[Required, Name("d", "delta"), Description("Path of the delta patch file")]
[Required, Name("d", "delta"), OptionOrder(2), Description("Path of the delta patch file")]
public string DeltaFile { get; set; }

[Required, Name("n", "new"), OptionOrder(3), Description("Output path of the patched file")]
public string NewFile { get; set; }
}
}
17 changes: 12 additions & 5 deletions VCDiff.Core.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MatthiWare.Compression.VCDiff.Includes;
using System;
using System.IO;
using System.Linq;

namespace MatthiWare.Compression.VCDiff.Cli
{
Expand Down Expand Up @@ -36,24 +37,24 @@ static int Main(string[] args)
var parserResult = parser.Parse(args);

if (parserResult.HasErrors && !parserResult.HelpRequested)
{
result = VCDiffResult.Error;
}

switch (result)
{
case VCDiffResult.NOOP:
parser.Printer.PrintUsage();
break;
case VCDiffResult.Succes:
default:
break;
case VCDiffResult.Error:
Console.Error.WriteLine("Unexpected error occured");

return -1;
case VCDiffResult.EOD:
Console.Error.WriteLine("Unexpected end of data");

return -2;
case VCDiffResult.Succes:
default:
break;
}

return 0;
Expand All @@ -64,15 +65,19 @@ private static VCDiffResult Patch(PatchOptions opt)
using (var sold = File.OpenRead(opt.OldFile)) // old file
using (var snew = File.OpenRead(opt.DeltaFile)) // delta file
using (var sout = File.OpenWrite(opt.NewFile)) // out file
{
return Decode(sold, snew, sout);
}
}

private static VCDiffResult Create(CreateOptions opt)
{
using (var sold = File.OpenRead(opt.OldFile)) // old file
using (var snew = File.OpenRead(opt.NewFile)) // new file
using (var sout = File.OpenWrite(opt.DeltaFile)) // delta file
{
return Encode(sold, snew, sout, opt.BufferSize);
}
}

private static VCDiffResult Encode(Stream sold, Stream snew, Stream sout, int bufferSize)
Expand All @@ -89,7 +94,9 @@ private static VCDiffResult Decode(Stream sold, Stream sdelta, Stream sout)
var result = decoder.Start();

if (result != VCDiffResult.Succes)
{
return result;
}

return decoder.Decode(out _);
}
Expand Down
4 changes: 2 additions & 2 deletions VCDiff.Core.Cli/VCDiff.Core.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Company>MatthiWare</Company>
<Authors>Matthias Beerens</Authors>
<Version>0.1.0</Version>
Expand All @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MatthiWare.CommandLineParser" Version="0.2.4" />
<PackageReference Include="MatthiWare.CommandLineParser" Version="0.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 6110c57

Please sign in to comment.