Skip to content

Commit

Permalink
Export
Browse files Browse the repository at this point in the history
  • Loading branch information
buldo committed May 24, 2024
1 parent 1ac90e3 commit dd4ba07
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/EfuseManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<Button
Margin="2,0,0,0"
Command="{Binding WriteFileCommand}">Write file</Button>
<Button
Margin="2,0,0,0"
Command="{Binding ExportFileCommand}">Export as text</Button>
</StackPanel>

</GroupBox>
Expand Down
21 changes: 21 additions & 0 deletions src/EfuseManager/TextFormatter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
23 changes: 23 additions & 0 deletions src/EfuseManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -52,6 +53,8 @@ public MainViewModel(IDialogService dialogService)

public RelayCommand WriteFileCommand { get; }

public RelayCommand ExportFileCommand { get; }

public ObservableCollection<DeviceViewModel> Devices { get; } = new();

public DeviceViewModel? SelectedDevice
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit dd4ba07

Please sign in to comment.