aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
Diffstat (limited to 'launcher')
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackExportTask.cpp12
-rw-r--r--launcher/settings/INIFile.cpp85
-rw-r--r--launcher/ui/MainWindow.cpp27
-rw-r--r--launcher/ui/MainWindow.ui10
4 files changed, 110 insertions, 24 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
index 29df90dd..bff9bf42 100644
--- a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
@@ -27,7 +27,7 @@
#include "minecraft/PackProfile.h"
#include "minecraft/mod/ModFolderModel.h"
-const QStringList ModrinthPackExportTask::PREFIXES({ "mods", "coremods", "resourcepacks", "texturepacks", "shaderpacks" });
+const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
ModrinthPackExportTask::ModrinthPackExportTask(const QString& name,
@@ -99,14 +99,12 @@ void ModrinthPackExportTask::collectHashes()
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
// require sensible file types
- if (!std::any_of(PREFIXES.begin(), PREFIXES.end(),
- [&relative](const QString& prefix) { return relative.startsWith(prefix + QDir::separator()); }))
+ if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); }))
continue;
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
- })) {
+ }))
continue;
- }
QCryptographicHash sha512(QCryptographicHash::Algorithm::Sha512);
@@ -303,9 +301,7 @@ QByteArray ModrinthPackExportTask::generateIndex()
const ResolvedFile& value = iterator.value();
QJsonObject file;
- QString path = iterator.key();
- path.replace(QDir::separator(), "/");
- file["path"] = path;
+ file["path"] = iterator.key();
file["downloads"] = QJsonArray({ iterator.value().url });
QJsonObject hashes;
diff --git a/launcher/settings/INIFile.cpp b/launcher/settings/INIFile.cpp
index f0347cab..cb909ae7 100644
--- a/launcher/settings/INIFile.cpp
+++ b/launcher/settings/INIFile.cpp
@@ -45,12 +45,12 @@
#include <QSettings>
-INIFile::INIFile()
-{
-}
+INIFile::INIFile() {}
bool INIFile::saveFile(QString fileName)
{
+ if (!contains("ConfigVersion"))
+ insert("ConfigVersion", "1.1");
QSettings _settings_obj{ fileName, QSettings::Format::IniFormat };
_settings_obj.setFallbacksEnabled(false);
@@ -71,6 +71,67 @@ bool INIFile::saveFile(QString fileName)
return true;
}
+QString unescape(QString orig)
+{
+ QString out;
+ QChar prev = QChar::Null;
+ for (auto c : orig) {
+ if (prev == '\\') {
+ if (c == 'n')
+ out += '\n';
+ else if (c == 't')
+ out += '\t';
+ else if (c == '#')
+ out += '#';
+ else
+ out += c;
+ prev = QChar::Null;
+ } else {
+ if (c == '\\') {
+ prev = c;
+ continue;
+ }
+ out += c;
+ prev = QChar::Null;
+ }
+ }
+ return out;
+}
+bool parseOldFileFormat(QIODevice& device, QSettings::SettingsMap& map)
+{
+ QTextStream in(device.readAll());
+#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
+ in.setCodec("UTF-8");
+#endif
+
+ QStringList lines = in.readAll().split('\n');
+ for (int i = 0; i < lines.count(); i++) {
+ QString& lineRaw = lines[i];
+ // Ignore comments.
+ int commentIndex = 0;
+ QString line = lineRaw;
+ // Search for comments until no more escaped # are available
+ while ((commentIndex = line.indexOf('#', commentIndex + 1)) != -1) {
+ if (commentIndex > 0 && line.at(commentIndex - 1) == '\\') {
+ continue;
+ }
+ line = line.left(lineRaw.indexOf('#')).trimmed();
+ }
+
+ int eqPos = line.indexOf('=');
+ if (eqPos == -1)
+ continue;
+ QString key = line.left(eqPos).trimmed();
+ QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
+
+ valueStr = unescape(valueStr);
+
+ QVariant value(valueStr);
+ map.insert(key, value);
+ }
+
+ return true;
+}
bool INIFile::loadFile(QString fileName)
{
@@ -84,10 +145,19 @@ bool INIFile::loadFile(QString fileName)
qCritical() << "A format error occurred (e.g. loading a malformed INI file).";
return false;
}
-
- for (auto&& key : _settings_obj.allKeys())
- insert(key, _settings_obj.value(key));
-
+ if (!_settings_obj.value("ConfigVersion").isValid()) {
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly))
+ return false;
+ QSettings::SettingsMap map;
+ parseOldFileFormat(file, map);
+ file.close();
+ for (auto&& key : map.keys())
+ insert(key, map.value(key));
+ insert("ConfigVersion", "1.1");
+ } else
+ for (auto&& key : _settings_obj.allKeys())
+ insert(key, _settings_obj.value(key));
return true;
}
@@ -103,4 +173,3 @@ void INIFile::set(QString key, QVariant val)
{
this->operator[](key) = val;
}
-
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 834f57dd..1addfe21 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -187,7 +187,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
}
- // set the menu for the folders help, and accounts tool buttons
+ // set the menu for the folders help, accounts, and export tool buttons
{
auto foldersMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionFoldersButton));
ui->actionFoldersButton->setMenu(ui->foldersMenu);
@@ -201,6 +201,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
auto accountMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionAccountsButton));
accountMenuButton->setPopupMode(QToolButton::InstantPopup);
+
+ auto exportInstanceMenu = new QMenu(this);
+ exportInstanceMenu->addAction(ui->actionExportInstanceZip);
+ exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
+ ui->actionExportInstance->setMenu(exportInstanceMenu);
}
// hide, disable and show stuff
@@ -397,8 +402,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// removing this looks stupid
view->setFocus();
- ui->actionExportInstance->setMenu(ui->exportInstanceMenu);
-
retranslateUi();
}
@@ -470,7 +473,23 @@ void MainWindow::lockToolbars(bool state)
void MainWindow::konamiTriggered()
{
- qDebug() << "Super Secret Mode ACTIVATED!";
+ QString gradient = " stop:0 rgba(125, 0, 0, 255), stop:0.166 rgba(125, 125, 0, 255), stop:0.333 rgba(0, 125, 0, 255), stop:0.5 rgba(0, 125, 125, 255), stop:0.666 rgba(0, 0, 125, 255), stop:0.833 rgba(125, 0, 125, 255), stop:1 rgba(125, 0, 0, 255));";
+ QString stylesheet = "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0," + gradient;
+ if (ui->mainToolBar->styleSheet() == stylesheet) {
+ ui->mainToolBar->setStyleSheet("");
+ ui->instanceToolBar->setStyleSheet("");
+ ui->centralWidget->setStyleSheet("");
+ ui->newsToolBar->setStyleSheet("");
+ ui->statusBar->setStyleSheet("");
+ qDebug() << "Super Secret Mode DEACTIVATED!";
+ } else {
+ ui->mainToolBar->setStyleSheet(stylesheet);
+ ui->instanceToolBar->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1," + gradient);
+ ui->centralWidget->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1," + gradient);
+ ui->newsToolBar->setStyleSheet(stylesheet);
+ ui->statusBar->setStyleSheet(stylesheet);
+ qDebug() << "Super Secret Mode ACTIVATED!";
+ }
}
void MainWindow::showInstanceContextMenu(const QPoint &pos)
diff --git a/launcher/ui/MainWindow.ui b/launcher/ui/MainWindow.ui
index 4a89bc10..9e639ab0 100644
--- a/launcher/ui/MainWindow.ui
+++ b/launcher/ui/MainWindow.ui
@@ -150,10 +150,6 @@
<addaction name="actionChangeInstGroup"/>
<addaction name="actionViewSelectedInstFolder"/>
<addaction name="actionExportInstance"/>
- <widget class="QMenu" name="exportInstanceMenu">
- <addaction name="actionExportInstanceZip"/>
- <addaction name="actionExportInstanceMrPack"/>
- </widget>
<addaction name="actionCopyInstance"/>
<addaction name="actionDeleteInstance"/>
<addaction name="actionCreateInstanceShortcut"/>
@@ -467,11 +463,17 @@
</property>
</action>
<action name="actionExportInstanceZip">
+ <property name="icon">
+ <iconset theme="launcher"/>
+ </property>
<property name="text">
<string>Prism Launcher (zip)</string>
</property>
</action>
<action name="actionExportInstanceMrPack">
+ <property name="icon">
+ <iconset theme="modrinth"/>
+ </property>
<property name="text">
<string>Modrinth (mrpack)</string>
</property>