Skip to content

Commit 3bc6726

Browse files
committed
add geode index install command & fix install_mod
1 parent 8f77409 commit 3bc6726

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "geode"
3-
version = "2.1.2"
3+
version = "2.2.0"
44
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

src/index.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ pub enum Index {
2424
output: PathBuf
2525
},
2626

27+
/// Install a mod from the index to the current profile
28+
Install {
29+
/// Mod ID to install
30+
id: String,
31+
32+
/// Mod version to install, defaults to latest
33+
version: Option<VersionReq>,
34+
},
35+
2736
/// Updates the index cache
2837
Update,
2938
}
@@ -173,18 +182,29 @@ pub fn install_mod(config: &Config, id: &String, version: &VersionReq) -> PathBu
173182

174183
info!("Installing mod '{}' version '{}'", id, version);
175184

176-
let mut pkg_data = io::Cursor::new(Vec::new());
177-
178-
reqwest::blocking::get(entry.r#mod.download)
185+
let bytes = reqwest::blocking::get(entry.r#mod.download)
179186
.expect("Unable to download mod")
180-
.copy_to(&mut pkg_data)
187+
.bytes()
181188
.expect("Unable to download mod");
182189

183190
let dest = config.get_current_profile().mods_dir().join(format!("{id}.geode"));
184-
let mut file = std::fs::File::create(&dest)
185-
.expect("Unable to create destination file for mod");
186-
187-
std::io::copy(&mut pkg_data, &mut file).expect("Unable to install mod");
191+
192+
let mut hasher = Sha3_256::new();
193+
hasher.update(&bytes);
194+
let hash = hex::encode(hasher.finalize().to_vec());
195+
196+
if hash != entry.r#mod.hash {
197+
fatal!(
198+
"Downloaded file doesn't match expected hash\n\
199+
{hash}\n\
200+
vs {}\n\
201+
Try again, and if the issue persists, report this on GitHub: \
202+
https://github.com/geode-sdk/cli/issues/new",
203+
entry.r#mod.hash
204+
);
205+
}
206+
207+
fs::write(&dest, bytes).expect("Unable to install .geode file");
188208

189209
dest
190210
}
@@ -279,5 +299,10 @@ pub fn subcommand(config: &mut Config, cmd: Index) {
279299
match cmd {
280300
Index::New { output } => create_entry(&output),
281301
Index::Update => update_index(config),
302+
Index::Install { id, version } => {
303+
update_index(config);
304+
install_mod(config, &id, &version.unwrap_or(VersionReq::STAR));
305+
done!("Mod installed");
306+
},
282307
}
283308
}

0 commit comments

Comments
 (0)