Skip to content

Commit

Permalink
Pull changes across projects
Browse files Browse the repository at this point in the history
- Merge from Collapse:main at 3e94029
- Update SharpHDiff Submodules to 14029aea346bf5f8389a5725b73daec9c63df55c
  • Loading branch information
bagusnl committed Oct 28, 2023
1 parent 9f0df43 commit 4eb3192
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 61 deletions.
4 changes: 3 additions & 1 deletion CollapseLauncher/Classes/CachesManagement/StarRail/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private async Task<List<SRAsset>> Fetch(CancellationToken token)
_status.IsProgressTotalIndetermined = true;
_status.IsIncludePerFileIndicator = false;
UpdateStatus();
await _innerGameVersionManager.StarRailMetadataTool.Initialize(token, GetExistingGameRegionID(), Path.Combine(_gamePath, $"{Path.GetFileNameWithoutExtension(_gameVersionManager.GamePreset.GameExecutableName)}_Data\\Persistent"));

if (!await _innerGameVersionManager.StarRailMetadataTool.Initialize(token, GetExistingGameRegionID(), Path.Combine(_gamePath, $"{Path.GetFileNameWithoutExtension(_gameVersionManager.GamePreset.GameExecutableName)}_Data\\Persistent")))
throw new InvalidDataException("The dispatcher response is invalid! Please open an issue to our GitHub page to report this issue.");

// Iterate type and do fetch
foreach (SRAssetType type in Enum.GetValues(typeof(SRAssetType)))
Expand Down
3 changes: 1 addition & 2 deletions CollapseLauncher/Classes/EventsManagement/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using Squirrel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Windows.Foundation;
using Squirrel;
using Windows.Networking.Connectivity;
using static CollapseLauncher.InnerLauncherConfig;
using static Hi3Helper.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hi3Helper.Preset;
using Hi3Helper.Shared.ClassStruct;
using Hi3Helper.Shared.Region;
using Hi3Helper.SharpHDiffPatch;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Win32;
Expand All @@ -24,6 +25,7 @@
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
using PatcherHDiff = Hi3Helper.SharpHDiffPatch;
using CoreCombinedStream = Hi3Helper.EncTool.CombinedStream;

