Add version to account file

This commit is contained in:
AsamK 2021-05-05 19:02:22 +02:00
parent 3357945a5a
commit 3d361d54bb

View file

@ -64,6 +64,9 @@ public class SignalAccount implements Closeable {
private final static Logger logger = LoggerFactory.getLogger(SignalAccount.class);
private static final int MINIMUM_STORAGE_VERSION = 1;
private static final int CURRENT_STORAGE_VERSION = 2;
private final ObjectMapper jsonProcessor = Utils.createStorageObjectMapper();
private final FileChannel fileChannel;
@ -281,6 +284,15 @@ public class SignalAccount implements Closeable {
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
}
if (rootNode.hasNonNull("version")) {
var accountVersion = rootNode.get("version").asInt(1);
if (accountVersion > CURRENT_STORAGE_VERSION) {
throw new IOException("Config file was created by a more recent version!");
} else if (accountVersion < MINIMUM_STORAGE_VERSION) {
throw new IOException("Config file was created by a no longer supported older version!");
}
}
username = Utils.getNotNullNode(rootNode, "username").asText();
password = Utils.getNotNullNode(rootNode, "password").asText();
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
@ -558,7 +570,8 @@ public class SignalAccount implements Closeable {
private void save() {
synchronized (fileChannel) {
var rootNode = jsonProcessor.createObjectNode();
rootNode.put("username", username)
rootNode.put("version", CURRENT_STORAGE_VERSION)
.put("username", username)
.put("uuid", uuid == null ? null : uuid.toString())
.put("deviceId", deviceId)
.put("isMultiDevice", isMultiDevice)