2011-10-18 17:39:51 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-03-11 17:45:48 +01:00
|
|
|
* Copyright (C) 2010-2013 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"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-03-17 10:26:47 +01:00
|
|
|
Updater::Version prof(profile);
|
2011-10-18 14:30:17 +02:00
|
|
|
|
2013-03-17 10:26:47 +01:00
|
|
|
if (prof == Updater::Version("1.0.0")) {
|
2011-12-14 18:09:43 +01:00
|
|
|
update100();
|
2012-01-07 12:43:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2013-03-17 10:26:47 +01:00
|
|
|
if (prof == Updater::Version("1.1.0")
|
|
|
|
|| prof == Updater::Version("1.1.5")
|
|
|
|
|| prof == Updater::Version("1.1.8")) {
|
2012-07-11 18:31:23 +02:00
|
|
|
update118();
|
2012-02-14 15:47:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-17 10:26:47 +01:00
|
|
|
if (prof == Updater::Version("1.2.0")) {
|
2012-07-11 18:31:23 +02:00
|
|
|
update120();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-17 10:26:47 +01:00
|
|
|
if (prof == Updater::Version("1.3.0")
|
|
|
|
|| prof == Updater::Version("1.3.1")) {
|
2012-07-16 13:59:24 +02:00
|
|
|
update130();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:17:27 +01:00
|
|
|
if (prof >= Updater::Version("1.4.0") && prof <= Updater::Version("1.5.0")) {
|
|
|
|
update140();
|
2013-03-11 17:45:48 +01: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()) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString browseDataBackup = QzTools::ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
|
|
|
|
const QString settingsBackup = QzTools::ensureUniqueFilename(m_profilePath + "settings-backup.ini");
|
2012-04-04 23:28:19 +02:00
|
|
|
browseData.copy(browseDataBackup);
|
|
|
|
QFile(m_profilePath + "settings.ini").copy(settingsBackup);
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "
|
|
|
|
"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
|
|
|
|
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");
|
2013-11-08 22:17:27 +01:00
|
|
|
|
|
|
|
update140();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileUpdater::update140()
|
|
|
|
{
|
|
|
|
std::cout << "QupZilla: Upgrading profile version from 1.4.0..." << std::endl;
|
|
|
|
mApp->connectDatabase();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
2013-11-09 13:32:03 +01:00
|
|
|
query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT");
|
2012-07-16 13:59:24 +02:00
|
|
|
}
|