Combine() public method

public Combine ( ) : GlobalPath
return GlobalPath
コード例 #1
0
ファイル: VolumeManager.cs プロジェクト: minorDeveloper/KOS
        public bool Copy(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace = true)
        {
            Volume sourceVolume      = GetVolumeFromPath(sourcePath);
            Volume destinationVolume = GetVolumeFromPath(destinationPath);

            VolumeItem source      = sourceVolume.Open(sourcePath);
            VolumeItem destination = destinationVolume.Open(destinationPath);

            if (source == null)
            {
                throw new KOSPersistenceException("Path does not exist: " + sourcePath);
            }

            if (source is VolumeDirectory)
            {
                if (destination is VolumeFile)
                {
                    throw new KOSPersistenceException("Can't copy directory into a file");
                }

                if (destination == null)
                {
                    destination = destinationVolume.CreateDirectory(destinationPath);
                }
                else if (!sourcePath.IsRoot)
                {
                    destinationPath = destinationPath.Combine(sourcePath.Name);
                    destination     = destinationVolume.OpenOrCreateDirectory(destinationPath);
                }

                if (destination == null)
                {
                    throw new KOSException("Path was expected to point to a directory: " + destinationPath);
                }

                return(CopyDirectory(sourcePath, destinationPath, verifyFreeSpace));
            }
            else
            {
                if (destination is VolumeFile || destination == null)
                {
                    Volume targetVolume = GetVolumeFromPath(destinationPath);
                    return(CopyFile(source as VolumeFile, destinationPath, targetVolume, verifyFreeSpace));
                }
                else
                {
                    return(CopyFileToDirectory(source as VolumeFile, destination as VolumeDirectory, verifyFreeSpace));
                }
            }
        }
コード例 #2
0
ファイル: VolumeManager.cs プロジェクト: minorDeveloper/KOS
        protected bool CopyDirectory(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace)
        {
            if (sourcePath.IsParent(destinationPath))
            {
                throw new KOSPersistenceException("Can't copy directory to a subdirectory of itself: " + destinationPath);
            }

            Volume sourceVolume      = GetVolumeFromPath(sourcePath);
            Volume destinationVolume = GetVolumeFromPath(destinationPath);

            VolumeDirectory source = sourceVolume.Open(sourcePath) as VolumeDirectory;

            VolumeItem destinationItem = destinationVolume.Open(destinationPath);

            if (destinationItem is VolumeFile)
            {
                throw new KOSPersistenceException("Can't copy directory into a file");
            }

            VolumeDirectory destination = destinationItem as VolumeDirectory;

            if (destination == null)
            {
                destination = destinationVolume.CreateDirectory(destinationPath);
            }

            var l = source.List();

            foreach (KeyValuePair <string, VolumeItem> pair in l)
            {
                if (pair.Value is VolumeDirectory)
                {
                    if (!CopyDirectory(sourcePath.Combine(pair.Key), destinationPath.Combine(pair.Key), verifyFreeSpace))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!CopyFileToDirectory(pair.Value as VolumeFile, destination, verifyFreeSpace))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #3
0
ファイル: VolumeManager.cs プロジェクト: KSP-KOS/KOS
        public bool Copy(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace = true)
        {
            Volume sourceVolume = GetVolumeFromPath(sourcePath);
            Volume destinationVolume = GetVolumeFromPath(destinationPath);

            VolumeItem source = sourceVolume.Open(sourcePath);
            VolumeItem destination = destinationVolume.Open(destinationPath);

            if (source == null)
            {
                throw new KOSPersistenceException("Path does not exist: " + sourcePath);
            }

            if (source is VolumeDirectory)
            {
                if (destination is VolumeFile)
                {
                    throw new KOSPersistenceException("Can't copy directory into a file");
                }

                if (destination == null)
                {
                    destination = destinationVolume.CreateDirectory(destinationPath);
                }
                else if (!sourcePath.IsRoot)
                {
                    destinationPath = destinationPath.Combine(sourcePath.Name);
                    destination = destinationVolume.OpenOrCreateDirectory(destinationPath);
                }

                if (destination == null)
                {
                    throw new KOSException("Path was expected to point to a directory: " + destinationPath);
                }

                return CopyDirectory(sourcePath, destinationPath, verifyFreeSpace);
            } else
            {
                if (destination is VolumeFile || destination == null)
                {
                    Volume targetVolume = GetVolumeFromPath(destinationPath);
                    return CopyFile(source as VolumeFile, destinationPath, targetVolume, verifyFreeSpace);
                }
                else
                {
                    return CopyFileToDirectory(source as VolumeFile, destination as VolumeDirectory, verifyFreeSpace);
                }
            }
        }
コード例 #4
0
ファイル: VolumeManager.cs プロジェクト: KSP-KOS/KOS
        protected bool CopyDirectory(GlobalPath sourcePath, GlobalPath destinationPath, bool verifyFreeSpace)
        {
            if (sourcePath.IsParent(destinationPath))
            {
                throw new KOSPersistenceException("Can't copy directory to a subdirectory of itself: " + destinationPath);
            }

            Volume sourceVolume = GetVolumeFromPath(sourcePath);
            Volume destinationVolume = GetVolumeFromPath(destinationPath);

            VolumeDirectory source = sourceVolume.Open(sourcePath) as VolumeDirectory;

            VolumeItem destinationItem = destinationVolume.Open(destinationPath);

            if (destinationItem is VolumeFile)
            {
                throw new KOSPersistenceException("Can't copy directory into a file");
            }

            VolumeDirectory destination = destinationItem as VolumeDirectory;

            if (destination == null)
            {
                destination = destinationVolume.CreateDirectory(destinationPath);
            }

            var l = source.List();

            foreach (KeyValuePair<string, VolumeItem> pair in l)
            {
                if (pair.Value is VolumeDirectory)
                {
                    if (!CopyDirectory(sourcePath.Combine(pair.Key), destinationPath.Combine(pair.Key), verifyFreeSpace))
                    {
                        return false;
                    }
                }
                else
                {
                    if (!CopyFileToDirectory(pair.Value as VolumeFile, destination, verifyFreeSpace))
                    {
                        return false;
                    }
                }
            }

            return true;
        }
コード例 #5
0
ファイル: CopyAndMoveTest.cs プロジェクト: KSP-KOS/KOS
        private void CompareDirectories(GlobalPath dir1Path, GlobalPath dir2Path)
        {
            Volume dir1Volume = volumeManager.GetVolumeFromPath(dir1Path);
            Volume dir2Volume = volumeManager.GetVolumeFromPath(dir2Path);

            VolumeDirectory dir1 = dir1Volume.Open(dir1Path) as VolumeDirectory;
            VolumeDirectory dir2 = dir2Volume.Open(dir2Path) as VolumeDirectory;

            Assert.NotNull(dir1);
            Assert.NotNull(dir2);

            int dir1Count = dir1.List().Count;
            int dir2Count = dir2.List().Count;

            if (dir1Count != dir2Count)
            {
                Assert.Fail("Item count not equal: " + dir1Count + " != " + dir2Count);
            }

            foreach (KeyValuePair<string, VolumeItem> pair in dir1.List())
            {
                VolumeItem dir2Item = dir2Volume.Open(dir2Path.Combine(pair.Key));

                if (pair.Value is VolumeDirectory && dir2Item is VolumeDirectory)
                {
                    CompareDirectories(dir1Path.Combine(pair.Key), dir2Path.Combine(pair.Key));
                } else if (pair.Value is VolumeFile && dir2Item is VolumeFile)
                {
                    VolumeFile file1 = pair.Value as VolumeFile;
                    VolumeFile file2 = dir2Item as VolumeFile;

                    Assert.AreEqual(file1.ReadAll(), file2.ReadAll());
                } else
                {
                    Assert.Fail("Items are not of the same type: " + dir1Path.Combine(pair.Key) + ", " + dir2Path.Combine(pair.Key));
                }
            }
        }
コード例 #6
0
ファイル: CopyAndMoveTest.cs プロジェクト: KSP-KOS/KOS
        public void SetupVolumes()
        {
            dir1Path = GlobalPath.FromString("0:" + dir1);
            subdir1Path = dir1Path.Combine(subdir1);
            subdir2Path = dir1Path.Combine(subdir2);
            subsubdir1Path = subdir1Path.Combine(subsubdir1);

            file1Path = GlobalPath.FromString("0:" + file1);
            dir1File1Path = dir1Path.Combine(file1);
            dir1File2Path = dir1Path.Combine(file2);
            dir1File3Path = dir1Path.Combine(file3);
            subdir1File1Path = subdir1Path.Combine(file1);
            subsubdir1File1Path = subsubdir1Path.Combine(file1);

            SourceVolume.Clear();
            TargetVolume.Clear();

            SourceVolume.CreateDirectory(subdir2Path);
            SourceVolume.CreateDirectory(subsubdir1Path);

            SourceVolume.CreateFile(file1Path).WriteLn(file1);
            SourceVolume.CreateFile(dir1File3Path).WriteLn(file2);
            SourceVolume.CreateFile(subsubdir1File1Path).WriteLn("subsubdir1File1");
        }