Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable 1.82.13 Hotfix #657

Merged
merged 24 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0dcd11a
[skip ci] Update README.md
neon-nyan Jan 2, 2025
ae2b3d0
[skip ci] Sync translation Translate en_US.json in zh_CN
transifex-integration[bot] Jan 2, 2025
cbf297c
[skip ci] Sync translation Translate en_US.json in es_419
transifex-integration[bot] Jan 2, 2025
06f1144
[skip ci] Sync translation Translate en_US.json in ja_JP
transifex-integration[bot] Jan 3, 2025
6e1c7d2
[skip ci] Sync translation Translate en_US.json in fr_FR
transifex-integration[bot] Jan 3, 2025
9100467
[Sophon] Fix "Obsolete" update issue
neon-nyan Jan 3, 2025
c7ca052
More null check on CurrentToastNotificationService
neon-nyan Jan 3, 2025
a0bd7c2
Update overlay mask according to UI changes
shatyuka Jan 4, 2025
28e3d7f
Hide all system buttons
shatyuka Jan 4, 2025
291957d
Add taskbar state/progress control api
shatyuka Jan 4, 2025
a3eab5a
[GI] Fix repair status flicker
shatyuka Jan 4, 2025
9e00bc3
Append time left string to game repair status
shatyuka Jan 4, 2025
fc4760b
Make CurrentAumid and the Guid available early
neon-nyan Jan 5, 2025
6c60c73
Bump version
neon-nyan Jan 5, 2025
5336976
Fix NaN on counting progress percentage on Hi3 cache
neon-nyan Jan 5, 2025
f76517c
[Sophon] Fix 0 total size on fallback to install mode
neon-nyan Jan 5, 2025
a331303
Fix double logging on sophon update -> install fallback
neon-nyan Jan 5, 2025
2aecbb9
[ZZZ GSP] Fix wrong index on resolution list
neon-nyan Jan 5, 2025
c51465b
[ZZZ GSP] Fix resolution rounding error
neon-nyan Jan 5, 2025
4f44fd0
[Hi3 Repair] Fix DirectoryNotFoundException and Video Metadata fetch
neon-nyan Jan 5, 2025
41f9174
[Sophon] Ensure directory creation on target file
neon-nyan Jan 5, 2025
18545e5
[Sophon] Disable verbose logging on release build
neon-nyan Jan 5, 2025
5663c80
Tidy-up LauncherConfig and Logger properties
neon-nyan Jan 5, 2025
2d1ad71
Make CodeQA happy
neon-nyan Jan 5, 2025
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
Binary file modified CollapseLauncher/Assets/Images/ImageCropperOverlay/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified CollapseLauncher/Assets/Images/ImageCropperOverlay/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void EnsureImageLoadingStarted()
if (!_isImageLoadingStarted)
{
var eventHandler = new TypedEventHandler<LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs>(HandleLoadCompleted);
_image_image_0 = LoadedImageSurface.StartLoadFromStream(File.OpenRead(Path.Combine(LauncherConfig.AppFolder, @"Assets\CollapseLauncherLogo.png")).AsRandomAccessStream());
_image_image_0 = LoadedImageSurface.StartLoadFromStream(File.OpenRead(Path.Combine(LauncherConfig.AppExecutableDir, @"Assets\CollapseLauncherLogo.png")).AsRandomAccessStream());
_image_image_0.LoadCompleted += eventHandler;
_isImageLoadingStarted = true;
}
Expand Down
77 changes: 48 additions & 29 deletions CollapseLauncher/Classes/CachesManagement/Honkai/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Hi3Helper.Http;
using Hi3Helper.UABT;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -17,6 +18,7 @@
using static Hi3Helper.Data.ConverterTool;
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault

