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 rand::{thread_rng, Rng};
|
||||||
use reqwest::{header::{CONTENT_TYPE, CONNECTION, ACCEPT, AUTHORIZATION}, Client};
|
use reqwest::{header::{CONTENT_TYPE, CONNECTION, ACCEPT, AUTHORIZATION}, Client};
|
||||||
use serde_json::{Value, json};
|
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 tokio::{sync::mpsc, join};
|
||||||
use urlencoding::encode;
|
use urlencoding::encode;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -49,7 +49,9 @@ pub struct VersionDetail {
|
|||||||
arguments: Map<String, Value>,
|
arguments: Map<String, Value>,
|
||||||
#[serde(rename(serialize = "assetIndex", deserialize = "assetIndex"))]
|
#[serde(rename(serialize = "assetIndex", deserialize = "assetIndex"))]
|
||||||
pub asset_index: AssetIndex,
|
pub asset_index: AssetIndex,
|
||||||
assets: String,
|
pub assets: String,
|
||||||
|
#[serde(rename(serialize = "complianceLevel", deserialize = "complianceLevel"))]
|
||||||
|
compliance_level: i32,
|
||||||
downloads: Map<String, Value>,
|
downloads: Map<String, Value>,
|
||||||
id: String,
|
id: String,
|
||||||
#[serde(rename(serialize = "javaVersion", deserialize = "javaVersion"))]
|
#[serde(rename(serialize = "javaVersion", deserialize = "javaVersion"))]
|
||||||
|
@ -68,21 +68,48 @@ impl<'a> MinecraftClient<'_> {
|
|||||||
Ok((details, version_assets))
|
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<()> {
|
pub async fn download_requirements(&mut self) -> Result<()> {
|
||||||
// create root folder if it doesn't exist
|
// create root folder if it doesn't exist
|
||||||
if !self.opts.root_path.exists() {
|
self.create_dirs().await?;
|
||||||
fs::create_dir_all(self.opts.root_path).await?;
|
|
||||||
}
|
|
||||||
let lib = &self.opts.root_path.join("libraries");
|
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");
|
let asset = &self.opts.root_path.join("assets").join("objects");
|
||||||
if !asset.exists() {
|
self.save_version_index().await?;
|
||||||
fs::create_dir_all(asset).await?;
|
|
||||||
}
|
|
||||||
self.download_libraries(lib).await?;
|
self.download_libraries(lib).await?;
|
||||||
self.download_assets(asset).await?;
|
self.download_assets(asset).await?;
|
||||||
|
self.opts.log_channel.send(ProgressMessage { p_type: "completed".to_string(), current: 0, total: 0 }).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +231,10 @@ impl<'a> MinecraftClient<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn launch_game(&self) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user