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;
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();
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)