summaryrefslogtreecommitdiffstats
path: root/src/launcher
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-22 23:18:58 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-22 23:18:58 -0600
commitc81e9faad0f8cef711c66197023e5934eb0a85c4 (patch)
treecb6299124daa1e850dbd09e35c13509b21285da0 /src/launcher
parentfix version resolution (diff)
make some changes after testing some mod loaders
- fabric - forge - neoforge
Diffstat (limited to 'src/launcher')
-rw-r--r--src/launcher/download.rs37
-rw-r--r--src/launcher/jre/download.rs19
-rw-r--r--src/launcher/runner.rs11
3 files changed, 30 insertions, 37 deletions
diff --git a/src/launcher/download.rs b/src/launcher/download.rs
index 846bed1..ec4a59c 100644
--- a/src/launcher/download.rs
+++ b/src/launcher/download.rs
@@ -1,10 +1,9 @@
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
-use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use futures::{stream, StreamExt, TryStream, TryStreamExt};
-use log::{debug, warn};
-use reqwest::{Client, IntoUrl, Method, RequestBuilder};
+use log::debug;
+use reqwest::{Client, Method, RequestBuilder};
use sha1_smol::{Digest, Sha1};
use tokio::fs;
use tokio::fs::File;
@@ -15,13 +14,15 @@ use crate::util::{FileVerifyError, IntegrityError};
pub trait Download: Debug + Display {
// return Ok(None) to skip downloading this file
- fn get_url(&self) -> impl IntoUrl;
-
- async fn prepare(&mut self, req: RequestBuilder) -> Result<Option<RequestBuilder>, Box<dyn Error>>;
+ async fn prepare(&mut self, client: &Client) -> Result<Option<RequestBuilder>, Box<dyn Error>>;
async fn handle_chunk(&mut self, chunk: &[u8]) -> Result<(), Box<dyn Error>>;
async fn finish(&mut self) -> Result<(), Box<dyn Error>>;
}
+pub trait FileDownload: Download {
+ fn get_path(&self) -> &Path;
+}
+
pub struct MultiDownloader<'j, T: Download + 'j, I: Iterator<Item = &'j mut T>> {
jobs: I,
nconcurrent: usize
@@ -110,12 +111,12 @@ impl<'j, T: Download + 'j, I: Iterator<Item = &'j mut T>> MultiDownloader<'j, T,
}
}
- let Some(rq) = map_err!(
- job.prepare(client.request(Method::GET, job.get_url())
- .header(reqwest::header::USER_AGENT, USER_AGENT)).await, Phase::Prepare, job) else {
+ let Some(rq) = map_err!(job.prepare(client).await, Phase::Prepare, job) else {
return Ok(())
};
+ let rq = rq.header(reqwest::header::USER_AGENT, USER_AGENT);
+
let mut data = map_err!(map_err!(rq.send().await, Phase::Send, job).error_for_status(), Phase::Send, job).bytes_stream();
while let Some(bytes) = data.next().await {
@@ -187,10 +188,6 @@ impl VerifiedDownload {
&self.url
}
- pub fn get_path(&self) -> &Path {
- &self.path
- }
-
pub fn get_expect_size(&self) -> Option<usize> {
self.expect_size
}
@@ -210,11 +207,7 @@ impl VerifiedDownload {
}
impl Download for VerifiedDownload {
- fn get_url(&self) -> impl IntoUrl {
- &self.url
- }
-
- async fn prepare(&mut self, req: RequestBuilder) -> Result<Option<RequestBuilder>, Box<dyn Error>> {
+ async fn prepare(&mut self, client: &Client) -> Result<Option<RequestBuilder>, Box<dyn Error>> {
if !util::should_download(&self.path, self.expect_size, self.expect_sha1).await? {
return Ok(None)
}
@@ -222,7 +215,7 @@ impl Download for VerifiedDownload {
// potentially racy to close the file and reopen it... :/
self.open_output().await?;
- Ok(Some(req))
+ Ok(Some(client.request(Method::GET, &self.url)))
}
async fn handle_chunk(&mut self, chunk: &[u8]) -> Result<(), Box<dyn Error>> {
@@ -257,6 +250,12 @@ impl Download for VerifiedDownload {
}
}
+impl FileDownload for VerifiedDownload {
+ fn get_path(&self) -> &Path {
+ &self.path
+ }
+}
+
pub async fn verify_files(files: impl Iterator<Item = &mut VerifiedDownload>) -> Result<(), FileVerifyError> {
stream::iter(files)
.map(|dl| Ok(async move {
diff --git a/src/launcher/jre/download.rs b/src/launcher/jre/download.rs
index d8631aa..c24b82f 100644
--- a/src/launcher/jre/download.rs
+++ b/src/launcher/jre/download.rs
@@ -6,7 +6,7 @@ use std::ops::AddAssign;
use std::path::{Path, PathBuf};
use log::debug;
use lzma_rs::decompress;
-use reqwest::{IntoUrl, RequestBuilder};
+use reqwest::{Client, IntoUrl, RequestBuilder};
use sha1_smol::{Digest, Sha1};
use tokio::fs;
use tokio::io::AsyncWriteExt;
@@ -31,9 +31,6 @@ pub struct LzmaDownloadJob {
raw_size: Option<usize>,
raw_sha1: Option<Digest>,
- com_size: Option<usize>,
- com_sha1: Option<Digest>,
-
raw_sha1_st: Sha1,
raw_tally: usize,
@@ -52,9 +49,6 @@ impl LzmaDownloadJob {
raw_size: raw.size,
raw_sha1: raw.sha1,
- com_size: lzma.size,
- com_sha1: lzma.sha1,
-
raw_sha1_st: Sha1::new(),
raw_tally: 0,
@@ -73,9 +67,6 @@ impl LzmaDownloadJob {
raw_size: raw.size,
raw_sha1: raw.sha1,
- com_size: None,
- com_sha1: None,
-
raw_sha1_st: Sha1::new(),
raw_tally: 0,
@@ -125,11 +116,7 @@ impl Display for LzmaDownloadJob {
}
impl Download for LzmaDownloadJob {
- fn get_url(&self) -> impl IntoUrl {
- self.url.as_str()
- }
-
- async fn prepare(&mut self, req: RequestBuilder) -> Result<Option<RequestBuilder>, Box<dyn Error>> {
+ async fn prepare(&mut self, client: &Client) -> Result<Option<RequestBuilder>, Box<dyn Error>> {
if !util::should_download(&self.path, self.raw_size, self.raw_sha1).await? {
return Ok(None)
}
@@ -147,7 +134,7 @@ impl Download for LzmaDownloadJob {
let file = options.create(true).write(true).truncate(true).open(&self.path).await?;
self.out_file = Some(file);
- Ok(Some(req))
+ Ok(Some(client.get(&self.url)))
}
async fn handle_chunk(&mut self, chunk: &[u8]) -> Result<(), Box<dyn Error>> {
diff --git a/src/launcher/runner.rs b/src/launcher/runner.rs
index 50a9ff8..a58602e 100644
--- a/src/launcher/runner.rs
+++ b/src/launcher/runner.rs
@@ -14,6 +14,13 @@ use super::{Launch, LaunchInfo};
#[derive(Clone, Copy)]
struct LaunchArgSub<'a, 'l, F: FeatureMatcher>(&'a LaunchInfo<'l, F>);
+// FIXME: this is not correct
+#[cfg(windows)]
+const PATH_SEP: &str = ";";
+
+#[cfg(not(windows))]
+const PATH_SEP: &str = ":";
+
impl<'rep, 'l, F: FeatureMatcher> SubFunc<'rep> for LaunchArgSub<'rep, 'l, F> {
fn substitute(&self, key: &str) -> Option<Cow<'rep, str>> {
match key {
@@ -24,8 +31,8 @@ impl<'rep, 'l, F: FeatureMatcher> SubFunc<'rep> for LaunchArgSub<'rep, 'l, F> {
"auth_session" => Some(Cow::Borrowed("-")), // TODO
"auth_uuid" => Some(Cow::Borrowed("00000000-0000-0000-0000-000000000000")), // TODO
"auth_xuid" => Some(Cow::Borrowed("00000000-0000-0000-0000-000000000000")), // TODO
- "classpath" => Some(Cow::Borrowed(self.0.classpath.as_str())), // TODO
- "classpath_separator" => None, // FIXME
+ "classpath" => Some(Cow::Borrowed(self.0.classpath.as_str())),
+ "classpath_separator" => Some(Cow::Borrowed(PATH_SEP)),
"game_assets" => self.0.virtual_assets_path.as_ref()
.map(|s| s.as_path().as_java_path().to_string_lossy()),
"game_directory" => Some(self.0.instance_home.as_java_path().to_string_lossy()),