diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index a2cf846..5722231 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -2211,6 +2211,39 @@ namespace SourceGenWPF { return -1; } + public void ShowFileHexDump() { + OpenFileDialog fileDlg = new OpenFileDialog() { + Filter = Res.Strings.FILE_FILTER_ALL, + FilterIndex = 1 + }; + if (fileDlg.ShowDialog() != true) { + return; + } + string fileName = fileDlg.FileName; + FileInfo fi = new FileInfo(fileName); + if (fi.Length > Tools.WpfGui.HexDumpViewer.MAX_LENGTH) { + string msg = string.Format(Res.Strings.OPEN_DATA_TOO_LARGE_FMT, + fi.Length / 1024, Tools.WpfGui.HexDumpViewer.MAX_LENGTH / 1024); + MessageBox.Show(msg, Res.Strings.OPEN_DATA_FAIL_CAPTION, + MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + byte[] data; + try { + data = File.ReadAllBytes(fileName); + } catch (Exception ex) { + // not expecting this to happen + MessageBox.Show(ex.Message); + return; + } + + // Fire and forget. + Tools.WpfGui.HexDumpViewer dlg = new Tools.WpfGui.HexDumpViewer(mMainWin, + data, mOutputFormatter); + dlg.SetFileName(Path.GetFileName(fileName)); + dlg.Show(); + } + public void ShowHexDump() { if (mHexDumpDialog == null) { // Create and show modeless dialog. This one is "always on top" by default, diff --git a/SourceGenWPF/Res/Strings.xaml b/SourceGenWPF/Res/Strings.xaml index 7d4d60d..4487692 100644 --- a/SourceGenWPF/Res/Strings.xaml +++ b/SourceGenWPF/Res/Strings.xaml @@ -79,7 +79,7 @@ limitations under the License. Unable to load contents of data file The file could not be opened: {0}. Unable to read the entire file - File is too large ({0:N0} KiB, {1:N0} KiB max). + File is too large ({0:N0} KiB, max is {1:N0} KiB). The file is {0:N0} bytes long, but the project expected {1:N0}. The file has CRC {0}, but the project expected {1}. Failed diff --git a/SourceGenWPF/Tools/WpfGui/HexDumpViewer.xaml.cs b/SourceGenWPF/Tools/WpfGui/HexDumpViewer.xaml.cs index 3e61d2a..a7f93ab 100644 --- a/SourceGenWPF/Tools/WpfGui/HexDumpViewer.xaml.cs +++ b/SourceGenWPF/Tools/WpfGui/HexDumpViewer.xaml.cs @@ -125,6 +125,13 @@ namespace SourceGenWPF.Tools.WpfGui { // Debug.WriteLine("Column width: " + hexDumpData.Columns[0].ActualWidth); //} + /// + /// Sets the filename associated with the data. This is for display purposes only. + /// + public void SetFileName(string fileName) { + Title = fileName; + } + private void CharConvComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ReplaceFormatter(); diff --git a/SourceGenWPF/WpfGui/MainWindow.xaml b/SourceGenWPF/WpfGui/MainWindow.xaml index 34ad23a..97c6ad2 100644 --- a/SourceGenWPF/WpfGui/MainWindow.xaml +++ b/SourceGenWPF/WpfGui/MainWindow.xaml @@ -121,6 +121,7 @@ limitations under the License. Ctrl+A + @@ -204,6 +205,8 @@ limitations under the License. + - + diff --git a/SourceGenWPF/WpfGui/MainWindow.xaml.cs b/SourceGenWPF/WpfGui/MainWindow.xaml.cs index cc14d81..b92ed85 100644 --- a/SourceGenWPF/WpfGui/MainWindow.xaml.cs +++ b/SourceGenWPF/WpfGui/MainWindow.xaml.cs @@ -987,6 +987,10 @@ namespace SourceGenWPF.WpfGui { Debug.WriteLine("Select All cmd: " + (DateTime.Now - start).TotalMilliseconds + " ms"); } + private void ShowFileHexDumpCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.ShowFileHexDump(); + } + private void ShowHexDumpCmd_Executed(object sender, ExecutedRoutedEventArgs e) { mMainCtrl.ShowHexDump(); }