Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions docs/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ One `GET api.github.com/repos/{owner}/{repo}/releases/latest` (60 an hour per IP
size and `digest: sha256:…`. Drafts and pre-releases are refused; a release not newer than the running
version is never offered (no downgrade). The download uses that release's own URLs.

Two witnesses to the file, both over TLS: the workflow's `SHA256SUMS.txt` and GitHub's digest computed on
Two witnesses to the file, both over TLS: the workflow's `SHA256SUMS.txt` and, when GitHub gives one (it
computes it for every asset uploaded since 2025, this repository's included), its digest computed on
upload. They must agree with each other and with the downloaded bytes, else the file is deleted. **What this
does not defend against:** a compromised account or workflow — the hash proves the file is the one
published, not that it is honest. Verifying the build attestation (Sigstore) inside the application was
Expand All @@ -40,7 +41,13 @@ the Web, so SmartScreen does not see it: the hash is what vouches for it.

TLS: rustls (through `ureq`), certificates checked against the OS's trust store (`rustls-platform-verifier`:
a corporate proxy's own root is accepted like in a browser), Windows' proxy settings read
(`win-system-proxy`). A generic `User-Agent` with the version, nothing about the user.
(`win-system-proxy`). A generic `User-Agent` with the version, nothing about the user. The trade, said
plainly: a TLS-inspecting proxy whose root the machine trusts can replace both the checksums and the file,
and the hash then proves nothing against it — as for any download on that machine.

GitHub allows 60 unauthenticated API requests an hour per IP address, shared by everyone behind it (a
household, an office, a carrier's NAT). A click-only check rarely comes near it; when it does, the window
says so and when the limit resets (`x-ratelimit-reset`), rather than "GitHub answered 403".

## The swap

Expand All @@ -51,13 +58,22 @@ a separate process can rename it once it has exited:
copy. Creating it is also the test that the folder can be written; a read-only folder (Program Files)
fails here and the window offers the release page.
2. *Restart now* writes `updates\pending.txt` (the version being installed) in the data folder, starts a
hidden Windows PowerShell (`-NoProfile -NonInteractive -WindowStyle Hidden`, `CREATE_NO_WINDOW`) and
closes the window the normal way.
3. The script waits for this exact process (`Wait-Process -Id <pid> -Timeout 30`), removes an older `.old`,
renames `<exe>` to `<exe>.old` and `<exe>.new` to `<exe>` — each step retried up to 10 times, 0.5 s
apart, because OneDrive or an antivirus may hold a file just written — then starts `<exe>`.
4. On any failure, it writes the reason to `updates\result.txt`, puts `<exe>.old` back if `<exe>` is gone,
and starts the executable again.
hidden Windows PowerShell by its absolute path (`%SystemRoot%\System32\WindowsPowerShell\v1.0`, never
by name: Windows searches the application's own folder first, and a `powershell.exe` dropped in a
Downloads folder would run; winget likewise) with `-NoProfile -NonInteractive -WindowStyle Hidden` and
`CREATE_NO_WINDOW`, and closes the window the normal way. The window warns first when videos are in the
queue: the queue lives in memory and does not survive the restart.
3. The script waits for this process (`Wait-Process -Id <pid> -Timeout 30`, only while that id is still
this program by name: an id can be reused), removes an older `.old`, renames `<exe>` to `<exe>.old`
(retried 10 times, 0.5 s apart) and `<exe>.new` to `<exe>` (retried for 30 s: OneDrive may still be
uploading the new file — think of an executable on a Desktop that Windows 11 backs up), then starts
`<exe>`. If the application did not close in 30 s, nothing is touched and `result.txt` says so.
4. On any failure, each recovery step runs in its own `try`, restore first: if the old executable was
moved, the new one is set aside (back to `.new`) and the old one put back (retried); then the executable
in place is started; `result.txt` is written last, so failing to write it never skips the restore. A new
executable that is in place but refuses to start (an antivirus) is set aside the same way. The script a
version carries is the one that installs the next: these paths were reviewed by GameModeExecutor's
session on 2026-11-24, before 1.1.0 froze them.
5. The next start compares `pending.txt` with its own version: equal, *Updated to X* and the `.old` goes;
different, the failure and `result.txt`'s reason, and the unused `.new` goes. A `.new` left without a
pending update (a download never installed) is deleted at start.
Expand All @@ -84,8 +100,21 @@ newer:
| *Restart now* | the window closed; the swap left `quick-video-transcoder.exe` with the published 1.0.0's SHA-256 (`a55a5f19…05ee02`) and the debug build as `.old`; 1.0.0 started and came to the foreground |
| Rollback | the same, with `.old` held open by another process: the removal failed ten times, the catch wrote *The process cannot access the file…* to `result.txt`, the executable stayed in place and restarted, and its next start showed the failure and the reason |

After the review's changes, 2026-11-24, the same way (`review test [it's]`):

| Case | Result |
| --- | --- |
| Normal update | 1.0.0 in place (`a55a5f19…`), the previous build as `.old`, 1.0.0 running |
| The new file refuses to start (the verified download replaced by a non-program just before *Restart now*) | `Start-Process` failed (*not a valid application for this OS platform*); the script set the new file aside, put the old executable back, started it; the next start showed the reason and deleted the rejected file — no `.old`, no `.new` left |

Not measured: behind a proxy; the *Updated to* message from a real release pair (1.0.0 does not read
`pending.txt` — it waits for 1.1.0 → 1.2.0); OneDrive's locks (the retries are there for them).
`pending.txt` — it waits for 1.1.0 → 1.2.0); OneDrive's locks (the retries are there for them); the
focus after a slow close (near the 30 s wait, the window may only flash in the taskbar).

Known rare cases, left as they are: a second window (when the single instance could not be claimed) still
running the old image keeps `.old` held, and the next update fails safely until it is closed; that second
window's start may also delete a download the first one is making (`settle` tidies a `.new` with no pending
update), and the swap then fails safely.

## Files written

Expand Down
14 changes: 14 additions & 0 deletions i18n/en/quick_video_transcoder.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,17 @@ update-fault-not-verified = The downloaded file does not match the published one
update-fault-cannot-write = This copy's folder cannot be written. Download the new version from the release page instead.
# $detail: why the install failed (technical, English: a Windows or PowerShell message).
update-fault-install = The update could not be installed: { $detail }
# GitHub refused because its hourly limit (60 checks per internet connection, shared by everyone on it) is
# reached. $minutes: minutes until it resets.
update-fault-rate-limited =
GitHub limits checks to 60 an hour per internet connection, and that limit is reached. Try again in { $minutes ->
[one] { NUM($minutes) } minute
*[other] { NUM($minutes) } minutes
}.
update-fault-rate-limited-later = GitHub limits checks to 60 an hour per internet connection, and that limit is reached. Try again later.
# Under Restart now when videos are in the queue: the queue is not kept across the restart.
update-queue-cleared =
Restarting clears the queue ({ $count ->
[one] { NUM($count) } video
*[other] { NUM($count) } videos
}): their trims and settings are not kept.
11 changes: 11 additions & 0 deletions i18n/fr/quick_video_transcoder.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,14 @@ update-fault-unexpected = La réponse de GitHub ne correspond pas à ce que cett
update-fault-not-verified = Le fichier téléchargé ne correspond pas au fichier publié : il a été supprimé. Réessayez.
update-fault-cannot-write = Le dossier de cette copie n’est pas modifiable. Téléchargez plutôt la nouvelle version depuis sa page.
update-fault-install = La mise à jour n’a pas pu être installée : { $detail }
update-fault-rate-limited =
GitHub limite les vérifications à 60 par heure et par connexion Internet, et cette limite est atteinte. Réessayez dans { $minutes ->
[one] { NUM($minutes) } minute
*[other] { NUM($minutes) } minutes
}.
update-fault-rate-limited-later = GitHub limite les vérifications à 60 par heure et par connexion Internet, et cette limite est atteinte. Réessayez plus tard.
update-queue-cleared =
Le redémarrage vide la file d’attente ({ $count ->
[one] { NUM($count) } vidéo
*[other] { NUM($count) } vidéos
}) : les découpes et réglages ne sont pas conservés.
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ impl eframe::App for TranscoderApp {
self.profiles_window(&ctx);
self.about_window(&ctx);
self.update_window(&ctx);
if self.close_for_update {
if std::mem::take(&mut self.close_for_update) {
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
}
self.ffmpeg_window(&ctx);
Expand Down
19 changes: 17 additions & 2 deletions src/app/update_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl TranscoderApp {
let mut open = true;
let mut event = None;
let encoding = self.encoding();
let queued = self.queue.jobs.len();
let phase = self.updater.machine.phase().clone();
egui::Window::new(crate::tr!("update-title"))
.id(egui::Id::unique("update window"))
Expand All @@ -166,7 +167,7 @@ impl TranscoderApp {
version = running_version().to_string()
));
ui.add_space(8.0);
event = phase_ui(ui, &phase, encoding);
event = phase_ui(ui, &phase, encoding, queued);
});
if let Some(event) = event {
self.send_update(event);
Expand All @@ -179,7 +180,7 @@ impl TranscoderApp {
}

/// The body of the window for a phase; returns the event a button sent.
fn phase_ui(ui: &mut egui::Ui, phase: &Phase, encoding: bool) -> Option<Event> {
fn phase_ui(ui: &mut egui::Ui, phase: &Phase, encoding: bool, queued: usize) -> Option<Event> {
let mut event = None;
match phase {
Phase::Idle => {
Expand Down Expand Up @@ -243,6 +244,16 @@ fn phase_ui(ui: &mut egui::Ui, phase: &Phase, encoding: bool) -> Option<Event> {
.small()
.weak(),
);
} else if queued > 0 {
// The queue lives in memory only: trims and settings of queued videos are not kept.
ui.label(
egui::RichText::new(crate::tr!(
"update-queue-cleared",
count = (queued as f64)
))
.small()
.color(ui.visuals().warn_fg_color),
);
}
if restart.clicked() {
event = Some(Event::RestartAsked);
Expand Down Expand Up @@ -355,6 +366,10 @@ fn fault_text(fault: &Fault) -> String {
match fault {
Fault::NoConnection(_) => crate::tr!("update-fault-connection"),
Fault::Status(status) => crate::tr!("update-fault-status", status = status.to_string()),
Fault::RateLimited(Some(minutes)) => {
crate::tr!("update-fault-rate-limited", minutes = (*minutes as f64))
}
Fault::RateLimited(None) => crate::tr!("update-fault-rate-limited-later"),
Fault::Unexpected(_) => crate::tr!("update-fault-unexpected"),
Fault::NotVerified => crate::tr!("update-fault-not-verified"),
Fault::CannotWrite(_) => crate::tr!("update-fault-cannot-write"),
Expand Down
33 changes: 29 additions & 4 deletions src/ffmpeg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
/// The `PATH` read from the settings by [`refresh_path`], when the inherited one lacks FFmpeg.
static FRESH_PATH: RwLock<Option<OsString>> = RwLock::new(None);

/// Windows PowerShell by its absolute path, without a console window. Never looked up by name: Windows
/// searches the application's own folder before System32, so a `powershell.exe` dropped beside this
/// executable (a Downloads folder) would run instead (found in review, 2026-11-24).
pub fn powershell() -> Command {
let root = std::env::var_os("SystemRoot").unwrap_or_else(|| "C:\\Windows".into());
let path = std::path::Path::new(&root)
.join("System32")
.join("WindowsPowerShell")
.join("v1.0")
.join("powershell.exe");
tool(&path.to_string_lossy())
}

/// winget by its absolute path (the App Installer's alias in the user's WindowsApps folder), for the
/// same reason as [`powershell`]. `None` when it is not installed.
fn winget() -> Option<Command> {
let path = std::path::Path::new(&std::env::var_os("LOCALAPPDATA")?)
.join("Microsoft")
.join("WindowsApps")
.join("winget.exe");
path.exists().then(|| tool(&path.to_string_lossy()))
}

/// A [`Command`] for an FFmpeg tool that does not open a console window on Windows.
pub fn tool(program: &str) -> Command {
let mut command = Command::new(program);
Expand Down Expand Up @@ -204,7 +227,7 @@ pub fn refresh_path() -> bool {
"[Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + ",
"[Environment]::GetEnvironmentVariable('Path', 'User')"
);
let Ok(output) = tool("powershell.exe")
let Ok(output) = powershell()
.args(["-NoProfile", "-NonInteractive", "-Command", script])
.stdin(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
Expand All @@ -227,22 +250,24 @@ pub const WINGET_PACKAGE: &str = "Gyan.FFmpeg";

/// `true` when Windows' package manager, winget, runs here.
pub fn winget_available() -> bool {
cfg!(windows)
&& tool("winget")
winget().is_some_and(|mut winget| {
winget
.arg("--version")
.stdin(std::process::Stdio::null())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.is_ok_and(|s| s.success())
})
}

/// Installs FFmpeg with winget, for the current user, accepting the package's agreements (the user asked
/// for it from the *FFmpeg is needed* window, which says so). Takes a minute or two; the error carries
/// winget's last lines.
pub fn install_with_winget() -> anyhow::Result<()> {
use anyhow::Context;
let output = tool("winget")
let output = winget()
.with_context(|| crate::tr!("media-winget-start-failed"))?
.args(["install", "--id", WINGET_PACKAGE, "--exact", "--silent"])
.args(["--accept-package-agreements", "--accept-source-agreements"])
.arg("--disable-interactivity")
Expand Down
2 changes: 1 addition & 1 deletion src/sendto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn install() -> Result<PathBuf> {
$link.WorkingDirectory = $env:QVT_FOLDER; \
$link.Description = $env:QVT_DESCRIPTION; \
$link.Save()";
let output = crate::ffmpeg::tool("powershell.exe")
let output = crate::ffmpeg::powershell()
.args(["-NoProfile", "-NonInteractive", "-Command", script])
.env("QVT_LINK", &link)
.env("QVT_TARGET", &exe)
Expand Down
50 changes: 42 additions & 8 deletions src/update/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,25 @@ impl GitHub {
.map_err(|error| Fault::NoConnection(error.to_string()))?;
let status = response.status().as_u16();
if status == 200 {
Ok(response)
} else {
log::warn!("update: {url} answered {status}");
Err(Fault::Status(status))
return Ok(response);
}
log::warn!("update: {url} answered {status}");
let header = |name: &str| {
response
.headers()
.get(name)
.and_then(|v| v.to_str().ok())
.and_then(|v| v.trim().parse::<u64>().ok())
};
if matches!(status, 403 | 429) && header("x-ratelimit-remaining") == Some(0) {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_secs());
let minutes =
header("x-ratelimit-reset").map(|reset| reset.saturating_sub(now).div_ceil(60));
return Err(Fault::RateLimited(minutes));
}
Err(Fault::Status(status))
}
}

Expand Down Expand Up @@ -257,12 +271,13 @@ mod tests {
));
}

/// A one-shot HTTP server on 127.0.0.1 answering each request with the next canned response.
fn serve(responses: Vec<(u16, String)>) -> String {
/// A one-shot HTTP server on 127.0.0.1 answering each request with the next canned response
/// (status, extra headers, body).
fn serve_with(responses: Vec<(u16, &'static str, String)>) -> String {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let address = listener.local_addr().unwrap();
std::thread::spawn(move || {
for (status, body) in responses {
for (status, headers, body) in responses {
let Ok((mut stream, _)) = listener.accept() else {
return;
};
Expand All @@ -273,14 +288,33 @@ mod tests {
}
let _ = write!(
stream,
"HTTP/1.1 {status} X\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
"HTTP/1.1 {status} X\r\n{headers}Content-Length: {}\r\nConnection: close\r\n\r\n{body}",
body.len()
);
}
});
format!("http://{address}")
}

fn serve(responses: Vec<(u16, String)>) -> String {
serve_with(responses.into_iter().map(|(s, b)| (s, "", b)).collect())
}

#[test]
fn says_when_the_hourly_limit_is_reached() {
let base = serve_with(vec![
(
403,
"x-ratelimit-remaining: 0\r\nx-ratelimit-reset: 1\r\n",
"{}".to_owned(),
),
(403, "x-ratelimit-remaining: 12\r\n", "{}".to_owned()),
]);
let feed = GitHub::with_api(&base, "o/r");
assert_eq!(feed.latest(), Err(Fault::RateLimited(Some(0))));
assert_eq!(feed.latest(), Err(Fault::Status(403)));
}

#[test]
fn talks_http_and_reports_statuses() {
let base = serve(vec![
Expand Down
Loading