From 982cbfcf5eae6fcc93b92cfc6d05fd1f8bc12536 Mon Sep 17 00:00:00 2001 From: Bagus Nur Listiyono Date: Sun, 4 Aug 2024 17:41:49 +0700 Subject: [PATCH 01/22] [ZZZ GSP] Add experimental Mobile Mode toggle --- .../ZenlessGameSettingsPage.Ext.cs | 13 +++++++++++-- .../GameSettingsPages/ZenlessGameSettingsPage.xaml | 4 +--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs index af9874f1e..9675bf970 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs @@ -301,8 +301,17 @@ public bool IsGameBoost public bool IsMobileMode { - get => Settings?.SettingsCollapseMisc?.LaunchMobileMode ?? false; - set => Settings.SettingsCollapseMisc.LaunchMobileMode = value; + get + { + var cSet = Settings?.SettingsCollapseMisc?.LaunchMobileMode ?? false; + var gSet = Settings.GeneralData.LocalUILayoutPlatform == 1; + return cSet || gSet; + } + set + { + Settings.SettingsCollapseMisc.LaunchMobileMode = value; + Settings.GeneralData.LocalUILayoutPlatform = value ? 1 : 3; + } } #endregion diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml index 5b60e918c..28bd8cd81 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml +++ b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml @@ -162,9 +162,7 @@ + IsChecked="{x:Bind IsMobileMode, Mode=TwoWay}"> From afeb190ebcd2a8a6ab0dbfa7cb61d5e5747b3038 Mon Sep 17 00:00:00 2001 From: Bagus Nur Listiyono Date: Thu, 19 Dec 2024 16:04:26 +0700 Subject: [PATCH 02/22] what in the absolute FRICK - Fix cleanup method when using >1000 files DO NOT ASK HOW LONG THIS TOOK --- .../InstallManagerBase.PkgVersion.cs | 76 ++--- .../XAMLs/MainApp/Pages/FileCleanupPage.xaml | 2 +- .../MainApp/Pages/FileCleanupPage.xaml.cs | 277 +++++++++++++++--- 3 files changed, 274 insertions(+), 81 deletions(-) diff --git a/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.PkgVersion.cs b/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.PkgVersion.cs index 35493cd82..c01eb37f2 100644 --- a/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.PkgVersion.cs +++ b/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.PkgVersion.cs @@ -102,7 +102,7 @@ public virtual async ValueTask CleanUpGameFiles(bool withDialog = true) { // Get the unused file info asynchronously List unusedFileInfo = await GetUnusedFileInfoList(withDialog); - + // Spawn dialog if used if (withDialog) { @@ -113,11 +113,13 @@ public virtual async ValueTask CleanUpGameFiles(bool withDialog = true) mainWindow.overlayFrame.Navigate(typeof(FileCleanupPage), null, new DrillInNavigationTransitionInfo()); } - + if (FileCleanupPage.Current == null) return; - - FileCleanupPage.Current.InjectFileInfoSource(unusedFileInfo); + await FileCleanupPage.Current.InjectFileInfoSource(unusedFileInfo); + + LoadingMessageHelper.HideLoadingFrame(); + FileCleanupPage.Current.MenuExitButton.Click += ExitFromOverlay; FileCleanupPage.Current.MenuReScanButton.Click += ExitFromOverlay; FileCleanupPage.Current.MenuReScanButton.Click += async (_, _) => @@ -170,9 +172,9 @@ protected virtual async Task> GetUnusedFileInfoList(bool inc { // Initialize new proxy-aware HttpClient using HttpClient httpClient = new HttpClientBuilder() - .UseLauncherConfig(_downloadThreadCount + _downloadThreadCountReserved) - .SetAllowedDecompression(DecompressionMethods.None) - .Create(); + .UseLauncherConfig(_downloadThreadCount + _downloadThreadCountReserved) + .SetAllowedDecompression(DecompressionMethods.None) + .Create(); // Initialize and get game state, then get the latest package info LoadingMessageHelper.SetMessage( @@ -238,9 +240,10 @@ await DownloadOtherAudioPkgVersion(_gameAudioLangListPathStatic, true); } } - + // Add pre-download zips into the ignored list - RegionResourceVersion? packagePreDownloadList = _gameVersionManager.GetGamePreloadZip()?.FirstOrDefault(); + RegionResourceVersion? packagePreDownloadList = + _gameVersionManager.GetGamePreloadZip()?.FirstOrDefault(); if (packagePreDownloadList != null) { var preDownloadZips = new List(); @@ -253,7 +256,7 @@ await DownloadOtherAudioPkgVersion(_gameAudioLangListPathStatic, preDownloadZips.AddRange(packagePreDownloadList.voice_packs .Select(audioRes => new GameInstallPackage(audioRes, - _gamePath) + _gamePath) { PackageType = GameInstallPackageType.Audio @@ -268,11 +271,11 @@ await DownloadOtherAudioPkgVersion(_gameAudioLangListPathStatic, ignoredFiles = ignoredFiles.Concat(preDownloadZips).ToArray(); } } - + if (ignoredFiles.Length > 0) LogWriteLine($"[GetUnusedFileInfoList] Final ignored file list:\r\n{string.Join(", ", ignoredFiles)}", LogType.Scheme, true); - + // Get the list of the local file paths List localFileInfo = []; await GetRelativeLocalFilePaths(localFileInfo, includeZipCheck, gameStateEnum, _token.Token); @@ -295,9 +298,10 @@ await Task.Run(() => return unusedFileInfo; } - finally + catch (Exception ex) { - LoadingMessageHelper.HideLoadingFrame(); + ErrorSender.SendException(ex); + return new List(); } } @@ -465,14 +469,15 @@ protected virtual async Task GetRelativeLocalFilePaths(List local { await Task.Run(() => { - int count = 0; - long totalSize = 0; - string gamePath = _gamePath; - DirectoryInfo dirInfo = new DirectoryInfo(gamePath); + int count = 0; + long totalSize = 0; + string gamePath = _gamePath; + DirectoryInfo dirInfo = new DirectoryInfo(gamePath); + int updateInterval = 100; // Update UI every 100 files + int processedCount = 0; // Do the do in parallel since it will be a really CPU expensive task due to janky checks here and there. - Parallel.ForEach(dirInfo - .EnumerateFiles("*", SearchOption.AllDirectories), + Parallel.ForEach(dirInfo.EnumerateFiles("*", SearchOption.AllDirectories), new ParallelOptions { CancellationToken = token }, (fileInfo, _) => { @@ -481,23 +486,26 @@ await Task.Run(() => // Do the check within the lambda function to possibly check the file // condition in multithread - if (!IsCategorizedAsGameFile(fileInfo, gamePath, includeZipCheck, - gameState, - out LocalFileInfo localFileInfo)) + if (!IsCategorizedAsGameFile(fileInfo, gamePath, includeZipCheck, gameState, out LocalFileInfo localFileInfo)) return; - Interlocked.Add(ref totalSize, - fileInfo.Exists ? fileInfo.Length : 0); + Interlocked.Add(ref totalSize, fileInfo.Exists ? fileInfo.Length : 0); Interlocked.Increment(ref count); - _parentUI.DispatcherQueue.TryEnqueue(() => - LoadingMessageHelper.SetMessage( - Locale.Lang._FileCleanupPage.LoadingTitle, - string - .Format(Locale.Lang._FileCleanupPage.LoadingSubtitle1, - count, - ConverterTool - .SummarizeSizeSimple(totalSize)) - )); + int currentCount = Interlocked.Increment(ref processedCount); + + if (currentCount % updateInterval == 0) + { + _parentUI.DispatcherQueue.TryEnqueue(() => + { + LoadingMessageHelper.SetMessage( + Locale.Lang._FileCleanupPage.LoadingTitle, + string.Format(Locale.Lang._FileCleanupPage.LoadingSubtitle1, + count, + ConverterTool.SummarizeSizeSimple(totalSize)) + ); + }); + } + lock (localFileInfoList) { localFileInfoList.Add(localFileInfo); diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml index 4a2fe1c32..42502bc10 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml +++ b/CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml @@ -156,7 +156,7 @@