2021-04-06 23:10:57 +08:00
|
|
|
#include "mainwindow.h"
|
2021-04-08 10:29:21 +08:00
|
|
|
#include "settings.h"
|
2021-04-11 21:33:08 +08:00
|
|
|
#include "systemconsts.h"
|
2021-04-13 22:17:18 +08:00
|
|
|
#include "utils.h"
|
2021-04-06 23:10:57 +08:00
|
|
|
#include <QApplication>
|
2021-04-12 00:00:29 +08:00
|
|
|
#include <QDir>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QDebug>
|
2021-04-13 22:17:18 +08:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
// we have to wrap the following in a function, or it will crash createAppSettings when debug, don't know why
|
|
|
|
void showConfigCantWriteMsg(const QString& filename) {
|
|
|
|
QMessageBox::information(nullptr, QObject::tr("Error"),
|
|
|
|
QString(QObject::tr("Can't write to configuration file %1")).arg(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings* createAppSettings(const QString& filepath = QString()) {
|
|
|
|
QString filename("");
|
|
|
|
if (filename.isEmpty()) {
|
|
|
|
|
|
|
|
// // if (isGreenEdition()) {
|
|
|
|
// // name = QApplication::applicationDirPath() + QDir::separator() +
|
|
|
|
// // "config" + QDir::separator() + APP_SETTSINGS_FILENAME;
|
|
|
|
// // } else {
|
|
|
|
filename = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0]
|
|
|
|
+ QDir::separator() + APP_SETTSINGS_FILENAME;
|
|
|
|
// // }
|
|
|
|
} else {
|
|
|
|
filename = filepath;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDir dir = QFileInfo(filename).absoluteDir();
|
|
|
|
if (!dir.exists()) {
|
|
|
|
if (!dir.mkpath(dir.absolutePath())) {
|
|
|
|
QMessageBox::information(nullptr, QObject::tr("Error"),
|
|
|
|
QString(QObject::tr("Can't create configuration folder %1")).arg(dir.absolutePath()));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo fileInfo(filename);
|
|
|
|
|
|
|
|
if (fileInfo.exists() && !fileInfo.isWritable()) {
|
|
|
|
showConfigCantWriteMsg(filename);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new Settings(filename);
|
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-04-11 21:33:08 +08:00
|
|
|
QApplication app(argc, argv);
|
2021-04-13 22:17:18 +08:00
|
|
|
|
|
|
|
//load translations
|
2021-04-12 00:00:29 +08:00
|
|
|
QTranslator trans;
|
|
|
|
trans.load(("RedPandaIDE_zh_CN"));
|
|
|
|
app.installTranslator(&trans);
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
SystemConsts systemConsts;
|
|
|
|
pSystemConsts = &systemConsts;
|
2021-04-13 22:17:18 +08:00
|
|
|
|
|
|
|
pSettings = createAppSettings();
|
|
|
|
if (pSettings == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
auto settings = std::unique_ptr<Settings>(pSettings);
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
MainWindow mainWindow;
|
|
|
|
pMainWindow = &mainWindow;
|
|
|
|
mainWindow.show();
|
|
|
|
return app.exec();
|
2021-04-06 23:10:57 +08:00
|
|
|
}
|