1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-30 22:29:27 +00:00

Implement Tools > Hex Dump

This commit is contained in:
Andy McFadden 2019-07-12 17:46:37 -07:00
parent acfbfcb642
commit ea3108c564
5 changed files with 49 additions and 2 deletions

View File

@ -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,

View File

@ -79,7 +79,7 @@ limitations under the License.
<system:String x:Key="str_OpenDataFailMessage">Unable to load contents of data file</system:String>
<system:String x:Key="str_OpenDataLoadFailedFmt">The file could not be opened: {0}.</system:String>
<system:String x:Key="str_OpenDataPartialRead">Unable to read the entire file</system:String>
<system:String x:Key="str_OpenDataTooLargeFmt">File is too large ({0:N0} KiB, {1:N0} KiB max).</system:String>
<system:String x:Key="str_OpenDataTooLargeFmt">File is too large ({0:N0} KiB, max is {1:N0} KiB).</system:String>
<system:String x:Key="str_OpenDataWrongLengthFmt">The file is {0:N0} bytes long, but the project expected {1:N0}.</system:String>
<system:String x:Key="str_OpenDataWrongCrcFmt">The file has CRC {0}, but the project expected {1}.</system:String>
<system:String x:Key="str_OperationFailed">Failed</system:String>

View File

@ -125,6 +125,13 @@ namespace SourceGenWPF.Tools.WpfGui {
// Debug.WriteLine("Column width: " + hexDumpData.Columns[0].ActualWidth);
//}
/// <summary>
/// Sets the filename associated with the data. This is for display purposes only.
/// </summary>
public void SetFileName(string fileName) {
Title = fileName;
}
private void CharConvComboBox_SelectionChanged(object sender,
SelectionChangedEventArgs e) {
ReplaceFormatter();

View File

@ -121,6 +121,7 @@ limitations under the License.
<KeyGesture>Ctrl+A</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="ShowFileHexDumpCmd" Text="Hex Dump..."/>
<RoutedUICommand x:Key="ShowHexDumpCmd" Text="Show Hex Dump"/>
<RoutedUICommand x:Key="ToggleDataScanCmd" Text="Toggle Data Scan">
<RoutedUICommand.InputGestures>
@ -204,6 +205,8 @@ limitations under the License.
<!-- ListView has a built-in Ctrl+A handler; this only fires when codeListView is not in focus -->
<CommandBinding Command="{StaticResource SelectAllCmd}"
CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/>
<CommandBinding Command="{StaticResource ShowFileHexDumpCmd}"
Executed="ShowFileHexDumpCmd_Executed"/>
<CommandBinding Command="{StaticResource ShowHexDumpCmd}"
CanExecute="IsProjectOpen" Executed="ShowHexDumpCmd_Executed"/>
<CommandBinding Command="{StaticResource ToggleDataScanCmd}"
@ -272,7 +275,7 @@ limitations under the License.
<MenuItem Command="{StaticResource ShowHexDumpCmd}"/>
</MenuItem>
<MenuItem Header="_Tools">
<MenuItem Header="Hex Dump..."/>
<MenuItem Command="{StaticResource ShowFileHexDumpCmd}"/>
<MenuItem Header="ASCII Chart"/>
</MenuItem>
<MenuItem Header="_Help">

View File

@ -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();
}