mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
SessionManager: Fix fallback to default session if session file is invalid
Creating available sessions metadata is now also faster as it doesn't need to parse the entire session file, only check for validity. See #2331
This commit is contained in:
parent
0096801556
commit
0141a2e621
|
@ -100,6 +100,32 @@ static void loadVersion3(QDataStream &stream, RestoreData &data)
|
|||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool RestoreManager::validateFile(const QString &file)
|
||||
{
|
||||
if (!QFile::exists(file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile recoveryFile(file);
|
||||
if (!recoveryFile.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDataStream stream(&recoveryFile);
|
||||
|
||||
int version;
|
||||
stream >> version;
|
||||
|
||||
if (version == Qz::sessionVersion || version == 0x0003 || version == (0x0003 | 0x050000)) {
|
||||
int windowCount;
|
||||
stream >> windowCount;
|
||||
return windowCount > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
void RestoreManager::createFromFile(const QString &file, RestoreData &data)
|
||||
{
|
||||
|
@ -108,7 +134,10 @@ void RestoreManager::createFromFile(const QString &file, RestoreData &data)
|
|||
}
|
||||
|
||||
QFile recoveryFile(file);
|
||||
recoveryFile.open(QIODevice::ReadOnly);
|
||||
if (!recoveryFile.open(QIODevice::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDataStream stream(&recoveryFile);
|
||||
|
||||
int version;
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
|
||||
QObject *recoveryObject(WebPage *page);
|
||||
|
||||
static bool validateFile(const QString &file);
|
||||
static void createFromFile(const QString &file, RestoreData &data);
|
||||
|
||||
private:
|
||||
|
|
|
@ -279,10 +279,8 @@ void SessionManager::fillSessionsMetaDataListIfNeeded()
|
|||
|
||||
for (int i = 0; i < sessionFiles.size(); ++i) {
|
||||
const QFileInfo &fileInfo = sessionFiles.at(i);
|
||||
RestoreData data;
|
||||
RestoreManager::createFromFile(fileInfo.absoluteFilePath(), data);
|
||||
|
||||
if (data.isEmpty())
|
||||
if (!RestoreManager::validateFile(fileInfo.absoluteFilePath()))
|
||||
continue;
|
||||
|
||||
SessionMetaData metaData;
|
||||
|
@ -321,8 +319,8 @@ void SessionManager::loadSettings()
|
|||
m_lastActiveSessionPath = sessionsDir.absoluteFilePath(m_lastActiveSessionPath);
|
||||
}
|
||||
|
||||
// fallback to default session
|
||||
if (!QFile::exists(m_lastActiveSessionPath))
|
||||
// Fallback to default session
|
||||
if (!RestoreManager::validateFile(m_lastActiveSessionPath))
|
||||
m_lastActiveSessionPath = defaultSessionPath();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user