mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 14:59:14 +00:00
Don't write the counter and id's to disk
Why do I keep changing my mind
This commit is contained in:
parent
cba38b7b57
commit
418f5aed29
2 changed files with 3 additions and 22 deletions
|
@ -22,7 +22,6 @@ public class Database {
|
|||
JSONObject obj = new JSONObject();
|
||||
obj.put("version", VERSION);
|
||||
obj.put("entries", array);
|
||||
obj.put("counter", _counter);
|
||||
|
||||
return obj.toString().getBytes("UTF-8");
|
||||
}
|
||||
|
@ -36,25 +35,11 @@ public class Database {
|
|||
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");
|
||||
}
|
||||
|
||||
JSONArray array = obj.getJSONArray("entries");
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
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);
|
||||
}
|
||||
entry.deserialize(array.getJSONObject(i));
|
||||
addKey(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,16 +19,12 @@ public class DatabaseEntry implements Serializable {
|
|||
|
||||
public JSONObject serialize() throws JSONException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("id", _id);
|
||||
obj.put("name", _name);
|
||||
obj.put("url", _info.getURL());
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void deserialize(JSONObject obj, boolean ignoreID) throws Exception {
|
||||
if (!ignoreID) {
|
||||
_id = obj.getLong("id");
|
||||
}
|
||||
public void deserialize(JSONObject obj) throws Exception {
|
||||
_name = obj.getString("name");
|
||||
_info = KeyInfo.fromURL(obj.getString("url"));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue