コード例 #1
0
        public void CanCopyRootDirectoryToExistingDirectory()
        {
            TargetVolume.CreateDirectory(VolumePath.FromString("/newdirectory"));
            Assert.IsTrue(volumeManager.Copy(GlobalPath.FromString("0:/"), GlobalPath.FromString("1:/newdirectory")));

            CompareDirectories(GlobalPath.FromString("0:/"), GlobalPath.FromString("1:/newdirectory"));
        }
コード例 #2
0
        public override IDictionary <string, VolumeItem> List()
        {
            string[] files     = Directory.GetFiles(volumePath);
            var      filterHid = files.Where(f => (File.GetAttributes(f) & FileAttributes.Hidden) != 0);
            var      filterSys = files.Where(f => (File.GetAttributes(f) & FileAttributes.System) != 0);
            var      visFiles  = files.Except(filterSys).Except(filterHid).ToArray();

            string[] directories = Directory.GetDirectories(volumePath);

            Array.Sort(directories);
            Array.Sort(visFiles);

            var result = new Dictionary <string, VolumeItem>();

            foreach (string directory in directories)
            {
                string directoryName = System.IO.Path.GetFileName(directory);
                result.Add(directoryName, new CliVolumeDirectory(volume, VolumePath.FromString(directoryName, Path)));
            }

            foreach (string file in visFiles)
            {
                string fileName = System.IO.Path.GetFileName(file);
                result.Add(fileName, new CliVolumeFile(volume, new FileInfo(file), VolumePath.FromString(fileName, Path)));
            }

            return(result);
        }
コード例 #3
0
        public override VolumeItem Open(VolumePath path, bool ksmDefault = false)
        {
            try
            {
                var fileSystemInfo = Search(path, ksmDefault);

                if (fileSystemInfo == null)
                {
                    return(null);
                }
                else if (fileSystemInfo is FileInfo)
                {
                    VolumePath filePath = VolumePath.FromString(fileSystemInfo.FullName.Substring(VolumeFolder.Length).Replace(Path.DirectorySeparatorChar, VolumePath.PathSeparator));
                    return(new CliVolumeFile(this, fileSystemInfo as FileInfo, filePath));
                }
                else
                {
                    // we can use 'path' here, default extensions are not added to directories
                    return(new CliVolumeDirectory(this, path));
                }
            }
            catch (Exception e)
            {
                throw new KOSPersistenceException("Could not open path: " + path, e);
            }
        }
