Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CompactGUI.Core/CompactGUI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.298">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 5 additions & 3 deletions CompactGUI.Core/Estimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private float EstimateCompressabilityHDD(FileStream input, long fileSize, Compre

unsafe long GetFirstLcn(string fileName)
{
SafeFileHandle handle = File.OpenHandle(fileName);
using SafeFileHandle handle = File.OpenHandle(fileName);

if (handle.IsInvalid) throw new IOException("Failed to open file handle for " + fileName);

Expand All @@ -172,7 +172,7 @@ unsafe long GetFirstLcn(string fileName)
uint bytesReturned = 0;

var result = PInvoke.DeviceIoControl(
handle,
(Windows.Win32.Foundation.HANDLE)handle.DangerousGetHandle(),
NTFSInterop.FSCTL_GET_RETRIEVAL_POINTERS,
&inBuffer,
inBufferSize,
Expand All @@ -181,6 +181,8 @@ unsafe long GetFirstLcn(string fileName)
&bytesReturned,
null);

GC.KeepAlive(handle);

if (!result) return long.MaxValue;

int extentOffset = Marshal.OffsetOf<NTFSInterop.RETRIEVAL_POINTERS_BUFFER>("Extents").ToInt32();
Expand All @@ -193,4 +195,4 @@ unsafe long GetFirstLcn(string fileName)



}
}
20 changes: 8 additions & 12 deletions CompactGUI.Core/SharedMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,24 @@ private static string GetShortPath(string filePath)



public static unsafe uint GetClusterSize(string folderPath)
public static uint GetClusterSize(string folderPath)
{
UInt32 lpSectorsPerCluster;
UInt32 lpBytesPerSector;

PInvoke.GetDiskFreeSpace(
new DirectoryInfo(folderPath).Root.ToString(),
&lpSectorsPerCluster,
&lpBytesPerSector,
null,
null
out UInt32 lpSectorsPerCluster,
out UInt32 lpBytesPerSector,
out _,
out _
);

return lpSectorsPerCluster * lpBytesPerSector;

}


public static unsafe long GetFileSizeOnDisk(string file)
public static long GetFileSizeOnDisk(string file)
{
uint highOrder;
uint lowOrder = PInvoke.GetCompressedFileSize(file, &highOrder);
uint lowOrder = PInvoke.GetCompressedFileSize(file, out uint highOrder);
if (lowOrder == 0xFFFFFFFF && (Marshal.GetLastWin32Error() != 0)) return -1;
return ((long)highOrder << 32) | lowOrder;
}
Expand Down Expand Up @@ -300,4 +296,4 @@ public static bool IsDirectStorageGameFolder(string folderPath)
}


}
}
6 changes: 4 additions & 2 deletions CompactGUI.Core/Uncompactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private unsafe FileOperationResult WOFDecompressFile(string file)
using (SafeFileHandle fs = File.OpenHandle(file))
{
bool succeeded = PInvoke.DeviceIoControl(
fs,
(Windows.Win32.Foundation.HANDLE)fs.DangerousGetHandle(),
WOFHelper.FSCTL_DELETE_EXTERNAL_BACKING,
null,
0,
Expand All @@ -156,6 +156,8 @@ private unsafe FileOperationResult WOFDecompressFile(string file)
null,
null);

GC.KeepAlive(fs);

if (succeeded) return new FileOperationResult(true);

int errorCode = Marshal.GetLastWin32Error();
Expand Down Expand Up @@ -205,4 +207,4 @@ public void Dispose()



}
}
4 changes: 2 additions & 2 deletions CompactGUI.Core/WOFHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static unsafe WOFCompressionAlgorithm DetectCompression(FileInfo fileInfo
WOFHelper.WOF_FILE_COMPRESSION_INFO_V1 info;
uint buffer = 8;

var ret = PInvoke.WofIsExternalFile(fileInfo.FullName, &isExternalFile, &provider, &info, &buffer);
var ret = PInvoke.WofIsExternalFile(fileInfo.FullName, out isExternalFile, out provider, &info, ref buffer);

WOFCompressionAlgorithm algorithm = (WOFCompressionAlgorithm)info.Algorithm;

Expand All @@ -112,4 +112,4 @@ public static unsafe WOFCompressionAlgorithm DetectCompression(FileInfo fileInfo
return algorithm;

}
}
}
Loading