mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 06:22:49 +00:00
Converted old databases to using id's for entries
This commit is contained in:
parent
043d70f190
commit
05cfc0bc5f
2 changed files with 20 additions and 6 deletions
|
@ -36,13 +36,25 @@ public class Database {
|
|||
throw new Exception("Unsupported version");
|
||||
}
|
||||
|
||||
_counter = obj.getLong("counter");
|
||||
// if no counter is present, ignore and reset the id of all entries
|
||||
boolean ignoreID = false;
|
||||
if (!obj.has("counter")) {
|
||||
ignoreID = true;
|
||||
} else {
|
||||
_counter = obj.getLong("counter");
|
||||
}
|
||||
|
||||
JSONArray array = obj.getJSONArray("entries");
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
DatabaseEntry e = new DatabaseEntry(null);
|
||||
e.deserialize(array.getJSONObject(i));
|
||||
_entries.add(e);
|
||||
DatabaseEntry entry = new DatabaseEntry(null);
|
||||
entry.deserialize(array.getJSONObject(i), ignoreID);
|
||||
|
||||
// if the id was ignored, make sure it receives a new one
|
||||
if (ignoreID) {
|
||||
addKey(entry);
|
||||
} else {
|
||||
_entries.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,10 @@ public class DatabaseEntry implements Serializable {
|
|||
return obj;
|
||||
}
|
||||
|
||||
public void deserialize(JSONObject obj) throws Exception {
|
||||
_id = obj.getLong("id");
|
||||
public void deserialize(JSONObject obj, boolean ignoreID) throws Exception {
|
||||
if (!ignoreID) {
|
||||
_id = obj.getLong("id");
|
||||
}
|
||||
_name = obj.getString("name");
|
||||
_info = KeyInfo.fromURL(obj.getString("url"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue