예제 #1
0
        private void ReplaceAction(object sender, EventArgs args)
        {
            //Add folders and files from selected path
            FolderSelectDialog ofd = new FolderSelectDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //Clear all nodes
                foreach (var node in TreeViewExtensions.Collect(Nodes))
                {
                    if (node is ArchiveFileWrapper)
                    {
                        ArchiveFile.DeleteFile(((ArchiveFileWrapper)node).ArchiveFileInfo);
                    }
                }

                Nodes.Clear();

                var proccessedFiles = TreeHelper.ReadFiles(ofd.SelectedPath);

                string folderPath = TreeHelper.GetFolderAbsoultePath(this, RootNode);
                for (int i = 0; i < proccessedFiles.Count; i++)
                {
                    ArchiveFile.AddFile(new ArchiveFileInfo()
                    {
                        FileName = $"{folderPath}/{proccessedFiles[i].Item1}",
                        FileData = File.ReadAllBytes(proccessedFiles[i].Item2),
                    });
                }
                RootNode.FillTreeNodes();
            }
        }
예제 #2
0
        private void ClearAction(object sender, EventArgs args)
        {
            foreach (var node in TreeViewExtensions.Collect(Nodes))
            {
                if (node is ArchiveFileWrapper)
                {
                    ArchiveFile.DeleteFile(((ArchiveFileWrapper)node).ArchiveFileInfo);
                }
            }

            Nodes.Clear();
        }
예제 #3
0
        public static void RemoveFolder(TreeNode folderNode, IArchiveFile archiveFile)
        {
            if (!archiveFile.CanDeleteFiles) return;

            foreach (var node in TreeViewExtensions.Collect(folderNode.Nodes))
            {
                if (node is ArchiveFileWrapper)
                    archiveFile.DeleteFile(((ArchiveFileWrapper)node).ArchiveFileInfo);
            }

            var parentNode = folderNode.Parent;
            parentNode.Nodes.Remove(folderNode);
        }
예제 #4
0
        private void ReplaceAction(object sender, EventArgs args)
        {
            //Add folders and files from selected path
            FolderSelectDialog ofd = new FolderSelectDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //Clear all nodes
                foreach (var node in TreeViewExtensions.Collect(Nodes))
                {
                    if (node is ArchiveFileWrapper)
                    {
                        ArchiveFile.DeleteFile(((ArchiveFileWrapper)node).ArchiveFileInfo);
                    }
                }

                Nodes.Clear();

                TreeHelper.AddFiles(this, RootNode, Directory.GetFiles(ofd.SelectedPath));
            }
        }
예제 #5
0
        public static string[] ExtractAllFiles(string ParentPath, TreeNodeCollection Nodes, string overridePath = "")
        {
            List <string> filesExtracted = new List <string>();

            if (overridePath == string.Empty)
            {
                FolderSelectDialog folderDialog = new FolderSelectDialog();
                if (folderDialog.ShowDialog() != DialogResult.OK)
                {
                    return(new string[0]);
                }

                overridePath = folderDialog.SelectedPath;
            }

            STProgressBar progressBar = new STProgressBar();

            progressBar.Task = "Extracing Files...";
            progressBar.Refresh();
            progressBar.Value         = 0;
            progressBar.StartPosition = FormStartPosition.CenterScreen;
            progressBar.Show();

            var Collection = TreeViewExtensions.Collect(Nodes);

            int Curfile = 0;

            foreach (TreeNode file in Collection)
            {
                if (file is ArchiveFileWrapper)
                {
                    string FilePath      = ((ArchiveFileWrapper)file).ArchiveFileInfo.FileName;
                    string FolderPath    = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
                    string FolderPathDir = Path.Combine(overridePath, FolderPath);

                    if (!Directory.Exists(FolderPathDir))
                    {
                        Directory.CreateDirectory(FolderPathDir);
                    }

                    string FileName = file.Text.RemoveIllegaleFileNameCharacters();

                    FilePath = Path.Combine(FolderPath, FileName);

                    if (ParentPath != string.Empty)
                    {
                        FilePath = FilePath.Replace(ParentPath, string.Empty);
                    }

                    var path = Path.Combine(overridePath, FilePath);

                    progressBar.Task  = $"Extracting File {file}";
                    progressBar.Value = (Curfile++ *100) / Collection.Count();
                    progressBar.Refresh();
                    CreateDirectoryIfExists($"{path}");

                    if (file is ArchiveFileWrapper)
                    {
                        filesExtracted.Add($"{path}");

                        File.WriteAllBytes($"{path}",
                                           ((ArchiveFileWrapper)file).ArchiveFileInfo.FileData);
                    }
                }
            }

            progressBar.Value = 100;
            progressBar.Refresh();
            progressBar.Close();

            return(filesExtracted.ToArray());
        }
