From 9dabb758b50f4dc439858f031288af015816f288 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:03:40 +0900 Subject: [PATCH] Update FileSizeCalculator.cs --- .../Utils/Storage/Operations/FileSizeCalculator.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Utils/Storage/Operations/FileSizeCalculator.cs b/src/Files.App/Utils/Storage/Operations/FileSizeCalculator.cs index 302a8fbd822d..818271092d6a 100644 --- a/src/Files.App/Utils/Storage/Operations/FileSizeCalculator.cs +++ b/src/Files.App/Utils/Storage/Operations/FileSizeCalculator.cs @@ -39,6 +39,7 @@ await Parallel.ForEachAsync( unsafe void ComputeSizeRecursively(string path, CancellationToken token) { var queue = new Queue(); + if (!Win32Helper.HasFileAttribute(path, FileAttributes.Directory)) { ComputeFileSize(path); @@ -49,14 +50,14 @@ unsafe void ComputeSizeRecursively(string path, CancellationToken token) while (queue.TryDequeue(out var directory)) { - WIN32_FIND_DATAW* findData = default; + WIN32_FIND_DATAW findData = default; fixed (char* pszFilePath = directory + "\\*.*") { var hFile = PInvoke.FindFirstFileEx( pszFilePath, FINDEX_INFO_LEVELS.FindExInfoBasic, - findData, + &findData, FINDEX_SEARCH_OPS.FindExSearchNameMatch, null, FIND_FIRST_EX_FLAGS.FIND_FIRST_EX_LARGE_FETCH); @@ -65,19 +66,20 @@ unsafe void ComputeSizeRecursively(string path, CancellationToken token) { do { - FILE_FLAGS_AND_ATTRIBUTES attributes = (FILE_FLAGS_AND_ATTRIBUTES)findData->dwFileAttributes; + FILE_FLAGS_AND_ATTRIBUTES attributes = (FILE_FLAGS_AND_ATTRIBUTES)findData.dwFileAttributes; if (attributes.HasFlag(FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_REPARSE_POINT)) // Skip symbolic links and junctions continue; - var itemPath = Path.Combine(directory, findData->cFileName.ToString()); + var itemPath = Path.Combine(directory, findData.cFileName.ToString()); if (attributes.HasFlag(FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_DIRECTORY)) { + // Recurse ComputeFileSize(itemPath); } - else if (findData->cFileName.ToString() is string fileName && + else if (findData.cFileName.ToString() is string fileName && fileName.Equals(".", StringComparison.OrdinalIgnoreCase) && fileName.Equals("..", StringComparison.OrdinalIgnoreCase)) { @@ -87,7 +89,7 @@ unsafe void ComputeSizeRecursively(string path, CancellationToken token) if (token.IsCancellationRequested) break; } - while (PInvoke.FindNextFile(hFile, findData)); + while (PInvoke.FindNextFile(hFile, &findData)); } PInvoke.CloseHandle(hFile);