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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "3"

[package]
name = "usb-forge"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
rust-version = "1.92"
description = "Build a verified multi-boot USB thumb drive from official ISOs on Windows and Linux"
Expand Down
Binary file added assets/boot-theme/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions assets/boot-theme/make-theme.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Regenerates the USB Forge boot menu theme images in this folder (theme.txt is hand-written).
# Colours match src/theme.rs. Usage: powershell -ExecutionPolicy Bypass -File assets/boot-theme/make-theme.ps1
Add-Type -AssemblyName System.Drawing
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path

function C([string]$hex, [int]$a = 255) {
$v = [Convert]::ToInt32($hex.TrimStart('#'), 16)
[Drawing.Color]::FromArgb($a, ($v -shr 16) -band 255, ($v -shr 8) -band 255, $v -band 255)
}
$BG = C '0f1117'; $PANEL = C '151821'; $CARD_HOVER = C '222734'; $BORDER = C '2a303e'
$TEXT = C 'e6e8ee'; $MUTED = C '8b93a7'; $ACCENT = C 'ff7a45'; $DEEP = C '0b0d12'; $THUMB = C '4a5368'

function Save([Drawing.Bitmap]$bmp, [string]$name) {
$bmp.Save((Join-Path $here $name), [Drawing.Imaging.ImageFormat]::Png)
$bmp.Dispose()
}

function Solid([string]$name, [int]$w, [int]$h, [Drawing.Color]$color) {
$bmp = New-Object Drawing.Bitmap $w, $h, ([Drawing.Imaging.PixelFormat]::Format32bppArgb)
$g = [Drawing.Graphics]::FromImage($bmp)
$g.Clear($color)
$g.Dispose()
Save $bmp $name
}

# A 9-slice box: 1px-wide border pieces (2x2 corners) around a stretched centre.
function Box([string]$prefix, [Drawing.Color]$edge, [Drawing.Color]$fill, [int]$t = 2) {
foreach ($p in 'nw', 'ne', 'sw', 'se') { Solid "${prefix}_$p.png" $t $t $edge }
foreach ($p in 'n', 's') { Solid "${prefix}_$p.png" 4 $t $edge }
foreach ($p in 'w', 'e') { Solid "${prefix}_$p.png" $t 4 $edge }
Solid "${prefix}_c.png" 4 4 $fill
}

# ---- background: dark gradient, logo + wordmark in the top quarter ----------------------
$W = 1024; $H = 768
$bmp = New-Object Drawing.Bitmap $W, $H, ([Drawing.Imaging.PixelFormat]::Format24bppRgb)
$g = [Drawing.Graphics]::FromImage($bmp)
$g.SmoothingMode = 'AntiAlias'
$g.InterpolationMode = 'HighQualityBicubic'
$g.TextRenderingHint = 'AntiAliasGridFit'
$grad = New-Object Drawing.Drawing2D.LinearGradientBrush ([Drawing.PointF]::new(0, 0)), ([Drawing.PointF]::new(0, $H)), $PANEL, $BG
$g.FillRectangle($grad, 0, 0, $W, $H)

# Soft warm glow behind the logo.
$glow = New-Object Drawing.Drawing2D.GraphicsPath
$glow.AddEllipse(312, -140, 400, 340)
$pgb = New-Object Drawing.Drawing2D.PathGradientBrush $glow
$pgb.CenterColor = (C 'ff7a45' 38)
$pgb.SurroundColors = [Drawing.Color[]]@((C 'ff7a45' 0))
$g.FillPath($pgb, $glow)

$icon = [Drawing.Image]::FromFile((Join-Path (Split-Path -Parent $here) 'icon.png'))
$title = 'USB Forge'
$font = New-Object Drawing.Font 'Segoe UI Semibold', 40, ([Drawing.FontStyle]::Regular), ([Drawing.GraphicsUnit]::Pixel)
$size = $g.MeasureString($title, $font)
$iconSize = 76; $gap = 14
$x = [int](($W - ($iconSize + $gap + $size.Width)) / 2)
$g.DrawImage($icon, $x, 58, $iconSize, $iconSize)
$g.DrawString($title, $font, (New-Object Drawing.SolidBrush $TEXT), [float]($x + $iconSize + $gap), [float](96 - $size.Height / 2))
$icon.Dispose()

$sub = New-Object Drawing.Font 'Segoe UI', 16, ([Drawing.FontStyle]::Regular), ([Drawing.GraphicsUnit]::Pixel)
$fmt = New-Object Drawing.StringFormat
$fmt.Alignment = 'Center'
$g.DrawString('Choose an operating system or tool to start', $sub, (New-Object Drawing.SolidBrush $MUTED), [Drawing.RectangleF]::new(0, 152, $W, 24), $fmt)

# Thin accent rule under the heading.
$g.FillRectangle((New-Object Drawing.SolidBrush $ACCENT), [int]($W / 2 - 28), 186, 56, 3)
$g.Dispose()
Save $bmp 'background.png'

