mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-22 16:15:40 +01:00
Add default path handling
This commit is contained in:
parent
d537b80e12
commit
88cbb91dc6
@ -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<bool>
|
||||
pub name : String,
|
||||
pub description : String,
|
||||
pub default : Option<bool>
|
||||
}
|
||||
|
||||
/// 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<PackageDescription>
|
||||
pub general : GeneralConfig,
|
||||
pub packages : Vec<PackageDescription>
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -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<String> {
|
||||
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 {
|
||||
|
11
src/rest.rs
11
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
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
<div class="field has-addons">
|
||||
<div class="control is-expanded">
|
||||
<input class="input" type="text" v-model="install_location"
|
||||
placeholder="%localappdata%\yuzu">
|
||||
placeholder="Enter a install path here">
|
||||
</div>
|
||||
<div class="control">
|
||||
<a class="button is-info" v-on:click="select_file">
|
||||
@ -81,12 +81,11 @@
|
||||
el: '#app',
|
||||
data: {
|
||||
config : config,
|
||||
install_location : "%localappdata%\yuzu"
|
||||
install_location : ""
|
||||
},
|
||||
methods: {
|
||||
"select_file": function() {
|
||||
ajax("/api/file-select", function(e) {
|
||||
alert(e);
|
||||
if (e.path != null) {
|
||||
app.install_location = e.path;
|
||||
}
|
||||
@ -94,6 +93,12 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ajax("/api/default-path", function(e) {
|
||||
if (e.path != null) {
|
||||
app.install_location = e.path;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user