refactor: idiomatic Rust cleanup and quality improvements
- Replace .map().unwrap_or(false) with .is_some_and()/.is_ok_and()
- Use path.display() instead of {:?} for user-facing messages
- Replace Option<Option<Vec<String>>> with GamescopeUpdate enum
- Replace manual parent-walking loops with .ancestors() iterators
- Simplify kill()/kill_all() signatures to return () instead of Result
- Use tokio::task::spawn_blocking instead of hand-rolled thread+oneshot
- Read /proc/self/status for UID instead of spawning id subprocess
- Build Exec= line directly in render_desktop instead of string-replace
- Bump PKGBUILD pkgrel to 6
This commit is contained in:
+6
-21
@@ -23,8 +23,7 @@ pub fn scan_for_gui(config: &Config) -> Vec<DetectHit> {
|
||||
if prefix.join("drive_c").join(&preset.exe_path).exists() {
|
||||
let configured = config
|
||||
.find(&preset.name)
|
||||
.map(|l| l.prefix_dir == *prefix)
|
||||
.unwrap_or(false);
|
||||
.is_some_and(|l| l.prefix_dir == *prefix);
|
||||
hits.push(DetectHit {
|
||||
display: preset.display.clone(),
|
||||
prefix: prefix.clone(),
|
||||
@@ -182,14 +181,7 @@ fn parse_heroic_gog_installed(text: &str, map: &mut HashMap<PathBuf, String>) {
|
||||
|
||||
/// Walk up from `exe_path` checking each ancestor against `STORE_TITLES`.
|
||||
fn store_title(exe_path: &Path) -> Option<String> {
|
||||
let mut dir = exe_path.parent();
|
||||
while let Some(d) = dir {
|
||||
if let Some(title) = STORE_TITLES.get(d) {
|
||||
return Some(title.clone());
|
||||
}
|
||||
dir = d.parent();
|
||||
}
|
||||
None
|
||||
exe_path.ancestors().skip(1).find_map(|d| STORE_TITLES.get(d).cloned())
|
||||
}
|
||||
|
||||
/// Scan a launcher's Wine prefix for installed game executables.
|
||||
@@ -251,8 +243,7 @@ fn scan_exe_dir(
|
||||
} else if path
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.map(|e| e.eq_ignore_ascii_case("exe"))
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|e| e.eq_ignore_ascii_case("exe"))
|
||||
{
|
||||
let Ok(rel) = path.strip_prefix(drive_c) else { continue };
|
||||
let rel_str = rel.to_string_lossy().to_string();
|
||||
@@ -344,20 +335,16 @@ fn resolve_uncached(exe_path: &Path) -> String {
|
||||
/// - GOG: `goggame-<id>.info` → `{ "gameName": "..." }`
|
||||
/// - Epic: `.egstore/<id>.item` → `{ "DisplayName": "..." }`
|
||||
fn read_manifest_name(exe_path: &Path) -> Option<String> {
|
||||
let mut dir = exe_path.parent();
|
||||
while let Some(d) = dir {
|
||||
for d in exe_path.ancestors().skip(1) {
|
||||
let dirname = d.file_name().and_then(|n| n.to_str()).unwrap_or("").to_lowercase();
|
||||
// Stop once we reach drive_c root or the Program Files tier — manifests
|
||||
// are never above the game's installation folder.
|
||||
if dirname == "drive_c" || dirname.starts_with("program files") {
|
||||
break;
|
||||
}
|
||||
|
||||
if let Some(name) = read_gog_manifest(d).or_else(|| read_epic_manifest(d)) {
|
||||
return Some(name);
|
||||
}
|
||||
|
||||
dir = d.parent();
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -438,8 +425,7 @@ fn nearest_dir_name(path: &Path) -> String {
|
||||
"launcher", "engine", "client",
|
||||
];
|
||||
|
||||
let mut dir = path.parent();
|
||||
while let Some(d) = dir {
|
||||
for d in path.ancestors().skip(1) {
|
||||
let name = d.file_name().and_then(|n| n.to_str()).unwrap_or("");
|
||||
let lower = name.to_lowercase();
|
||||
if !name.is_empty()
|
||||
@@ -448,7 +434,6 @@ fn nearest_dir_name(path: &Path) -> String {
|
||||
{
|
||||
return name.to_string();
|
||||
}
|
||||
dir = d.parent();
|
||||
}
|
||||
|
||||
// Nothing useful in the path — return the exe stem as-is.
|
||||
@@ -529,7 +514,7 @@ fn collect_prefixes(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
|
||||
return;
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
if entry.file_type().map(|t| t.is_dir()).unwrap_or(false) {
|
||||
if entry.file_type().is_ok_and(|t| t.is_dir()) {
|
||||
collect_prefixes(&entry.path(), depth + 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user