aboutsummaryrefslogtreecommitdiff
path: root/launcher/src/lib.rs
blob: 32ae8eef8f0a5c4d6741447a422ced812be9c44b (plain)
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
32
33
34
35
36
37
38
39
pub mod constants;

use std::ffi::OsStr;
use std::path::PathBuf;
use crate::AppDataError::NotFound;

pub enum AppData {
    Folder(PathBuf),
    Asar(PathBuf)
}

pub enum AppDataError {
    NotFound(PathBuf, PathBuf)
}

impl AppData {
    pub fn get_path(&self) -> &OsStr {
        match self {
            AppData::Folder(path) => path.as_ref(),
            AppData::Asar(path) => path.as_ref()
        }
    }

    pub fn locate_app(work_dir: &PathBuf) -> Result<AppData, AppDataError> {
        let mut app_path_folder = PathBuf::from(work_dir);
        app_path_folder.push(constants::APP_FOLDER_PATH);

        let mut app_path_asar = PathBuf::from(work_dir);
        app_path_asar.push(constants::APP_ASAR_PATH);

        if app_path_folder.exists() {
            Ok(AppData::Folder(app_path_folder))
        } else if app_path_asar.exists() {
            Ok(AppData::Asar(app_path_asar))
        } else {
            Err(NotFound(app_path_folder, app_path_asar))
        }
    }
}