Skip to content

Commit

Permalink
retroarch: added reset configurations helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cmitu committed Feb 5, 2021
1 parent cf5cdd4 commit 9e3e617
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scriptmodules/emulators/retroarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,37 @@ function _set_config_option_retroarch()
iniSet "$option" "$value"
fi
}

# Resets the `retroarch.cfg` for a system
# @parm system - the system to reset. If empty, reset the global RetroArch config
function _reset_system_retro_config_retroarch() {
local sys="$1"
local cfg
if [[ -z "$sys" ]]; then
printMsgs console "Resetting global RetroArch configuration"
cfg="$configdir/all/retroarch.cfg"
else
printMsgs console "Resetting $sys RetroArch configuration"
cfg="$configdir/$sys/retroarch.cfg"
fi

[[ -f "$cfg" ]] && mv "$cfg" "${cfg}_$(date +"%Y.%m.%d_%H.%M").bak"

if [[ -f "$cfg.rp-dist" ]]; then
copyDefaultConfig "$cfg.rp-dist" "$cfg"
else
# No .rp-dist available, so it's not the global conf
if [[ -n "$sys" ]]; then
ensureSystemretroconfig "$sys"
fi
fi
}

# Find the core 'library_name' for a libretro core
# This is used by RetroArch to store core related configurations
function _get_core_name_retroarch() {
local core_file="$1"
[[ -z "$core_file" ]] && return ""

LD_LIBRARY_PATH="$(dirname "$core_file")" python3 "$md_data/get_libretro_name.py" "$core_file"
}
29 changes: 29 additions & 0 deletions scriptmodules/emulators/retroarch/get_libretro_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
import ctypes
import sys
import os.path

class RetroSystemInfo(ctypes.Structure):
_fields_ = [
("library_name", ctypes.c_char_p),
("library_version", ctypes.c_char_p),
("valid_extensions", ctypes.c_char_p),
("need_fullpath", ctypes.c_bool),
("block_extract", ctypes.c_bool)
]

retro_info = RetroSystemInfo(b'', b'', b'', False, False)

if sys.argv[1:]:
if not os.path.isfile(sys.argv[1]):
print('File not found', file=sys.stderr)
sys.exit(1)

core_file_name = sys.argv[1]
try:
core_file = ctypes.cdll.LoadLibrary(core_file_name)
core_file.retro_get_system_info(ctypes.byref(retro_info))
print(retro_info.library_name.decode('LATIN1'));
except Exception as e:
print('Cannot load DSO ' + str(e), file=sys.stderr )
sys.exit(2)

0 comments on commit 9e3e617

Please sign in to comment.