Skip to content

Commit 2a326b7

Browse files
committed
Fix #434
1 parent b2eafc8 commit 2a326b7

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

CompactGUI.Core/Analyser.vb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,29 @@ Public Class Analyser
9595
Public Function HasDirectoryWritePermission() As Boolean
9696

9797
Try
98-
Dim writeAllow = False
99-
10098
Dim ACRules = New DirectoryInfo(FolderName).GetAccessControl().GetAccessRules(True, True, GetType(Security.Principal.NTAccount))
101-
If ACRules Is Nothing Then Return False
10299

103100
Dim identity = Security.Principal.WindowsIdentity.GetCurrent
104101
Dim principal = New Security.Principal.WindowsPrincipal(identity)
102+
Dim writeDenied = False
103+
105104
For Each FSRule As FileSystemAccessRule In ACRules
105+
If (FSRule.FileSystemRights And FileSystemRights.Write) = 0 Then Continue For
106+
Dim ntAccount As Security.Principal.NTAccount = TryCast(FSRule.IdentityReference, Security.Principal.NTAccount)
106107

107-
If (FSRule.FileSystemRights And FileSystemRights.Write) <= 0 Then Continue For
108-
Dim ntAccount As Security.Principal.NTAccount = FSRule.IdentityReference
109-
If ntAccount Is Nothing Then Continue For
110-
If Not principal.IsInRole(ntAccount.Value) Then Continue For
111-
If FSRule.AccessControlType = AccessControlType.Deny Then Return False
112-
writeAllow = True
108+
If ntAccount Is Nothing OrElse Not principal.IsInRole(ntAccount.Value) Then Continue For
113109

114-
Next
110+
If FSRule.AccessControlType = AccessControlType.Deny Then
111+
writeDenied = True
112+
Exit For
113+
End If
115114

116-
Return writeAllow
115+
Next
117116

117+
Return Not writeDenied
118118
Catch ex As System.UnauthorizedAccessException
119-
119+
' Consider logging the exception or notifying the caller
120120
Return False
121-
122121
End Try
123122

124123
End Function

0 commit comments

Comments
 (0)