Skip to content

Commit 626989f

Browse files
authored
Preview 1.82.5 Release (#618)
# What's new? - 1.82.5 - **[Fix]** Various weird errors that might be caused by Optimization preference, by @neon-nyan & @bagusnl - We are noticing quite odd behaviors with some functions, critically Sophon and Http downloader and also SevenZipExtractor modules - This error does not seem to be reproducible in Debug environment, but recent development by @neon-nyan found that setting the optimization profile to `Speed` may cause compiler over optimization in certain areas. - This fix set the project's compiler optimization to `Size` instead (which is the default .NET behaviour). - If this fixes those errors that were problematic then good, if not then we have to rethink about those problematic modules... - **[Fix]** Exceptions in Carousel methods, by @bagusnl - Third time the charm 🤞 - **[Fix]** DirectoryNotFound exception in HTTP module, by @bagusnl - **[Imp]** Only recreate shortcut once, by @bagusnl - Please, no more re-pinning my shortcut... - **[Fix]** App crash when finalizing update, by @bagusnl - **[Fix]** Prevent image load fails when waifu2x failes to load / nulled, by @shatyuka - **[Fix]** (Attempt to) Fix corruption when extracting packages via SevenZipExtractor, by @neon-nyan
2 parents 2c06d09 + 1d56b4f commit 626989f

39 files changed

+605
-155
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
- name: Build
5151
run: |
52-
dotnet publish CollapseLauncher -p:PublishProfile=Publish-DebugCIRelease -p:PublishDir=".\debug-build\"
52+
dotnet publish CollapseLauncher -c ${{matrix.Configuration}} -p:PublishProfile=Publish-DebugCIRelease -p:PublishDir=".\debug-build\"
5353
5454
- name: Upload Artifact
5555
uses: actions/[email protected]
@@ -94,7 +94,7 @@ jobs:
9494

9595
- name: Build
9696
run: |
97-
dotnet publish CollapseLauncher -p:PublishProfile=Publish-DebugCIReleaseAOT -p:PublishDir=".\debug-aot-build\"
97+
dotnet publish CollapseLauncher -c ${{matrix.Configuration}} -p:PublishProfile=Publish-DebugCIReleaseAOT -p:PublishDir=".\debug-aot-build\"
9898
9999
- name: Upload Artifact
100100
uses: actions/[email protected]

CollapseLauncher/Classes/GameManagement/GameVersion/BaseClass/GameVersionBase.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,21 @@ private bool IsTryParseIniVersionExist(string iniPath)
11401140
return false;
11411141
}
11421142

1143-
private bool IsDiskPartitionExist(string path) => !string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(Path.GetPathRoot(path)) && new DriveInfo(Path.GetPathRoot(path) ?? string.Empty).IsReady;
1143+
private bool IsDiskPartitionExist(string path)
1144+
{
1145+
try
1146+
{
1147+
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(Path.GetPathRoot(path)))
1148+
{
1149+
return false;
1150+
}
1151+
return new DriveInfo(Path.GetPathRoot(path) ?? string.Empty).IsReady;
1152+
}
1153+
catch (Exception)
1154+
{
1155+
return false;
1156+
}
1157+
}
11441158