namespace CollapseLauncher.InstallManager.Base
{
Expand Down Expand Up @@ -309,7 +311,7 @@ private long GetAssetIndexTotalUncompressSize(SevenZipTool zip, List<GameInstall
private Stream GetSingleOrSegmentedDownloadStream(GameInstallPackage asset)
{
return asset.Segments != null && asset.Segments.Count != 0 ?
new CombinedStream(asset.Segments.Select(x => x.GetReadStream(_downloadThreadCount)).ToArray()) :
new CoreCombinedStream(asset.Segments.Select(x => x.GetReadStream(_downloadThreadCount)).ToArray()) :
asset.GetReadStream(_downloadThreadCount);
}

Expand Down Expand Up @@ -522,6 +524,7 @@ public async ValueTask<bool> UninstallGame()
}
else foldersToKeepInDataFullPath = Array.Empty<string>();

#pragma warning disable CS8604 // Possible null reference argument.
LogWriteLine($"Uninstalling game: {_gameVersionManager.GameType} - region: {_gameVersionManager.GamePreset.ZoneName}\r\n" +
$" GameFolder : {GameFolder}\r\n" +
$" gameDataFolderName : {UninstallProperty.gameDataFolderName}\r\n" +
Expand All @@ -530,6 +533,7 @@ public async ValueTask<bool> UninstallGame()
$" foldersToKeepInData : {string.Join(", ", UninstallProperty.foldersToKeepInData)}\r\n" +
$" _Data folder path : {_DataFolderFullPath}\r\n" +
$" Excluded full paths : {string.Join(", ", foldersToKeepInDataFullPath)}", LogType.Warning, true);
#pragma warning restore CS8604 // Possible null reference argument.

// Cleanup Game_Data folder while keeping whatever specified in foldersToKeepInData
foreach (string folderGameData in Directory.EnumerateFileSystemEntries(_DataFolderFullPath))
Expand Down Expand Up @@ -715,7 +719,7 @@ public virtual async ValueTask ApplyHdiffListPatch()
_progressTotalCount = 1;
_progressTotalCountFound = hdiffEntry.Count;

PatcherHDiff.HDiffPatch patcher = new PatcherHDiff.HDiffPatch();
HDiffPatch patcher = new HDiffPatch();
foreach (PkgVersionProperties entry in hdiffEntry)
{
_status.ActivityStatus = string.Format("{0}: {1}", Lang._Misc.Patching, string.Format(Lang._Misc.PerFromTo, _progressTotalCount, _progressTotalCountFound));
Expand All @@ -728,7 +732,9 @@ public virtual async ValueTask ApplyHdiffListPatch()
try
{
_token.Token.ThrowIfCancellationRequested();
PatcherHDiff.EventListener.PatchEvent += EventListener_PatchEvent;
HDiffPatch.LogVerbosity = Verbosity.Verbose;
EventListener.LoggerEvent += EventListener_PatchLogEvent;
EventListener.PatchEvent += EventListener_PatchEvent;
if (File.Exists(sourceBasePath) && File.Exists(patchPath))
{
LogWriteLine($"Patching file {entry.remoteName}...", LogType.Default, true);
Expand All @@ -738,7 +744,7 @@ public virtual async ValueTask ApplyHdiffListPatch()
await Task.Run(() =>
{
patcher.Initialize(patchPath);
patcher.Patch(sourceBasePath, destPath, true, _token.Token);
patcher.Patch(sourceBasePath, destPath, true, _token.Token, false, true);
}, _token.Token);

File.Move(destPath, sourceBasePath, true);
Expand All @@ -763,7 +769,8 @@ await Task.Run(() =>
}
finally
{
PatcherHDiff.EventListener.PatchEvent -= EventListener_PatchEvent;
EventListener.PatchEvent -= EventListener_PatchEvent;
EventListener.LoggerEvent -= EventListener_PatchLogEvent;
try
{
if (File.Exists(destPath)) File.Delete(destPath);
Expand All @@ -782,7 +789,7 @@ await Task.Run(() =>
}
}

private async void EventListener_PatchEvent(object sender, PatcherHDiff.PatchEvent e)
private async void EventListener_PatchEvent(object sender, PatchEvent e)
{
_progress.ProgressTotalDownload += e.Read;
if (await base.CheckIfNeedRefreshStopwatch())
Expand All @@ -795,6 +802,29 @@ private async void EventListener_PatchEvent(object sender, PatcherHDiff.PatchEve
}
}

private void EventListener_PatchLogEvent(object sender, LoggerEvent e)
{
if (HDiffPatch.LogVerbosity == Verbosity.Quiet
|| (HDiffPatch.LogVerbosity == Verbosity.Debug
&& !(e.LogLevel == Verbosity.Debug ||
e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Verbose
&& !(e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Info
&& !(e.LogLevel == Verbosity.Info))) return;

LogType type = e.LogLevel switch
{
Verbosity.Verbose => LogType.Debug,
Verbosity.Debug => LogType.Debug,
_ => LogType.Default
};

LogWriteLine(e.Message, type, true);
}

public virtual List<PkgVersionProperties> TryGetHDiffList()
{
List<PkgVersionProperties> _out = new List<PkgVersionProperties>();
Expand All @@ -810,18 +840,14 @@ public virtual List<PkgVersionProperties> TryGetHDiffList()
{
while (!listReader.EndOfStream)
{
prop = (PkgVersionProperties)JsonSerializer
.Deserialize(
listReader.ReadLine(),
typeof(PkgVersionProperties),
CoreLibraryJSONContext.Default);
prop = listReader.ReadLine().Deserialize<PkgVersionProperties>(CoreLibraryJSONContext.Default);

string filePath = Path.Combine(_gamePath, prop.remoteName + ".hdiff");
if (File.Exists(filePath))
{
try
{
prop.fileSize = PatcherHDiff.HDiffPatch.GetHDiffNewSize(filePath);
prop.fileSize = HDiffPatch.GetHDiffNewSize(filePath);
LogWriteLine($"hdiff entry: {prop.remoteName}", LogType.Default, true);

_out.Add(prop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,15 @@ public async Task StartConversion()

Directory.CreateDirectory(OutputPath);

HDiffPatch.LogVerbosity = Verbosity.Verbose;
EventListener.LoggerEvent += EventListener_PatchLogEvent;
EventListener.PatchEvent += EventListener_PatchEvent;

await Task.Run(() =>
{
HDiffPatch patch = new HDiffPatch();
patch.Initialize(CookbookPath);
patch.Patch(IngredientsPath, OutputPath, false, Token);
patch.Patch(IngredientsPath, OutputPath, true, Token, false, true);
}, Token);

TryDirectoryDelete(IngredientsPath, true);
Expand All @@ -325,9 +327,33 @@ await Task.Run(() =>
finally
{
EventListener.PatchEvent -= EventListener_PatchEvent;
EventListener.LoggerEvent -= EventListener_PatchLogEvent;
}
}

private void EventListener_PatchLogEvent(object sender, LoggerEvent e)
{
if (HDiffPatch.LogVerbosity == Verbosity.Quiet
|| (HDiffPatch.LogVerbosity == Verbosity.Debug
&& !(e.LogLevel == Verbosity.Debug ||
e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Verbose
&& !(e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Info
&& !(e.LogLevel == Verbosity.Info))) return;

LogType type = e.LogLevel switch
{
Verbosity.Verbose => LogType.Debug,
Verbosity.Debug => LogType.Debug,
_ => LogType.Default
};

LogWriteLine(e.Message, type, true);
}

private void EventListener_PatchEvent(object sender, PatchEvent e)
{
ConvertDetail = string.Format(Lang._Misc.Converting, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ protected override async Task StartPackageInstallationInner()
RestartStopwatch();

// Start the patching process
HDiffPatch.LogVerbosity = Verbosity.Verbose;
EventListener.PatchEvent += DeltaPatchCheckProgress;
EventListener.LoggerEvent += DeltaPatchCheckLogEvent;
await Task.Run(() =>
{
HDiffPatch patch = new HDiffPatch();
patch.Initialize(patchProperty.PatchPath);
patch.Patch(ingredientPath, previousPath, false, _token.Token);
patch.Patch(ingredientPath, previousPath, true, _token.Token, false, true);
});

// Remove ingredient folder
Expand All @@ -159,6 +161,7 @@ await Task.Run(() =>
finally
{
EventListener.PatchEvent -= DeltaPatchCheckProgress;
EventListener.LoggerEvent -= DeltaPatchCheckLogEvent;
}
}

Expand Down Expand Up @@ -302,6 +305,29 @@ private async void DeltaPatchCheckProgress(object sender, PatchEvent e)
}
}

private void DeltaPatchCheckLogEvent(object sender, LoggerEvent e)
{
if (HDiffPatch.LogVerbosity == Verbosity.Quiet
|| (HDiffPatch.LogVerbosity == Verbosity.Debug
&& !(e.LogLevel == Verbosity.Debug ||
e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Verbose
&& !(e.LogLevel == Verbosity.Verbose ||
e.LogLevel == Verbosity.Info))
|| (HDiffPatch.LogVerbosity == Verbosity.Info
&& !(e.LogLevel == Verbosity.Info))) return;

LogType type = e.LogLevel switch
{
Verbosity.Verbose => LogType.Debug,
Verbosity.Debug => LogType.Debug,
_ => LogType.Default
};

LogWriteLine(e.Message, type, true);
}

private async void DeltaPatchCheckProgress(object sender, TotalPerfileProgress e)
{
_progress.ProgressTotalPercentage = e.ProgressTotalPercentage == 0 ? e.ProgressPerFilePercentage : e.ProgressTotalPercentage;
Expand Down
Loading

0 comments on commit 4eb3192

Please sign in to comment.