mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Faster profile settings saving
Don't reload from disk right before we save
This commit is contained in:
parent
1a8afd9543
commit
d50bcd1161
|
@ -283,6 +283,7 @@ void Settings::loadPersonnal(Profile* profile)
|
|||
qDebug()<<"Loading personnal settings from"<<filePath;
|
||||
|
||||
SettingsSerializer ps(filePath, profile->getPassword());
|
||||
ps.load();
|
||||
friendLst.clear();
|
||||
ps.beginGroup("Friends");
|
||||
int size = ps.beginReadArray("Friend");
|
||||
|
@ -463,7 +464,7 @@ void Settings::savePersonal(QString profileName, QString password)
|
|||
ps.setValue("enableLogging", enableLogging);
|
||||
ps.endGroup();
|
||||
|
||||
ps.write();
|
||||
ps.save();
|
||||
}
|
||||
|
||||
uint32_t Settings::makeProfileId(const QString& profile)
|
||||
|
|
|
@ -74,20 +74,6 @@ SettingsSerializer::SettingsSerializer(QString filePath, QString password)
|
|||
: path{filePath}, password{password},
|
||||
group{-1}, array{-1}, arrayIndex{-1}
|
||||
{
|
||||
if (isSerializedFormat(filePath))
|
||||
readSerialized();
|
||||
else
|
||||
readIni();
|
||||
|
||||
/* Dump state for debugging
|
||||
qDebug() << "SettingsSerializer data:";
|
||||
for (int i=0; i<groups.size(); i++)
|
||||
qDebug()<<"Group"<<i<<"is"<<groups[i];
|
||||
for (int i=0; i<arrays.size(); i++)
|
||||
qDebug()<<"Array"<<i<<"size"<<arrays[i].size<<arrays[i].values.size()<<"of group"<<arrays[i].group<<"is"<<arrays[i].name;
|
||||
for (int i=0; i<values.size(); i++)
|
||||
qDebug()<<"Value"<<i<<"of group"<<values[i].group<<"array"<<values[i].array<<values[i].arrayIndex<<"key"<<values[i].key;
|
||||
*/
|
||||
}
|
||||
|
||||
void SettingsSerializer::beginGroup(const QString &prefix)
|
||||
|
@ -222,7 +208,25 @@ bool SettingsSerializer::isSerializedFormat(QString filePath)
|
|||
return !memcmp(fmagic, magic, 4) || tox_is_data_encrypted((uint8_t*)fmagic);
|
||||
}
|
||||
|
||||
void SettingsSerializer::write()
|
||||
void SettingsSerializer::load()
|
||||
{
|
||||
if (isSerializedFormat(path))
|
||||
readSerialized();
|
||||
else
|
||||
readIni();
|
||||
|
||||
/* Dump state for debugging
|
||||
qDebug() << "SettingsSerializer data:";
|
||||
for (int i=0; i<groups.size(); i++)
|
||||
qDebug()<<"Group"<<i<<"is"<<groups[i];
|
||||
for (int i=0; i<arrays.size(); i++)
|
||||
qDebug()<<"Array"<<i<<"size"<<arrays[i].size<<arrays[i].values.size()<<"of group"<<arrays[i].group<<"is"<<arrays[i].name;
|
||||
for (int i=0; i<values.size(); i++)
|
||||
qDebug()<<"Value"<<i<<"of group"<<values[i].group<<"array"<<values[i].array<<values[i].arrayIndex<<"key"<<values[i].key;
|
||||
*/
|
||||
}
|
||||
|
||||
void SettingsSerializer::save()
|
||||
{
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
||||
|
|
|
@ -28,16 +28,17 @@
|
|||
/// SettingsSerializer can detect regular .ini files and serialized ones,
|
||||
/// it will read both regular and serialized .ini, but only save in serialized format.
|
||||
/// The file is encrypted with the current profile's password, if any.
|
||||
/// The file is only written to disk if write() is called, the destructor does not write to disk
|
||||
/// The file is only written to disk if save() is called, the destructor does not save to disk
|
||||
/// All member functions are reentrant, but not thread safe.
|
||||
class SettingsSerializer
|
||||
{
|
||||
public:
|
||||
SettingsSerializer(QString filePath, QString password=QString()); ///< Loads the settings from file
|
||||
SettingsSerializer(QString filePath, QString password=QString());
|
||||
|
||||
static bool isSerializedFormat(QString filePath); ///< Check if the file is serialized settings. False on error.
|
||||
|
||||
void write(); ///< Writes the current settings back to file
|
||||
void load(); ///< Loads the settings from file
|
||||
void save(); ///< Saves the current settings back to file
|
||||
|
||||
void beginGroup(const QString &prefix);
|
||||
void endGroup();
|
||||
|
|
Loading…
Reference in New Issue
Block a user