Refactored directory system
This commit is contained in:
@@ -4,7 +4,7 @@ use serde::Deserialize;
|
||||
use tauri::{AppHandle, Emitter, State};
|
||||
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)]
|
||||
struct ModrinthVersion {
|
||||
@@ -25,12 +25,12 @@ struct ModrinthFile {
|
||||
pub async fn get_installed_mods(version_id: String) -> Result<Vec<Mod>, String> {
|
||||
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 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
|
||||
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]
|
||||
pub async fn remove_mod(version: String, file_name: String) -> Result<(), String> {
|
||||
// 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
|
||||
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]
|
||||
pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> {
|
||||
// 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
|
||||
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]
|
||||
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");
|
||||
|
||||
@@ -181,7 +181,7 @@ pub async fn install_mod(mut mod_meta: Mod, versions: Vec<String>) -> Result<(),
|
||||
|
||||
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)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
@@ -228,7 +228,7 @@ pub async fn install_mod(mut mod_meta: Mod, versions: Vec<String>) -> Result<(),
|
||||
.await
|
||||
.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())?;
|
||||
|
||||
@@ -304,7 +304,7 @@ pub async fn install_paths(
|
||||
.and_then(|name| name.to_str())
|
||||
.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") {
|
||||
"mods"
|
||||
|
||||
@@ -5,10 +5,10 @@ use tauri::{command, AppHandle, Emitter, Manager, Url};
|
||||
|
||||
use lyceris::auth::microsoft::{authenticate, create_link, refresh, validate, MinecraftAccount};
|
||||
|
||||
use crate::launcher::LAUNCHER_DIR;
|
||||
use crate::launcher::launcher_dir;
|
||||
|
||||
fn accounts_path() -> PathBuf {
|
||||
LAUNCHER_DIR.data_dir().join("accounts.json")
|
||||
launcher_dir().join("accounts.json")
|
||||
}
|
||||
|
||||
fn load_accounts() -> Vec<MinecraftAccount> {
|
||||
@@ -52,30 +52,31 @@ pub fn auth_create_link(app: AppHandle) -> Result<String, String> {
|
||||
|
||||
std::thread::spawn(move || {
|
||||
tauri::WebviewWindowBuilder::new(&app, "auth", tauri::WebviewUrl::External(url))
|
||||
.title("Microsoft Login")
|
||||
.inner_size(500.0, 700.0)
|
||||
.resizable(false)
|
||||
.on_navigation(move |nav_url| {
|
||||
let url_str = nav_url.to_string();
|
||||
.title("Microsoft Login")
|
||||
.inner_size(500.0, 700.0)
|
||||
.resizable(false)
|
||||
.on_navigation(move |nav_url| {
|
||||
let url_str = nav_url.to_string();
|
||||
|
||||
// Check for auth code
|
||||
if url_str.contains("code=") {
|
||||
if let Some(code) = extract_code(&url_str) {
|
||||
println!("Auth code received: {}", code);
|
||||
// Check for auth code
|
||||
if url_str.contains("code=") {
|
||||
if let Some(code) = extract_code(&url_str) {
|
||||
println!("Auth code received: {}", code);
|
||||
|
||||
let _ = app_handle.emit("auth-code", code);
|
||||
let _ = app_handle.emit("auth-code", code);
|
||||
|
||||
if let Some(win) = app_handle.get_webview_window("auth") {
|
||||
let _ = win.close();
|
||||
if let Some(win) = app_handle.get_webview_window("auth") {
|
||||
let _ = win.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Always allow navigation
|
||||
true
|
||||
})
|
||||
.build()
|
||||
.map_err(|e| e.to_string()).unwrap();
|
||||
// Always allow navigation
|
||||
true
|
||||
})
|
||||
.build()
|
||||
.map_err(|e| e.to_string())
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
Ok(link)
|
||||
|
||||
@@ -2,7 +2,8 @@ pub mod auth;
|
||||
pub mod downloader;
|
||||
pub mod install;
|
||||
|
||||
use directories::ProjectDirs;
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use lyceris::{
|
||||
auth::microsoft::MinecraftAccount,
|
||||
minecraft::{
|
||||
@@ -12,15 +13,35 @@ use lyceris::{
|
||||
loader::fabric::Fabric,
|
||||
},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use tauri::{Emitter as _, State};
|
||||
|
||||
use crate::{GameVersion, SharedState};
|
||||
|
||||
pub static LAUNCHER_DIR: Lazy<ProjectDirs> = Lazy::new(|| {
|
||||
ProjectDirs::from("org", "SaturnLauncher", "SaturnLauncher")
|
||||
.expect("Failed to create project directories")
|
||||
});
|
||||
pub fn launcher_dir() -> PathBuf {
|
||||
if cfg!(target_os = "macos") {
|
||||
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]
|
||||
pub async fn launch_game(
|
||||
@@ -70,10 +91,8 @@ pub async fn launch_game(
|
||||
})
|
||||
.await;
|
||||
|
||||
let current_dir = LAUNCHER_DIR.data_dir();
|
||||
|
||||
let config = ConfigBuilder::new(
|
||||
current_dir.join(&version.id),
|
||||
launcher_dir().join(&version.id),
|
||||
version.id.clone(),
|
||||
lyceris::auth::AuthMethod::Microsoft {
|
||||
username: account.username,
|
||||
|
||||
@@ -2,9 +2,13 @@ pub mod commands;
|
||||
pub mod launcher;
|
||||
|
||||
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>>;
|
||||
|
||||
@@ -51,7 +55,7 @@ impl Default for AppState {
|
||||
|
||||
// Helper to get config path
|
||||
fn config_path() -> PathBuf {
|
||||
LAUNCHER_DIR.config_dir().join("launcher.json")
|
||||
launcher_dir().join("launcher.json")
|
||||
}
|
||||
|
||||
// --- Load ---
|
||||
@@ -101,4 +105,3 @@ pub fn save_state(state: &SharedState) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user