Exemplo n.º 1
0
        /// <summary>
        /// Creates a set of directories based on a treenode information.
        /// </summary>
        /// <param name="parentDirectory">Parent directory.</param>
        /// <param name="treeNode">Tree node to map.</param>
        public static void CreateDirectories(JDirectory parentDirectory, JStoreFileTreeNode treeNode)
        {
            //List<FileListViewItem> fileItems;
            JFile      file;
            JDirectory childDirectory;
            List <JSoreFileItemInfo> fileItems = treeNode.Tag;

            // Create the files of the directory
            //fileItems = (List<FileListViewItem>)treeNode.Tag;
            foreach (JSoreFileItemInfo fileItem in fileItems)
            {
                file          = new JFile(fileItem.fileName);
                file.Filters  = fileItem.Filters;
                file.FileInfo = fileItem.Info;

                parentDirectory.AddFile(file);
            }

            // Create the subdirectories
            foreach (JStoreFileTreeNode node in treeNode.Nodes)
            {
                childDirectory = new JDirectory(node.DirName);
                parentDirectory.AddDirectory(childDirectory);

                CreateDirectories(childDirectory, node);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Overloaded constructor
        /// </summary>
        /// <param name="name">Name of the storage</param>
        /// <param name="version">Version of the storage</param>
        /// <param name="filters">Filters known by the storage</param>
        /// <param name="root">Root directory of the storage</param>
        public JStorageSource(String name, int version, List <IJFilter> filters, JDirectory root)
            : this(name)
        {
            _version = version;
            _root    = root;

            if (filters != null)
            {
                _filters = filters;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Extracts the contents of one directory and all the subdirectories inside it
        /// </summary>
        /// <param name="path">Path to extract the contents</param>
        /// <param name="rootDirectory">Root directory where the extraction begins</param>
        private void ExtractDirectoryFiles(String path, JDirectory rootDirectory)
        {
            Stream       inFile, outFile;
            BinaryWriter bw = null;

            byte[] bytes;
            int    bytesRead;

            // If the path doesn't exist, create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // For each file in the root node
            foreach (JFile file in rootDirectory.GetFiles())
            {
                try
                {
                    // Create the new hard disk file
                    outFile = File.Open(System.IO.Path.Combine(path, file.Name), FileMode.Create, FileAccess.Write);
                    bw      = new BinaryWriter(outFile);

                    inFile = GetStream(file);

                    // Write the storage data to it
                    bytes = new byte[4096];
                    while ((bytesRead = inFile.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        bw.Write(bytes, 0, bytesRead);
                    }

                    bw.Flush();
                }

                catch (Exception)
                { }

                finally
                {
                    if (bw != null)
                    {
                        bw.Close();
                    }
                }
            }

            foreach (JDirectory directory in rootDirectory.GetDirectories())
            {
                ExtractDirectoryFiles(System.IO.Path.Combine(path, directory.Name), directory);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new storage.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="version">Version of the storage.</param>
        /// <param name="name">Name of the storage.</param>
        /// <param name="filters">Filters used in the storage.</param>
        /// <param name="rootNode">Root node of the storage.</param>
        /// <param name="oldStorage">Old storage (it can contain some files used in the new storage).</param>
        /// <returns>A new storage.</returns>
        public static JStorageSource CreateStorage(string fileName, int version, string name, List <IJFilter> filters, JStoreFileTreeNode rootNode, JStorageSource oldStorage)
        {
            JDirectory     rootDirectory;
            JStorageSource newStorage;

            // Create the directories from the treeview
            rootDirectory = new JDirectory("Root");
            CreateDirectories(rootDirectory, rootNode);

            // Create the storage
            newStorage = new JStorageSource(name, version, filters, rootDirectory);

            // Write it
            newStorage.Write(fileName, oldStorage);

            return(newStorage);
        }
        public static HDirectory ToHDirectory(this JDirectory jDirectory)
        {
            HDirectory directory = new HDirectory
            {
                Name = jDirectory.Name
            };

            List <HDirectory> directories = jDirectory.GetHDirectories();

            if (directories != null)
            {
                directory.Directories.AddRange(directories);
            }

            List <HFile> files = jDirectory.GetHFiles();

            if (files != null)
            {
                directory.Files.AddRange(files);
            }

            return(directory);
        }
 private static List <HFile> GetHFiles(this JDirectory jDirectory)
 {
     return(jDirectory.Files?
            .Select(x => x.ToHFile())
            .ToList());
 }
 private static List <HDirectory> GetHDirectories(this JDirectory jDirectory)
 {
     return(jDirectory.Directories?
            .Select(x => ToHDirectory(x))
            .ToList());
 }