2011-10-18 17:39:51 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-10-18 17:39:51 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2012-04-04 23:28:19 +02:00
|
|
|
#include "globalfunctions.h"
|
2011-10-23 14:44:18 +02:00
|
|
|
#include "mainapplication.h"
|
2011-10-18 14:30:17 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QSqlQuery>
|
2012-04-04 23:28:19 +02:00
|
|
|
#include <QMessageBox>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2011-12-27 15:26:32 +01:00
|
|
|
ProfileUpdater::ProfileUpdater(const QString &profilePath)
|
2012-01-21 20:27:45 +01:00
|
|
|
: m_profilePath(profilePath)
|
2011-10-18 14:30:17 +02:00
|
|
|
{
|
2012-09-02 15:19:12 +02:00
|
|
|
// FIXME: Remove this line when releasing new version
|
|
|
|
update131();
|
2011-10-18 14:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.0.0")) {
|
|
|
|
update100();
|
2012-01-07 12:43:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2012-09-02 15:19:12 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.1.0") ||
|
|
|
|
profileVersion == Updater::parseVersionFromString("1.1.5") ||
|
|
|
|
profileVersion == Updater::parseVersionFromString("1.1.8")) {
|
2012-07-11 18:31:23 +02:00
|
|
|
update118();
|
2012-02-14 15:47:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 15:19:12 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.2.0")) {
|
2012-07-11 18:31:23 +02:00
|
|
|
update120();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 15:19:12 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.3.0")) {
|
2012-07-16 13:59:24 +02:00
|
|
|
update130();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 15:19:12 +02:00
|
|
|
if (profileVersion == Updater::parseVersionFromString("1.3.1")) {
|
|
|
|
update131();
|
2012-04-02 19:33:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-12 18:22:01 +01:00
|
|
|
std::cout << "QupZilla: Incompatible profile version detected, overwriting profile data..." << std::endl;
|
2011-10-18 14:30:17 +02:00
|
|
|
|
|
|
|
copyDataToProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::copyDataToProfile()
|
|
|
|
{
|
|
|
|
QDir profileDir(m_profilePath);
|
|
|
|
profileDir.mkdir("certificates");
|
|
|
|
|
2012-04-04 23:28:19 +02:00
|
|
|
QFile browseData(m_profilePath + "browsedata.db");
|
|
|
|
if (browseData.exists()) {
|
|
|
|
const QString &browseDataBackup = qz_ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
|
|
|
|
const QString &settingsBackup = qz_ensureUniqueFilename(m_profilePath + "settings-backup.ini");
|
|
|
|
browseData.copy(browseDataBackup);
|
|
|
|
QFile(m_profilePath + "settings.ini").copy(settingsBackup);
|
|
|
|
const QString &text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "
|
2012-04-05 10:27:35 +02:00
|
|
|
"backed up in following directories:<br/><br/><b>" + browseDataBackup + "<br/>" + settingsBackup + "<br/></b>";
|
2012-04-04 23:28:19 +02:00
|
|
|
QMessageBox::warning(0, "QupZilla: Incompatible profile version", text);
|
|
|
|
}
|
|
|
|
|
|
|
|
browseData.remove();
|
2011-12-27 15:26:32 +01:00
|
|
|
QFile(":data/browsedata.db").copy(m_profilePath + "browsedata.db");
|
|
|
|
QFile(m_profilePath + "browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
|
2011-10-18 14:30:17 +02:00
|
|
|
}
|
2011-10-21 23:51:02 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update100b4()
|
|
|
|
{
|
2012-03-12 18:22:01 +01:00
|
|
|
std::cout << "QupZilla: 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);");
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update100rc1();
|
2011-10-21 23:51:02 +02:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update100rc1()
|
|
|
|
{
|
2012-03-12 18:22:01 +01:00
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.0.0-rc1..." << std::endl;
|
2011-10-28 17:52:42 +02:00
|
|
|
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");
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update100();
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
2011-12-14 18:09:43 +01:00
|
|
|
|
|
|
|
void ProfileUpdater::update100()
|
|
|
|
{
|
2012-03-12 18:22:01 +01:00
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.0.0..." << std::endl;
|
2011-12-14 18:09:43 +01:00
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE autofill ADD COLUMN last_used NUMERIC");
|
|
|
|
query.exec("UPDATE autofill SET last_used=0");
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update118();
|
2011-12-14 18:09:43 +01:00
|
|
|
}
|
2012-04-02 19:33:05 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update118()
|
|
|
|
{
|
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.1.8..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE folders ADD COLUMN parent TEXT");
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update120();
|
2012-04-02 19:33:05 +02:00
|
|
|
}
|
2012-07-11 18:31:23 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update120()
|
|
|
|
{
|
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.2.0..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlDatabase db = QSqlDatabase::database();
|
|
|
|
db.transaction();
|
|
|
|
|
|
|
|
// This is actually just renaming bookmarks.toolbar_position to bookmarks.position
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE bookmarks RENAME TO tmp_bookmarks");
|
|
|
|
query.exec("CREATE TABLE bookmarks (icon TEXT, folder TEXT, id INTEGER PRIMARY KEY, title VARCHAR(200), url VARCHAR(200), position NUMERIC)");
|
|
|
|
query.exec("INSERT INTO bookmarks(icon, folder, id, title, url, position)"
|
|
|
|
"SELECT icon, folder, id, title, url, toolbar_position FROM tmp_bookmarks");
|
|
|
|
query.exec("DROP TABLE tmp_bookmarks");
|
|
|
|
query.exec("CREATE INDEX bookmarksTitle ON bookmarks(title ASC)");
|
|
|
|
query.exec("CREATE INDEX bookmarksUrl ON bookmarks(url ASC)");
|
|
|
|
|
|
|
|
db.commit();
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update130();
|
2012-07-11 18:31:23 +02:00
|
|
|
}
|
2012-07-16 13:59:24 +02:00
|
|
|
|
|
|
|
void ProfileUpdater::update130()
|
|
|
|
{
|
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.3.0..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE bookmarks ADD COLUMN keyword TEXT");
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
update131();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::update131()
|
|
|
|
{
|
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.3.1..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("ALTER TABLE bookmarks ADD COLUMN count NUMERIC");
|
|
|
|
query.exec("UPDATE bookmarks SET count=0");
|
2012-07-16 13:59:24 +02:00
|
|
|
}
|