private void StartReadingTlkButton_Click(object sender, RoutedEventArgs e) { BusyReading(true); TalkFile.Fileformat ff = TalkFile.Fileformat.Xml; var loadingWorker = new BackgroundWorker(); loadingWorker.WorkerReportsProgress = true; loadingWorker.ProgressChanged += delegate(object sender2, ProgressChangedEventArgs e2) { readingTlkProgressBar.Value = e2.ProgressPercentage; }; loadingWorker.DoWork += delegate { try { TalkFile tf = new TalkFile(); tf.LoadTlkData(_inputTlkFilePath); tf.ProgressChanged += loadingWorker.ReportProgress; tf.DumpToFile(_outputTextFilePath, ff); // debug // tf.PrintHuffmanTree(); tf.ProgressChanged -= loadingWorker.ReportProgress; } catch (FileNotFoundException) { System.Windows.MessageBox.Show( Properties.Resources.AlertExceptionTlkNotFound, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); } catch (IOException) { System.Windows.MessageBox.Show( Properties.Resources.AlertExceptionTlkFormat, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { string message = Properties.Resources.AlertExceptionGeneric; message += Properties.Resources.AlertExceptionGenericDescription + ex.Message; System.Windows.MessageBox.Show(message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Exclamation); } }; loadingWorker.RunWorkerCompleted += delegate { BusyReading(false); System.Windows.MessageBox.Show(Properties.Resources.AlertTlkLoadingFinished, Properties.Resources.Done, MessageBoxButton.OK, MessageBoxImage.Information); }; loadingWorker.RunWorkerAsync(); }
private void StartReadingTlkButton_Click(object sender, RoutedEventArgs e) { BusyReading(true); var loadingWorker = new BackgroundWorker { WorkerReportsProgress = true }; loadingWorker.ProgressChanged += delegate(object sender2, ProgressChangedEventArgs e2) { readingTlkProgressBar.Value = e2.ProgressPercentage; }; loadingWorker.DoWork += delegate { try { TalkFile tf = new TalkFile(); tf.LoadTlkData(InputTlkFilePath); tf.ProgressChanged += loadingWorker.ReportProgress; tf.DumpToFile(OutputTextFilePath); // debug // tf.PrintHuffmanTree(); tf.ProgressChanged -= loadingWorker.ReportProgress; MessageBox.Show("Finished reading TLK file.", "Done!", MessageBoxButton.OK, MessageBoxImage.Information); } catch (FileNotFoundException) { MessageBox.Show("Selected TLK file was not found or is corrupted.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (IOException) { MessageBox.Show("Error reading TLK file!\nPlease make sure you have chosen a file in a TLK format for Mass Effect 2 or 3.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }; loadingWorker.RunWorkerCompleted += delegate { BusyReading(false); }; loadingWorker.RunWorkerAsync(); }