Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CollapseLauncher/Classes/CachesManagement/Honkai/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CollapseLauncher.RepairManagement;
using Hi3Helper;
using Hi3Helper.EncTool;
using Hi3Helper.EncTool.Enc;
using Hi3Helper.EncTool.Parser.KianaDispatch;
using Hi3Helper.UABT;
using System;
Expand Down Expand Up @@ -310,8 +311,15 @@ private byte[] GetAssetIndexSalt(string data)
key = LauncherMetadataHelper.CurrentMasterKey?.Key;
}

MhyEncTool saltTool = new MhyEncTool(data, key);
return saltTool.GetSalt();
byte[] saltBytes = new byte[8];
if (!MhyEncTool.TryGetSalt(data,
key,
saltBytes,
out _,
out Exception exception))
throw exception;

return saltBytes;
}

private string GetAssetBasePathByType(CacheAssetType type) => Path.Combine(GamePath!, type == CacheAssetType.Data ? "Data" : "Resources");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CollapseLauncher.Helper.Update;
using CollapseLauncher.Plugins;
using DiscordRPC;
using DiscordRPC.Entities;
using DiscordRPC.Message;
using Hi3Helper;
using System;
Expand Down Expand Up @@ -139,9 +140,9 @@ private void EnablePresence(ulong applicationId)
Logger.LogWriteLine("Discord Presence is Enabled!");
}

private void OnReady(object? _, ReadyMessage msg)
private void OnReady(object? _, ReadyMessage? msg)
{
Logger.LogWriteLine($"Connected to Discord with user {msg.User.Username}");
Logger.LogWriteLine($"Connected to Discord with user {msg?.User?.Username}");
if (!_firstTimeConnect)
{
// Restart Discord RPC client
Expand All @@ -161,9 +162,9 @@ private void OnReady(object? _, ReadyMessage msg)
}
}

