Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release-7.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Octol1ttle committed Jun 16, 2023
2 parents 03f000f + 34d80a8 commit 126c373
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trigger_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
mv PrismLauncher-macOS-Legacy*/PrismLauncher.tar.gz PrismLauncher-macOS-Legacy-${{ env.VERSION }}.tar.gz
mv PrismLauncher-macOS*/PrismLauncher.tar.gz PrismLauncher-macOS-${{ env.VERSION }}.tar.gz
tar -czf PrismLauncher-${{ env.VERSION }}.tar.gz PrismLauncher-${{ env.VERSION }}
tar --exclude='.git' -czf PrismLauncher-${{ env.VERSION }}.tar.gz PrismLauncher-${{ env.VERSION }}
for d in PrismLauncher-Windows-MSVC*; do
cd "${d}" || continue
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ set(Launcher_HELP_URL "https://prismlauncher.org/wiki/help-pages/%1" CACHE STRIN

######## Set version numbers ########
set(Launcher_VERSION_MAJOR 7)
set(Launcher_VERSION_MINOR 0)
set(Launcher_VERSION_MINOR 1)

set(Launcher_VERSION_NAME "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}")
set(Launcher_VERSION_NAME4 "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.0.0")
Expand Down
41 changes: 21 additions & 20 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,33 +376,33 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)

