diff --git a/src/installer.rs b/src/installer.rs index 65a64be..b52ed48 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -48,7 +48,7 @@ pub enum InstallMessage { pub struct InstallerFramework { config: Config, database: Vec, - install_path: Option, + install_path: Option, preexisting_install: bool } @@ -109,10 +109,9 @@ impl InstallerFramework { None => return Err(format!("No install directory for installer")) }; - println!("Framework: Installing {:?} to {}", items, path); + println!("Framework: Installing {:?} to {:?}", items, path); // Create our install directory - let path = PathBuf::from(path); if !path.exists() { match create_dir_all(&path) { Ok(_) => {} @@ -386,7 +385,7 @@ impl InstallerFramework { None => return Err(format!("No install directory for installer")) }; - let metadata_path = Path::new(&path).join("metadata.json"); + let metadata_path = path.join("metadata.json"); let metadata_file = match File::create(metadata_path) { Ok(v) => v, Err(v) => return Err(format!("Unable to open file handle: {:?}", v)), @@ -403,14 +402,17 @@ impl InstallerFramework { /// Configures this installer to install to the specified location. /// If there was a currently configured install path, this will be left as-is. pub fn set_install_dir(&mut self, dir : &str) { - self.install_path = Some(dir.to_owned()); + self.install_path = Some(Path::new(dir).to_owned()); } /// Returns metadata on the current status of the installation. pub fn get_installation_status(&self) -> InstallationStatus { InstallationStatus { database: self.database.clone(), - install_path: self.install_path.clone(), + install_path: match self.install_path.clone() { + Some(v) => Some(v.display().to_string()), + None => None + }, preexisting_install: self.preexisting_install } } @@ -427,8 +429,9 @@ impl InstallerFramework { /// Creates a new instance of the Installer Framework with a specified Config, managing /// a pre-existing installation. - pub fn new_with_db(config: Config, install_path : String) -> Result { - let metadata_path = Path::new(&install_path).join("metadata.json"); + pub fn new_with_db(config: Config, install_path : &Path) -> Result { + let path = install_path.to_owned(); + let metadata_path = path.join("metadata.json"); let metadata_file = match File::open(metadata_path) { Ok(v) => v, Err(v) => return Err(format!("Unable to open file handle: {:?}", v)), @@ -442,7 +445,7 @@ impl InstallerFramework { Ok(InstallerFramework { config, database, - install_path : Some(install_path), + install_path : Some(path), preexisting_install : true }) } diff --git a/src/main.rs b/src/main.rs index e95f601..33e528e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,13 +48,18 @@ fn main() { let app_name = config.general.name.clone(); - let metadata_file = Path::new("metadata.json"); + let current_exe = std::env::current_exe().unwrap(); + let current_path = current_exe.parent().unwrap(); + let metadata_file = current_path.join("metadata.json"); + println!("Attempting to open: {:?}", metadata_file); let framework = if metadata_file.exists() { - InstallerFramework::new_with_db(config, format!("./")).unwrap() + InstallerFramework::new_with_db(config, current_path).unwrap() } else { InstallerFramework::new(config) }; + // blah 1 + let server = WebServer::new(framework).unwrap(); // Startup HTTP server for handling the web view diff --git a/static/index.html b/static/index.html index 25f3415..7019430 100644 --- a/static/index.html +++ b/static/index.html @@ -41,6 +41,15 @@ Back + +
+

Choose an option:

+ + Update + Modify + Uninstall +
+

Select your preferred settings:

@@ -112,13 +121,19 @@ data: { config : config, install_location : "", + modify_install : false, select_packages : true, is_installing : false, is_finished : false, progress : 0, progress_message : "", has_error : false, - error : "" + error : "", + metadata : { + database : [], + install_path : "", + preexisting_install : false + } }, methods: { "select_file": function() { @@ -134,7 +149,7 @@ var results = {}; - console.log(this.config.packages); + console.log("Packages: " + this.config.packages); for (var package_index = 0; package_index < this.config.packages.length; package_index++) { var current_package = this.config.packages[package_index]; @@ -142,7 +157,7 @@ results[current_package.name] = current_package.default; } } - console.log(results); + console.log("Results: " + results); results["path"] = this.install_location; @@ -174,9 +189,18 @@ } }); - ajax("/api/default-path", function(e) { - if (e.path != null) { - app.install_location = e.path; + ajax("/api/installation-status", function(e) { + app.metadata = e; + if (e.preexisting_install) { + app.modify_install = true; + app.select_packages = false; + app.install_location = e.install_path; + } else { + ajax("/api/default-path", function(e) { + if (e.path != null) { + app.install_location = e.path; + } + }); } });