Exemplo n.º 1
0
        public void ImportPP(string filename, IProgress <int> progress)
        {
            ppParser pp = new ppParser(filename);

            TreeNode parent = null;

            string name = Path.GetFileNameWithoutExtension(filename);

            trvFiles.DynamicInvoke(() =>
            {
                parent = trvFiles.Nodes.Add(name);
            });

            int counter = 0;

            foreach (IReadFile file in pp.Subfiles)
            {
                SubfileHolder tag = new SubfileHolder(new PPSource(file), file.Name);
                progress.Report(100 * counter++ / pp.Subfiles.Count);

                trvFiles.DynamicInvoke(() =>
                {
                    TreeNode node = parent.Nodes.Add(file.Name);
                    node.Tag      = tag;
                    SetAutoIcon(node);
                });
            }



            this.DynamicInvoke(() =>
            {
                IsModified = true;
            });
        }
Exemplo n.º 2
0
        public static void SetAutoIcon(TreeNode node)
        {
            SubfileHolder current = null;

            if (node.Tag != null)
            {
                current = node.Tag as SubfileHolder;
            }

            if (node.Level == 0)
            {
                node.ImageIndex = node.SelectedImageIndex = 0;
            }
            else if (current.Type == "Audio")
            {
                node.ImageIndex = node.SelectedImageIndex = 2;
            }
            else if (current.Type == "Image")
            {
                node.ImageIndex = node.SelectedImageIndex = 3;
            }
            else
            {
                node.ImageIndex = node.SelectedImageIndex = 1;
            }
        }
Exemplo n.º 3
0
        public void ImportFolder(string path)
        {
            var files = Directory.EnumerateFiles(path);

            var parent = trvFiles.Nodes.Add(Path.GetFileName(path));

            string name = Path.GetFileName(path);

            foreach (string file in files)
            {
                TreeNode node = parent.Nodes.Add(Path.GetFileName(file));

                var tag = new SubfileHolder(new FileSource(file), Path.GetFileName(file));
                node.Tag = tag;
                SetAutoIcon(node);
            }

            IsModified = true;
        }
Exemplo n.º 4
0
        public void TestCompression()
        {
            if (trvFiles.SelectedNode != null)
            {
                IProgress <Tuple <string, int> > progress = new Progress <Tuple <string, int> >((x) =>
                {
                    prgFileProgress.Value = x.Item2;
                    txtFileProg.AppendText(x.Item1);
                });
                ArchiveChunkCompression method = (ArchiveChunkCompression)cmbCompression.SelectedIndex;

                if (trvFiles.SelectedNode.Tag == null)
                {
                    //Is a PP file node
                    List <SubfileHolder> items = trvFiles.SelectedNode.Nodes
                                                 .Cast <TreeNode>()
                                                 .Select(x => x.Tag as SubfileHolder)
                                                 .ToList();

                    prgFileProgress.Value = 0;

                    int i = 0;

                    Task.Run(() =>
                    {
                        long ucb = 0;
                        long cb  = 0;

                        foreach (var item in items)
                        {
                            ucb += (long)item.Size;

                            using (Stream data = item.Source.GetStream())
                                cb += PPeX.Utility.TestCompression(data, method);

                            progress.Report(new Tuple <string, int>(
                                                "",
                                                100 * i / items.Count));
                        }

                        string uncompressedSize = PPeX.Utility.GetBytesReadable(ucb);

                        string size = PPeX.Utility.GetBytesReadable(cb);

                        string ratio = ((double)cb / ucb).ToString("P2");
                        switch (method)
                        {
                        case ArchiveChunkCompression.Uncompressed:
                            progress.Report(new Tuple <string, int>("No compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;

                        case ArchiveChunkCompression.LZ4:
                            progress.Report(new Tuple <string, int>("LZ4 compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;

                        case ArchiveChunkCompression.Zstandard:
                            progress.Report(new Tuple <string, int>("Zstandard compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;
                        }
                    });
                }
                else
                {
                    //Is a PP subfile node
                    SubfileHolder sh = trvFiles.SelectedNode.Tag as SubfileHolder;

                    using (Stream stream = sh.Source.GetStream())
                    {
                        string uncompressedSize = PPeX.Utility.GetBytesReadable(stream.Length);

                        long   bytes = PPeX.Utility.TestCompression(stream, method);
                        string size  = PPeX.Utility.GetBytesReadable(bytes);

                        string ratio = ((double)bytes / stream.Length).ToString("P2");
                        switch (method)
                        {
                        case ArchiveChunkCompression.Uncompressed:
                            progress.Report(new Tuple <string, int>("No compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;

                        case ArchiveChunkCompression.LZ4:
                            progress.Report(new Tuple <string, int>("LZ4 compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;

                        case ArchiveChunkCompression.Zstandard:
                            progress.Report(new Tuple <string, int>("Zstandard compression: " + uncompressedSize + " => " + size + " (" + ratio + ")\n", 100));
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void ExportItem()
        {
            if (trvFiles.SelectedNode != null)
            {
                IProgress <Tuple <string, int> > progress = new Progress <Tuple <string, int> >((x) =>
                {
                    prgFileProgress.Value = x.Item2;
                    txtFileProg.AppendText(x.Item1);
                });

                if (trvFiles.SelectedNode.Tag == null)
                {
                    //Is a PP file node
                    List <SubfileHolder> items = trvFiles.SelectedNode.Nodes
                                                 .Cast <TreeNode>()
                                                 .Select(x => x.Tag as SubfileHolder)
                                                 .ToList();

                    string path = ShowFolderDialog().FirstOrDefault();

                    if (string.IsNullOrEmpty(path))
                    {
                        return;
                    }

                    prgFileProgress.Value = 0;
                    txtFileProg.AppendText("Beginning export to \"" + path + "\"...\n");

                    int i = 0;

                    Task.Run(() =>
                    {
                        foreach (var item in items)
                        {
                            string filename = Path.Combine(path, item.Name);
                            i++;

                            if (File.Exists(filename))
                            {
                                progress.Report(new Tuple <string, int>(
                                                    "[" + i + " / " + items.Count + "] Skipping " + item.Name + " as it already exists\n",
                                                    i));

                                continue;
                            }

                            using (FileStream fs = new FileStream(filename, FileMode.CreateNew))
                            {
                                (item.Source as ArchiveFileSource).GetStream().CopyTo(fs);
                            }

                            progress.Report(new Tuple <string, int>(
                                                "[" + i + " / " + items.Count + "] Exported " + item.Name + " (" + item.Size + " bytes)\n",
                                                100 * i / items.Count));
                        }

                        progress.Report(new Tuple <string, int>(
                                            "Done!\n",
                                            100));
                    });
                }
                else
                {
                    //Is a PP subfile node
                    SubfileHolder sh = trvFiles.SelectedNode.Tag as SubfileHolder;

                    string path = ShowSaveFileDialog("All Files|*.*", sh.Name);

                    if (string.IsNullOrEmpty(path))
                    {
                        return;
                    }

                    using (FileStream fs = new FileStream(path, FileMode.Create))
                    {
                        (sh.Source as ArchiveFileSource).GetStream().CopyTo(fs);
                        //sh.Source.GetStream().CopyTo(fs);
                    }

                    prgFileProgress.Value = 100;
                    txtFileProg.AppendText("Exported " + Path.GetFileName(path) + " (" + sh.Source.Size + " bytes)\n");
                }
            }
        }
Exemplo n.º 6
0
        public void ExportItem()
        {
            if (trvFiles.SelectedNode != null)
            {
                IProgress <Tuple <string, int> > progress = new Progress <Tuple <string, int> >((x) =>
                {
                    prgFileProgress.Value = x.Item2;
                    txtFileProg.AppendText(x.Item1);
                });

                if (trvFiles.SelectedNode.Tag == null)
                {
                    List <SubfileHolder> items = trvFiles.SelectedNode.Nodes
                                                 .Cast <TreeNode>()
                                                 .Select(x => x.Tag as SubfileHolder)
                                                 .ToList();

                    CommonOpenFileDialog dialog = new CommonOpenFileDialog
                    {
                        IsFolderPicker = true,
                        Multiselect    = false
                    };
#warning somehow change the button text to save

                    if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
                    {
                        return;
                    }

                    prgFileProgress.Value = 0;
                    txtFileProg.AppendText("Beginning export to \"" + dialog.FileName + "\"...\n");

                    int i = 0;

                    Task.Run(() =>
                    {
                        foreach (var item in items)
                        {
                            string filename = Path.Combine(dialog.FileName, item.Name);
                            i++;

                            if (File.Exists(filename))
                            {
                                progress.Report(new Tuple <string, int>(
                                                    "[" + i + " / " + items.Count + "] Skipping " + item.Name + " as it already exists\n",
                                                    i));

                                continue;
                            }

                            using (FileStream fs = new FileStream(filename, FileMode.CreateNew))
                            {
                                item.Source.GetStream().CopyTo(fs);
                            }

                            progress.Report(new Tuple <string, int>(
                                                "[" + i + " / " + items.Count + "] Exported " + item.Name + " (" + item.Size + " bytes)\n",
                                                100 * i / items.Count));
                        }

                        progress.Report(new Tuple <string, int>(
                                            "Done!\n",
                                            100));
                    });
                }
                else
                {
                    SubfileHolder        sh     = trvFiles.SelectedNode.Tag as SubfileHolder;
                    CommonSaveFileDialog dialog = new CommonSaveFileDialog()
                    {
                        DefaultFileName = sh.Name
                    };
                    dialog.Filters.Add(new CommonFileDialogFilter("All Files", "*.*"));

                    if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
                    {
                        return;
                    }

                    using (FileStream fs = new FileStream(dialog.FileName, FileMode.Create))
                    {
                        sh.Source.GetStream().CopyTo(fs);
                    }

                    prgFileProgress.Value = 100;
                    txtFileProg.AppendText("Exported " + Path.GetFileName(dialog.FileName) + " (" + sh.Source.Size + " bytes)\n");
                }
            }
        }