Closed Roadou closed 4 months ago
I asked ChatGPT to rewrite the HasDirectoryWritePermission function, and it is now working properly:
Public Function HasDirectoryWritePermission() As Boolean
Try
Dim writeAllow As Boolean = False
' Replace FolderName with the actual path you're checking
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)
For Each rule As FileSystemAccessRule In ACRules
If (rule.FileSystemRights And FileSystemRights.Write) = FileSystemRights.Write Then
Dim identityReference = rule.IdentityReference
' Check the type of identityReference
If TypeOf identityReference Is Security.Principal.NTAccount Then
Dim ntAccount As Security.Principal.NTAccount = DirectCast(identityReference, Security.Principal.NTAccount)
If principal.IsInRole(ntAccount.Value) Then
If rule.AccessControlType = AccessControlType.Deny Then
Return False
End If
writeAllow = True
End If
ElseIf TypeOf identityReference Is Security.Principal.SecurityIdentifier Then
' Handle SecurityIdentifier if needed
' You can choose to handle SecurityIdentifier differently if required.
' For example, you could log or skip these cases.
' For now, let's just log a message.
Console.WriteLine("Found a SecurityIdentifier: " & DirectCast(identityReference, Security.Principal.SecurityIdentifier).ToString())
End If
End If
Next
Return writeAllow
Catch ex As UnauthorizedAccessException
' Handle unauthorized access exception
Console.WriteLine("UnauthorizedAccessException: " & ex.Message)
Return False
Catch ex As Exception
' Handle other exceptions
Console.WriteLine("Exception occurred: " & ex.Message)
Return False
End Try
End Function
Hello, when i try to compress the MSFS2020 folder, both including official and community packages (basically plane/maps...), the program crash, The folder is located in C:\Users\Road\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages Here's the crashlog
It may be because the buffer that hold directory name is not large enough ? Thank you.