simple core info querying
This commit is contained in:
parent
b2c2c93537
commit
768dfb75bb
|
@ -0,0 +1,12 @@
|
|||
use ferretro_base::retro::loading::LibretroApi;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
|
||||
for core_path in std::env::args().skip(1) {
|
||||
println!("{}:", core_path);
|
||||
let lib = libloading::Library::new(&core_path)?;
|
||||
let api = LibretroApi::from_library(lib)?;
|
||||
let info = api.get_system_info();
|
||||
println!("\t{} {} {:?}", info.library_name, info.library_version, info.valid_extensions);
|
||||
}
|
||||
Ok(())
|
||||
}
|
|
@ -4,6 +4,7 @@ use std::os::raw::{c_char, c_void};
|
|||
use std::path::Path;
|
||||
|
||||
use libloading;
|
||||
use crate::prelude::SystemInfo2;
|
||||
|
||||
use super::ffi::*;
|
||||
|
||||
|
@ -143,11 +144,11 @@ impl LibretroApi {
|
|||
unsafe { (&self.core_api.retro_api_version)() as u32 }
|
||||
}
|
||||
/// Gets statically known system info. Can be called at any time, even before retro_init().
|
||||
pub fn get_system_info(&self) -> SystemInfo {
|
||||
pub fn get_system_info(&self) -> SystemInfo2 {
|
||||
unsafe {
|
||||
let mut info = ::std::mem::zeroed::<SystemInfo>();
|
||||
(&self.core_api.retro_get_system_info)(&mut info);
|
||||
info
|
||||
SystemInfo2::from(&info)
|
||||
}
|
||||
}
|
||||
/// Gets information about system audio/video timings and geometry.
|
||||
|
|
|
@ -2,12 +2,24 @@ use core::convert::{TryFrom, TryInto};
|
|||
use core::mem::size_of;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::os::raw::{c_uint};
|
||||
use std::os::raw::{c_char, c_uint};
|
||||
use std::slice::from_raw_parts;
|
||||
|
||||
use super::constants::*;
|
||||
use super::ffi::*;
|
||||
|
||||
fn delimited_cstr(cstr: *const c_char, delim: char) -> Vec<String> {
|
||||
if cstr.is_null() {
|
||||
Vec::new()
|
||||
} else {
|
||||
unsafe { CStr::from_ptr(cstr) }
|
||||
.to_string_lossy()
|
||||
.split(delim)
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum VideoFrame<'a> {
|
||||
XRGB1555 { data: &'a [u16], width: c_uint, height: c_uint, pitch_u16: usize },
|
||||
|
@ -124,6 +136,26 @@ impl<D> TryFrom<(D, c_uint)> for InputDeviceId
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SystemInfo2 {
|
||||
pub library_name: String,
|
||||
pub library_version: String,
|
||||
pub valid_extensions: Vec<String>,
|
||||
pub need_fullpath: bool,
|
||||
pub block_extract: bool,
|
||||
}
|
||||
|
||||
impl From<&SystemInfo> for SystemInfo2 {
|
||||
fn from(info: &SystemInfo) -> Self {
|
||||
SystemInfo2 {
|
||||
library_name: unsafe { CStr::from_ptr(info.library_name) }.to_string_lossy().to_string(),
|
||||
library_version: unsafe { CStr::from_ptr(info.library_version) }.to_string_lossy().to_string(),
|
||||
valid_extensions: delimited_cstr(info.valid_extensions, '|'),
|
||||
need_fullpath: info.need_fullpath,
|
||||
block_extract: info.block_extract,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Variable2 {
|
||||
pub key: String,
|
||||
|
@ -145,7 +177,7 @@ impl From<&Variable> for Variable2 {
|
|||
.get(1)
|
||||
.unwrap_or(&"")
|
||||
.split('|')
|
||||
.map(String::from)
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
Variable2 {
|
||||
key,
|
||||
|
@ -268,11 +300,7 @@ impl From<&SubsystemRomInfo> for SubsystemRomInfo2 {
|
|||
description: unsafe { CStr::from_ptr(sri.desc) }
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
valid_extensions: unsafe { CStr::from_ptr(sri.valid_extensions) }
|
||||
.to_string_lossy()
|
||||
.split('|')
|
||||
.map(str::to_string)
|
||||
.collect(),
|
||||
valid_extensions: delimited_cstr(sri.valid_extensions, '|'),
|
||||
need_fullpath: sri.need_fullpath,
|
||||
block_extract: sri.block_extract,
|
||||
required: sri.required,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::path::Path;
|
||||
|
||||
use sdl2::Sdl;
|
||||
|
@ -108,7 +107,7 @@ impl RetroComponent for SimpleSdl2CanvasComponent {
|
|||
let sys_info = retro.get_system_info();
|
||||
let title = format!(
|
||||
"{} - {} - ferretro SDL",
|
||||
unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy(),
|
||||
sys_info.library_name,
|
||||
rom.file_stem().unwrap_or_default().to_string_lossy(),
|
||||
);
|
||||
self.canvas.window_mut().set_title(&title)?;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_uint;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -97,7 +96,7 @@ impl RetroComponent for SimpleSdl2OpenglComponent {
|
|||
let sys_info = retro.get_system_info();
|
||||
let title = format!(
|
||||
"{} - {} - ferretro SDL GL",
|
||||
unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy(),
|
||||
sys_info.library_name,
|
||||
rom.file_stem().unwrap_or_default().to_string_lossy(),
|
||||
);
|
||||
self.canvas.window_mut().set_title(&title)?;
|
||||
|
|
Loading…
Reference in New Issue