예제 #6
0
        public static string[] ExtractAllFiles(string ParentPath, TreeNodeCollection Nodes, string overridePath = "")
        {
            List <string> filesExtracted = new List <string>();

            if (overridePath == string.Empty)
            {
                FolderSelectDialog folderDialog = new FolderSelectDialog();
                if (folderDialog.ShowDialog() != DialogResult.OK)
                {
                    return(new string[0]);
                }

                overridePath = folderDialog.SelectedPath;
            }

            STProgressBar progressBar = new STProgressBar();

            progressBar.Task = "Extracing Files...";
            progressBar.Refresh();
            progressBar.Value         = 0;
            progressBar.StartPosition = FormStartPosition.CenterScreen;
            progressBar.Show();

            Thread Thread = new Thread((ThreadStart)(() =>
            {
                var Collection = TreeViewExtensions.Collect(Nodes).ToList();
                Console.WriteLine($"Collection {Collection.Count}");

                int Curfile = 0;
                foreach (TreeNode node in Collection)
                {
                    if (progressBar.IsDisposed || progressBar.Disposing)
                    {
                        break;
                    }

                    ArchiveFileInfo file = null;

                    if (node.Tag != null && node.Tag is ArchiveFileInfo)
                    {
                        file = (ArchiveFileInfo)node.Tag;
                    }
                    else if (node is ArchiveFileWrapper)
                    {
                        file = ((ArchiveFileWrapper)node).ArchiveFileInfo;
                    }

                    if (file != null)
                    {
                        string FilePath = file.FileName;
                        string FolderPath = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
                        string FolderPathDir = Path.Combine(overridePath, FolderPath);

                        if (!Directory.Exists(FolderPathDir))
                        {
                            Directory.CreateDirectory(FolderPathDir);
                        }

                        string FileName = Path.GetFileName(file.FileName).RemoveIllegaleFileNameCharacters();

                        FilePath = Path.Combine(FolderPath, FileName);

                        if (ParentPath != string.Empty)
                        {
                            FilePath = FilePath.Replace(ParentPath, string.Empty);
                        }

                        var path = $"{overridePath}/{FilePath}";

                        if (progressBar.InvokeRequired)
                        {
                            progressBar.Invoke((MethodInvoker) delegate {
                                // Running on the UI thread
                                progressBar.Task = $"Extracting File {FileName}";
                                progressBar.Value = (Curfile++ *100) / Collection.Count;
                                progressBar.Refresh();
                            });
                        }

                        CreateDirectoryIfExists($"{path}");

                        filesExtracted.Add($"{path}");

                        if (file.FileFormat != null && file.FileFormat.CanSave)
                        {
                            file.SaveFileFormat();
                        }

                        if (file.FileDataStream != null)
                        {
                            file.FileDataStream.ExportToFile(path);
                        }
                        else
                        {
                            File.WriteAllBytes($"{path}", file.FileData);
                        }
                    }
                }

                if (progressBar.InvokeRequired)
                {
                    progressBar.Invoke((MethodInvoker) delegate {
                        progressBar.Value = 100;
                        progressBar.Refresh();
                        progressBar.Close();
                    });
                }
                else
                {
                    progressBar.Value = 100;
                    progressBar.Refresh();
                    progressBar.Close();
                }
            }));

            Thread.Start();

            return(filesExtracted.ToArray());
        }