mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add version to account file
This commit is contained in:
parent
3357945a5a
commit
3d361d54bb
1 changed files with 14 additions and 1 deletions
|
@ -64,6 +64,9 @@ public class SignalAccount implements Closeable {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(SignalAccount.class);
|
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 ObjectMapper jsonProcessor = Utils.createStorageObjectMapper();
|
||||||
|
|
||||||
private final FileChannel fileChannel;
|
private final FileChannel fileChannel;
|
||||||
|
@ -281,6 +284,15 @@ public class SignalAccount implements Closeable {
|
||||||
rootNode = jsonProcessor.readTree(Channels.newInputStream(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();
|
username = Utils.getNotNullNode(rootNode, "username").asText();
|
||||||
password = Utils.getNotNullNode(rootNode, "password").asText();
|
password = Utils.getNotNullNode(rootNode, "password").asText();
|
||||||
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
|
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
|
||||||
|
@ -558,7 +570,8 @@ public class SignalAccount implements Closeable {
|
||||||
private void save() {
|
private void save() {
|
||||||
synchronized (fileChannel) {
|
synchronized (fileChannel) {
|
||||||
var rootNode = jsonProcessor.createObjectNode();
|
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("uuid", uuid == null ? null : uuid.toString())
|
||||||
.put("deviceId", deviceId)
|
.put("deviceId", deviceId)
|
||||||
.put("isMultiDevice", isMultiDevice)
|
.put("isMultiDevice", isMultiDevice)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue