Browse Source

update// address improvement

pull/130/head
Strider 9 months ago
parent
commit
4413d3de62
4 changed files with 54 additions and 38 deletions
  1. +5
    -0
      .gdb_history
  2. +1
    -1
      peda-session-SilentDragonLite.txt
  3. +48
    -32
      src/FileSystem/FileSystem.cpp
  4. +0
    -5
      src/addressbook.cpp

+ 5
- 0
.gdb_history

@ -54,3 +54,8 @@ r
s
n
q
b FileSystem::readContactsOldFormat
r
n
c
q

+ 1
- 1
peda-session-SilentDragonLite.txt

@ -1,2 +1,2 @@
break FileEncryption::encrypt
break FileSystem::readContactsOldFormat

+ 48
- 32
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<QList<QString>> 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<QPair<QString,QString>> 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<QList<QString>> 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

+ 0
- 5
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()

Loading…
Cancel
Save