Skip to content

Commit

Permalink
Fix #434
Browse files Browse the repository at this point in the history
  • Loading branch information
Iridium-IO committed Jun 28, 2024
1 parent b2eafc8 commit 2a326b7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions CompactGUI.Core/Analyser.vb
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,29 @@ Public Class Analyser
Public Function HasDirectoryWritePermission() As Boolean

Try
Dim writeAllow = False

Dim ACRules = New DirectoryInfo(FolderName).GetAccessControl().GetAccessRules(True, True, GetType(Security.Principal.NTAccount))
If ACRules Is Nothing Then Return False

Dim identity = Security.Principal.WindowsIdentity.GetCurrent
Dim principal = New Security.Principal.WindowsPrincipal(identity)
Dim writeDenied = False

For Each FSRule As FileSystemAccessRule In ACRules
If (FSRule.FileSystemRights And FileSystemRights.Write) = 0 Then Continue For
Dim ntAccount As Security.Principal.NTAccount = TryCast(FSRule.IdentityReference, Security.Principal.NTAccount)

If (FSRule.FileSystemRights And FileSystemRights.Write) <= 0 Then Continue For
Dim ntAccount As Security.Principal.NTAccount = FSRule.IdentityReference
If ntAccount Is Nothing Then Continue For
If Not principal.IsInRole(ntAccount.Value) Then Continue For
If FSRule.AccessControlType = AccessControlType.Deny Then Return False
writeAllow = True
If ntAccount Is Nothing OrElse Not principal.IsInRole(ntAccount.Value) Then Continue For

Next
If FSRule.AccessControlType = AccessControlType.Deny Then
writeDenied = True
Exit For
End If

Return writeAllow
Next

Return Not writeDenied
Catch ex As System.UnauthorizedAccessException

' Consider logging the exception or notifying the caller
Return False

End Try

End Function
Expand Down

0 comments on commit 2a326b7

Please sign in to comment.