Skip to content

Commit

Permalink
assets downloading + gh actions cache
Browse files Browse the repository at this point in the history
  • Loading branch information
DerCommander323 committed Nov 18, 2023
1 parent 7065957 commit 81f79f4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
- name: Install frontend dependencies
run: pnpm install

- name: Setup rust build cache
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri

- name: Install Tauri-CLI
run: cargo install tauri-cli

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ async fn download_file(client: &Client, path: &PathBuf, url: &String) {
pub fn get_data_dir() -> PathBuf { data_dir().unwrap().join("yamcl") }
pub fn get_client_jar_dir() -> PathBuf { get_data_dir().join("client_jars") }
pub fn get_library_dir() -> PathBuf { get_data_dir().join("libraries") }
pub fn get_assets_dir() -> PathBuf { get_data_dir().join("assets") }
pub fn get_log4j_dir() -> PathBuf { get_data_dir().join("log4j_configs") }
2 changes: 1 addition & 1 deletion src-tauri/src/minecraft/launching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ async fn parse_arguments(args_struct: Args, account: MCAccount, version: MCExten
("${user_properties}", "something".to_string()),

("${classpath}", version.get_classpath(client).await),
("${assets_root}", version.get_client_assets(client).await),
("${version_name}", version.id.replace(' ', "_").replace(':', "_")),
("${assets_index_name}", version.asset_index.id),
("${assets_root}", "/home/der/.local/share/PrismLauncher/assets".to_string()),
("${version_type}", version.typ),

("${natives_directory}", format!("{minecraft_path}/natives")),
Expand Down
40 changes: 38 additions & 2 deletions src-tauri/src/minecraft/versions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{iter, path::PathBuf};
use std::{iter, path::PathBuf, collections::HashMap, fs};

use reqwest::Client;
use serde::{Serialize, Deserialize};

use crate::{get_client_jar_dir, download_file_checked, get_log4j_dir};
use crate::{get_client_jar_dir, download_file_checked, get_log4j_dir, get_assets_dir};

use super::libraries::{MCLibrary, MCRule};

Expand Down Expand Up @@ -154,6 +154,31 @@ impl MCExtendedVersion {
Some((logging.client.argument.to_string(), path))
} else { None }
}

pub async fn get_client_assets(&self, client: &Client) -> String {
let assets_dir = get_assets_dir();
let index_path = &assets_dir.join("indexes").join(format!("{}.json", &self.asset_index.id));
download_file_checked(
client,
&self.asset_index.sha1,
index_path,
&self.asset_index.url
).await;

let file = fs::read_to_string(index_path).unwrap();
let index: AssetIndexFile = serde_json::from_str(&file).unwrap();

for asset in index.objects {
let url = format!("https://resources.download.minecraft.net/{}/{}", &asset.1.hash[..2], asset.1.hash);
download_file_checked(
client,
&asset.1.hash,
&assets_dir.join("objects").join(&asset.1.hash[..2]).join(&asset.1.hash),
&url
).await;
}
assets_dir.to_string_lossy().to_string()
}
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -293,4 +318,15 @@ pub struct MCLoggingClientFile {
size: u64,
url: String,
sha1: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AssetIndexFile {
objects: HashMap<String, MCAsset>
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MCAsset {
hash: String,
size: u32
}

0 comments on commit 81f79f4

Please sign in to comment.