- private void load() throws IOException {
- openFileChannel();
- JsonNode rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
-
- JsonNode node = rootNode.get("deviceId");
- if (node != null) {
- deviceId = node.asInt();
- }
- username = getNotNullNode(rootNode, "username").asText();
- password = getNotNullNode(rootNode, "password").asText();
- JsonNode pinNode = rootNode.get("registrationLockPin");
- registrationLockPin = pinNode == null ? null : pinNode.asText();
- if (rootNode.has("signalingKey")) {
- signalingKey = getNotNullNode(rootNode, "signalingKey").asText();
- }
- if (rootNode.has("preKeyIdOffset")) {
- preKeyIdOffset = getNotNullNode(rootNode, "preKeyIdOffset").asInt(0);
- } else {
- preKeyIdOffset = 0;
- }
- if (rootNode.has("nextSignedPreKeyId")) {
- nextSignedPreKeyId = getNotNullNode(rootNode, "nextSignedPreKeyId").asInt();
- } else {
- nextSignedPreKeyId = 0;
- }
- if (rootNode.has("profileKey")) {
- profileKey = Base64.decode(getNotNullNode(rootNode, "profileKey").asText());
- } else {
- // Old config file, creating new profile key
- profileKey = KeyUtils.createProfileKey();
- }
-
- signalProtocolStore = jsonProcessor.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class);
- registered = getNotNullNode(rootNode, "registered").asBoolean();
- JsonNode groupStoreNode = rootNode.get("groupStore");
- if (groupStoreNode != null) {
- groupStore = jsonProcessor.convertValue(groupStoreNode, JsonGroupStore.class);
- }
- if (groupStore == null) {
- groupStore = new JsonGroupStore();
- }
-
- JsonNode contactStoreNode = rootNode.get("contactStore");
- if (contactStoreNode != null) {
- contactStore = jsonProcessor.convertValue(contactStoreNode, JsonContactsStore.class);
- }
- if (contactStore == null) {
- contactStore = new JsonContactsStore();
- }
- JsonNode threadStoreNode = rootNode.get("threadStore");
- if (threadStoreNode != null) {
- threadStore = jsonProcessor.convertValue(threadStoreNode, JsonThreadStore.class);
- }
- if (threadStore == null) {
- threadStore = new JsonThreadStore();
- }
- }
-