You've already forked AstralRinth
forked from didirus/AstralRinth
fix all the red wiggly wiggles
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1191,6 +1191,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"json5",
|
"json5",
|
||||||
"log",
|
"log",
|
||||||
|
"once_cell",
|
||||||
"path-clean",
|
"path-clean",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ sys-info = "0.9.0"
|
|||||||
|
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
const_format = "0.2.22"
|
const_format = "0.2.22"
|
||||||
|
once_cell = "1.9.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
argh = "0.1.6"
|
argh = "0.1.6"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use crate::data::DataError;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use crate::{data::DataError, LAUNCHER_WORK_DIR};
|
||||||
use once_cell::sync;
|
use once_cell::sync;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
@@ -17,13 +19,11 @@ pub struct Metadata {
|
|||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub async fn init() -> Result<(), DataError> {
|
pub async fn init() -> Result<(), DataError> {
|
||||||
let meta_path = crate::LAUNCHER_WORK_DIR.join(META_FILE);
|
let meta_path = Path::new(LAUNCHER_WORK_DIR).join(META_FILE);
|
||||||
|
|
||||||
if meta_path.exists() {
|
if meta_path.exists() {
|
||||||
let meta_data = std::fs::read_to_string(meta_path)
|
let meta_data = std::fs::read_to_string(meta_path).ok()
|
||||||
.map(|x| serde_json::from_str::<Metadata>(&*x).ok())
|
.and_then(|x| serde_json::from_str::<Metadata>(&x).ok());
|
||||||
.ok()
|
|
||||||
.flatten();
|
|
||||||
|
|
||||||
if let Some(metadata) = meta_data {
|
if let Some(metadata) = meta_data {
|
||||||
METADATA.get_or_init(|| RwLock::new(metadata));
|
METADATA.get_or_init(|| RwLock::new(metadata));
|
||||||
@@ -36,8 +36,8 @@ impl Metadata {
|
|||||||
let new = Self::fetch().await?;
|
let new = Self::fetch().await?;
|
||||||
|
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
crate::LAUNCHER_WORK_DIR.join(META_FILE),
|
Path::new(LAUNCHER_WORK_DIR).join(META_FILE),
|
||||||
&*serde_json::to_string(&new)?,
|
&serde_json::to_string(&new)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if let Some(metadata) = METADATA.get() {
|
if let Some(metadata) = METADATA.get() {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use crate::data::DataError;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use crate::{data::DataError, LAUNCHER_WORK_DIR};
|
||||||
use once_cell::sync;
|
use once_cell::sync;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
@@ -32,7 +34,7 @@ impl Default for Settings {
|
|||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub async fn init() -> Result<(), DataError> {
|
pub async fn init() -> Result<(), DataError> {
|
||||||
let settings_path = crate::LAUNCHER_WORK_DIR.join(SETTINGS_FILE);
|
let settings_path = Path::new(LAUNCHER_WORK_DIR).join(SETTINGS_FILE);
|
||||||
|
|
||||||
if settings_path.exists() {
|
if settings_path.exists() {
|
||||||
let settings_data = std::fs::read_to_string(settings_path)
|
let settings_data = std::fs::read_to_string(settings_path)
|
||||||
@@ -49,7 +51,7 @@ impl Settings {
|
|||||||
let new = Self::default();
|
let new = Self::default();
|
||||||
|
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
crate::LAUNCHER_WORK_DIR.join(SETTINGS_FILE),
|
Path::new(LAUNCHER_WORK_DIR).join(SETTINGS_FILE),
|
||||||
&*serde_json::to_string(&new)?,
|
&*serde_json::to_string(&new)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -60,8 +62,8 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load() -> Result<(), DataError> {
|
pub async fn load() -> Result<(), DataError> {
|
||||||
let new = serde_json::from_str::<Settings>(&*std::fs::read_to_string(
|
let new = serde_json::from_str::<Settings>(&std::fs::read_to_string(
|
||||||
crate::LAUNCHER_WORK_DIR.join(SETTINGS_FILE),
|
Path::new(LAUNCHER_WORK_DIR).join(SETTINGS_FILE),
|
||||||
)?)?;
|
)?)?;
|
||||||
|
|
||||||
let write = &mut *SETTINGS
|
let write = &mut *SETTINGS
|
||||||
@@ -79,8 +81,8 @@ impl Settings {
|
|||||||
let settings = Self::get().await?;
|
let settings = Self::get().await?;
|
||||||
|
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
crate::LAUNCHER_WORK_DIR.join(SETTINGS_FILE),
|
Path::new(LAUNCHER_WORK_DIR).join(SETTINGS_FILE),
|
||||||
&*serde_json::to_string(&*settings)?,
|
&serde_json::to_string(&*settings)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -21,21 +21,19 @@ pub fn get_class_paths(
|
|||||||
libraries: &[Library],
|
libraries: &[Library],
|
||||||
client_path: &Path,
|
client_path: &Path,
|
||||||
) -> Result<String, LauncherError> {
|
) -> Result<String, LauncherError> {
|
||||||
let mut class_paths = Vec::new();
|
let mut class_paths = libraries.iter().filter_map(|library| {
|
||||||
|
|
||||||
for library in libraries {
|
|
||||||
if let Some(rules) = &library.rules {
|
if let Some(rules) = &library.rules {
|
||||||
if !super::rules::parse_rules(rules.as_slice()) {
|
if !super::rules::parse_rules(rules.as_slice()) {
|
||||||
continue;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !library.include_in_classpath {
|
if !library.include_in_classpath {
|
||||||
continue;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
class_paths.push(get_lib_path(libraries_path, &library.name)?);
|
Some(get_lib_path(libraries_path, &library.name))
|
||||||
}
|
}).collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
class_paths.push(
|
class_paths.push(
|
||||||
crate::util::absolute_path(&client_path)
|
crate::util::absolute_path(&client_path)
|
||||||
@@ -56,19 +54,14 @@ pub fn get_class_paths_jar<T: AsRef<str>>(
|
|||||||
libraries_path: &Path,
|
libraries_path: &Path,
|
||||||
libraries: &[T],
|
libraries: &[T],
|
||||||
) -> Result<String, LauncherError> {
|
) -> Result<String, LauncherError> {
|
||||||
let mut class_paths = Vec::new();
|
let class_paths = libraries.iter().map(|library| {
|
||||||
|
get_lib_path(libraries_path, library.as_ref())
|
||||||
|
}).collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
for library in libraries {
|
Ok(class_paths.join(get_cp_separator()))
|
||||||
class_paths.push(get_lib_path(libraries_path, library)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(class_paths.join(match super::download::get_os() {
|
|
||||||
Os::Osx | Os::Linux | Os::Unknown => ":",
|
|
||||||
Os::Windows => ";",
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lib_path<T: AsRef<str>>(libraries_path: &Path, lib: T) -> Result<String, LauncherError> {
|
pub fn get_lib_path(libraries_path: &Path, lib: &str) -> Result<String, LauncherError> {
|
||||||
let mut path = libraries_path.to_path_buf();
|
let mut path = libraries_path.to_path_buf();
|
||||||
|
|
||||||
path.push(get_path_from_artifact(lib.as_ref())?);
|
path.push(get_path_from_artifact(lib.as_ref())?);
|
||||||
@@ -105,7 +98,7 @@ pub fn get_jvm_arguments(
|
|||||||
if let Some(args) = arguments {
|
if let Some(args) = arguments {
|
||||||
parse_arguments(args, &mut parsed_arguments, |arg| {
|
parse_arguments(args, &mut parsed_arguments, |arg| {
|
||||||
parse_jvm_argument(
|
parse_jvm_argument(
|
||||||
arg,
|
arg.to_string(),
|
||||||
natives_path,
|
natives_path,
|
||||||
libraries_path,
|
libraries_path,
|
||||||
class_paths,
|
class_paths,
|
||||||
@@ -138,18 +131,17 @@ pub fn get_jvm_arguments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_jvm_argument(
|
fn parse_jvm_argument(
|
||||||
argument: &str,
|
mut argument: String,
|
||||||
natives_path: &Path,
|
natives_path: &Path,
|
||||||
libraries_path: &Path,
|
libraries_path: &Path,
|
||||||
class_paths: &str,
|
class_paths: &str,
|
||||||
version_name: &str,
|
version_name: &str,
|
||||||
) -> Result<String, LauncherError> {
|
) -> Result<String, LauncherError> {
|
||||||
let mut argument = argument.to_string();
|
|
||||||
argument.retain(|c| !c.is_whitespace());
|
argument.retain(|c| !c.is_whitespace());
|
||||||
Ok(argument
|
Ok(argument
|
||||||
.replace(
|
.replace(
|
||||||
"${natives_directory}",
|
"${natives_directory}",
|
||||||
&*crate::util::absolute_path(natives_path)
|
&crate::util::absolute_path(natives_path)
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
LauncherError::InvalidInput(format!(
|
LauncherError::InvalidInput(format!(
|
||||||
"Specified natives path {} does not exist",
|
"Specified natives path {} does not exist",
|
||||||
@@ -196,8 +188,8 @@ pub fn get_minecraft_arguments(
|
|||||||
parse_arguments(arguments, &mut parsed_arguments, |arg| {
|
parse_arguments(arguments, &mut parsed_arguments, |arg| {
|
||||||
parse_minecraft_argument(
|
parse_minecraft_argument(
|
||||||
arg,
|
arg,
|
||||||
&*credentials.access_token,
|
&credentials.access_token,
|
||||||
&*credentials.username,
|
&credentials.username,
|
||||||
&credentials.id,
|
&credentials.id,
|
||||||
version,
|
version,
|
||||||
asset_index_name,
|
asset_index_name,
|
||||||
@@ -212,8 +204,8 @@ pub fn get_minecraft_arguments(
|
|||||||
} else if let Some(legacy_arguments) = legacy_arguments {
|
} else if let Some(legacy_arguments) = legacy_arguments {
|
||||||
Ok(parse_minecraft_argument(
|
Ok(parse_minecraft_argument(
|
||||||
legacy_arguments,
|
legacy_arguments,
|
||||||
&*credentials.access_token,
|
&credentials.access_token,
|
||||||
&*credentials.username,
|
&credentials.username,
|
||||||
&credentials.id,
|
&credentials.id,
|
||||||
version,
|
version,
|
||||||
asset_index_name,
|
asset_index_name,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ fn get_loader_version(loader: ModLoader, version: &str) -> ModpackResult<String>
|
|||||||
}?;
|
}?;
|
||||||
let manifest = futures::executor::block_on(daedalus::modded::fetch_manifest(&source))?;
|
let manifest = futures::executor::block_on(daedalus::modded::fetch_manifest(&source))?;
|
||||||
|
|
||||||
Ok(manifest
|
let version = manifest
|
||||||
.game_versions
|
.game_versions
|
||||||
.iter()
|
.iter()
|
||||||
.find(|&it| it.id == version)
|
.find(|&it| it.id == version)
|
||||||
@@ -63,8 +63,8 @@ fn get_loader_version(loader: ModLoader, version: &str) -> ModpackResult<String>
|
|||||||
ModpackError::VersionError(format!(
|
ModpackError::VersionError(format!(
|
||||||
"No versions of modloader {loader:?} exist for Minecraft {version}",
|
"No versions of modloader {loader:?} exist for Minecraft {version}",
|
||||||
))
|
))
|
||||||
})?
|
})?;
|
||||||
.id)
|
Ok(version.id.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<pack::Modpack> for Manifest {
|
impl TryFrom<pack::Modpack> for Manifest {
|
||||||
@@ -79,20 +79,20 @@ impl TryFrom<pack::Modpack> for Manifest {
|
|||||||
files,
|
files,
|
||||||
} = pack;
|
} = pack;
|
||||||
|
|
||||||
let game = match game {
|
let game_name = match &game {
|
||||||
ModpackGame::Minecraft(..) => "minecraft".into(),
|
ModpackGame::Minecraft(..) => "minecraft".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let files: Vec<_> = pack.files.into_iter().map(ManifestFile::from).collect();
|
let files: Vec<_> = files.into_iter().map(ManifestFile::from).collect();
|
||||||
|
|
||||||
Ok(Manifest {
|
Ok(Manifest {
|
||||||
format_version: DEFAULT_FORMAT_VERSION,
|
format_version: DEFAULT_FORMAT_VERSION,
|
||||||
game,
|
game: game_name,
|
||||||
version_id: version,
|
version_id: version,
|
||||||
name,
|
name,
|
||||||
summary,
|
summary,
|
||||||
files,
|
files,
|
||||||
dependencies: ManifestDeps::try_from(pack.game)?,
|
dependencies: ManifestDeps::try_from(game)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,12 +240,12 @@ impl TryFrom<pack::ModpackGame> for ManifestDeps {
|
|||||||
Ok(match game {
|
Ok(match game {
|
||||||
Minecraft(minecraft, ModLoader::Vanilla) => Self::MinecraftVanilla { minecraft },
|
Minecraft(minecraft, ModLoader::Vanilla) => Self::MinecraftVanilla { minecraft },
|
||||||
Minecraft(minecraft, ModLoader::Fabric) => Self::MinecraftFabric {
|
Minecraft(minecraft, ModLoader::Fabric) => Self::MinecraftFabric {
|
||||||
minecraft,
|
|
||||||
fabric_loader: get_loader_version(ModLoader::Fabric, &minecraft)?,
|
fabric_loader: get_loader_version(ModLoader::Fabric, &minecraft)?,
|
||||||
|
minecraft,
|
||||||
},
|
},
|
||||||
Minecraft(minecraft, ModLoader::Forge) => Self::MinecraftForge {
|
Minecraft(minecraft, ModLoader::Forge) => Self::MinecraftForge {
|
||||||
minecraft,
|
|
||||||
forge: get_loader_version(ModLoader::Fabric, &minecraft)?,
|
forge: get_loader_version(ModLoader::Fabric, &minecraft)?,
|
||||||
|
minecraft,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ pub struct Modpack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Modpack {
|
impl Modpack {
|
||||||
|
pub fn new(game: ModpackGame, version: &str, name: &str, summary: Option<&str>) -> Self {
|
||||||
|
Self {
|
||||||
|
game,
|
||||||
|
version: String::from(version),
|
||||||
|
name: String::from(name),
|
||||||
|
summary: summary.map(String::from),
|
||||||
|
files: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Download a modpack's files for a given side to a given destination
|
/// Download a modpack's files for a given side to a given destination
|
||||||
/// Assumes the destination exists and is a directory
|
/// Assumes the destination exists and is a directory
|
||||||
pub async fn download_files(&self, dest: &Path, side: ModpackSide) -> ModpackResult<()> {
|
pub async fn download_files(&self, dest: &Path, side: ModpackSide) -> ModpackResult<()> {
|
||||||
@@ -49,16 +59,6 @@ impl Modpack {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(game: ModpackGame, version: &str, name: &str, summary: Option<&str>) -> Self {
|
|
||||||
Self {
|
|
||||||
game,
|
|
||||||
version: String::from(version),
|
|
||||||
name: String::from(name),
|
|
||||||
summary: summary.map(String::from),
|
|
||||||
files: HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn add_project(
|
pub async fn add_project(
|
||||||
&mut self,
|
&mut self,
|
||||||
project: &str,
|
project: &str,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::{env, io};
|
|||||||
|
|
||||||
use path_clean::PathClean;
|
use path_clean::PathClean;
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/54817755
|
||||||
pub fn absolute_path(path: impl AsRef<Path>) -> io::Result<PathBuf> {
|
pub fn absolute_path(path: impl AsRef<Path>) -> io::Result<PathBuf> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user