From 6166566fc6a7302e87d32a05eb60f2d71f25d4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 16 Sep 2024 05:51:58 +0200 Subject: [PATCH] Fixed: #2310 Text search history showing as null --- CHANGELOG.md | 4 +- .../flash/gui/SearchResultsStorage.java | 68 ++++++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d8ca0b87..477d5fe27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ All notable changes to this project will be documented in this file. - [#2309] XML export/import - Decimal support - [#2300], [#2303] ShellFolder Comparator Windows Java error - [#2302] AS3 Class linkage - changes did not save -- [PR203] AS1/2 lagging on saving +- [PR203] AS1/2 extreme lagging +- [#2310] Text search history showing as null ## [21.0.5] - 2024-09-05 ### Fixed @@ -3548,6 +3549,7 @@ Major version of SWF to XML export changed to 2. [#2300]: https://www.free-decompiler.com/flash/issues/2300 [#2303]: https://www.free-decompiler.com/flash/issues/2303 [#2302]: https://www.free-decompiler.com/flash/issues/2302 +[#2310]: https://www.free-decompiler.com/flash/issues/2310 [#2293]: https://www.free-decompiler.com/flash/issues/2293 [#2294]: https://www.free-decompiler.com/flash/issues/2294 [#2299]: https://www.free-decompiler.com/flash/issues/2299 diff --git a/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java b/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java index 877df1b25..b095aef13 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java @@ -67,7 +67,7 @@ public class SearchResultsStorage { private int currentGroupId = 0; - public void finishGroup() { + public synchronized void finishGroup() { currentGroupId++; } @@ -91,12 +91,12 @@ public class SearchResultsStorage { return "**NONE**"; } - public int getCount() { + public synchronized int getCount() { return openableIds.size(); } - public String getSearchedValueAt(int index) { - for (int j = 0; j < data.size(); j++) { + public synchronized String getSearchedValueAt(int index) { + for (int j = 0; j < groups.size(); j++) { if (groups.get(j) == index) { return searchedValues.get(j); } @@ -104,7 +104,7 @@ public class SearchResultsStorage { return null; } - public boolean isIgnoreCaseAt(int index) { + public synchronized boolean isIgnoreCaseAt(int index) { for (int j = 0; j < data.size(); j++) { if (groups.get(j) == index) { return isIgnoreCase.get(j); @@ -113,7 +113,7 @@ public class SearchResultsStorage { return false; } - public boolean isRegExpAt(int index) { + public synchronized boolean isRegExpAt(int index) { for (int j = 0; j < data.size(); j++) { if (groups.get(j) == index) { return isRegExp.get(j); @@ -122,7 +122,7 @@ public class SearchResultsStorage { return false; } - public List getIndicesForOpenable(Openable swf) { + public synchronized List getIndicesForOpenable(Openable swf) { String swfId = getOpenableId(swf); List res = new ArrayList<>(); Set foundGroups = new LinkedHashSet<>(); @@ -135,7 +135,7 @@ public class SearchResultsStorage { } @SuppressWarnings("unchecked") - public List getSearchResultsAt(Set allOpenables, int index) { + public synchronized List getSearchResultsAt(Set allOpenables, int index) { List result = new ArrayList<>(); Map openableIdToOpenable = new HashMap<>(); @@ -191,7 +191,7 @@ public class SearchResultsStorage { } @SuppressWarnings("unchecked") - public void load() throws IOException { + public synchronized void load() throws IOException { String configFile = getConfigFile(); if (new File(configFile).exists()) { try (FileInputStream fis = new FileInputStream(configFile); ObjectInputStream ois = new ObjectInputStream(fis)) { @@ -206,6 +206,22 @@ public class SearchResultsStorage { isRegExp = (List) ois.readObject(); groups = (List) ois.readObject(); data = readByteList(ois); + + int size = openableIds.size(); + if (searchedValues.size() != size + || isIgnoreCase.size() != size + || isRegExp.size() != size + || groups.size() != size + || data.size() != size) { + //something wrong, do not load this state + openableIds.clear(); + searchedValues.clear(); + isIgnoreCase.clear(); + isRegExp.clear(); + groups.clear(); + data.clear(); + } + int maxgroup = -1; for (int g : groups) { if (g > maxgroup) { @@ -220,11 +236,30 @@ public class SearchResultsStorage { } } catch (ClassNotFoundException ex) { Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException iex) { + openableIds.clear(); + searchedValues.clear(); + isIgnoreCase.clear(); + isRegExp.clear(); + groups.clear(); + data.clear(); + unpackedData.clear(); + currentGroupId = 0; + throw iex; } } } - public void save() throws IOException { + public synchronized void save() throws IOException { + int size = openableIds.size(); + if (searchedValues.size() != size + || isIgnoreCase.size() != size + || isRegExp.size() != size + || groups.size() != size + || data.size() != size) { + //something wrong, do not save this state + return; + } String configFile = getConfigFile(); try (FileOutputStream fos = new FileOutputStream(configFile); ObjectOutputStream oos = new ObjectOutputStream(fos)) { oos.write(SERIAL_VERSION_MAJOR); @@ -238,7 +273,7 @@ public class SearchResultsStorage { } } - public void addABCResults(Openable openable, String searchedString, boolean ignoreCase, boolean regExp, List results) { + public synchronized void addABCResults(Openable openable, String searchedString, boolean ignoreCase, boolean regExp, List results) { openableIds.add(getOpenableId(openable)); searchedValues.add(searchedString); isIgnoreCase.add(ignoreCase); @@ -265,7 +300,7 @@ public class SearchResultsStorage { } - public void addActionResults(SWF swf, String searchedString, boolean ignoreCase, boolean regExp, List results) { + public synchronized void addActionResults(SWF swf, String searchedString, boolean ignoreCase, boolean regExp, List results) { openableIds.add(getOpenableId(swf)); searchedValues.add(searchedString); isIgnoreCase.add(ignoreCase); @@ -290,7 +325,7 @@ public class SearchResultsStorage { data.add(baos.toByteArray()); } - public void clear() { + public synchronized void clear() { openableIds.clear(); searchedValues.clear(); isIgnoreCase.clear(); @@ -300,9 +335,9 @@ public class SearchResultsStorage { unpackedData.clear(); } - public void clearForOpenable(Openable openable) { + public synchronized void clearForOpenable(Openable openable) { String swfId = getOpenableId(openable); - for (int i = 0; i < openableIds.size(); i++) { + for (int i = openableIds.size() - 1; i >= 0; i--) { if (openableIds.get(i).equals(swfId)) { openableIds.remove(i); searchedValues.remove(i); @@ -311,7 +346,6 @@ public class SearchResultsStorage { groups.remove(i); data.remove(i); unpackedData.remove(i); - i--; } } } @@ -336,7 +370,7 @@ public class SearchResultsStorage { return ret; } - public void destroySwf(SWF swf) { + public synchronized void destroySwf(SWF swf) { String swfId = getOpenableId(swf); for (int i = 0; i < openableIds.size(); i++) { if (openableIds.get(i).equals(swfId) && unpackedData.size() > i) {