Skip to content

Commit d98c1b9

Browse files
committed
Fix crash when the user does not have permission to access a subdirectory in a folder during the check to ensure the folder is not empty. Closes #395
- Version bump to 3.2.0
1 parent 5acfbe1 commit d98c1b9

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

CompactGUI.Core/SharedMethods.vb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,47 @@ Public Module SharedMethods
1010
If Not IO.Directory.Exists(folder) Then : Return (False, "Directory does not exist")
1111
ElseIf folder.Contains((Environment.GetFolderPath(Environment.SpecialFolder.Windows))) Then : Return (False, "Cannot compress system directory")
1212
ElseIf folder.EndsWith(":\") Then : Return (False, "Cannot compress root directory")
13-
ElseIf Not IO.Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Any() Then : Return (False, "Directory is empty")
13+
ElseIf IsDirectoryEmptySafe(folder) Then : Return (False, "This directory is either empty or you are not authorized to access its files.")
1414
ElseIf DriveInfo.GetDrives().First(Function(f) folder.StartsWith(f.Name)).DriveFormat <> "NTFS" Then : Return (False, "Cannot compress a directory on a non-NTFS drive")
1515
End If
1616

1717
Return (True, "")
1818

1919
End Function
2020

21+
Function IsDirectoryEmptySafe(folder As String)
22+
23+
Try
24+
Return Not IO.Directory.EnumerateFileSystemEntries(folder).Any()
25+
26+
For Each subdir In IO.Directory.EnumerateDirectories(folder)
27+
Try
28+
If Not IsDirectoryEmptySafe(subdir) Then Return False
29+
Catch ex As System.UnauthorizedAccessException
30+
31+
End Try
32+
Next
33+
34+
For Each file In IO.Directory.EnumerateFiles(folder)
35+
Try
36+
Return False
37+
Catch ex As System.UnauthorizedAccessException
38+
39+
End Try
40+
Next
41+
42+
Return True
43+
44+
Catch ex As System.UnauthorizedAccessException
45+
MsgBox("You are not authorized to access some items in this folder." & vbCrLf & "Please try running CompactGUI as an administrator, otherwise these items will be skipped.", MsgBoxStyle.Exclamation, "Unauthorized Access")
46+
Return False
47+
48+
Catch ex As Exception
49+
Return False
50+
End Try
51+
52+
End Function
53+
2154
Function GetFileSizeOnDisk(file As String) As Long
2255
Dim hosize As UInteger
2356
Dim losize As UInteger = GetCompressedFileSizeW(file, hosize)

CompactGUI/Models/UpdateHandler.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Imports System.Text.Json
33
Public Class UpdateHandler
44

5-
Public Shared CurrentVersion As New SemVersion(3, 1, 1)
5+
Public Shared CurrentVersion As New SemVersion(3, 2, 0)
66
Public Shared NewVersion As SemVersion
77
Shared UpdateURL As String = "https://raw.githubusercontent.com/IridiumIO/CompactGUI/database/version.json"
88

0 commit comments

Comments
 (0)