private void _RebuildTreeView(BackgroundWorker wrk) { DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { treeView.Items.Clear(); RDAFolder root = CurrentReader.rdaFolder; foreach (RDAFolder folder in root.Folders) { treeView.Items.Add(new RDAFolderTreeViewItem() { Folder = folder, Header = ControlExtension.BuildImageTextblock("pack://application:,,,/Images/Icons/folder.png", folder.Name) }); } foreach (RDAFile file in root.Files) { treeView.Items.Add(Misc.RDAFileExtension.ToTreeViewItem(file)); } foreach (RDASkippedDataSection skippedBlock in CurrentReader.SkippedDataSections) { string title = skippedBlock.blockInfo.fileCount + " encrypted files"; treeView.Items.Add(new RDASkippedDataSectionTreeViewItem() { Section = skippedBlock, Header = ControlExtension.BuildImageTextblock("pack://application:,,,/Images/Icons/error.png", title) }); } }); }
private void context_Extract_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog() != DialogResult.OK) { return; } BackgroundWorker wrk = new BackgroundWorker(); wrk.WorkerReportsProgress = true; MainWindow.CurrentMainWindow.progressBar_Status.Visibility = Visibility.Visible; wrk.ProgressChanged += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, (() => { MainWindow.CurrentMainWindow.label_Status.Text = RDAExplorer.RDAFileExtension.ExtractAll_LastMessage; MainWindow.CurrentMainWindow.progressBar_Status.Value = e2.ProgressPercentage; })); wrk.RunWorkerCompleted += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, (() => { MainWindow.CurrentMainWindow.label_Status.Text = MainWindow.CurrentMainWindow.CurrentReader.rdaFolder.GetAllFiles().Count + " files"; MainWindow.CurrentMainWindow.progressBar_Status.Visibility = Visibility.Collapsed; })); wrk.DoWork += (s, e2) => RDAExplorer.RDAFileExtension.ExtractAll(Folder.GetAllFiles(), folderBrowserDialog.SelectedPath, wrk); wrk.RunWorkerAsync(); }
private static void DecodeTaskWorker() { var loop = true; // exit handler App.ApplicationFinalize += () => { loop = false; // ReSharper disable once AccessToDisposedClosure _decodeSignal.Set(); }; // ReSharper disable once LoopVariableIsNeverChangedInsideLoop while (loop) { _decodeSignal.Reset(); while (true) { Tuple <Guid, Uri, byte[], int, int> item; lock (_decodeStack) { if (_decodeStack.Count == 0) { break; } item = _decodeStack.First.Value; _decodeStack.RemoveFirst(); } // create image var bitmap = CreateImage(item.Item3, item.Item4, item.Item5); // apply image var id = item.Item1; var uri = item.Item2; Tuple <IImageVisual, Uri, int, int> tuple; if (_visualTable.TryRemove(id, out tuple) && bitmap != null && tuple.Item1.Id == id && tuple.Item2 == uri) { // push dispatcher queue ApplyImage(tuple.Item1, uri, bitmap); } // reset signal _decodeSignal.Reset(); } _decodeSignal.Wait(); } // dispose decode signal _decodeSignal.Dispose(); // cleaning up dispatcher. DispatcherExtension.BeginInvokeShutdown(); }
private void OpenFile(string fileName, bool isreadonly) { RDAReader reader = new RDAReader(); ResetDocument(); CurrentFileName = fileName; if (!isreadonly) { fileName = DirectoryExtension.GetTempWorkingDirectory() + "\\" + Path.GetFileName(fileName); } else { file_Save.IsEnabled = false; } CurrentReader = reader; reader.FileName = fileName; progressBar_Status.Visibility = Visibility.Visible; Title = GetTitle() + " - " + Path.GetFileName(reader.FileName); reader.backgroundWorker = new BackgroundWorker(); reader.backgroundWorker.WorkerReportsProgress = true; reader.backgroundWorker.ProgressChanged += (sender2, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { progressBar_Status.Value = e2.ProgressPercentage; label_Status.Text = reader.backgroundWorkerLastMessage; }); reader.backgroundWorker.DoWork += (sender2, e2) => { try { if (!isreadonly) { DispatcherExtension.Dispatch(System.Windows.Application.Current, () => label_Status.Text = "Copying *.rda file to a temparary directory ..."); FileSystem.CopyFile(CurrentFileName, fileName, UIOption.AllDialogs, UICancelOption.ThrowException); } reader.ReadRDAFile(); } catch (Exception ex) { DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { int num = (int)MessageWindow.Show(ex.Message); NewFile(); }); } }; reader.backgroundWorker.RunWorkerCompleted += (sender2, e2) => { progressBar_Status.Visibility = Visibility.Collapsed; RebuildTreeView(); }; reader.backgroundWorker.RunWorkerAsync(); }
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) { base.OnItemsChanged(e); if (e.Action != NotifyCollectionChangedAction.Remove || e.OldStartingIndex <= 0 || Items.Count == 0) { return; } new Thread((ParameterizedThreadStart) delegate { Thread.Sleep(75); DispatcherExtension.Dispatch <Application>(Application.Current, app => (Items[e.OldStartingIndex - 1] as TreeViewItem).IsSelected = true); }).Start(); }
private void SaveFile(string fileName) { SaveRDAFileWindow saveRdaFileWindow = new SaveRDAFileWindow(); saveRdaFileWindow.Folder = CurrentReader.rdaFolder; saveRdaFileWindow.field_OutputFile.Text = fileName; saveRdaFileWindow.MustChooseFolderVersionDueToEncryptedBlocks = CurrentReader.SkippedDataSections.Count > 0; if (!saveRdaFileWindow.ShowDialog().GetValueOrDefault()) { return; } fileName = saveRdaFileWindow.field_OutputFile.Text; FileHeader.Version version = CurrentReader.SkippedDataSections.Count > 0 ? CurrentReader.rdaFolder.Version : saveRdaFileWindow.SelectedVersion; bool compress = saveRdaFileWindow.check_IsCompressed.IsChecked.Value; if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } RDAWriter writer = new RDAWriter(CurrentReader.rdaFolder); BackgroundWorker wrk = new BackgroundWorker(); wrk.WorkerReportsProgress = true; progressBar_Status.Visibility = Visibility.Visible; wrk.ProgressChanged += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = writer.UI_LastMessage; progressBar_Status.Value = e2.ProgressPercentage; }); wrk.RunWorkerCompleted += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = CurrentReader.rdaFolder.GetAllFiles().Count + " files"; progressBar_Status.Visibility = Visibility.Collapsed; }); wrk.DoWork += (s, e2) => { try { writer.Write(fileName, version, compress, CurrentReader, wrk); } catch (Exception ex) { int num2 = (int)DispatcherExtension.Dispatch(System.Windows.Application.Current, () => MessageWindow.Show(ex.Message)); } }; wrk.RunWorkerAsync(); return; }
private void archive_ExtractSelected_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog dlg = new FolderBrowserDialog(); dlg.SelectedPath = Settings.Default.LastSelectedPathForExtraction; if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } Settings.Default.LastSelectedPathForExtraction = dlg.SelectedPath; // Settings are saved when the application exits BackgroundWorker wrk = new BackgroundWorker(); wrk.WorkerReportsProgress = true; progressBar_Status.Visibility = Visibility.Visible; wrk.ProgressChanged += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = RDAExplorer.RDAFileExtension.ExtractAll_LastMessage; progressBar_Status.Value = e2.ProgressPercentage; }); wrk.RunWorkerCompleted += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = CurrentReader.rdaFolder.GetAllFiles().Count + " files"; progressBar_Status.Visibility = Visibility.Collapsed; }); wrk.DoWork += (s, e2) => { try { List <RDAFile> list = new List <RDAFile>(); foreach (RDAFileTreeViewItem fileTreeViewItem in Enumerable.OfType <RDAFileTreeViewItem>(treeView.SelectedItems)) { list.Add(fileTreeViewItem.File); } foreach (RDAFolderTreeViewItem folderTreeViewItem in Enumerable.OfType <RDAFolderTreeViewItem>(treeView.SelectedItems)) { list.AddRange(folderTreeViewItem.Folder.GetAllFiles()); } RDAExplorer.RDAFileExtension.ExtractAll(Enumerable.ToList(Enumerable.Distinct(list)), dlg.SelectedPath, wrk); } catch (Exception ex1) { Exception ex = ex1; int num = (int)DispatcherExtension.Dispatch(System.Windows.Application.Current, () => MessageWindow.Show(ex.Message)); } }; wrk.RunWorkerAsync(); }
public void RebuildTreeView() { BackgroundWorker wrk = new BackgroundWorker(); wrk.WorkerReportsProgress = true; progressBar_Status.Visibility = Visibility.Visible; wrk.ProgressChanged += (s, e) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { progressBar_Status.Value = e.ProgressPercentage; label_Status.Text = "Updating UI"; }); wrk.DoWork += (s, e) => _RebuildTreeView(wrk); wrk.RunWorkerCompleted += (s, e) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => progressBar_Status.Visibility = Visibility.Collapsed); wrk.RunWorkerAsync(); }
private void archive_ExtractAll_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } BackgroundWorker wrk = new BackgroundWorker(); wrk.WorkerReportsProgress = true; progressBar_Status.Visibility = Visibility.Visible; wrk.ProgressChanged += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = RDAExplorer.RDAFileExtension.ExtractAll_LastMessage; progressBar_Status.Value = e2.ProgressPercentage; }); wrk.RunWorkerCompleted += (s, e2) => DispatcherExtension.Dispatch(System.Windows.Application.Current, () => { label_Status.Text = CurrentReader.rdaFolder.GetAllFiles().Count + " files"; progressBar_Status.Visibility = Visibility.Collapsed; }); wrk.DoWork += (s, e2) => { try { RDAExplorer.RDAFileExtension.ExtractAll(CurrentReader.rdaFolder.GetAllFiles(), dlg.SelectedPath, wrk); } catch (Exception ex1) { Exception ex = ex1; int num = (int)DispatcherExtension.Dispatch(System.Windows.Application.Current, () => MessageWindow.Show(ex.Message)); } }; wrk.RunWorkerAsync(); }