Skip to content

Commit

Permalink
Stable 1.82.13 Hotfix (#657)
Browse files Browse the repository at this point in the history
# What's new ? - 1.82.13 [Hotfix]
- **[Loc]** Localization Sync from Transifex, by Localizers <3
- **[Fix]** **[Regression]** False "Obsolete Version" detection on
Sophon method while the update is actually available, by @neon-nyan
- **[Fix]** Crash due to ``NullReferenceException`` while ``ToastCOM``'s
``NotificationService`` is failing to initialize, by @neon-nyan
- **[Imp + Fix]** UI Improvements, by @shatyuka
  - Update overlay mask on Image Cropping dialog
  - Hide all invisible system buttons
  - Implement Taskbar State/Progress API (will be used in the future)
  - Fix repair status flicker
- **[Fix]** **[Regression]** Crash while checking Cache files on Honkai
Impact 3rd, by @neon-nyan
- **[Fix]** Fix more Issues on Sophon, by @neon-nyan
- 0 total size on display while falling back from Update to Install mode
on Sophon
- Double logging while falling back from Update to Install mode on
Sophon
- **[Fix]** **[ZZZ GSP]** Wrong index assigned to the resolution list
and width rounding issue, by @neon-nyan
- If the default resolution exist on the fullscreen resolution list, the
index of that resolution will be shifted to the first index. Previously
in Collapse, it was manually added to the top while it actually not
deleted to the fullscreen list, making it duplicated. Now, it should
matches the behaviour
- Some resolution which have rounding digits might have displayed
incorrectly.

![Untitled-4](https://github.com/user-attachments/assets/c54c4a4d-5983-4833-8478-a727e41b28a6)
  • Loading branch information
neon-nyan authored Jan 5, 2025
2 parents 921215a + 2d1ad71 commit f498a09
Show file tree
Hide file tree
Showing 44 changed files with 800 additions and 450 deletions.
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

0 comments on commit f498a09

Please sign in to comment.