Skip to content

Commit 3aaf764

Browse files
authored
Merge pull request #379 from yyjdelete/fix_compSize
Fall back to unCompSize if GetFileSizeOnDisk failed
2 parents 868320a + 723e3ed commit 3aaf764

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CompactGUI.Core/Analyser.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Public Class Analyser
3939
Dim fInfo As New FileInfo(file)
4040
Dim unCompSize = fInfo.Length
4141
Dim compSize = GetFileSizeOnDisk(file)
42+
If compSize < 0 Then
43+
'GetFileSizeOnDisk failed, fall back to unCompSize
44+
compSize = unCompSize
45+
End If
4246
Dim cLevel As CompressionAlgorithm = If(compSize = unCompSize, CompressionAlgorithm.NO_COMPRESSION, DetectCompression(fInfo))
4347

4448
'Sets the backing private fields directly because Interlocked doesn't play nice with properties!

CompactGUI.Core/SharedMethods.vb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Public Module SharedMethods
2020
Function GetFileSizeOnDisk(file As String) As Long
2121
Dim hosize As UInteger
2222
Dim losize As UInteger = GetCompressedFileSizeW(file, hosize)
23+
'INVALID_FILE_SIZE (0xFFFFFFFF)
24+
If losize = 4294967295 Then
25+
Dim errCode As Integer
26+
errCode = Marshal.GetLastPInvokeError()
27+
If errCode <> 0 Then
28+
Return -1
29+
End If
30+
End If
2331
Return CLng(hosize) << 32 Or losize
2432
End Function
2533

@@ -72,7 +80,7 @@ Public Module SharedMethods
7280

7381
#Region "DLL Imports"
7482

75-
<DllImport("kernel32.dll")>
83+
<DllImport("kernel32.dll", SetLastError:=True)>
7684
Private Function GetCompressedFileSizeW(
7785
<[In](), MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,
7886
<Out(), MarshalAs(UnmanagedType.U4)> ByRef lpFileSizeHigh As UInteger) _

0 commit comments

Comments
 (0)