cobble_core/instance/fabric/
install.rs

1use crate::error::{CobbleError, CobbleResult};
2use crate::minecraft::models::{VersionData, VersionManifest};
3use crate::minecraft::{
4    install_assets, install_client, install_fabric_libraries, install_libraries,
5    install_log_config, FabricVersionData, InstallOptionsBuilder, InstallationUpdate,
6};
7use crate::Instance;
8use tokio::sync::mpsc::Sender;
9
10impl Instance {
11    /// Performs a full installation of Minecraft.
12    ///
13    /// Includes
14    ///
15    /// - Saving version data
16    /// - Saving fabric version data
17    /// - Libraries
18    /// - Fabric libraries (when enabled)
19    /// - Assets / Resources
20    /// - Log config
21    /// - Client
22    #[instrument(
23        name = "full_installation",
24        level = "debug",
25        skip_all,
26        fields(
27            version = &self.version,
28            parallel,
29            retries,
30            verify,
31        )
32    )]
33    pub async fn full_installation(
34        &mut self,
35        parallel: u16,
36        retries: u16,
37        verify: bool,
38        update_sender: Sender<InstallationUpdate>,
39    ) -> CobbleResult<()> {
40        trace!("Fetching version manifest");
41        let manifest = VersionManifest::fetch().await?;
42
43        trace!("Fetching version data");
44        let summary = manifest
45            .versions
46            .get(&self.version)
47            .ok_or_else(|| CobbleError::InvalidVersion(self.version.clone()))?;
48        let version_data = VersionData::fetch(&summary.url).await?;
49
50        trace!("Saving version data");
51        self.save_version_data(&version_data).await?;
52
53        trace!("Fetching asset index");
54        let asset_index = version_data.asset_index.fetch_index().await?;
55
56        let options = InstallOptionsBuilder::default()
57            .version_data(version_data)
58            .asset_index(asset_index)
59            .libraries_path(self.libraries_path())
60            .natives_path(self.natives_path())
61            .assets_path(self.assets_path())
62            .log_configs_path(self.log_configs_path())
63            .minecraft_path(self.dot_minecraft_path())
64            .parallel_downloads(parallel)
65            .download_retries(retries)
66            .verify_downloads(verify)
67            .build()
68            .unwrap();
69
70        install_libraries(&options, update_sender.clone()).await?;
71        install_assets(&options, update_sender.clone()).await?;
72        install_log_config(&options, update_sender.clone()).await?;
73        install_client(&options, update_sender.clone()).await?;
74
75        // Fabric
76        if let Some(fabric_version) = &self.fabric_version {
77            trace!("Fetching fabric version data");
78            let fabric_version_data =
79                FabricVersionData::fetch(&self.version, fabric_version).await?;
80
81            trace!("Saving fabric version data");
82            self.save_fabric_version_data(&fabric_version_data).await?;
83
84            install_fabric_libraries(&fabric_version_data, &options, update_sender).await?;
85        }
86
87        self.installed = true;
88        Ok(())
89    }
90}