コード例 #4
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanDeleteFiles()
        {
            string parent1 = "/parent1";
            string file1 = parent1 + "/sub1", file2 = parent1 + "/sub2";

            TestVolume.CreateFile(VolumePath.FromString(file1));
            TestVolume.CreateFile(VolumePath.FromString(file2));

            Assert.IsTrue(TestVolume.Delete(VolumePath.FromString(file1)));

            VolumeDirectory dir = TestVolume.Open(VolumePath.FromString(parent1)) as VolumeDirectory;

            Assert.AreEqual(1, dir.List().Count);
            Assert.AreEqual(file2, dir.List()["sub2"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["sub2"]);

            TestVolume.CreateFile(VolumePath.FromString(file2 + ".ks"));
            Assert.IsTrue(TestVolume.Delete(VolumePath.FromString(file2 + ".ks")));
            Assert.AreEqual(1, dir.List().Count);
            Assert.AreEqual(file2, dir.List()["sub2"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["sub2"]);

            TestVolume.CreateFile(VolumePath.FromString(file2 + ".ks"));
            Assert.IsTrue(TestVolume.Delete(VolumePath.FromString(file2)));
            Assert.AreEqual(1, dir.List().Count);
            Assert.AreEqual(file2 + ".ks", dir.List()["sub2.ks"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["sub2.ks"]);

            Assert.IsTrue(TestVolume.Delete(VolumePath.FromString(file2)));
            Assert.AreEqual(0, dir.List().Count);
        }
コード例 #5
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanCreateFiles()
        {
            string parent1 = "/parent1", parent2 = "/parent2";
            string file1 = parent1 + "/sub1/file", file2 = parent1 + "/sub2", file3 = parent2 + "/sub3";

            TestVolume.CreateFile(VolumePath.FromString(file1));
            TestVolume.CreateFile(VolumePath.FromString(file2));
            TestVolume.CreateFile(VolumePath.FromString(file3));

            Assert.AreEqual(2, TestVolume.Root.List().Count);
            Assert.AreEqual(parent1, TestVolume.Root.List()["parent1"].Path.ToString());
            Assert.AreEqual(parent2, TestVolume.Root.List()["parent2"].Path.ToString());

            VolumeDirectory dir = TestVolume.Open(VolumePath.FromString(parent1)) as VolumeDirectory;

            Assert.AreEqual(2, dir.List().Count);
            Assert.AreEqual("/parent1/sub1", dir.List()["sub1"].Path.ToString());
            Assert.IsInstanceOf <VolumeDirectory>(dir.List()["sub1"]);
            Assert.AreEqual(file2, dir.List()["sub2"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["sub2"]);

            dir = TestVolume.Open(VolumePath.FromString("/parent1/sub1")) as VolumeDirectory;
            Assert.AreEqual(1, dir.List().Count);
            Assert.AreEqual("/parent1/sub1/file", dir.List()["file"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["file"]);

            dir = TestVolume.Open(VolumePath.FromString(parent2)) as VolumeDirectory;
            Assert.AreEqual(1, dir.List().Count);
            Assert.AreEqual(file3, dir.List()["sub3"].Path.ToString());
            Assert.IsInstanceOf <VolumeFile>(dir.List()["sub3"]);
        }
コード例 #6
0
        private IEnumerable <VolumePath> BootDirectoryFiles()
        {
            var result = new List <VolumePath>();

            var archive = new Archive(SafeHouse.ArchiveFolder);

            var path = VolumePath.FromString(BootDirectoryName);

            var bootDirectory = archive.Open(path) as VolumeDirectory;

            if (bootDirectory == null)
            {
                return(result);
            }

            var files = bootDirectory.List();

            foreach (KeyValuePair <string, VolumeItem> pair in files)
            {
                if (pair.Value is VolumeFile && (pair.Value.Extension.Equals(Volume.KERBOSCRIPT_EXTENSION) ||
                                                 pair.Value.Extension.Equals(Volume.KOS_MACHINELANGUAGE_EXTENSION)))
                {
                    result.Add(pair.Value.Path);
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanReadAndWriteFiles()
        {
            string dir           = "/content_parent/content_test";
            string content       = "some test content!@#$;\n\rtaenstałąż";
            int    contentLength = Encoding.UTF8.GetBytes(content).Length;

            VolumeFile volumeFile = TestVolume.CreateFile(VolumePath.FromString(dir));

            Assert.AreEqual(0, volumeFile.ReadAll().Bytes.Length);
            Assert.AreEqual("", volumeFile.ReadAll().String);

            Assert.IsTrue(volumeFile.Write(content));
            Assert.AreEqual(FileCategory.ASCII, volumeFile.ReadAll().Category);

            Assert.AreEqual(contentLength, TestVolume.Size);

            if (ExpectedCapacity != Volume.INFINITE_CAPACITY)
            {
                Assert.AreEqual(ExpectedCapacity - contentLength, TestVolume.FreeSpace);
            }
            else
            {
                Assert.AreEqual(Volume.INFINITE_CAPACITY, TestVolume.FreeSpace);
            }

            Assert.AreEqual(contentLength, volumeFile.Size);
            Assert.AreEqual(content, volumeFile.ReadAll().String);

            // we should be able to save the same file again
            Assert.IsTrue(TestVolume.SaveFile(volumeFile) != null);
        }
コード例 #8
0
        public void CanHandleSimplePath()
        {
            VolumePath path = VolumePath.FromString("/identifier");

            Assert.AreEqual(1, path.Length);
            Assert.AreEqual(1, path.Depth);
        }
コード例 #9
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanFailWhenSavingFileOverDirectory()
        {
            string parent1 = "/parent1";
            string file1   = parent1 + "/sub1";

            TestVolume.CreateDirectory(VolumePath.FromString(file1));
            TestVolume.SaveFile(VolumePath.FromString(file1), new FileContent());
        }
コード例 #10
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanFailWhenCreatingFileInASubdirectoryThatIsAFile()
        {
            string parent = "/parent1";
            string file   = parent + "/file";

            TestVolume.CreateFile(VolumePath.FromString(parent));
            TestVolume.CreateFile(VolumePath.FromString(file));
        }
コード例 #11
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanFailWhenCreatingFileOverExistingFile()
        {
            string parent = "/parent1";
            string file   = parent + "/file";

            TestVolume.CreateFile(VolumePath.FromString(file));
            TestVolume.CreateFile(VolumePath.FromString(file));
        }
コード例 #12
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanDeleteNonExistingDirectories()
        {
            VolumePath path = VolumePath.FromString("/abc");

            TestVolume.CreateDirectory(path);
            TestVolume.Delete(path);
            TestVolume.Delete(path);
        }
コード例 #13
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanFailWhenCreatingDirectoryOverExistingDirectory()
        {
            string parent = "/parent1";
            string dir    = parent + "/sub1";

            TestVolume.CreateDirectory(VolumePath.FromString(dir));
            TestVolume.CreateDirectory(VolumePath.FromString(dir));
        }
コード例 #14
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanFailWhenCreatingDirectoryOverFile()
        {
            string parent1 = "/parent1";
            string file1   = parent1 + "/sub1";

            TestVolume.CreateFile(VolumePath.FromString(file1));
            TestVolume.CreateDirectory(VolumePath.FromString(file1));
        }
コード例 #15
0
        public void CanHandleTwoDots()
        {
            VolumePath parent = VolumePath.FromString("/parent/deeper/and_deeper");
            VolumePath path   = VolumePath.FromString("../../", parent);

            Assert.AreEqual(1, path.Depth);
            Assert.AreEqual(1, path.Length);
        }
コード例 #16
0
        public void CanHandleMultipleSlashes()
        {
            VolumePath path = VolumePath.FromString("//test//test2/");

            Assert.AreEqual(2, path.Length);
            Assert.AreEqual(2, path.Depth);
            Assert.AreEqual("test2", path.Name);
        }
コード例 #17
0
        public void CanCopyDirectoryToExistingDirectoryTwice()
        {
            TargetVolume.CreateDirectory(VolumePath.FromString("/newdirectory"));
            Assert.IsTrue(volumeManager.Copy(dir1Path, GlobalPath.FromString("1:/newdirectory")));
            Assert.IsTrue(volumeManager.Copy(dir1Path, GlobalPath.FromString("1:/newdirectory")));

            CompareDirectories(dir1Path, GlobalPath.FromString("1:/newdirectory/" + dir1));
        }
コード例 #18
0
        public void CanCombinePathsThatContainSlashes()
        {
            VolumePath path      = VolumePath.FromString("/test");
            VolumePath combined  = path.Combine("sub1/sub2");
            VolumePath combined2 = path.Combine("sub1/..");

            Assert.AreEqual(3, combined.Depth);
            Assert.AreEqual(1, combined2.Depth);
        }
コード例 #19
0
        public void CanCombinePaths()
        {
            VolumePath path      = VolumePath.FromString("/test");
            VolumePath combined  = path.Combine("sub1", "sub2");
            VolumePath combined2 = path.Combine("..");

            Assert.AreEqual(3, combined.Depth);
            Assert.AreEqual(0, combined2.Depth);
        }
コード例 #20
0
        public void CanHandleRootPath()
        {
            VolumePath path = VolumePath.FromString("/");

            Assert.AreEqual(0, path.Length);
            Assert.AreEqual(0, path.Depth);
            Assert.AreEqual(string.Empty, path.Name);
            Assert.AreEqual(string.Empty, path.Extension);
        }
コード例 #21
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanDeleteNonExistingFiles()
        {
            VolumePath path = VolumePath.FromString("/abc");

            TestVolume.CreateFile(path);

            // Delete the file twice
            Assert.IsTrue(TestVolume.Delete(path));
            Assert.IsFalse(TestVolume.Delete(path));
        }
コード例 #22
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanDeleteDirectories()
        {
            string parent1 = "/parent1", parent2 = "/parent2";
            string dir1 = parent1 + "/sub1", dir2 = parent1 + "/sub2", dir3 = parent2 + "/sub3";

            TestVolume.CreateDirectory(VolumePath.FromString(dir1));
            TestVolume.CreateDirectory(VolumePath.FromString(dir2));
            TestVolume.CreateDirectory(VolumePath.FromString(dir3));

            VolumeDirectory parent = TestVolume.Open(VolumePath.FromString(parent1)) as VolumeDirectory;

            TestVolume.Delete(VolumePath.FromString(dir1));
            Assert.AreEqual(1, parent.List().Count);
            Assert.AreEqual(dir2, parent.List()["sub2"].Path.ToString());

            TestVolume.Delete(VolumePath.FromString(parent2));
            Assert.AreEqual(1, TestVolume.Root.List().Count);
            Assert.AreEqual(parent1, TestVolume.Root.List()["parent1"].Path.ToString());
        }
コード例 #23
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
        public void CanCreateDirectories()
        {
            string dir1 = "/testdir", dir2 = "/abc", dir3 = "/abc2", dir4 = "/abc/subdirectory";

            Assert.AreEqual(0, TestVolume.Root.List().Count);

            TestVolume.CreateDirectory(VolumePath.FromString(dir1));
            TestVolume.CreateDirectory(VolumePath.FromString(dir2));
            TestVolume.CreateDirectory(VolumePath.FromString(dir3));
            TestVolume.CreateDirectory(VolumePath.FromString(dir4));

            Assert.AreEqual(3, TestVolume.Root.List().Count);
            Assert.AreEqual(dir2, TestVolume.Root.List()["abc"].Path.ToString());
            Assert.AreEqual(dir3, TestVolume.Root.List()["abc2"].Path.ToString());
            Assert.AreEqual(dir1, TestVolume.Root.List()["testdir"].Path.ToString());

            Assert.AreEqual(1, (TestVolume.Root.List()["abc"] as VolumeDirectory).List().Values.Count);
            Assert.AreEqual(dir4, (TestVolume.Root.List()["abc"] as VolumeDirectory).List()["subdirectory"].Path.ToString());
        }
コード例 #24
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
 public void CanFailWhenCreatingDirectoryOverRootDirectory()
 {
     TestVolume.CreateDirectory(VolumePath.FromString("/"));
 }
コード例 #25
0
        private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path)
        {
            HarddiskDirectory directory = new HarddiskDirectory(harddisk, path);

            foreach (ConfigNode fileNode in configNode.GetNodes("file"))
            {
                directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory));
            }

            foreach (ConfigNode dirNode in configNode.GetNodes("directory"))
            {
                string dirName = dirNode.GetValue(DirnameValueString);

                directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path)));
            }

            return(directory);
        }
コード例 #26
0
ファイル: VolumeTest.cs プロジェクト: stephengeorgewest/KOS-1
 public void CanHandleOpeningNonExistingFiles()
 {
     Assert.IsNull(TestVolume.Open(VolumePath.FromString("/idonotexist")));
 }
コード例 #27
0
        private void InitUI()
        {
            //Populate selector for boot scripts
            BaseField field   = Fields["bootFile"];
            var       options = (UI_ChooseOption)field.uiControlEditor;

            var bootFiles = new List <VolumePath>();

            bootFiles.AddRange(BootDirectoryFiles());

            //no need to show the control if there are no available boot files
            options.controlEnabled = bootFiles.Count >= 1;
            field.guiActiveEditor  = bootFiles.Count >= 1;
            var availableOptions  = bootFiles.Select(e => e.ToString()).ToList();
            var availableDisplays = bootFiles.Select(e => e.Name).ToList();

            availableOptions.Insert(0, "None");
            availableDisplays.Insert(0, "None");

            var bootFilePath = BootFilePath; // store the selected path temporarily

            if (bootFilePath != null && !bootFiles.Contains(bootFilePath))
            {
                // if the path is not null ("None", null, or empty) and if it isn't in list of files
                var archive = new Archive(SafeHouse.ArchiveFolder);
                var file    = archive.Open(bootFilePath) as VolumeFile; // try to open the file as saved
                if (file == null)
                {
                    // check the same file name, but in the boot directory.
                    var path = VolumePath.FromString(BootDirectoryName).Combine(bootFilePath.Name);
                    file = archive.Open(path) as VolumeFile; // try to open the new path
                    if (file == null)
                    {
                        // try the file name without "boot" prefix
                        var name = bootFilePath.Name;
                        if (name.StartsWith("boot", StringComparison.OrdinalIgnoreCase) && name.Length > 4)
                        {
                            // strip the boot prefix and try that file name
                            name = name.Substring(4);
                            path = VolumePath.FromString(BootDirectoryName).Combine(name);
                            file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                            if (file == null)
                            {
                                // try the file name without "boot_" prefix
                                if (name.StartsWith("_", StringComparison.OrdinalIgnoreCase) && name.Length > 1)
                                {
                                    // only need to strip "_" here
                                    name = name.Substring(1);
                                    path = VolumePath.FromString(BootDirectoryName).Combine(name);
                                    file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                                }
                            }
                        }
                    }
                }

                // now, if we have a file object, use its values.
                if (file != null)
                {
                    // store the boot file information
                    bootFile = file.Path.ToString();
                    if (!bootFiles.Contains(file.Path))
                    {
                        availableOptions.Insert(1, bootFile);
                        availableDisplays.Insert(1, "*" + file.Path.Name); // "*" is indication the file is not normally available
                    }
                }
            }
            SafeHouse.Logger.SuperVerbose("bootFile: " + bootFile);

            options.options = availableOptions.ToArray();
            options.display = availableDisplays.ToArray();

            //populate diskSpaceUI selector
            diskSpaceUI = diskSpace.ToString();
            field       = Fields["diskSpaceUI"];
            options     = (UI_ChooseOption)field.uiControlEditor;
            var sizeOptions = new string[3];

            sizeOptions[0]  = baseDiskSpace.ToString();
            sizeOptions[1]  = (baseDiskSpace * 2).ToString();
            sizeOptions[2]  = (baseDiskSpace * 4).ToString();
            options.options = sizeOptions;
        }
コード例 #28
0
 public void CanHandlePathsThatPointOutside2()
 {
     VolumePath.FromString("/../test/test/test");
 }
コード例 #29
0
 public void CanHandlePathsThatPointOutside1()
 {
     VolumePath.FromString("/..");
 }
コード例 #30
0
        public void CanHandleAbsolutePathWithParent()
        {
            VolumePath parent = VolumePath.FromString("/parent");

            VolumePath.FromString("/identifier", parent);
        }