Skip to content

Commit

Permalink
Add Region setting for emulator labels
Browse files Browse the repository at this point in the history
- add "emulators_list.db" database which contains  directory names, emulator names (depending the region), manufacturer, release date, ... It will be a database to maintain to allow quick renaming via System Tools.
- add scripts which allow to rename all the emulators in one click

This database will be used to offer the possibility to the user to select the kind of emulator label he want:
https://docs.google.com/spreadsheets/d/1sSi6PamSL6nHU3nORooms9AjNKYcoGGDZNJbUkF-sa0/edit?usp=sharing
For example US users want "Genesis" and EU want "Mega Drive". Do not hesitate to post an issue if there are errors.

For each US/EU/JP there is a full name and a short name. The short name will be used to prefix with manufacturer name (and group the emulators by manufacturer).

For example you'll have the choice between:
- if you're from EU: Mega Drive or Seg. MD
- if you're from US: Genesis or Seg. Gen.

The current type of emulator label is kept in crossmix.json as "EMU LABELS".

These emulator rename scripts will be used later by CrossMix "Theme Pack Selector".
  • Loading branch information
cizia64 committed Jul 6, 2024
1 parent eb03ed4 commit 12e425b
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 17 deletions.
11 changes: 7 additions & 4 deletions Apps/EmuCleaner/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ for arg in "$@"; do
fi
done

EmuCleanerPath="$(dirname "$0")/"
RomsFolder="/mnt/SDCARD/Roms"
EmuFolder="/mnt/SDCARD/Emus"
json_file="/mnt/SDCARD/Emus/show.json"
Expand All @@ -20,7 +21,7 @@ NumRemoved=0
NumAdded=0

if [ "$silent" = false ]; then
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -i ./background.jpg
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -i "$EmuCleanerPath/background.jpg"
fi

