added box pins (#110)

* added box pins

* clippy
This commit is contained in:
Wyatt Verchere 2023-05-09 12:05:52 -07:00 committed by GitHub
parent 1796c48fc7
commit da4fc1c835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1146 additions and 1095 deletions

View File

@ -79,7 +79,7 @@ pub async fn install_pack_from_version_id(
title: Option<String>,
) -> crate::Result<PathBuf> {
let state = State::get().await?;
Box::pin(async move {
let loading_bar = init_loading(
LoadingBarType::PackFileDownload {
pack_name: title,
@ -126,7 +126,8 @@ pub async fn install_pack_from_version_id(
&state.fetch_semaphore,
)
.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(
Method::GET,
@ -140,7 +141,8 @@ pub async fn install_pack_from_version_id(
emit_loading(&loading_bar, 10.0, Some("Retrieving icon")).await?;
let icon = if let Some(icon_url) = project.icon_url {
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();
@ -171,6 +173,8 @@ pub async fn install_pack_from_version_id(
Some(loading_bar),
)
.await
})
.await
}
pub async fn install_pack_from_file(path: PathBuf) -> crate::Result<PathBuf> {
@ -189,10 +193,12 @@ async fn install_pack(
) -> crate::Result<PathBuf> {
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
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(
"Failed to read input modpack zip".to_string(),
))
@ -325,9 +331,14 @@ async fn install_pack(
.next();
if let Some(path) = path {
match path {
Component::CurDir | Component::Normal(_) => {
Component::CurDir
| Component::Normal(_) => {
let path = profile.join(project.path);
write(&path, &file, &state.io_semaphore)
write(
&path,
&file,
&state.io_semaphore,
)
.await?;
}
_ => {}
@ -366,7 +377,8 @@ async fn install_pack(
{
// Reads the file into the 'content' variable
let mut content = Vec::new();
let mut reader = overrides_zip.entry(index).await?;
let mut reader =
overrides_zip.entry(index).await?;
reader
.read_to_end_checked(&mut content, &file)
.await?;
@ -398,10 +410,16 @@ async fn install_pack(
.await?;
extract_overrides("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?;
if let Some(profile) = crate::api::profile::get(&profile).await? {
if let Some(profile) =
crate::api::profile::get(&profile).await?
{
tokio::try_join!(
super::profile::sync(&profile.path),
crate::launcher::install_minecraft(
@ -428,4 +446,6 @@ async fn install_pack(
"No pack manifest found in mrpack".to_string(),
)))
}
})
.await
}

View File

@ -139,6 +139,7 @@ pub async fn install(path: &Path) -> crate::Result<()> {
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
let state = State::get().await?;
Box::pin(async move {
let mut profiles = state.profiles.write().await;
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())
}
})
.await
}
pub async fn update_project(
@ -372,6 +375,7 @@ pub async fn run_credentials(
path: &Path,
credentials: &auth::Credentials,
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
Box::pin(async move {
let state = State::get().await?;
let settings = state.settings.read().await;
let metadata = state.metadata.read().await;
@ -512,6 +516,7 @@ pub async fn run_credentials(
&profile,
)
.await?;
Ok(mc_process)
})
.await
}

View File

@ -51,6 +51,7 @@ pub async fn profile_create(
) -> crate::Result<PathBuf> {
trace!("Creating new profile. {}", name);
let state = State::get().await?;
Box::pin(async move {
let metadata = state.metadata.read().await;
let uuid = Uuid::new_v4();
@ -198,6 +199,8 @@ pub async fn profile_create(
State::sync().await?;
Ok(path)
}).await
}
#[derive(thiserror::Error, Debug)]

View File

@ -49,8 +49,10 @@ pub async fn download_version_info(
force: Option<bool>,
loading_bar: Option<&LoadingBarId>,
) -> crate::Result<GameVersionInfo> {
let version_id = loader
.map_or(version.id.clone(), |it| format!("{}-{}", version.id, it.id));
Box::pin(async move {
let version_id = loader.map_or(version.id.clone(), |it| {
format!("{}-{}", version.id, it.id)
});
tracing::debug!("Loading version info for Minecraft {version_id}");
let path = st
.directories
@ -63,11 +65,15 @@ pub async fn download_version_info(
.await
.and_then(|ref it| Ok(serde_json::from_slice(it)?))
} 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?;
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.id = version_id.clone();
@ -96,6 +102,8 @@ pub async fn download_version_info(
tracing::debug!("Loaded version info for Minecraft {version_id}");
Ok(res)
})
.await
}
#[tracing::instrument(skip_all)]
@ -104,6 +112,7 @@ pub async fn download_client(
version_info: &GameVersionInfo,
loading_bar: Option<&LoadingBarId>,
) -> crate::Result<()> {
Box::pin(async move {
let version = &version_info.id;
tracing::debug!("Locating client for version {version}");
let client_download = version_info
@ -136,6 +145,8 @@ pub async fn download_client(
tracing::debug!("Client loaded for version {version}!");
Ok(())
})
.await
}
#[tracing::instrument(skip_all)]
@ -176,6 +187,7 @@ pub async fn download_assets(
index: &AssetsIndex,
loading_bar: Option<&LoadingBarId>,
) -> crate::Result<()> {
Box::pin(async move {
tracing::debug!("Loading assets");
let num_futs = index.objects.len();
let assets = stream::iter(index.objects.iter())
@ -228,6 +240,8 @@ pub async fn download_assets(
tracing::debug!("Done loading assets!");
Ok(())
}).await
}
#[tracing::instrument(skip(st, libraries))]
@ -237,6 +251,7 @@ pub async fn download_libraries(
version: &str,
loading_bar: Option<&LoadingBarId>,
) -> crate::Result<()> {
Box::pin(async move {
tracing::debug!("Loading libraries");
tokio::try_join! {
@ -329,4 +344,6 @@ pub async fn download_libraries(
tracing::debug!("Done loading libraries!");
Ok(())
}).await
}

View File

@ -58,6 +58,7 @@ pub async fn install_minecraft(
profile: &Profile,
existing_loading_bar: Option<LoadingBarId>,
) -> crate::Result<()> {
Box::pin(async move {
let state = State::get().await?;
let instance_path = &canonicalize(&profile.path)?;
let metadata = state.metadata.read().await;
@ -210,6 +211,8 @@ pub async fn install_minecraft(
State::sync().await?;
Ok(())
}).await
}
#[allow(clippy::too_many_arguments)]
@ -224,6 +227,7 @@ pub async fn launch_minecraft(
post_exit_hook: Option<Command>,
profile: &Profile,
) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> {
Box::pin(async move {
if !profile.installed {
install_minecraft(profile, None).await?;
}
@ -360,4 +364,6 @@ pub async fn launch_minecraft(
post_exit_hook,
)
.await
}).await
}

View File

@ -6,7 +6,7 @@
use dunce::canonicalize;
use theseus::jre::autodetect_java_globals;
use theseus::prelude::*;
use theseus::profile_create::profile_create;
use tokio::time::{sleep, Duration};
use tracing_error::ErrorLayer;
use tracing_subscriber::layer::SubscriberExt;