mirror of
https://github.com/yuzu-emu/liftinstall
synced 2024-11-23 21:33:59 +00:00
Add default path handling
This commit is contained in:
parent
d537b80e12
commit
88cbb91dc6
4 changed files with 46 additions and 10 deletions
|
@ -10,21 +10,21 @@ use serde_json::{self, Error as SerdeError};
|
||||||
/// Describes a overview of a individual package.
|
/// Describes a overview of a individual package.
|
||||||
#[derive(Deserialize, Serialize, Clone)]
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
pub struct PackageDescription {
|
pub struct PackageDescription {
|
||||||
name : String,
|
pub name : String,
|
||||||
description : String,
|
pub description : String,
|
||||||
default : Option<bool>
|
pub default : Option<bool>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes the application itself.
|
/// Describes the application itself.
|
||||||
#[derive(Deserialize, Serialize, Clone)]
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
pub struct GeneralConfig {
|
pub struct GeneralConfig {
|
||||||
name : String
|
pub name : String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone)]
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
general : GeneralConfig,
|
pub general : GeneralConfig,
|
||||||
packages : Vec<PackageDescription>
|
pub packages : Vec<PackageDescription>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
///
|
///
|
||||||
/// Contains the main installer structure, as well as high-level means of controlling it.
|
/// 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;
|
use config::Config;
|
||||||
|
|
||||||
/// The installer framework contains metadata about packages, what is installable, what isn't,
|
/// The installer framework contains metadata about packages, what is installable, what isn't,
|
||||||
|
@ -16,6 +21,23 @@ impl InstallerFramework {
|
||||||
self.config.clone()
|
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.
|
/// Creates a new instance of the Installer Framework with a specified Config.
|
||||||
pub fn new(config : Config) -> Self {
|
pub fn new(config : Config) -> Self {
|
||||||
InstallerFramework {
|
InstallerFramework {
|
||||||
|
|
11
src/rest.rs
11
src/rest.rs
|
@ -104,7 +104,16 @@ impl WebServer {
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(serde_json::to_string(&response).unwrap())
|
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
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control is-expanded">
|
<div class="control is-expanded">
|
||||||
<input class="input" type="text" v-model="install_location"
|
<input class="input" type="text" v-model="install_location"
|
||||||
placeholder="%localappdata%\yuzu">
|
placeholder="Enter a install path here">
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<a class="button is-info" v-on:click="select_file">
|
<a class="button is-info" v-on:click="select_file">
|
||||||
|
@ -81,12 +81,11 @@
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
config : config,
|
config : config,
|
||||||
install_location : "%localappdata%\yuzu"
|
install_location : ""
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
"select_file": function() {
|
"select_file": function() {
|
||||||
ajax("/api/file-select", function(e) {
|
ajax("/api/file-select", function(e) {
|
||||||
alert(e);
|
|
||||||
if (e.path != null) {
|
if (e.path != null) {
|
||||||
app.install_location = e.path;
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue