From 30bb31c9ebf9865454a560a065c6a2fb5e1bd9d4 Mon Sep 17 00:00:00 2001 From: crueter Date: Sat, 18 Oct 2025 21:56:26 -0400 Subject: [PATCH] faster unused string find Signed-off-by: crueter --- .../app/src/main/res/values/strings.xml | 55 ------------------- tools/README.md | 2 + tools/find-unused-strings.pl | 53 ------------------ tools/unused-strings.sh | 33 +++++++++++ 4 files changed, 35 insertions(+), 108 deletions(-) delete mode 100644 tools/find-unused-strings.pl create mode 100755 tools/unused-strings.sh diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 79767f9231..380f0556ba 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -158,8 +158,6 @@ Multiplayer Host your own game room or join an existing one to play with people - Room: %1$s - Console ID:%1$s Create Join Browse Public Rooms @@ -168,11 +166,6 @@ Port Room created successfully Joined room successfully - Failed to create room - Failed to join room - Name is too short - Invalid address - Invalid port Exit Room Network error Lost connection @@ -201,21 +194,15 @@ %1$s banned Address unbanned Kick Out - Send messages… Password Joining… Creating… Room Name - Room name must be between 3 and 20 characters - Max Players (16) Max Players: %d Chat More Options - IP Address copied to clipboard - Server Address Chat Type message… - Send Send Message Moderation Ban List @@ -235,12 +222,8 @@ Hide Empty Rooms Tap refresh to check again Search Lobbies… - Multiplayer - Preferred Games Preferred Game Lobby Type - No Games Found - You must choose a Preferred Game to host a room. Must be between 3 and 20 characters Required Web Token required, go to Advanced Settings -> System -> Network @@ -274,7 +257,6 @@ Next Back Add Games - Select your games folder Complete! Bluetooth permissions granted. Bluetooth permissions denied. Controller support may be limited. @@ -291,14 +273,10 @@ Pre-Alpha Software WARNING: This software is in the pre-alpha stage and may have bugs and incomplete feature implementations. Don\'t Show Again - PRE-ALPHA SOFTWARE New game directory added successfully - Games Search Settings No files were found or no game directory has been selected yet. - Search and filter games - Select games folder Manage game folders Allows Eden to populate the games list Skip selecting games folder? @@ -306,7 +284,6 @@ https://yuzu-mirror.github.io/help/quickstart/#dumping-games Search games Search settings - Games directory selected Install prod.keys Required to decrypt retail games Skip adding keys? @@ -330,14 +307,10 @@ Cancel Install Amiibo keys Required to use Amiibo in game - Verify your keys file has a .bin extension and try again. - https://yuzu-mirror.github.io/help/quickstart/#dumping-decryption-keys GPU driver fetcher GPU driver manager - Install GPU driver Install alternative drivers for potentially better performance or accuracy Advanced settings - Advanced settings: %1$s Configure emulator settings Recently played Recently added @@ -351,18 +324,14 @@ Save data found. Please select an option below. Import save data This will overwrite all existing save data with the provided file. Are you sure that you want to continue? - Import or export save files Importing save files… Exporting save files… Imported successfully Invalid save directory structure The first subfolder name must be the title ID of the game. - Import - Export Install firmware Firmware must be in a ZIP archive and is needed to boot some games Installing firmware - Firmware installed successfully Firmware installation failed Make sure the firmware nca files are at the root of the zip and try again. Firmware uninstallation failed @@ -375,7 +344,6 @@ Error installing file(s) to NAND Please ensure content(s) are valid and that the prod.keys file is installed. Installation of base games isn\'t permitted in order to avoid possible conflicts. - Only NSP and XCI content is supported. Please verify the game content(s) are valid. %1$d installation error(s) Game content(s) installed successfully %1$d installed successfully @@ -385,8 +353,6 @@ Custom driver loading isn\'t currently supported for this device.\nCheck this option again in the future to see if support was added! Manage Eden data Import/export firmware, keys, user data, and more! - Share save file - Failed to export save Game folders Deep scan Add game folder @@ -413,11 +379,9 @@ Uninstalling firmware Firmware uninstalled successfully - Firmware Invalid Firmware is required to run certain games and use system applications. Eden only works with firmware 19.0.1 and earlier. Firmware reported as present, but was unable to be read. Check for decryption keys and redump firmware if necessary. Firmware is too new or could not be read. Eden only works with firmware 19.0.1 and earlier. - https://yuzu-mirror.github.io/help/quickstart/#dumping-system-firmware Failed to Install Keys Keys successfully installed @@ -458,7 +422,6 @@ Import/export all app data.\n\nWhen importing user data, all existing user data will be deleted!\n\nImporting data from Citron may cause issues. It\'s recommended to manually import all needed data. Exporting user data… Importing user data… - Import user data Invalid Eden backup User data exported successfully User data imported successfully @@ -598,7 +561,6 @@ %1$s%2$s%3$sButton %4$s Axis %1$s%2$s Unused - Unsupported input type Input mapping filter Select a device to filter mapping inputs Auto-map a controller @@ -642,8 +604,6 @@ Default - Saved settings - Saved settings for %1$s Loading… Shutting down… Do you want to reset this setting back to its default value? @@ -679,22 +639,16 @@ Save - Select GPU driver - Would you like to replace your current GPU driver? - Install Default - Using default GPU driver Invalid driver selected Driver already installed System GPU driver Installing driver… - Error while Fetching Show Releases Failed to fetch Error during Fetch - Downloads Show Downloads Hide Downloads Cache directory unavailable @@ -796,7 +750,6 @@ prod.keys file is installed so that games can be decrypted.]]> An error occurred initializing the video core This is usually caused by an incompatible GPU driver. Installing a custom GPU driver may resolve this problem. - Unable to load ROM ROM file does not exist Game Requires Firmware @@ -828,12 +781,6 @@ Overwrite - GPU Driver Missing - The selected custom driver \"%s\" is not installed. Would you like to download and install it now? - Downloading driver... - Driver installed successfully - Driver Installation Failed - Failed to install the GPU driver: %s Required driver not installed: %s Invalid driver file: %s No network connection available. Please check your internet connection and try again. @@ -865,7 +812,6 @@ Unlock drawer Reset - Loading settings… Software keyboard @@ -879,7 +825,6 @@ Save/Load Error Fatal Error A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes. - Turning off this setting will significantly degrade performance. It"s recommended that you leave this setting enabled. Device RAM: %1$s\nRecommended: %2$s %1$s %2$s No bootable game present! diff --git a/tools/README.md b/tools/README.md index 5fa4614a96..14547888a4 100644 --- a/tools/README.md +++ b/tools/README.md @@ -20,6 +20,8 @@ Tools for Eden and other subprojects. - `lanczos_gen.c` - `clang-format.sh`: Runs `clang-format` on the entire codebase. * Requires: clang +- `unused-strings.sh`: Finds unused strings in Android `strings.xml` files. + * It's recommended to run this after almost any Android change; this operation is relatively fast. ## Translations diff --git a/tools/find-unused-strings.pl b/tools/find-unused-strings.pl deleted file mode 100644 index 08b73486da..0000000000 --- a/tools/find-unused-strings.pl +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl -# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project -# SPDX-License-Identifier: GPL-3.0-or-later -use strict; -use warnings; -use List::Util qw(uniq); -open STRINGS, '<', 'src/android/app/src/main/res/values/strings.xml'; -my @raw_strings = ; -my @line_strings = grep {/\bstring name="\b/} @raw_strings; -my @strings = map { my @x = split('"', $_); $x[1] } @line_strings; -close STRINGS; -my $pattern = join('|', @strings); -my $regex = qr/($pattern)/; -my @unused_strings = @strings; -sub process_file { - my $b = $_[1]; - open FILE, "<".$_[0] or die "cant open ".$_[0]; - #print ""."\n"; - while (my $line = ) { - $line =~ s/^\s+|\s+$//g; #trim - if ($line =~ $regex) { - foreach my $e (@strings) { - my $re = $b != 0 ? ('\b'.quotemeta("R.string.".$e).'\b') : quotemeta("\@string/".$e); - #print "\n" if $line =~ /$re/; - @unused_strings = grep {!/$e/} @unused_strings if $line =~ /$re/; - } - } - } - close FILE; -} -# xml files -open XML_LIST, "find src/android/app/src/main -type f -iname '*.xml' |" || die; -foreach () { process_file($_, 0) if $_ !~ /\/strings.xml/; } -close XML_LIST; -# kotlin -open KOT_LIST, "find src/android/app/src/main -type f -iname '*.kt' |" || die; -foreach () { process_file $_, 1; } -close KOT_LIST; -#print "unused strings: ".scalar(@unused_strings)."\n"; -#foreach (@unused_strings) { print $_."\n"; } -open STRINGS, '<', 'src/android/app/src/main/res/values/strings.xml'; -while (my $line = ) { - my $b = 1; - if ($line =~ $regex) { - foreach my $e (@unused_strings) { - my $re = quotemeta('"'.$e.'"'); - print "\n" if $line =~ /$re/; - $b = $line =~ /$re/ ? 0 : $b; - } - } - print $line if $b > 0; -} -close STRINGS; diff --git a/tools/unused-strings.sh b/tools/unused-strings.sh new file mode 100755 index 0000000000..7cef95795b --- /dev/null +++ b/tools/unused-strings.sh @@ -0,0 +1,33 @@ +#!/bin/sh -e + +ANDROID=src/android/app/src/main +STRINGS=$ANDROID/res/values/strings.xml + +TMP_DIR=$(mktemp -d) + +USED="$TMP_DIR"/used +UNUSED="$TMP_DIR"/unused +FILTERED="$TMP_DIR"/filtered +ALL_STRINGS="$TMP_DIR"/all + +find $ANDROID -type f -iname '*.xml' -a -not -iname '*strings.xml' -o -iname '*.kt' | grep -v drawable > "$TMP_DIR"/files +grep -e "string name" $STRINGS | cut -d'"' -f2 > "$ALL_STRINGS" + +while IFS= read -r file; do +echo "$file" + grep -o 'R\.string\.[a-zA-Z0-9_]\+' "$file" >> "$USED" || true + grep -o '@string/[a-zA-Z0-9_]\+' "$file" >> "$USED" || true +done < "$TMP_DIR"/files + +sed 's/R.string.\|@string\///' "$USED" | sort -u | grep -v app_name_suffixed > "$FILTERED" +cat "$FILTERED" "$ALL_STRINGS" | sort | uniq -u > "$UNUSED" + +while IFS= read -r string; do + echo "$string" + find $ANDROID/res/values -iname '*strings.xml' | while IFS= read -r file; do + sed "/string name=\"$string\"/d" "$file" > "$file.new" + mv "$file.new" "$file" + done + # grep -re "R.string.$string\|@string/$string" $ANDROID | grep -v strings.xml || true +done < "$UNUSED" +