// init the logger
{
static const QString logBase = BuildConfig.LAUNCHER_NAME + "-%0.log";
auto moveFile = [](const QString &oldName, const QString &newName)
{
static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "-%0.log";
static const QString logBase = FS::PathCombine("logs", baseLogFile);
auto moveFile = [](const QString& oldName, const QString& newName) {
QFile::remove(newName);
QFile::copy(oldName, newName);
QFile::remove(oldName);
};
if (FS::ensureFolderPathExists("logs")) { // if this did not fail
for (auto i = 0; i <= 4; i++)
if (auto oldName = baseLogFile.arg(i);
QFile::exists(oldName)) // do not pointlessly delete new files if the old ones are not there
moveFile(oldName, logBase.arg(i));
}

moveFile(logBase.arg(3), logBase.arg(4));
moveFile(logBase.arg(2), logBase.arg(3));
moveFile(logBase.arg(1), logBase.arg(2));
moveFile(logBase.arg(0), logBase.arg(1));
for (auto i = 4; i > 0; i--)
moveFile(logBase.arg(i - 1), logBase.arg(i));

logFile = std::unique_ptr<QFile>(new QFile(logBase.arg(0)));
if(!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
{
showFatalErrorMessage(
"The launcher data folder is not writable!",
QString(
"The launcher couldn't create a log file - the data folder is not writable.\n"
"\n"
"Make sure you have write permissions to the data folder.\n"
"(%1)\n"
"\n"
"The launcher cannot continue until you fix this problem."
).arg(dataPath)
);
if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
showFatalErrorMessage("The launcher data folder is not writable!",
QString("The launcher couldn't create a log file - the data folder is not writable.\n"
"\n"
"Make sure you have write permissions to the data folder.\n"
"(%1)\n"
"\n"
"The launcher cannot continue until you fix this problem.")
.arg(dataPath));
return;
}
qInstallMessageHandler(appDebugOutput);
Expand Down Expand Up @@ -1699,6 +1699,7 @@ bool Application::handleDataMigration(const QString& currentData,
matcher->add(std::make_shared<SimplePrefixMatcher>(configFile));
matcher->add(std::make_shared<SimplePrefixMatcher>(
BuildConfig.LAUNCHER_CONFIGFILE)); // it's possible that we already used that directory before
matcher->add(std::make_shared<SimplePrefixMatcher>("logs/"));
matcher->add(std::make_shared<SimplePrefixMatcher>("accounts.json"));
matcher->add(std::make_shared<SimplePrefixMatcher>("accounts/"));
matcher->add(std::make_shared<SimplePrefixMatcher>("assets/"));
Expand Down
5 changes: 4 additions & 1 deletion launcher/InstanceTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ QString InstanceName::name() const
{
if (!m_modified_name.isEmpty())
return modifiedName();
return QString("%1 %2").arg(m_original_name, m_original_version);
if (!m_original_version.isEmpty())
return QString("%1 %2").arg(m_original_name, m_original_version);

return m_original_name;
}

QString InstanceName::originalName() const
Expand Down
3 changes: 2 additions & 1 deletion launcher/minecraft/MinecraftInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ void MinecraftInstance::loadSpecificSettings()

// special!
m_settings->registerPassthrough(global_settings->getSetting("JavaTimestamp"), javaOrLocation);
m_settings->registerPassthrough(global_settings->getSetting("JavaVersion"), javaOrLocation);
m_settings->registerPassthrough(global_settings->getSetting("JavaArchitecture"), javaOrLocation);
m_settings->registerPassthrough(global_settings->getSetting("JavaRealArchitecture"), javaOrLocation);
m_settings->registerPassthrough(global_settings->getSetting("JavaVersion"), javaOrLocation);
m_settings->registerPassthrough(global_settings->getSetting("JavaVendor"), javaOrLocation);

// Window Size
auto windowSetting = m_settings->registerSetting("OverrideWindow", false);
Expand Down
12 changes: 4 additions & 8 deletions launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions launcher/net/ByteArraySink.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,32 @@ class ByteArraySink : public Sink {
public:
auto init(QNetworkRequest& request) -> Task::State override
{
m_output->clear();
if (m_output)
m_output->clear();
else
qWarning() << "ByteArraySink did not initialize the buffer because it's not addressable";
if (initAllValidators(request))
return Task::State::Running;
return Task::State::Failed;
};

auto write(QByteArray& data) -> Task::State override
{
m_output->append(data);
if (m_output)
m_output->append(data);
else
qWarning() << "ByteArraySink did not write the buffer because it's not addressable";
if (writeAllValidators(data))
return Task::State::Running;
return Task::State::Failed;
}

auto abort() -> Task::State override
{
m_output->clear();
if (m_output)
m_output->clear();
else
qWarning() << "ByteArraySink did not clear the buffer because it's not addressable";
failAllValidators();
return Task::State::Failed;
}
Expand Down
109 changes: 101 additions & 8 deletions launcher/settings/INIFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@

#include <QSettings>

INIFile::INIFile()
{
}
INIFile::INIFile() {}

bool INIFile::saveFile(QString fileName)
{
if (!contains("ConfigVersion"))
insert("ConfigVersion", "1.2");
QSettings _settings_obj{ fileName, QSettings::Format::IniFormat };
_settings_obj.setFallbacksEnabled(false);

Expand All @@ -71,6 +71,81 @@ 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;
}

QString unquote(QString str)
{
if ((str.contains(QChar(';')) || str.contains(QChar('=')) || str.contains(QChar(','))) && str.endsWith("\"") && str.startsWith("\"")) {
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
str = str.remove(0, 1);
str = str.remove(str.size() - 1, 1);
#else
str = str.removeFirst().removeLast();
#endif
}
return str;
}

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 = unquote(unescape(valueStr));

QVariant value(valueStr);
map.insert(key, value);
}

return true;
}

bool INIFile::loadFile(QString fileName)
{
Expand All @@ -84,10 +159,29 @@ 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.2");
} else if (_settings_obj.value("ConfigVersion").toString() == "1.1") {
for (auto&& key : _settings_obj.allKeys()) {
if (auto valueStr = _settings_obj.value(key).toString();
(valueStr.contains(QChar(';')) || valueStr.contains(QChar('=')) || valueStr.contains(QChar(','))) &&
valueStr.endsWith("\"") && valueStr.startsWith("\"")) {
insert(key, unquote(valueStr));
} else
insert(key, _settings_obj.value(key));
}
insert("ConfigVersion", "1.2");
} else
for (auto&& key : _settings_obj.allKeys())
insert(key, _settings_obj.value(key));
return true;
}

Expand All @@ -103,4 +197,3 @@ void INIFile::set(QString key, QVariant val)
{
this->operator[](key) = val;
}

3 changes: 1 addition & 2 deletions launcher/tasks/ConcurrentTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,18 @@ void ConcurrentTask::startNext()
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });

m_doing.insert(next.get(), next);
qsizetype num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
auto task_progress = std::make_shared<TaskStepProgress>(next->getUid());
m_task_progress.insert(next->getUid(), task_progress);

updateState();
updateStepProgress(*task_progress.get(), Operation::ADDED);


QCoreApplication::processEvents();

QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection);

// Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task.
int num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
for (int i = 0; i < num_starts; i++)
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
}
Expand Down
Loading

0 comments on commit 126c373

Please sign in to comment.