mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-08 07:37:44 +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();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("version", VERSION);
|
obj.put("version", VERSION);
|
||||||
obj.put("entries", array);
|
obj.put("entries", array);
|
||||||
obj.put("counter", _counter);
|
|
||||||
|
|
||||||
return obj.toString().getBytes("UTF-8");
|
return obj.toString().getBytes("UTF-8");
|
||||||
}
|
}
|
||||||
|
@ -36,25 +35,11 @@ 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 entry = new DatabaseEntry(null);
|
DatabaseEntry entry = new DatabaseEntry(null);
|
||||||
entry.deserialize(array.getJSONObject(i), ignoreID);
|
entry.deserialize(array.getJSONObject(i));
|
||||||
|
|
||||||
// if the id was ignored, make sure it receives a new one
|
|
||||||
if (ignoreID) {
|
|
||||||
addKey(entry);
|
addKey(entry);
|
||||||
} else {
|
|
||||||
_entries.add(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,12 @@ public class DatabaseEntry implements Serializable {
|
||||||
|
|
||||||
public JSONObject serialize() throws JSONException {
|
public JSONObject serialize() throws JSONException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("id", _id);
|
|
||||||
obj.put("name", _name);
|
obj.put("name", _name);
|
||||||
obj.put("url", _info.getURL());
|
obj.put("url", _info.getURL());
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deserialize(JSONObject obj, boolean ignoreID) throws Exception {
|
public void deserialize(JSONObject obj) throws Exception {
|
||||||
if (!ignoreID) {
|
|
||||||
_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