Skip to main content

conduit_cli/loaders/
mod.rs

1use crate::core::events::CoreCallbacks;
2
3pub mod neoforge;
4
5pub struct LoaderInfo {
6    pub name: String,
7    pub version: String,
8}
9
10impl LoaderInfo {
11    pub fn parse(loader_str: &str) -> Self {
12        let parts: Vec<&str> = loader_str.split('@').collect();
13        let name = parts[0].to_string();
14        let version = if parts.len() > 1 {
15            parts[1].to_string()
16        } else {
17            "latest".to_string()
18        };
19        Self { name, version }
20    }
21}
22
23pub enum Loader {
24    NeoForge,
25}
26
27impl Loader {
28    pub async fn get_latest_version(
29        &self,
30        mc_version: &str,
31        callbacks: &mut dyn CoreCallbacks,
32    ) -> Result<String, Box<dyn std::error::Error>> {
33        match self {
34            Loader::NeoForge => neoforge::get_latest_neoforge_version(mc_version, callbacks).await,
35        }
36    }
37
38    pub async fn download_installer(
39        &self,
40        mc_version: &str,
41        loader_version: &str,
42        install_path: &std::path::Path,
43        callbacks: &mut dyn CoreCallbacks,
44    ) -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
45        match self {
46            Loader::NeoForge => {
47                neoforge::download_neoforge_installer(
48                    mc_version,
49                    loader_version,
50                    install_path,
51                    callbacks,
52                )
53                .await
54            }
55        }
56    }
57
58    pub async fn execute_installer(
59        &self,
60        installer_path: &std::path::Path,
61        callbacks: &mut dyn CoreCallbacks,
62    ) -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
63        match self {
64            Loader::NeoForge => {
65                neoforge::execute_neoforge_installer(installer_path, callbacks).await
66            }
67        }
68    }
69
70    pub async fn post_install(
71        &self,
72        installer_path: &std::path::Path,
73        install_path: &std::path::Path,
74        callbacks: &mut dyn CoreCallbacks,
75    ) -> Result<(), Box<dyn std::error::Error>> {
76        match self {
77            Loader::NeoForge => {
78                neoforge::post_install_neoforge(installer_path, install_path, callbacks).await
79            }
80        }
81    }
82}