1 Commits
Author SHA1 Message Date
vhaudiquet e3a62aa6ae app: check Gitea releases and install update capsules
record-daemon / Check and lint (Linux) (push) Successful in 1m5s
record-daemon / Build (Windows x64) (push) Successful in 1m54s
The app asks the project's Gitea release list about five seconds after
startup and every six hours. A stable release beats a newer prerelease,
and a release is offered only when its tag is newer than the running
build and it carries a .capsule asset for this target.

A capsule is a ZIP with capsule.json and a payload. Every payload file
carries its size and BLAKE3 digest in the manifest, and staging rejects
absolute paths, parent segments, undeclared entries, digest mismatches,
and versions that are not newer. The verified payload is stored under the
app data directory, so a download survives a restart.

The manifest and archive format live in crates/capsule-format, shared by
the app's verifier and the release tool.

Settings > Advanced shows the state, the notes, and the download and
install buttons. The status bar shows an accent chip while an update is
waiting. Install copies the app to a temp helper, asks the daemon to stop,
and quits. The helper waits for the process, swaps the files with a
rollback copy of each old file, removes stale files, and starts the new
app. A failed swap puts the old files back and logs the reason.

--check-updates runs the release check from a shell. The release tool in
tools/capsule builds a capsule from the same files the installer puts
down, using packager.toml, so a release does not need an installed copy.
docs/updates.md covers the format and the release steps.
2026-11-24 21:59:17 +01:00
17 changed files with 3535 additions and 6 deletions

No files matched your search

+2
View File
@@ -1,2 +1,4 @@
/.rhema/
/app/vendor/rune/target
/tools/capsule/target
/crates/capsule-format/target
+4 -2
View File
@@ -1,11 +1,13 @@
# Working in this repository
The repository holds two Rust programs: `record-daemon/` (the recorder) and `app/` (the rune
front end).
front end). The release tool under `tools/capsule/` and the capsule format it shares with the
app under `crates/capsule-format/` are built only for releases.
## Before every commit
In `app/` and in `record-daemon/`, all of these must pass:
In `app/`, `record-daemon/`, `tools/capsule/`, and `crates/capsule-format/`, all of these must
pass:
```sh
cargo fmt
+15
View File
@@ -530,6 +530,17 @@ dependencies = [
"wayland-client",
]
[[package]]
name = "capsule-format"
version = "0.1.0"
dependencies = [
"blake3",
"semver",
"serde",
"serde_json",
"zip",
]
[[package]]
name = "cc"
version = "1.11.2"
@@ -1549,6 +1560,8 @@ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
name = "leaguerecorder"
version = "0.3.3"
dependencies = [
"blake3",
"capsule-format",
"chrono",
"directories",
"ffmpeg-sidecar",
@@ -1556,6 +1569,7 @@ dependencies = [
"rune",
"rune-kit",
"rune-notify",
"semver",
"serde",
"serde_json",
"tokio",
@@ -1564,6 +1578,7 @@ dependencies = [
"windows",
"winreg",
"winresource",
"zip",
]
[[package]]
+6
View File
@@ -17,6 +17,7 @@ winresource = "0.1"
rune = { path = "vendor/rune/crates/rune", features = ["native-file-dialog"] }
rune-kit = { path = "vendor/rune/crates/rune-kit" }
rune-notify = { path = "vendor/rune/crates/rune-notify" }
capsule-format = { path = "../crates/capsule-format" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
@@ -26,6 +27,11 @@ tokio = { version = "1", features = ["rt", "net", "io-util", "time", "sync"] }
uuid = { version = "1", features = ["v4", "serde"] }
ffmpeg-sidecar = "2.7"
ureq = "3.5"
# Updates: the Gitea release list over ureq, a capsule is a ZIP, and every file in it carries
# a BLAKE3 digest.
semver = "1"
blake3 = "1"
zip = { version = "9.6", default-features = false, features = ["deflate-flate2"] }
# PNG decode of the bundled tray icon; the same crate and features rune itself uses.
image = { version = "0.25", default-features = false, features = ["png"] }
+22
View File
@@ -74,6 +74,7 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti
| `src/export.rs` | ffmpeg clip export, the clips folder it fills and its miniatures |
| `src/os.rs` | Run key, toasts, tray icon and menu |
| `src/ui.rs` | Colours, cards, switches, sliders, buttons |
| `src/update.rs` | Release checks, the capsule format, staging, and the apply helper |
| `src/screens/` | Settings, match history, clips, game review, the recording in progress |
## Where this stands against TODO.txt
@@ -118,6 +119,9 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti
runtime beside the exe. `cargo install cargo-packager --locked && cargo packager --release`.
On the first run the app downloads ffmpeg (`--fetch-ffmpeg` does it from a shell), so clip
export is ready before the first clip. The installer has not been run on a clean VM yet.
10. Updates: the app checks Gitea releases, downloads a capsule, verifies it, and restarts into
a helper that swaps the files. The apply path has been exercised on a scratch folder; it has
not run against a capsule published on Gitea yet.
### The recording screen
@@ -136,6 +140,24 @@ in Match history as a game that never happened, next to one with no champion. Th
the open timeline into the one holding the video (`history::close_stopped`), and "Stop and
delete" removes the clip and both.
## Updates
The app checks the project's Gitea releases about five seconds after startup, then every six
hours. Settings > Advanced has the running version, the result, and the buttons that download a
release and restart to install it. A release carries a `.capsule` asset: a ZIP with
`capsule.json` at the root and every install file under `payload/`. The manifest names each
file with a size and BLAKE3 digest, and the app checks every one before it stages the update.
`../tools/capsule` builds a capsule from the release tree and `packager.toml`, without an
installed copy. `--check-updates` runs the same check from a shell. The restart starts a copy
of the app from the temp folder; that copy waits for the app and daemon to exit, replaces the
files, and starts the new app. A failed replace puts the old files back and writes
`update.log` under the app data directory. `../docs/updates.md` has the format, the release
steps, and the limits.
The capsule is not signed. HTTPS and the per-file digests detect a broken or truncated
download, not a server that serves a matching capsule.
### Known gaps
- Item images are not drawn. Champion portraits download from Data Dragon on first sight and are
+4
View File
@@ -3,6 +3,10 @@
# The app exe is the cargo binary. Everything the daemon needs at run time sits beside it in the
# install root: the daemon, OBS and its data are built into record-daemon/target/release by the
# daemon's own build and copied from there. The app downloads ffmpeg itself on the first export.
# After packaging, build the matching update capsule from the same release files and upload it
# to the Gitea release:
# cargo run --manifest-path ../tools/capsule/Cargo.toml -- --config packager.toml
# See ../docs/updates.md for the format and the release steps.
"$schema" = "https://raw.githubusercontent.com/crabnebula-dev/cargo-packager/main/crates/packager/schema.json"
name = "leaguerecorder"
+116 -4
View File
@@ -2,9 +2,9 @@
use std::path::PathBuf;
use std::sync::mpsc::{Receiver, TryRecvError, channel};
use std::time::Duration;
use std::time::{Duration, Instant};
use rune::tok::type_;
use rune::tok::{radius, type_};
use rune::{ChromeInsets, Cx, El, Key, KeyEvent, Tx, col, el, row, text};
use crate::export::{self, Clip};
@@ -188,6 +188,11 @@ pub struct App {
/// ffmpeg being downloaded on the first run, and the whole percent it last reported.
pub ffmpeg_rx: Option<Receiver<export::FetchEvent>>,
pub ffmpeg_pct: Option<u64>,
/// The release check, the capsule being downloaded, and the one waiting to install.
pub update: crate::update::Updates,
/// When the user pressed Restart and install: the daemon gets a moment to stop before
/// the app quits and the helper replaces its files.
pub quitting_for_update: Option<Instant>,
pub autostart: bool,
pub logs: String,
pub pending_review: bool,
@@ -251,6 +256,8 @@ impl App {
notice: None,
ffmpeg_rx: None,
ffmpeg_pct: None,
update: crate::update::Updates::new(),
quitting_for_update: None,
autostart,
logs: String::new(),
pending_review: false,
@@ -368,6 +375,7 @@ impl App {
},
];
self.form.apply(&settings);
self.update.demo_available();
// The sample sources read as a running process and one that is not, so a snapshot
// shows both states of the chip.
self.processes = settings
@@ -765,6 +773,11 @@ pub fn setup(app: &mut App, waker: rune::Waker) {
app.icons = Some(rune::ImageCache::new(waker.clone()));
app.thumbs = Some(rune::ImageCache::new(waker.clone()));
app.daemon.set_waker(waker.clone());
// A snapshot run reads nothing from the network: the update card keeps its "not checked"
// state unless the scene gives it demo data.
if headless() {
app.update.auto = false;
}
app.refresh_settings();
app.refresh_games();
app.daemon.get_status();
@@ -841,10 +854,65 @@ impl App {
}
}
impl App {
/// Keep the release check moving and turn its results into notices. The worker sends on a
/// channel, so this never waits on the network.
fn poll_updates(&mut self, t: f64) -> bool {
let (news, arrived) = self.update.drain();
let mut changed = arrived;
for news in news {
changed = true;
match news {
crate::update::News::Available(available) => self.notify(format!(
"League Recorder {} is available. Settings > Advanced downloads it.",
available.version
)),
crate::update::News::UpToDate => self.notify("League Recorder is up to date"),
crate::update::News::Ready(staged) => self.notify(format!(
"Update {} is ready. Restart from Settings > Advanced to install it.",
staged.version
)),
crate::update::News::Error(e) => self.notify_error(format!("Update: {e}")),
}
}
changed | self.update.tick(t)
}
/// Download and install the staged capsule. The update helper waits for this process to
/// exit, so the app stays up long enough to ask the daemon to stop and flush that request.
pub fn install_update(&mut self, tx: &mut Tx) {
if self.status.is_recording {
self.notify_error("Stop the recording before installing an update.");
return;
}
match self.update.install() {
Ok(()) => {
self.daemon.shutdown();
self.quitting_for_update = Some(Instant::now());
self.notify("Restarting to install the update...");
tx.wake_after(Duration::from_millis(300));
}
Err(e) => self.notify_error(e),
}
}
}
impl App {
fn handle_poll(&mut self, t: f64, tx: &mut Tx) -> bool {
let mut changed = false;
// A staged update asks the daemon to stop, then quits so the helper can replace the
// files. The short pause is for the shutdown request to leave this process.
if let Some(at) = self.quitting_for_update {
if at.elapsed() >= Duration::from_millis(1500) {
tx.quit();
} else {
tx.wake_after(Duration::from_millis(200));
}
}
changed |= self.poll_updates(t);
// Being full screen is a state of the window, not only of the review: the view drops
// the title bar and the status bar the moment the review asks for it, and the window
// follows in the same frame. Any way out of the review, or off the screen it was on,
@@ -1275,8 +1343,11 @@ fn statusbar(p: Paint, app: &App) -> El {
.key("status-text")
.font(body(11.5))
.color(p.muted()),
)
.child(el().grow(1.0));
);
if let Some(chip) = update_chip(app, p) {
bar = bar.child(chip);
}
bar = bar.child(el().grow(1.0));
if let Some(note) = recording {
bar = bar.child(
text(note)
@@ -1288,6 +1359,47 @@ fn statusbar(p: Paint, app: &App) -> El {
bar
}
/// The status bar's way into a pending update. Accent ink marks it as an action rather than a
/// daemon state; a staged update says it is ready instead of available.
fn update_chip(app: &App, p: Paint) -> Option<El> {
use crate::update::Phase;
let (label, version) = match (&app.update.phase, &app.update.available, &app.update.staged) {
(Phase::Staged, _, Some(staged)) => ("Update ready", staged.version.to_string()),
(Phase::Available | Phase::Failed, Some(available), _) => {
("Update available", available.version.to_string())
}
_ => return None,
};
Some(
el().key("update-chip")
.role("button")
.label(format!("{label}, version {version}"))
.focusable(true)
.h(20.0)
.px(8.0)
.gap(6.0)
.center_y()
.radius(radius::SM)
.fill(p.accent.alpha(0.14))
.border(p.hair, p.accent.alpha(0.32))
.hover(p.accent.alpha(0.22))
.press(p.accent.alpha(0.3))
.on_press_tx(|app: &mut App, tx: &mut Tx| {
app.jump(Screen::Settings);
app.settings_tab = SettingsTab::Advanced;
tx.scroll_to("scroller", 0.0, 0.0);
})
.child(ui::dot(p.accent))
.child(
text(format!("{label} · {version}"))
.key("label")
.font(body(10.5))
.color(p.accent)
.a11y_hidden(),
),
)
}
/// What the back arrow says it returns to.
fn back_label(screen: Screen) -> &'static str {
match screen {
+30
View File
@@ -23,6 +23,7 @@ mod screens;
mod settings;
mod theme;
mod ui;
mod update;
/// Print to the shell that started this app, when there is one.
///
@@ -55,6 +56,20 @@ fn demo_recording(app: &mut app::App) {
fn main() {
attach_console();
// The update helper is this same exe in apply mode: no window and no single-instance lock.
if let Some(index) = std::env::args().position(|arg| arg == "--apply-update") {
let args: Vec<String> = std::env::args().skip(index + 1).collect();
update::run_apply(&args);
return;
}
if std::env::args().any(|arg| arg == "--version") {
println!("leaguerecorder {}", update::current_version());
return;
}
if std::env::args().any(|arg| arg == "--check-updates") {
check_updates();
return;
}
if std::env::args().any(|arg| arg == "--games") {
println!("{} timelines", crate::history::timeline_paths().len());
return;
@@ -232,6 +247,21 @@ fn fetch_ffmpeg() {
}
}
/// `--check-updates`: ask the release list whether a newer capsule exists, then print it.
fn check_updates() {
match update::check(&update::releases_url()) {
Ok(Some(available)) => println!(
"{} is available: {} ({})",
available.version, available.asset, available.url
),
Ok(None) => println!("up to date ({})", update::current_version()),
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
}
}
/// `--probe`: bring the daemon up and print what it answers, then exit. A quick check that the
/// IPC client and the daemon agree without opening a window.
fn probe() {
+92
View File
@@ -930,6 +930,17 @@ fn captioned_field(
))
}
/// The first lines of a release note, enough to say what changed without turning the card
/// into a document.
fn notes_excerpt(notes: &str) -> String {
let mut text = notes.lines().take(6).collect::<Vec<_>>().join("\n");
if let Some((cut, _)) = text.char_indices().nth(700) {
text.truncate(cut);
text.push_str("...");
}
text
}
fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let status_row = |key: &str, label: &'static str, value: String| {
row()
@@ -951,7 +962,88 @@ fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, conte
};
let recording = if app.status.is_recording { "yes" } else { "no" };
let mut update_rows = vec![
status_row("app-version", "Version", app.update.current.to_string()),
status_row("update-status", "Status", app.update.status_text()),
];
if let Some(available) = &app.update.available {
if let Some(published) = available.published.as_deref() {
let shown = chrono::DateTime::parse_from_rfc3339(published)
.map(|at| crate::format::relative_time(at.with_timezone(&chrono::Utc)))
.unwrap_or_else(|_| published.to_string());
update_rows.push(status_row("update-published", "Published", shown));
}
if !available.notes.trim().is_empty() {
update_rows.push(
row()
.key("update-notes")
.w_full()
.px(space::S3)
.py(space::S2)
.child(
text(notes_excerpt(&available.notes))
.key("notes")
.font(body(11.5))
.color(p.muted())
.w_full(),
),
);
}
}
if app.update.can_check() || app.update.can_download() || app.update.can_install() {
let mut actions = row()
.key("update-actions")
.w_full()
.gap(8.0)
.px(space::S3)
.py(space::S2)
.center_y();
if app.update.can_check() {
actions = actions.child(ui::button(
p,
"update-check",
"Check now",
false,
|app: &mut App| app.update.check(true),
));
}
if app.update.can_download() {
let available = app.update.available.as_ref();
let version = available
.map(|available| available.version.to_string())
.unwrap_or_default();
let size = available
.map(|available| format!(" ({})", crate::format::bytes(available.size)))
.unwrap_or_default();
actions = actions.child(ui::button(
p,
"update-download",
&format!("Download {version}{size}"),
true,
|app: &mut App| app.update.download(),
));
}
if app.update.can_install() {
actions = actions.child(ui::button_tx(
p,
"update-install",
"Restart and install",
true,
|app: &mut App, tx: &mut rune::Tx| app.install_update(tx),
));
}
actions = actions.child(ui::button(
p,
"update-folder",
"Open update folder",
false,
|_app: &mut App| crate::daemon::open_folder(&crate::update::updates_dir()),
));
update_rows.push(actions);
}
content
.child(ui::card(p, Some("Updates"), update_rows))
.child(ui::card(
p,
Some("Daemon"),
+1458
View File
File diff suppressed because it is too large. Load diff
+419
View File
@@ -0,0 +1,419 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "arrayvec"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]]
name = "bitflags"
version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "blake3"
version = "1.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"
dependencies = [
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq 0.4.2",
"cpufeatures",
]
[[package]]
name = "bumpalo"
version = "3.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
[[package]]
name = "capsule-format"
version = "0.1.0"
dependencies = [
"blake3",
"semver",
"serde",
"serde_json",
"zip",
]
[[package]]
name = "cc"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "cfg_aliases"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "constant_time_eq"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
[[package]]
name = "constant_time_eq"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9"
dependencies = [
"rustversion",
]
[[package]]
name = "cpufeatures"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
dependencies = [
"cfg-if",
]
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "flate2"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
dependencies = [
"zlib-rs",
]
[[package]]
name = "getrandom"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"r-efi",
"wasm-bindgen",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "js-sys"
version = "0.3.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "nix"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "serde_json"
version = "1.0.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typed-path"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "wasm-bindgen"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
dependencies = [
"cfg-if",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn 3.0.10",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "zeroize"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zip"
version = "9.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cc68510ea7553c30a69c732de5278e94183f68765af6c642dbccefd6ec777e"
dependencies = [
"constant_time_eq 0.6.1",
"crc32fast",
"flate2",
"getrandom",
"indexmap",
"libc",
"memchr",
"nix",
"typed-path",
"windows-sys",
"zeroize",
]
[[package]]
name = "zlib-rs"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
[[package]]
name = "zmij"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "capsule-format"
version = "0.1.0"
edition = "2024"
description = "The .capsule manifest and archive format shared by the app and the release tool"
license = "MIT"
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
semver = "1"
blake3 = "1"
zip = { version = "9.6", default-features = false, features = ["deflate-flate2-zlib-rs"] }
+365
View File
@@ -0,0 +1,365 @@
//! The `.capsule` archive the updater reads and the release tool writes.
//!
//! A capsule is a ZIP with `capsule.json` at the root and every installed file under
//! `payload/`. The manifest names each file with its size and BLAKE3 digest.
use semver::Version;
use std::collections::HashSet;
use std::fs::{self, File};
use std::io::{BufWriter, Read, Write};
use std::path::{Path, PathBuf};
/// The product name a capsule must carry.
pub const PRODUCT: &str = "leaguerecorder";
/// The capsule manifest version this build understands.
pub const CAPSULE_FORMAT: u32 = 1;
/// The target string a capsule is built for, such as `windows-x86_64`.
pub fn target() -> &'static str {
if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
"windows-x86_64"
} else if cfg!(all(target_os = "windows", target_arch = "aarch64")) {
"windows-aarch64"
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
"linux-x86_64"
} else if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
"macos-aarch64"
} else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
"macos-x86_64"
} else {
"unknown"
}
}
/// The app binary's name, which is also the capsule entry.
pub fn default_entry() -> &'static str {
if cfg!(windows) {
"leaguerecorder.exe"
} else {
"leaguerecorder"
}
}
/// One file in a capsule: its path relative to the install root, its size, and its BLAKE3
/// digest in lowercase hex.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct FileEntry {
pub path: String,
pub size: u64,
pub blake3: String,
}
/// `capsule.json`: what a capsule holds and the version it installs.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Manifest {
pub format: u32,
pub product: String,
pub version: String,
pub target: String,
pub entry: String,
#[serde(default)]
pub notes: String,
pub files: Vec<FileEntry>,
/// Files from an older install that the new version no longer ships.
#[serde(default)]
pub remove: Vec<String>,
}
/// The byte for a backslash. Capsule paths use forward slashes only.
const BACKSLASH: u8 = 0x5c;
/// A relative path a capsule may name. Anything that could leave the install root is refused:
/// an absolute path, a drive prefix, a backslash, an empty segment, `.` or `..`.
pub fn safe_relative(path: &str) -> bool {
if path.is_empty()
|| path.starts_with('/')
|| path.as_bytes().contains(&BACKSLASH)
|| path.contains(':')
{
return false;
}
!path
.split('/')
.any(|part| part.is_empty() || part == "." || part == "..")
}
fn hash_file(path: &Path) -> Result<(u64, String), String> {
let mut file = File::open(path).map_err(|e| format!("cannot read {}: {e}", path.display()))?;
let mut hasher = blake3::Hasher::new();
let mut size = 0u64;
let mut buf = [0u8; 64 * 1024];
loop {
let read = file
.read(&mut buf)
.map_err(|e| format!("cannot read {}: {e}", path.display()))?;
if read == 0 {
break;
}
size += read as u64;
hasher.update(&buf[..read]);
}
Ok((size, hasher.finalize().to_hex().to_string()))
}
impl Manifest {
/// Check the parts that do not depend on the running version.
pub fn validate(&self) -> Result<(), String> {
if self.format != CAPSULE_FORMAT {
return Err(format!(
"the capsule has format {}, and this app reads {CAPSULE_FORMAT}",
self.format
));
}
if self.product != PRODUCT {
return Err(format!(
"the capsule is for {}, not {PRODUCT}",
self.product
));
}
if self.target != target() {
return Err(format!(
"the capsule is built for {}, and this app runs on {}",
self.target,
target()
));
}
if self.files.is_empty() {
return Err("the capsule holds no files".into());
}
if !safe_relative(&self.entry) {
return Err(format!(
"the capsule entry {:?} is not a plain path",
self.entry
));
}
let mut seen = HashSet::new();
for file in &self.files {
if !safe_relative(&file.path) {
return Err(format!(
"the capsule names {:?}, which is not a plain path under the install folder",
file.path
));
}
if !seen.insert(file.path.as_str()) {
return Err(format!("the capsule names {} twice", file.path));
}
if file.blake3.len() != 64 || !file.blake3.chars().all(|c| c.is_ascii_hexdigit()) {
return Err(format!("{} has no BLAKE3 digest", file.path));
}
}
if !seen.contains(self.entry.as_str()) {
return Err(format!(
"the capsule entry {} is not one of its files",
self.entry
));
}
for path in &self.remove {
if !safe_relative(path) {
return Err(format!(
"the capsule asks to remove {path:?}, which is not a plain path under the install folder"
));
}
if seen.contains(path.as_str()) {
return Err(format!("the capsule installs and removes {path}"));
}
}
Ok(())
}
/// The version the capsule installs.
pub fn version(&self) -> Result<Version, String> {
Version::parse(&self.version)
.map_err(|e| format!("the capsule version {:?} does not parse: {e}", self.version))
}
}
/// Pack the install folder `dir` into `out` for `version`.
pub fn pack(dir: &Path, out: &Path, version: &str) -> Result<Manifest, String> {
let version = Version::parse(version)
.map_err(|e| format!("the version {version:?} does not parse: {e}"))?;
if !dir.join(default_entry()).is_file() {
return Err(format!("{} has no {}", dir.display(), default_entry()));
}
let mut paths = Vec::new();
collect_files(dir, out, &mut paths)?;
paths.sort();
let mut files = Vec::new();
for path in &paths {
let relative = path
.strip_prefix(dir)
.map_err(|_| format!("{} is not under {}", path.display(), dir.display()))?;
let relative = relative
.components()
.filter_map(|part| match part {
std::path::Component::Normal(part) => Some(part.to_string_lossy().to_string()),
_ => None,
})
.collect::<Vec<_>>()
.join("/");
let (size, blake3) = hash_file(path)?;
files.push(FileEntry {
path: relative,
size,
blake3,
});
}
if files.is_empty() {
return Err(format!("{} holds no files", dir.display()));
}
let manifest = Manifest {
format: CAPSULE_FORMAT,
product: PRODUCT.into(),
version: version.to_string(),
target: target().into(),
entry: default_entry().into(),
notes: String::new(),
files,
remove: Vec::new(),
};
manifest.validate()?;
if let Some(parent) = out.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("cannot create {}: {e}", parent.display()))?;
}
let part = out.with_extension("capsule.part");
let file = File::create(&part).map_err(|e| format!("cannot write {}: {e}", part.display()))?;
let mut zip = zip::ZipWriter::new(BufWriter::new(file));
let options = zip::write::SimpleFileOptions::default()
.compression_method(zip::CompressionMethod::Deflated);
zip.start_file("capsule.json", options)
.map_err(|e| format!("cannot write capsule.json: {e}"))?;
let text = serde_json::to_vec_pretty(&manifest)
.map_err(|e| format!("the manifest did not serialize: {e}"))?;
zip.write_all(&text)
.map_err(|e| format!("cannot write capsule.json: {e}"))?;
for file in &manifest.files {
let path = dir.join(&file.path);
zip.start_file(format!("payload/{}", file.path), options)
.map_err(|e| format!("cannot add {}: {e}", file.path))?;
let mut input =
File::open(&path).map_err(|e| format!("cannot read {}: {e}", path.display()))?;
std::io::copy(&mut input, &mut zip)
.map_err(|e| format!("cannot add {}: {e}", file.path))?;
}
let mut writer = zip
.finish()
.map_err(|e| format!("cannot finish the capsule: {e}"))?;
writer
.flush()
.map_err(|e| format!("cannot finish {}: {e}", part.display()))?;
drop(writer);
fs::rename(&part, out).map_err(|e| format!("cannot write {}: {e}", out.display()))?;
Ok(manifest)
}
fn collect_files(dir: &Path, out: &Path, files: &mut Vec<PathBuf>) -> Result<(), String> {
let entries = fs::read_dir(dir).map_err(|e| format!("cannot read {}: {e}", dir.display()))?;
for entry in entries.flatten() {
let path = entry.path();
if path == out || path == out.with_extension("capsule.part") {
continue;
}
let kind = entry
.file_type()
.map_err(|e| format!("cannot read {}: {e}", path.display()))?;
if kind.is_dir() {
collect_files(&path, out, files)?;
} else if kind.is_file() {
let name = path
.file_name()
.map(|name| name.to_string_lossy().to_ascii_lowercase())
.unwrap_or_default();
if name.ends_with(".capsule") || name.ends_with(".lrnew") || name.ends_with(".lrold") {
continue;
}
files.push(path);
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
fn digest(bytes: &[u8]) -> String {
blake3::hash(bytes).to_hex().to_string()
}
fn manifest(version: &str, files: &[(&str, &[u8])]) -> Manifest {
Manifest {
format: CAPSULE_FORMAT,
product: PRODUCT.into(),
version: version.into(),
target: target().into(),
entry: default_entry().into(),
notes: String::new(),
files: files
.iter()
.map(|(path, bytes)| FileEntry {
path: (*path).into(),
size: bytes.len() as u64,
blake3: digest(bytes),
})
.collect(),
remove: Vec::new(),
}
}
#[test]
fn capsule_paths_must_stay_under_the_install_folder() {
for bad in [
"../evil.exe",
"/etc/passwd",
"a/../../b",
"C:/Windows/system32",
"a//b",
"./a",
"",
] {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.files[0].path = bad.into();
assert!(manifest.validate().is_err(), "{bad:?} was accepted");
}
assert!(!safe_relative(&format!("a{}b", char::from(0x5cu8))));
}
#[test]
fn the_entry_must_be_one_of_the_files() {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.entry = "other.exe".into();
assert!(manifest.validate().is_err());
}
#[test]
fn a_capsule_with_the_wrong_target_is_refused() {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.target = "plan9-sparc".into();
assert!(manifest.validate().is_err());
}
#[test]
fn a_folder_packs_with_a_manifest_that_names_every_file() {
let root = std::env::temp_dir().join(format!("capsule-format-pack-{}", std::process::id()));
let payload = root.join("payload");
fs::create_dir_all(payload.join("data")).unwrap();
fs::write(payload.join(default_entry()), b"app").unwrap();
fs::write(payload.join("data").join("file.bin"), b"some data").unwrap();
let manifest = pack(&payload, &root.join("release.capsule"), "0.4.0").unwrap();
assert_eq!(manifest.files.len(), 2);
assert_eq!(manifest.version, "0.4.0");
assert!(manifest.validate().is_ok());
let file = File::open(root.join("release.capsule")).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();
assert!(archive.by_name("capsule.json").is_ok());
assert!(archive.by_name("payload/data/file.bin").is_ok());
drop(archive);
let _ = fs::remove_dir_all(&root);
}
}
+152
View File
@@ -0,0 +1,152 @@
# Updates
The app checks the project's Gitea release list, downloads a `.capsule` asset, verifies every
file in it, and replaces the install with a small helper process.
## The check
`src/update.rs` reads:
```
https://git.vhaudiquet.fr/api/v1/repos/vhaudiquet/leaguerecorder/releases?limit=60
```
The first automatic check runs about five seconds after startup. Later ones run every six hours,
only while the app is open. The check runs on its own thread, so the window never waits on the
network. A manual check is in Settings > Advanced, under Updates. When a release is waiting,
the status bar carries a yellow **Update available** chip beside the daemon state; it opens
Settings > Advanced. The chip turns into **Update ready** once the capsule is staged.
A release is offered when all of these hold:
- it is not a draft;
- its tag parses as a version, with or without a leading `v`;
- the version is newer than the running build;
- it has an asset whose name ends in `.capsule`.
A stable release beats a newer prerelease. The project currently marks every release as a
prerelease at Gitea, so the check falls back to prereleases when that is all it finds.
`--check-updates` runs the same check from a shell and prints the result.
## The capsule
A capsule is a ZIP file with this layout:
```
capsule.json
payload/leaguerecorder.exe
payload/record-daemon.exe
payload/...
```
`capsule.json` looks like this:
```json
{
"format": 1,
"product": "leaguerecorder",
"version": "0.4.0",
"target": "windows-x86_64",
"entry": "leaguerecorder.exe",
"notes": "",
"files": [
{
"path": "leaguerecorder.exe",
"size": 67496448,
"blake3": "5a3c..."
}
],
"remove": []
}
```
`path` is relative to the install root and always uses forward slashes. `blake3` is the
lowercase hex digest of the file. `remove` names files from an older install that the new
version no longer ships; it is optional and empty by default.
The downloader refuses a capsule when:
- the ZIP cannot be read, or `capsule.json` is missing or malformed;
- the manifest format, product, or target does not match this build;
- any path is absolute, contains `..`, a backslash, a drive prefix, or an empty segment;
- a file in `payload/` is not named in `capsule.json`;
- a size or BLAKE3 digest does not match;
- the version is not newer than the running build.
The extracted payload is kept under the app data directory in `updates/<version>/`. A
complete stage is found again on the next start, so an update downloaded before a restart can
still be installed.
## Building a capsule
The release tool builds the install tree from `packager.toml` and packs it. It does not need an
installed copy, and the app has no packaging mode.
Build the release, then run the tool from `app/`:
```sh
cargo packager --release
cargo run --manifest-path ../tools/capsule/Cargo.toml -- --config packager.toml
```
`cargo packager` builds both programs and writes the NSIS installer. The tool reads the same
release binaries, so the capsule carries the files the installer puts down. It writes
`dist/leaguerecorder-<version>-windows-x86_64.capsule`, using the version in `packager.toml`.
The tool also checks that `Cargo.toml` carries that version, so a release cannot pack one
version's files under another version's manifest.
Pass `--out <file>` to write somewhere else. The tool also accepts
`--folder <install-root> --version <x.y.z> --out <file>` for a tree that is already assembled.
The builder skips `.capsule`, `.lrnew`, and `.lrold` files. It writes an empty `remove` list. If
a release drops a file, unzip the capsule, add the path to `remove` in `capsule.json`, and zip
it again with `capsule.json` at the root. The payload hashes stay valid.
Upload the `.capsule` as an asset on the Gitea release whose tag matches the version. The
manifest version and the tag should name the same release. The check compares tags, and staging
compares the manifest. Put the target in the asset name (`windows-x86_64`) so a machine picks
the right one when a release carries several builds.
## Installing
Press **Download** in Settings > Advanced. The app downloads the capsule, verifies it, and leaves
it staged. Press **Restart and install**.
The app starts a copy of itself from the temp folder, asks the daemon to stop, then quits. The
copy is started with:
```
--apply-update <staged-folder> <install-folder> <app-pid>
```
The helper waits for that process to exit, then:
1. copies each new file beside its target as `<name>.lrnew`;
2. moves each old file aside as `<name>.lrold`, then renames the new file into place;
3. removes the files named in `remove`;
4. deletes the `.lrold` copies and the staging folder;
5. starts the installed `leaguerecorder.exe`.
A failure at any step puts the old files back, starts the old app, and writes the reason to
`updates/update.log` in the app data directory. On Windows that is
`%LOCALAPPDATA%\leaguerecorder\leaguerecorder\data\updates`. If the daemon still holds a file,
the whole install is retried once a second for 30 seconds. The Open update folder button in the
same card opens that folder.
## What this does not protect against
The app reads the release page over HTTPS and checks each file against the manifest inside the
same capsule. That detects a broken or truncated download. It does not detect a server that
serves a matching capsule and manifest, because the manifest is not signed.
Signing the exe and the capsule remains a separate task. Until then, a compromised Gitea account
or DNS can install arbitrary code, and Windows SmartScreen still warns on the first run.
## Environment variables
| Name | Use |
| --- | --- |
| `LEAGUERECORDER_RELEASES_URL` | Read a different release list, such as a mirror or a test server. |
| `LEAGUERECORDER_UPDATE_DIR` | Put staged capsules and `update.log` somewhere else. |
| `LEAGUERECORDER_NO_UPDATE_CHECK` | Turn the automatic check off for this process. |
+489
View File
@@ -0,0 +1,489 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "arrayvec"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]]
name = "bitflags"
version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "blake3"
version = "1.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"
dependencies = [
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq 0.4.2",
"cpufeatures",
]
[[package]]
name = "bumpalo"
version = "3.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
[[package]]
name = "capsule-format"
version = "0.1.0"
dependencies = [
"blake3",
"semver",
"serde",
"serde_json",
"zip",
]
[[package]]
name = "cc"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "cfg_aliases"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "constant_time_eq"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
[[package]]
name = "constant_time_eq"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9"
dependencies = [
"rustversion",
]
[[package]]
name = "cpufeatures"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
dependencies = [
"cfg-if",
]
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "flate2"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
dependencies = [
"zlib-rs",
]
[[package]]
name = "getrandom"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"r-efi",
"wasm-bindgen",
]
[[package]]
name = "glob"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "js-sys"
version = "0.3.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "make-capsule"
version = "0.1.0"
dependencies = [
"capsule-format",
"glob",
"serde",
"toml",
]
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "nix"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "serde_json"
version = "1.0.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "serde_spanned"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782"
dependencies = [
"serde_core",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "toml"
version = "1.2.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5426cb1b964690d913f6c5c1a1ae0b42f428ec506bb4d452876d7a209c9bca3b"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "1.1.3+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_parser"
version = "1.1.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.2.0+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a"
[[package]]
name = "typed-path"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "wasm-bindgen"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
dependencies = [
"cfg-if",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn 3.0.10",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "winnow"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
[[package]]
name = "zeroize"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zip"
version = "9.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cc68510ea7553c30a69c732de5278e94183f68765af6c642dbccefd6ec777e"
dependencies = [
"constant_time_eq 0.6.1",
"crc32fast",
"flate2",
"getrandom",
"indexmap",
"libc",
"memchr",
"nix",
"typed-path",
"windows-sys",
"zeroize",
]
[[package]]
name = "zlib-rs"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
[[package]]
name = "zmij"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "make-capsule"
version = "0.1.0"
edition = "2024"
description = "Build a .capsule update archive from the release build"
license = "MIT"
[dependencies]
capsule-format = { path = "../../crates/capsule-format" }
serde = { version = "1", features = ["derive"] }
toml = "1"
glob = "0.3"
+336
View File
@@ -0,0 +1,336 @@
//! Build a `.capsule` update archive from the release build.
//!
//! The install tree comes from `packager.toml`, so the capsule carries exactly the files the
//! installer puts down. No installed copy of the app is needed.
use serde::Deserialize;
use std::fs;
use std::path::{Path, PathBuf};
#[derive(Debug, Deserialize)]
struct Config {
version: String,
#[serde(rename = "binaries-dir", default)]
binaries_dir: Option<String>,
#[serde(default)]
binaries: Vec<Binary>,
#[serde(default)]
resources: Vec<Resource>,
#[serde(rename = "out-dir", default)]
out_dir: Option<String>,
}
#[derive(Debug, Deserialize)]
struct Binary {
path: String,
}
#[derive(Debug, Deserialize)]
struct Resource {
src: String,
#[serde(default)]
target: String,
}
fn main() {
if let Err(e) = run(std::env::args().skip(1).collect()) {
eprintln!("{e}");
std::process::exit(1);
}
}
fn run(args: Vec<String>) -> Result<(), String> {
let mut config = None;
let mut folder = None;
let mut out = None;
let mut version = None;
let mut args = args.into_iter();
while let Some(arg) = args.next() {
match arg.as_str() {
"--config" => config = Some(args.next().ok_or("--config needs a path")?),
"--folder" => folder = Some(args.next().ok_or("--folder needs a path")?),
"--out" => out = Some(args.next().ok_or("--out needs a path")?),
"--version" => version = Some(args.next().ok_or("--version needs a version")?),
"-h" | "--help" => {
println!("{}", usage());
return Ok(());
}
other => return Err(format!("unknown argument {other:?}\n\n{}", usage())),
}
}
match (config, folder) {
(Some(_), Some(_)) => Err("use --config or --folder, not both".into()),
(None, None) => Err(usage().into()),
(Some(config), None) => from_config(Path::new(&config), version, out),
(None, Some(folder)) => {
let version = version.ok_or("--version is required with --folder")?;
let out = out.ok_or("--out is required with --folder")?;
let manifest = capsule_format::pack(Path::new(&folder), Path::new(&out), &version)?;
println!(
"{}: {} files for {} on {}",
out,
manifest.files.len(),
manifest.version,
manifest.target
);
Ok(())
}
}
}
fn from_config(
config_path: &Path,
version: Option<String>,
out: Option<String>,
) -> Result<(), String> {
let text = fs::read_to_string(config_path)
.map_err(|e| format!("cannot read {}: {e}", config_path.display()))?;
let config: Config =
toml::from_str(&text).map_err(|e| format!("cannot read {}: {e}", config_path.display()))?;
if let Some(version) = version
&& version != config.version
{
return Err(format!(
"--version says {version}, and {} says {}; bump the file or drop the flag",
config_path.display(),
config.version
));
}
let config_dir = config_path.parent().unwrap_or(Path::new("."));
if let Some(cargo) = cargo_version(config_dir)
&& cargo != config.version
{
return Err(format!(
"{} says {cargo}, and {} says {}; bump both",
config_dir.join("Cargo.toml").display(),
config_path.display(),
config.version
));
}
let out = out.map(PathBuf::from).unwrap_or_else(|| {
config_dir
.join(config.out_dir.as_deref().unwrap_or("dist"))
.join(format!(
"{}-{}-{}.capsule",
capsule_format::PRODUCT,
config.version,
capsule_format::target()
))
});
let stage = std::env::temp_dir().join(format!("make-capsule-{}", std::process::id()));
if stage.exists() {
fs::remove_dir_all(&stage).map_err(|e| format!("cannot clear {}: {e}", stage.display()))?;
}
fs::create_dir_all(&stage).map_err(|e| format!("cannot create {}: {e}", stage.display()))?;
let result = (|| {
stage_config(&config, config_dir, &stage)?;
let manifest = capsule_format::pack(&stage, &out, &config.version)?;
println!(
"{}: {} files for {} on {}",
out.display(),
manifest.files.len(),
manifest.version,
manifest.target
);
Ok(())
})();
let _ = fs::remove_dir_all(&stage);
result
}
fn cargo_version(dir: &Path) -> Option<String> {
let text = fs::read_to_string(dir.join("Cargo.toml")).ok()?;
let value: toml::Value = toml::from_str(&text).ok()?;
value
.get("package")?
.get("version")?
.as_str()
.map(str::to_string)
}
fn usage() -> &'static str {
"usage:\n \
make-capsule --config <packager.toml> [--out <file>]\n \
make-capsule --folder <install-root> --version <x.y.z> --out <file>"
}
fn stage_config(config: &Config, dir: &Path, stage: &Path) -> Result<(), String> {
let binaries_dir = dir.join(config.binaries_dir.as_deref().unwrap_or("."));
for binary in &config.binaries {
let source = with_exe(binaries_dir.join(&binary.path));
copy_file(&source, &stage.join(file_name(&source)?))?;
}
for resource in &config.resources {
copy_resource(dir, resource, stage)?;
}
Ok(())
}
fn with_exe(path: PathBuf) -> PathBuf {
if cfg!(windows) && path.extension().is_none() {
path.with_extension("exe")
} else {
path
}
}
fn copy_resource(dir: &Path, resource: &Resource, stage: &Path) -> Result<(), String> {
let source = dir.join(&resource.src);
let pattern = source.to_string_lossy().replace(char::from(0x5c), "/");
if pattern.contains(['*', '?', '[']) {
let mut found = false;
for path in
glob::glob(&pattern).map_err(|e| format!("{} is not a glob: {e}", source.display()))?
{
let path = path.map_err(|e| format!("cannot read {}: {e}", source.display()))?;
if path.is_file() {
found = true;
let target = target_dir(stage, &resource.target)?;
copy_file(&path, &target.join(file_name(&path)?))?;
}
}
if !found {
return Err(format!("{} matched no files", source.display()));
}
return Ok(());
}
if source.is_dir() {
copy_dir(&source, &target_dir(stage, &resource.target)?)
} else if source.is_file() {
let target = if resource.target.is_empty()
|| resource.target == "."
|| resource.target.ends_with('/')
|| resource.target.ends_with(char::from(0x5c))
{
target_dir(stage, &resource.target)?.join(file_name(&source)?)
} else {
stage.join(&resource.target)
};
copy_file(&source, &target)
} else {
Err(format!("{} does not exist", source.display()))
}
}
fn target_dir(stage: &Path, target: &str) -> Result<PathBuf, String> {
if target.is_empty() || target == "." {
return Ok(stage.to_path_buf());
}
if target.starts_with('/')
|| target.starts_with(char::from(0x5c))
|| target.contains(':')
|| target
.split(['/', char::from(0x5c)])
.any(|part| part == "..")
{
return Err(format!("resource target {target:?} is not a relative path"));
}
Ok(stage.join(target))
}
fn copy_dir(from: &Path, to: &Path) -> Result<(), String> {
fs::create_dir_all(to).map_err(|e| format!("cannot create {}: {e}", to.display()))?;
let entries = fs::read_dir(from).map_err(|e| format!("cannot read {}: {e}", from.display()))?;
for entry in entries {
let entry = entry.map_err(|e| format!("cannot read {}: {e}", from.display()))?;
let path = entry.path();
let dest = to.join(entry.file_name());
if path.is_dir() {
copy_dir(&path, &dest)?;
} else if path.is_file() {
copy_file(&path, &dest)?;
}
}
Ok(())
}
fn copy_file(from: &Path, to: &Path) -> Result<(), String> {
if let Some(parent) = to.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("cannot create {}: {e}", parent.display()))?;
}
fs::copy(from, to)
.map(|_| ())
.map_err(|e| format!("cannot copy {} to {}: {e}", from.display(), to.display()))
}
fn file_name(path: &Path) -> Result<std::ffi::OsString, String> {
path.file_name()
.map(|name| name.to_os_string())
.ok_or_else(|| format!("{} has no file name", path.display()))
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
fn temp_dir(tag: &str) -> PathBuf {
let dir =
std::env::temp_dir().join(format!("make-capsule-test-{tag}-{}", std::process::id()));
let _ = fs::remove_dir_all(&dir);
fs::create_dir_all(&dir).unwrap();
dir
}
#[test]
fn the_release_tree_follows_the_packager_entries() {
let root = temp_dir("stage");
let app = root.join("app");
fs::create_dir_all(app.join("target/release")).unwrap();
fs::write(app.join("target/release/leaguerecorder.exe"), b"app").unwrap();
fs::create_dir_all(app.join("vendor/vcruntime")).unwrap();
fs::write(app.join("vendor/vcruntime/vcruntime140.dll"), b"runtime").unwrap();
let daemon = root.join("daemon/target/release");
fs::create_dir_all(daemon.join("data")).unwrap();
fs::create_dir_all(daemon.join("obs-plugins")).unwrap();
fs::write(daemon.join("record-daemon.exe"), b"daemon").unwrap();
fs::write(daemon.join("libobs.dll"), b"dll").unwrap();
fs::write(daemon.join("data/area.effect"), b"effect").unwrap();
fs::write(daemon.join("obs-plugins/plugin.dll"), b"plugin").unwrap();
let config = Config {
version: "0.4.0".into(),
binaries_dir: Some("app/target/release".into()),
binaries: vec![Binary {
path: "leaguerecorder".into(),
}],
resources: vec![
Resource {
src: "daemon/target/release/record-daemon.exe".into(),
target: ".".into(),
},
Resource {
src: "daemon/target/release/*.dll".into(),
target: ".".into(),
},
Resource {
src: "daemon/target/release/data".into(),
target: "data".into(),
},
Resource {
src: "daemon/target/release/obs-plugins".into(),
target: "obs-plugins".into(),
},
Resource {
src: "app/vendor/vcruntime/*.dll".into(),
target: ".".into(),
},
],
out_dir: None,
};
let stage = root.join("stage-out");
stage_config(&config, &root, &stage).unwrap();
assert!(stage.join("leaguerecorder.exe").is_file());
assert!(stage.join("record-daemon.exe").is_file());
assert!(stage.join("libobs.dll").is_file());
assert!(stage.join("vcruntime140.dll").is_file());
assert!(stage.join("data/area.effect").is_file());
assert!(stage.join("obs-plugins/plugin.dll").is_file());
let _ = fs::remove_dir_all(&root);
}
}