From 5e606220195b147ea47d5e3889683ffcdffac63e Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 18 Oct 2025 23:55:50 +0000 Subject: [PATCH] [android, tools] remove unused XML strings; add script to find unused XML strings Signed-off-by: lizzie --- .../app/src/main/res/values/strings.xml | 25 --------- tools/README.md | 1 + tools/find-unused-strings.pl | 53 +++++++++++++++++++ 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 tools/find-unused-strings.pl diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 13eaa5bd26..79767f9231 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -17,7 +17,6 @@ Increment Decrement - Value Value must be at least %1$d Value must be at most %1$d Invalid value @@ -50,8 +49,6 @@ Display current frames per second Show Frametime Display current frametime - Show Speed - Display current emulation speed percentage Show App Memory Usage Display the amount of RAM the emulator is using Show System Memory Usage @@ -344,8 +341,6 @@ Configure emulator settings Recently played Recently added - Retail - Homebrew Open Eden folder Manage Eden\'s internal files Modify the look of the app @@ -603,7 +598,6 @@ %1$s%2$s%3$sButton %4$s Axis %1$s%2$s Unused - Move or press an input Unsupported input type Input mapping filter Select a device to filter mapping inputs @@ -650,8 +644,6 @@ Default Saved settings Saved settings for %1$s - Error saving %1$s.ini: %2$s - Unimplemented Menu Loading… Shutting down… Do you want to reset this setting back to its default value? @@ -677,15 +669,11 @@ Imported successfully Exported successfully Start - Clear Global Custom - Notice Import complete - More options Use global setting The operation completed successfully - Retry Confirm Load Save @@ -703,12 +691,9 @@ Error while Fetching - Check your connection and try again. Show Releases - Release Notes Failed to fetch Error during Fetch - Toggle release notes Downloads Show Downloads Hide Downloads @@ -728,7 +713,6 @@ Settings - General System Docked mode, region, language Graphics @@ -841,8 +825,6 @@ Custom settings already exist for %1$s.\n\nWould you like to overwrite the existing configuration?\n\nThis action cannot be undone. Checking for existing configuration... Overwrite cancelled - Checking for custom driver: %1$s - Custom driver not available for this device Overwrite @@ -852,8 +834,6 @@ Driver installed successfully Driver Installation Failed Failed to install the GPU driver: %s - Driver Not Available - The selected driver is not available for download. Required driver not installed: %s Invalid driver file: %s No network connection available. Please check your internet connection and try again. @@ -865,8 +845,6 @@ Exit emulation Done - FPS counter - Thermal indicator Toggle controls Relative stick center D-pad slide @@ -921,7 +899,6 @@ 8GB (Unsafe) - Base (1000MHz) Boost (1700MHz) Fast (2000MHz) @@ -956,7 +933,6 @@ српски - Byte B KB MB @@ -1074,7 +1050,6 @@ Screenshot - Preparing shaders Building shaders diff --git a/tools/README.md b/tools/README.md index 35fd7a390c..5fa4614a96 100644 --- a/tools/README.md +++ b/tools/README.md @@ -8,6 +8,7 @@ Tools for Eden and other subprojects. ## Eden +- `find-unused-strings.pl`: Find unused strings (for Android XML files). - `shellcheck.sh`: Ensure POSIX compliance (and syntax sanity) for all tools in this directory and subdirectories. - `llvmpipe-run.sh`: Sets environment variables needed to run any command (or Eden) with llvmpipe. - `optimize-assets.sh`: Optimize PNG assets with OptiPng. diff --git a/tools/find-unused-strings.pl b/tools/find-unused-strings.pl new file mode 100644 index 0000000000..08b73486da --- /dev/null +++ b/tools/find-unused-strings.pl @@ -0,0 +1,53 @@ +#!/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;