make storage size calculation asynchronous and running in parallel

This commit is contained in:
rootdarkarchon
2024-02-15 02:38:41 +01:00
committed by Loporrit
parent 50990542fd
commit e1ca5dd6f8
9 changed files with 105 additions and 35 deletions

View File

@@ -62,9 +62,11 @@ public sealed class FileCompactor
MassCompactRunning = false;
}
public long GetFileSizeOnDisk(string filePath)
public long GetFileSizeOnDisk(string filePath, bool? isNTFS = null)
{
if (Dalamud.Utility.Util.IsWine()) return new FileInfo(filePath).Length;
bool ntfs = isNTFS ?? string.Equals(new DriveInfo(new FileInfo(filePath).Directory!.Root.FullName).DriveFormat, "NTFS", StringComparison.OrdinalIgnoreCase);
if (Dalamud.Utility.Util.IsWine() || !ntfs) return new FileInfo(filePath).Length;
var clusterSize = GetClusterSize(filePath);
if (clusterSize == -1) return new FileInfo(filePath).Length;
@@ -105,6 +107,14 @@ public sealed class FileCompactor
private void CompactFile(string filePath)
{
var fs = new DriveInfo(new FileInfo(filePath).Directory!.Root.FullName);
bool isNTFS = string.Equals(fs.DriveFormat, "NTFS", StringComparison.OrdinalIgnoreCase);
if (!isNTFS)
{
_logger.LogWarning("Drive for file {file} is not NTFS", filePath);
return;
}
var oldSize = new FileInfo(filePath).Length;
var clusterSize = GetClusterSize(filePath);