Skip to content

Commit

Permalink
Minor changes and dependencies updates
Browse files Browse the repository at this point in the history
- Workaround SEGA's way: the hash table file is included in PatchListAlways.txt. Launcher can now ignore checking the file if the 'replace hash table file for modding'  behavior is enabled.
- Remove ZamboniLib for now since I'm just too lazy to make mod manager.
- Update WebView2, SQLitePCL dependencies.
  • Loading branch information
Leayal committed Jun 10, 2023
1 parent ed57579 commit a413134
Show file tree
Hide file tree
Showing 44 changed files with 63 additions and 243 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "ZamboniLib"]
path = ZamboniLib
url = https://github.com/Shadowth117/ZamboniLib
67 changes: 0 additions & 67 deletions AdminProcess/AdminEntryProgram.cs

This file was deleted.

22 changes: 0 additions & 22 deletions AdminProcess/AdminProcess.Elevated.cs

This file was deleted.

49 changes: 0 additions & 49 deletions AdminProcess/AdminProcess.Host.cs

This file was deleted.

50 changes: 0 additions & 50 deletions AdminProcess/AdminProcess.cs

This file was deleted.

16 changes: 0 additions & 16 deletions AdminProcess/AdminProcess.csproj

This file was deleted.

12 changes: 0 additions & 12 deletions AdminProcess/Elevator.cs

This file was deleted.

4 changes: 4 additions & 0 deletions LauncherCore/Classes/PSO2/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public enum FileScanFlags
/// </remarks>
CacheOnly = 1 << 4,

/// <summary>Excludes the hash table file from file check and download.</summary>
/// <remarks><para>Hash table file is <u>data/win32/d4455ebc2bef618f29106da7692ebc1a</u>.</para></remarks>
IgnoreHashTableFile = 1 << 5,

// Preset below

[EnumDisplayName("Prefer speed [Not recommended: Unreliable] (Check missing and compare the cached MD5-hash if the file is already existed)")]
Expand Down
1 change: 1 addition & 0 deletions LauncherCore/Classes/PSO2/GameClientUpdater.Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Leayal.PSO2Launcher.Core.Classes.PSO2
{
partial class GameClientUpdater
{
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
private async Task InnerDownloadSingleFile(int id, BlockingCollection<DownloadItem> pendingFiles, IFileCheckHashCache duhB, DownloadFinishCallback onFinished, CancellationToken cancellationToken)
{
// var downloadbuffer = new byte[4096];
Expand Down
18 changes: 18 additions & 0 deletions LauncherCore/Classes/PSO2/GameClientUpdater.FileScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
using System.Threading.Tasks;
using System.Security.Cryptography;
using Leayal.Shared.Windows;
using System.Runtime.CompilerServices;

namespace Leayal.PSO2Launcher.Core.Classes.PSO2
{
#nullable enable
partial class GameClientUpdater
{
private static readonly string __Filename_HashTableRelativePath = "data/win32/d4455ebc2bef618f29106da7692ebc1a";

const int ScanBufferSize = 1024 * 16; // 16KB buffer
private async Task<PatchListMemory> InnerGetFilelistToScan(GameClientSelection selection, CancellationToken cancellationToken)
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void AddToPatchListTasks(Task<PatchListMemory> t, List<Task<PatchListMemory>> list)
{
if (t.Status == TaskStatus.Created)
Expand Down Expand Up @@ -223,6 +227,7 @@ private static int RestoreBackups(BackupFileFoundEventArgs e_onBackup, in Cancel
// So optional, silent the error since it's okay even if it fails.

// Add "Directory.ResolveLinkTarget" so that in case the backup directory is actually a symlink. We will preserve it instead.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void TryDelEmptyBackupFolder(string path)
{
if (Directory.Exists(path) && Directory.ResolveLinkTarget(path, false) == null && !DirectoryHelper.IsDirectoryNotEmpty(path))
Expand Down Expand Up @@ -266,6 +271,7 @@ static void TryDelEmptyBackupFolder(string path)
}
}

[MethodImpl(MethodImplOptions.AggressiveOptimization)]
private async Task InnerScanForFilesNeedToDownload(BlockingCollection<DownloadItem> pendingFiles, string dir_pso2bin, string? dir_classic_data, PSO2TweakerHashCache? tweakerHashCache, GameClientSelection selection, FileScanFlags fScanReboot, FileScanFlags fScanClassic, IFileCheckHashCache duhB, PatchListBase headacheMatterAgain, InnerDownloadQueueAddCallback onDownloadQueueAdd, CancellationToken cancellationToken)
{
if (fScanClassic == FileScanFlags.None)
Expand Down Expand Up @@ -319,6 +325,11 @@ static async Task<string> ___GetFileMD5(FileStream fs, MD5 hashal, CancellationT
*/

int processedFiles = 0;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IsHashTableFile(PatchListItem item) => (MemoryExtensions.Equals(item.GetSpanFilenameWithoutAffix(), __Filename_HashTableRelativePath, StringComparison.OrdinalIgnoreCase) || MemoryExtensions.Equals(item.GetSpanFilenameWithoutAffix(), __Filename_HashTableRelativePath.AsSpan(11), StringComparison.OrdinalIgnoreCase));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void AddItemToQueue(BlockingCollection<DownloadItem> queue, InnerDownloadQueueAddCallback callback, PatchListItem patchItem, string localFilePath, string dir_pso2bin, string? dir_classic_data, CancellationToken cancellationToken)
{
var linkTo = DetermineWhere(patchItem, dir_pso2bin, dir_classic_data, out var isLink);
Expand All @@ -327,6 +338,7 @@ static void AddItemToQueue(BlockingCollection<DownloadItem> queue, InnerDownload
callback.Invoke(in item);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static byte[] BorrowBufferCertainSize(byte[]? buffer, int size)
{
if (buffer == null)
Expand All @@ -342,6 +354,7 @@ static byte[] BorrowBufferCertainSize(byte[]? buffer, int size)
return buffer;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static async Task<ReadOnlyMemory<byte>> Md5ComputeHash(IncrementalHash engine, FileStream stream, byte[] workingbuffer, CancellationToken cancellationToken, bool retainPosition = false)
{
long pos = -1;
Expand Down Expand Up @@ -374,6 +387,7 @@ static async Task<ReadOnlyMemory<byte>> Md5ComputeHash(IncrementalHash engine, F
return new ReadOnlyMemory<byte>(workingbuffer, 0, hashlen);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static FileStream OpenToScan(string localFilePath) => new FileStream(localFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 0, true);

using (var throttleWaiter = (fileCheckThrottleFactor == 0 ? null : new PeriodicTimerWithoutException(TimeSpan.FromMilliseconds(fileCheckThrottleFactor))))
Expand All @@ -392,6 +406,10 @@ static async Task<ReadOnlyMemory<byte>> Md5ComputeHash(IncrementalHash engine, F
}

var flags = (patchItem.IsRebootData == false) ? fScanClassic : fScanReboot;
if ((flags & FileScanFlags.IgnoreHashTableFile) != 0 && IsHashTableFile(patchItem))
{
continue;
}
// data/win32/2b486d03bca4c2578f9e204b234f389b
if (flags == FileScanFlags.MissingFilesOnly)
{
Expand Down

0 comments on commit a413134

Please sign in to comment.