diff --git a/index.html b/index.html index f77292d..8ad1dcb 100644 --- a/index.html +++ b/index.html @@ -99,8 +99,8 @@ - +
diff --git a/public/scripts/MarcFile.js b/public/scripts/MarcFile.js index ec86c08..c782606 100644 --- a/public/scripts/MarcFile.js +++ b/public/scripts/MarcFile.js @@ -139,10 +139,10 @@ MarcFile.prototype.save=function(){ blob=bb.getBlob(this.fileType); }else{ throw new Error('Incompatible Browser'); - return false; } } - saveAs(blob,this.fileName); + + tauriSaveFile(this.fileName, blob) } diff --git a/public/scripts/RomPatcher.js b/public/scripts/RomPatcher.js index ed390f1..5f55a11 100644 --- a/public/scripts/RomPatcher.js +++ b/public/scripts/RomPatcher.js @@ -704,56 +704,34 @@ function createPatch(sourceFile, modifiedFile, mode){ return false; } + try{ + sourceFile.seek(0); + modifiedFile.seek(0); - if(CAN_USE_WEB_WORKERS){ - setTabCreateEnabled(false); - - setMessage('create', 'creating_patch', 'loading'); - - webWorkerCreate.postMessage( - { - sourceFileU8Array:sourceFile._u8array, - modifiedFileU8Array:modifiedFile._u8array, - modifiedFileName:modifiedFile.fileName, - patchMode:mode - },[ - sourceFile._u8array.buffer, - modifiedFile._u8array.buffer - ] - ); - - romFile1=new MarcFile(el('input-file-rom1')); - romFile2=new MarcFile(el('input-file-rom2')); - }else{ - try{ - sourceFile.seek(0); - modifiedFile.seek(0); - - var newPatch; - if(mode==='ips'){ - newPatch=createIPSFromFiles(sourceFile, modifiedFile); - }else if(mode==='bps'){ - newPatch=createBPSFromFiles(sourceFile, modifiedFile, (sourceFile.fileSize<=4194304)); - }else if(mode==='ups'){ - newPatch=createUPSFromFiles(sourceFile, modifiedFile); - }else if(mode==='aps'){ - newPatch=createAPSFromFiles(sourceFile, modifiedFile); - }else if(mode==='rup'){ - newPatch=createRUPFromFiles(sourceFile, modifiedFile); - }else{ - setMessage('create', 'error_invalid_patch', 'error'); - } - - - if(crc32(modifiedFile)===crc32(newPatch.apply(sourceFile))){ - newPatch.export(modifiedFile.fileName.replace(/\.[^\.]+$/,'')).save(); - }else{ - setMessage('create', 'Unexpected error: verification failed. Patched file and modified file mismatch. Please report this bug.', 'error'); - } - - }catch(e){ - setMessage('create', 'Error: '+_(e.message), 'error'); + var newPatch; + if(mode==='ips'){ + newPatch=createIPSFromFiles(sourceFile, modifiedFile); + }else if(mode==='bps'){ + newPatch=createBPSFromFiles(sourceFile, modifiedFile, (sourceFile.fileSize<=4194304)); + }else if(mode==='ups'){ + newPatch=createUPSFromFiles(sourceFile, modifiedFile); + }else if(mode==='aps'){ + newPatch=createAPSFromFiles(sourceFile, modifiedFile); + }else if(mode==='rup'){ + newPatch=createRUPFromFiles(sourceFile, modifiedFile); + }else{ + setMessage('create', 'error_invalid_patch', 'error'); } + + + if(crc32(modifiedFile)===crc32(newPatch.apply(sourceFile))){ + newPatch.export(modifiedFile.fileName.replace(/\.[^\.]+$/,'')).save(); + }else{ + setMessage('create', 'Unexpected error: verification failed. Patched file and modified file mismatch. Please report this bug.', 'error'); + } + + }catch(e){ + setMessage('create', 'Error: '+_(e.message), 'error'); } } diff --git a/public/scripts/tauriSaveFile.js b/public/scripts/tauriSaveFile.js new file mode 100644 index 0000000..9184f07 --- /dev/null +++ b/public/scripts/tauriSaveFile.js @@ -0,0 +1,14 @@ +const { save } = window.__TAURI__.dialog; +const { writeBinaryFile } = window.__TAURI__.fs; + +const tauriSaveFile = async (filename, blob) => { + try { + const path = await save({ defaultPath: filename }); + const contents = await blob.arrayBuffer(); + if (path && contents) { + await writeBinaryFile({ path, contents }); + } + } catch (err) { + console.log(err); + } +}; diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f8d5ba2..6cc61e9 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1641,6 +1641,17 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -2158,6 +2169,30 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rfd" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea" +dependencies = [ + "block", + "dispatch", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "lazy_static", + "log", + "objc", + "objc-foundation", + "objc_id", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows 0.37.0", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2633,6 +2668,7 @@ dependencies = [ "percent-encoding", "rand 0.8.5", "raw-window-handle", + "rfd", "semver", "serde", "serde_json", @@ -3190,6 +3226,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -3219,6 +3267,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webkit2gtk" version = "0.18.2" @@ -3335,6 +3393,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" +dependencies = [ + "windows_aarch64_msvc 0.37.0", + "windows_i686_gnu 0.37.0", + "windows_i686_msvc 0.37.0", + "windows_x86_64_gnu 0.37.0", + "windows_x86_64_msvc 0.37.0", +] + [[package]] name = "windows" version = "0.39.0" @@ -3469,6 +3540,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +[[package]] +name = "windows_aarch64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -3487,6 +3564,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +[[package]] +name = "windows_i686_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" + [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -3511,6 +3594,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +[[package]] +name = "windows_i686_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" + [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -3529,6 +3618,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +[[package]] +name = "windows_x86_64_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" + [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -3559,6 +3654,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +[[package]] +name = "windows_x86_64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 78fab66..6ccb7cf 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.5.2", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.6.5", features = [] } +tauri = { version = "1.6.5", features = [ "fs-write-file", "dialog-save"] } [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index b626803..f7210d0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -4,7 +4,8 @@ "beforeBuildCommand": "npm run build", "beforeDevCommand": "npm run dev", "devPath": "http://localhost:5555", - "distDir": "../dist" + "distDir": "../dist", + "withGlobalTauri": true }, "package": { "productName": "rompatcher", @@ -12,7 +13,17 @@ }, "tauri": { "allowlist": { - "all": false + "dialog": { + "ask": false, + "confirm": false, + "message": false, + "open": false, + "save": true + }, + "fs": { + "scope": [], + "writeFile": true + } }, "bundle": { "active": true,