Merge branch 'develop' into env-vars
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
commit
bfafbdc51e
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# EditorConfig specs and documentation: https://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# C++ Code Style settings
|
||||||
|
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
|
||||||
|
cpp_generate_documentation_comments = doxygen_slash_star
|
32
.github/workflows/backport.yml
vendored
Normal file
32
.github/workflows/backport.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
name: Backport
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [closed, labeled]
|
||||||
|
|
||||||
|
# WARNING:
|
||||||
|
# When extending this action, be aware that $GITHUB_TOKEN allows write access to
|
||||||
|
# the GitHub repository. This means that it should not evaluate user input in a
|
||||||
|
# way that allows code injection.
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
backport:
|
||||||
|
permissions:
|
||||||
|
contents: write # for korthout/backport-action to create branch
|
||||||
|
pull-requests: write # for korthout/backport-action to create PR to backport
|
||||||
|
name: Backport Pull Request
|
||||||
|
if: github.repository_owner == 'PrismLauncher' && github.event.pull_request.merged == true && (github.event_name != 'labeled' || startsWith('backport', github.event.label.name))
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
- name: Create backport PRs
|
||||||
|
uses: korthout/backport-action@v1.3.1
|
||||||
|
with:
|
||||||
|
# Config README: https://github.com/korthout/backport-action#backport-action
|
||||||
|
pull_description: |-
|
||||||
|
Bot-based backport to `${target_branch}`, triggered by a label in #${pull_number}.
|
||||||
|
|
10
.github/workflows/build.yml
vendored
10
.github/workflows/build.yml
vendored
@ -264,23 +264,23 @@ jobs:
|
|||||||
- name: Configure CMake (macOS)
|
- name: Configure CMake (macOS)
|
||||||
if: runner.os == 'macOS' && matrix.qt_ver == 6
|
if: runner.os == 'macOS' && matrix.qt_ver == 6
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -G Ninja
|
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=official -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -G Ninja
|
||||||
|
|
||||||
- name: Configure CMake (macOS-Legacy)
|
- name: Configure CMake (macOS-Legacy)
|
||||||
if: runner.os == 'macOS' && matrix.qt_ver == 5
|
if: runner.os == 'macOS' && matrix.qt_ver == 5
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DMACOSX_SPARKLE_UPDATE_PUBLIC_KEY="" -DMACOSX_SPARKLE_UPDATE_FEED_URL="" -G Ninja
|
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=official -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DMACOSX_SPARKLE_UPDATE_PUBLIC_KEY="" -DMACOSX_SPARKLE_UPDATE_FEED_URL="" -G Ninja
|
||||||
|
|
||||||
- name: Configure CMake (Windows MinGW-w64)
|
- name: Configure CMake (Windows MinGW-w64)
|
||||||
if: runner.os == 'Windows' && matrix.msystem != ''
|
if: runner.os == 'Windows' && matrix.msystem != ''
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=6 -DCMAKE_OBJDUMP=/mingw64/bin/objdump.exe -G Ninja
|
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=official -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=6 -DCMAKE_OBJDUMP=/mingw64/bin/objdump.exe -G Ninja
|
||||||
|
|
||||||
- name: Configure CMake (Windows MSVC)
|
- name: Configure CMake (Windows MSVC)
|
||||||
if: runner.os == 'Windows' && matrix.msystem == ''
|
if: runner.os == 'Windows' && matrix.msystem == ''
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" -A${{ matrix.architecture}} -DLauncher_FORCE_BUNDLED_LIBS=ON
|
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=official -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" -A${{ matrix.architecture}} -DLauncher_FORCE_BUNDLED_LIBS=ON
|
||||||
# https://github.com/ccache/ccache/wiki/MS-Visual-Studio (I coudn't figure out the compiler prefix)
|
# https://github.com/ccache/ccache/wiki/MS-Visual-Studio (I coudn't figure out the compiler prefix)
|
||||||
if ("${{ env.CCACHE_VAR }}")
|
if ("${{ env.CCACHE_VAR }}")
|
||||||
{
|
{
|
||||||
@ -295,7 +295,7 @@ jobs:
|
|||||||
- name: Configure CMake (Linux)
|
- name: Configure CMake (Linux)
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=Linux -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -G Ninja
|
cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=official -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -G Ninja
|
||||||
|
|
||||||
##
|
##
|
||||||
# BUILD
|
# BUILD
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -19,3 +19,6 @@
|
|||||||
[submodule "libraries/cmark"]
|
[submodule "libraries/cmark"]
|
||||||
path = libraries/cmark
|
path = libraries/cmark
|
||||||
url = https://github.com/commonmark/cmark.git
|
url = https://github.com/commonmark/cmark.git
|
||||||
|
[submodule "flatpak/shared-modules"]
|
||||||
|
path = flatpak/shared-modules
|
||||||
|
url = https://github.com/flathub/shared-modules.git
|
||||||
|
@ -85,6 +85,38 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOML_ENABLE_FLOAT16=0")
|
|||||||
# set CXXFLAGS for build targets
|
# set CXXFLAGS for build targets
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}")
|
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
|
|
||||||
|
option(DEBUG_ADDRESS_SANITIZER "Enable Address Sanitizer in Debug builds" on)
|
||||||
|
|
||||||
|
# If this is a Debug build turn on address sanitiser
|
||||||
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEBUG_ADDRESS_SANITIZER)
|
||||||
|
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
|
||||||
|
message(STATUS "Address Sanitizer available on Clang MSVC frontend")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /O1 /Oy-")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address /O1 /Oy-")
|
||||||
|
else()
|
||||||
|
# AppleClang and Clang
|
||||||
|
message(STATUS "Address Sanitizer available on Clang")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer")
|
||||||
|
endif()
|
||||||
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
|
# GCC
|
||||||
|
message(STATUS "Address Sanitizer available on GCC")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer")
|
||||||
|
link_libraries("asan")
|
||||||
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||||
|
message(STATUS "Address Sanitizer available on MSVC")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /O1 /Oy-")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address /O1 /Oy-")
|
||||||
|
else()
|
||||||
|
message(STATUS "Address Sanitizer not available on compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
option(ENABLE_LTO "Enable Link Time Optimization" off)
|
option(ENABLE_LTO "Enable Link Time Optimization" off)
|
||||||
|
|
||||||
if(ENABLE_LTO)
|
if(ENABLE_LTO)
|
||||||
@ -146,7 +178,7 @@ set(Launcher_VERSION_NAME4 "${Launcher_VERSION_MAJOR}.${Launcher_VERSION_MINOR}.
|
|||||||
set(Launcher_VERSION_NAME4_COMMA "${Launcher_VERSION_MAJOR},${Launcher_VERSION_MINOR},0,0")
|
set(Launcher_VERSION_NAME4_COMMA "${Launcher_VERSION_MAJOR},${Launcher_VERSION_MINOR},0,0")
|
||||||
|
|
||||||
# Build platform.
|
# Build platform.
|
||||||
set(Launcher_BUILD_PLATFORM "" CACHE STRING "A short string identifying the platform that this build was built for. Only used to display in the about dialog.")
|
set(Launcher_BUILD_PLATFORM "unknown" CACHE STRING "A short string identifying the platform that this build was built for. Only used to display in the about dialog.")
|
||||||
|
|
||||||
# Channel list URL
|
# Channel list URL
|
||||||
set(Launcher_UPDATER_BASE "" CACHE STRING "Base URL for the updater.")
|
set(Launcher_UPDATER_BASE "" CACHE STRING "Base URL for the updater.")
|
||||||
@ -332,7 +364,7 @@ elseif(UNIX)
|
|||||||
|
|
||||||
set(BINARY_DEST_DIR "bin")
|
set(BINARY_DEST_DIR "bin")
|
||||||
set(LIBRARY_DEST_DIR "lib${LIB_SUFFIX}")
|
set(LIBRARY_DEST_DIR "lib${LIB_SUFFIX}")
|
||||||
set(JARS_DEST_DIR "share/${Launcher_APP_BINARY_NAME}")
|
set(JARS_DEST_DIR "share/${Launcher_Name}")
|
||||||
|
|
||||||
# install as bundle with no dependencies included
|
# install as bundle with no dependencies included
|
||||||
set(INSTALL_BUNDLE "nodeps")
|
set(INSTALL_BUNDLE "nodeps")
|
||||||
@ -345,7 +377,7 @@ elseif(UNIX)
|
|||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_SVG} DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/scalable/apps")
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_SVG} DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/scalable/apps")
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_mrpack_MIMEInfo} DESTINATION ${KDE_INSTALL_MIMEDIR})
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_mrpack_MIMEInfo} DESTINATION ${KDE_INSTALL_MIMEDIR})
|
||||||
|
|
||||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/launcher/qtlogging.ini" DESTINATION "${KDE_INSTALL_DATADIR}/${Launcher_Name}")
|
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/launcher/qtlogging.ini" DESTINATION "share/${Launcher_Name}")
|
||||||
|
|
||||||
if(Launcher_ManPage)
|
if(Launcher_ManPage)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${Launcher_ManPage} DESTINATION "${KDE_INSTALL_MANDIR}/man6")
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${Launcher_ManPage} DESTINATION "${KDE_INSTALL_MANDIR}/man6")
|
||||||
|
@ -61,3 +61,10 @@ As a bonus, you can also [cryptographically sign your commits][gh-signing-commit
|
|||||||
|
|
||||||
[gh-signing-commits]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
|
[gh-signing-commits]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
|
||||||
[gh-vigilant-mode]: https://docs.github.com/en/authentication/managing-commit-signature-verification/displaying-verification-statuses-for-all-of-your-commits
|
[gh-vigilant-mode]: https://docs.github.com/en/authentication/managing-commit-signature-verification/displaying-verification-statuses-for-all-of-your-commits
|
||||||
|
|
||||||
|
|
||||||
|
## Backporting to Release Branches
|
||||||
|
|
||||||
|
We use [automated backports](https://github.com/PrismLauncher/PrismLauncher/blob/develop/.github/workflows/backport.yml) to merge specific contributions from develop into `release` branches.
|
||||||
|
|
||||||
|
This is done when pull requests are merged and have labels such as `backport release-7.x` - which should be added along with the milestone for the release.
|
||||||
|
@ -65,7 +65,7 @@ Config::Config()
|
|||||||
MAC_SPARKLE_PUB_KEY = "@MACOSX_SPARKLE_UPDATE_PUBLIC_KEY@";
|
MAC_SPARKLE_PUB_KEY = "@MACOSX_SPARKLE_UPDATE_PUBLIC_KEY@";
|
||||||
MAC_SPARKLE_APPCAST_URL = "@MACOSX_SPARKLE_UPDATE_FEED_URL@";
|
MAC_SPARKLE_APPCAST_URL = "@MACOSX_SPARKLE_UPDATE_FEED_URL@";
|
||||||
|
|
||||||
if (BUILD_PLATFORM == "macOS" && !MAC_SPARKLE_PUB_KEY.isEmpty() && !MAC_SPARKLE_APPCAST_URL.isEmpty())
|
if (!MAC_SPARKLE_PUB_KEY.isEmpty() && !MAC_SPARKLE_APPCAST_URL.isEmpty())
|
||||||
{
|
{
|
||||||
UPDATER_ENABLED = true;
|
UPDATER_ENABLED = true;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class Config {
|
|||||||
|
|
||||||
bool UPDATER_ENABLED = false;
|
bool UPDATER_ENABLED = false;
|
||||||
|
|
||||||
/// A short string identifying this build's platform. For example, "lin64" or "win32".
|
/// A short string identifying this build's platform or distribution.
|
||||||
QString BUILD_PLATFORM;
|
QString BUILD_PLATFORM;
|
||||||
|
|
||||||
/// A string containing the build timestamp
|
/// A string containing the build timestamp
|
||||||
|
18
flake.lock
generated
18
flake.lock
generated
@ -21,11 +21,11 @@
|
|||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688254665,
|
"lastModified": 1688466019,
|
||||||
"narHash": "sha256-8FHEgBrr7gYNiS/NzCxIO3m4hvtLRW9YY1nYo1ivm3o=",
|
"narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "267149c58a14d15f7f81b4d737308421de9d7152",
|
"rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -91,11 +91,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688221086,
|
"lastModified": 1689413807,
|
||||||
"narHash": "sha256-cdW6qUL71cNWhHCpMPOJjlw0wzSRP0pVlRn2vqX/VVg=",
|
"narHash": "sha256-exuzOvOhGAEKWQKwDuZAL4N8a1I837hH5eocaTcIbLc=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cd99c2b3c9f160cd004318e0697f90bbd5960825",
|
"rev": "46ed466081b9cad1125b11f11a2af5cc40b942c7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -138,11 +138,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688386108,
|
"lastModified": 1689328505,
|
||||||
"narHash": "sha256-Vffto9QaVonzYAcPlAzd0soqWYpPpKk60dfNLSIXcFA=",
|
"narHash": "sha256-9B3+OeUn1a/CvzE3GW6nWNwS5J7PDHTyHGlpL3wV5oA=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "pre-commit-hooks.nix",
|
"repo": "pre-commit-hooks.nix",
|
||||||
"rev": "42587d3414d1747999a5f71e92a83cf6547b62da",
|
"rev": "5e28316db471d1ac234beb70031b635437421dd6",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
22
flatpak/libdecor.json
Normal file
22
flatpak/libdecor.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "libdecor",
|
||||||
|
"buildsystem": "meson",
|
||||||
|
"config-opts": [
|
||||||
|
"-Ddemo=false"
|
||||||
|
],
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://gitlab.freedesktop.org/libdecor/libdecor.git",
|
||||||
|
"commit": "73260393a97291c887e1074ab7f318e031be0ac6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"path": "patches/weird_libdecor.patch"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cleanup": [
|
||||||
|
"/include",
|
||||||
|
"/lib/pkgconfig"
|
||||||
|
]
|
||||||
|
}
|
@ -5,13 +5,6 @@ sdk: org.kde.Sdk
|
|||||||
sdk-extensions:
|
sdk-extensions:
|
||||||
- org.freedesktop.Sdk.Extension.openjdk17
|
- org.freedesktop.Sdk.Extension.openjdk17
|
||||||
- org.freedesktop.Sdk.Extension.openjdk8
|
- org.freedesktop.Sdk.Extension.openjdk8
|
||||||
add-extensions:
|
|
||||||
com.valvesoftware.Steam.Utility.gamescope:
|
|
||||||
version: stable
|
|
||||||
add-ld-path: lib
|
|
||||||
no-autodownload: true
|
|
||||||
autodelete: false
|
|
||||||
directory: utils/gamescope
|
|
||||||
|
|
||||||
command: prismlauncher
|
command: prismlauncher
|
||||||
finish-args:
|
finish-args:
|
||||||
@ -26,12 +19,22 @@ finish-args:
|
|||||||
# Mod drag&drop
|
# Mod drag&drop
|
||||||
- --filesystem=xdg-download:ro
|
- --filesystem=xdg-download:ro
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
- /lib/libGLU*
|
||||||
|
|
||||||
modules:
|
modules:
|
||||||
|
# Might be needed by some Controller mods (see https://github.com/isXander/Controlify/issues/31)
|
||||||
|
- shared-modules/libusb/libusb.json
|
||||||
|
|
||||||
|
# Needed for proper Wayland support
|
||||||
|
- libdecor.json
|
||||||
|
|
||||||
- name: prismlauncher
|
- name: prismlauncher
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
|
builddir: true
|
||||||
config-opts:
|
config-opts:
|
||||||
- -DLauncher_BUILD_PLATFORM=flatpak
|
- -DLauncher_BUILD_PLATFORM=flatpak
|
||||||
- -DCMAKE_BUILD_TYPE=Debug
|
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||||
- -DLauncher_QT_VERSION_MAJOR=5
|
- -DLauncher_QT_VERSION_MAJOR=5
|
||||||
build-options:
|
build-options:
|
||||||
env:
|
env:
|
||||||
@ -40,7 +43,7 @@ modules:
|
|||||||
sources:
|
sources:
|
||||||
- type: dir
|
- type: dir
|
||||||
path: ../
|
path: ../
|
||||||
builddir: true
|
|
||||||
- name: openjdk
|
- name: openjdk
|
||||||
buildsystem: simple
|
buildsystem: simple
|
||||||
build-commands:
|
build-commands:
|
||||||
@ -49,14 +52,45 @@ modules:
|
|||||||
- mv /app/jre /app/jdk/17
|
- mv /app/jre /app/jdk/17
|
||||||
- /usr/lib/sdk/openjdk8/install.sh
|
- /usr/lib/sdk/openjdk8/install.sh
|
||||||
- mv /app/jre /app/jdk/8
|
- mv /app/jre /app/jdk/8
|
||||||
cleanup: [/jre]
|
cleanup:
|
||||||
|
- /jre
|
||||||
|
|
||||||
|
- name: glfw
|
||||||
|
buildsystem: cmake-ninja
|
||||||
|
config-opts:
|
||||||
|
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||||
|
- -DBUILD_SHARED_LIBS:BOOL=ON
|
||||||
|
- -DGLFW_USE_WAYLAND=ON
|
||||||
|
sources:
|
||||||
|
- type: git
|
||||||
|
url: https://github.com/glfw/glfw.git
|
||||||
|
commit: 3fa2360720eeba1964df3c0ecf4b5df8648a8e52
|
||||||
|
- type: patch
|
||||||
|
path: patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch
|
||||||
|
- type: patch
|
||||||
|
path: patches/0005-Add-warning-about-being-an-unofficial-patch.patch
|
||||||
|
- type: patch
|
||||||
|
path: patches/0007-Platform-Prefer-Wayland-over-X11.patch
|
||||||
|
cleanup:
|
||||||
|
- /include
|
||||||
|
- /lib/cmake
|
||||||
|
- /lib/pkgconfig
|
||||||
|
|
||||||
- name: xrandr
|
- name: xrandr
|
||||||
buildsystem: autotools
|
buildsystem: autotools
|
||||||
sources:
|
sources:
|
||||||
- type: archive
|
- type: archive
|
||||||
url: https://xorg.freedesktop.org/archive/individual/app/xrandr-1.5.1.tar.xz
|
url: https://xorg.freedesktop.org/archive/individual/app/xrandr-1.5.2.tar.xz
|
||||||
sha256: 7bc76daf9d72f8aff885efad04ce06b90488a1a169d118dea8a2b661832e8762
|
sha256: c8bee4790d9058bacc4b6246456c58021db58a87ddda1a9d0139bf5f18f1f240
|
||||||
cleanup: [/share/man, /bin/xkeystone]
|
x-checker-data:
|
||||||
|
type: anitya
|
||||||
|
project-id: 14957
|
||||||
|
stable-only: true
|
||||||
|
url-template: https://xorg.freedesktop.org/archive/individual/app/xrandr-$version.tar.xz
|
||||||
|
cleanup:
|
||||||
|
- /share/man
|
||||||
|
- /bin/xkeystone
|
||||||
|
|
||||||
- name: gamemode
|
- name: gamemode
|
||||||
buildsystem: meson
|
buildsystem: meson
|
||||||
config-opts:
|
config-opts:
|
||||||
@ -67,19 +101,56 @@ modules:
|
|||||||
# post-install is running inside the build dir, we need it from the source though
|
# post-install is running inside the build dir, we need it from the source though
|
||||||
- install -Dm755 ../data/gamemoderun -t /app/bin
|
- install -Dm755 ../data/gamemoderun -t /app/bin
|
||||||
sources:
|
sources:
|
||||||
- type: git
|
- type: archive
|
||||||
url: https://github.com/FeralInteractive/gamemode
|
archive-type: tar-gzip
|
||||||
tag: "1.7"
|
url: https://api.github.com/repos/FeralInteractive/gamemode/tarball/1.7
|
||||||
commit: 4dc99dff76218718763a6b07fc1900fa6d1dafd9
|
sha256: 57ce73ba605d1cf12f8d13725006a895182308d93eba0f69f285648449641803
|
||||||
|
x-checker-data:
|
||||||
|
type: json
|
||||||
|
url: https://api.github.com/repos/FeralInteractive/gamemode/releases/latest
|
||||||
|
version-query: .tag_name
|
||||||
|
url-query: .tarball_url
|
||||||
|
timestamp-query: .published_at
|
||||||
|
cleanup:
|
||||||
|
- /include
|
||||||
|
- /lib/pkgconfig
|
||||||
|
- /lib/libgamemodeauto.a
|
||||||
|
|
||||||
|
- name: glxinfo
|
||||||
|
buildsystem: meson
|
||||||
|
config-opts:
|
||||||
|
- --bindir=/app/mesa-demos
|
||||||
|
- -Degl=disabled
|
||||||
|
- -Dglut=disabled
|
||||||
|
- -Dosmesa=disabled
|
||||||
|
- -Dvulkan=disabled
|
||||||
|
- -Dwayland=disabled
|
||||||
|
post-install:
|
||||||
|
- mv -v /app/mesa-demos/glxinfo /app/bin
|
||||||
|
sources:
|
||||||
|
- type: archive
|
||||||
|
url: https://archive.mesa3d.org/demos/mesa-demos-9.0.0.tar.xz
|
||||||
|
sha256: 3046a3d26a7b051af7ebdd257a5f23bfeb160cad6ed952329cdff1e9f1ed496b
|
||||||
|
x-checker-data:
|
||||||
|
type: anitya
|
||||||
|
project-id: 16781
|
||||||
|
stable-only: true
|
||||||
|
url-template: https://archive.mesa3d.org/demos/mesa-demos-$version.tar.xz
|
||||||
|
cleanup:
|
||||||
|
- /include
|
||||||
|
- /mesa-demos
|
||||||
|
- /share
|
||||||
|
modules:
|
||||||
|
- shared-modules/glu/glu-9.json
|
||||||
|
|
||||||
- name: enhance
|
- name: enhance
|
||||||
buildsystem: simple
|
buildsystem: simple
|
||||||
build-commands:
|
build-commands:
|
||||||
- mkdir -p /app/utils/gamescope
|
|
||||||
- install -Dm755 prime-run /app/bin/prime-run
|
- install -Dm755 prime-run /app/bin/prime-run
|
||||||
- mv /app/bin/prismlauncher /app/bin/prismrun
|
- mv /app/bin/prismlauncher /app/bin/prismrun
|
||||||
- install -Dm755 prismlauncher /app/bin/prismlauncher
|
- install -Dm755 prismlauncher /app/bin/prismlauncher
|
||||||
sources:
|
sources:
|
||||||
- type: file
|
- type: file
|
||||||
path: ../flatpak/prime-run
|
path: prime-run
|
||||||
- type: file
|
- type: file
|
||||||
path: ../flatpak/prismlauncher
|
path: prismlauncher
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
diff --git a/src/wl_window.c b/src/wl_window.c
|
||||||
|
index 52d3b9eb..4ac4eb5d 100644
|
||||||
|
--- a/src/wl_window.c
|
||||||
|
+++ b/src/wl_window.c
|
||||||
|
@@ -2117,8 +2117,7 @@ void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title)
|
||||||
|
void _glfwSetWindowIconWayland(_GLFWwindow* window,
|
||||||
|
int count, const GLFWimage* images)
|
||||||
|
{
|
||||||
|
- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
|
||||||
|
- "Wayland: The platform does not support setting the window icon");
|
||||||
|
+ fprintf(stderr, "!!! Ignoring Error: Wayland: The platform does not support setting the window icon\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
|
||||||
|
@@ -2361,8 +2360,7 @@ void _glfwRequestWindowAttentionWayland(_GLFWwindow* window)
|
||||||
|
|
||||||
|
void _glfwFocusWindowWayland(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
|
||||||
|
- "Wayland: The platform does not support setting the input focus");
|
||||||
|
+ fprintf(stderr, "!!! Ignoring Error: Wayland: The platform does not support setting the input focus\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwSetWindowMonitorWayland(_GLFWwindow* window,
|
@ -0,0 +1,17 @@
|
|||||||
|
diff --git a/src/init.c b/src/init.c
|
||||||
|
index 06dbb3f2..a7c6da86 100644
|
||||||
|
--- a/src/init.c
|
||||||
|
+++ b/src/init.c
|
||||||
|
@@ -449,6 +449,12 @@ GLFWAPI int glfwInit(void)
|
||||||
|
_glfw.initialized = GLFW_TRUE;
|
||||||
|
|
||||||
|
glfwDefaultWindowHints();
|
||||||
|
+
|
||||||
|
+ fprintf(stderr, "!!! Patched GLFW from https://github.com/Admicos/minecraft-wayland\n"
|
||||||
|
+ "!!! If any issues with the window, or some issues with rendering, occur, "
|
||||||
|
+ "first try with the built-in GLFW, and if that solves the issue, report there first.\n"
|
||||||
|
+ "!!! Use outside Minecraft is untested, and things might break.\n");
|
||||||
|
+
|
||||||
|
return GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
20
flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch
Normal file
20
flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
diff --git a/src/platform.c b/src/platform.c
|
||||||
|
index c5966ae7..3e7442f9 100644
|
||||||
|
--- a/src/platform.c
|
||||||
|
+++ b/src/platform.c
|
||||||
|
@@ -49,12 +49,12 @@ static const struct
|
||||||
|
#if defined(_GLFW_COCOA)
|
||||||
|
{ GLFW_PLATFORM_COCOA, _glfwConnectCocoa },
|
||||||
|
#endif
|
||||||
|
-#if defined(_GLFW_X11)
|
||||||
|
- { GLFW_PLATFORM_X11, _glfwConnectX11 },
|
||||||
|
-#endif
|
||||||
|
#if defined(_GLFW_WAYLAND)
|
||||||
|
{ GLFW_PLATFORM_WAYLAND, _glfwConnectWayland },
|
||||||
|
#endif
|
||||||
|
+#if defined(_GLFW_X11)
|
||||||
|
+ { GLFW_PLATFORM_X11, _glfwConnectX11 },
|
||||||
|
+#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform)
|
40
flatpak/patches/weird_libdecor.patch
Normal file
40
flatpak/patches/weird_libdecor.patch
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
diff --git a/src/libdecor.c b/src/libdecor.c
|
||||||
|
index a9c1106..1aa38b3 100644
|
||||||
|
--- a/src/libdecor.c
|
||||||
|
+++ b/src/libdecor.c
|
||||||
|
@@ -1391,22 +1391,32 @@ calculate_priority(const struct libdecor_plugin_description *plugin_description)
|
||||||
|
static bool
|
||||||
|
check_symbol_conflicts(const struct libdecor_plugin_description *plugin_description)
|
||||||
|
{
|
||||||
|
+ bool ret = true;
|
||||||
|
char * const *symbol;
|
||||||
|
+ void* main_prog = dlopen(NULL, RTLD_LAZY);
|
||||||
|
+ if (!main_prog) {
|
||||||
|
+ fprintf(stderr, "Plugin \"%s\" couldn't check conflicting symbols: \"%s\".\n",
|
||||||
|
+ plugin_description->description, dlerror());
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
|
||||||
|
symbol = plugin_description->conflicting_symbols;
|
||||||
|
while (*symbol) {
|
||||||
|
dlerror();
|
||||||
|
- dlsym (RTLD_DEFAULT, *symbol);
|
||||||
|
+ dlsym (main_prog, *symbol);
|
||||||
|
if (!dlerror()) {
|
||||||
|
fprintf(stderr, "Plugin \"%s\" uses conflicting symbol \"%s\".\n",
|
||||||
|
plugin_description->description, *symbol);
|
||||||
|
- return false;
|
||||||
|
+ ret = false;
|
||||||
|
+ break;
|
||||||
|
}
|
||||||
|
|
||||||
|
symbol++;
|
||||||
|
}
|
||||||
|
|
||||||
|
- return true;
|
||||||
|
+ dlclose(main_prog);
|
||||||
|
+ return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct plugin_loader *
|
@ -5,7 +5,7 @@ for i in {0..9}; do
|
|||||||
test -S "$XDG_RUNTIME_DIR"/discord-ipc-"$i" || ln -sf {app/com.discordapp.Discord,"$XDG_RUNTIME_DIR"}/discord-ipc-"$i";
|
test -S "$XDG_RUNTIME_DIR"/discord-ipc-"$i" || ln -sf {app/com.discordapp.Discord,"$XDG_RUNTIME_DIR"}/discord-ipc-"$i";
|
||||||
done
|
done
|
||||||
|
|
||||||
export PATH="${PATH}${PATH:+:}/app/utils/gamescope/bin:/usr/lib/extensions/vulkan/MangoHud/bin"
|
export PATH="${PATH}${PATH:+:}/usr/lib/extensions/vulkan/gamescope/bin:/usr/lib/extensions/vulkan/MangoHud/bin"
|
||||||
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}/usr/lib/extensions/vulkan/MangoHud/\$LIB/"
|
export VK_LAYER_PATH="/usr/lib/extensions/vulkan/share/vulkan/implicit_layer.d/"
|
||||||
|
|
||||||
exec /app/bin/prismrun "$@"
|
exec /app/bin/prismrun "$@"
|
||||||
|
1
flatpak/shared-modules
Submodule
1
flatpak/shared-modules
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 45094ca570be383d06df729b6972830ec63bd3df
|
@ -6,9 +6,10 @@
|
|||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 Lenny McLennington <lenny@sneed.church>
|
* Copyright (C) 2022 Lenny McLennington <lenny@sneed.church>
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||||
|
* Copyright (C) 2023 seth <getchoo at tuta dot io>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -434,7 +435,11 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
}
|
}
|
||||||
// seach root path
|
// seach root path
|
||||||
if(!foundLoggingRules) {
|
if(!foundLoggingRules) {
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
||||||
|
logRulesPath = FS::PathCombine(m_rootPath, "share", BuildConfig.LAUNCHER_NAME, logRulesFile);
|
||||||
|
#else
|
||||||
logRulesPath = FS::PathCombine(m_rootPath, logRulesFile);
|
logRulesPath = FS::PathCombine(m_rootPath, logRulesFile);
|
||||||
|
#endif
|
||||||
qDebug() << "Testing" << logRulesPath << "...";
|
qDebug() << "Testing" << logRulesPath << "...";
|
||||||
foundLoggingRules = QFile::exists(logRulesPath);
|
foundLoggingRules = QFile::exists(logRulesPath);
|
||||||
}
|
}
|
||||||
@ -472,6 +477,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
|
|
||||||
qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT;
|
qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT;
|
||||||
qDebug() << "Version : " << BuildConfig.printableVersionString();
|
qDebug() << "Version : " << BuildConfig.printableVersionString();
|
||||||
|
qDebug() << "Platform : " << BuildConfig.BUILD_PLATFORM;
|
||||||
qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT;
|
qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT;
|
||||||
qDebug() << "Git refspec : " << BuildConfig.GIT_REFSPEC;
|
qDebug() << "Git refspec : " << BuildConfig.GIT_REFSPEC;
|
||||||
if (adjustedBy.size())
|
if (adjustedBy.size())
|
||||||
@ -569,6 +575,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
|
|
||||||
// Language
|
// Language
|
||||||
m_settings->registerSetting("Language", QString());
|
m_settings->registerSetting("Language", QString());
|
||||||
|
m_settings->registerSetting("UseSystemLocale", false);
|
||||||
|
|
||||||
// Console
|
// Console
|
||||||
m_settings->registerSetting("ShowConsole", false);
|
m_settings->registerSetting("ShowConsole", false);
|
||||||
@ -605,6 +612,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
m_settings->registerSetting("IgnoreJavaCompatibility", false);
|
m_settings->registerSetting("IgnoreJavaCompatibility", false);
|
||||||
m_settings->registerSetting("IgnoreJavaWizard", false);
|
m_settings->registerSetting("IgnoreJavaWizard", false);
|
||||||
|
|
||||||
|
// Mod loader settings
|
||||||
|
m_settings->registerSetting("DisableQuiltBeacon", false);
|
||||||
|
|
||||||
// Native library workarounds
|
// Native library workarounds
|
||||||
m_settings->registerSetting("UseNativeOpenAL", false);
|
m_settings->registerSetting("UseNativeOpenAL", false);
|
||||||
m_settings->registerSetting("UseNativeGLFW", false);
|
m_settings->registerSetting("UseNativeGLFW", false);
|
||||||
@ -922,12 +932,7 @@ bool Application::createSetupWizard()
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}();
|
}();
|
||||||
bool languageRequired = [&]()
|
bool languageRequired = settings()->get("Language").toString().isEmpty();
|
||||||
{
|
|
||||||
if (settings()->get("Language").toString().isEmpty())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}();
|
|
||||||
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
|
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
|
||||||
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
|
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
|
||||||
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
|
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
|
||||||
@ -1185,6 +1190,16 @@ QIcon Application::getThemedIcon(const QString& name)
|
|||||||
return QIcon::fromTheme(name);
|
return QIcon::fromTheme(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<CatPack*> Application::getValidCatPacks()
|
||||||
|
{
|
||||||
|
return m_themeManager->getValidCatPacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Application::getCatPack(QString catName)
|
||||||
|
{
|
||||||
|
return m_themeManager->getCatPack(catName);
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::openJsonEditor(const QString& filename)
|
bool Application::openJsonEditor(const QString& filename)
|
||||||
{
|
{
|
||||||
const QString file = QDir::current().absoluteFilePath(filename);
|
const QString file = QDir::current().absoluteFilePath(filename);
|
||||||
@ -1571,7 +1586,7 @@ QString Application::getJarPath(QString jarFile)
|
|||||||
{
|
{
|
||||||
QStringList potentialPaths = {
|
QStringList potentialPaths = {
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
||||||
FS::PathCombine(m_rootPath, "share/" + BuildConfig.LAUNCHER_APP_BINARY_NAME),
|
FS::PathCombine(m_rootPath, "share", BuildConfig.LAUNCHER_NAME),
|
||||||
#endif
|
#endif
|
||||||
FS::PathCombine(m_rootPath, "jars"),
|
FS::PathCombine(m_rootPath, "jars"),
|
||||||
FS::PathCombine(applicationDirPath(), "jars"),
|
FS::PathCombine(applicationDirPath(), "jars"),
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -48,6 +48,7 @@
|
|||||||
#include <BaseInstance.h>
|
#include <BaseInstance.h>
|
||||||
|
|
||||||
#include "minecraft/launch/MinecraftServerTarget.h"
|
#include "minecraft/launch/MinecraftServerTarget.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
|
|
||||||
class LaunchController;
|
class LaunchController;
|
||||||
class LocalPeer;
|
class LocalPeer;
|
||||||
@ -126,9 +127,11 @@ public:
|
|||||||
|
|
||||||
void setApplicationTheme(const QString& name);
|
void setApplicationTheme(const QString& name);
|
||||||
|
|
||||||
shared_qobject_ptr<ExternalUpdater> updater() {
|
QList<CatPack*> getValidCatPacks();
|
||||||
return m_updater;
|
|
||||||
}
|
QString getCatPack(QString catName = "");
|
||||||
|
|
||||||
|
shared_qobject_ptr<ExternalUpdater> updater() { return m_updater; }
|
||||||
|
|
||||||
void triggerUpdateCheck();
|
void triggerUpdateCheck();
|
||||||
|
|
||||||
|
@ -15,15 +15,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <QString>
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* An abstract base class for versions.
|
* An abstract base class for versions.
|
||||||
*/
|
*/
|
||||||
class BaseVersion
|
class BaseVersion {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<BaseVersion>;
|
using Ptr = std::shared_ptr<BaseVersion>;
|
||||||
virtual ~BaseVersion() {}
|
virtual ~BaseVersion() {}
|
||||||
@ -45,14 +44,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual QString typeString() const = 0;
|
virtual QString typeString() const = 0;
|
||||||
|
|
||||||
virtual bool operator<(BaseVersion &a)
|
virtual bool operator<(BaseVersion& a) { return name() < a.name(); };
|
||||||
{
|
virtual bool operator>(BaseVersion& a) { return name() > a.name(); };
|
||||||
return name() < a.name();
|
|
||||||
};
|
|
||||||
virtual bool operator>(BaseVersion &a)
|
|
||||||
{
|
|
||||||
return name() > a.name();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BaseVersion::Ptr)
|
Q_DECLARE_METATYPE(BaseVersion::Ptr)
|
||||||
|
@ -487,6 +487,9 @@ set(API_SOURCES
|
|||||||
modplatform/helpers/HashUtils.cpp
|
modplatform/helpers/HashUtils.cpp
|
||||||
modplatform/helpers/OverrideUtils.h
|
modplatform/helpers/OverrideUtils.h
|
||||||
modplatform/helpers/OverrideUtils.cpp
|
modplatform/helpers/OverrideUtils.cpp
|
||||||
|
|
||||||
|
modplatform/helpers/ExportToModList.h
|
||||||
|
modplatform/helpers/ExportToModList.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FTB_SOURCES
|
set(FTB_SOURCES
|
||||||
@ -758,6 +761,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/themes/SystemTheme.h
|
ui/themes/SystemTheme.h
|
||||||
ui/themes/ThemeManager.cpp
|
ui/themes/ThemeManager.cpp
|
||||||
ui/themes/ThemeManager.h
|
ui/themes/ThemeManager.h
|
||||||
|
ui/themes/CatPack.cpp
|
||||||
|
ui/themes/CatPack.h
|
||||||
|
|
||||||
# Processes
|
# Processes
|
||||||
LaunchController.h
|
LaunchController.h
|
||||||
@ -913,6 +918,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/dialogs/ExportInstanceDialog.h
|
ui/dialogs/ExportInstanceDialog.h
|
||||||
ui/dialogs/ExportPackDialog.cpp
|
ui/dialogs/ExportPackDialog.cpp
|
||||||
ui/dialogs/ExportPackDialog.h
|
ui/dialogs/ExportPackDialog.h
|
||||||
|
ui/dialogs/ExportToModListDialog.cpp
|
||||||
|
ui/dialogs/ExportToModListDialog.h
|
||||||
ui/dialogs/IconPickerDialog.cpp
|
ui/dialogs/IconPickerDialog.cpp
|
||||||
ui/dialogs/IconPickerDialog.h
|
ui/dialogs/IconPickerDialog.h
|
||||||
ui/dialogs/ImportResourceDialog.cpp
|
ui/dialogs/ImportResourceDialog.cpp
|
||||||
@ -1063,6 +1070,7 @@ qt_wrap_ui(LAUNCHER_UI
|
|||||||
ui/dialogs/SkinUploadDialog.ui
|
ui/dialogs/SkinUploadDialog.ui
|
||||||
ui/dialogs/ExportInstanceDialog.ui
|
ui/dialogs/ExportInstanceDialog.ui
|
||||||
ui/dialogs/ExportPackDialog.ui
|
ui/dialogs/ExportPackDialog.ui
|
||||||
|
ui/dialogs/ExportToModListDialog.ui
|
||||||
ui/dialogs/IconPickerDialog.ui
|
ui/dialogs/IconPickerDialog.ui
|
||||||
ui/dialogs/ImportResourceDialog.ui
|
ui/dialogs/ImportResourceDialog.ui
|
||||||
ui/dialogs/MSALoginDialog.ui
|
ui/dialogs/MSALoginDialog.ui
|
||||||
|
@ -390,7 +390,10 @@ void LaunchController::launchInstance()
|
|||||||
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));
|
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));
|
||||||
|
|
||||||
// Prepend Version
|
// Prepend Version
|
||||||
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), BuildConfig.LAUNCHER_DISPLAYNAME + " version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::Launcher));
|
{
|
||||||
|
auto versionString = QString("%1 version: %2 (%3)").arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString(), BuildConfig.BUILD_PLATFORM);
|
||||||
|
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), versionString + "\n\n", MessageLevel::Launcher));
|
||||||
|
}
|
||||||
m_launcher->start();
|
m_launcher->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -33,56 +34,50 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "MMCZip.h"
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
#include <quazip/quazipfile.h>
|
#include <quazip/quazipfile.h>
|
||||||
#include "MMCZip.h"
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
|
namespace MMCZip {
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, const FilterFunction filter)
|
bool mergeZipFiles(QuaZip* into, QFileInfo from, QSet<QString>& contained, const FilterFunction filter)
|
||||||
{
|
{
|
||||||
QuaZip modZip(from.filePath());
|
QuaZip modZip(from.filePath());
|
||||||
modZip.open(QuaZip::mdUnzip);
|
modZip.open(QuaZip::mdUnzip);
|
||||||
|
|
||||||
QuaZipFile fileInsideMod(&modZip);
|
QuaZipFile fileInsideMod(&modZip);
|
||||||
QuaZipFile zipOutFile(into);
|
QuaZipFile zipOutFile(into);
|
||||||
for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
|
for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile()) {
|
||||||
{
|
|
||||||
QString filename = modZip.getCurrentFileName();
|
QString filename = modZip.getCurrentFileName();
|
||||||
if (filter && !filter(filename))
|
if (filter && !filter(filename)) {
|
||||||
{
|
qDebug() << "Skipping file " << filename << " from " << from.fileName() << " - filtered";
|
||||||
qDebug() << "Skipping file " << filename << " from "
|
|
||||||
<< from.fileName() << " - filtered";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (contained.contains(filename))
|
if (contained.contains(filename)) {
|
||||||
{
|
qDebug() << "Skipping already contained file " << filename << " from " << from.fileName();
|
||||||
qDebug() << "Skipping already contained file " << filename << " from "
|
|
||||||
<< from.fileName();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
contained.insert(filename);
|
contained.insert(filename);
|
||||||
|
|
||||||
if (!fileInsideMod.open(QIODevice::ReadOnly))
|
if (!fileInsideMod.open(QIODevice::ReadOnly)) {
|
||||||
{
|
|
||||||
qCritical() << "Failed to open " << filename << " from " << from.fileName();
|
qCritical() << "Failed to open " << filename << " from " << from.fileName();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
|
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
|
||||||
|
|
||||||
if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
|
if (!zipOutFile.open(QIODevice::WriteOnly, info_out)) {
|
||||||
{
|
|
||||||
qCritical() << "Failed to open " << filename << " in the jar";
|
qCritical() << "Failed to open " << filename << " in the jar";
|
||||||
fileInsideMod.close();
|
fileInsideMod.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!JlCompress::copyData(fileInsideMod, zipOutFile))
|
if (!JlCompress::copyData(fileInsideMod, zipOutFile)) {
|
||||||
{
|
|
||||||
zipOutFile.close();
|
zipOutFile.close();
|
||||||
fileInsideMod.close();
|
fileInsideMod.close();
|
||||||
qCritical() << "Failed to copy data of " << filename << " into the jar";
|
qCritical() << "Failed to copy data of " << filename << " into the jar";
|
||||||
@ -94,10 +89,11 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files, bool followSymlinks)
|
bool compressDirFiles(QuaZip* zip, QString dir, QFileInfoList files, bool followSymlinks)
|
||||||
{
|
{
|
||||||
QDir directory(dir);
|
QDir directory(dir);
|
||||||
if (!directory.exists()) return false;
|
if (!directory.exists())
|
||||||
|
return false;
|
||||||
|
|
||||||
for (auto e : files) {
|
for (auto e : files) {
|
||||||
auto filePath = directory.relativeFilePath(e.absoluteFilePath());
|
auto filePath = directory.relativeFilePath(e.absoluteFilePath());
|
||||||
@ -109,13 +105,14 @@ bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files, boo
|
|||||||
srcPath = e.canonicalFilePath();
|
srcPath = e.canonicalFilePath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !JlCompress::compressFile(zip, srcPath, filePath)) return false;
|
if (!JlCompress::compressFile(zip, srcPath, filePath))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files, bool followSymlinks)
|
bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files, bool followSymlinks)
|
||||||
{
|
{
|
||||||
QuaZip zip(fileCompressed);
|
QuaZip zip(fileCompressed);
|
||||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||||
@ -136,11 +133,10 @@ bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods)
|
bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods)
|
||||||
{
|
{
|
||||||
QuaZip zipOut(targetJarPath);
|
QuaZip zipOut(targetJarPath);
|
||||||
if (!zipOut.open(QuaZip::mdCreate))
|
if (!zipOut.open(QuaZip::mdCreate)) {
|
||||||
{
|
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to open the minecraft.jar for modding";
|
qCritical() << "Failed to open the minecraft.jar for modding";
|
||||||
return false;
|
return false;
|
||||||
@ -151,37 +147,29 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
|
|
||||||
// Modify the jar
|
// Modify the jar
|
||||||
// This needs to be done in reverse-order to ensure we respect the loading order of components
|
// This needs to be done in reverse-order to ensure we respect the loading order of components
|
||||||
for (auto i = mods.crbegin(); i != mods.crend(); i++)
|
for (auto i = mods.crbegin(); i != mods.crend(); i++) {
|
||||||
{
|
|
||||||
const auto* mod = *i;
|
const auto* mod = *i;
|
||||||
// do not merge disabled mods.
|
// do not merge disabled mods.
|
||||||
if (!mod->enabled())
|
if (!mod->enabled())
|
||||||
continue;
|
continue;
|
||||||
if (mod->type() == ResourceType::ZIPFILE)
|
if (mod->type() == ResourceType::ZIPFILE) {
|
||||||
{
|
if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles)) {
|
||||||
if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles))
|
|
||||||
{
|
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (mod->type() == ResourceType::SINGLEFILE) {
|
||||||
else if (mod->type() == ResourceType::SINGLEFILE)
|
|
||||||
{
|
|
||||||
// FIXME: buggy - does not work with addedFiles
|
// FIXME: buggy - does not work with addedFiles
|
||||||
auto filename = mod->fileinfo();
|
auto filename = mod->fileinfo();
|
||||||
if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
|
if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) {
|
||||||
{
|
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
addedFiles.insert(filename.fileName());
|
addedFiles.insert(filename.fileName());
|
||||||
}
|
} else if (mod->type() == ResourceType::FOLDER) {
|
||||||
else if (mod->type() == ResourceType::FOLDER)
|
|
||||||
{
|
|
||||||
// untested, but seems to be unused / not possible to reach
|
// untested, but seems to be unused / not possible to reach
|
||||||
// FIXME: buggy - does not work with addedFiles
|
// FIXME: buggy - does not work with addedFiles
|
||||||
auto filename = mod->fileinfo();
|
auto filename = mod->fileinfo();
|
||||||
@ -190,25 +178,21 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
dir.cdUp();
|
dir.cdUp();
|
||||||
QString parent_dir = dir.absolutePath();
|
QString parent_dir = dir.absolutePath();
|
||||||
auto files = QFileInfoList();
|
auto files = QFileInfoList();
|
||||||
MMCZip::collectFileListRecursively(what_to_zip, nullptr, &files, nullptr);
|
collectFileListRecursively(what_to_zip, nullptr, &files, nullptr);
|
||||||
|
|
||||||
for (auto e : files) {
|
for (auto e : files) {
|
||||||
if (addedFiles.contains(e.filePath()))
|
if (addedFiles.contains(e.filePath()))
|
||||||
files.removeAll(e);
|
files.removeAll(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MMCZip::compressDirFiles(&zipOut, parent_dir, files))
|
if (!compressDirFiles(&zipOut, parent_dir, files)) {
|
||||||
{
|
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug() << "Adding folder " << filename.fileName() << " from "
|
qDebug() << "Adding folder " << filename.fileName() << " from " << filename.absoluteFilePath();
|
||||||
<< filename.absoluteFilePath();
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Make sure we do not continue launching when something is missing or undefined...
|
// Make sure we do not continue launching when something is missing or undefined...
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
@ -217,8 +201,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key){return !key.contains("META-INF");}))
|
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key) { return !key.contains("META-INF"); })) {
|
||||||
{
|
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to insert minecraft.jar contents.";
|
qCritical() << "Failed to insert minecraft.jar contents.";
|
||||||
@ -227,8 +210,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
|
|
||||||
// Recompress the jar
|
// Recompress the jar
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
if (zipOut.getZipError() != 0)
|
if (zipOut.getZipError() != 0) {
|
||||||
{
|
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
qCritical() << "Failed to finalize minecraft.jar!";
|
qCritical() << "Failed to finalize minecraft.jar!";
|
||||||
return false;
|
return false;
|
||||||
@ -237,7 +219,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
QString MMCZip::findFolderOfFileInZip(QuaZip* zip, const QString& what, const QStringList& ignore_paths, const QString& root)
|
QString findFolderOfFileInZip(QuaZip* zip, const QString& what, const QStringList& ignore_paths, const QString& root)
|
||||||
{
|
{
|
||||||
QuaZipDir rootDir(zip, root);
|
QuaZipDir rootDir(zip, root);
|
||||||
for (auto&& fileName : rootDir.entryList(QDir::Files)) {
|
for (auto&& fileName : rootDir.entryList(QDir::Files)) {
|
||||||
@ -261,27 +243,23 @@ QString MMCZip::findFolderOfFileInZip(QuaZip* zip, const QString& what, const QS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root)
|
bool findFilesInZip(QuaZip* zip, const QString& what, QStringList& result, const QString& root)
|
||||||
{
|
{
|
||||||
QuaZipDir rootDir(zip, root);
|
QuaZipDir rootDir(zip, root);
|
||||||
for(auto fileName: rootDir.entryList(QDir::Files))
|
for (auto fileName : rootDir.entryList(QDir::Files)) {
|
||||||
{
|
if (fileName == what) {
|
||||||
if(fileName == what)
|
|
||||||
{
|
|
||||||
result.append(root);
|
result.append(root);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(auto fileName: rootDir.entryList(QDir::Dirs))
|
for (auto fileName : rootDir.entryList(QDir::Dirs)) {
|
||||||
{
|
|
||||||
findFilesInZip(zip, what, result, root + fileName);
|
findFilesInZip(zip, what, result, root + fileName);
|
||||||
}
|
}
|
||||||
return !result.isEmpty();
|
return !result.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
|
std::optional<QStringList> extractSubDir(QuaZip* zip, const QString& subdir, const QString& target)
|
||||||
{
|
{
|
||||||
auto target_top_dir = QUrl::fromLocalFile(target);
|
auto target_top_dir = QUrl::fromLocalFile(target);
|
||||||
|
|
||||||
@ -292,13 +270,10 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
|
|||||||
if (numEntries < 0) {
|
if (numEntries < 0) {
|
||||||
qWarning() << "Failed to enumerate files in archive";
|
qWarning() << "Failed to enumerate files in archive";
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
} else if (numEntries == 0) {
|
||||||
else if(numEntries == 0) {
|
|
||||||
qDebug() << "Extracting empty archives seems odd...";
|
qDebug() << "Extracting empty archives seems odd...";
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
} else if (!zip->goToFirstFile()) {
|
||||||
else if (!zip->goToFirstFile())
|
|
||||||
{
|
|
||||||
qWarning() << "Failed to seek to first file in zip";
|
qWarning() << "Failed to seek to first file in zip";
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -334,7 +309,8 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!target_top_dir.isParentOf(QUrl::fromLocalFile(target_file_path))) {
|
if (!target_top_dir.isParentOf(QUrl::fromLocalFile(target_file_path))) {
|
||||||
qWarning() << "Extracting" << relative_file_name << "was cancelled, because it was effectively outside of the target path" << target;
|
qWarning() << "Extracting" << relative_file_name << "was cancelled, because it was effectively outside of the target path"
|
||||||
|
<< target;
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +321,8 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
|
|||||||
}
|
}
|
||||||
|
|
||||||
extracted.append(target_file_path);
|
extracted.append(target_file_path);
|
||||||
QFile::setPermissions(target_file_path, QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser);
|
QFile::setPermissions(target_file_path,
|
||||||
|
QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser);
|
||||||
|
|
||||||
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
||||||
} while (zip->goToNextFile());
|
} while (zip->goToNextFile());
|
||||||
@ -354,51 +331,50 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::extractRelFile(QuaZip *zip, const QString &file, const QString &target)
|
bool extractRelFile(QuaZip* zip, const QString& file, const QString& target)
|
||||||
{
|
{
|
||||||
return JlCompress::extractFile(zip, file, target);
|
return JlCompress::extractFile(zip, file, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
std::optional<QStringList> MMCZip::extractDir(QString fileCompressed, QString dir)
|
std::optional<QStringList> extractDir(QString fileCompressed, QString dir)
|
||||||
{
|
{
|
||||||
QuaZip zip(fileCompressed);
|
QuaZip zip(fileCompressed);
|
||||||
if (!zip.open(QuaZip::mdUnzip))
|
if (!zip.open(QuaZip::mdUnzip)) {
|
||||||
{
|
|
||||||
// check if this is a minimum size empty zip file...
|
// check if this is a minimum size empty zip file...
|
||||||
QFileInfo fileInfo(fileCompressed);
|
QFileInfo fileInfo(fileCompressed);
|
||||||
if (fileInfo.size() == 22) {
|
if (fileInfo.size() == 22) {
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();;
|
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
|
||||||
|
;
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return MMCZip::extractSubDir(&zip, "", dir);
|
return extractSubDir(&zip, "", dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
std::optional<QStringList> MMCZip::extractDir(QString fileCompressed, QString subdir, QString dir)
|
std::optional<QStringList> extractDir(QString fileCompressed, QString subdir, QString dir)
|
||||||
{
|
{
|
||||||
QuaZip zip(fileCompressed);
|
QuaZip zip(fileCompressed);
|
||||||
if (!zip.open(QuaZip::mdUnzip))
|
if (!zip.open(QuaZip::mdUnzip)) {
|
||||||
{
|
|
||||||
// check if this is a minimum size empty zip file...
|
// check if this is a minimum size empty zip file...
|
||||||
QFileInfo fileInfo(fileCompressed);
|
QFileInfo fileInfo(fileCompressed);
|
||||||
if (fileInfo.size() == 22) {
|
if (fileInfo.size() == 22) {
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();;
|
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
|
||||||
|
;
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return MMCZip::extractSubDir(&zip, subdir, dir);
|
return extractSubDir(&zip, subdir, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::extractFile(QString fileCompressed, QString file, QString target)
|
bool extractFile(QString fileCompressed, QString file, QString target)
|
||||||
{
|
{
|
||||||
QuaZip zip(fileCompressed);
|
QuaZip zip(fileCompressed);
|
||||||
if (!zip.open(QuaZip::mdUnzip))
|
if (!zip.open(QuaZip::mdUnzip)) {
|
||||||
{
|
|
||||||
// check if this is a minimum size empty zip file...
|
// check if this is a minimum size empty zip file...
|
||||||
QFileInfo fileInfo(fileCompressed);
|
QFileInfo fileInfo(fileCompressed);
|
||||||
if (fileInfo.size() == 22) {
|
if (fileInfo.size() == 22) {
|
||||||
@ -407,13 +383,14 @@ bool MMCZip::extractFile(QString fileCompressed, QString file, QString target)
|
|||||||
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
|
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return MMCZip::extractRelFile(&zip, file, target);
|
return extractRelFile(&zip, file, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList *files,
|
bool collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList* files, FilterFunction excludeFilter)
|
||||||
MMCZip::FilterFunction excludeFilter) {
|
{
|
||||||
QDir rootDirectory(rootDir);
|
QDir rootDirectory(rootDir);
|
||||||
if (!rootDirectory.exists()) return false;
|
if (!rootDirectory.exists())
|
||||||
|
return false;
|
||||||
|
|
||||||
QDir directory;
|
QDir directory;
|
||||||
if (subDir == nullptr)
|
if (subDir == nullptr)
|
||||||
@ -421,7 +398,8 @@ bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& s
|
|||||||
else
|
else
|
||||||
directory = QDir(subDir);
|
directory = QDir(subDir);
|
||||||
|
|
||||||
if (!directory.exists()) return false; // shouldn't ever happen
|
if (!directory.exists())
|
||||||
|
return false; // shouldn't ever happen
|
||||||
|
|
||||||
// recurse directories
|
// recurse directories
|
||||||
QFileInfoList entries = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);
|
QFileInfoList entries = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);
|
||||||
@ -439,7 +417,88 @@ bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
files->append(e); // we want the original paths for MMCZip::compressDirFiles
|
files->append(e); // we want the original paths for compressDirFiles
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExportToZipTask::executeTask()
|
||||||
|
{
|
||||||
|
setStatus("Adding files...");
|
||||||
|
setProgress(0, m_files.length());
|
||||||
|
m_build_zip_future = QtConcurrent::run(QThreadPool::globalInstance(), [this]() { return exportZip(); });
|
||||||
|
connect(&m_build_zip_watcher, &QFutureWatcher<ZipResult>::finished, this, &ExportToZipTask::finish);
|
||||||
|
m_build_zip_watcher.setFuture(m_build_zip_future);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ExportToZipTask::exportZip() -> ZipResult
|
||||||
|
{
|
||||||
|
if (!m_dir.exists()) {
|
||||||
|
return ZipResult(tr("Folder doesn't exist"));
|
||||||
|
}
|
||||||
|
if (!m_output.isOpen() && !m_output.open(QuaZip::mdCreate)) {
|
||||||
|
return ZipResult(tr("Could not create file"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto fileName : m_extra_files.keys()) {
|
||||||
|
if (m_build_zip_future.isCanceled())
|
||||||
|
return ZipResult();
|
||||||
|
QuaZipFile indexFile(&m_output);
|
||||||
|
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileName))) {
|
||||||
|
return ZipResult(tr("Could not create:") + fileName);
|
||||||
|
}
|
||||||
|
indexFile.write(m_extra_files[fileName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QFileInfo& file : m_files) {
|
||||||
|
if (m_build_zip_future.isCanceled())
|
||||||
|
return ZipResult();
|
||||||
|
|
||||||
|
auto absolute = file.absoluteFilePath();
|
||||||
|
auto relative = m_dir.relativeFilePath(absolute);
|
||||||
|
setStatus("Compresing: " + relative);
|
||||||
|
setProgress(m_progress + 1, m_progressTotal);
|
||||||
|
if (m_follow_symlinks) {
|
||||||
|
if (file.isSymLink())
|
||||||
|
absolute = file.symLinkTarget();
|
||||||
|
else
|
||||||
|
absolute = file.canonicalFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_exclude_files.contains(relative) && !JlCompress::compressFile(&m_output, absolute, m_destination_prefix + relative)) {
|
||||||
|
return ZipResult(tr("Could not read and compress %1").arg(relative));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_output.close();
|
||||||
|
if (m_output.getZipError() != 0) {
|
||||||
|
return ZipResult(tr("A zip error occurred"));
|
||||||
|
}
|
||||||
|
return ZipResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportToZipTask::finish()
|
||||||
|
{
|
||||||
|
if (m_build_zip_future.isCanceled()) {
|
||||||
|
QFile::remove(m_output_path);
|
||||||
|
emitAborted();
|
||||||
|
} else if (auto result = m_build_zip_future.result(); result.has_value()) {
|
||||||
|
QFile::remove(m_output_path);
|
||||||
|
emitFailed(result.value());
|
||||||
|
} else {
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExportToZipTask::abort()
|
||||||
|
{
|
||||||
|
if (m_build_zip_future.isRunning()) {
|
||||||
|
m_build_zip_future.cancel();
|
||||||
|
// NOTE: Here we don't do `emitAborted()` because it will be done when `m_build_zip_future` actually cancels, which may not occur
|
||||||
|
// immediately.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace MMCZip
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -35,24 +36,28 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <quazip.h>
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QSet>
|
|
||||||
#include "minecraft/mod/Mod.h"
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include <quazip/JlCompress.h>
|
#include <quazip/JlCompress.h>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QSet>
|
||||||
|
#include <QString>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include "minecraft/mod/Mod.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
namespace MMCZip
|
namespace MMCZip {
|
||||||
{
|
|
||||||
using FilterFunction = std::function<bool(const QString&)>;
|
using FilterFunction = std::function<bool(const QString&)>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge two zip files, using a filter function
|
* Merge two zip files, using a filter function
|
||||||
*/
|
*/
|
||||||
bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
|
bool mergeZipFiles(QuaZip* into, QFileInfo from, QSet<QString>& contained, const FilterFunction filter = nullptr);
|
||||||
const FilterFunction filter = nullptr);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress directory, by providing a list of files to compress
|
* Compress directory, by providing a list of files to compress
|
||||||
@ -141,4 +146,47 @@ namespace MMCZip
|
|||||||
* \return true for success or false for failure
|
* \return true for success or false for failure
|
||||||
*/
|
*/
|
||||||
bool collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList* files, FilterFunction excludeFilter);
|
bool collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList* files, FilterFunction excludeFilter);
|
||||||
}
|
|
||||||
|
class ExportToZipTask : public Task {
|
||||||
|
public:
|
||||||
|
ExportToZipTask(QString outputPath, QDir dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false)
|
||||||
|
: m_output_path(outputPath)
|
||||||
|
, m_output(outputPath)
|
||||||
|
, m_dir(dir)
|
||||||
|
, m_files(files)
|
||||||
|
, m_destination_prefix(destinationPrefix)
|
||||||
|
, m_follow_symlinks(followSymlinks)
|
||||||
|
{
|
||||||
|
setAbortable(true);
|
||||||
|
};
|
||||||
|
ExportToZipTask(QString outputPath, QString dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false)
|
||||||
|
: ExportToZipTask(outputPath, QDir(dir), files, destinationPrefix, followSymlinks){};
|
||||||
|
|
||||||
|
virtual ~ExportToZipTask() = default;
|
||||||
|
|
||||||
|
void setExcludeFiles(QStringList excludeFiles) { m_exclude_files = excludeFiles; }
|
||||||
|
void addExtraFile(QString fileName, QByteArray data) { m_extra_files.insert(fileName, data); }
|
||||||
|
|
||||||
|
typedef std::optional<QString> ZipResult;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void executeTask() override;
|
||||||
|
bool abort() override;
|
||||||
|
|
||||||
|
ZipResult exportZip();
|
||||||
|
void finish();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_output_path;
|
||||||
|
QuaZip m_output;
|
||||||
|
QDir m_dir;
|
||||||
|
QFileInfoList m_files;
|
||||||
|
QString m_destination_prefix;
|
||||||
|
bool m_follow_symlinks;
|
||||||
|
QStringList m_exclude_files;
|
||||||
|
QHash<QString, QByteArray> m_extra_files;
|
||||||
|
|
||||||
|
QFuture<ZipResult> m_build_zip_future;
|
||||||
|
QFutureWatcher<ZipResult> m_build_zip_watcher;
|
||||||
|
};
|
||||||
|
} // namespace MMCZip
|
||||||
|
@ -1,5 +1,24 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "JavaInstall.h"
|
#include "JavaInstall.h"
|
||||||
|
|
||||||
|
#include "BaseVersion.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
bool JavaInstall::operator<(const JavaInstall& rhs)
|
bool JavaInstall::operator<(const JavaInstall& rhs)
|
||||||
@ -7,12 +26,10 @@ bool JavaInstall::operator<(const JavaInstall &rhs)
|
|||||||
auto archCompare = StringUtils::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
|
auto archCompare = StringUtils::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
|
||||||
if (archCompare != 0)
|
if (archCompare != 0)
|
||||||
return archCompare < 0;
|
return archCompare < 0;
|
||||||
if(id < rhs.id)
|
if (id < rhs.id) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(id > rhs.id)
|
if (id > rhs.id) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return StringUtils::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
return StringUtils::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
||||||
@ -27,3 +44,21 @@ bool JavaInstall::operator>(const JavaInstall &rhs)
|
|||||||
{
|
{
|
||||||
return (!operator<(rhs)) && (!operator==(rhs));
|
return (!operator<(rhs)) && (!operator==(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JavaInstall::operator<(BaseVersion& a)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return operator<(dynamic_cast<JavaInstall&>(a));
|
||||||
|
} catch (const std::bad_cast& e) {
|
||||||
|
return BaseVersion::operator<(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JavaInstall::operator>(BaseVersion& a)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return operator>(dynamic_cast<JavaInstall&>(a));
|
||||||
|
} catch (const std::bad_cast& e) {
|
||||||
|
return BaseVersion::operator>(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,30 +1,37 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "JavaVersion.h"
|
#include "JavaVersion.h"
|
||||||
|
|
||||||
struct JavaInstall : public BaseVersion
|
struct JavaInstall : public BaseVersion {
|
||||||
{
|
|
||||||
JavaInstall() {}
|
JavaInstall() {}
|
||||||
JavaInstall(QString id, QString arch, QString path)
|
JavaInstall(QString id, QString arch, QString path) : id(id), arch(arch), path(path) {}
|
||||||
: id(id), arch(arch), path(path)
|
virtual QString descriptor() { return id.toString(); }
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual QString descriptor()
|
|
||||||
{
|
|
||||||
return id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual QString name()
|
virtual QString name() { return id.toString(); }
|
||||||
{
|
|
||||||
return id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual QString typeString() const
|
virtual QString typeString() const { return arch; }
|
||||||
{
|
|
||||||
return arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
virtual bool operator<(BaseVersion& a) override;
|
||||||
|
virtual bool operator>(BaseVersion& a) override;
|
||||||
bool operator<(const JavaInstall& rhs);
|
bool operator<(const JavaInstall& rhs);
|
||||||
bool operator==(const JavaInstall& rhs);
|
bool operator==(const JavaInstall& rhs);
|
||||||
bool operator>(const JavaInstall& rhs);
|
bool operator>(const JavaInstall& rhs);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
|
* Copyright (c) 2023 seth <getchoo at tuta dot io>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -190,6 +191,10 @@ void MinecraftInstance::loadSpecificSettings()
|
|||||||
m_settings->registerSetting("OverrideEnv", false);
|
m_settings->registerSetting("OverrideEnv", false);
|
||||||
m_settings->registerSetting("Env", QVariant(QMap<QString, QVariant>()));
|
m_settings->registerSetting("Env", QVariant(QMap<QString, QVariant>()));
|
||||||
|
|
||||||
|
// Mod loader specific options
|
||||||
|
auto modLoaderSettings = m_settings->registerSetting("OverrideModLoaderSettings", false);
|
||||||
|
m_settings->registerOverride(global_settings->getSetting("DisableQuiltBeacon"), modLoaderSettings);
|
||||||
|
|
||||||
m_settings->set("InstanceType", "OneSix");
|
m_settings->set("InstanceType", "OneSix");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,6 +400,12 @@ QStringList MinecraftInstance::extraArguments()
|
|||||||
agent->library()->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
|
agent->library()->getApplicableFiles(runtimeContext(), jar, temp1, temp2, temp3, getLocalLibraryPath());
|
||||||
list.append("-javaagent:"+jar[0]+(agent->argument().isEmpty() ? "" : "="+agent->argument()));
|
list.append("-javaagent:"+jar[0]+(agent->argument().isEmpty() ? "" : "="+agent->argument()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto loaders = version->getModLoaders();
|
||||||
|
if (loaders.has_value() && loaders.value() & ResourceAPI::Quilt && settings()->get("DisableQuiltBeacon").toBool())
|
||||||
|
list.append("-Dloader.disable_beacon=true");
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ bool AuthSession::MakeOffline(QString offline_playername)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
session = "-";
|
session = "-";
|
||||||
|
access_token = "0";
|
||||||
player_name = offline_playername;
|
player_name = offline_playername;
|
||||||
status = PlayableOffline;
|
status = PlayableOffline;
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "MinecraftAccount.h"
|
#include "MinecraftAccount.h"
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
@ -100,7 +101,7 @@ MinecraftAccountPtr MinecraftAccount::createOffline(const QString &username)
|
|||||||
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
||||||
account->data.minecraftEntitlement.ownsMinecraft = true;
|
account->data.minecraftEntitlement.ownsMinecraft = true;
|
||||||
account->data.minecraftEntitlement.canPlayMinecraft = true;
|
account->data.minecraftEntitlement.canPlayMinecraft = true;
|
||||||
account->data.minecraftProfile.id = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegularExpression("[{}-]"));
|
||||||
account->data.minecraftProfile.name = username;
|
account->data.minecraftProfile.name = username;
|
||||||
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
|
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
|
||||||
return account;
|
return account;
|
||||||
@ -334,3 +335,32 @@ void MinecraftAccount::incrementUses()
|
|||||||
qWarning() << "Profile" << data.profileId() << "is now in use.";
|
qWarning() << "Profile" << data.profileId() << "is now in use.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUuid MinecraftAccount::uuidFromUsername(QString username) {
|
||||||
|
auto input = QString("OfflinePlayer:%1").arg(username).toUtf8();
|
||||||
|
|
||||||
|
// basically a reimplementation of Java's UUID#nameUUIDFromBytes
|
||||||
|
QByteArray digest = QCryptographicHash::hash(input, QCryptographicHash::Md5);
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
auto bOr = [](QByteArray& array, int index, char value) {
|
||||||
|
array[index] = array.at(index) | value;
|
||||||
|
};
|
||||||
|
auto bAnd = [](QByteArray& array, int index, char value) {
|
||||||
|
array[index] = array.at(index) & value;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
auto bOr = [](QByteArray& array, qsizetype index, char value) {
|
||||||
|
array[index] |= value;
|
||||||
|
};
|
||||||
|
auto bAnd = [](QByteArray& array, qsizetype index, char value) {
|
||||||
|
array[index] &= value;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
bAnd(digest, 6, (char) 0x0f); // clear version
|
||||||
|
bOr(digest, 6, (char) 0x30); // set to version 3
|
||||||
|
bAnd(digest, 8, (char) 0x3f); // clear variant
|
||||||
|
bOr(digest, 8, (char) 0x80); // set to IETF variant
|
||||||
|
|
||||||
|
return QUuid::fromRfc4122(digest);
|
||||||
|
}
|
||||||
|
@ -98,6 +98,8 @@ public: /* construction */
|
|||||||
static MinecraftAccountPtr loadFromJsonV2(const QJsonObject &json);
|
static MinecraftAccountPtr loadFromJsonV2(const QJsonObject &json);
|
||||||
static MinecraftAccountPtr loadFromJsonV3(const QJsonObject &json);
|
static MinecraftAccountPtr loadFromJsonV3(const QJsonObject &json);
|
||||||
|
|
||||||
|
static QUuid uuidFromUsername(QString username);
|
||||||
|
|
||||||
//! Saves a MinecraftAccount to a JSON object and returns it.
|
//! Saves a MinecraftAccount to a JSON object and returns it.
|
||||||
QJsonObject saveToJson() const;
|
QJsonObject saveToJson() const;
|
||||||
|
|
||||||
|
@ -44,7 +44,11 @@ static const QMap<PackedResourceType, QString> s_packed_type_names = {
|
|||||||
namespace ResourceUtils {
|
namespace ResourceUtils {
|
||||||
PackedResourceType identify(QFileInfo file){
|
PackedResourceType identify(QFileInfo file){
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
if (ResourcePackUtils::validate(file)) {
|
if (ModUtils::validate(file)) {
|
||||||
|
// mods can contain resource and data packs so they must be tested first
|
||||||
|
qDebug() << file.fileName() << "is a mod";
|
||||||
|
return PackedResourceType::Mod;
|
||||||
|
} else if (ResourcePackUtils::validate(file)) {
|
||||||
qDebug() << file.fileName() << "is a resource pack";
|
qDebug() << file.fileName() << "is a resource pack";
|
||||||
return PackedResourceType::ResourcePack;
|
return PackedResourceType::ResourcePack;
|
||||||
} else if (TexturePackUtils::validate(file)) {
|
} else if (TexturePackUtils::validate(file)) {
|
||||||
@ -53,9 +57,6 @@ PackedResourceType identify(QFileInfo file){
|
|||||||
} else if (DataPackUtils::validate(file)) {
|
} else if (DataPackUtils::validate(file)) {
|
||||||
qDebug() << file.fileName() << "is a data pack";
|
qDebug() << file.fileName() << "is a data pack";
|
||||||
return PackedResourceType::DataPack;
|
return PackedResourceType::DataPack;
|
||||||
} else if (ModUtils::validate(file)) {
|
|
||||||
qDebug() << file.fileName() << "is a mod";
|
|
||||||
return PackedResourceType::Mod;
|
|
||||||
} else if (WorldSaveUtils::validate(file)) {
|
} else if (WorldSaveUtils::validate(file)) {
|
||||||
qDebug() << file.fileName() << "is a world save";
|
qDebug() << file.fileName() << "is a world save";
|
||||||
return PackedResourceType::WorldSave;
|
return PackedResourceType::WorldSave;
|
||||||
|
@ -145,7 +145,8 @@ void EnsureMetadataTask::executeTask()
|
|||||||
connect(project_task.get(), &Task::finished, this, [=] {
|
connect(project_task.get(), &Task::finished, this, [=] {
|
||||||
invalidade_leftover();
|
invalidade_leftover();
|
||||||
project_task->deleteLater();
|
project_task->deleteLater();
|
||||||
m_current_task = nullptr;
|
if (m_current_task)
|
||||||
|
m_current_task.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_current_task = project_task;
|
m_current_task = project_task;
|
||||||
@ -154,7 +155,8 @@ void EnsureMetadataTask::executeTask()
|
|||||||
|
|
||||||
connect(version_task.get(), &Task::finished, [=] {
|
connect(version_task.get(), &Task::finished, [=] {
|
||||||
version_task->deleteLater();
|
version_task->deleteLater();
|
||||||
m_current_task = nullptr;
|
if (m_current_task)
|
||||||
|
m_current_task.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (m_mods.size() > 1)
|
if (m_mods.size() > 1)
|
||||||
|
@ -21,6 +21,10 @@ bool Flame::FileResolvingTask::abort()
|
|||||||
|
|
||||||
void Flame::FileResolvingTask::executeTask()
|
void Flame::FileResolvingTask::executeTask()
|
||||||
{
|
{
|
||||||
|
if (m_toProcess.files.isEmpty()) { // no file to resolve so leave it empty and emit success immediately
|
||||||
|
emitSucceeded();
|
||||||
|
return;
|
||||||
|
}
|
||||||
setStatus(tr("Resolving mod IDs..."));
|
setStatus(tr("Resolving mod IDs..."));
|
||||||
setProgress(0, 3);
|
setProgress(0, 3);
|
||||||
m_dljob.reset(new NetJob("Mod id resolver", m_network));
|
m_dljob.reset(new NetJob("Mod id resolver", m_network));
|
||||||
@ -128,7 +132,8 @@ void Flame::FileResolvingTask::netJobFinished()
|
|||||||
m_checkJob->start();
|
m_checkJob->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flame::FileResolvingTask::modrinthCheckFinished() {
|
void Flame::FileResolvingTask::modrinthCheckFinished()
|
||||||
|
{
|
||||||
setProgress(2, 3);
|
setProgress(2, 3);
|
||||||
qDebug() << "Finished with blocked mods : " << blockedProjects.size();
|
qDebug() << "Finished with blocked mods : " << blockedProjects.size();
|
||||||
|
|
||||||
@ -156,9 +161,7 @@ void Flame::FileResolvingTask::modrinthCheckFinished() {
|
|||||||
// copy to an output list and filter out projects found on modrinth
|
// copy to an output list and filter out projects found on modrinth
|
||||||
auto block = std::make_shared<QList<File*>>();
|
auto block = std::make_shared<QList<File*>>();
|
||||||
auto it = blockedProjects.keys();
|
auto it = blockedProjects.keys();
|
||||||
std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File *f) {
|
std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File* f) { return !f->resolved; });
|
||||||
return !f->resolved;
|
|
||||||
});
|
|
||||||
// Display not found mods early
|
// Display not found mods early
|
||||||
if (!block->empty()) {
|
if (!block->empty()) {
|
||||||
// blocked mods found, we need the slug for displaying.... we need another job :D !
|
// blocked mods found, we need the slug for displaying.... we need another job :D !
|
||||||
@ -173,8 +176,8 @@ void Flame::FileResolvingTask::modrinthCheckFinished() {
|
|||||||
QObject::connect(dl.get(), &Net::Download::succeeded, [block, index, output]() {
|
QObject::connect(dl.get(), &Net::Download::succeeded, [block, index, output]() {
|
||||||
auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done
|
auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done
|
||||||
auto json = QJsonDocument::fromJson(*output);
|
auto json = QJsonDocument::fromJson(*output);
|
||||||
auto base = Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json),"data"),"links"),
|
auto base =
|
||||||
"websiteUrl");
|
Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json), "data"), "links"), "websiteUrl");
|
||||||
auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId));
|
auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId));
|
||||||
mod->websiteUrl = link;
|
mod->websiteUrl = link;
|
||||||
});
|
});
|
||||||
|
@ -563,6 +563,8 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
if (FS::move(localPath, destPath)) {
|
if (FS::move(localPath, destPath)) {
|
||||||
return destPath;
|
return destPath;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Target folder of" << fileName << "is correct at" << targetFolder;
|
||||||
}
|
}
|
||||||
return localPath;
|
return localPath;
|
||||||
};
|
};
|
||||||
@ -584,6 +586,9 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
QString worldPath;
|
QString worldPath;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case PackedResourceType::Mod :
|
||||||
|
validatePath(fileName, targetFolder, "mods");
|
||||||
|
break;
|
||||||
case PackedResourceType::ResourcePack :
|
case PackedResourceType::ResourcePack :
|
||||||
validatePath(fileName, targetFolder, "resourcepacks");
|
validatePath(fileName, targetFolder, "resourcepacks");
|
||||||
break;
|
break;
|
||||||
@ -593,9 +598,6 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
case PackedResourceType::DataPack :
|
case PackedResourceType::DataPack :
|
||||||
validatePath(fileName, targetFolder, "datapacks");
|
validatePath(fileName, targetFolder, "datapacks");
|
||||||
break;
|
break;
|
||||||
case PackedResourceType::Mod :
|
|
||||||
validatePath(fileName, targetFolder, "mods");
|
|
||||||
break;
|
|
||||||
case PackedResourceType::ShaderPack :
|
case PackedResourceType::ShaderPack :
|
||||||
// in theroy flame API can't do this but who knows, that *may* change ?
|
// in theroy flame API can't do this but who knows, that *may* change ?
|
||||||
// better to handle it if it *does* occure in the future
|
// better to handle it if it *does* occure in the future
|
||||||
|
@ -76,13 +76,8 @@ bool Flame::File::parseFromObject(const QJsonObject& obj, bool throw_on_blocked
|
|||||||
// It is also optional
|
// It is also optional
|
||||||
type = File::Type::SingleFile;
|
type = File::Type::SingleFile;
|
||||||
|
|
||||||
if (fileName.endsWith(".zip")) {
|
|
||||||
// this is probably a resource pack
|
|
||||||
targetFolder = "resourcepacks";
|
|
||||||
} else {
|
|
||||||
// this is probably a mod, dunno what else could modpacks download
|
|
||||||
targetFolder = "mods";
|
targetFolder = "mods";
|
||||||
}
|
|
||||||
// get the hash
|
// get the hash
|
||||||
hash = QString();
|
hash = QString();
|
||||||
auto hashes = Json::ensureArray(obj, "hashes");
|
auto hashes = Json::ensureArray(obj, "hashes");
|
||||||
|
200
launcher/modplatform/helpers/ExportToModList.cpp
Normal file
200
launcher/modplatform/helpers/ExportToModList.cpp
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "ExportToModList.h"
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
namespace ExportToModList {
|
||||||
|
QString toHTML(QList<Mod*> mods, OptionalData extraData)
|
||||||
|
{
|
||||||
|
QStringList lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name().toHtmlEscaped();
|
||||||
|
if (extraData & Url) {
|
||||||
|
auto url = mod->metaurl().toHtmlEscaped();
|
||||||
|
if (!url.isEmpty())
|
||||||
|
modName = QString("<a href=\"%1\">%2</a>").arg(url, modName);
|
||||||
|
}
|
||||||
|
auto line = modName;
|
||||||
|
if (extraData & Version) {
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
if (!ver.isEmpty())
|
||||||
|
line += QString(" [%1]").arg(ver.toHtmlEscaped());
|
||||||
|
}
|
||||||
|
if (extraData & Authors && !mod->authors().isEmpty())
|
||||||
|
line += " by " + mod->authors().join(", ").toHtmlEscaped();
|
||||||
|
lines.append(QString("<li>%1</li>").arg(line));
|
||||||
|
}
|
||||||
|
return QString("<html><body><ul>\n\t%1\n</ul></body></html>").arg(lines.join("\n\t"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString toMarkdown(QList<Mod*> mods, OptionalData extraData)
|
||||||
|
{
|
||||||
|
QStringList lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name();
|
||||||
|
if (extraData & Url) {
|
||||||
|
auto url = mod->metaurl();
|
||||||
|
if (!url.isEmpty())
|
||||||
|
modName = QString("[%1](%2)").arg(modName, url);
|
||||||
|
}
|
||||||
|
auto line = modName;
|
||||||
|
if (extraData & Version) {
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
if (!ver.isEmpty())
|
||||||
|
line += QString(" [%1]").arg(ver);
|
||||||
|
}
|
||||||
|
if (extraData & Authors && !mod->authors().isEmpty())
|
||||||
|
line += " by " + mod->authors().join(", ");
|
||||||
|
lines << "- " + line;
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString toPlainTXT(QList<Mod*> mods, OptionalData extraData)
|
||||||
|
{
|
||||||
|
QStringList lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name();
|
||||||
|
|
||||||
|
auto line = modName;
|
||||||
|
if (extraData & Url) {
|
||||||
|
auto url = mod->metaurl();
|
||||||
|
if (!url.isEmpty())
|
||||||
|
line += QString(" (%1)").arg(url);
|
||||||
|
}
|
||||||
|
if (extraData & Version) {
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
if (!ver.isEmpty())
|
||||||
|
line += QString(" [%1]").arg(ver);
|
||||||
|
}
|
||||||
|
if (extraData & Authors && !mod->authors().isEmpty())
|
||||||
|
line += " by " + mod->authors().join(", ");
|
||||||
|
lines << line;
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString toJSON(QList<Mod*> mods, OptionalData extraData)
|
||||||
|
{
|
||||||
|
QJsonArray lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name();
|
||||||
|
QJsonObject line;
|
||||||
|
line["name"] = modName;
|
||||||
|
if (extraData & Url) {
|
||||||
|
auto url = mod->metaurl();
|
||||||
|
if (!url.isEmpty())
|
||||||
|
line["url"] = url;
|
||||||
|
}
|
||||||
|
if (extraData & Version) {
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
if (!ver.isEmpty())
|
||||||
|
line["version"] = ver;
|
||||||
|
}
|
||||||
|
if (extraData & Authors && !mod->authors().isEmpty())
|
||||||
|
line["authors"] = QJsonArray::fromStringList(mod->authors());
|
||||||
|
lines << line;
|
||||||
|
}
|
||||||
|
QJsonDocument doc;
|
||||||
|
doc.setArray(lines);
|
||||||
|
return doc.toJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString toCSV(QList<Mod*> mods, OptionalData extraData)
|
||||||
|
{
|
||||||
|
QStringList lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
QStringList data;
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name();
|
||||||
|
|
||||||
|
data << modName;
|
||||||
|
if (extraData & Url)
|
||||||
|
data << mod->metaurl();
|
||||||
|
if (extraData & Version) {
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
data << ver;
|
||||||
|
}
|
||||||
|
if (extraData & Authors) {
|
||||||
|
QString authors;
|
||||||
|
if (mod->authors().length() == 1)
|
||||||
|
authors = mod->authors().back();
|
||||||
|
else if (mod->authors().length() > 1)
|
||||||
|
authors = QString("\"%1\"").arg(mod->authors().join(","));
|
||||||
|
data << authors;
|
||||||
|
}
|
||||||
|
lines << data.join(",");
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString exportToModList(QList<Mod*> mods, Formats format, OptionalData extraData)
|
||||||
|
{
|
||||||
|
switch (format) {
|
||||||
|
case HTML:
|
||||||
|
return toHTML(mods, extraData);
|
||||||
|
case MARKDOWN:
|
||||||
|
return toMarkdown(mods, extraData);
|
||||||
|
case PLAINTXT:
|
||||||
|
return toPlainTXT(mods, extraData);
|
||||||
|
case JSON:
|
||||||
|
return toJSON(mods, extraData);
|
||||||
|
case CSV:
|
||||||
|
return toCSV(mods, extraData);
|
||||||
|
default: {
|
||||||
|
return QString("unknown format:%1").arg(format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString exportToModList(QList<Mod*> mods, QString lineTemplate)
|
||||||
|
{
|
||||||
|
QStringList lines;
|
||||||
|
for (auto mod : mods) {
|
||||||
|
auto meta = mod->metadata();
|
||||||
|
auto modName = mod->name();
|
||||||
|
auto url = mod->metaurl();
|
||||||
|
auto ver = mod->version();
|
||||||
|
if (ver.isEmpty() && meta != nullptr)
|
||||||
|
ver = meta->version().toString();
|
||||||
|
auto authors = mod->authors().join(", ");
|
||||||
|
lines << QString(lineTemplate)
|
||||||
|
.replace("{name}", modName)
|
||||||
|
.replace("{url}", url)
|
||||||
|
.replace("{version}", ver)
|
||||||
|
.replace("{authors}", authors);
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
} // namespace ExportToModList
|
33
launcher/modplatform/helpers/ExportToModList.h
Normal file
33
launcher/modplatform/helpers/ExportToModList.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
#include "minecraft/mod/Mod.h"
|
||||||
|
|
||||||
|
namespace ExportToModList {
|
||||||
|
|
||||||
|
enum Formats { HTML, MARKDOWN, PLAINTXT, JSON, CSV, CUSTOM };
|
||||||
|
enum OptionalData {
|
||||||
|
Authors = 1 << 0,
|
||||||
|
Url = 1 << 1,
|
||||||
|
Version = 1 << 2,
|
||||||
|
};
|
||||||
|
QString exportToModList(QList<Mod*> mods, Formats format, OptionalData extraData);
|
||||||
|
QString exportToModList(QList<Mod*> mods, QString lineTemplate);
|
||||||
|
} // namespace ExportToModList
|
@ -37,16 +37,16 @@
|
|||||||
|
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
#include "MMCZip.h"
|
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "settings/INISettingsObject.h"
|
#include "MMCZip.h"
|
||||||
|
#include "minecraft/GradleSpecifier.h"
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
#include "minecraft/GradleSpecifier.h"
|
#include "settings/INISettingsObject.h"
|
||||||
|
|
||||||
#include "BuildConfig.h"
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "BuildConfig.h"
|
||||||
|
|
||||||
namespace LegacyFTB {
|
namespace LegacyFTB {
|
||||||
|
|
||||||
@ -65,6 +65,7 @@ void PackInstallTask::executeTask()
|
|||||||
void PackInstallTask::downloadPack()
|
void PackInstallTask::downloadPack()
|
||||||
{
|
{
|
||||||
setStatus(tr("Downloading zip for %1").arg(m_pack.name));
|
setStatus(tr("Downloading zip for %1").arg(m_pack.name));
|
||||||
|
setProgress(1, 4);
|
||||||
setAbortable(false);
|
setAbortable(false);
|
||||||
|
|
||||||
archivePath = QString("%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file);
|
archivePath = QString("%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file);
|
||||||
@ -78,11 +79,10 @@ void PackInstallTask::downloadPack()
|
|||||||
}
|
}
|
||||||
netJobContainer->addNetAction(Net::Download::makeFile(url, archivePath));
|
netJobContainer->addNetAction(Net::Download::makeFile(url, archivePath));
|
||||||
|
|
||||||
connect(netJobContainer.get(), &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded);
|
connect(netJobContainer.get(), &NetJob::succeeded, this, &PackInstallTask::unzip);
|
||||||
connect(netJobContainer.get(), &NetJob::failed, this, &PackInstallTask::onDownloadFailed);
|
connect(netJobContainer.get(), &NetJob::failed, this, &PackInstallTask::emitFailed);
|
||||||
connect(netJobContainer.get(), &NetJob::progress, this, &PackInstallTask::onDownloadProgress);
|
|
||||||
connect(netJobContainer.get(), &NetJob::stepProgress, this, &PackInstallTask::propogateStepProgress);
|
connect(netJobContainer.get(), &NetJob::stepProgress, this, &PackInstallTask::propogateStepProgress);
|
||||||
connect(netJobContainer.get(), &NetJob::aborted, this, &PackInstallTask::onDownloadAborted);
|
connect(netJobContainer.get(), &NetJob::aborted, this, &PackInstallTask::emitAborted);
|
||||||
|
|
||||||
netJobContainer->start();
|
netJobContainer->start();
|
||||||
|
|
||||||
@ -90,27 +90,6 @@ void PackInstallTask::downloadPack()
|
|||||||
progress(1, 4);
|
progress(1, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackInstallTask::onDownloadSucceeded()
|
|
||||||
{
|
|
||||||
unzip();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PackInstallTask::onDownloadFailed(QString reason)
|
|
||||||
{
|
|
||||||
emitFailed(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PackInstallTask::onDownloadProgress(qint64 current, qint64 total)
|
|
||||||
{
|
|
||||||
progress(current, total * 4);
|
|
||||||
setStatus(tr("Downloading zip for %1 (%2%)").arg(m_pack.name).arg(current / 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PackInstallTask::onDownloadAborted()
|
|
||||||
{
|
|
||||||
emitAborted();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PackInstallTask::unzip()
|
void PackInstallTask::unzip()
|
||||||
{
|
{
|
||||||
setStatus(tr("Extracting modpack"));
|
setStatus(tr("Extracting modpack"));
|
||||||
@ -120,16 +99,17 @@ void PackInstallTask::unzip()
|
|||||||
QDir extractDir(m_stagingPath);
|
QDir extractDir(m_stagingPath);
|
||||||
|
|
||||||
m_packZip.reset(new QuaZip(archivePath));
|
m_packZip.reset(new QuaZip(archivePath));
|
||||||
if(!m_packZip->open(QuaZip::mdUnzip))
|
if (!m_packZip->open(QuaZip::mdUnzip)) {
|
||||||
{
|
|
||||||
emitFailed(tr("Failed to open modpack file %1!").arg(archivePath));
|
emitFailed(tr("Failed to open modpack file %1!").arg(archivePath));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), QOverload<QString, QString>::of(MMCZip::extractDir), archivePath, extractDir.absolutePath() + "/unzip");
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), QOverload<QString, QString>::of(MMCZip::extractDir), archivePath,
|
||||||
|
extractDir.absolutePath() + "/unzip");
|
||||||
#else
|
#else
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/unzip");
|
m_extractFuture =
|
||||||
|
QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/unzip");
|
||||||
#endif
|
#endif
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onUnzipFinished);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onUnzipFinished);
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &PackInstallTask::onUnzipCanceled);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &PackInstallTask::onUnzipCanceled);
|
||||||
@ -151,11 +131,9 @@ void PackInstallTask::install()
|
|||||||
setStatus(tr("Installing modpack"));
|
setStatus(tr("Installing modpack"));
|
||||||
progress(3, 4);
|
progress(3, 4);
|
||||||
QDir unzipMcDir(m_stagingPath + "/unzip/minecraft");
|
QDir unzipMcDir(m_stagingPath + "/unzip/minecraft");
|
||||||
if(unzipMcDir.exists())
|
if (unzipMcDir.exists()) {
|
||||||
{
|
|
||||||
// ok, found minecraft dir, move contents to instance dir
|
// ok, found minecraft dir, move contents to instance dir
|
||||||
if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft"))
|
if (!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft")) {
|
||||||
{
|
|
||||||
emitFailed(tr("Failed to move unzipped Minecraft!"));
|
emitFailed(tr("Failed to move unzipped Minecraft!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -175,8 +153,7 @@ void PackInstallTask::install()
|
|||||||
// handle different versions
|
// handle different versions
|
||||||
QFile packJson(m_stagingPath + "/.minecraft/pack.json");
|
QFile packJson(m_stagingPath + "/.minecraft/pack.json");
|
||||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||||
if(packJson.exists())
|
if (packJson.exists()) {
|
||||||
{
|
|
||||||
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
|
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||||
packJson.close();
|
packJson.close();
|
||||||
@ -184,11 +161,9 @@ void PackInstallTask::install()
|
|||||||
// we only care about the libs
|
// we only care about the libs
|
||||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||||
|
|
||||||
foreach (const QJsonValue &value, libs)
|
foreach (const QJsonValue& value, libs) {
|
||||||
{
|
|
||||||
QString nameValue = value.toObject().value("name").toString();
|
QString nameValue = value.toObject().value("name").toString();
|
||||||
if(!nameValue.startsWith("net.minecraftforge"))
|
if (!nameValue.startsWith("net.minecraftforge")) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,16 +174,13 @@ void PackInstallTask::install()
|
|||||||
fallback = false;
|
fallback = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(jarmodDir.exists())
|
if (jarmodDir.exists()) {
|
||||||
{
|
|
||||||
qDebug() << "Found jarmods, installing...";
|
qDebug() << "Found jarmods, installing...";
|
||||||
|
|
||||||
QStringList jarmods;
|
QStringList jarmods;
|
||||||
for (auto info: jarmodDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files))
|
for (auto info : jarmodDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files)) {
|
||||||
{
|
|
||||||
qDebug() << "Jarmod:" << info.fileName();
|
qDebug() << "Jarmod:" << info.fileName();
|
||||||
jarmods.push_back(info.absoluteFilePath());
|
jarmods.push_back(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
@ -220,8 +192,7 @@ void PackInstallTask::install()
|
|||||||
// just nuke unzip directory, it s not needed anymore
|
// just nuke unzip directory, it s not needed anymore
|
||||||
FS::deletePath(m_stagingPath + "/unzip");
|
FS::deletePath(m_stagingPath + "/unzip");
|
||||||
|
|
||||||
if(fallback)
|
if (fallback) {
|
||||||
{
|
|
||||||
// TODO: Some fallback mechanism... or just keep failing!
|
// TODO: Some fallback mechanism... or just keep failing!
|
||||||
emitFailed(tr("No installation method found!"));
|
emitFailed(tr("No installation method found!"));
|
||||||
return;
|
return;
|
||||||
@ -232,8 +203,7 @@ void PackInstallTask::install()
|
|||||||
progress(4, 4);
|
progress(4, 4);
|
||||||
|
|
||||||
instance.setName(name());
|
instance.setName(name());
|
||||||
if(m_instIcon == "default")
|
if (m_instIcon == "default") {
|
||||||
{
|
|
||||||
m_instIcon = "ftb_logo";
|
m_instIcon = "ftb_logo";
|
||||||
}
|
}
|
||||||
instance.setIconKey(m_instIcon);
|
instance.setIconKey(m_instIcon);
|
||||||
@ -252,4 +222,4 @@ bool PackInstallTask::abort()
|
|||||||
return InstanceTask::abort();
|
return InstanceTask::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace LegacyFTB
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "InstanceTask.h"
|
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
|
#include "InstanceTask.h"
|
||||||
|
#include "PackHelpers.h"
|
||||||
#include "meta/Index.h"
|
#include "meta/Index.h"
|
||||||
#include "meta/Version.h"
|
#include "meta/Version.h"
|
||||||
#include "meta/VersionList.h"
|
#include "meta/VersionList.h"
|
||||||
#include "PackHelpers.h"
|
#include "net/NetJob.h"
|
||||||
|
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
|
|
||||||
@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
namespace LegacyFTB {
|
namespace LegacyFTB {
|
||||||
|
|
||||||
class PackInstallTask : public InstanceTask
|
class PackInstallTask : public InstanceTask {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -35,10 +34,6 @@ private:
|
|||||||
void install();
|
void install();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDownloadSucceeded();
|
|
||||||
void onDownloadFailed(QString reason);
|
|
||||||
void onDownloadProgress(qint64 current, qint64 total);
|
|
||||||
void onDownloadAborted();
|
|
||||||
|
|
||||||
void onUnzipFinished();
|
void onUnzipFinished();
|
||||||
void onUnzipCanceled();
|
void onUnzipCanceled();
|
||||||
@ -56,4 +51,4 @@ private: /* data */
|
|||||||
QString m_version;
|
QString m_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace LegacyFTB
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
@ -527,34 +528,34 @@ Language * TranslationsModel::findLanguage(const QString& key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
|
||||||
|
{
|
||||||
|
APPLICATION->settings()->set("UseSystemLocale", useSystemLocale);
|
||||||
|
QLocale::setDefault(QLocale(useSystemLocale ? QString::fromStdString(std::locale().name()) : defaultLangCode));
|
||||||
|
}
|
||||||
|
|
||||||
bool TranslationsModel::selectLanguage(QString key)
|
bool TranslationsModel::selectLanguage(QString key)
|
||||||
{
|
{
|
||||||
QString& langCode = key;
|
QString& langCode = key;
|
||||||
auto langPtr = findLanguage(key);
|
auto langPtr = findLanguage(key);
|
||||||
|
|
||||||
if (langCode.isEmpty())
|
if (langCode.isEmpty()) {
|
||||||
{
|
|
||||||
d->no_language_set = true;
|
d->no_language_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!langPtr)
|
if (!langPtr) {
|
||||||
{
|
|
||||||
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
|
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
|
||||||
langCode = defaultLangCode;
|
langCode = defaultLangCode;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
langCode = langPtr->key;
|
langCode = langPtr->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// uninstall existing translators if there are any
|
// uninstall existing translators if there are any
|
||||||
if (d->m_app_translator)
|
if (d->m_app_translator) {
|
||||||
{
|
|
||||||
QCoreApplication::removeTranslator(d->m_app_translator.get());
|
QCoreApplication::removeTranslator(d->m_app_translator.get());
|
||||||
d->m_app_translator.reset();
|
d->m_app_translator.reset();
|
||||||
}
|
}
|
||||||
if (d->m_qt_translator)
|
if (d->m_qt_translator) {
|
||||||
{
|
|
||||||
QCoreApplication::removeTranslator(d->m_qt_translator.get());
|
QCoreApplication::removeTranslator(d->m_qt_translator.get());
|
||||||
d->m_qt_translator.reset();
|
d->m_qt_translator.reset();
|
||||||
}
|
}
|
||||||
@ -564,8 +565,9 @@ bool TranslationsModel::selectLanguage(QString key)
|
|||||||
* In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
|
* In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
|
||||||
* This function is not reentrant.
|
* This function is not reentrant.
|
||||||
*/
|
*/
|
||||||
QLocale locale = QLocale(langCode);
|
QLocale::setDefault(
|
||||||
QLocale::setDefault(locale);
|
QLocale(APPLICATION->settings()->get("UseSystemLocale").toBool() ? QString::fromStdString(std::locale().name()) : langCode));
|
||||||
|
|
||||||
|
|
||||||
// if it's the default UI language, finish
|
// if it's the default UI language, finish
|
||||||
if(langCode == defaultLangCode)
|
if(langCode == defaultLangCode)
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
struct Language;
|
struct Language;
|
||||||
|
|
||||||
class TranslationsModel : public QAbstractListModel
|
class TranslationsModel : public QAbstractListModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TranslationsModel(QString path, QObject* parent = 0);
|
explicit TranslationsModel(QString path, QObject* parent = 0);
|
||||||
@ -38,6 +37,7 @@ public:
|
|||||||
QString selectedLanguage();
|
QString selectedLanguage();
|
||||||
|
|
||||||
void downloadIndex();
|
void downloadIndex();
|
||||||
|
void setUseSystemLocale(bool useSystemLocale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Language* findLanguage(const QString& key);
|
Language* findLanguage(const QString& key);
|
||||||
@ -57,7 +57,6 @@ private slots:
|
|||||||
void dlGood();
|
void dlGood();
|
||||||
void translationDirChanged(const QString& path);
|
void translationDirChanged(const QString& path);
|
||||||
|
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
struct Private;
|
struct Private;
|
||||||
std::unique_ptr<Private> d;
|
std::unique_ptr<Private> d;
|
||||||
|
@ -43,100 +43,98 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "ui/dialogs/ExportToModListDialog.h"
|
||||||
#include "ui_MainWindow.h"
|
#include "ui_MainWindow.h"
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QLabel>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QStatusBar>
|
|
||||||
#include <QToolBar>
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QInputDialog>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QWidgetAction>
|
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QWidgetAction>
|
||||||
|
|
||||||
#include <BaseInstance.h>
|
#include <BaseInstance.h>
|
||||||
#include <InstanceList.h>
|
|
||||||
#include <minecraft/MinecraftInstance.h>
|
|
||||||
#include <MMCZip.h>
|
|
||||||
#include <icons/IconList.h>
|
|
||||||
#include <java/JavaUtils.h>
|
|
||||||
#include <java/JavaInstallList.h>
|
|
||||||
#include <launch/LaunchTask.h>
|
|
||||||
#include <minecraft/auth/AccountList.h>
|
|
||||||
#include <SkinUtils.h>
|
|
||||||
#include <BuildConfig.h>
|
#include <BuildConfig.h>
|
||||||
#include <net/NetJob.h>
|
#include <DesktopServices.h>
|
||||||
|
#include <InstanceList.h>
|
||||||
|
#include <MMCZip.h>
|
||||||
|
#include <SkinUtils.h>
|
||||||
|
#include <icons/IconList.h>
|
||||||
|
#include <java/JavaInstallList.h>
|
||||||
|
#include <java/JavaUtils.h>
|
||||||
|
#include <launch/LaunchTask.h>
|
||||||
|
#include <minecraft/MinecraftInstance.h>
|
||||||
|
#include <minecraft/auth/AccountList.h>
|
||||||
#include <net/Download.h>
|
#include <net/Download.h>
|
||||||
|
#include <net/NetJob.h>
|
||||||
#include <news/NewsChecker.h>
|
#include <news/NewsChecker.h>
|
||||||
#include <tools/BaseProfiler.h>
|
#include <tools/BaseProfiler.h>
|
||||||
#include <updater/ExternalUpdater.h>
|
#include <updater/ExternalUpdater.h>
|
||||||
#include <DesktopServices.h>
|
|
||||||
#include "InstanceWindow.h"
|
|
||||||
#include "InstancePageProvider.h"
|
#include "InstancePageProvider.h"
|
||||||
|
#include "InstanceWindow.h"
|
||||||
#include "JavaCommon.h"
|
#include "JavaCommon.h"
|
||||||
#include "LaunchController.h"
|
#include "LaunchController.h"
|
||||||
|
|
||||||
#include "ui/instanceview/InstanceProxyModel.h"
|
|
||||||
#include "ui/instanceview/InstanceView.h"
|
|
||||||
#include "ui/instanceview/InstanceDelegate.h"
|
|
||||||
#include "ui/widgets/LabeledToolButton.h"
|
|
||||||
#include "ui/dialogs/NewInstanceDialog.h"
|
|
||||||
#include "ui/dialogs/NewsDialog.h"
|
|
||||||
#include "ui/dialogs/ProgressDialog.h"
|
|
||||||
#include "ui/dialogs/AboutDialog.h"
|
#include "ui/dialogs/AboutDialog.h"
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
|
||||||
#include "ui/dialogs/IconPickerDialog.h"
|
|
||||||
#include "ui/dialogs/CopyInstanceDialog.h"
|
#include "ui/dialogs/CopyInstanceDialog.h"
|
||||||
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
#include "ui/dialogs/EditAccountDialog.h"
|
#include "ui/dialogs/EditAccountDialog.h"
|
||||||
#include "ui/dialogs/ExportInstanceDialog.h"
|
#include "ui/dialogs/ExportInstanceDialog.h"
|
||||||
#include "ui/dialogs/ExportPackDialog.h"
|
#include "ui/dialogs/ExportPackDialog.h"
|
||||||
|
#include "ui/dialogs/IconPickerDialog.h"
|
||||||
#include "ui/dialogs/ImportResourceDialog.h"
|
#include "ui/dialogs/ImportResourceDialog.h"
|
||||||
|
#include "ui/dialogs/NewInstanceDialog.h"
|
||||||
|
#include "ui/dialogs/NewsDialog.h"
|
||||||
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
|
#include "ui/instanceview/InstanceDelegate.h"
|
||||||
|
#include "ui/instanceview/InstanceProxyModel.h"
|
||||||
|
#include "ui/instanceview/InstanceView.h"
|
||||||
#include "ui/themes/ITheme.h"
|
#include "ui/themes/ITheme.h"
|
||||||
#include "ui/themes/ThemeManager.h"
|
#include "ui/themes/ThemeManager.h"
|
||||||
|
#include "ui/widgets/LabeledToolButton.h"
|
||||||
|
|
||||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
#include "minecraft/WorldList.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
#include "minecraft/mod/ShaderPackFolderModel.h"
|
#include "minecraft/mod/ShaderPackFolderModel.h"
|
||||||
#include "minecraft/WorldList.h"
|
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||||
|
|
||||||
#include "KonamiCode.h"
|
#include "KonamiCode.h"
|
||||||
|
|
||||||
#include "InstanceImportTask.h"
|
|
||||||
#include "InstanceCopyTask.h"
|
#include "InstanceCopyTask.h"
|
||||||
|
#include "InstanceImportTask.h"
|
||||||
|
|
||||||
#include "MMCTime.h"
|
#include "MMCTime.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
QString profileInUseFilter(const QString& profile, bool used)
|
QString profileInUseFilter(const QString& profile, bool used)
|
||||||
{
|
{
|
||||||
if(used)
|
if (used) {
|
||||||
{
|
|
||||||
return QObject::tr("%1 (in use)").arg(profile);
|
return QObject::tr("%1 (in use)").arg(profile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
@ -184,7 +182,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
ui->instanceToolBar->addContextMenuAction(ui->newsToolBar->toggleViewAction());
|
ui->instanceToolBar->addContextMenuAction(ui->newsToolBar->toggleViewAction());
|
||||||
ui->instanceToolBar->addContextMenuAction(ui->instanceToolBar->toggleViewAction());
|
ui->instanceToolBar->addContextMenuAction(ui->instanceToolBar->toggleViewAction());
|
||||||
ui->instanceToolBar->addContextMenuAction(ui->actionLockToolbars);
|
ui->instanceToolBar->addContextMenuAction(ui->actionLockToolbars);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the menu for the folders help, accounts, and export tool buttons
|
// set the menu for the folders help, accounts, and export tool buttons
|
||||||
@ -206,6 +203,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
exportInstanceMenu->addAction(ui->actionExportInstanceZip);
|
exportInstanceMenu->addAction(ui->actionExportInstanceZip);
|
||||||
exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
|
exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
|
||||||
exportInstanceMenu->addAction(ui->actionExportInstanceFlamePack);
|
exportInstanceMenu->addAction(ui->actionExportInstanceFlamePack);
|
||||||
|
exportInstanceMenu->addAction(ui->actionExportInstanceToModList);
|
||||||
ui->actionExportInstance->setMenu(exportInstanceMenu);
|
ui->actionExportInstance->setMenu(exportInstanceMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +229,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
if (qgetenv("XDG_CURRENT_DESKTOP") == "gamescope") {
|
if (qgetenv("XDG_CURRENT_DESKTOP") == "gamescope") {
|
||||||
ui->mainToolBar->addAction(ui->actionCloseWindow);
|
ui->mainToolBar->addAction(ui->actionCloseWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the toolbar toggles to the view menu
|
// add the toolbar toggles to the view menu
|
||||||
@ -301,9 +298,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
|
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
|
||||||
|
|
||||||
view->setModel(proxymodel);
|
view->setModel(proxymodel);
|
||||||
view->setSourceOfGroupCollapseStatus([](const QString & groupName)->bool {
|
view->setSourceOfGroupCollapseStatus(
|
||||||
return APPLICATION->instances()->isGroupCollapsed(groupName);
|
[](const QString& groupName) -> bool { return APPLICATION->instances()->isGroupCollapsed(groupName); });
|
||||||
});
|
|
||||||
connect(view, &InstanceView::groupStateChanged, APPLICATION->instances().get(), &InstanceList::on_GroupStateChanged);
|
connect(view, &InstanceView::groupStateChanged, APPLICATION->instances().get(), &InstanceList::on_GroupStateChanged);
|
||||||
ui->horizontalLayout->addWidget(view);
|
ui->horizontalLayout->addWidget(view);
|
||||||
}
|
}
|
||||||
@ -361,21 +357,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
// Update the menu when the active account changes.
|
// Update the menu when the active account changes.
|
||||||
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
|
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
|
||||||
// Template hell sucks...
|
// Template hell sucks...
|
||||||
connect(
|
connect(APPLICATION->accounts().get(), &AccountList::defaultAccountChanged, [this] { defaultAccountChanged(); });
|
||||||
APPLICATION->accounts().get(),
|
connect(APPLICATION->accounts().get(), &AccountList::listChanged, [this] { repopulateAccountsMenu(); });
|
||||||
&AccountList::defaultAccountChanged,
|
|
||||||
[this] {
|
|
||||||
defaultAccountChanged();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
connect(
|
|
||||||
APPLICATION->accounts().get(),
|
|
||||||
&AccountList::listChanged,
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
repopulateAccountsMenu();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show initial account
|
// Show initial account
|
||||||
defaultAccountChanged();
|
defaultAccountChanged();
|
||||||
@ -427,7 +410,6 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
void MainWindow::retranslateUi()
|
void MainWindow::retranslateUi()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_selectedInstance) {
|
if (m_selectedInstance) {
|
||||||
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
||||||
} else {
|
} else {
|
||||||
@ -457,9 +439,7 @@ void MainWindow::retranslateUi()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu* MainWindow::createPopupMenu()
|
QMenu* MainWindow::createPopupMenu()
|
||||||
{
|
{
|
||||||
@ -478,10 +458,11 @@ void MainWindow::lockToolbars(bool state)
|
|||||||
APPLICATION->settings()->set("ToolbarsLocked", state);
|
APPLICATION->settings()->set("ToolbarsLocked", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::konamiTriggered()
|
void MainWindow::konamiTriggered()
|
||||||
{
|
{
|
||||||
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 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;
|
QString stylesheet = "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0," + gradient;
|
||||||
if (ui->mainToolBar->styleSheet() == stylesheet) {
|
if (ui->mainToolBar->styleSheet() == stylesheet) {
|
||||||
ui->mainToolBar->setStyleSheet("");
|
ui->mainToolBar->setStyleSheet("");
|
||||||
@ -508,8 +489,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
|||||||
actionSep->setSeparator(true);
|
actionSep->setSeparator(true);
|
||||||
|
|
||||||
bool onInstance = view->indexAt(pos).isValid();
|
bool onInstance = view->indexAt(pos).isValid();
|
||||||
if (onInstance)
|
if (onInstance) {
|
||||||
{
|
|
||||||
// reuse the file menu actions
|
// reuse the file menu actions
|
||||||
actions = ui->fileMenu->actions();
|
actions = ui->fileMenu->actions();
|
||||||
|
|
||||||
@ -526,9 +506,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
|||||||
QAction* actionVoid = new QAction(m_selectedInstance->name(), this);
|
QAction* actionVoid = new QAction(m_selectedInstance->name(), this);
|
||||||
actionVoid->setEnabled(false);
|
actionVoid->setEnabled(false);
|
||||||
actions.prepend(actionVoid);
|
actions.prepend(actionVoid);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto group = view->groupNameAt(pos);
|
auto group = view->groupNameAt(pos);
|
||||||
|
|
||||||
QAction* actionVoid = new QAction(BuildConfig.LAUNCHER_DISPLAYNAME, this);
|
QAction* actionVoid = new QAction(BuildConfig.LAUNCHER_DISPLAYNAME, this);
|
||||||
@ -536,8 +514,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
|||||||
|
|
||||||
QAction* actionCreateInstance = new QAction(tr("Create instance"), this);
|
QAction* actionCreateInstance = new QAction(tr("Create instance"), this);
|
||||||
actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip());
|
actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip());
|
||||||
if(!group.isNull())
|
if (!group.isNull()) {
|
||||||
{
|
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
data["group"] = group;
|
data["group"] = group;
|
||||||
actionCreateInstance->setData(data);
|
actionCreateInstance->setData(data);
|
||||||
@ -548,8 +525,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
|||||||
actions.prepend(actionSep);
|
actions.prepend(actionSep);
|
||||||
actions.prepend(actionVoid);
|
actions.prepend(actionVoid);
|
||||||
actions.append(actionCreateInstance);
|
actions.append(actionCreateInstance);
|
||||||
if(!group.isNull())
|
if (!group.isNull()) {
|
||||||
{
|
|
||||||
QAction* actionDeleteGroup = new QAction(tr("Delete group '%1'").arg(group), this);
|
QAction* actionDeleteGroup = new QAction(tr("Delete group '%1'").arg(group), this);
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
data["group"] = group;
|
data["group"] = group;
|
||||||
@ -582,12 +558,9 @@ void MainWindow::updateToolsMenu()
|
|||||||
ui->actionLaunchInstanceDemo->setDisabled(!m_selectedInstance || currentInstanceRunning);
|
ui->actionLaunchInstanceDemo->setDisabled(!m_selectedInstance || currentInstanceRunning);
|
||||||
|
|
||||||
QMenu* launchMenu = ui->actionLaunchInstance->menu();
|
QMenu* launchMenu = ui->actionLaunchInstance->menu();
|
||||||
if (launchMenu)
|
if (launchMenu) {
|
||||||
{
|
|
||||||
launchMenu->clear();
|
launchMenu->clear();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
launchMenu = new QMenu(this);
|
launchMenu = new QMenu(this);
|
||||||
}
|
}
|
||||||
QAction* normalLaunch = launchMenu->addAction(tr("Launch"));
|
QAction* normalLaunch = launchMenu->addAction(tr("Launch"));
|
||||||
@ -596,24 +569,15 @@ void MainWindow::updateToolsMenu()
|
|||||||
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
|
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
|
||||||
QAction* normalLaunchDemo = launchMenu->addAction(tr("Launch Demo"));
|
QAction* normalLaunchDemo = launchMenu->addAction(tr("Launch Demo"));
|
||||||
normalLaunchDemo->setShortcut(QKeySequence(tr("Ctrl+Alt+O")));
|
normalLaunchDemo->setShortcut(QKeySequence(tr("Ctrl+Alt+O")));
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
normalLaunch->setEnabled(m_selectedInstance->canLaunch());
|
normalLaunch->setEnabled(m_selectedInstance->canLaunch());
|
||||||
normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
|
normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
|
||||||
normalLaunchDemo->setEnabled(m_selectedInstance->canLaunch());
|
normalLaunchDemo->setEnabled(m_selectedInstance->canLaunch());
|
||||||
|
|
||||||
connect(normalLaunch, &QAction::triggered, [this]() {
|
connect(normalLaunch, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, true, false); });
|
||||||
APPLICATION->launch(m_selectedInstance, true, false);
|
connect(normalLaunchOffline, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, false, false); });
|
||||||
});
|
connect(normalLaunchDemo, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, false, true); });
|
||||||
connect(normalLaunchOffline, &QAction::triggered, [this]() {
|
} else {
|
||||||
APPLICATION->launch(m_selectedInstance, false, false);
|
|
||||||
});
|
|
||||||
connect(normalLaunchDemo, &QAction::triggered, [this]() {
|
|
||||||
APPLICATION->launch(m_selectedInstance, false, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
normalLaunch->setDisabled(true);
|
normalLaunch->setDisabled(true);
|
||||||
normalLaunchOffline->setDisabled(true);
|
normalLaunchOffline->setDisabled(true);
|
||||||
normalLaunchDemo->setDisabled(true);
|
normalLaunchDemo->setDisabled(true);
|
||||||
@ -627,35 +591,25 @@ void MainWindow::updateToolsMenu()
|
|||||||
|
|
||||||
QString profilersTitle = tr("Profilers");
|
QString profilersTitle = tr("Profilers");
|
||||||
launchMenu->addSeparator()->setText(profilersTitle);
|
launchMenu->addSeparator()->setText(profilersTitle);
|
||||||
for (auto profiler : APPLICATION->profilers().values())
|
for (auto profiler : APPLICATION->profilers().values()) {
|
||||||
{
|
|
||||||
QAction* profilerAction = launchMenu->addAction(profiler->name());
|
QAction* profilerAction = launchMenu->addAction(profiler->name());
|
||||||
QAction* profilerOfflineAction = launchMenu->addAction(tr("%1 Offline").arg(profiler->name()));
|
QAction* profilerOfflineAction = launchMenu->addAction(tr("%1 Offline").arg(profiler->name()));
|
||||||
QString error;
|
QString error;
|
||||||
if (!profiler->check(&error))
|
if (!profiler->check(&error)) {
|
||||||
{
|
|
||||||
profilerAction->setDisabled(true);
|
profilerAction->setDisabled(true);
|
||||||
profilerOfflineAction->setDisabled(true);
|
profilerOfflineAction->setDisabled(true);
|
||||||
QString profilerToolTip = tr("Profiler not setup correctly. Go into settings, \"External Tools\".");
|
QString profilerToolTip = tr("Profiler not setup correctly. Go into settings, \"External Tools\".");
|
||||||
profilerAction->setToolTip(profilerToolTip);
|
profilerAction->setToolTip(profilerToolTip);
|
||||||
profilerOfflineAction->setToolTip(profilerToolTip);
|
profilerOfflineAction->setToolTip(profilerToolTip);
|
||||||
}
|
} else if (m_selectedInstance) {
|
||||||
else if (m_selectedInstance)
|
|
||||||
{
|
|
||||||
profilerAction->setEnabled(m_selectedInstance->canLaunch());
|
profilerAction->setEnabled(m_selectedInstance->canLaunch());
|
||||||
profilerOfflineAction->setEnabled(m_selectedInstance->canLaunch());
|
profilerOfflineAction->setEnabled(m_selectedInstance->canLaunch());
|
||||||
|
|
||||||
connect(profilerAction, &QAction::triggered, [this, profiler]()
|
connect(profilerAction, &QAction::triggered,
|
||||||
{
|
[this, profiler]() { APPLICATION->launch(m_selectedInstance, true, false, profiler.get()); });
|
||||||
APPLICATION->launch(m_selectedInstance, true, false, profiler.get());
|
connect(profilerOfflineAction, &QAction::triggered,
|
||||||
});
|
[this, profiler]() { APPLICATION->launch(m_selectedInstance, false, false, profiler.get()); });
|
||||||
connect(profilerOfflineAction, &QAction::triggered, [this, profiler]()
|
} else {
|
||||||
{
|
|
||||||
APPLICATION->launch(m_selectedInstance, false, false, profiler.get());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
profilerAction->setDisabled(true);
|
profilerAction->setDisabled(true);
|
||||||
profilerOfflineAction->setDisabled(true);
|
profilerOfflineAction->setDisabled(true);
|
||||||
}
|
}
|
||||||
@ -712,11 +666,9 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
||||||
|
|
||||||
QString active_profileId = "";
|
QString active_profileId = "";
|
||||||
if (defaultAccount)
|
if (defaultAccount) {
|
||||||
{
|
|
||||||
// this can be called before accountMenuButton exists
|
// this can be called before accountMenuButton exists
|
||||||
if (ui->actionAccountsButton)
|
if (ui->actionAccountsButton) {
|
||||||
{
|
|
||||||
auto profileLabel = profileInUseFilter(defaultAccount->profileName(), defaultAccount->isInUse());
|
auto profileLabel = profileInUseFilter(defaultAccount->profileName(), defaultAccount->isInUse());
|
||||||
ui->actionAccountsButton->setText(profileLabel);
|
ui->actionAccountsButton->setText(profileLabel);
|
||||||
}
|
}
|
||||||
@ -724,38 +676,31 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
|
|
||||||
QActionGroup* accountsGroup = new QActionGroup(this);
|
QActionGroup* accountsGroup = new QActionGroup(this);
|
||||||
|
|
||||||
if (accounts->count() <= 0)
|
if (accounts->count() <= 0) {
|
||||||
{
|
|
||||||
ui->actionNoAccountsAdded->setEnabled(false);
|
ui->actionNoAccountsAdded->setEnabled(false);
|
||||||
ui->accountsMenu->addAction(ui->actionNoAccountsAdded);
|
ui->accountsMenu->addAction(ui->actionNoAccountsAdded);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO: Nicer way to iterate?
|
// TODO: Nicer way to iterate?
|
||||||
for (int i = 0; i < accounts->count(); i++)
|
for (int i = 0; i < accounts->count(); i++) {
|
||||||
{
|
|
||||||
MinecraftAccountPtr account = accounts->at(i);
|
MinecraftAccountPtr account = accounts->at(i);
|
||||||
auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
|
auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
|
||||||
QAction* action = new QAction(profileLabel, this);
|
QAction* action = new QAction(profileLabel, this);
|
||||||
action->setData(i);
|
action->setData(i);
|
||||||
action->setCheckable(true);
|
action->setCheckable(true);
|
||||||
action->setActionGroup(accountsGroup);
|
action->setActionGroup(accountsGroup);
|
||||||
if (defaultAccount == account)
|
if (defaultAccount == account) {
|
||||||
{
|
|
||||||
action->setChecked(true);
|
action->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto face = account->getFace();
|
auto face = account->getFace();
|
||||||
if (!face.isNull()) {
|
if (!face.isNull()) {
|
||||||
action->setIcon(face);
|
action->setIcon(face);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
action->setIcon(APPLICATION->getThemedIcon("noaccount"));
|
action->setIcon(APPLICATION->getThemedIcon("noaccount"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const int highestNumberKey = 9;
|
const int highestNumberKey = 9;
|
||||||
if(i<highestNumberKey)
|
if (i < highestNumberKey) {
|
||||||
{
|
|
||||||
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(i + 1)));
|
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(i + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,8 +727,7 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
|
|
||||||
void MainWindow::updatesAllowedChanged(bool allowed)
|
void MainWindow::updatesAllowedChanged(bool allowed)
|
||||||
{
|
{
|
||||||
if(!BuildConfig.UPDATER_ENABLED)
|
if (!BuildConfig.UPDATER_ENABLED) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->actionCheckUpdate->setEnabled(allowed);
|
ui->actionCheckUpdate->setEnabled(allowed);
|
||||||
@ -818,15 +762,13 @@ void MainWindow::defaultAccountChanged()
|
|||||||
MinecraftAccountPtr account = APPLICATION->accounts()->defaultAccount();
|
MinecraftAccountPtr account = APPLICATION->accounts()->defaultAccount();
|
||||||
|
|
||||||
// FIXME: this needs adjustment for MSA
|
// FIXME: this needs adjustment for MSA
|
||||||
if (account && account->profileName() != "")
|
if (account && account->profileName() != "") {
|
||||||
{
|
|
||||||
auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
|
auto profileLabel = profileInUseFilter(account->profileName(), account->isInUse());
|
||||||
ui->actionAccountsButton->setText(profileLabel);
|
ui->actionAccountsButton->setText(profileLabel);
|
||||||
auto face = account->getFace();
|
auto face = account->getFace();
|
||||||
if (face.isNull()) {
|
if (face.isNull()) {
|
||||||
ui->actionAccountsButton->setIcon(APPLICATION->getThemedIcon("noaccount"));
|
ui->actionAccountsButton->setIcon(APPLICATION->getThemedIcon("noaccount"));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ui->actionAccountsButton->setIcon(face);
|
ui->actionAccountsButton->setIcon(face);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -839,14 +781,11 @@ void MainWindow::defaultAccountChanged()
|
|||||||
|
|
||||||
bool MainWindow::eventFilter(QObject* obj, QEvent* ev)
|
bool MainWindow::eventFilter(QObject* obj, QEvent* ev)
|
||||||
{
|
{
|
||||||
if (obj == view)
|
if (obj == view) {
|
||||||
{
|
if (ev->type() == QEvent::KeyPress) {
|
||||||
if (ev->type() == QEvent::KeyPress)
|
|
||||||
{
|
|
||||||
secretEventFilter->input(ev);
|
secretEventFilter->input(ev);
|
||||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(ev);
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(ev);
|
||||||
switch (keyEvent->key())
|
switch (keyEvent->key()) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
@ -872,23 +811,17 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
|
|||||||
|
|
||||||
void MainWindow::updateNewsLabel()
|
void MainWindow::updateNewsLabel()
|
||||||
{
|
{
|
||||||
if (m_newsChecker->isLoadingNews())
|
if (m_newsChecker->isLoadingNews()) {
|
||||||
{
|
|
||||||
newsLabel->setText(tr("Loading news..."));
|
newsLabel->setText(tr("Loading news..."));
|
||||||
newsLabel->setEnabled(false);
|
newsLabel->setEnabled(false);
|
||||||
ui->actionMoreNews->setVisible(false);
|
ui->actionMoreNews->setVisible(false);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
QList<NewsEntryPtr> entries = m_newsChecker->getNewsEntries();
|
QList<NewsEntryPtr> entries = m_newsChecker->getNewsEntries();
|
||||||
if (entries.length() > 0)
|
if (entries.length() > 0) {
|
||||||
{
|
|
||||||
newsLabel->setText(entries[0]->title);
|
newsLabel->setText(entries[0]->title);
|
||||||
newsLabel->setEnabled(true);
|
newsLabel->setEnabled(true);
|
||||||
ui->actionMoreNews->setVisible(true);
|
ui->actionMoreNews->setVisible(true);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
newsLabel->setText(tr("No news available."));
|
newsLabel->setText(tr("No news available."));
|
||||||
newsLabel->setEnabled(false);
|
newsLabel->setEnabled(false);
|
||||||
ui->actionMoreNews->setVisible(false);
|
ui->actionMoreNews->setVisible(false);
|
||||||
@ -904,8 +837,7 @@ QList<int> stringToIntList(const QString &string)
|
|||||||
QStringList split = string.split(',', QString::SkipEmptyParts);
|
QStringList split = string.split(',', QString::SkipEmptyParts);
|
||||||
#endif
|
#endif
|
||||||
QList<int> out;
|
QList<int> out;
|
||||||
for (int i = 0; i < split.size(); ++i)
|
for (int i = 0; i < split.size(); ++i) {
|
||||||
{
|
|
||||||
out.append(split.at(i).toInt());
|
out.append(split.at(i).toInt());
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
@ -913,8 +845,7 @@ QList<int> stringToIntList(const QString &string)
|
|||||||
QString intListToString(const QList<int>& list)
|
QString intListToString(const QList<int>& list)
|
||||||
{
|
{
|
||||||
QStringList slist;
|
QStringList slist;
|
||||||
for (int i = 0; i < list.size(); ++i)
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
{
|
|
||||||
slist.append(QString::number(list.at(i)));
|
slist.append(QString::number(list.at(i)));
|
||||||
}
|
}
|
||||||
return slist.join(',');
|
return slist.join(',');
|
||||||
@ -934,21 +865,17 @@ void MainWindow::setCatBackground(bool enabled)
|
|||||||
|
|
||||||
void MainWindow::runModalTask(Task* task)
|
void MainWindow::runModalTask(Task* task)
|
||||||
{
|
{
|
||||||
connect(task, &Task::failed, [this](QString reason)
|
connect(task, &Task::failed,
|
||||||
{
|
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||||
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
|
connect(task, &Task::succeeded, [this, task]() {
|
||||||
});
|
|
||||||
connect(task, &Task::succeeded, [this, task]()
|
|
||||||
{
|
|
||||||
QStringList warnings = task->warnings();
|
QStringList warnings = task->warnings();
|
||||||
if(warnings.count())
|
if (warnings.count()) {
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
|
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(task, &Task::aborted, [this]
|
connect(task, &Task::aborted, [this] {
|
||||||
{
|
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)
|
||||||
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)->show();
|
->show();
|
||||||
});
|
});
|
||||||
ProgressDialog loadDialog(this);
|
ProgressDialog loadDialog(this);
|
||||||
loadDialog.setSkipButton(true, tr("Abort"));
|
loadDialog.setSkipButton(true, tr("Abort"));
|
||||||
@ -982,38 +909,30 @@ void MainWindow::finalizeInstance(InstancePtr inst)
|
|||||||
{
|
{
|
||||||
view->updateGeometries();
|
view->updateGeometries();
|
||||||
setSelectedInstanceById(inst->id());
|
setSelectedInstanceById(inst->id());
|
||||||
if (APPLICATION->accounts()->anyAccountIsValid())
|
if (APPLICATION->accounts()->anyAccountIsValid()) {
|
||||||
{
|
|
||||||
ProgressDialog loadDialog(this);
|
ProgressDialog loadDialog(this);
|
||||||
auto update = inst->createUpdateTask(Net::Mode::Online);
|
auto update = inst->createUpdateTask(Net::Mode::Online);
|
||||||
connect(update.get(), &Task::failed, [this](QString reason)
|
connect(update.get(), &Task::failed, [this](QString reason) {
|
||||||
{
|
|
||||||
QString error = QString("Instance load failed: %1").arg(reason);
|
QString error = QString("Instance load failed: %1").arg(reason);
|
||||||
CustomMessageBox::selectable(this, tr("Error"), error, QMessageBox::Warning)->show();
|
CustomMessageBox::selectable(this, tr("Error"), error, QMessageBox::Warning)->show();
|
||||||
});
|
});
|
||||||
if(update)
|
if (update) {
|
||||||
{
|
|
||||||
loadDialog.setSkipButton(true, tr("Abort"));
|
loadDialog.setSkipButton(true, tr("Abort"));
|
||||||
loadDialog.execWithTask(update.get());
|
loadDialog.execWithTask(update.get());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
CustomMessageBox::selectable(this, tr("Error"),
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(
|
|
||||||
this,
|
|
||||||
tr("Error"),
|
|
||||||
tr("The launcher cannot download Minecraft or update instances unless you have at least "
|
tr("The launcher cannot download Minecraft or update instances unless you have at least "
|
||||||
"one account added.\nPlease add your Mojang or Minecraft account."),
|
"one account added.\nPlease add your Mojang or Minecraft account."),
|
||||||
QMessageBox::Warning
|
QMessageBox::Warning)
|
||||||
)->show();
|
->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addInstance(QString url)
|
void MainWindow::addInstance(QString url)
|
||||||
{
|
{
|
||||||
QString groupName;
|
QString groupName;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
QObject* obj = sender();
|
QObject* obj = sender();
|
||||||
if (!obj)
|
if (!obj)
|
||||||
break;
|
break;
|
||||||
@ -1026,8 +945,7 @@ void MainWindow::addInstance(QString url)
|
|||||||
groupName = map["group"].toString();
|
groupName = map["group"].toString();
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if(groupName.isEmpty())
|
if (groupName.isEmpty()) {
|
||||||
{
|
|
||||||
groupName = APPLICATION->settings()->get("LastUsedGroupForNewInstance").toString();
|
groupName = APPLICATION->settings()->get("LastUsedGroupForNewInstance").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1038,8 +956,7 @@ void MainWindow::addInstance(QString url)
|
|||||||
APPLICATION->settings()->set("LastUsedGroupForNewInstance", newInstDlg.instGroup());
|
APPLICATION->settings()->set("LastUsedGroupForNewInstance", newInstDlg.instGroup());
|
||||||
|
|
||||||
InstanceTask* creationTask = newInstDlg.extractTask();
|
InstanceTask* creationTask = newInstDlg.extractTask();
|
||||||
if(creationTask)
|
if (creationTask) {
|
||||||
{
|
|
||||||
instanceFromInstanceTask(creationTask);
|
instanceFromInstanceTask(creationTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1133,8 +1050,7 @@ void MainWindow::on_actionChangeInstIcon_triggered()
|
|||||||
|
|
||||||
IconPickerDialog dlg(this);
|
IconPickerDialog dlg(this);
|
||||||
dlg.execWithSelection(m_selectedInstance->iconKey());
|
dlg.execWithSelection(m_selectedInstance->iconKey());
|
||||||
if (dlg.result() == QDialog::Accepted)
|
if (dlg.result() == QDialog::Accepted) {
|
||||||
{
|
|
||||||
m_selectedInstance->setIconKey(dlg.selectedIconKey);
|
m_selectedInstance->setIconKey(dlg.selectedIconKey);
|
||||||
auto icon = APPLICATION->icons()->getIcon(dlg.selectedIconKey);
|
auto icon = APPLICATION->icons()->getIcon(dlg.selectedIconKey);
|
||||||
ui->actionChangeInstIcon->setIcon(icon);
|
ui->actionChangeInstIcon->setIcon(icon);
|
||||||
@ -1144,8 +1060,7 @@ void MainWindow::on_actionChangeInstIcon_triggered()
|
|||||||
|
|
||||||
void MainWindow::iconUpdated(QString icon)
|
void MainWindow::iconUpdated(QString icon)
|
||||||
{
|
{
|
||||||
if (icon == m_currentInstIcon)
|
if (icon == m_currentInstIcon) {
|
||||||
{
|
|
||||||
auto icon = APPLICATION->icons()->getIcon(m_currentInstIcon);
|
auto icon = APPLICATION->icons()->getIcon(m_currentInstIcon);
|
||||||
ui->actionChangeInstIcon->setIcon(icon);
|
ui->actionChangeInstIcon->setIcon(icon);
|
||||||
changeIconButton->setIcon(icon);
|
changeIconButton->setIcon(icon);
|
||||||
@ -1165,8 +1080,7 @@ void MainWindow::setSelectedInstanceById(const QString &id)
|
|||||||
if (id.isNull())
|
if (id.isNull())
|
||||||
return;
|
return;
|
||||||
const QModelIndex index = APPLICATION->instances()->getInstanceIndexById(id);
|
const QModelIndex index = APPLICATION->instances()->getInstanceIndexById(id);
|
||||||
if (index.isValid())
|
if (index.isValid()) {
|
||||||
{
|
|
||||||
QModelIndex selectionIndex = proxymodel->mapFromSource(index);
|
QModelIndex selectionIndex = proxymodel->mapFromSource(index);
|
||||||
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
|
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
|
||||||
updateStatusCenter();
|
updateStatusCenter();
|
||||||
@ -1188,8 +1102,7 @@ void MainWindow::on_actionChangeInstGroup_triggered()
|
|||||||
|
|
||||||
name = QInputDialog::getItem(this, tr("Group name"), tr("Enter a new group name."), groups, foo, true, &ok);
|
name = QInputDialog::getItem(this, tr("Group name"), tr("Enter a new group name."), groups, foo, true, &ok);
|
||||||
name = name.simplified();
|
name = name.simplified();
|
||||||
if (ok)
|
if (ok) {
|
||||||
{
|
|
||||||
APPLICATION->instances()->setInstanceGroup(instId, name);
|
APPLICATION->instances()->setInstanceGroup(instId, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1206,12 +1119,10 @@ void MainWindow::deleteGroup()
|
|||||||
if (!map.contains("group"))
|
if (!map.contains("group"))
|
||||||
return;
|
return;
|
||||||
QString groupName = map["group"].toString();
|
QString groupName = map["group"].toString();
|
||||||
if(!groupName.isEmpty())
|
if (!groupName.isEmpty()) {
|
||||||
{
|
auto reply = QMessageBox::question(this, tr("Delete group"), tr("Are you sure you want to delete the group %1?").arg(groupName),
|
||||||
auto reply = QMessageBox::question(this, tr("Delete group"), tr("Are you sure you want to delete the group %1?")
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
.arg(groupName), QMessageBox::Yes | QMessageBox::No);
|
if (reply == QMessageBox::Yes) {
|
||||||
if(reply == QMessageBox::Yes)
|
|
||||||
{
|
|
||||||
APPLICATION->instances()->deleteGroup(groupName);
|
APPLICATION->instances()->deleteGroup(groupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1247,12 +1158,9 @@ void MainWindow::on_actionViewCentralModsFolder_triggered()
|
|||||||
|
|
||||||
void MainWindow::checkForUpdates()
|
void MainWindow::checkForUpdates()
|
||||||
{
|
{
|
||||||
if(BuildConfig.UPDATER_ENABLED)
|
if (BuildConfig.UPDATER_ENABLED) {
|
||||||
{
|
|
||||||
APPLICATION->triggerUpdateCheck();
|
APPLICATION->triggerUpdateCheck();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
qWarning() << "Updater not set up. Cannot check for updates.";
|
qWarning() << "Updater not set up. Cannot check for updates.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1280,7 +1188,6 @@ void MainWindow::globalSettingsClosed()
|
|||||||
|
|
||||||
void MainWindow::on_actionEditInstance_triggered()
|
void MainWindow::on_actionEditInstance_triggered()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_selectedInstance)
|
if (!m_selectedInstance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1289,7 +1196,8 @@ void MainWindow::on_actionEditInstance_triggered()
|
|||||||
} else {
|
} else {
|
||||||
CustomMessageBox::selectable(this, tr("Instance not editable"),
|
CustomMessageBox::selectable(this, tr("Instance not editable"),
|
||||||
tr("This instance is not editable. It may be broken, invalid, or too old. Check logs for details."),
|
tr("This instance is not editable. It may be broken, invalid, or too old. Check logs for details."),
|
||||||
QMessageBox::Critical)->show();
|
QMessageBox::Critical)
|
||||||
|
->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1352,7 +1260,8 @@ void MainWindow::newsButtonClicked()
|
|||||||
news_dialog.exec();
|
news_dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCatChanged(int) {
|
void MainWindow::onCatChanged(int)
|
||||||
|
{
|
||||||
setCatBackground(APPLICATION->settings()->get("TheCat").toBool());
|
setCatBackground(APPLICATION->settings()->get("TheCat").toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1383,14 +1292,15 @@ void MainWindow::on_actionDeleteInstance_triggered()
|
|||||||
|
|
||||||
auto linkedInstances = APPLICATION->instances()->getLinkedInstancesById(id);
|
auto linkedInstances = APPLICATION->instances()->getLinkedInstancesById(id);
|
||||||
if (!linkedInstances.empty()) {
|
if (!linkedInstances.empty()) {
|
||||||
response = CustomMessageBox::selectable(
|
response = CustomMessageBox::selectable(this, tr("There are linked instances"),
|
||||||
this, tr("There are linked instances"),
|
|
||||||
tr("The following instance(s) might reference files in this instance:\n\n"
|
tr("The following instance(s) might reference files in this instance:\n\n"
|
||||||
"%1\n\n"
|
"%1\n\n"
|
||||||
"Deleting it could break the other instance(s), \n\n"
|
"Deleting it could break the other instance(s), \n\n"
|
||||||
"Do you wish to proceed?", nullptr, linkedInstances.count()).arg(linkedInstances.join("\n")),
|
"Do you wish to proceed?",
|
||||||
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No
|
nullptr, linkedInstances.count())
|
||||||
)->exec();
|
.arg(linkedInstances.join("\n")),
|
||||||
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
||||||
|
->exec();
|
||||||
if (response != QMessageBox::Yes)
|
if (response != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1405,8 +1315,7 @@ void MainWindow::on_actionDeleteInstance_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionExportInstanceZip_triggered()
|
void MainWindow::on_actionExportInstanceZip_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
ExportInstanceDialog dlg(m_selectedInstance, this);
|
ExportInstanceDialog dlg(m_selectedInstance, this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
@ -1414,13 +1323,20 @@ void MainWindow::on_actionExportInstanceZip_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionExportInstanceMrPack_triggered()
|
void MainWindow::on_actionExportInstanceMrPack_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
ExportPackDialog dlg(m_selectedInstance, this);
|
ExportPackDialog dlg(m_selectedInstance, this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionExportInstanceToModList_triggered()
|
||||||
|
{
|
||||||
|
if (m_selectedInstance) {
|
||||||
|
ExportToModListDialog dlg(m_selectedInstance, this);
|
||||||
|
dlg.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExportInstanceFlamePack_triggered()
|
void MainWindow::on_actionExportInstanceFlamePack_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance) {
|
if (m_selectedInstance) {
|
||||||
@ -1447,16 +1363,14 @@ void MainWindow::on_actionExportInstanceFlamePack_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionRenameInstance_triggered()
|
void MainWindow::on_actionRenameInstance_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
view->edit(view->currentIndex());
|
view->edit(view->currentIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionViewSelectedInstFolder_triggered()
|
void MainWindow::on_actionViewSelectedInstFolder_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
QString str = m_selectedInstance->instanceRoot();
|
QString str = m_selectedInstance->instanceRoot();
|
||||||
DesktopServices::openDirectory(QDir(str).absolutePath());
|
DesktopServices::openDirectory(QDir(str).absolutePath());
|
||||||
}
|
}
|
||||||
@ -1474,8 +1388,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
|
|
||||||
void MainWindow::changeEvent(QEvent* event)
|
void MainWindow::changeEvent(QEvent* event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::LanguageChange)
|
if (event->type() == QEvent::LanguageChange) {
|
||||||
{
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
@ -1495,8 +1408,7 @@ void MainWindow::instanceActivated(QModelIndex index)
|
|||||||
|
|
||||||
void MainWindow::on_actionLaunchInstance_triggered()
|
void MainWindow::on_actionLaunchInstance_triggered()
|
||||||
{
|
{
|
||||||
if(m_selectedInstance && !m_selectedInstance->isRunning())
|
if (m_selectedInstance && !m_selectedInstance->isRunning()) {
|
||||||
{
|
|
||||||
APPLICATION->launch(m_selectedInstance);
|
APPLICATION->launch(m_selectedInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1508,24 +1420,21 @@ void MainWindow::activateInstance(InstancePtr instance)
|
|||||||
|
|
||||||
void MainWindow::on_actionLaunchInstanceOffline_triggered()
|
void MainWindow::on_actionLaunchInstanceOffline_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
APPLICATION->launch(m_selectedInstance, false);
|
APPLICATION->launch(m_selectedInstance, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionLaunchInstanceDemo_triggered()
|
void MainWindow::on_actionLaunchInstanceDemo_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
APPLICATION->launch(m_selectedInstance, false, true);
|
APPLICATION->launch(m_selectedInstance, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionKillInstance_triggered()
|
void MainWindow::on_actionKillInstance_triggered()
|
||||||
{
|
{
|
||||||
if(m_selectedInstance && m_selectedInstance->isRunning())
|
if (m_selectedInstance && m_selectedInstance->isRunning()) {
|
||||||
{
|
|
||||||
APPLICATION->kill(m_selectedInstance);
|
APPLICATION->kill(m_selectedInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1554,16 +1463,14 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto pIcon = APPLICATION->icons()->icon(m_selectedInstance->iconKey());
|
auto pIcon = APPLICATION->icons()->icon(m_selectedInstance->iconKey());
|
||||||
if (pIcon == nullptr)
|
if (pIcon == nullptr) {
|
||||||
{
|
|
||||||
pIcon = APPLICATION->icons()->icon("grass");
|
pIcon = APPLICATION->icons()->icon("grass");
|
||||||
}
|
}
|
||||||
|
|
||||||
iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "Icon.icns");
|
iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "Icon.icns");
|
||||||
|
|
||||||
QFile iconFile(iconPath);
|
QFile iconFile(iconPath);
|
||||||
if (!iconFile.open(QFile::WriteOnly))
|
if (!iconFile.open(QFile::WriteOnly)) {
|
||||||
{
|
|
||||||
QMessageBox::critical(this, tr("Create instance Application"), tr("Failed to create icon for Application."));
|
QMessageBox::critical(this, tr("Create instance Application"), tr("Failed to create icon for Application."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1573,8 +1480,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered()
|
|||||||
bool success = icon.pixmap(1024, 1024).save(iconPath, "ICNS");
|
bool success = icon.pixmap(1024, 1024).save(iconPath, "ICNS");
|
||||||
iconFile.close();
|
iconFile.close();
|
||||||
|
|
||||||
if (!success)
|
if (!success) {
|
||||||
{
|
|
||||||
iconFile.remove();
|
iconFile.remove();
|
||||||
QMessageBox::critical(this, tr("Create instance Application"), tr("Failed to create icon for Application."));
|
QMessageBox::critical(this, tr("Create instance Application"), tr("Failed to create icon for Application."));
|
||||||
return;
|
return;
|
||||||
@ -1692,8 +1598,7 @@ void MainWindow::startTask(Task *task)
|
|||||||
|
|
||||||
void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex& previous)
|
void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
{
|
{
|
||||||
if (!current.isValid())
|
if (!current.isValid()) {
|
||||||
{
|
|
||||||
APPLICATION->settings()->set("SelectedInstance", QString());
|
APPLICATION->settings()->set("SelectedInstance", QString());
|
||||||
selectionBad();
|
selectionBad();
|
||||||
return;
|
return;
|
||||||
@ -1703,8 +1608,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
|||||||
}
|
}
|
||||||
QString id = current.data(InstanceList::InstanceIDRole).toString();
|
QString id = current.data(InstanceList::InstanceIDRole).toString();
|
||||||
m_selectedInstance = APPLICATION->instances()->getInstanceById(id);
|
m_selectedInstance = APPLICATION->instances()->getInstanceById(id);
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance) {
|
||||||
{
|
|
||||||
ui->instanceToolBar->setEnabled(true);
|
ui->instanceToolBar->setEnabled(true);
|
||||||
setInstanceActionsEnabled(true);
|
setInstanceActionsEnabled(true);
|
||||||
ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
|
ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
|
||||||
@ -1729,9 +1633,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
|||||||
APPLICATION->settings()->set("SelectedInstance", m_selectedInstance->id());
|
APPLICATION->settings()->set("SelectedInstance", m_selectedInstance->id());
|
||||||
|
|
||||||
connect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
|
connect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->instanceToolBar->setEnabled(false);
|
ui->instanceToolBar->setEnabled(false);
|
||||||
setInstanceActionsEnabled(false);
|
setInstanceActionsEnabled(false);
|
||||||
ui->actionLaunchInstance->setEnabled(false);
|
ui->actionLaunchInstance->setEnabled(false);
|
||||||
@ -1753,8 +1655,7 @@ void MainWindow::instanceDataChanged(const QModelIndex &topLeft, const QModelInd
|
|||||||
{
|
{
|
||||||
auto current = view->selectionModel()->currentIndex();
|
auto current = view->selectionModel()->currentIndex();
|
||||||
QItemSelection test(topLeft, bottomRight);
|
QItemSelection test(topLeft, bottomRight);
|
||||||
if (test.contains(current))
|
if (test.contains(current)) {
|
||||||
{
|
|
||||||
instanceChanged(current, current);
|
instanceChanged(current, current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1778,34 +1679,28 @@ void MainWindow::selectionBad()
|
|||||||
void MainWindow::checkInstancePathForProblems()
|
void MainWindow::checkInstancePathForProblems()
|
||||||
{
|
{
|
||||||
QString instanceFolder = APPLICATION->settings()->get("InstanceDir").toString();
|
QString instanceFolder = APPLICATION->settings()->get("InstanceDir").toString();
|
||||||
if (FS::checkProblemticPathJava(QDir(instanceFolder)))
|
if (FS::checkProblemticPathJava(QDir(instanceFolder))) {
|
||||||
{
|
|
||||||
QMessageBox warning(this);
|
QMessageBox warning(this);
|
||||||
warning.setText(tr("Your instance folder contains \'!\' and this is known to cause Java problems!"));
|
warning.setText(tr("Your instance folder contains \'!\' and this is known to cause Java problems!"));
|
||||||
warning.setInformativeText(
|
warning.setInformativeText(tr("You have now two options: <br/>"
|
||||||
tr(
|
|
||||||
"You have now two options: <br/>"
|
|
||||||
" - change the instance folder in the settings <br/>"
|
" - change the instance folder in the settings <br/>"
|
||||||
" - move this installation of %1 to a different folder"
|
" - move this installation of %1 to a different folder")
|
||||||
).arg(BuildConfig.LAUNCHER_DISPLAYNAME)
|
.arg(BuildConfig.LAUNCHER_DISPLAYNAME));
|
||||||
);
|
|
||||||
warning.setDefaultButton(QMessageBox::Ok);
|
warning.setDefaultButton(QMessageBox::Ok);
|
||||||
warning.exec();
|
warning.exec();
|
||||||
}
|
}
|
||||||
auto tempFolderText = tr("This is a problem: <br/>"
|
auto tempFolderText =
|
||||||
|
tr("This is a problem: <br/>"
|
||||||
" - The launcher will likely be deleted without warning by the operating system <br/>"
|
" - The launcher will likely be deleted without warning by the operating system <br/>"
|
||||||
" - close the launcher now and extract it to a real location, not a temporary folder");
|
" - close the launcher now and extract it to a real location, not a temporary folder");
|
||||||
QString pathfoldername = QDir(instanceFolder).absolutePath();
|
QString pathfoldername = QDir(instanceFolder).absolutePath();
|
||||||
if (pathfoldername.contains("Rar$", Qt::CaseInsensitive))
|
if (pathfoldername.contains("Rar$", Qt::CaseInsensitive)) {
|
||||||
{
|
|
||||||
QMessageBox warning(this);
|
QMessageBox warning(this);
|
||||||
warning.setText(tr("Your instance folder contains \'Rar$\' - that means you haven't extracted the launcher archive!"));
|
warning.setText(tr("Your instance folder contains \'Rar$\' - that means you haven't extracted the launcher archive!"));
|
||||||
warning.setInformativeText(tempFolderText);
|
warning.setInformativeText(tempFolderText);
|
||||||
warning.setDefaultButton(QMessageBox::Ok);
|
warning.setDefaultButton(QMessageBox::Ok);
|
||||||
warning.exec();
|
warning.exec();
|
||||||
}
|
} else if (pathfoldername.startsWith(QDir::tempPath()) || pathfoldername.contains("/TempState/")) {
|
||||||
else if (pathfoldername.startsWith(QDir::tempPath()) || pathfoldername.contains("/TempState/"))
|
|
||||||
{
|
|
||||||
QMessageBox warning(this);
|
QMessageBox warning(this);
|
||||||
warning.setText(tr("Your instance folder is in a temporary folder: \'%1\'!").arg(QDir::tempPath()));
|
warning.setText(tr("Your instance folder is in a temporary folder: \'%1\'!").arg(QDir::tempPath()));
|
||||||
warning.setInformativeText(tempFolderText);
|
warning.setInformativeText(tempFolderText);
|
||||||
|
@ -158,6 +158,7 @@ private slots:
|
|||||||
void on_actionExportInstanceZip_triggered();
|
void on_actionExportInstanceZip_triggered();
|
||||||
void on_actionExportInstanceMrPack_triggered();
|
void on_actionExportInstanceMrPack_triggered();
|
||||||
void on_actionExportInstanceFlamePack_triggered();
|
void on_actionExportInstanceFlamePack_triggered();
|
||||||
|
void on_actionExportInstanceToModList_triggered();
|
||||||
|
|
||||||
void on_actionRenameInstance_triggered();
|
void on_actionRenameInstance_triggered();
|
||||||
|
|
||||||
|
@ -487,6 +487,14 @@
|
|||||||
<string>CurseForge (zip)</string>
|
<string>CurseForge (zip)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionExportInstanceToModList">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="new"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Mod List</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionCreateInstanceShortcut">
|
<action name="actionCreateInstanceShortcut">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="shortcut">
|
<iconset theme="shortcut">
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -41,6 +42,9 @@
|
|||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include "FileIgnoreProxy.h"
|
#include "FileIgnoreProxy.h"
|
||||||
|
#include "QObjectPtr.h"
|
||||||
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
#include "ui_ExportInstanceDialog.h"
|
#include "ui_ExportInstanceDialog.h"
|
||||||
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
@ -104,20 +108,14 @@ void SaveIcon(InstancePtr m_instance)
|
|||||||
auto& image = mmcIcon->m_images[mmcIcon->type()];
|
auto& image = mmcIcon->m_images[mmcIcon->type()];
|
||||||
auto& icon = image.icon;
|
auto& icon = image.icon;
|
||||||
auto sizes = icon.availableSizes();
|
auto sizes = icon.availableSizes();
|
||||||
if(sizes.size() == 0)
|
if (sizes.size() == 0) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto areaOf = [](QSize size)
|
auto areaOf = [](QSize size) { return size.width() * size.height(); };
|
||||||
{
|
|
||||||
return size.width() * size.height();
|
|
||||||
};
|
|
||||||
QSize largest = sizes[0];
|
QSize largest = sizes[0];
|
||||||
// find variant with largest area
|
// find variant with largest area
|
||||||
for(auto size: sizes)
|
for (auto size : sizes) {
|
||||||
{
|
if (areaOf(largest) < areaOf(size)) {
|
||||||
if(areaOf(largest) < areaOf(size))
|
|
||||||
{
|
|
||||||
largest = size;
|
largest = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,16 +123,15 @@ void SaveIcon(InstancePtr m_instance)
|
|||||||
pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
|
pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExportInstanceDialog::doExport()
|
void ExportInstanceDialog::doExport()
|
||||||
{
|
{
|
||||||
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
|
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
|
||||||
|
|
||||||
const QString output = QFileDialog::getSaveFileName(
|
const QString output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(m_instance->name()),
|
||||||
this, tr("Export %1").arg(m_instance->name()),
|
|
||||||
FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr);
|
FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr);
|
||||||
if (output.isEmpty())
|
if (output.isEmpty()) {
|
||||||
{
|
QDialog::done(QDialog::Rejected);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveIcon(m_instance);
|
SaveIcon(m_instance);
|
||||||
@ -143,46 +140,40 @@ bool ExportInstanceDialog::doExport()
|
|||||||
if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
|
if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
|
||||||
std::bind(&FileIgnoreProxy::filterFile, proxyModel, std::placeholders::_1))) {
|
std::bind(&FileIgnoreProxy::filterFile, proxyModel, std::placeholders::_1))) {
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||||
return false;
|
QDialog::done(QDialog::Rejected);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MMCZip::compressDirFiles(output, m_instance->instanceRoot(), files, true))
|
auto task = makeShared<MMCZip::ExportToZipTask>(output, m_instance->instanceRoot(), files, "", true);
|
||||||
{
|
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
connect(task.get(), &Task::failed, this,
|
||||||
return false;
|
[this, output](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||||
}
|
connect(task.get(), &Task::finished, this, [task] { task->deleteLater(); });
|
||||||
return true;
|
|
||||||
|
ProgressDialog progress(this);
|
||||||
|
progress.setSkipButton(true, tr("Abort"));
|
||||||
|
auto result = progress.execWithTask(task.get());
|
||||||
|
QDialog::done(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportInstanceDialog::done(int result)
|
void ExportInstanceDialog::done(int result)
|
||||||
{
|
{
|
||||||
savePackIgnore();
|
savePackIgnore();
|
||||||
if (result == QDialog::Accepted)
|
if (result == QDialog::Accepted) {
|
||||||
{
|
doExport();
|
||||||
if (doExport())
|
|
||||||
{
|
|
||||||
QDialog::done(QDialog::Accepted);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QDialog::done(result);
|
QDialog::done(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom)
|
void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom)
|
||||||
{
|
{
|
||||||
// WARNING: possible off-by-one?
|
// WARNING: possible off-by-one?
|
||||||
for(int i = top; i < bottom; i++)
|
for (int i = top; i < bottom; i++) {
|
||||||
{
|
|
||||||
auto node = proxyModel->index(i, 0, parent);
|
auto node = proxyModel->index(i, 0, parent);
|
||||||
if(proxyModel->shouldExpand(node))
|
if (proxyModel->shouldExpand(node)) {
|
||||||
{
|
|
||||||
auto expNode = node.parent();
|
auto expNode = node.parent();
|
||||||
if(!expNode.isValid())
|
if (!expNode.isValid()) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ui->treeView->expand(node);
|
ui->treeView->expand(node);
|
||||||
@ -199,8 +190,7 @@ void ExportInstanceDialog::loadPackIgnore()
|
|||||||
{
|
{
|
||||||
auto filename = ignoreFileName();
|
auto filename = ignoreFileName();
|
||||||
QFile ignoreFile(filename);
|
QFile ignoreFile(filename);
|
||||||
if(!ignoreFile.open(QIODevice::ReadOnly))
|
if (!ignoreFile.open(QIODevice::ReadOnly)) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto data = ignoreFile.readAll();
|
auto data = ignoreFile.readAll();
|
||||||
@ -216,12 +206,9 @@ void ExportInstanceDialog::savePackIgnore()
|
|||||||
{
|
{
|
||||||
auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
|
auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
|
||||||
auto filename = ignoreFileName();
|
auto filename = ignoreFileName();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
FS::write(filename, data);
|
FS::write(filename, data);
|
||||||
}
|
} catch (const Exception& e) {
|
||||||
catch (const Exception &e)
|
|
||||||
{
|
|
||||||
qWarning() << e.cause();
|
qWarning() << e.cause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -38,19 +39,17 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "FileIgnoreProxy.h"
|
|
||||||
#include "FastFileIconProvider.h"
|
#include "FastFileIconProvider.h"
|
||||||
|
#include "FileIgnoreProxy.h"
|
||||||
|
|
||||||
class BaseInstance;
|
class BaseInstance;
|
||||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui {
|
||||||
{
|
|
||||||
class ExportInstanceDialog;
|
class ExportInstanceDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExportInstanceDialog : public QDialog
|
class ExportInstanceDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -60,7 +59,7 @@ public:
|
|||||||
virtual void done(int result);
|
virtual void done(int result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool doExport();
|
void doExport();
|
||||||
void loadPackIgnore();
|
void loadPackIgnore();
|
||||||
void savePackIgnore();
|
void savePackIgnore();
|
||||||
QString ignoreFileName();
|
QString ignoreFileName();
|
||||||
|
223
launcher/ui/dialogs/ExportToModListDialog.cpp
Normal file
223
launcher/ui/dialogs/ExportToModListDialog.cpp
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ExportToModListDialog.h"
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "Markdown.h"
|
||||||
|
#include "minecraft/MinecraftInstance.h"
|
||||||
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
#include "modplatform/helpers/ExportToModList.h"
|
||||||
|
#include "ui_ExportToModListDialog.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
const QHash<ExportToModList::Formats, QString> ExportToModListDialog::exampleLines = {
|
||||||
|
{ ExportToModList::HTML, "<li><a href=\"{url}\">{name}</a> [{version}] by {authors}</li>" },
|
||||||
|
{ ExportToModList::MARKDOWN, "[{name}]({url}) [{version}] by {authors}" },
|
||||||
|
{ ExportToModList::PLAINTXT, "{name} ({url}) [{version}] by {authors}" },
|
||||||
|
{ ExportToModList::JSON, "{\"name\":\"{name}\",\"url\":\"{url}\",\"version\":\"{version}\",\"authors\":\"{authors}\"}," },
|
||||||
|
{ ExportToModList::CSV, "{name},{url},{version},\"{authors}\"" },
|
||||||
|
};
|
||||||
|
|
||||||
|
ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* parent)
|
||||||
|
: QDialog(parent), m_template_changed(false), name(instance->name()), ui(new Ui::ExportToModListDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
enableCustom(false);
|
||||||
|
|
||||||
|
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
||||||
|
if (mcInstance) {
|
||||||
|
mcInstance->loaderModList()->update();
|
||||||
|
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, [this, mcInstance]() {
|
||||||
|
m_allMods = mcInstance->loaderModList()->allMods();
|
||||||
|
triggerImp();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(ui->formatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ExportToModListDialog::formatChanged);
|
||||||
|
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
|
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
|
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
|
connect(ui->authorsButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Authors); });
|
||||||
|
connect(ui->versionButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Version); });
|
||||||
|
connect(ui->urlButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Url); });
|
||||||
|
connect(ui->templateText, &QTextEdit::textChanged, this, [this] {
|
||||||
|
if (ui->templateText->toPlainText() != exampleLines[format])
|
||||||
|
ui->formatComboBox->setCurrentIndex(5);
|
||||||
|
else
|
||||||
|
triggerImp();
|
||||||
|
});
|
||||||
|
connect(ui->copyButton, &QPushButton::clicked, this, [this](bool) {
|
||||||
|
this->ui->finalText->selectAll();
|
||||||
|
this->ui->finalText->copy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ExportToModListDialog::~ExportToModListDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportToModListDialog::formatChanged(int index)
|
||||||
|
{
|
||||||
|
switch (index) {
|
||||||
|
case 0: {
|
||||||
|
enableCustom(false);
|
||||||
|
ui->resultText->show();
|
||||||
|
format = ExportToModList::HTML;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
enableCustom(false);
|
||||||
|
ui->resultText->show();
|
||||||
|
format = ExportToModList::MARKDOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
enableCustom(false);
|
||||||
|
ui->resultText->hide();
|
||||||
|
format = ExportToModList::PLAINTXT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
enableCustom(false);
|
||||||
|
ui->resultText->hide();
|
||||||
|
format = ExportToModList::JSON;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
|
enableCustom(false);
|
||||||
|
ui->resultText->hide();
|
||||||
|
format = ExportToModList::CSV;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5: {
|
||||||
|
m_template_changed = true;
|
||||||
|
enableCustom(true);
|
||||||
|
ui->resultText->hide();
|
||||||
|
format = ExportToModList::CUSTOM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
triggerImp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportToModListDialog::triggerImp()
|
||||||
|
{
|
||||||
|
if (format == ExportToModList::CUSTOM) {
|
||||||
|
ui->finalText->setPlainText(ExportToModList::exportToModList(m_allMods, ui->templateText->toPlainText()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto opt = 0;
|
||||||
|
if (ui->authorsCheckBox->isChecked())
|
||||||
|
opt |= ExportToModList::Authors;
|
||||||
|
if (ui->versionCheckBox->isChecked())
|
||||||
|
opt |= ExportToModList::Version;
|
||||||
|
if (ui->urlCheckBox->isChecked())
|
||||||
|
opt |= ExportToModList::Url;
|
||||||
|
auto txt = ExportToModList::exportToModList(m_allMods, format, static_cast<ExportToModList::OptionalData>(opt));
|
||||||
|
ui->finalText->setPlainText(txt);
|
||||||
|
switch (format) {
|
||||||
|
case ExportToModList::CUSTOM:
|
||||||
|
return;
|
||||||
|
case ExportToModList::HTML:
|
||||||
|
ui->resultText->setHtml(txt);
|
||||||
|
break;
|
||||||
|
case ExportToModList::MARKDOWN:
|
||||||
|
ui->resultText->setHtml(markdownToHTML(txt));
|
||||||
|
break;
|
||||||
|
case ExportToModList::PLAINTXT:
|
||||||
|
break;
|
||||||
|
case ExportToModList::JSON:
|
||||||
|
break;
|
||||||
|
case ExportToModList::CSV:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto exampleLine = exampleLines[format];
|
||||||
|
if (!m_template_changed && ui->templateText->toPlainText() != exampleLine)
|
||||||
|
ui->templateText->setPlainText(exampleLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportToModListDialog::done(int result)
|
||||||
|
{
|
||||||
|
if (result == Accepted) {
|
||||||
|
const QString filename = FS::RemoveInvalidFilenameChars(name);
|
||||||
|
const QString output =
|
||||||
|
QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + extension()),
|
||||||
|
"File (*.txt *.html *.md *.json *.csv)", nullptr);
|
||||||
|
|
||||||
|
if (output.isEmpty())
|
||||||
|
return;
|
||||||
|
FS::write(output, ui->finalText->toPlainText().toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialog::done(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ExportToModListDialog::extension()
|
||||||
|
{
|
||||||
|
switch (format) {
|
||||||
|
case ExportToModList::HTML:
|
||||||
|
return ".html";
|
||||||
|
case ExportToModList::MARKDOWN:
|
||||||
|
return ".md";
|
||||||
|
case ExportToModList::PLAINTXT:
|
||||||
|
return ".txt";
|
||||||
|
case ExportToModList::CUSTOM:
|
||||||
|
return ".txt";
|
||||||
|
case ExportToModList::JSON:
|
||||||
|
return ".json";
|
||||||
|
case ExportToModList::CSV:
|
||||||
|
return ".csv";
|
||||||
|
}
|
||||||
|
return ".txt";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportToModListDialog::addExtra(ExportToModList::OptionalData option)
|
||||||
|
{
|
||||||
|
if (format != ExportToModList::CUSTOM)
|
||||||
|
return;
|
||||||
|
switch (option) {
|
||||||
|
case ExportToModList::Authors:
|
||||||
|
ui->templateText->insertPlainText("{authors}");
|
||||||
|
break;
|
||||||
|
case ExportToModList::Url:
|
||||||
|
ui->templateText->insertPlainText("{url}");
|
||||||
|
break;
|
||||||
|
case ExportToModList::Version:
|
||||||
|
ui->templateText->insertPlainText("{version}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ExportToModListDialog::enableCustom(bool enabled)
|
||||||
|
{
|
||||||
|
ui->authorsCheckBox->setHidden(enabled);
|
||||||
|
ui->versionCheckBox->setHidden(enabled);
|
||||||
|
ui->urlCheckBox->setHidden(enabled);
|
||||||
|
|
||||||
|
ui->authorsButton->setHidden(!enabled);
|
||||||
|
ui->versionButton->setHidden(!enabled);
|
||||||
|
ui->urlButton->setHidden(!enabled);
|
||||||
|
}
|
55
launcher/ui/dialogs/ExportToModListDialog.h
Normal file
55
launcher/ui/dialogs/ExportToModListDialog.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QList>
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
#include "minecraft/mod/Mod.h"
|
||||||
|
#include "modplatform/helpers/ExportToModList.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ExportToModListDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExportToModListDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ExportToModListDialog(InstancePtr instance, QWidget* parent = nullptr);
|
||||||
|
~ExportToModListDialog();
|
||||||
|
|
||||||
|
void done(int result) override;
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void formatChanged(int index);
|
||||||
|
void triggerImp();
|
||||||
|
void trigger(int) { triggerImp(); };
|
||||||
|
void addExtra(ExportToModList::OptionalData option);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString extension();
|
||||||
|
void enableCustom(bool enabled);
|
||||||
|
QList<Mod*> m_allMods;
|
||||||
|
bool m_template_changed;
|
||||||
|
QString name;
|
||||||
|
ExportToModList::Formats format = ExportToModList::Formats::HTML;
|
||||||
|
Ui::ExportToModListDialog* ui;
|
||||||
|
static const QHash<ExportToModList::Formats, QString> exampleLines;
|
||||||
|
};
|
240
launcher/ui/dialogs/ExportToModListDialog.ui
Normal file
240
launcher/ui/dialogs/ExportToModListDialog.ui
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ExportToModListDialog</class>
|
||||||
|
<widget class="QDialog" name="ExportToModListDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>650</width>
|
||||||
|
<height>446</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Export Pack to ModList</string>
|
||||||
|
</property>
|
||||||
|
<property name="sizeGripEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
|
<property name="title">
|
||||||
|
<string>Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="formatComboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>HTML</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Markdown</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Plaintext</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>JSON</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>CSV</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QGroupBox" name="templateGroup">
|
||||||
|
<property name="title">
|
||||||
|
<string>Template</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="templateText"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QGroupBox" name="optionsGroup">
|
||||||
|
<property name="title">
|
||||||
|
<string>Optional Info</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="versionCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Version</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="authorsCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Authors</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="urlCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>URL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="versionButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Version</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="authorsButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Authors</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="urlButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>URL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Plain</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Format</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_4">
|
||||||
|
<property name="title">
|
||||||
|
<string>Result</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="finalText">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>143</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="resultText">
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="warningLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>This depends on the mods' metadata. To ensure it is available, run an update on the instance. Installing the updates isn't necessary.</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="copyButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ExportToModListDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>334</x>
|
||||||
|
<y>435</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>324</x>
|
||||||
|
<y>206</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ExportToModListDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>324</x>
|
||||||
|
<y>390</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>324</x>
|
||||||
|
<y>206</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -48,7 +48,6 @@
|
|||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
|
|
||||||
#include "VisualGroup.h"
|
#include "VisualGroup.h"
|
||||||
#include "ui/themes/ThemeManager.h"
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@ -504,7 +503,7 @@ void InstanceView::setPaintCat(bool visible)
|
|||||||
{
|
{
|
||||||
m_catVisible = visible;
|
m_catVisible = visible;
|
||||||
if (visible)
|
if (visible)
|
||||||
m_catPixmap.load(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage()));
|
m_catPixmap.load(APPLICATION->getCatPack());
|
||||||
else
|
else
|
||||||
m_catPixmap = QPixmap();
|
m_catPixmap = QPixmap();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2023 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -35,22 +36,18 @@
|
|||||||
|
|
||||||
#include "VisualGroup.h"
|
#include "VisualGroup.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QApplication>
|
#include <utility>
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "InstanceView.h"
|
#include "InstanceView.h"
|
||||||
|
|
||||||
VisualGroup::VisualGroup(const QString &text, InstanceView *view) : view(view), text(text), collapsed(false)
|
VisualGroup::VisualGroup(QString text, InstanceView* view) : view(view), text(std::move(text)), collapsed(false) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VisualGroup::VisualGroup(const VisualGroup *other)
|
VisualGroup::VisualGroup(const VisualGroup* other) : view(other->view), text(other->text), collapsed(other->collapsed) {}
|
||||||
: view(other->view), text(other->text), collapsed(other->collapsed)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualGroup::update()
|
void VisualGroup::update()
|
||||||
{
|
{
|
||||||
@ -64,10 +61,8 @@ void VisualGroup::update()
|
|||||||
int positionInRow = 0;
|
int positionInRow = 0;
|
||||||
int currentRow = 0;
|
int currentRow = 0;
|
||||||
int offsetFromTop = 0;
|
int offsetFromTop = 0;
|
||||||
for (auto item: temp_items)
|
for (auto item : temp_items) {
|
||||||
{
|
if (positionInRow == itemsPerRow) {
|
||||||
if(positionInRow == itemsPerRow)
|
|
||||||
{
|
|
||||||
rows[currentRow].height = maxRowHeight;
|
rows[currentRow].height = maxRowHeight;
|
||||||
rows[currentRow].top = offsetFromTop;
|
rows[currentRow].top = offsetFromTop;
|
||||||
currentRow++;
|
currentRow++;
|
||||||
@ -83,8 +78,7 @@ void VisualGroup::update()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
|
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
|
||||||
if(itemHeight > maxRowHeight)
|
if (itemHeight > maxRowHeight) {
|
||||||
{
|
|
||||||
maxRowHeight = itemHeight;
|
maxRowHeight = itemHeight;
|
||||||
}
|
}
|
||||||
rows[currentRow].items.append(item);
|
rows[currentRow].items.append(item);
|
||||||
@ -97,12 +91,9 @@ void VisualGroup::update()
|
|||||||
QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const
|
QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (auto & row: rows)
|
for (auto& row : rows) {
|
||||||
{
|
for (auto x = 0; x < row.items.size(); x++) {
|
||||||
for(auto x = 0; x < row.items.size(); x++)
|
if (row.items[x] == index) {
|
||||||
{
|
|
||||||
if(row.items[x] == index)
|
|
||||||
{
|
|
||||||
return qMakePair(x, y);
|
return qMakePair(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,169 +120,85 @@ VisualGroup::HitResults VisualGroup::hitScan(const QPoint &pos) const
|
|||||||
VisualGroup::HitResults results = VisualGroup::NoHit;
|
VisualGroup::HitResults results = VisualGroup::NoHit;
|
||||||
int y_start = verticalPosition();
|
int y_start = verticalPosition();
|
||||||
int body_start = y_start + headerHeight();
|
int body_start = y_start + headerHeight();
|
||||||
int body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
|
int body_end = body_start + contentHeight();
|
||||||
int y = pos.y();
|
int y = pos.y();
|
||||||
// int x = pos.x();
|
// int x = pos.x();
|
||||||
if (y < y_start)
|
if (y < y_start) {
|
||||||
{
|
|
||||||
results = VisualGroup::NoHit;
|
results = VisualGroup::NoHit;
|
||||||
}
|
} else if (y < body_start) {
|
||||||
else if (y < body_start)
|
|
||||||
{
|
|
||||||
results = VisualGroup::HeaderHit;
|
results = VisualGroup::HeaderHit;
|
||||||
int collapseSize = headerHeight() - 4;
|
int collapseSize = headerHeight() - 4;
|
||||||
|
|
||||||
// the icon
|
// the icon
|
||||||
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y_start, collapseSize, collapseSize);
|
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y_start, view->width() - 4, collapseSize);
|
||||||
if (iconRect.contains(pos))
|
if (iconRect.contains(pos)) {
|
||||||
{
|
|
||||||
results |= VisualGroup::CheckboxHit;
|
results |= VisualGroup::CheckboxHit;
|
||||||
}
|
}
|
||||||
}
|
} else if (y < body_end) {
|
||||||
else if (y < body_end)
|
|
||||||
{
|
|
||||||
results |= VisualGroup::BodyHit;
|
results |= VisualGroup::BodyHit;
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualGroup::drawHeader(QPainter *painter, const QStyleOptionViewItem &option)
|
void VisualGroup::drawHeader(QPainter* painter, const QStyleOptionViewItem& option) const
|
||||||
{
|
{
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
QRect optRect = option.rect;
|
||||||
|
optRect.setTop(optRect.top() + 7);
|
||||||
const QRect optRect = option.rect;
|
|
||||||
QFont font(QApplication::font());
|
QFont font(QApplication::font());
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
const QFontMetrics fontMetrics = QFontMetrics(font);
|
const QFontMetrics fontMetrics = QFontMetrics(font);
|
||||||
|
|
||||||
QColor outlineColor = option.palette.text().color();
|
|
||||||
outlineColor.setAlphaF(0.35);
|
|
||||||
|
|
||||||
//BEGIN: top left corner
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
painter->setPen(outlineColor);
|
|
||||||
const QPointF topLeft(optRect.topLeft());
|
|
||||||
QRectF arc(topLeft, QSizeF(4, 4));
|
|
||||||
arc.translate(0.5, 0.5);
|
|
||||||
painter->drawArc(arc, 1440, 1440);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
//END: top left corner
|
|
||||||
|
|
||||||
//BEGIN: left vertical line
|
|
||||||
{
|
|
||||||
QPoint start(optRect.topLeft());
|
|
||||||
start.ry() += 3;
|
|
||||||
QPoint verticalGradBottom(optRect.topLeft());
|
|
||||||
verticalGradBottom.ry() += fontMetrics.height() + 5;
|
|
||||||
QLinearGradient gradient(start, verticalGradBottom);
|
|
||||||
gradient.setColorAt(0, outlineColor);
|
|
||||||
gradient.setColorAt(1, Qt::transparent);
|
|
||||||
painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
|
|
||||||
}
|
|
||||||
//END: left vertical line
|
|
||||||
|
|
||||||
//BEGIN: horizontal line
|
|
||||||
{
|
|
||||||
QPoint start(optRect.topLeft());
|
|
||||||
start.rx() += 3;
|
|
||||||
QPoint horizontalGradTop(optRect.topLeft());
|
|
||||||
horizontalGradTop.rx() += optRect.width() - 6;
|
|
||||||
painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor);
|
|
||||||
}
|
|
||||||
//END: horizontal line
|
|
||||||
|
|
||||||
//BEGIN: top right corner
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
painter->setPen(outlineColor);
|
|
||||||
QPointF topRight(optRect.topRight());
|
|
||||||
topRight.rx() -= 4;
|
|
||||||
QRectF arc(topRight, QSizeF(4, 4));
|
|
||||||
arc.translate(0.5, 0.5);
|
|
||||||
painter->drawArc(arc, 0, 1440);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
//END: top right corner
|
|
||||||
|
|
||||||
//BEGIN: right vertical line
|
|
||||||
{
|
|
||||||
QPoint start(optRect.topRight());
|
|
||||||
start.ry() += 3;
|
|
||||||
QPoint verticalGradBottom(optRect.topRight());
|
|
||||||
verticalGradBottom.ry() += fontMetrics.height() + 5;
|
|
||||||
QLinearGradient gradient(start, verticalGradBottom);
|
|
||||||
gradient.setColorAt(0, outlineColor);
|
|
||||||
gradient.setColorAt(1, Qt::transparent);
|
|
||||||
painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
|
|
||||||
}
|
|
||||||
//END: right vertical line
|
|
||||||
|
|
||||||
//BEGIN: checkboxy thing
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
QColor penColor(option.palette.text().color());
|
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(2);
|
||||||
|
QColor penColor = option.palette.text().color();
|
||||||
penColor.setAlphaF(0.6);
|
penColor.setAlphaF(0.6);
|
||||||
painter->setPen(penColor);
|
pen.setColor(penColor);
|
||||||
QRect iconSubRect(option.rect);
|
painter->setPen(pen);
|
||||||
iconSubRect.setTop(iconSubRect.top() + 7);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
iconSubRect.setLeft(iconSubRect.left() + 7);
|
|
||||||
|
|
||||||
int sizing = fontMetrics.height();
|
// sizes and offsets, to keep things consistent below
|
||||||
int even = ( (sizing - 1) % 2 );
|
int arrowOffsetLeft = fontMetrics.height() / 2 + 7;
|
||||||
|
int textOffsetLeft = arrowOffsetLeft * 2;
|
||||||
|
int arrowSize = 6;
|
||||||
|
int centerHeight = optRect.top() + fontMetrics.height() / 2;
|
||||||
|
|
||||||
iconSubRect.setHeight(sizing - even);
|
// BEGIN: arrow
|
||||||
iconSubRect.setWidth(sizing - even);
|
|
||||||
painter->drawRect(iconSubRect);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(collapsed)
|
|
||||||
painter->drawText(iconSubRect, Qt::AlignHCenter | Qt::AlignVCenter, "+");
|
|
||||||
else
|
|
||||||
painter->drawText(iconSubRect, Qt::AlignHCenter | Qt::AlignVCenter, "-");
|
|
||||||
*/
|
|
||||||
painter->setBrush(option.palette.text());
|
|
||||||
painter->fillRect(iconSubRect.x(), iconSubRect.y() + iconSubRect.height() / 2,
|
|
||||||
iconSubRect.width(), 2, penColor);
|
|
||||||
if (collapsed)
|
|
||||||
{
|
{
|
||||||
painter->fillRect(iconSubRect.x() + iconSubRect.width() / 2, iconSubRect.y(), 2,
|
QPolygon arrowPolygon;
|
||||||
iconSubRect.height(), penColor);
|
if (collapsed) {
|
||||||
|
arrowPolygon << QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight - arrowSize)
|
||||||
|
<< QPoint(arrowOffsetLeft + arrowSize / 2, centerHeight)
|
||||||
|
<< QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight + arrowSize);
|
||||||
|
painter->drawPolyline(arrowPolygon);
|
||||||
|
} else {
|
||||||
|
arrowPolygon << QPoint(arrowOffsetLeft - arrowSize, centerHeight - arrowSize / 2)
|
||||||
|
<< QPoint(arrowOffsetLeft, centerHeight + arrowSize / 2)
|
||||||
|
<< QPoint(arrowOffsetLeft + arrowSize, centerHeight - arrowSize / 2);
|
||||||
|
painter->drawPolyline(arrowPolygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
//END: checkboxy thing
|
// END: arrow
|
||||||
|
|
||||||
// BEGIN: text
|
// BEGIN: text
|
||||||
{
|
{
|
||||||
QRect textRect(option.rect);
|
QRect textRect(optRect);
|
||||||
textRect.setTop(textRect.top() + 7);
|
textRect.setTop(textRect.top());
|
||||||
textRect.setLeft(textRect.left() + 7 + fontMetrics.height() + 7);
|
textRect.setLeft(textOffsetLeft);
|
||||||
textRect.setHeight(fontMetrics.height());
|
textRect.setHeight(fontMetrics.height());
|
||||||
textRect.setRight(textRect.right() - 7);
|
textRect.setRight(textRect.right() - 7);
|
||||||
|
|
||||||
painter->save();
|
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, !text.isEmpty() ? text : QObject::tr("Ungrouped"));
|
||||||
painter->setFont(font);
|
|
||||||
QColor penColor(option.palette.text().color());
|
|
||||||
penColor.setAlphaF(0.6);
|
|
||||||
painter->setPen(penColor);
|
|
||||||
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
// END: text
|
// END: text
|
||||||
}
|
}
|
||||||
|
|
||||||
int VisualGroup::totalHeight() const
|
int VisualGroup::totalHeight() const
|
||||||
{
|
{
|
||||||
return headerHeight() + 5 + contentHeight(); // FIXME: wtf is that '5'?
|
return headerHeight() + contentHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
int VisualGroup::headerHeight() const
|
int VisualGroup::headerHeight()
|
||||||
{
|
{
|
||||||
QFont font(QApplication::font());
|
QFont font(QApplication::font());
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
@ -311,8 +218,7 @@ int VisualGroup::headerHeight() const
|
|||||||
|
|
||||||
int VisualGroup::contentHeight() const
|
int VisualGroup::contentHeight() const
|
||||||
{
|
{
|
||||||
if (collapsed)
|
if (collapsed) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto last = rows[numRows() - 1];
|
auto last = rows[numRows() - 1];
|
||||||
@ -321,7 +227,7 @@ int VisualGroup::contentHeight() const
|
|||||||
|
|
||||||
int VisualGroup::numRows() const
|
int VisualGroup::numRows() const
|
||||||
{
|
{
|
||||||
return rows.size();
|
return (int)rows.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int VisualGroup::verticalPosition() const
|
int VisualGroup::verticalPosition() const
|
||||||
@ -332,11 +238,9 @@ int VisualGroup::verticalPosition() const
|
|||||||
QList<QModelIndex> VisualGroup::items() const
|
QList<QModelIndex> VisualGroup::items() const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices;
|
QList<QModelIndex> indices;
|
||||||
for (int i = 0; i < view->model()->rowCount(); ++i)
|
for (int i = 0; i < view->model()->rowCount(); ++i) {
|
||||||
{
|
|
||||||
const QModelIndex index = view->model()->index(i, 0);
|
const QModelIndex index = view->model()->index(i, 0);
|
||||||
if (index.data(InstanceViewRoles::GroupRole).toString() == text)
|
if (index.data(InstanceViewRoles::GroupRole).toString() == text) {
|
||||||
{
|
|
||||||
indices.append(index);
|
indices.append(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,24 @@
|
|||||||
/* Copyright 2013-2021 MultiMC Contributors
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (C) 2023 Tayou <git@tayou.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -42,8 +62,8 @@ struct VisualRow
|
|||||||
struct VisualGroup
|
struct VisualGroup
|
||||||
{
|
{
|
||||||
/* constructors */
|
/* constructors */
|
||||||
VisualGroup(const QString &text, InstanceView *view);
|
VisualGroup(QString text, InstanceView *view);
|
||||||
VisualGroup(const VisualGroup *other);
|
explicit VisualGroup(const VisualGroup *other);
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
InstanceView *view = nullptr;
|
InstanceView *view = nullptr;
|
||||||
@ -58,13 +78,13 @@ struct VisualGroup
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
/// draw the header at y-position.
|
/// draw the header at y-position.
|
||||||
void drawHeader(QPainter *painter, const QStyleOptionViewItem &option);
|
void drawHeader(QPainter *painter, const QStyleOptionViewItem &option) const;
|
||||||
|
|
||||||
/// height of the group, in total. includes a small bit of padding.
|
/// height of the group, in total. includes a small bit of padding.
|
||||||
int totalHeight() const;
|
int totalHeight() const;
|
||||||
|
|
||||||
/// height of the group header, in pixels
|
/// height of the group header, in pixels
|
||||||
int headerHeight() const;
|
static int headerHeight() ;
|
||||||
|
|
||||||
/// height of the group content, in pixels
|
/// height of the group content, in pixels
|
||||||
int contentHeight() const;
|
int contentHeight() const;
|
||||||
|
@ -159,19 +159,6 @@ void AccountListPage::on_actionAddMojang_triggered()
|
|||||||
|
|
||||||
void AccountListPage::on_actionAddMicrosoft_triggered()
|
void AccountListPage::on_actionAddMicrosoft_triggered()
|
||||||
{
|
{
|
||||||
if(BuildConfig.BUILD_PLATFORM == "osx64") {
|
|
||||||
CustomMessageBox::selectable(
|
|
||||||
this,
|
|
||||||
tr("Microsoft Accounts not available"),
|
|
||||||
//: %1 refers to the launcher itself
|
|
||||||
tr(
|
|
||||||
"Microsoft accounts are only usable on macOS 10.13 or newer, with fully updated %1.\n\n"
|
|
||||||
"Please update both your operating system and %1."
|
|
||||||
).arg(BuildConfig.LAUNCHER_DISPLAYNAME),
|
|
||||||
QMessageBox::Warning
|
|
||||||
)->exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MinecraftAccountPtr account = MSALoginDialog::newAccount(
|
MinecraftAccountPtr account = MSALoginDialog::newAccount(
|
||||||
this,
|
this,
|
||||||
tr("Please enter your Mojang account email and password to add your account.")
|
tr("Please enter your Mojang account email and password to add your account.")
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (c) 2022 dada513 <dada513@protonmail.com>
|
* Copyright (c) 2022 dada513 <dada513@protonmail.com>
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* PolyMC - Minecraft Launcher
|
||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
* Copyright (C) 2023 seth <getchoo at tuta dot io>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -99,6 +100,9 @@ void MinecraftPage::applySettings()
|
|||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
|
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
|
||||||
s->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked());
|
s->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked());
|
||||||
|
|
||||||
|
// Mod loader settings
|
||||||
|
s->set("DisableQuiltBeacon", ui->disableQuiltBeaconCheckBox->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftPage::loadSettings()
|
void MinecraftPage::loadSettings()
|
||||||
@ -137,6 +141,8 @@ void MinecraftPage::loadSettings()
|
|||||||
|
|
||||||
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
|
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
|
||||||
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
|
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
|
||||||
|
|
||||||
|
ui->disableQuiltBeaconCheckBox->setChecked(s->get("DisableQuiltBeacon").toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftPage::retranslate()
|
void MinecraftPage::retranslate()
|
||||||
|
@ -190,6 +190,25 @@
|
|||||||
<string>Tweaks</string>
|
<string>Tweaks</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_12">
|
<layout class="QVBoxLayout" name="verticalLayout_12">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="modLoaderSettingsGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Mod loader settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="disableQuiltBeaconCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disable Quilt Loader Beacon</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Disable Quilt loader's beacon for counting monthly active users</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="nativeLibWorkaroundGroupBox">
|
<widget class="QGroupBox" name="nativeLibWorkaroundGroupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* PolyMC - Minecraft Launcher
|
* PolyMC - Minecraft Launcher
|
||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2023 seth <getchoo at tuta dot io>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -50,9 +51,9 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "minecraft/auth/AccountList.h"
|
#include "minecraft/auth/AccountList.h"
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
#include "java/JavaInstallList.h"
|
#include "java/JavaInstallList.h"
|
||||||
#include "java/JavaUtils.h"
|
#include "java/JavaUtils.h"
|
||||||
#include "FileSystem.h"
|
|
||||||
|
|
||||||
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||||
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
||||||
@ -288,6 +289,14 @@ void InstanceSettingsPage::applySettings()
|
|||||||
m_settings->reset("InstanceAccountId");
|
m_settings->reset("InstanceAccountId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool overrideModLoaderSettings = ui->modLoaderSettingsGroupBox->isChecked();
|
||||||
|
m_settings->set("OverrideModLoaderSettings", overrideModLoaderSettings);
|
||||||
|
if (overrideModLoaderSettings) {
|
||||||
|
m_settings->set("DisableQuiltBeacon", ui->disableQuiltBeaconCheckBox->isChecked());
|
||||||
|
} else {
|
||||||
|
m_settings->reset("DisableQuiltBeacon");
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: This should probably be called by a signal instead
|
// FIXME: This should probably be called by a signal instead
|
||||||
m_instance->updateRuntimeContext();
|
m_instance->updateRuntimeContext();
|
||||||
}
|
}
|
||||||
@ -396,6 +405,10 @@ void InstanceSettingsPage::loadSettings()
|
|||||||
|
|
||||||
ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
|
ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
|
||||||
updateAccountsMenu();
|
updateAccountsMenu();
|
||||||
|
|
||||||
|
// Mod loader specific settings
|
||||||
|
ui->modLoaderSettingsGroupBox->setChecked(m_settings->get("OverrideModLoaderSettings").toBool());
|
||||||
|
ui->disableQuiltBeaconCheckBox->setChecked(m_settings->get("DisableQuiltBeacon").toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
||||||
|
@ -548,6 +548,31 @@
|
|||||||
<string>Miscellaneous</string>
|
<string>Miscellaneous</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="modLoaderSettingsGroupBox">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>Mod loader settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="VerticalLayout_16">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="disableQuiltBeaconCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disable Quilt Loader Beacon</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Disable Quilt loader's beacon for counting monthly active users</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="gameTimeGroupBox">
|
<widget class="QGroupBox" name="gameTimeGroupBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
@ -104,6 +104,7 @@ void ResourcePage::openedImpl()
|
|||||||
|
|
||||||
updateSelectionButton();
|
updateSelectionButton();
|
||||||
triggerSearch();
|
triggerSearch();
|
||||||
|
m_ui->searchEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool
|
auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -61,7 +61,7 @@ void ThemeWizardPage::updateIcons()
|
|||||||
void ThemeWizardPage::updateCat()
|
void ThemeWizardPage::updateCat()
|
||||||
{
|
{
|
||||||
qDebug() << "Setting Cat";
|
qDebug() << "Setting Cat";
|
||||||
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(ThemeManager::getCatImage())));
|
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->getCatPack())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeWizardPage::retranslate()
|
void ThemeWizardPage::retranslate()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
117
launcher/ui/themes/CatPack.cpp
Normal file
117
launcher/ui/themes/CatPack.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "Json.h"
|
||||||
|
|
||||||
|
QString BasicCatPack::path()
|
||||||
|
{
|
||||||
|
const auto now = QDate::currentDate();
|
||||||
|
const auto birthday = QDate(now.year(), 11, 30);
|
||||||
|
const auto xmas = QDate(now.year(), 12, 25);
|
||||||
|
const auto halloween = QDate(now.year(), 10, 31);
|
||||||
|
|
||||||
|
QString cat = QString(":/backgrounds/%1").arg(m_id);
|
||||||
|
if (std::abs(now.daysTo(xmas)) <= 4) {
|
||||||
|
cat += "-xmas";
|
||||||
|
} else if (std::abs(now.daysTo(halloween)) <= 4) {
|
||||||
|
cat += "-spooky";
|
||||||
|
} else if (std::abs(now.daysTo(birthday)) <= 12) {
|
||||||
|
cat += "-bday";
|
||||||
|
}
|
||||||
|
return cat;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonCatPack::PartialDate partialDate(QJsonObject date)
|
||||||
|
{
|
||||||
|
auto month = Json::ensureInteger(date, "month", 1);
|
||||||
|
if (month > 12)
|
||||||
|
month = 12;
|
||||||
|
else if (month <= 0)
|
||||||
|
month = 1;
|
||||||
|
auto day = Json::ensureInteger(date, "day", 1);
|
||||||
|
if (day > 31)
|
||||||
|
day = 31;
|
||||||
|
else if (day <= 0)
|
||||||
|
day = 1;
|
||||||
|
return { month, day };
|
||||||
|
};
|
||||||
|
|
||||||
|
JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.dir().dirName())
|
||||||
|
{
|
||||||
|
QString path = manifestInfo.path();
|
||||||
|
auto doc = Json::requireDocument(manifestInfo.absoluteFilePath(), "CatPack JSON file");
|
||||||
|
const auto root = doc.object();
|
||||||
|
m_name = Json::requireString(root, "name", "Catpack name");
|
||||||
|
m_defaultPath = FS::PathCombine(path, Json::requireString(root, "default", "Default Cat"));
|
||||||
|
auto variants = Json::ensureArray(root, "variants", QJsonArray(), "Catpack Variants");
|
||||||
|
for (auto v : variants) {
|
||||||
|
auto variant = Json::ensureObject(v, QJsonObject(), "Cat variant");
|
||||||
|
m_variants << Variant{ FS::PathCombine(path, Json::requireString(variant, "path", "Variant path")),
|
||||||
|
partialDate(Json::requireObject(variant, "startTime", "Variant startTime")),
|
||||||
|
partialDate(Json::requireObject(variant, "endTime", "Variant endTime")) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate ensureDay(int year, int month, int day)
|
||||||
|
{
|
||||||
|
QDate date(year, month, 1);
|
||||||
|
if (day > date.daysInMonth())
|
||||||
|
day = date.daysInMonth();
|
||||||
|
return QDate(year, month, day);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JsonCatPack::path()
|
||||||
|
{
|
||||||
|
const QDate now = QDate::currentDate();
|
||||||
|
for (auto var : m_variants) {
|
||||||
|
QDate startDate = ensureDay(now.year(), var.startTime.month, var.startTime.day);
|
||||||
|
QDate endDate = ensureDay(now.year(), var.endTime.month, var.endTime.day);
|
||||||
|
if (startDate > endDate) { // it's spans over multiple years
|
||||||
|
if (endDate <= now) // end date is in the past so jump one year into the future for endDate
|
||||||
|
endDate = endDate.addYears(1);
|
||||||
|
else // end date is in the future so jump one year into the past for startDate
|
||||||
|
startDate = startDate.addYears(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDate >= now && now >= endDate)
|
||||||
|
return var.path;
|
||||||
|
}
|
||||||
|
return m_defaultPath;
|
||||||
|
}
|
91
launcher/ui/themes/CatPack.h
Normal file
91
launcher/ui/themes/CatPack.h
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class CatPack {
|
||||||
|
public:
|
||||||
|
virtual ~CatPack() {}
|
||||||
|
virtual QString id() = 0;
|
||||||
|
virtual QString name() = 0;
|
||||||
|
virtual QString path() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BasicCatPack : public CatPack {
|
||||||
|
public:
|
||||||
|
BasicCatPack(QString id, QString name) : m_id(id), m_name(name) {}
|
||||||
|
BasicCatPack(QString id) : BasicCatPack(id, id) {}
|
||||||
|
virtual QString id() { return m_id; };
|
||||||
|
virtual QString name() { return m_name; };
|
||||||
|
virtual QString path();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_id;
|
||||||
|
QString m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileCatPack : public BasicCatPack {
|
||||||
|
public:
|
||||||
|
FileCatPack(QString id, QFileInfo& fileInfo) : BasicCatPack(id), m_path(fileInfo.absoluteFilePath()) {}
|
||||||
|
FileCatPack(QFileInfo& fileInfo) : FileCatPack(fileInfo.baseName(), fileInfo) {}
|
||||||
|
virtual QString path() { return m_path; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JsonCatPack : public BasicCatPack {
|
||||||
|
public:
|
||||||
|
struct PartialDate {
|
||||||
|
int month;
|
||||||
|
int day;
|
||||||
|
};
|
||||||
|
struct Variant {
|
||||||
|
QString path;
|
||||||
|
PartialDate startTime;
|
||||||
|
PartialDate endTime;
|
||||||
|
};
|
||||||
|
JsonCatPack(QFileInfo& manifestInfo);
|
||||||
|
virtual QString path();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_defaultPath;
|
||||||
|
QList<Variant> m_variants;
|
||||||
|
};
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -21,7 +21,10 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include "Exception.h"
|
||||||
#include "ui/themes/BrightTheme.h"
|
#include "ui/themes/BrightTheme.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
#include "ui/themes/CustomTheme.h"
|
#include "ui/themes/CustomTheme.h"
|
||||||
#include "ui/themes/DarkTheme.h"
|
#include "ui/themes/DarkTheme.h"
|
||||||
#include "ui/themes/SystemTheme.h"
|
#include "ui/themes/SystemTheme.h"
|
||||||
@ -32,6 +35,7 @@ ThemeManager::ThemeManager(MainWindow* mainWindow)
|
|||||||
{
|
{
|
||||||
m_mainWindow = mainWindow;
|
m_mainWindow = mainWindow;
|
||||||
initializeThemes();
|
initializeThemes();
|
||||||
|
initializeCatPacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Adds the Theme to the list of themes
|
/// @brief Adds the Theme to the list of themes
|
||||||
@ -40,7 +44,10 @@ ThemeManager::ThemeManager(MainWindow* mainWindow)
|
|||||||
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
|
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
|
||||||
{
|
{
|
||||||
QString id = theme->id();
|
QString id = theme->id();
|
||||||
|
if (m_themes.find(id) == m_themes.end())
|
||||||
m_themes.emplace(id, std::move(theme));
|
m_themes.emplace(id, std::move(theme));
|
||||||
|
else
|
||||||
|
themeWarningLog() << "Theme(" << id << ") not added to prevent id duplication";
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +84,7 @@ void ThemeManager::initializeThemes()
|
|||||||
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
||||||
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
||||||
|
|
||||||
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
while (directoryIterator.hasNext()) {
|
while (directoryIterator.hasNext()) {
|
||||||
QDir dir(directoryIterator.next());
|
QDir dir(directoryIterator.next());
|
||||||
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
||||||
@ -111,6 +118,16 @@ QList<ITheme*> ThemeManager::getValidApplicationThemes()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<CatPack*> ThemeManager::getValidCatPacks()
|
||||||
|
{
|
||||||
|
QList<CatPack*> ret;
|
||||||
|
ret.reserve(m_catPacks.size());
|
||||||
|
for (auto&& [id, theme] : m_catPacks) {
|
||||||
|
ret.append(theme.get());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeManager::setIconTheme(const QString& name)
|
void ThemeManager::setIconTheme(const QString& name)
|
||||||
{
|
{
|
||||||
QIcon::setThemeName(name);
|
QIcon::setThemeName(name);
|
||||||
@ -137,19 +154,74 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ThemeManager::getCatImage(QString catName)
|
QString ThemeManager::getCatPack(QString catName)
|
||||||
{
|
{
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
auto catIter = m_catPacks.find(!catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString());
|
||||||
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
|
if (catIter != m_catPacks.end()) {
|
||||||
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
|
auto& catPack = catIter->second;
|
||||||
QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
|
themeDebugLog() << "applying catpack" << catPack->id();
|
||||||
QString cat = !catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString();
|
return catPack->path();
|
||||||
if (std::abs(now.daysTo(xmas)) <= 4) {
|
} else {
|
||||||
cat += "-xmas";
|
themeWarningLog() << "Tried to get invalid catPack:" << catName;
|
||||||
} else if (std::abs(now.daysTo(halloween)) <= 4) {
|
}
|
||||||
cat += "-spooky";
|
|
||||||
} else if (std::abs(now.daysTo(birthday)) <= 12) {
|
return m_catPacks.begin()->second->path();
|
||||||
cat += "-bday";
|
}
|
||||||
|
|
||||||
|
QString ThemeManager::addCatPack(std::unique_ptr<CatPack> catPack)
|
||||||
|
{
|
||||||
|
QString id = catPack->id();
|
||||||
|
if (m_catPacks.find(id) == m_catPacks.end())
|
||||||
|
m_catPacks.emplace(id, std::move(catPack));
|
||||||
|
else
|
||||||
|
themeWarningLog() << "CatPack(" << id << ") not added to prevent id duplication";
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeManager::initializeCatPacks()
|
||||||
|
{
|
||||||
|
QList<std::pair<QString, QString>> defaultCats{ { "kitteh", QObject::tr("Background Cat (from MultiMC)") },
|
||||||
|
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
|
||||||
|
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
|
||||||
|
{ "teawie", QObject::tr("Teawie (drawn by SympathyTea)") } };
|
||||||
|
for (auto [id, name] : defaultCats) {
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new BasicCatPack(id, name)));
|
||||||
|
}
|
||||||
|
QDir catpacksDir("catpacks");
|
||||||
|
QString catpacksFolder = catpacksDir.absoluteFilePath("");
|
||||||
|
themeDebugLog() << "CatPacks Folder Path:" << catpacksFolder;
|
||||||
|
|
||||||
|
QStringList supportedImageFormats;
|
||||||
|
for (auto format : QImageReader::supportedImageFormats()) {
|
||||||
|
supportedImageFormats.append("*." + format);
|
||||||
|
}
|
||||||
|
auto loadFiles = [this, supportedImageFormats](QDir dir) {
|
||||||
|
// Load image files directly
|
||||||
|
QDirIterator ImageFileIterator(dir.absoluteFilePath(""), supportedImageFormats, QDir::Files);
|
||||||
|
while (ImageFileIterator.hasNext()) {
|
||||||
|
QFile customCatFile(ImageFileIterator.next());
|
||||||
|
QFileInfo customCatFileInfo(customCatFile);
|
||||||
|
themeDebugLog() << "Loading CatPack from:" << customCatFileInfo.absoluteFilePath();
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new FileCatPack(customCatFileInfo)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadFiles(catpacksDir);
|
||||||
|
|
||||||
|
QDirIterator directoryIterator(catpacksFolder, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
|
while (directoryIterator.hasNext()) {
|
||||||
|
QDir dir(directoryIterator.next());
|
||||||
|
QFileInfo manifest(dir.absoluteFilePath("catpack.json"));
|
||||||
|
if (manifest.isFile()) {
|
||||||
|
try {
|
||||||
|
// Load background manifest
|
||||||
|
themeDebugLog() << "Loading background manifest from:" << manifest.absoluteFilePath();
|
||||||
|
addCatPack(std::unique_ptr<CatPack>(new JsonCatPack(manifest)));
|
||||||
|
} catch (const Exception& e) {
|
||||||
|
themeWarningLog() << "Couldn't load catpack json:" << e.cause();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadFiles(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cat;
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,6 +20,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
|
#include "ui/themes/CatPack.h"
|
||||||
#include "ui/themes/ITheme.h"
|
#include "ui/themes/ITheme.h"
|
||||||
|
|
||||||
inline auto themeDebugLog()
|
inline auto themeDebugLog()
|
||||||
@ -40,18 +41,20 @@ class ThemeManager {
|
|||||||
void applyCurrentlySelectedTheme(bool initial = false);
|
void applyCurrentlySelectedTheme(bool initial = false);
|
||||||
void setApplicationTheme(const QString& name, bool initial = false);
|
void setApplicationTheme(const QString& name, bool initial = false);
|
||||||
|
|
||||||
/// <summary>
|
/// @brief Returns the background based on selected and with events (Birthday, XMas, etc.)
|
||||||
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
/// @param catName Optional, if you need a specific background.
|
||||||
/// </summary>
|
/// @return
|
||||||
/// <param name="catName">Optional, if you need a specific cat.</param>
|
QString getCatPack(QString catName = "");
|
||||||
/// <returns></returns>
|
QList<CatPack*> getValidCatPacks();
|
||||||
static QString getCatImage(QString catName = "");
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||||
|
std::map<QString, std::unique_ptr<CatPack>> m_catPacks;
|
||||||
MainWindow* m_mainWindow;
|
MainWindow* m_mainWindow;
|
||||||
|
|
||||||
void initializeThemes();
|
void initializeThemes();
|
||||||
|
void initializeCatPacks();
|
||||||
QString addTheme(std::unique_ptr<ITheme> theme);
|
QString addTheme(std::unique_ptr<ITheme> theme);
|
||||||
ITheme* getTheme(QString themeId);
|
ITheme* getTheme(QString themeId);
|
||||||
|
QString addCatPack(std::unique_ptr<CatPack> catPack);
|
||||||
};
|
};
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include "LanguageSelectionWidget.h"
|
#include "LanguageSelectionWidget.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QCheckBox>
|
||||||
#include <QTreeView>
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QTreeView>
|
||||||
|
#include <QVBoxLayout>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "translations/TranslationsModel.h"
|
|
||||||
#include "settings/Setting.h"
|
#include "settings/Setting.h"
|
||||||
|
#include "translations/TranslationsModel.h"
|
||||||
|
|
||||||
LanguageSelectionWidget::LanguageSelectionWidget(QWidget *parent) :
|
LanguageSelectionWidget::LanguageSelectionWidget(QWidget* parent) : QWidget(parent)
|
||||||
QWidget(parent)
|
|
||||||
{
|
{
|
||||||
verticalLayout = new QVBoxLayout(this);
|
verticalLayout = new QVBoxLayout(this);
|
||||||
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
||||||
@ -31,6 +31,13 @@ LanguageSelectionWidget::LanguageSelectionWidget(QWidget *parent) :
|
|||||||
helpUsLabel->setWordWrap(true);
|
helpUsLabel->setWordWrap(true);
|
||||||
verticalLayout->addWidget(helpUsLabel);
|
verticalLayout->addWidget(helpUsLabel);
|
||||||
|
|
||||||
|
formatCheckbox = new QCheckBox(this);
|
||||||
|
formatCheckbox->setObjectName(QStringLiteral("formatCheckbox"));
|
||||||
|
formatCheckbox->setCheckState(APPLICATION->settings()->get("UseSystemLocale").toBool() ? Qt::Checked : Qt::Unchecked);
|
||||||
|
connect(formatCheckbox, &QCheckBox::stateChanged,
|
||||||
|
[this]() { APPLICATION->translations()->setUseSystemLocale(formatCheckbox->isChecked()); });
|
||||||
|
verticalLayout->addWidget(formatCheckbox);
|
||||||
|
|
||||||
auto translations = APPLICATION->translations();
|
auto translations = APPLICATION->translations();
|
||||||
auto index = translations->selectedIndex();
|
auto index = translations->selectedIndex();
|
||||||
languageView->setModel(translations.get());
|
languageView->setModel(translations.get());
|
||||||
@ -55,13 +62,12 @@ void LanguageSelectionWidget::retranslate()
|
|||||||
QString text = tr("Don't see your language or the quality is poor?<br/><a href=\"%1\">Help us with translations!</a>")
|
QString text = tr("Don't see your language or the quality is poor?<br/><a href=\"%1\">Help us with translations!</a>")
|
||||||
.arg(BuildConfig.TRANSLATIONS_URL);
|
.arg(BuildConfig.TRANSLATIONS_URL);
|
||||||
helpUsLabel->setText(text);
|
helpUsLabel->setText(text);
|
||||||
|
formatCheckbox->setText(tr("Use system locales"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguageSelectionWidget::languageRowChanged(const QModelIndex& current, const QModelIndex& previous)
|
void LanguageSelectionWidget::languageRowChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
{
|
{
|
||||||
if (current == previous)
|
if (current == previous) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto translations = APPLICATION->translations();
|
auto translations = APPLICATION->translations();
|
||||||
|
@ -21,9 +21,9 @@ class QVBoxLayout;
|
|||||||
class QTreeView;
|
class QTreeView;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class Setting;
|
class Setting;
|
||||||
|
class QCheckBox;
|
||||||
|
|
||||||
class LanguageSelectionWidget: public QWidget
|
class LanguageSelectionWidget : public QWidget {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LanguageSelectionWidget(QWidget* parent = 0);
|
explicit LanguageSelectionWidget(QWidget* parent = 0);
|
||||||
@ -40,4 +40,5 @@ private:
|
|||||||
QVBoxLayout* verticalLayout = nullptr;
|
QVBoxLayout* verticalLayout = nullptr;
|
||||||
QTreeView* languageView = nullptr;
|
QTreeView* languageView = nullptr;
|
||||||
QLabel* helpUsLabel = nullptr;
|
QLabel* helpUsLabel = nullptr;
|
||||||
|
QCheckBox* formatCheckbox = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -95,9 +95,14 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index) {
|
|||||||
emit currentWidgetThemeChanged(index);
|
emit currentWidgetThemeChanged(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeCustomizationWidget::applyCatTheme(int index) {
|
void ThemeCustomizationWidget::applyCatTheme(int index)
|
||||||
|
{
|
||||||
auto settings = APPLICATION->settings();
|
auto settings = APPLICATION->settings();
|
||||||
settings->set("BackgroundCat", m_catOptions[index].first);
|
auto originalCat = settings->get("BackgroundCat").toString();
|
||||||
|
auto newCat = ui->backgroundCatComboBox->currentData().toString();
|
||||||
|
if (originalCat != newCat) {
|
||||||
|
settings->set("BackgroundCat", newCat);
|
||||||
|
}
|
||||||
|
|
||||||
emit currentCatChanged(index);
|
emit currentCatChanged(index);
|
||||||
}
|
}
|
||||||
@ -135,10 +140,10 @@ void ThemeCustomizationWidget::loadSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto cat = settings->get("BackgroundCat").toString();
|
auto cat = settings->get("BackgroundCat").toString();
|
||||||
for (auto& catFromList : m_catOptions) {
|
for (auto& catFromList : APPLICATION->getValidCatPacks()) {
|
||||||
QIcon catIcon = QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first)));
|
QIcon catIcon = QIcon(QString("%1").arg(catFromList->path()));
|
||||||
ui->backgroundCatComboBox->addItem(catIcon, catFromList.second);
|
ui->backgroundCatComboBox->addItem(catIcon, catFromList->name(), catFromList->id());
|
||||||
if (cat == catFromList.first) {
|
if (cat == catFromList->id()) {
|
||||||
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -54,8 +54,7 @@ class ThemeCustomizationWidget : public QWidget {
|
|||||||
Ui::ThemeCustomizationWidget* ui;
|
Ui::ThemeCustomizationWidget* ui;
|
||||||
|
|
||||||
// TODO finish implementing
|
// TODO finish implementing
|
||||||
QList<std::pair<QString, QString>> m_iconThemeOptions{
|
QList<std::pair<QString, QString>> m_iconThemeOptions{ { "pe_colored", QObject::tr("Simple (Colored Icons)") },
|
||||||
{ "pe_colored", QObject::tr("Simple (Colored Icons)") },
|
|
||||||
{ "pe_light", QObject::tr("Simple (Light Icons)") },
|
{ "pe_light", QObject::tr("Simple (Light Icons)") },
|
||||||
{ "pe_dark", QObject::tr("Simple (Dark Icons)") },
|
{ "pe_dark", QObject::tr("Simple (Dark Icons)") },
|
||||||
{ "pe_blue", QObject::tr("Simple (Blue Icons)") },
|
{ "pe_blue", QObject::tr("Simple (Blue Icons)") },
|
||||||
@ -66,12 +65,5 @@ class ThemeCustomizationWidget : public QWidget {
|
|||||||
{ "flat", QObject::tr("Flat") },
|
{ "flat", QObject::tr("Flat") },
|
||||||
{ "flat_white", QObject::tr("Flat (White)") },
|
{ "flat_white", QObject::tr("Flat (White)") },
|
||||||
{ "multimc", QObject::tr("Legacy") },
|
{ "multimc", QObject::tr("Legacy") },
|
||||||
{ "custom", QObject::tr("Custom") }
|
{ "custom", QObject::tr("Custom") } };
|
||||||
};
|
|
||||||
QList<std::pair<QString, QString>> m_catOptions{
|
|
||||||
{ "kitteh", QObject::tr("Background Cat (from MultiMC)") },
|
|
||||||
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
|
|
||||||
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
|
|
||||||
{ "teawie", QObject::tr("Teawie (drawn by SympathyTea)") }
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
@ -42,6 +42,10 @@ class LinkTask : public Task {
|
|||||||
m_lnk->debug(true);
|
m_lnk->debug(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~LinkTask() {
|
||||||
|
delete m_lnk;
|
||||||
|
}
|
||||||
|
|
||||||
void matcher(const IPathMatcher *filter)
|
void matcher(const IPathMatcher *filter)
|
||||||
{
|
{
|
||||||
m_lnk->matcher(filter);
|
m_lnk->matcher(filter);
|
||||||
@ -219,7 +223,8 @@ slots:
|
|||||||
qDebug() << tempDir.path();
|
qDebug() << tempDir.path();
|
||||||
qDebug() << target_dir.path();
|
qDebug() << target_dir.path();
|
||||||
FS::copy c(folder, target_dir.path());
|
FS::copy c(folder, target_dir.path());
|
||||||
c.matcher(new RegexpMatcher("[.]?mcmeta"));
|
RegexpMatcher re("[.]?mcmeta");
|
||||||
|
c.matcher(&re);
|
||||||
c();
|
c();
|
||||||
|
|
||||||
for(auto entry: target_dir.entryList())
|
for(auto entry: target_dir.entryList())
|
||||||
@ -253,7 +258,8 @@ slots:
|
|||||||
qDebug() << tempDir.path();
|
qDebug() << tempDir.path();
|
||||||
qDebug() << target_dir.path();
|
qDebug() << target_dir.path();
|
||||||
FS::copy c(folder, target_dir.path());
|
FS::copy c(folder, target_dir.path());
|
||||||
c.matcher(new RegexpMatcher("[.]?mcmeta"));
|
RegexpMatcher re("[.]?mcmeta");
|
||||||
|
c.matcher(&re);
|
||||||
c.whitelist(true);
|
c.whitelist(true);
|
||||||
c();
|
c();
|
||||||
|
|
||||||
@ -460,7 +466,8 @@ slots:
|
|||||||
qDebug() << target_dir.path();
|
qDebug() << target_dir.path();
|
||||||
|
|
||||||
LinkTask lnk_tsk(folder, target_dir.path());
|
LinkTask lnk_tsk(folder, target_dir.path());
|
||||||
lnk_tsk.matcher(new RegexpMatcher("[.]?mcmeta"));
|
RegexpMatcher re("[.]?mcmeta");
|
||||||
|
lnk_tsk.matcher(&re);
|
||||||
lnk_tsk.linkRecursively(true);
|
lnk_tsk.linkRecursively(true);
|
||||||
QObject::connect(&lnk_tsk, &Task::finished, [&]{
|
QObject::connect(&lnk_tsk, &Task::finished, [&]{
|
||||||
QVERIFY2(lnk_tsk.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
QVERIFY2(lnk_tsk.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
||||||
@ -511,7 +518,8 @@ slots:
|
|||||||
qDebug() << target_dir.path();
|
qDebug() << target_dir.path();
|
||||||
|
|
||||||
LinkTask lnk_tsk(folder, target_dir.path());
|
LinkTask lnk_tsk(folder, target_dir.path());
|
||||||
lnk_tsk.matcher(new RegexpMatcher("[.]?mcmeta"));
|
RegexpMatcher re("[.]?mcmeta");
|
||||||
|
lnk_tsk.matcher(&re);
|
||||||
lnk_tsk.linkRecursively(true);
|
lnk_tsk.linkRecursively(true);
|
||||||
lnk_tsk.whitelist(true);
|
lnk_tsk.whitelist(true);
|
||||||
QObject::connect(&lnk_tsk, &Task::finished, [&]{
|
QObject::connect(&lnk_tsk, &Task::finished, [&]{
|
||||||
|
@ -38,6 +38,7 @@ class DummyResourceModel : public ResourceModel {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
DummyResourceModel() : ResourceModel(new DummyResourceAPI) {}
|
DummyResourceModel() : ResourceModel(new DummyResourceAPI) {}
|
||||||
|
~DummyResourceModel() {}
|
||||||
|
|
||||||
[[nodiscard]] auto metaEntryBase() const -> QString override { return ""; };
|
[[nodiscard]] auto metaEntryBase() const -> QString override { return ""; };
|
||||||
|
|
||||||
@ -58,7 +59,10 @@ class DummyResourceModel : public ResourceModel {
|
|||||||
class ResourceModelTest : public QObject {
|
class ResourceModelTest : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void test_abstract_item_model() { [[maybe_unused]] auto tester = new QAbstractItemModelTester(new DummyResourceModel); }
|
void test_abstract_item_model() {
|
||||||
|
auto dummy = DummyResourceModel();
|
||||||
|
auto tester = QAbstractItemModelTester(&dummy);
|
||||||
|
}
|
||||||
|
|
||||||
void test_search()
|
void test_search()
|
||||||
{
|
{
|
||||||
@ -78,6 +82,8 @@ class ResourceModelTest : public QObject {
|
|||||||
QVERIFY(processed_pack->addonId.toString() == Json::requireString(processed_response, "project_id"));
|
QVERIFY(processed_pack->addonId.toString() == Json::requireString(processed_response, "project_id"));
|
||||||
QVERIFY(processed_pack->description == Json::requireString(processed_response, "description"));
|
QVERIFY(processed_pack->description == Json::requireString(processed_response, "description"));
|
||||||
QVERIFY(processed_pack->authors.first().name == Json::requireString(processed_response, "author"));
|
QVERIFY(processed_pack->authors.first().name == Json::requireString(processed_response, "author"));
|
||||||
|
|
||||||
|
delete model;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QTimer>
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <tasks/ConcurrentTask.h>
|
#include <tasks/ConcurrentTask.h>
|
||||||
#include <tasks/MultipleOptionsTask.h>
|
#include <tasks/MultipleOptionsTask.h>
|
||||||
@ -19,10 +19,7 @@ class BasicTask : public Task {
|
|||||||
BasicTask(bool show_debug_log = true) : Task(nullptr, show_debug_log) {}
|
BasicTask(bool show_debug_log = true) : Task(nullptr, show_debug_log) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void executeTask() override
|
void executeTask() override { emitSucceeded(); };
|
||||||
{
|
|
||||||
emitSucceeded();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Does nothing. Only used for testing. */
|
/* Does nothing. Only used for testing. */
|
||||||
@ -53,47 +50,40 @@ class BigConcurrentTask : public ConcurrentTask {
|
|||||||
class BigConcurrentTaskThread : public QThread {
|
class BigConcurrentTaskThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
BigConcurrentTask big_task;
|
QTimer m_deadline;
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
QTimer deadline;
|
BigConcurrentTask big_task;
|
||||||
deadline.setInterval(10000);
|
m_deadline.setInterval(10000);
|
||||||
connect(&deadline, &QTimer::timeout, this, [this]{ passed_the_deadline = true; });
|
|
||||||
deadline.start();
|
|
||||||
|
|
||||||
// NOTE: Arbitrary value that manages to trigger a problem when there is one.
|
// NOTE: Arbitrary value that manages to trigger a problem when there is one.
|
||||||
// Considering each tasks, in a problematic state, adds 1024 * 4 bytes to the stack,
|
// Considering each tasks, in a problematic state, adds 1024 * 4 bytes to the stack,
|
||||||
// this number is enough to fill up 16 MiB of stack, more than enough to cause a problem.
|
// this number is enough to fill up 16 MiB of stack, more than enough to cause a problem.
|
||||||
static const unsigned s_num_tasks = 1 << 12;
|
static const unsigned s_num_tasks = 1 << 12;
|
||||||
auto sub_tasks = new BasicTask::Ptr[s_num_tasks];
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < s_num_tasks; i++) {
|
for (unsigned i = 0; i < s_num_tasks; i++) {
|
||||||
auto sub_task = makeShared<BasicTask>(false);
|
auto sub_task = makeShared<BasicTask>(false);
|
||||||
sub_tasks[i] = sub_task;
|
|
||||||
big_task.addTask(sub_task);
|
big_task.addTask(sub_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(&big_task, &Task::finished, this, &QThread::quit);
|
||||||
|
connect(&m_deadline, &QTimer::timeout, this, [&] { passed_the_deadline = true; quit(); });
|
||||||
|
|
||||||
|
m_deadline.start();
|
||||||
big_task.run();
|
big_task.run();
|
||||||
|
|
||||||
while (!big_task.isFinished() && !passed_the_deadline)
|
exec();
|
||||||
QCoreApplication::processEvents();
|
|
||||||
|
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool passed_the_deadline = false;
|
bool passed_the_deadline = false;
|
||||||
|
|
||||||
signals:
|
|
||||||
void finished();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TaskTest : public QObject {
|
class TaskTest : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void test_SetStatus_NoMultiStep(){
|
void test_SetStatus_NoMultiStep()
|
||||||
|
{
|
||||||
BasicTask t;
|
BasicTask t;
|
||||||
QString status{ "test status" };
|
QString status{ "test status" };
|
||||||
|
|
||||||
@ -103,7 +93,8 @@ class TaskTest : public QObject {
|
|||||||
QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
|
QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_SetStatus_MultiStep(){
|
void test_SetStatus_MultiStep()
|
||||||
|
{
|
||||||
BasicTask_MultiStep t;
|
BasicTask_MultiStep t;
|
||||||
QString status{ "test status" };
|
QString status{ "test status" };
|
||||||
|
|
||||||
@ -115,7 +106,8 @@ class TaskTest : public QObject {
|
|||||||
QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
|
QCOMPARE(t.getStepProgress().isEmpty(), TaskStepProgressList{}.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_SetProgress(){
|
void test_SetProgress()
|
||||||
|
{
|
||||||
BasicTask t;
|
BasicTask t;
|
||||||
int current = 42;
|
int current = 42;
|
||||||
int total = 207;
|
int total = 207;
|
||||||
@ -126,17 +118,18 @@ class TaskTest : public QObject {
|
|||||||
QCOMPARE(t.getTotalProgress(), total);
|
QCOMPARE(t.getTotalProgress(), total);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_basicRun(){
|
void test_basicRun()
|
||||||
|
{
|
||||||
BasicTask t;
|
BasicTask t;
|
||||||
QObject::connect(&t, &Task::finished, [&]{ QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been."); });
|
QObject::connect(&t, &Task::finished,
|
||||||
|
[&] { QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been."); });
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
QVERIFY2(QTest::qWaitFor([&]() {
|
QVERIFY2(QTest::qWaitFor([&]() { return t.isFinished(); }, 1000), "Task didn't finish as it should.");
|
||||||
return t.isFinished();
|
|
||||||
}, 1000), "Task didn't finish as it should.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_basicConcurrentRun(){
|
void test_basicConcurrentRun()
|
||||||
|
{
|
||||||
auto t1 = makeShared<BasicTask>();
|
auto t1 = makeShared<BasicTask>();
|
||||||
auto t2 = makeShared<BasicTask>();
|
auto t2 = makeShared<BasicTask>();
|
||||||
auto t3 = makeShared<BasicTask>();
|
auto t3 = makeShared<BasicTask>();
|
||||||
@ -147,7 +140,7 @@ class TaskTest : public QObject {
|
|||||||
t.addTask(t2);
|
t.addTask(t2);
|
||||||
t.addTask(t3);
|
t.addTask(t3);
|
||||||
|
|
||||||
QObject::connect(&t, &Task::finished, [&]{
|
QObject::connect(&t, &Task::finished, [&t, &t1, &t2, &t3] {
|
||||||
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
||||||
QVERIFY(t1->wasSuccessful());
|
QVERIFY(t1->wasSuccessful());
|
||||||
QVERIFY(t2->wasSuccessful());
|
QVERIFY(t2->wasSuccessful());
|
||||||
@ -155,13 +148,12 @@ class TaskTest : public QObject {
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
QVERIFY2(QTest::qWaitFor([&]() {
|
QVERIFY2(QTest::qWaitFor([&]() { return t.isFinished(); }, 1000), "Task didn't finish as it should.");
|
||||||
return t.isFinished();
|
|
||||||
}, 1000), "Task didn't finish as it should.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests if starting new tasks after the 6 initial ones is working
|
// Tests if starting new tasks after the 6 initial ones is working
|
||||||
void test_moreConcurrentRun(){
|
void test_moreConcurrentRun()
|
||||||
|
{
|
||||||
auto t1 = makeShared<BasicTask>();
|
auto t1 = makeShared<BasicTask>();
|
||||||
auto t2 = makeShared<BasicTask>();
|
auto t2 = makeShared<BasicTask>();
|
||||||
auto t3 = makeShared<BasicTask>();
|
auto t3 = makeShared<BasicTask>();
|
||||||
@ -184,7 +176,7 @@ class TaskTest : public QObject {
|
|||||||
t.addTask(t8);
|
t.addTask(t8);
|
||||||
t.addTask(t9);
|
t.addTask(t9);
|
||||||
|
|
||||||
QObject::connect(&t, &Task::finished, [&]{
|
QObject::connect(&t, &Task::finished, [&t, &t1, &t2, &t3, &t4, &t5, &t6, &t7, &t8, &t9] {
|
||||||
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
||||||
QVERIFY(t1->wasSuccessful());
|
QVERIFY(t1->wasSuccessful());
|
||||||
QVERIFY(t2->wasSuccessful());
|
QVERIFY(t2->wasSuccessful());
|
||||||
@ -198,12 +190,11 @@ class TaskTest : public QObject {
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
QVERIFY2(QTest::qWaitFor([&]() {
|
QVERIFY2(QTest::qWaitFor([&]() { return t.isFinished(); }, 1000), "Task didn't finish as it should.");
|
||||||
return t.isFinished();
|
|
||||||
}, 1000), "Task didn't finish as it should.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_basicSequentialRun(){
|
void test_basicSequentialRun()
|
||||||
|
{
|
||||||
auto t1 = makeShared<BasicTask>();
|
auto t1 = makeShared<BasicTask>();
|
||||||
auto t2 = makeShared<BasicTask>();
|
auto t2 = makeShared<BasicTask>();
|
||||||
auto t3 = makeShared<BasicTask>();
|
auto t3 = makeShared<BasicTask>();
|
||||||
@ -214,7 +205,7 @@ class TaskTest : public QObject {
|
|||||||
t.addTask(t2);
|
t.addTask(t2);
|
||||||
t.addTask(t3);
|
t.addTask(t3);
|
||||||
|
|
||||||
QObject::connect(&t, &Task::finished, [&]{
|
QObject::connect(&t, &Task::finished, [&t, &t1, &t2, &t3] {
|
||||||
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
||||||
QVERIFY(t1->wasSuccessful());
|
QVERIFY(t1->wasSuccessful());
|
||||||
QVERIFY(t2->wasSuccessful());
|
QVERIFY(t2->wasSuccessful());
|
||||||
@ -222,12 +213,11 @@ class TaskTest : public QObject {
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
QVERIFY2(QTest::qWaitFor([&]() {
|
QVERIFY2(QTest::qWaitFor([&]() { return t.isFinished(); }, 1000), "Task didn't finish as it should.");
|
||||||
return t.isFinished();
|
|
||||||
}, 1000), "Task didn't finish as it should.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_basicMultipleOptionsRun(){
|
void test_basicMultipleOptionsRun()
|
||||||
|
{
|
||||||
auto t1 = makeShared<BasicTask>();
|
auto t1 = makeShared<BasicTask>();
|
||||||
auto t2 = makeShared<BasicTask>();
|
auto t2 = makeShared<BasicTask>();
|
||||||
auto t3 = makeShared<BasicTask>();
|
auto t3 = makeShared<BasicTask>();
|
||||||
@ -238,7 +228,7 @@ class TaskTest : public QObject {
|
|||||||
t.addTask(t2);
|
t.addTask(t2);
|
||||||
t.addTask(t3);
|
t.addTask(t3);
|
||||||
|
|
||||||
QObject::connect(&t, &Task::finished, [&]{
|
QObject::connect(&t, &Task::finished, [&t, &t1, &t2, &t3] {
|
||||||
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been.");
|
||||||
QVERIFY(t1->wasSuccessful());
|
QVERIFY(t1->wasSuccessful());
|
||||||
QVERIFY(!t2->wasSuccessful());
|
QVERIFY(!t2->wasSuccessful());
|
||||||
@ -246,25 +236,22 @@ class TaskTest : public QObject {
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
QVERIFY2(QTest::qWaitFor([&]() {
|
QVERIFY2(QTest::qWaitFor([&]() { return t.isFinished(); }, 1000), "Task didn't finish as it should.");
|
||||||
return t.isFinished();
|
|
||||||
}, 1000), "Task didn't finish as it should.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_stackOverflowInConcurrentTask()
|
void test_stackOverflowInConcurrentTask()
|
||||||
{
|
{
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
auto thread = new BigConcurrentTaskThread;
|
BigConcurrentTaskThread thread;
|
||||||
|
|
||||||
connect(thread, &BigConcurrentTaskThread::finished, &loop, &QEventLoop::quit);
|
connect(&thread, &BigConcurrentTaskThread::finished, &loop, &QEventLoop::quit);
|
||||||
|
|
||||||
thread->start();
|
thread.start();
|
||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
QVERIFY(!thread->passed_the_deadline);
|
QVERIFY(!thread.passed_the_deadline);
|
||||||
thread->deleteLater();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
class VersionTest : public QObject {
|
class VersionTest : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
QStringList m_flex_test_names = {};
|
||||||
|
|
||||||
void addDataColumns()
|
void addDataColumns()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("first");
|
QTest::addColumn<QString>("first");
|
||||||
@ -101,8 +103,9 @@ class VersionTest : public QObject {
|
|||||||
QString first{split_line.first().simplified()};
|
QString first{split_line.first().simplified()};
|
||||||
QString second{split_line.last().simplified()};
|
QString second{split_line.last().simplified()};
|
||||||
|
|
||||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "lessThan").toLatin1().data();
|
auto new_test_name = test_name_template.arg(QString::number(test_number), "lessThan");
|
||||||
QTest::newRow(new_test_name) << first << second << true << false;
|
m_flex_test_names.append(new_test_name);
|
||||||
|
QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << true << false;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -112,8 +115,9 @@ class VersionTest : public QObject {
|
|||||||
QString first{split_line.first().simplified()};
|
QString first{split_line.first().simplified()};
|
||||||
QString second{split_line.last().simplified()};
|
QString second{split_line.last().simplified()};
|
||||||
|
|
||||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "equals").toLatin1().data();
|
auto new_test_name = test_name_template.arg(QString::number(test_number), "equals");
|
||||||
QTest::newRow(new_test_name) << first << second << false << true;
|
m_flex_test_names.append(new_test_name);
|
||||||
|
QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << false << true;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -123,8 +127,9 @@ class VersionTest : public QObject {
|
|||||||
QString first{split_line.first().simplified()};
|
QString first{split_line.first().simplified()};
|
||||||
QString second{split_line.last().simplified()};
|
QString second{split_line.last().simplified()};
|
||||||
|
|
||||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "greaterThan").toLatin1().data();
|
auto new_test_name = test_name_template.arg(QString::number(test_number), "greaterThan");
|
||||||
QTest::newRow(new_test_name) << first << second << false << false;
|
m_flex_test_names.append(new_test_name);
|
||||||
|
QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << false << false;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user