コード例 #1
0
ファイル: File.cs プロジェクト: bangush/LongPath
        public static void Encrypt(String path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Encrypt(path);
                return;
            }
            String fullPath       = Path.GetFullPath(path);
            string normalizedPath = Path.NormalizeLongPath(fullPath);

            if (NativeMethods.EncryptFile(normalizedPath))
            {
                return;
            }
            int errorCode = Marshal.GetLastWin32Error();

            if (errorCode == NativeMethods.ERROR_ACCESS_DENIED)
            {
                var di = new DriveInfo(Path.GetPathRoot(normalizedPath));
                if (!String.Equals("NTFS", di.DriveFormat))
                {
                    throw new NotSupportedException("NTFS drive required for file encryption");
                }
            }
            Common.ThrowIOError(errorCode, fullPath);
        }