Skip to content

Commit 5663c80

Browse files
committed
Tidy-up LauncherConfig and Logger properties
1 parent 18545e5 commit 5663c80

File tree

24 files changed

+358
-304
lines changed

24 files changed

+358
-304
lines changed

CollapseLauncher/Classes/AnimatedVisuals/Lottie/NewLogoTitleIntro.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void EnsureImageLoadingStarted()
156156
if (!_isImageLoadingStarted)
157157
{
158158
var eventHandler = new TypedEventHandler<LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs>(HandleLoadCompleted);
159-
_image_image_0 = LoadedImageSurface.StartLoadFromStream(File.OpenRead(Path.Combine(LauncherConfig.AppFolder, @"Assets\CollapseLauncherLogo.png")).AsRandomAccessStream());
159+
_image_image_0 = LoadedImageSurface.StartLoadFromStream(File.OpenRead(Path.Combine(LauncherConfig.AppExecutableDir, @"Assets\CollapseLauncherLogo.png")).AsRandomAccessStream());
160160
_image_image_0.LoadCompleted += eventHandler;
161161
_isImageLoadingStarted = true;
162162
}

CollapseLauncher/Classes/FileDialog/FileDialogHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static bool IsProgramFilesPath(ReadOnlySpan<char> path)
150150

