From 99fe6f79d5e877226025600e8456320a1820f234 Mon Sep 17 00:00:00 2001 From: Argent77 <4519923+Argent77@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:42:43 +0200 Subject: [PATCH] Check for unused files: Include string table when checking WAV resources Strings with associated WAV resources were ignored when scanning scripts. --- .../infinity/check/ResourceUseChecker.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/check/ResourceUseChecker.java b/src/org/infinity/check/ResourceUseChecker.java index 95346d04a..9edcd8e00 100644 --- a/src/org/infinity/check/ResourceUseChecker.java +++ b/src/org/infinity/check/ResourceUseChecker.java @@ -304,6 +304,9 @@ private void checkCode(String compiledCode, ScriptType type) throws Exception { for (final ResourceEntry entry : decompiler.getResourcesUsed()) { unusedResources.remove(entry.getResourceName()); } + for (final int strref : decompiler.getStringRefsUsed()) { + checkSound(strref); + } } } @@ -331,9 +334,22 @@ private void checkResourceRef(ResourceRef ref) { * @param ref Reference to entry in string table that contains sound file name */ private void checkSound(StringRef ref) { - final int index = ref.getValue(); - if (index >= 0) { - final String wav = StringTable.getSoundResource(index); + if (ref != null) { + checkSound(ref.getValue()); + } + } + + /** + * If string reference has the associated sound, removes this sound from {@link #unusedResources}, otherwise do + * nothing. + *

+ * This method can be called from several threads + * + * @param ref Reference to entry in string table that contains sound file name + */ + private void checkSound(int strref) { + if (strref >= 0) { + final String wav = StringTable.getSoundResource(strref); if (!wav.isEmpty()) { removeEntries(wav + ".WAV"); }