diff --git a/src-tauri/src/export.rs b/src-tauri/src/export.rs index 89cf0fe..bbb0579 100644 --- a/src-tauri/src/export.rs +++ b/src-tauri/src/export.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::Path; use base64::Engine; -use crate::access_manager::AccessManager; +use crate::access_manager::{AccessFilter, AccessManager}; use crate::build::HexRegion; fn write_region_contents(destination: &Path, contents: &str) { @@ -10,6 +10,15 @@ fn write_region_contents(destination: &Path, contents: &str) { fs::write(destination, value).ok(); } +#[tauri::command] +pub async fn export_binary_contents(data: Vec, filters: Vec, state: tauri::State<'_, AccessManager>) -> Result { + let destination = state.select_save("Save File", &filters, false).await.ok_or(())?; + + fs::write(&destination, data).map_err(|_| ())?; + + Ok(destination.to_string_lossy().to_string()) +} + #[tauri::command] pub async fn export_hex_contents(data: &str, state: tauri::State<'_, AccessManager>) -> Result { let destination = state.select_save("Save Region File", &[], false).await.ok_or(())?; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 454aaf8..d98d40e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -32,7 +32,7 @@ use crate::debug::{read_bytes, set_register, swap_breakpoints, write_bytes}; use crate::menu::platform_shortcuts; use crate::midi::{midi_install, midi_protocol, MidiProviderContainer}; use crate::state::commands::DebuggerBody; -use crate::export::{export_hex_regions, export_hex_contents}; +use crate::export::{export_hex_regions, export_hex_contents, export_binary_contents}; use crate::state::commands::{resume, rewind, pause, stop, last_pc, post_key, post_input, wake_sync}; use crate::testing::{all_tests, run_tests}; @@ -127,6 +127,7 @@ fn main() { detailed_disassemble, export_hex_regions, export_hex_contents, + export_binary_contents, ]) .register_uri_scheme_protocol("midi", midi_protocol) .register_uri_scheme_protocol("display", display_protocol) diff --git a/src/utils/debug.ts b/src/utils/debug.ts index d30551e..cb6a9fc 100644 --- a/src/utils/debug.ts +++ b/src/utils/debug.ts @@ -8,7 +8,9 @@ import { } from '../state/console-data' import { AssemblerResult, - assembleText, assembleWithBinary, disassemblyDetails, + assembleText, + assembleWithBinary, + disassemblyDetails, ExecutionModeType, ExecutionResult, ExecutionState diff --git a/src/utils/events.ts b/src/utils/events.ts index ff3d82d..02f0fb1 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -24,7 +24,7 @@ import { appWindow } from '@tauri-apps/api/window' import { watch } from 'vue' import { MidiNote, playNote } from './midi' import { splitLines } from './split-lines' -import { writeBinaryFile } from '@tauri-apps/api/fs' +import { exportBinaryContents } from './query/serialize-files' export enum PromptType { NeverPrompt, @@ -203,16 +203,10 @@ export async function setupEvents() { binary = result.binary } - let destination: AccessFile | null = null + let destination: string | null = null if (binary !== null) { - destination = await selectSaveDestination('Save File', elfFilter) - - if (!destination) { - return - } - - await writeBinaryFile(destination.path, binary) + destination = await exportBinaryContents(binary.buffer, elfFilter) } consoleData.showConsole = true @@ -222,7 +216,7 @@ export async function setupEvents() { } if (destination !== null) { - pushConsole(`ELF file written to ${destination.path}`, ConsoleType.Info) + pushConsole(`ELF file written to ${destination}`, ConsoleType.Info) } }) diff --git a/src/utils/query/serialize-files.ts b/src/utils/query/serialize-files.ts index d40049b..9a6026b 100644 --- a/src/utils/query/serialize-files.ts +++ b/src/utils/query/serialize-files.ts @@ -1,6 +1,18 @@ import { HexRegion } from '../mips' import { invoke } from '@tauri-apps/api' +import { AccessFilter } from './access-manager' + +export async function exportBinaryContents(data: ArrayBuffer, filters: AccessFilter[]): Promise { + try { + return await invoke('export_binary_contents', { + data: Array.from(new Uint8Array(data)), + filters + }) + } catch { + return null + } +} export async function exportHexContents(data: string): Promise { try {