namespace CollapseLauncher
{
Expand All @@ -41,34 +43,39 @@ private async Task<List<CacheAsset>> Fetch(CancellationToken token)
await BuildGameRepoURL(downloadClient, token);

// Iterate type and do fetch
foreach (CacheAssetType type in Enum.GetValues<CacheAssetType>())
{
// Skip for unused type
switch (type)
await Parallel.ForEachAsync(
Enum.GetValues<CacheAssetType>(),
new ParallelOptions
{
case CacheAssetType.Unused:
case CacheAssetType.Dispatcher:
case CacheAssetType.Gateway:
case CacheAssetType.General:
case CacheAssetType.IFix:
case CacheAssetType.DesignData:
case CacheAssetType.Lua:
continue;
}

// uint = Count of the assets available
// long = Total size of the assets available
(int, long) count = await FetchByType(type, downloadClient, returnAsset, token);

// Write a log about the metadata
LogWriteLine($"Cache Metadata [T: {type}]:", LogType.Default, true);
LogWriteLine($" Cache Count = {count.Item1}", LogType.NoTag, true);
LogWriteLine($" Cache Size = {SummarizeSizeSimple(count.Item2)}", LogType.NoTag, true);

// Increment the Total Size and Count
_progressAllCountTotal += count.Item1;
_progressAllSizeTotal += count.Item2;
}
MaxDegreeOfParallelism = _threadCount,
CancellationToken = token
},
async (type, ctx) =>
{
switch (type)
{
case CacheAssetType.Data:
case CacheAssetType.Event:
case CacheAssetType.AI:
{
// uint = Count of the assets available
// long = Total size of the assets available
(int, long) count = await FetchByType(type, downloadClient, returnAsset, ctx);

// Write a log about the metadata
LogWriteLine($"Cache Metadata [T: {type}]:", LogType.Default, true);
LogWriteLine($" Cache Count = {count.Item1}", LogType.NoTag, true);
LogWriteLine($" Cache Size = {SummarizeSizeSimple(count.Item2)}", LogType.NoTag, true);

// Increment the Total Size and Count
Interlocked.Add(ref _progressAllCountTotal, count.Item1);
Interlocked.Add(ref _progressAllSizeTotal, count.Item2);
}
break;
default:
return;
}
});

// Return asset index
return returnAsset;
Expand Down Expand Up @@ -230,7 +237,7 @@ private IEnumerable<CacheAsset> EnumerateCacheTextAsset(CacheAssetType type, IEn
}
}

