c# - Unity-Mono 在检查目录权限时抛出 PlatformNotSupportedException

标签 c# mono unity3d

我正在使用以下代码检查 Windows 中目录的权限。

我在 Unity 3.5.7f6 中使用 BuildSettings 中的“PC & Mac”平台。

我遇到以下异常:

  1. PlatformNotSupportedException
  2. 未授权访问异常

    string l_userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    
    DirectorySecurity folderSecurity;
    //Way 1: Getting **PlatformNotSupportedException** with below line.
    
    folderSecurity = new DirectorySecurity(a_directoryPath, AccessControlSections.Audit);
    
    //Way 1---ENDS HERE
    
    
    //Way 2: Getting **UnauthorizedAccessException** in last line of Way 2 block.
    
    DirectoryInfo l_directory = new DirectoryInfo(a_directoryPath);     
    folderSecurity = l_directory.GetAccessControl(AccessControlSections.Audit);
    
    //Way 2---ENDS HERE
    
    foreach (FileSystemAccessRule fileSystemAccessRule in folderSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
    {
    
        string l_domain_userName = fileSystemAccessRule.IdentityReference.Value;
        if (l_domain_userName.Equals(l_userName))
        {
            string l_userRights = fileSystemAccessRule.FileSystemRights.ToString();
            Debug.Log(l_domain_userName + ":" + l_userRights);
    
            if (fileSystemAccessRule.FileSystemRights.HasFlag(a_rightToCheck))
            {
                Debug.Log("-----have Accesss:" + a_rightToCheck);
                l_isGranted = true;
                break;
            }
        }
    }
    

我试过打印操作系统版本:

Environment.OSVersion.Platform

它打印: WindowsNT 5.1.2600(即 XP)

我在上面尝试的是获取文件夹是否具有权限(读取或写入)。

帮我解决这个问题。

最佳答案

简短回答:目前 Unity 根本没有实现此功能。

Unity 使用的是相当旧的 Mono 版本。移动平台和控制台似乎存在一些许可问题,因此他们无法简单地使用最新版本的 Mono。

正如您在 Mono source code 中看到的那样对于 Unity 4.3,DirectorySecurity 的构造函数只是引发一个 PlatformNotSupportedException。因为 GetAccessControl 依赖于 DirectorySecurity 它也将只是 raise an exception .

如果您解释为什么需要这些权限或您的最终目标是什么,我们也许能够为您的问题找到其他解决方案。

关于c# - Unity-Mono 在检查目录权限时抛出 PlatformNotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23429615/

相关文章:

c# - 什么是 dealloc 的 Monotouch 等价物?

c# - mongodb 中的身份验证

c# - Mono 是否支持 64 位 Windows?

unity3d - 统一平台android取消订阅中的Firebase数据库不起作用

java - 将日期从 JDateChooser 插入到 MySql 数据库

c# - C# 从数组中提取数组

c# - 当多个线程写入控制台时,如何重定向在 Linux 上的单声道 (c#) 上运行的应用程序中的输出以避免 'Array index is out of range.'?

mono - 圆形仪表渐变 - TeeChart - MonoAndroid

c# - 属性私有(private)集崩溃统一

c# - Unity Build错误::audioinaec中的属性application @ allowBackups = false:与另一个值冲突