예제 #1
0
        /// <summary>
        /// Makes a copy of this entry and moves the copy to the specified directory.
        /// </summary>
        /// <param name="directory"></param>
        /// <returns>The copy.</returns>
        public VirtualFileSystemEntry CopyTo(VirtualDirectory directory)
        {
            var copy = Copy();

            // Add file to destination directory
            copy.Parent = directory;

            if (directory != null)
            {
                copy.MoveTo(directory, true);
            }

            return(copy);
        }
예제 #2
0
        /// <summary>
        /// Moves this entry from it's parent directory to the specified directory.
        /// </summary>
        /// <param name="directory"></param>
        public void MoveTo(VirtualDirectory directory, bool replace = false)
        {
            // Remove file from parent directory
            if (Parent != null)
            {
                Parent.Remove(this);
            }

            // Add file to destination directory
            Parent = directory;

            if (directory != null)
            {
                directory.PerformOperation(this, replace ? Operation.AddOrReplace : Operation.AddOnly);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new virtual directory from a directory on the host filesystem.
        /// </summary>
        /// <param name="hostDirectoryPath"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static VirtualDirectory FromHostDirectory(string hostDirectoryPath, VirtualDirectory parent = null)
        {
            var directory = new VirtualDirectory(parent, hostDirectoryPath, Path.GetFileName(hostDirectoryPath));

            foreach (var entry in Directory.EnumerateFileSystemEntries(hostDirectoryPath))
            {
                if (File.Exists(entry))
                {
                    directory.mEntries.AddLast(VirtualFile.FromHostFile(entry, false, directory));
                }
                else
                {
                    directory.mEntries.AddLast(FromHostDirectory(entry, directory));
                }
            }

            return(directory);
        }
예제 #4
0
 public VirtualDirectory(VirtualDirectory parent, string name)
     : base(parent, null, name, VirtualFileSystemEntryType.Directory)
 {
     mEntries = new LinkedList <VirtualFileSystemEntry>();
 }
예제 #5
0
 public VirtualFile(VirtualDirectory parent, Stream stream, string name)
     : base(parent, null, name, VirtualFileSystemEntryType.File)
 {
     mStream = stream ?? throw new ArgumentNullException(nameof(stream));
 }
예제 #6
0
        /// <summary>
        /// Creates a new virtual file from a file on the host filesystem.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static VirtualFile FromHostFile(string path, bool copyToMemory = false, VirtualDirectory parent = null)
        {
            if (copyToMemory)
            {
                MemoryStream stream = new MemoryStream();
                using (var fileStream = File.OpenRead(path))
                    fileStream.CopyTo(fileStream);

                return(new VirtualFile(parent, stream, Path.GetFileName(path)));
            }
            else
            {
                return(new VirtualFile(parent, path, Path.GetFileName(path)));
            }
        }
예제 #7
0
 public VirtualFile(VirtualDirectory parent, string hostPath, string name)
     : base(parent, hostPath, name, VirtualFileSystemEntryType.File)
 {
 }