Faster speeds
This commit is contained in:
@@ -21,12 +21,12 @@ use lyceris::{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
minecraft::{
|
minecraft::{
|
||||||
install::FileType, CLASSPATH_SEPARATOR, JAVA_MANIFEST_ENDPOINT, RESOURCES_ENDPOINT,
|
emitter::{Emit, Event},
|
||||||
VERSION_MANIFEST_ENDPOINT,
|
install::FileType,
|
||||||
|
CLASSPATH_SEPARATOR, JAVA_MANIFEST_ENDPOINT, RESOURCES_ENDPOINT, VERSION_MANIFEST_ENDPOINT,
|
||||||
},
|
},
|
||||||
util::{
|
util::{
|
||||||
extract::{extract_file, read_file_from_jar},
|
extract::{extract_file, read_file_from_jar},
|
||||||
hash::calculate_sha1,
|
|
||||||
json::{read_json, write_json},
|
json::{read_json, write_json},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -44,7 +44,6 @@ use crate::launcher::downloader::{download, download_multiple};
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct DownloadFile {
|
struct DownloadFile {
|
||||||
file_name: String,
|
file_name: String,
|
||||||
sha1: String,
|
|
||||||
url: String,
|
url: String,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
r#type: FileType,
|
r#type: FileType,
|
||||||
@@ -63,13 +62,25 @@ pub async fn install<T: Loader>(
|
|||||||
config: &Config<T>,
|
config: &Config<T>,
|
||||||
emitter: Option<&Emitter>,
|
emitter: Option<&Emitter>,
|
||||||
) -> lyceris::Result<()> {
|
) -> lyceris::Result<()> {
|
||||||
let manifest: VersionManifest =
|
emitter.emit(Event::Console, "Fetching manifest...").await;
|
||||||
fetch(VERSION_MANIFEST_ENDPOINT, config.client.as_ref()).await?;
|
|
||||||
|
let (manifest, java_manifest) = tokio::join!(
|
||||||
|
fetch(VERSION_MANIFEST_ENDPOINT, config.client.as_ref()),
|
||||||
|
fetch(JAVA_MANIFEST_ENDPOINT, config.client.as_ref())
|
||||||
|
);
|
||||||
|
|
||||||
|
let manifest = manifest?;
|
||||||
|
let java_manifest = java_manifest?;
|
||||||
|
|
||||||
let version_json_path = config.get_version_json_path();
|
let version_json_path = config.get_version_json_path();
|
||||||
let mut meta: VersionMeta = if !version_json_path.exists() {
|
let mut meta: VersionMeta = if !version_json_path.exists() {
|
||||||
|
emitter
|
||||||
|
.emit(Event::Console, "Fetching version metadata")
|
||||||
|
.await;
|
||||||
let mut meta =
|
let mut meta =
|
||||||
fetch_version_meta(&manifest, &config.version, config.client.as_ref()).await?;
|
fetch_version_meta(&manifest, &config.version, config.client.as_ref()).await?;
|
||||||
if let Some(loader) = &config.loader {
|
if let Some(loader) = &config.loader {
|
||||||
|
emitter.emit(Event::Console, "Resolving loader").await;
|
||||||
meta = loader.merge(&config.into_vanilla(), meta, emitter).await?;
|
meta = loader.merge(&config.into_vanilla(), meta, emitter).await?;
|
||||||
}
|
}
|
||||||
write_json(&version_json_path, &meta).await?;
|
write_json(&version_json_path, &meta).await?;
|
||||||
@@ -78,6 +89,8 @@ pub async fn install<T: Loader>(
|
|||||||
read_json(&version_json_path).await?
|
read_json(&version_json_path).await?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitter.emit(Event::Console, "Fetching assets index").await;
|
||||||
|
|
||||||
let asset_index_path = config
|
let asset_index_path = config
|
||||||
.get_indexes_path()
|
.get_indexes_path()
|
||||||
.join(format!("{}.json", &meta.asset_index.id));
|
.join(format!("{}.json", &meta.asset_index.id));
|
||||||
@@ -95,6 +108,8 @@ pub async fn install<T: Loader>(
|
|||||||
create_dir_all(&natives_path)?;
|
create_dir_all(&natives_path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitter.emit(Event::Console, "Configuring files").await;
|
||||||
|
|
||||||
let check_natives = fs::read_dir(&natives_path)?.count() == 0;
|
let check_natives = fs::read_dir(&natives_path)?.count() == 0;
|
||||||
let mut to_be_extracted = Vec::with_capacity(10);
|
let mut to_be_extracted = Vec::with_capacity(10);
|
||||||
|
|
||||||
@@ -102,7 +117,6 @@ pub async fn install<T: Loader>(
|
|||||||
let java_version = meta.java_version.as_ref().unwrap_or(&default_java_version);
|
let java_version = meta.java_version.as_ref().unwrap_or(&default_java_version);
|
||||||
let runtime_path = config.get_runtime_path().join(&java_version.component);
|
let runtime_path = config.get_runtime_path().join(&java_version.component);
|
||||||
|
|
||||||
let java_manifest: JavaManifest = fetch(JAVA_MANIFEST_ENDPOINT, config.client.as_ref()).await?;
|
|
||||||
let java_url = get_java_url(&java_manifest, java_version)?;
|
let java_url = get_java_url(&java_manifest, java_version)?;
|
||||||
let java_files: JavaFileManifest = fetch(java_url, config.client.as_ref()).await?;
|
let java_files: JavaFileManifest = fetch(java_url, config.client.as_ref()).await?;
|
||||||
|
|
||||||
@@ -116,6 +130,8 @@ pub async fn install<T: Loader>(
|
|||||||
&mut to_be_extracted,
|
&mut to_be_extracted,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
emitter.emit(Event::Console, "Downloading files").await;
|
||||||
|
|
||||||
download_necessary(
|
download_necessary(
|
||||||
file_map,
|
file_map,
|
||||||
&config.game_dir,
|
&config.game_dir,
|
||||||
@@ -251,9 +267,7 @@ fn build_file_map(
|
|||||||
to_be_extracted: &mut Vec<vanilla::File>,
|
to_be_extracted: &mut Vec<vanilla::File>,
|
||||||
) -> lyceris::Result<Vec<DownloadFile>> {
|
) -> lyceris::Result<Vec<DownloadFile>> {
|
||||||
let version_jar_path = config.get_version_jar_path();
|
let version_jar_path = config.get_version_jar_path();
|
||||||
let version_download = if !version_jar_path.exists()
|
let version_download = if !version_jar_path.exists() {
|
||||||
|| !calculate_sha1(&version_jar_path)?.eq(&meta.downloads.client.sha1)
|
|
||||||
{
|
|
||||||
Some(DownloadFile {
|
Some(DownloadFile {
|
||||||
file_name: version_jar_path
|
file_name: version_jar_path
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -262,7 +276,6 @@ fn build_file_map(
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
r#type: FileType::Library,
|
r#type: FileType::Library,
|
||||||
path: version_jar_path,
|
path: version_jar_path,
|
||||||
sha1: meta.downloads.client.sha1.clone(),
|
|
||||||
url: meta.downloads.client.url.clone(),
|
url: meta.downloads.client.url.clone(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -277,7 +290,6 @@ fn build_file_map(
|
|||||||
let hash = &meta.hash;
|
let hash = &meta.hash;
|
||||||
DownloadFile {
|
DownloadFile {
|
||||||
file_name: key.clone(),
|
file_name: key.clone(),
|
||||||
sha1: hash.clone(),
|
|
||||||
url: format!("{}/{}/{}", RESOURCES_ENDPOINT, &hash[0..2], hash),
|
url: format!("{}/{}/{}", RESOURCES_ENDPOINT, &hash[0..2], hash),
|
||||||
path: assets_path.join("objects").join(&hash[0..2]).join(hash),
|
path: assets_path.join("objects").join(&hash[0..2]).join(hash),
|
||||||
r#type: FileType::Asset {
|
r#type: FileType::Asset {
|
||||||
@@ -324,7 +336,6 @@ fn build_file_map(
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
sha1,
|
|
||||||
url,
|
url,
|
||||||
path,
|
path,
|
||||||
r#type: FileType::Library,
|
r#type: FileType::Library,
|
||||||
@@ -340,7 +351,6 @@ fn build_file_map(
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
sha1: artifact.sha1.clone(),
|
|
||||||
url: artifact.url.clone(),
|
url: artifact.url.clone(),
|
||||||
path: config
|
path: config
|
||||||
.game_dir
|
.game_dir
|
||||||
@@ -363,7 +373,6 @@ fn build_file_map(
|
|||||||
.unwrap_or(name)
|
.unwrap_or(name)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
path,
|
path,
|
||||||
sha1: downloads.raw.sha1.clone(),
|
|
||||||
url: downloads.raw.url.clone(),
|
url: downloads.raw.url.clone(),
|
||||||
r#type: FileType::Java,
|
r#type: FileType::Java,
|
||||||
})
|
})
|
||||||
@@ -565,7 +574,7 @@ async fn download_necessary(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !target_path.exists() || calculate_sha1(&target_path).ok()? != file.sha1 {
|
if !target_path.exists() {
|
||||||
fs::copy(&file.path, &target_path).ok();
|
fs::copy(&file.path, &target_path).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use lyceris::minecraft::{
|
|||||||
config::ConfigBuilder,
|
config::ConfigBuilder,
|
||||||
emitter::{Emitter, Event},
|
emitter::{Emitter, Event},
|
||||||
launch::launch,
|
launch::launch,
|
||||||
|
loader::fabric::Fabric,
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
@@ -56,22 +57,26 @@ pub async fn launch_game() -> Result<(), String> {
|
|||||||
let current_dir = LAUNCHER_DIR.data_dir();
|
let current_dir = LAUNCHER_DIR.data_dir();
|
||||||
|
|
||||||
let config = ConfigBuilder::new(
|
let config = ConfigBuilder::new(
|
||||||
current_dir.join("game"),
|
current_dir.join("1.21.4"),
|
||||||
"1.21.4".into(),
|
"1.21.4".into(),
|
||||||
lyceris::auth::AuthMethod::Offline {
|
lyceris::auth::AuthMethod::Offline {
|
||||||
username: "Lyceris".into(),
|
username: "Lyceris".into(),
|
||||||
// If none given, it will be generated.
|
|
||||||
uuid: None,
|
uuid: None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.loader(Fabric("0.18.6".to_string()).into())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
println!("Starting installation");
|
||||||
|
|
||||||
// Install method also checks for broken files
|
// Install method also checks for broken files
|
||||||
// and downloads them again if they are broken.
|
// and downloads them again if they are broken.
|
||||||
install::install(&config, Some(&emitter))
|
install::install(&config, Some(&emitter))
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
println!("Finished installing");
|
||||||
|
|
||||||
// This method never downloads any file and just runs the game.
|
// This method never downloads any file and just runs the game.
|
||||||
launch(&config, Some(&emitter))
|
launch(&config, Some(&emitter))
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user