# ---- menu, selection, scrollbar, command-line box ---------------------------------------
Box 'menu' $BORDER $PANEL
Solid 'select_c.png' 4 4 $CARD_HOVER
Solid 'select_w.png' 4 4 $ACCENT
Solid 'slider_n.png' 10 2 $THUMB
Solid 'slider_c.png' 10 4 $THUMB
Solid 'slider_s.png' 10 2 $THUMB
Box 'terminal_box' $BORDER $DEEP
Binary file added assets/boot-theme/menu_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_ne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_nw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_se.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_sw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/menu_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/select_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/select_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/slider_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/slider_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/slider_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_ne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_nw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_se.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_sw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boot-theme/terminal_box_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions assets/boot-theme/theme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# USB Forge boot menu theme (GRUB gfxmenu). Colours match src/theme.rs.
# Images are generated by make-theme.ps1. Layout follows the boot loader's stock theme so its
# hotkey and boot-mode hints (the @VTOY_*@ labels) keep working.

desktop-image: "background.png"
desktop-color: "#0f1117"
title-text: " "
title-color: "#e6e8ee"
message-color: "#e6e8ee"

terminal-box: "terminal_box_*.png"

+ boot_menu {
left = 15%
width = 70%
top = 30%
height = 52%

menu_pixmap_style = "menu_*.png"

item_color = "#e6e8ee"
item_height = 32
item_spacing = 2
item_padding = 6

selected_item_color = "#ff7a45"
selected_item_pixmap_style = "select_*.png"

item_icon_space = 0

scrollbar = true
scrollbar_width = 10
scrollbar_thumb = "slider_*.png"
}

+ progress_bar {
id = "__timeout__"
text = "@TIMEOUT_NOTIFICATION_LONG@"

left = 15%
width = 70%
top = 84%
height = 20

text_color = "#8b93a7"
fg_color = "#5a2e1c"
bg_color = "#151821"
border_color = "#2a303e"
}

+ hbox{
left = 30%
top = 95%
width = 10%
height = 25
+ label {text = "@VTOY_HOTKEY_TIP@" color = "#8b93a7" align = "left"}
}

+ hbox{
left = 30%
top = 95%-25
width = 10%
height = 25
+ label {text = "@VTOY_MEM_DISK@" color = "#f5c451" align = "left"}
}

+ hbox{
left = 30%
top = 95%-50
width = 10%
height = 25
+ label {text = "@VTOY_ISO_RAW@" color = "#f5c451" align = "left"}
}

+ hbox{
left = 30%+200
top = 95%-50
width = 10%
height = 25
+ label {text = "@VTOY_GRUB2_MODE@" color = "#f5c451" align = "left"}
}

+ hbox{
left = 30%+200
top = 95%-25
width = 10%
height = 25
+ label {text = "@VTOY_WIMBOOT_MODE@" color = "#f5c451" align = "left"}
}