151151
private static bool IsCollapseProgramPath(ReadOnlySpan<char> path)
152152
{
153-
string collapseProgramPath = LauncherConfig.AppFolder;
153+
string collapseProgramPath = LauncherConfig.AppExecutableDir;
154154
if (path.StartsWith(collapseProgramPath))
155155
return true;
156156

CollapseLauncher/Classes/GameManagement/GameSettings/Honkai/RegistryClass/Preset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Preset(string presetJSONPath, JsonTypeInfo<Dictionary<string, T1>?> jsonT
6868
/// <returns>The instance of preset</returns>
6969
public static Preset<T1, TObjectType> LoadPreset(GameNameType gameType, JsonTypeInfo<Dictionary<string, T1>?> jsonType)
7070
{
71-
string presetPath = Path.Combine(AppFolder, $"Assets\\Presets\\{gameType}\\", $"{typeof(T1).Name}.json");
71+
string presetPath = Path.Combine(AppExecutableDir, $"Assets\\Presets\\{gameType}\\", $"{typeof(T1).Name}.json");
7272
return new Preset<T1, TObjectType>(presetPath, jsonType);
7373
}
7474

CollapseLauncher/Classes/Helper/HttpClientBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public HttpClientBuilder<THandler> UseProxy(bool isUseSystemProxy = true)
4545
private static string GetDefaultUserAgent()
4646
{
4747
Version operatingSystemVer = Environment.OSVersion.Version;
48-
FileVersionInfo winAppSDKVer = FileVersionInfo.GetVersionInfo("Microsoft.ui.xaml.dll");
4948

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

5655
public HttpClientBuilder<THandler> UseExternalProxy(string host, string? username = null, string? password = null)

CollapseLauncher/Classes/Helper/Image/ImageLoaderHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private static Waifu2X CreateWaifu2X()
8989
{
9090
waifu2X.SetParam(Param.Noise, -1);
9191
waifu2X.SetParam(Param.Scale, 2);
92-
waifu2X.Load(Path.Combine(AppFolder!, @"Assets\Waifu2X_Models\scale2.0x_model.param.bin"),
93-
Path.Combine(AppFolder!, @"Assets\Waifu2X_Models\scale2.0x_model.bin"));
92+
waifu2X.Load(Path.Combine(AppExecutableDir, @"Assets\Waifu2X_Models\scale2.0x_model.param.bin"),
93+
Path.Combine(AppExecutableDir, @"Assets\Waifu2X_Models\scale2.0x_model.bin"));
9494
_cachedStatus = waifu2X.Status;
9595
}
9696
return waifu2X;
@@ -179,7 +179,7 @@ private static async Task<FileStream> SpawnImageCropperDialog(string filePath, s
179179
imageCropper.Opacity = 0;
180180

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

185185
// Why not use ImageBrush?

CollapseLauncher/Classes/Helper/Image/Waifu2X.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static Waifu2XPInvoke()
2828

2929
private static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
3030
{
31-
appDirPath ??= LauncherConfig.AppFolder;
31+
appDirPath ??= LauncherConfig.AppExecutableDir;
3232

3333
if (DllImportSearchPath.AssemblyDirectory != searchPath
3434
&& DllImportSearchPath.ApplicationDirectory != searchPath)

CollapseLauncher/Classes/Helper/TaskSchedulerHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private static async Task<int> GetInvokeCommandReturnCode(string argument)
233233
const string retValMark = "RETURNVAL_";
234234

235235
// Get the applet path and check if the file exist
236-
string appletPath = Path.Combine(LauncherConfig.AppFolder, "Lib", "win-x64", "Hi3Helper.TaskScheduler.exe");
236+
string appletPath = Path.Combine(LauncherConfig.AppExecutableDir, "Lib", "win-x64", "Hi3Helper.TaskScheduler.exe");
237237
if (!File.Exists(appletPath))
238238
{
239239
Logger.LogWriteLine($"Task Scheduler Applet does not exist in this path: {appletPath}", LogType.Error, true);

CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using Hi3Helper.Shared.Region;
66
using System;
77
using System.Threading.Tasks;
8+
using System.Diagnostics.CodeAnalysis;
9+
810
#if !USEVELOPACK
911
using Squirrel;
1012
using Squirrel.Sources;
@@ -20,26 +22,13 @@ namespace CollapseLauncher.Helper.Update
2022
{
2123
internal static class LauncherUpdateHelper
2224
{
23-
static LauncherUpdateHelper()
24-
{
25-
string? versionString = LauncherConfig.AppCurrentVersionString;
26-
if (string.IsNullOrEmpty(versionString))
27-
throw new NullReferenceException("App cannot retrieve the current version of the executable!");
28-
29-
_launcherCurrentVersion = new GameVersion(versionString);
30-
_launcherCurrentVersionString = _launcherCurrentVersion.VersionString;
31-
}
32-
3325
internal static AppUpdateVersionProp? AppUpdateVersionProp;
3426
internal static bool IsLauncherUpdateAvailable;
3527

36-
private static readonly GameVersion _launcherCurrentVersion;
37-
internal static GameVersion? LauncherCurrentVersion
38-
=> _launcherCurrentVersion;
28+
internal static GameVersion? LauncherCurrentVersion => field ??= new(LauncherConfig.AppCurrentVersionString);
3929

40-
private static readonly string _launcherCurrentVersionString;
41-
internal static string LauncherCurrentVersionString
42-
=> _launcherCurrentVersionString;
30+
[field: AllowNull, MaybeNull]
31+
internal static string LauncherCurrentVersionString => field = LauncherConfig.AppCurrentVersionString;
4332

4433
internal static async Task RunUpdateCheckDetached()
4534
{

CollapseLauncher/Classes/Properties/InnerLauncherConfig.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public enum AppMode
4646
public static AppMode m_appMode;
4747
public static Arguments m_arguments = new();
4848
public static bool m_isWindows11;
49-
public static IntPtr m_oldWndProc;
50-
public static Delegate? m_newWndProcDelegate;
5149
public static ConsoleControlHandler? m_consoleCtrlHandler;
5250
public static MainPage? m_mainPage;
5351
public static HomePage? m_homePage;

CollapseLauncher/Classes/RegionManagement/RegionManagement.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ private async Task DownloadBackgroundImage(CancellationToken Token)
202202
var currentGameType = GamePropertyVault.GetCurrentGameProperty()._GameVersion.GameType;
203203
tempImage ??= currentGameType switch
204204
{
205-
GameNameType.Honkai => Path.Combine(AppFolder, @"Assets\Images\GameBackground\honkai.webp"),
206-
GameNameType.Genshin => Path.Combine(AppFolder, @"Assets\Images\GameBackground\genshin.webp"),
207-
GameNameType.StarRail => Path.Combine(AppFolder, @"Assets\Images\GameBackground\starrail.webp"),
208-
GameNameType.Zenless => Path.Combine(AppFolder, @"Assets\Images\GameBackground\zzz.webp"),
205+
GameNameType.Honkai => Path.Combine(AppExecutableDir, @"Assets\Images\GameBackground\honkai.webp"),
206+
GameNameType.Genshin => Path.Combine(AppExecutableDir, @"Assets\Images\GameBackground\genshin.webp"),
207+
GameNameType.StarRail => Path.Combine(AppExecutableDir, @"Assets\Images\GameBackground\starrail.webp"),
208+
GameNameType.Zenless => Path.Combine(AppExecutableDir, @"Assets\Images\GameBackground\zzz.webp"),
209209
_ => AppDefaultBG
210210
};
211211
BackgroundImgChanger.ChangeBackground(tempImage, () =>

0 commit comments

Comments
 (0)