Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mod/etc/options_menu/themes/creator/scripts/om_applytheme
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
source $mountpoint/etc/options_menu/themes/scripts/om_vars
script_init

"$om_scripts/gen_splash" /tmp/om_splash.png THEME_SAVING && decodepng /tmp/om_splash.png >/dev/fb0
omSplash THEME_SAVING

name="diy_theme"
i=1
Expand Down
9 changes: 2 additions & 7 deletions mod/etc/options_menu/themes/creator/scripts/om_preview
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
source $mountpoint/etc/options_menu/themes/scripts/om_vars
script_init

"$om_scripts/gen_splash" /tmp/om_splash.png THEME_PREVIEW_LOADING && decodepng /tmp/om_splash.png >/dev/fb0
omSplash THEME_PREVIEW_LOADING
if [ ! -f "$b_file" ]; then
sed '1,2d' $om_theme_script >"$b_file"
echo "themeSelector" >"$p_file"
Expand All @@ -31,9 +31,4 @@ fi
source "$b_file"
themeSelector

echo "usleep 20000; \
uistart; \
chmenu 001; \
usleep 200000; \
chmenu 000; \
/etc/init.d/S8103OptionsMenu restart " >/var/exec.flag
omReloadMenuLater /etc/init.d/S8103OptionsMenu restart
11 changes: 10 additions & 1 deletion mod/etc/options_menu/themes/creator/scripts/om_removediy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
source $mountpoint/etc/options_menu/themes/scripts/om_vars
script_init

# a previewed DIY stays bound over the UI until the theme is mounted again
diy_bound=""
awk '$4 ~ /^\/diy_theme\// { found = 1 } END { exit !found }' /proc/self/mountinfo && diy_bound=1

diyThemeRemover

$options_menu/lib/theme_manager --commandPath $om_mod_gen_cmds/ --scriptPath $om_mod_gen_scripts --title "$om_title" &
if [ -n "$diy_bound" ]; then
omSplash THEME_RESTORING
omReloadMenuLater /etc/init.d/S8103OptionsMenu restart
else
$options_menu/lib/theme_manager --commandPath $om_mod_gen_cmds/ --scriptPath $om_mod_gen_scripts --title "$om_title" &
fi
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/de-DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Bitte warten . . .
THEME_LOADING_ASSETS=Assets werden geladen...
THEME_SAVING=Eigenes Theme wird gespeichert...
THEME_PREVIEW_LOADING=Themenvorschau wird geladen...
THEME_RESTORING=Design wird wiederhergestellt...
THEME_APPLYING_LINE1=Design wird übernommen
THEME_APPLYING_LINE2=Neustart läuft . . .
THEME_DELETE_IN_USE=Dieses Design ist aktiv und kann nicht entfernt werden.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/en-US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Please Wait . . .
THEME_LOADING_ASSETS=Loading assets...
THEME_SAVING=Saving custom theme...
THEME_PREVIEW_LOADING=Loading theme preview...
THEME_RESTORING=Restoring the theme...
THEME_APPLYING_LINE1=Applying Theme
THEME_APPLYING_LINE2=Rebooting Now . . .
THEME_DELETE_IN_USE=This theme is in use and can't be removed.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/es-ES.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Espere Por Favor . . .
THEME_LOADING_ASSETS=Cargando recursos...
THEME_SAVING=Guardando tema personalizado...
THEME_PREVIEW_LOADING=Cargando vista previa del tema...
THEME_RESTORING=Restaurando el tema...
THEME_APPLYING_LINE1=Aplicando Tema
THEME_APPLYING_LINE2=Reiniciando Ahora . . .
THEME_DELETE_IN_USE=Este tema está en uso y no se puede eliminar.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/fr-FR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Veuillez Patienter . . .
THEME_LOADING_ASSETS=Chargement des ressources...
THEME_SAVING=Enregistrement du thème personnalisé...
THEME_PREVIEW_LOADING=Chargement de l'aperçu du thème...
THEME_RESTORING=Restauration du thème...
THEME_APPLYING_LINE1=Application du Thème
THEME_APPLYING_LINE2=Redémarrage en Cours . . .
THEME_DELETE_IN_USE=Ce thème est utilisé et ne peut pas être supprimé.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/it-IT.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Attendere Prego . . .
THEME_LOADING_ASSETS=Caricamento risorse...
THEME_SAVING=Salvataggio tema personalizzato...
THEME_PREVIEW_LOADING=Caricamento anteprima tema...
THEME_RESTORING=Ripristino del tema...
THEME_APPLYING_LINE1=Applicazione del Tema in Corso
THEME_APPLYING_LINE2=Riavvio in Corso . . .
THEME_DELETE_IN_USE=Questo tema è in uso e non può essere eliminato.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/ja-JP.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=おまちください . . .
THEME_LOADING_ASSETS=Assetをよみこみちゅう...
THEME_SAVING=じぶんのThemeをほぞんちゅう...
THEME_PREVIEW_LOADING=Themeのpreviewをよみこみちゅう...
THEME_RESTORING=Themeをもとにもどしています...
THEME_APPLYING_LINE1=Themeを てきようしています
THEME_APPLYING_LINE2=さいきどうしています . . .
THEME_DELETE_IN_USE=このテーマは使用中のため削除できません。
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/nl-NL.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Even Geduld . . .
THEME_LOADING_ASSETS=Assets worden geladen...
THEME_SAVING=Eigen thema wordt opgeslagen...
THEME_PREVIEW_LOADING=Themavoorbeeld wordt geladen...
THEME_RESTORING=Thema wordt hersteld...
THEME_APPLYING_LINE1=Thema Wordt Toegepast
THEME_APPLYING_LINE2=Nu Herstarten . . .
THEME_DELETE_IN_USE=Dit thema wordt gebruikt en kan niet worden verwijderd.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/pt-PT.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Aguarde Por Favor . . .
THEME_LOADING_ASSETS=A carregar recursos...
THEME_SAVING=A guardar tema personalizado...
THEME_PREVIEW_LOADING=A carregar pré-visualização do tema...
THEME_RESTORING=A repor o tema...
THEME_APPLYING_LINE1=A Aplicar o Tema
THEME_APPLYING_LINE2=A Reiniciar Agora . . .
THEME_DELETE_IN_USE=Este tema está em uso e não pode ser removido.
1 change: 1 addition & 0 deletions mod/etc/options_menu/themes/lang/ru-RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ THEME_MOVING_LINE2=Пожалуйста, подождите . . .
THEME_LOADING_ASSETS=Загрузка ресурсов...
THEME_SAVING=Сохранение своей темы...
THEME_PREVIEW_LOADING=Загрузка предпросмотра темы...
THEME_RESTORING=Восстановление темы...
THEME_APPLYING_LINE1=Применение Темы
THEME_APPLYING_LINE2=Перезагрузка . . .
THEME_DELETE_IN_USE=Эта тема используется и не может быть удалена.
95 changes: 87 additions & 8 deletions mod/etc/options_menu/themes/scripts/om_overlaythmcript
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,83 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# corrected copies of theme files, at their path under the UI; they sit on top of the theme.
# /var is already a tmpfs at boot, where /tmp is still the NAND
theme_fixes="$mountpoint/var/theme_fixes"

