1- Imports System.Threading
1+ Imports System.IO
2+ Imports System.Runtime.InteropServices
3+ Imports System.Threading
24Imports MethodTimer
35
46Public Class Compactor
@@ -13,6 +15,10 @@ Public Class Compactor
1315 Private _workingDir As String
1416 Private _compressionLevel As String
1517 Private _excludedFileTypes As List( Of String )
18+ Private _WOFcompressionLevel As ULong
19+
20+ Private _EFInfo As _WOF_FILE_COMPRESSION_INFO_V1
21+ Private _EFInfoPtr As IntPtr
1622
1723 Sub New (folder As String , cLevelIndex As Integer , excludedfiletypes As List( Of String ))
1824
@@ -21,6 +27,10 @@ Public Class Compactor
2127 _workingDir = folder
2228 _excludedFileTypes = excludedfiletypes
2329 _compressionLevel = CompressionLevel(cLevelIndex)
30+ _WOFcompressionLevel = WOFConvertCompressionLevel(cLevelIndex)
31+ _EFInfo = New _WOF_FILE_COMPRESSION_INFO_V1 With {.Algorithm = _WOFcompressionLevel, .Flags = 0 }
32+ _EFInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(_EFInfo))
33+ Marshal.StructureToPtr(_EFInfo, _EFInfoPtr, True )
2434
2535 End Sub
2636
@@ -53,6 +63,36 @@ Public Class Compactor
5363
5464 End Sub
5565
66+
67+ Shared Function DetectCompression(path As String )
68+
69+ Dim isextFile As Integer
70+ Dim prov As ULong
71+ Dim info As _WOF_FILE_COMPRESSION_INFO_V1
72+ Dim buf As UInt16 = 8
73+ Dim ret = WofIsExternalFile(path, isextFile, prov, info, buf)
74+
75+ End Function
76+
77+
78+ Sub WOFCompressFile(path As String )
79+
80+ Dim length As ULong = Marshal.SizeOf(_EFInfoPtr)
81+
82+ Using fs As FileStream = New FileStream(path, FileMode.Open)
83+ Dim hFile = fs.SafeFileHandle.DangerousGetHandle()
84+ 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
91+ End Using
92+
93+ End Sub
94+
95+
5696 <Time>
5797 Async Function RunCompactAsync(progress As IProgress( Of (percentageProgress As Integer , currentFile As String ))) As Task( Of Boolean )
5898
@@ -64,7 +104,8 @@ Public Class Compactor
64104
65105 Await Parallel.ForEachAsync(_filesList,
66106 Function (file, _ctx)
67- GenerateThread(_workingDir, compactArgs & " " & """" & file & """" )
107+ WOFCompressFile(file)
108+ 'GenerateThread(_workingDir, compactArgs & " " & """" & file & """")
68109 Dim result = Interlocked.Increment(count)
69110 progress.Report(( CInt (((result / totalFiles) * 100 )), file))
70111 End Function ).ConfigureAwait( False )
0 commit comments