private static void OnPresenceUpdate(object? _, PresenceMessage msg)
private static void OnPresenceUpdate(object? _, PresenceMessage? msg)
{
if (msg.Presence == null)
if (msg?.Presence == null)
{
Logger.LogWriteLine("Activity cleared!");
}
Expand Down
18 changes: 6 additions & 12 deletions CollapseLauncher/Classes/Extension/VelopackLocatorExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using Hi3Helper.Win32.ShellLinkCOM;
using NuGet.Versioning;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -34,12 +32,8 @@ internal static void StartUpdaterHook(string aumid)
// its custom AUMID
IVelopackLogger? logger = ILoggerHelper.GetILogger("Velopack").ToVelopackLogger();

Process currentProcess = Process.GetCurrentProcess();

WindowsVelopackLocator locator =
new(currentProcess.MainModule!.FileName,
(uint)currentProcess.Id,
logger);
DefaultProcessImpl procDefault = new(logger);
WindowsVelopackLocator locator = new(procDefault, logger);
// HACK: Always ensure to set the AUMID field null so it won't
// set the AUMID to its own.
locator.GetLocatorAumidField() = null;
Expand Down Expand Up @@ -168,7 +162,7 @@ public static void TryCleanupFallbackUpdate(SemanticVersion newVersion)

// Try open the shortcut and check whether this shortcut is actually pointing to
// CollapseLauncher.exe file
using ShellLink shellLink = new(thisUserStartMenuShortcut);
ShellLink shellLink = new(thisUserStartMenuShortcut);
// Try to get the target path and its filename
string shortcutTargetPath = shellLink.Target;
if (!shortcutTargetPath.Equals(currentExecutedPath, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -247,10 +241,10 @@ internal static void GenerateVelopackMetadata(string aumid)
</package>
"""; // Adding shortcutAumid for future use, since they typo-ed the XML tag LMAO
string currentVersion = LauncherUpdateHelper.LauncherCurrentVersionString;
string xmlPath = Path.Combine(LauncherConfig.AppExecutableDir, "sq.version");
string xmlPath = Path.Combine(LauncherConfig.AppExecutableDir, "sq.version");
string xmlContent = string.Format(xmlTemplate, currentVersion, LauncherConfig.IsPreview ? "preview" : "stable",
aumid).ReplaceLineEndings("\n");

// Check if file exist
if (File.Exists(xmlPath))
{
Expand All @@ -266,4 +260,4 @@ internal static void GenerateVelopackMetadata(string aumid)
Logger.LogWriteLine($"Velopack metadata has been successfully written!\r\n{xmlContent}", LogType.Default, true);
}
}
}
}
39 changes: 18 additions & 21 deletions CollapseLauncher/Classes/Extension/WriteableBitmapExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Win32.ManagedTools;
using Hi3Helper.Win32.Native.Interfaces;
using Hi3Helper.Win32.WinRT.IBufferCOM;
using Microsoft.UI.Xaml.Media.Imaging;
Expand All @@ -9,29 +8,27 @@
#pragma warning disable IDE0130

#nullable enable
namespace CollapseLauncher.Extension
namespace CollapseLauncher.Extension;

internal static class WriteableBitmapExtension
{
internal static class WriteableBitmapExtension
internal static nint GetBufferPointer(this WriteableBitmap writeableBitmap, out uint length)
{
internal static nint GetBufferPointer(this WriteableBitmap writeableBitmap, out uint length)
length = writeableBitmap.PixelBuffer.Length;
try
{
length = writeableBitmap.PixelBuffer.Length;
IBufferByteAccess byteAccess = writeableBitmap.PixelBuffer.AsBufferByteAccess();
try
{
byteAccess.Buffer(out nint bufferP);
return bufferP;
}
finally
{
if (!ComMarshal<IBufferByteAccess>.TryReleaseComObject(byteAccess, out Exception? ex))
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"Cannot free the instance of IBufferByteAccess from WriteableBitmap\r\n{ex}",
LogType.Error,
true);
}
}
byteAccess.Buffer(out nint bufferP);
return bufferP;
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"Cannot free the instance of IBufferByteAccess from WriteableBitmap\r\n{ex}",
LogType.Error,
true);
}

return nint.Zero;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static ScreenSettingData Load(IGameSettings gameSettings)
$"{ex}", ex));
}

return new ScreenSettingData();
return new ScreenSettingData(gameSettings);
}

public override void Save()
Expand Down
38 changes: 19 additions & 19 deletions CollapseLauncher/Classes/Helper/TaskSchedulerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;

// ReSharper disable CommentTypo
// ReSharper disable StringLiteralTypo
// ReSharper disable GrammarMistakeInComment
Expand Down Expand Up @@ -59,11 +59,11 @@ private static void InvokeGetStatusCommand()
// -1 means task is disabled with tray enabled
-1 => (false, true),
// 0 means task is disabled with tray disabled
0 => (false, false),
0 => (false, false),
// 1 means task is enabled with tray disabled
1 => (true, false),
1 => (true, false),
// 2 means task is enabled with tray enabled
2 => (true, true),
2 => (true, true),
// Otherwise, return both disabled (due to failure)
_ => (false, false)
};
Expand Down Expand Up @@ -172,9 +172,9 @@ private static void CreateShortcut(

// Try create directory
Directory.CreateDirectory(iconLocationDir);

// Create ShellLink instance
using ShellLink shellLink = new ShellLink();
ShellLink shellLink = new();

// If existing icon exist, try open it
try
Expand All @@ -188,14 +188,14 @@ private static void CreateShortcut(
SentryHelper.ExceptionHandler(new Exception(msg, ex));
Logger.LogWriteLine(msg + $"\r\n{ex}", LogType.Error, true);
}

// Set params on the shortcut instance
shellLink.IconIndex = 0;
shellLink.IconPath = executablePath ?? "";
shellLink.DisplayMode = LinkDisplayMode.edmNormal;
shellLink.WorkingDirectory = workingDirPath ?? "";
shellLink.Target = executablePath ?? "";
shellLink.Description = appDescription ?? "";
shellLink.IconIndex = 0;
shellLink.IconPath = executablePath ?? "";
shellLink.DisplayMode = LinkDisplayMode.edmNormal;
shellLink.WorkingDirectory = workingDirPath ?? "";
shellLink.Target = executablePath ?? "";
shellLink.Description = appDescription ?? "";

// Save the icons
shellLink.Save(iconLocation);
Expand Down Expand Up @@ -248,11 +248,11 @@ private static int GetInvokeCommandReturnCode(string argument)
using Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = appletPath,
Arguments = argument,
UseShellExecute = false,
FileName = appletPath,
Arguments = argument,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
CreateNoWindow = true
};

#if DEBUG
Expand All @@ -264,7 +264,7 @@ private static int GetInvokeCommandReturnCode(string argument)
{
// Start the applet and wait until it exit.
process.Start();
while (process.StandardOutput.ReadLine() is {} consoleStdOut)
while (process.StandardOutput.ReadLine() is { } consoleStdOut)
{
Logger.LogWriteLine("[TaskScheduler] " + consoleStdOut, LogType.Debug, true);

Expand Down Expand Up @@ -294,4 +294,4 @@ private static int GetInvokeCommandReturnCode(string argument)
return lastErrCode;
}
}
}
}
15 changes: 8 additions & 7 deletions CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using System;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
using Velopack;
using Velopack.Locators;
using Velopack.Logging;
Expand All @@ -22,7 +22,7 @@ namespace CollapseLauncher.Helper.Update
internal static class LauncherUpdateHelper
{
internal static AppUpdateVersionProp? AppUpdateVersionProp;
private static bool _isLauncherUpdateAvailable;
private static bool _isLauncherUpdateAvailable;

internal static GameVersion? LauncherCurrentVersion => field ??= LauncherConfig.AppCurrentVersionString;

Expand All @@ -41,7 +41,7 @@ internal static async Task RunUpdateCheckDetached()
Logger.LogWriteLine($"The update manager check throws an error, Skipping update check!\r\n{ex}",
LogType.Warning, true);
if (!ex.Message.Contains("application which is not installed",
StringComparison.InvariantCultureIgnoreCase))
StringComparison.InvariantCultureIgnoreCase))
await SentryHelper.ExceptionHandlerAsync(ex);
}
}
Expand All @@ -60,7 +60,8 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal
IFileDownloader updateManagerHttpAdapter = new UpdateManagerHttpAdapter();
// Initialize update manager logger, locator and options
IVelopackLogger? velopackLogger = ILoggerHelper.GetILogger("Velopack").ToVelopackLogger();
IVelopackLocator updateManagerLocator = VelopackLocator.CreateDefaultForPlatform(velopackLogger);
DefaultProcessImpl defaultProcessImpl = new(velopackLogger);
IVelopackLocator updateManagerLocator = VelopackLocator.CreateDefaultForPlatform(defaultProcessImpl, velopackLogger);
UpdateOptions updateManagerOptions = new()
{
AllowVersionDowngrade = true,
Expand Down Expand Up @@ -102,9 +103,9 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal

private static async ValueTask<AppUpdateVersionProp?> GetUpdateMetadata(string updateChannel)
{
string relativePath = updateChannel.CombineURLFromString("fileindex.json");
await using Stream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath);
string relativePath = updateChannel.CombineURLFromString("fileindex.json");
await using Stream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath);
return await ms.DeserializeAsync(AppUpdateVersionPropJsonContext.Default.AppUpdateVersionProp);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,11 @@ await Parallel.ForEachAsync(sophonUpdateAssetList
parallelOptions,
(asset, _) => Action(httpClient, asset));

// Forcely update status
UpdateSophonDownloadStatus(null!);
UpdateSophonFileTotalProgress(0, true);
UpdateSophonFileDownloadProgress(0, 0);

_isSophonPreloadCompleted = isPreloadMode;

// If it's in update mode, then clean up the temp sophon verified files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ await EnsureDiskSpaceSufficiencyAsync(downloadSizePatchOnlyRemote,
// Run parallel pipeline for download
await Parallel.ForEachAsync(pipelineDownloadEnumerable, parallelOptions, ImplDownload);

// Forcely update status
UpdateCurrentDownloadStatus();
UpdateSophonFileTotalProgress(0, true);
UpdateSophonFileDownloadProgress(0, 0);

// If it's on preload mode, then return as we only need to perform patch download.
if (isPreloadMode)
{
Expand All @@ -551,6 +556,11 @@ await EnsureDiskSpaceSufficiencyAsync(downloadSizePatchOnlyRemote,
// Run parallel pipeline for patch
await Parallel.ForEachAsync(pipelinePatchEnumerable, parallelOptions, ImplPatchUpdate);

// Forcely update status
UpdateCurrentDownloadStatus();
UpdateSophonFileTotalProgress(0, true);
UpdateSophonFileDownloadProgress(0, 0);

if (_canDeleteZip)
{
patchAssets.RemovePatches(patchOutputDir);
Expand Down
7 changes: 5 additions & 2 deletions CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ protected bool CheckIfNeedRefreshStopwatch()
private long _sophonDownloadOnlyCurrentDownloadedBytes;
private long _sophonDownloadOnlyLastDownloadedBytes;

protected void UpdateSophonFileTotalProgress(long read)

protected void UpdateSophonFileTotalProgress(long read) => UpdateSophonFileTotalProgress(read, false);

protected void UpdateSophonFileTotalProgress(long read, bool forceUpdate)
{
_ = Interlocked.Add(ref ProgressAllSizeCurrent, read);

Expand All @@ -526,7 +529,7 @@ protected void UpdateSophonFileTotalProgress(long read)
// Calculate the clamped speed for download and timelapse
double speedDownloadClamped = _sophonDownloadOnlySpeed.ClampLimitedSpeedNumber();

if (!CheckIfNeedRefreshStopwatch())
if (!CheckIfNeedRefreshStopwatch() && !forceUpdate)
{
return;
}
Expand Down
Loading
Loading