Save version index in the right folder
This commit is contained in:
parent
cdbf1bdcef
commit
201bad4074
1732
src-tauri/Cargo.lock
generated
1732
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@ use std::{fmt, net::TcpListener, sync::Arc};
|
||||
use rand::{thread_rng, Rng};
|
||||
use reqwest::{header::{CONTENT_TYPE, CONNECTION, ACCEPT, AUTHORIZATION}, Client};
|
||||
use serde_json::{Value, json};
|
||||
use tauri::{WindowEvent, async_runtime::{spawn_blocking}};
|
||||
use tauri::{WindowEvent, async_runtime::spawn_blocking};
|
||||
use tokio::{sync::mpsc, join};
|
||||
use urlencoding::encode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -49,7 +49,9 @@ pub struct VersionDetail {
|
||||
arguments: Map<String, Value>,
|
||||
#[serde(rename(serialize = "assetIndex", deserialize = "assetIndex"))]
|
||||
pub asset_index: AssetIndex,
|
||||
assets: String,
|
||||
pub assets: String,
|
||||
#[serde(rename(serialize = "complianceLevel", deserialize = "complianceLevel"))]
|
||||
compliance_level: i32,
|
||||
downloads: Map<String, Value>,
|
||||
id: String,
|
||||
#[serde(rename(serialize = "javaVersion", deserialize = "javaVersion"))]
|
||||
|
@ -67,22 +67,49 @@ impl<'a> MinecraftClient<'_> {
|
||||
let version_assets = get_version_assets(reqwest_client, &details.asset_index).await?;
|
||||
Ok((details, version_assets))
|
||||
}
|
||||
|
||||
async fn create_dirs(&self) -> Result<()> {
|
||||
let folders = vec![
|
||||
self.opts.root_path.join("libraries"),
|
||||
self.opts.root_path.join("assets").join("objects"),
|
||||
self.opts.root_path.join("assets").join("indexes")
|
||||
];
|
||||
let mut tasks = Vec::with_capacity(folders.len());
|
||||
for folder in folders {
|
||||
if !folder.exists() {
|
||||
tasks.push(tokio::spawn(async { fs::create_dir(folder).await }));
|
||||
}
|
||||
}
|
||||
for task in tasks {
|
||||
let _ = task.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn save_version_index(&self) -> Result<()> {
|
||||
let indexes = &self.opts.root_path.join("assets").join("indexes");
|
||||
let mut filename = self.details.assets.clone();
|
||||
filename.push_str(".json");
|
||||
let filepath = indexes.join(filename);
|
||||
let file = File::create(filepath).await;
|
||||
match file {
|
||||
Ok(mut f) => {
|
||||
f.write_all(serde_json::to_string(&self.details)?.as_bytes()).await?;
|
||||
Ok(())
|
||||
},
|
||||
Err(err) => bail!(err),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn download_requirements(&mut self) -> Result<()> {
|
||||
// create root folder if it doesn't exist
|
||||
if !self.opts.root_path.exists() {
|
||||
fs::create_dir_all(self.opts.root_path).await?;
|
||||
}
|
||||
self.create_dirs().await?;
|
||||
let lib = &self.opts.root_path.join("libraries");
|
||||
if !lib.exists() {
|
||||
fs::create_dir(lib).await?;
|
||||
}
|
||||
let asset = &self.opts.root_path.join("assets").join("objects");
|
||||
if !asset.exists() {
|
||||
fs::create_dir_all(asset).await?;
|
||||
}
|
||||
self.save_version_index().await?;
|
||||
self.download_libraries(lib).await?;
|
||||
self.download_assets(asset).await?;
|
||||
self.opts.log_channel.send(ProgressMessage { p_type: "completed".to_string(), current: 0, total: 0 }).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -203,6 +230,10 @@ impl<'a> MinecraftClient<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn launch_game(&self) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user