Skip to content

Commit

Permalink
update to 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonPAKA committed Jun 2, 2024
1 parent 15d664e commit cb4b15f
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dependencies/SharpHDiffPatch-Dotnet"]
path = dependencies/SharpHDiffPatch-Dotnet
url = https://github.com/Leayal/SharpHDiffPatch-Dotnet
2 changes: 1 addition & 1 deletion src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ namespace Leayal.SnowBreakLauncher
{
static internal class AssemblyInfo
{
public const string Version = "1.2.11";
public const string Version = "1.3.0";
}
}
73 changes: 73 additions & 0 deletions src/Classes/Hpatchz.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpHDiffPatch.Core;
using System.Runtime.CompilerServices;
using SharpHDiffPatch.Core.Event;
using SharpHDiffPatch.Core.Patch;
using Avalonia.Controls.Shapes;


namespace Leayal.SnowBreakLauncher.Classes
{
/// <summary>Just a facade</summary>
sealed class Hpatchz
{
/* Already Quiet by default
static Hpatchz()
{
HDiffPatch.LogVerbosity = Verbosity.Quiet;
}
*/
// Have to self-fix it

private readonly HeaderInfo headerInfo;
private readonly DataReferenceInfo referenceInfo;
public readonly string diffPath;
private readonly bool isPatchDir;

public long DiffSize
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.headerInfo.newDataSize;
}

public Hpatchz(string hDiffFile)
{
this.diffPath = hDiffFile;

using (var diffStream = new FileStream(hDiffFile, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan))
{
this.isPatchDir = Header.TryParseHeaderInfo(diffStream, hDiffFile, out HeaderInfo headerInfo, out DataReferenceInfo referenceInfo);

this.headerInfo = headerInfo;
this.referenceInfo = referenceInfo;
}
}

// Currently, the internal code of HDiffPatch doesn't have instances of patching, so progress tracking per instance isn't possible.
// I'm not even sure if the HDiffPatchCore is even thread-safe to use.
public async Task Patch(string originalFile, string outputFile, CancellationToken cancellation = default)
{
if (!File.Exists(originalFile)) throw new FileNotFoundException(null, originalFile);

await Task.Factory.StartNew((object? obj) =>
{
if (obj == null) throw new InvalidOperationException(); // Can't be here anyway
var (myself, originalFile, outputFile, cancellation) = ((Tuple<Hpatchz, string, string, CancellationToken>)obj);

var headerInfo = myself.headerInfo;

IPatch patcher = (myself.isPatchDir && headerInfo.isInputDir && headerInfo.isOutputDir) ?
new PatchDir(headerInfo, myself.referenceInfo, myself.diffPath, cancellation)
: new PatchSingle(myself.headerInfo, cancellation);

patcher.Patch(originalFile, outputFile, true, false, true);

}, new Tuple<Hpatchz, string, string,CancellationToken> (this, originalFile, outputFile, cancellation), cancellation, TaskCreationOptions.LongRunning, TaskScheduler.Current ?? TaskScheduler.Default);
}
}
}
4 changes: 4 additions & 0 deletions src/SnowBreakLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@
<ItemGroup>
<AdditionalFiles Include="NativeMethods.txt" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\dependencies\SharpHDiffPatch-Dotnet\SharpHDiffPatch.Core\SharpHDiffPatch.Core.csproj" />
</ItemGroup>
</Project>
36 changes: 36 additions & 0 deletions src/SnowBreakLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,52 @@ VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnowBreakLauncher", "SnowBreakLauncher.csproj", "{2E479288-38E1-458D-8790-7701BD242A3B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpHDiffPatch.Core", "..\dependencies\SharpHDiffPatch-Dotnet\SharpHDiffPatch.Core\SharpHDiffPatch.Core.csproj", "{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|ARM64.Build.0 = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|x64.ActiveCfg = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|x64.Build.0 = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|x86.ActiveCfg = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Debug|x86.Build.0 = Debug|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|Any CPU.Build.0 = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|ARM64.ActiveCfg = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|ARM64.Build.0 = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|x64.ActiveCfg = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|x64.Build.0 = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|x86.ActiveCfg = Release|Any CPU
{2E479288-38E1-458D-8790-7701BD242A3B}.Release|x86.Build.0 = Release|Any CPU
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|ARM64.ActiveCfg = Debug|ARM64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|ARM64.Build.0 = Debug|ARM64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|x64.ActiveCfg = Debug|x64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|x64.Build.0 = Debug|x64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|x86.ActiveCfg = Debug|x86
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Debug|x86.Build.0 = Debug|x86
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|Any CPU.Build.0 = Release|Any CPU
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|ARM64.ActiveCfg = Release|ARM64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|ARM64.Build.0 = Release|ARM64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|x64.ActiveCfg = Release|x64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|x64.Build.0 = Release|x64
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|x86.ActiveCfg = Release|x86
{26D8D03B-5E63-495B-8A44-4E1C8C2FA2BC}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit cb4b15f

Please # to comment.