conduit_cli/core/
paths.rs1use crate::core::{
2 error::{CoreError, CoreResult},
3 runtime::loaders::LoaderType,
4};
5use std::path::{Path, PathBuf};
6
7#[derive(Debug, Clone)]
8pub struct CorePaths {
9 pub project_dir: PathBuf,
10 pub manifest_path: PathBuf,
11 pub lock_path: PathBuf,
12 pub mods_dir: PathBuf,
13 pub cache_dir: PathBuf,
14 pub config_path: PathBuf,
15}
16
17impl CorePaths {
18 pub fn from_project_dir(project_dir: impl Into<PathBuf>) -> CoreResult<Self> {
19 let project_dir = project_dir.into();
20 let cache_dir = dirs::data_local_dir()
21 .ok_or(CoreError::MissingLocalDataDir)?
22 .join("conduit")
23 .join("cache");
24
25 if !cache_dir.exists() {
26 std::fs::create_dir_all(&cache_dir)
27 .map_err(|e| CoreError::RuntimeError(e.to_string()))?;
28 }
29
30 Ok(Self {
31 manifest_path: project_dir.join("conduit.json"),
32 lock_path: project_dir.join("conduit.lock"),
33 config_path: project_dir.join("config.toml"),
34 mods_dir: project_dir.join("mods"),
35 project_dir,
36 cache_dir,
37 })
38 }
39
40 pub fn manifest_path(&self) -> &Path {
41 &self.manifest_path
42 }
43
44 pub fn config_path(&self) -> &Path {
45 &self.config_path
46 }
47
48 pub fn project_dir(&self) -> &Path {
49 &self.project_dir
50 }
51
52 pub fn lock_path(&self) -> &Path {
53 &self.lock_path
54 }
55
56 pub fn mods_dir(&self) -> &Path {
57 &self.mods_dir
58 }
59
60 pub fn cache_dir(&self) -> &Path {
61 &self.cache_dir
62 }
63
64 pub fn loader_libs_dir(&self) -> PathBuf {
65 self.project_dir.join("libraries")
66 }
67
68 pub fn neoforge_version_dir(&self, version: &str) -> PathBuf {
69 self.loader_libs_dir()
70 .join("net/neoforged/neoforge")
71 .join(version)
72 }
73
74 pub fn get_neoforge_path(&self, version: &str) -> PathBuf {
75 self.project_dir()
76 .join("libraries")
77 .join("net/neoforged/neoforge")
78 .join(version)
79 }
80
81 pub fn is_loader_ready(&self, loader_type: &LoaderType, version: &str) -> bool {
82 match loader_type {
83 LoaderType::NeoForge => {
84 let path = self.get_neoforge_path(version);
85 println!("{}", path.join("unix_args.txt").display());
86 path.join("unix_args.txt").exists() && path.join("win_args.txt").exists()
87 }
88 }
89 }
90}