mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-10 12:40:35 +02:00
Revert "Rewrite folder write permission check to hopefully make it more reliable"
This reverts commit 1f9db3bda6
.
This commit is contained in:
parent
09d39df15a
commit
57b0821e19
@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
|
||||
@ -7,15 +8,23 @@ namespace TweetDck.Core.Utils{
|
||||
static class WindowsUtils{
|
||||
public static bool CheckFolderPermission(string path, FileSystemRights right){
|
||||
try{
|
||||
AuthorizationRuleCollection collection = Directory.GetAccessControl(path).GetAccessRules(true, true, typeof(NTAccount));
|
||||
AuthorizationRuleCollection rules = Directory.GetAccessControl(path).GetAccessRules(true, true, typeof(SecurityIdentifier));
|
||||
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
||||
|
||||
foreach(FileSystemAccessRule rule in collection){
|
||||
if ((rule.FileSystemRights & right) == right){
|
||||
return true;
|
||||
if (identity.Groups == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
bool accessAllow = false, accessDeny = false;
|
||||
|
||||
foreach(FileSystemAccessRule rule in rules.Cast<FileSystemAccessRule>().Where(rule => identity.Groups.Contains(rule.IdentityReference) && (right & rule.FileSystemRights) == right)){
|
||||
switch(rule.AccessControlType){
|
||||
case AccessControlType.Allow: accessAllow = true; break;
|
||||
case AccessControlType.Deny: accessDeny = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return accessAllow && !accessDeny;
|
||||
}
|
||||
catch{
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user