1use std::process::Command;
2use uxn_tal_common::cache::RomEntryResolver;
3
4#[cfg(windows)]
5use std::os::windows::process::CommandExt;
6
7pub fn create_git_command() -> Command {
9 #[cfg(windows)]
10 let mut cmd = Command::new("git");
11 #[cfg(not(windows))]
12 let cmd = Command::new("git");
13 #[cfg(windows)]
14 {
15 cmd.creation_flags(0x08000000);
17 }
18 cmd
19}
20
21pub struct RealRomEntryResolver;
23impl RomEntryResolver for RealRomEntryResolver {
24 fn resolve_entry_and_cache_dir(
25 &self,
26 url: &str,
27 ) -> Result<(std::path::PathBuf, std::path::PathBuf), String> {
28 crate::fetch::downloader::resolve_and_fetch_entry(url).map_err(|e| format!("{e}"))
29 }
30}
31use crate::assemble_file;
32use std::io::IsTerminal;
34
35pub fn pause_on_error() {
37 if !std::io::stderr().is_terminal() && !std::io::stdout().is_terminal() {
38 return;
40 }
41 use std::{thread, time};
42 eprintln!("\n---\nKeeping window open for 15 seconds so you can read the above. Press Enter to continue...");
43 use std::sync::mpsc;
44
45 let (tx, rx) = mpsc::channel();
46 #[cfg(not(target_arch = "wasm32"))]
47 thread::spawn(move || {
48 let mut _buf = String::new();
49 let _ = std::io::stdin().read_line(&mut _buf);
50 let _ = tx.send(());
51 });
52 let _ = rx.recv_timeout(time::Duration::from_secs(15));
53}
54pub fn pause_for_windows() {
56 #[cfg(target_os = "windows")]
57 {
58 if std::io::stdout().is_terminal() || std::io::stderr().is_terminal() {
59 use std::io::Write;
60
61 print!("Press Enter to continue...");
62 let _ = std::io::stdout().flush();
63 let mut _buf = String::new();
64 let _ = std::io::stdin().read_line(&mut _buf);
65 }
66 }
67}
68
69use std::path::{Path, PathBuf};
70pub struct RealRomCache;
72impl uxn_tal_common::cache::RomCache for RealRomCache {
73 fn get_or_write_cached_rom(&self, url: &str, out_path: &Path) -> Result<PathBuf, String> {
74 let (entry_path, cache_dir) = crate::fetch::downloader::resolve_and_fetch_entry(url)
76 .map_err(|e| format!("resolve_and_fetch_entry failed: {e}"))?;
77 let rom_path = cache_dir.join(
78 out_path
79 .file_name()
80 .unwrap_or_else(|| std::ffi::OsStr::new("out.rom")),
81 );
82 if rom_path.exists() {
84 return Ok(rom_path);
85 }
86 if let Some(ext) = entry_path.extension() {
88 if ext == "rom" {
89 std::fs::copy(&entry_path, &rom_path)
90 .map_err(|e| format!("Failed to copy ROM: {e}"))?;
91 return Ok(rom_path);
92 }
93 }
94 let tal_path = entry_path;
96 let rom_bytes = assemble_file(&tal_path).map_err(|e| format!("Assembler error: {e}"))?;
97 std::fs::write(&rom_path, &rom_bytes).map_err(|e| format!("Failed to write ROM: {e}"))?;
98 Ok(rom_path)
99 }
100}