Folder names (#318)

This commit is contained in:
Wyatt Verchere
2023-07-21 20:16:07 -07:00
committed by GitHub
parent 4941260805
commit 3fa33dc241
42 changed files with 1129 additions and 535 deletions

View File

@@ -4,7 +4,7 @@ use crate::event::emit::{
};
use crate::event::LoadingBarType;
use crate::pack::install_from::{EnvType, PackFile, PackFileHash};
use crate::state::{LinkedData, ProfileInstallStage, SideType};
use crate::state::{LinkedData, ProfileInstallStage, ProfilePathId, SideType};
use crate::util::fetch::{fetch_mirrors, write};
use crate::State;
use async_zip::tokio::read::seek::ZipFileReader;
@@ -20,8 +20,8 @@ use super::install_from::{
#[theseus_macros::debug_pin]
pub async fn install_pack(
location: CreatePackLocation,
profile: PathBuf,
) -> crate::Result<PathBuf> {
profile_path: ProfilePathId,
) -> crate::Result<ProfilePathId> {
// Get file from description
let description: CreatePackDescription = match location {
CreatePackLocation::FromVersionId {
@@ -31,12 +31,16 @@ pub async fn install_pack(
icon_url,
} => {
generate_pack_from_version_id(
project_id, version_id, title, icon_url, profile,
project_id,
version_id,
title,
icon_url,
profile_path,
)
.await?
}
CreatePackLocation::FromFile { path } => {
generate_pack_from_file(path, profile).await?
generate_pack_from_file(path, profile_path).await?
}
};
@@ -46,7 +50,7 @@ pub async fn install_pack(
let project_id = description.project_id;
let version_id = description.version_id;
let existing_loading_bar = description.existing_loading_bar;
let profile = description.profile;
let profile_path = description.profile_path;
let state = &State::get().await?;
@@ -125,7 +129,7 @@ pub async fn install_pack(
loader_version.cloned(),
)
.await?;
crate::api::profile::edit(&profile, |prof| {
crate::api::profile::edit(&profile_path, |prof| {
prof.metadata.name =
override_title.clone().unwrap_or_else(|| pack.name.clone());
prof.install_stage = ProfileInstallStage::PackInstalling;
@@ -142,12 +146,15 @@ pub async fn install_pack(
})
.await?;
let profile = profile.clone();
let profile_path = profile_path.clone();
let result = async {
let loading_bar = init_or_edit_loading(
existing_loading_bar,
LoadingBarType::PackDownload {
profile_path: profile.clone(),
profile_path: profile_path
.get_full_path()
.await?
.clone(),
pack_name: pack.name.clone(),
icon,
pack_id: project_id,
@@ -169,7 +176,7 @@ pub async fn install_pack(
num_files,
None,
|project| {
let profile = profile.clone();
let profile_path = profile_path.clone();
async move {
//TODO: Future update: prompt user for optional files in a modpack
if let Some(env) = project.env {
@@ -203,7 +210,10 @@ pub async fn install_pack(
match path {
Component::CurDir
| Component::Normal(_) => {
let path = profile.join(project.path);
let path = profile_path
.get_full_path()
.await?
.join(project.path);
write(
&path,
&file,
@@ -265,7 +275,10 @@ pub async fn install_pack(
if new_path.file_name().is_some() {
write(
&profile.join(new_path),
&profile_path
.get_full_path()
.await?
.join(new_path),
&content,
&state.io_semaphore,
)
@@ -285,7 +298,7 @@ pub async fn install_pack(
}
if let Some(profile_val) =
crate::api::profile::get(&profile, None).await?
crate::api::profile::get(&profile_path, None).await?
{
crate::launcher::install_minecraft(
&profile_val,
@@ -296,14 +309,14 @@ pub async fn install_pack(
State::sync().await?;
}
Ok::<PathBuf, crate::Error>(profile.clone())
Ok::<ProfilePathId, crate::Error>(profile_path.clone())
}
.await;
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile).await;
let _ = crate::api::profile::remove(&profile_path).await;
Err(err)
}
@@ -319,7 +332,7 @@ pub async fn install_pack(
match result {
Ok(profile) => Ok(profile),
Err(err) => {
let _ = crate::api::profile::remove(&profile).await;
let _ = crate::api::profile::remove(&profile_path).await;
Err(err)
}

View File

@@ -2,7 +2,9 @@ use crate::config::MODRINTH_API_URL;
use crate::data::ModLoader;
use crate::event::emit::{emit_loading, init_loading};
use crate::event::{LoadingBarId, LoadingBarType};
use crate::state::{LinkedData, ModrinthProject, ModrinthVersion, SideType};
use crate::state::{
LinkedData, ModrinthProject, ModrinthVersion, ProfilePathId, SideType,
};
use crate::util::fetch::{
fetch, fetch_advanced, fetch_json, write_cached_icon,
};
@@ -71,7 +73,7 @@ pub enum PackDependency {
Minecraft,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum CreatePackLocation {
FromVersionId {
@@ -98,6 +100,7 @@ pub struct CreatePackProfile {
pub skip_install_profile: Option<bool>,
}
#[derive(Debug)]
pub struct CreatePackDescription {
pub file: bytes::Bytes,
pub icon: Option<PathBuf>,
@@ -105,7 +108,7 @@ pub struct CreatePackDescription {
pub project_id: Option<String>,
pub version_id: Option<String>,
pub existing_loading_bar: Option<LoadingBarId>,
pub profile: PathBuf,
pub profile_path: ProfilePathId,
}
pub fn get_profile_from_pack(
@@ -158,13 +161,13 @@ pub async fn generate_pack_from_version_id(
version_id: String,
title: String,
icon_url: Option<String>,
profile: PathBuf,
profile_path: ProfilePathId,
) -> crate::Result<CreatePackDescription> {
let state = State::get().await?;
let loading_bar = init_loading(
LoadingBarType::PackFileDownload {
profile_path: profile.clone(),
profile_path: profile_path.get_full_path().await?,
pack_name: title,
icon: icon_url,
pack_version: version_id.clone(),
@@ -253,7 +256,7 @@ pub async fn generate_pack_from_version_id(
project_id: Some(project_id),
version_id: Some(version_id),
existing_loading_bar: Some(loading_bar),
profile,
profile_path,
})
}
@@ -261,7 +264,7 @@ pub async fn generate_pack_from_version_id(
#[theseus_macros::debug_pin]
pub async fn generate_pack_from_file(
path: PathBuf,
profile: PathBuf,
profile_path: ProfilePathId,
) -> crate::Result<CreatePackDescription> {
let file = io::read(&path).await?;
Ok(CreatePackDescription {
@@ -271,6 +274,6 @@ pub async fn generate_pack_from_file(
project_id: None,
version_id: None,
existing_loading_bar: None,
profile,
profile_path,
})
}