Skip to content

Commit

Permalink
Merge branch 'feature/collection-frb-v2' into feature/mod-mangement
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSimplyKyle committed Jan 25, 2024
2 parents 89529e8 + c971db5 commit e451295
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 99 deletions.
36 changes: 7 additions & 29 deletions app/rust/src/api/backend_exclusive/vanilla/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ pub async fn prepare_vanilla_download<'a>(
.await
.context("fail to create native directory (vanilla)")?;

let logging_arguments = setup_logging(&game_manifest, &game_directory).await?;
let game_flags = setup_game_flags(game_manifest.arguments.game);
let jvm_flags = setup_jvm_flags(game_manifest.arguments.jvm);

Expand Down Expand Up @@ -179,7 +178,6 @@ pub async fn prepare_vanilla_download<'a>(
jvm_flags,
)?;

jvm_flags.arguments.push(logging_arguments);
jvm_flags.arguments = jvm_args_parse(&jvm_flags.arguments, &jvm_options);

let mut handles = Vec::new();
Expand Down Expand Up @@ -245,28 +243,6 @@ pub async fn prepare_vanilla_download<'a>(
))
}

async fn setup_logging(game_manifest: &GameManifest, game_directory: &PathBuf) -> Result<String> {
let logging_url = &game_manifest.logging.client.file.url;
let logging_path =
game_directory.join(&game_manifest.logging.client.logging_type.replace("-", "."));
if !logging_path.exists() {
let p = download_file(logging_url, None).await?;
fs::write(&logging_path, p).await?;
} else if validate_sha1(&logging_path, &game_manifest.logging.client.file.sha1)
.await
.is_err()
{
let p = download_file(logging_url, None).await?;
fs::write(&logging_path, p).await?;
}
let logging_argument = game_manifest
.logging
.client
.argument
.replace("${path}", &logging_path.to_string_lossy().to_string());
Ok(logging_argument)
}

