liftinstall/src/installer.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

2018-01-27 04:27:41 +01:00
/// installer.rs
///
/// Contains the main installer structure, as well as high-level means of controlling it.
2018-01-27 05:14:56 +01:00
use std::env::home_dir;
use std::env::var;
use std::path::PathBuf;
2018-01-27 04:27:41 +01:00
use config::Config;
/// The installer framework contains metadata about packages, what is installable, what isn't,
/// etc.
pub struct InstallerFramework {
2018-01-27 12:58:56 +01:00
config: Config,
2018-01-27 04:27:41 +01:00
}
impl InstallerFramework {
/// Returns a copy of the configuration.
pub fn get_config(&self) -> Config {
self.config.clone()
}
2018-01-27 05:14:56 +01:00
/// Returns the default install path.
pub fn get_default_path(&self) -> Option<String> {
let app_name = &self.config.general.name;
let base_dir = match var("LOCALAPPDATA") {
Ok(path) => PathBuf::from(path),
2018-01-27 12:58:56 +01:00
Err(_) => home_dir()?,
2018-01-27 05:14:56 +01:00
};
println!("{:?}", base_dir);
let file = base_dir.join(app_name);
println!("{:?}", file);
Some(file.to_str()?.to_owned())
}
2018-01-27 04:27:41 +01:00
/// Creates a new instance of the Installer Framework with a specified Config.
2018-01-27 12:58:56 +01:00
pub fn new(config: Config) -> Self {
InstallerFramework { config }
2018-01-27 04:27:41 +01:00
}
}