Skip to content

Commit 31105f2

Browse files
committed
Added ability to uncompress using the WinAPI as well.
1 parent f130bd1 commit 31105f2

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

CompactGUI/Compactor.vb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,27 @@ Public Class Compactor
7575
End Function
7676

7777

78-
Sub WOFCompressFile(path As String)
78+
Function WOFCompressFile(path As String)
7979

8080
Dim length As ULong = Marshal.SizeOf(_EFInfoPtr)
8181

8282
Using fs As FileStream = New FileStream(path, FileMode.Open)
8383
Dim hFile = fs.SafeFileHandle.DangerousGetHandle()
8484
Dim res = WofSetFileDataLocation(hFile, WOF_PROVIDER_FILE, _EFInfoPtr, length)
85-
If res <> 0 Then
86-
If res <> -2147024552 Then
87-
Debug.WriteLine("spaghetti")
88-
End If
89-
90-
End If
85+
Return res
9186
End Using
9287

93-
End Sub
88+
End Function
89+
90+
Shared Function WOFDecompressFile(path As String)
9491

92+
Using fs As FileStream = New FileStream(path, FileMode.Open)
93+
Dim hDevice = fs.SafeFileHandle.DangerousGetHandle
94+
Dim res = DeviceIoControl(hDevice, FSCTL_DELETE_EXTERNAL_BACKING, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero)
95+
Return res
96+
End Using
97+
98+
End Function
9599

96100
<Time>
97101
Async Function RunCompactAsync(progress As IProgress(Of (percentageProgress As Integer, currentFile As String))) As Task(Of Boolean)
@@ -104,7 +108,7 @@ Public Class Compactor
104108

105109
Await Parallel.ForEachAsync(_filesList,
106110
Function(file, _ctx)
107-
WOFCompressFile(file)
111+
Dim res = WOFCompressFile(file)
108112
'GenerateThread(_workingDir, compactArgs & " " & """" & file & """")
109113
Dim result = Interlocked.Increment(count)
110114
progress.Report((CInt(((result / totalFiles) * 100)), file))
@@ -164,7 +168,8 @@ Public Class Compactor
164168
Dim count As Integer = 0
165169
Await Parallel.ForEachAsync(filesList,
166170
Function(file, _ctx)
167-
GenerateThread(workingDir, compactArgs & " " & """" & file & """")
171+
Dim res = WOFDecompressFile(file)
172+
'GenerateThread(workingDir, compactArgs & " " & """" & file & """")
168173
Dim result = Interlocked.Increment(count)
169174
progress.Report((CInt(((result / totalFiles) * 100)), file))
170175
End Function).ConfigureAwait(False)

CompactGUI/WOFHelper.vb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Module WOFHelper
77
Public Const FILE_PROVIDER_COMPRESSION_LZX As ULong = 1
88
Public Const FILE_PROVIDER_COMPRESSION_XPRESS8K As ULong = 2
99
Public Const FILE_PROVIDER_COMPRESSION_XPRESS16K As ULong = 3
10+
Public Const FSCTL_DELETE_EXTERNAL_BACKING As UInteger = &H90314
1011

1112

1213
Public Function WOFConvertCompressionLevel(compressionlevel As Integer) As ULong
@@ -43,4 +44,19 @@ Module WOFHelper
4344
ExternalFileInfo As IntPtr,
4445
Length As ULong) As Integer
4546
End Function
47+
48+
'Most of these should be optional if MS Docs are to be believed -.-
49+
<DllImport("kernel32.dll")>
50+
Public Function DeviceIoControl(
51+
hDevice As IntPtr,
52+
dwIoControlCode As UInteger,
53+
lpInBuffer As IntPtr,
54+
nInBufferSize As UInteger,
55+
lpOutBuffer As IntPtr,
56+
nOutBufferSize As UInteger,
57+
<Out> lpBytesReturned As IntPtr,
58+
<Out> lpOverlapped As IntPtr) As Integer
59+
60+
End Function
61+
4662
End Module

0 commit comments

Comments
 (0)