This commit is contained in:
Caelan Sayler
2024-02-01 20:54:20 +00:00
parent f030a90491
commit 555cdc2d4d
6 changed files with 62 additions and 5 deletions

9
src/Rust/Cargo.lock generated
View File

@@ -1321,18 +1321,18 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.25.0"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.25.3"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18"
dependencies = [
"heck",
"proc-macro2",
@@ -1581,6 +1581,7 @@ dependencies = [
"strum",
"tempfile",
"ureq",
"url",
"wait-timeout",
"waitpid-any",
"webview2-com",

View File

@@ -58,7 +58,7 @@ semver = "1.0"
chrono = "0.4"
wait-timeout = "0.2"
lazy_static = "1.4"
strum = { version = "0.25", features = ["derive"] }
strum = { version = "0.26", features = ["derive"] }
ureq = { version = "2.9", default-features = false, features = [
"native-tls",
"gzip",
@@ -74,6 +74,7 @@ remove_dir_all = { git = "https://github.com/caesay/remove_dir_all.git", feature
] }
zstd = "0.13"
sha1_smol = "1.0"
url = "2.5"
[target.'cfg(unix)'.dependencies]
native-dialog = "0.7"

View File

@@ -0,0 +1,38 @@
use crate::bundle::Manifest;
use anyhow::{bail, Result};
use std::path::PathBuf;
use url::{ParseError, Url};
pub fn check(root_path: &PathBuf, app: &Manifest, path: String, allow_downgrade: bool, channel: Option<String>) -> Result<()> {
match Url::parse(&path) {
Ok(url) => check_url(root_path, app, url, allow_downgrade, channel),
_ => {
let buf = PathBuf::from(&path);
if !buf.exists() {
bail!("Path must be a valid HTTP Url or a path to an existing directory: {}", path);
}
check_dir(root_path, app, buf, allow_downgrade, channel)
}
}
}
fn check_url(root_path: &PathBuf, app: &Manifest, path: Url, allow_downgrade: bool, channel: Option<String>) -> Result<()> {
let channel = channel.unwrap_or(app.channel.clone());
let releases_name = format!("releases.{}.json", channel);
todo!();
}
fn check_dir(root_path: &PathBuf, app: &Manifest, path: PathBuf, allow_downgrade: bool, channel: Option<String>) -> Result<()> {
let channel = channel.unwrap_or(app.channel.clone());
let releases_name = format!("releases.{}.json", channel);
let releases_path = path.join(&releases_name);
if !releases_path.exists() {
bail!("Could not find releases file: {}", path.to_string_lossy());
}
todo!();
}

View File

@@ -4,6 +4,9 @@ pub use apply::*;
mod patch;
pub use patch::*;
mod check;
pub use check::*;
#[cfg(target_os = "linux")]
mod apply_linux_impl;
#[cfg(target_os = "macos")]

View File

@@ -308,6 +308,7 @@ pub struct Manifest {
pub main_exe: String,
pub os: String,
pub os_min_version: String,
pub channel: String,
}
#[cfg(target_os = "windows")]
@@ -407,6 +408,8 @@ pub fn read_manifest_from_string(xml: &str) -> Result<Manifest> {
obj.os = text;
} else if el_name == "osMinVersion" {
obj.os_min_version = text;
} else if el_name == "channel" {
obj.channel = text;
}
}
Ok(XmlEvent::EndElement { .. }) => {

View File

@@ -27,6 +27,17 @@ fn root_command() -> Command {
.arg(arg!(--patch <FILE> "The Zstd patch to apply to the old file").required(true).value_parser(value_parser!(PathBuf)))
.arg(arg!(--output <FILE> "The file to create with the patch applied").required(true).value_parser(value_parser!(PathBuf)))
)
.subcommand(Command::new("check")
.about("Checks for available updates")
.arg(arg!([PATH] "HTTP URL or path to local folder containing an update source.").required(true))
.arg(arg!(--downgrade "Allow version downgrade"))
.arg(arg!(--channel <NAME> "Explicitly switch to a specific channel"))
)
.subcommand(Command::new("download")
.about("Download/copies an available remote file into the packages directory.")
.arg(arg!([PATH] "HTTP URL or path to local folder containing an update source.").required(true))
.arg(arg!([NAME] "The remote package file to download.").required(true))
)
.arg(arg!(--verbose "Print debug messages to console / log").global(true))
.arg(arg!(--nocolor "Disable colored output").hide(true).global(true))
.arg(arg!(-s --silent "Don't show any prompts / dialogs").global(true))