diff --git a/src/config.rs b/src/config.rs index cbc4854..629fa4d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,21 +10,21 @@ use serde_json::{self, Error as SerdeError}; /// Describes a overview of a individual package. #[derive(Deserialize, Serialize, Clone)] pub struct PackageDescription { - name : String, - description : String, - default : Option + pub name : String, + pub description : String, + pub default : Option } /// Describes the application itself. #[derive(Deserialize, Serialize, Clone)] pub struct GeneralConfig { - name : String + pub name : String } #[derive(Deserialize, Serialize, Clone)] pub struct Config { - general : GeneralConfig, - packages : Vec + pub general : GeneralConfig, + pub packages : Vec } impl Config { diff --git a/src/installer.rs b/src/installer.rs index fd4d848..ccba867 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -2,6 +2,11 @@ /// /// Contains the main installer structure, as well as high-level means of controlling it. +use std::env::home_dir; +use std::env::var; + +use std::path::PathBuf; + use config::Config; /// The installer framework contains metadata about packages, what is installable, what isn't, @@ -16,6 +21,23 @@ impl InstallerFramework { self.config.clone() } + /// Returns the default install path. + pub fn get_default_path(&self) -> Option { + let app_name = &self.config.general.name; + + let base_dir = match var("LOCALAPPDATA") { + Ok(path) => PathBuf::from(path), + Err(_) => home_dir()? + }; + + println!("{:?}", base_dir); + + let file = base_dir.join(app_name); + println!("{:?}", file); + + Some(file.to_str()?.to_owned()) + } + /// Creates a new instance of the Installer Framework with a specified Config. pub fn new(config : Config) -> Self { InstallerFramework { diff --git a/src/rest.rs b/src/rest.rs index 6e2f5c3..fb74edf 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -104,7 +104,16 @@ impl WebServer { }; Some(serde_json::to_string(&response).unwrap()) - } + }, + "default-path" => { + let path = self.framework.get_default_path(); + + let response = FileSelection { + path + }; + + Some(serde_json::to_string(&response).unwrap()) + }, _ => None } } diff --git a/static/index.html b/static/index.html index e0c26a1..fc036f5 100644 --- a/static/index.html +++ b/static/index.html @@ -57,7 +57,7 @@