From e62d05698ba6af03906fb79acee1da488e64871a Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 30 Dec 2024 19:33:48 -0600 Subject: some stuff has changed --- src/launcher/instance.rs | 9 +++++++++ src/launcher/profile.rs | 8 ++++++++ src/launcher/version.rs | 31 ++++++++++++------------------- 3 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 src/launcher/instance.rs create mode 100644 src/launcher/profile.rs (limited to 'src/launcher') diff --git a/src/launcher/instance.rs b/src/launcher/instance.rs new file mode 100644 index 0000000..3e62990 --- /dev/null +++ b/src/launcher/instance.rs @@ -0,0 +1,9 @@ +use std::path::PathBuf; +use serde::Deserialize; +use uuid::Uuid; + +#[derive(Deserialize, Debug, Clone)] +pub struct Instance { + pub uuid: Uuid, + pub path: PathBuf +} diff --git a/src/launcher/profile.rs b/src/launcher/profile.rs new file mode 100644 index 0000000..835d912 --- /dev/null +++ b/src/launcher/profile.rs @@ -0,0 +1,8 @@ +use super::instance::Instance; + +struct Profile<'l> { + name: String, + version_id: String, + java_runtime: Option, + instance: &'l Instance +} \ No newline at end of file diff --git a/src/launcher/version.rs b/src/launcher/version.rs index 378e008..08c3bb5 100644 --- a/src/launcher/version.rs +++ b/src/launcher/version.rs @@ -3,13 +3,10 @@ use std::borrow::Cow; use std::collections::HashSet; use std::fmt::Display; use std::path::{Path, PathBuf}; -use chrono::{DateTime, Utc}; -use crypto::digest::Digest; -use crypto::sha1::Sha1; -use serde::{Serialize, Deserialize}; use log::{debug, info, warn}; - +use sha1_smol::Digest; +use crate::util; use crate::version::{*, manifest::*}; use super::constants::*; @@ -51,7 +48,7 @@ impl RemoteVersionList { let ver_text = reqwest::get(ver.url.as_str()).await?.error_for_status()?.text().await?; // make sure it's valid - ver.sha1.verify(ver_text.as_str()) + util::verify_sha1(ver.sha1, ver_text.as_str()) .map_err::, _>(|e| format!("downloaded version {} has wrong hash! (expect {}, got {})", ver.id.as_str(), &ver.sha1, e).as_str().into())?; // make sure it's well-formed @@ -70,7 +67,7 @@ struct LocalVersionList { #[derive(Debug)] enum LocalVersionError { - Sha1Mismatch { exp: Sha1Digest, got: Sha1Digest }, + Sha1Mismatch { exp: Digest, got: Digest }, VersionMismatch { fname: String, json: String }, Unknown(Box) } @@ -78,10 +75,10 @@ enum LocalVersionError { impl Display for LocalVersionError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Sha1Mismatch { exp, got } => { + LocalVersionError::Sha1Mismatch { exp, got } => { write!(f, "sha1 mismatch (exp {exp}, got {got})") }, - VersionMismatch { fname, json } => { + LocalVersionError::VersionMismatch { fname, json } => { write!(f, "version ID mismatch (filename {fname}, json {json})") }, LocalVersionError::Unknown(err) => { @@ -94,12 +91,12 @@ impl Display for LocalVersionError { impl Error for LocalVersionError {} impl LocalVersionList { - async fn load_version(path: &Path, sha1: Option<&Sha1Digest>) -> Result { + async fn load_version(path: &Path, sha1: Option) -> Result { // grumble grumble I don't like reading in the whole file at once let ver = tokio::fs::read_to_string(path).await.map_err(|e| LocalVersionError::Unknown(Box::new(e)))?; if let Some(digest_exp) = sha1 { - digest_exp.verify(ver.as_str()) - .map_err(|got| Sha1Mismatch { exp: digest_exp.to_owned(), got })?; + util::verify_sha1(digest_exp, ver.as_str()) + .map_err(|got| LocalVersionError::Sha1Mismatch { exp: digest_exp.to_owned(), got })?; } let ver: CompleteVersion = serde_json::from_str(ver.as_str()).map_err(|e| LocalVersionError::Unknown(Box::new(e)))?; @@ -112,7 +109,7 @@ impl LocalVersionList { if fname_id == ver.id.as_str() { Ok(ver) } else { - Err(VersionMismatch { fname: fname_id.to_owned(), json: ver.id }) + Err(LocalVersionError::VersionMismatch { fname: fname_id.to_owned(), json: ver.id }) } } @@ -199,10 +196,6 @@ pub enum VersionResolveError { Unknown(Box) } -use crate::util::{Sha1Digest, SHA1_DIGEST_BYTES}; -use crate::launcher::version::LocalVersionError::{Sha1Mismatch, VersionMismatch}; -use crate::launcher::version::VersionResolveError::MissingVersion; - impl VersionList { pub async fn online(home: &Path) -> Result> { let remote = RemoteVersionList::new().await?; @@ -247,7 +240,7 @@ impl VersionList { let mut ver_path = self.home.join(id); ver_path.push(format!("{id}.json")); - match LocalVersionList::load_version(ver_path.as_path(), Some(&ver.sha1)).await { + match LocalVersionList::load_version(ver_path.as_path(), Some(ver.sha1)).await { Ok(v) => return Ok(v), Err(e) => { info!("redownloading {id}, since the local copy could not be loaded: {e}"); @@ -275,7 +268,7 @@ impl VersionList { Cow::Owned(self.load_remote_version(v).await.map_err(|e| VersionResolveError::Unknown(e))?), VersionResult::None => { warn!("Cannot resolve version {}, it inherits an unknown version {inherit}", ver.id); - return Err(MissingVersion(inherit)); + return Err(VersionResolveError::MissingVersion(inherit)); } }; -- cgit v1.2.3-70-g09d2