fn add_jvm_rules(
library_list: Arc<[Library]>,
library_path: impl AsRef<Path>,
Expand All @@ -293,11 +269,13 @@ fn add_jvm_rules(
let mut classpath_list = parsed_library_list
.iter()
.map(|x| {
library_path
.as_ref()
.join(&x.downloads.artifact.path)
.to_string_lossy()
.to_string()
if let Some(ref path) = x.downloads.artifact.path {
library_path.as_ref().join(path)
} else {
library_path.as_ref().to_path_buf()
}
.to_string_lossy()
.to_string()
})
.collect::<Vec<String>>();

Expand Down
68 changes: 37 additions & 31 deletions app/rust/src/api/backend_exclusive/vanilla/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Library {

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct Metadata {
pub path: String,
pub path: Option<String>,
pub sha1: String,
pub size: usize,
pub url: String,
Expand All @@ -50,8 +50,8 @@ pub fn os_match<'a>(library: &Library, current_os_type: &'a OsName) -> (bool, bo
}
is_native_library = true;
library_extension_type = match current_os_type {
OsName::Osx => ".dylib",
OsName::Linux => ".so",
OsName::Osx | OsName::OsxArm64 => ".dylib",
OsName::Linux | OsName::LinuxArm64 | OsName::LinuxArm32 => ".so",
OsName::Windows => ".dll",
}
}
Expand Down Expand Up @@ -96,22 +96,43 @@ pub async fn parallel_library(
let path = library.downloads.artifact.path.clone();
let (process_native, is_native_library, library_extension) =
os_match(library, &current_os_type);
let non_native_download_path = folder_clone.join(&path);
let non_native_redownload = if non_native_download_path.exists() {
if let Err(x) = if !process_native && !is_native_library {
validate_sha1(&non_native_download_path, &library.downloads.artifact.sha1)
if let Some(ref path) = path {
let non_native_download_path = folder_clone.join(&path);
let non_native_redownload = if non_native_download_path.exists() {
if let Err(x) = if !process_native && !is_native_library {
validate_sha1(
&non_native_download_path,
&library.downloads.artifact.sha1,
)
.await
} else {
Ok(())
} {
error!("{x}, \nredownloading.");
true
} else {
false
}
} else {
Ok(())
} {
error!("{x}, \nredownloading.");
true
} else {
false
};
if !process_native && non_native_redownload {
total_size_clone
.fetch_add(library.downloads.artifact.size, Ordering::Relaxed);
let parent_dir = non_native_download_path
.parent()
.context("Can't find parent of non_native_download_path")?;
fs::create_dir_all(parent_dir)
.await
.context("Fail to create parent dir(library)")?;
let url = &library.downloads.artifact.url;
let bytes =
download_file(url, Some(Arc::clone(&current_size_clone))).await?;
fs::write(&non_native_download_path, bytes)
.await
.map_err(|err| anyhow!(err))?;
}
} else {
true
};
}

// always download(kinda required for now.)
if process_native {
Expand All @@ -124,23 +145,8 @@ pub async fn parallel_library(
library_extension,
)
.await?;
Ok(())
} else if !non_native_redownload {
Ok(())
} else {
total_size_clone.fetch_add(library.downloads.artifact.size, Ordering::Relaxed);
let parent_dir = non_native_download_path
.parent()
.context("Can't find parent of non_native_download_path")?;
fs::create_dir_all(parent_dir)
.await
.context("Fail to create parent dir(library)")?;
let url = &library.downloads.artifact.url;
let bytes = download_file(url, Some(current_size_clone)).await?;
fs::write(&non_native_download_path, bytes)
.await
.map_err(|err| anyhow!(err))
}
Ok(())
} else {
Ok(())
}
Expand Down
23 changes: 0 additions & 23 deletions app/rust/src/api/backend_exclusive/vanilla/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ pub struct GameManifest {
pub arguments: Arguments,
pub asset_index: AssetIndex,
pub assets: String,
pub compliance_level: u32,
pub downloads: Downloads,
pub id: String,
pub java_version: JavaVersion,
pub libraries: Vec<Library>,
pub logging: LoggingConfig,
pub main_class: String,
pub minimum_launcher_version: u32,
pub release_time: DateTime<Utc>,
Expand Down Expand Up @@ -74,27 +72,6 @@ pub struct JavaVersion {
pub major_version: u32,
}

#[derive(Debug, Deserialize, Clone)]
pub struct LoggingConfig {
pub client: LoggingClientConfig,
}

#[derive(Debug, Deserialize, Clone)]
pub struct LoggingClientConfig {
pub argument: String,
pub file: LoggingFile,
#[serde(rename = "type")]
pub logging_type: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct LoggingFile {
pub id: String,
pub sha1: String,
pub size: u64,
pub url: String,
}

pub async fn fetch_game_manifest(url: &str) -> anyhow::Result<GameManifest> {
let response = download_file(url, None).await?;
let p = serde_json::from_slice(&response)?;
Expand Down
11 changes: 10 additions & 1 deletion app/rust/src/api/backend_exclusive/vanilla/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ pub enum OsName {
Windows,
#[serde(rename = "linux")]
Linux,
#[serde(rename = "osx-arm64")]
OsxArm64,
#[serde(rename = "linux-arm64")]
LinuxArm64,
#[serde(rename = "linux-arm32")]
LinuxArm32,
}

impl fmt::Display for OsName {
Expand All @@ -29,6 +35,9 @@ impl fmt::Display for OsName {
Self::Osx => write!(f, "Osx"),
Self::Windows => write!(f, "Windows"),
Self::Linux => write!(f, "Linux"),
Self::OsxArm64 => write!(f, "Arm64 Osx"),
Self::LinuxArm64 => write!(f, "Arm64 Linux"),
Self::LinuxArm32 => write!(f, "Arm32 Linux"),
}
}
}
Expand All @@ -43,7 +52,7 @@ pub struct Os {
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct Rule {
pub action: ActionType,
pub features: Option<HashMap<String, bool>>,
pub features: Option<HashMap<String, Option<bool>>>,
pub os: Option<Os>,
}

Expand Down
3 changes: 1 addition & 2 deletions app/rust/src/api/backend_exclusive/vanilla/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use serde::{Deserialize, Serialize};

use crate::api::backend_exclusive::download::download_file;

const VERSION_MANIFEST_URL: &str =
"https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
const VERSION_MANIFEST_URL: &str = "https://meta.modrinth.com/minecraft/v0/manifest.json";

#[derive(Debug, Deserialize)]
pub struct VersionsManifest {
Expand Down
25 changes: 12 additions & 13 deletions app/rust/src/api/shared_resources/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,20 @@ pub async fn create_collection(
collection.entry_path.display()
);
let id = Arc::new(collection.get_collection_id());
let download_handle: flutter_rust_bridge::JoinHandle<anyhow::Result<()>> =
tokio::spawn(async move {
loop {
let (tx, mut rx) = unbounded_channel();
DOWNLOAD_PROGRESS.send(HashMapMessage::Get(Arc::clone(&id), tx))?;
if let Some(Some(x)) = rx.recv().await {
if x.percentages >= 100.0 {
break;
}
debug!("{:#?}", x);
let download_handle = tokio::spawn(async move {
loop {
let (tx, mut rx) = unbounded_channel();
DOWNLOAD_PROGRESS.send(HashMapMessage::Get(Arc::clone(&id), tx))?;
if let Some(Some(x)) = rx.recv().await {
if x.percentages >= 100.0 {
break;
}
tokio::time::sleep(Duration::from_millis(500)).await;
debug!("{:#?}", x);
}
Ok(())
});
tokio::time::sleep(Duration::from_millis(500)).await;
}
Ok::<(), anyhow::Error>(())
});

info!(
"Successfully created collection basic file at {}",
Expand Down

0 comments on commit e451295

Please sign in to comment.