Skip to main content

conduit_cli/core/runtime/loaders/
mod.rs

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