Beispiel #1
0
        public void TestDecrypt()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString();

            try
            {
                using (var s = File.Create(tempLongPathFilename, 200))
                {
                }
                var preAttrib = File.GetAttributes(tempLongPathFilename);
                Assert.AreEqual((FileAttributes)0, (preAttrib & FileAttributes.Encrypted));

                var fi = new FileInfo(tempLongPathFilename);
                fi.Encrypt();

                var postAttrib = File.GetAttributes(tempLongPathFilename);
                Assert.AreEqual(FileAttributes.Encrypted, (postAttrib & FileAttributes.Encrypted));

                fi.Decrypt();

                postAttrib = File.GetAttributes(tempLongPathFilename);
                Assert.AreEqual((FileAttributes)0, (postAttrib & FileAttributes.Encrypted));
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
Beispiel #2
0
        public void TestOpenHidden()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file25.ext").ToString();
            var fi = new FileInfo(tempLongPathFilename);

            using (fi.Create())
            {
            }
            try
            {
                Assert.Throws <UnauthorizedAccessException>(() =>
                {
                    File.SetAttributes(fi.FullName, File.GetAttributes(fi.FullName) | FileAttributes.Hidden);

                    using (var fileStream = fi.Open(FileMode.Create))
                    {
                        Assert.IsNotNull(fileStream);
                    }
                });
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
        public FileSystemResult <IObject> ResolveSynchronous(string path)
        {
            try
            {
                // Allow either and convert to OS desired later
                if (path.StartsWith("\\\\") || path.StartsWith("//"))
                {
                    int idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, 2);
                    if (idx >= 0)
                    {
                        idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, idx + 1);
                        if (idx < 0)
                        {
                            idx = path.Length;
                        }
                    }
                    else
                    {
                        idx = path.Length;
                    }
                    string share = path.Substring(0, idx);
                    if (!Directory.Exists(share))
                    {
                        return(new FileSystemResult <IObject>("Not found"));
                    }
                    if (!FS.Directories.Any(a => a.FullName.Equals(share, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        FS.AddUncPath(share);
                    }
                }
            }
            catch (Exception e)
            {
                // Last ditch effort to catch errors, this needs to always succeed.
                return(new FileSystemResult <IObject>(e.Message));
            }
            if (File.Exists(path) || Directory.Exists(path))
            {
                FileAttributes attr = File.GetAttributes(path);

                // It's a directory
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return(new FileSystemResult <IObject>(new LocalDirectory(new DirectoryInfo(path), FS)));
                }

                // It's a file
                return(new FileSystemResult <IObject>(new LocalFile(new FileInfo(path), FS)));
            }

            return(new FileSystemResult <IObject>("Not found"));
        }
Beispiel #4
0
 public static FileAttributes GetAttributes(string path)
 {
     return(File.GetAttributes(path));
 }