diff --git a/crates/summit-cli/src/main.rs b/crates/summit-cli/src/main.rs
index 7699484..9cd6059 100644
--- a/crates/summit-cli/src/main.rs
+++ b/crates/summit-cli/src/main.rs
@@ -168,10 +168,7 @@ fn main() -> Result<()> {
println!("resolved {n}");
}
Cmd::Add { title, path, software } => {
- anyhow::ensure!(path.exists(), "{} does not exist", path.display());
- let id = format!("custom:{}", title.to_lowercase().replace(' ', "-"));
- let custom = state::Custom { id: id.clone(), title, path: state::path_text(&path.canonicalize()?)?, software };
- state::update(|st| { st.custom.retain(|c| c.id != id); st.custom.push(custom); })?; println!("added {id}");
+ println!("added {}", state::add_custom(&title, &path, software)?);
}
Cmd::Enhance { profile, source, no_watermark, out, max_ticks, dry_run } => {
let eng = engine::find_engine().ok_or_else(|| anyhow::anyhow!("engine not found: set SUMMIT_ENGINE to the engine/ folder"))?;
diff --git a/crates/summit-core/src/state.rs b/crates/summit-core/src/state.rs
index bbb00fa..2c30cfc 100644
--- a/crates/summit-core/src/state.rs
+++ b/crates/summit-core/src/state.rs
@@ -35,6 +35,37 @@ pub fn load() -> State {
pub fn save(s: &State) -> Result<()> { write_atomic(&path()?, serde_json::to_string_pretty(s)?.as_bytes()) }
+/// The entry `summit add` (and the launcher's Add a game) stores: id `custom:
`.
+pub fn custom_for(title: &str, path: &std::path::Path, software: bool) -> Result {
+ let title = title.trim();
+ anyhow::ensure!(!title.is_empty(), "the name is empty");
+ anyhow::ensure!(path.exists(), "{} does not exist", path.display());
+ let id = format!("custom:{}", title.to_lowercase().replace(' ', "-"));
+ Ok(Custom { id, title: title.to_string(), path: path_text(&path.canonicalize()?)?, software })
+}
+
+/// Add (or replace, same id) an entry by hand. Returns its id.
+pub fn add_custom(title: &str, path: &std::path::Path, software: bool) -> Result {
+ let c = custom_for(title, path, software)?;
+ let id = c.id.clone();
+ update(|st| { st.custom.retain(|x| x.id != id); st.custom.push(c); })?;
+ Ok(id)
+}
+
+/// A name for a game from the file picked to start it: its folder's name, unless that folder is a generic one
+/// (`bin`, `x86_64`, `Binaries/Linux`...), then the next folder up; the file name if no folder fits.
+pub fn title_guess(file: &std::path::Path) -> String {
+ const GENERIC: &[&str] = &["bin", "bin32", "bin64", "x86", "x64", "x86_64", "amd64", "linux", "linux64", "linux32",
+ "win32", "win64", "windows", "binaries", "game", "games", "release", "build", "data", "app", "files", "home", "opt", "usr", "local", "applications"];
+ let tidy = |s: &str| s.replace(['_', '-'], " ").split_whitespace().collect::>().join(" ");
+ for dir in file.ancestors().skip(1).take(3) {
+ let Some(name) = dir.file_name().and_then(|n| n.to_str()) else { break };
+ if !name.starts_with('.') && !GENERIC.contains(&name.to_ascii_lowercase().as_str()) { return tidy(name); }
+ }
+ let stem = file.file_stem().and_then(|n| n.to_str()).unwrap_or("Game");
+ tidy(stem.split('.').next().unwrap_or(stem))
+}
+
/// Load, change and save `state.json` while holding a lock (`flock` on `state.json.lock`), so the launcher saving a
/// pin and `summit run` saving a session at the same moment both keep their change. Returns the saved state.
pub fn update(f: impl FnOnce(&mut State)) -> Result { update_at(&path()?, f) }
@@ -112,6 +143,22 @@ pub fn apply(entries: &mut [crate::model::Entry], st: &State) {
#[cfg(test)]
mod tests {
+ #[test]
+ fn title_guess_skips_generic_folders() {
+ use std::path::Path;
+ assert_eq!(super::title_guess(Path::new("/home/u/Games/Voidrunner/top_down_shooter")), "Voidrunner");
+ assert_eq!(super::title_guess(Path::new("/games/Hollow_Knight/bin/x86_64/hollow_knight.x86_64")), "Hollow Knight");
+ assert_eq!(super::title_guess(Path::new("/games/Cool-Game/Binaries/Linux/CoolGame-Linux-Shipping")), "Cool Game");
+ assert_eq!(super::title_guess(Path::new("/opt/bin/launch.sh")), "launch");
+ }
+ #[test]
+ fn custom_ids_and_refusals() {
+ let f = std::env::current_exe().unwrap();
+ let c = super::custom_for(" My Game ", &f, false).unwrap();
+ assert_eq!((c.id.as_str(), c.title.as_str()), ("custom:my-game", "My Game"));
+ assert!(super::custom_for(" ", &f, false).is_err());
+ assert!(super::custom_for("X", std::path::Path::new("/nonexistent/summit/x"), false).is_err());
+ }
#[test]
fn concurrent_updates_all_land() {
let d = std::env::temp_dir().join(format!("summit-state-lock-{}", std::process::id()));
diff --git a/crates/summit-gui/src/art.rs b/crates/summit-gui/src/art.rs
index 644200b..def7f2a 100644
--- a/crates/summit-gui/src/art.rs
+++ b/crates/summit-gui/src/art.rs
@@ -11,12 +11,12 @@ pub type Rgb = SharedPixelBuffer;
pub type Rgba = SharedPixelBuffer;
pub enum Job {
- Cover { idx: usize, path: PathBuf },
+ Cover { idx: usize, gen: u64, path: PathBuf },
Backdrop { idx: usize, seq: u64, hero: Option, cover: Option, logo: Option, c1: [u8; 3], c2: [u8; 3] },
}
pub enum Done {
- Cover { idx: usize, img: Option },
+ Cover { idx: usize, gen: u64, img: Option },
Backdrop { idx: usize, seq: u64, img: Rgb, logo: Option },
}
@@ -87,7 +87,7 @@ pub fn logo(path: &Path) -> Option {
pub fn run(job: Job) -> Done {
match job {
- Job::Cover { idx, path } => Done::Cover { idx, img: cover(&path) },
+ Job::Cover { idx, gen, path } => Done::Cover { idx, gen, img: cover(&path) },
Job::Backdrop { idx, seq, hero, cover, logo: l, c1, c2 } => Done::Backdrop {
idx, seq, img: backdrop(hero.as_deref(), cover.as_deref(), c1, c2), logo: l.as_deref().and_then(logo),
},
@@ -175,7 +175,7 @@ mod tests {
#[test]
fn queue_loader_hands_jobs_back() {
let l = Loader::queued();
- l.push(Job::Cover { idx: 3, path: "/x".into() });
+ l.push(Job::Cover { idx: 3, gen: 0, path: "/x".into() });
assert_eq!(l.take().len(), 1);
assert!(l.take().is_empty());
}
diff --git a/crates/summit-gui/src/data.rs b/crates/summit-gui/src/data.rs
index 05f9898..edc590f 100644
--- a/crates/summit-gui/src/data.rs
+++ b/crates/summit-gui/src/data.rs
@@ -232,15 +232,36 @@ pub fn last_error(log: &str) -> Option {
/// The desktop's file dialog for picking a cover: kdialog on KDE, zenity elsewhere (whichever is installed, the
/// desktop's own first). `None` when neither is there.
pub fn art_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str) -> Option> {
+ file_picker(kde, have, start, "Summit: pick a cover image", Some(("Images", "*.png *.jpg *.jpeg *.webp")))
+}
+
+/// Add a game: pick the file that starts it (any file: Linux games rarely have an extension).
+pub fn exe_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str) -> Option> {
+ file_picker(kde, have, start, "Summit: pick the file that starts the game", None)
+}
+
+/// The desktop's own dialog first (kdialog on KDE, zenity elsewhere); `filter` is (label, "*.a *.b").
+fn file_picker(kde: bool, have: impl Fn(&str) -> bool, start: &str, title: &str, filter: Option<(&str, &str)>) -> Option> {
let order = if kde { ["kdialog", "zenity"] } else { ["zenity", "kdialog"] };
let name = order.into_iter().find(|n| have(n))?;
- Some(if name == "kdialog" {
- vec!["kdialog".to_string(), "--title".into(), "Summit: pick a cover image".into(),
- "--getopenfilename".into(), start.into(), "*.png *.jpg *.jpeg *.webp|Images".into()]
+ let mut v = if name == "kdialog" {
+ vec!["kdialog".to_string(), "--title".into(), title.into(), "--getopenfilename".into(), start.into()]
} else {
- vec!["zenity".to_string(), "--file-selection".into(), "--title=Summit: pick a cover image".into(),
- format!("--filename={start}/"), "--file-filter=Images | *.png *.jpg *.jpeg *.webp".into()]
- })
+ vec!["zenity".to_string(), "--file-selection".into(), format!("--title={title}"), format!("--filename={start}/")]
+ };
+ if let Some((label, pats)) = filter {
+ v.push(if name == "kdialog" { format!("{pats}|{label}") } else { format!("--file-filter={label} | {pats}") });
+ }
+ Some(v)
+}
+
+/// After picking the file: ask for the game's name, with a guess filled in. Same tool as the file dialog.
+pub fn name_prompt(tool: &str, guess: &str) -> Vec {
+ if tool == "kdialog" {
+ vec!["kdialog".into(), "--title".into(), "Summit: add a game".into(), "--inputbox".into(), "Name of the game".into(), guess.into()]
+ } else {
+ vec!["zenity".into(), "--entry".into(), "--title=Summit: add a game".into(), "--text=Name of the game".into(), format!("--entry-text={guess}")]
+ }
}
#[cfg(test)]
@@ -260,6 +281,11 @@ mod tests {
assert_eq!(super::art_picker(true, |n: &str| n == "zenity", "/h").unwrap()[0], "zenity");
assert!(super::art_picker(false, |_: &str| false, "/h").is_none());
assert!(super::art_picker(false, both, "/h").unwrap().contains(&"--filename=/h/".to_string()));
+ assert_eq!(super::art_picker(true, both, "/h").unwrap().last().unwrap(), "*.png *.jpg *.jpeg *.webp|Images");
+ assert_eq!(super::exe_picker(true, both, "/g").unwrap().last().unwrap(), "/g");
+ assert!(super::exe_picker(false, both, "/g").unwrap().iter().all(|a| !a.starts_with("--file-filter")));
+ assert_eq!(super::name_prompt("zenity", "Voidrunner").last().unwrap(), "--entry-text=Voidrunner");
+ assert_eq!(super::name_prompt("kdialog", "Voidrunner").last().unwrap(), "Voidrunner");
}
use super::*;
diff --git a/crates/summit-gui/src/main.rs b/crates/summit-gui/src/main.rs
index 32da201..ce6f3cc 100644
--- a/crates/summit-gui/src/main.rs
+++ b/crates/summit-gui/src/main.rs
@@ -42,6 +42,10 @@ pub struct App {
save_timer: slint::Timer,
/// The profile editor's game id and the outputs listed when it opened (or why there is no list).
editing: RefCell