parent
1796c48fc7
commit
da4fc1c835
@ -79,7 +79,7 @@ pub async fn install_pack_from_version_id(
|
|||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
) -> crate::Result<PathBuf> {
|
) -> crate::Result<PathBuf> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
|
Box::pin(async move {
|
||||||
let loading_bar = init_loading(
|
let loading_bar = init_loading(
|
||||||
LoadingBarType::PackFileDownload {
|
LoadingBarType::PackFileDownload {
|
||||||
pack_name: title,
|
pack_name: title,
|
||||||
@ -126,7 +126,8 @@ pub async fn install_pack_from_version_id(
|
|||||||
&state.fetch_semaphore,
|
&state.fetch_semaphore,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
emit_loading(&loading_bar, 0.0, Some("Fetching project metadata")).await?;
|
emit_loading(&loading_bar, 0.0, Some("Fetching project metadata"))
|
||||||
|
.await?;
|
||||||
|
|
||||||
let project: ModrinthProject = fetch_json(
|
let project: ModrinthProject = fetch_json(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
@ -140,7 +141,8 @@ pub async fn install_pack_from_version_id(
|
|||||||
emit_loading(&loading_bar, 10.0, Some("Retrieving icon")).await?;
|
emit_loading(&loading_bar, 10.0, Some("Retrieving icon")).await?;
|
||||||
let icon = if let Some(icon_url) = project.icon_url {
|
let icon = if let Some(icon_url) = project.icon_url {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let icon_bytes = fetch(&icon_url, None, &state.fetch_semaphore).await?;
|
let icon_bytes =
|
||||||
|
fetch(&icon_url, None, &state.fetch_semaphore).await?;
|
||||||
|
|
||||||
let filename = icon_url.rsplit('/').next();
|
let filename = icon_url.rsplit('/').next();
|
||||||
|
|
||||||
@ -171,6 +173,8 @@ pub async fn install_pack_from_version_id(
|
|||||||
Some(loading_bar),
|
Some(loading_bar),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn install_pack_from_file(path: PathBuf) -> crate::Result<PathBuf> {
|
pub async fn install_pack_from_file(path: PathBuf) -> crate::Result<PathBuf> {
|
||||||
@ -189,10 +193,12 @@ async fn install_pack(
|
|||||||
) -> crate::Result<PathBuf> {
|
) -> crate::Result<PathBuf> {
|
||||||
let state = &State::get().await?;
|
let state = &State::get().await?;
|
||||||
|
|
||||||
let reader = Cursor::new(&file);
|
Box::pin(async move {
|
||||||
|
let reader: Cursor<&bytes::Bytes> = Cursor::new(&file);
|
||||||
|
|
||||||
// Create zip reader around file
|
// Create zip reader around file
|
||||||
let mut zip_reader = ZipFileReader::new(reader).await.map_err(|_| {
|
let mut zip_reader =
|
||||||
|
ZipFileReader::new(reader).await.map_err(|_| {
|
||||||
crate::Error::from(crate::ErrorKind::InputError(
|
crate::Error::from(crate::ErrorKind::InputError(
|
||||||
"Failed to read input modpack zip".to_string(),
|
"Failed to read input modpack zip".to_string(),
|
||||||
))
|
))
|
||||||
@ -325,9 +331,14 @@ async fn install_pack(
|
|||||||
.next();
|
.next();
|
||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
match path {
|
match path {
|
||||||
Component::CurDir | Component::Normal(_) => {
|
Component::CurDir
|
||||||
|
| Component::Normal(_) => {
|
||||||
let path = profile.join(project.path);
|
let path = profile.join(project.path);
|
||||||
write(&path, &file, &state.io_semaphore)
|
write(
|
||||||
|
&path,
|
||||||
|
&file,
|
||||||
|
&state.io_semaphore,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -366,7 +377,8 @@ async fn install_pack(
|
|||||||
{
|
{
|
||||||
// Reads the file into the 'content' variable
|
// Reads the file into the 'content' variable
|
||||||
let mut content = Vec::new();
|
let mut content = Vec::new();
|
||||||
let mut reader = overrides_zip.entry(index).await?;
|
let mut reader =
|
||||||
|
overrides_zip.entry(index).await?;
|
||||||
reader
|
reader
|
||||||
.read_to_end_checked(&mut content, &file)
|
.read_to_end_checked(&mut content, &file)
|
||||||
.await?;
|
.await?;
|
||||||
@ -398,10 +410,16 @@ async fn install_pack(
|
|||||||
.await?;
|
.await?;
|
||||||
extract_overrides("overrides".to_string()).await?;
|
extract_overrides("overrides".to_string()).await?;
|
||||||
extract_overrides("client_overrides".to_string()).await?;
|
extract_overrides("client_overrides".to_string()).await?;
|
||||||
emit_loading(&loading_bar, 29.9, Some("Done extacting overrides"))
|
emit_loading(
|
||||||
|
&loading_bar,
|
||||||
|
29.9,
|
||||||
|
Some("Done extacting overrides"),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(profile) = crate::api::profile::get(&profile).await? {
|
if let Some(profile) =
|
||||||
|
crate::api::profile::get(&profile).await?
|
||||||
|
{
|
||||||
tokio::try_join!(
|
tokio::try_join!(
|
||||||
super::profile::sync(&profile.path),
|
super::profile::sync(&profile.path),
|
||||||
crate::launcher::install_minecraft(
|
crate::launcher::install_minecraft(
|
||||||
@ -428,4 +446,6 @@ async fn install_pack(
|
|||||||
"No pack manifest found in mrpack".to_string(),
|
"No pack manifest found in mrpack".to_string(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,6 +139,7 @@ pub async fn install(path: &Path) -> crate::Result<()> {
|
|||||||
|
|
||||||
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
|
Box::pin(async move {
|
||||||
let mut profiles = state.profiles.write().await;
|
let mut profiles = state.profiles.write().await;
|
||||||
|
|
||||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||||
@ -174,6 +175,8 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
|||||||
)
|
)
|
||||||
.as_error())
|
.as_error())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_project(
|
pub async fn update_project(
|
||||||
@ -372,6 +375,7 @@ pub async fn run_credentials(
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
credentials: &auth::Credentials,
|
credentials: &auth::Credentials,
|
||||||
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
|
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
|
||||||
|
Box::pin(async move {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let settings = state.settings.read().await;
|
let settings = state.settings.read().await;
|
||||||
let metadata = state.metadata.read().await;
|
let metadata = state.metadata.read().await;
|
||||||
@ -512,6 +516,7 @@ pub async fn run_credentials(
|
|||||||
&profile,
|
&profile,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(mc_process)
|
Ok(mc_process)
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,7 @@ pub async fn profile_create(
|
|||||||
) -> crate::Result<PathBuf> {
|
) -> crate::Result<PathBuf> {
|
||||||
trace!("Creating new profile. {}", name);
|
trace!("Creating new profile. {}", name);
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
|
Box::pin(async move {
|
||||||
let metadata = state.metadata.read().await;
|
let metadata = state.metadata.read().await;
|
||||||
|
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
@ -198,6 +199,8 @@ pub async fn profile_create(
|
|||||||
State::sync().await?;
|
State::sync().await?;
|
||||||
|
|
||||||
Ok(path)
|
Ok(path)
|
||||||
|
|
||||||
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
|||||||
@ -49,8 +49,10 @@ pub async fn download_version_info(
|
|||||||
force: Option<bool>,
|
force: Option<bool>,
|
||||||
loading_bar: Option<&LoadingBarId>,
|
loading_bar: Option<&LoadingBarId>,
|
||||||
) -> crate::Result<GameVersionInfo> {
|
) -> crate::Result<GameVersionInfo> {
|
||||||
let version_id = loader
|
Box::pin(async move {
|
||||||
.map_or(version.id.clone(), |it| format!("{}-{}", version.id, it.id));
|
let version_id = loader.map_or(version.id.clone(), |it| {
|
||||||
|
format!("{}-{}", version.id, it.id)
|
||||||
|
});
|
||||||
tracing::debug!("Loading version info for Minecraft {version_id}");
|
tracing::debug!("Loading version info for Minecraft {version_id}");
|
||||||
let path = st
|
let path = st
|
||||||
.directories
|
.directories
|
||||||
@ -63,11 +65,15 @@ pub async fn download_version_info(
|
|||||||
.await
|
.await
|
||||||
.and_then(|ref it| Ok(serde_json::from_slice(it)?))
|
.and_then(|ref it| Ok(serde_json::from_slice(it)?))
|
||||||
} else {
|
} else {
|
||||||
tracing::info!("Downloading version info for version {}", &version.id);
|
tracing::info!(
|
||||||
|
"Downloading version info for version {}",
|
||||||
|
&version.id
|
||||||
|
);
|
||||||
let mut info = d::minecraft::fetch_version_info(version).await?;
|
let mut info = d::minecraft::fetch_version_info(version).await?;
|
||||||
|
|
||||||
if let Some(loader) = loader {
|
if let Some(loader) = loader {
|
||||||
let partial = d::modded::fetch_partial_version(&loader.url).await?;
|
let partial =
|
||||||
|
d::modded::fetch_partial_version(&loader.url).await?;
|
||||||
info = d::modded::merge_partial_version(partial, info);
|
info = d::modded::merge_partial_version(partial, info);
|
||||||
}
|
}
|
||||||
info.id = version_id.clone();
|
info.id = version_id.clone();
|
||||||
@ -96,6 +102,8 @@ pub async fn download_version_info(
|
|||||||
|
|
||||||
tracing::debug!("Loaded version info for Minecraft {version_id}");
|
tracing::debug!("Loaded version info for Minecraft {version_id}");
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
@ -104,6 +112,7 @@ pub async fn download_client(
|
|||||||
version_info: &GameVersionInfo,
|
version_info: &GameVersionInfo,
|
||||||
loading_bar: Option<&LoadingBarId>,
|
loading_bar: Option<&LoadingBarId>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
|
Box::pin(async move {
|
||||||
let version = &version_info.id;
|
let version = &version_info.id;
|
||||||
tracing::debug!("Locating client for version {version}");
|
tracing::debug!("Locating client for version {version}");
|
||||||
let client_download = version_info
|
let client_download = version_info
|
||||||
@ -136,6 +145,8 @@ pub async fn download_client(
|
|||||||
|
|
||||||
tracing::debug!("Client loaded for version {version}!");
|
tracing::debug!("Client loaded for version {version}!");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
@ -176,6 +187,7 @@ pub async fn download_assets(
|
|||||||
index: &AssetsIndex,
|
index: &AssetsIndex,
|
||||||
loading_bar: Option<&LoadingBarId>,
|
loading_bar: Option<&LoadingBarId>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
|
Box::pin(async move {
|
||||||
tracing::debug!("Loading assets");
|
tracing::debug!("Loading assets");
|
||||||
let num_futs = index.objects.len();
|
let num_futs = index.objects.len();
|
||||||
let assets = stream::iter(index.objects.iter())
|
let assets = stream::iter(index.objects.iter())
|
||||||
@ -228,6 +240,8 @@ pub async fn download_assets(
|
|||||||
|
|
||||||
tracing::debug!("Done loading assets!");
|
tracing::debug!("Done loading assets!");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(st, libraries))]
|
#[tracing::instrument(skip(st, libraries))]
|
||||||
@ -237,6 +251,7 @@ pub async fn download_libraries(
|
|||||||
version: &str,
|
version: &str,
|
||||||
loading_bar: Option<&LoadingBarId>,
|
loading_bar: Option<&LoadingBarId>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
|
Box::pin(async move {
|
||||||
tracing::debug!("Loading libraries");
|
tracing::debug!("Loading libraries");
|
||||||
|
|
||||||
tokio::try_join! {
|
tokio::try_join! {
|
||||||
@ -329,4 +344,6 @@ pub async fn download_libraries(
|
|||||||
|
|
||||||
tracing::debug!("Done loading libraries!");
|
tracing::debug!("Done loading libraries!");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
|
}).await
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,7 @@ pub async fn install_minecraft(
|
|||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
existing_loading_bar: Option<LoadingBarId>,
|
existing_loading_bar: Option<LoadingBarId>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
|
Box::pin(async move {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let instance_path = &canonicalize(&profile.path)?;
|
let instance_path = &canonicalize(&profile.path)?;
|
||||||
let metadata = state.metadata.read().await;
|
let metadata = state.metadata.read().await;
|
||||||
@ -210,6 +211,8 @@ pub async fn install_minecraft(
|
|||||||
State::sync().await?;
|
State::sync().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
|
}).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@ -224,6 +227,7 @@ pub async fn launch_minecraft(
|
|||||||
post_exit_hook: Option<Command>,
|
post_exit_hook: Option<Command>,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> {
|
) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> {
|
||||||
|
Box::pin(async move {
|
||||||
if !profile.installed {
|
if !profile.installed {
|
||||||
install_minecraft(profile, None).await?;
|
install_minecraft(profile, None).await?;
|
||||||
}
|
}
|
||||||
@ -360,4 +364,6 @@ pub async fn launch_minecraft(
|
|||||||
post_exit_hook,
|
post_exit_hook,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
||||||
|
}).await
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
use dunce::canonicalize;
|
use dunce::canonicalize;
|
||||||
use theseus::jre::autodetect_java_globals;
|
use theseus::jre::autodetect_java_globals;
|
||||||
use theseus::prelude::*;
|
use theseus::prelude::*;
|
||||||
use theseus::profile_create::profile_create;
|
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user