Skip to content

Commit

Permalink
Merge branch 'release-5.x' of upstream into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
fn2006 committed Nov 16, 2022
2 parents 413dd73 + 790e077 commit 6135b74
Show file tree
Hide file tree
Showing 55 changed files with 238 additions and 227 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ set(CMAKE_C_STANDARD 11)
include(GenerateExportHeader)
set(CMAKE_CXX_FLAGS "-Wall -pedantic -fstack-protector-strong --param=ssp-buffer-size=4 ${CMAKE_CXX_FLAGS}")

# ATL's packlist needs more than the default 1 Mib stack on windows
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--stack,8388608 ${CMAKE_EXE_LINKER_FLAGS}")
endif()

# Fix build with Qt 5.13
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_NO_DEPRECATED_WARNINGS=Y")

Expand Down Expand Up @@ -77,7 +82,7 @@ set(Launcher_HELP_URL "https://prismlauncher.org/wiki/help-pages/%1" CACHE STRIN

######## Set version numbers ########
set(Launcher_VERSION_MAJOR 5)
set(Launcher_VERSION_MINOR 1)
set(Launcher_VERSION_MINOR 2)

set(Launcher_VERSION_NAME "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}")
set(Launcher_VERSION_NAME4 "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.0.0")
Expand Down
5 changes: 3 additions & 2 deletions launcher/BaseInstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

#include <memory>

#include "BaseVersion.h"

class MinecraftInstance;
class QDir;
class QString;
class QObject;
class Task;
class BaseVersion;
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;

class BaseInstaller
{
Expand All @@ -35,7 +36,7 @@ class BaseInstaller
virtual bool add(MinecraftInstance *to);
virtual bool remove(MinecraftInstance *from);

virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersion::Ptr version, QObject *parent) = 0;

protected:
virtual QString id() const = 0;
Expand Down
5 changes: 2 additions & 3 deletions launcher/BaseVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class BaseVersion
{
public:
using Ptr = std::shared_ptr<BaseVersion>;
virtual ~BaseVersion() {}
/*!
* A string used to identify this version in config files.
Expand Down Expand Up @@ -54,6 +55,4 @@ class BaseVersion
};
};

typedef std::shared_ptr<BaseVersion> BaseVersionPtr;

Q_DECLARE_METATYPE(BaseVersionPtr)
Q_DECLARE_METATYPE(BaseVersion::Ptr)
10 changes: 5 additions & 5 deletions launcher/BaseVersionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ BaseVersionList::BaseVersionList(QObject *parent) : QAbstractListModel(parent)
{
}

BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
BaseVersion::Ptr BaseVersionList::findVersion(const QString &descriptor)
{
for (int i = 0; i < count(); i++)
{
if (at(i)->descriptor() == descriptor)
return at(i);
}
return BaseVersionPtr();
return nullptr;
}

BaseVersionPtr BaseVersionList::getRecommended() const
BaseVersion::Ptr BaseVersionList::getRecommended() const
{
if (count() <= 0)
return BaseVersionPtr();
return nullptr;
else
return at(0);
}
Expand All @@ -66,7 +66,7 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
if (index.row() > count())
return QVariant();

BaseVersionPtr version = at(index.row());
BaseVersion::Ptr version = at(index.row());

switch (role)
{
Expand Down
8 changes: 4 additions & 4 deletions launcher/BaseVersionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BaseVersionList : public QAbstractListModel
virtual bool isLoaded() = 0;

//! Gets the version at the given index.
virtual const BaseVersionPtr at(int i) const = 0;
virtual const BaseVersion::Ptr at(int i) const = 0;

//! Returns the number of versions in the list.
virtual int count() const = 0;
Expand All @@ -90,13 +90,13 @@ class BaseVersionList : public QAbstractListModel
* \return A const pointer to the version with the given descriptor. NULL if
* one doesn't exist.
*/
virtual BaseVersionPtr findVersion(const QString &descriptor);
virtual BaseVersion::Ptr findVersion(const QString &descriptor);

/*!
* \brief Gets the recommended version from this list
* If the list doesn't support recommended versions, this works exactly as getLatestStable
*/
virtual BaseVersionPtr getRecommended() const;
virtual BaseVersion::Ptr getRecommended() const;

/*!
* Sorts the version list.
Expand All @@ -117,5 +117,5 @@ protected
* then copies the versions and sets their parents correctly.
* \param versions List of versions whose parents should be set.
*/
virtual void updateListData(QList<BaseVersionPtr> versions) = 0;
virtual void updateListData(QList<BaseVersion::Ptr> versions) = 0;
};
4 changes: 2 additions & 2 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ set(CORE_SOURCES
NullInstance.h
MMCZip.h
MMCZip.cpp
MMCStrings.h
MMCStrings.cpp
StringUtils.h
StringUtils.cpp
RuntimeContext.h

# Basic instance manipulation tasks (derived from InstanceTask)
Expand Down
26 changes: 6 additions & 20 deletions launcher/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#include <QStandardPaths>
#include <QTextStream>
#include <QUrl>

#include "DesktopServices.h"
#include "StringUtils.h"

#if defined Q_OS_WIN32
#include <objbase.h>
Expand Down Expand Up @@ -79,22 +81,6 @@ namespace fs = std::filesystem;
namespace fs = ghc::filesystem;
#endif

#if defined Q_OS_WIN32

std::wstring toStdString(QString s)
{
return s.toStdWString();
}

#else

std::string toStdString(QString s)
{
return s.toStdString();
}

#endif

namespace FS {

void ensureExists(const QDir& dir)
Expand Down Expand Up @@ -191,7 +177,7 @@ bool copy::operator()(const QString& offset)
auto dst_path = PathCombine(dst, relative_dst_path);
ensureFilePathExists(dst_path);

fs::copy(toStdString(src_path), toStdString(dst_path), opt, err);
fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
if (err) {
qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
qDebug() << "Source file:" << src_path;
Expand All @@ -213,7 +199,7 @@ bool copy::operator()(const QString& offset)
}

// If the root src is not a directory, the previous iterator won't run.
if (!fs::is_directory(toStdString(src)))
if (!fs::is_directory(StringUtils::toStdString(src)))
copy_file(src, "");

return err.value() == 0;
Expand All @@ -223,7 +209,7 @@ bool deletePath(QString path)
{
std::error_code err;

fs::remove_all(toStdString(path), err);
fs::remove_all(StringUtils::toStdString(path), err);

if (err) {
qWarning() << "Failed to remove files:" << QString::fromStdString(err.message());
Expand Down Expand Up @@ -414,7 +400,7 @@ bool overrideFolder(QString overwritten_path, QString override_path)
fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing;

// FIXME: hello traveller! Apparently std::copy does NOT overwrite existing files on GNU libstdc++ on Windows?
fs::copy(toStdString(override_path), toStdString(overwritten_path), opt, err);
fs::copy(StringUtils::toStdString(override_path), StringUtils::toStdString(overwritten_path), opt, err);

if (err) {
qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path);
Expand Down
2 changes: 1 addition & 1 deletion launcher/JavaCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "JavaCommon.h"
#include "java/JavaUtils.h"
#include "ui/dialogs/CustomMessageBox.h"
#include <MMCStrings.h>

#include <QRegularExpression>

bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent)
Expand Down
8 changes: 0 additions & 8 deletions launcher/MMCStrings.h

This file was deleted.

42 changes: 21 additions & 21 deletions launcher/MMCStrings.cpp → launcher/StringUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#include "MMCStrings.h"
#include "StringUtils.h"

/// If you're wondering where these came from exactly, then know you're not the only one =D

/// TAKEN FROM Qt, because it doesn't expose it intelligently
static inline QChar getNextChar(const QString &s, int location)
static inline QChar getNextChar(const QString& s, int location)
{
return (location < s.length()) ? s.at(location) : QChar();
}

/// TAKEN FROM Qt, because it doesn't expose it intelligently
int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
int StringUtils::naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs)
{
for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2)
{
int l1 = 0, l2 = 0;
while (l1 <= s1.count() && l2 <= s2.count()) {
// skip spaces, tabs and 0's
QChar c1 = getNextChar(s1, l1);
while (c1.isSpace())
c1 = getNextChar(s1, ++l1);

QChar c2 = getNextChar(s2, l2);
while (c2.isSpace())
c2 = getNextChar(s2, ++l2);

if (c1.isDigit() && c2.isDigit())
{
if (c1.isDigit() && c2.isDigit()) {
while (c1.digitValue() == 0)
c1 = getNextChar(s1, ++l1);
while (c2.digitValue() == 0)
Expand All @@ -30,11 +32,8 @@ int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensit
int lookAheadLocation2 = l2;
int currentReturnValue = 0;
// find the last digit, setting currentReturnValue as we go if it isn't equal
for (QChar lookAhead1 = c1, lookAhead2 = c2;
(lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
lookAhead1 = getNextChar(s1, ++lookAheadLocation1),
lookAhead2 = getNextChar(s2, ++lookAheadLocation2))
{
for (QChar lookAhead1 = c1, lookAhead2 = c2; (lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
lookAhead1 = getNextChar(s1, ++lookAheadLocation1), lookAhead2 = getNextChar(s2, ++lookAheadLocation2)) {
bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit();
bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit();
if (!is1ADigit && !is2ADigit)
Expand All @@ -43,34 +42,35 @@ int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensit
return -1;
if (!is2ADigit)
return 1;
if (currentReturnValue == 0)
{
if (lookAhead1 < lookAhead2)
{
if (currentReturnValue == 0) {
if (lookAhead1 < lookAhead2) {
currentReturnValue = -1;
}
else if (lookAhead1 > lookAhead2)
{
} else if (lookAhead1 > lookAhead2) {
currentReturnValue = 1;
}
}
}
if (currentReturnValue != 0)
return currentReturnValue;
}
if (cs == Qt::CaseInsensitive)
{

if (cs == Qt::CaseInsensitive) {
if (!c1.isLower())
c1 = c1.toLower();
if (!c2.isLower())
c2 = c2.toLower();
}

int r = QString::localeAwareCompare(c1, c2);
if (r < 0)
return -1;
if (r > 0)
return 1;

l1 += 1;
l2 += 1;
}

// The two strings are the same (02 == 2) so fall back to the normal sort
return QString::compare(s1, s2, cs);
}
32 changes: 32 additions & 0 deletions launcher/StringUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <QString>

namespace StringUtils {

#if defined Q_OS_WIN32
using string = std::wstring;

inline string toStdString(QString s)
{
return s.toStdWString();
}
inline QString fromStdString(string s)
{
return QString::fromStdWString(s);
}
#else
using string = std::string;

inline string toStdString(QString s)
{
return s.toStdString();
}
inline QString fromStdString(string s)
{
return QString::fromStdString(s);
}
#endif

int naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs);
} // namespace StringUtils
7 changes: 4 additions & 3 deletions launcher/java/JavaInstall.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "JavaInstall.h"
#include <MMCStrings.h>

#include "StringUtils.h"

bool JavaInstall::operator<(const JavaInstall &rhs)
{
auto archCompare = Strings::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
auto archCompare = StringUtils::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
if(archCompare != 0)
return archCompare < 0;
if(id < rhs.id)
Expand All @@ -14,7 +15,7 @@ bool JavaInstall::operator<(const JavaInstall &rhs)
{
return false;
}
return Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
return StringUtils::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
}

bool JavaInstall::operator==(const JavaInstall &rhs)
Expand Down
Loading

0 comments on commit 6135b74

Please sign in to comment.