themeFixesUnbind() {
awk -v dir="$original_theme/" 'index($5, dir) == 1 && $4 ~ /\/theme_fixes\// { print $5 }' /proc/self/mountinfo |
sed -n '1!G;h;$p' | while IFS= read -r fix; do
umount "$fix"
done
rm -rf "$theme_fixes"
}

# the USA/EUR firmwares name the s/m/l fonts *.font and the Super Famicom *.fnt;
# the UI exits when dependencies.json lists one that isn't there
themeDepsFix() {
local deps="$original_theme/dependencies.json"
local fixed="$theme_fixes/dependencies.json"
local font other
[ -f "$deps" ] || return 0
mkdir -p "$theme_fixes"
cp -f "$deps" "$fixed"
for font in $(grep -o '"/fonts/[^"]*"' "$deps" | tr -d '"'); do
[ -e "$original_theme/resources$font" ] && continue
case "$font" in
*.font) other="${font%.font}.fnt" ;;
*.fnt) other="${font%.fnt}.font" ;;
*) continue ;;
esac
[ -e "$original_theme/resources$other" ] && sed -i "s#\"$font\"#\"$other\"#" "$fixed"
done
if cmp -s "$deps" "$fixed"; then
rm -f "$fixed"
else
mount -o bind "$fixed" "$deps"
fi
}

# byte offset of the first occurrence of $2 in file $1
byteOffset() {
local want
want="$(printf '%s' "$2" | od -An -tx1 | tr -d ' \n')"
od -An -v -tx1 "$1" | tr -s ' ' '\n' | grep . | awk -v want="$want" -v n="${#2}" '
{ s = s $1; if (length(s) > 2 * n) s = substr(s, 3); if (s == want) { print NR - n; exit } }'
}

