diff --git a/README.md b/README.md index 599eed1..ea49891 100644 --- a/README.md +++ b/README.md @@ -25,25 +25,33 @@ Using the CLI for creating delta patches and applying delta ### Create delta patch -`dotnet .\VCDiff.Core.Cli.dll -e .\original.exe .\updated.exe .\delta 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 `-e [original] [updated] [output] [window size]`. +or + +`dotnet .\VCDiff.Core.Cli create --old .\original.exe --new .\updated.exe --delta .\delta --buffer 8` + +To encode/create delta patch you need to specify `create -o [original] -n [updated] -d [output] -b [window size]`. _[Window size]: The maximum buffer size for window chunking (in megabytes)._ ### Apply delta patch -`dotnet .\VCDiff.Core.Cli.dll -d .\original.exe .\delta .\updated.exe` +`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe` + +or + +`dotnet .\VCDiff.Core.Cli patch --old .\original.exe --delta .\delta --new .\updated.exe` -To apply delta patch you need to specify `-d [original] [delta] [output]`. +To apply delta patch you need to specify `apply -o [original] -d [delta] -o [output]`. ### Verify hashes in PowerShell -- Encode -`dotnet .\VCDiff.Core.Cli.dll -e .\original.exe .\updated.exe .\delta 8` +- Encode/Create patch +`dotnet .\VCDiff.Core.Cli create -o .\original.exe -n .\updated.exe -d .\delta -b 8` -- Decode -`dotnet .\VCDiff.Core.Cli.dll -d .\original.exe .\delta .\updated_with_delta.exe` +- Decode/Apply patch +`dotnet .\VCDiff.Core.Cli patch -o .\original.exe -d .\delta -n .\updated.exe` - Verify hash `get-filehash -Path ".\updated.exe", ".\updated_with_delta.exe" -algorithm MD5` diff --git a/VCDiff.Core.Cli/Options/CreateOptions.cs b/VCDiff.Core.Cli/Options/CreateOptions.cs new file mode 100644 index 0000000..f643fc1 --- /dev/null +++ b/VCDiff.Core.Cli/Options/CreateOptions.cs @@ -0,0 +1,19 @@ +using MatthiWare.CommandLine.Core.Attributes; + +namespace MatthiWare.Compression.VCDiff.Cli.Options +{ + public class CreateOptions + { + [Required, Name("o", "old"), 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")] + public string NewFile { get; set; } + + [Required, Name("d", "delta"), Description("Output path of the delta patch file")] + public string DeltaFile { get; set; } + + [Name("b", "buffer"), Description("Optional buffer size to use"), DefaultValue(1)] + public int BufferSize { get; set; } + } +} diff --git a/VCDiff.Core.Cli/Options/PatchOptions.cs b/VCDiff.Core.Cli/Options/PatchOptions.cs new file mode 100644 index 0000000..5ca8926 --- /dev/null +++ b/VCDiff.Core.Cli/Options/PatchOptions.cs @@ -0,0 +1,16 @@ +using MatthiWare.CommandLine.Core.Attributes; + +namespace MatthiWare.Compression.VCDiff.Cli.Options +{ + public class PatchOptions + { + [Required, Name("o", "old"), 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")] + public string DeltaFile { get; set; } + } +} diff --git a/VCDiff.Core.Cli/Options/ProgramOptions.cs b/VCDiff.Core.Cli/Options/ProgramOptions.cs new file mode 100644 index 0000000..08c542b --- /dev/null +++ b/VCDiff.Core.Cli/Options/ProgramOptions.cs @@ -0,0 +1,10 @@ +using MatthiWare.CommandLine.Core.Attributes; + +namespace MatthiWare.Compression.VCDiff.Cli.Options +{ + public class ProgramOptions + { + [Required(false), Name("v", "verbose"), DefaultValue(false), Description("Verbose output")] + public bool Verbose { get; set; } + } +} diff --git a/VCDiff.Core.Cli/Program.cs b/VCDiff.Core.Cli/Program.cs index 83a7fcf..50ff4a2 100644 --- a/VCDiff.Core.Cli/Program.cs +++ b/VCDiff.Core.Cli/Program.cs @@ -1,8 +1,10 @@ -using System; -using System.IO; +using MatthiWare.CommandLine; +using MatthiWare.Compression.VCDiff.Cli.Options; using MatthiWare.Compression.VCDiff.Decoders; using MatthiWare.Compression.VCDiff.Encoders; using MatthiWare.Compression.VCDiff.Includes; +using System; +using System.IO; namespace MatthiWare.Compression.VCDiff.Cli { @@ -10,42 +12,67 @@ class Program { static int Main(string[] args) { - string type = args[0]; // -e -d - var oldPath = args[1]; - var newPath = args[2]; - var outPath = args[3]; + var cliParserOptions = new CommandLineParserOptions + { + AppName = "VCDiff.Core.Cli" + }; - if (type != "-e" && type != "-d") throw new ArgumentException("Invalid parameters, use -e or -d"); + var result = VCDiffResult.NOOP; - var result = VCDiffResult.SUCCESS; + var parser = new CommandLineParser(); - if (type == "-e") - { - var size = int.Parse(args[4]); + parser.AddCommand() + .Name("create") + .Required(false) + .Description("Creates a delta patch from the given input") + .OnExecuting((o, opt) => result = Create(opt)); - using (var sold = File.OpenRead(oldPath)) // old file - using (var snew = File.OpenRead(newPath)) // new file - using (var sout = File.OpenWrite(outPath)) // delta file - result = Encode(sold, snew, sout, size); - } - else if (type == "-d") - { - using (var sold = File.OpenRead(oldPath)) // old file - using (var snew = File.OpenRead(newPath)) // delta file - using (var sout = File.OpenWrite(outPath)) // out file - result = Decode(sold, snew, sout); - } + parser.AddCommand() + .Name("patch") + .Required(false) + .Description("Appplies the give patch to the file") + .OnExecuting((o, opt) => result = Patch(opt)); + + var parserResult = parser.Parse(args); + + if (parserResult.HasErrors && !parserResult.HelpRequested) + result = VCDiffResult.Error; switch (result) { - case VCDiffResult.SUCCESS: + case VCDiffResult.NOOP: + parser.Printer.PrintUsage(); + break; + case VCDiffResult.Succes: default: - return 0; - case VCDiffResult.ERROR: + break; + case VCDiffResult.Error: + Console.Error.WriteLine("Unexpected error occured"); + return -1; case VCDiffResult.EOD: + Console.Error.WriteLine("Unexpected end of data"); + return -2; } + + return 0; + } + + 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) @@ -61,7 +88,7 @@ private static VCDiffResult Decode(Stream sold, Stream sdelta, Stream sout) var result = decoder.Start(); - if (result != VCDiffResult.SUCCESS) + if (result != VCDiffResult.Succes) return result; return decoder.Decode(out _); diff --git a/VCDiff.Core.Cli/Properties/launchSettings.json b/VCDiff.Core.Cli/Properties/launchSettings.json index f69dd1c..9cb8445 100644 --- a/VCDiff.Core.Cli/Properties/launchSettings.json +++ b/VCDiff.Core.Cli/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "VCDiff.Core.Cli": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "create -o blob.bin -n blob_updated.bin -d delta" } } } \ No newline at end of file diff --git a/VCDiff.Core.Cli/VCDiff.Core.Cli.csproj b/VCDiff.Core.Cli/VCDiff.Core.Cli.csproj index 33958c9..04353cf 100644 --- a/VCDiff.Core.Cli/VCDiff.Core.Cli.csproj +++ b/VCDiff.Core.Cli/VCDiff.Core.Cli.csproj @@ -13,8 +13,13 @@ VCDiff delta cli MatthiWare.Compression.VCDiff.Cli + 7.3 + + + + diff --git a/VCDiff.Core.Tests/Integration/IntegrationTests.cs b/VCDiff.Core.Tests/Integration/IntegrationTests.cs index 65dd766..f948604 100644 --- a/VCDiff.Core.Tests/Integration/IntegrationTests.cs +++ b/VCDiff.Core.Tests/Integration/IntegrationTests.cs @@ -1,27 +1,17 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using MatthiWare.Compression.VCDiff.Decoders; +using MatthiWare.Compression.VCDiff.Decoders; using MatthiWare.Compression.VCDiff.Encoders; using MatthiWare.Compression.VCDiff.Includes; -using Xunit; -using Xunit.Abstractions; +using NUnit.Framework; +using System; +using System.IO; namespace VCDiff.Core.Tests.Integration { - + [TestFixture] public class IntegrationTests { - private readonly ITestOutputHelper output; - - public IntegrationTests(ITestOutputHelper output) - { - this.output = output; - } - - [Fact] + [Test] public void TestEncodeAndDecodeShouldBeTheSame() { int size = 20 * 1024 * 1024; // 20 MB @@ -38,9 +28,9 @@ public void TestEncodeAndDecodeShouldBeTheSame() var sDelta = new MemoryStream(new byte[size], true); var coder = new VCCoder(sOld, sNew, sDelta); - Assert.Equal(VCDiffResult.SUCCESS, coder.Encode()); + Assert.AreEqual(VCDiffResult.Succes, coder.Encode()); - output.WriteLine($"Delta is {sDelta.Position / 1024 / 1024} MB's"); + TestContext.Out.WriteLine($"Delta is {sDelta.Position / 1024 / 1024} MB's"); sDelta.SetLength(sDelta.Position); sDelta.Position = 0; @@ -50,15 +40,15 @@ public void TestEncodeAndDecodeShouldBeTheSame() var sPatched = new MemoryStream(new byte[size], true); var decoder = new VCDecoder(sOld, sDelta, sPatched); - Assert.Equal(VCDiffResult.SUCCESS, decoder.Start()); - Assert.Equal(VCDiffResult.SUCCESS, decoder.Decode(out long bytesWritten)); + Assert.AreEqual(VCDiffResult.Succes, decoder.Start()); + Assert.AreEqual(VCDiffResult.Succes, decoder.Decode(out long bytesWritten)); - output.WriteLine($"Written {bytesWritten / 1024 / 1024} MB's"); + TestContext.Out.WriteLine($"Written {bytesWritten / 1024 / 1024} MB's"); - Assert.Equal(sNew.ToArray(), sPatched.ToArray()); + Assert.AreEqual(sNew.ToArray(), sPatched.ToArray()); } - private Random random = new Random(DateTime.Now.GetHashCode()); + private static readonly Random random = new Random(DateTime.Now.GetHashCode()); private byte[] CreateRandomByteArray(int size) { diff --git a/VCDiff.Core.Tests/VCDiff.Core.Tests.csproj b/VCDiff.Core.Tests/VCDiff.Core.Tests.csproj index 65040d5..e921d32 100644 --- a/VCDiff.Core.Tests/VCDiff.Core.Tests.csproj +++ b/VCDiff.Core.Tests/VCDiff.Core.Tests.csproj @@ -4,12 +4,15 @@ netcoreapp2.1 false + + 7.3 - - + + + diff --git a/VCDiff.Core.sln b/VCDiff.Core.sln index 2c0780f..79af3c2 100644 --- a/VCDiff.Core.sln +++ b/VCDiff.Core.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.cake = build.cake build.ps1 = build.ps1 build.sh = build.sh + codecov.yml = codecov.yml LICENSE = LICENSE README.md = README.md EndProjectSection diff --git a/VCDiff.Core/Decoders/BodyDecoder.cs b/VCDiff.Core/Decoders/BodyDecoder.cs index df4f403..00de14b 100644 --- a/VCDiff.Core/Decoders/BodyDecoder.cs +++ b/VCDiff.Core/Decoders/BodyDecoder.cs @@ -32,7 +32,6 @@ public class BodyDecoder : IDisposable private IByteBuffer dict; private IByteBuffer target; private AddressCache addressCache; - private long bytesWritten = 0; private IList targetData; private readonly CustomCodeTableDecoder customTable; @@ -73,7 +72,7 @@ public BodyDecoder(WindowDecoder w, IByteBuffer dictionary, IByteBuffer target, /// public VCDiffResult DecodeInterleave() { - VCDiffResult result = VCDiffResult.SUCCESS; + VCDiffResult result = VCDiffResult.Succes; //since interleave expected then the last point that was most likely decoded was the lengths section //so following is all data for the add run copy etc long interleaveLength = window.InstructionAndSizesLength; @@ -120,7 +119,7 @@ public VCDiffResult DecodeInterleave() break; case VCDiffInstructionType.ERROR: targetData.Clear(); - return VCDiffResult.ERROR; + return VCDiffResult.Error; default: break; } @@ -159,7 +158,7 @@ public VCDiffResult DecodeInterleave() break; default: targetData.Clear(); - return VCDiffResult.ERROR; + return VCDiffResult.Error; } if (result == VCDiffResult.EOD) @@ -194,7 +193,7 @@ public VCDiffResult DecodeInterleave() if (adler != window.Checksum) { - result = VCDiffResult.ERROR; + result = VCDiffResult.Error; } } @@ -214,7 +213,7 @@ public VCDiffResult Decode() InstructionDecoder instrDecoder = new InstructionDecoder(instructionBuffer, customTable); - VCDiffResult result = VCDiffResult.SUCCESS; + VCDiffResult result = VCDiffResult.Succes; while (Decoded < window.DecodedDeltaLength && instructionBuffer.CanRead) { @@ -228,7 +227,7 @@ public VCDiffResult Decode() return VCDiffResult.EOD; case VCDiffInstructionType.ERROR: targetData.Clear(); - return VCDiffResult.ERROR; + return VCDiffResult.Error; default: break; } @@ -246,7 +245,7 @@ public VCDiffResult Decode() break; default: targetData.Clear(); - return VCDiffResult.ERROR; + return VCDiffResult.Error; } } @@ -256,7 +255,7 @@ public VCDiffResult Decode() if (adler != window.Checksum) { - result = VCDiffResult.ERROR; + result = VCDiffResult.Error; } } @@ -271,14 +270,14 @@ VCDiffResult DecodeCopy(int size, byte mode, ByteBuffer addresses) switch ((VCDiffResult)decoded) { - case VCDiffResult.ERROR: - return VCDiffResult.ERROR; + case VCDiffResult.Error: + return VCDiffResult.Error; case VCDiffResult.EOD: return VCDiffResult.EOD; default: if (decoded < 0 || decoded > here) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } break; } @@ -293,7 +292,7 @@ VCDiffResult DecodeCopy(int size, byte mode, ByteBuffer addresses) targetData.Add(b); Decoded += size; - return VCDiffResult.SUCCESS; + return VCDiffResult.Succes; } ///will come back to this once @@ -322,7 +321,7 @@ VCDiffResult DecodeCopy(int size, byte mode, ByteBuffer addresses) target.Position = decoded; sout.writeBytes(target.ReadBytes(size));*/ - return VCDiffResult.ERROR; + return VCDiffResult.Error; } VCDiffResult DecodeRun(int size, ByteBuffer addRun) @@ -347,7 +346,7 @@ VCDiffResult DecodeRun(int size, ByteBuffer addRun) Decoded += size; - return VCDiffResult.SUCCESS; + return VCDiffResult.Succes; } VCDiffResult DecodeAdd(int size, ByteBuffer addRun) @@ -369,7 +368,7 @@ VCDiffResult DecodeAdd(int size, ByteBuffer addRun) targetData.Add(b); Decoded += size; - return VCDiffResult.SUCCESS; + return VCDiffResult.Succes; } public void Dispose() diff --git a/VCDiff.Core/Decoders/CustomCodeTableDecoder.cs b/VCDiff.Core/Decoders/CustomCodeTableDecoder.cs index 0a95354..267d5da 100644 --- a/VCDiff.Core/Decoders/CustomCodeTableDecoder.cs +++ b/VCDiff.Core/Decoders/CustomCodeTableDecoder.cs @@ -38,14 +38,14 @@ public CustomCodeTableDecoder() public VCDiffResult Decode(IByteBuffer source) { - VCDiffResult result = VCDiffResult.SUCCESS; + VCDiffResult result = VCDiffResult.Succes; //the custom codetable itself is a VCDiff file but it is required to be encoded with the standard table //the length should be the first thing after the hdr_indicator if not supporting compression //at least according to the RFC specs. int lengthOfCodeTable = VarIntBE.ParseInt32(source); - if (lengthOfCodeTable == 0) return VCDiffResult.ERROR; + if (lengthOfCodeTable == 0) return VCDiffResult.Error; ByteBuffer codeTable = new ByteBuffer(source.ReadBytes(lengthOfCodeTable)); @@ -58,7 +58,7 @@ public VCDiffResult Decode(IByteBuffer source) if (NearSize == 0 || SameSize == 0 || NearSize > byte.MaxValue || SameSize > byte.MaxValue) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } CustomTable = new CodeTable(); @@ -72,7 +72,7 @@ public VCDiffResult Decode(IByteBuffer source) VCDecoder decoder = new VCDecoder(dictionary, codeTable, sout); result = decoder.Start(); - if (result != VCDiffResult.SUCCESS) + if (result != VCDiffResult.Succes) { return result; } @@ -80,15 +80,15 @@ public VCDiffResult Decode(IByteBuffer source) long bytesWritten = 0; result = decoder.Decode(out bytesWritten); - if (result != VCDiffResult.SUCCESS || bytesWritten == 0) + if (result != VCDiffResult.Succes || bytesWritten == 0) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } //set the new table data that was decoded if (!CustomTable.SetBytes(sout.ToArray())) { - result = VCDiffResult.ERROR; + result = VCDiffResult.Error; } } diff --git a/VCDiff.Core/Decoders/InstructionDecoder.cs b/VCDiff.Core/Decoders/InstructionDecoder.cs index 0e946a3..6752027 100644 --- a/VCDiff.Core/Decoders/InstructionDecoder.cs +++ b/VCDiff.Core/Decoders/InstructionDecoder.cs @@ -94,7 +94,7 @@ public VCDiffInstructionType Next(out int size, out byte mode) { switch (size = VarIntBE.ParseInt32(source)) { - case (int)VCDiffResult.ERROR: + case (int)VCDiffResult.Error: mode = 0; size = 0; return VCDiffInstructionType.ERROR; diff --git a/VCDiff.Core/Decoders/VCDecoder.cs b/VCDiff.Core/Decoders/VCDecoder.cs index b80916d..b75bcaf 100644 --- a/VCDiff.Core/Decoders/VCDecoder.cs +++ b/VCDiff.Core/Decoders/VCDecoder.cs @@ -91,28 +91,28 @@ public VCDiffResult Start() if (V != MagicBytes[0]) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } if (C != MagicBytes[1]) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } if (D != MagicBytes[2]) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } if (version != 0x00 && version != 'S') { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } //compression not supported if ((hdr & (int)VCDiffCodeFlags.VCDDECOMPRESS) != 0) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } //custom code table! @@ -125,7 +125,7 @@ public VCDiffResult Start() customTable = new CustomCodeTableDecoder(); VCDiffResult result = customTable.Decode(delta); - if (result != VCDiffResult.SUCCESS) + if (result != VCDiffResult.Succes) { return result; } @@ -138,7 +138,7 @@ public VCDiffResult Start() //buffer all the dictionary up front dict.BufferAll(); - return VCDiffResult.SUCCESS; + return VCDiffResult.Succes; } /// @@ -153,10 +153,10 @@ public VCDiffResult Decode(out long bytesWritten) if (!IsStarted) { bytesWritten = 0; - return VCDiffResult.ERROR; + return VCDiffResult.Error; } - VCDiffResult result = VCDiffResult.SUCCESS; + VCDiffResult result = VCDiffResult.Succes; bytesWritten = 0; if (!delta.CanRead) return VCDiffResult.EOD; @@ -177,7 +177,7 @@ public VCDiffResult Decode(out long bytesWritten) //decodedinterleave actually has an internal loop for waiting and streaming the incoming rest of the interleaved window result = body.DecodeInterleave(); - if (result != VCDiffResult.SUCCESS && result != VCDiffResult.EOD) + if (result != VCDiffResult.Succes && result != VCDiffResult.EOD) { return result; } @@ -194,7 +194,7 @@ public VCDiffResult Decode(out long bytesWritten) result = body.Decode(); - if (result != VCDiffResult.SUCCESS) + if (result != VCDiffResult.Succes) { return result; } @@ -208,7 +208,7 @@ public VCDiffResult Decode(out long bytesWritten) //in the stream result = body.Decode(); - if (result != VCDiffResult.SUCCESS) + if (result != VCDiffResult.Succes) { return result; } @@ -218,7 +218,7 @@ public VCDiffResult Decode(out long bytesWritten) else { //invalid file - return VCDiffResult.ERROR; + return VCDiffResult.Error; } } } diff --git a/VCDiff.Core/Decoders/WindowDecoder.cs b/VCDiff.Core/Decoders/WindowDecoder.cs index 82bf409..1de6e39 100644 --- a/VCDiff.Core/Decoders/WindowDecoder.cs +++ b/VCDiff.Core/Decoders/WindowDecoder.cs @@ -80,7 +80,7 @@ public WindowDecoder(long dictionarySize, IByteBuffer buffer) this.dictionarySize = dictionarySize; this.buffer = buffer; chunk = new ParseableChunk(buffer.Position, buffer.Length); - Result = (int)VCDiffResult.SUCCESS; + Result = (int)VCDiffResult.Succes; } /// @@ -128,7 +128,7 @@ public bool Decode(bool googleVersion) private bool ParseByte(out byte value) { - if ((int)VCDiffResult.SUCCESS != Result) + if ((int)VCDiffResult.Succes != Result) { value = 0; return false; @@ -146,7 +146,7 @@ private bool ParseByte(out byte value) private bool ParseInt32(out int value) { - if ((int)VCDiffResult.SUCCESS != Result) + if ((int)VCDiffResult.Succes != Result) { value = 0; return false; @@ -161,7 +161,7 @@ private bool ParseInt32(out int value) int parsed = VarIntBE.ParseInt32(buffer); switch (parsed) { - case (int)VCDiffResult.ERROR: + case (int)VCDiffResult.Error: value = 0; return false; @@ -179,7 +179,7 @@ private bool ParseInt32(out int value) private bool ParseUInt32(out uint value) { - if ((int)VCDiffResult.SUCCESS != Result) + if ((int)VCDiffResult.Succes != Result) { value = 0; return false; @@ -194,7 +194,7 @@ private bool ParseUInt32(out uint value) long parsed = VarIntBE.ParseInt64(buffer); switch (parsed) { - case (int)VCDiffResult.ERROR: + case (int)VCDiffResult.Error: value = 0; return false; @@ -207,7 +207,7 @@ private bool ParseUInt32(out uint value) } if (parsed > 0xFFFFFFFF) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; value = 0; return false; } @@ -228,7 +228,7 @@ private bool ParseSourceSegmentLengthAndPosition(long from, out long sourceLengt sourceLength = outLength; if (sourceLength > from) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; sourceLength = 0; sourcePosition = 0; return false; @@ -243,7 +243,7 @@ private bool ParseSourceSegmentLengthAndPosition(long from, out long sourceLengt sourcePosition = outPos; if (sourcePosition > from) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; sourceLength = 0; sourcePosition = 0; return false; @@ -252,7 +252,7 @@ private bool ParseSourceSegmentLengthAndPosition(long from, out long sourceLengt long segmentEnd = sourcePosition + sourceLength; if (segmentEnd > from) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; sourceLength = 0; sourcePosition = 0; return false; @@ -284,7 +284,7 @@ private bool ParseWindowIndicatorAndSegment(long dictionarySize, long decodedTar winIndicator = 0; sourceSegmentLength = 0; sourceSegmentPosition = 0; - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; return false; } return ParseSourceSegmentLengthAndPosition(decodedTargetSize, out sourceSegmentLength, out sourceSegmentPosition); @@ -327,12 +327,12 @@ private bool ParseDeltaIndicator() { if (!ParseByte(out deltaIndicator)) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; return false; } if ((deltaIndicator & ((int)VCDiffCompressFlags.VCDDATACOMP | (int)VCDiffCompressFlags.VCDINSTCOMP | (int)VCDiffCompressFlags.VCDADDRCOMP)) > 0) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; return false; } return true; @@ -357,7 +357,7 @@ public bool ParseSectionLengths(bool hasChecksum, out long addRunLength, out lon addressLength = outAddress; instructionsLength = outInstruct; - if (Result != (int)VCDiffResult.SUCCESS) + if (Result != (int)VCDiffResult.Succes) { return false; } @@ -367,7 +367,7 @@ public bool ParseSectionLengths(bool hasChecksum, out long addRunLength, out lon if (deltaEncodingLength != totalLen) { - Result = (int)VCDiffResult.ERROR; + Result = (int)VCDiffResult.Error; return false; } diff --git a/VCDiff.Core/Encoders/VCCoder.cs b/VCDiff.Core/Encoders/VCCoder.cs index 1850161..59694fe 100644 --- a/VCDiff.Core/Encoders/VCCoder.cs +++ b/VCDiff.Core/Encoders/VCCoder.cs @@ -67,10 +67,10 @@ public VCDiffResult Encode(bool interleaved = false, bool checksum = false) { if (newData.Length == 0 || oldData.Length == 0) { - return VCDiffResult.ERROR; + return VCDiffResult.Error; } - VCDiffResult result = VCDiffResult.SUCCESS; + VCDiffResult result = VCDiffResult.Succes; oldData.Position = 0; newData.Position = 0; diff --git a/VCDiff.Core/Includes/Include.cs b/VCDiff.Core/Includes/Include.cs index 80c3eb1..c718690 100644 --- a/VCDiff.Core/Includes/Include.cs +++ b/VCDiff.Core/Includes/Include.cs @@ -22,9 +22,25 @@ namespace MatthiWare.Compression.VCDiff.Includes { public enum VCDiffResult { - SUCCESS = 0, - ERROR = -1, - EOD = -2 + /// + /// Indicates succes + /// + Succes = 0, + + /// + /// Indicates an error occured + /// + Error = -1, + + /// + /// End of data + /// + EOD = -2, + + /// + /// Indicates nothing happend + /// + NOOP = 1 } // The possible values for the Hdr_Indicator field, as described diff --git a/VCDiff.Core/Shared/AddressCache.cs b/VCDiff.Core/Shared/AddressCache.cs index 9152f47..c3c15f5 100644 --- a/VCDiff.Core/Shared/AddressCache.cs +++ b/VCDiff.Core/Shared/AddressCache.cs @@ -199,7 +199,7 @@ public long DecodeAddress(long here, byte mode, ByteBuffer sin) long start = sin.Position; if (here < 0) { - return (int)VCDiffResult.ERROR; + return (int)VCDiffResult.Error; } if (!sin.CanRead) @@ -219,7 +219,7 @@ public long DecodeAddress(long here, byte mode, ByteBuffer sin) switch (encoded) { - case (int)VCDiffResult.ERROR: + case (int)VCDiffResult.Error: return encoded; case (int)VCDiffResult.EOD: sin.Position = start; @@ -242,13 +242,13 @@ public long DecodeAddress(long here, byte mode, ByteBuffer sin) } else { - return (int)VCDiffResult.ERROR; + return (int)VCDiffResult.Error; } } if (!IsDecodedAddressValid(decoded, here)) { - return (int)VCDiffResult.ERROR; + return (int)VCDiffResult.Error; } UpdateCache(decoded); return decoded; diff --git a/VCDiff.Core/Shared/VarIntBE.cs b/VCDiff.Core/Shared/VarIntBE.cs index e59e0e2..dee5320 100644 --- a/VCDiff.Core/Shared/VarIntBE.cs +++ b/VCDiff.Core/Shared/VarIntBE.cs @@ -46,7 +46,7 @@ public static int ParseInt32(IByteBuffer sin) } if (result > (int32MaxValue >> 7)) { - return (int)VCDiffResult.ERROR; + return (int)VCDiffResult.Error; } result = result << 7; sin.Next(); @@ -67,7 +67,7 @@ public static long ParseInt64(IByteBuffer sin) } if (result > (int64MaxValue >> 7)) { - return (long)VCDiffResult.ERROR; + return (long)VCDiffResult.Error; } result = result << 7; sin.Next(); diff --git a/VCDiff.Core/VCDiff.Core.csproj b/VCDiff.Core/VCDiff.Core.csproj index 9e01387..69ad67c 100644 --- a/VCDiff.Core/VCDiff.Core.csproj +++ b/VCDiff.Core/VCDiff.Core.csproj @@ -16,5 +16,6 @@ VCDiff delta 0.1.0 Matthias Beerens + 7.3 \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 81906d7..99e8c10 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,10 @@ os: Visual Studio 2017 version: 0.1.{build} +environment: + CODECOV_TOKEN: + secure: GgeOsPP+RVbbkIGt2RkhNhiLhf1K5WO2yM++zC4kgc7Z6YCFFX2XPwWqzpJqF/s7 + # Build script build_script: - ps: .\build.ps1 --target="AppVeyor" --verbosity=Verbose diff --git a/build.cake b/build.cake index 40fd09c..30ca896 100644 --- a/build.cake +++ b/build.cake @@ -1,3 +1,8 @@ +#tool nuget:?package=Codecov +#addin nuget:?package=Cake.Codecov +#tool "nuget:?package=OpenCover" +#tool "nuget:?package=NUnit.ConsoleRunner" + /////////////////////////////////////////////////////////////////////////////// // ARGUMENTS /////////////////////////////////////////////////////////////////////////////// @@ -12,8 +17,9 @@ var configuration = Argument("configuration", "Release"); var project = "VCDiff.Core"; var projectCli = $"{project}.Cli"; var solution = $"./{project}.sln"; -var tests = $"./{project}.Tests/{project}.Tests.csproj"; +var tests = $"./output/{project}.Tests.dll"; var publishPath = MakeAbsolute(Directory("./output")); +var codedovToken = EnvironmentVariable("CODECOV_TOKEN"); /////////////////////////////////////////////////////////////////////////////// // TASKS @@ -39,6 +45,7 @@ Task("Build") DotNetCoreBuild(solution, new DotNetCoreBuildSettings { + ArgumentCustomization = arg => arg.AppendSwitch("/p:DebugType","=","Full"), NoRestore = false, Configuration = configuration }); @@ -46,17 +53,32 @@ Task("Build") Task("Test") .IsDependentOn("Build") - .Does( () => { - DotNetCoreTest(tests, - new DotNetCoreTestSettings { - NoBuild = true, - NoRestore = true, - Configuration = configuration + .Does(() => { + + // Information(MakeAbsolute(Directory(tests))); + + OpenCover(tool => { + + + + tool.NUnit3(tests); + }, + new FilePath("./TestResult.xml"), + new OpenCoverSettings() + .WithFilter($"+[{project}]*") + .WithFilter($"-[{project}.Tests]*")); }); + +Task("Upload-Coverage") + .IsDependentOn("Test") + .Does(() => +{ + // Upload a coverage report by providing the Codecov upload token. + Codecov("coverage.xml", codedovToken); }); Task("Publish") - .IsDependentOn("Test") + .IsDependentOn("Build") .IsDependentOn("Clean-Publish") .Does( () => { DotNetCorePublish(solution, @@ -72,6 +94,7 @@ Task("Default") .IsDependentOn("Test"); Task("AppVeyor") - .IsDependentOn("Publish"); + .IsDependentOn("Publish") + .IsDependentOn("Upload-Coverage"); RunTarget(target); \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..68ec52b --- /dev/null +++ b/codecov.yml @@ -0,0 +1,26 @@ +codecov: + notify: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "25...75" + + status: + project: yes + patch: yes + changes: no + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "header, diff, changes, sunburst, uncovered" + behavior: default + require_changes: no \ No newline at end of file