diff --git a/.gdb_history b/.gdb_history index 06f6849..4846c14 100644 --- a/.gdb_history +++ b/.gdb_history @@ -54,3 +54,8 @@ r s n q +b FileSystem::readContactsOldFormat +r +n +c +q diff --git a/peda-session-SilentDragonLite.txt b/peda-session-SilentDragonLite.txt index 6f620bf..12c5dfb 100644 --- a/peda-session-SilentDragonLite.txt +++ b/peda-session-SilentDragonLite.txt @@ -1,2 +1,2 @@ -break FileEncryption::encrypt +break FileSystem::readContactsOldFormat diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 92f5bb8..f7d37be 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -83,7 +83,7 @@ void FileSystem::writeContactsOldFormat(QString file, QList contact c.push_back(item.getAvatar()); _contacts.push_back(c); } - out << QString("v1") << _contacts; + out << QString("v2") << _contacts; _file.close(); } @@ -96,52 +96,68 @@ QList FileSystem::readContactsOldFormat(QString file) contacts.clear(); _file.open(QIODevice::ReadOnly); QDataStream in(&_file); // read the data serialized from the file - QString version; - in >> version; - qDebug() << "Read " << version << " Hush contacts from disk..."; - qDebug() << "Detected old addressbook format"; if(in.status() == QDataStream::ReadCorruptData) { - qDebug() << "Error reading contacts! ---> Your hush contacts from disk maybe corrupted"; - QFile::rename(file, file + QString(".corrupted")); - QMessageBox::critical( - nullptr, - QObject::tr("Error reading contacts!"), - QObject::tr("Your hush contacts from disk maybe corrupted"), - QMessageBox::Ok - ); + qDebug() << "Error reading contacts! ---> Your hush contacts from disk maybe corrupted"; + QFile::rename(file, file + QString(".corrupted")); + QMessageBox::critical( + nullptr, + QObject::tr("Error reading contacts!"), + QObject::tr("Your hush contacts from disk maybe corrupted"), + QMessageBox::Ok + ); } - else + else { - qDebug() << "Read " << version << " Hush contacts from disk..."; - QList> stuff; - in >> stuff; - for (int i=0; i < stuff.size(); i++) + QString version; + in >> version; + if(version == "v1") { - qDebug() << stuff[i].size(); - ContactItem contact; - if(stuff[i].size() == 2) + qDebug() << "Detected old addressbook format"; + // Convert old addressbook format v1 to v2 + QList> stuff; + in >> stuff; + qDebug() << "Stuff: " << stuff; + for (int i=0; i < stuff.size(); i++) { - contact = ContactItem(stuff[i][0],stuff[i][1]); - + ContactItem contact = ContactItem(stuff[i].first, stuff[i].second); + contacts.push_back(contact); + qDebug() << "contact=" << contact.toQTString(); } - else if(stuff[i].size() == 4) + + } + else + { + qDebug() << "Read " << version << " Hush contacts from disk..."; + QList> stuff; + in >> stuff; + qDebug() << "Dataarray size: " << stuff.size(); + if(stuff.size() == 0) + return contacts; + + for (int i= 0; i < stuff.size(); i++) { - contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3]); + qDebug() << stuff[i].size(); + ContactItem contact; + if(stuff[i].size() == 4) + { + contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3]); + } + else + { + contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]); + } + qDebug() << contact.toQTString(); + contacts.push_back(contact); } - else - { - contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]); - } - + - contacts.push_back(contact); } qDebug() << "Hush contacts readed from disk..."; } - + _file.close(); } else diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 808ca40..6d7f913 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -417,12 +417,7 @@ void AddressBook::readFromStorage() allLabels = FileSystem::getInstance()->readContacts(AddressBook::writeableFile()); // test to see if the contact items in datastore are correctly dumped to json - for(ContactItem item: allLabels) - { - DataStore::getContactDataStore()->setData(item.getCid(), item); - } DataStore::getContactDataStore()->dump(); - AddressBook::writeToStorage(); } void AddressBook::writeToStorage()