private async ValueTask<(int, long)> BuildAssetIndex(CacheAssetType type, string baseURL, Stream stream,
private async ValueTask<ValueTuple<int, long>> BuildAssetIndex(CacheAssetType type, string baseURL, Stream stream,
List<CacheAsset> assetIndex, CancellationToken token)
{
int count = 0;
Expand Down Expand Up @@ -258,6 +265,9 @@ private IEnumerable<CacheAsset> EnumerateCacheTextAsset(CacheAssetType type, IEn
.SetAllowedDecompression(DecompressionMethods.None)
.Create();

// Use ConcurrentQueue for adding assets in parallel.
ConcurrentQueue<CacheAsset> assetQueue = [];

// Iterate lines of the TextAsset in parallel
await Parallel.ForEachAsync(EnumerateCacheTextAsset(type, dataTextAsset.GetStringList(), baseURL),
new ParallelOptions
Expand All @@ -283,9 +293,18 @@ await Parallel.ForEachAsync(EnumerateCacheTextAsset(type, dataTextAsset.GetStrin
if (!urlStatus.IsSuccessStatusCode) return;
}

assetIndex.Add(content);
// Append the content to the queue
assetQueue.Enqueue(content);

// Increment the count and size
Interlocked.Increment(ref count);
Interlocked.Add(ref size, content.CS);
});

// Take out from the ConcurrentQueue
assetIndex.AddRange(assetQueue);
assetQueue.Clear();

// Return the count and the size
return (count, size);
}
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/FileDialog/FileDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static bool IsProgramFilesPath(ReadOnlySpan<char> path)

private static bool IsCollapseProgramPath(ReadOnlySpan<char> path)
{
string collapseProgramPath = LauncherConfig.AppFolder;
string collapseProgramPath = LauncherConfig.AppExecutableDir;
if (path.StartsWith(collapseProgramPath))
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Preset(string presetJSONPath, JsonTypeInfo<Dictionary<string, T1>?> jsonT
/// <returns>The instance of preset</returns>
public static Preset<T1, TObjectType> LoadPreset(GameNameType gameType, JsonTypeInfo<Dictionary<string, T1>?> jsonType)
{
string presetPath = Path.Combine(AppFolder, $"Assets\\Presets\\{gameType}\\", $"{typeof(T1).Name}.json");
string presetPath = Path.Combine(AppExecutableDir, $"Assets\\Presets\\{gameType}\\", $"{typeof(T1).Name}.json");
return new Preset<T1, TObjectType>(presetPath, jsonType);
}

Expand Down
24 changes: 11 additions & 13 deletions CollapseLauncher/Classes/Helper/HttpClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Hi3Helper.Shared.Region;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Net.Security;
Expand All @@ -15,23 +14,23 @@ public class HttpClientBuilder : HttpClientBuilder<SocketsHttpHandler>;

public class HttpClientBuilder<THandler> where THandler : HttpMessageHandler, new()
{
private const int _maxConnectionsDefault = 32;
private const double _httpTimeoutDefault = 90; // in Seconds
private const int MaxConnectionsDefault = 32;
private const double HttpTimeoutDefault = 90; // in Seconds

private bool IsUseProxy { get; set; } = true;
private bool IsUseSystemProxy { get; set; } = true;
private bool IsAllowHttpRedirections { get; set; }
private bool IsAllowHttpCookies { get; set; }
private bool IsAllowUntrustedCert { get; set; }

private int MaxConnections { get; set; } = _maxConnectionsDefault;
private int MaxConnections { get; set; } = MaxConnectionsDefault;
private DecompressionMethods DecompressionMethod { get; set; } = DecompressionMethods.All;
private WebProxy? ExternalProxy { get; set; }
private Version HttpProtocolVersion { get; set; } = HttpVersion.Version30;
private string? HttpUserAgent { get; set; } = GetDefaultUserAgent();
private string? HttpAuthHeader { get; set; }
private HttpVersionPolicy HttpProtocolVersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower;
private TimeSpan HttpTimeout { get; set; } = TimeSpan.FromSeconds(_httpTimeoutDefault);
private TimeSpan HttpTimeout { get; set; } = TimeSpan.FromSeconds(HttpTimeoutDefault);
private Uri? HttpBaseUri { get; set; }
private Dictionary<string, string?> HttpHeaders { get; set; } = new(StringComparer.OrdinalIgnoreCase);

Expand All @@ -45,12 +44,11 @@ public HttpClientBuilder<THandler> UseProxy(bool isUseSystemProxy = true)
private static string GetDefaultUserAgent()
{
Version operatingSystemVer = Environment.OSVersion.Version;
FileVersionInfo winAppSDKVer = FileVersionInfo.GetVersionInfo("Microsoft.ui.xaml.dll");

return $"Mozilla/5.0 (Windows NT {operatingSystemVer}; Win64; x64) "
+ $"{RuntimeInformation.FrameworkDescription.Replace(' ', '/')} (KHTML, like Gecko) "
+ $"Collapse/{LauncherUpdateHelper.LauncherCurrentVersionString}-{(LauncherConfig.IsPreview ? "Preview" : "Stable")} "
+ $"WinAppSDK/{winAppSDKVer.ProductVersion}";
+ $"WinAppSDK/{LauncherConfig.WindowsAppSdkVersion}";
}

public HttpClientBuilder<THandler> UseExternalProxy(string host, string? username = null, string? password = null)
Expand Down Expand Up @@ -81,7 +79,7 @@ public HttpClientBuilder<THandler> UseExternalProxy(Uri hostUri, string? usernam
return this;
}

public HttpClientBuilder<THandler> UseLauncherConfig(int maxConnections = _maxConnectionsDefault)
public HttpClientBuilder<THandler> UseLauncherConfig(int maxConnections = MaxConnectionsDefault)
{
bool lIsUseProxy = LauncherConfig.GetAppConfigValue("IsUseProxy").ToBool();
bool lIsAllowHttpRedirections = LauncherConfig.GetAppConfigValue("IsAllowHttpRedirections").ToBool();
Expand Down Expand Up @@ -112,7 +110,7 @@ public HttpClientBuilder<THandler> UseLauncherConfig(int maxConnections = _maxCo
return this;
}

public HttpClientBuilder<THandler> SetMaxConnection(int maxConnections = _maxConnectionsDefault)
public HttpClientBuilder<THandler> SetMaxConnection(int maxConnections = MaxConnectionsDefault)
{
if (maxConnections < 2)
maxConnections = 2;
Expand Down Expand Up @@ -160,18 +158,18 @@ public HttpClientBuilder<THandler> SetHttpVersion(Version? version = null, HttpV
return this;
}

public HttpClientBuilder<THandler> SetTimeout(double fromSeconds = _httpTimeoutDefault)
public HttpClientBuilder<THandler> SetTimeout(double fromSeconds = HttpTimeoutDefault)
{
if (double.IsNaN(fromSeconds) || double.IsInfinity(fromSeconds))
fromSeconds = _httpTimeoutDefault;
fromSeconds = HttpTimeoutDefault;

return SetTimeout(TimeSpan.FromSeconds(fromSeconds));
}

public HttpClientBuilder<THandler> SetTimeout(TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromSeconds(_httpTimeoutDefault);
HttpTimeout = timeout.Value;
timeout ??= TimeSpan.FromSeconds(HttpTimeoutDefault);
HttpTimeout = timeout.Value;
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions CollapseLauncher/Classes/Helper/Image/ImageLoaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private static Waifu2X CreateWaifu2X()
{
waifu2X.SetParam(Param.Noise, -1);
waifu2X.SetParam(Param.Scale, 2);
waifu2X.Load(Path.Combine(AppFolder!, @"Assets\Waifu2X_Models\scale2.0x_model.param.bin"),
Path.Combine(AppFolder!, @"Assets\Waifu2X_Models\scale2.0x_model.bin"));
waifu2X.Load(Path.Combine(AppExecutableDir, @"Assets\Waifu2X_Models\scale2.0x_model.param.bin"),
Path.Combine(AppExecutableDir, @"Assets\Waifu2X_Models\scale2.0x_model.bin"));
_cachedStatus = waifu2X.Status;
}
return waifu2X;
Expand Down Expand Up @@ -179,7 +179,7 @@ private static async Task<FileStream> SpawnImageCropperDialog(string filePath, s
imageCropper.Opacity = 0;

// Path of image
Uri overlayImageUri = new Uri(Path.Combine(AppFolder!, @"Assets\Images\ImageCropperOverlay",
Uri overlayImageUri = new Uri(Path.Combine(AppExecutableDir, @"Assets\Images\ImageCropperOverlay",
GetAppConfigValue("WindowSizeProfile").ToString() == "Small" ? "small.png" : "normal.png"));

// Why not use ImageBrush?
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/Helper/Image/Waifu2X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static Waifu2XPInvoke()

private static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
appDirPath ??= LauncherConfig.AppFolder;
appDirPath ??= LauncherConfig.AppExecutableDir;

if (DllImportSearchPath.AssemblyDirectory != searchPath
&& DllImportSearchPath.ApplicationDirectory != searchPath)
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/Helper/TaskSchedulerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static async Task<int> GetInvokeCommandReturnCode(string argument)
const string retValMark = "RETURNVAL_";

// Get the applet path and check if the file exist
string appletPath = Path.Combine(LauncherConfig.AppFolder, "Lib", "win-x64", "Hi3Helper.TaskScheduler.exe");
string appletPath = Path.Combine(LauncherConfig.AppExecutableDir, "Lib", "win-x64", "Hi3Helper.TaskScheduler.exe");
if (!File.Exists(appletPath))
{
Logger.LogWriteLine($"Task Scheduler Applet does not exist in this path: {appletPath}", LogType.Error, true);
Expand Down
21 changes: 5 additions & 16 deletions CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Hi3Helper.Shared.Region;
using System;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

#if !USEVELOPACK
using Squirrel;
using Squirrel.Sources;
Expand All @@ -20,26 +22,13 @@ namespace CollapseLauncher.Helper.Update
{
internal static class LauncherUpdateHelper
{
static LauncherUpdateHelper()
{
string? versionString = LauncherConfig.AppCurrentVersionString;
if (string.IsNullOrEmpty(versionString))
throw new NullReferenceException("App cannot retrieve the current version of the executable!");

_launcherCurrentVersion = new GameVersion(versionString);
_launcherCurrentVersionString = _launcherCurrentVersion.VersionString;
}

internal static AppUpdateVersionProp? AppUpdateVersionProp;
internal static bool IsLauncherUpdateAvailable;

private static readonly GameVersion _launcherCurrentVersion;
internal static GameVersion? LauncherCurrentVersion
=> _launcherCurrentVersion;
internal static GameVersion? LauncherCurrentVersion => field ??= new(LauncherConfig.AppCurrentVersionString);

private static readonly string _launcherCurrentVersionString;
internal static string LauncherCurrentVersionString
=> _launcherCurrentVersionString;
[field: AllowNull, MaybeNull]
internal static string LauncherCurrentVersionString => field = LauncherConfig.AppCurrentVersionString;

internal static async Task RunUpdateCheckDetached()
{
Expand Down
Loading
Loading