From 9ad6fe84cabb94b24ec0be7dadfea0fb9b237f82 Mon Sep 17 00:00:00 2001 From: IAFEnvoy Date: Sat, 21 Sep 2024 22:25:35 +0800 Subject: [PATCH] add mcmod format export --- frontend/index.html | 2 ++ frontend/index.js | 20 ++++++++++++++++++++ src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 4 +++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index d8dc119..b88a3f1 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -41,6 +41,8 @@     
+      +
diff --git a/frontend/index.js b/frontend/index.js index 0848437..4fbad41 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -10,6 +10,7 @@ let currentLoader = 'fabric', currentDisplayMod = 'unknown' window.onload = async _ => { document.getElementById("open-folder").onclick = openModFolder + document.getElementById("export-list").onclick = exportModList tauri.event.listen('mod-config-read', e => { let index = processingFiles.indexOf(e.payload.file) if (index == -1) return @@ -247,6 +248,25 @@ const openModFolder = async _ => { loadMods(selected) } +const exportModList = async _ => { + const selected = await tauri.dialog.save({ + filters: [{ + name: 'export-modlist', + extensions: ['json'] + }] + }) + if (!selected) return + await tauri.fs.writeTextFile(selected, JSON.stringify(Object.values(modData).reduce((p, c) => { + if (c.id && c.name && c.version) + p.push({ + modid: c.id, + name: c.name, + version: c.version + }) + return p + }, []), null, '\t')) +} + const updateLoadingStatus = _ => { let dom = document.getElementById('loading-process') dom.innerHTML = `解析元数据:${totalMods - processingFiles.length}/${totalMods}
解析Logo:${totalMods - processingFiles.length - processingIcon.length}/${totalMods}` diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 92b3e63..9f1bb2a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" tauri-build = { version = "1.4", features = [] } [dependencies] -tauri = { version = "1.4", features = [ "path-all", "dialog-open", "fs-read-dir"] } +tauri = { version = "1.4", features = [ "fs-write-file", "dialog-save", "path-all", "dialog-open", "fs-read-dir"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" zip = "0.5.5" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c5e1f72..c650e23 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -15,11 +15,13 @@ "all": false, "dialog": { "all": false, - "open": true + "open": true, + "save": true }, "fs": { "all": false, "readDir": true, + "writeFile": true, "scope": [ "**" ]