write_entry() {
Expand Down Expand Up @@ -82,8 +83,10 @@ sed -i '$ s/,$//' $json_file
echo "]" >>$json_file
sync

# Refresh Emus list
jq '(.list[].tabstate[] | select(has("pagestart"))).pagestart = 0 | (.list[].tabstate[] | select(has("pageend"))).pageend = 7' /tmp/state.json >/tmp/state.tmp && mv /tmp/state.tmp /tmp/state.json
if [ "$silent" = false ]; then
# Refresh Emus list
jq '(.list[].tabstate[] | select(has("pagestart"))).pagestart = 0 | (.list[].tabstate[] | select(has("pageend"))).pageend = 7' /tmp/state.json >/tmp/state.tmp && mv /tmp/state.tmp /tmp/state.json
fi

sync

Expand All @@ -92,5 +95,5 @@ echo -ne "${NumRemoved} hidden emulator(s)\n${NumAdded} displayed emulator(s)\n"
echo -ne "=============================\n\n"

if [ "$silent" = false ]; then
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -i ./background-info.jpg -m "${NumAdded} displayed emulator(s). ${NumRemoved} hidden emulator(s)." -t 2
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -i "$EmuCleanerPath/background-info.jpg" -m "${NumAdded} displayed emulator(s). ${NumRemoved} hidden emulator(s)." -t 2.5
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

# Export necessary environment variables
export PATH="/mnt/SDCARD/System/bin:$PATH"
export LD_LIBRARY_PATH="/mnt/SDCARD/System/lib:/usr/trimui/lib:$LD_LIBRARY_PATH"

# Display a message indicating the application of default icons
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -m "Applying \"$(basename "$0" .sh)\" icons by default..."

# Get the script name without the extension
script_name=$(basename "$0" .sh)

# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all directories in /mnt/SDCARD/Emus/
for dir in /mnt/SDCARD/Emus/*/; do
folder_name=$(basename "$dir")
# Skip directories starting with an underscore
if [[ "$folder_name" == _* ]]; then
echo "Skipping $folder_name"
continue
fi
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_full_EU from the database
trimui_name_full_EU=$(sqlite3 "$db_path" "SELECT trimui_name_full_EU FROM systems WHERE crossmix_foldername = '$folder_name'")
if [ -n "$trimui_name_full_EU" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_full_EU" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$trimui_name_full_EU\""
else
echo "No trimui_name_full_EU found for folder $folder_name"
fi
fi
done

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
if [ ! -f "$json_file" ]; then
echo "{}" >"$json_file"
fi
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '. += {"EMU LABELS": $script_name}' "$json_file" >"/tmp/json_file.tmp" && mv "/tmp/json_file.tmp" "$json_file"

# Update the SQLite database
database_file="/mnt/SDCARD/Apps/SystemTools/Menu/Menu_cache7.db"
sqlite3 "$database_file" <<EOF
UPDATE Menu_roms SET disp = 'EMULATOR LABELS ($script_name)', pinyin = 'EMULATOR LABELS ($script_name)', cpinyin = 'EMULATOR LABELS ($script_name)', opinyin = 'EMULATOR LABELS ($script_name)' WHERE disp LIKE 'EMULATOR LABELS (%)';
UPDATE Menu_roms SET ppath = 'EMULATOR LABELS ($script_name)' WHERE ppath LIKE 'EMULATOR LABELS (%)';
EOF

# Update the state.json file if it exists
json_file="/tmp/state.json"
if [ -f "$json_file" ]; then
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '.list |= map(if (.ppath | index("EMULATOR LABELS ")) then .ppath = "EMULATOR LABELS (\($script_name))" else . end)' "$json_file" > "$json_file.tmp" && mv "$json_file.tmp" "$json_file"
fi

# Synchronize the filesystem
sync
sleep 0.1

# Labels has changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# Export necessary environment variables
export PATH="/mnt/SDCARD/System/bin:$PATH"
export LD_LIBRARY_PATH="/mnt/SDCARD/System/lib:/usr/trimui/lib:$LD_LIBRARY_PATH"

# Display a message indicating the application of default icons
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -m "Applying \"$(basename "$0" .sh)\" icons by default..."

# Get the script name without the extension
script_name=$(basename "$0" .sh)

# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all directories in /mnt/SDCARD/Emus/
for dir in /mnt/SDCARD/Emus/*/; do
folder_name=$(basename "$dir")
# Skip directories starting with an underscore
if [[ "$folder_name" == _* ]]; then
echo "Skipping $folder_name"
continue
fi

config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_full_US from the database
trimui_name_full_US=$(sqlite3 "$db_path" "SELECT trimui_name_full_US FROM systems WHERE crossmix_foldername = '$folder_name'")
if [ -n "$trimui_name_full_US" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_full_US" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$trimui_name_full_US\""
else
echo "No trimui_name_full_US found for folder $folder_name"
fi
fi
done

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
if [ ! -f "$json_file" ]; then
echo "{}" >"$json_file"
fi
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '. += {"EMU LABELS": $script_name}' "$json_file" >"/tmp/json_file.tmp" && mv "/tmp/json_file.tmp" "$json_file"

# Update the SQLite database
database_file="/mnt/SDCARD/Apps/SystemTools/Menu/Menu_cache7.db"
sqlite3 "$database_file" <<EOF
UPDATE Menu_roms SET disp = 'EMULATOR LABELS ($script_name)', pinyin = 'EMULATOR LABELS ($script_name)', cpinyin = 'EMULATOR LABELS ($script_name)', opinyin = 'EMULATOR LABELS ($script_name)' WHERE disp LIKE 'EMULATOR LABELS (%)';
UPDATE Menu_roms SET ppath = 'EMULATOR LABELS ($script_name)' WHERE ppath LIKE 'EMULATOR LABELS (%)';
EOF

# Update the state.json file if it exists
json_file="/tmp/state.json"
if [ -f "$json_file" ]; then
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '.list |= map(if (.ppath | index("EMULATOR LABELS ")) then .ppath = "EMULATOR LABELS (\($script_name))" else . end)' "$json_file" > "$json_file.tmp" && mv "$json_file.tmp" "$json_file"
fi

# Synchronize the filesystem
sync
sleep 0.1

# Labels has changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# Export necessary environment variables
export PATH="/mnt/SDCARD/System/bin:$PATH"
export LD_LIBRARY_PATH="/mnt/SDCARD/System/lib:/usr/trimui/lib:$LD_LIBRARY_PATH"

# Display a message indicating the application of default icons
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -m "Applying \"$(basename "$0" .sh)\" icons by default..."

# Get the script name without the extension
script_name=$(basename "$0" .sh)

# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all directories in /mnt/SDCARD/Emus/
for dir in /mnt/SDCARD/Emus/*/; do
folder_name=$(basename "$dir")
# Skip directories starting with an underscore
if [[ "$folder_name" == _* ]]; then
echo "Skipping $folder_name"
continue
fi

config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_short_EU from the database
trimui_name_short_EU=$(sqlite3 "$db_path" "SELECT trimui_name_short_EU FROM systems WHERE crossmix_foldername = '$folder_name'")
if [ -n "$trimui_name_short_EU" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_short_EU" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$trimui_name_short_EU\""
else
echo "No trimui_name_short_EU found for folder $folder_name"
fi
fi
done

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
if [ ! -f "$json_file" ]; then
echo "{}" >"$json_file"
fi
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '. += {"EMU LABELS": $script_name}' "$json_file" >"/tmp/json_file.tmp" && mv "/tmp/json_file.tmp" "$json_file"

# Update the SQLite database
database_file="/mnt/SDCARD/Apps/SystemTools/Menu/Menu_cache7.db"
sqlite3 "$database_file" <<EOF
UPDATE Menu_roms SET disp = 'EMULATOR LABELS ($script_name)', pinyin = 'EMULATOR LABELS ($script_name)', cpinyin = 'EMULATOR LABELS ($script_name)', opinyin = 'EMULATOR LABELS ($script_name)' WHERE disp LIKE 'EMULATOR LABELS (%)';
UPDATE Menu_roms SET ppath = 'EMULATOR LABELS ($script_name)' WHERE ppath LIKE 'EMULATOR LABELS (%)';
EOF

# Update the state.json file if it exists
json_file="/tmp/state.json"
if [ -f "$json_file" ]; then
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '.list |= map(if (.ppath | index("EMULATOR LABELS ")) then .ppath = "EMULATOR LABELS (\($script_name))" else . end)' "$json_file" > "$json_file.tmp" && mv "$json_file.tmp" "$json_file"
fi

# Synchronize the filesystem
sync
sleep 0.1

# Labels has changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# Export necessary environment variables
export PATH="/mnt/SDCARD/System/bin:$PATH"
export LD_LIBRARY_PATH="/mnt/SDCARD/System/lib:/usr/trimui/lib:$LD_LIBRARY_PATH"

# Display a message indicating the application of default icons
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -m "Applying \"$(basename "$0" .sh)\" icons by default..."

# Get the script name without the extension
script_name=$(basename "$0" .sh)

# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all directories in /mnt/SDCARD/Emus/
for dir in /mnt/SDCARD/Emus/*/; do
folder_name=$(basename "$dir")
# Skip directories starting with an underscore
if [[ "$folder_name" == _* ]]; then
echo "Skipping $folder_name"
continue
fi

config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_short_US from the database
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_US FROM systems WHERE crossmix_foldername = '$folder_name'")
if [ -n "$trimui_name_short_US" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_short_US" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$trimui_name_short_US\""
else
echo "No trimui_name_short_US found for folder $folder_name"
fi
fi
done

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
if [ ! -f "$json_file" ]; then
echo "{}" >"$json_file"
fi
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '. += {"EMU LABELS": $script_name}' "$json_file" >"/tmp/json_file.tmp" && mv "/tmp/json_file.tmp" "$json_file"

# Update the SQLite database
database_file="/mnt/SDCARD/Apps/SystemTools/Menu/Menu_cache7.db"
sqlite3 "$database_file" <<EOF
UPDATE Menu_roms SET disp = 'EMULATOR LABELS ($script_name)', pinyin = 'EMULATOR LABELS ($script_name)', cpinyin = 'EMULATOR LABELS ($script_name)', opinyin = 'EMULATOR LABELS ($script_name)' WHERE disp LIKE 'EMULATOR LABELS (%)';
UPDATE Menu_roms SET ppath = 'EMULATOR LABELS ($script_name)' WHERE ppath LIKE 'EMULATOR LABELS (%)';
EOF

# Update the state.json file if it exists
json_file="/tmp/state.json"
if [ -f "$json_file" ]; then
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '.list |= map(if (.ppath | index("EMULATOR LABELS ")) then .ppath = "EMULATOR LABELS (\($script_name))" else . end)' "$json_file" > "$json_file.tmp" && mv "$json_file.tmp" "$json_file"
fi

# Synchronize the filesystem
sync
sleep 0.1

# Labels has changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

# Export necessary environment variables
export PATH="/mnt/SDCARD/System/bin:$PATH"
export LD_LIBRARY_PATH="/mnt/SDCARD/System/lib:/usr/trimui/lib:$LD_LIBRARY_PATH"

# Display a message indicating the application of default icons
/mnt/SDCARD/System/usr/trimui/scripts/infoscreen.sh -m "Applying \"$(basename "$0" .sh)\" icons by default..."

# Get the script name without the extension
script_name=$(basename "$0" .sh)

# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all config.json files in /mnt/SDCARD/Emus/ and set the label from the database
find /mnt/SDCARD/Emus/ -type d -exec sh -c '
for dir do
config_file="$dir/config.json"
if [ -f "$config_file" ]; then
folder_name=$(basename "$dir")
# Retrieve the crossmix_name from the database
crossmix_name=$(sqlite3 '"$db_path"' "SELECT crossmix_name FROM systems WHERE crossmix_foldername = \"$folder_name\"")
if [ -n "$crossmix_name" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$crossmix_name" ".label = \$new_label" "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to $crossmix_name"
else
echo "No crossmix_name found for folder $folder_name"
fi
fi
done
' sh {} +

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
if [ ! -f "$json_file" ]; then
echo "{}" >"$json_file"
fi
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '. += {"EMU LABELS": $script_name}' "$json_file" >"/tmp/json_file.tmp" && mv "/tmp/json_file.tmp" "$json_file"

# Update the SQLite database
database_file="/mnt/SDCARD/Apps/SystemTools/Menu/Menu_cache7.db"
sqlite3 "$database_file" <<EOF
UPDATE Menu_roms SET disp = 'EMULATOR LABELS ($script_name)', pinyin = 'EMULATOR LABELS ($script_name)', cpinyin = 'EMULATOR LABELS ($script_name)', opinyin = 'EMULATOR LABELS ($script_name)' WHERE disp LIKE 'EMULATOR LABELS (%)';
UPDATE Menu_roms SET ppath = 'EMULATOR LABELS ($script_name)' WHERE ppath LIKE 'EMULATOR LABELS (%)';
EOF

# Update the state.json file if it exists
json_file="/tmp/state.json"
if [ -f "$json_file" ]; then
/mnt/SDCARD/System/bin/jq --arg script_name "$script_name" '.list |= map(if (.ppath | index("EMULATOR LABELS ")) then .ppath = "EMULATOR LABELS (\($script_name))" else . end)' "$json_file" > "$json_file.tmp" && mv "$json_file.tmp" "$json_file"
fi

# Synchronize the filesystem
sync
sleep 0.1

# Labels has changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Loading

0 comments on commit 12e425b

Please sign in to comment.