Refactored directory system
This commit is contained in:
Generated
-11
@@ -874,15 +874,6 @@ dependencies = [
|
|||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "directories"
|
|
||||||
version = "6.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d"
|
|
||||||
dependencies = [
|
|
||||||
"dirs-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "6.0.0"
|
version = "6.0.0"
|
||||||
@@ -3898,10 +3889,8 @@ dependencies = [
|
|||||||
name = "saturn-launcher"
|
name = "saturn-launcher"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"directories",
|
|
||||||
"futures",
|
"futures",
|
||||||
"lyceris",
|
"lyceris",
|
||||||
"once_cell",
|
|
||||||
"rayon",
|
"rayon",
|
||||||
"reqwest 0.12.28",
|
"reqwest 0.12.28",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ tauri = { version = "2", features = [] }
|
|||||||
tauri-plugin-opener = "2"
|
tauri-plugin-opener = "2"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
directories = "6.0"
|
|
||||||
once_cell = "1.21"
|
|
||||||
lyceris = "1.1.3"
|
lyceris = "1.1.3"
|
||||||
rayon = "1.10.0"
|
rayon = "1.10.0"
|
||||||
reqwest = "0.12.9"
|
reqwest = "0.12.9"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use serde::Deserialize;
|
|||||||
use tauri::{AppHandle, Emitter, State};
|
use tauri::{AppHandle, Emitter, State};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use crate::{launcher::LAUNCHER_DIR, save_state, LauncherSettings, Mod, SharedState};
|
use crate::{launcher::launcher_dir, save_state, LauncherSettings, Mod, SharedState};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ModrinthVersion {
|
struct ModrinthVersion {
|
||||||
@@ -25,12 +25,12 @@ struct ModrinthFile {
|
|||||||
pub async fn get_installed_mods(version_id: String) -> Result<Vec<Mod>, String> {
|
pub async fn get_installed_mods(version_id: String) -> Result<Vec<Mod>, String> {
|
||||||
let mut mods = Vec::new();
|
let mut mods = Vec::new();
|
||||||
|
|
||||||
let base_dir = LAUNCHER_DIR.data_dir().join(&version_id).join("mods");
|
let base_dir = launcher_dir().join(&version_id).join("mods");
|
||||||
|
|
||||||
let enabled_dir = base_dir.clone();
|
let enabled_dir = base_dir.clone();
|
||||||
let disabled_dir = base_dir.join("disabled_mods");
|
let disabled_dir = base_dir.join("disabled_mods");
|
||||||
|
|
||||||
let cache_dir = LAUNCHER_DIR.data_dir().join("cache");
|
let cache_dir = launcher_dir().join("cache");
|
||||||
|
|
||||||
// process a directory async
|
// process a directory async
|
||||||
async fn process_dir(dir: PathBuf, enabled: bool, cache_dir: PathBuf) -> Vec<Mod> {
|
async fn process_dir(dir: PathBuf, enabled: bool, cache_dir: PathBuf) -> Vec<Mod> {
|
||||||
@@ -108,7 +108,7 @@ fn fallback_mod(file_name: &str, enabled: bool) -> Mod {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn remove_mod(version: String, file_name: String) -> Result<(), String> {
|
pub async fn remove_mod(version: String, file_name: String) -> Result<(), String> {
|
||||||
// mods folder
|
// mods folder
|
||||||
let mods_dir: PathBuf = LAUNCHER_DIR.data_dir().join(&version).join("mods");
|
let mods_dir: PathBuf = launcher_dir().join(&version).join("mods");
|
||||||
|
|
||||||
// File to remove
|
// File to remove
|
||||||
let mut source = mods_dir.join(&file_name);
|
let mut source = mods_dir.join(&file_name);
|
||||||
@@ -130,7 +130,7 @@ pub async fn remove_mod(version: String, file_name: String) -> Result<(), String
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> {
|
pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> {
|
||||||
// mods folder
|
// mods folder
|
||||||
let mods_dir: PathBuf = LAUNCHER_DIR.data_dir().join(&version).join("mods");
|
let mods_dir: PathBuf = launcher_dir().join(&version).join("mods");
|
||||||
|
|
||||||
// disabled_mods folder
|
// disabled_mods folder
|
||||||
let disabled_dir = mods_dir.join("disabled_mods");
|
let disabled_dir = mods_dir.join("disabled_mods");
|
||||||
@@ -157,7 +157,7 @@ pub async fn disable_mod(version: String, file_name: String) -> Result<(), Strin
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn enable_mod(version: String, file_name: String) -> Result<(), String> {
|
pub async fn enable_mod(version: String, file_name: String) -> Result<(), String> {
|
||||||
let mods_dir = LAUNCHER_DIR.data_dir().join(&version).join("mods");
|
let mods_dir = launcher_dir().join(&version).join("mods");
|
||||||
|
|
||||||
let disabled_dir = mods_dir.join("disabled_mods");
|
let disabled_dir = mods_dir.join("disabled_mods");
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ pub async fn install_mod(mut mod_meta: Mod, versions: Vec<String>) -> Result<(),
|
|||||||
|
|
||||||
println!("Installing {} for {:?}", mod_meta.name, versions);
|
println!("Installing {} for {:?}", mod_meta.name, versions);
|
||||||
|
|
||||||
let cache_dir = LAUNCHER_DIR.data_dir().join("cache");
|
let cache_dir = launcher_dir().join("cache");
|
||||||
fs::create_dir_all(&cache_dir)
|
fs::create_dir_all(&cache_dir)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
@@ -228,7 +228,7 @@ pub async fn install_mod(mut mod_meta: Mod, versions: Vec<String>) -> Result<(),
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let dir: PathBuf = LAUNCHER_DIR.data_dir().join(&mc_version).join("mods");
|
let dir: PathBuf = launcher_dir().join(&mc_version).join("mods");
|
||||||
|
|
||||||
fs::create_dir_all(&dir).await.map_err(|e| e.to_string())?;
|
fs::create_dir_all(&dir).await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ pub async fn install_paths(
|
|||||||
.and_then(|name| name.to_str())
|
.and_then(|name| name.to_str())
|
||||||
.ok_or_else(|| String::from("File name not found"))?;
|
.ok_or_else(|| String::from("File name not found"))?;
|
||||||
|
|
||||||
let version_dir = LAUNCHER_DIR.data_dir().join(&state.lock().unwrap().version);
|
let version_dir = launcher_dir().join(&state.lock().unwrap().version);
|
||||||
|
|
||||||
let mc_child = if path.ends_with(".jar") {
|
let mc_child = if path.ends_with(".jar") {
|
||||||
"mods"
|
"mods"
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ use tauri::{command, AppHandle, Emitter, Manager, Url};
|
|||||||
|
|
||||||
use lyceris::auth::microsoft::{authenticate, create_link, refresh, validate, MinecraftAccount};
|
use lyceris::auth::microsoft::{authenticate, create_link, refresh, validate, MinecraftAccount};
|
||||||
|
|
||||||
use crate::launcher::LAUNCHER_DIR;
|
use crate::launcher::launcher_dir;
|
||||||
|
|
||||||
fn accounts_path() -> PathBuf {
|
fn accounts_path() -> PathBuf {
|
||||||
LAUNCHER_DIR.data_dir().join("accounts.json")
|
launcher_dir().join("accounts.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_accounts() -> Vec<MinecraftAccount> {
|
fn load_accounts() -> Vec<MinecraftAccount> {
|
||||||
@@ -75,7 +75,8 @@ pub fn auth_create_link(app: AppHandle) -> Result<String, String> {
|
|||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| e.to_string()).unwrap();
|
.map_err(|e| e.to_string())
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(link)
|
Ok(link)
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ pub mod auth;
|
|||||||
pub mod downloader;
|
pub mod downloader;
|
||||||
pub mod install;
|
pub mod install;
|
||||||
|
|
||||||
use directories::ProjectDirs;
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use lyceris::{
|
use lyceris::{
|
||||||
auth::microsoft::MinecraftAccount,
|
auth::microsoft::MinecraftAccount,
|
||||||
minecraft::{
|
minecraft::{
|
||||||
@@ -12,15 +13,35 @@ use lyceris::{
|
|||||||
loader::fabric::Fabric,
|
loader::fabric::Fabric,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use tauri::{Emitter as _, State};
|
use tauri::{Emitter as _, State};
|
||||||
|
|
||||||
use crate::{GameVersion, SharedState};
|
use crate::{GameVersion, SharedState};
|
||||||
|
|
||||||
pub static LAUNCHER_DIR: Lazy<ProjectDirs> = Lazy::new(|| {
|
pub fn launcher_dir() -> PathBuf {
|
||||||
ProjectDirs::from("org", "SaturnLauncher", "SaturnLauncher")
|
if cfg!(target_os = "macos") {
|
||||||
.expect("Failed to create project directories")
|
let home = env::var("HOME")
|
||||||
});
|
.map(PathBuf::from)
|
||||||
|
.expect("HOME environment variable not set");
|
||||||
|
|
||||||
|
home.join("Library/Application Support/SaturnLauncher")
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
env::var("APPDATA")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| PathBuf::from("."))
|
||||||
|
.join("SaturnLauncher")
|
||||||
|
} else {
|
||||||
|
env::var("XDG_DATA_HOME")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| {
|
||||||
|
env::var("HOME")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| PathBuf::from("."))
|
||||||
|
.join(".local/share")
|
||||||
|
})
|
||||||
|
.join("SaturnLauncher")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn launch_game(
|
pub async fn launch_game(
|
||||||
@@ -70,10 +91,8 @@ pub async fn launch_game(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let current_dir = LAUNCHER_DIR.data_dir();
|
|
||||||
|
|
||||||
let config = ConfigBuilder::new(
|
let config = ConfigBuilder::new(
|
||||||
current_dir.join(&version.id),
|
launcher_dir().join(&version.id),
|
||||||
version.id.clone(),
|
version.id.clone(),
|
||||||
lyceris::auth::AuthMethod::Microsoft {
|
lyceris::auth::AuthMethod::Microsoft {
|
||||||
username: account.username,
|
username: account.username,
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ pub mod commands;
|
|||||||
pub mod launcher;
|
pub mod launcher;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fs, path::PathBuf, sync::{Arc, Mutex}};
|
use std::{
|
||||||
|
fs,
|
||||||
|
path::PathBuf,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::launcher::LAUNCHER_DIR;
|
use crate::launcher::launcher_dir;
|
||||||
|
|
||||||
pub type SharedState = Arc<Mutex<AppState>>;
|
pub type SharedState = Arc<Mutex<AppState>>;
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ impl Default for AppState {
|
|||||||
|
|
||||||
// Helper to get config path
|
// Helper to get config path
|
||||||
fn config_path() -> PathBuf {
|
fn config_path() -> PathBuf {
|
||||||
LAUNCHER_DIR.config_dir().join("launcher.json")
|
launcher_dir().join("launcher.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Load ---
|
// --- Load ---
|
||||||
@@ -101,4 +105,3 @@ pub fn save_state(state: &SharedState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user