Use PathBufs internally, correctly find metadata

This commit is contained in:
James Lonie 2018-05-03 14:14:44 +10:00
parent 93ebca5f3c
commit a174c265d4
3 changed files with 49 additions and 17 deletions

View File

@ -48,7 +48,7 @@ pub enum InstallMessage {
pub struct InstallerFramework {
config: Config,
database: Vec<LocalInstallation>,
install_path: Option<String>,
install_path: Option<PathBuf>,
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<Self, String> {
let metadata_path = Path::new(&install_path).join("metadata.json");
pub fn new_with_db(config: Config, install_path : &Path) -> Result<Self, String> {
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
})
}

View File

@ -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

View File

@ -41,6 +41,15 @@
<a class="button is-primary is-pulled-right" v-on:click="back_to_packages">Back</a>
</div>
<div class="column" v-else-if="modify_install">
<h4 class="subtitle">Choose an option:</h4>
<a class="button is-primary is-pulled-right" v-on:click="exit">Update</a>
<a class="button is-primary is-pulled-right" v-on:click="exit">Modify</a>
<a class="button is-primary is-pulled-right" v-on:click="exit">Uninstall</a>
</div>
<div class="column" v-else-if="select_packages">
<h4 class="subtitle">Select your preferred settings:</h4>
@ -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;
}
});
}
});
</script>