Exemple #1
0
        public void RefreshFileContent()
        {
            this.subFiles.Clear();

            if (this.libraryFolder.Exists)
            {
                IList <FileInfo> childFiles = null;

                try
                {
                    childFiles = LibraryFile.GetChildFiles(this.libraryFolder);
                }
                catch (Exception)
                {
                }

                if (childFiles != null)
                {
                    foreach (FileInfo fileInFolder in childFiles)
                    {
                        LibraryFile file = new LibraryFile(fileInFolder);
                        this.subFiles.Add(file);
                    }
                }
            }
        }
        public void OpenTagFile(TreeNode treeNode)
        {
            if (IsFileTreeNode(treeNode))
            {
                LibraryFile labFile = (LibraryFile)treeNode.Tag;

                labFile.OpenFile();
            }
        }
        private void tVLibraryTree_DragOver(object sender, DragEventArgs e)
        {
            bool canAdd = false;

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                Point treePoint = tVLibraryTree.PointToClient(new Point(e.X, e.Y));

                TreeNode node = tVLibraryTree.GetNodeAt(treePoint);

                if (node != null)
                {
                    if (IsDirectoryInfoTreeNode(node))
                    {
                        tVLibraryTree.SelectedNode = node;
                    }
                    else if (IsFileTreeNode(node))
                    {
                        tVLibraryTree.SelectedNode = node.Parent;
                    }

                    string[] filePathCollection = (string[])e.Data.GetData(DataFormats.FileDrop);

                    foreach (string filePath in filePathCollection)
                    {
                        if (File.Exists(filePath) && LibraryFile.IsInterestingFile(Path.GetExtension(filePath)))
                        {
                            canAdd = true;
                            break;
                        }
                    }
                }
            }

            if (canAdd)
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

            this.Activate();
            this.Show();
        }
        public void OpenTagFolder(TreeNode treeNode)
        {
            if (treeNode != null && treeNode.Tag != null)
            {
                if (IsDirectoryInfoTreeNode(treeNode))
                {
                    LibraryFolder libFolder = (LibraryFolder)treeNode.Tag;

                    libFolder.OpenFolder();
                }
                else if (IsFileTreeNode(treeNode))
                {
                    LibraryFile labFile = (LibraryFile)treeNode.Tag;

                    labFile.OpenFileFolder();
                }
            }
        }
Exemple #5
0
        public static LibraryFile CreateLibraryFileFromXml(XmlNode node)
        {
            LibraryFile result = null;

            if (node.Name == xmlNodeName)
            {
                XmlAttribute attr;

                attr = node.Attributes["FullName"];
                if (attr != null && !string.IsNullOrEmpty(attr.Value))
                {
                    FileInfo file = new FileInfo(attr.Value);

                    result = new LibraryFile(file);
                }
            }

            return(result);
        }
        private void FillFiles(XmlNode root, DirectoryInfo folder, string parentFolderName)
        {
            DirectoryInfo[] subFolderCollection = folder.GetDirectories();
            foreach (DirectoryInfo subFolder in subFolderCollection)
            {
                FillFiles(root, subFolder, parentFolderName);
            }

            IEnumerable <FileInfo> childFiles = folder.EnumerateFiles();

            //IList<FileInfo> childFiles = LibraryFile.GetChildFiles(folder);

            foreach (FileInfo fileInFolder in childFiles)
            {
                XmlNode fileNode = root.OwnerDocument.CreateElement("File");
                root.AppendChild(fileNode);

                XmlAttribute fileName = root.OwnerDocument.CreateAttribute("FileName");
                fileNode.Attributes.Append(fileName);
                fileName.Value = fileInFolder.Name;

                XmlAttribute fileHashString = root.OwnerDocument.CreateAttribute("HashString");
                fileNode.Attributes.Append(fileHashString);
                fileHashString.Value = LibraryFile.GetHashString(fileInFolder);

                XmlAttribute fileExtension = root.OwnerDocument.CreateAttribute("Extension");
                fileNode.Attributes.Append(fileExtension);
                fileExtension.Value = fileInFolder.Extension.ToLower();

                XmlAttribute filePath = root.OwnerDocument.CreateAttribute("FilePath");
                fileNode.Attributes.Append(filePath);
                filePath.Value = fileInFolder.DirectoryName;

                string relative = fileInFolder.DirectoryName.Replace(parentFolderName, string.Empty);
                relative = relative.TrimStart('\\');

                XmlAttribute relativePath = root.OwnerDocument.CreateAttribute("RelativePath");
                fileNode.Attributes.Append(relativePath);
                relativePath.Value = relative;
            }
        }
        private void SearchAndAddIntoListView(TreeNodeCollection treeNodeCollection, string searchPattern)
        {
            foreach (TreeNode node in treeNodeCollection)
            {
                if (this.ownerForm.IsFileTreeNode(node))
                {
                    LibraryFile labFile = (LibraryFile)node.Tag;

                    if (FileNameMatchPattern(labFile.FileName, searchPattern))
                    {
                        ListViewItem lvi = new ListViewItem(labFile.FileName, node.ImageKey);
                        lvi.Tag = node;
                        lvi.SubItems.Add(node.Parent.FullPath);

                        lVBookSearch.Items.Add(lvi);
                    }
                }

                SearchAndAddIntoListView(node.Nodes, searchPattern);
            }
        }
Exemple #8
0
        public static LibraryFolder CreateLibraryFolderFromXml(XmlNode node)
        {
            LibraryFolder result = null;

            if (node.Name == xmlNodeName)
            {
                XmlAttribute attr;

                attr = node.Attributes["FullName"];
                if (attr != null && !string.IsNullOrEmpty(attr.Value))
                {
                    DirectoryInfo directory = new DirectoryInfo(attr.Value);

                    result = new LibraryFolder(directory);

                    XmlNodeList list;

                    list = node.SelectNodes(xmlNodeName);
                    foreach (XmlNode item in list)
                    {
                        LibraryFolder folder = LibraryFolder.CreateLibraryFolderFromXml(item);

                        if (folder.subFiles.Count > 0 || folder.subFolders.Count > 0)
                        {
                            result.subFolders.Add(folder);
                        }
                    }

                    list = node.SelectNodes(LibraryFile.xmlNodeName);
                    foreach (XmlNode item in list)
                    {
                        LibraryFile file = LibraryFile.CreateLibraryFileFromXml(item);

                        result.subFiles.Add(file);
                    }
                }
            }

            return(result);
        }
        private TreeNode CreateTreeNodeForFile(LibraryFile fileInFolder)
        {
            TreeNode fileNode = new TreeNode(fileInFolder.FileName);

            fileNode.Tag = fileInFolder;

            string extension = fileInFolder.FileExtension;

            if (imageList.Images.ContainsKey(extension))
            {
                fileNode.ImageKey         = extension;
                fileNode.SelectedImageKey = extension;
            }
            else
            {
                fileNode.ImageKey         = "file";
                fileNode.SelectedImageKey = "file";
            }

            fileNode.ContextMenuStrip = contMSTreeViewFile;

            return(fileNode);
        }