+ hbox{
left = 90%
top = 55
width = 10%
height = 25
+ label {text = "@VTOY_ISO_UEFI_DRV@" color = "#f5c451" align = "left"}
}
36 changes: 14 additions & 22 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl UsbForgeApp {
}
}
if let Some(disk) = self.selected_disk()
&& total > disk.size.saturating_sub(64 * 1024 * 1024)
&& total > disk.size.saturating_sub(disks::RESERVED_BYTES)
{
problems.push(format!(
"The selection needs {} but the drive holds {}.",
Expand Down Expand Up @@ -530,31 +530,23 @@ impl UsbForgeApp {
fn tool_row(&mut self, ui: &mut egui::Ui, tool: &catalog::ToolInfo) {
let mut on = self.chosen.get(&tool.id).copied().unwrap_or(false);
let mut channel = self.channel(tool.id);
let lookup_text = {
let max_file = self.fs.max_file();
let (lookup_text, saved, too_big) = {
let map = self.lookups.lock().ok();
match map.as_ref().and_then(|m| m.get(&(tool.id, channel))) {
Some(Lookup::Ready(r)) => Some(Ok(format!(
"{} · {}",
r.version,
r.size.map(human_size).unwrap_or_else(|| "size ?".into())
))),
Some(Lookup::Failed(e)) => Some(Err(e.clone())),
Some(Lookup::Loading) | None => None,
Some(Lookup::Ready(r)) => (
Some(Ok(format!(
"{} · {}",
r.version,
r.size.map(human_size).unwrap_or_else(|| "size ?".into())
))),
cache_state(r),
r.size.zip(max_file).is_some_and(|(s, max)| s > max),
),
Some(Lookup::Failed(e)) => (Some(Err(e.clone())), CacheState::Missing, false),
Some(Lookup::Loading) | None => (None, CacheState::Missing, false),
}
};
let saved = {
let map = self.lookups.lock().ok();
match map.as_ref().and_then(|m| m.get(&(tool.id, channel))) {
Some(Lookup::Ready(r)) => cache_state(r),
_ => CacheState::Missing,
}
};
let too_big = matches!(&lookup_text, Some(Ok(_)))
&& self.fs.max_file().is_some_and(|max| {
self.lookups.lock().ok().is_some_and(|m| {
matches!(m.get(&(tool.id, channel)), Some(Lookup::Ready(r)) if r.size.is_some_and(|s| s > max))
})
});

let (fill, stroke) = if on {
(CARD_HOVER, ACCENT)
Expand Down
124 changes: 124 additions & 0 deletions src/boot_theme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! The USB Forge boot menu theme, written to the data partition after the ISOs.
//!
//! The boot loader reads `/ventoy/ventoy.json` from the data partition and supports a GRUB
//! gfxmenu theme through its theme plugin, so branding needs no change to the boot loader
//! itself (and nothing about Secure Boot). Images come from `assets/boot-theme/make-theme.ps1`.

use std::path::Path;

/// Folder on the data partition that holds the theme, relative to the drive root.
const THEME_DIR: &str = "ventoy/theme/usb-forge";

macro_rules! theme_files {
($($name:literal),* $(,)?) => {
&[$(($name, include_bytes!(concat!("../assets/boot-theme/", $name)) as &[u8])),*]
};
}

const FILES: &[(&str, &[u8])] = theme_files![
"theme.txt",
"background.png",
"menu_c.png",
"menu_n.png",
"menu_s.png",
"menu_e.png",
"menu_w.png",
"menu_ne.png",
"menu_nw.png",
"menu_se.png",
"menu_sw.png",
"select_c.png",
"select_w.png",
"slider_c.png",
"slider_n.png",
"slider_s.png",
"terminal_box_c.png",
"terminal_box_n.png",
"terminal_box_s.png",
"terminal_box_e.png",
"terminal_box_w.png",
"terminal_box_ne.png",
"terminal_box_nw.png",
"terminal_box_se.png",
"terminal_box_sw.png",
];

/// Background colour at the bottom of `background.png`. The boot loader always prints its own
/// name and version line; drawing it in this colour hides it.
const HIDDEN_TEXT_COLOR: &str = "#0f1117";

/// Plugin config: use the theme in graphical mode, with the boot loader's version line hidden.
fn plugin_config() -> String {
format!(
r##"{{
"theme": {{
"file": "/{THEME_DIR}/theme.txt",
"display_mode": "GUI",
"ventoy_left": "5%",
"ventoy_top": "95%",
"ventoy_color": "{HIDDEN_TEXT_COLOR}"
}}
}}
"##
)
}

/// Write the theme and the plugin config onto the drive mounted at `root`.
pub fn install(root: &Path) -> Result<(), String> {
let dir = root.join(THEME_DIR);
std::fs::create_dir_all(&dir).map_err(|e| format!("Cannot create {}: {e}", dir.display()))?;
for (name, bytes) in FILES {
let path = dir.join(name);
std::fs::write(&path, bytes)
.map_err(|e| format!("Cannot write {}: {e}", path.display()))?;
}
let config = root.join("ventoy").join("ventoy.json");
std::fs::write(&config, plugin_config())
.map_err(|e| format!("Cannot write {}: {e}", config.display()))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn config_points_at_the_bundled_theme() {
let v: serde_json::Value = serde_json::from_str(&plugin_config()).expect("valid JSON");
let file = v["theme"]["file"].as_str().unwrap();
let name = file.strip_prefix(&format!("/{THEME_DIR}/")).unwrap();
assert!(FILES.iter().any(|(n, _)| *n == name));
assert_eq!(v["theme"]["ventoy_color"], HIDDEN_TEXT_COLOR);
assert!(
std::str::from_utf8(FILES[0].1)
.unwrap()
.contains(&format!("desktop-color: \"{HIDDEN_TEXT_COLOR}\"")),
"hidden text colour must match the theme background"
);
}

#[test]
fn every_image_the_theme_uses_is_bundled() {
let theme = std::str::from_utf8(FILES[0].1).unwrap();
let bundled = |n: &str| FILES.iter().any(|(f, _)| *f == n);
for pattern in theme.split('"').filter(|s| s.ends_with(".png")) {
if let Some(prefix) = pattern.strip_suffix("*.png") {
assert!(bundled(&format!("{prefix}c.png")), "{pattern}");
} else {
assert!(bundled(pattern), "{pattern}");
}
}
for (name, bytes) in FILES.iter().filter(|(n, _)| n.ends_with(".png")) {
assert!(bytes.starts_with(b"\x89PNG"), "{name} is not a PNG");
}
}

#[test]
fn installs_into_a_drive_folder() {
let root = std::env::temp_dir().join(format!("usbf-theme-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
install(&root).unwrap();
assert!(root.join("ventoy/ventoy.json").is_file());
assert!(root.join(THEME_DIR).join("background.png").is_file());
let _ = std::fs::remove_dir_all(&root);
}
}
Loading