11451159
private void SaveGameIni(string filePath, in IniFile INI)
11461160
{

CollapseLauncher/Classes/Helper/Image/ImageLoaderHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static Waifu2XStatus Waifu2XStatus
7070

7171
public static bool IsWaifu2XEnabled
7272
{
73-
get => GetAppConfigValue("EnableWaifu2X").ToBool() && IsWaifu2XUsable;
73+
get => GetAppConfigValue("EnableWaifu2X").ToBool() && IsWaifu2XUsable && _waifu2X != null;
7474
set
7575
{
7676
SetAndSaveConfigValue("EnableWaifu2X", value);

CollapseLauncher/Classes/Helper/TaskSchedulerHelper.cs

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Threading.Tasks;
1010

11+
#nullable enable
1112
namespace CollapseLauncher.Helper
1213
{
1314
internal static class TaskSchedulerHelper
@@ -143,49 +144,77 @@ private static void AppendTaskNameAndPathArgument(StringBuilder argumentBuilder)
143144

144145
internal static void RecreateIconShortcuts()
145146
{
146-
/* Invocation from Hi3Helper.TaskScheduler is no longer being user.
147-
* Moving to Main App's ShellLink implementation instead!
148-
149-
// Build the argument and get the current executable path
150-
StringBuilder argumentBuilder = new StringBuilder();
151-
argumentBuilder.Append("RecreateIcons");
152-
string currentExecPath = LauncherConfig.AppExecutablePath;
147+
// Get icons paths
148+
(string iconLocationStartMenu, string iconLocationDesktop)
149+
= GetIconLocationPaths(
150+
out _,
151+
out string? appDescription,
152+
out string? executablePath,
153+
out string? workingDirPath);
153154

154-
// Build argument to the executable path
155-
argumentBuilder.Append(" \"");
156-
argumentBuilder.Append(currentExecPath);
157-
argumentBuilder.Append('"');
155+
// Create shell link instance and save the shortcut under Desktop and User's Start menu
156+
CreateShortcut(iconLocationStartMenu, appDescription, executablePath, workingDirPath);
157+
CreateShortcut(iconLocationDesktop, appDescription, executablePath, workingDirPath);
158+
}
158159

159-
// Store argument builder as string
160-
string argumentString = argumentBuilder.ToString();
160+
private static void CreateShortcut(
161+
string iconLocation,
162+
string? appDescription,
163+
string? executablePath,
164+
string? workingDirPath)
165+
{
166+
// Try create icon location directory
167+
string iconLocationDir = Path.GetDirectoryName(iconLocation) ?? "";
161168

162-
// Invoke applet
163-
int returnCode = await GetInvokeCommandReturnCode(argumentString);
169+
// Try create directory
170+
Directory.CreateDirectory(iconLocationDir);
171+
172+
// Create ShellLink instance
173+
using ShellLink shellLink = new ShellLink();
164174

165-
// Print init determination
166-
CheckInitDetermination(returnCode);
167-
*/
175+
// If existing icon exist, try open it
176+
try
177+
{
178+
if (File.Exists(iconLocation))
179+
shellLink.Open(iconLocation);
180+
}
181+
catch (Exception ex)
182+
{
183+
string msg = $"An error occurred while opening existing icon file at: {iconLocation}";
184+
SentryHelper.ExceptionHandler(new Exception(msg, ex));
185+
Logger.LogWriteLine(msg + $"\r\n{ex}", LogType.Error, true);
186+
}
187+
188+
// Set params on the shortcut instance
189+
shellLink.IconIndex = 0;
190+
shellLink.IconPath = executablePath ?? "";
191+
shellLink.DisplayMode = LinkDisplayMode.edmNormal;
192+
shellLink.WorkingDirectory = workingDirPath ?? "";
193+
shellLink.Target = executablePath ?? "";
194+
shellLink.Description = appDescription ?? "";
195+
196+
// Save the icons
197+
shellLink.Save(iconLocation);
198+
}
168199

200+
internal static (string IconStartMenu, string IconDesktop) GetIconLocationPaths(
201+
out string? appProductName,
202+
out string? appDescription,
203+
out string? executablePath,
204+
out string? workingDirPath)
205+
{
169206
// Get current executable path as its target.
170-
string currentExecPath = LauncherConfig.AppExecutablePath;
171-
string workingDirPath = Path.GetDirectoryName(currentExecPath);
207+
executablePath = LauncherConfig.AppExecutablePath;
208+
workingDirPath = Path.GetDirectoryName(executablePath);
172209

173210
// Get exe's description
174-
FileVersionInfo currentExecVersionInfo = FileVersionInfo.GetVersionInfo(currentExecPath);
175-
string currentExecDescription = currentExecVersionInfo.FileDescription ?? "";
176-
177-
// Create shell link instance and save the shortcut under Desktop and User's Start menu
178-
using ShellLink shellLink = new ShellLink();
179-
shellLink.IconIndex = 0;
180-
shellLink.IconPath = currentExecPath;
181-
shellLink.DisplayMode = LinkDisplayMode.edmNormal;
182-
shellLink.WorkingDirectory = workingDirPath ?? "";
183-
shellLink.Target = currentExecPath;
184-
shellLink.Description = currentExecDescription;
211+
FileVersionInfo currentExecVersionInfo = FileVersionInfo.GetVersionInfo(executablePath);
212+
appDescription = currentExecVersionInfo.FileDescription ?? "";
185213

186214
// Get paths
187-
string shortcutFilename = currentExecVersionInfo.ProductName + ".lnk";
188-
string startMenuLocation = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
215+
appProductName = currentExecVersionInfo.ProductName;
216+
string shortcutFilename = appProductName + ".lnk";
217+
string startMenuLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
189218
string desktopLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
190219
string iconLocationStartMenu = Path.Combine(
191220
startMenuLocation,
@@ -196,17 +225,7 @@ internal static void RecreateIconShortcuts()
196225
desktopLocation,
197226
shortcutFilename);
198227

199-
// Get icon location directory
200-
string iconLocationStartMenuDir = Path.GetDirectoryName(iconLocationStartMenu);
201-
string iconLocationDesktopDir = Path.GetDirectoryName(iconLocationDesktop);
202-
203-
// Try create directory
204-
Directory.CreateDirectory(iconLocationStartMenuDir!);
205-
Directory.CreateDirectory(iconLocationDesktopDir!);
206-
207-
// Save the icons
208-
shellLink.Save(iconLocationStartMenu);
209-
shellLink.Save(iconLocationDesktop);
228+
return (iconLocationStartMenu, iconLocationDesktop);
210229
}
211230

212231
private static async Task<int> GetInvokeCommandReturnCode(string argument)
@@ -243,7 +262,7 @@ private static async Task<int> GetInvokeCommandReturnCode(string argument)
243262
process.Start();
244263
while (!process.StandardOutput.EndOfStream)
245264
{
246-
string consoleStdOut = await process.StandardOutput.ReadLineAsync();
265+
string? consoleStdOut = await process.StandardOutput.ReadLineAsync();
247266
Logger.LogWriteLine("[TaskScheduler] " + consoleStdOut, LogType.Debug, true);
248267

249268
// Parse if it has RETURNVAL_

CollapseLauncher/Classes/Helper/WindowUtility.cs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Hi3Helper.Win32.Native.ManagedTools;
1111
using Hi3Helper.Win32.Native.Structs;
1212
using Hi3Helper.Win32.Screen;
13+
using Hi3Helper.Win32.ToastCOM.Notification;
1314
using Microsoft.Graphics.Display;
1415
using Microsoft.UI;
1516
using Microsoft.UI.Composition.SystemBackdrops;
@@ -19,6 +20,7 @@
1920
using Microsoft.UI.Xaml;
2021
using Microsoft.UI.Xaml.Media;
2122
using System;
23+
using System.Collections.Generic;
2224
using System.Runtime.InteropServices;
2325
using Windows.Foundation;
2426
using Windows.Graphics;
@@ -283,6 +285,45 @@ internal static IconShowOptions CurrentWindowTitlebarIconShowOption
283285
}
284286
}
285287

288+
private static NotificationService? _currentToastNotificationService;
289+
internal static NotificationService? CurrentToastNotificationService
290+
{
291+
get
292+
{
293+
// If toast notification service field is null, then initialize
294+
if (_currentToastNotificationService == null)
295+
{
296+
// Get Icon location paths
297+
(string iconLocationStartMenu, _)
298+
= TaskSchedulerHelper.GetIconLocationPaths(
299+
out string? appAumIdName,
300+
out _,
301+
out string? executablePath,
302+
out _);
303+
304+
// Register notification service
305+
_currentToastNotificationService = new NotificationService(ILoggerHelper.GetILogger("ToastCOM"));
306+
307+
// Get string for AumId registration
308+
if (!string.IsNullOrEmpty(appAumIdName))
309+
{
310+
// Initialize Toast Notification service
311+
_currentToastNotificationService.Initialize(
312+
appAumIdName,
313+
executablePath ?? "",
314+
iconLocationStartMenu,
315+
asElevatedUser: true
316+
);
317+
318+
// Subscribe ToastCallback
319+
_currentToastNotificationService.ToastCallback += Service_ToastNotificationCallback;
320+
}
321+
}
322+
323+
return _currentToastNotificationService;
324+
}
325+
}
326+
286327
internal static void RegisterWindow(this Window window)
287328
{
288329
// Uninstall existing drag area change
@@ -339,7 +380,6 @@ private static void WindowDragAreaChangeEventHandler(object? sender, RectInt32[]
339380
#endregion
340381

341382
#region WndProc Handler
342-
343383
private static IntPtr InstallWndProcCallback(IntPtr hwnd, WndProcDelegate wndProc)
344384
{
345385
// Install WndProc hook
@@ -486,7 +526,6 @@ private static IntPtr MainWndProc(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr
486526
#endregion
487527

488528
#region Titlebar Methods
489-
490529
private static void ApplyWindowTitlebarContextFix()
491530
{
492531
if (!CurrentWindowId.HasValue)
@@ -560,11 +599,9 @@ internal static void SetWindowTitlebarIcon(nint smallIconPtr, nint largeIconPtr)
560599

561600
Windowing.SetWindowIcon(CurrentWindowPtr, smallIconPtr, largeIconPtr);
562601
}
563-
564602
#endregion
565603

566604
#region Window state methods
567-
568605
private static void ApplyWindowBorderFix()
569606
{
570607
// Hide window border but keep drop shadow
@@ -691,7 +728,6 @@ internal static bool IsCurrentWindowInFocus()
691728
IntPtr currentForegroundWindow = PInvoke.GetForegroundWindow();
692729
return CurrentWindowPtr == currentForegroundWindow;
693730
}
694-
695731
#endregion
696732

697733
#region Tray Icon Invoker
@@ -718,7 +754,7 @@ public static void ToggleToTray_AllWindow()
718754
}
719755

720756
/// <summary>
721-
/// <inheritdoc cref="CollapseLauncher.TrayIcon.ShowNotification"/>
757+
/// <inheritdoc cref="TrayIcon.ShowNotification"/>
722758
/// </summary>
723759
/// <param name="title">The title to display on the balloon tip.</param>
724760
/// <param name="message">The text to display on the balloon tip.</param>
@@ -774,6 +810,16 @@ private static void TrayNullHandler(string caller)
774810
Logger.LogWriteLine($"TrayIcon is null/not initialized!\r\n\tCalled by: {caller}");
775811
}
776812

813+
private static void Service_ToastNotificationCallback(string app, string arg, Dictionary<string, string?>? userInputData)
814+
{
815+
if (CurrentWindow is not MainWindow window) return;
816+
817+
// If the MainWindow is currently active, then set the window
818+
// to foreground.
819+
window._TrayIcon?.ToggleAllVisibility();
820+
821+
// TODO: Make the callback actually usable on elevated app
822+
}
777823
#endregion
778824
}
779825
}

CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ protected void TryUnassignReadOnlyFiles(string path)
495495
foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
496496
{
497497
FileInfo fileInfo = new FileInfo(file);
498-
if (fileInfo.IsReadOnly)
498+
if (fileInfo is { Exists: true, IsReadOnly: true })
499499
fileInfo.IsReadOnly = false;
500500
}
501501
}

CollapseLauncher/Classes/RegionManagement/FallbackCDNUtil.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ private static async ValueTask<bool> TryGetCDNContent(CDNURLProperty cdnProp, Do
375375
// Handle the error and log it. If fails, then log it and return false
376376
catch (Exception ex)
377377
{
378-
await SentryHelper.ExceptionHandlerAsync(ex, SentryHelper.ExceptionType.UnhandledOther);
379378
LogWriteLine($"Failed while getting CDN content from: {cdnProp.Name} (prefix: {cdnProp.URLPrefix}) (relPath: {relativeURL})\r\n{ex}", LogType.Error, true);
380379
return false;
381380
}
@@ -439,8 +438,8 @@ private static async ValueTask<CDNUtilHTTPStatus> TryGetURLStatus(CDNURLProperty
439438
}
440439
catch (Exception ex)
441440
{
442-
await SentryHelper.ExceptionHandlerAsync(ex, SentryHelper.ExceptionType.UnhandledOther);
443441
LogWriteLine($"CDN content from: {cdnProp.Name} (prefix: {cdnProp.URLPrefix}) (relPath: {relativeURL}) has failed to initialize due to an exception:\r\n{ex}", LogType.Error, true);
442+
await SentryHelper.ExceptionHandlerAsync(ex);
444443
return CDNUtilHTTPStatus.CreateInitializationError();
445444
}
446445
}

CollapseLauncher/Classes/RepairManagement/Genshin/GenshinRepair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private async Task<bool> CheckRoutine()
6868
ResetStatusAndProgress();
6969
_assetIndex.Clear();
7070

71-
// Step 1: Ensure that every files are not read-only
71+
// Step 1: Ensure that every file are not read-only
7272
TryUnassignReadOnlyFiles(_gamePath);
7373

7474
// Step 2: Fetch asset index

CollapseLauncher/Classes/RepairManagement/Zenless/ZenlessRepair.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ private async Task<bool> CheckRoutine()
122122

123123
// Step 4: Summarize and returns true if the assetIndex count != 0 indicates broken file was found.
124124
// either way, returns false.
125+
string status3Msg = IsCacheUpdateMode ? Locale.Lang._CachesPage.CachesStatusNeedUpdate : Locale.Lang._GameRepairPage.Status3;
126+
string status4Msg = IsCacheUpdateMode ? Locale.Lang._CachesPage.CachesStatusUpToDate : Locale.Lang._GameRepairPage.Status4;
125127
return SummarizeStatusAndProgress(
126128
_assetIndex,
127-
string.Format(Locale.Lang._GameRepairPage.Status3, _progressAllCountFound, ConverterTool.SummarizeSizeSimple(_progressAllSizeFound)),
128-
Locale.Lang._GameRepairPage.Status4);
129+
string.Format(status3Msg, _progressAllCountFound, ConverterTool.SummarizeSizeSimple(_progressAllSizeFound)),
130+
status4Msg);
129131
}
130132

131133
private async Task<bool> RepairRoutine()
@@ -147,7 +149,7 @@ private async Task<bool> RepairRoutine()
147149
{
148150
_status.IsCompleted = true;
149151
_status.IsCanceled = false;
150-
_status.ActivityStatus = Locale.Lang._GameRepairPage.Status7;
152+
_status.ActivityStatus = IsCacheUpdateMode ? Locale.Lang._CachesPage.CachesStatusUpToDate : Locale.Lang._GameRepairPage.Status7;
151153
}
152154

153155
// Update status and progress

0 commit comments

Comments
 (0)