its ready

This commit is contained in:
sample-text-here 2021-11-09 17:28:20 -08:00
parent 50fb19094b
commit f6d46f3646
4 changed files with 39 additions and 13 deletions

30
Cargo.lock generated
View file

@ -129,7 +129,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486d44227f71a1ef39554c0dc47e44b9f4139927c75043312690c3f476d1d788"
dependencies = [
"bitflags",
"crossterm_winapi",
"crossterm_winapi 0.8.0",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c"
dependencies = [
"bitflags",
"crossterm_winapi 0.9.0",
"libc",
"mio",
"parking_lot",
@ -147,6 +163,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
dependencies = [
"winapi",
]
[[package]]
name = "flate2"
version = "1.0.22"
@ -239,7 +264,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2660dd0494633c5d60afe445e54fc5486a9a628d0ae58ee9e09cd42b6e976500"
dependencies = [
"bitflags",
"crossterm",
"crossterm 0.21.0",
"lazy_static",
"newline-converter",
"thiserror",
@ -336,6 +361,7 @@ version = "0.1.0"
dependencies = [
"attohttpc",
"colored",
"crossterm 0.22.1",
"inquire",
"pbr",
"semver",

View file

@ -10,6 +10,7 @@ edition = "2021"
[dependencies]
attohttpc = { version = "0.18.0", features = ["json"] }
colored = "2.0.0"
crossterm = "0.22.1"
inquire = "0.2.1"
pbr = "1.0.4"
semver = "1.0.4"

View file

@ -1 +0,0 @@
{"version":"1.17.0","mods":[{"id":"AANobbMI","url":"https://cdn.modrinth.com/data/AANobbMI/versions/mc1.16.5-0.2.0/sodium-fabric-mc1.16.5-0.2.0+build.4.jar","filename":"sodium-fabric-mc1.16.5-0.2.0+build.4.jar"},{"id":"AANobbMI","url":"https://cdn.modrinth.com/data/AANobbMI/versions/mc1.16.5-0.2.0/sodium-fabric-mc1.16.5-0.2.0+build.4.jar","filename":"sodium-fabric-mc1.16.5-0.2.0+build.4.jar"},{"id":"gvQqBUqZ","url":"https://cdn.modrinth.com/data/gvQqBUqZ/versions/mc1.17.1-0.7.5/lithium-fabric-mc1.17.1-0.7.5.jar","filename":"lithium-fabric-mc1.17.1-0.7.5.jar"},{"id":"AZomiSrC","url":"https://cdn.modrinth.com/data/AZomiSrC/versions/mc1.17.1-0.3.1/hydrogen-fabric-mc1.17.1-0.3.jar","filename":"hydrogen-fabric-mc1.17.1-0.3.jar"},{"id":"Gov5Dboq","url":"https://cdn.modrinth.com/data/Gov5Dboq/versions/0.3.17/Modern-Industrialization-0.3.17.jar","filename":"Modern-Industrialization-0.3.17.jar"},{"id":"NK39zBp2","url":"https://cdn.modrinth.com/data/NK39zBp2/versions/2.4.0/blur-2.4.0.jar","filename":"blur-2.4.0.jar"},{"id":"P7dR8mSH","url":"https://cdn.modrinth.com/data/P7dR8mSH/versions/0.42.0+1.16/fabric-api-0.42.0+1.16.jar","filename":"fabric-api-0.42.0+1.16.jar"},{"id":"Ha28R6CL","url":"https://cdn.modrinth.com/data/Ha28R6CL/versions/1.6.4+kotlin.1.5.30/fabric-language-kotlin-1.6.4+kotlin.1.5.30.jar","filename":"fabric-language-kotlin-1.6.4+kotlin.1.5.30.jar"},{"id":"Orvt0mRa","url":"https://cdn.modrinth.com/data/Orvt0mRa/versions/1.0.0+mc1.16.5/indium-1.0.0+mc1.16.5.jar","filename":"indium-1.0.0+mc1.16.5.jar"},{"id":"YL57xq9U","url":"https://cdn.modrinth.com//data/YL57xq9U/versions/mc1.16.5-1.1.2/iris-and-sodium-mc1.16.5-1.1.2+build.4.jar","filename":"iris-and-sodium-mc1.16.5-1.1.2+build.4.jar"},{"id":"LQ3K71Q1","url":"https://cdn.modrinth.com/data/LQ3K71Q1/versions/v2.0.4/dynamic-fps-2.0.4.jar","filename":"dynamic-fps-2.0.4.jar"},{"id":"hvFnDODi","url":"https://cdn.modrinth.com/data/hvFnDODi/versions/0.1.2/lazydfu-0.1.2.jar","filename":"lazydfu-0.1.2.jar"},{"id":"8qkXwOnk","url":"https://cdn.modrinth.com//data/8qkXwOnk/versions/mc1.17.1-1.1.0/morechathistory-1.17.1-1.1.0.jar","filename":"morechathistory-1.17.1-1.1.0.jar"},{"id":"mOgUt4GM","url":"https://cdn.modrinth.com/data/mOgUt4GM/versions/2.0.14/modmenu-2.0.14.jar","filename":"modmenu-2.0.14.jar"},{"id":"AANobbMI","url":"https://cdn.modrinth.com/data/AANobbMI/versions/mc1.16.5-0.2.0/sodium-fabric-mc1.16.5-0.2.0+build.4.jar","filename":"sodium-fabric-mc1.16.5-0.2.0+build.4.jar"},{"id":"AANobbMI","url":"https://cdn.modrinth.com/data/AANobbMI/versions/mc1.16.5-0.2.0/sodium-fabric-mc1.16.5-0.2.0+build.4.jar","filename":"sodium-fabric-mc1.16.5-0.2.0+build.4.jar"},{"id":"AANobbMI","url":"https://cdn.modrinth.com/data/AANobbMI/versions/mc1.16.5-0.2.0/sodium-fabric-mc1.16.5-0.2.0+build.4.jar","filename":"sodium-fabric-mc1.16.5-0.2.0+build.4.jar"},{"id":"Gov5Dboq","url":"https://cdn.modrinth.com/data/Gov5Dboq/versions/0.3.17/Modern-Industrialization-0.3.17.jar","filename":"Modern-Industrialization-0.3.17.jar"}]}

View file

@ -69,13 +69,12 @@ pub fn find_correct_version(id: &String, target: &Version) -> Result<ModFile, st
Ok(ver) => ver.matches(&target),
Err(_) => true,
});
println!("{}, {:?}", found, version);
if found {
return Ok(version.files.get(0).unwrap().to_owned());
}
}
Err(std::io::Error::new(std::io::ErrorKind::NotFound, "cant find mod"))
Err(std::io::Error::new(std::io::ErrorKind::NotFound, "cant find correct version"))
}
fn install<T: std::io::Write>(url: &String, filename: &String, mut bar: ProgressBar<T>) -> Result<(), std::io::Error> {
@ -118,7 +117,7 @@ fn install<T: std::io::Write>(url: &String, filename: &String, mut bar: Progress
}
fn install_single(id: &String, target: &Version) -> Result<OptionMod, std::io::Error> {
let bullseye = find_correct_version(&id, &target).expect("couldnt find mod");
let bullseye = find_correct_version(&id, &target)?;
let ModFile { url, filename } = bullseye;
let bar = ProgressBar::new(0);
@ -132,17 +131,15 @@ fn install_single(id: &String, target: &Version) -> Result<OptionMod, std::io::E
}
fn install_pack(mods: &Vec<OptionMod>) -> Result<(), std::io::Error> {
let multi = pbr::MultiBar::new();
multi.println(&"downloading mods".cyan().bold());
println!("{}", "downloading mods".cyan().bold());
for m in mods {
let bar = multi.create_bar(0);
// TODO: make multithreaded?
if std::fs::metadata(&m.filename).is_ok() { continue }
let bar = ProgressBar::new(0);
install(&m.url, &m.filename, bar)?;
}
multi.listen();
multi.println(&"done!".green().bold());
println!("\r{}{}", crossterm::terminal::Clear(crossterm::terminal::ClearType::CurrentLine), "done!".green().bold());
Ok(())
}
@ -218,7 +215,10 @@ fn main() -> Result<(), std::io::Error> {
match find_mod(&query, &mods, &options) {
Some(ModState::Uninstalled(m)) => {
let version = Version::parse(&options.version).unwrap();
options.mods.push(install_single(&m, &version)?)
match install_single(&m, &version) {
Ok(m) => options.mods.push(m),
Err(why) => println!("{} {}", "error:".bold().red(), why),
};
},
Some(ModState::Installed(_)) => {
println!("already installed!");