bit more env var stuff

This commit is contained in:
lifning 2021-12-11 01:38:34 -08:00
parent 2259265107
commit b8cc606bd5
3 changed files with 22 additions and 17 deletions

View File

@ -119,13 +119,15 @@ pub fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
emu.register_component(StderrSysInfoLogComponent::default())?; emu.register_component(StderrSysInfoLogComponent::default())?;
} }
let mut variables = VariableStoreComponent::default(); emu.register_component(EnvironmentVariableComponent::default())?;
let mut var_store = VariableStoreComponent::default();
// TODO: load a config file specified on the CLI // TODO: load a config file specified on the CLI
variables.insert("mgba_skip_bios", "ON"); var_store.insert("mgba_skip_bios", "ON");
variables.insert("gpsp_drc", "enabled"); var_store.insert("gpsp_drc", "enabled");
variables.insert("gpsp_frame_mixing", "enabled"); var_store.insert("gpsp_frame_mixing", "enabled");
variables.insert("gpsp_save_method", "libretro"); var_store.insert("gpsp_save_method", "libretro");
emu.register_component(variables)?; emu.register_component(var_store)?;
emu.init()?; emu.init()?;
emu.load_game(&opt.rom)?; emu.load_game(&opt.rom)?;

View File

@ -16,4 +16,4 @@ pub use input::StatefulInputComponent;
pub use paths::PathBufComponent; pub use paths::PathBufComponent;
pub use print::*; pub use print::*;
pub use saves::LocalFileSaveComponent; pub use saves::LocalFileSaveComponent;
pub use variables::VariableStoreComponent; pub use variables::*;

View File

@ -15,19 +15,22 @@ impl RetroCallbacks for EnvironmentVariableComponent {
fn set_variables(&mut self, variables: &[Variable2]) -> Option<bool> { fn set_variables(&mut self, variables: &[Variable2]) -> Option<bool> {
for v in variables { for v in variables {
println!("# {}", v.description); println!(
let value = if let Ok(x) = std::env::var(&v.key) { "# {}: {}",
if !v.options.contains(&x) { v.description,
panic!("Invalid value {:?} for variable {:?} (expected one of {:?})", x, v.key, v.options); v.options.iter().map(String::as_str).collect::<Vec<_>>().join(", ")
} else if x != v.options[0] { );
if let Ok(value) = std::env::var(&v.key) {
if !v.options.contains(&value) {
panic!("Invalid value {:?} for variable {:?} (expected one of {:?})", value, v.key, v.options);
} else if value != v.options[0] {
println!("# (overridden, default {})", v.options[0]); println!("# (overridden, default {})", v.options[0]);
} }
x println!("{}={}", v.key, value);
self.variables.insert(v.key.to_owned(), value);
} else { } else {
v.options[0].clone() println!("{}=", v.key);
}; }
println!("{}={} # {:?}", v.key, value, v.options);
self.variables.insert(v.key.to_owned(), value);
} }
Some(true) Some(true)
} }