aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/core/modpack/archive.rs
diff options
context:
space:
mode:
author苏向夜 <46275354+fu050409@users.noreply.github.com>2026-04-02 11:27:09 +0800
committerGitHub <noreply@github.com>2026-04-02 11:27:09 +0800
commite5f94912615e69c32c353fd6a63790e9b16685e4 (patch)
treedc1a8a0f757e4b4829bbc08c401ac9016f9b52b3 /src-tauri/src/core/modpack/archive.rs
parent0f44b957f0e4bd76146c95ef5c8b75cd61b457c1 (diff)
downloadDropOut-e5f94912615e69c32c353fd6a63790e9b16685e4.tar.gz
DropOut-e5f94912615e69c32c353fd6a63790e9b16685e4.zip
refactor(modpack): split modpack module and extract curseforge api (#127)
Co-authored-by: wsrsq <wsrsq001@163.com> Co-authored-by: 简律纯 <i@jyunko.cn> Co-authored-by: HsiangNianian <44714368+HsiangNianian@users.noreply.github.com>
Diffstat (limited to 'src-tauri/src/core/modpack/archive.rs')
-rw-r--r--src-tauri/src/core/modpack/archive.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src-tauri/src/core/modpack/archive.rs b/src-tauri/src/core/modpack/archive.rs
new file mode 100644
index 0000000..89aaef0
--- /dev/null
+++ b/src-tauri/src/core/modpack/archive.rs
@@ -0,0 +1,25 @@
+use std::{fs, io::Read, path::Path};
+
+pub(crate) type Archive = zip::ZipArchive<fs::File>;
+
+pub(crate) fn open(path: &Path) -> Result<Archive, String> {
+ let file = fs::File::open(path).map_err(|e| format!("Failed to open: {e}"))?;
+ zip::ZipArchive::new(file).map_err(|e| format!("Invalid zip: {e}"))
+}
+
+pub(crate) fn read_entry(archive: &mut Archive, name: &str) -> Option<String> {
+ let mut buf = String::new();
+ archive.by_name(name).ok()?.read_to_string(&mut buf).ok()?;
+ Some(buf)
+}
+
+pub(crate) fn read_json(archive: &mut Archive, name: &str) -> Result<serde_json::Value, String> {
+ let content = read_entry(archive, name).ok_or_else(|| format!("{name} not found"))?;
+ serde_json::from_str(&content).map_err(|e| e.to_string())
+}
+
+pub(crate) fn list_names(archive: &mut Archive) -> Vec<String> {
+ (0..archive.len())
+ .filter_map(|index| Some(archive.by_index_raw(index).ok()?.name().to_string()))
+ .collect()
+}