Ejemplo n.º 1
0
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            ArchiveExplorer wnd = new ArchiveExplorer();

            wnd.Show();

            if (e.Args.Length == 1)
            {
                await wnd.OpenP4kAsync(e.Args[0]);
            }
        }
Ejemplo n.º 2
0
        public ArchiveExplorer()
        {
            ArchiveExplorer._instance = this;

            InitializeComponent();

            this.Icon = IconManager.GetCachedFileIcon("data.zip", IconManager.IconSize.Large);

            trvFileExploder.Focus();

            new Thread(async() =>
            {
                while (true)
                {
                    await Task.Delay(FILTER_PING);

                    while (this._lastFilterText != this._activeFilterText)
                    {
                        var now = this._lastFilterTime ?? DateTime.Now;

                        while ((DateTime.Now - now).TotalMilliseconds < FILTER_DELAY)
                        {
                            await Task.Delay(FILTER_PING);
                            now = this._lastFilterTime ?? DateTime.Now;
                        }

                        if (this._root != null)
                        {
                            var filterText = this._lastFilterText;

                            var sw = new Stopwatch();

                            sw.Start();

                            var allChildren = this._root.AllChildren.ToArray();

                            await this.Dispatcher.Invoke(async() =>
                            {
                                foreach (var child in allChildren)
                                {
                                    child.IsHidden = !this.Filter(child);
                                }
                            });

                            // await this.NotifyNodesAsync(this._root);

                            sw.Stop();

                            await ArchiveExplorer.UpdateStatus($"Filter took {sw.ElapsedMilliseconds:#,##0}ms");

                            this._activeFilterText = filterText;
                        }

                        await Task.Delay(FILTER_PING);
                    }
                }
            }).Start();

            new Thread(async() =>
            {
                while (true)
                {
                    await this.Dispatcher.Invoke(async() =>
                    {
                        await ArchiveExplorer._updateDelegate(this.barProgress);
                    });

                    await Task.Delay(100);
                }
            }).Start();
        }
Ejemplo n.º 3
0
        public async Task <Boolean> ExtractNodeAsync(ITreeItem selectedItem, Boolean useTemp = false)
        {
            if (selectedItem == null)
            {
                return(false);
            }

            Boolean?result = false;
            String  path   = String.Empty;

            if (useTemp)
            {
                path   = Path.Combine(Path.GetTempPath(), "unp4k", selectedItem.Title);
                result = true;
            }

            var extractMode = ExtractModeEnum.NewOrLatest;

            if (String.IsNullOrWhiteSpace(path))
            {
                if (selectedItem is IStreamTreeItem)
                {
                    var dlg = new VistaSaveFileDialog
                    {
                        FileName        = selectedItem.Title,
                        OverwritePrompt = true,
                        Title           = $"Export {selectedItem.Text} File",
                        Filter          = $"Selected File|{Path.GetExtension(selectedItem.Title)}",
                    };

                    result = dlg.ShowDialog();
                    path   = dlg.FileName;

                    extractMode = ExtractModeEnum.Overwrite;
                }

                else if (selectedItem is IBranchItem)
                {
                    var dlg = new VistaFolderBrowserDialog
                    {
                        Description            = $"Export {selectedItem.Text} Directory",
                        UseDescriptionForTitle = true,
                        SelectedPath           = selectedItem.Title,
                    };

                    result = dlg.ShowDialog();
                    path   = dlg.SelectedPath;

                    extractMode = ExtractModeEnum.NewOrLatest;
                }
            }

            if (result == true)
            {
                this._filesSelected = await this.CountNodesAsync(selectedItem);

                this._filesExtracted = 0;

                var oldProgress = ArchiveExplorer.RegisterProgress(async(ProgressBar barProgress) =>
                {
                    barProgress.Maximum = this._filesSelected + 1;                     // Add 1 as we increment early
                    barProgress.Value   = this._filesExtracted;

                    await ArchiveExplorer.UpdateStatus($"Extracting file {this._filesExtracted:#,##0}/{this._filesSelected:#,##0} from archive");

                    await Task.CompletedTask;
                });

                var sw = new Stopwatch();

                sw.Start();

                result &= await this.ExtractNodeAsync(selectedItem, path, extractMode);

                sw.Stop();

                await ArchiveExplorer.UpdateStatus($"Extracted {this._filesExtracted:#,##0} files in {sw.ElapsedMilliseconds:#,000}ms");

                ArchiveExplorer.RegisterProgress(oldProgress);

                if (useTemp && (File.Exists(path) || Directory.Exists(path)))
                {
                    System.Diagnostics.Process.Start(path);
                }
            }

            return(result ?? false);
        }