mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-07 03:56:28 +00:00
saved search results have serial version
This commit is contained in:
@@ -54,12 +54,16 @@ public class ABCSearchResult implements Serializable {
|
||||
|
||||
private final int traitId;
|
||||
|
||||
private static final int SERIAL_VERSION_MAJOR = 1;
|
||||
private static final int SERIAL_VERSION_MINOR = 0;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ABCSearchResult(SWF swf, ObjectInputStream ois) throws IOException, ScriptNotFoundException {
|
||||
public ABCSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
int versionMajor = ois.read();
|
||||
ois.read(); //minor
|
||||
if (versionMajor != 1) {
|
||||
throw new IOException("Unknown search result version");
|
||||
if (versionMajor != SERIAL_VERSION_MAJOR) {
|
||||
throw new IOException("Unknown search result version: " + versionMajor);
|
||||
}
|
||||
|
||||
ClassPath cp;
|
||||
@@ -88,14 +92,16 @@ public class ABCSearchResult implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ObjectOutputStream oos) throws IOException {
|
||||
oos.write(1); //version major
|
||||
oos.write(0); //version minor
|
||||
public void save(OutputStream os) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
oos.write(SERIAL_VERSION_MAJOR);
|
||||
oos.write(SERIAL_VERSION_MINOR);
|
||||
oos.writeObject(scriptPack.getClassPath());
|
||||
oos.writeObject(scriptPack.traitIndices);
|
||||
oos.writeBoolean(pcode);
|
||||
oos.writeInt(classIndex);
|
||||
oos.writeInt(traitId);
|
||||
oos.flush();
|
||||
}
|
||||
|
||||
public ABCSearchResult(ScriptPack scriptPack) {
|
||||
|
||||
@@ -39,8 +39,17 @@ public class ActionSearchResult {
|
||||
|
||||
private final String path;
|
||||
|
||||
public ActionSearchResult(SWF swf, ObjectInputStream ois) throws IOException, ScriptNotFoundException {
|
||||
private static final int SERIAL_VERSION_MAJOR = 1;
|
||||
private static final int SERIAL_VERSION_MINOR = 0;
|
||||
|
||||
public ActionSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
|
||||
Map<String, ASMSource> asms = swf.getASMs(false);
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
int versionMajor = ois.read();
|
||||
ois.read(); //minor
|
||||
if (versionMajor != SERIAL_VERSION_MAJOR) {
|
||||
throw new IOException("Unknown search result version: " + versionMajor);
|
||||
}
|
||||
path = ois.readUTF();
|
||||
if (asms.containsKey(path)) {
|
||||
src = asms.get(path);
|
||||
@@ -50,9 +59,13 @@ public class ActionSearchResult {
|
||||
pcode = ois.readBoolean();
|
||||
}
|
||||
|
||||
public void save(ObjectOutputStream oos) throws IOException {
|
||||
public void save(OutputStream os) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
oos.write(SERIAL_VERSION_MAJOR);
|
||||
oos.write(SERIAL_VERSION_MINOR);
|
||||
oos.writeUTF(path);
|
||||
oos.writeBoolean(pcode);
|
||||
oos.flush();
|
||||
}
|
||||
|
||||
public ActionSearchResult(ASMSource src, boolean pcode, String path) {
|
||||
|
||||
@@ -44,7 +44,10 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class SearchResultsStorage {
|
||||
|
||||
public static final String SEARCH_RESULTS_FILE = "search_results.bin";
|
||||
public static final String SEARCH_RESULTS_FILE = "searchresults.bin";
|
||||
|
||||
private static final int SERIAL_VERSION_MAJOR = 1;
|
||||
private static final int SERIAL_VERSION_MINOR = 0;
|
||||
|
||||
private static String getConfigFile() throws IOException {
|
||||
return Configuration.getFFDecHome() + SEARCH_RESULTS_FILE;
|
||||
@@ -114,15 +117,15 @@ public class SearchResultsStorage {
|
||||
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(itemData));
|
||||
int cnt = ois.readInt();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
List<byte[]> resultData = (List<byte[]>) ois.readObject();
|
||||
for (int i = 0; i < resultData.size(); i++) {
|
||||
try {
|
||||
result.add(new ABCSearchResult(swf, ois));
|
||||
} catch (ScriptNotFoundException ex) {
|
||||
result.add(new ABCSearchResult(swf, new ByteArrayInputStream(resultData.get(i))));
|
||||
} catch (ScriptNotFoundException | IOException ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
unpackedData.put(index, result);
|
||||
@@ -139,15 +142,15 @@ public class SearchResultsStorage {
|
||||
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(itemData));
|
||||
int cnt = ois.readInt();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
List<byte[]> resultData = (List<byte[]>) ois.readObject();
|
||||
for (int i = 0; i < resultData.size(); i++) {
|
||||
try {
|
||||
result.add(new ActionSearchResult(swf, ois));
|
||||
} catch (ScriptNotFoundException ex) {
|
||||
result.add(new ActionSearchResult(swf, new ByteArrayInputStream(resultData.get(i))));
|
||||
} catch (ScriptNotFoundException | IOException ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
unpackedData.put(index, result);
|
||||
@@ -160,6 +163,11 @@ public class SearchResultsStorage {
|
||||
if (new File(configFile).exists()) {
|
||||
try (FileInputStream fis = new FileInputStream(configFile);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
||||
int major = ois.read();
|
||||
ois.read(); // minor
|
||||
if (major != SERIAL_VERSION_MAJOR) { //incompatible version
|
||||
return;
|
||||
}
|
||||
swfIds = (List<String>) ois.readObject();
|
||||
searchedValues = (List<String>) ois.readObject();
|
||||
isIgnoreCase = (List<Boolean>) ois.readObject();
|
||||
@@ -175,6 +183,8 @@ public class SearchResultsStorage {
|
||||
String configFile = getConfigFile();
|
||||
try (FileOutputStream fos = new FileOutputStream(configFile);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
||||
oos.write(SERIAL_VERSION_MAJOR);
|
||||
oos.write(SERIAL_VERSION_MINOR);
|
||||
oos.writeObject(swfIds);
|
||||
oos.writeObject(searchedValues);
|
||||
oos.writeObject(isIgnoreCase);
|
||||
@@ -192,10 +202,13 @@ public class SearchResultsStorage {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeInt(results.size());
|
||||
List<byte[]> resultData = new ArrayList<>();
|
||||
for (ABCSearchResult res : results) {
|
||||
res.save(oos);
|
||||
ByteArrayOutputStream resultBaos = new ByteArrayOutputStream();
|
||||
res.save(resultBaos);
|
||||
resultData.add(resultBaos.toByteArray());
|
||||
}
|
||||
oos.writeObject(resultData);
|
||||
oos.flush();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@@ -214,10 +227,13 @@ public class SearchResultsStorage {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeInt(results.size());
|
||||
List<byte[]> resultData = new ArrayList<>();
|
||||
for (ActionSearchResult res : results) {
|
||||
res.save(oos);
|
||||
ByteArrayOutputStream resultBaos = new ByteArrayOutputStream();
|
||||
res.save(resultBaos);
|
||||
resultData.add(resultBaos.toByteArray());
|
||||
}
|
||||
oos.writeObject(resultData);
|
||||
oos.flush();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SearchResultsStorage.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
Reference in New Issue
Block a user