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

FileCleanup Improvements #633

Merged
merged 27 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
982cbfc
[ZZZ GSP] Add experimental Mobile Mode toggle
bagusnl Aug 4, 2024
82f5caa
Merge branch 'main' into zzz-mobile-mode
bagusnl Aug 4, 2024
3cffc8c
sync zzz-mobile-mode with main (#604)
bagusnl Nov 15, 2024
afeb190
what in the absolute FRICK - Fix cleanup method when using >1000 files
bagusnl Dec 19, 2024
a3ca990
fix logging
bagusnl Dec 19, 2024
a65b937
how is it not clear that idk what im doing
bagusnl Dec 19, 2024
442fcf4
Hilariously improve select all speed by using a one-liner instead of …
bagusnl Dec 19, 2024
5edc9c6
Merge remote-tracking branch 'origin/filecleanup-improvement' into fi…
bagusnl Dec 19, 2024
32c6cae
More improvements
bagusnl Dec 19, 2024
474422f
Merge remote-tracking branch 'origin/zzz-mobile-mode' into filecleanu…
bagusnl Dec 20, 2024
d2038b0
Use .NET's built-in SIMD Sum tool instead on ListView_SelectionChanged
bagusnl Dec 20, 2024
2a3373c
Localize and tidy up
bagusnl Dec 20, 2024
699e1f7
Revert "Merge remote-tracking branch 'origin/zzz-mobile-mode' into fi…
bagusnl Dec 20, 2024
6bedf77
Merge branch 'main' into filecleanup-improvement
bagusnl Dec 20, 2024
7b139bc
Remove unnecessary refresh on FileInfo.EnsureNoReadOnly
neon-nyan Dec 21, 2024
19b0959
Reduce memory allocation on RecycleBin tool
neon-nyan Dec 21, 2024
2d9d3ee
[Perf] Improve after-deletion item removal on FileInfoSource
neon-nyan Dec 21, 2024
19b66d8
[Perf] Improve LocalFileInfo injection process
neon-nyan Dec 21, 2024
314c21a
[Perf] Detach thread on normal deletion
neon-nyan Dec 21, 2024
0e7b845
Catch exceptions on deletion method
neon-nyan Dec 21, 2024
3c5fc36
Fix wrong list to reset on cancelled delete
neon-nyan Dec 21, 2024
0e724fd
Fix Recycle Bin cancellation not thrown
neon-nyan Dec 21, 2024
1e521a9
Use DispatcherQueue on Show/HideLoadingFrame if necessary
neon-nyan Dec 21, 2024
6a8fc67
Improve FileCleanupPage methods (again)
bagusnl Dec 21, 2024
66dac00
Fix inconsistent deletedItems entry
neon-nyan Dec 21, 2024
1bda3ec
Another Improvements
neon-nyan Dec 21, 2024
afc9dd8
Remove unused namespace :teriderp:
neon-nyan Dec 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public virtual async ValueTask CleanUpGameFiles(bool withDialog = true)
{
// Get the unused file info asynchronously
List<LocalFileInfo> unusedFileInfo = await GetUnusedFileInfoList(withDialog);

// Spawn dialog if used
if (withDialog)
{
Expand All @@ -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 (_, _) =>
Expand Down Expand Up @@ -170,9 +172,9 @@ protected virtual async Task<List<LocalFileInfo>> 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(
Expand Down Expand Up @@ -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<string>();
Expand All @@ -253,7 +256,7 @@ await DownloadOtherAudioPkgVersion(_gameAudioLangListPathStatic,
preDownloadZips.AddRange(packagePreDownloadList.voice_packs
.Select(audioRes =>
new GameInstallPackage(audioRes,
_gamePath)
_gamePath)
{
PackageType =
GameInstallPackageType.Audio
Expand All @@ -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> localFileInfo = [];
await GetRelativeLocalFilePaths(localFileInfo, includeZipCheck, gameStateEnum, _token.Token);
Expand All @@ -295,9 +298,10 @@ await Task.Run(() =>

return unusedFileInfo;
}
finally
catch (Exception ex)
{
LoadingMessageHelper.HideLoadingFrame();
ErrorSender.SendException(ex);
return new List<LocalFileInfo>();
}
}

Expand Down Expand Up @@ -465,14 +469,15 @@ protected virtual async Task GetRelativeLocalFilePaths(List<LocalFileInfo> 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, _) =>
{
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
</Grid.ColumnDefinitions>
<CheckBox x:Name="ToggleCheckAllCheckBox"
Checked="ToggleCheckAll"
IsChecked="True"
IsChecked="False"
Unchecked="ToggleCheckAll" />
<Button x:Name="DeleteSelectedFiles"
Grid.Column="0"
Expand Down
Loading
Loading