Skip to content

Commit

Permalink
Bump Theseus Version (#818)
Browse files Browse the repository at this point in the history
* push to test on windows

* Fix windows sup

* Fix macos

* Fix back

* new resolver for windows testing

* Custom macos handling for some versions

* Fix 1.13+ broken

* fix arg parsing mac

* small winblows fix

* remove debug info; set meta url

* run lint + fix clippy

* Remove useless commnet
  • Loading branch information
Geometrically committed Oct 21, 2023
1 parent 7fb8850 commit afaec4b
Show file tree
Hide file tree
Showing 27 changed files with 189 additions and 97 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion theseus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "theseus"
version = "0.5.4"
version = "0.6.0"
authors = ["Jai A <[email protected]>"]
edition = "2018"

Expand Down
12 changes: 8 additions & 4 deletions theseus/src/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ pub async fn refresh(user: uuid::Uuid) -> crate::Result<Credentials> {
}

// Update player info from bearer token
let player_info = hydra::stages::player_info::fetch_info(&credentials.access_token).await.map_err(|_err| {
crate::ErrorKind::HydraError("No Minecraft account for your profile. Make sure you own the game and have set a username through the official Minecraft launcher."
.to_string())
})?;
let player_info =
hydra::stages::player_info::fetch_info(&credentials.access_token)
.await
.map_err(|_err| {
crate::ErrorKind::HydraError(
"No Minecraft account for your profile. Please try again or contact support in our Discord for help!".to_string(),
)
})?;

credentials.username = player_info.name;
users.insert(&credentials).await?;
Expand Down
2 changes: 1 addition & 1 deletion theseus/src/api/hydra/stages/player_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Default for PlayerInfo {
fn default() -> Self {
Self {
id: "606e2ff0ed7748429d6ce1d3321c7838".to_string(),
name: String::from("???"),
name: String::from("Unknown"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion theseus/src/api/jre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub async fn auto_install_java(java_version: u32) -> crate::Result<PathBuf> {

// removes the old installation of java
if let Some(file) = archive.file_names().next() {
if let Some(dir) = file.split("/").next() {
if let Some(dir) = file.split('/').next() {
let path = path.join(dir);

if path.exists() {
Expand Down
8 changes: 6 additions & 2 deletions theseus/src/api/pack/import/atlauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ async fn import_atlauncher_unmanaged(
if let Some(profile_val) =
crate::api::profile::get(&profile_path, None).await?
{
crate::launcher::install_minecraft(&profile_val, Some(loading_bar))
.await?;
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
false,
)
.await?;
{
let state = State::get().await?;
let mut file_watcher = state.file_watcher.write().await;
Expand Down
8 changes: 6 additions & 2 deletions theseus/src/api/pack/import/curseforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ pub async fn import_curseforge(
if let Some(profile_val) =
crate::api::profile::get(&profile_path, None).await?
{
crate::launcher::install_minecraft(&profile_val, Some(loading_bar))
.await?;
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
false,
)
.await?;

{
let state = State::get().await?;
Expand Down
8 changes: 6 additions & 2 deletions theseus/src/api/pack/import/gdlauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ pub async fn import_gdlauncher(
if let Some(profile_val) =
crate::api::profile::get(&profile_path, None).await?
{
crate::launcher::install_minecraft(&profile_val, Some(loading_bar))
.await?;
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
false,
)
.await?;
{
let state = State::get().await?;
let mut file_watcher = state.file_watcher.write().await;
Expand Down
8 changes: 6 additions & 2 deletions theseus/src/api/pack/import/mmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ async fn import_mmc_unmanaged(
if let Some(profile_val) =
crate::api::profile::get(&profile_path, None).await?
{
crate::launcher::install_minecraft(&profile_val, Some(loading_bar))
.await?;
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
false,
)
.await?;
{
let state = State::get().await?;
let mut file_watcher = state.file_watcher.write().await;
Expand Down
8 changes: 6 additions & 2 deletions theseus/src/api/pack/install_mrpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@ pub async fn install_zipped_mrpack_files(
}

if let Some(profile_val) = profile::get(&profile_path, None).await? {
crate::launcher::install_minecraft(&profile_val, Some(loading_bar))
.await?;
crate::launcher::install_minecraft(
&profile_val,
Some(loading_bar),
false,
)
.await?;

State::sync().await?;
}
Expand Down
5 changes: 3 additions & 2 deletions theseus/src/api/profile/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn profile_create(
}

if !skip_install_profile.unwrap_or(false) {
crate::launcher::install_minecraft(&profile, None).await?;
crate::launcher::install_minecraft(&profile, None, false).await?;
}
State::sync().await?;

Expand Down Expand Up @@ -196,7 +196,8 @@ pub async fn profile_create_from_duplicate(
ErrorKind::UnmanagedProfileError(profile_path_id.to_string())
})?;

crate::launcher::install_minecraft(&duplicated_profile, Some(bar)).await?;
crate::launcher::install_minecraft(&duplicated_profile, Some(bar), false)
.await?;
{
let state = State::get().await?;
let mut file_watcher = state.file_watcher.write().await;
Expand Down
4 changes: 2 additions & 2 deletions theseus/src/api/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ pub async fn list(

/// Installs/Repairs a profile
#[tracing::instrument]
pub async fn install(path: &ProfilePathId) -> crate::Result<()> {
pub async fn install(path: &ProfilePathId, force: bool) -> crate::Result<()> {
if let Some(profile) = get(path, None).await? {
crate::launcher::install_minecraft(&profile, None).await?;
crate::launcher::install_minecraft(&profile, None, force).await?;
} else {
return Err(crate::ErrorKind::UnmanagedProfileError(path.to_string())
.as_error());
Expand Down
9 changes: 5 additions & 4 deletions theseus/src/launcher/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Minecraft CLI argument logic
// TODO: Rafactor this section
use super::{auth::Credentials, parse_rule};
use super::auth::Credentials;
use crate::launcher::parse_rules;
use crate::{
state::{MemorySettings, WindowSize},
util::{io::IOError, platform::classpath_separator},
Expand All @@ -23,12 +23,13 @@ pub fn get_class_paths(
libraries: &[Library],
client_path: &Path,
java_arch: &str,
minecraft_updated: bool,
) -> crate::Result<String> {
let mut cps = libraries
.iter()
.filter_map(|library| {
if let Some(rules) = &library.rules {
if !rules.iter().any(|x| parse_rule(x, java_arch)) {
if !parse_rules(rules, java_arch, minecraft_updated) {
return None;
}
}
Expand Down Expand Up @@ -335,7 +336,7 @@ where
}
}
Argument::Ruled { rules, value } => {
if rules.iter().any(|x| parse_rule(x, java_arch)) {
if parse_rules(rules, java_arch, true) {
match value {
ArgumentValue::Single(arg) => {
parsed_arguments.push(parse_function(
Expand Down
36 changes: 23 additions & 13 deletions theseus/src/launcher/download.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Downloader for Minecraft data

use crate::launcher::parse_rules;
use crate::state::CredentialsStore;
use crate::{
event::{
Expand All @@ -26,11 +27,13 @@ pub async fn download_minecraft(
version: &GameVersionInfo,
loading_bar: &LoadingBarId,
java_arch: &str,
force: bool,
minecraft_updated: bool,
) -> crate::Result<()> {
tracing::info!("Downloading Minecraft version {}", version.id);
// 5
let assets_index =
download_assets_index(st, version, Some(loading_bar)).await?;
download_assets_index(st, version, Some(loading_bar), force).await?;

let amount = if version
.processors
Expand All @@ -45,9 +48,9 @@ pub async fn download_minecraft(

tokio::try_join! {
// Total loading sums to 90/60
download_client(st, version, Some(loading_bar)), // 10
download_assets(st, version.assets == "legacy", &assets_index, Some(loading_bar), amount), // 40
download_libraries(st, version.libraries.as_slice(), &version.id, Some(loading_bar), amount, java_arch) // 40
download_client(st, version, Some(loading_bar), force), // 10
download_assets(st, version.assets == "legacy", &assets_index, Some(loading_bar), amount, force), // 40
download_libraries(st, version.libraries.as_slice(), &version.id, Some(loading_bar), amount, java_arch, force, minecraft_updated) // 40
}?;

tracing::info!("Done downloading Minecraft!");
Expand Down Expand Up @@ -105,6 +108,7 @@ pub async fn download_client(
st: &State,
version_info: &GameVersionInfo,
loading_bar: Option<&LoadingBarId>,
force: bool,
) -> crate::Result<()> {
let version = &version_info.id;
tracing::debug!("Locating client for version {version}");
Expand All @@ -123,7 +127,7 @@ pub async fn download_client(
.await
.join(format!("{version}.jar"));

if !path.exists() {
if !path.exists() || force {
let bytes = fetch(
&client_download.url,
Some(&client_download.sha1),
Expand All @@ -148,6 +152,7 @@ pub async fn download_assets_index(
st: &State,
version: &GameVersionInfo,
loading_bar: Option<&LoadingBarId>,
force: bool,
) -> crate::Result<AssetsIndex> {
tracing::debug!("Loading assets index");
let path = st
Expand All @@ -156,7 +161,7 @@ pub async fn download_assets_index(
.await
.join(format!("{}.json", &version.asset_index.id));

let res = if path.exists() {
let res = if path.exists() && !force {
io::read(path)
.err_into::<crate::Error>()
.await
Expand All @@ -183,6 +188,7 @@ pub async fn download_assets(
index: &AssetsIndex,
loading_bar: Option<&LoadingBarId>,
loading_amount: f64,
force: bool,
) -> crate::Result<()> {
tracing::debug!("Loading assets");
let num_futs = index.objects.len();
Expand All @@ -206,7 +212,7 @@ pub async fn download_assets(
let fetch_cell = OnceCell::<bytes::Bytes>::new();
tokio::try_join! {
async {
if !resource_path.exists() {
if !resource_path.exists() || force {
let resource = fetch_cell
.get_or_try_init(|| fetch(&url, Some(hash), &st.fetch_semaphore, &CredentialsStore(None)))
.await?;
Expand All @@ -216,13 +222,14 @@ pub async fn download_assets(
Ok::<_, crate::Error>(())
},
async {
if with_legacy {
let resource_path = st.directories.legacy_assets_dir().await.join(
name.replace('/', &String::from(std::path::MAIN_SEPARATOR))
);

if with_legacy && !resource_path.exists() || force {
let resource = fetch_cell
.get_or_try_init(|| fetch(&url, Some(hash), &st.fetch_semaphore, &CredentialsStore(None)))
.await?;
let resource_path = st.directories.legacy_assets_dir().await.join(
name.replace('/', &String::from(std::path::MAIN_SEPARATOR))
);
write(&resource_path, resource, &st.io_semaphore).await?;
tracing::trace!("Fetched legacy asset with hash {hash}");
}
Expand All @@ -239,13 +246,16 @@ pub async fn download_assets(

#[tracing::instrument(skip(st, libraries))]
#[theseus_macros::debug_pin]
#[allow(clippy::too_many_arguments)]
pub async fn download_libraries(
st: &State,
libraries: &[Library],
version: &str,
loading_bar: Option<&LoadingBarId>,
loading_amount: f64,
java_arch: &str,
force: bool,
minecraft_updated: bool,
) -> crate::Result<()> {
tracing::debug!("Loading libraries");

Expand All @@ -258,7 +268,7 @@ pub async fn download_libraries(
stream::iter(libraries.iter())
.map(Ok::<&Library, crate::Error>), None, loading_bar,loading_amount,num_files, None,|library| async move {
if let Some(rules) = &library.rules {
if !rules.iter().any(|x| super::parse_rule(x, java_arch)) {
if !parse_rules(rules, java_arch, minecraft_updated) {
tracing::trace!("Skipped library {}", &library.name);
return Ok(());
}
Expand All @@ -270,7 +280,7 @@ pub async fn download_libraries(
let path = st.directories.libraries_dir().await.join(&artifact_path);

match library.downloads {
_ if path.exists() => Ok(()),
_ if path.exists() && !force => Ok(()),
Some(d::minecraft::LibraryDownloads {
artifact: Some(ref artifact),
..
Expand Down
Loading

0 comments on commit afaec4b

Please sign in to comment.