diff --git a/src/EfuseManager/MainWindow.xaml b/src/EfuseManager/MainWindow.xaml index 1464723..eb7443a 100644 --- a/src/EfuseManager/MainWindow.xaml +++ b/src/EfuseManager/MainWindow.xaml @@ -58,6 +58,9 @@ + diff --git a/src/EfuseManager/TextFormatter.cs b/src/EfuseManager/TextFormatter.cs new file mode 100644 index 0000000..6454a3a --- /dev/null +++ b/src/EfuseManager/TextFormatter.cs @@ -0,0 +1,21 @@ +using System.Text; + +namespace EfuseManager; + +internal static class TextFormatter +{ + public static string FormatByteArray(byte[] bytes) + { + var builder = new StringBuilder(); + var linesCount = bytes.Length / 16; + for (int i = 0; i < linesCount; i++) + { + var startByte = i * 16; + var bl = bytes.AsSpan(startByte, 16); + builder.AppendLine( + $"0x{startByte:x3}: {bl[0]:X2} {bl[1]:X2} {bl[2]:X2} {bl[3]:X2} {bl[4]:X2} {bl[5]:X2} {bl[6]:X2} {bl[7]:X2} {bl[8]:X2} {bl[9]:X2} {bl[10]:X2} {bl[11]:X2} {bl[12]:X2} {bl[13]:X2} {bl[14]:X2} {bl[15]:X2}"); + } + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/src/EfuseManager/ViewModels/MainViewModel.cs b/src/EfuseManager/ViewModels/MainViewModel.cs index 6965e00..b9ba559 100644 --- a/src/EfuseManager/ViewModels/MainViewModel.cs +++ b/src/EfuseManager/ViewModels/MainViewModel.cs @@ -38,6 +38,7 @@ public MainViewModel(IDialogService dialogService) WriteCommand = new RelayCommand(ExecuteWrite); ReadFileCommand = new RelayCommand(ExecuteReadFile); WriteFileCommand = new RelayCommand(ExecuteWriteFile); + ExportFileCommand = new RelayCommand(ExecuteExportFile); _driver = new WiFiDriver(NullLoggerFactory.Instance); } @@ -52,6 +53,8 @@ public MainViewModel(IDialogService dialogService) public RelayCommand WriteFileCommand { get; } + public RelayCommand ExportFileCommand { get; } + public ObservableCollection Devices { get; } = new(); public DeviceViewModel? SelectedDevice @@ -120,6 +123,26 @@ private void ExecuteWriteFile() } } + private void ExecuteExportFile() + { + var efuseMap = EfuseMap.GetData(); + var saveFileDialogSettings = new SaveFileDialogSettings() + { + AddExtension = true, + DefaultExt = ".txt", + Filter = "Text files|*.txt" + }; + var isOk = _dialogService.ShowSaveFileDialog( + this, + saveFileDialogSettings); + if (isOk == true) + { + File.WriteAllText( + saveFileDialogSettings.FileName, + TextFormatter.FormatByteArray(efuseMap)); + } + } + private void ExecuteReadFile() { _dialogService.ShowMessageBox(