# each firmware reads only its own palette (env_<region>.lua loads colors_<region>); a theme made
# for another region gets its colors_*.lua renamed in place (same length) and bound over this one
themeColorsFix() {
local env_dir="$original_theme/resources/scripts/env"
local theme_env="$full_theme_path/resources/scripts/env"
local region src fixed offset
for region in jpn usa eur; do
[ -f "$env_dir/env_$region.lua" ] && break
done
[ -f "$env_dir/env_$region.lua" ] && [ ! -f "$theme_env/colors_$region.lua" ] || return 0
for src in usa eur jpn; do
[ -f "$theme_env/colors_$src.lua" ] && break
done
[ -f "$theme_env/colors_$src.lua" ] || return 0
fixed="$theme_fixes/resources/scripts/env/colors_$region.lua"
mkdir -p "${fixed%/*}"
cp -f "$theme_env/colors_$src.lua" "$fixed"
offset="$(byteOffset "$fixed" "colors_$src")"
if [ -z "$offset" ]; then
rm -f "$fixed"
return 0
fi
printf 'colors_%s' "$region" | dd of="$fixed" bs=1 seek="$offset" conv=notrunc 2>/dev/null
mount -o bind "$fixed" "$env_dir/colors_$region.lua"
}

fontBindFix() {
[ ! -f "${font_path}/title.fnt.backup" ] && cp "${font_path}/title.fnt" "${font_path}/title.fnt.backup"
for font_name in title s m l small medium large; do
if [ "$1" == "backup" ] && [ -f "$full_theme_path/fonts/${font_name}.fnt" ]; then
cp "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt"
cmp -s "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt" ||
cp "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt"
elif [ "$font_name" == "title" ]; then
cp "${font_path}/title.fnt.backup" "${font_path}/title.fnt"
else
Expand Down Expand Up @@ -75,30 +147,37 @@ themeSelector() {

local font_path="$mountpoint/media/$modname/fonts"
[ ! -d "$font_path" ] && font_path="$rootfs/usr/share/fonts"
local title_font="$font_path/title.fnt"
local title_theme_font="$full_theme_path/fonts/title.fnt"

# an install leaves the placeholder until a theme is applied from the menu
[ "$selected_theme" = "CHANGEME" ] && return 0

if [ "$selected_theme" != "$previous_theme" ] || [ ! -f "$last_theme" ] || [ ! -f "$active_theme_file" ]; then
echo "$selected_theme" >"$last_theme"
echo "$full_theme_path" >"$active_theme_file"
fi

if [ -d "$full_theme_path/fonts" ]; then
if [ "$(cksum "$title_font" | awk '{ print $1; }')" != "$(cksum "$title_theme_font" | awk '{ print $1; }')" ]; then
fontBindFix "backup"
fi
fontBindFix "backup"
else
fontBindFix "restore"
fi

themeFixesUnbind
mountpoint -q "$original_theme" && umount "$original_theme"
[ -d "$full_theme_path" ] && mount -t overlayfs -o lowerdir="$original_theme",upperdir="$full_theme_path" overlayfs "$original_theme"
themeDepsFix
themeColorsFix
local cl_functions="$rootfs/etc/options_menu/console_language/scripts/cl_functions"
if [ -f "$cl_functions" ]; then
# shellcheck source=/dev/null
source "$cl_functions"
clInit
clUmountLang
clMountLang
# older Console Language releases have no clRebind
if type clRebind >/dev/null 2>&1; then
clRebind
else
clUmountLang
clMountLang
fi
fi
}
95 changes: 88 additions & 7 deletions mod/etc/options_menu/themes/scripts/om_themescript
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,83 @@ unbindThemeMounts() {
[ -n "$mount_points" ] && echo "$mount_points" | xargs umount
}

# corrected copies of theme files, at their path under the UI; they sit on top of the theme.
# /var is already a tmpfs at boot, where /tmp is still the NAND
theme_fixes="$mountpoint/var/theme_fixes"

themeFixesUnbind() {
awk -v dir="$original_theme/" 'index($5, dir) == 1 && $4 ~ /\/theme_fixes\// { print $5 }' /proc/self/mountinfo |
sed -n '1!G;h;$p' | while IFS= read -r fix; do
umount "$fix"
done
rm -rf "$theme_fixes"
}

# the USA/EUR firmwares name the s/m/l fonts *.font and the Super Famicom *.fnt;
# the UI exits when dependencies.json lists one that isn't there
themeDepsFix() {
local deps="$original_theme/dependencies.json"
local fixed="$theme_fixes/dependencies.json"
local font other
[ -f "$deps" ] || return 0
mkdir -p "$theme_fixes"
cp -f "$deps" "$fixed"
for font in $(grep -o '"/fonts/[^"]*"' "$deps" | tr -d '"'); do
[ -e "$original_theme/resources$font" ] && continue
case "$font" in
*.font) other="${font%.font}.fnt" ;;
*.fnt) other="${font%.fnt}.font" ;;
*) continue ;;
esac
[ -e "$original_theme/resources$other" ] && sed -i "s#\"$font\"#\"$other\"#" "$fixed"
done
if cmp -s "$deps" "$fixed"; then
rm -f "$fixed"
else
mount -o bind "$fixed" "$deps"
fi
}

