Skip to content

Commit

Permalink
Merge branch 'PrismLauncher:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Diegiwg authored Oct 22, 2024
2 parents 8da6e67 + a43ebef commit 9a8e24e
Show file tree
Hide file tree
Showing 28 changed files with 304 additions and 187 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ jobs:
if: matrix.name == 'macOS'
run: |
if [ '${{ secrets.SPARKLE_ED25519_KEY }}' != '' ]; then
brew install openssl@3
echo '${{ secrets.SPARKLE_ED25519_KEY }}' > ed25519-priv.pem
signature=$(/usr/local/opt/openssl@3/bin/openssl pkeyutl -sign -rawin -in ${{ github.workspace }}/PrismLauncher.zip -inkey ed25519-priv.pem | openssl base64 | tr -d \\n)
signature=$(/opt/homebrew/opt/openssl@3/bin/openssl pkeyutl -sign -rawin -in ${{ github.workspace }}/PrismLauncher.zip -inkey ed25519-priv.pem | openssl base64 | tr -d \\n)
rm ed25519-priv.pem
cat >> $GITHUB_STEP_SUMMARY << EOF
### Artifact Information :information_source:
Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if ((CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebI
message(STATUS "Address Sanitizer enabled for Debug builds, Turn it off with -DDEBUG_ADDRESS_SANITIZER=off")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
# using clang with clang-cl front end
# using clang with clang-cl front end
message(STATUS "Address Sanitizer available on Clang MSVC frontend")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /Oy-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address /Oy-")
Expand Down Expand Up @@ -225,7 +225,7 @@ set(Launcher_QT_VERSION_MAJOR "6" CACHE STRING "Major Qt version to build agains
# Java downloader
set(Launcher_ENABLE_JAVA_DOWNLOADER_DEFAULT ON)

# Although we recommend enabling this, we cannot guarantee binary compatibility on
# Although we recommend enabling this, we cannot guarantee binary compatibility on
# differing Linux/BSD/etc distributions. Downstream packagers should be explicitly opt-ing into this
# feature if they know it will work with their distribution.
if(UNIX AND NOT APPLE)
Expand Down Expand Up @@ -438,10 +438,10 @@ elseif(UNIX)
set(PLUGIN_DEST_DIR "plugins")
set(BUNDLE_DEST_DIR ".")
set(RESOURCES_DEST_DIR ".")

# Apps to bundle
set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${Launcher_APP_BINARY_NAME}")

# directories to look for dependencies
set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
Expand Down Expand Up @@ -495,7 +495,7 @@ if(FORCE_BUNDLED_ZLIB)
set(SKIP_INSTALL_ALL ON)
add_subdirectory(libraries/zlib EXCLUDE_FROM_ALL)

# On OS where unistd.h exists, zlib's generated header defines `Z_HAVE_UNISTD_H`, while the included header does not.
# On OS where unistd.h exists, zlib's generated header defines `Z_HAVE_UNISTD_H`, while the included header does not.
# We cannot safely undo the rename on those systems, and they generally have packages for zlib anyway.
check_include_file(unistd.h NEED_GENERATED_ZCONF)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib/zconf.h.included" AND NOT NEED_GENERATED_ZCONF)
Expand Down Expand Up @@ -532,10 +532,12 @@ else()
endif()
if(NOT cmark_FOUND)
message(STATUS "Using bundled cmark")
set(ORIGINAL_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING 0)
set(BUILD_SHARED_LIBS 0)
set(BUILD_SHARED_LIBS 0)
add_subdirectory(libraries/cmark EXCLUDE_FROM_ALL) # Markdown parser
add_library(cmark::cmark ALIAS cmark)
set(BUILD_TESTING ${ORIGINAL_BUILD_TESTING})
else()
message(STATUS "Using system cmark")
endif()
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions flatpak/org.prismlauncher.PrismLauncher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ runtime: org.kde.Platform
runtime-version: 6.7
sdk: org.kde.Sdk
sdk-extensions:
- org.freedesktop.Sdk.Extension.openjdk21
- org.freedesktop.Sdk.Extension.openjdk17
- org.freedesktop.Sdk.Extension.openjdk8

command: prismlauncher
finish-args:
Expand Down Expand Up @@ -39,23 +37,11 @@ modules:
env:
JAVA_HOME: /usr/lib/sdk/openjdk17/jvm/openjdk-17
JAVA_COMPILER: /usr/lib/sdk/openjdk17/jvm/openjdk-17/bin/javac
run-tests: true
sources:
- type: dir
path: ../

- name: openjdk
buildsystem: simple
build-commands:
- mkdir -p /app/jdk/
- /usr/lib/sdk/openjdk21/install.sh
- mv /app/jre /app/jdk/21
- /usr/lib/sdk/openjdk17/install.sh
- mv /app/jre /app/jdk/17
- /usr/lib/sdk/openjdk8/install.sh
- mv /app/jre /app/jdk/8
cleanup:
- /jre

- name: glfw
buildsystem: cmake-ninja
config-opts:
Expand Down
8 changes: 4 additions & 4 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
bool Application::createSetupWizard()
{
bool javaRequired = [&]() {
if (BuildConfig.JAVA_DOWNLOADER_ENABLED && m_settings->get("AutomaticJavaDownload").toBool()) {
return false;
}
bool ignoreJavaWizard = m_settings->get("IgnoreJavaWizard").toBool();
if (ignoreJavaWizard) {
return false;
Expand All @@ -1083,10 +1086,7 @@ bool Application::createSetupWizard()
}
QString currentJavaPath = settings()->get("JavaPath").toString();
QString actualPath = FS::ResolveExecutable(currentJavaPath);
if (actualPath.isNull()) {
return true;
}
return false;
return actualPath.isNull();
}();
bool askjava = BuildConfig.JAVA_DOWNLOADER_ENABLED && !javaRequired && !m_settings->get("AutomaticJavaDownload").toBool() &&
!m_settings->get("AutomaticJavaSwitch").toBool() && !m_settings->get("UserAskedAboutAutomaticJavaDownload").toBool();
Expand Down
6 changes: 6 additions & 0 deletions launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class Index;
#endif
#define APPLICATION (static_cast<Application*>(QCoreApplication::instance()))

// Used for checking if is a test
#if defined(APPLICATION_DYN)
#undef APPLICATION_DYN
#endif
#define APPLICATION_DYN (dynamic_cast<Application*>(QCoreApplication::instance()))

class Application : public QApplication {
// friends for the purpose of limiting access to deprecated stuff
Q_OBJECT
Expand Down
10 changes: 3 additions & 7 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ set(PRISMUPDATER_SOURCES
updater/prismupdater/UpdaterDialogs.cpp
updater/prismupdater/GitHubRelease.h
updater/prismupdater/GitHubRelease.cpp

Json.h
Json.cpp
FileSystem.h
Expand All @@ -625,7 +625,7 @@ set(PRISMUPDATER_SOURCES
# Zip
MMCZip.h
MMCZip.cpp

# Time
MMCTime.h
MMCTime.cpp
Expand Down Expand Up @@ -1265,14 +1265,10 @@ include(CompilerWarnings)

# Add executable
add_library(Launcher_logic STATIC ${LOGIC_SOURCES} ${LAUNCHER_SOURCES} ${LAUNCHER_UI} ${LAUNCHER_RESOURCES})
if(BUILD_TESTING)
target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_TEST)
endif()
set_project_warnings(Launcher_logic
"${Launcher_MSVC_WARNINGS}"
"${Launcher_CLANG_WARNINGS}"
"${Launcher_GCC_WARNINGS}")
target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_APPLICATION)
target_include_directories(Launcher_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_APPLICATION)
target_link_libraries(Launcher_logic
Expand Down Expand Up @@ -1376,7 +1372,7 @@ if(Launcher_BUILD_UPDATER)
add_executable("${Launcher_Name}_updater" WIN32 updater/prismupdater/updater_main.cpp)
target_sources("${Launcher_Name}_updater" PRIVATE updater/prismupdater/updater.exe.manifest)
target_link_libraries("${Launcher_Name}_updater" prism_updater_logic)

if(DEFINED Launcher_APP_BINARY_NAME)
set_target_properties("${Launcher_Name}_updater" PROPERTIES OUTPUT_NAME "${Launcher_APP_BINARY_NAME}_updater")
endif()
Expand Down
19 changes: 13 additions & 6 deletions launcher/InstanceCreationTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,29 @@ void InstanceCreationTask::executeTask()
// files scheduled to, and we'd better not let the user abort in the middle of it, since it'd
// put the instance in an invalid state.
if (shouldOverride()) {
bool deleteFailed = false;

setAbortable(false);
setStatus(tr("Removing old conflicting files..."));
qDebug() << "Removing old files";

for (auto path : m_files_to_remove) {
for (const QString& path : m_files_to_remove) {
if (!QFile::exists(path))
continue;

qDebug() << "Removing" << path;
if (!FS::deletePath(path)) {
qCritical() << "Couldn't remove the old conflicting files.";
emitFailed(tr("Failed to remove old conflicting files."));
return;

if (!QFile::remove(path)) {
qCritical() << "Could not remove" << path;
deleteFailed = true;
}
}

if (deleteFailed) {
emitFailed(tr("Failed to remove old conflicting files."));
return;
}
}

emitSucceeded();
return;
}
10 changes: 9 additions & 1 deletion launcher/Launcher.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ if [ "x$DEPS_LIST" = "x" ]; then
# Just to be sure...
chmod +x "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}"

ARGS=("${LAUNCHER_DIR}/${LAUNCHER_NAME}" "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}")

if [ -f portable.txt ]; then
ARGS+=("-d" "${LAUNCHER_DIR}")
fi

ARGS+=("$@")

# Run the launcher
exec -a "${LAUNCHER_DIR}/${LAUNCHER_NAME}" "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}" -d "${LAUNCHER_DIR}" "$@"
exec -a "${ARGS[@]}"

# Run the launcher in valgrind
# valgrind --log-file="valgrind.log" --leak-check=full --track-origins=yes "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}" -d "${LAUNCHER_DIR}" "$@"
Expand Down
6 changes: 3 additions & 3 deletions launcher/MTPixmapCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PixmapCache final : public QObject {
*/
bool _markCacheMissByEviciton()
{
static constexpr uint maxInt = static_cast<uint>(std::numeric_limits<int>::max());
static constexpr uint maxCache = static_cast<uint>(std::numeric_limits<int>::max()) / 4;
static constexpr uint step = 10240;
static constexpr int oneSecond = 1000;

Expand All @@ -118,8 +118,8 @@ class PixmapCache final : public QObject {
if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) {
// increase the cache size
uint newSize = _cacheLimit() + step;
if (newSize >= maxInt) { // increase it until you overflow :D
newSize = maxInt;
if (newSize >= maxCache) { // increase it until you overflow :D
newSize = maxCache;
qDebug() << m_consecutive_fast_evicitons
<< tr("pixmap cache misses by eviction happened too fast, doing nothing as the cache size reached it's limit");
} else {
Expand Down
5 changes: 3 additions & 2 deletions launcher/minecraft/auth/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ bool parseMinecraftProfile(QByteArray& data, MinecraftProfile& output)
if (!getString(skinObj.value("url"), skinOut.url)) {
continue;
}
skinOut.url.replace("http://textures.minecraft.net", "https://textures.minecraft.net");
if (!getString(skinObj.value("variant"), skinOut.variant)) {
continue;
}
Expand Down Expand Up @@ -221,9 +222,9 @@ namespace {
// these skin URLs are for the MHF_Steve and MHF_Alex accounts (made by a Mojang employee)
// they are needed because the session server doesn't return skin urls for default skins
static const QString SKIN_URL_STEVE =
"http://textures.minecraft.net/texture/1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b";
"https://textures.minecraft.net/texture/1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b";
static const QString SKIN_URL_ALEX =
"http://textures.minecraft.net/texture/83cee5ca6afcdb171285aa00e8049c297b2dbeba0efb8ff970a5677a1b644032";
"https://textures.minecraft.net/texture/83cee5ca6afcdb171285aa00e8049c297b2dbeba0efb8ff970a5677a1b644032";

bool isDefaultModelSteve(QString uuid)
{
Expand Down
41 changes: 25 additions & 16 deletions launcher/minecraft/mod/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/

#include "Mod.h"
#include <qpixmap.h>

#include <QDebug>
#include <QDir>
Expand Down Expand Up @@ -241,7 +242,7 @@ void Mod::finishResolvingWithDetails(ModDetails&& details)
if (metadata)
setMetadata(std::move(metadata));
if (!iconPath().isEmpty()) {
m_pack_image_cache_key.was_read_attempt = false;
m_packImageCacheKey.wasReadAttempt = false;
}
}

Expand Down Expand Up @@ -290,45 +291,53 @@ auto Mod::issueTracker() const -> QString
return details().issue_tracker;
}

void Mod::setIcon(QImage new_image) const
QPixmap Mod::setIcon(QImage new_image) const
{
QMutexLocker locker(&m_data_lock);

Q_ASSERT(!new_image.isNull());

if (m_pack_image_cache_key.key.isValid())
PixmapCache::remove(m_pack_image_cache_key.key);
if (m_packImageCacheKey.key.isValid())
PixmapCache::remove(m_packImageCacheKey.key);

// scale the image to avoid flooding the pixmapcache
auto pixmap =
QPixmap::fromImage(new_image.scaled({ 64, 64 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding, Qt::SmoothTransformation));

m_pack_image_cache_key.key = PixmapCache::insert(pixmap);
m_pack_image_cache_key.was_ever_used = true;
m_pack_image_cache_key.was_read_attempt = true;
m_packImageCacheKey.key = PixmapCache::insert(pixmap);
m_packImageCacheKey.wasEverUsed = true;
m_packImageCacheKey.wasReadAttempt = true;
return pixmap;
}

QPixmap Mod::icon(QSize size, Qt::AspectRatioMode mode) const
{
QPixmap cached_image;
if (PixmapCache::find(m_pack_image_cache_key.key, &cached_image)) {
auto pixmap_transform = [&size, &mode](QPixmap pixmap) {
if (size.isNull())
return cached_image;
return cached_image.scaled(size, mode, Qt::SmoothTransformation);
return pixmap;
return pixmap.scaled(size, mode, Qt::SmoothTransformation);
};

QPixmap cached_image;
if (PixmapCache::find(m_packImageCacheKey.key, &cached_image)) {
return pixmap_transform(cached_image);
}

// No valid image we can get
if ((!m_pack_image_cache_key.was_ever_used && m_pack_image_cache_key.was_read_attempt) || iconPath().isEmpty())
if ((!m_packImageCacheKey.wasEverUsed && m_packImageCacheKey.wasReadAttempt) || iconPath().isEmpty())
return {};

if (m_pack_image_cache_key.was_ever_used) {
if (m_packImageCacheKey.wasEverUsed) {
qDebug() << "Mod" << name() << "Had it's icon evicted from the cache. reloading...";
PixmapCache::markCacheMissByEviciton();
}
// Image got evicted from the cache or an attempt to load it has not been made. load it and retry.
m_pack_image_cache_key.was_read_attempt = true;
ModUtils::loadIconFile(*this);
return icon(size);
m_packImageCacheKey.wasReadAttempt = true;
if (ModUtils::loadIconFile(*this, &cached_image)) {
return pixmap_transform(cached_image);
}
// Image failed to load
return {};
}

bool Mod::valid() const
Expand Down
8 changes: 4 additions & 4 deletions launcher/minecraft/mod/Mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Mod : public Resource {
/** Gets the icon of the mod, converted to a QPixmap for drawing, and scaled to size. */
[[nodiscard]] QPixmap icon(QSize size, Qt::AspectRatioMode mode = Qt::AspectRatioMode::IgnoreAspectRatio) const;
/** Thread-safe. */
void setIcon(QImage new_image) const;
QPixmap setIcon(QImage new_image) const;

auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
Expand Down Expand Up @@ -111,7 +111,7 @@ class Mod : public Resource {

struct {
QPixmapCache::Key key;
bool was_ever_used = false;
bool was_read_attempt = false;
} mutable m_pack_image_cache_key;
bool wasEverUsed = false;
bool wasReadAttempt = false;
} mutable m_packImageCacheKey;
};
Loading

0 comments on commit 9a8e24e

Please sign in to comment.