diff --git a/README.md b/README.md index 2700680..8ada1c6 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,40 @@ # Sealupd -Updater for [SealDice](https://github.com/sealdice), successor of [seal-updater](https://github.com/sealdice/seal-updater). +Updater for [SealDice], successor of [seal-updater]. + +# Usage + +The program accepts to principal arguments: `--package` (short `-p`, alias `--upgrade`) and `--pid`. It waits for the process with the specified PID to terminate before extracting files from the provided package into the current directory. Finally, it tries to start the executable named `sealdice-core` or `sealdice-core.exe` unless the `--skip-launch` flag is set. + +For a full definition of acceptable arguments and flags, see `src/cli.rs`. + +# Development > [!WARNING] -> Please use Rust 1.80.0 and above to build this project, as it uses new features such as `std::sync::LazyLock`. +> Please use Rust 1.80.0 and above to build this project, as it leverages new features such as `std::sync::LazyLock`. + +## Style Guides + +1. Use `cargo fmt` without any options to format the project. Do not use `rustfmt` as it formats on a per-file basis and removes disambiguate imports. + +2. Import types directly; prefer `File` instead of `std::fs::File` or `fs::File`, unless ambiguity forbids (`Error` and `io::Error`). + +3. Import functions by their immediate parent module; prefer `io::stdin()` instead of `std::io::stdin()` or `stdin()`. ## TODO - [x] Implement business logic. - [x] Add log information. - [x] Add manifest and static build for Windows (via `embed_manifest` and `static_vcruntime`). -- [ ] CI/CD -- [ ] Tests \ No newline at end of file +- [ ] CI/CD & auto-release +- [ ] Tests +- [ ] Make [SealDice] migrate from the old [seal-updater]. + +## Other Notes + +- We might need a graceful way to log and print information rather than littering `debug!()` and `println!()` everywhere. + +- The current implementation of `proc::wait()` is the best we can do, but feedback we got from [seal-updater] proves it is not always reliable. + +[SealDice]: https://github.com/sealdice +[seal-updater]: https://github.com/sealdice/seal-updater diff --git a/src/decompress/mod.rs b/src/decompress/mod.rs index 95ab233..fa867eb 100644 --- a/src/decompress/mod.rs +++ b/src/decompress/mod.rs @@ -8,6 +8,7 @@ use std::{ }; use ::zip::result::ZipError; +use log::info; mod tar; mod util; @@ -28,6 +29,7 @@ where Err(format!("decompress zip: {}", err))?; } + info!("Invalid ZIP archive detected, falling back to tarball."); file.seek(SeekFrom::Start(0))?; tar::decompress(file, dest).map_err(|e| format!("decompress tar: {}", e))?; } diff --git a/src/main.rs b/src/main.rs index 56e26c5..00a390f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ mod cli; mod consts; mod decompress; mod log; -mod proc_wait; +mod proc; mod term_color; mod util; @@ -18,7 +18,7 @@ fn main() { if CLI_ARGS.pid != 0 { debug!("Starting to wait for process {}.", CLI_ARGS.pid); println!("Waiting for process {} to finish.", CLI_ARGS.pid); - proc_wait::wait(CLI_ARGS.pid); + proc::wait(CLI_ARGS.pid); } debug!("Backing up old sealdice-core."); diff --git a/src/proc_wait.rs b/src/proc.rs similarity index 100% rename from src/proc_wait.rs rename to src/proc.rs diff --git a/src/term_color.rs b/src/term_color.rs index 2d998a6..f42102f 100644 --- a/src/term_color.rs +++ b/src/term_color.rs @@ -17,9 +17,9 @@ pub struct ColoredString { impl ColoredString { /// Creates a new [`ColoredString`] with an initial color code. /// If the code is 0, it will be ignored. - pub fn new(s: &str, code: i32) -> Self { - let mut vec = Vec::new(); - if code != 0 { + pub fn new(s: &str, codes: &[i32]) -> Self { + let mut vec = Vec::with_capacity(codes.len()); + for &code in codes { vec.push(code); } @@ -29,8 +29,10 @@ impl ColoredString { } } - fn append_color(&mut self, code: i32) { - self.codes.push(code); + fn append_colors(&mut self, codes: &[i32]) { + for &code in codes { + self.codes.push(code); + } } } @@ -63,31 +65,31 @@ pub trait Colorable { // Implementing for `&str` also implements for `String`. impl<'a> Colorable for &'a str { fn error(self) -> ColoredString { - ColoredString::new(self, 31) + ColoredString::new(self, &[31, 1]) } fn warn(self) -> ColoredString { - ColoredString::new(self, 33) + ColoredString::new(self, &[33]) } fn success(self) -> ColoredString { - ColoredString::new(self, 32) + ColoredString::new(self, &[32, 1]) } } impl Colorable for ColoredString { fn error(mut self) -> ColoredString { - self.append_color(31); + self.append_colors(&[31, 1]); self } fn warn(mut self) -> ColoredString { - self.append_color(33); + self.append_colors(&[33]); self } fn success(mut self) -> ColoredString { - self.append_color(32); + self.append_colors(&[32, 1]); self } } diff --git a/src/util.rs b/src/util.rs index 1859c48..4e6b407 100644 --- a/src/util.rs +++ b/src/util.rs @@ -40,6 +40,8 @@ pub fn backup_sealdice() -> Result<(), io::Error> { fs::rename(cwd.join(EXE_NAME), cwd.join(old)) } +/// Attempts to run `chmod 755` on `sealdice-core` and then start it. Exit the program +/// if anything goes wrong. #[cfg(target_family = "unix")] pub fn restart_sealdice() { use std::os::unix::{fs::PermissionsExt, process::CommandExt}; @@ -75,6 +77,7 @@ pub fn restart_sealdice() { graceful_exit(1); } +/// Attempts to start `sealdice-core`. Exit the program if anything goes wrong. #[cfg(target_family = "windows")] pub fn restart_sealdice() { let dest = Path::new(".").join(EXE_NAME);