mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 14:32: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");
|
throw new Exception("Unsupported version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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");
|
_counter = obj.getLong("counter");
|
||||||
|
}
|
||||||
|
|
||||||
JSONArray array = obj.getJSONArray("entries");
|
JSONArray array = obj.getJSONArray("entries");
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
DatabaseEntry e = new DatabaseEntry(null);
|
DatabaseEntry entry = new DatabaseEntry(null);
|
||||||
e.deserialize(array.getJSONObject(i));
|
entry.deserialize(array.getJSONObject(i), ignoreID);
|
||||||
_entries.add(e);
|
|
||||||
|
// 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;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deserialize(JSONObject obj) throws Exception {
|
public void deserialize(JSONObject obj, boolean ignoreID) throws Exception {
|
||||||
|
if (!ignoreID) {
|
||||||
_id = obj.getLong("id");
|
_id = obj.getLong("id");
|
||||||
|
}
|
||||||
_name = obj.getString("name");
|
_name = obj.getString("name");
|
||||||
_info = KeyInfo.fromURL(obj.getString("url"));
|
_info = KeyInfo.fromURL(obj.getString("url"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue