ToString() public method

public ToString ( ) : string
return string
示例#1
0
        public HarddiskDirectory GetSubdirectory(VolumePath path, bool create = false)
        {
            if (Path.Equals(path))
            {
                return(this);
            }

            if (!Path.IsParent(path))
            {
                throw new KOSException("This directory does not contain path: " + path.ToString());
            }

            string subdirectory = path.Segments[Path.Segments.Count];

            if (!items.ContainsKey(subdirectory))
            {
                if (create)
                {
                    CreateDirectory(subdirectory);
                }
                else
                {
                    return(null);
                }
            }

            HarddiskDirectory directory = items[subdirectory] as HarddiskDirectory;

            if (directory == null)
            {
                throw new KOSPersistenceException("Directory does not exist: " + path.ToString());
            }

            return(directory.GetSubdirectory(path, create));
        }
示例#2
0
        public string GetArchivePath(VolumePath path)
        {
            if (path.PointsOutside)
            {
                throw new KOSInvalidPathException("Path refers to parent directory", path.ToString());
            }

            string mergedPath = ArchiveFolder;

            foreach (string segment in path.Segments)
            {
                mergedPath = Path.Combine(mergedPath, segment);
            }

            string fullPath = Path.GetFullPath(mergedPath);

            if (!fullPath.StartsWith(ArchiveFolder, StringComparison.Ordinal))
            {
                throw new KOSInvalidPathException("Path refers to parent directory", path.ToString());
            }

            return(fullPath);
        }
示例#3
0
        public string GetArchivePath(VolumePath path)
        {
            if (path.PointsOutside)
            {
                throw new KOSInvalidPathException("Path refers to parent directory", path.ToString());
            }

            string mergedPath = ArchiveFolder;

            foreach (string segment in path.Segments)
            {
                mergedPath = Path.Combine(mergedPath, segment);
            }

            return(mergedPath);
        }
示例#4
0
文件: Archive.cs 项目: KSP-KOS/KOS
        public string GetArchivePath(VolumePath path)
        {
            if (path.PointsOutside)
            {
                throw new KOSInvalidPathException("Path refers to parent directory", path.ToString());
            }

            string mergedPath = ArchiveFolder;

            foreach (string segment in path.Segments)
            {
                mergedPath = Path.Combine(mergedPath, segment);
            }

            return mergedPath;
        }
示例#5
0
文件: Archive.cs 项目: KSP-KOS/KOS
        public override VolumeFile CreateFile(VolumePath path)
        {
            if (path.Depth == 0)
            {
                throw new KOSPersistenceException("Can't create a file over root directory");
            }

            string archivePath = GetArchivePath(path);

            if (File.Exists(archivePath))
            {
                throw new KOSPersistenceException("Already exists: " + path);
            }

            try
            {
                Directory.CreateDirectory(GetArchivePath(path.GetParent()));
            }
            catch (IOException)
            {
                throw new KOSPersistenceException("Parent directory for path does not exist: " + path.ToString());
            }

            try
            {
                File.Create(archivePath).Dispose();
            }
            catch (UnauthorizedAccessException)
            {
                throw new KOSPersistenceException("Could not create file: " + path);
            }

            return Open(path) as VolumeFile;
        }
示例#6
0
        public override VolumeFile CreateFile(VolumePath path)
        {
            if (path.Depth == 0)
            {
                throw new KOSPersistenceException("Can't create a file over root directory");
            }

            string archivePath = GetArchivePath(path);

            if (File.Exists(archivePath))
            {
                throw new KOSPersistenceException("Already exists: " + path);
            }

            try
            {
                Directory.CreateDirectory(GetArchivePath(path.GetParent()));
            }
            catch (IOException)
            {
                throw new KOSPersistenceException("Parent directory for path does not exist: " + path.ToString());
            }

            try
            {
                File.Create(archivePath).Dispose();
            }
            catch (UnauthorizedAccessException)
            {
                throw new KOSPersistenceException("Could not create file: " + path);
            }

            return(Open(path) as VolumeFile);
        }