2018-04-15 12:41:10 +00:00
|
|
|
|
2018-02-10 18:04:31 +00:00
|
|
|
#include "CutterApplication.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2019-03-09 13:11:39 +00:00
|
|
|
#include "common/UpdateWorker.h"
|
2019-05-01 16:15:33 +00:00
|
|
|
#include "common/ColorThemeWorker.h"
|
2019-03-09 13:11:39 +00:00
|
|
|
#include "CutterConfig.h"
|
2019-04-09 07:44:44 +00:00
|
|
|
#include "common/CrashHandler.h"
|
2017-09-25 12:55:41 +00:00
|
|
|
|
2019-05-01 16:15:33 +00:00
|
|
|
#include <QJsonObject>
|
2019-05-23 16:22:31 +00:00
|
|
|
#include <QJsonArray>
|
2019-05-01 16:15:33 +00:00
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Migrate Settings used before Cutter 1.8
|
2019-05-19 15:34:06 +00:00
|
|
|
*
|
|
|
|
* @return whether any settings have been migrated
|
2019-02-22 13:38:02 +00:00
|
|
|
*/
|
2019-05-19 15:34:06 +00:00
|
|
|
static bool migrateSettingsPre18(QSettings &newSettings)
|
2019-02-22 13:38:02 +00:00
|
|
|
{
|
2019-05-19 15:34:06 +00:00
|
|
|
if(newSettings.value("settings_migrated", false).toBool()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-22 13:38:02 +00:00
|
|
|
QSettings oldSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, "Cutter", "Cutter");
|
2019-05-19 15:34:06 +00:00
|
|
|
QStringList allKeys = oldSettings.allKeys();
|
|
|
|
if (allKeys.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
qInfo() << "Migrating Settings from pre-1.8";
|
|
|
|
for (const QString &key : allKeys) {
|
2019-02-22 13:38:02 +00:00
|
|
|
newSettings.setValue(key, oldSettings.value(key));
|
|
|
|
}
|
|
|
|
oldSettings.clear();
|
|
|
|
QFile settingsFile(oldSettings.fileName());
|
|
|
|
settingsFile.remove();
|
2019-05-19 15:34:06 +00:00
|
|
|
newSettings.setValue("settings_migrated", true);
|
|
|
|
return true;
|
2019-02-22 13:38:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-19 15:34:06 +00:00
|
|
|
#define CUTTER_SETTINGS_VERSION_CURRENT 1
|
|
|
|
#define CUTTER_SETTINGS_VERSION_KEY "version"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* How Settings migrations work:
|
|
|
|
*
|
|
|
|
* Every time settings are changed in a way that needs migration,
|
|
|
|
* CUTTER_SETTINGS_VERSION_CURRENT is raised by 1 and a function migrateSettingsToX
|
|
|
|
* is implemented and added to initializeSettings().
|
|
|
|
* This function takes care of migrating from EXACTLY version X-1 to X.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void migrateSettingsTo1(QSettings &settings) {
|
|
|
|
settings.remove("settings_migrated"); // now handled by version
|
|
|
|
settings.remove("updated_custom_themes"); // now handled by theme_version
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initializeSettings()
|
|
|
|
{
|
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
int settingsVersion = settings.value(CUTTER_SETTINGS_VERSION_KEY, 0).toInt();
|
|
|
|
if(settingsVersion == 0) {
|
|
|
|
migrateSettingsPre18(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(settings.allKeys().length() > 0) {
|
|
|
|
if (settingsVersion > CUTTER_SETTINGS_VERSION_CURRENT) {
|
|
|
|
qWarning() << "Settings have a higher version than current! Skipping migration.";
|
|
|
|
} else if(settingsVersion >= 0) {
|
|
|
|
for (int v = settingsVersion + 1; v <= CUTTER_SETTINGS_VERSION_CURRENT; v++) {
|
|
|
|
qInfo() << "Migrating Settings to Version" << v;
|
|
|
|
switch (v) {
|
|
|
|
case 1:
|
2019-06-18 13:02:41 +00:00
|
|
|
migrateSettingsTo1(settings); break;
|
2019-05-19 15:34:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.setValue(CUTTER_SETTINGS_VERSION_KEY, CUTTER_SETTINGS_VERSION_CURRENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define THEME_VERSION_CURRENT 1
|
|
|
|
#define THEME_VERSION_KEY "theme_version"
|
|
|
|
|
|
|
|
static void removeObsoleteOptionsFromCustomThemes() {
|
|
|
|
const QStringList options = Core()->cmdj("ecj").object().keys()
|
|
|
|
<< ColorThemeWorker::cutterSpecificOptions;
|
|
|
|
for (auto theme : Core()->cmdList("eco*")) {
|
|
|
|
theme = theme.trimmed();
|
|
|
|
if (!ThemeWorker().isCustomTheme(theme)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QJsonObject updatedTheme;
|
|
|
|
auto sch = ThemeWorker().getTheme(theme).object();
|
|
|
|
for (const auto& key : sch.keys()) {
|
|
|
|
if (options.contains(key)) {
|
|
|
|
updatedTheme.insert(key, sch[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ThemeWorker().save(QJsonDocument(updatedTheme), theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void migrateThemes()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
int themeVersion = settings.value(THEME_VERSION_KEY, 0).toInt();
|
|
|
|
if (themeVersion != THEME_VERSION_CURRENT) {
|
|
|
|
removeObsoleteOptionsFromCustomThemes();
|
|
|
|
settings.setValue(THEME_VERSION_KEY, THEME_VERSION_CURRENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-04-09 19:33:13 +00:00
|
|
|
if (argc >= 3 && QString::fromLocal8Bit(argv[1]) == "--start-crash-handler") {
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
QString dumpLocation = QString::fromLocal8Bit(argv[2]);
|
|
|
|
showCrashDialog(dumpLocation);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-09 07:44:44 +00:00
|
|
|
initCrashHandler();
|
|
|
|
|
2018-05-28 20:06:24 +00:00
|
|
|
qRegisterMetaType<QList<StringDescription>>();
|
2018-06-25 19:28:34 +00:00
|
|
|
qRegisterMetaType<QList<FunctionDescription>>();
|
2018-05-28 20:06:24 +00:00
|
|
|
|
2019-02-22 13:38:02 +00:00
|
|
|
QCoreApplication::setOrganizationName("RadareOrg");
|
2019-01-20 17:00:23 +00:00
|
|
|
QCoreApplication::setApplicationName("Cutter");
|
2019-02-22 13:38:02 +00:00
|
|
|
|
2019-05-19 15:34:06 +00:00
|
|
|
initializeSettings();
|
2019-01-20 17:00:23 +00:00
|
|
|
|
2019-03-25 20:43:00 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // needed for QtWebEngine inside Plugins
|
|
|
|
|
2018-03-09 16:06:41 +00:00
|
|
|
CutterApplication a(argc, argv);
|
|
|
|
|
2019-05-19 15:34:06 +00:00
|
|
|
migrateThemes();
|
2019-05-01 16:15:33 +00:00
|
|
|
|
2019-03-09 13:11:39 +00:00
|
|
|
if (Config()->getAutoUpdateEnabled()) {
|
|
|
|
UpdateWorker *updateWorker = new UpdateWorker;
|
|
|
|
QObject::connect(updateWorker, &UpdateWorker::checkComplete,
|
2019-03-18 20:42:00 +00:00
|
|
|
[=](const QVersionNumber &version, const QString & error) {
|
2019-03-23 10:54:34 +00:00
|
|
|
if (error.isEmpty() && version > UpdateWorker::currentVersionNumber()) {
|
2019-03-09 13:11:39 +00:00
|
|
|
updateWorker->showUpdateDialog(true);
|
|
|
|
}
|
|
|
|
updateWorker->deleteLater();
|
|
|
|
});
|
|
|
|
updateWorker->checkCurrentVersion(7000);
|
|
|
|
}
|
|
|
|
|
2017-10-23 09:22:15 +00:00
|
|
|
int ret = a.exec();
|
|
|
|
|
|
|
|
return ret;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|