mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-25 20:15:42 +01:00
Add database for version information
This commit is contained in:
parent
6cd8abebe5
commit
248bdbbb7b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -680,6 +680,7 @@ version = "0.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -27,7 +27,7 @@ toml = "0.4"
|
|||||||
|
|
||||||
nfd = "0.0.4"
|
nfd = "0.0.4"
|
||||||
|
|
||||||
semver = "0.9.0"
|
semver = {version = "0.9.0", features = ["serde"]}
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
|
|
||||||
zip = "0.2.8"
|
zip = "0.2.8"
|
||||||
|
@ -6,6 +6,8 @@ use regex::Regex;
|
|||||||
|
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use number_prefix::{decimal_prefix, Prefixed, Standalone};
|
use number_prefix::{decimal_prefix, Prefixed, Standalone};
|
||||||
|
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
@ -21,6 +23,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::io::copy;
|
use std::io::copy;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
@ -30,6 +33,8 @@ use config::Config;
|
|||||||
|
|
||||||
use http::stream_file;
|
use http::stream_file;
|
||||||
|
|
||||||
|
use sources::types::Version;
|
||||||
|
|
||||||
/// A message thrown during the installation of packages.
|
/// A message thrown during the installation of packages.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub enum InstallMessage {
|
pub enum InstallMessage {
|
||||||
@ -49,6 +54,14 @@ struct DownloadProgress {
|
|||||||
downloaded: usize,
|
downloaded: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tracks the state of a local installation
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct LocalInstallation {
|
||||||
|
name: String,
|
||||||
|
version: Version,
|
||||||
|
files: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
impl InstallerFramework {
|
impl InstallerFramework {
|
||||||
/// Returns a copy of the configuration.
|
/// Returns a copy of the configuration.
|
||||||
pub fn get_config(&self) -> Config {
|
pub fn get_config(&self) -> Config {
|
||||||
@ -117,6 +130,8 @@ impl InstallerFramework {
|
|||||||
let mut count = 0.0 as f64;
|
let mut count = 0.0 as f64;
|
||||||
let max = to_install.len() as f64;
|
let max = to_install.len() as f64;
|
||||||
|
|
||||||
|
let mut installed_packages = Vec::new();
|
||||||
|
|
||||||
for package in to_install.iter() {
|
for package in to_install.iter() {
|
||||||
let base_package_percentage = count / max;
|
let base_package_percentage = count / max;
|
||||||
let base_package_range = ((count + 1.0) / max) - base_package_percentage;
|
let base_package_range = ((count + 1.0) / max) - base_package_percentage;
|
||||||
@ -161,6 +176,8 @@ impl InstallerFramework {
|
|||||||
None => return Err(format!("No release with correct file found")),
|
None => return Err(format!("No release with correct file found")),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let latest_version = latest_result.version.clone();
|
||||||
|
|
||||||
// Find the matching file in here
|
// Find the matching file in here
|
||||||
let latest_file = latest_result
|
let latest_file = latest_result
|
||||||
.files
|
.files
|
||||||
@ -221,6 +238,8 @@ impl InstallerFramework {
|
|||||||
println!("File downloaded successfully");
|
println!("File downloaded successfully");
|
||||||
|
|
||||||
// Extract this downloaded file
|
// Extract this downloaded file
|
||||||
|
let mut installed_files = Vec::new();
|
||||||
|
|
||||||
// TODO: Handle files other then zips
|
// TODO: Handle files other then zips
|
||||||
// TODO: Make database for uninstall
|
// TODO: Make database for uninstall
|
||||||
let data = data_storage.lock().unwrap();
|
let data = data_storage.lock().unwrap();
|
||||||
@ -252,6 +271,8 @@ impl InstallerFramework {
|
|||||||
let target_path = path.join(file.name());
|
let target_path = path.join(file.name());
|
||||||
println!("target_path: {:?}", target_path);
|
println!("target_path: {:?}", target_path);
|
||||||
|
|
||||||
|
installed_files.push(file.name().to_owned());
|
||||||
|
|
||||||
// Check to make sure this isn't a directory
|
// Check to make sure this isn't a directory
|
||||||
if file.name().ends_with("/") || file.name().ends_with("\\") {
|
if file.name().ends_with("/") || file.name().ends_with("\\") {
|
||||||
// Create this directory and move on
|
// Create this directory and move on
|
||||||
@ -278,13 +299,37 @@ impl InstallerFramework {
|
|||||||
// Cross the streams
|
// Cross the streams
|
||||||
match copy(&mut file, &mut target_file) {
|
match copy(&mut file, &mut target_file) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(v) => return Err(format!("Unable to open write file: {:?}", v)),
|
Err(v) => return Err(format!("Unable to write to file: {:?}", v)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save metadata about this package
|
||||||
|
installed_packages.push(LocalInstallation {
|
||||||
|
name: package.name.to_owned(),
|
||||||
|
version: latest_version,
|
||||||
|
files: installed_files,
|
||||||
|
});
|
||||||
|
|
||||||
count += 1.0;
|
count += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make copy of metadata
|
||||||
|
// TODO: Combine with already installed database, if needed
|
||||||
|
let metadata_compiled = serde_json::to_string(&installed_packages).unwrap();
|
||||||
|
|
||||||
|
{
|
||||||
|
let metadata_path = path.join("metadata.json");
|
||||||
|
let mut metadata_file = match File::create(metadata_path) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(v) => return Err(format!("Unable to open file handle: {:?}", v)),
|
||||||
|
};
|
||||||
|
|
||||||
|
match metadata_file.write_all(metadata_compiled.as_bytes()) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(v) => return Err(format!("Unable to write to file: {:?}", v)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Copy installer binary to target directory
|
// Copy installer binary to target directory
|
||||||
messages
|
messages
|
||||||
.send(InstallMessage::Status(
|
.send(InstallMessage::Status(
|
||||||
|
@ -9,7 +9,7 @@ pub use semver::Version as SemverVersion;
|
|||||||
pub use toml::value::Value as TomlValue;
|
pub use toml::value::Value as TomlValue;
|
||||||
|
|
||||||
/// The version of an application.
|
/// The version of an application.
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
pub enum Version {
|
pub enum Version {
|
||||||
Semver(SemverVersion),
|
Semver(SemverVersion),
|
||||||
Integer(u64),
|
Integer(u64),
|
||||||
|
Loading…
Reference in New Issue
Block a user