Exemple #1
0
        public void DeleteNode(ShellItemViewModel item)
        {
            switch (item.Type)
            {
            case ShellItemType.Directory:
                Log.Info(string.Format(Resources.IO_DeletingDirectoryFromArchive, item.FullPath), Resources.Tag_IO);
                // create shallow copy to iterate over, because the collection is modified in the loop
                foreach (var child in item.Children.ToList())
                {
                    DeleteNode(child);
                }

                item.Parent.Children.Remove(item);
                Nodes.Remove(item.FullPath);
                break;

            case ShellItemType.File:
                Log.Info(string.Format(Resources.IO_DeletingFileFromArchive, item.FullPath), Resources.Tag_IO);
                // delete file from archive
                FileSystem.DeleteFile(item.FullPath);
                // remove node from tree view
                item.Parent.Children.Remove(item);
                Nodes.Remove(item.FullPath);
                break;

            case ShellItemType.Root:
                Log.Fail(Resources.IO_CannotDeleteRootNode, Resources.Tag_IO);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        public FileSystemViewModel(FileSystem fileSystem)
        {
            FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));

            Root = new ShellItemViewModel(this, null, fileSystem.Name, ShellItemType.Root);

            foreach (string file in FileSystem.GetFiles())
            {
                AddFile(file);
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a file/directory node and all its parents to the directory tree if it doesn't exist yet.
        /// </summary>
        /// <param name="path">Full path of the added element within the file system</param>
        /// <param name="type">Type of the element to be added (file/directory)</param>
        /// <param name="nodes">A directory containing all previously created nodes</param>
        /// <returns>The node corresponding to the specified path</returns>
        protected ShellItemViewModel CreateNode(string path, ShellItemType type, Dictionary <string, ShellItemViewModel> nodes)
        {
            if (nodes.ContainsKey(path))
            {
                return(nodes[path]);
            }

            string parentPath = Path.GetDirectoryName(path);
            var    parent     = !string.IsNullOrWhiteSpace(parentPath) ? CreateNode(parentPath, ShellItemType.Directory, nodes) : Root;

            var node = new ShellItemViewModel(this, parent, path, type);

            parent.Children.Add(node);

            nodes[path] = node;
            return(node);
        }
Exemple #4
0
 public void ExportFileOrFolder(ShellItemViewModel item, bool convert, string targetFolder = null)
 {
     ExportPaths(new[] { item.FullPath }, (item.DropTargetPath + '\\').TrimStart('\\'), convert, targetFolder);
 }