# byte offset of the first occurrence of $2 in file $1
byteOffset() {
local want
want="$(printf '%s' "$2" | od -An -tx1 | tr -d ' \n')"
od -An -v -tx1 "$1" | tr -s ' ' '\n' | grep . | awk -v want="$want" -v n="${#2}" '
{ s = s $1; if (length(s) > 2 * n) s = substr(s, 3); if (s == want) { print NR - n; exit } }'
}

# each firmware reads only its own palette (env_<region>.lua loads colors_<region>); a theme made
# for another region gets its colors_*.lua renamed in place (same length) and bound over this one
themeColorsFix() {
local env_dir="$original_theme/resources/scripts/env"
local theme_env="$full_theme_path/resources/scripts/env"
local region src fixed offset
for region in jpn usa eur; do
[ -f "$env_dir/env_$region.lua" ] && break
done
[ -f "$env_dir/env_$region.lua" ] && [ ! -f "$theme_env/colors_$region.lua" ] || return 0
for src in usa eur jpn; do
[ -f "$theme_env/colors_$src.lua" ] && break
done
[ -f "$theme_env/colors_$src.lua" ] || return 0
fixed="$theme_fixes/resources/scripts/env/colors_$region.lua"
mkdir -p "${fixed%/*}"
cp -f "$theme_env/colors_$src.lua" "$fixed"
offset="$(byteOffset "$fixed" "colors_$src")"
if [ -z "$offset" ]; then
rm -f "$fixed"
return 0
fi
printf 'colors_%s' "$region" | dd of="$fixed" bs=1 seek="$offset" conv=notrunc 2>/dev/null
mount -o bind "$fixed" "$env_dir/colors_$region.lua"
}

fontBindFix() {
[ ! -f "${font_path}/title.fnt.backup" ] && cp "${font_path}/title.fnt" "${font_path}/title.fnt.backup"
for font_name in title s m l small medium large; do
if [ "$1" == "backup" ] && [ -f "$full_theme_path/fonts/${font_name}.fnt" ]; then
cp "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt"
cmp -s "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt" ||
cp "$full_theme_path/fonts/${font_name}.fnt" "${font_path}/${font_name}.fnt"
elif [ "$font_name" == "title" ]; then
cp "${font_path}/title.fnt.backup" "${font_path}/title.fnt"
else
Expand Down Expand Up @@ -169,8 +241,6 @@ themeSelector() {
local full_theme_path="$themes_path/$selected_theme"
local font_path="$mountpoint/media/$modname/fonts"
[ ! -d "$font_path" ] && font_path="$rootfs/usr/share/fonts"
local title_font="$font_path/title.fnt"
local theme_font_path="$full_theme_path/fonts"

local silent_wav="$rootfs/usr/share/themes/bgm_boot.wav"
local music_path="$mountpoint/media/$modname/music_menu"
Expand Down Expand Up @@ -210,6 +280,9 @@ themeSelector() {
full_theme_path="$diy_theme"
fi

# an install leaves the placeholder until a theme is applied from the menu
[ "$selected_theme" = "CHANGEME" ] && [ "$full_theme_path" != "$diy_theme" ] && return 0

if [ "$selected_theme" != "$previous_theme" ] || [ ! -f "$last_theme" ] || [ ! -f "$active_theme_file" ]; then
echo "$selected_theme" >"$last_theme"
echo "$full_theme_path" >"$active_theme_file"
Expand All @@ -222,12 +295,13 @@ themeSelector() {
return 0
fi

if [ -d "$theme_font_path" ]; then
cmp -s "$title_font" "$theme_font_path/title.fnt" || fontBindFix "backup"
if [ -d "$full_theme_path/fonts" ]; then
fontBindFix "backup"
else
fontBindFix "restore"
fi

themeFixesUnbind
unbindThemeMounts
while grep -q " $original_theme overlayfs " /proc/mounts; do
umount -l "$original_theme" || break
Expand All @@ -252,14 +326,21 @@ themeSelector() {
done
fi
[ -n "$assigned_music" ] && musicHackBind "$music_path/$assigned_music" "$music_path/$assigned_music" "$original_theme_audio"
themeDepsFix
themeColorsFix

local cl_functions="$rootfs/etc/options_menu/console_language/scripts/cl_functions"
if [ -f "$cl_functions" ]; then
# shellcheck source=/dev/null
source "$cl_functions"
clInit
clUmountLang
clMountLang
# older Console Language releases have no clRebind
if type clRebind >/dev/null 2>&1; then
clRebind
else
clUmountLang
clMountLang
fi
fi
[ -z "$mountpoint" ] && echo "$applied" >"$applied_file"
}
Loading
Loading