From e9587f7ece4cb14e03bc8a794502463f47e8b2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 7 Mar 2021 14:10:47 +0100 Subject: [PATCH] Fixed: #1648 Search - loaded search results mixed --- CHANGELOG.md | 2 + .../flash/gui/SearchResultsStorage.java | 43 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 940cb3068..88de7dcd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. - [#1332] Flash viewer - Show directly added images when placeFlagHasImage is true on AS3 swfs - XML Import - not set SWF and Timelined internal values caused an exception on item display - Goto usage exception and incorrect trait position +- [#1648] Search - loaded search results mixed ## [14.1.0] - 2021-03-05 ### Added @@ -2096,6 +2097,7 @@ All notable changes to this project will be documented in this file. [#1636]: https://www.free-decompiler.com/flash/issues/1636 [#1647]: https://www.free-decompiler.com/flash/issues/1647 [#1332]: https://www.free-decompiler.com/flash/issues/1332 +[#1648]: https://www.free-decompiler.com/flash/issues/1648 [#1561]: https://www.free-decompiler.com/flash/issues/1561 [#1623]: https://www.free-decompiler.com/flash/issues/1623 [#1622]: https://www.free-decompiler.com/flash/issues/1622 diff --git a/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java b/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java index 146f564e6..82ef24cb1 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchResultsStorage.java @@ -64,7 +64,7 @@ public class SearchResultsStorage { List isRegExp = new ArrayList<>(); List isIgnoreCase = new ArrayList<>(); List data = new ArrayList<>(); - Map> unpackedData = new HashMap<>(); + List> unpackedData = new ArrayList<>(); List groups = new ArrayList<>(); private int currentGroupId = 0; @@ -138,18 +138,6 @@ public class SearchResultsStorage { @SuppressWarnings("unchecked") public List getSearchResultsAt(Set allSwfs, int index) { - if (unpackedData.containsKey(index)) { - - List unpacked = unpackedData.get(index); - List res = new ArrayList<>(); - for (ScriptSearchResult sr : unpacked) { - if (allSwfs.contains(sr.getSWF())) { - res.add(sr); - } - } - - return res; - } List result = new ArrayList<>(); Map swfIdToSwf = new HashMap<>(); @@ -162,8 +150,18 @@ public class SearchResultsStorage { if (!swfIdToSwf.containsKey(swfIds.get(j))) { continue; } + if (unpackedData.get(j) != null) { + List unpacked = unpackedData.get(j); + for (ScriptSearchResult sr : unpacked) { + if (allSwfs.contains(sr.getSWF())) { + result.add(sr); + } + } + continue; + } SWF swf = swfIdToSwf.get(swfIds.get(j)); byte[] itemData = data.get(j); + List currentResults = new ArrayList<>(); try { ByteArrayInputStream bais1 = new ByteArrayInputStream(itemData); int kind = bais1.read(); @@ -174,10 +172,10 @@ public class SearchResultsStorage { ByteArrayInputStream bais = new ByteArrayInputStream(resultData.get(i)); if (kind == DATA_ABC) { - result.add(new ABCSearchResult(swf, bais)); + currentResults.add(new ABCSearchResult(swf, bais)); } if (kind == DATA_ACTION) { - result.add(new ActionSearchResult(swf, bais)); + currentResults.add(new ActionSearchResult(swf, bais)); } } catch (ScriptNotFoundException | IOException ex) { ex.printStackTrace(); @@ -187,7 +185,8 @@ public class SearchResultsStorage { } catch (IOException ex) { Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex); } - unpackedData.put(j, result); + unpackedData.set(j, currentResults); + result.addAll(currentResults); } } return result; @@ -217,6 +216,11 @@ public class SearchResultsStorage { } } currentGroupId = maxgroup + 1; + + unpackedData = new ArrayList<>(); + for (int i = 0; i < data.size(); i++) { + unpackedData.add(null); + } } catch (ClassNotFoundException ex) { Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex); } @@ -244,7 +248,7 @@ public class SearchResultsStorage { isIgnoreCase.add(ignoreCase); isRegExp.add(regExp); groups.add(currentGroupId); - unpackedData.put(data.size(), new ArrayList<>(results)); + unpackedData.add(new ArrayList<>(results)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(DATA_ABC); try { @@ -271,7 +275,7 @@ public class SearchResultsStorage { isIgnoreCase.add(ignoreCase); isRegExp.add(regExp); groups.add(currentGroupId); - unpackedData.put(data.size(), new ArrayList<>(results)); + unpackedData.add(new ArrayList<>(results)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(DATA_ACTION); try { @@ -311,6 +315,7 @@ public class SearchResultsStorage { groups.remove(i); data.remove(i); unpackedData.remove(i); + i--; } } } @@ -339,7 +344,7 @@ public class SearchResultsStorage { String swfId = getSwfId(swf); for (int i = 0; i < swfIds.size(); i++) { if (swfIds.get(i).equals(swfId)) { - unpackedData.remove(i); + unpackedData.set(i, null); } } }