2011-10-18 17:39:51 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-10-18 14:30:17 +02:00
|
|
|
#include "profileupdater.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "updater.h"
|
2011-10-23 14:44:18 +02:00
|
|
|
#include "mainapplication.h"
|
2011-10-18 14:30:17 +02:00
|
|
|
|
|
|
|
ProfileUpdater::ProfileUpdater(const QString &profilePath, const QString &dataPath)
|
|
|
|
: QObject()
|
|
|
|
, m_profilePath(profilePath)
|
|
|
|
, m_dataPath(dataPath)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::checkProfile()
|
|
|
|
{
|
|
|
|
QDir profileDir(m_profilePath);
|
|
|
|
|
|
|
|
if (!profileDir.exists()) {
|
|
|
|
QDir newDir(profileDir.path().remove(profileDir.dirName()));
|
|
|
|
newDir.mkdir(profileDir.dirName());
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile versionFile(m_profilePath + "version");
|
|
|
|
if (versionFile.exists()) {
|
|
|
|
versionFile.open(QFile::ReadOnly);
|
|
|
|
QString profileVersion = versionFile.readAll();
|
|
|
|
versionFile.close();
|
|
|
|
versionFile.remove();
|
|
|
|
|
2011-10-21 23:51:02 +02:00
|
|
|
updateProfile(QupZilla::VERSION, profileVersion.trimmed());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-10-18 14:30:17 +02:00
|
|
|
copyDataToProfile();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-18 14:30:17 +02:00
|
|
|
|
|
|
|
versionFile.open(QFile::WriteOnly);
|
2011-12-04 16:54:57 +01:00
|
|
|
versionFile.write(QupZilla::VERSION.toUtf8());
|
2011-10-18 14:30:17 +02:00
|
|
|
versionFile.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::updateProfile(const QString ¤t, const QString &profile)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (current == profile) {
|
2011-10-18 14:30:17 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-18 14:30:17 +02:00
|
|
|
|
|
|
|
// Updater::Version currentVersion = Updater::parseVersionFromString(current);
|
|
|
|
Updater::Version profileVersion = Updater::parseVersionFromString(profile);
|
|
|
|
|
2011-10-21 23:51:02 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.0.0-b4")) {
|
|
|
|
update100b4();
|
2011-10-28 17:52:42 +02:00
|
|
|
update100rc1();
|
2011-12-14 18:09:43 +01:00
|
|
|
update100();
|
2011-10-18 14:30:17 +02:00
|
|
|
return;
|
2011-10-21 23:51:02 +02:00
|
|
|
}
|
2011-10-18 14:30:17 +02:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.0.0-rc1")) {
|
|
|
|
update100rc1();
|
2011-12-14 18:09:43 +01:00
|
|
|
update100();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.0.0")) {
|
|
|
|
update100();
|
2011-10-28 17:52:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 14:30:17 +02:00
|
|
|
std::cout << "incompatible profile version detected, updating profile data..." << std::endl;
|
|
|
|
|
|
|
|
copyDataToProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::copyDataToProfile()
|
|
|
|
{
|
|
|
|
QDir profileDir(m_profilePath);
|
|
|
|
profileDir.mkdir("certificates");
|
|
|
|
|
|
|
|
QFile(m_profilePath + "browsedata.db").remove();
|
|
|
|
QFile(m_dataPath + "data/default/profiles/default/browsedata.db").copy(m_profilePath + "browsedata.db");
|
|
|
|
}
|
2011-10-21 23:51:02 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update100b4()
|
|
|
|
{
|
|
|
|
std::cout << "upgrading profile version from 1.0.0-b4..." << std::endl;
|
2011-10-23 14:44:18 +02:00
|
|
|
mApp->connectDatabase();
|
2011-10-21 23:51:02 +02:00
|
|
|
|
|
|
|
QSqlQuery query;
|
2011-10-28 17:52:42 +02:00
|
|
|
query.exec("CREATE TABLE IF NOT EXISTS search_engines (id INTEGER PRIMARY KEY, name TEXT, icon TEXT,"
|
2011-10-21 23:51:02 +02:00
|
|
|
"url TEXT, shortcut TEXT, suggestionsUrl TEXT, suggestionsParameters TEXT);");
|
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update100rc1()
|
|
|
|
{
|
|
|
|
std::cout << "upgrading profile version from 1.0.0-rc1..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE folders ADD COLUMN subfolder TEXT");
|
|
|
|
query.exec("UPDATE folders SET subfolder='no'");
|
|
|
|
|
|
|
|
query.exec("ALTER TABLE bookmarks ADD COLUMN toolbar_position NUMERIC");
|
|
|
|
query.exec("UPDATE bookmarks SET toolbar_position=0");
|
|
|
|
|
|
|
|
}
|
2011-12-14 18:09:43 +01:00
|
|
|
|
|
|
|
void ProfileUpdater::update100()
|
|
|
|
{
|
|
|
|
std::cout << "upgrading profile version from 1.0.0..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE autofill ADD COLUMN last_used NUMERIC");
|
|
|
|
query.exec("UPDATE autofill SET last_used=0");
|
|
|
|
}
|