1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::error::CobbleResult;
use crate::instance::Instance;

impl Instance {
    /// Checks if the instance is already installed.
    ///
    /// Currently only checks
    ///
    /// - Version data exists and
    /// - Minecraft client exists
    pub fn check_installed(&self) -> CobbleResult<bool> {
        let version_data_path = self.version_data_path();
        if !version_data_path.is_file() {
            return Ok(false);
        }

        let version_data = self.read_version_data()?;

        if version_data.downloads.is_some() {
            let mut client_path = self.dot_minecraft_path();
            client_path.push("bin");
            client_path.push(format!("minecraft-{}-client.jar", &version_data.id));

            if client_path.is_file() {
                return Ok(true);
            }
        }

        Ok(false)
    }
}