You've already forked AstralRinth
forked from didirus/AstralRinth
fixes (#449)
* fixes * prettier * more bugs * changes * more fixes * prettier, fmt, clippy * fix regressed error * println, console.log * fix imports --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com> Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{
|
||||
fmt,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use io::IOError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -6,7 +9,10 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::{
|
||||
prelude::ProfilePathId,
|
||||
state::Profiles,
|
||||
util::{fetch, io},
|
||||
util::{
|
||||
fetch::{self, IoSemaphore},
|
||||
io,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod atlauncher;
|
||||
@@ -24,6 +30,19 @@ pub enum ImportLauncherType {
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
// impl display
|
||||
impl fmt::Display for ImportLauncherType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ImportLauncherType::MultiMC => write!(f, "MultiMC"),
|
||||
ImportLauncherType::PrismLauncher => write!(f, "PrismLauncher"),
|
||||
ImportLauncherType::ATLauncher => write!(f, "ATLauncher"),
|
||||
ImportLauncherType::GDLauncher => write!(f, "GDLauncher"),
|
||||
ImportLauncherType::Curseforge => write!(f, "Curseforge"),
|
||||
ImportLauncherType::Unknown => write!(f, "Unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return a list of importable instances from a launcher type and base path, by iterating through the folder and checking
|
||||
pub async fn get_importable_instances(
|
||||
@@ -31,12 +50,12 @@ pub async fn get_importable_instances(
|
||||
base_path: PathBuf,
|
||||
) -> crate::Result<Vec<String>> {
|
||||
// Some launchers have a different folder structure for instances
|
||||
let instances_folder = match launcher_type {
|
||||
let instances_subfolder = match launcher_type {
|
||||
ImportLauncherType::GDLauncher
|
||||
| ImportLauncherType::MultiMC
|
||||
| ImportLauncherType::PrismLauncher
|
||||
| ImportLauncherType::ATLauncher => base_path.join("instances"),
|
||||
ImportLauncherType::Curseforge => base_path.join("Instances"),
|
||||
| ImportLauncherType::ATLauncher => "instances",
|
||||
ImportLauncherType::Curseforge => "Instances",
|
||||
ImportLauncherType::Unknown => {
|
||||
return Err(crate::ErrorKind::InputError(
|
||||
"Launcher type Unknown".to_string(),
|
||||
@@ -44,8 +63,13 @@ pub async fn get_importable_instances(
|
||||
.into())
|
||||
}
|
||||
};
|
||||
let instances_folder = base_path.join(instances_subfolder);
|
||||
let mut instances = Vec::new();
|
||||
let mut dir = io::read_dir(&instances_folder).await?;
|
||||
let mut dir = io::read_dir(&instances_folder).await.map_err(| _ | {
|
||||
crate::ErrorKind::InputError(format!(
|
||||
"Invalid {launcher_type} launcher path, could not find '{instances_subfolder}' subfolder."
|
||||
))
|
||||
})?;
|
||||
while let Some(entry) = dir
|
||||
.next_entry()
|
||||
.await
|
||||
@@ -216,6 +240,7 @@ pub async fn recache_icon(
|
||||
async fn copy_dotminecraft(
|
||||
profile_path: ProfilePathId,
|
||||
dotminecraft: PathBuf,
|
||||
io_semaphore: &IoSemaphore,
|
||||
) -> crate::Result<()> {
|
||||
// Get full path to profile
|
||||
let profile_path = profile_path.get_full_path().await?;
|
||||
@@ -236,6 +261,7 @@ async fn copy_dotminecraft(
|
||||
&path.display()
|
||||
))
|
||||
})?),
|
||||
io_semaphore,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -247,9 +273,13 @@ async fn copy_dotminecraft(
|
||||
#[theseus_macros::debug_pin]
|
||||
#[async_recursion::async_recursion]
|
||||
#[tracing::instrument]
|
||||
async fn copy_dir_to(src: &Path, dst: &Path) -> crate::Result<()> {
|
||||
async fn copy_dir_to(
|
||||
src: &Path,
|
||||
dst: &Path,
|
||||
io_semaphore: &IoSemaphore,
|
||||
) -> crate::Result<()> {
|
||||
if !src.is_dir() {
|
||||
io::copy(src, dst).await?;
|
||||
fetch::copy(src, dst, io_semaphore).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -273,10 +303,10 @@ async fn copy_dir_to(src: &Path, dst: &Path) -> crate::Result<()> {
|
||||
|
||||
if src_child.is_dir() {
|
||||
// Recurse into sub-directory
|
||||
copy_dir_to(&src_child, &dst_child).await?;
|
||||
copy_dir_to(&src_child, &dst_child, io_semaphore).await?;
|
||||
} else {
|
||||
// Copy file
|
||||
io::copy(&src_child, &dst_child).await?;
|
||||
fetch::copy(&src_child, &dst_child, io_semaphore).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user