Files
AstralRinth/theseus/src/state/dirs.rs
Wyatt Verchere 91d3bf825d Misc settings (#137)
* Initial bug fixes

* fix compile error on non-mac

* Fix even more bugs

* Fix more

* fix more

* fix build

* fix build

* Search fixes

* Fix small instance ui

* working basic

* fix javaw issue

* removed zip

* working functions

* merge fixes

* fixed loadintg bar bug

* menu fix

* wait for settings to sync

* safety expanded and for loading bars

* swtiching to windows

* minimize

* default landing page

* test link registry

* url redirection

* fix formatting

* .mrpack windows

* working mrpack reader

* changed to one layer deep

* working .mrpack + command handling for both opening and existing process

* forge version numbers

* working mac opening mrpack

* reverted changes

* prettier/fmt

* missed debug statement

* improvements + refactoring

* renamed things to fit plugin

* fixed bugs

* removed println

* overrides dont include mrpack

* merge

* fixes

* fixes

* fixed deletion

* merge errors

* force sync before export

* removed testing

* missed line

* removed console log

* mac error reverted

* incoreclty named helper

* additional fixes

* added removed merges

* fixed mislabled invokes

* mac

* added to new register method

* comments, cleanup

* mac clippy change

* review changes

* minor changes

* moved create pack

* removed playground compilation bug

* fixed linux bug; other add ons

* fixed review commets

* cicd fix

* mistaken import for prod

* cicd fix

---------

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
2023-06-30 08:11:32 -07:00

167 lines
4.5 KiB
Rust

//! Theseus directory information
use std::fs;
use std::path::PathBuf;
#[derive(Debug)]
pub struct DirectoryInfo {
pub config_dir: PathBuf,
pub working_dir: PathBuf,
}
impl DirectoryInfo {
/// Get all paths needed for Theseus to operate properly
#[tracing::instrument]
pub fn init() -> crate::Result<Self> {
// Working directory
let working_dir = std::env::current_dir().map_err(|err| {
crate::ErrorKind::FSError(format!(
"Could not open working directory: {err}"
))
})?;
// Config directory
let config_dir = Self::env_path("THESEUS_CONFIG_DIR")
.or_else(|| Some(dirs::config_dir()?.join("com.modrinth.theseus")))
.ok_or(crate::ErrorKind::FSError(
"Could not find valid config dir".to_string(),
))?;
fs::create_dir_all(&config_dir).map_err(|err| {
crate::ErrorKind::FSError(format!(
"Error creating Theseus config directory: {err}"
))
})?;
Ok(Self {
config_dir,
working_dir,
})
}
/// Get the Minecraft instance metadata directory
#[inline]
pub fn metadata_dir(&self) -> PathBuf {
self.config_dir.join("meta")
}
/// Get the Minecraft java versions metadata directory
#[inline]
pub fn java_versions_dir(&self) -> PathBuf {
self.metadata_dir().join("java_versions")
}
/// Get the Minecraft versions metadata directory
#[inline]
pub fn versions_dir(&self) -> PathBuf {
self.metadata_dir().join("versions")
}
/// Get the metadata directory for a given version
#[inline]
pub fn version_dir(&self, version: &str) -> PathBuf {
self.versions_dir().join(version)
}
/// Get the Minecraft libraries metadata directory
#[inline]
pub fn libraries_dir(&self) -> PathBuf {
self.metadata_dir().join("libraries")
}
/// Get the Minecraft assets metadata directory
#[inline]
pub fn assets_dir(&self) -> PathBuf {
self.metadata_dir().join("assets")
}
/// Get the assets index directory
#[inline]
pub fn assets_index_dir(&self) -> PathBuf {
self.assets_dir().join("indexes")
}
/// Get the assets objects directory
#[inline]
pub fn objects_dir(&self) -> PathBuf {
self.assets_dir().join("objects")
}
/// Get the directory for a specific object
#[inline]
pub fn object_dir(&self, hash: &str) -> PathBuf {
self.objects_dir().join(&hash[..2]).join(hash)
}
/// Get the Minecraft legacy assets metadata directory
#[inline]
pub fn legacy_assets_dir(&self) -> PathBuf {
self.metadata_dir().join("resources")
}
/// Get the Minecraft legacy assets metadata directory
#[inline]
pub fn natives_dir(&self) -> PathBuf {
self.metadata_dir().join("natives")
}
/// Get the natives directory for a version of Minecraft
#[inline]
pub fn version_natives_dir(&self, version: &str) -> PathBuf {
self.natives_dir().join(version)
}
/// Get the directory containing instance icons
#[inline]
pub fn icon_dir(&self) -> PathBuf {
self.config_dir.join("icons")
}
/// Get the profiles directory for created profiles
#[inline]
pub fn profiles_dir(&self) -> PathBuf {
self.config_dir.join("profiles")
}
/// Gets the logs dir for a given profile
#[inline]
pub fn profile_logs_dir(&self, profile: uuid::Uuid) -> PathBuf {
self.profiles_dir()
.join(profile.to_string())
.join("modrinth_logs")
}
#[inline]
pub fn launcher_logs_dir(&self) -> PathBuf {
self.config_dir.join("launcher_logs")
}
/// Get the file containing the global database
#[inline]
pub fn database_file(&self) -> PathBuf {
self.config_dir.join("data.bin")
}
/// Get the settings file for Theseus
#[inline]
pub fn settings_file(&self) -> PathBuf {
self.config_dir.join("settings.json")
}
/// Get the cache directory for Theseus
#[inline]
pub fn caches_dir(&self) -> PathBuf {
self.config_dir.join("caches")
}
#[inline]
pub fn caches_meta_dir(&self) -> PathBuf {
self.config_dir.join("caches").join("metadata")
}
/// Get path from environment variable
#[inline]
fn env_path(name: &str) -> Option<PathBuf> {
std::env::var_os(name).map(PathBuf::from)
}
}