Remove 'reqwest' dependency from sdl2 frontend
It was useless and lengthened the build time Former-commit-id: 44b9c836d9b75142ef4bdb3602ede3f87b03f08f Former-commit-id: 4c737704103654673366a7a83bf9b7614df40416
This commit is contained in:
parent
e1ec96f9e4
commit
bccb31c142
|
@ -14,7 +14,6 @@ log = "0.4.8"
|
||||||
flexi_logger = { version = "0.14", features = ["colors"] }
|
flexi_logger = { version = "0.14", features = ["colors"] }
|
||||||
bit = "^0.1"
|
bit = "^0.1"
|
||||||
spin_sleep = "0.3.7"
|
spin_sleep = "0.3.7"
|
||||||
reqwest = { version = "0.10", features = ["blocking"] }
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winres = "0.1"
|
winres = "0.1"
|
||||||
|
|
|
@ -3,7 +3,6 @@ use sdl2::controller::Button;
|
||||||
use sdl2::event::{Event, WindowEvent};
|
use sdl2::event::{Event, WindowEvent};
|
||||||
use sdl2::image::{InitFlag, LoadSurface, LoadTexture};
|
use sdl2::image::{InitFlag, LoadSurface, LoadTexture};
|
||||||
use sdl2::keyboard::Scancode;
|
use sdl2::keyboard::Scancode;
|
||||||
use sdl2::messagebox::*;
|
|
||||||
use sdl2::pixels::Color;
|
use sdl2::pixels::Color;
|
||||||
use sdl2::rect::Rect;
|
use sdl2::rect::Rect;
|
||||||
use sdl2::render::WindowCanvas;
|
use sdl2::render::WindowCanvas;
|
||||||
|
@ -18,7 +17,7 @@ use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Cursor, Read};
|
use std::io::Cursor;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
@ -33,8 +32,6 @@ extern crate log;
|
||||||
use flexi_logger;
|
use flexi_logger;
|
||||||
use flexi_logger::*;
|
use flexi_logger::*;
|
||||||
|
|
||||||
use reqwest;
|
|
||||||
|
|
||||||
mod audio;
|
mod audio;
|
||||||
mod input;
|
mod input;
|
||||||
mod video;
|
mod video;
|
||||||
|
@ -101,50 +98,10 @@ fn wait_for_rom(canvas: &mut WindowCanvas, event_pump: &mut EventPump) -> Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ask_download_bios() -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> {
|
fn ask_download_bios() {
|
||||||
const OPEN_SOURCE_BIOS_URL: &'static str =
|
const OPEN_SOURCE_BIOS_URL: &'static str =
|
||||||
"https://github.com/Nebuleon/ReGBA/raw/master/bios/gba_bios.bin";
|
"https://github.com/Nebuleon/ReGBA/raw/master/bios/gba_bios.bin";
|
||||||
|
println!("Missing BIOS file. If you don't have the original GBA BIOS, you can download an open-source bios from {}", OPEN_SOURCE_BIOS_URL);
|
||||||
let buttons: Vec<_> = vec![
|
|
||||||
ButtonData {
|
|
||||||
flags: MessageBoxButtonFlag::NOTHING,
|
|
||||||
button_id: 100,
|
|
||||||
text: "No, Exit!",
|
|
||||||
},
|
|
||||||
ButtonData {
|
|
||||||
flags: MessageBoxButtonFlag::NOTHING,
|
|
||||||
button_id: 101,
|
|
||||||
text: "Yes",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let res = show_message_box(
|
|
||||||
MessageBoxFlag::WARNING,
|
|
||||||
buttons.as_slice(),
|
|
||||||
"bios not found",
|
|
||||||
"would you like to me download an open source bios for you?",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
match res {
|
|
||||||
ClickedButton::CloseButton => Ok(None),
|
|
||||||
ClickedButton::CustomButton(button) => match button.button_id {
|
|
||||||
101 => {
|
|
||||||
let mut resp = reqwest::blocking::get(OPEN_SOURCE_BIOS_URL)?;
|
|
||||||
let mut bios = Vec::with_capacity(16 * 1024);
|
|
||||||
resp.read_to_end(&mut bios)?;
|
|
||||||
show_simple_message_box(
|
|
||||||
MessageBoxFlag::INFORMATION,
|
|
||||||
"Download Finished!",
|
|
||||||
"Download Finished!",
|
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
Ok(Some(bios))
|
|
||||||
}
|
|
||||||
_ => Ok(None),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -162,6 +119,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let yaml = load_yaml!("cli.yml");
|
let yaml = load_yaml!("cli.yml");
|
||||||
let matches = clap::App::from_yaml(yaml).get_matches();
|
let matches = clap::App::from_yaml(yaml).get_matches();
|
||||||
|
|
||||||
|
let bios_path = Path::new(matches.value_of("bios").unwrap_or_default());
|
||||||
|
let bios_bin = match read_bin_file(bios_path) {
|
||||||
|
Ok(bios) => bios,
|
||||||
|
_ => {
|
||||||
|
ask_download_bios();
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let skip_bios = matches.occurrences_of("skip_bios") != 0;
|
let skip_bios = matches.occurrences_of("skip_bios") != 0;
|
||||||
|
|
||||||
let debug = matches.occurrences_of("debug") != 0;
|
let debug = matches.occurrences_of("debug") != 0;
|
||||||
|
@ -170,27 +136,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
info!("Initializing SDL2 context");
|
info!("Initializing SDL2 context");
|
||||||
let sdl_context = sdl2::init().expect("failed to initialize sdl2");
|
let sdl_context = sdl2::init().expect("failed to initialize sdl2");
|
||||||
|
|
||||||
let bios_path = Path::new(matches.value_of("bios").unwrap_or_default());
|
|
||||||
let bios_bin = match read_bin_file(bios_path) {
|
|
||||||
Ok(bios) => bios,
|
|
||||||
_ => match ask_download_bios() {
|
|
||||||
Ok(Some(bios)) => {
|
|
||||||
info!("saving downloaded bios to {}", bios_path.display());
|
|
||||||
write_bin_file(bios_path, &bios)?;
|
|
||||||
|
|
||||||
bios
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
info!("Exiting");
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("error when downloading bios: {}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut event_pump = sdl_context.event_pump()?;
|
let mut event_pump = sdl_context.event_pump()?;
|
||||||
|
|
||||||
let video_subsystem = sdl_context.video()?;
|
let video_subsystem = sdl_context.video()?;
|
||||||
|
|
Reference in a new issue