mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-15 16:37:15 +00:00
Compare commits
2 Commits
feature/of
...
0.5.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
170bd677fd | ||
|
|
84e23e2e7a |
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"project_id": "MultiMC5",
|
"project_id": "MultiMC5",
|
||||||
"conduit_uri": "http://ph.multimc.org"
|
"conduit_uri": "http://ph.multimc.org"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
UseTab: false
|
UseTab: true
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
|||||||
11
.github/ISSUE_TEMPLATE.md
vendored
11
.github/ISSUE_TEMPLATE.md
vendored
@@ -2,16 +2,15 @@
|
|||||||
Before submitting this issue, please make sure you have:
|
Before submitting this issue, please make sure you have:
|
||||||
|
|
||||||
1. Filled out this form completely, the only optional field is "additional info".
|
1. Filled out this form completely, the only optional field is "additional info".
|
||||||
- Use as many details as possible and state the problem clearly.
|
- Use as many details as possible and state the problem clearly.
|
||||||
2. Proof-read your ENTIRE issue report.
|
2. Proof-read your ENTIRE issue report.
|
||||||
- Grammar and spelling mistakes make issue reports harder to understand.
|
- Grammar and spelling mistakes make issue reports harder to understand.
|
||||||
3. Made sure your problem is not caused by an issue in your own modpack.
|
3. Made sure your problem is not caused by an issue in your own modpack.
|
||||||
- We provide support for MultiMC, not your modpack. Problems with your modpack will be ignored.
|
- We provide support for MultiMC, not your modpack. Problems with your modpack will be ignored.
|
||||||
4. Given the issue a descriptive title.
|
4. Given the issue a descriptive title.
|
||||||
- A good title includes a brief summary of the issue and avoids things such as "Help" and "What?!".
|
- A good title includes a brief summary of the issue and avoids things such as "Help" and "What?!".
|
||||||
Use of UPPERCASE is discouraged, as it reads like someone is screaming.
|
|
||||||
5. Place all information below the ---- of lines.
|
5. Place all information below the ---- of lines.
|
||||||
- It makes the issue look pretty
|
- It makes the issue look pretty
|
||||||
|
|
||||||
If you believe your issue to be a bug, please make sure you check the wiki page: https://github.com/MultiMC/MultiMC5/wiki/Report-a-Bug
|
If you believe your issue to be a bug, please make sure you check the wiki page: https://github.com/MultiMC/MultiMC5/wiki/Report-a-Bug
|
||||||
-->
|
-->
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -15,8 +15,6 @@ CMakeLists.txt.user
|
|||||||
CMakeLists.txt.user.*
|
CMakeLists.txt.user.*
|
||||||
/.project
|
/.project
|
||||||
/.settings
|
/.settings
|
||||||
/.idea
|
|
||||||
cmake-build-*/
|
|
||||||
|
|
||||||
# Build dirs
|
# Build dirs
|
||||||
build
|
build
|
||||||
|
|||||||
7
.gitmodules
vendored
7
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
|||||||
[submodule "depends/libnbtplusplus"]
|
[submodule "depends/libnbtplusplus"]
|
||||||
path = libraries/libnbtplusplus
|
path = libraries/libnbtplusplus
|
||||||
url = https://github.com/MultiMC/libnbtplusplus.git
|
url = https://github.com/MultiMC/libnbtplusplus.git
|
||||||
[submodule "libraries/quazip"]
|
|
||||||
path = libraries/quazip
|
|
||||||
url = https://github.com/MultiMC/quazip.git
|
|
||||||
|
|||||||
41
.travis.yml
41
.travis.yml
@@ -2,28 +2,29 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
cache: apt
|
cache: apt
|
||||||
|
|
||||||
|
# Build matrix set up
|
||||||
|
compiler:
|
||||||
|
- gcc
|
||||||
|
# - clang
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
# - osx
|
||||||
|
env:
|
||||||
|
- QT_VERSION=5.4.2
|
||||||
|
- QT_VERSION=5.5.1
|
||||||
|
# - QT_VERSION=5.6.2
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
exclude:
|
||||||
- os: linux
|
# only use clang on OS X
|
||||||
dist: precise
|
- os: osx
|
||||||
sudo: required
|
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
env: TRAVIS_DIST=precise QT_VERSION=5.4.2
|
# only use the qt available from homebrew
|
||||||
- os: linux
|
- os: osx
|
||||||
dist: precise
|
env: QT_VERSION=5.4.2
|
||||||
sudo: required
|
- os: osx
|
||||||
compiler: gcc
|
env: QT_VERSION=5.5.1
|
||||||
env: TRAVIS_DIST=precise QT_VERSION=5.6.2
|
# - os: osx
|
||||||
- os: linux
|
# env: QT_VERSION=5.6
|
||||||
dist: trusty
|
|
||||||
sudo: required
|
|
||||||
compiler: gcc
|
|
||||||
env: TRAVIS_DIST=trusty QT_VERSION=5.4.2
|
|
||||||
- os: linux
|
|
||||||
dist: trusty
|
|
||||||
sudo: required
|
|
||||||
compiler: gcc
|
|
||||||
env: TRAVIS_DIST=trusty QT_VERSION=5.6.2
|
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
install:
|
install:
|
||||||
|
|||||||
20
BUILD.md
20
BUILD.md
@@ -32,11 +32,11 @@ git submodule update
|
|||||||
Getting the project to build and run on Linux is easy if you use any modern and up-to-date linux distribution.
|
Getting the project to build and run on Linux is easy if you use any modern and up-to-date linux distribution.
|
||||||
|
|
||||||
## Build dependencies
|
## Build dependencies
|
||||||
* A C++ compiler capable of building C++11 code.
|
* Ideally a compiler capable of building C++14 code (for example, GCC 5.2 and above).
|
||||||
* Qt 5.6+ Development tools (http://qt-project.org/downloads) ("Qt Online Installer for Linux (64 bit)") or the equivalent from your package manager. It is always better to use the Qt from your distribution, as long as it has a new enough version.
|
* Qt 5.4.1+ Development tools (http://qt-project.org/downloads) ("Qt Online Installer for Linux (64 bit)") or the equivalent from your package manager. It is always better to use the Qt from your distribution.
|
||||||
* cmake 3.1 or newer
|
* cmake 3.1 or newer
|
||||||
* zlib (for example, `zlib1g-dev`)
|
* zlib (for example, `zlib1g-dev`)
|
||||||
* Java JDK 8 (for example, `openjdk-8-jdk`)
|
* java (for example, `openjdk-8-jdk`)
|
||||||
* GL headers (for example, `libgl1-mesa-dev`)
|
* GL headers (for example, `libgl1-mesa-dev`)
|
||||||
|
|
||||||
### Building from command line
|
### Building from command line
|
||||||
@@ -64,7 +64,7 @@ You can use IDEs like KDevelop or QtCreator to open the CMake project if you wan
|
|||||||
1. Run the Qt installer.
|
1. Run the Qt installer.
|
||||||
2. Choose a place to install Qt.
|
2. Choose a place to install Qt.
|
||||||
3. Choose the components you want to install.
|
3. Choose the components you want to install.
|
||||||
- You need Qt 5.6.x 64-bit ticked.
|
- You need Qt 5.4.1/gcc 64-bit ticked.
|
||||||
- You need Tools/Qt Creator ticked.
|
- You need Tools/Qt Creator ticked.
|
||||||
- Other components are selected by default, you can untick them if you don't need them.
|
- Other components are selected by default, you can untick them if you don't need them.
|
||||||
4. Accept the license agreements.
|
4. Accept the license agreements.
|
||||||
@@ -77,7 +77,7 @@ You can use IDEs like KDevelop or QtCreator to open the CMake project if you wan
|
|||||||
3. Navigate to the MultiMC5 source folder you cloned and choose CMakeLists.txt.
|
3. Navigate to the MultiMC5 source folder you cloned and choose CMakeLists.txt.
|
||||||
4. Read the instructions that just popped up about a build location and choose one.
|
4. Read the instructions that just popped up about a build location and choose one.
|
||||||
5. You should see "Run CMake" in the window.
|
5. You should see "Run CMake" in the window.
|
||||||
- Make sure that Generator is set to "Unix Generator (Desktop Qt 5.6.x GCC 64bit)".
|
- Make sure that Generator is set to "Unix Generator (Desktop Qt 5.4.1 GCC 64bit)".
|
||||||
- Hit the "Run CMake" button.
|
- Hit the "Run CMake" button.
|
||||||
- You'll see warnings and it might not be clear that it succeeded until you scroll to the bottom of the window.
|
- You'll see warnings and it might not be clear that it succeeded until you scroll to the bottom of the window.
|
||||||
- Hit "Finish" if CMake ran successfully.
|
- Hit "Finish" if CMake ran successfully.
|
||||||
@@ -91,13 +91,13 @@ You can use IDEs like KDevelop or QtCreator to open the CMake project if you wan
|
|||||||
Getting the project to build and run on Windows is easy if you use Qt's IDE, Qt Creator. The project will simply not compile using Microsoft build tools, because that's not something we do. If it does compile, it is by chance only.
|
Getting the project to build and run on Windows is easy if you use Qt's IDE, Qt Creator. The project will simply not compile using Microsoft build tools, because that's not something we do. If it does compile, it is by chance only.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
* [Qt 5.6+ Development tools](http://qt-project.org/downloads) -- Qt Online Installer for Windows
|
* [Qt 5.4.1+ Development tools](http://qt-project.org/downloads) -- Qt Online Installer for Windows
|
||||||
* [OpenSSL](http://slproweb.com/products/Win32OpenSSL.html) -- Newest Win32 OpenSSL Light
|
* [OpenSSL](http://slproweb.com/products/Win32OpenSSL.html) -- Newest Win32 OpenSSL Light
|
||||||
- Microsoft Visual C++ 2008 Redist is required for this, there's a link on the OpenSSL download page above next to the main download.
|
- Microsoft Visual C++ 2008 Redist is required for this, there's a link on the OpenSSL download page above next to the main download.
|
||||||
- We use a custom build of OpenSSL that doesn't have this dependency. For normal development, the custom build is not necessary though.
|
- We use a custom build of OpenSSL that doesn't have this dependency. For normal development, the custom build is not necessary though.
|
||||||
* [zlib 1.2+](http://gnuwin32.sourceforge.net/packages/zlib.htm) - the Setup is fine
|
* [zlib 1.2.8+](http://zlib.net/zlib128-dll.zip)
|
||||||
* [Java JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
|
|
||||||
* [CMake](http://www.cmake.org/cmake/resources/software.html) -- Windows (Win32 Installer)
|
* [CMake](http://www.cmake.org/cmake/resources/software.html) -- Windows (Win32 Installer)
|
||||||
|
* [patch.exe from the GnuWin project](http://gnuwin32.sourceforge.net/packages/patch.htm).
|
||||||
|
|
||||||
Put it somewhere on the `PATH`, so that it is accessible from the console.
|
Put it somewhere on the `PATH`, so that it is accessible from the console.
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ Getting the project to build and run on Windows is easy if you use Qt's IDE, Qt
|
|||||||
1. Run the Qt installer
|
1. Run the Qt installer
|
||||||
2. Choose a place to install Qt (C:\Qt is the default),
|
2. Choose a place to install Qt (C:\Qt is the default),
|
||||||
3. Choose the components you want to install
|
3. Choose the components you want to install
|
||||||
- You need Qt 5.6 (32 bit) ticked,
|
- You need Qt 5.4.1/MinGW 4.9 (32 bit) ticked,
|
||||||
- You need Tools/Qt Creator ticked,
|
- You need Tools/Qt Creator ticked,
|
||||||
- Other components are selected by default, you can untick them if you don't need them.
|
- Other components are selected by default, you can untick them if you don't need them.
|
||||||
4. Accept the license agreements,
|
4. Accept the license agreements,
|
||||||
@@ -132,7 +132,7 @@ Getting the project to build and run on Windows is easy if you use Qt's IDE, Qt
|
|||||||
5. If you chose not to add CMake to the system PATH, tell Qt Creator where you installed it,
|
5. If you chose not to add CMake to the system PATH, tell Qt Creator where you installed it,
|
||||||
- Otherwise you can skip this step.
|
- Otherwise you can skip this step.
|
||||||
6. You should see "Run CMake" in the window,
|
6. You should see "Run CMake" in the window,
|
||||||
- Make sure that Generator is set to "MinGW Generator (Desktop Qt 5.6.x MinGW 32bit)",
|
- Make sure that Generator is set to "MinGW Generator (Desktop Qt 5.4.1 MinGW 32bit)",
|
||||||
- Hit the "Run CMake" button,
|
- Hit the "Run CMake" button,
|
||||||
- You'll see warnings and it might not be clear that it succeeded until you scroll to the bottom of the window.
|
- You'll see warnings and it might not be clear that it succeeded until you scroll to the bottom of the window.
|
||||||
- Hit "Finish" if CMake ran successfully.
|
- Hit "Finish" if CMake ran successfully.
|
||||||
|
|||||||
216
CMakeLists.txt
216
CMakeLists.txt
@@ -2,18 +2,18 @@ cmake_minimum_required(VERSION 3.1)
|
|||||||
|
|
||||||
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
|
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
|
||||||
if(IS_IN_SOURCE_BUILD)
|
if(IS_IN_SOURCE_BUILD)
|
||||||
message(AUTHOR_WARNING "You are building MultiMC in-source. This is NOT recommended!")
|
message(AUTHOR_WARNING "You are building MultiMC in-source. This is NOT recommended!")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
|
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
|
||||||
cmake_policy(SET CMP0020 OLD)
|
cmake_policy(SET CMP0020 OLD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(MultiMC)
|
project(MultiMC)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
##################################### Set CMake options #####################################
|
######## Set CMake options ########
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
|
|||||||
# Output all executables and shared libs in the main build folder, not in subfolders.
|
# Output all executables and shared libs in the main build folder, not in subfolders.
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
|
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
|
||||||
|
|
||||||
@@ -32,61 +32,22 @@ set(CMAKE_C_STANDARD_REQUIRED true)
|
|||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
include(GenerateExportHeader)
|
include(GenerateExportHeader)
|
||||||
set(CMAKE_CXX_FLAGS " -Wall -pedantic -Werror -Wno-deprecated-declarations -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong --param=ssp-buffer-size=4 -O3 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS " -Wall -D_GLIBCXX_USE_CXX11_ABI=0 ${CMAKE_CXX_FLAGS}")
|
||||||
if(UNIX AND APPLE)
|
if(UNIX AND APPLE)
|
||||||
set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror=return-type")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror=return-type")
|
||||||
|
|
||||||
##################################### Set Application options #####################################
|
|
||||||
|
|
||||||
######## Set URLs ########
|
|
||||||
set(MultiMC_NEWS_RSS_URL "https://multimc.org/rss.xml" CACHE STRING "URL to fetch MultiMC's news RSS feed from.")
|
|
||||||
|
|
||||||
######## Set version numbers ########
|
|
||||||
set(MultiMC_VERSION_MAJOR 0)
|
|
||||||
set(MultiMC_VERSION_MINOR 6)
|
|
||||||
set(MultiMC_VERSION_HOTFIX 6)
|
|
||||||
|
|
||||||
# Build number
|
|
||||||
set(MultiMC_VERSION_BUILD -1 CACHE STRING "Build number. -1 for no build number.")
|
|
||||||
|
|
||||||
# Build platform.
|
|
||||||
set(MultiMC_BUILD_PLATFORM "" CACHE STRING "A short string identifying the platform that this build was built for. Only used by the notification system and to display in the about dialog.")
|
|
||||||
|
|
||||||
# Channel list URL
|
|
||||||
set(MultiMC_CHANLIST_URL "" CACHE STRING "URL for the channel list.")
|
|
||||||
|
|
||||||
# Notification URL
|
|
||||||
set(MultiMC_NOTIFICATION_URL "" CACHE STRING "URL for checking for notifications.")
|
|
||||||
|
|
||||||
# paste.ee API key
|
|
||||||
set(MultiMC_PASTE_EE_API_KEY "utLvciUouSURFzfjPxLBf5W4ISsUX4pwBDF7N1AfZ" CACHE STRING "API key you can get from paste.ee when you register an account")
|
|
||||||
|
|
||||||
# Google analytics ID
|
|
||||||
set(MultiMC_ANALYTICS_ID "UA-87731965-2" CACHE STRING "ID you can get from Google analytics")
|
|
||||||
|
|
||||||
#### Check the current Git commit and branch
|
|
||||||
include(GetGitRevisionDescription)
|
|
||||||
get_git_head_revision(MultiMC_GIT_REFSPEC MultiMC_GIT_COMMIT)
|
|
||||||
|
|
||||||
message(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
|
|
||||||
message(STATUS "Git refspec: ${MultiMC_GIT_REFSPEC}")
|
|
||||||
|
|
||||||
set(MultiMC_RELEASE_VERSION_NAME "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}")
|
|
||||||
|
|
||||||
#### Custom target to just print the version.
|
|
||||||
add_custom_target(version echo "Version: ${MultiMC_RELEASE_VERSION_NAME}")
|
|
||||||
|
|
||||||
################################ 3rd Party Libs ################################
|
################################ 3rd Party Libs ################################
|
||||||
|
|
||||||
# Find the required Qt parts
|
# Find the required Qt parts
|
||||||
find_package(Qt5Core REQUIRED)
|
find_package(Qt5Core)
|
||||||
find_package(Qt5Widgets REQUIRED)
|
find_package(Qt5Widgets)
|
||||||
find_package(Qt5Concurrent REQUIRED)
|
find_package(Qt5Concurrent)
|
||||||
find_package(Qt5Network REQUIRED)
|
find_package(Qt5Network)
|
||||||
find_package(Qt5Test REQUIRED)
|
find_package(Qt5Test)
|
||||||
find_package(Qt5Xml REQUIRED)
|
find_package(Qt5Xml)
|
||||||
|
|
||||||
# The Qt5 cmake files don't provide its install paths, so ask qmake.
|
# The Qt5 cmake files don't provide its install paths, so ask qmake.
|
||||||
include(QMakeQuery)
|
include(QMakeQuery)
|
||||||
@@ -101,143 +62,34 @@ if (Qt5_POSITION_INDEPENDENT_CODE)
|
|||||||
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
####################################### Install layout #######################################
|
|
||||||
|
|
||||||
# How to install the build results
|
|
||||||
set(MultiMC_LAYOUT "auto" CACHE STRING "The layout for MultiMC installation (auto, win-bundle, lin-bundle, lin-nodeps, lin-system, mac-bundle)")
|
|
||||||
set_property(CACHE MultiMC_LAYOUT PROPERTY STRINGS auto win-bundle lin-bundle lin-nodeps lin-system mac-bundle)
|
|
||||||
|
|
||||||
if(MultiMC_LAYOUT STREQUAL "auto")
|
|
||||||
if(UNIX AND APPLE)
|
|
||||||
set(MultiMC_LAYOUT_REAL "mac-bundle")
|
|
||||||
elseif(UNIX)
|
|
||||||
set(MultiMC_LAYOUT_REAL "lin-nodeps")
|
|
||||||
elseif(WIN32)
|
|
||||||
set(MultiMC_LAYOUT_REAL "win-bundle")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Cannot choose a sensible install layout for your platform.")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set(MultiMC_LAYOUT_REAL ${MultiMC_LAYOUT})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(MultiMC_LAYOUT_REAL STREQUAL "mac-bundle")
|
|
||||||
set(BINARY_DEST_DIR "MultiMC.app/Contents/MacOS")
|
|
||||||
set(LIBRARY_DEST_DIR "MultiMC.app/Contents/MacOS")
|
|
||||||
set(PLUGIN_DEST_DIR "MultiMC.app/Contents/MacOS")
|
|
||||||
set(RESOURCES_DEST_DIR "MultiMC.app/Contents/Resources")
|
|
||||||
set(JARS_DEST_DIR "MultiMC.app/Contents/MacOS/jars")
|
|
||||||
|
|
||||||
set(BUNDLE_DEST_DIR ".")
|
|
||||||
|
|
||||||
# Apps to bundle
|
|
||||||
set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.app")
|
|
||||||
|
|
||||||
# Mac bundle settings
|
|
||||||
set(MACOSX_BUNDLE_BUNDLE_NAME "MultiMC")
|
|
||||||
set(MACOSX_BUNDLE_INFO_STRING "MultiMC Minecraft launcher and management utility.")
|
|
||||||
set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.MultiMC5")
|
|
||||||
set(MACOSX_BUNDLE_BUNDLE_VERSION "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
|
|
||||||
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
|
|
||||||
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
|
|
||||||
set(MACOSX_BUNDLE_ICON_FILE MultiMC.icns)
|
|
||||||
set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2015-2019 MultiMC Contributors")
|
|
||||||
|
|
||||||
# directories to look for dependencies
|
|
||||||
set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
||||||
|
|
||||||
# install as bundle
|
|
||||||
set(INSTALL_BUNDLE "full")
|
|
||||||
|
|
||||||
# Add the icon
|
|
||||||
install(FILES application/resources/MultiMC.icns DESTINATION ${RESOURCES_DEST_DIR})
|
|
||||||
|
|
||||||
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-bundle")
|
|
||||||
set(BINARY_DEST_DIR "bin")
|
|
||||||
set(LIBRARY_DEST_DIR "bin")
|
|
||||||
set(PLUGIN_DEST_DIR "plugins")
|
|
||||||
set(BUNDLE_DEST_DIR ".")
|
|
||||||
set(RESOURCES_DEST_DIR ".")
|
|
||||||
set(JARS_DEST_DIR "bin/jars")
|
|
||||||
|
|
||||||
# Apps to bundle
|
|
||||||
set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/MultiMC")
|
|
||||||
|
|
||||||
# directories to look for dependencies
|
|
||||||
set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
||||||
|
|
||||||
# install as bundle
|
|
||||||
set(INSTALL_BUNDLE "full")
|
|
||||||
|
|
||||||
# Set RPATH
|
|
||||||
SET(MultiMC_BINARY_RPATH "$ORIGIN/")
|
|
||||||
|
|
||||||
# Install basic runner script
|
|
||||||
install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
|
|
||||||
|
|
||||||
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-nodeps")
|
|
||||||
set(BINARY_DEST_DIR "bin")
|
|
||||||
set(LIBRARY_DEST_DIR "bin")
|
|
||||||
set(PLUGIN_DEST_DIR "plugins")
|
|
||||||
set(BUNDLE_DEST_DIR ".")
|
|
||||||
set(RESOURCES_DEST_DIR ".")
|
|
||||||
set(JARS_DEST_DIR "bin/jars")
|
|
||||||
|
|
||||||
# install as bundle with no dependencies included
|
|
||||||
set(INSTALL_BUNDLE "nodeps")
|
|
||||||
|
|
||||||
# Set RPATH
|
|
||||||
SET(MultiMC_BINARY_RPATH "$ORIGIN/")
|
|
||||||
|
|
||||||
# Install basic runner script
|
|
||||||
install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
|
|
||||||
|
|
||||||
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-system")
|
|
||||||
set(MultiMC_APP_BINARY_NAME "multimc" CACHE STRING "Name of the MultiMC binary")
|
|
||||||
set(MultiMC_BINARY_DEST_DIR "bin" CACHE STRING "Path to the binary directory")
|
|
||||||
set(MultiMC_LIBRARY_DEST_DIR "lib${LIB_SUFFIX}" CACHE STRING "Path to the library directory")
|
|
||||||
set(MultiMC_SHARE_DEST_DIR "share/multimc" CACHE STRING "Path to the shared data directory")
|
|
||||||
set(JARS_DEST_DIR "${MultiMC_SHARE_DEST_DIR}/jars")
|
|
||||||
|
|
||||||
set(BINARY_DEST_DIR ${MultiMC_BINARY_DEST_DIR})
|
|
||||||
set(LIBRARY_DEST_DIR ${MultiMC_LIBRARY_DEST_DIR})
|
|
||||||
|
|
||||||
MESSAGE(STATUS "Compiling for linux system with ${MultiMC_SHARE_DEST_DIR} and MULTIMC_LINUX_DATADIR")
|
|
||||||
SET(MultiMC_APP_BINARY_DEFS "-DMULTIMC_JARS_LOCATION=${CMAKE_INSTALL_PREFIX}/${JARS_DEST_DIR}" "-DMULTIMC_LINUX_DATADIR")
|
|
||||||
|
|
||||||
# install as bundle with no dependencies included
|
|
||||||
set(INSTALL_BUNDLE "nodeps")
|
|
||||||
|
|
||||||
elseif(MultiMC_LAYOUT_REAL STREQUAL "win-bundle")
|
|
||||||
set(BINARY_DEST_DIR ".")
|
|
||||||
set(LIBRARY_DEST_DIR ".")
|
|
||||||
set(PLUGIN_DEST_DIR ".")
|
|
||||||
set(BUNDLE_DEST_DIR ".")
|
|
||||||
set(RESOURCES_DEST_DIR ".")
|
|
||||||
set(JARS_DEST_DIR "jars")
|
|
||||||
|
|
||||||
# Apps to bundle
|
|
||||||
set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.exe")
|
|
||||||
|
|
||||||
# directories to look for dependencies
|
|
||||||
set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
||||||
|
|
||||||
# install as bundle
|
|
||||||
set(INSTALL_BUNDLE "full")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "No sensible install layout set.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
################################ Included Libs ################################
|
################################ Included Libs ################################
|
||||||
|
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
set_directory_properties(PROPERTIES EP_BASE External)
|
set_directory_properties(PROPERTIES EP_BASE External)
|
||||||
|
|
||||||
|
# Add quazip
|
||||||
|
add_definitions(-DQUAZIP_STATIC)
|
||||||
|
set(QUAZIP_VERSION "0.7.1")
|
||||||
|
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/quazip-${QUAZIP_VERSION}.tar.gz)
|
||||||
|
file(DOWNLOAD http://downloads.sourceforge.net/project/quazip/quazip/${QUAZIP_VERSION}/quazip-${QUAZIP_VERSION}.tar.gz ${CMAKE_CURRENT_BINARY_DIR}/quazip-${QUAZIP_VERSION}.tar.gz)
|
||||||
|
endif()
|
||||||
|
ExternalProject_Add(QuaZIP
|
||||||
|
SOURCE_DIR <BINARY_DIR>/../Source/quazip-${QUAZIP_VERSION}
|
||||||
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR>/.. ${CMAKE_COMMAND} -E tar xzf ${CMAKE_CURRENT_BINARY_DIR}/quazip-${QUAZIP_VERSION}.tar.gz
|
||||||
|
PATCH_COMMAND patch -p0 -i ${CMAKE_SOURCE_DIR}/quazip.patch
|
||||||
|
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||||
|
)
|
||||||
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}/External/Install/QuaZIP/include/quazip")
|
||||||
|
if(UNIX)
|
||||||
|
set(QUAZIP_LIBRARIES -L"${CMAKE_CURRENT_BINARY_DIR}/External/Install/QuaZIP/lib" quazip z)
|
||||||
|
else()
|
||||||
|
set(QUAZIP_LIBRARIES -L"${CMAKE_CURRENT_BINARY_DIR}/External/Install/QuaZIP/lib" quazip)
|
||||||
|
endif()
|
||||||
|
|
||||||
option(NBT_BUILD_SHARED "Build NBT shared library" ON)
|
option(NBT_BUILD_SHARED "Build NBT shared library" ON)
|
||||||
option(NBT_USE_ZLIB "Build NBT library with zlib support" OFF)
|
option(NBT_USE_ZLIB "Build NBT library with zlib support" OFF)
|
||||||
option(NBT_BUILD_TESTS "Build NBT library tests" OFF) #FIXME: fix unit tests.
|
option(NBT_BUILD_TESTS "Build NBT library tests" OFF) #FIXME: fix unit tests.
|
||||||
set(NBT_NAME MultiMC_nbt++)
|
set(NBT_NAME MultiMC_nbt++)
|
||||||
set(NBT_DEST_DIR ${LIBRARY_DEST_DIR})
|
|
||||||
add_subdirectory(libraries/libnbtplusplus)
|
add_subdirectory(libraries/libnbtplusplus)
|
||||||
|
|
||||||
add_subdirectory(libraries/ganalytics) # google analytics library
|
add_subdirectory(libraries/ganalytics) # google analytics library
|
||||||
@@ -246,17 +98,15 @@ add_subdirectory(libraries/hoedown) # markdown parser
|
|||||||
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
||||||
add_subdirectory(libraries/javacheck) # java compatibility checker
|
add_subdirectory(libraries/javacheck) # java compatibility checker
|
||||||
add_subdirectory(libraries/xz-embedded) # xz compression
|
add_subdirectory(libraries/xz-embedded) # xz compression
|
||||||
add_subdirectory(libraries/quazip) # zip manipulation library
|
|
||||||
add_subdirectory(libraries/pack200) # java pack200 compression
|
add_subdirectory(libraries/pack200) # java pack200 compression
|
||||||
add_subdirectory(libraries/rainbow) # Qt extension for colors
|
add_subdirectory(libraries/rainbow) # Qt extension for colors
|
||||||
add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
|
add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
|
||||||
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
|
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
|
||||||
add_subdirectory(libraries/classparser) # google analytics library
|
|
||||||
|
|
||||||
############################### Built Artifacts ###############################
|
############################### Built Artifacts ###############################
|
||||||
|
|
||||||
add_subdirectory(api/logic)
|
add_subdirectory(api/logic)
|
||||||
add_subdirectory(api/gui)
|
add_subdirectory(api/gui)
|
||||||
|
|
||||||
# NOTE: this must always be last to appease the CMake deity of quirky install command evaluation order.
|
|
||||||
add_subdirectory(application)
|
add_subdirectory(application)
|
||||||
|
add_subdirectory(wonkoclient)
|
||||||
|
|||||||
349
COPYING.md
349
COPYING.md
@@ -1,254 +1,205 @@
|
|||||||
# MultiMC
|
#MultiMC
|
||||||
|
|
||||||
Copyright 2012-2019 MultiMC Contributors
|
Copyright 2012-2017 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.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
# MinGW runtime (Windows)
|
#MinGW runtime (Windows)
|
||||||
|
|
||||||
Copyright (c) 2012 MinGW.org project
|
Copyright (c) 2012 MinGW.org project
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
to deal in the Software without restriction, including without limitation
|
to deal in the Software without restriction, including without limitation
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
Software is furnished to do so, subject to the following conditions:
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice, this permission notice and the below disclaimer
|
The above copyright notice, this permission notice and the below disclaimer
|
||||||
shall be included in all copies or substantial portions of the Software.
|
shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
# Qt 5
|
#Qt 5
|
||||||
|
|
||||||
Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
Contact: http://www.qt-project.org/legal
|
Contact: http://www.qt-project.org/legal
|
||||||
|
|
||||||
Licensed under LGPL v2.1
|
Licensed under LGPL v2.1
|
||||||
|
|
||||||
# libnbt++
|
#libnbt++
|
||||||
|
|
||||||
libnbt++ - A library for the Minecraft Named Binary Tag format.
|
libnbt++ - A library for the Minecraft Named Binary Tag format.
|
||||||
Copyright (C) 2013, 2015 ljfa-ag
|
Copyright (C) 2013, 2015 ljfa-ag
|
||||||
|
|
||||||
libnbt++ is free software: you can redistribute it and/or modify
|
libnbt++ is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
libnbt++ is distributed in the hope that it will be useful,
|
libnbt++ is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Lesser General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
|
along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# rainbow (KGuiAddons)
|
#Group View
|
||||||
|
|
||||||
Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
|
Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
|
||||||
Copyright (C) 2007 Olaf Schmidt <ojschmidt@kde.org>
|
Copyright (C) 2007 John Tapsell <tapsell@kde.org>
|
||||||
Copyright (C) 2007 Thomas Zander <zander@kde.org>
|
|
||||||
Copyright (C) 2007 Zack Rusin <zack@kde.org>
|
|
||||||
Copyright (C) 2015 Petr Mrazek <peterix@gmail.com>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Library General Public
|
modify it under the terms of the GNU Library General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Library General Public License for more details.
|
Library General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public License
|
You should have received a copy of the GNU Library General Public License
|
||||||
along with this library; see the file COPYING.LIB. If not, write to
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
# Hoedown
|
#rainbow (KGuiAddons)
|
||||||
|
|
||||||
Copyright (c) 2008, Natacha Porté
|
Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
|
||||||
Copyright (c) 2011, Vicent Martí
|
Copyright (C) 2007 Olaf Schmidt <ojschmidt@kde.org>
|
||||||
Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
|
Copyright (C) 2007 Thomas Zander <zander@kde.org>
|
||||||
|
Copyright (C) 2007 Zack Rusin <zack@kde.org>
|
||||||
|
Copyright (C) 2015 Petr Mrazek <peterix@gmail.com>
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
This library is free software; you can redistribute it and/or
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
modify it under the terms of the GNU Library General Public
|
||||||
copyright notice and this permission notice appear in all copies.
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
This library is distributed in the hope that it will be useful,
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
Library General Public License for more details.
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
# Batch icon set
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
You are free to use Batch (the "icon set") or any part thereof (the "icons")
|
#Hoedown
|
||||||
in any personal, open-source or commercial work without obligation of payment
|
|
||||||
(monetary or otherwise) or attribution. Do not sell the icon set, host
|
|
||||||
the icon set or rent the icon set (either in existing or modified form).
|
|
||||||
|
|
||||||
While attribution is optional, it is always appreciated.
|
Copyright (c) 2008, Natacha Porté
|
||||||
|
Copyright (c) 2011, Vicent Martí
|
||||||
|
Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
|
||||||
|
|
||||||
Intellectual property rights are not transferred with the download of the icons.
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL ADAM WHITCROFT
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL,
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THE USE OF THE ICONS,
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
# Material Design Icons
|
#Batch icon set
|
||||||
|
|
||||||
Copyright (c) 2014, Austin Andrews (http://materialdesignicons.com/),
|
You are free to use Batch (the "icon set") or any part thereof (the "icons")
|
||||||
with Reserved Font Name Material Design Icons.
|
in any personal, open-source or commercial work without obligation of payment
|
||||||
Copyright (c) 2014, Google (http://www.google.com/design/)
|
(monetary or otherwise) or attribution. Do not sell the icon set, host
|
||||||
uses the license at https://github.com/google/material-design-icons/blob/master/LICENSE
|
the icon set or rent the icon set (either in existing or modified form).
|
||||||
|
|
||||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
While attribution is optional, it is always appreciated.
|
||||||
This license is copied below, and is also available with a FAQ at:
|
|
||||||
http://scripts.sil.org/OFL
|
|
||||||
|
|
||||||
# Pack200
|
Intellectual property rights are not transferred with the download of the icons.
|
||||||
|
|
||||||
The GNU General Public License (GPL)
|
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL ADAM WHITCROFT
|
||||||
|
BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL,
|
||||||
|
PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THE USE OF THE ICONS,
|
||||||
|
EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
Version 2, June 1991
|
#Pack200
|
||||||
|
|
||||||
+ "CLASSPATH" EXCEPTION TO THE GPL
|
The GNU General Public License (GPL)
|
||||||
|
|
||||||
Certain source files distributed by Oracle America and/or its affiliates are
|
Version 2, June 1991
|
||||||
subject to the following clarification and special exception to the GPL, but
|
|
||||||
only where Oracle has expressly included in the particular source file's header
|
|
||||||
the words "Oracle designates this particular file as subject to the "Classpath"
|
|
||||||
exception as provided by Oracle in the LICENSE file that accompanied this code."
|
|
||||||
|
|
||||||
Linking this library statically or dynamically with other modules is making
|
+ "CLASSPATH" EXCEPTION TO THE GPL
|
||||||
a combined work based on this library. Thus, the terms and conditions of
|
|
||||||
the GNU General Public License cover the whole combination.
|
|
||||||
|
|
||||||
As a special exception, the copyright holders of this library give you
|
Certain source files distributed by Oracle America and/or its affiliates are
|
||||||
permission to link this library with independent modules to produce an
|
subject to the following clarification and special exception to the GPL, but
|
||||||
executable, regardless of the license terms of these independent modules,
|
only where Oracle has expressly included in the particular source file's header
|
||||||
and to copy and distribute the resulting executable under terms of your
|
the words "Oracle designates this particular file as subject to the "Classpath"
|
||||||
choice, provided that you also meet, for each linked independent module,
|
exception as provided by Oracle in the LICENSE file that accompanied this code."
|
||||||
the terms and conditions of the license of that module. An independent
|
|
||||||
module is a module which is not derived from or based on this library. If
|
|
||||||
you modify this library, you may extend this exception to your version of
|
|
||||||
the library, but you are not obligated to do so. If you do not wish to do
|
|
||||||
so, delete this exception statement from your version.
|
|
||||||
|
|
||||||
# Quazip
|
Linking this library statically or dynamically with other modules is making
|
||||||
|
a combined work based on this library. Thus, the terms and conditions of
|
||||||
|
the GNU General Public License cover the whole combination.
|
||||||
|
|
||||||
Copyright (C) 2005-2011 Sergey A. Tachenov
|
As a special exception, the copyright holders of this library give you
|
||||||
|
permission to link this library with independent modules to produce an
|
||||||
|
executable, regardless of the license terms of these independent modules,
|
||||||
|
and to copy and distribute the resulting executable under terms of your
|
||||||
|
choice, provided that you also meet, for each linked independent module,
|
||||||
|
the terms and conditions of the license of that module. An independent
|
||||||
|
module is a module which is not derived from or based on this library. If
|
||||||
|
you modify this library, you may extend this exception to your version of
|
||||||
|
the library, but you are not obligated to do so. If you do not wish to do
|
||||||
|
so, delete this exception statement from your version.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
#Quazip
|
||||||
under the terms of the GNU Lesser General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or (at
|
|
||||||
your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
Copyright (C) 2005-2011 Sergey A. Tachenov
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
This program is free software; you can redistribute it and/or modify it
|
||||||
along with this program; if not, write to the Free Software Foundation,
|
under the terms of the GNU Lesser General Public License as published by
|
||||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
your option) any later version.
|
||||||
|
|
||||||
See COPYING file for the full LGPL text.
|
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 Lesser
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
# xz-minidec
|
See COPYING file for the full LGPL text.
|
||||||
|
|
||||||
XZ decompressor
|
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||||
|
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||||
|
|
||||||
Authors: Lasse Collin <lasse.collin@tukaani.org>
|
#xz-minidec
|
||||||
Igor Pavlov <http://7-zip.org/>
|
|
||||||
|
|
||||||
This file has been put into the public domain.
|
XZ decompressor
|
||||||
You can do whatever you want with this file.
|
|
||||||
|
|
||||||
# ColumnResizer
|
Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||||
|
Igor Pavlov <http://7-zip.org/>
|
||||||
|
|
||||||
Copyright (c) 2011-2016 Aurélien Gâteau and contributors.
|
This file has been put into the public domain.
|
||||||
|
You can do whatever you want with this file.
|
||||||
|
|
||||||
All rights reserved.
|
#ColumnResizer
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
|
||||||
modification, are permitted (subject to the limitations in the
|
License: LGPL v2.1 or later (see COPYING)
|
||||||
disclaimer below) provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
* The name of the contributors may not be used to endorse or
|
|
||||||
promote products derived from this software without specific prior
|
|
||||||
written permission.
|
|
||||||
|
|
||||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
|
|
||||||
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
|
|
||||||
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
|
||||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
||||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
||||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
# lionshead
|
|
||||||
|
|
||||||
Code has been taken from https://github.com/natefoo/lionshead and loosely
|
|
||||||
translated to C++ laced with Qt.
|
|
||||||
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Nate Coraor
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|||||||
5
LGPL_EXCEPTION.txt
Normal file
5
LGPL_EXCEPTION.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
As a special exception to the GNU Lesser General Public License version 2.1, the object code form of a "work
|
||||||
|
that uses the Library" may incorporate material from a header file that is part of the Library. You may
|
||||||
|
distribute such object code under terms of your choice, provided that the incorporated material (i) does not
|
||||||
|
exceed more than 5% of the total size of the Library; and (ii) is limited to numerical parameters, data
|
||||||
|
structure layouts, accessors, macros, inline functions and templates.
|
||||||
502
LICENSE.LPGLv21
Normal file
502
LICENSE.LPGLv21
Normal file
@@ -0,0 +1,502 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some
|
||||||
|
specially designated software packages--typically libraries--of the
|
||||||
|
Free Software Foundation and other authors who decide to use it. You
|
||||||
|
can use it too, but we suggest you first think carefully about whether
|
||||||
|
this license or the ordinary General Public License is the better
|
||||||
|
strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use,
|
||||||
|
not price. Our General Public Licenses are designed to make sure that
|
||||||
|
you have the freedom to distribute copies of free software (and charge
|
||||||
|
for this service if you wish); that you receive source code or can get
|
||||||
|
it if you want it; that you can change the software and use pieces of
|
||||||
|
it in new free programs; and that you are informed that you can do
|
||||||
|
these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
distributors to deny you these rights or to ask you to surrender these
|
||||||
|
rights. These restrictions translate to certain responsibilities for
|
||||||
|
you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link other code with the library, you must provide
|
||||||
|
complete object files to the recipients, so that they can relink them
|
||||||
|
with the library after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the
|
||||||
|
library, and (2) we offer you this license, which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that
|
||||||
|
there is no warranty for the free library. Also, if the library is
|
||||||
|
modified by someone else and passed on, the recipients should know
|
||||||
|
that what they have is not the original version, so that the original
|
||||||
|
author's reputation will not be affected by problems that might be
|
||||||
|
introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of
|
||||||
|
any free program. We wish to make sure that a company cannot
|
||||||
|
effectively restrict the users of a free program by obtaining a
|
||||||
|
restrictive license from a patent holder. Therefore, we insist that
|
||||||
|
any patent license obtained for a version of the library must be
|
||||||
|
consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the
|
||||||
|
ordinary GNU General Public License. This license, the GNU Lesser
|
||||||
|
General Public License, applies to certain designated libraries, and
|
||||||
|
is quite different from the ordinary General Public License. We use
|
||||||
|
this license for certain libraries in order to permit linking those
|
||||||
|
libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using
|
||||||
|
a shared library, the combination of the two is legally speaking a
|
||||||
|
combined work, a derivative of the original library. The ordinary
|
||||||
|
General Public License therefore permits such linking only if the
|
||||||
|
entire combination fits its criteria of freedom. The Lesser General
|
||||||
|
Public License permits more lax criteria for linking other code with
|
||||||
|
the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it
|
||||||
|
does Less to protect the user's freedom than the ordinary General
|
||||||
|
Public License. It also provides other free software developers Less
|
||||||
|
of an advantage over competing non-free programs. These disadvantages
|
||||||
|
are the reason we use the ordinary General Public License for many
|
||||||
|
libraries. However, the Lesser license provides advantages in certain
|
||||||
|
special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to
|
||||||
|
encourage the widest possible use of a certain library, so that it becomes
|
||||||
|
a de-facto standard. To achieve this, non-free programs must be
|
||||||
|
allowed to use the library. A more frequent case is that a free
|
||||||
|
library does the same job as widely used non-free libraries. In this
|
||||||
|
case, there is little to gain by limiting the free library to free
|
||||||
|
software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free
|
||||||
|
programs enables a greater number of people to use a large body of
|
||||||
|
free software. For example, permission to use the GNU C Library in
|
||||||
|
non-free programs enables many more people to use the whole GNU
|
||||||
|
operating system, as well as its variant, the GNU/Linux operating
|
||||||
|
system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the
|
||||||
|
users' freedom, it does ensure that the user of a program that is
|
||||||
|
linked with the Library has the freedom and the wherewithal to run
|
||||||
|
that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, whereas the latter must
|
||||||
|
be combined with the library in order to run.
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library or other
|
||||||
|
program which contains a notice placed by the copyright holder or
|
||||||
|
other authorized party saying it may be distributed under the terms of
|
||||||
|
this Lesser General Public License (also called "this License").
|
||||||
|
Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, complete source code means
|
||||||
|
all the source code for all modules it contains, plus any associated
|
||||||
|
interface definition files, plus the scripts used to control compilation
|
||||||
|
and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete source code as you receive it, in any medium, provided that
|
||||||
|
you conspicuously and appropriately publish on each copy an
|
||||||
|
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||||
|
all the notices that refer to this License and to the absence of any
|
||||||
|
warranty; and distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
|
and you may at your option offer warranty protection in exchange for a
|
||||||
|
fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Library, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote
|
||||||
|
it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you accompany
|
||||||
|
it with the complete corresponding machine-readable source code, which
|
||||||
|
must be distributed under the terms of Sections 1 and 2 above on a
|
||||||
|
medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy
|
||||||
|
from a designated place, then offering equivalent access to copy the
|
||||||
|
source code from the same place satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
|
copy of the library already present on the user's computer system,
|
||||||
|
rather than copying library functions into the executable, and (2)
|
||||||
|
will operate properly with a modified version of the library, if
|
||||||
|
the user installs one, as long as the modified version is
|
||||||
|
interface-compatible with the version that the work was made with.
|
||||||
|
|
||||||
|
c) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
d) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
e) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the materials to be distributed need not include anything that is
|
||||||
|
normally distributed (in either source or binary form) with the major
|
||||||
|
components (compiler, kernel, and so on) of the operating system on
|
||||||
|
which the executable runs, unless that component itself accompanies
|
||||||
|
the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
0the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library is void, and will automatically terminate your
|
||||||
|
rights under this License. However, parties who have received copies,
|
||||||
|
or rights, from you under this License will not have their licenses
|
||||||
|
terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
subject to these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties with
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any
|
||||||
|
particular circumstance, the balance of the section is intended to apply,
|
||||||
|
and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library under this License may add
|
||||||
|
an explicit geographical distribution limitation excluding those countries,
|
||||||
|
so that distribution is permitted only in or among countries not thus
|
||||||
|
excluded. In such case, this License incorporates the limitation as if
|
||||||
|
written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Lesser General Public License from time to time.
|
||||||
|
Such new versions will be similar in spirit to the present version,
|
||||||
|
but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library
|
||||||
|
specifies a version number of this License which applies to it and
|
||||||
|
"any later version", you have the option of following the terms and
|
||||||
|
conditions either of that version or of any later version published by
|
||||||
|
the Free Software Foundation. If the Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
write to the author to ask for permission. For software which is
|
||||||
|
copyrighted by the Free Software Foundation, write to the Free
|
||||||
|
Software Foundation; we sometimes make exceptions for this. Our
|
||||||
|
decision will be guided by the two goals of preserving the free status
|
||||||
|
of all derivatives of our free software and of promoting the sharing
|
||||||
|
and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||||
|
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||||
|
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||||
|
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||||
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||||
|
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||||
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||||
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Libraries
|
||||||
|
|
||||||
|
If you develop a new library, and you want it to be of the greatest
|
||||||
|
possible use to the public, we recommend making it free software that
|
||||||
|
everyone can redistribute and change. You can do so by permitting
|
||||||
|
redistribution under these terms (or, alternatively, under the terms of the
|
||||||
|
ordinary General Public License).
|
||||||
|
|
||||||
|
To apply these terms, attach the following notices to the library. It is
|
||||||
|
safest to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the library's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||||
|
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1990
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
That's all there is to it!
|
||||||
12
README.md
12
README.md
@@ -1,6 +1,4 @@
|
|||||||
<p align="center">
|

|
||||||
<img src="https://avatars2.githubusercontent.com/u/5411890" alt="MultiMC logo"/>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
MultiMC 5
|
MultiMC 5
|
||||||
=========
|
=========
|
||||||
@@ -13,7 +11,7 @@ The project uses C++ and Qt5 as the language and base framework. This might seem
|
|||||||
|
|
||||||
We can do more, with less, on worse hardware and leave more resources for the game while keeping the launcher running and providing extra features.
|
We can do more, with less, on worse hardware and leave more resources for the game while keeping the launcher running and providing extra features.
|
||||||
|
|
||||||
If you want to contribute, either talk to us on [Discord](https://discord.gg/0k2zsXGNHs0fE4Wm), [IRC](http://webchat.esper.net/?nick=&channels=MultiMC)(esper.net/#MultiMC) or pick up some item from [workflowy](https://workflowy.com/s/2EyDMcp7CU) - there are many.
|
If you want to contribute, either talk to us on [IRC](http://webchat.esper.net/?nick=&channels=MultiMC)(esper.net/#MultiMC), or pick up one of the issues that are ready for development: [](http://waffle.io/MultiMC/MultiMC5)
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
If you want to build MultiMC yourself, check [BUILD.md](BUILD.md) for build instructions.
|
If you want to build MultiMC yourself, check [BUILD.md](BUILD.md) for build instructions.
|
||||||
@@ -27,7 +25,9 @@ We use [Clang Format](http://clang.llvm.org/docs/ClangFormat.html) to format the
|
|||||||
|
|
||||||
|
|
||||||
## Translations
|
## Translations
|
||||||
Translations can be done either directly in the [translations repository](https://github.com/MultiMC/MultiMC5). For more details, see: [Translating-MultiMC](https://github.com/MultiMC/MultiMC5/wiki/Translating-MultiMC).
|
Translations can be done either directly in the [translations repository](https://github.com/MultiMC/MultiMC5) or using our [translation server](http://translate.multimc.org). For more details, see: [Translating-MultiMC](https://github.com/MultiMC/MultiMC5/wiki/Translating-MultiMC).
|
||||||
|
|
||||||
|
Currently, MultiMC is [](http://translate.multimc.org/engage/multimc/?utm_source=widget)
|
||||||
|
|
||||||
## Forking/Redistributing
|
## Forking/Redistributing
|
||||||
We keep MultiMC open source because we think it's important to be able to see the source code for a project like this, and we do so using the Apache license.
|
We keep MultiMC open source because we think it's important to be able to see the source code for a project like this, and we do so using the Apache license.
|
||||||
@@ -38,7 +38,7 @@ Apache covers reasonable use for the name - a mention of the project's origins i
|
|||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
Copyright © 2013-2019 MultiMC Contributors
|
Copyright © 2013-2017 MultiMC Contributors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this program except in compliance with the License. You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this program except in compliance with the License. You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
project(MultiMC_gui LANGUAGES CXX)
|
project(MultiMC_gui LANGUAGES CXX)
|
||||||
|
|
||||||
set(GUI_SOURCES
|
set(GUI_SOURCES
|
||||||
DesktopServices.h
|
DesktopServices.h
|
||||||
DesktopServices.cpp
|
DesktopServices.cpp
|
||||||
|
|
||||||
# Icons
|
# Icons
|
||||||
icons/MMCIcon.h
|
icons/MMCIcon.h
|
||||||
icons/MMCIcon.cpp
|
icons/MMCIcon.cpp
|
||||||
icons/IconList.h
|
icons/IconList.h
|
||||||
icons/IconList.cpp
|
icons/IconList.cpp
|
||||||
|
|
||||||
SkinUtils.cpp
|
SkinUtils.cpp
|
||||||
SkinUtils.h
|
SkinUtils.h
|
||||||
)
|
)
|
||||||
################################ COMPILE ################################
|
################################ COMPILE ################################
|
||||||
|
|
||||||
@@ -21,14 +21,8 @@ set_target_properties(MultiMC_gui PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBI
|
|||||||
generate_export_header(MultiMC_gui)
|
generate_export_header(MultiMC_gui)
|
||||||
|
|
||||||
# Link
|
# Link
|
||||||
target_link_libraries(MultiMC_gui MultiMC_iconfix MultiMC_logic Qt5::Gui)
|
target_link_libraries(MultiMC_gui iconfix MultiMC_logic)
|
||||||
|
qt5_use_modules(MultiMC_gui Gui)
|
||||||
|
|
||||||
# Mark and export headers
|
# Mark and export headers
|
||||||
target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
# Install it
|
|
||||||
install(
|
|
||||||
TARGETS MultiMC_gui
|
|
||||||
RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
|
|
||||||
LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
|
|
||||||
)
|
|
||||||
@@ -17,132 +17,132 @@
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool IndirectOpen(T callable, qint64 *pid_forked = nullptr)
|
bool IndirectOpen(T callable, qint64 *pid_forked = nullptr)
|
||||||
{
|
{
|
||||||
auto pid = fork();
|
auto pid = fork();
|
||||||
if(pid_forked)
|
if(pid_forked)
|
||||||
{
|
{
|
||||||
if(pid > 0)
|
if(pid > 0)
|
||||||
*pid_forked = pid;
|
*pid_forked = pid;
|
||||||
else
|
else
|
||||||
*pid_forked = 0;
|
*pid_forked = 0;
|
||||||
}
|
}
|
||||||
if(pid == -1)
|
if(pid == -1)
|
||||||
{
|
{
|
||||||
qWarning() << "IndirectOpen failed to fork: " << errno;
|
qWarning() << "IndirectOpen failed to fork: " << errno;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// child - do the stuff
|
// child - do the stuff
|
||||||
if(pid == 0)
|
if(pid == 0)
|
||||||
{
|
{
|
||||||
// unset all this garbage so it doesn't get passed to the child process
|
// unset all this garbage so it doesn't get passed to the child process
|
||||||
qunsetenv("LD_PRELOAD");
|
qunsetenv("LD_PRELOAD");
|
||||||
qunsetenv("LD_LIBRARY_PATH");
|
qunsetenv("LD_LIBRARY_PATH");
|
||||||
qunsetenv("LD_DEBUG");
|
qunsetenv("LD_DEBUG");
|
||||||
qunsetenv("QT_PLUGIN_PATH");
|
qunsetenv("QT_PLUGIN_PATH");
|
||||||
qunsetenv("QT_FONTPATH");
|
qunsetenv("QT_FONTPATH");
|
||||||
|
|
||||||
// open the URL
|
// open the URL
|
||||||
auto status = callable();
|
auto status = callable();
|
||||||
|
|
||||||
// detach from the parent process group.
|
// detach from the parent process group.
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
// die. now. do not clean up anything, it would just hang forever.
|
// die. now. do not clean up anything, it would just hang forever.
|
||||||
_exit(status ? 0 : 1);
|
_exit(status ? 0 : 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//parent - assume it worked.
|
//parent - assume it worked.
|
||||||
int status;
|
int status;
|
||||||
while (waitpid(pid, &status, 0))
|
while (waitpid(pid, &status, 0))
|
||||||
{
|
{
|
||||||
if(WIFEXITED(status))
|
if(WIFEXITED(status))
|
||||||
{
|
{
|
||||||
return WEXITSTATUS(status) == 0;
|
return WEXITSTATUS(status) == 0;
|
||||||
}
|
}
|
||||||
if(WIFSIGNALED(status))
|
if(WIFSIGNALED(status))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace DesktopServices {
|
namespace DesktopServices {
|
||||||
bool openDirectory(const QString &path, bool ensureExists)
|
bool openDirectory(const QString &path, bool ensureExists)
|
||||||
{
|
{
|
||||||
qDebug() << "Opening directory" << path;
|
qDebug() << "Opening directory" << path;
|
||||||
QDir parentPath;
|
QDir parentPath;
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
{
|
{
|
||||||
parentPath.mkpath(dir.absolutePath());
|
parentPath.mkpath(dir.absolutePath());
|
||||||
}
|
}
|
||||||
auto f = [&]()
|
auto f = [&]()
|
||||||
{
|
{
|
||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
return IndirectOpen(f);
|
return IndirectOpen(f);
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool openFile(const QString &path)
|
bool openFile(const QString &path)
|
||||||
{
|
{
|
||||||
qDebug() << "Opening file" << path;
|
qDebug() << "Opening file" << path;
|
||||||
auto f = [&]()
|
auto f = [&]()
|
||||||
{
|
{
|
||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
return IndirectOpen(f);
|
return IndirectOpen(f);
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid)
|
bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid)
|
||||||
{
|
{
|
||||||
qDebug() << "Opening file" << path << "using" << application;
|
qDebug() << "Opening file" << path << "using" << application;
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
||||||
return IndirectOpen([&]()
|
return IndirectOpen([&]()
|
||||||
{
|
{
|
||||||
return QProcess::startDetached(application, QStringList() << path, workingDirectory);
|
return QProcess::startDetached(application, QStringList() << path, workingDirectory);
|
||||||
}, pid);
|
}, pid);
|
||||||
#else
|
#else
|
||||||
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
|
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid)
|
bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid)
|
||||||
{
|
{
|
||||||
qDebug() << "Running" << application << "with args" << args.join(' ');
|
qDebug() << "Running" << application << "with args" << args.join(' ');
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
||||||
return IndirectOpen([&]()
|
return IndirectOpen([&]()
|
||||||
{
|
{
|
||||||
return QProcess::startDetached(application, args, workingDirectory);
|
return QProcess::startDetached(application, args, workingDirectory);
|
||||||
}, pid);
|
}, pid);
|
||||||
#else
|
#else
|
||||||
return QProcess::startDetached(application, args, workingDirectory, pid);
|
return QProcess::startDetached(application, args, workingDirectory, pid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool openUrl(const QUrl &url)
|
bool openUrl(const QUrl &url)
|
||||||
{
|
{
|
||||||
qDebug() << "Opening URL" << url.toString();
|
qDebug() << "Opening URL" << url.toString();
|
||||||
auto f = [&]()
|
auto f = [&]()
|
||||||
{
|
{
|
||||||
return QDesktopServices::openUrl(url);
|
return QDesktopServices::openUrl(url);
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
return IndirectOpen(f);
|
return IndirectOpen(f);
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,28 +10,28 @@
|
|||||||
*/
|
*/
|
||||||
namespace DesktopServices
|
namespace DesktopServices
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Open a file in whatever application is applicable
|
* Open a file in whatever application is applicable
|
||||||
*/
|
*/
|
||||||
MULTIMC_GUI_EXPORT bool openFile(const QString &path);
|
MULTIMC_GUI_EXPORT bool openFile(const QString &path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a file in the specified application
|
* Open a file in the specified application
|
||||||
*/
|
*/
|
||||||
MULTIMC_GUI_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0);
|
MULTIMC_GUI_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run an application
|
* Run an application
|
||||||
*/
|
*/
|
||||||
MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0);
|
MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a directory
|
* Open a directory
|
||||||
*/
|
*/
|
||||||
MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false);
|
MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the URL, most likely in a browser. Maybe.
|
* Open the URL, most likely in a browser. Maybe.
|
||||||
*/
|
*/
|
||||||
MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url);
|
MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -29,19 +29,19 @@ namespace SkinUtils
|
|||||||
*/
|
*/
|
||||||
QPixmap getFaceFromCache(QString username, int height, int width)
|
QPixmap getFaceFromCache(QString username, int height, int width)
|
||||||
{
|
{
|
||||||
QFile fskin(ENV.metacache()
|
QFile fskin(ENV.metacache()
|
||||||
->resolveEntry("skins", username + ".png")
|
->resolveEntry("skins", username + ".png")
|
||||||
->getFullPath());
|
->getFullPath());
|
||||||
|
|
||||||
if (fskin.exists())
|
if (fskin.exists())
|
||||||
{
|
{
|
||||||
QPixmap skin(fskin.fileName());
|
QPixmap skin(fskin.fileName());
|
||||||
if(!skin.isNull())
|
if(!skin.isNull())
|
||||||
{
|
{
|
||||||
return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
|
return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -27,393 +27,392 @@
|
|||||||
|
|
||||||
IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
|
IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
QSet<QString> builtinNames;
|
QSet<QString> builtinNames;
|
||||||
|
|
||||||
// add builtin icons
|
// add builtin icons
|
||||||
for(auto & builtinPath: builtinPaths)
|
for(auto & builtinPath: builtinPaths)
|
||||||
{
|
{
|
||||||
QDir instance_icons(builtinPath);
|
QDir instance_icons(builtinPath);
|
||||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
||||||
for (auto file_info : file_info_list)
|
for (auto file_info : file_info_list)
|
||||||
{
|
{
|
||||||
builtinNames.insert(file_info.baseName());
|
builtinNames.insert(file_info.baseName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(auto & builtinName : builtinNames)
|
for(auto & builtinName : builtinNames)
|
||||||
{
|
{
|
||||||
addThemeIcon(builtinName);
|
addThemeIcon(builtinName);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_watcher.reset(new QFileSystemWatcher());
|
m_watcher.reset(new QFileSystemWatcher());
|
||||||
is_watching = false;
|
is_watching = false;
|
||||||
connect(m_watcher.get(), SIGNAL(directoryChanged(QString)),
|
connect(m_watcher.get(), SIGNAL(directoryChanged(QString)),
|
||||||
SLOT(directoryChanged(QString)));
|
SLOT(directoryChanged(QString)));
|
||||||
connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
|
connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
|
||||||
|
|
||||||
directoryChanged(path);
|
directoryChanged(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::directoryChanged(const QString &path)
|
void IconList::directoryChanged(const QString &path)
|
||||||
{
|
{
|
||||||
QDir new_dir (path);
|
QDir new_dir (path);
|
||||||
if(m_dir.absolutePath() != new_dir.absolutePath())
|
if(m_dir.absolutePath() != new_dir.absolutePath())
|
||||||
{
|
{
|
||||||
m_dir.setPath(path);
|
m_dir.setPath(path);
|
||||||
m_dir.refresh();
|
m_dir.refresh();
|
||||||
if(is_watching)
|
if(is_watching)
|
||||||
stopWatching();
|
stopWatching();
|
||||||
startWatching();
|
startWatching();
|
||||||
}
|
}
|
||||||
if(!m_dir.exists())
|
if(!m_dir.exists())
|
||||||
if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
|
if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
|
||||||
return;
|
return;
|
||||||
m_dir.refresh();
|
m_dir.refresh();
|
||||||
auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
|
auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
|
||||||
for (auto it = new_list.begin(); it != new_list.end(); it++)
|
for (auto it = new_list.begin(); it != new_list.end(); it++)
|
||||||
{
|
{
|
||||||
QString &foo = (*it);
|
QString &foo = (*it);
|
||||||
foo = m_dir.filePath(foo);
|
foo = m_dir.filePath(foo);
|
||||||
}
|
}
|
||||||
auto new_set = new_list.toSet();
|
auto new_set = new_list.toSet();
|
||||||
QList<QString> current_list;
|
QList<QString> current_list;
|
||||||
for (auto &it : icons)
|
for (auto &it : icons)
|
||||||
{
|
{
|
||||||
if (!it.has(IconType::FileBased))
|
if (!it.has(IconType::FileBased))
|
||||||
continue;
|
continue;
|
||||||
current_list.push_back(it.m_images[IconType::FileBased].filename);
|
current_list.push_back(it.m_images[IconType::FileBased].filename);
|
||||||
}
|
}
|
||||||
QSet<QString> current_set = current_list.toSet();
|
QSet<QString> current_set = current_list.toSet();
|
||||||
|
|
||||||
QSet<QString> to_remove = current_set;
|
QSet<QString> to_remove = current_set;
|
||||||
to_remove -= new_set;
|
to_remove -= new_set;
|
||||||
|
|
||||||
QSet<QString> to_add = new_set;
|
QSet<QString> to_add = new_set;
|
||||||
to_add -= current_set;
|
to_add -= current_set;
|
||||||
|
|
||||||
for (auto remove : to_remove)
|
for (auto remove : to_remove)
|
||||||
{
|
{
|
||||||
qDebug() << "Removing " << remove;
|
qDebug() << "Removing " << remove;
|
||||||
QFileInfo rmfile(remove);
|
QFileInfo rmfile(remove);
|
||||||
QString key = rmfile.baseName();
|
QString key = rmfile.baseName();
|
||||||
int idx = getIconIndex(key);
|
int idx = getIconIndex(key);
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
continue;
|
continue;
|
||||||
icons[idx].remove(IconType::FileBased);
|
icons[idx].remove(IconType::FileBased);
|
||||||
if (icons[idx].type() == IconType::ToBeDeleted)
|
if (icons[idx].type() == IconType::ToBeDeleted)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
beginRemoveRows(QModelIndex(), idx, idx);
|
||||||
icons.remove(idx);
|
icons.remove(idx);
|
||||||
reindex();
|
reindex();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dataChanged(index(idx), index(idx));
|
dataChanged(index(idx), index(idx));
|
||||||
}
|
}
|
||||||
m_watcher->removePath(remove);
|
m_watcher->removePath(remove);
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto add : to_add)
|
for (auto add : to_add)
|
||||||
{
|
{
|
||||||
qDebug() << "Adding " << add;
|
qDebug() << "Adding " << add;
|
||||||
QFileInfo addfile(add);
|
QFileInfo addfile(add);
|
||||||
QString key = addfile.baseName();
|
QString key = addfile.baseName();
|
||||||
if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
|
if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
|
||||||
{
|
{
|
||||||
m_watcher->addPath(add);
|
m_watcher->addPath(add);
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::fileChanged(const QString &path)
|
void IconList::fileChanged(const QString &path)
|
||||||
{
|
{
|
||||||
qDebug() << "Checking " << path;
|
qDebug() << "Checking " << path;
|
||||||
QFileInfo checkfile(path);
|
QFileInfo checkfile(path);
|
||||||
if (!checkfile.exists())
|
if (!checkfile.exists())
|
||||||
return;
|
return;
|
||||||
QString key = checkfile.baseName();
|
QString key = checkfile.baseName();
|
||||||
int idx = getIconIndex(key);
|
int idx = getIconIndex(key);
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
QIcon icon(path);
|
QIcon icon(path);
|
||||||
if (!icon.availableSizes().size())
|
if (!icon.availableSizes().size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
icons[idx].m_images[IconType::FileBased].icon = icon;
|
icons[idx].m_images[IconType::FileBased].icon = icon;
|
||||||
dataChanged(index(idx), index(idx));
|
dataChanged(index(idx), index(idx));
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::SettingChanged(const Setting &setting, QVariant value)
|
void IconList::SettingChanged(const Setting &setting, QVariant value)
|
||||||
{
|
{
|
||||||
if(setting.id() != "IconsDir")
|
if(setting.id() != "IconsDir")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
directoryChanged(value.toString());
|
directoryChanged(value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::startWatching()
|
void IconList::startWatching()
|
||||||
{
|
{
|
||||||
auto abs_path = m_dir.absolutePath();
|
auto abs_path = m_dir.absolutePath();
|
||||||
FS::ensureFolderPathExists(abs_path);
|
FS::ensureFolderPathExists(abs_path);
|
||||||
is_watching = m_watcher->addPath(abs_path);
|
is_watching = m_watcher->addPath(abs_path);
|
||||||
if (is_watching)
|
if (is_watching)
|
||||||
{
|
{
|
||||||
qDebug() << "Started watching " << abs_path;
|
qDebug() << "Started watching " << abs_path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Failed to start watching " << abs_path;
|
qDebug() << "Failed to start watching " << abs_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::stopWatching()
|
void IconList::stopWatching()
|
||||||
{
|
{
|
||||||
m_watcher->removePaths(m_watcher->files());
|
m_watcher->removePaths(m_watcher->files());
|
||||||
m_watcher->removePaths(m_watcher->directories());
|
m_watcher->removePaths(m_watcher->directories());
|
||||||
is_watching = false;
|
is_watching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList IconList::mimeTypes() const
|
QStringList IconList::mimeTypes() const
|
||||||
{
|
{
|
||||||
QStringList types;
|
QStringList types;
|
||||||
types << "text/uri-list";
|
types << "text/uri-list";
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
Qt::DropActions IconList::supportedDropActions() const
|
Qt::DropActions IconList::supportedDropActions() const
|
||||||
{
|
{
|
||||||
return Qt::CopyAction;
|
return Qt::CopyAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
|
||||||
|
const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (action == Qt::IgnoreAction)
|
if (action == Qt::IgnoreAction)
|
||||||
return true;
|
return true;
|
||||||
// check if the action is supported
|
// check if the action is supported
|
||||||
if (!data || !(action & supportedDropActions()))
|
if (!data || !(action & supportedDropActions()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// files dropped from outside?
|
// files dropped from outside?
|
||||||
if (data->hasUrls())
|
if (data->hasUrls())
|
||||||
{
|
{
|
||||||
auto urls = data->urls();
|
auto urls = data->urls();
|
||||||
QStringList iconFiles;
|
QStringList iconFiles;
|
||||||
for (auto url : urls)
|
for (auto url : urls)
|
||||||
{
|
{
|
||||||
// only local files may be dropped...
|
// only local files may be dropped...
|
||||||
if (!url.isLocalFile())
|
if (!url.isLocalFile())
|
||||||
continue;
|
continue;
|
||||||
iconFiles += url.toLocalFile();
|
iconFiles += url.toLocalFile();
|
||||||
}
|
}
|
||||||
installIcons(iconFiles);
|
installIcons(iconFiles);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags IconList::flags(const QModelIndex &index) const
|
Qt::ItemFlags IconList::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
|
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||||
else
|
else
|
||||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant IconList::data(const QModelIndex &index, int role) const
|
QVariant IconList::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
|
|
||||||
if (row < 0 || row >= icons.size())
|
if (row < 0 || row >= icons.size())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (role)
|
switch (role)
|
||||||
{
|
{
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return icons[row].icon();
|
return icons[row].icon();
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return icons[row].name();
|
return icons[row].name();
|
||||||
case Qt::UserRole:
|
case Qt::UserRole:
|
||||||
return icons[row].m_key;
|
return icons[row].m_key;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int IconList::rowCount(const QModelIndex &parent) const
|
int IconList::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return icons.size();
|
return icons.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::installIcons(const QStringList &iconFiles)
|
void IconList::installIcons(const QStringList &iconFiles)
|
||||||
{
|
{
|
||||||
for (QString file : iconFiles)
|
for (QString file : iconFiles)
|
||||||
{
|
{
|
||||||
QFileInfo fileinfo(file);
|
QFileInfo fileinfo(file);
|
||||||
if (!fileinfo.isReadable() || !fileinfo.isFile())
|
if (!fileinfo.isReadable() || !fileinfo.isFile())
|
||||||
continue;
|
continue;
|
||||||
QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
|
QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
|
||||||
|
|
||||||
QString suffix = fileinfo.suffix();
|
QString suffix = fileinfo.suffix();
|
||||||
if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
|
if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!QFile::copy(file, target))
|
if (!QFile::copy(file, target))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void IconList::installIcon(const QString &file, const QString &name)
|
|
||||||
{
|
|
||||||
QFileInfo fileinfo(file);
|
|
||||||
if(!fileinfo.isReadable() || !fileinfo.isFile())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString target = FS::PathCombine(m_dir.dirName(), name);
|
|
||||||
|
|
||||||
QFile::copy(file, target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::iconFileExists(const QString &key) const
|
bool IconList::iconFileExists(const QString &key) const
|
||||||
{
|
{
|
||||||
auto iconEntry = icon(key);
|
auto iconEntry = icon(key);
|
||||||
if(!iconEntry)
|
if(!iconEntry)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return iconEntry->has(IconType::FileBased);
|
return iconEntry->has(IconType::FileBased);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MMCIcon *IconList::icon(const QString &key) const
|
const MMCIcon *IconList::icon(const QString &key) const
|
||||||
{
|
{
|
||||||
int iconIdx = getIconIndex(key);
|
int iconIdx = getIconIndex(key);
|
||||||
if (iconIdx == -1)
|
if (iconIdx == -1)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &icons[iconIdx];
|
return &icons[iconIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::deleteIcon(const QString &key)
|
bool IconList::deleteIcon(const QString &key)
|
||||||
{
|
{
|
||||||
int iconIdx = getIconIndex(key);
|
int iconIdx = getIconIndex(key);
|
||||||
if (iconIdx == -1)
|
if (iconIdx == -1)
|
||||||
return false;
|
return false;
|
||||||
auto &iconEntry = icons[iconIdx];
|
auto &iconEntry = icons[iconIdx];
|
||||||
if (iconEntry.has(IconType::FileBased))
|
if (iconEntry.has(IconType::FileBased))
|
||||||
{
|
{
|
||||||
return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
|
return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::addThemeIcon(const QString& key)
|
bool IconList::addThemeIcon(const QString& key)
|
||||||
{
|
{
|
||||||
auto iter = name_index.find(key);
|
auto iter = name_index.find(key);
|
||||||
if (iter != name_index.end())
|
if (iter != name_index.end())
|
||||||
{
|
{
|
||||||
auto &oldOne = icons[*iter];
|
auto &oldOne = icons[*iter];
|
||||||
oldOne.replace(Builtin, key);
|
oldOne.replace(Builtin, key);
|
||||||
dataChanged(index(*iter), index(*iter));
|
dataChanged(index(*iter), index(*iter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// add a new icon
|
// add a new icon
|
||||||
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
||||||
{
|
{
|
||||||
MMCIcon mmc_icon;
|
MMCIcon mmc_icon;
|
||||||
mmc_icon.m_name = key;
|
mmc_icon.m_name = key;
|
||||||
mmc_icon.m_key = key;
|
mmc_icon.m_key = key;
|
||||||
mmc_icon.replace(Builtin, key);
|
mmc_icon.replace(Builtin, key);
|
||||||
icons.push_back(mmc_icon);
|
icons.push_back(mmc_icon);
|
||||||
name_index[key] = icons.size() - 1;
|
name_index[key] = icons.size() - 1;
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
|
bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
|
||||||
{
|
{
|
||||||
// replace the icon even? is the input valid?
|
// replace the icon even? is the input valid?
|
||||||
QIcon icon(path);
|
QIcon icon(path);
|
||||||
if (icon.isNull())
|
if (!icon.availableSizes().size())
|
||||||
return false;
|
return false;
|
||||||
auto iter = name_index.find(key);
|
auto iter = name_index.find(key);
|
||||||
if (iter != name_index.end())
|
if (iter != name_index.end())
|
||||||
{
|
{
|
||||||
auto &oldOne = icons[*iter];
|
auto &oldOne = icons[*iter];
|
||||||
oldOne.replace(type, icon, path);
|
oldOne.replace(type, icon, path);
|
||||||
dataChanged(index(*iter), index(*iter));
|
dataChanged(index(*iter), index(*iter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// add a new icon
|
// add a new icon
|
||||||
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
||||||
{
|
{
|
||||||
MMCIcon mmc_icon;
|
MMCIcon mmc_icon;
|
||||||
mmc_icon.m_name = name;
|
mmc_icon.m_name = name;
|
||||||
mmc_icon.m_key = key;
|
mmc_icon.m_key = key;
|
||||||
mmc_icon.replace(type, icon, path);
|
mmc_icon.replace(type, icon, path);
|
||||||
icons.push_back(mmc_icon);
|
icons.push_back(mmc_icon);
|
||||||
name_index[key] = icons.size() - 1;
|
name_index[key] = icons.size() - 1;
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconList::saveIcon(const QString &key, const QString &path, const char * format) const
|
void IconList::saveIcon(const QString &key, const QString &path, const char * format) const
|
||||||
{
|
{
|
||||||
auto icon = getIcon(key);
|
auto icon = getIcon(key);
|
||||||
auto pixmap = icon.pixmap(128, 128);
|
auto pixmap = icon.pixmap(128, 128);
|
||||||
pixmap.save(path, format);
|
pixmap.save(path, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IconList::reindex()
|
void IconList::reindex()
|
||||||
{
|
{
|
||||||
name_index.clear();
|
name_index.clear();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &iter : icons)
|
for (auto &iter : icons)
|
||||||
{
|
{
|
||||||
name_index[iter.m_key] = i;
|
name_index[iter.m_key] = i;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon IconList::getIcon(const QString &key) const
|
QIcon IconList::getIcon(const QString &key) const
|
||||||
{
|
{
|
||||||
int icon_index = getIconIndex(key);
|
int icon_index = getIconIndex(key);
|
||||||
|
|
||||||
if (icon_index != -1)
|
if (icon_index != -1)
|
||||||
return icons[icon_index].icon();
|
return icons[icon_index].icon();
|
||||||
|
|
||||||
// Fallback for icons that don't exist.
|
// Fallback for icons that don't exist.
|
||||||
icon_index = getIconIndex("infinity");
|
icon_index = getIconIndex("infinity");
|
||||||
|
|
||||||
if (icon_index != -1)
|
if (icon_index != -1)
|
||||||
return icons[icon_index].icon();
|
return icons[icon_index].icon();
|
||||||
return QIcon();
|
return QIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon IconList::getBigIcon(const QString &key) const
|
||||||
|
{
|
||||||
|
int icon_index = getIconIndex(key);
|
||||||
|
|
||||||
|
// Fallback for icons that don't exist.
|
||||||
|
icon_index = getIconIndex(icon_index == -1 ? "infinity" : key);
|
||||||
|
|
||||||
|
if (icon_index == -1)
|
||||||
|
return QIcon();
|
||||||
|
|
||||||
|
QPixmap bigone = icons[icon_index].icon().pixmap(256,256).scaled(256,256);
|
||||||
|
return QIcon(bigone);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IconList::getIconIndex(const QString &key) const
|
int IconList::getIconIndex(const QString &key) const
|
||||||
{
|
{
|
||||||
auto iter = name_index.find(key == "default" ? "infinity" : key);
|
auto iter = name_index.find(key == "default" ? "infinity" : key);
|
||||||
if (iter != name_index.end())
|
if (iter != name_index.end())
|
||||||
return *iter;
|
return *iter;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
QString IconList::getDirectory() const
|
|
||||||
{
|
|
||||||
return m_dir.absolutePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#include "IconList.moc"
|
//#include "IconList.moc"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -32,57 +32,56 @@ class QFileSystemWatcher;
|
|||||||
|
|
||||||
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
|
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
|
explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
|
||||||
virtual ~IconList() {};
|
virtual ~IconList() {};
|
||||||
|
|
||||||
QIcon getIcon(const QString &key) const;
|
QIcon getIcon(const QString &key) const;
|
||||||
int getIconIndex(const QString &key) const;
|
QIcon getBigIcon(const QString &key) const;
|
||||||
QString getDirectory() const;
|
int getIconIndex(const QString &key) const;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
bool addThemeIcon(const QString &key);
|
bool addThemeIcon(const QString &key);
|
||||||
bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override;
|
bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override;
|
||||||
void saveIcon(const QString &key, const QString &path, const char * format) const override;
|
void saveIcon(const QString &key, const QString &path, const char * format) const override;
|
||||||
bool deleteIcon(const QString &key) override;
|
bool deleteIcon(const QString &key) override;
|
||||||
bool iconFileExists(const QString &key) const override;
|
bool iconFileExists(const QString &key) const override;
|
||||||
|
|
||||||
virtual QStringList mimeTypes() const override;
|
virtual QStringList mimeTypes() const override;
|
||||||
virtual Qt::DropActions supportedDropActions() const override;
|
virtual Qt::DropActions supportedDropActions() const override;
|
||||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
void installIcons(const QStringList &iconFiles) override;
|
void installIcons(const QStringList &iconFiles) override;
|
||||||
void installIcon(const QString &file, const QString &name) override;
|
|
||||||
|
|
||||||
const MMCIcon * icon(const QString &key) const;
|
const MMCIcon * icon(const QString &key) const;
|
||||||
|
|
||||||
void startWatching();
|
void startWatching();
|
||||||
void stopWatching();
|
void stopWatching();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void iconUpdated(QString key);
|
void iconUpdated(QString key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// hide copy constructor
|
// hide copy constructor
|
||||||
IconList(const IconList &) = delete;
|
IconList(const IconList &) = delete;
|
||||||
// hide assign op
|
// hide assign op
|
||||||
IconList &operator=(const IconList &) = delete;
|
IconList &operator=(const IconList &) = delete;
|
||||||
void reindex();
|
void reindex();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void directoryChanged(const QString &path);
|
void directoryChanged(const QString &path);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void fileChanged(const QString &path);
|
void fileChanged(const QString &path);
|
||||||
void SettingChanged(const Setting & setting, QVariant value);
|
void SettingChanged(const Setting & setting, QVariant value);
|
||||||
private:
|
private:
|
||||||
shared_qobject_ptr<QFileSystemWatcher> m_watcher;
|
std::shared_ptr<QFileSystemWatcher> m_watcher;
|
||||||
bool is_watching;
|
bool is_watching;
|
||||||
QMap<QString, int> name_index;
|
QMap<QString, int> name_index;
|
||||||
QVector<MMCIcon> icons;
|
QVector<MMCIcon> icons;
|
||||||
QDir m_dir;
|
QDir m_dir;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -19,100 +19,86 @@
|
|||||||
|
|
||||||
IconType operator--(IconType &t, int)
|
IconType operator--(IconType &t, int)
|
||||||
{
|
{
|
||||||
IconType temp = t;
|
IconType temp = t;
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case IconType::Builtin:
|
case IconType::Builtin:
|
||||||
t = IconType::ToBeDeleted;
|
t = IconType::ToBeDeleted;
|
||||||
break;
|
break;
|
||||||
case IconType::Transient:
|
case IconType::Transient:
|
||||||
t = IconType::Builtin;
|
t = IconType::Builtin;
|
||||||
break;
|
break;
|
||||||
case IconType::FileBased:
|
case IconType::FileBased:
|
||||||
t = IconType::Transient;
|
t = IconType::Transient;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
IconType MMCIcon::type() const
|
IconType MMCIcon::type() const
|
||||||
{
|
{
|
||||||
return m_current_type;
|
return m_current_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MMCIcon::name() const
|
QString MMCIcon::name() const
|
||||||
{
|
{
|
||||||
if (m_name.size())
|
if (m_name.size())
|
||||||
return m_name;
|
return m_name;
|
||||||
return m_key;
|
return m_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCIcon::has(IconType _type) const
|
bool MMCIcon::has(IconType _type) const
|
||||||
{
|
{
|
||||||
return m_images[_type].present();
|
return m_images[_type].present();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon MMCIcon::icon() const
|
QIcon MMCIcon::icon() const
|
||||||
{
|
{
|
||||||
if (m_current_type == IconType::ToBeDeleted)
|
if (m_current_type == IconType::ToBeDeleted)
|
||||||
return QIcon();
|
return QIcon();
|
||||||
auto & icon = m_images[m_current_type].icon;
|
auto & icon = m_images[m_current_type].icon;
|
||||||
if(!icon.isNull())
|
if(!icon.isNull())
|
||||||
return icon;
|
return icon;
|
||||||
// FIXME: inject this.
|
// FIXME: inject this.
|
||||||
return XdgIcon::fromTheme(m_images[m_current_type].key);
|
return XdgIcon::fromTheme(m_images[m_current_type].key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMCIcon::remove(IconType rm_type)
|
void MMCIcon::remove(IconType rm_type)
|
||||||
{
|
{
|
||||||
m_images[rm_type].filename = QString();
|
m_images[rm_type].filename = QString();
|
||||||
m_images[rm_type].icon = QIcon();
|
m_images[rm_type].icon = QIcon();
|
||||||
for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--)
|
for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--)
|
||||||
{
|
{
|
||||||
if (m_images[iter].present())
|
if (m_images[iter].present())
|
||||||
{
|
{
|
||||||
m_current_type = iter;
|
m_current_type = iter;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_current_type = IconType::ToBeDeleted;
|
m_current_type = IconType::ToBeDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
|
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
|
||||||
{
|
{
|
||||||
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
||||||
{
|
{
|
||||||
m_current_type = new_type;
|
m_current_type = new_type;
|
||||||
}
|
}
|
||||||
m_images[new_type].icon = icon;
|
m_images[new_type].icon = icon;
|
||||||
m_images[new_type].filename = path;
|
m_images[new_type].filename = path;
|
||||||
m_images[new_type].key = QString();
|
m_images[new_type].key = QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMCIcon::replace(IconType new_type, const QString& key)
|
void MMCIcon::replace(IconType new_type, const QString& key)
|
||||||
{
|
{
|
||||||
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
||||||
{
|
{
|
||||||
m_current_type = new_type;
|
m_current_type = new_type;
|
||||||
}
|
}
|
||||||
m_images[new_type].icon = QIcon();
|
m_images[new_type].icon = QIcon();
|
||||||
m_images[new_type].filename = QString();
|
m_images[new_type].filename = QString();
|
||||||
m_images[new_type].key = key;
|
m_images[new_type].key = key;
|
||||||
}
|
|
||||||
|
|
||||||
QString MMCIcon::getFilePath() const
|
|
||||||
{
|
|
||||||
if(m_current_type == IconType::ToBeDeleted){
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return m_images[m_current_type].filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool MMCIcon::isBuiltIn() const
|
|
||||||
{
|
|
||||||
return m_current_type == IconType::Builtin;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -23,29 +23,27 @@
|
|||||||
|
|
||||||
struct MULTIMC_GUI_EXPORT MMCImage
|
struct MULTIMC_GUI_EXPORT MMCImage
|
||||||
{
|
{
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
QString key;
|
QString key;
|
||||||
QString filename;
|
QString filename;
|
||||||
bool present() const
|
bool present() const
|
||||||
{
|
{
|
||||||
return !icon.isNull() || !key.isEmpty();
|
return !icon.isNull() || !key.isEmpty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MULTIMC_GUI_EXPORT MMCIcon
|
struct MULTIMC_GUI_EXPORT MMCIcon
|
||||||
{
|
{
|
||||||
QString m_key;
|
QString m_key;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
MMCImage m_images[ICONS_TOTAL];
|
MMCImage m_images[ICONS_TOTAL];
|
||||||
IconType m_current_type = ToBeDeleted;
|
IconType m_current_type = ToBeDeleted;
|
||||||
|
|
||||||
IconType type() const;
|
IconType type() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
bool has(IconType _type) const;
|
bool has(IconType _type) const;
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
void remove(IconType rm_type);
|
void remove(IconType rm_type);
|
||||||
void replace(IconType new_type, QIcon icon, QString path = QString());
|
void replace(IconType new_type, QIcon icon, QString path = QString());
|
||||||
void replace(IconType new_type, const QString &key);
|
void replace(IconType new_type, const QString &key);
|
||||||
bool isBuiltIn() const;
|
|
||||||
QString getFilePath() const;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -16,46 +16,46 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
#include "BaseInstaller.h"
|
#include "BaseInstaller.h"
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/onesix/OneSixInstance.h"
|
||||||
|
|
||||||
BaseInstaller::BaseInstaller()
|
BaseInstaller::BaseInstaller()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstaller::isApplied(MinecraftInstance *on)
|
bool BaseInstaller::isApplied(OneSixInstance *on)
|
||||||
{
|
{
|
||||||
return QFile::exists(filename(on->instanceRoot()));
|
return QFile::exists(filename(on->instanceRoot()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstaller::add(MinecraftInstance *to)
|
bool BaseInstaller::add(OneSixInstance *to)
|
||||||
{
|
{
|
||||||
if (!patchesDir(to->instanceRoot()).exists())
|
if (!patchesDir(to->instanceRoot()).exists())
|
||||||
{
|
{
|
||||||
QDir(to->instanceRoot()).mkdir("patches");
|
QDir(to->instanceRoot()).mkdir("patches");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isApplied(to))
|
if (isApplied(to))
|
||||||
{
|
{
|
||||||
if (!remove(to))
|
if (!remove(to))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstaller::remove(MinecraftInstance *from)
|
bool BaseInstaller::remove(OneSixInstance *from)
|
||||||
{
|
{
|
||||||
return QFile::remove(filename(from->instanceRoot()));
|
return QFile::remove(filename(from->instanceRoot()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstaller::filename(const QString &root) const
|
QString BaseInstaller::filename(const QString &root) const
|
||||||
{
|
{
|
||||||
return patchesDir(root).absoluteFilePath(id() + ".json");
|
return patchesDir(root).absoluteFilePath(id() + ".json");
|
||||||
}
|
}
|
||||||
QDir BaseInstaller::patchesDir(const QString &root) const
|
QDir BaseInstaller::patchesDir(const QString &root) const
|
||||||
{
|
{
|
||||||
return QDir(root + "/patches/");
|
return QDir(root + "/patches/");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
class MinecraftInstance;
|
class OneSixInstance;
|
||||||
class QDir;
|
class QDir;
|
||||||
class QString;
|
class QString;
|
||||||
class QObject;
|
class QObject;
|
||||||
@@ -30,17 +30,17 @@ typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
|
|||||||
class MULTIMC_LOGIC_EXPORT BaseInstaller
|
class MULTIMC_LOGIC_EXPORT BaseInstaller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseInstaller();
|
BaseInstaller();
|
||||||
virtual ~BaseInstaller(){};
|
virtual ~BaseInstaller(){};
|
||||||
bool isApplied(MinecraftInstance *on);
|
bool isApplied(OneSixInstance *on);
|
||||||
|
|
||||||
virtual bool add(MinecraftInstance *to);
|
virtual bool add(OneSixInstance *to);
|
||||||
virtual bool remove(MinecraftInstance *from);
|
virtual bool remove(OneSixInstance *from);
|
||||||
|
|
||||||
virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
|
virtual Task *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QString id() const = 0;
|
virtual QString id() const = 0;
|
||||||
QString filename(const QString &root) const;
|
QString filename(const QString &root) const;
|
||||||
QDir patchesDir(const QString &root) const;
|
QDir patchesDir(const QString &root) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -23,232 +23,285 @@
|
|||||||
#include "settings/Setting.h"
|
#include "settings/Setting.h"
|
||||||
#include "settings/OverrideSetting.h"
|
#include "settings/OverrideSetting.h"
|
||||||
|
|
||||||
|
#include "minecraft/MinecraftVersionList.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Commandline.h"
|
#include "Commandline.h"
|
||||||
|
|
||||||
BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
|
BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
|
||||||
: QObject()
|
: QObject()
|
||||||
{
|
{
|
||||||
m_settings = settings;
|
m_settings = settings;
|
||||||
m_rootDir = rootDir;
|
m_rootDir = rootDir;
|
||||||
|
|
||||||
m_settings->registerSetting("name", "Unnamed Instance");
|
m_settings->registerSetting("name", "Unnamed Instance");
|
||||||
m_settings->registerSetting("iconKey", "default");
|
m_settings->registerSetting("iconKey", "default");
|
||||||
m_settings->registerSetting("notes", "");
|
m_settings->registerSetting("notes", "");
|
||||||
m_settings->registerSetting("lastLaunchTime", 0);
|
m_settings->registerSetting("lastLaunchTime", 0);
|
||||||
m_settings->registerSetting("totalTimePlayed", 0);
|
m_settings->registerSetting("totalTimePlayed", 0);
|
||||||
|
|
||||||
// Custom Commands
|
// Custom Commands
|
||||||
auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
|
auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting);
|
m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting);
|
m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting);
|
m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting);
|
||||||
|
|
||||||
// Console
|
// Console
|
||||||
auto consoleSetting = m_settings->registerSetting("OverrideConsole", false);
|
auto consoleSetting = m_settings->registerSetting("OverrideConsole", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting);
|
m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting);
|
m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting);
|
m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting);
|
m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting);
|
||||||
|
|
||||||
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr);
|
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr);
|
||||||
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr);
|
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::getPreLaunchCommand()
|
QString BaseInstance::getPreLaunchCommand()
|
||||||
{
|
{
|
||||||
return settings()->get("PreLaunchCommand").toString();
|
return settings()->get("PreLaunchCommand").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::getWrapperCommand()
|
QString BaseInstance::getWrapperCommand()
|
||||||
{
|
{
|
||||||
return settings()->get("WrapperCommand").toString();
|
return settings()->get("WrapperCommand").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::getPostExitCommand()
|
QString BaseInstance::getPostExitCommand()
|
||||||
{
|
{
|
||||||
return settings()->get("PostExitCommand").toString();
|
return settings()->get("PostExitCommand").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseInstance::getConsoleMaxLines() const
|
int BaseInstance::getConsoleMaxLines() const
|
||||||
{
|
{
|
||||||
auto lineSetting = settings()->getSetting("ConsoleMaxLines");
|
auto lineSetting = settings()->getSetting("ConsoleMaxLines");
|
||||||
bool conversionOk = false;
|
bool conversionOk = false;
|
||||||
int maxLines = lineSetting->get().toInt(&conversionOk);
|
int maxLines = lineSetting->get().toInt(&conversionOk);
|
||||||
if(!conversionOk)
|
if(!conversionOk)
|
||||||
{
|
{
|
||||||
maxLines = lineSetting->defValue().toInt();
|
maxLines = lineSetting->defValue().toInt();
|
||||||
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
||||||
}
|
}
|
||||||
return maxLines;
|
return maxLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::shouldStopOnConsoleOverflow() const
|
bool BaseInstance::shouldStopOnConsoleOverflow() const
|
||||||
{
|
{
|
||||||
return settings()->get("ConsoleOverflowStop").toBool();
|
return settings()->get("ConsoleOverflowStop").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::iconUpdated(QString key)
|
void BaseInstance::iconUpdated(QString key)
|
||||||
{
|
{
|
||||||
if(iconKey() == key)
|
if(iconKey() == key)
|
||||||
{
|
{
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::invalidate()
|
void BaseInstance::invalidate()
|
||||||
{
|
{
|
||||||
changeStatus(Status::Gone);
|
changeStatus(Status::Gone);
|
||||||
qDebug() << "Instance" << id() << "has been invalidated.";
|
qDebug() << "Instance" << id() << "has been invalidated.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseInstance::nuke()
|
||||||
|
{
|
||||||
|
changeStatus(Status::Gone);
|
||||||
|
qDebug() << "Instance" << id() << "has been deleted by MultiMC.";
|
||||||
|
FS::deletePath(instanceRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::changeStatus(BaseInstance::Status newStatus)
|
void BaseInstance::changeStatus(BaseInstance::Status newStatus)
|
||||||
{
|
{
|
||||||
Status status = currentStatus();
|
Status status = currentStatus();
|
||||||
if(status != newStatus)
|
if(status != newStatus)
|
||||||
{
|
{
|
||||||
m_status = newStatus;
|
m_status = newStatus;
|
||||||
emit statusChanged(status, newStatus);
|
emit statusChanged(status, newStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseInstance::Status BaseInstance::currentStatus() const
|
BaseInstance::Status BaseInstance::currentStatus() const
|
||||||
{
|
{
|
||||||
return m_status;
|
return m_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::id() const
|
QString BaseInstance::id() const
|
||||||
{
|
{
|
||||||
return QFileInfo(instanceRoot()).fileName();
|
return QFileInfo(instanceRoot()).fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::isRunning() const
|
bool BaseInstance::isRunning() const
|
||||||
{
|
{
|
||||||
return m_isRunning;
|
return m_isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setRunning(bool running)
|
void BaseInstance::setRunning(bool running)
|
||||||
{
|
{
|
||||||
if(running == m_isRunning)
|
if(running == m_isRunning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_isRunning = running;
|
m_isRunning = running;
|
||||||
|
|
||||||
if(running)
|
if(running)
|
||||||
{
|
{
|
||||||
m_timeStarted = QDateTime::currentDateTime();
|
m_timeStarted = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
||||||
QDateTime timeEnded = QDateTime::currentDateTime();
|
QDateTime timeEnded = QDateTime::currentDateTime();
|
||||||
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
|
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit runningStatusChanged(running);
|
emit runningStatusChanged(running);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t BaseInstance::totalTimePlayed() const
|
int64_t BaseInstance::totalTimePlayed() const
|
||||||
{
|
{
|
||||||
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
||||||
if(m_isRunning)
|
if(m_isRunning)
|
||||||
{
|
{
|
||||||
QDateTime timeNow = QDateTime::currentDateTime();
|
QDateTime timeNow = QDateTime::currentDateTime();
|
||||||
return current + m_timeStarted.secsTo(timeNow);
|
return current + m_timeStarted.secsTo(timeNow);
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::resetTimePlayed()
|
void BaseInstance::resetTimePlayed()
|
||||||
{
|
{
|
||||||
settings()->reset("totalTimePlayed");
|
settings()->reset("totalTimePlayed");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::instanceType() const
|
QString BaseInstance::instanceType() const
|
||||||
{
|
{
|
||||||
return m_settings->get("InstanceType").toString();
|
return m_settings->get("InstanceType").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::instanceRoot() const
|
QString BaseInstance::instanceRoot() const
|
||||||
{
|
{
|
||||||
return m_rootDir;
|
return m_rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
InstancePtr BaseInstance::getSharedPtr()
|
||||||
|
{
|
||||||
|
return shared_from_this();
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsObjectPtr BaseInstance::settings() const
|
SettingsObjectPtr BaseInstance::settings() const
|
||||||
{
|
{
|
||||||
return m_settings;
|
return m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::canLaunch() const
|
bool BaseInstance::canLaunch() const
|
||||||
{
|
{
|
||||||
return (!hasVersionBroken() && !isRunning());
|
return (!hasVersionBroken() && !isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::reloadSettings()
|
bool BaseInstance::reload()
|
||||||
{
|
{
|
||||||
return m_settings->reload();
|
return m_settings->reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 BaseInstance::lastLaunch() const
|
qint64 BaseInstance::lastLaunch() const
|
||||||
{
|
{
|
||||||
return m_settings->get("lastLaunchTime").value<qint64>();
|
return m_settings->get("lastLaunchTime").value<qint64>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setLastLaunch(qint64 val)
|
void BaseInstance::setLastLaunch(qint64 val)
|
||||||
{
|
{
|
||||||
//FIXME: if no change, do not set. setting involves saving a file.
|
//FIXME: if no change, do not set. setting involves saving a file.
|
||||||
m_settings->set("lastLaunchTime", val);
|
m_settings->set("lastLaunchTime", val);
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseInstance::setGroupInitial(QString val)
|
||||||
|
{
|
||||||
|
if(m_group == val)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_group = val;
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseInstance::setGroupPost(QString val)
|
||||||
|
{
|
||||||
|
if(m_group == val)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setGroupInitial(val);
|
||||||
|
emit groupChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BaseInstance::group() const
|
||||||
|
{
|
||||||
|
return m_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setNotes(QString val)
|
void BaseInstance::setNotes(QString val)
|
||||||
{
|
{
|
||||||
//FIXME: if no change, do not set. setting involves saving a file.
|
//FIXME: if no change, do not set. setting involves saving a file.
|
||||||
m_settings->set("notes", val);
|
m_settings->set("notes", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::notes() const
|
QString BaseInstance::notes() const
|
||||||
{
|
{
|
||||||
return m_settings->get("notes").toString();
|
return m_settings->get("notes").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setIconKey(QString val)
|
void BaseInstance::setIconKey(QString val)
|
||||||
{
|
{
|
||||||
//FIXME: if no change, do not set. setting involves saving a file.
|
//FIXME: if no change, do not set. setting involves saving a file.
|
||||||
m_settings->set("iconKey", val);
|
m_settings->set("iconKey", val);
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::iconKey() const
|
QString BaseInstance::iconKey() const
|
||||||
{
|
{
|
||||||
return m_settings->get("iconKey").toString();
|
return m_settings->get("iconKey").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setName(QString val)
|
void BaseInstance::setName(QString val)
|
||||||
{
|
{
|
||||||
//FIXME: if no change, do not set. setting involves saving a file.
|
//FIXME: if no change, do not set. setting involves saving a file.
|
||||||
m_settings->set("name", val);
|
m_settings->set("name", val);
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::name() const
|
QString BaseInstance::name() const
|
||||||
{
|
{
|
||||||
return m_settings->get("name").toString();
|
return m_settings->get("name").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::windowTitle() const
|
QString BaseInstance::windowTitle() const
|
||||||
{
|
{
|
||||||
return "MultiMC: " + name().replace(QRegExp("[ \n\r\t]+"), " ");
|
return "MultiMC: " + name();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: why is this here? move it to MinecraftInstance!!!
|
|
||||||
QStringList BaseInstance::extraArguments() const
|
QStringList BaseInstance::extraArguments() const
|
||||||
{
|
{
|
||||||
return Commandline::splitArgs(settings()->get("JvmArgs").toString());
|
return Commandline::splitArgs(settings()->get("JvmArgs").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<LaunchTask> BaseInstance::getLaunchTask()
|
std::shared_ptr<LaunchTask> BaseInstance::getLaunchTask()
|
||||||
{
|
{
|
||||||
return m_launchProcess;
|
return m_launchProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseInstance::setProvider(BaseInstanceProvider* provider)
|
||||||
|
{
|
||||||
|
// only once.
|
||||||
|
assert(!m_provider);
|
||||||
|
if(m_provider)
|
||||||
|
{
|
||||||
|
qWarning() << "Provider set more than once for instance" << id();
|
||||||
|
}
|
||||||
|
m_provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseInstanceProvider* BaseInstance::provider() const
|
||||||
|
{
|
||||||
|
return m_provider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -30,14 +30,13 @@
|
|||||||
#include "MessageLevel.h"
|
#include "MessageLevel.h"
|
||||||
#include "pathmatcher/IPathMatcher.h"
|
#include "pathmatcher/IPathMatcher.h"
|
||||||
|
|
||||||
#include "net/Mode.h"
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
class QDir;
|
class QDir;
|
||||||
class Task;
|
class Task;
|
||||||
class LaunchTask;
|
class LaunchTask;
|
||||||
class BaseInstance;
|
class BaseInstance;
|
||||||
|
class BaseInstanceProvider;
|
||||||
|
|
||||||
// pointer for lazy people
|
// pointer for lazy people
|
||||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||||
@@ -52,217 +51,260 @@ typedef std::shared_ptr<BaseInstance> InstancePtr;
|
|||||||
*/
|
*/
|
||||||
class MULTIMC_LOGIC_EXPORT BaseInstance : public QObject, public std::enable_shared_from_this<BaseInstance>
|
class MULTIMC_LOGIC_EXPORT BaseInstance : public QObject, public std::enable_shared_from_this<BaseInstance>
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
/// no-touchy!
|
/// no-touchy!
|
||||||
BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
||||||
|
|
||||||
public: /* types */
|
public: /* types */
|
||||||
enum class Status
|
enum class Status
|
||||||
{
|
{
|
||||||
Present,
|
Present,
|
||||||
Gone // either nuked or invalidated
|
Gone // either nuked or invalidated
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// virtual destructor to make sure the destruction is COMPLETE
|
/// virtual destructor to make sure the destruction is COMPLETE
|
||||||
virtual ~BaseInstance() {};
|
virtual ~BaseInstance() {};
|
||||||
|
|
||||||
virtual void saveNow() = 0;
|
virtual void copy(SettingsObjectPtr newSettings, const QDir &newDir) {}
|
||||||
|
|
||||||
/***
|
virtual void init() = 0;
|
||||||
* the instance has been invalidated - it is no longer tracked by MultiMC for some reason,
|
|
||||||
* but it has not necessarily been deleted.
|
|
||||||
*
|
|
||||||
* Happens when the instance folder changes to some other location, or the instance is removed by external means.
|
|
||||||
*/
|
|
||||||
void invalidate();
|
|
||||||
|
|
||||||
/// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to
|
/// nuke thoroughly - deletes the instance contents, notifies the list/model which is
|
||||||
/// be unique.
|
/// responsible of cleaning up the husk
|
||||||
virtual QString id() const;
|
void nuke();
|
||||||
|
|
||||||
void setRunning(bool running);
|
/***
|
||||||
bool isRunning() const;
|
* the instance has been invalidated - it is no longer tracked by MultiMC for some reason,
|
||||||
int64_t totalTimePlayed() const;
|
* but it has not necessarily been deleted.
|
||||||
void resetTimePlayed();
|
*
|
||||||
|
* Happens when the instance folder changes to some other location, or the instance is removed by external means.
|
||||||
|
*/
|
||||||
|
void invalidate();
|
||||||
|
|
||||||
/// get the type of this instance
|
/// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to
|
||||||
QString instanceType() const;
|
/// be unique.
|
||||||
|
virtual QString id() const;
|
||||||
|
|
||||||
/// Path to the instance's root directory.
|
void setRunning(bool running);
|
||||||
QString instanceRoot() const;
|
bool isRunning() const;
|
||||||
|
int64_t totalTimePlayed() const;
|
||||||
|
void resetTimePlayed();
|
||||||
|
|
||||||
/// Path to the instance's game root directory.
|
void setProvider(BaseInstanceProvider * provider);
|
||||||
virtual QString gameRoot() const
|
BaseInstanceProvider * provider() const;
|
||||||
{
|
|
||||||
return instanceRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString name() const;
|
/// get the type of this instance
|
||||||
void setName(QString val);
|
QString instanceType() const;
|
||||||
|
|
||||||
/// Value used for instance window titles
|
/// Path to the instance's root directory.
|
||||||
QString windowTitle() const;
|
QString instanceRoot() const;
|
||||||
|
|
||||||
QString iconKey() const;
|
QString name() const;
|
||||||
void setIconKey(QString val);
|
void setName(QString val);
|
||||||
|
|
||||||
QString notes() const;
|
/// Value used for instance window titles
|
||||||
void setNotes(QString val);
|
QString windowTitle() const;
|
||||||
|
|
||||||
QString getPreLaunchCommand();
|
QString iconKey() const;
|
||||||
QString getPostExitCommand();
|
void setIconKey(QString val);
|
||||||
QString getWrapperCommand();
|
|
||||||
|
|
||||||
/// guess log level from a line of game log
|
QString notes() const;
|
||||||
virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level)
|
void setNotes(QString val);
|
||||||
{
|
|
||||||
return level;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual QStringList extraArguments() const;
|
QString group() const;
|
||||||
|
void setGroupInitial(QString val);
|
||||||
|
void setGroupPost(QString val);
|
||||||
|
|
||||||
/// Traits. Normally inside the version, depends on instance implementation.
|
QString getPreLaunchCommand();
|
||||||
virtual QSet <QString> traits() const = 0;
|
QString getPostExitCommand();
|
||||||
|
QString getWrapperCommand();
|
||||||
|
|
||||||
/**
|
/// guess log level from a line of game log
|
||||||
* Gets the time that the instance was last launched.
|
virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level)
|
||||||
* Stored in milliseconds since epoch.
|
{
|
||||||
*/
|
return level;
|
||||||
qint64 lastLaunch() const;
|
};
|
||||||
/// Sets the last launched time to 'val' milliseconds since epoch
|
|
||||||
void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
|
|
||||||
|
|
||||||
/*!
|
virtual QStringList extraArguments() const;
|
||||||
* \brief Gets this instance's settings object.
|
|
||||||
* This settings object stores instance-specific settings.
|
|
||||||
* \return A pointer to this instance's settings object.
|
|
||||||
*/
|
|
||||||
virtual SettingsObjectPtr settings() const;
|
|
||||||
|
|
||||||
/// returns a valid update task
|
virtual QString intendedVersionId() const = 0;
|
||||||
virtual shared_qobject_ptr<Task> createUpdateTask(Net::Mode mode) = 0;
|
virtual bool setIntendedVersionId(QString version) = 0;
|
||||||
|
|
||||||
/// returns a valid launcher (task container)
|
/*!
|
||||||
virtual shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) = 0;
|
* The instance's current version.
|
||||||
|
* This value represents the instance's current version. If this value is
|
||||||
|
* different from the intendedVersion, the instance should be updated.
|
||||||
|
* \warning Don't change this value unless you know what you're doing.
|
||||||
|
*/
|
||||||
|
virtual QString currentVersionId() const = 0;
|
||||||
|
|
||||||
/// returns the current launch task (if any)
|
/*!
|
||||||
shared_qobject_ptr<LaunchTask> getLaunchTask();
|
* Whether or not 'the game' should be downloaded when the instance is launched.
|
||||||
|
*/
|
||||||
|
virtual bool shouldUpdate() const = 0;
|
||||||
|
virtual void setShouldUpdate(bool val) = 0;
|
||||||
|
|
||||||
/*!
|
/// Traits. Normally inside the version, depends on instance implementation.
|
||||||
* Create envrironment variables for running the instance
|
virtual QSet <QString> traits() = 0;
|
||||||
*/
|
|
||||||
virtual QProcessEnvironment createEnvironment() = 0;
|
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
* Returns a matcher that can maps relative paths within the instance to whether they are 'log files'
|
* Gets the time that the instance was last launched.
|
||||||
*/
|
* Stored in milliseconds since epoch.
|
||||||
virtual IPathMatcher::Ptr getLogFileMatcher() = 0;
|
*/
|
||||||
|
qint64 lastLaunch() const;
|
||||||
|
/// Sets the last launched time to 'val' milliseconds since epoch
|
||||||
|
void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
|
||||||
|
|
||||||
/*!
|
InstancePtr getSharedPtr();
|
||||||
* Returns the root folder to use for looking up log files
|
|
||||||
*/
|
|
||||||
virtual QString getLogFileRoot() = 0;
|
|
||||||
|
|
||||||
virtual QString getStatusbarDescription() = 0;
|
/*!
|
||||||
|
* \brief Gets a pointer to this instance's version list.
|
||||||
|
* \return A pointer to the available version list for this instance.
|
||||||
|
*/
|
||||||
|
virtual std::shared_ptr<BaseVersionList> versionList() const = 0;
|
||||||
|
|
||||||
/// FIXME: this really should be elsewhere...
|
/*!
|
||||||
virtual QString instanceConfigFolder() const = 0;
|
* \brief Gets this instance's settings object.
|
||||||
|
* This settings object stores instance-specific settings.
|
||||||
|
* \return A pointer to this instance's settings object.
|
||||||
|
*/
|
||||||
|
virtual SettingsObjectPtr settings() const;
|
||||||
|
|
||||||
/// get variables this instance exports
|
/// returns a valid update task
|
||||||
virtual QMap<QString, QString> getVariables() const = 0;
|
virtual shared_qobject_ptr<Task> createUpdateTask() = 0;
|
||||||
|
|
||||||
virtual QString typeName() const = 0;
|
/// returns a valid launcher (task container)
|
||||||
|
virtual std::shared_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) = 0;
|
||||||
|
|
||||||
bool hasVersionBroken() const
|
/// returns the current launch task (if any)
|
||||||
{
|
std::shared_ptr<LaunchTask> getLaunchTask();
|
||||||
return m_hasBrokenVersion;
|
|
||||||
}
|
|
||||||
void setVersionBroken(bool value)
|
|
||||||
{
|
|
||||||
if(m_hasBrokenVersion != value)
|
|
||||||
{
|
|
||||||
m_hasBrokenVersion = value;
|
|
||||||
emit propertiesChanged(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasUpdateAvailable() const
|
/*!
|
||||||
{
|
* Returns a task that should be done right before launch
|
||||||
return m_hasUpdate;
|
* This task should do any extra preparations needed
|
||||||
}
|
*/
|
||||||
void setUpdateAvailable(bool value)
|
virtual std::shared_ptr<Task> createJarModdingTask() = 0;
|
||||||
{
|
|
||||||
if(m_hasUpdate != value)
|
|
||||||
{
|
|
||||||
m_hasUpdate = value;
|
|
||||||
emit propertiesChanged(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasCrashed() const
|
/*!
|
||||||
{
|
* Create envrironment variables for running the instance
|
||||||
return m_crashed;
|
*/
|
||||||
}
|
virtual QProcessEnvironment createEnvironment() = 0;
|
||||||
void setCrashed(bool value)
|
|
||||||
{
|
|
||||||
if(m_crashed != value)
|
|
||||||
{
|
|
||||||
m_crashed = value;
|
|
||||||
emit propertiesChanged(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool canLaunch() const;
|
/*!
|
||||||
virtual bool canEdit() const = 0;
|
* Returns a matcher that can maps relative paths within the instance to whether they are 'log files'
|
||||||
virtual bool canExport() const = 0;
|
*/
|
||||||
|
virtual IPathMatcher::Ptr getLogFileMatcher() = 0;
|
||||||
|
|
||||||
bool reloadSettings();
|
/*!
|
||||||
|
* Returns the root folder to use for looking up log files
|
||||||
|
*/
|
||||||
|
virtual QString getLogFileRoot() = 0;
|
||||||
|
|
||||||
/**
|
virtual QString getStatusbarDescription() = 0;
|
||||||
* 'print' a verbose desription of the instance into a QStringList
|
|
||||||
*/
|
|
||||||
virtual QStringList verboseDescription(AuthSessionPtr session) = 0;
|
|
||||||
|
|
||||||
Status currentStatus() const;
|
/// FIXME: this really should be elsewhere...
|
||||||
|
virtual QString instanceConfigFolder() const = 0;
|
||||||
|
|
||||||
int getConsoleMaxLines() const;
|
/// get variables this instance exports
|
||||||
bool shouldStopOnConsoleOverflow() const;
|
virtual QMap<QString, QString> getVariables() const = 0;
|
||||||
|
|
||||||
|
virtual QString typeName() const = 0;
|
||||||
|
|
||||||
|
bool hasVersionBroken() const
|
||||||
|
{
|
||||||
|
return m_hasBrokenVersion;
|
||||||
|
}
|
||||||
|
void setVersionBroken(bool value)
|
||||||
|
{
|
||||||
|
if(m_hasBrokenVersion != value)
|
||||||
|
{
|
||||||
|
m_hasBrokenVersion = value;
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasUpdateAvailable() const
|
||||||
|
{
|
||||||
|
return m_hasUpdate;
|
||||||
|
}
|
||||||
|
void setUpdateAvailable(bool value)
|
||||||
|
{
|
||||||
|
if(m_hasUpdate != value)
|
||||||
|
{
|
||||||
|
m_hasUpdate = value;
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasCrashed() const
|
||||||
|
{
|
||||||
|
return m_crashed;
|
||||||
|
}
|
||||||
|
void setCrashed(bool value)
|
||||||
|
{
|
||||||
|
if(m_crashed != value)
|
||||||
|
{
|
||||||
|
m_crashed = value;
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canLaunch() const;
|
||||||
|
virtual bool canExport() const = 0;
|
||||||
|
|
||||||
|
virtual bool reload();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 'print' a verbose desription of the instance into a QStringList
|
||||||
|
*/
|
||||||
|
virtual QStringList verboseDescription(AuthSessionPtr session) = 0;
|
||||||
|
|
||||||
|
Status currentStatus() const;
|
||||||
|
|
||||||
|
int getConsoleMaxLines() const;
|
||||||
|
bool shouldStopOnConsoleOverflow() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeStatus(Status newStatus);
|
void changeStatus(Status newStatus);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/*!
|
/*!
|
||||||
* \brief Signal emitted when properties relevant to the instance view change
|
* \brief Signal emitted when properties relevant to the instance view change
|
||||||
*/
|
*/
|
||||||
void propertiesChanged(BaseInstance *inst);
|
void propertiesChanged(BaseInstance *inst);
|
||||||
|
/*!
|
||||||
|
* \brief Signal emitted when groups are affected in any way
|
||||||
|
*/
|
||||||
|
void groupChanged();
|
||||||
|
|
||||||
void launchTaskChanged(shared_qobject_ptr<LaunchTask>);
|
void launchTaskChanged(std::shared_ptr<LaunchTask>);
|
||||||
|
|
||||||
void runningStatusChanged(bool running);
|
void runningStatusChanged(bool running);
|
||||||
|
|
||||||
void statusChanged(Status from, Status to);
|
void statusChanged(Status from, Status to);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void iconUpdated(QString key);
|
void iconUpdated(QString key);
|
||||||
|
|
||||||
protected: /* data */
|
protected: /* data */
|
||||||
QString m_rootDir;
|
QString m_rootDir;
|
||||||
SettingsObjectPtr m_settings;
|
QString m_group;
|
||||||
// InstanceFlags m_flags;
|
SettingsObjectPtr m_settings;
|
||||||
bool m_isRunning = false;
|
// InstanceFlags m_flags;
|
||||||
shared_qobject_ptr<LaunchTask> m_launchProcess;
|
bool m_isRunning = false;
|
||||||
QDateTime m_timeStarted;
|
std::shared_ptr<LaunchTask> m_launchProcess;
|
||||||
|
QDateTime m_timeStarted;
|
||||||
|
BaseInstanceProvider * m_provider = nullptr;
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
Status m_status = Status::Present;
|
Status m_status = Status::Present;
|
||||||
bool m_crashed = false;
|
bool m_crashed = false;
|
||||||
bool m_hasUpdate = false;
|
bool m_hasUpdate = false;
|
||||||
bool m_hasBrokenVersion = false;
|
bool m_hasBrokenVersion = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(shared_qobject_ptr<BaseInstance>)
|
Q_DECLARE_METATYPE(std::shared_ptr<BaseInstance>)
|
||||||
//Q_DECLARE_METATYPE(BaseInstance::InstanceFlag)
|
//Q_DECLARE_METATYPE(BaseInstance::InstanceFlag)
|
||||||
//Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)
|
//Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)
|
||||||
|
|||||||
57
api/logic/BaseInstanceProvider.h
Normal file
57
api/logic/BaseInstanceProvider.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
#include "settings/SettingsObject.h"
|
||||||
|
|
||||||
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
|
using InstanceId = QString;
|
||||||
|
using InstanceLocator = std::pair<InstancePtr, int>;
|
||||||
|
|
||||||
|
enum class InstCreateError
|
||||||
|
{
|
||||||
|
NoCreateError = 0,
|
||||||
|
NoSuchVersion,
|
||||||
|
UnknownCreateError,
|
||||||
|
InstExists,
|
||||||
|
CantCreateDir
|
||||||
|
};
|
||||||
|
|
||||||
|
class MULTIMC_LOGIC_EXPORT BaseInstanceProvider : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
BaseInstanceProvider(SettingsObjectPtr settings) : m_globalSettings(settings)
|
||||||
|
{
|
||||||
|
// nil
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
virtual QList<InstanceId> discoverInstances() = 0;
|
||||||
|
virtual InstancePtr loadInstance(const InstanceId &id) = 0;
|
||||||
|
virtual void loadGroupList() = 0;
|
||||||
|
virtual void saveGroupList() = 0;
|
||||||
|
|
||||||
|
virtual QString getStagedInstancePath()
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
virtual bool commitStagedInstance(const QString & keyPath, const QString & path, const QString& instanceName, const QString & groupName)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool destroyStagingPath(const QString & path)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
// Emit this when the list of provided instances changed
|
||||||
|
void instancesChanged();
|
||||||
|
// Emit when the set of groups your provider supplies changes.
|
||||||
|
void groupsChanged(QSet<QString> groups);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SettingsObjectPtr m_globalSettings;
|
||||||
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -25,33 +25,33 @@
|
|||||||
class BaseVersion
|
class BaseVersion
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~BaseVersion() {}
|
virtual ~BaseVersion() {}
|
||||||
/*!
|
/*!
|
||||||
* A string used to identify this version in config files.
|
* A string used to identify this version in config files.
|
||||||
* This should be unique within the version list or shenanigans will occur.
|
* This should be unique within the version list or shenanigans will occur.
|
||||||
*/
|
*/
|
||||||
virtual QString descriptor() = 0;
|
virtual QString descriptor() = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* The name of this version as it is displayed to the user.
|
* The name of this version as it is displayed to the user.
|
||||||
* For example: "1.5.1"
|
* For example: "1.5.1"
|
||||||
*/
|
*/
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This should return a string that describes
|
* This should return a string that describes
|
||||||
* the kind of version this is (Stable, Beta, Snapshot, whatever)
|
* the kind of version this is (Stable, Beta, Snapshot, whatever)
|
||||||
*/
|
*/
|
||||||
virtual QString typeString() const = 0;
|
virtual QString typeString() const = 0;
|
||||||
|
|
||||||
virtual bool operator<(BaseVersion &a)
|
virtual bool operator<(BaseVersion &a)
|
||||||
{
|
{
|
||||||
return name() < a.name();
|
return name() < a.name();
|
||||||
};
|
};
|
||||||
virtual bool operator>(BaseVersion &a)
|
virtual bool operator>(BaseVersion &a)
|
||||||
{
|
{
|
||||||
return name() > a.name();
|
return name() > a.name();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
|
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -22,78 +22,83 @@ BaseVersionList::BaseVersionList(QObject *parent) : QAbstractListModel(parent)
|
|||||||
|
|
||||||
BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
|
BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count(); i++)
|
for (int i = 0; i < count(); i++)
|
||||||
{
|
{
|
||||||
if (at(i)->descriptor() == descriptor)
|
if (at(i)->descriptor() == descriptor)
|
||||||
return at(i);
|
return at(i);
|
||||||
}
|
}
|
||||||
return BaseVersionPtr();
|
return BaseVersionPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseVersionPtr BaseVersionList::getLatestStable() const
|
||||||
|
{
|
||||||
|
if (count() <= 0)
|
||||||
|
return BaseVersionPtr();
|
||||||
|
else
|
||||||
|
return at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseVersionPtr BaseVersionList::getRecommended() const
|
BaseVersionPtr BaseVersionList::getRecommended() const
|
||||||
{
|
{
|
||||||
if (count() <= 0)
|
return getLatestStable();
|
||||||
return BaseVersionPtr();
|
|
||||||
else
|
|
||||||
return at(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (index.row() > count())
|
if (index.row() > count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
BaseVersionPtr version = at(index.row());
|
BaseVersionPtr version = at(index.row());
|
||||||
|
|
||||||
switch (role)
|
switch (role)
|
||||||
{
|
{
|
||||||
case VersionPointerRole:
|
case VersionPointerRole:
|
||||||
return qVariantFromValue(version);
|
return qVariantFromValue(version);
|
||||||
|
|
||||||
case VersionRole:
|
case VersionRole:
|
||||||
return version->name();
|
return version->name();
|
||||||
|
|
||||||
case VersionIdRole:
|
case VersionIdRole:
|
||||||
return version->descriptor();
|
return version->descriptor();
|
||||||
|
|
||||||
case TypeRole:
|
case TypeRole:
|
||||||
return version->typeString();
|
return version->typeString();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseVersionList::RoleList BaseVersionList::providesRoles() const
|
BaseVersionList::RoleList BaseVersionList::providesRoles() const
|
||||||
{
|
{
|
||||||
return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
|
return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseVersionList::rowCount(const QModelIndex &parent) const
|
int BaseVersionList::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// Return count
|
// Return count
|
||||||
return count();
|
return count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseVersionList::columnCount(const QModelIndex &parent) const
|
int BaseVersionList::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> BaseVersionList::roleNames() const
|
QHash<int, QByteArray> BaseVersionList::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
|
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
|
||||||
roles.insert(VersionRole, "version");
|
roles.insert(VersionRole, "version");
|
||||||
roles.insert(VersionIdRole, "versionId");
|
roles.insert(VersionIdRole, "versionId");
|
||||||
roles.insert(ParentVersionRole, "parentGameVersion");
|
roles.insert(ParentGameVersionRole, "parentGameVersion");
|
||||||
roles.insert(RecommendedRole, "recommended");
|
roles.insert(RecommendedRole, "recommended");
|
||||||
roles.insert(LatestRole, "latest");
|
roles.insert(LatestRole, "latest");
|
||||||
roles.insert(TypeRole, "type");
|
roles.insert(TypeRole, "type");
|
||||||
roles.insert(BranchRole, "branch");
|
roles.insert(BranchRole, "branch");
|
||||||
roles.insert(PathRole, "path");
|
roles.insert(PathRole, "path");
|
||||||
roles.insert(ArchitectureRole, "architecture");
|
roles.insert(ArchitectureRole, "architecture");
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
#include "QObjectPtr.h"
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Class that each instance type's version list derives from.
|
* \brief Class that each instance type's version list derives from.
|
||||||
@@ -38,85 +37,90 @@
|
|||||||
*/
|
*/
|
||||||
class MULTIMC_LOGIC_EXPORT BaseVersionList : public QAbstractListModel
|
class MULTIMC_LOGIC_EXPORT BaseVersionList : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum ModelRoles
|
enum ModelRoles
|
||||||
{
|
{
|
||||||
VersionPointerRole = Qt::UserRole,
|
VersionPointerRole = Qt::UserRole,
|
||||||
VersionRole,
|
VersionRole,
|
||||||
VersionIdRole,
|
VersionIdRole,
|
||||||
ParentVersionRole,
|
ParentGameVersionRole,
|
||||||
RecommendedRole,
|
RecommendedRole,
|
||||||
LatestRole,
|
LatestRole,
|
||||||
TypeRole,
|
TypeRole,
|
||||||
BranchRole,
|
BranchRole,
|
||||||
PathRole,
|
PathRole,
|
||||||
ArchitectureRole,
|
ArchitectureRole,
|
||||||
SortRole
|
SortRole
|
||||||
};
|
};
|
||||||
typedef QList<int> RoleList;
|
typedef QList<int> RoleList;
|
||||||
|
|
||||||
explicit BaseVersionList(QObject *parent = 0);
|
explicit BaseVersionList(QObject *parent = 0);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets a task that will reload the version list.
|
* \brief Gets a task that will reload the version list.
|
||||||
* Simply execute the task to load the list.
|
* Simply execute the task to load the list.
|
||||||
* The task returned by this function should reset the model when it's done.
|
* The task returned by this function should reset the model when it's done.
|
||||||
* \return A pointer to a task that reloads the version list.
|
* \return A pointer to a task that reloads the version list.
|
||||||
*/
|
*/
|
||||||
virtual shared_qobject_ptr<Task> getLoadTask() = 0;
|
virtual Task *getLoadTask() = 0;
|
||||||
|
|
||||||
//! Checks whether or not the list is loaded. If this returns false, the list should be
|
//! Checks whether or not the list is loaded. If this returns false, the list should be
|
||||||
//loaded.
|
//loaded.
|
||||||
virtual bool isLoaded() = 0;
|
virtual bool isLoaded() = 0;
|
||||||
|
|
||||||
//! Gets the version at the given index.
|
//! Gets the version at the given index.
|
||||||
virtual const BaseVersionPtr at(int i) const = 0;
|
virtual const BaseVersionPtr at(int i) const = 0;
|
||||||
|
|
||||||
//! Returns the number of versions in the list.
|
//! Returns the number of versions in the list.
|
||||||
virtual int count() const = 0;
|
virtual int count() const = 0;
|
||||||
|
|
||||||
//////// List Model Functions ////////
|
//////// List Model Functions ////////
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
virtual int rowCount(const QModelIndex &parent) const;
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
virtual int columnCount(const QModelIndex &parent) const;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
virtual QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
//! which roles are provided by this version list?
|
//! which roles are provided by this version list?
|
||||||
virtual RoleList providesRoles() const;
|
virtual RoleList providesRoles() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Finds a version by its descriptor.
|
* \brief Finds a version by its descriptor.
|
||||||
* \param descriptor The descriptor of the version to find.
|
* \param The descriptor of the version to find.
|
||||||
* \return A const pointer to the version with the given descriptor. NULL if
|
* \return A const pointer to the version with the given descriptor. NULL if
|
||||||
* one doesn't exist.
|
* one doesn't exist.
|
||||||
*/
|
*/
|
||||||
virtual BaseVersionPtr findVersion(const QString &descriptor);
|
virtual BaseVersionPtr findVersion(const QString &descriptor);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the recommended version from this list
|
* \brief Gets the latest stable version from this list
|
||||||
* If the list doesn't support recommended versions, this works exactly as getLatestStable
|
*/
|
||||||
*/
|
virtual BaseVersionPtr getLatestStable() const;
|
||||||
virtual BaseVersionPtr getRecommended() const;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Sorts the version list.
|
* \brief Gets the recommended version from this list
|
||||||
*/
|
* If the list doesn't support recommended versions, this works exactly as getLatestStable
|
||||||
virtual void sortVersions() = 0;
|
*/
|
||||||
|
virtual BaseVersionPtr getRecommended() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Sorts the version list.
|
||||||
|
*/
|
||||||
|
virtual void sortVersions() = 0;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
slots:
|
slots:
|
||||||
/*!
|
/*!
|
||||||
* Updates this list with the given list of versions.
|
* Updates this list with the given list of versions.
|
||||||
* This is done by copying each version in the given list and inserting it
|
* This is done by copying each version in the given list and inserting it
|
||||||
* into this one.
|
* into this one.
|
||||||
* We need to do this so that we can set the parents of the versions are set to this
|
* We need to do this so that we can set the parents of the versions are set to this
|
||||||
* version list. This can't be done in the load task, because the versions the load
|
* version list. This can't be done in the load task, because the versions the load
|
||||||
* task creates are on the load task's thread and Qt won't allow their parents
|
* task creates are on the load task's thread and Qt won't allow their parents
|
||||||
* to be set to something created on another thread.
|
* to be set to something created on another thread.
|
||||||
* To get around that problem, we invoke this method on the GUI thread, which
|
* To get around that problem, we invoke this method on the GUI thread, which
|
||||||
* then copies the versions and sets their parents correctly.
|
* then copies the versions and sets their parents correctly.
|
||||||
* \param versions List of versions whose parents should be set.
|
* \param versions List of versions whose parents should be set.
|
||||||
*/
|
*/
|
||||||
virtual void updateListData(QList<BaseVersionPtr> versions) = 0;
|
virtual void updateListData(QList<BaseVersionPtr> versions) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,454 +3,461 @@ project(MultiMC_logic)
|
|||||||
include (UnitTest)
|
include (UnitTest)
|
||||||
|
|
||||||
set(CORE_SOURCES
|
set(CORE_SOURCES
|
||||||
# LOGIC - Base classes and infrastructure
|
# LOGIC - Base classes and infrastructure
|
||||||
BaseInstaller.h
|
BaseInstaller.h
|
||||||
BaseInstaller.cpp
|
BaseInstaller.cpp
|
||||||
BaseVersionList.h
|
BaseVersionList.h
|
||||||
BaseVersionList.cpp
|
BaseVersionList.cpp
|
||||||
InstanceList.h
|
InstanceCreationTask.h
|
||||||
InstanceList.cpp
|
InstanceCreationTask.cpp
|
||||||
InstanceTask.h
|
InstanceCopyTask.h
|
||||||
InstanceTask.cpp
|
InstanceCopyTask.cpp
|
||||||
LoggedProcess.h
|
InstanceImportTask.h
|
||||||
LoggedProcess.cpp
|
InstanceImportTask.cpp
|
||||||
MessageLevel.cpp
|
InstanceList.h
|
||||||
MessageLevel.h
|
InstanceList.cpp
|
||||||
BaseVersion.h
|
LoggedProcess.h
|
||||||
BaseInstance.h
|
LoggedProcess.cpp
|
||||||
BaseInstance.cpp
|
MessageLevel.cpp
|
||||||
NullInstance.h
|
MessageLevel.h
|
||||||
MMCZip.h
|
BaseInstanceProvider.h
|
||||||
MMCZip.cpp
|
FolderInstanceProvider.h
|
||||||
MMCStrings.h
|
FolderInstanceProvider.cpp
|
||||||
MMCStrings.cpp
|
BaseVersion.h
|
||||||
|
BaseInstance.h
|
||||||
|
BaseInstance.cpp
|
||||||
|
NullInstance.h
|
||||||
|
MMCZip.h
|
||||||
|
MMCZip.cpp
|
||||||
|
MMCStrings.h
|
||||||
|
MMCStrings.cpp
|
||||||
|
|
||||||
# Basic instance manipulation tasks (derived from InstanceTask)
|
# Use tracking separate from memory management
|
||||||
InstanceCreationTask.h
|
Usable.h
|
||||||
InstanceCreationTask.cpp
|
|
||||||
InstanceCopyTask.h
|
|
||||||
InstanceCopyTask.cpp
|
|
||||||
InstanceImportTask.h
|
|
||||||
InstanceImportTask.cpp
|
|
||||||
|
|
||||||
# Use tracking separate from memory management
|
# Prefix tree where node names are strings between separators
|
||||||
Usable.h
|
SeparatorPrefixTree.h
|
||||||
|
|
||||||
# Prefix tree where node names are strings between separators
|
# WARNING: globals live here
|
||||||
SeparatorPrefixTree.h
|
Env.h
|
||||||
|
Env.cpp
|
||||||
|
|
||||||
# WARNING: globals live here
|
# JSON parsing helpers
|
||||||
Env.h
|
Json.h
|
||||||
Env.cpp
|
Json.cpp
|
||||||
|
|
||||||
# String filters
|
FileSystem.h
|
||||||
Filter.h
|
FileSystem.cpp
|
||||||
Filter.cpp
|
|
||||||
|
|
||||||
# JSON parsing helpers
|
Exception.h
|
||||||
Json.h
|
|
||||||
Json.cpp
|
|
||||||
|
|
||||||
FileSystem.h
|
# RW lock protected map
|
||||||
FileSystem.cpp
|
RWStorage.h
|
||||||
|
|
||||||
Exception.h
|
# A variable that has an implicit default value and keeps track of changes
|
||||||
|
DefaultVariable.h
|
||||||
|
|
||||||
# RW lock protected map
|
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
|
||||||
RWStorage.h
|
QObjectPtr.h
|
||||||
|
|
||||||
# A variable that has an implicit default value and keeps track of changes
|
# Compression support
|
||||||
DefaultVariable.h
|
GZip.h
|
||||||
|
GZip.cpp
|
||||||
|
|
||||||
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
|
# Command line parameter parsing
|
||||||
QObjectPtr.h
|
Commandline.h
|
||||||
|
Commandline.cpp
|
||||||
|
|
||||||
# Compression support
|
# Version number string support
|
||||||
GZip.h
|
Version.h
|
||||||
GZip.cpp
|
Version.cpp
|
||||||
|
|
||||||
# Command line parameter parsing
|
# A Recursive file system watcher
|
||||||
Commandline.h
|
RecursiveFileSystemWatcher.h
|
||||||
Commandline.cpp
|
RecursiveFileSystemWatcher.cpp
|
||||||
|
|
||||||
# Version number string support
|
|
||||||
Version.h
|
|
||||||
Version.cpp
|
|
||||||
|
|
||||||
# A Recursive file system watcher
|
|
||||||
RecursiveFileSystemWatcher.h
|
|
||||||
RecursiveFileSystemWatcher.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(FileSystem
|
add_unit_test(FileSystem
|
||||||
SOURCES FileSystem_test.cpp
|
SOURCES FileSystem_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
DATA testdata
|
DATA testdata
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(GZip
|
add_unit_test(GZip
|
||||||
SOURCES GZip_test.cpp
|
SOURCES GZip_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
set(PATHMATCHER_SOURCES
|
set(PATHMATCHER_SOURCES
|
||||||
# Path matchers
|
# Path matchers
|
||||||
pathmatcher/FSTreeMatcher.h
|
pathmatcher/FSTreeMatcher.h
|
||||||
pathmatcher/IPathMatcher.h
|
pathmatcher/IPathMatcher.h
|
||||||
pathmatcher/MultiMatcher.h
|
pathmatcher/MultiMatcher.h
|
||||||
pathmatcher/RegexpMatcher.h
|
pathmatcher/RegexpMatcher.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(NET_SOURCES
|
set(NET_SOURCES
|
||||||
# network stuffs
|
# network stuffs
|
||||||
net/ByteArraySink.h
|
net/ByteArraySink.h
|
||||||
net/ChecksumValidator.h
|
net/ChecksumValidator.h
|
||||||
net/Download.cpp
|
net/Download.cpp
|
||||||
net/Download.h
|
net/Download.h
|
||||||
net/FileSink.cpp
|
net/FileSink.cpp
|
||||||
net/FileSink.h
|
net/FileSink.h
|
||||||
net/HttpMetaCache.cpp
|
net/HttpMetaCache.cpp
|
||||||
net/HttpMetaCache.h
|
net/HttpMetaCache.h
|
||||||
net/MetaCacheSink.cpp
|
net/MetaCacheSink.cpp
|
||||||
net/MetaCacheSink.h
|
net/MetaCacheSink.h
|
||||||
net/NetAction.h
|
net/NetAction.h
|
||||||
net/NetJob.cpp
|
net/NetJob.cpp
|
||||||
net/NetJob.h
|
net/NetJob.h
|
||||||
net/PasteUpload.cpp
|
net/PasteUpload.cpp
|
||||||
net/PasteUpload.h
|
net/PasteUpload.h
|
||||||
net/Sink.h
|
net/Sink.h
|
||||||
net/URLConstants.cpp
|
net/URLConstants.cpp
|
||||||
net/URLConstants.h
|
net/URLConstants.h
|
||||||
net/Validator.h
|
net/Validator.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Game launch logic
|
# Game launch logic
|
||||||
set(LAUNCH_SOURCES
|
set(LAUNCH_SOURCES
|
||||||
launch/steps/PostLaunchCommand.cpp
|
launch/steps/PostLaunchCommand.cpp
|
||||||
launch/steps/PostLaunchCommand.h
|
launch/steps/PostLaunchCommand.h
|
||||||
launch/steps/PreLaunchCommand.cpp
|
launch/steps/PreLaunchCommand.cpp
|
||||||
launch/steps/PreLaunchCommand.h
|
launch/steps/PreLaunchCommand.h
|
||||||
launch/steps/TextPrint.cpp
|
launch/steps/TextPrint.cpp
|
||||||
launch/steps/TextPrint.h
|
launch/steps/TextPrint.h
|
||||||
launch/steps/Update.cpp
|
launch/steps/Update.cpp
|
||||||
launch/steps/Update.h
|
launch/steps/Update.h
|
||||||
launch/LaunchStep.cpp
|
launch/LaunchStep.cpp
|
||||||
launch/LaunchStep.h
|
launch/LaunchStep.h
|
||||||
launch/LaunchTask.cpp
|
launch/LaunchTask.cpp
|
||||||
launch/LaunchTask.h
|
launch/LaunchTask.h
|
||||||
launch/LogModel.cpp
|
launch/LogModel.cpp
|
||||||
launch/LogModel.h
|
launch/LogModel.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# Old update system
|
# Old update system
|
||||||
set(UPDATE_SOURCES
|
set(UPDATE_SOURCES
|
||||||
updater/GoUpdate.h
|
updater/GoUpdate.h
|
||||||
updater/GoUpdate.cpp
|
updater/GoUpdate.cpp
|
||||||
updater/UpdateChecker.h
|
updater/UpdateChecker.h
|
||||||
updater/UpdateChecker.cpp
|
updater/UpdateChecker.cpp
|
||||||
updater/DownloadTask.h
|
updater/DownloadTask.h
|
||||||
updater/DownloadTask.cpp
|
updater/DownloadTask.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(UpdateChecker
|
add_unit_test(UpdateChecker
|
||||||
SOURCES updater/UpdateChecker_test.cpp
|
SOURCES updater/UpdateChecker_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
DATA updater/testdata
|
DATA updater/testdata
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(DownloadTask
|
add_unit_test(DownloadTask
|
||||||
SOURCES updater/DownloadTask_test.cpp
|
SOURCES updater/DownloadTask_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
DATA updater/testdata
|
DATA updater/testdata
|
||||||
)
|
)
|
||||||
|
|
||||||
# Rarely used notifications
|
# Rarely used notifications
|
||||||
set(NOTIFICATIONS_SOURCES
|
set(NOTIFICATIONS_SOURCES
|
||||||
# Notifications - short warning messages
|
# Notifications - short warning messages
|
||||||
notifications/NotificationChecker.h
|
notifications/NotificationChecker.h
|
||||||
notifications/NotificationChecker.cpp
|
notifications/NotificationChecker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Backend for the news bar... there's usually no news.
|
# Backend for the news bar... there's usually no news.
|
||||||
set(NEWS_SOURCES
|
set(NEWS_SOURCES
|
||||||
# News System
|
# News System
|
||||||
news/NewsChecker.h
|
news/NewsChecker.h
|
||||||
news/NewsChecker.cpp
|
news/NewsChecker.cpp
|
||||||
news/NewsEntry.h
|
news/NewsEntry.h
|
||||||
news/NewsEntry.cpp
|
news/NewsEntry.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Icon interface
|
# Icon interface
|
||||||
set(ICONS_SOURCES
|
set(ICONS_SOURCES
|
||||||
# Icons System and related code
|
# News System
|
||||||
icons/IIconList.h
|
icons/IIconList.h
|
||||||
icons/IIconList.cpp
|
icons/IIconList.cpp
|
||||||
icons/IconUtils.h
|
|
||||||
icons/IconUtils.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Minecraft services status checker
|
# Minecraft services status checker
|
||||||
set(STATUS_SOURCES
|
set(STATUS_SOURCES
|
||||||
# Status system
|
# Status system
|
||||||
status/StatusChecker.h
|
status/StatusChecker.h
|
||||||
status/StatusChecker.cpp
|
status/StatusChecker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Support for Minecraft instances and launch
|
# Support for Minecraft instances and launch
|
||||||
set(MINECRAFT_SOURCES
|
set(MINECRAFT_SOURCES
|
||||||
# Minecraft support
|
# Minecraft support
|
||||||
minecraft/auth/AuthSession.h
|
minecraft/auth/AuthSession.h
|
||||||
minecraft/auth/AuthSession.cpp
|
minecraft/auth/AuthSession.cpp
|
||||||
minecraft/auth/MojangAccountList.h
|
minecraft/auth/MojangAccountList.h
|
||||||
minecraft/auth/MojangAccountList.cpp
|
minecraft/auth/MojangAccountList.cpp
|
||||||
minecraft/auth/MojangAccount.h
|
minecraft/auth/MojangAccount.h
|
||||||
minecraft/auth/MojangAccount.cpp
|
minecraft/auth/MojangAccount.cpp
|
||||||
minecraft/auth/YggdrasilTask.h
|
minecraft/auth/YggdrasilTask.h
|
||||||
minecraft/auth/YggdrasilTask.cpp
|
minecraft/auth/YggdrasilTask.cpp
|
||||||
minecraft/auth/flows/AuthenticateTask.h
|
minecraft/auth/flows/AuthenticateTask.h
|
||||||
minecraft/auth/flows/AuthenticateTask.cpp
|
minecraft/auth/flows/AuthenticateTask.cpp
|
||||||
minecraft/auth/flows/RefreshTask.cpp
|
minecraft/auth/flows/RefreshTask.cpp
|
||||||
minecraft/auth/flows/RefreshTask.cpp
|
minecraft/auth/flows/RefreshTask.cpp
|
||||||
minecraft/auth/flows/ValidateTask.h
|
minecraft/auth/flows/ValidateTask.h
|
||||||
minecraft/auth/flows/ValidateTask.cpp
|
minecraft/auth/flows/ValidateTask.cpp
|
||||||
minecraft/gameoptions/GameOptions.h
|
minecraft/onesix/OneSixUpdate.h
|
||||||
minecraft/gameoptions/GameOptions.cpp
|
minecraft/onesix/OneSixUpdate.cpp
|
||||||
minecraft/update/AssetUpdateTask.h
|
minecraft/onesix/OneSixInstance.h
|
||||||
minecraft/update/AssetUpdateTask.cpp
|
minecraft/onesix/OneSixInstance.cpp
|
||||||
minecraft/update/FMLLibrariesTask.cpp
|
minecraft/onesix/OneSixProfileStrategy.cpp
|
||||||
minecraft/update/FMLLibrariesTask.h
|
minecraft/onesix/OneSixProfileStrategy.h
|
||||||
minecraft/update/FoldersTask.cpp
|
minecraft/onesix/OneSixVersionFormat.cpp
|
||||||
minecraft/update/FoldersTask.h
|
minecraft/onesix/OneSixVersionFormat.h
|
||||||
minecraft/update/LibrariesTask.cpp
|
minecraft/onesix/update/AssetUpdateTask.h
|
||||||
minecraft/update/LibrariesTask.h
|
minecraft/onesix/update/AssetUpdateTask.cpp
|
||||||
minecraft/launch/ClaimAccount.cpp
|
minecraft/onesix/update/FMLLibrariesTask.cpp
|
||||||
minecraft/launch/ClaimAccount.h
|
minecraft/onesix/update/FMLLibrariesTask.h
|
||||||
minecraft/launch/CreateServerResourcePacksFolder.cpp
|
minecraft/onesix/update/FoldersTask.cpp
|
||||||
minecraft/launch/CreateServerResourcePacksFolder.h
|
minecraft/onesix/update/FoldersTask.h
|
||||||
minecraft/launch/ModMinecraftJar.cpp
|
minecraft/onesix/update/LibrariesTask.cpp
|
||||||
minecraft/launch/ModMinecraftJar.h
|
minecraft/onesix/update/LibrariesTask.h
|
||||||
minecraft/launch/DirectJavaLaunch.cpp
|
minecraft/launch/ClaimAccount.cpp
|
||||||
minecraft/launch/DirectJavaLaunch.h
|
minecraft/launch/ClaimAccount.h
|
||||||
minecraft/launch/ExtractNatives.cpp
|
minecraft/launch/CreateServerResourcePacksFolder.cpp
|
||||||
minecraft/launch/ExtractNatives.h
|
minecraft/launch/CreateServerResourcePacksFolder.h
|
||||||
minecraft/launch/LauncherPartLaunch.cpp
|
minecraft/launch/ModMinecraftJar.cpp
|
||||||
minecraft/launch/LauncherPartLaunch.h
|
minecraft/launch/ModMinecraftJar.h
|
||||||
minecraft/launch/PrintInstanceInfo.cpp
|
minecraft/launch/DirectJavaLaunch.cpp
|
||||||
minecraft/launch/PrintInstanceInfo.h
|
minecraft/launch/DirectJavaLaunch.h
|
||||||
minecraft/launch/ReconstructAssets.cpp
|
minecraft/launch/ExtractNatives.cpp
|
||||||
minecraft/launch/ReconstructAssets.h
|
minecraft/launch/ExtractNatives.h
|
||||||
minecraft/legacy/LegacyModList.h
|
minecraft/launch/LauncherPartLaunch.cpp
|
||||||
minecraft/legacy/LegacyModList.cpp
|
minecraft/launch/LauncherPartLaunch.h
|
||||||
minecraft/legacy/LegacyInstance.h
|
minecraft/launch/PrintInstanceInfo.cpp
|
||||||
minecraft/legacy/LegacyInstance.cpp
|
minecraft/launch/PrintInstanceInfo.h
|
||||||
minecraft/legacy/LegacyUpgradeTask.h
|
minecraft/legacy/LegacyModList.h
|
||||||
minecraft/legacy/LegacyUpgradeTask.cpp
|
minecraft/legacy/LegacyModList.cpp
|
||||||
minecraft/GradleSpecifier.h
|
minecraft/legacy/LegacyUpdate.h
|
||||||
minecraft/MinecraftInstance.cpp
|
minecraft/legacy/LegacyUpdate.cpp
|
||||||
minecraft/MinecraftInstance.h
|
minecraft/legacy/LegacyInstance.h
|
||||||
minecraft/LaunchProfile.cpp
|
minecraft/legacy/LegacyInstance.cpp
|
||||||
minecraft/LaunchProfile.h
|
minecraft/legacy/LwjglVersionList.h
|
||||||
minecraft/Component.cpp
|
minecraft/legacy/LwjglVersionList.cpp
|
||||||
minecraft/Component.h
|
minecraft/GradleSpecifier.h
|
||||||
minecraft/ComponentList.cpp
|
minecraft/MinecraftProfile.cpp
|
||||||
minecraft/ComponentList.h
|
minecraft/MinecraftProfile.h
|
||||||
minecraft/ComponentUpdateTask.cpp
|
minecraft/MojangVersionFormat.cpp
|
||||||
minecraft/ComponentUpdateTask.h
|
minecraft/MojangVersionFormat.h
|
||||||
minecraft/MinecraftLoadAndCheck.h
|
minecraft/JarMod.h
|
||||||
minecraft/MinecraftLoadAndCheck.cpp
|
minecraft/MinecraftInstance.cpp
|
||||||
minecraft/MinecraftUpdate.h
|
minecraft/MinecraftInstance.h
|
||||||
minecraft/MinecraftUpdate.cpp
|
minecraft/MinecraftVersion.cpp
|
||||||
minecraft/MojangVersionFormat.cpp
|
minecraft/MinecraftVersion.h
|
||||||
minecraft/MojangVersionFormat.h
|
minecraft/MinecraftVersionList.cpp
|
||||||
minecraft/Rule.cpp
|
minecraft/MinecraftVersionList.h
|
||||||
minecraft/Rule.h
|
minecraft/Rule.cpp
|
||||||
minecraft/OneSixVersionFormat.cpp
|
minecraft/Rule.h
|
||||||
minecraft/OneSixVersionFormat.h
|
minecraft/OpSys.cpp
|
||||||
minecraft/OpSys.cpp
|
minecraft/OpSys.h
|
||||||
minecraft/OpSys.h
|
minecraft/ParseUtils.cpp
|
||||||
minecraft/ParseUtils.cpp
|
minecraft/ParseUtils.h
|
||||||
minecraft/ParseUtils.h
|
minecraft/ProfileUtils.cpp
|
||||||
minecraft/ProfileUtils.cpp
|
minecraft/ProfileUtils.h
|
||||||
minecraft/ProfileUtils.h
|
minecraft/ProfileStrategy.h
|
||||||
minecraft/Library.cpp
|
minecraft/Library.cpp
|
||||||
minecraft/Library.h
|
minecraft/Library.h
|
||||||
minecraft/MojangDownloadInfo.h
|
minecraft/MojangDownloadInfo.h
|
||||||
minecraft/VersionFile.cpp
|
minecraft/VersionBuildError.h
|
||||||
minecraft/VersionFile.h
|
minecraft/VersionFile.cpp
|
||||||
minecraft/VersionFilterData.h
|
minecraft/VersionFile.h
|
||||||
minecraft/VersionFilterData.cpp
|
minecraft/ProfilePatch.h
|
||||||
minecraft/Mod.h
|
minecraft/VersionFilterData.h
|
||||||
minecraft/Mod.cpp
|
minecraft/VersionFilterData.cpp
|
||||||
minecraft/SimpleModList.h
|
minecraft/Mod.h
|
||||||
minecraft/SimpleModList.cpp
|
minecraft/Mod.cpp
|
||||||
minecraft/World.h
|
minecraft/ModList.h
|
||||||
minecraft/World.cpp
|
minecraft/ModList.cpp
|
||||||
minecraft/WorldList.h
|
minecraft/World.h
|
||||||
minecraft/WorldList.cpp
|
minecraft/World.cpp
|
||||||
|
minecraft/WorldList.h
|
||||||
|
minecraft/WorldList.cpp
|
||||||
|
|
||||||
# Assets
|
# FTB
|
||||||
minecraft/AssetsUtils.h
|
minecraft/ftb/OneSixFTBInstance.h
|
||||||
minecraft/AssetsUtils.cpp
|
minecraft/ftb/OneSixFTBInstance.cpp
|
||||||
|
minecraft/ftb/LegacyFTBInstance.h
|
||||||
|
minecraft/ftb/LegacyFTBInstance.cpp
|
||||||
|
minecraft/ftb/FTBProfileStrategy.h
|
||||||
|
minecraft/ftb/FTBProfileStrategy.cpp
|
||||||
|
minecraft/ftb/FTBInstanceProvider.cpp
|
||||||
|
minecraft/ftb/FTBInstanceProvider.h
|
||||||
|
minecraft/ftb/FTBPlugin.h
|
||||||
|
minecraft/ftb/FTBPlugin.cpp
|
||||||
|
|
||||||
# Forge and all things forge related
|
# Assets
|
||||||
minecraft/forge/ForgeXzDownload.h
|
minecraft/AssetsUtils.h
|
||||||
minecraft/forge/ForgeXzDownload.cpp
|
minecraft/AssetsUtils.cpp
|
||||||
|
|
||||||
# Skin upload utilities
|
# Forge and all things forge related
|
||||||
minecraft/SkinUpload.cpp
|
minecraft/forge/ForgeVersion.h
|
||||||
minecraft/SkinUpload.h
|
minecraft/forge/ForgeVersion.cpp
|
||||||
)
|
minecraft/forge/ForgeVersionList.h
|
||||||
|
minecraft/forge/ForgeVersionList.cpp
|
||||||
|
minecraft/forge/ForgeXzDownload.h
|
||||||
|
minecraft/forge/ForgeXzDownload.cpp
|
||||||
|
minecraft/forge/LegacyForge.h
|
||||||
|
minecraft/forge/LegacyForge.cpp
|
||||||
|
minecraft/forge/ForgeInstaller.h
|
||||||
|
minecraft/forge/ForgeInstaller.cpp
|
||||||
|
|
||||||
|
# Liteloader and related things
|
||||||
|
minecraft/liteloader/LiteLoaderInstaller.h
|
||||||
|
minecraft/liteloader/LiteLoaderInstaller.cpp
|
||||||
|
minecraft/liteloader/LiteLoaderVersionList.h
|
||||||
|
minecraft/liteloader/LiteLoaderVersionList.cpp
|
||||||
|
minecraft/SkinUpload.cpp
|
||||||
|
minecraft/SkinUpload.h
|
||||||
|
)
|
||||||
|
|
||||||
add_unit_test(GradleSpecifier
|
add_unit_test(GradleSpecifier
|
||||||
SOURCES minecraft/GradleSpecifier_test.cpp
|
SOURCES minecraft/GradleSpecifier_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(MojangVersionFormat
|
add_unit_test(MojangVersionFormat
|
||||||
SOURCES minecraft/MojangVersionFormat_test.cpp
|
SOURCES minecraft/MojangVersionFormat_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
DATA minecraft/testdata
|
DATA minecraft/testdata
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(Library
|
add_unit_test(Library
|
||||||
SOURCES minecraft/Library_test.cpp
|
SOURCES minecraft/Library_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME: shares data with FileSystem test
|
# FIXME: shares data with FileSystem test
|
||||||
add_unit_test(SimpleModList
|
add_unit_test(ModList
|
||||||
SOURCES minecraft/SimpleModList_test.cpp
|
SOURCES minecraft/ModList_test.cpp
|
||||||
DATA testdata
|
DATA testdata
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(ParseUtils
|
add_unit_test(ParseUtils
|
||||||
SOURCES minecraft/ParseUtils_test.cpp
|
SOURCES minecraft/ParseUtils_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
# the screenshots feature
|
# the screenshots feature
|
||||||
set(SCREENSHOTS_SOURCES
|
set(SCREENSHOTS_SOURCES
|
||||||
screenshots/Screenshot.h
|
screenshots/Screenshot.h
|
||||||
screenshots/ImgurUpload.h
|
screenshots/ImgurUpload.h
|
||||||
screenshots/ImgurUpload.cpp
|
screenshots/ImgurUpload.cpp
|
||||||
screenshots/ImgurAlbumCreation.h
|
screenshots/ImgurAlbumCreation.h
|
||||||
screenshots/ImgurAlbumCreation.cpp
|
screenshots/ImgurAlbumCreation.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TASKS_SOURCES
|
set(TASKS_SOURCES
|
||||||
# Tasks
|
# Tasks
|
||||||
tasks/Task.h
|
tasks/Task.h
|
||||||
tasks/Task.cpp
|
tasks/Task.cpp
|
||||||
tasks/SequentialTask.h
|
tasks/ThreadTask.h
|
||||||
tasks/SequentialTask.cpp
|
tasks/ThreadTask.cpp
|
||||||
|
tasks/SequentialTask.h
|
||||||
|
tasks/SequentialTask.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SETTINGS_SOURCES
|
set(SETTINGS_SOURCES
|
||||||
# Settings
|
# Settings
|
||||||
settings/INIFile.cpp
|
settings/INIFile.cpp
|
||||||
settings/INIFile.h
|
settings/INIFile.h
|
||||||
settings/INISettingsObject.cpp
|
settings/INISettingsObject.cpp
|
||||||
settings/INISettingsObject.h
|
settings/INISettingsObject.h
|
||||||
settings/OverrideSetting.cpp
|
settings/OverrideSetting.cpp
|
||||||
settings/OverrideSetting.h
|
settings/OverrideSetting.h
|
||||||
settings/PassthroughSetting.cpp
|
settings/PassthroughSetting.cpp
|
||||||
settings/PassthroughSetting.h
|
settings/PassthroughSetting.h
|
||||||
settings/Setting.cpp
|
settings/Setting.cpp
|
||||||
settings/Setting.h
|
settings/Setting.h
|
||||||
settings/SettingsObject.cpp
|
settings/SettingsObject.cpp
|
||||||
settings/SettingsObject.h
|
settings/SettingsObject.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(INIFile
|
add_unit_test(INIFile
|
||||||
SOURCES settings/INIFile_test.cpp
|
SOURCES settings/INIFile_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
set(JAVA_SOURCES
|
set(JAVA_SOURCES
|
||||||
# Java related code
|
# Java related code
|
||||||
java/launch/CheckJava.cpp
|
java/launch/CheckJava.cpp
|
||||||
java/launch/CheckJava.h
|
java/launch/CheckJava.h
|
||||||
java/JavaChecker.h
|
java/JavaChecker.h
|
||||||
java/JavaChecker.cpp
|
java/JavaChecker.cpp
|
||||||
java/JavaCheckerJob.h
|
java/JavaCheckerJob.h
|
||||||
java/JavaCheckerJob.cpp
|
java/JavaCheckerJob.cpp
|
||||||
java/JavaInstall.h
|
java/JavaInstall.h
|
||||||
java/JavaInstall.cpp
|
java/JavaInstall.cpp
|
||||||
java/JavaInstallList.h
|
java/JavaInstallList.h
|
||||||
java/JavaInstallList.cpp
|
java/JavaInstallList.cpp
|
||||||
java/JavaUtils.h
|
java/JavaUtils.h
|
||||||
java/JavaUtils.cpp
|
java/JavaUtils.cpp
|
||||||
java/JavaVersion.h
|
java/JavaVersion.h
|
||||||
java/JavaVersion.cpp
|
java/JavaVersion.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(JavaVersion
|
add_unit_test(JavaVersion
|
||||||
SOURCES java/JavaVersion_test.cpp
|
SOURCES java/JavaVersion_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TRANSLATIONS_SOURCES
|
set(TRANSLATIONS_SOURCES
|
||||||
translations/TranslationsModel.h
|
translations/TranslationsModel.h
|
||||||
translations/TranslationsModel.cpp
|
translations/TranslationsModel.cpp
|
||||||
translations/POTranslator.h
|
|
||||||
translations/POTranslator.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TOOLS_SOURCES
|
set(TOOLS_SOURCES
|
||||||
# Tools
|
# Tools
|
||||||
tools/BaseExternalTool.cpp
|
tools/BaseExternalTool.cpp
|
||||||
tools/BaseExternalTool.h
|
tools/BaseExternalTool.h
|
||||||
tools/BaseProfiler.cpp
|
tools/BaseProfiler.cpp
|
||||||
tools/BaseProfiler.h
|
tools/BaseProfiler.h
|
||||||
tools/JProfiler.cpp
|
tools/JProfiler.cpp
|
||||||
tools/JProfiler.h
|
tools/JProfiler.h
|
||||||
tools/JVisualVM.cpp
|
tools/JVisualVM.cpp
|
||||||
tools/JVisualVM.h
|
tools/JVisualVM.h
|
||||||
tools/MCEditTool.cpp
|
tools/MCEditTool.cpp
|
||||||
tools/MCEditTool.h
|
tools/MCEditTool.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(META_SOURCES
|
set(WONKO_SOURCES
|
||||||
# Metadata sources
|
# Wonko
|
||||||
meta/JsonFormat.cpp
|
wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp
|
||||||
meta/JsonFormat.h
|
wonko/tasks/BaseWonkoEntityRemoteLoadTask.h
|
||||||
meta/BaseEntity.cpp
|
wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp
|
||||||
meta/BaseEntity.h
|
wonko/tasks/BaseWonkoEntityLocalLoadTask.h
|
||||||
meta/VersionList.cpp
|
wonko/format/WonkoFormatV1.cpp
|
||||||
meta/VersionList.h
|
wonko/format/WonkoFormatV1.h
|
||||||
meta/Version.cpp
|
wonko/format/WonkoFormat.cpp
|
||||||
meta/Version.h
|
wonko/format/WonkoFormat.h
|
||||||
meta/Index.cpp
|
wonko/BaseWonkoEntity.cpp
|
||||||
meta/Index.h
|
wonko/BaseWonkoEntity.h
|
||||||
|
wonko/WonkoVersionList.cpp
|
||||||
|
wonko/WonkoVersionList.h
|
||||||
|
wonko/WonkoVersion.cpp
|
||||||
|
wonko/WonkoVersion.h
|
||||||
|
wonko/WonkoIndex.cpp
|
||||||
|
wonko/WonkoIndex.h
|
||||||
|
wonko/WonkoUtil.cpp
|
||||||
|
wonko/WonkoUtil.h
|
||||||
|
wonko/WonkoReference.cpp
|
||||||
|
wonko/WonkoReference.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FTB_SOURCES
|
add_unit_test(WonkoIndex
|
||||||
modplatform/ftb/FtbPackFetchTask.h
|
SOURCES wonko/WonkoIndex_test.cpp
|
||||||
modplatform/ftb/FtbPackFetchTask.cpp
|
LIBS MultiMC_logic
|
||||||
modplatform/ftb/FtbPackInstallTask.h
|
)
|
||||||
modplatform/ftb/FtbPackInstallTask.cpp
|
|
||||||
|
|
||||||
modplatform/ftb/FtbPrivatePackManager.h
|
|
||||||
modplatform/ftb/FtbPrivatePackManager.cpp
|
|
||||||
|
|
||||||
modplatform/ftb/PackHelpers.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FLAME_SOURCES
|
|
||||||
# Flame
|
|
||||||
modplatform/flame/PackManifest.h
|
|
||||||
modplatform/flame/PackManifest.cpp
|
|
||||||
modplatform/flame/FileResolvingTask.h
|
|
||||||
modplatform/flame/FileResolvingTask.cpp
|
|
||||||
modplatform/flame/UrlResolvingTask.h
|
|
||||||
modplatform/flame/UrlResolvingTask.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(Index
|
|
||||||
SOURCES meta/Index_test.cpp
|
|
||||||
LIBS MultiMC_logic
|
|
||||||
)
|
|
||||||
|
|
||||||
################################ COMPILE ################################
|
################################ COMPILE ################################
|
||||||
|
|
||||||
@@ -458,44 +465,34 @@ add_unit_test(Index
|
|||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
|
|
||||||
set(LOGIC_SOURCES
|
set(LOGIC_SOURCES
|
||||||
${CORE_SOURCES}
|
${CORE_SOURCES}
|
||||||
${PATHMATCHER_SOURCES}
|
${PATHMATCHER_SOURCES}
|
||||||
${NET_SOURCES}
|
${NET_SOURCES}
|
||||||
${LAUNCH_SOURCES}
|
${LAUNCH_SOURCES}
|
||||||
${UPDATE_SOURCES}
|
${UPDATE_SOURCES}
|
||||||
${NOTIFICATIONS_SOURCES}
|
${NOTIFICATIONS_SOURCES}
|
||||||
${NEWS_SOURCES}
|
${NEWS_SOURCES}
|
||||||
${STATUS_SOURCES}
|
${STATUS_SOURCES}
|
||||||
${MINECRAFT_SOURCES}
|
${MINECRAFT_SOURCES}
|
||||||
${SCREENSHOTS_SOURCES}
|
${SCREENSHOTS_SOURCES}
|
||||||
${TASKS_SOURCES}
|
${TASKS_SOURCES}
|
||||||
${SETTINGS_SOURCES}
|
${SETTINGS_SOURCES}
|
||||||
${JAVA_SOURCES}
|
${JAVA_SOURCES}
|
||||||
${TRANSLATIONS_SOURCES}
|
${TRANSLATIONS_SOURCES}
|
||||||
${TOOLS_SOURCES}
|
${TOOLS_SOURCES}
|
||||||
${META_SOURCES}
|
${WONKO_SOURCES}
|
||||||
${ICONS_SOURCES}
|
${ICONS_SOURCES}
|
||||||
${FTB_SOURCES}
|
|
||||||
${FLAME_SOURCES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
message(STATUS "FOO! ${LOGIC_SOURCES}")
|
|
||||||
|
|
||||||
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
|
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
|
||||||
set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
|
set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
|
||||||
|
|
||||||
generate_export_header(MultiMC_logic)
|
generate_export_header(MultiMC_logic)
|
||||||
|
|
||||||
# Link
|
# Link
|
||||||
target_link_libraries(MultiMC_logic xz-embedded MultiMC_unpack200 systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES})
|
target_link_libraries(MultiMC_logic xz-embedded unpack200 systeminfo ${QUAZIP_LIBRARIES} ${NBT_NAME} ${ZLIB_LIBRARIES})
|
||||||
target_link_libraries(MultiMC_logic Qt5::Core Qt5::Xml Qt5::Network Qt5::Concurrent)
|
qt5_use_modules(MultiMC_logic Core Xml Network Concurrent)
|
||||||
|
add_dependencies(MultiMC_logic QuaZIP)
|
||||||
|
|
||||||
# Mark and export headers
|
# Mark and export headers
|
||||||
target_include_directories(MultiMC_logic PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PRIVATE "${ZLIB_INCLUDE_DIRS}")
|
target_include_directories(MultiMC_logic PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PRIVATE "${ZLIB_INCLUDE_DIRS}")
|
||||||
|
|
||||||
# Install it
|
|
||||||
install(
|
|
||||||
TARGETS MultiMC_logic
|
|
||||||
RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
|
|
||||||
LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 MultiMC Contributors
|
||||||
*
|
*
|
||||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -27,453 +27,453 @@ namespace Commandline
|
|||||||
// commandline splitter
|
// commandline splitter
|
||||||
QStringList splitArgs(QString args)
|
QStringList splitArgs(QString args)
|
||||||
{
|
{
|
||||||
QStringList argv;
|
QStringList argv;
|
||||||
QString current;
|
QString current;
|
||||||
bool escape = false;
|
bool escape = false;
|
||||||
QChar inquotes;
|
QChar inquotes;
|
||||||
for (int i = 0; i < args.length(); i++)
|
for (int i = 0; i < args.length(); i++)
|
||||||
{
|
{
|
||||||
QChar cchar = args.at(i);
|
QChar cchar = args.at(i);
|
||||||
|
|
||||||
// \ escaped
|
// \ escaped
|
||||||
if (escape)
|
if (escape)
|
||||||
{
|
{
|
||||||
current += cchar;
|
current += cchar;
|
||||||
escape = false;
|
escape = false;
|
||||||
// in "quotes"
|
// in "quotes"
|
||||||
}
|
}
|
||||||
else if (!inquotes.isNull())
|
else if (!inquotes.isNull())
|
||||||
{
|
{
|
||||||
if (cchar == '\\')
|
if (cchar == 0x5C)
|
||||||
escape = true;
|
escape = true;
|
||||||
else if (cchar == inquotes)
|
else if (cchar == inquotes)
|
||||||
inquotes = 0;
|
inquotes = 0;
|
||||||
else
|
else
|
||||||
current += cchar;
|
current += cchar;
|
||||||
// otherwise
|
// otherwise
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cchar == ' ')
|
if (cchar == 0x20)
|
||||||
{
|
{
|
||||||
if (!current.isEmpty())
|
if (!current.isEmpty())
|
||||||
{
|
{
|
||||||
argv << current;
|
argv << current;
|
||||||
current.clear();
|
current.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cchar == '"' || cchar == '\'')
|
else if (cchar == 0x22 || cchar == 0x27)
|
||||||
inquotes = cchar;
|
inquotes = cchar;
|
||||||
else
|
else
|
||||||
current += cchar;
|
current += cchar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!current.isEmpty())
|
if (!current.isEmpty())
|
||||||
argv << current;
|
argv << current;
|
||||||
return argv;
|
return argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle)
|
Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle)
|
||||||
{
|
{
|
||||||
m_flagStyle = flagStyle;
|
m_flagStyle = flagStyle;
|
||||||
m_argStyle = argStyle;
|
m_argStyle = argStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// styles setter/getter
|
// styles setter/getter
|
||||||
void Parser::setArgumentStyle(ArgumentStyle::Enum style)
|
void Parser::setArgumentStyle(ArgumentStyle::Enum style)
|
||||||
{
|
{
|
||||||
m_argStyle = style;
|
m_argStyle = style;
|
||||||
}
|
}
|
||||||
ArgumentStyle::Enum Parser::argumentStyle()
|
ArgumentStyle::Enum Parser::argumentStyle()
|
||||||
{
|
{
|
||||||
return m_argStyle;
|
return m_argStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::setFlagStyle(FlagStyle::Enum style)
|
void Parser::setFlagStyle(FlagStyle::Enum style)
|
||||||
{
|
{
|
||||||
m_flagStyle = style;
|
m_flagStyle = style;
|
||||||
}
|
}
|
||||||
FlagStyle::Enum Parser::flagStyle()
|
FlagStyle::Enum Parser::flagStyle()
|
||||||
{
|
{
|
||||||
return m_flagStyle;
|
return m_flagStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup methods
|
// setup methods
|
||||||
void Parser::addSwitch(QString name, bool def)
|
void Parser::addSwitch(QString name, bool def)
|
||||||
{
|
{
|
||||||
if (m_params.contains(name))
|
if (m_params.contains(name))
|
||||||
throw "Name not unique";
|
throw "Name not unique";
|
||||||
|
|
||||||
OptionDef *param = new OptionDef;
|
OptionDef *param = new OptionDef;
|
||||||
param->type = otSwitch;
|
param->type = otSwitch;
|
||||||
param->name = name;
|
param->name = name;
|
||||||
param->metavar = QString("<%1>").arg(name);
|
param->metavar = QString("<%1>").arg(name);
|
||||||
param->def = def;
|
param->def = def;
|
||||||
|
|
||||||
m_options[name] = param;
|
m_options[name] = param;
|
||||||
m_params[name] = (CommonDef *)param;
|
m_params[name] = (CommonDef *)param;
|
||||||
m_optionList.append(param);
|
m_optionList.append(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::addOption(QString name, QVariant def)
|
void Parser::addOption(QString name, QVariant def)
|
||||||
{
|
{
|
||||||
if (m_params.contains(name))
|
if (m_params.contains(name))
|
||||||
throw "Name not unique";
|
throw "Name not unique";
|
||||||
|
|
||||||
OptionDef *param = new OptionDef;
|
OptionDef *param = new OptionDef;
|
||||||
param->type = otOption;
|
param->type = otOption;
|
||||||
param->name = name;
|
param->name = name;
|
||||||
param->metavar = QString("<%1>").arg(name);
|
param->metavar = QString("<%1>").arg(name);
|
||||||
param->def = def;
|
param->def = def;
|
||||||
|
|
||||||
m_options[name] = param;
|
m_options[name] = param;
|
||||||
m_params[name] = (CommonDef *)param;
|
m_params[name] = (CommonDef *)param;
|
||||||
m_optionList.append(param);
|
m_optionList.append(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::addArgument(QString name, bool required, QVariant def)
|
void Parser::addArgument(QString name, bool required, QVariant def)
|
||||||
{
|
{
|
||||||
if (m_params.contains(name))
|
if (m_params.contains(name))
|
||||||
throw "Name not unique";
|
throw "Name not unique";
|
||||||
|
|
||||||
PositionalDef *param = new PositionalDef;
|
PositionalDef *param = new PositionalDef;
|
||||||
param->name = name;
|
param->name = name;
|
||||||
param->def = def;
|
param->def = def;
|
||||||
param->required = required;
|
param->required = required;
|
||||||
param->metavar = name;
|
param->metavar = name;
|
||||||
|
|
||||||
m_positionals.append(param);
|
m_positionals.append(param);
|
||||||
m_params[name] = (CommonDef *)param;
|
m_params[name] = (CommonDef *)param;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::addDocumentation(QString name, QString doc, QString metavar)
|
void Parser::addDocumentation(QString name, QString doc, QString metavar)
|
||||||
{
|
{
|
||||||
if (!m_params.contains(name))
|
if (!m_params.contains(name))
|
||||||
throw "Name does not exist";
|
throw "Name does not exist";
|
||||||
|
|
||||||
CommonDef *param = m_params[name];
|
CommonDef *param = m_params[name];
|
||||||
param->doc = doc;
|
param->doc = doc;
|
||||||
if (!metavar.isNull())
|
if (!metavar.isNull())
|
||||||
param->metavar = metavar;
|
param->metavar = metavar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::addShortOpt(QString name, QChar flag)
|
void Parser::addShortOpt(QString name, QChar flag)
|
||||||
{
|
{
|
||||||
if (!m_params.contains(name))
|
if (!m_params.contains(name))
|
||||||
throw "Name does not exist";
|
throw "Name does not exist";
|
||||||
if (!m_options.contains(name))
|
if (!m_options.contains(name))
|
||||||
throw "Name is not an Option or Swtich";
|
throw "Name is not an Option or Swtich";
|
||||||
|
|
||||||
OptionDef *param = m_options[name];
|
OptionDef *param = m_options[name];
|
||||||
m_flags[flag] = param;
|
m_flags[flag] = param;
|
||||||
param->flag = flag;
|
param->flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// help methods
|
// help methods
|
||||||
QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags)
|
QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags)
|
||||||
{
|
{
|
||||||
QStringList help;
|
QStringList help;
|
||||||
help << compileUsage(progName, useFlags) << "\r\n";
|
help << compileUsage(progName, useFlags) << "\r\n";
|
||||||
|
|
||||||
// positionals
|
// positionals
|
||||||
if (!m_positionals.isEmpty())
|
if (!m_positionals.isEmpty())
|
||||||
{
|
{
|
||||||
help << "\r\n";
|
help << "\r\n";
|
||||||
help << "Positional arguments:\r\n";
|
help << "Positional arguments:\r\n";
|
||||||
QListIterator<PositionalDef *> it2(m_positionals);
|
QListIterator<PositionalDef *> it2(m_positionals);
|
||||||
while (it2.hasNext())
|
while (it2.hasNext())
|
||||||
{
|
{
|
||||||
PositionalDef *param = it2.next();
|
PositionalDef *param = it2.next();
|
||||||
help << " " << param->metavar;
|
help << " " << param->metavar;
|
||||||
help << " " << QString(helpIndent - param->metavar.length() - 1, ' ');
|
help << " " << QString(helpIndent - param->metavar.length() - 1, ' ');
|
||||||
help << param->doc << "\r\n";
|
help << param->doc << "\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
if (!m_optionList.isEmpty())
|
if (!m_optionList.isEmpty())
|
||||||
{
|
{
|
||||||
help << "\r\n";
|
help << "\r\n";
|
||||||
QString optPrefix, flagPrefix;
|
QString optPrefix, flagPrefix;
|
||||||
getPrefix(optPrefix, flagPrefix);
|
getPrefix(optPrefix, flagPrefix);
|
||||||
|
|
||||||
help << "Options & Switches:\r\n";
|
help << "Options & Switches:\r\n";
|
||||||
QListIterator<OptionDef *> it(m_optionList);
|
QListIterator<OptionDef *> it(m_optionList);
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
OptionDef *option = it.next();
|
OptionDef *option = it.next();
|
||||||
help << " ";
|
help << " ";
|
||||||
int nameLength = optPrefix.length() + option->name.length();
|
int nameLength = optPrefix.length() + option->name.length();
|
||||||
if (!option->flag.isNull())
|
if (!option->flag.isNull())
|
||||||
{
|
{
|
||||||
nameLength += 3 + flagPrefix.length();
|
nameLength += 3 + flagPrefix.length();
|
||||||
help << flagPrefix << option->flag << ", ";
|
help << flagPrefix << option->flag << ", ";
|
||||||
}
|
}
|
||||||
help << optPrefix << option->name;
|
help << optPrefix << option->name;
|
||||||
if (option->type == otOption)
|
if (option->type == otOption)
|
||||||
{
|
{
|
||||||
QString arg = QString("%1%2").arg(
|
QString arg = QString("%1%2").arg(
|
||||||
((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar);
|
((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar);
|
||||||
nameLength += arg.length();
|
nameLength += arg.length();
|
||||||
help << arg;
|
help << arg;
|
||||||
}
|
}
|
||||||
help << " " << QString(helpIndent - nameLength - 1, ' ');
|
help << " " << QString(helpIndent - nameLength - 1, ' ');
|
||||||
help << option->doc << "\r\n";
|
help << option->doc << "\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return help.join("");
|
return help.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Parser::compileUsage(QString progName, bool useFlags)
|
QString Parser::compileUsage(QString progName, bool useFlags)
|
||||||
{
|
{
|
||||||
QStringList usage;
|
QStringList usage;
|
||||||
usage << "Usage: " << progName;
|
usage << "Usage: " << progName;
|
||||||
|
|
||||||
QString optPrefix, flagPrefix;
|
QString optPrefix, flagPrefix;
|
||||||
getPrefix(optPrefix, flagPrefix);
|
getPrefix(optPrefix, flagPrefix);
|
||||||
|
|
||||||
// options
|
// options
|
||||||
QListIterator<OptionDef *> it(m_optionList);
|
QListIterator<OptionDef *> it(m_optionList);
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
OptionDef *option = it.next();
|
OptionDef *option = it.next();
|
||||||
usage << " [";
|
usage << " [";
|
||||||
if (!option->flag.isNull() && useFlags)
|
if (!option->flag.isNull() && useFlags)
|
||||||
usage << flagPrefix << option->flag;
|
usage << flagPrefix << option->flag;
|
||||||
else
|
else
|
||||||
usage << optPrefix << option->name;
|
usage << optPrefix << option->name;
|
||||||
if (option->type == otOption)
|
if (option->type == otOption)
|
||||||
usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar;
|
usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar;
|
||||||
usage << "]";
|
usage << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// arguments
|
// arguments
|
||||||
QListIterator<PositionalDef *> it2(m_positionals);
|
QListIterator<PositionalDef *> it2(m_positionals);
|
||||||
while (it2.hasNext())
|
while (it2.hasNext())
|
||||||
{
|
{
|
||||||
PositionalDef *param = it2.next();
|
PositionalDef *param = it2.next();
|
||||||
usage << " " << (param->required ? "<" : "[");
|
usage << " " << (param->required ? "<" : "[");
|
||||||
usage << param->metavar;
|
usage << param->metavar;
|
||||||
usage << (param->required ? ">" : "]");
|
usage << (param->required ? ">" : "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return usage.join("");
|
return usage.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsing
|
// parsing
|
||||||
QHash<QString, QVariant> Parser::parse(QStringList argv)
|
QHash<QString, QVariant> Parser::parse(QStringList argv)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> map;
|
QHash<QString, QVariant> map;
|
||||||
|
|
||||||
QStringListIterator it(argv);
|
QStringListIterator it(argv);
|
||||||
QString programName = it.next();
|
QString programName = it.next();
|
||||||
|
|
||||||
QString optionPrefix;
|
QString optionPrefix;
|
||||||
QString flagPrefix;
|
QString flagPrefix;
|
||||||
QListIterator<PositionalDef *> positionals(m_positionals);
|
QListIterator<PositionalDef *> positionals(m_positionals);
|
||||||
QStringList expecting;
|
QStringList expecting;
|
||||||
|
|
||||||
getPrefix(optionPrefix, flagPrefix);
|
getPrefix(optionPrefix, flagPrefix);
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
QString arg = it.next();
|
QString arg = it.next();
|
||||||
|
|
||||||
if (!expecting.isEmpty())
|
if (!expecting.isEmpty())
|
||||||
// we were expecting an argument
|
// we were expecting an argument
|
||||||
{
|
{
|
||||||
QString name = expecting.first();
|
QString name = expecting.first();
|
||||||
/*
|
/*
|
||||||
if (map.contains(name))
|
if (map.contains(name))
|
||||||
throw ParsingError(
|
throw ParsingError(
|
||||||
QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
|
QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
|
||||||
*/
|
*/
|
||||||
map[name] = QVariant(arg);
|
map[name] = QVariant(arg);
|
||||||
|
|
||||||
expecting.removeFirst();
|
expecting.removeFirst();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith(optionPrefix))
|
if (arg.startsWith(optionPrefix))
|
||||||
// we have an option
|
// we have an option
|
||||||
{
|
{
|
||||||
// qDebug("Found option %s", qPrintable(arg));
|
// qDebug("Found option %s", qPrintable(arg));
|
||||||
|
|
||||||
QString name = arg.mid(optionPrefix.length());
|
QString name = arg.mid(optionPrefix.length());
|
||||||
QString equals;
|
QString equals;
|
||||||
|
|
||||||
if ((m_argStyle == ArgumentStyle::Equals ||
|
if ((m_argStyle == ArgumentStyle::Equals ||
|
||||||
m_argStyle == ArgumentStyle::SpaceAndEquals) &&
|
m_argStyle == ArgumentStyle::SpaceAndEquals) &&
|
||||||
name.contains("="))
|
name.contains("="))
|
||||||
{
|
{
|
||||||
int i = name.indexOf("=");
|
int i = name.indexOf("=");
|
||||||
equals = name.mid(i + 1);
|
equals = name.mid(i + 1);
|
||||||
name = name.left(i);
|
name = name.left(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_options.contains(name))
|
if (m_options.contains(name))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if (map.contains(name))
|
if (map.contains(name))
|
||||||
throw ParsingError(QString("Option %2%1 was given multiple times")
|
throw ParsingError(QString("Option %2%1 was given multiple times")
|
||||||
.arg(name, optionPrefix));
|
.arg(name, optionPrefix));
|
||||||
*/
|
*/
|
||||||
OptionDef *option = m_options[name];
|
OptionDef *option = m_options[name];
|
||||||
if (option->type == otSwitch)
|
if (option->type == otSwitch)
|
||||||
map[name] = true;
|
map[name] = true;
|
||||||
else // if (option->type == otOption)
|
else // if (option->type == otOption)
|
||||||
{
|
{
|
||||||
if (m_argStyle == ArgumentStyle::Space)
|
if (m_argStyle == ArgumentStyle::Space)
|
||||||
expecting.append(name);
|
expecting.append(name);
|
||||||
else if (!equals.isNull())
|
else if (!equals.isNull())
|
||||||
map[name] = equals;
|
map[name] = equals;
|
||||||
else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
|
else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
|
||||||
expecting.append(name);
|
expecting.append(name);
|
||||||
else
|
else
|
||||||
throw ParsingError(QString("Option %2%1 reqires an argument.")
|
throw ParsingError(QString("Option %2%1 reqires an argument.")
|
||||||
.arg(name, optionPrefix));
|
.arg(name, optionPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix));
|
throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith(flagPrefix))
|
if (arg.startsWith(flagPrefix))
|
||||||
// we have (a) flag(s)
|
// we have (a) flag(s)
|
||||||
{
|
{
|
||||||
// qDebug("Found flags %s", qPrintable(arg));
|
// qDebug("Found flags %s", qPrintable(arg));
|
||||||
|
|
||||||
QString flags = arg.mid(flagPrefix.length());
|
QString flags = arg.mid(flagPrefix.length());
|
||||||
QString equals;
|
QString equals;
|
||||||
|
|
||||||
if ((m_argStyle == ArgumentStyle::Equals ||
|
if ((m_argStyle == ArgumentStyle::Equals ||
|
||||||
m_argStyle == ArgumentStyle::SpaceAndEquals) &&
|
m_argStyle == ArgumentStyle::SpaceAndEquals) &&
|
||||||
flags.contains("="))
|
flags.contains("="))
|
||||||
{
|
{
|
||||||
int i = flags.indexOf("=");
|
int i = flags.indexOf("=");
|
||||||
equals = flags.mid(i + 1);
|
equals = flags.mid(i + 1);
|
||||||
flags = flags.left(i);
|
flags = flags.left(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < flags.length(); i++)
|
for (int i = 0; i < flags.length(); i++)
|
||||||
{
|
{
|
||||||
QChar flag = flags.at(i);
|
QChar flag = flags.at(i);
|
||||||
|
|
||||||
if (!m_flags.contains(flag))
|
if (!m_flags.contains(flag))
|
||||||
throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
|
throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
|
||||||
|
|
||||||
OptionDef *option = m_flags[flag];
|
OptionDef *option = m_flags[flag];
|
||||||
/*
|
/*
|
||||||
if (map.contains(option->name))
|
if (map.contains(option->name))
|
||||||
throw ParsingError(QString("Option %2%1 was given multiple times")
|
throw ParsingError(QString("Option %2%1 was given multiple times")
|
||||||
.arg(option->name, optionPrefix));
|
.arg(option->name, optionPrefix));
|
||||||
*/
|
*/
|
||||||
if (option->type == otSwitch)
|
if (option->type == otSwitch)
|
||||||
map[option->name] = true;
|
map[option->name] = true;
|
||||||
else // if (option->type == otOption)
|
else // if (option->type == otOption)
|
||||||
{
|
{
|
||||||
if (m_argStyle == ArgumentStyle::Space)
|
if (m_argStyle == ArgumentStyle::Space)
|
||||||
expecting.append(option->name);
|
expecting.append(option->name);
|
||||||
else if (!equals.isNull())
|
else if (!equals.isNull())
|
||||||
if (i == flags.length() - 1)
|
if (i == flags.length() - 1)
|
||||||
map[option->name] = equals;
|
map[option->name] = equals;
|
||||||
else
|
else
|
||||||
throw ParsingError(QString("Flag %4%2 of Argument-requiring Option "
|
throw ParsingError(QString("Flag %4%2 of Argument-requiring Option "
|
||||||
"%1 not last flag in %4%3")
|
"%1 not last flag in %4%3")
|
||||||
.arg(option->name, flag, flags, flagPrefix));
|
.arg(option->name, flag, flags, flagPrefix));
|
||||||
else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
|
else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
|
||||||
expecting.append(option->name);
|
expecting.append(option->name);
|
||||||
else
|
else
|
||||||
throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)")
|
throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)")
|
||||||
.arg(option->name, flag, flagPrefix));
|
.arg(option->name, flag, flagPrefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be a positional argument
|
// must be a positional argument
|
||||||
if (!positionals.hasNext())
|
if (!positionals.hasNext())
|
||||||
throw ParsingError(QString("Don't know what to do with '%1'").arg(arg));
|
throw ParsingError(QString("Don't know what to do with '%1'").arg(arg));
|
||||||
|
|
||||||
PositionalDef *param = positionals.next();
|
PositionalDef *param = positionals.next();
|
||||||
|
|
||||||
map[param->name] = arg;
|
map[param->name] = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we're missing something
|
// check if we're missing something
|
||||||
if (!expecting.isEmpty())
|
if (!expecting.isEmpty())
|
||||||
throw ParsingError(QString("Was still expecting arguments for %2%1").arg(
|
throw ParsingError(QString("Was still expecting arguments for %2%1").arg(
|
||||||
expecting.join(QString(", ") + optionPrefix), optionPrefix));
|
expecting.join(QString(", ") + optionPrefix), optionPrefix));
|
||||||
|
|
||||||
while (positionals.hasNext())
|
while (positionals.hasNext())
|
||||||
{
|
{
|
||||||
PositionalDef *param = positionals.next();
|
PositionalDef *param = positionals.next();
|
||||||
if (param->required)
|
if (param->required)
|
||||||
throw ParsingError(
|
throw ParsingError(
|
||||||
QString("Missing required positional argument '%1'").arg(param->name));
|
QString("Missing required positional argument '%1'").arg(param->name));
|
||||||
else
|
else
|
||||||
map[param->name] = param->def;
|
map[param->name] = param->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill out gaps
|
// fill out gaps
|
||||||
QListIterator<OptionDef *> iter(m_optionList);
|
QListIterator<OptionDef *> iter(m_optionList);
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
OptionDef *option = iter.next();
|
OptionDef *option = iter.next();
|
||||||
if (!map.contains(option->name))
|
if (!map.contains(option->name))
|
||||||
map[option->name] = option->def;
|
map[option->name] = option->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear defs
|
// clear defs
|
||||||
void Parser::clear()
|
void Parser::clear()
|
||||||
{
|
{
|
||||||
m_flags.clear();
|
m_flags.clear();
|
||||||
m_params.clear();
|
m_params.clear();
|
||||||
m_options.clear();
|
m_options.clear();
|
||||||
|
|
||||||
QMutableListIterator<OptionDef *> it(m_optionList);
|
QMutableListIterator<OptionDef *> it(m_optionList);
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
OptionDef *option = it.next();
|
OptionDef *option = it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
delete option;
|
delete option;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutableListIterator<PositionalDef *> it2(m_positionals);
|
QMutableListIterator<PositionalDef *> it2(m_positionals);
|
||||||
while (it2.hasNext())
|
while (it2.hasNext())
|
||||||
{
|
{
|
||||||
PositionalDef *arg = it2.next();
|
PositionalDef *arg = it2.next();
|
||||||
it2.remove();
|
it2.remove();
|
||||||
delete arg;
|
delete arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Parser::~Parser()
|
Parser::~Parser()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPrefix
|
// getPrefix
|
||||||
void Parser::getPrefix(QString &opt, QString &flag)
|
void Parser::getPrefix(QString &opt, QString &flag)
|
||||||
{
|
{
|
||||||
if (m_flagStyle == FlagStyle::Windows)
|
if (m_flagStyle == FlagStyle::Windows)
|
||||||
opt = flag = "/";
|
opt = flag = "/";
|
||||||
else if (m_flagStyle == FlagStyle::Unix)
|
else if (m_flagStyle == FlagStyle::Unix)
|
||||||
opt = flag = "-";
|
opt = flag = "-";
|
||||||
// else if (m_flagStyle == FlagStyle::GNU)
|
// else if (m_flagStyle == FlagStyle::GNU)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opt = "--";
|
opt = "--";
|
||||||
flag = "-";
|
flag = "-";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsingError
|
// ParsingError
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 MultiMC Contributors
|
||||||
*
|
*
|
||||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -51,13 +51,13 @@ namespace FlagStyle
|
|||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
GNU, /**< --option and -o (GNU Style) */
|
GNU, /**< --option and -o (GNU Style) */
|
||||||
Unix, /**< -option and -o (Unix Style) */
|
Unix, /**< -option and -o (Unix Style) */
|
||||||
Windows, /**< /option and /o (Windows Style) */
|
Windows, /**< /option and /o (Windows Style) */
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
Default = Windows
|
Default = Windows
|
||||||
#else
|
#else
|
||||||
Default = GNU
|
Default = GNU
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -69,13 +69,13 @@ namespace ArgumentStyle
|
|||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
Space, /**< --option=value */
|
Space, /**< --option=value */
|
||||||
Equals, /**< --option value */
|
Equals, /**< --option value */
|
||||||
SpaceAndEquals, /**< --option[= ]value */
|
SpaceAndEquals, /**< --option[= ]value */
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
Default = Equals
|
Default = Equals
|
||||||
#else
|
#else
|
||||||
Default = SpaceAndEquals
|
Default = SpaceAndEquals
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ enum Enum
|
|||||||
class MULTIMC_LOGIC_EXPORT ParsingError : public std::runtime_error
|
class MULTIMC_LOGIC_EXPORT ParsingError : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ParsingError(const QString &what);
|
ParsingError(const QString &what);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,158 +95,158 @@ public:
|
|||||||
class MULTIMC_LOGIC_EXPORT Parser
|
class MULTIMC_LOGIC_EXPORT Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Parser constructor
|
* @brief Parser constructor
|
||||||
* @param flagStyle the FlagStyle to use in this Parser
|
* @param flagStyle the FlagStyle to use in this Parser
|
||||||
* @param argStyle the ArgumentStyle to use in this Parser
|
* @param argStyle the ArgumentStyle to use in this Parser
|
||||||
*/
|
*/
|
||||||
Parser(FlagStyle::Enum flagStyle = FlagStyle::Default,
|
Parser(FlagStyle::Enum flagStyle = FlagStyle::Default,
|
||||||
ArgumentStyle::Enum argStyle = ArgumentStyle::Default);
|
ArgumentStyle::Enum argStyle = ArgumentStyle::Default);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set the flag style
|
* @brief set the flag style
|
||||||
* @param style
|
* @param style
|
||||||
*/
|
*/
|
||||||
void setFlagStyle(FlagStyle::Enum style);
|
void setFlagStyle(FlagStyle::Enum style);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the flag style
|
* @brief get the flag style
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
FlagStyle::Enum flagStyle();
|
FlagStyle::Enum flagStyle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set the argument style
|
* @brief set the argument style
|
||||||
* @param style
|
* @param style
|
||||||
*/
|
*/
|
||||||
void setArgumentStyle(ArgumentStyle::Enum style);
|
void setArgumentStyle(ArgumentStyle::Enum style);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the argument style
|
* @brief get the argument style
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ArgumentStyle::Enum argumentStyle();
|
ArgumentStyle::Enum argumentStyle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief define a boolean switch
|
* @brief define a boolean switch
|
||||||
* @param name the parameter name
|
* @param name the parameter name
|
||||||
* @param def the default value
|
* @param def the default value
|
||||||
*/
|
*/
|
||||||
void addSwitch(QString name, bool def = false);
|
void addSwitch(QString name, bool def = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief define an option that takes an additional argument
|
* @brief define an option that takes an additional argument
|
||||||
* @param name the parameter name
|
* @param name the parameter name
|
||||||
* @param def the default value
|
* @param def the default value
|
||||||
*/
|
*/
|
||||||
void addOption(QString name, QVariant def = QVariant());
|
void addOption(QString name, QVariant def = QVariant());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief define a positional argument
|
* @brief define a positional argument
|
||||||
* @param name the parameter name
|
* @param name the parameter name
|
||||||
* @param required wether this argument is required
|
* @param required wether this argument is required
|
||||||
* @param def the default value
|
* @param def the default value
|
||||||
*/
|
*/
|
||||||
void addArgument(QString name, bool required = true, QVariant def = QVariant());
|
void addArgument(QString name, bool required = true, QVariant def = QVariant());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief adds a flag to an existing parameter
|
* @brief adds a flag to an existing parameter
|
||||||
* @param name the (existing) parameter name
|
* @param name the (existing) parameter name
|
||||||
* @param flag the flag character
|
* @param flag the flag character
|
||||||
* @see addSwitch addArgument addOption
|
* @see addSwitch addArgument addOption
|
||||||
* Note: any one parameter can only have one flag
|
* Note: any one parameter can only have one flag
|
||||||
*/
|
*/
|
||||||
void addShortOpt(QString name, QChar flag);
|
void addShortOpt(QString name, QChar flag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief adds documentation to a Parameter
|
* @brief adds documentation to a Parameter
|
||||||
* @param name the parameter name
|
* @param name the parameter name
|
||||||
* @param metavar a string to be displayed as placeholder for the value
|
* @param metavar a string to be displayed as placeholder for the value
|
||||||
* @param doc a QString containing the documentation
|
* @param doc a QString containing the documentation
|
||||||
* Note: on positional arguments, metavar replaces the name as displayed.
|
* Note: on positional arguments, metavar replaces the name as displayed.
|
||||||
* on options , metavar replaces the value placeholder
|
* on options , metavar replaces the value placeholder
|
||||||
*/
|
*/
|
||||||
void addDocumentation(QString name, QString doc, QString metavar = QString());
|
void addDocumentation(QString name, QString doc, QString metavar = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief generate a help message
|
* @brief generate a help message
|
||||||
* @param progName the program name to use in the help message
|
* @param progName the program name to use in the help message
|
||||||
* @param helpIndent how much the parameter documentation should be indented
|
* @param helpIndent how much the parameter documentation should be indented
|
||||||
* @param flagsInUsage whether we should use flags instead of options in the usage
|
* @param flagsInUsage whether we should use flags instead of options in the usage
|
||||||
* @return a help message
|
* @return a help message
|
||||||
*/
|
*/
|
||||||
QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true);
|
QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief generate a short usage message
|
* @brief generate a short usage message
|
||||||
* @param progName the program name to use in the usage message
|
* @param progName the program name to use in the usage message
|
||||||
* @param useFlags whether we should use flags instead of options
|
* @param useFlags whether we should use flags instead of options
|
||||||
* @return a usage message
|
* @return a usage message
|
||||||
*/
|
*/
|
||||||
QString compileUsage(QString progName, bool useFlags = true);
|
QString compileUsage(QString progName, bool useFlags = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief parse
|
* @brief parse
|
||||||
* @param argv a QStringList containing the program ARGV
|
* @param argv a QStringList containing the program ARGV
|
||||||
* @return a QHash mapping argument names to their values
|
* @return a QHash mapping argument names to their values
|
||||||
*/
|
*/
|
||||||
QHash<QString, QVariant> parse(QStringList argv);
|
QHash<QString, QVariant> parse(QStringList argv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief clear all definitions
|
* @brief clear all definitions
|
||||||
*/
|
*/
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
~Parser();
|
~Parser();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FlagStyle::Enum m_flagStyle;
|
FlagStyle::Enum m_flagStyle;
|
||||||
ArgumentStyle::Enum m_argStyle;
|
ArgumentStyle::Enum m_argStyle;
|
||||||
|
|
||||||
enum OptionType
|
enum OptionType
|
||||||
{
|
{
|
||||||
otSwitch,
|
otSwitch,
|
||||||
otOption
|
otOption
|
||||||
};
|
};
|
||||||
|
|
||||||
// Important: the common part MUST BE COMMON ON ALL THREE structs
|
// Important: the common part MUST BE COMMON ON ALL THREE structs
|
||||||
struct CommonDef
|
struct CommonDef
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
QString doc;
|
QString doc;
|
||||||
QString metavar;
|
QString metavar;
|
||||||
QVariant def;
|
QVariant def;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OptionDef
|
struct OptionDef
|
||||||
{
|
{
|
||||||
// common
|
// common
|
||||||
QString name;
|
QString name;
|
||||||
QString doc;
|
QString doc;
|
||||||
QString metavar;
|
QString metavar;
|
||||||
QVariant def;
|
QVariant def;
|
||||||
// option
|
// option
|
||||||
OptionType type;
|
OptionType type;
|
||||||
QChar flag;
|
QChar flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PositionalDef
|
struct PositionalDef
|
||||||
{
|
{
|
||||||
// common
|
// common
|
||||||
QString name;
|
QString name;
|
||||||
QString doc;
|
QString doc;
|
||||||
QString metavar;
|
QString metavar;
|
||||||
QVariant def;
|
QVariant def;
|
||||||
// positional
|
// positional
|
||||||
bool required;
|
bool required;
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<QString, OptionDef *> m_options;
|
QHash<QString, OptionDef *> m_options;
|
||||||
QHash<QChar, OptionDef *> m_flags;
|
QHash<QChar, OptionDef *> m_flags;
|
||||||
QHash<QString, CommonDef *> m_params;
|
QHash<QString, CommonDef *> m_params;
|
||||||
QList<PositionalDef *> m_positionals;
|
QList<PositionalDef *> m_positionals;
|
||||||
QList<OptionDef *> m_optionList;
|
QList<OptionDef *> m_optionList;
|
||||||
|
|
||||||
void getPrefix(QString &opt, QString &flag);
|
void getPrefix(QString &opt, QString &flag);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,32 +4,32 @@ template <typename T>
|
|||||||
class DefaultVariable
|
class DefaultVariable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DefaultVariable(const T & value)
|
DefaultVariable(const T & value)
|
||||||
{
|
{
|
||||||
defaultValue = value;
|
defaultValue = value;
|
||||||
}
|
}
|
||||||
DefaultVariable<T> & operator =(const T & value)
|
DefaultVariable<T> & operator =(const T & value)
|
||||||
{
|
{
|
||||||
currentValue = value;
|
currentValue = value;
|
||||||
is_default = currentValue == defaultValue;
|
is_default = currentValue == defaultValue;
|
||||||
is_explicit = true;
|
is_explicit = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
operator const T &() const
|
operator const T &() const
|
||||||
{
|
{
|
||||||
return is_default ? defaultValue : currentValue;
|
return is_default ? defaultValue : currentValue;
|
||||||
}
|
}
|
||||||
bool isDefault() const
|
bool isDefault() const
|
||||||
{
|
{
|
||||||
return is_default;
|
return is_default;
|
||||||
}
|
}
|
||||||
bool isExplicit() const
|
bool isExplicit() const
|
||||||
{
|
{
|
||||||
return is_explicit;
|
return is_explicit;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T currentValue;
|
T currentValue;
|
||||||
T defaultValue;
|
T defaultValue;
|
||||||
bool is_default = true;
|
bool is_default = true;
|
||||||
bool is_explicit = false;
|
bool is_explicit = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,24 +3,23 @@
|
|||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "BaseVersionList.h"
|
#include "BaseVersionList.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
#include "meta/Index.h"
|
#include "wonko/WonkoIndex.h"
|
||||||
#include "FileSystem.h"
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
struct Env::Private
|
class Env::Private
|
||||||
{
|
{
|
||||||
QNetworkAccessManager m_qnam;
|
public:
|
||||||
shared_qobject_ptr<HttpMetaCache> m_metacache;
|
QNetworkAccessManager m_qnam;
|
||||||
std::shared_ptr<IIconList> m_iconlist;
|
shared_qobject_ptr<HttpMetaCache> m_metacache;
|
||||||
shared_qobject_ptr<Meta::Index> m_metadataIndex;
|
std::shared_ptr<IIconList> m_iconlist;
|
||||||
QString m_jarsPath;
|
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
||||||
QSet<QString> m_features;
|
shared_qobject_ptr<WonkoIndex> m_wonkoIndex;
|
||||||
|
QString m_wonkoRootUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Env * instance;
|
static Env * instance;
|
||||||
@@ -31,179 +30,175 @@ static Env * instance;
|
|||||||
|
|
||||||
Env::Env()
|
Env::Env()
|
||||||
{
|
{
|
||||||
d = new Private();
|
d = new Private();
|
||||||
}
|
}
|
||||||
|
|
||||||
Env::~Env()
|
Env::~Env()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Env& Env::Env::getInstance()
|
Env& Env::Env::getInstance()
|
||||||
{
|
{
|
||||||
if(!instance)
|
if(!instance)
|
||||||
{
|
{
|
||||||
instance = new Env();
|
instance = new Env();
|
||||||
}
|
}
|
||||||
return *instance;
|
return *instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Env::dispose()
|
void Env::dispose()
|
||||||
{
|
{
|
||||||
delete instance;
|
delete instance;
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr< HttpMetaCache > Env::metacache()
|
shared_qobject_ptr< HttpMetaCache > Env::metacache()
|
||||||
{
|
{
|
||||||
return d->m_metacache;
|
return d->m_metacache;
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkAccessManager& Env::qnam() const
|
QNetworkAccessManager& Env::qnam() const
|
||||||
{
|
{
|
||||||
return d->m_qnam;
|
return d->m_qnam;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IIconList> Env::icons()
|
std::shared_ptr<IIconList> Env::icons()
|
||||||
{
|
{
|
||||||
return d->m_iconlist;
|
return d->m_iconlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
||||||
{
|
{
|
||||||
d->m_iconlist = iconlist;
|
d->m_iconlist = iconlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<Meta::Index> Env::metadataIndex()
|
BaseVersionPtr Env::getVersion(QString component, QString version)
|
||||||
{
|
{
|
||||||
if (!d->m_metadataIndex)
|
auto list = getVersionList(component);
|
||||||
{
|
if(!list)
|
||||||
d->m_metadataIndex.reset(new Meta::Index());
|
{
|
||||||
}
|
return nullptr;
|
||||||
return d->m_metadataIndex;
|
}
|
||||||
|
return list->findVersion(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr< BaseVersionList > Env::getVersionList(QString component)
|
||||||
|
{
|
||||||
|
auto iter = d->m_versionLists.find(component);
|
||||||
|
if(iter != d->m_versionLists.end())
|
||||||
|
{
|
||||||
|
return *iter;
|
||||||
|
}
|
||||||
|
//return std::make_shared<NullVersionList>();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Env::registerVersionList(QString name, std::shared_ptr< BaseVersionList > vlist)
|
||||||
|
{
|
||||||
|
d->m_versionLists[name] = vlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_qobject_ptr<WonkoIndex> Env::wonkoIndex()
|
||||||
|
{
|
||||||
|
if (!d->m_wonkoIndex)
|
||||||
|
{
|
||||||
|
d->m_wonkoIndex.reset(new WonkoIndex());
|
||||||
|
}
|
||||||
|
return d->m_wonkoIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Env::initHttpMetaCache()
|
void Env::initHttpMetaCache()
|
||||||
{
|
{
|
||||||
auto &m_metacache = d->m_metacache;
|
auto &m_metacache = d->m_metacache;
|
||||||
m_metacache.reset(new HttpMetaCache("metacache"));
|
m_metacache.reset(new HttpMetaCache("metacache"));
|
||||||
m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
|
m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
|
||||||
m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
|
m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
|
||||||
m_metacache->addBase("versions", QDir("versions").absolutePath());
|
m_metacache->addBase("versions", QDir("versions").absolutePath());
|
||||||
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
|
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
|
||||||
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
|
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
|
||||||
m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
|
m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
|
||||||
m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
|
m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
|
||||||
m_metacache->addBase("general", QDir("cache").absolutePath());
|
m_metacache->addBase("general", QDir("cache").absolutePath());
|
||||||
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
|
m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
|
||||||
m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
|
m_metacache->addBase("root", QDir::currentPath());
|
||||||
m_metacache->addBase("root", QDir::currentPath());
|
m_metacache->addBase("translations", QDir("translations").absolutePath());
|
||||||
m_metacache->addBase("translations", QDir("translations").absolutePath());
|
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
|
||||||
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
|
m_metacache->addBase("wonko", QDir("cache/wonko").absolutePath());
|
||||||
m_metacache->addBase("meta", QDir("meta").absolutePath());
|
m_metacache->Load();
|
||||||
m_metacache->Load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
|
void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
|
||||||
{
|
{
|
||||||
// Set the application proxy settings.
|
// Set the application proxy settings.
|
||||||
if (proxyTypeStr == "SOCKS5")
|
if (proxyTypeStr == "SOCKS5")
|
||||||
{
|
{
|
||||||
QNetworkProxy::setApplicationProxy(
|
QNetworkProxy::setApplicationProxy(
|
||||||
QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
|
QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
|
||||||
}
|
}
|
||||||
else if (proxyTypeStr == "HTTP")
|
else if (proxyTypeStr == "HTTP")
|
||||||
{
|
{
|
||||||
QNetworkProxy::setApplicationProxy(
|
QNetworkProxy::setApplicationProxy(
|
||||||
QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
|
QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
|
||||||
}
|
}
|
||||||
else if (proxyTypeStr == "None")
|
else if (proxyTypeStr == "None")
|
||||||
{
|
{
|
||||||
// If we have no proxy set, set no proxy and return.
|
// If we have no proxy set, set no proxy and return.
|
||||||
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
|
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If we have "Default" selected, set Qt to use the system proxy settings.
|
// If we have "Default" selected, set Qt to use the system proxy settings.
|
||||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Detecting proxy settings...";
|
qDebug() << "Detecting proxy settings...";
|
||||||
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
||||||
d->m_qnam.setProxy(proxy);
|
d->m_qnam.setProxy(proxy);
|
||||||
QString proxyDesc;
|
QString proxyDesc;
|
||||||
if (proxy.type() == QNetworkProxy::NoProxy)
|
if (proxy.type() == QNetworkProxy::NoProxy)
|
||||||
{
|
{
|
||||||
qDebug() << "Using no proxy is an option!";
|
qDebug() << "Using no proxy is an option!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (proxy.type())
|
switch (proxy.type())
|
||||||
{
|
{
|
||||||
case QNetworkProxy::DefaultProxy:
|
case QNetworkProxy::DefaultProxy:
|
||||||
proxyDesc = "Default proxy: ";
|
proxyDesc = "Default proxy: ";
|
||||||
break;
|
break;
|
||||||
case QNetworkProxy::Socks5Proxy:
|
case QNetworkProxy::Socks5Proxy:
|
||||||
proxyDesc = "Socks5 proxy: ";
|
proxyDesc = "Socks5 proxy: ";
|
||||||
break;
|
break;
|
||||||
case QNetworkProxy::HttpProxy:
|
case QNetworkProxy::HttpProxy:
|
||||||
proxyDesc = "HTTP proxy: ";
|
proxyDesc = "HTTP proxy: ";
|
||||||
break;
|
break;
|
||||||
case QNetworkProxy::HttpCachingProxy:
|
case QNetworkProxy::HttpCachingProxy:
|
||||||
proxyDesc = "HTTP caching: ";
|
proxyDesc = "HTTP caching: ";
|
||||||
break;
|
break;
|
||||||
case QNetworkProxy::FtpCachingProxy:
|
case QNetworkProxy::FtpCachingProxy:
|
||||||
proxyDesc = "FTP caching: ";
|
proxyDesc = "FTP caching: ";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
proxyDesc = "DERP proxy: ";
|
proxyDesc = "DERP proxy: ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
proxyDesc += QString("%3@%1:%2 pass %4")
|
proxyDesc += QString("%3@%1:%2 pass %4")
|
||||||
.arg(proxy.hostName())
|
.arg(proxy.hostName())
|
||||||
.arg(proxy.port())
|
.arg(proxy.port())
|
||||||
.arg(proxy.user())
|
.arg(proxy.user())
|
||||||
.arg(proxy.password());
|
.arg(proxy.password());
|
||||||
qDebug() << proxyDesc;
|
qDebug() << proxyDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Env::getJarsPath()
|
QString Env::wonkoRootUrl() const
|
||||||
{
|
{
|
||||||
if(d->m_jarsPath.isEmpty())
|
return d->m_wonkoRootUrl;
|
||||||
{
|
|
||||||
return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
|
|
||||||
}
|
|
||||||
return d->m_jarsPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Env::setJarsPath(const QString& path)
|
void Env::setWonkoRootUrl(const QString& url)
|
||||||
{
|
{
|
||||||
d->m_jarsPath = path;
|
d->m_wonkoRootUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Env::enableFeature(const QString& featureName, bool state)
|
#include "Env.moc"
|
||||||
{
|
|
||||||
if(state)
|
|
||||||
{
|
|
||||||
d->m_features.insert(featureName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
d->m_features.remove(featureName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Env::isFeatureEnabled(const QString& featureName) const
|
|
||||||
{
|
|
||||||
return d->m_features.contains(featureName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Env::getEnabledFeatures(QSet<QString>& features) const
|
|
||||||
{
|
|
||||||
features = d->m_features;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Env::setEnabledFeatures(const QSet<QString>& features) const
|
|
||||||
{
|
|
||||||
d->m_features = features;
|
|
||||||
}
|
|
||||||
@@ -13,53 +13,51 @@ class QNetworkAccessManager;
|
|||||||
class HttpMetaCache;
|
class HttpMetaCache;
|
||||||
class BaseVersionList;
|
class BaseVersionList;
|
||||||
class BaseVersion;
|
class BaseVersion;
|
||||||
|
class WonkoIndex;
|
||||||
namespace Meta
|
|
||||||
{
|
|
||||||
class Index;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ENV)
|
#if defined(ENV)
|
||||||
#undef ENV
|
#undef ENV
|
||||||
#endif
|
#endif
|
||||||
#define ENV (Env::getInstance())
|
#define ENV (Env::getInstance())
|
||||||
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT Env
|
class MULTIMC_LOGIC_EXPORT Env
|
||||||
{
|
{
|
||||||
friend class MultiMC;
|
friend class MultiMC;
|
||||||
private:
|
private:
|
||||||
struct Private;
|
class Private;
|
||||||
Env();
|
Env();
|
||||||
~Env();
|
~Env();
|
||||||
static void dispose();
|
static void dispose();
|
||||||
public:
|
public:
|
||||||
static Env& getInstance();
|
static Env& getInstance();
|
||||||
|
|
||||||
QNetworkAccessManager &qnam() const;
|
QNetworkAccessManager &qnam() const;
|
||||||
|
|
||||||
shared_qobject_ptr<HttpMetaCache> metacache();
|
shared_qobject_ptr<HttpMetaCache> metacache();
|
||||||
|
|
||||||
std::shared_ptr<IIconList> icons();
|
std::shared_ptr<IIconList> icons();
|
||||||
|
|
||||||
/// init the cache. FIXME: possible future hook point
|
/// init the cache. FIXME: possible future hook point
|
||||||
void initHttpMetaCache();
|
void initHttpMetaCache();
|
||||||
|
|
||||||
/// Updates the application proxy settings from the settings object.
|
/// Updates the application proxy settings from the settings object.
|
||||||
void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
|
void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
|
||||||
|
|
||||||
void registerIconList(std::shared_ptr<IIconList> iconlist);
|
/// get a version list by name
|
||||||
|
std::shared_ptr<BaseVersionList> getVersionList(QString component);
|
||||||
|
|
||||||
shared_qobject_ptr<Meta::Index> metadataIndex();
|
/// get a version by list name and version name
|
||||||
|
std::shared_ptr<BaseVersion> getVersion(QString component, QString version);
|
||||||
|
|
||||||
QString getJarsPath();
|
void registerVersionList(QString name, std::shared_ptr<BaseVersionList> vlist);
|
||||||
void setJarsPath(const QString & path);
|
|
||||||
|
|
||||||
bool isFeatureEnabled(const QString & featureName) const;
|
void registerIconList(std::shared_ptr<IIconList> iconlist);
|
||||||
void enableFeature(const QString & featureName, bool state = true);
|
|
||||||
void getEnabledFeatures(QSet<QString> & features) const;
|
shared_qobject_ptr<WonkoIndex> wonkoIndex();
|
||||||
void setEnabledFeatures(const QSet<QString> & features) const;
|
|
||||||
|
QString wonkoRootUrl() const;
|
||||||
|
void setWonkoRootUrl(const QString &url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Private * d;
|
Private * d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,24 +11,24 @@
|
|||||||
class MULTIMC_LOGIC_EXPORT Exception : public std::exception
|
class MULTIMC_LOGIC_EXPORT Exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Exception(const QString &message) : std::exception(), m_message(message)
|
Exception(const QString &message) : std::exception(), m_message(message)
|
||||||
{
|
{
|
||||||
qCritical() << "Exception:" << message;
|
qCritical() << "Exception:" << message;
|
||||||
}
|
}
|
||||||
Exception(const Exception &other)
|
Exception(const Exception &other)
|
||||||
: std::exception(), m_message(other.cause())
|
: std::exception(), m_message(other.cause())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~Exception() noexcept {}
|
virtual ~Exception() noexcept {}
|
||||||
const char *what() const noexcept
|
const char *what() const noexcept
|
||||||
{
|
{
|
||||||
return m_message.toLatin1().constData();
|
return m_message.toLatin1().constData();
|
||||||
}
|
}
|
||||||
QString cause() const
|
QString cause() const
|
||||||
{
|
{
|
||||||
return m_message;
|
return m_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_message;
|
QString m_message;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline void clamp(T& current, T min, T max)
|
|
||||||
{
|
|
||||||
if (current < min)
|
|
||||||
{
|
|
||||||
current = min;
|
|
||||||
}
|
|
||||||
else if(current > max)
|
|
||||||
{
|
|
||||||
current = max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of numbers from min to max. Next is exponent times bigger than previous.
|
|
||||||
|
|
||||||
class ExponentialSeries
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2)
|
|
||||||
{
|
|
||||||
m_current = m_min = min;
|
|
||||||
m_max = max;
|
|
||||||
m_exponent = exponent;
|
|
||||||
}
|
|
||||||
void reset()
|
|
||||||
{
|
|
||||||
m_current = m_min;
|
|
||||||
}
|
|
||||||
unsigned operator()()
|
|
||||||
{
|
|
||||||
unsigned retval = m_current;
|
|
||||||
m_current *= m_exponent;
|
|
||||||
clamp(m_current, m_min, m_max);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
unsigned m_current;
|
|
||||||
unsigned m_min;
|
|
||||||
unsigned m_max;
|
|
||||||
unsigned m_exponent;
|
|
||||||
};
|
|
||||||
@@ -3,271 +3,263 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTextStream>
|
|
||||||
|
|
||||||
#if defined Q_OS_WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#include <string>
|
|
||||||
#include <sys/utime.h>
|
|
||||||
#include <winnls.h>
|
|
||||||
#include <shobjidl.h>
|
|
||||||
#include <objbase.h>
|
|
||||||
#include <objidl.h>
|
|
||||||
#include <shlguid.h>
|
|
||||||
#include <shlobj.h>
|
|
||||||
#else
|
|
||||||
#include <utime.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace FS {
|
namespace FS {
|
||||||
|
|
||||||
void ensureExists(const QDir &dir)
|
void ensureExists(const QDir &dir)
|
||||||
{
|
{
|
||||||
if (!QDir().mkpath(dir.absolutePath()))
|
if (!QDir().mkpath(dir.absolutePath()))
|
||||||
{
|
{
|
||||||
throw FileSystemException("Unable to create folder " + dir.dirName() + " (" +
|
throw FileSystemException("Unable to create folder " + dir.dirName() + " (" +
|
||||||
dir.absolutePath() + ")");
|
dir.absolutePath() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const QString &filename, const QByteArray &data)
|
void write(const QString &filename, const QByteArray &data)
|
||||||
{
|
{
|
||||||
ensureExists(QFileInfo(filename).dir());
|
ensureExists(QFileInfo(filename).dir());
|
||||||
QSaveFile file(filename);
|
QSaveFile file(filename);
|
||||||
if (!file.open(QSaveFile::WriteOnly))
|
if (!file.open(QSaveFile::WriteOnly))
|
||||||
{
|
{
|
||||||
throw FileSystemException("Couldn't open " + filename + " for writing: " +
|
throw FileSystemException("Couldn't open " + filename + " for writing: " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
}
|
}
|
||||||
if (data.size() != file.write(data))
|
if (data.size() != file.write(data))
|
||||||
{
|
{
|
||||||
throw FileSystemException("Error writing data to " + filename + ": " +
|
throw FileSystemException("Error writing data to " + filename + ": " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
}
|
}
|
||||||
if (!file.commit())
|
if (!file.commit())
|
||||||
{
|
{
|
||||||
throw FileSystemException("Error while committing data to " + filename + ": " +
|
throw FileSystemException("Error while committing data to " + filename + ": " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray read(const QString &filename)
|
QByteArray read(const QString &filename)
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (!file.open(QFile::ReadOnly))
|
if (!file.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
throw FileSystemException("Unable to open " + filename + " for reading: " +
|
throw FileSystemException("Unable to open " + filename + " for reading: " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
}
|
}
|
||||||
const qint64 size = file.size();
|
const qint64 size = file.size();
|
||||||
QByteArray data(int(size), 0);
|
QByteArray data(int(size), 0);
|
||||||
const qint64 ret = file.read(data.data(), size);
|
const qint64 ret = file.read(data.data(), size);
|
||||||
if (ret == -1 || ret != size)
|
if (ret == -1 || ret != size)
|
||||||
{
|
{
|
||||||
throw FileSystemException("Error reading data from " + filename + ": " +
|
throw FileSystemException("Error reading data from " + filename + ": " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool updateTimestamp(const QString& filename)
|
bool updateTimestamp(const QString& filename)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
QFile file(filename);
|
||||||
std::wstring filename_utf_16 = filename.toStdWString();
|
if (!file.exists())
|
||||||
return (_wutime64(filename_utf_16.c_str(), nullptr) == 0);
|
{
|
||||||
#else
|
return false;
|
||||||
QByteArray filenameBA = QFile::encodeName(filename);
|
}
|
||||||
return (utime(filenameBA.data(), nullptr) == 0);
|
if (!file.open(QIODevice::ReadWrite))
|
||||||
#endif
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const quint64 size = file.size();
|
||||||
|
file.seek(size);
|
||||||
|
file.write( QByteArray(1, '0') );
|
||||||
|
file.resize(size);
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ensureFilePathExists(QString filenamepath)
|
bool ensureFilePathExists(QString filenamepath)
|
||||||
{
|
{
|
||||||
QFileInfo a(filenamepath);
|
QFileInfo a(filenamepath);
|
||||||
QDir dir;
|
QDir dir;
|
||||||
QString ensuredPath = a.path();
|
QString ensuredPath = a.path();
|
||||||
bool success = dir.mkpath(ensuredPath);
|
bool success = dir.mkpath(ensuredPath);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ensureFolderPathExists(QString foldernamepath)
|
bool ensureFolderPathExists(QString foldernamepath)
|
||||||
{
|
{
|
||||||
QFileInfo a(foldernamepath);
|
QFileInfo a(foldernamepath);
|
||||||
QDir dir;
|
QDir dir;
|
||||||
QString ensuredPath = a.filePath();
|
QString ensuredPath = a.filePath();
|
||||||
bool success = dir.mkpath(ensuredPath);
|
bool success = dir.mkpath(ensuredPath);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool copy::operator()(const QString &offset)
|
bool copy::operator()(const QString &offset)
|
||||||
{
|
{
|
||||||
//NOTE always deep copy on windows. the alternatives are too messy.
|
//NOTE always deep copy on windows. the alternatives are too messy.
|
||||||
#if defined Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
m_followSymlinks = true;
|
m_followSymlinks = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto src = PathCombine(m_src.absolutePath(), offset);
|
auto src = PathCombine(m_src.absolutePath(), offset);
|
||||||
auto dst = PathCombine(m_dst.absolutePath(), offset);
|
auto dst = PathCombine(m_dst.absolutePath(), offset);
|
||||||
|
|
||||||
QFileInfo currentSrc(src);
|
QFileInfo currentSrc(src);
|
||||||
if (!currentSrc.exists())
|
if (!currentSrc.exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!m_followSymlinks && currentSrc.isSymLink())
|
if(!m_followSymlinks && currentSrc.isSymLink())
|
||||||
{
|
{
|
||||||
qDebug() << "creating symlink" << src << " - " << dst;
|
qDebug() << "creating symlink" << src << " - " << dst;
|
||||||
if (!ensureFilePathExists(dst))
|
if (!ensureFilePathExists(dst))
|
||||||
{
|
{
|
||||||
qWarning() << "Cannot create path!";
|
qWarning() << "Cannot create path!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return QFile::link(currentSrc.symLinkTarget(), dst);
|
return QFile::link(currentSrc.symLinkTarget(), dst);
|
||||||
}
|
}
|
||||||
else if(currentSrc.isFile())
|
else if(currentSrc.isFile())
|
||||||
{
|
{
|
||||||
qDebug() << "copying file" << src << " - " << dst;
|
qDebug() << "copying file" << src << " - " << dst;
|
||||||
if (!ensureFilePathExists(dst))
|
if (!ensureFilePathExists(dst))
|
||||||
{
|
{
|
||||||
qWarning() << "Cannot create path!";
|
qWarning() << "Cannot create path!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return QFile::copy(src, dst);
|
return QFile::copy(src, dst);
|
||||||
}
|
}
|
||||||
else if(currentSrc.isDir())
|
else if(currentSrc.isDir())
|
||||||
{
|
{
|
||||||
qDebug() << "recursing" << offset;
|
qDebug() << "recursing" << offset;
|
||||||
if (!ensureFolderPathExists(dst))
|
if (!ensureFolderPathExists(dst))
|
||||||
{
|
{
|
||||||
qWarning() << "Cannot create path!";
|
qWarning() << "Cannot create path!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QDir currentDir(src);
|
QDir currentDir(src);
|
||||||
for(auto & f : currentDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
|
for(auto & f : currentDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
|
||||||
{
|
{
|
||||||
auto inner_offset = PathCombine(offset, f);
|
auto inner_offset = PathCombine(offset, f);
|
||||||
// ignore and skip stuff that matches the blacklist.
|
// ignore and skip stuff that matches the blacklist.
|
||||||
if(m_blacklist && m_blacklist->matches(inner_offset))
|
if(m_blacklist && m_blacklist->matches(inner_offset))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!operator()(inner_offset))
|
if(!operator()(inner_offset))
|
||||||
{
|
{
|
||||||
qWarning() << "Failed to copy" << inner_offset;
|
qWarning() << "Failed to copy" << inner_offset;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qCritical() << "Copy ERROR: Unknown filesystem object:" << src;
|
qCritical() << "Copy ERROR: Unknown filesystem object:" << src;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined Q_OS_WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
#endif
|
||||||
bool deletePath(QString path)
|
bool deletePath(QString path)
|
||||||
{
|
{
|
||||||
bool OK = true;
|
bool OK = true;
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
|
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
{
|
{
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
|
auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
|
||||||
QDir::AllDirs | QDir::Files,
|
QDir::AllDirs | QDir::Files,
|
||||||
QDir::DirsFirst);
|
QDir::DirsFirst);
|
||||||
|
|
||||||
for(auto & info: allEntries)
|
for(auto & info: allEntries)
|
||||||
{
|
{
|
||||||
#if defined Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath());
|
QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath());
|
||||||
auto wString = nativePath.toStdWString();
|
auto wString = nativePath.toStdWString();
|
||||||
DWORD dwAttrs = GetFileAttributesW(wString.c_str());
|
DWORD dwAttrs = GetFileAttributesW(wString.c_str());
|
||||||
// Windows: check for junctions, reparse points and other nasty things of that sort
|
// Windows: check for junctions, reparse points and other nasty things of that sort
|
||||||
if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT)
|
if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT)
|
||||||
{
|
{
|
||||||
if (info.isFile())
|
if (info.isFile())
|
||||||
{
|
{
|
||||||
OK &= QFile::remove(info.absoluteFilePath());
|
OK &= QFile::remove(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
else if (info.isDir())
|
else if (info.isDir())
|
||||||
{
|
{
|
||||||
OK &= dir.rmdir(info.absoluteFilePath());
|
OK &= dir.rmdir(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// We do not trust Qt with reparse points, but do trust it with unix symlinks.
|
// We do not trust Qt with reparse points, but do trust it with unix symlinks.
|
||||||
if(info.isSymLink())
|
if(info.isSymLink())
|
||||||
{
|
{
|
||||||
OK &= QFile::remove(info.absoluteFilePath());
|
OK &= QFile::remove(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (info.isDir())
|
else if (info.isDir())
|
||||||
{
|
{
|
||||||
OK &= deletePath(info.absoluteFilePath());
|
OK &= deletePath(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
else if (info.isFile())
|
else if (info.isFile())
|
||||||
{
|
{
|
||||||
OK &= QFile::remove(info.absoluteFilePath());
|
OK &= QFile::remove(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OK = false;
|
OK = false;
|
||||||
qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath();
|
qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OK &= dir.rmdir(dir.absolutePath());
|
OK &= dir.rmdir(dir.absolutePath());
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString PathCombine(const QString & path1, const QString & path2)
|
QString PathCombine(QString path1, QString path2)
|
||||||
{
|
{
|
||||||
if(!path1.size())
|
if(!path1.size())
|
||||||
return path2;
|
return path2;
|
||||||
if(!path2.size())
|
if(!path2.size())
|
||||||
return path1;
|
return path1;
|
||||||
return QDir::cleanPath(path1 + QDir::separator() + path2);
|
return QDir::cleanPath(path1 + QDir::separator() + path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PathCombine(const QString & path1, const QString & path2, const QString & path3)
|
QString PathCombine(QString path1, QString path2, QString path3)
|
||||||
{
|
{
|
||||||
return PathCombine(PathCombine(path1, path2), path3);
|
return PathCombine(PathCombine(path1, path2), path3);
|
||||||
}
|
|
||||||
|
|
||||||
QString PathCombine(const QString & path1, const QString & path2, const QString & path3, const QString & path4)
|
|
||||||
{
|
|
||||||
return PathCombine(PathCombine(path1, path2, path3), path4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AbsolutePath(QString path)
|
QString AbsolutePath(QString path)
|
||||||
{
|
{
|
||||||
return QFileInfo(path).absolutePath();
|
return QFileInfo(path).absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ResolveExecutable(QString path)
|
QString ResolveExecutable(QString path)
|
||||||
{
|
{
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if(!path.contains('/'))
|
if(!path.contains('/'))
|
||||||
{
|
{
|
||||||
path = QStandardPaths::findExecutable(path);
|
path = QStandardPaths::findExecutable(path);
|
||||||
}
|
}
|
||||||
QFileInfo pathInfo(path);
|
QFileInfo pathInfo(path);
|
||||||
if(!pathInfo.exists() || !pathInfo.isExecutable())
|
if(!pathInfo.exists() || !pathInfo.isExecutable())
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
return pathInfo.absoluteFilePath();
|
return pathInfo.absoluteFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,175 +270,187 @@ QString ResolveExecutable(QString path)
|
|||||||
*/
|
*/
|
||||||
QString NormalizePath(QString path)
|
QString NormalizePath(QString path)
|
||||||
{
|
{
|
||||||
QDir a = QDir::currentPath();
|
QDir a = QDir::currentPath();
|
||||||
QString currentAbsolute = a.absolutePath();
|
QString currentAbsolute = a.absolutePath();
|
||||||
|
|
||||||
QDir b(path);
|
QDir b(path);
|
||||||
QString newAbsolute = b.absolutePath();
|
QString newAbsolute = b.absolutePath();
|
||||||
|
|
||||||
if (newAbsolute.startsWith(currentAbsolute))
|
if (newAbsolute.startsWith(currentAbsolute))
|
||||||
{
|
{
|
||||||
return a.relativeFilePath(newAbsolute);
|
return a.relativeFilePath(newAbsolute);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return newAbsolute;
|
return newAbsolute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString badFilenameChars = "\"\\/?<>:*|!+\r\n";
|
QString badFilenameChars = "\"\\/?<>:*|!";
|
||||||
|
|
||||||
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < string.length(); i++)
|
for (int i = 0; i < string.length(); i++)
|
||||||
{
|
{
|
||||||
if (badFilenameChars.contains(string[i]))
|
if (badFilenameChars.contains(string[i]))
|
||||||
{
|
{
|
||||||
string[i] = replaceWith;
|
string[i] = replaceWith;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DirNameFromString(QString string, QString inDir)
|
QString DirNameFromString(QString string, QString inDir)
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
QString baseName = RemoveInvalidFilenameChars(string, '-');
|
QString baseName = RemoveInvalidFilenameChars(string, '-');
|
||||||
QString dirName;
|
QString dirName;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(num == 0)
|
if(num == 0)
|
||||||
{
|
{
|
||||||
dirName = baseName;
|
dirName = baseName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dirName = baseName + QString::number(num);;
|
dirName = baseName + QString::number(num);;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's over 9000
|
// If it's over 9000
|
||||||
if (num > 9000)
|
if (num > 9000)
|
||||||
return "";
|
return "";
|
||||||
num++;
|
num++;
|
||||||
} while (QFileInfo(PathCombine(inDir, dirName)).exists());
|
} while (QFileInfo(PathCombine(inDir, dirName)).exists());
|
||||||
return dirName;
|
return dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does the folder path contain any '!'? If yes, return true, otherwise false.
|
// Does the folder path contain any '!'? If yes, return true, otherwise false.
|
||||||
// (This is a problem for Java)
|
// (This is a problem for Java)
|
||||||
bool checkProblemticPathJava(QDir folder)
|
bool checkProblemticPathJava(QDir folder)
|
||||||
{
|
{
|
||||||
QString pathfoldername = folder.absolutePath();
|
QString pathfoldername = folder.absolutePath();
|
||||||
return pathfoldername.contains("!", Qt::CaseInsensitive);
|
return pathfoldername.contains("!", Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
// Win32 crap
|
// Win32 crap
|
||||||
#if defined Q_OS_WIN
|
#if defined Q_OS_WIN
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winnls.h>
|
||||||
|
#include <shobjidl.h>
|
||||||
|
#include <objbase.h>
|
||||||
|
#include <objidl.h>
|
||||||
|
#include <shlguid.h>
|
||||||
|
#include <shlobj.h>
|
||||||
|
|
||||||
bool called_coinit = false;
|
bool called_coinit = false;
|
||||||
|
|
||||||
HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args)
|
HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args)
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
if (!called_coinit)
|
if (!called_coinit)
|
||||||
{
|
{
|
||||||
hres = CoInitialize(NULL);
|
hres = CoInitialize(NULL);
|
||||||
called_coinit = true;
|
called_coinit = true;
|
||||||
|
|
||||||
if (!SUCCEEDED(hres))
|
if (!SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
qWarning("Failed to initialize COM. Error 0x%08lX", hres);
|
qWarning("Failed to initialize COM. Error 0x%08X", hres);
|
||||||
return hres;
|
return hres;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IShellLink *link;
|
IShellLink *link;
|
||||||
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
||||||
(LPVOID *)&link);
|
(LPVOID *)&link);
|
||||||
|
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
IPersistFile *persistFile;
|
IPersistFile *persistFile;
|
||||||
|
|
||||||
link->SetPath(targetPath);
|
link->SetPath(targetPath);
|
||||||
link->SetArguments(args);
|
link->SetArguments(args);
|
||||||
|
|
||||||
hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile);
|
hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile);
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
WCHAR wstr[MAX_PATH];
|
WCHAR wstr[MAX_PATH];
|
||||||
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
|
MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
|
||||||
|
|
||||||
hres = persistFile->Save(wstr, TRUE);
|
hres = persistFile->Save(wstr, TRUE);
|
||||||
persistFile->Release();
|
persistFile->Release();
|
||||||
}
|
}
|
||||||
link->Release();
|
link->Release();
|
||||||
}
|
}
|
||||||
return hres;
|
return hres;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString getDesktopDir()
|
QString getDesktopDir()
|
||||||
{
|
{
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross-platform Shortcut creation
|
// Cross-platform Shortcut creation
|
||||||
bool createShortCut(QString location, QString dest, QStringList args, QString name,
|
bool createShortCut(QString location, QString dest, QStringList args, QString name,
|
||||||
QString icon)
|
QString icon)
|
||||||
{
|
{
|
||||||
#if defined Q_OS_LINUX
|
#if defined Q_OS_LINUX
|
||||||
location = PathCombine(location, name + ".desktop");
|
location = PathCombine(location, name + ".desktop");
|
||||||
|
|
||||||
QFile f(location);
|
QFile f(location);
|
||||||
f.open(QIODevice::WriteOnly | QIODevice::Text);
|
f.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
QTextStream stream(&f);
|
QTextStream stream(&f);
|
||||||
|
|
||||||
QString argstring;
|
QString argstring;
|
||||||
if (!args.empty())
|
if (!args.empty())
|
||||||
argstring = " '" + args.join("' '") + "'";
|
argstring = " '" + args.join("' '") + "'";
|
||||||
|
|
||||||
stream << "[Desktop Entry]"
|
stream << "[Desktop Entry]"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
stream << "Type=Application"
|
stream << "Type=Application"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
stream << "TryExec=" << dest.toLocal8Bit() << "\n";
|
stream << "TryExec=" << dest.toLocal8Bit() << "\n";
|
||||||
stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n";
|
stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n";
|
||||||
stream << "Name=" << name.toLocal8Bit() << "\n";
|
stream << "Name=" << name.toLocal8Bit() << "\n";
|
||||||
stream << "Icon=" << icon.toLocal8Bit() << "\n";
|
stream << "Icon=" << icon.toLocal8Bit() << "\n";
|
||||||
|
|
||||||
stream.flush();
|
stream.flush();
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup |
|
f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup |
|
||||||
QFileDevice::ExeOther);
|
QFileDevice::ExeOther);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#elif defined Q_OS_WIN
|
#elif defined Q_OS_WIN
|
||||||
// TODO: Fix
|
// TODO: Fix
|
||||||
// QFile file(PathCombine(location, name + ".lnk"));
|
// QFile file(PathCombine(location, name + ".lnk"));
|
||||||
// WCHAR *file_w;
|
// WCHAR *file_w;
|
||||||
// WCHAR *dest_w;
|
// WCHAR *dest_w;
|
||||||
// WCHAR *args_w;
|
// WCHAR *args_w;
|
||||||
// file.fileName().toWCharArray(file_w);
|
// file.fileName().toWCharArray(file_w);
|
||||||
// dest.toWCharArray(dest_w);
|
// dest.toWCharArray(dest_w);
|
||||||
|
|
||||||
// QString argStr;
|
// QString argStr;
|
||||||
// for (int i = 0; i < args.count(); i++)
|
// for (int i = 0; i < args.count(); i++)
|
||||||
// {
|
// {
|
||||||
// argStr.append(args[i]);
|
// argStr.append(args[i]);
|
||||||
// argStr.append(" ");
|
// argStr.append(" ");
|
||||||
// }
|
// }
|
||||||
// argStr.toWCharArray(args_w);
|
// argStr.toWCharArray(args_w);
|
||||||
|
|
||||||
// return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
|
// return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
qWarning("Desktop Shortcuts not supported on your platform!");
|
qWarning("Desktop Shortcuts not supported on your platform!");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace FS
|
|||||||
class MULTIMC_LOGIC_EXPORT FileSystemException : public ::Exception
|
class MULTIMC_LOGIC_EXPORT FileSystemException : public ::Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileSystemException(const QString &message) : Exception(message) {}
|
FileSystemException(const QString &message) : Exception(message) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,34 +48,34 @@ MULTIMC_LOGIC_EXPORT bool ensureFolderPathExists(QString filenamepath);
|
|||||||
class MULTIMC_LOGIC_EXPORT copy
|
class MULTIMC_LOGIC_EXPORT copy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
copy(const QString & src, const QString & dst)
|
copy(const QString & src, const QString & dst)
|
||||||
{
|
{
|
||||||
m_src = src;
|
m_src = src;
|
||||||
m_dst = dst;
|
m_dst = dst;
|
||||||
}
|
}
|
||||||
copy & followSymlinks(const bool follow)
|
copy & followSymlinks(const bool follow)
|
||||||
{
|
{
|
||||||
m_followSymlinks = follow;
|
m_followSymlinks = follow;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
copy & blacklist(const IPathMatcher * filter)
|
copy & blacklist(const IPathMatcher * filter)
|
||||||
{
|
{
|
||||||
m_blacklist = filter;
|
m_blacklist = filter;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
bool operator()()
|
bool operator()()
|
||||||
{
|
{
|
||||||
return operator()(QString());
|
return operator()(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool operator()(const QString &offset);
|
bool operator()(const QString &offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_followSymlinks = true;
|
bool m_followSymlinks = true;
|
||||||
const IPathMatcher * m_blacklist = nullptr;
|
const IPathMatcher * m_blacklist = nullptr;
|
||||||
QDir m_src;
|
QDir m_src;
|
||||||
QDir m_dst;
|
QDir m_dst;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +83,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
MULTIMC_LOGIC_EXPORT bool deletePath(QString path);
|
MULTIMC_LOGIC_EXPORT bool deletePath(QString path);
|
||||||
|
|
||||||
MULTIMC_LOGIC_EXPORT QString PathCombine(const QString &path1, const QString &path2);
|
MULTIMC_LOGIC_EXPORT QString PathCombine(QString path1, QString path2);
|
||||||
MULTIMC_LOGIC_EXPORT QString PathCombine(const QString &path1, const QString &path2, const QString &path3);
|
MULTIMC_LOGIC_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
|
||||||
MULTIMC_LOGIC_EXPORT QString PathCombine(const QString &path1, const QString &path2, const QString &path3, const QString &path4);
|
|
||||||
|
|
||||||
MULTIMC_LOGIC_EXPORT QString AbsolutePath(QString path);
|
MULTIMC_LOGIC_EXPORT QString AbsolutePath(QString path);
|
||||||
|
|
||||||
|
|||||||
@@ -7,155 +7,155 @@
|
|||||||
|
|
||||||
class FileSystemTest : public QObject
|
class FileSystemTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const QString bothSlash = "/foo/";
|
const QString bothSlash = "/foo/";
|
||||||
const QString trailingSlash = "foo/";
|
const QString trailingSlash = "foo/";
|
||||||
const QString leadingSlash = "/foo";
|
const QString leadingSlash = "/foo";
|
||||||
|
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
void test_pathCombine()
|
void test_pathCombine()
|
||||||
{
|
{
|
||||||
QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash));
|
QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash));
|
||||||
QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash));
|
QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash));
|
||||||
QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash));
|
QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash));
|
||||||
|
|
||||||
QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash));
|
QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash));
|
||||||
QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash));
|
QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash));
|
||||||
QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash));
|
QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PathCombine1_data()
|
void test_PathCombine1_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("result");
|
QTest::addColumn<QString>("result");
|
||||||
QTest::addColumn<QString>("path1");
|
QTest::addColumn<QString>("path1");
|
||||||
QTest::addColumn<QString>("path2");
|
QTest::addColumn<QString>("path2");
|
||||||
|
|
||||||
QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl";
|
QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl";
|
||||||
QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl";
|
QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl";
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc";
|
QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc";
|
||||||
QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl";
|
QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl";
|
||||||
QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl";
|
QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PathCombine1()
|
void test_PathCombine1()
|
||||||
{
|
{
|
||||||
QFETCH(QString, result);
|
QFETCH(QString, result);
|
||||||
QFETCH(QString, path1);
|
QFETCH(QString, path1);
|
||||||
QFETCH(QString, path2);
|
QFETCH(QString, path2);
|
||||||
|
|
||||||
QCOMPARE(FS::PathCombine(path1, path2), result);
|
QCOMPARE(FS::PathCombine(path1, path2), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PathCombine2_data()
|
void test_PathCombine2_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("result");
|
QTest::addColumn<QString>("result");
|
||||||
QTest::addColumn<QString>("path1");
|
QTest::addColumn<QString>("path1");
|
||||||
QTest::addColumn<QString>("path2");
|
QTest::addColumn<QString>("path2");
|
||||||
QTest::addColumn<QString>("path3");
|
QTest::addColumn<QString>("path3");
|
||||||
|
|
||||||
QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl";
|
QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl";
|
||||||
QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl";
|
QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl";
|
||||||
QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl";
|
QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl";
|
||||||
QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl";
|
QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl";
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl";
|
QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl";
|
||||||
QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
|
QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
|
||||||
QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl";
|
QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl";
|
||||||
QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
|
QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PathCombine2()
|
void test_PathCombine2()
|
||||||
{
|
{
|
||||||
QFETCH(QString, result);
|
QFETCH(QString, result);
|
||||||
QFETCH(QString, path1);
|
QFETCH(QString, path1);
|
||||||
QFETCH(QString, path2);
|
QFETCH(QString, path2);
|
||||||
QFETCH(QString, path3);
|
QFETCH(QString, path3);
|
||||||
|
|
||||||
QCOMPARE(FS::PathCombine(path1, path2, path3), result);
|
QCOMPARE(FS::PathCombine(path1, path2, path3), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_copy()
|
void test_copy()
|
||||||
{
|
{
|
||||||
QString folder = QFINDTESTDATA("data/test_folder");
|
QString folder = QFINDTESTDATA("data/test_folder");
|
||||||
auto f = [&folder]()
|
auto f = [&folder]()
|
||||||
{
|
{
|
||||||
QTemporaryDir tempDir;
|
QTemporaryDir tempDir;
|
||||||
tempDir.setAutoRemove(true);
|
tempDir.setAutoRemove(true);
|
||||||
qDebug() << "From:" << folder << "To:" << tempDir.path();
|
qDebug() << "From:" << folder << "To:" << tempDir.path();
|
||||||
|
|
||||||
QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
|
QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
|
||||||
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();
|
c();
|
||||||
|
|
||||||
for(auto entry: target_dir.entryList())
|
for(auto entry: target_dir.entryList())
|
||||||
{
|
{
|
||||||
qDebug() << entry;
|
qDebug() << entry;
|
||||||
}
|
}
|
||||||
QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
|
QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
|
||||||
QVERIFY(target_dir.entryList().contains("assets"));
|
QVERIFY(target_dir.entryList().contains("assets"));
|
||||||
};
|
};
|
||||||
|
|
||||||
// first try variant without trailing /
|
// first try variant without trailing /
|
||||||
QVERIFY(!folder.endsWith('/'));
|
QVERIFY(!folder.endsWith('/'));
|
||||||
f();
|
f();
|
||||||
|
|
||||||
// then variant with trailing /
|
// then variant with trailing /
|
||||||
folder.append('/');
|
folder.append('/');
|
||||||
QVERIFY(folder.endsWith('/'));
|
QVERIFY(folder.endsWith('/'));
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_getDesktop()
|
void test_getDesktop()
|
||||||
{
|
{
|
||||||
QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
|
QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is only valid on linux
|
// this is only valid on linux
|
||||||
// FIXME: implement on windows, OSX, then test.
|
// FIXME: implement on windows, OSX, then test.
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
void test_createShortcut_data()
|
void test_createShortcut_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("location");
|
QTest::addColumn<QString>("location");
|
||||||
QTest::addColumn<QString>("dest");
|
QTest::addColumn<QString>("dest");
|
||||||
QTest::addColumn<QStringList>("args");
|
QTest::addColumn<QStringList>("args");
|
||||||
QTest::addColumn<QString>("name");
|
QTest::addColumn<QString>("name");
|
||||||
QTest::addColumn<QString>("iconLocation");
|
QTest::addColumn<QString>("iconLocation");
|
||||||
QTest::addColumn<QByteArray>("result");
|
QTest::addColumn<QByteArray>("result");
|
||||||
|
|
||||||
QTest::newRow("unix") << QDir::currentPath()
|
QTest::newRow("unix") << QDir::currentPath()
|
||||||
<< "asdfDest"
|
<< "asdfDest"
|
||||||
<< (QStringList() << "arg1" << "arg2")
|
<< (QStringList() << "arg1" << "arg2")
|
||||||
<< "asdf"
|
<< "asdf"
|
||||||
<< QString()
|
<< QString()
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
<< MULTIMC_GET_TEST_FILE("data/FileSystem-test_createShortcut-unix")
|
<< MULTIMC_GET_TEST_FILE("data/FileSystem-test_createShortcut-unix")
|
||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
<< QByteArray()
|
<< QByteArray()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_createShortcut()
|
void test_createShortcut()
|
||||||
{
|
{
|
||||||
QFETCH(QString, location);
|
QFETCH(QString, location);
|
||||||
QFETCH(QString, dest);
|
QFETCH(QString, dest);
|
||||||
QFETCH(QStringList, args);
|
QFETCH(QStringList, args);
|
||||||
QFETCH(QString, name);
|
QFETCH(QString, name);
|
||||||
QFETCH(QString, iconLocation);
|
QFETCH(QString, iconLocation);
|
||||||
QFETCH(QByteArray, result);
|
QFETCH(QByteArray, result);
|
||||||
|
|
||||||
QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
|
QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
|
||||||
QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
|
QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
|
||||||
|
|
||||||
//QDir().remove(location);
|
//QDir().remove(location);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
#include "Filter.h"
|
|
||||||
|
|
||||||
Filter::~Filter(){}
|
|
||||||
|
|
||||||
ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){}
|
|
||||||
ContainsFilter::~ContainsFilter(){}
|
|
||||||
bool ContainsFilter::accepts(const QString& value)
|
|
||||||
{
|
|
||||||
return value.contains(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){}
|
|
||||||
ExactFilter::~ExactFilter(){}
|
|
||||||
bool ExactFilter::accepts(const QString& value)
|
|
||||||
{
|
|
||||||
return value == pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
|
|
||||||
:invert(invert)
|
|
||||||
{
|
|
||||||
pattern.setPattern(regexp);
|
|
||||||
pattern.optimize();
|
|
||||||
}
|
|
||||||
RegexpFilter::~RegexpFilter(){}
|
|
||||||
bool RegexpFilter::accepts(const QString& value)
|
|
||||||
{
|
|
||||||
auto match = pattern.match(value);
|
|
||||||
bool matched = match.hasMatch();
|
|
||||||
return invert ? (!matched) : (matched);
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT Filter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Filter();
|
|
||||||
virtual bool accepts(const QString & value) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT ContainsFilter: public Filter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ContainsFilter(const QString &pattern);
|
|
||||||
virtual ~ContainsFilter();
|
|
||||||
bool accepts(const QString & value) override;
|
|
||||||
private:
|
|
||||||
QString pattern;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT ExactFilter: public Filter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ExactFilter(const QString &pattern);
|
|
||||||
virtual ~ExactFilter();
|
|
||||||
bool accepts(const QString & value) override;
|
|
||||||
private:
|
|
||||||
QString pattern;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT RegexpFilter: public Filter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RegexpFilter(const QString ®exp, bool invert);
|
|
||||||
virtual ~RegexpFilter();
|
|
||||||
bool accepts(const QString & value) override;
|
|
||||||
private:
|
|
||||||
QRegularExpression pattern;
|
|
||||||
bool invert = false;
|
|
||||||
};
|
|
||||||
356
api/logic/FolderInstanceProvider.cpp
Normal file
356
api/logic/FolderInstanceProvider.cpp
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
#include "FolderInstanceProvider.h"
|
||||||
|
#include "settings/INISettingsObject.h"
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "minecraft/onesix/OneSixInstance.h"
|
||||||
|
#include "minecraft/legacy/LegacyInstance.h"
|
||||||
|
#include "NullInstance.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
const static int GROUP_FILE_FORMAT_VERSION = 1;
|
||||||
|
|
||||||
|
struct WatchLock
|
||||||
|
{
|
||||||
|
WatchLock(QFileSystemWatcher * watcher, const QString& instDir)
|
||||||
|
: m_watcher(watcher), m_instDir(instDir)
|
||||||
|
{
|
||||||
|
m_watcher->removePath(m_instDir);
|
||||||
|
}
|
||||||
|
~WatchLock()
|
||||||
|
{
|
||||||
|
m_watcher->addPath(m_instDir);
|
||||||
|
}
|
||||||
|
QFileSystemWatcher * m_watcher;
|
||||||
|
QString m_instDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
FolderInstanceProvider::FolderInstanceProvider(SettingsObjectPtr settings, const QString& instDir)
|
||||||
|
: BaseInstanceProvider(settings)
|
||||||
|
{
|
||||||
|
m_instDir = instDir;
|
||||||
|
if (!QDir::current().exists(m_instDir))
|
||||||
|
{
|
||||||
|
QDir::current().mkpath(m_instDir);
|
||||||
|
}
|
||||||
|
m_watcher = new QFileSystemWatcher(this);
|
||||||
|
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &FolderInstanceProvider::instanceDirContentsChanged);
|
||||||
|
m_watcher->addPath(m_instDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< InstanceId > FolderInstanceProvider::discoverInstances()
|
||||||
|
{
|
||||||
|
QList<InstanceId> out;
|
||||||
|
QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable, QDirIterator::FollowSymlinks);
|
||||||
|
while (iter.hasNext())
|
||||||
|
{
|
||||||
|
QString subDir = iter.next();
|
||||||
|
QFileInfo dirInfo(subDir);
|
||||||
|
if (!QFileInfo(FS::PathCombine(subDir, "instance.cfg")).exists())
|
||||||
|
continue;
|
||||||
|
// if it is a symlink, ignore it if it goes to the instance folder
|
||||||
|
if(dirInfo.isSymLink())
|
||||||
|
{
|
||||||
|
QFileInfo targetInfo(dirInfo.symLinkTarget());
|
||||||
|
QFileInfo instDirInfo(m_instDir);
|
||||||
|
if(targetInfo.canonicalPath() == instDirInfo.canonicalFilePath())
|
||||||
|
{
|
||||||
|
qDebug() << "Ignoring symlink" << subDir << "that leads into the instances folder";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto id = dirInfo.fileName();
|
||||||
|
out.append(id);
|
||||||
|
qDebug() << "Found instance ID" << id;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
InstancePtr FolderInstanceProvider::loadInstance(const InstanceId& id)
|
||||||
|
{
|
||||||
|
if(!m_groupsLoaded)
|
||||||
|
{
|
||||||
|
loadGroupList();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto instanceRoot = FS::PathCombine(m_instDir, id);
|
||||||
|
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(instanceRoot, "instance.cfg"));
|
||||||
|
InstancePtr inst;
|
||||||
|
|
||||||
|
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||||
|
|
||||||
|
QString inst_type = instanceSettings->get("InstanceType").toString();
|
||||||
|
|
||||||
|
if (inst_type == "OneSix" || inst_type == "Nostalgia")
|
||||||
|
{
|
||||||
|
inst.reset(new OneSixInstance(m_globalSettings, instanceSettings, instanceRoot));
|
||||||
|
}
|
||||||
|
else if (inst_type == "Legacy")
|
||||||
|
{
|
||||||
|
inst.reset(new LegacyInstance(m_globalSettings, instanceSettings, instanceRoot));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inst.reset(new NullInstance(m_globalSettings, instanceSettings, instanceRoot));
|
||||||
|
}
|
||||||
|
inst->init();
|
||||||
|
inst->setProvider(this);
|
||||||
|
auto iter = groupMap.find(id);
|
||||||
|
if (iter != groupMap.end())
|
||||||
|
{
|
||||||
|
inst->setGroupInitial((*iter));
|
||||||
|
}
|
||||||
|
connect(inst.get(), &BaseInstance::groupChanged, this, &FolderInstanceProvider::groupChanged);
|
||||||
|
qDebug() << "Loaded instance " << inst->name() << " from " << inst->instanceRoot();
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "InstanceImportTask.h"
|
||||||
|
Task * FolderInstanceProvider::zipImportTask(const QUrl sourceUrl, const QString& instName, const QString& instGroup, const QString& instIcon)
|
||||||
|
{
|
||||||
|
return new InstanceImportTask(m_globalSettings, sourceUrl, this, instName, instIcon, instGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "InstanceCreationTask.h"
|
||||||
|
Task * FolderInstanceProvider::creationTask(BaseVersionPtr version, const QString& instName, const QString& instGroup, const QString& instIcon)
|
||||||
|
{
|
||||||
|
return new InstanceCreationTask(m_globalSettings, this, version, instName, instIcon, instGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "InstanceCopyTask.h"
|
||||||
|
Task * FolderInstanceProvider::copyTask(const InstancePtr& oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves)
|
||||||
|
{
|
||||||
|
return new InstanceCopyTask(m_globalSettings, this, oldInstance, instName, instIcon, instGroup, copySaves);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderInstanceProvider::saveGroupList()
|
||||||
|
{
|
||||||
|
WatchLock foo(m_watcher, m_instDir);
|
||||||
|
QString groupFileName = m_instDir + "/instgroups.json";
|
||||||
|
QMap<QString, QSet<QString>> reverseGroupMap;
|
||||||
|
for (auto iter = groupMap.begin(); iter != groupMap.end(); iter++)
|
||||||
|
{
|
||||||
|
QString id = iter.key();
|
||||||
|
QString group = iter.value();
|
||||||
|
if (group.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!reverseGroupMap.count(group))
|
||||||
|
{
|
||||||
|
QSet<QString> set;
|
||||||
|
set.insert(id);
|
||||||
|
reverseGroupMap[group] = set;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSet<QString> &set = reverseGroupMap[group];
|
||||||
|
set.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QJsonObject toplevel;
|
||||||
|
toplevel.insert("formatVersion", QJsonValue(QString("1")));
|
||||||
|
QJsonObject groupsArr;
|
||||||
|
for (auto iter = reverseGroupMap.begin(); iter != reverseGroupMap.end(); iter++)
|
||||||
|
{
|
||||||
|
auto list = iter.value();
|
||||||
|
auto name = iter.key();
|
||||||
|
QJsonObject groupObj;
|
||||||
|
QJsonArray instanceArr;
|
||||||
|
groupObj.insert("hidden", QJsonValue(QString("false")));
|
||||||
|
for (auto item : list)
|
||||||
|
{
|
||||||
|
instanceArr.append(QJsonValue(item));
|
||||||
|
}
|
||||||
|
groupObj.insert("instances", instanceArr);
|
||||||
|
groupsArr.insert(name, groupObj);
|
||||||
|
}
|
||||||
|
toplevel.insert("groups", groupsArr);
|
||||||
|
QJsonDocument doc(toplevel);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FS::write(groupFileName, doc.toJson());
|
||||||
|
}
|
||||||
|
catch(FS::FileSystemException & e)
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to write instance group file :" << e.cause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderInstanceProvider::loadGroupList()
|
||||||
|
{
|
||||||
|
QSet<QString> groupSet;
|
||||||
|
|
||||||
|
QString groupFileName = m_instDir + "/instgroups.json";
|
||||||
|
|
||||||
|
// if there's no group file, fail
|
||||||
|
if (!QFileInfo(groupFileName).exists())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QByteArray jsonData;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jsonData = FS::read(groupFileName);
|
||||||
|
}
|
||||||
|
catch (FS::FileSystemException & e)
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to read instance group file :" << e.cause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error);
|
||||||
|
|
||||||
|
// if the json was bad, fail
|
||||||
|
if (error.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
qCritical() << QString("Failed to parse instance group file: %1 at offset %2")
|
||||||
|
.arg(error.errorString(), QString::number(error.offset))
|
||||||
|
.toUtf8();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the root of the json wasn't an object, fail
|
||||||
|
if (!jsonDoc.isObject())
|
||||||
|
{
|
||||||
|
qWarning() << "Invalid group file. Root entry should be an object.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject rootObj = jsonDoc.object();
|
||||||
|
|
||||||
|
// Make sure the format version matches, otherwise fail.
|
||||||
|
if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get the groups. if it's not an object, fail
|
||||||
|
if (!rootObj.value("groups").isObject())
|
||||||
|
{
|
||||||
|
qWarning() << "Invalid group list JSON: 'groups' should be an object.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
groupMap.clear();
|
||||||
|
|
||||||
|
// Iterate through all the groups.
|
||||||
|
QJsonObject groupMapping = rootObj.value("groups").toObject();
|
||||||
|
for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++)
|
||||||
|
{
|
||||||
|
QString groupName = iter.key();
|
||||||
|
|
||||||
|
// If not an object, complain and skip to the next one.
|
||||||
|
if (!iter.value().isObject())
|
||||||
|
{
|
||||||
|
qWarning() << QString("Group '%1' in the group list should "
|
||||||
|
"be an object.")
|
||||||
|
.arg(groupName)
|
||||||
|
.toUtf8();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject groupObj = iter.value().toObject();
|
||||||
|
if (!groupObj.value("instances").isArray())
|
||||||
|
{
|
||||||
|
qWarning() << QString("Group '%1' in the group list is invalid. "
|
||||||
|
"It should contain an array "
|
||||||
|
"called 'instances'.")
|
||||||
|
.arg(groupName)
|
||||||
|
.toUtf8();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep a list/set of groups for choosing
|
||||||
|
groupSet.insert(groupName);
|
||||||
|
|
||||||
|
// Iterate through the list of instances in the group.
|
||||||
|
QJsonArray instancesArray = groupObj.value("instances").toArray();
|
||||||
|
|
||||||
|
for (QJsonArray::iterator iter2 = instancesArray.begin(); iter2 != instancesArray.end();
|
||||||
|
iter2++)
|
||||||
|
{
|
||||||
|
groupMap[(*iter2).toString()] = groupName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_groupsLoaded = true;
|
||||||
|
emit groupsChanged(groupSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderInstanceProvider::groupChanged()
|
||||||
|
{
|
||||||
|
// save the groups. save all of them.
|
||||||
|
auto instance = (BaseInstance *) QObject::sender();
|
||||||
|
auto id = instance->id();
|
||||||
|
groupMap[id] = instance->group();
|
||||||
|
emit groupsChanged({instance->group()});
|
||||||
|
saveGroupList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FolderInstanceProvider::instanceDirContentsChanged(const QString& path)
|
||||||
|
{
|
||||||
|
Q_UNUSED(path);
|
||||||
|
emit instancesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderInstanceProvider::on_InstFolderChanged(const Setting &setting, QVariant value)
|
||||||
|
{
|
||||||
|
QString newInstDir = value.toString();
|
||||||
|
if(newInstDir != m_instDir)
|
||||||
|
{
|
||||||
|
if(m_groupsLoaded)
|
||||||
|
{
|
||||||
|
saveGroupList();
|
||||||
|
}
|
||||||
|
m_instDir = newInstDir;
|
||||||
|
m_groupsLoaded = false;
|
||||||
|
emit instancesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FolderInstanceProvider::getStagedInstancePath()
|
||||||
|
{
|
||||||
|
QString key = QUuid::createUuid().toString();
|
||||||
|
QString relPath = FS::PathCombine("_MMC_TEMP/" , key);
|
||||||
|
QDir rootPath(m_instDir);
|
||||||
|
auto path = FS::PathCombine(m_instDir, relPath);
|
||||||
|
if(!rootPath.mkpath(relPath))
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FolderInstanceProvider::commitStagedInstance(const QString& keyPath, const QString& path, const QString& instanceName,
|
||||||
|
const QString& groupName)
|
||||||
|
{
|
||||||
|
if(!path.contains(keyPath))
|
||||||
|
{
|
||||||
|
qWarning() << "It is not possible to commit" << path << "because it is not in" << keyPath;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QDir dir;
|
||||||
|
QString instID = FS::DirNameFromString(instanceName, m_instDir);
|
||||||
|
{
|
||||||
|
WatchLock lock(m_watcher, m_instDir);
|
||||||
|
if(!dir.rename(path, FS::PathCombine(m_instDir, instID)))
|
||||||
|
{
|
||||||
|
destroyStagingPath(keyPath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
groupMap[instID] = groupName;
|
||||||
|
emit groupsChanged({groupName});
|
||||||
|
emit instancesChanged();
|
||||||
|
}
|
||||||
|
saveGroupList();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FolderInstanceProvider::destroyStagingPath(const QString& keyPath)
|
||||||
|
{
|
||||||
|
return FS::deletePath(keyPath);
|
||||||
|
}
|
||||||
|
|
||||||
63
api/logic/FolderInstanceProvider.h
Normal file
63
api/logic/FolderInstanceProvider.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BaseInstanceProvider.h"
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
|
class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FolderInstanceProvider(SettingsObjectPtr settings, const QString & instDir);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// used by InstanceList to @return a list of plausible IDs to probe for
|
||||||
|
QList<InstanceId> discoverInstances() override;
|
||||||
|
|
||||||
|
/// used by InstanceList to (re)load an instance with the given @id.
|
||||||
|
InstancePtr loadInstance(const InstanceId& id) override;
|
||||||
|
|
||||||
|
|
||||||
|
// create instance in this provider
|
||||||
|
Task * creationTask(BaseVersionPtr version, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||||
|
|
||||||
|
// copy instance to this provider
|
||||||
|
Task * copyTask(const InstancePtr &oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves);
|
||||||
|
|
||||||
|
// import zipped instance into this provider
|
||||||
|
Task * zipImportTask(const QUrl sourceUrl, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new empty staging area for instance creation and @return a path/key top commit it later.
|
||||||
|
* Used by instance manipulation tasks.
|
||||||
|
*/
|
||||||
|
QString getStagedInstancePath() override;
|
||||||
|
/**
|
||||||
|
* Commit the staging area given by @keyPath to the provider - used when creation succeeds.
|
||||||
|
* Used by instance manipulation tasks.
|
||||||
|
*/
|
||||||
|
bool commitStagedInstance(const QString & keyPath, const QString & path, const QString& instanceName, const QString & groupName) override;
|
||||||
|
/**
|
||||||
|
* Destroy a previously created staging area given by @keyPath - used when creation fails.
|
||||||
|
* Used by instance manipulation tasks.
|
||||||
|
*/
|
||||||
|
bool destroyStagingPath(const QString & keyPath) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_InstFolderChanged(const Setting &setting, QVariant value);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void instanceDirContentsChanged(const QString &path);
|
||||||
|
void groupChanged();
|
||||||
|
|
||||||
|
private: /* methods */
|
||||||
|
void loadGroupList() override;
|
||||||
|
void saveGroupList() override;
|
||||||
|
|
||||||
|
private: /* data */
|
||||||
|
QString m_instDir;
|
||||||
|
QFileSystemWatcher * m_watcher;
|
||||||
|
QMap<QString, QString> groupMap;
|
||||||
|
bool m_groupsLoaded = false;
|
||||||
|
};
|
||||||
@@ -4,112 +4,112 @@
|
|||||||
|
|
||||||
bool GZip::unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes)
|
bool GZip::unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes)
|
||||||
{
|
{
|
||||||
if (compressedBytes.size() == 0)
|
if (compressedBytes.size() == 0)
|
||||||
{
|
{
|
||||||
uncompressedBytes = compressedBytes;
|
uncompressedBytes = compressedBytes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned uncompLength = compressedBytes.size();
|
unsigned uncompLength = compressedBytes.size();
|
||||||
uncompressedBytes.clear();
|
uncompressedBytes.clear();
|
||||||
uncompressedBytes.resize(uncompLength);
|
uncompressedBytes.resize(uncompLength);
|
||||||
|
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
memset(&strm, 0, sizeof(strm));
|
memset(&strm, 0, sizeof(strm));
|
||||||
strm.next_in = (Bytef *)compressedBytes.data();
|
strm.next_in = (Bytef *)compressedBytes.data();
|
||||||
strm.avail_in = compressedBytes.size();
|
strm.avail_in = compressedBytes.size();
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK)
|
if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = Z_OK;
|
int err = Z_OK;
|
||||||
|
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
// If our output buffer is too small
|
// If our output buffer is too small
|
||||||
if (strm.total_out >= uncompLength)
|
if (strm.total_out >= uncompLength)
|
||||||
{
|
{
|
||||||
uncompressedBytes.resize(uncompLength * 2);
|
uncompressedBytes.resize(uncompLength * 2);
|
||||||
uncompLength *= 2;
|
uncompLength *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.next_out = (Bytef *)(uncompressedBytes.data() + strm.total_out);
|
strm.next_out = (Bytef *)(uncompressedBytes.data() + strm.total_out);
|
||||||
strm.avail_out = uncompLength - strm.total_out;
|
strm.avail_out = uncompLength - strm.total_out;
|
||||||
|
|
||||||
// Inflate another chunk.
|
// Inflate another chunk.
|
||||||
err = inflate(&strm, Z_SYNC_FLUSH);
|
err = inflate(&strm, Z_SYNC_FLUSH);
|
||||||
if (err == Z_STREAM_END)
|
if (err == Z_STREAM_END)
|
||||||
done = true;
|
done = true;
|
||||||
else if (err != Z_OK)
|
else if (err != Z_OK)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inflateEnd(&strm) != Z_OK || !done)
|
if (inflateEnd(&strm) != Z_OK || !done)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uncompressedBytes.resize(strm.total_out);
|
uncompressedBytes.resize(strm.total_out);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GZip::zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes)
|
bool GZip::zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes)
|
||||||
{
|
{
|
||||||
if (uncompressedBytes.size() == 0)
|
if (uncompressedBytes.size() == 0)
|
||||||
{
|
{
|
||||||
compressedBytes = uncompressedBytes;
|
compressedBytes = uncompressedBytes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned compLength = std::min(uncompressedBytes.size(), 16);
|
unsigned compLength = std::min(uncompressedBytes.size(), 16);
|
||||||
compressedBytes.clear();
|
compressedBytes.clear();
|
||||||
compressedBytes.resize(compLength);
|
compressedBytes.resize(compLength);
|
||||||
|
|
||||||
z_stream zs;
|
z_stream zs;
|
||||||
memset(&zs, 0, sizeof(zs));
|
memset(&zs, 0, sizeof(zs));
|
||||||
|
|
||||||
if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (16 + MAX_WBITS), 8, Z_DEFAULT_STRATEGY) != Z_OK)
|
if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (16 + MAX_WBITS), 8, Z_DEFAULT_STRATEGY) != Z_OK)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
zs.next_in = (Bytef*)uncompressedBytes.data();
|
zs.next_in = (Bytef*)uncompressedBytes.data();
|
||||||
zs.avail_in = uncompressedBytes.size();
|
zs.avail_in = uncompressedBytes.size();
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
compressedBytes.resize(uncompressedBytes.size());
|
compressedBytes.resize(uncompressedBytes.size());
|
||||||
|
|
||||||
unsigned offset = 0;
|
unsigned offset = 0;
|
||||||
unsigned temp = 0;
|
unsigned temp = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto remaining = compressedBytes.size() - offset;
|
auto remaining = compressedBytes.size() - offset;
|
||||||
if(remaining < 1)
|
if(remaining < 1)
|
||||||
{
|
{
|
||||||
compressedBytes.resize(compressedBytes.size() * 2);
|
compressedBytes.resize(compressedBytes.size() * 2);
|
||||||
}
|
}
|
||||||
zs.next_out = (Bytef *) (compressedBytes.data() + offset);
|
zs.next_out = (Bytef *) (compressedBytes.data() + offset);
|
||||||
temp = zs.avail_out = compressedBytes.size() - offset;
|
temp = zs.avail_out = compressedBytes.size() - offset;
|
||||||
ret = deflate(&zs, Z_FINISH);
|
ret = deflate(&zs, Z_FINISH);
|
||||||
offset += temp - zs.avail_out;
|
offset += temp - zs.avail_out;
|
||||||
} while (ret == Z_OK);
|
} while (ret == Z_OK);
|
||||||
|
|
||||||
compressedBytes.resize(offset);
|
compressedBytes.resize(offset);
|
||||||
|
|
||||||
if (deflateEnd(&zs) != Z_OK)
|
if (deflateEnd(&zs) != Z_OK)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != Z_STREAM_END)
|
if (ret != Z_STREAM_END)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
class MULTIMC_LOGIC_EXPORT GZip
|
class MULTIMC_LOGIC_EXPORT GZip
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes);
|
static bool unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes);
|
||||||
static bool zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes);
|
static bool zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,50 +6,50 @@
|
|||||||
|
|
||||||
void fib(int &prev, int &cur)
|
void fib(int &prev, int &cur)
|
||||||
{
|
{
|
||||||
auto ret = prev + cur;
|
auto ret = prev + cur;
|
||||||
prev = cur;
|
prev = cur;
|
||||||
cur = ret;
|
cur = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GZipTest : public QObject
|
class GZipTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
|
|
||||||
void test_Through()
|
void test_Through()
|
||||||
{
|
{
|
||||||
// test up to 10 MB
|
// test up to 10 MB
|
||||||
static const int size = 10 * 1024 * 1024;
|
static const int size = 10 * 1024 * 1024;
|
||||||
QByteArray random;
|
QByteArray random;
|
||||||
QByteArray compressed;
|
QByteArray compressed;
|
||||||
QByteArray decompressed;
|
QByteArray decompressed;
|
||||||
std::default_random_engine eng((std::random_device())());
|
std::default_random_engine eng((std::random_device())());
|
||||||
std::uniform_int_distribution<uint8_t> idis(0, std::numeric_limits<uint8_t>::max());
|
std::uniform_int_distribution<uint8_t> idis(0, std::numeric_limits<uint8_t>::max());
|
||||||
|
|
||||||
// initialize random buffer
|
// initialize random buffer
|
||||||
for(int i = 0; i < size; i++)
|
for(int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
random.append((char)idis(eng));
|
random.append((char)idis(eng));
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize fibonacci
|
// initialize fibonacci
|
||||||
int prev = 1;
|
int prev = 1;
|
||||||
int cur = 1;
|
int cur = 1;
|
||||||
|
|
||||||
// test if fibonacci long random buffers pass through GZip
|
// test if fibonacci long random buffers pass through GZip
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
QByteArray copy = random;
|
QByteArray copy = random;
|
||||||
copy.resize(cur);
|
copy.resize(cur);
|
||||||
compressed.clear();
|
compressed.clear();
|
||||||
decompressed.clear();
|
decompressed.clear();
|
||||||
QVERIFY(GZip::zip(copy, compressed));
|
QVERIFY(GZip::zip(copy, compressed));
|
||||||
QVERIFY(GZip::unzip(compressed, decompressed));
|
QVERIFY(GZip::unzip(compressed, decompressed));
|
||||||
QCOMPARE(decompressed, copy);
|
QCOMPARE(decompressed, copy);
|
||||||
fib(prev, cur);
|
fib(prev, cur);
|
||||||
} while (cur < size);
|
} while (cur < size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(GZipTest)
|
QTEST_GUILESS_MAIN(GZipTest)
|
||||||
|
|||||||
@@ -1,56 +1,68 @@
|
|||||||
#include "InstanceCopyTask.h"
|
#include "InstanceCopyTask.h"
|
||||||
|
#include "BaseInstanceProvider.h"
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "NullInstance.h"
|
#include "NullInstance.h"
|
||||||
#include "pathmatcher/RegexpMatcher.h"
|
#include "pathmatcher/RegexpMatcher.h"
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves)
|
InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvider* target, InstancePtr origInstance, const QString& instName, const QString& instIcon, const QString& instGroup, bool copySaves)
|
||||||
{
|
{
|
||||||
m_origInstance = origInstance;
|
m_globalSettings = settings;
|
||||||
|
m_target = target;
|
||||||
|
m_origInstance = origInstance;
|
||||||
|
m_instName = instName;
|
||||||
|
m_instIcon = instIcon;
|
||||||
|
m_instGroup = instGroup;
|
||||||
|
|
||||||
if(!copySaves)
|
if(!copySaves)
|
||||||
{
|
{
|
||||||
// FIXME: get this from the original instance type...
|
// FIXME: get this from the original instance type...
|
||||||
auto matcherReal = new RegexpMatcher("[.]?minecraft/saves");
|
auto matcherReal = new RegexpMatcher("[.]?minecraft/saves");
|
||||||
matcherReal->caseSensitive(false);
|
matcherReal->caseSensitive(false);
|
||||||
m_matcher.reset(matcherReal);
|
m_matcher.reset(matcherReal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceCopyTask::executeTask()
|
void InstanceCopyTask::executeTask()
|
||||||
{
|
{
|
||||||
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
|
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
|
||||||
|
m_stagingPath = m_target->getStagedInstancePath();
|
||||||
|
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
|
||||||
|
folderCopy.followSymlinks(false).blacklist(m_matcher.get());
|
||||||
|
|
||||||
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
|
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
|
||||||
folderCopy.followSymlinks(false).blacklist(m_matcher.get());
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &InstanceCopyTask::copyFinished);
|
||||||
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &InstanceCopyTask::copyAborted);
|
||||||
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
|
m_copyFutureWatcher.setFuture(m_copyFuture);
|
||||||
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &InstanceCopyTask::copyFinished);
|
|
||||||
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &InstanceCopyTask::copyAborted);
|
|
||||||
m_copyFutureWatcher.setFuture(m_copyFuture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceCopyTask::copyFinished()
|
void InstanceCopyTask::copyFinished()
|
||||||
{
|
{
|
||||||
auto successful = m_copyFuture.result();
|
auto successful = m_copyFuture.result();
|
||||||
if(!successful)
|
if(!successful)
|
||||||
{
|
{
|
||||||
emitFailed(tr("Instance folder copy failed."));
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
return;
|
emitFailed(tr("Instance folder copy failed."));
|
||||||
}
|
return;
|
||||||
// FIXME: shouldn't this be able to report errors?
|
}
|
||||||
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
|
// FIXME: shouldn't this be able to report errors?
|
||||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
|
||||||
|
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||||
|
|
||||||
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
// FIXME: and this too? errors???
|
||||||
inst->setName(m_instName);
|
m_origInstance->copy(instanceSettings, m_stagingPath);
|
||||||
inst->setIconKey(m_instIcon);
|
|
||||||
emitSucceeded();
|
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
||||||
|
inst->setName(m_instName);
|
||||||
|
inst->setIconKey(m_instIcon);
|
||||||
|
m_target->commitStagedInstance(m_stagingPath, m_stagingPath, m_instName, m_instGroup);
|
||||||
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceCopyTask::copyAborted()
|
void InstanceCopyTask::copyAborted()
|
||||||
{
|
{
|
||||||
emitFailed(tr("Instance folder copy has been aborted."));
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
return;
|
emitFailed(tr("Instance folder copy has been aborted."));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,23 +9,34 @@
|
|||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
#include "InstanceTask.h"
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask
|
|
||||||
|
class BaseInstanceProvider;
|
||||||
|
|
||||||
|
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves);
|
explicit InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvider * target, InstancePtr origInstance, const QString &instName,
|
||||||
|
const QString &instIcon, const QString &instGroup, bool copySaves);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
void copyFinished();
|
void copyFinished();
|
||||||
void copyAborted();
|
void copyAborted();
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
InstancePtr m_origInstance;
|
SettingsObjectPtr m_globalSettings;
|
||||||
QFuture<bool> m_copyFuture;
|
BaseInstanceProvider * m_target = nullptr;
|
||||||
QFutureWatcher<bool> m_copyFutureWatcher;
|
InstancePtr m_origInstance;
|
||||||
std::unique_ptr<IPathMatcher> m_matcher;
|
QString m_instName;
|
||||||
|
QString m_instIcon;
|
||||||
|
QString m_instGroup;
|
||||||
|
QString m_stagingPath;
|
||||||
|
QFuture<bool> m_copyFuture;
|
||||||
|
QFutureWatcher<bool> m_copyFutureWatcher;
|
||||||
|
std::unique_ptr<IPathMatcher> m_matcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,46 @@
|
|||||||
#include "InstanceCreationTask.h"
|
#include "InstanceCreationTask.h"
|
||||||
|
#include "BaseInstanceProvider.h"
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
//FIXME: remove this
|
//FIXME: remove this
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftVersion.h"
|
||||||
#include "minecraft/ComponentList.h"
|
#include "minecraft/onesix/OneSixInstance.h"
|
||||||
|
|
||||||
InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version)
|
InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider* target, BaseVersionPtr version,
|
||||||
|
const QString& instName, const QString& instIcon, const QString& instGroup)
|
||||||
{
|
{
|
||||||
m_version = version;
|
m_globalSettings = settings;
|
||||||
|
m_target = target;
|
||||||
|
m_instName = instName;
|
||||||
|
m_instIcon = instIcon;
|
||||||
|
m_instGroup = instGroup;
|
||||||
|
m_version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceCreationTask::executeTask()
|
void InstanceCreationTask::executeTask()
|
||||||
{
|
{
|
||||||
setStatus(tr("Creating instance from version %1").arg(m_version->name()));
|
setStatus(tr("Creating instance from version %1").arg(m_version->name()));
|
||||||
{
|
auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
|
||||||
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
|
if(!minecraftVersion)
|
||||||
instanceSettings->suspendSave();
|
{
|
||||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
emitFailed(tr("The supplied version is not a Minecraft version."));
|
||||||
instanceSettings->set("InstanceType", "OneSix");
|
return ;
|
||||||
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
|
}
|
||||||
auto components = inst.getComponentList();
|
|
||||||
components->buildingFromScratch();
|
QString stagingPath = m_target->getStagedInstancePath();
|
||||||
components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
|
QDir rootDir(stagingPath);
|
||||||
inst.setName(m_instName);
|
|
||||||
inst.setIconKey(m_instIcon);
|
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(stagingPath, "instance.cfg"));
|
||||||
instanceSettings->resumeSave();
|
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||||
}
|
|
||||||
emitSucceeded();
|
auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
|
||||||
|
instanceSettings->set("InstanceType", "OneSix");
|
||||||
|
InstancePtr inst(new OneSixInstance(m_globalSettings, instanceSettings, stagingPath));
|
||||||
|
inst->setIntendedVersionId(m_version->descriptor());
|
||||||
|
inst->setName(m_instName);
|
||||||
|
inst->setIconKey(m_instIcon);
|
||||||
|
inst->init();
|
||||||
|
m_target->commitStagedInstance(stagingPath, stagingPath, m_instName, m_instGroup);
|
||||||
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,26 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "InstanceTask.h"
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public InstanceTask
|
class BaseInstanceProvider;
|
||||||
|
|
||||||
|
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit InstanceCreationTask(BaseVersionPtr version);
|
explicit InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider * target, BaseVersionPtr version, const QString &instName,
|
||||||
|
const QString &instIcon, const QString &instGroup);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
BaseVersionPtr m_version;
|
SettingsObjectPtr m_globalSettings;
|
||||||
|
BaseInstanceProvider * m_target;
|
||||||
|
BaseVersionPtr m_version;
|
||||||
|
QString m_instName;
|
||||||
|
QString m_instIcon;
|
||||||
|
QString m_instGroup;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,411 +1,164 @@
|
|||||||
|
|
||||||
#include "InstanceImportTask.h"
|
#include "InstanceImportTask.h"
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
|
#include "BaseInstanceProvider.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Env.h"
|
#include "Env.h"
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "NullInstance.h"
|
#include "NullInstance.h"
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
#include "icons/IIconList.h"
|
#include "icons/IIconList.h"
|
||||||
#include "icons/IconUtils.h"
|
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
// FIXME: this does not belong here, it's Minecraft/Flame specific
|
InstanceImportTask::InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, BaseInstanceProvider * target,
|
||||||
#include "minecraft/MinecraftInstance.h"
|
const QString &instName, const QString &instIcon, const QString &instGroup)
|
||||||
#include "minecraft/ComponentList.h"
|
|
||||||
#include "modplatform/flame/FileResolvingTask.h"
|
|
||||||
#include "modplatform/flame/PackManifest.h"
|
|
||||||
#include "Json.h"
|
|
||||||
|
|
||||||
InstanceImportTask::InstanceImportTask(const QUrl sourceUrl)
|
|
||||||
{
|
{
|
||||||
m_sourceUrl = sourceUrl;
|
m_globalSettings = settings;
|
||||||
|
m_sourceUrl = sourceUrl;
|
||||||
|
m_target = target;
|
||||||
|
m_instName = instName;
|
||||||
|
m_instIcon = instIcon;
|
||||||
|
m_instGroup = instGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::executeTask()
|
void InstanceImportTask::executeTask()
|
||||||
{
|
{
|
||||||
InstancePtr newInstance;
|
InstancePtr newInstance;
|
||||||
|
|
||||||
if (m_sourceUrl.isLocalFile())
|
if (m_sourceUrl.isLocalFile())
|
||||||
{
|
{
|
||||||
m_archivePath = m_sourceUrl.toLocalFile();
|
m_archivePath = m_sourceUrl.toLocalFile();
|
||||||
processZipPack();
|
extractAndTweak();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
|
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
|
||||||
m_downloadRequired = true;
|
m_downloadRequired = true;
|
||||||
|
|
||||||
const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path();
|
const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path();
|
||||||
auto entry = ENV.metacache()->resolveEntry("general", path);
|
auto entry = ENV.metacache()->resolveEntry("general", path);
|
||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
m_filesNetJob.reset(new NetJob(tr("Modpack download")));
|
m_filesNetJob.reset(new NetJob(tr("Modpack download")));
|
||||||
m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
|
m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
|
||||||
m_archivePath = entry->getFullPath();
|
m_archivePath = entry->getFullPath();
|
||||||
auto job = m_filesNetJob.get();
|
auto job = m_filesNetJob.get();
|
||||||
connect(job, &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
|
connect(job, &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
|
||||||
connect(job, &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
|
connect(job, &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
|
||||||
connect(job, &NetJob::failed, this, &InstanceImportTask::downloadFailed);
|
connect(job, &NetJob::failed, this, &InstanceImportTask::downloadFailed);
|
||||||
m_filesNetJob->start();
|
m_filesNetJob->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::downloadSucceeded()
|
void InstanceImportTask::downloadSucceeded()
|
||||||
{
|
{
|
||||||
processZipPack();
|
extractAndTweak();
|
||||||
m_filesNetJob.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::downloadFailed(QString reason)
|
void InstanceImportTask::downloadFailed(QString reason)
|
||||||
{
|
{
|
||||||
emitFailed(reason);
|
emitFailed(reason);
|
||||||
m_filesNetJob.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::downloadProgressChanged(qint64 current, qint64 total)
|
void InstanceImportTask::downloadProgressChanged(qint64 current, qint64 total)
|
||||||
{
|
{
|
||||||
setProgress(current / 2, total);
|
setProgress(current / 2, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::processZipPack()
|
static QFileInfo findRecursive(const QString &dir, const QString &name)
|
||||||
{
|
{
|
||||||
setStatus(tr("Extracting modpack"));
|
for (const auto info : QDir(dir).entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files, QDir::DirsLast))
|
||||||
QDir extractDir(m_stagingPath);
|
{
|
||||||
qDebug() << "Attempting to create instance from" << m_archivePath;
|
if (info.isFile() && info.fileName() == name)
|
||||||
|
{
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
else if (info.isDir())
|
||||||
|
{
|
||||||
|
const QFileInfo res = findRecursive(info.absoluteFilePath(), name);
|
||||||
|
if (res.isFile() && res.exists())
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QFileInfo();
|
||||||
|
}
|
||||||
|
|
||||||
// open the zip and find relevant files in it
|
void InstanceImportTask::extractAndTweak()
|
||||||
m_packZip.reset(new QuaZip(m_archivePath));
|
{
|
||||||
if (!m_packZip->open(QuaZip::mdUnzip))
|
setStatus(tr("Extracting modpack"));
|
||||||
{
|
m_stagingPath = m_target->getStagedInstancePath();
|
||||||
emitFailed(tr("Unable to open supplied modpack zip file."));
|
QDir extractDir(m_stagingPath);
|
||||||
return;
|
qDebug() << "Attempting to create instance from" << m_archivePath;
|
||||||
}
|
|
||||||
|
|
||||||
QStringList blacklist = {"instance.cfg", "manifest.json"};
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath());
|
||||||
QString mmcFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg");
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
|
||||||
QString flameFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json");
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
|
||||||
QString root;
|
m_extractFutureWatcher.setFuture(m_extractFuture);
|
||||||
if(!mmcFound.isNull())
|
|
||||||
{
|
|
||||||
// process as MultiMC instance/pack
|
|
||||||
qDebug() << "MultiMC:" << mmcFound;
|
|
||||||
root = mmcFound;
|
|
||||||
m_modpackType = ModpackType::MultiMC;
|
|
||||||
}
|
|
||||||
else if(!flameFound.isNull())
|
|
||||||
{
|
|
||||||
// process as Flame pack
|
|
||||||
qDebug() << "Flame:" << flameFound;
|
|
||||||
root = flameFound;
|
|
||||||
m_modpackType = ModpackType::Flame;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m_modpackType == ModpackType::Unknown)
|
|
||||||
{
|
|
||||||
emitFailed(tr("Archive does not contain a recognized modpack type."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure we extract just the pack
|
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
|
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
|
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
|
|
||||||
m_extractFutureWatcher.setFuture(m_extractFuture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::extractFinished()
|
void InstanceImportTask::extractFinished()
|
||||||
{
|
{
|
||||||
m_packZip.reset();
|
if (m_extractFuture.result().isEmpty())
|
||||||
if (m_extractFuture.result().isEmpty())
|
{
|
||||||
{
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
emitFailed(tr("Failed to extract modpack"));
|
emitFailed(tr("Failed to extract modpack"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QDir extractDir(m_stagingPath);
|
QDir extractDir(m_stagingPath);
|
||||||
|
const QFileInfo instanceCfgFile = findRecursive(extractDir.absolutePath(), "instance.cfg");
|
||||||
|
if (!instanceCfgFile.isFile() || !instanceCfgFile.exists())
|
||||||
|
{
|
||||||
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
|
emitFailed(tr("Archive does not contain instance.cfg"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Fixing permissions for extracted pack files...";
|
// FIXME: copy from FolderInstanceProvider!!! FIX IT!!!
|
||||||
QDirIterator it(extractDir, QDirIterator::Subdirectories);
|
auto instanceSettings = std::make_shared<INISettingsObject>(instanceCfgFile.absoluteFilePath());
|
||||||
while (it.hasNext())
|
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||||
{
|
|
||||||
auto filepath = it.next();
|
|
||||||
QFileInfo file(filepath);
|
|
||||||
auto permissions = QFile::permissions(filepath);
|
|
||||||
auto origPermissions = permissions;
|
|
||||||
if(file.isDir())
|
|
||||||
{
|
|
||||||
// Folder +rwx for current user
|
|
||||||
permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// File +rw for current user
|
|
||||||
permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser;
|
|
||||||
}
|
|
||||||
if(origPermissions != permissions)
|
|
||||||
{
|
|
||||||
if(!QFile::setPermissions(filepath, permissions))
|
|
||||||
{
|
|
||||||
logWarning(tr("Could not fix permissions for %1").arg(filepath));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "Fixed" << filepath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(m_modpackType)
|
QString actualDir = instanceCfgFile.absolutePath();
|
||||||
{
|
NullInstance instance(m_globalSettings, instanceSettings, actualDir);
|
||||||
case ModpackType::Flame:
|
|
||||||
processFlame();
|
// reset time played on import... because packs.
|
||||||
return;
|
instance.resetTimePlayed();
|
||||||
case ModpackType::MultiMC:
|
|
||||||
processMultiMC();
|
// set a new nice name
|
||||||
return;
|
instance.setName(m_instName);
|
||||||
case ModpackType::Unknown:
|
|
||||||
emitFailed(tr("Archive does not contain a recognized modpack type."));
|
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
||||||
return;
|
if (m_instIcon != "default")
|
||||||
}
|
{
|
||||||
|
instance.setIconKey(m_instIcon);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_instIcon = instance.iconKey();
|
||||||
|
auto importIconPath = FS::PathCombine(instance.instanceRoot(), m_instIcon + ".png");
|
||||||
|
if (QFile::exists(importIconPath))
|
||||||
|
{
|
||||||
|
// import icon
|
||||||
|
auto iconList = ENV.icons();
|
||||||
|
if (iconList->iconFileExists(m_instIcon))
|
||||||
|
{
|
||||||
|
iconList->deleteIcon(m_instIcon);
|
||||||
|
}
|
||||||
|
iconList->installIcons({importIconPath});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!m_target->commitStagedInstance(m_stagingPath, actualDir, m_instName, m_instGroup))
|
||||||
|
{
|
||||||
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
|
emitFailed(tr("Unable to commit instance"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceImportTask::extractAborted()
|
void InstanceImportTask::extractAborted()
|
||||||
{
|
{
|
||||||
emitFailed(tr("Instance import has been aborted."));
|
m_target->destroyStagingPath(m_stagingPath);
|
||||||
return;
|
emitFailed(tr("Instance import has been aborted."));
|
||||||
}
|
return;
|
||||||
|
|
||||||
void InstanceImportTask::processFlame()
|
|
||||||
{
|
|
||||||
const static QMap<QString,QString> forgemap = {
|
|
||||||
{"1.2.5", "3.4.9.171"},
|
|
||||||
{"1.4.2", "6.0.1.355"},
|
|
||||||
{"1.4.7", "6.6.2.534"},
|
|
||||||
{"1.5.2", "7.8.1.737"}
|
|
||||||
};
|
|
||||||
Flame::Manifest pack;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
QString configPath = FS::PathCombine(m_stagingPath, "manifest.json");
|
|
||||||
Flame::loadManifest(pack, configPath);
|
|
||||||
QFile::remove(configPath);
|
|
||||||
}
|
|
||||||
catch (const JSONValidationError &e)
|
|
||||||
{
|
|
||||||
emitFailed(tr("Could not understand pack manifest:\n") + e.cause());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!pack.overrides.isEmpty())
|
|
||||||
{
|
|
||||||
QString overridePath = FS::PathCombine(m_stagingPath, pack.overrides);
|
|
||||||
if (QFile::exists(overridePath))
|
|
||||||
{
|
|
||||||
QString mcPath = FS::PathCombine(m_stagingPath, "minecraft");
|
|
||||||
if (!QFile::rename(overridePath, mcPath))
|
|
||||||
{
|
|
||||||
emitFailed(tr("Could not rename the overrides folder:\n") + pack.overrides);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logWarning(tr("The specified overrides folder (%1) is missing. Maybe the modpack was already used before?").arg(pack.overrides));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString forgeVersion;
|
|
||||||
for(auto &loader: pack.minecraft.modLoaders)
|
|
||||||
{
|
|
||||||
auto id = loader.id;
|
|
||||||
if(id.startsWith("forge-"))
|
|
||||||
{
|
|
||||||
id.remove("forge-");
|
|
||||||
forgeVersion = id;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
logWarning(tr("Unknown mod loader in manifest: %1").arg(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
|
||||||
auto instanceSettings = std::make_shared<INISettingsObject>(configPath);
|
|
||||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
|
||||||
instanceSettings->set("InstanceType", "OneSix");
|
|
||||||
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
|
||||||
auto mcVersion = pack.minecraft.version;
|
|
||||||
// Hack to correct some 'special sauce'...
|
|
||||||
if(mcVersion.endsWith('.'))
|
|
||||||
{
|
|
||||||
mcVersion.remove(QRegExp("[.]+$"));
|
|
||||||
logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
|
|
||||||
}
|
|
||||||
auto components = instance.getComponentList();
|
|
||||||
components->buildingFromScratch();
|
|
||||||
components->setComponentVersion("net.minecraft", mcVersion, true);
|
|
||||||
if(!forgeVersion.isEmpty())
|
|
||||||
{
|
|
||||||
// FIXME: dirty, nasty, hack. Proper solution requires dependency resolution and knowledge of the metadata.
|
|
||||||
if(forgeVersion == "recommended")
|
|
||||||
{
|
|
||||||
if(forgemap.contains(mcVersion))
|
|
||||||
{
|
|
||||||
forgeVersion = forgemap[mcVersion];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logWarning(tr("Could not map recommended forge version for Minecraft %1").arg(mcVersion));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
components->setComponentVersion("net.minecraftforge", forgeVersion);
|
|
||||||
}
|
|
||||||
if (m_instIcon != "default")
|
|
||||||
{
|
|
||||||
instance.setIconKey(m_instIcon);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(pack.name.contains("Direwolf20"))
|
|
||||||
{
|
|
||||||
instance.setIconKey("steve");
|
|
||||||
}
|
|
||||||
else if(pack.name.contains("FTB") || pack.name.contains("Feed The Beast"))
|
|
||||||
{
|
|
||||||
instance.setIconKey("ftb_logo");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// default to something other than the MultiMC default to distinguish these
|
|
||||||
instance.setIconKey("flame");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QString jarmodsPath = FS::PathCombine(m_stagingPath, "minecraft", "jarmods");
|
|
||||||
QFileInfo jarmodsInfo(jarmodsPath);
|
|
||||||
if(jarmodsInfo.isDir())
|
|
||||||
{
|
|
||||||
// install all the jar mods
|
|
||||||
qDebug() << "Found jarmods:";
|
|
||||||
QDir jarmodsDir(jarmodsPath);
|
|
||||||
QStringList jarMods;
|
|
||||||
for (auto info: jarmodsDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files))
|
|
||||||
{
|
|
||||||
qDebug() << info.fileName();
|
|
||||||
jarMods.push_back(info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
auto profile = instance.getComponentList();
|
|
||||||
profile->installJarMods(jarMods);
|
|
||||||
// nuke the original files
|
|
||||||
FS::deletePath(jarmodsPath);
|
|
||||||
}
|
|
||||||
instance.setName(m_instName);
|
|
||||||
m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
|
|
||||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
|
|
||||||
{
|
|
||||||
auto results = m_modIdResolver->getResults();
|
|
||||||
m_filesNetJob.reset(new NetJob(tr("Mod download")));
|
|
||||||
for(auto result: results.files)
|
|
||||||
{
|
|
||||||
QString filename = result.fileName;
|
|
||||||
if(!result.required)
|
|
||||||
{
|
|
||||||
filename += ".disabled";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto relpath = FS::PathCombine("minecraft", result.targetFolder, filename);
|
|
||||||
auto path = FS::PathCombine(m_stagingPath , relpath);
|
|
||||||
|
|
||||||
switch(result.type)
|
|
||||||
{
|
|
||||||
case Flame::File::Type::Folder:
|
|
||||||
{
|
|
||||||
logWarning(tr("This 'Folder' may need extracting: %1").arg(relpath));
|
|
||||||
// fall-through intentional, we treat these as plain old mods and dump them wherever.
|
|
||||||
}
|
|
||||||
case Flame::File::Type::SingleFile:
|
|
||||||
case Flame::File::Type::Mod:
|
|
||||||
{
|
|
||||||
qDebug() << "Will download" << result.url << "to" << path;
|
|
||||||
auto dl = Net::Download::makeFile(result.url, path);
|
|
||||||
m_filesNetJob->addNetAction(dl);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Flame::File::Type::Modpack:
|
|
||||||
logWarning(tr("Nesting modpacks in modpacks is not implemented, nothing was downloaded: %1").arg(relpath));
|
|
||||||
break;
|
|
||||||
case Flame::File::Type::Cmod2:
|
|
||||||
case Flame::File::Type::Ctoc:
|
|
||||||
case Flame::File::Type::Unknown:
|
|
||||||
logWarning(tr("Unrecognized/unhandled PackageType for: %1").arg(relpath));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_modIdResolver.reset();
|
|
||||||
connect(m_filesNetJob.get(), &NetJob::succeeded, this, [&]()
|
|
||||||
{
|
|
||||||
m_filesNetJob.reset();
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
connect(m_filesNetJob.get(), &NetJob::failed, [&](QString reason)
|
|
||||||
{
|
|
||||||
m_filesNetJob.reset();
|
|
||||||
emitFailed(reason);
|
|
||||||
});
|
|
||||||
connect(m_filesNetJob.get(), &NetJob::progress, [&](qint64 current, qint64 total)
|
|
||||||
{
|
|
||||||
setProgress(current, total);
|
|
||||||
});
|
|
||||||
setStatus(tr("Downloading mods..."));
|
|
||||||
m_filesNetJob->start();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason)
|
|
||||||
{
|
|
||||||
m_modIdResolver.reset();
|
|
||||||
emitFailed(tr("Unable to resolve mod IDs:\n") + reason);
|
|
||||||
});
|
|
||||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::progress, [&](qint64 current, qint64 total)
|
|
||||||
{
|
|
||||||
setProgress(current, total);
|
|
||||||
});
|
|
||||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status)
|
|
||||||
{
|
|
||||||
setStatus(status);
|
|
||||||
});
|
|
||||||
m_modIdResolver->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstanceImportTask::processMultiMC()
|
|
||||||
{
|
|
||||||
// FIXME: copy from FolderInstanceProvider!!! FIX IT!!!
|
|
||||||
QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
|
|
||||||
auto instanceSettings = std::make_shared<INISettingsObject>(configPath);
|
|
||||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
|
||||||
|
|
||||||
NullInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
|
||||||
|
|
||||||
// reset time played on import... because packs.
|
|
||||||
instance.resetTimePlayed();
|
|
||||||
|
|
||||||
// set a new nice name
|
|
||||||
instance.setName(m_instName);
|
|
||||||
|
|
||||||
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
|
||||||
if (m_instIcon != "default")
|
|
||||||
{
|
|
||||||
instance.setIconKey(m_instIcon);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_instIcon = instance.iconKey();
|
|
||||||
|
|
||||||
auto importIconPath = IconUtils::findBestIconIn(instance.instanceRoot(), m_instIcon);
|
|
||||||
if (!importIconPath.isNull() && QFile::exists(importIconPath))
|
|
||||||
{
|
|
||||||
// import icon
|
|
||||||
auto iconList = ENV.icons();
|
|
||||||
if (iconList->iconFileExists(m_instIcon))
|
|
||||||
{
|
|
||||||
iconList->deleteIcon(m_instIcon);
|
|
||||||
}
|
|
||||||
iconList->installIcons({importIconPath});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "InstanceTask.h"
|
#include "tasks/Task.h"
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "QObjectPtr.h"
|
|
||||||
|
|
||||||
class QuaZip;
|
class BaseInstanceProvider;
|
||||||
namespace Flame
|
|
||||||
{
|
|
||||||
class FileResolvingTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public InstanceTask
|
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit InstanceImportTask(const QUrl sourceUrl);
|
explicit InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, BaseInstanceProvider * target, const QString &instName,
|
||||||
|
const QString &instIcon, const QString &instGroup);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processZipPack();
|
void extractAndTweak();
|
||||||
void processMultiMC();
|
|
||||||
void processFlame();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void downloadSucceeded();
|
void downloadSucceeded();
|
||||||
void downloadFailed(QString reason);
|
void downloadFailed(QString reason);
|
||||||
void downloadProgressChanged(qint64 current, qint64 total);
|
void downloadProgressChanged(qint64 current, qint64 total);
|
||||||
void extractFinished();
|
void extractFinished();
|
||||||
void extractAborted();
|
void extractAborted();
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
NetJobPtr m_filesNetJob;
|
SettingsObjectPtr m_globalSettings;
|
||||||
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
|
NetJobPtr m_filesNetJob;
|
||||||
QUrl m_sourceUrl;
|
QUrl m_sourceUrl;
|
||||||
QString m_archivePath;
|
BaseInstanceProvider * m_target;
|
||||||
bool m_downloadRequired = false;
|
QString m_archivePath;
|
||||||
std::unique_ptr<QuaZip> m_packZip;
|
bool m_downloadRequired = false;
|
||||||
QFuture<QStringList> m_extractFuture;
|
QString m_instName;
|
||||||
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
QString m_instIcon;
|
||||||
enum class ModpackType{
|
QString m_instGroup;
|
||||||
Unknown,
|
QString m_stagingPath;
|
||||||
MultiMC,
|
QFuture<QStringList> m_extractFuture;
|
||||||
Flame
|
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
||||||
} m_modpackType = ModpackType::Unknown;
|
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -21,146 +21,88 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
|
#include "BaseInstanceProvider.h"
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
#include "QObjectPtr.h"
|
#include "QObjectPtr.h"
|
||||||
|
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
class InstanceTask;
|
class BaseInstance;
|
||||||
using InstanceId = QString;
|
class QDir;
|
||||||
using GroupId = QString;
|
|
||||||
using InstanceLocator = std::pair<InstancePtr, int>;
|
|
||||||
|
|
||||||
enum class InstCreateError
|
|
||||||
{
|
|
||||||
NoCreateError = 0,
|
|
||||||
NoSuchVersion,
|
|
||||||
UnknownCreateError,
|
|
||||||
InstExists,
|
|
||||||
CantCreateDir
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class GroupsState
|
|
||||||
{
|
|
||||||
NotLoaded,
|
|
||||||
Steady,
|
|
||||||
Dirty
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
|
class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit InstanceList(SettingsObjectPtr settings, const QString & instDir, QObject *parent = 0);
|
explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0);
|
||||||
virtual ~InstanceList();
|
virtual ~InstanceList();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
|
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
bool setData(const QModelIndex & index, const QVariant & value, int role) override;
|
enum AdditionalRoles
|
||||||
|
{
|
||||||
|
GroupRole = Qt::UserRole,
|
||||||
|
InstancePointerRole = 0x34B1CB48, ///< Return pointer to real instance
|
||||||
|
InstanceIDRole = 0x34B1CB49 ///< Return id if the instance
|
||||||
|
};
|
||||||
|
/*!
|
||||||
|
* \brief Error codes returned by functions in the InstanceList class.
|
||||||
|
* NoError Indicates that no error occurred.
|
||||||
|
* UnknownError indicates that an unspecified error occurred.
|
||||||
|
*/
|
||||||
|
enum InstListError
|
||||||
|
{
|
||||||
|
NoError = 0,
|
||||||
|
UnknownError
|
||||||
|
};
|
||||||
|
|
||||||
enum AdditionalRoles
|
InstancePtr at(int i) const
|
||||||
{
|
{
|
||||||
GroupRole = Qt::UserRole,
|
return m_instances.at(i);
|
||||||
InstancePointerRole = 0x34B1CB48, ///< Return pointer to real instance
|
}
|
||||||
InstanceIDRole = 0x34B1CB49 ///< Return id if the instance
|
|
||||||
};
|
|
||||||
/*!
|
|
||||||
* \brief Error codes returned by functions in the InstanceList class.
|
|
||||||
* NoError Indicates that no error occurred.
|
|
||||||
* UnknownError indicates that an unspecified error occurred.
|
|
||||||
*/
|
|
||||||
enum InstListError
|
|
||||||
{
|
|
||||||
NoError = 0,
|
|
||||||
UnknownError
|
|
||||||
};
|
|
||||||
|
|
||||||
InstancePtr at(int i) const
|
int count() const
|
||||||
{
|
{
|
||||||
return m_instances.at(i);
|
return m_instances.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int count() const
|
InstListError loadList(bool complete = false);
|
||||||
{
|
|
||||||
return m_instances.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
InstListError loadList();
|
/// Add an instance provider. Takes ownership of it. Should only be done before the first load.
|
||||||
void saveNow();
|
void addInstanceProvider(BaseInstanceProvider * provider);
|
||||||
|
|
||||||
|
InstancePtr getInstanceById(QString id) const;
|
||||||
|
QModelIndex getInstanceIndexById(const QString &id) const;
|
||||||
|
QStringList getGroups();
|
||||||
|
|
||||||
InstancePtr getInstanceById(QString id) const;
|
void deleteGroup(const QString & name);
|
||||||
QModelIndex getInstanceIndexById(const QString &id) const;
|
|
||||||
QStringList getGroups();
|
|
||||||
GroupId getInstanceGroup(const InstanceId & id) const;
|
|
||||||
void setInstanceGroup(const InstanceId & id, const GroupId& name);
|
|
||||||
|
|
||||||
void deleteGroup(const GroupId & name);
|
|
||||||
void deleteInstance(const InstanceId & id);
|
|
||||||
|
|
||||||
// Wrap an instance creation task in some more task machinery and make it ready to be used
|
|
||||||
Task * wrapInstanceTask(InstanceTask * task);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new empty staging area for instance creation and @return a path/key top commit it later.
|
|
||||||
* Used by instance manipulation tasks.
|
|
||||||
*/
|
|
||||||
QString getStagedInstancePath();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit the staging area given by @keyPath to the provider - used when creation succeeds.
|
|
||||||
* Used by instance manipulation tasks.
|
|
||||||
*/
|
|
||||||
bool commitStagedInstance(const QString & keyPath, const QString& instanceName, const QString & groupName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy a previously created staging area given by @keyPath - used when creation fails.
|
|
||||||
* Used by instance manipulation tasks.
|
|
||||||
*/
|
|
||||||
bool destroyStagingPath(const QString & keyPath);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataIsInvalid();
|
void dataIsInvalid();
|
||||||
void instancesChanged();
|
|
||||||
void instanceSelectRequest(QString instanceId);
|
|
||||||
void groupsChanged(QSet<QString> groups);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void on_InstFolderChanged(const Setting &setting, QVariant value);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void propertiesChanged(BaseInstance *inst);
|
void propertiesChanged(BaseInstance *inst);
|
||||||
void providerUpdated();
|
void groupsPublished(QSet<QString>);
|
||||||
void instanceDirContentsChanged(const QString &path);
|
void providerUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int getInstIndex(BaseInstance *inst) const;
|
int getInstIndex(BaseInstance *inst) const;
|
||||||
void suspendWatch();
|
void suspendWatch();
|
||||||
void resumeWatch();
|
void resumeWatch();
|
||||||
void add(const QList<InstancePtr> &list);
|
void add(const QList<InstancePtr> &list);
|
||||||
void loadGroupList();
|
|
||||||
void saveGroupList();
|
|
||||||
QList<InstanceId> discoverInstances();
|
|
||||||
InstancePtr loadInstance(const InstanceId& id);
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
int m_watchLevel = 0;
|
int m_watchLevel = 0;
|
||||||
bool m_dirty = false;
|
QSet<BaseInstanceProvider *> m_updatedProviders;
|
||||||
QList<InstancePtr> m_instances;
|
QString m_instDir;
|
||||||
QSet<QString> m_groups;
|
QList<InstancePtr> m_instances;
|
||||||
|
QSet<QString> m_groups;
|
||||||
SettingsObjectPtr m_globalSettings;
|
SettingsObjectPtr m_globalSettings;
|
||||||
QString m_instDir;
|
QVector<shared_qobject_ptr<BaseInstanceProvider>> m_providers;
|
||||||
QFileSystemWatcher * m_watcher;
|
|
||||||
QMap<InstanceId, GroupId> m_groupMap;
|
|
||||||
QSet<InstanceId> instanceSet;
|
|
||||||
bool m_groupsLoaded = false;
|
|
||||||
bool m_instancesProbed = false;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
#include "InstanceTask.h"
|
|
||||||
|
|
||||||
InstanceTask::InstanceTask()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceTask::~InstanceTask()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
#include "multimc_logic_export.h"
|
|
||||||
#include "settings/SettingsObject.h"
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT InstanceTask : public Task
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit InstanceTask();
|
|
||||||
virtual ~InstanceTask();
|
|
||||||
|
|
||||||
void setParentSettings(SettingsObjectPtr settings)
|
|
||||||
{
|
|
||||||
m_globalSettings = settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setStagingPath(const QString &stagingPath)
|
|
||||||
{
|
|
||||||
m_stagingPath = stagingPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_instName = name;
|
|
||||||
}
|
|
||||||
QString name() const
|
|
||||||
{
|
|
||||||
return m_instName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
m_instIcon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setGroup(const QString &group)
|
|
||||||
{
|
|
||||||
m_instGroup = group;
|
|
||||||
}
|
|
||||||
QString group() const
|
|
||||||
{
|
|
||||||
return m_instGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected: /* data */
|
|
||||||
SettingsObjectPtr m_globalSettings;
|
|
||||||
QString m_instName;
|
|
||||||
QString m_instIcon;
|
|
||||||
QString m_instGroup;
|
|
||||||
QString m_stagingPath;
|
|
||||||
};
|
|
||||||
@@ -11,262 +11,262 @@ namespace Json
|
|||||||
{
|
{
|
||||||
void write(const QJsonDocument &doc, const QString &filename)
|
void write(const QJsonDocument &doc, const QString &filename)
|
||||||
{
|
{
|
||||||
FS::write(filename, doc.toJson());
|
FS::write(filename, doc.toJson());
|
||||||
}
|
}
|
||||||
void write(const QJsonObject &object, const QString &filename)
|
void write(const QJsonObject &object, const QString &filename)
|
||||||
{
|
{
|
||||||
write(QJsonDocument(object), filename);
|
write(QJsonDocument(object), filename);
|
||||||
}
|
}
|
||||||
void write(const QJsonArray &array, const QString &filename)
|
void write(const QJsonArray &array, const QString &filename)
|
||||||
{
|
{
|
||||||
write(QJsonDocument(array), filename);
|
write(QJsonDocument(array), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray toBinary(const QJsonObject &obj)
|
QByteArray toBinary(const QJsonObject &obj)
|
||||||
{
|
{
|
||||||
return QJsonDocument(obj).toBinaryData();
|
return QJsonDocument(obj).toBinaryData();
|
||||||
}
|
}
|
||||||
QByteArray toBinary(const QJsonArray &array)
|
QByteArray toBinary(const QJsonArray &array)
|
||||||
{
|
{
|
||||||
return QJsonDocument(array).toBinaryData();
|
return QJsonDocument(array).toBinaryData();
|
||||||
}
|
}
|
||||||
QByteArray toText(const QJsonObject &obj)
|
QByteArray toText(const QJsonObject &obj)
|
||||||
{
|
{
|
||||||
return QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
return QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||||
}
|
}
|
||||||
QByteArray toText(const QJsonArray &array)
|
QByteArray toText(const QJsonArray &array)
|
||||||
{
|
{
|
||||||
return QJsonDocument(array).toJson(QJsonDocument::Compact);
|
return QJsonDocument(array).toJson(QJsonDocument::Compact);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isBinaryJson(const QByteArray &data)
|
static bool isBinaryJson(const QByteArray &data)
|
||||||
{
|
{
|
||||||
decltype(QJsonDocument::BinaryFormatTag) tag = QJsonDocument::BinaryFormatTag;
|
decltype(QJsonDocument::BinaryFormatTag) tag = QJsonDocument::BinaryFormatTag;
|
||||||
return memcmp(data.constData(), &tag, sizeof(QJsonDocument::BinaryFormatTag)) == 0;
|
return memcmp(data.constData(), &tag, sizeof(QJsonDocument::BinaryFormatTag)) == 0;
|
||||||
}
|
}
|
||||||
QJsonDocument requireDocument(const QByteArray &data, const QString &what)
|
QJsonDocument requireDocument(const QByteArray &data, const QString &what)
|
||||||
{
|
{
|
||||||
if (isBinaryJson(data))
|
if (isBinaryJson(data))
|
||||||
{
|
{
|
||||||
QJsonDocument doc = QJsonDocument::fromBinaryData(data);
|
QJsonDocument doc = QJsonDocument::fromBinaryData(data);
|
||||||
if (doc.isNull())
|
if (doc.isNull())
|
||||||
{
|
{
|
||||||
throw JsonException(what + ": Invalid JSON (binary JSON detected)");
|
throw JsonException(what + ": Invalid JSON (binary JSON detected)");
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument doc = QJsonDocument::fromJson(data, &error);
|
||||||
if (error.error != QJsonParseError::NoError)
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
throw JsonException(what + ": Error parsing JSON: " + error.errorString());
|
throw JsonException(what + ": Error parsing JSON: " + error.errorString());
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QJsonDocument requireDocument(const QString &filename, const QString &what)
|
QJsonDocument requireDocument(const QString &filename, const QString &what)
|
||||||
{
|
{
|
||||||
return requireDocument(FS::read(filename), what);
|
return requireDocument(FS::read(filename), what);
|
||||||
}
|
}
|
||||||
QJsonObject requireObject(const QJsonDocument &doc, const QString &what)
|
QJsonObject requireObject(const QJsonDocument &doc, const QString &what)
|
||||||
{
|
{
|
||||||
if (!doc.isObject())
|
if (!doc.isObject())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not an object");
|
throw JsonException(what + " is not an object");
|
||||||
}
|
}
|
||||||
return doc.object();
|
return doc.object();
|
||||||
}
|
}
|
||||||
QJsonArray requireArray(const QJsonDocument &doc, const QString &what)
|
QJsonArray requireArray(const QJsonDocument &doc, const QString &what)
|
||||||
{
|
{
|
||||||
if (!doc.isArray())
|
if (!doc.isArray())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not an array");
|
throw JsonException(what + " is not an array");
|
||||||
}
|
}
|
||||||
return doc.array();
|
return doc.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeString(QJsonObject &to, const QString &key, const QString &value)
|
void writeString(QJsonObject &to, const QString &key, const QString &value)
|
||||||
{
|
{
|
||||||
if (!value.isEmpty())
|
if (!value.isEmpty())
|
||||||
{
|
{
|
||||||
to.insert(key, value);
|
to.insert(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeStringList(QJsonObject &to, const QString &key, const QStringList &values)
|
void writeStringList(QJsonObject &to, const QString &key, const QStringList &values)
|
||||||
{
|
{
|
||||||
if (!values.isEmpty())
|
if (!values.isEmpty())
|
||||||
{
|
{
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
for(auto value: values)
|
for(auto value: values)
|
||||||
{
|
{
|
||||||
array.append(value);
|
array.append(value);
|
||||||
}
|
}
|
||||||
to.insert(key, array);
|
to.insert(key, array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QUrl>(const QUrl &url)
|
QJsonValue toJson<QUrl>(const QUrl &url)
|
||||||
{
|
{
|
||||||
return QJsonValue(url.toString(QUrl::FullyEncoded));
|
return QJsonValue(url.toString(QUrl::FullyEncoded));
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QByteArray>(const QByteArray &data)
|
QJsonValue toJson<QByteArray>(const QByteArray &data)
|
||||||
{
|
{
|
||||||
return QJsonValue(QString::fromLatin1(data.toHex()));
|
return QJsonValue(QString::fromLatin1(data.toHex()));
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QDateTime>(const QDateTime &datetime)
|
QJsonValue toJson<QDateTime>(const QDateTime &datetime)
|
||||||
{
|
{
|
||||||
return QJsonValue(datetime.toString(Qt::ISODate));
|
return QJsonValue(datetime.toString(Qt::ISODate));
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QDir>(const QDir &dir)
|
QJsonValue toJson<QDir>(const QDir &dir)
|
||||||
{
|
{
|
||||||
return QDir::current().relativeFilePath(dir.absolutePath());
|
return QDir::current().relativeFilePath(dir.absolutePath());
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QUuid>(const QUuid &uuid)
|
QJsonValue toJson<QUuid>(const QUuid &uuid)
|
||||||
{
|
{
|
||||||
return uuid.toString();
|
return uuid.toString();
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QVariant>(const QVariant &variant)
|
QJsonValue toJson<QVariant>(const QVariant &variant)
|
||||||
{
|
{
|
||||||
return QJsonValue::fromVariant(variant);
|
return QJsonValue::fromVariant(variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<> QByteArray requireIsType<QByteArray>(const QJsonValue &value, const QString &what)
|
template<> QByteArray requireIsType<QByteArray>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const QString string = ensureIsType<QString>(value, what);
|
const QString string = ensureIsType<QString>(value, what);
|
||||||
// ensure that the string can be safely cast to Latin1
|
// ensure that the string can be safely cast to Latin1
|
||||||
if (string != QString::fromLatin1(string.toLatin1()))
|
if (string != QString::fromLatin1(string.toLatin1()))
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not encodable as Latin1");
|
throw JsonException(what + " is not encodable as Latin1");
|
||||||
}
|
}
|
||||||
return QByteArray::fromHex(string.toLatin1());
|
return QByteArray::fromHex(string.toLatin1());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QJsonArray requireIsType<QJsonArray>(const QJsonValue &value, const QString &what)
|
template<> QJsonArray requireIsType<QJsonArray>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (!value.isArray())
|
if (!value.isArray())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not an array");
|
throw JsonException(what + " is not an array");
|
||||||
}
|
}
|
||||||
return value.toArray();
|
return value.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<> QString requireIsType<QString>(const QJsonValue &value, const QString &what)
|
template<> QString requireIsType<QString>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (!value.isString())
|
if (!value.isString())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a string");
|
throw JsonException(what + " is not a string");
|
||||||
}
|
}
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> bool requireIsType<bool>(const QJsonValue &value, const QString &what)
|
template<> bool requireIsType<bool>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (!value.isBool())
|
if (!value.isBool())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a bool");
|
throw JsonException(what + " is not a bool");
|
||||||
}
|
}
|
||||||
return value.toBool();
|
return value.toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> double requireIsType<double>(const QJsonValue &value, const QString &what)
|
template<> double requireIsType<double>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (!value.isDouble())
|
if (!value.isDouble())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a double");
|
throw JsonException(what + " is not a double");
|
||||||
}
|
}
|
||||||
return value.toDouble();
|
return value.toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> int requireIsType<int>(const QJsonValue &value, const QString &what)
|
template<> int requireIsType<int>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const double doubl = requireIsType<double>(value, what);
|
const double doubl = requireIsType<double>(value, what);
|
||||||
if (fmod(doubl, 1) != 0)
|
if (fmod(doubl, 1) != 0)
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not an integer");
|
throw JsonException(what + " is not an integer");
|
||||||
}
|
}
|
||||||
return int(doubl);
|
return int(doubl);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QDateTime requireIsType<QDateTime>(const QJsonValue &value, const QString &what)
|
template<> QDateTime requireIsType<QDateTime>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const QString string = requireIsType<QString>(value, what);
|
const QString string = requireIsType<QString>(value, what);
|
||||||
const QDateTime datetime = QDateTime::fromString(string, Qt::ISODate);
|
const QDateTime datetime = QDateTime::fromString(string, Qt::ISODate);
|
||||||
if (!datetime.isValid())
|
if (!datetime.isValid())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a ISO formatted date/time value");
|
throw JsonException(what + " is not a ISO formatted date/time value");
|
||||||
}
|
}
|
||||||
return datetime;
|
return datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QUrl requireIsType<QUrl>(const QJsonValue &value, const QString &what)
|
template<> QUrl requireIsType<QUrl>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const QString string = ensureIsType<QString>(value, what);
|
const QString string = ensureIsType<QString>(value, what);
|
||||||
if (string.isEmpty())
|
if (string.isEmpty())
|
||||||
{
|
{
|
||||||
return QUrl();
|
return QUrl();
|
||||||
}
|
}
|
||||||
const QUrl url = QUrl(string, QUrl::StrictMode);
|
const QUrl url = QUrl(string, QUrl::StrictMode);
|
||||||
if (!url.isValid())
|
if (!url.isValid())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a correctly formatted URL");
|
throw JsonException(what + " is not a correctly formatted URL");
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QDir requireIsType<QDir>(const QJsonValue &value, const QString &what)
|
template<> QDir requireIsType<QDir>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const QString string = requireIsType<QString>(value, what);
|
const QString string = requireIsType<QString>(value, what);
|
||||||
// FIXME: does not handle invalid characters!
|
// FIXME: does not handle invalid characters!
|
||||||
return QDir::current().absoluteFilePath(string);
|
return QDir::current().absoluteFilePath(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QUuid requireIsType<QUuid>(const QJsonValue &value, const QString &what)
|
template<> QUuid requireIsType<QUuid>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
const QString string = requireIsType<QString>(value, what);
|
const QString string = requireIsType<QString>(value, what);
|
||||||
const QUuid uuid = QUuid(string);
|
const QUuid uuid = QUuid(string);
|
||||||
if (uuid.toString() != string) // converts back => valid
|
if (uuid.toString() != string) // converts back => valid
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not a valid UUID");
|
throw JsonException(what + " is not a valid UUID");
|
||||||
}
|
}
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QJsonObject requireIsType<QJsonObject>(const QJsonValue &value, const QString &what)
|
template<> QJsonObject requireIsType<QJsonObject>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (!value.isObject())
|
if (!value.isObject())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is not an object");
|
throw JsonException(what + " is not an object");
|
||||||
}
|
}
|
||||||
return value.toObject();
|
return value.toObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QVariant requireIsType<QVariant>(const QJsonValue &value, const QString &what)
|
template<> QVariant requireIsType<QVariant>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (value.isNull() || value.isUndefined())
|
if (value.isNull() || value.isUndefined())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is null or undefined");
|
throw JsonException(what + " is null or undefined");
|
||||||
}
|
}
|
||||||
return value.toVariant();
|
return value.toVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> QJsonValue requireIsType<QJsonValue>(const QJsonValue &value, const QString &what)
|
template<> QJsonValue requireIsType<QJsonValue>(const QJsonValue &value, const QString &what)
|
||||||
{
|
{
|
||||||
if (value.isNull() || value.isUndefined())
|
if (value.isNull() || value.isUndefined())
|
||||||
{
|
{
|
||||||
throw JsonException(what + " is null or undefined");
|
throw JsonException(what + " is null or undefined");
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
160
api/logic/Json.h
160
api/logic/Json.h
@@ -19,7 +19,7 @@ namespace Json
|
|||||||
class MULTIMC_LOGIC_EXPORT JsonException : public ::Exception
|
class MULTIMC_LOGIC_EXPORT JsonException : public ::Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonException(const QString &message) : Exception(message) {}
|
JsonException(const QString &message) : Exception(message) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @throw FileSystemException
|
/// @throw FileSystemException
|
||||||
@@ -51,7 +51,7 @@ void writeStringList(QJsonObject & to, const QString &key, const QStringList &va
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
QJsonValue toJson(const T &t)
|
QJsonValue toJson(const T &t)
|
||||||
{
|
{
|
||||||
return QJsonValue(t);
|
return QJsonValue(t);
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
QJsonValue toJson<QUrl>(const QUrl &url);
|
QJsonValue toJson<QUrl>(const QUrl &url);
|
||||||
@@ -69,12 +69,12 @@ QJsonValue toJson<QVariant>(const QVariant &variant);
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
QJsonArray toJsonArray(const QList<T> &container)
|
QJsonArray toJsonArray(const QList<T> &container)
|
||||||
{
|
{
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
for (const T item : container)
|
for (const T item : container)
|
||||||
{
|
{
|
||||||
array.append(toJson<T>(item));
|
array.append(toJson<T>(item));
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////// READING ////////////////////
|
////////////////// READING ////////////////////
|
||||||
@@ -115,119 +115,119 @@ template<> MULTIMC_LOGIC_EXPORT QUrl requireIsType<QUrl>(const QJsonValue &value
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &what = "Value")
|
T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &what = "Value")
|
||||||
{
|
{
|
||||||
if (value.isUndefined() || value.isNull())
|
if (value.isUndefined() || value.isNull())
|
||||||
{
|
{
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return requireIsType<T>(value, what);
|
return requireIsType<T>(value, what);
|
||||||
}
|
}
|
||||||
catch (const JsonException &)
|
catch (JsonException &)
|
||||||
{
|
{
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw JsonException
|
/// @throw JsonException
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T requireIsType(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__")
|
T requireIsType(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__")
|
||||||
{
|
{
|
||||||
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
||||||
if (!parent.contains(key))
|
if (!parent.contains(key))
|
||||||
{
|
{
|
||||||
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
||||||
}
|
}
|
||||||
return requireIsType<T>(parent.value(key), localWhat);
|
return requireIsType<T>(parent.value(key), localWhat);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T ensureIsType(const QJsonObject &parent, const QString &key, const T default_ = T(), const QString &what = "__placeholder__")
|
T ensureIsType(const QJsonObject &parent, const QString &key, const T default_ = T(), const QString &what = "__placeholder__")
|
||||||
{
|
{
|
||||||
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
||||||
if (!parent.contains(key))
|
if (!parent.contains(key))
|
||||||
{
|
{
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
return ensureIsType<T>(parent.value(key), default_, localWhat);
|
return ensureIsType<T>(parent.value(key), default_, localWhat);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QVector<T> requireIsArrayOf(const QJsonDocument &doc)
|
QVector<T> requireIsArrayOf(const QJsonDocument &doc)
|
||||||
{
|
{
|
||||||
const QJsonArray array = requireArray(doc);
|
const QJsonArray array = requireArray(doc);
|
||||||
QVector<T> out;
|
QVector<T> out;
|
||||||
for (const QJsonValue val : array)
|
for (const QJsonValue val : array)
|
||||||
{
|
{
|
||||||
out.append(requireIsType<T>(val, "Document"));
|
out.append(requireIsType<T>(val, "Document"));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value")
|
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value")
|
||||||
{
|
{
|
||||||
const QJsonArray array = ensureIsType<QJsonArray>(value, QJsonArray(), what);
|
const QJsonArray array = ensureIsType<QJsonArray>(value, QJsonArray(), what);
|
||||||
QVector<T> out;
|
QVector<T> out;
|
||||||
for (const QJsonValue val : array)
|
for (const QJsonValue val : array)
|
||||||
{
|
{
|
||||||
out.append(requireIsType<T>(val, what));
|
out.append(requireIsType<T>(val, what));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QVector<T> default_, const QString &what = "Value")
|
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QVector<T> default_, const QString &what = "Value")
|
||||||
{
|
{
|
||||||
if (value.isUndefined())
|
if (value.isUndefined())
|
||||||
{
|
{
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
return ensureIsArrayOf<T>(value, what);
|
return ensureIsArrayOf<T>(value, what);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @throw JsonException
|
/// @throw JsonException
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QVector<T> requireIsArrayOf(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__")
|
QVector<T> requireIsArrayOf(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__")
|
||||||
{
|
{
|
||||||
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
||||||
if (!parent.contains(key))
|
if (!parent.contains(key))
|
||||||
{
|
{
|
||||||
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
||||||
}
|
}
|
||||||
return ensureIsArrayOf<T>(parent.value(key), localWhat);
|
return ensureIsArrayOf<T>(parent.value(key), localWhat);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QVector<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
QVector<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
||||||
const QVector<T> &default_ = QVector<T>(), const QString &what = "__placeholder__")
|
const QVector<T> &default_ = QVector<T>(), const QString &what = "__placeholder__")
|
||||||
{
|
{
|
||||||
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
||||||
if (!parent.contains(key))
|
if (!parent.contains(key))
|
||||||
{
|
{
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
return ensureIsArrayOf<T>(parent.value(key), default_, localWhat);
|
return ensureIsArrayOf<T>(parent.value(key), default_, localWhat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this macro part could be replaced by variadic functions that just pass on their arguments, but that wouldn't work well with IDE helpers
|
// this macro part could be replaced by variadic functions that just pass on their arguments, but that wouldn't work well with IDE helpers
|
||||||
#define JSON_HELPERFUNCTIONS(NAME, TYPE) \
|
#define JSON_HELPERFUNCTIONS(NAME, TYPE) \
|
||||||
inline TYPE require##NAME(const QJsonValue &value, const QString &what = "Value") \
|
inline TYPE require##NAME(const QJsonValue &value, const QString &what = "Value") \
|
||||||
{ \
|
{ \
|
||||||
return requireIsType<TYPE>(value, what); \
|
return requireIsType<TYPE>(value, what); \
|
||||||
} \
|
} \
|
||||||
inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_ = TYPE(), const QString &what = "Value") \
|
inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_ = TYPE(), const QString &what = "Value") \
|
||||||
{ \
|
{ \
|
||||||
return ensureIsType<TYPE>(value, default_, what); \
|
return ensureIsType<TYPE>(value, default_, what); \
|
||||||
} \
|
} \
|
||||||
inline TYPE require##NAME(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") \
|
inline TYPE require##NAME(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") \
|
||||||
{ \
|
{ \
|
||||||
return requireIsType<TYPE>(parent, key, what); \
|
return requireIsType<TYPE>(parent, key, what); \
|
||||||
} \
|
} \
|
||||||
inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_ = TYPE(), const QString &what = "__placeholder") \
|
inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_ = TYPE(), const QString &what = "__placeholder") \
|
||||||
{ \
|
{ \
|
||||||
return ensureIsType<TYPE>(parent, key, default_, what); \
|
return ensureIsType<TYPE>(parent, key, default_, what); \
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_HELPERFUNCTIONS(Array, QJsonArray)
|
JSON_HELPERFUNCTIONS(Array, QJsonArray)
|
||||||
JSON_HELPERFUNCTIONS(Object, QJsonObject)
|
JSON_HELPERFUNCTIONS(Object, QJsonObject)
|
||||||
|
|||||||
@@ -4,157 +4,157 @@
|
|||||||
|
|
||||||
LoggedProcess::LoggedProcess(QObject *parent) : QProcess(parent)
|
LoggedProcess::LoggedProcess(QObject *parent) : QProcess(parent)
|
||||||
{
|
{
|
||||||
// QProcess has a strange interface... let's map a lot of those into a few.
|
// QProcess has a strange interface... let's map a lot of those into a few.
|
||||||
connect(this, &QProcess::readyReadStandardOutput, this, &LoggedProcess::on_stdOut);
|
connect(this, &QProcess::readyReadStandardOutput, this, &LoggedProcess::on_stdOut);
|
||||||
connect(this, &QProcess::readyReadStandardError, this, &LoggedProcess::on_stdErr);
|
connect(this, &QProcess::readyReadStandardError, this, &LoggedProcess::on_stdErr);
|
||||||
connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(on_exit(int,QProcess::ExitStatus)));
|
connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(on_exit(int,QProcess::ExitStatus)));
|
||||||
connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(on_error(QProcess::ProcessError)));
|
connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(on_error(QProcess::ProcessError)));
|
||||||
connect(this, &QProcess::stateChanged, this, &LoggedProcess::on_stateChange);
|
connect(this, &QProcess::stateChanged, this, &LoggedProcess::on_stateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoggedProcess::~LoggedProcess()
|
LoggedProcess::~LoggedProcess()
|
||||||
{
|
{
|
||||||
if(m_is_detachable)
|
if(m_is_detachable)
|
||||||
{
|
{
|
||||||
setProcessState(QProcess::NotRunning);
|
setProcessState(QProcess::NotRunning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList reprocess(const QByteArray & data, QString & leftover)
|
QStringList reprocess(const QByteArray & data, QString & leftover)
|
||||||
{
|
{
|
||||||
QString str = leftover + QString::fromLocal8Bit(data);
|
QString str = leftover + QString::fromLocal8Bit(data);
|
||||||
|
|
||||||
str.remove('\r');
|
str.remove('\r');
|
||||||
QStringList lines = str.split("\n");
|
QStringList lines = str.split("\n");
|
||||||
leftover = lines.takeLast();
|
leftover = lines.takeLast();
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::on_stdErr()
|
void LoggedProcess::on_stdErr()
|
||||||
{
|
{
|
||||||
auto lines = reprocess(readAllStandardError(), m_err_leftover);
|
auto lines = reprocess(readAllStandardError(), m_err_leftover);
|
||||||
emit log(lines, MessageLevel::StdErr);
|
emit log(lines, MessageLevel::StdErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::on_stdOut()
|
void LoggedProcess::on_stdOut()
|
||||||
{
|
{
|
||||||
auto lines = reprocess(readAllStandardOutput(), m_out_leftover);
|
auto lines = reprocess(readAllStandardOutput(), m_out_leftover);
|
||||||
emit log(lines, MessageLevel::StdOut);
|
emit log(lines, MessageLevel::StdOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::on_exit(int exit_code, QProcess::ExitStatus status)
|
void LoggedProcess::on_exit(int exit_code, QProcess::ExitStatus status)
|
||||||
{
|
{
|
||||||
// save the exit code
|
// save the exit code
|
||||||
m_exit_code = exit_code;
|
m_exit_code = exit_code;
|
||||||
|
|
||||||
// Flush console window
|
// Flush console window
|
||||||
if (!m_err_leftover.isEmpty())
|
if (!m_err_leftover.isEmpty())
|
||||||
{
|
{
|
||||||
emit log({m_err_leftover}, MessageLevel::StdErr);
|
emit log({m_err_leftover}, MessageLevel::StdErr);
|
||||||
m_err_leftover.clear();
|
m_err_leftover.clear();
|
||||||
}
|
}
|
||||||
if (!m_out_leftover.isEmpty())
|
if (!m_out_leftover.isEmpty())
|
||||||
{
|
{
|
||||||
emit log({m_err_leftover}, MessageLevel::StdOut);
|
emit log({m_err_leftover}, MessageLevel::StdOut);
|
||||||
m_out_leftover.clear();
|
m_out_leftover.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// based on state, send signals
|
// based on state, send signals
|
||||||
if (!m_is_aborting)
|
if (!m_is_aborting)
|
||||||
{
|
{
|
||||||
if (status == QProcess::NormalExit)
|
if (status == QProcess::NormalExit)
|
||||||
{
|
{
|
||||||
//: Message displayed on instance exit
|
//: Message displayed on instance exit
|
||||||
emit log({tr("Process exited with code %1.").arg(exit_code)}, MessageLevel::MultiMC);
|
emit log({tr("Process exited with code %1.").arg(exit_code)}, MessageLevel::MultiMC);
|
||||||
changeState(LoggedProcess::Finished);
|
changeState(LoggedProcess::Finished);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//: Message displayed on instance crashed
|
//: Message displayed on instance crashed
|
||||||
if(exit_code == -1)
|
if(exit_code == -1)
|
||||||
emit log({tr("Process crashed.")}, MessageLevel::MultiMC);
|
emit log({tr("Process crashed.")}, MessageLevel::MultiMC);
|
||||||
else
|
else
|
||||||
emit log({tr("Process crashed with exitcode %1.").arg(exit_code)}, MessageLevel::MultiMC);
|
emit log({tr("Process crashed with exitcode %1.").arg(exit_code)}, MessageLevel::MultiMC);
|
||||||
changeState(LoggedProcess::Crashed);
|
changeState(LoggedProcess::Crashed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//: Message displayed after the instance exits due to kill request
|
//: Message displayed after the instance exits due to kill request
|
||||||
emit log({tr("Process was killed by user.")}, MessageLevel::Error);
|
emit log({tr("Process was killed by user.")}, MessageLevel::Error);
|
||||||
changeState(LoggedProcess::Aborted);
|
changeState(LoggedProcess::Aborted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::on_error(QProcess::ProcessError error)
|
void LoggedProcess::on_error(QProcess::ProcessError error)
|
||||||
{
|
{
|
||||||
switch(error)
|
switch(error)
|
||||||
{
|
{
|
||||||
case QProcess::FailedToStart:
|
case QProcess::FailedToStart:
|
||||||
{
|
{
|
||||||
emit log({tr("The process failed to start.")}, MessageLevel::Fatal);
|
emit log({tr("The process failed to start.")}, MessageLevel::Fatal);
|
||||||
changeState(LoggedProcess::FailedToStart);
|
changeState(LoggedProcess::FailedToStart);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// we'll just ignore those... never needed them
|
// we'll just ignore those... never needed them
|
||||||
case QProcess::Crashed:
|
case QProcess::Crashed:
|
||||||
case QProcess::ReadError:
|
case QProcess::ReadError:
|
||||||
case QProcess::Timedout:
|
case QProcess::Timedout:
|
||||||
case QProcess::UnknownError:
|
case QProcess::UnknownError:
|
||||||
case QProcess::WriteError:
|
case QProcess::WriteError:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::kill()
|
void LoggedProcess::kill()
|
||||||
{
|
{
|
||||||
m_is_aborting = true;
|
m_is_aborting = true;
|
||||||
QProcess::kill();
|
QProcess::kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoggedProcess::exitCode() const
|
int LoggedProcess::exitCode() const
|
||||||
{
|
{
|
||||||
return m_exit_code;
|
return m_exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::changeState(LoggedProcess::State state)
|
void LoggedProcess::changeState(LoggedProcess::State state)
|
||||||
{
|
{
|
||||||
if(state == m_state)
|
if(state == m_state)
|
||||||
return;
|
return;
|
||||||
m_state = state;
|
m_state = state;
|
||||||
emit stateChanged(m_state);
|
emit stateChanged(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoggedProcess::State LoggedProcess::state() const
|
LoggedProcess::State LoggedProcess::state() const
|
||||||
{
|
{
|
||||||
return m_state;
|
return m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggedProcess::on_stateChange(QProcess::ProcessState state)
|
void LoggedProcess::on_stateChange(QProcess::ProcessState state)
|
||||||
{
|
{
|
||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
case QProcess::NotRunning:
|
case QProcess::NotRunning:
|
||||||
break; // let's not - there are too many that handle this already.
|
break; // let's not - there are too many that handle this already.
|
||||||
case QProcess::Starting:
|
case QProcess::Starting:
|
||||||
{
|
{
|
||||||
if(m_state != LoggedProcess::NotRunning)
|
if(m_state != LoggedProcess::NotRunning)
|
||||||
{
|
{
|
||||||
qWarning() << "Wrong state change for process from state" << m_state << "to" << (int) LoggedProcess::Starting;
|
qWarning() << "Wrong state change for process from state" << m_state << "to" << (int) LoggedProcess::Starting;
|
||||||
}
|
}
|
||||||
changeState(LoggedProcess::Starting);
|
changeState(LoggedProcess::Starting);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case QProcess::Running:
|
case QProcess::Running:
|
||||||
{
|
{
|
||||||
if(m_state != LoggedProcess::Starting)
|
if(m_state != LoggedProcess::Starting)
|
||||||
{
|
{
|
||||||
qWarning() << "Wrong state change for process from state" << m_state << "to" << (int) LoggedProcess::Running;
|
qWarning() << "Wrong state change for process from state" << m_state << "to" << (int) LoggedProcess::Running;
|
||||||
}
|
}
|
||||||
changeState(LoggedProcess::Running);
|
changeState(LoggedProcess::Running);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
@@ -172,5 +172,5 @@ qint64 LoggedProcess::processId() const
|
|||||||
|
|
||||||
void LoggedProcess::setDetachable(bool detachable)
|
void LoggedProcess::setDetachable(bool detachable)
|
||||||
{
|
{
|
||||||
m_is_detachable = detachable;
|
m_is_detachable = detachable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -27,54 +27,54 @@ class MULTIMC_LOGIC_EXPORT LoggedProcess : public QProcess
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
NotRunning,
|
NotRunning,
|
||||||
Starting,
|
Starting,
|
||||||
FailedToStart,
|
FailedToStart,
|
||||||
Running,
|
Running,
|
||||||
Finished,
|
Finished,
|
||||||
Crashed,
|
Crashed,
|
||||||
Aborted
|
Aborted
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LoggedProcess(QObject* parent = 0);
|
explicit LoggedProcess(QObject* parent = 0);
|
||||||
virtual ~LoggedProcess();
|
virtual ~LoggedProcess();
|
||||||
|
|
||||||
State state() const;
|
State state() const;
|
||||||
int exitCode() const;
|
int exitCode() const;
|
||||||
qint64 processId() const;
|
qint64 processId() const;
|
||||||
|
|
||||||
void setDetachable(bool detachable);
|
void setDetachable(bool detachable);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void log(QStringList lines, MessageLevel::Enum level);
|
void log(QStringList lines, MessageLevel::Enum level);
|
||||||
void stateChanged(LoggedProcess::State state);
|
void stateChanged(LoggedProcess::State state);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief kill the process - equivalent to kill -9
|
* @brief kill the process - equivalent to kill -9
|
||||||
*/
|
*/
|
||||||
void kill();
|
void kill();
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_stdErr();
|
void on_stdErr();
|
||||||
void on_stdOut();
|
void on_stdOut();
|
||||||
void on_exit(int exit_code, QProcess::ExitStatus status);
|
void on_exit(int exit_code, QProcess::ExitStatus status);
|
||||||
void on_error(QProcess::ProcessError error);
|
void on_error(QProcess::ProcessError error);
|
||||||
void on_stateChange(QProcess::ProcessState);
|
void on_stateChange(QProcess::ProcessState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void changeState(LoggedProcess::State state);
|
void changeState(LoggedProcess::State state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_err_leftover;
|
QString m_err_leftover;
|
||||||
QString m_out_leftover;
|
QString m_out_leftover;
|
||||||
bool m_killed = false;
|
bool m_killed = false;
|
||||||
State m_state = NotRunning;
|
State m_state = NotRunning;
|
||||||
int m_exit_code = 0;
|
int m_exit_code = 0;
|
||||||
bool m_is_aborting = false;
|
bool m_is_aborting = false;
|
||||||
bool m_is_detachable = false;
|
bool m_is_detachable = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,74 +3,74 @@
|
|||||||
/// TAKEN FROM Qt, because it doesn't expose it intelligently
|
/// TAKEN FROM Qt, because it doesn't expose it intelligently
|
||||||
static inline QChar getNextChar(const QString &s, int location)
|
static inline QChar getNextChar(const QString &s, int location)
|
||||||
{
|
{
|
||||||
return (location < s.length()) ? s.at(location) : QChar();
|
return (location < s.length()) ? s.at(location) : QChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TAKEN FROM Qt, because it doesn't expose it intelligently
|
/// TAKEN FROM Qt, because it doesn't expose it intelligently
|
||||||
int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
|
int Strings::naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
|
||||||
{
|
{
|
||||||
for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2)
|
for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2)
|
||||||
{
|
{
|
||||||
// skip spaces, tabs and 0's
|
// skip spaces, tabs and 0's
|
||||||
QChar c1 = getNextChar(s1, l1);
|
QChar c1 = getNextChar(s1, l1);
|
||||||
while (c1.isSpace())
|
while (c1.isSpace())
|
||||||
c1 = getNextChar(s1, ++l1);
|
c1 = getNextChar(s1, ++l1);
|
||||||
QChar c2 = getNextChar(s2, l2);
|
QChar c2 = getNextChar(s2, l2);
|
||||||
while (c2.isSpace())
|
while (c2.isSpace())
|
||||||
c2 = getNextChar(s2, ++l2);
|
c2 = getNextChar(s2, ++l2);
|
||||||
|
|
||||||
if (c1.isDigit() && c2.isDigit())
|
if (c1.isDigit() && c2.isDigit())
|
||||||
{
|
{
|
||||||
while (c1.digitValue() == 0)
|
while (c1.digitValue() == 0)
|
||||||
c1 = getNextChar(s1, ++l1);
|
c1 = getNextChar(s1, ++l1);
|
||||||
while (c2.digitValue() == 0)
|
while (c2.digitValue() == 0)
|
||||||
c2 = getNextChar(s2, ++l2);
|
c2 = getNextChar(s2, ++l2);
|
||||||
|
|
||||||
int lookAheadLocation1 = l1;
|
int lookAheadLocation1 = l1;
|
||||||
int lookAheadLocation2 = l2;
|
int lookAheadLocation2 = l2;
|
||||||
int currentReturnValue = 0;
|
int currentReturnValue = 0;
|
||||||
// find the last digit, setting currentReturnValue as we go if it isn't equal
|
// find the last digit, setting currentReturnValue as we go if it isn't equal
|
||||||
for (QChar lookAhead1 = c1, lookAhead2 = c2;
|
for (QChar lookAhead1 = c1, lookAhead2 = c2;
|
||||||
(lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
|
(lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
|
||||||
lookAhead1 = getNextChar(s1, ++lookAheadLocation1),
|
lookAhead1 = getNextChar(s1, ++lookAheadLocation1),
|
||||||
lookAhead2 = getNextChar(s2, ++lookAheadLocation2))
|
lookAhead2 = getNextChar(s2, ++lookAheadLocation2))
|
||||||
{
|
{
|
||||||
bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit();
|
bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit();
|
||||||
bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit();
|
bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit();
|
||||||
if (!is1ADigit && !is2ADigit)
|
if (!is1ADigit && !is2ADigit)
|
||||||
break;
|
break;
|
||||||
if (!is1ADigit)
|
if (!is1ADigit)
|
||||||
return -1;
|
return -1;
|
||||||
if (!is2ADigit)
|
if (!is2ADigit)
|
||||||
return 1;
|
return 1;
|
||||||
if (currentReturnValue == 0)
|
if (currentReturnValue == 0)
|
||||||
{
|
{
|
||||||
if (lookAhead1 < lookAhead2)
|
if (lookAhead1 < lookAhead2)
|
||||||
{
|
{
|
||||||
currentReturnValue = -1;
|
currentReturnValue = -1;
|
||||||
}
|
}
|
||||||
else if (lookAhead1 > lookAhead2)
|
else if (lookAhead1 > lookAhead2)
|
||||||
{
|
{
|
||||||
currentReturnValue = 1;
|
currentReturnValue = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentReturnValue != 0)
|
if (currentReturnValue != 0)
|
||||||
return currentReturnValue;
|
return currentReturnValue;
|
||||||
}
|
}
|
||||||
if (cs == Qt::CaseInsensitive)
|
if (cs == Qt::CaseInsensitive)
|
||||||
{
|
{
|
||||||
if (!c1.isLower())
|
if (!c1.isLower())
|
||||||
c1 = c1.toLower();
|
c1 = c1.toLower();
|
||||||
if (!c2.isLower())
|
if (!c2.isLower())
|
||||||
c2 = c2.toLower();
|
c2 = c2.toLower();
|
||||||
}
|
}
|
||||||
int r = QString::localeAwareCompare(c1, c2);
|
int r = QString::localeAwareCompare(c1, c2);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// The two strings are the same (02 == 2) so fall back to the normal sort
|
// The two strings are the same (02 == 2) so fall back to the normal sort
|
||||||
return QString::compare(s1, s2, cs);
|
return QString::compare(s1, s2, cs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
|
|
||||||
namespace Strings
|
namespace Strings
|
||||||
{
|
{
|
||||||
int MULTIMC_LOGIC_EXPORT naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs);
|
int MULTIMC_LOGIC_EXPORT naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,255 +1,491 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/*
|
||||||
*
|
Copyright (C) 2010 Roberto Pompermaier
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
Parts of this file were part of QuaZIP.
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
QuaZIP is free software: you can redistribute it and/or modify
|
||||||
*
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
the Free Software Foundation, either version 2.1 of the License, or
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
(at your option) any later version.
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
QuaZIP is distributed in the hope that it will be useful,
|
||||||
* limitations under the License.
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
*/
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
See COPYING file for the full LGPL text.
|
||||||
|
|
||||||
|
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||||
|
see quazip/(un)MMCZip.h files for details. Basically it's the zlib license.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <quazip.h>
|
#include <quazip.h>
|
||||||
#include <quazipdir.h>
|
|
||||||
#include <quazipfile.h>
|
|
||||||
#include <JlCompress.h>
|
#include <JlCompress.h>
|
||||||
|
#include <quazipdir.h>
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
// ours
|
bool copyData(QIODevice &inFile, QIODevice &outFile)
|
||||||
bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, const JlCompress::FilterFunction filter)
|
|
||||||
{
|
{
|
||||||
QuaZip modZip(from.filePath());
|
while (!inFile.atEnd())
|
||||||
modZip.open(QuaZip::mdUnzip);
|
{
|
||||||
|
char buf[4096];
|
||||||
QuaZipFile fileInsideMod(&modZip);
|
qint64 readLen = inFile.read(buf, 4096);
|
||||||
QuaZipFile zipOutFile(into);
|
if (readLen <= 0)
|
||||||
for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
|
return false;
|
||||||
{
|
if (outFile.write(buf, readLen) != readLen)
|
||||||
QString filename = modZip.getCurrentFileName();
|
return false;
|
||||||
if (filter && !filter(filename))
|
}
|
||||||
{
|
return true;
|
||||||
qDebug() << "Skipping file " << filename << " from "
|
|
||||||
<< from.fileName() << " - filtered";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (contained.contains(filename))
|
|
||||||
{
|
|
||||||
qDebug() << "Skipping already contained file " << filename << " from "
|
|
||||||
<< from.fileName();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
contained.insert(filename);
|
|
||||||
|
|
||||||
if (!fileInsideMod.open(QIODevice::ReadOnly))
|
|
||||||
{
|
|
||||||
qCritical() << "Failed to open " << filename << " from " << from.fileName();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
|
|
||||||
|
|
||||||
if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
|
|
||||||
{
|
|
||||||
qCritical() << "Failed to open " << filename << " in the jar";
|
|
||||||
fileInsideMod.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!JlCompress::copyData(fileInsideMod, zipOutFile))
|
|
||||||
{
|
|
||||||
zipOutFile.close();
|
|
||||||
fileInsideMod.close();
|
|
||||||
qCritical() << "Failed to copy data of " << filename << " into the jar";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
zipOutFile.close();
|
|
||||||
fileInsideMod.close();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ours
|
|
||||||
bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods)
|
|
||||||
{
|
|
||||||
QuaZip zipOut(targetJarPath);
|
|
||||||
if (!zipOut.open(QuaZip::mdCreate))
|
|
||||||
{
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to open the minecraft.jar for modding";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Files already added to the jar.
|
|
||||||
// These files will be skipped.
|
|
||||||
QSet<QString> addedFiles;
|
|
||||||
|
|
||||||
// Modify the jar
|
|
||||||
QListIterator<Mod> i(mods);
|
|
||||||
i.toBack();
|
|
||||||
while (i.hasPrevious())
|
|
||||||
{
|
|
||||||
const Mod &mod = i.previous();
|
|
||||||
// do not merge disabled mods.
|
|
||||||
if (!mod.enabled())
|
|
||||||
continue;
|
|
||||||
if (mod.type() == Mod::MOD_ZIPFILE)
|
|
||||||
{
|
|
||||||
if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles))
|
|
||||||
{
|
|
||||||
zipOut.close();
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (mod.type() == Mod::MOD_SINGLEFILE)
|
|
||||||
{
|
|
||||||
// FIXME: buggy - does not work with addedFiles
|
|
||||||
auto filename = mod.filename();
|
|
||||||
if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
|
|
||||||
{
|
|
||||||
zipOut.close();
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
addedFiles.insert(filename.fileName());
|
|
||||||
}
|
|
||||||
else if (mod.type() == Mod::MOD_FOLDER)
|
|
||||||
{
|
|
||||||
// FIXME: buggy - does not work with addedFiles
|
|
||||||
auto filename = mod.filename();
|
|
||||||
QString what_to_zip = filename.absoluteFilePath();
|
|
||||||
QDir dir(what_to_zip);
|
|
||||||
dir.cdUp();
|
|
||||||
QString parent_dir = dir.absolutePath();
|
|
||||||
if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles))
|
|
||||||
{
|
|
||||||
zipOut.close();
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
qDebug() << "Adding folder " << filename.fileName() << " from "
|
|
||||||
<< filename.absoluteFilePath();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Make sure we do not continue launching when something is missing or undefined...
|
|
||||||
zipOut.close();
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to add unknown mod type" << mod.filename().fileName() << "to the jar.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key){return !key.contains("META-INF");}))
|
|
||||||
{
|
|
||||||
zipOut.close();
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to insert minecraft.jar contents.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recompress the jar
|
|
||||||
zipOut.close();
|
|
||||||
if (zipOut.getZipError() != 0)
|
|
||||||
{
|
|
||||||
QFile::remove(targetJarPath);
|
|
||||||
qCritical() << "Failed to finalize minecraft.jar!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ours
|
|
||||||
QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root)
|
|
||||||
{
|
|
||||||
QuaZipDir rootDir(zip, root);
|
|
||||||
for(auto fileName: rootDir.entryList(QDir::Files))
|
|
||||||
{
|
|
||||||
if(fileName == what)
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
for(auto fileName: rootDir.entryList(QDir::Dirs))
|
|
||||||
{
|
|
||||||
QString result = findFolderOfFileInZip(zip, what, root + fileName);
|
|
||||||
if(!result.isEmpty())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ours
|
|
||||||
bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root)
|
|
||||||
{
|
|
||||||
QuaZipDir rootDir(zip, root);
|
|
||||||
for(auto fileName: rootDir.entryList(QDir::Files))
|
|
||||||
{
|
|
||||||
if(fileName == what)
|
|
||||||
{
|
|
||||||
result.append(root);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(auto fileName: rootDir.entryList(QDir::Dirs))
|
|
||||||
{
|
|
||||||
findFilesInZip(zip, what, result, root + fileName);
|
|
||||||
}
|
|
||||||
return !result.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ours
|
|
||||||
QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
|
|
||||||
{
|
|
||||||
QDir directory(target);
|
|
||||||
QStringList extracted;
|
|
||||||
qDebug() << "Extracting subdir" << subdir << "from" << zip->getZipName() << "to" << target;
|
|
||||||
if (!zip->goToFirstFile())
|
|
||||||
{
|
|
||||||
qWarning() << "Failed to seek to first file in zip";
|
|
||||||
return QStringList();
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
|
||||||
QString name = zip->getCurrentFileName();
|
|
||||||
if(!name.startsWith(subdir))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
name.remove(0, subdir.size());
|
|
||||||
QString absFilePath = directory.absoluteFilePath(name);
|
|
||||||
if(name.isEmpty())
|
|
||||||
{
|
|
||||||
absFilePath += "/";
|
|
||||||
}
|
|
||||||
if (!JlCompress::extractFile(zip, "", absFilePath))
|
|
||||||
{
|
|
||||||
qWarning() << "Failed to extract file" << name << "to" << absFilePath;
|
|
||||||
JlCompress::removeFile(extracted);
|
|
||||||
return QStringList();
|
|
||||||
}
|
|
||||||
extracted.append(absFilePath);
|
|
||||||
qDebug() << "Extracted file" << name;
|
|
||||||
} while (zip->goToNextFile());
|
|
||||||
return extracted;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ours
|
|
||||||
QStringList MMCZip::extractDir(QString fileCompressed, QString dir)
|
QStringList MMCZip::extractDir(QString fileCompressed, QString dir)
|
||||||
{
|
{
|
||||||
QuaZip zip(fileCompressed);
|
return JlCompress::extractDir(fileCompressed, dir);
|
||||||
if (!zip.open(QuaZip::mdUnzip))
|
}
|
||||||
{
|
|
||||||
return {};
|
bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
|
||||||
}
|
{
|
||||||
return MMCZip::extractSubDir(&zip, "", dir);
|
if (!zip)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (zip->getMode() != QuaZip::mdCreate && zip->getMode() != QuaZip::mdAppend &&
|
||||||
|
zip->getMode() != QuaZip::mdAdd)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile inFile;
|
||||||
|
inFile.setFileName(fileName);
|
||||||
|
if (!inFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZipFile outFile(zip);
|
||||||
|
if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!copyData(inFile, outFile) || outFile.getZipError() != UNZ_OK)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outFile.close();
|
||||||
|
if (outFile.getZipError() != UNZ_OK)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inFile.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QString>& added, QString prefix, const SeparatorPrefixTree <'/'> * blacklist)
|
||||||
|
{
|
||||||
|
if (!zip) return false;
|
||||||
|
if (zip->getMode()!=QuaZip::mdCreate && zip->getMode()!=QuaZip::mdAppend && zip->getMode()!=QuaZip::mdAdd)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir directory(dir);
|
||||||
|
if (!directory.exists())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir origDirectory(origDir);
|
||||||
|
if (dir != origDir)
|
||||||
|
{
|
||||||
|
QString internalDirName = origDirectory.relativeFilePath(dir);
|
||||||
|
if(!blacklist || !blacklist->covers(internalDirName))
|
||||||
|
{
|
||||||
|
QuaZipFile dirZipFile(zip);
|
||||||
|
auto dirPrefix = FS::PathCombine(prefix, origDirectory.relativeFilePath(dir)) + "/";
|
||||||
|
if (!dirZipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(dirPrefix, dir), 0, 0, 0))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dirZipFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfoList files = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);
|
||||||
|
for (auto file: files)
|
||||||
|
{
|
||||||
|
if(!file.isDir())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!compressSubDir(zip,file.absoluteFilePath(),origDir, added, prefix, blacklist))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
files = directory.entryInfoList(QDir::Files);
|
||||||
|
for (auto file: files)
|
||||||
|
{
|
||||||
|
if(!file.isFile())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.absoluteFilePath()==zip->getZipName())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString filename = origDirectory.relativeFilePath(file.absoluteFilePath());
|
||||||
|
if(blacklist && blacklist->covers(filename))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(prefix.size())
|
||||||
|
{
|
||||||
|
filename = FS::PathCombine(prefix, filename);
|
||||||
|
}
|
||||||
|
added.insert(filename);
|
||||||
|
if (!compressFile(zip,file.absoluteFilePath(),filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
|
||||||
|
std::function<bool(QString)> filter)
|
||||||
|
{
|
||||||
|
QuaZip modZip(from.filePath());
|
||||||
|
modZip.open(QuaZip::mdUnzip);
|
||||||
|
|
||||||
|
QuaZipFile fileInsideMod(&modZip);
|
||||||
|
QuaZipFile zipOutFile(into);
|
||||||
|
for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
|
||||||
|
{
|
||||||
|
QString filename = modZip.getCurrentFileName();
|
||||||
|
if (!filter(filename))
|
||||||
|
{
|
||||||
|
qDebug() << "Skipping file " << filename << " from "
|
||||||
|
<< from.fileName() << " - filtered";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (contained.contains(filename))
|
||||||
|
{
|
||||||
|
qDebug() << "Skipping already contained file " << filename << " from "
|
||||||
|
<< from.fileName();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
contained.insert(filename);
|
||||||
|
|
||||||
|
if (!fileInsideMod.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to open " << filename << " from " << from.fileName();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
|
||||||
|
|
||||||
|
if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to open " << filename << " in the jar";
|
||||||
|
fileInsideMod.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!copyData(fileInsideMod, zipOutFile))
|
||||||
|
{
|
||||||
|
zipOutFile.close();
|
||||||
|
fileInsideMod.close();
|
||||||
|
qCritical() << "Failed to copy data of " << filename << " into the jar";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
zipOutFile.close();
|
||||||
|
fileInsideMod.close();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods)
|
||||||
|
{
|
||||||
|
QuaZip zipOut(targetJarPath);
|
||||||
|
if (!zipOut.open(QuaZip::mdCreate))
|
||||||
|
{
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to open the minecraft.jar for modding";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Files already added to the jar.
|
||||||
|
// These files will be skipped.
|
||||||
|
QSet<QString> addedFiles;
|
||||||
|
|
||||||
|
// Modify the jar
|
||||||
|
QListIterator<Mod> i(mods);
|
||||||
|
i.toBack();
|
||||||
|
while (i.hasPrevious())
|
||||||
|
{
|
||||||
|
const Mod &mod = i.previous();
|
||||||
|
// do not merge disabled mods.
|
||||||
|
if (!mod.enabled())
|
||||||
|
continue;
|
||||||
|
if (mod.type() == Mod::MOD_ZIPFILE)
|
||||||
|
{
|
||||||
|
if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles, noFilter))
|
||||||
|
{
|
||||||
|
zipOut.close();
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mod.type() == Mod::MOD_SINGLEFILE)
|
||||||
|
{
|
||||||
|
auto filename = mod.filename();
|
||||||
|
if (!compressFile(&zipOut, filename.absoluteFilePath(),
|
||||||
|
filename.fileName()))
|
||||||
|
{
|
||||||
|
zipOut.close();
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
addedFiles.insert(filename.fileName());
|
||||||
|
}
|
||||||
|
else if (mod.type() == Mod::MOD_FOLDER)
|
||||||
|
{
|
||||||
|
auto filename = mod.filename();
|
||||||
|
QString what_to_zip = filename.absoluteFilePath();
|
||||||
|
QDir dir(what_to_zip);
|
||||||
|
dir.cdUp();
|
||||||
|
QString parent_dir = dir.absolutePath();
|
||||||
|
if (!compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles))
|
||||||
|
{
|
||||||
|
zipOut.close();
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qDebug() << "Adding folder " << filename.fileName() << " from "
|
||||||
|
<< filename.absoluteFilePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, metaInfFilter))
|
||||||
|
{
|
||||||
|
zipOut.close();
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to insert minecraft.jar contents.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recompress the jar
|
||||||
|
zipOut.close();
|
||||||
|
if (zipOut.getZipError() != 0)
|
||||||
|
{
|
||||||
|
QFile::remove(targetJarPath);
|
||||||
|
qCritical() << "Failed to finalize minecraft.jar!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::noFilter(QString)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::metaInfFilter(QString key)
|
||||||
|
{
|
||||||
|
if(key.contains("META-INF"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::compressDir(QString zipFile, QString dir, QString prefix, const SeparatorPrefixTree <'/'> * blacklist)
|
||||||
|
{
|
||||||
|
QuaZip zip(zipFile);
|
||||||
|
QDir().mkpath(QFileInfo(zipFile).absolutePath());
|
||||||
|
if(!zip.open(QuaZip::mdCreate))
|
||||||
|
{
|
||||||
|
QFile::remove(zipFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSet<QString> added;
|
||||||
|
if (!compressSubDir(&zip, dir, dir, added, prefix, blacklist))
|
||||||
|
{
|
||||||
|
QFile::remove(zipFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
zip.close();
|
||||||
|
if(zip.getZipError()!=0)
|
||||||
|
{
|
||||||
|
QFile::remove(zipFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MMCZip::findFileInZip(QuaZip * zip, const QString & what, const QString &root)
|
||||||
|
{
|
||||||
|
QuaZipDir rootDir(zip, root);
|
||||||
|
for(auto fileName: rootDir.entryList(QDir::Files))
|
||||||
|
{
|
||||||
|
if(fileName == what)
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
for(auto fileName: rootDir.entryList(QDir::Dirs))
|
||||||
|
{
|
||||||
|
QString result = findFileInZip(zip, what, root + fileName);
|
||||||
|
if(!result.isEmpty())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root)
|
||||||
|
{
|
||||||
|
QuaZipDir rootDir(zip, root);
|
||||||
|
for(auto fileName: rootDir.entryList(QDir::Files))
|
||||||
|
{
|
||||||
|
if(fileName == what)
|
||||||
|
{
|
||||||
|
result.append(root);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(auto fileName: rootDir.entryList(QDir::Dirs))
|
||||||
|
{
|
||||||
|
findFilesInZip(zip, what, result, root + fileName);
|
||||||
|
}
|
||||||
|
return !result.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool removeFile(QStringList listFile)
|
||||||
|
{
|
||||||
|
bool ret = true;
|
||||||
|
for (int i = 0; i < listFile.count(); i++)
|
||||||
|
{
|
||||||
|
ret &= QFile::remove(listFile.at(i));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest)
|
||||||
|
{
|
||||||
|
if(!zip)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (zip->getMode() != QuaZip::mdUnzip)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
zip->setCurrentFile(fileName);
|
||||||
|
|
||||||
|
QuaZipFile inFile(zip);
|
||||||
|
if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Controllo esistenza cartella file risultato
|
||||||
|
QDir curDir;
|
||||||
|
if (fileDest.endsWith('/'))
|
||||||
|
{
|
||||||
|
if (!curDir.mkpath(fileDest))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!curDir.mkpath(QFileInfo(fileDest).absolutePath()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZipFileInfo64 info;
|
||||||
|
if (!zip->getCurrentFileInfo(&info))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QFile::Permissions srcPerm = info.getPermissions();
|
||||||
|
if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir())
|
||||||
|
{
|
||||||
|
if (srcPerm != 0)
|
||||||
|
{
|
||||||
|
QFile(fileDest).setPermissions(srcPerm);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile outFile;
|
||||||
|
outFile.setFileName(fileDest);
|
||||||
|
if (!outFile.open(QIODevice::WriteOnly))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!copyData(inFile, outFile) || inFile.getZipError() != UNZ_OK)
|
||||||
|
{
|
||||||
|
outFile.close();
|
||||||
|
removeFile(QStringList(fileDest));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
outFile.close();
|
||||||
|
|
||||||
|
inFile.close();
|
||||||
|
if (inFile.getZipError() != UNZ_OK)
|
||||||
|
{
|
||||||
|
removeFile(QStringList(fileDest));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srcPerm != 0)
|
||||||
|
{
|
||||||
|
outFile.setPermissions(srcPerm);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
|
||||||
|
{
|
||||||
|
QDir directory(target);
|
||||||
|
QStringList extracted;
|
||||||
|
if (!zip->goToFirstFile())
|
||||||
|
{
|
||||||
|
return QStringList();
|
||||||
|
}
|
||||||
|
do
|
||||||
|
{
|
||||||
|
QString name = zip->getCurrentFileName();
|
||||||
|
if(!name.startsWith(subdir))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
name.remove(0, subdir.size());
|
||||||
|
QString absFilePath = directory.absoluteFilePath(name);
|
||||||
|
if(name.isEmpty())
|
||||||
|
{
|
||||||
|
absFilePath += "/";
|
||||||
|
}
|
||||||
|
if (!extractFile(zip, "", absFilePath))
|
||||||
|
{
|
||||||
|
removeFile(extracted);
|
||||||
|
return QStringList();
|
||||||
|
}
|
||||||
|
extracted.append(absFilePath);
|
||||||
|
} while (zip->goToNextFile());
|
||||||
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +1,88 @@
|
|||||||
/* Copyright 2013-2019 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
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include "minecraft/Mod.h"
|
#include "minecraft/Mod.h"
|
||||||
|
#include "SeparatorPrefixTree.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
#include <JlCompress.h>
|
class QuaZip;
|
||||||
|
|
||||||
namespace MMCZip
|
namespace MMCZip
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge two zip files, using a filter function
|
* Compress a subdirectory.
|
||||||
|
* \param parentZip Opened zip containing the parent directory.
|
||||||
|
* \param dir The full path to the directory to pack.
|
||||||
|
* \param parentDir The full path to the directory corresponding to the root of the ZIP.
|
||||||
|
* \param recursive Whether to pack sub-directories as well or only files.
|
||||||
|
* \return true if success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool MULTIMC_LOGIC_EXPORT mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
|
bool MULTIMC_LOGIC_EXPORT compressSubDir(QuaZip *zip, QString dir, QString origDir, QSet<QString> &added,
|
||||||
const JlCompress::FilterFunction filter = nullptr);
|
QString prefix = QString(), const SeparatorPrefixTree <'/'> * blacklist = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* take a source jar, add mods to it, resulting in target jar
|
* Compress a whole directory.
|
||||||
*/
|
* \param fileCompressed The name of the archive.
|
||||||
bool MULTIMC_LOGIC_EXPORT createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods);
|
* \param dir The directory to compress.
|
||||||
|
* \param recursive Whether to pack the subdirectories as well, or just regular files.
|
||||||
|
* \return true if success, false otherwise.
|
||||||
|
*/
|
||||||
|
bool MULTIMC_LOGIC_EXPORT compressDir(QString zipFile, QString dir, QString prefix = QString(), const SeparatorPrefixTree <'/'> * blacklist = nullptr);
|
||||||
|
|
||||||
/**
|
/// filter function for @mergeZipFiles - passthrough
|
||||||
* Find a single file in archive by file name (not path)
|
bool MULTIMC_LOGIC_EXPORT noFilter(QString key);
|
||||||
*
|
|
||||||
* \return the path prefix where the file is
|
|
||||||
*/
|
|
||||||
QString MULTIMC_LOGIC_EXPORT findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root = QString(""));
|
|
||||||
|
|
||||||
/**
|
/// filter function for @mergeZipFiles - ignores METAINF
|
||||||
* Find a multiple files of the same name in archive by file name
|
bool MULTIMC_LOGIC_EXPORT metaInfFilter(QString key);
|
||||||
* If a file is found in a path, no deeper paths are searched
|
|
||||||
*
|
|
||||||
* \return true if anything was found
|
|
||||||
*/
|
|
||||||
bool MULTIMC_LOGIC_EXPORT findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root = QString());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a subdirectory from an archive
|
* Merge two zip files, using a filter function
|
||||||
*/
|
*/
|
||||||
QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target);
|
bool MULTIMC_LOGIC_EXPORT mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, std::function<bool(QString)> filter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a whole archive.
|
* take a source jar, add mods to it, resulting in target jar
|
||||||
*
|
*/
|
||||||
* \param fileCompressed The name of the archive.
|
bool MULTIMC_LOGIC_EXPORT createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods);
|
||||||
* \param dir The directory to extract to, the current directory if left empty.
|
|
||||||
* \return The list of the full paths of the files extracted, empty on failure.
|
|
||||||
*/
|
|
||||||
QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a whole archive.
|
||||||
|
*
|
||||||
|
* \param fileCompressed The name of the archive.
|
||||||
|
* \param dir The directory to extract to, the current directory if
|
||||||
|
* left empty.
|
||||||
|
* \return The list of the full paths of the files extracted, empty on failure.
|
||||||
|
*/
|
||||||
|
QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir = QString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a single file in archive by file name (not path)
|
||||||
|
*
|
||||||
|
* \return the path prefix where the file is
|
||||||
|
*/
|
||||||
|
QString MULTIMC_LOGIC_EXPORT findFileInZip(QuaZip * zip, const QString & what, const QString &root = QString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a multiple files of the same name in archive by file name
|
||||||
|
* If a file is found in a path, no deeper paths are searched
|
||||||
|
*
|
||||||
|
* \return true if anything was found
|
||||||
|
*/
|
||||||
|
bool MULTIMC_LOGIC_EXPORT findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root = QString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a single file to a destination
|
||||||
|
*
|
||||||
|
* \return true if it succeeds
|
||||||
|
*/
|
||||||
|
bool MULTIMC_LOGIC_EXPORT extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a subdirectory from an archive
|
||||||
|
*/
|
||||||
|
QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,35 @@
|
|||||||
|
|
||||||
MessageLevel::Enum MessageLevel::getLevel(const QString& levelName)
|
MessageLevel::Enum MessageLevel::getLevel(const QString& levelName)
|
||||||
{
|
{
|
||||||
if (levelName == "MultiMC")
|
if (levelName == "MultiMC")
|
||||||
return MessageLevel::MultiMC;
|
return MessageLevel::MultiMC;
|
||||||
else if (levelName == "Debug")
|
else if (levelName == "Debug")
|
||||||
return MessageLevel::Debug;
|
return MessageLevel::Debug;
|
||||||
else if (levelName == "Info")
|
else if (levelName == "Info")
|
||||||
return MessageLevel::Info;
|
return MessageLevel::Info;
|
||||||
else if (levelName == "Message")
|
else if (levelName == "Message")
|
||||||
return MessageLevel::Message;
|
return MessageLevel::Message;
|
||||||
else if (levelName == "Warning")
|
else if (levelName == "Warning")
|
||||||
return MessageLevel::Warning;
|
return MessageLevel::Warning;
|
||||||
else if (levelName == "Error")
|
else if (levelName == "Error")
|
||||||
return MessageLevel::Error;
|
return MessageLevel::Error;
|
||||||
else if (levelName == "Fatal")
|
else if (levelName == "Fatal")
|
||||||
return MessageLevel::Fatal;
|
return MessageLevel::Fatal;
|
||||||
// Skip PrePost, it's not exposed to !![]!
|
// Skip PrePost, it's not exposed to !![]!
|
||||||
// Also skip StdErr and StdOut
|
// Also skip StdErr and StdOut
|
||||||
else
|
else
|
||||||
return MessageLevel::Unknown;
|
return MessageLevel::Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLevel::Enum MessageLevel::fromLine(QString &line)
|
MessageLevel::Enum MessageLevel::fromLine(QString &line)
|
||||||
{
|
{
|
||||||
// Level prefix
|
// Level prefix
|
||||||
int endmark = line.indexOf("]!");
|
int endmark = line.indexOf("]!");
|
||||||
if (line.startsWith("!![") && endmark != -1)
|
if (line.startsWith("!![") && endmark != -1)
|
||||||
{
|
{
|
||||||
auto level = MessageLevel::getLevel(line.left(endmark).mid(3));
|
auto level = MessageLevel::getLevel(line.left(endmark).mid(3));
|
||||||
line = line.mid(endmark + 2);
|
line = line.mid(endmark + 2);
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
return MessageLevel::Unknown;
|
return MessageLevel::Unknown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ namespace MessageLevel
|
|||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
Unknown, /**< No idea what this is or where it came from */
|
Unknown, /**< No idea what this is or where it came from */
|
||||||
StdOut, /**< Undetermined stderr messages */
|
StdOut, /**< Undetermined stderr messages */
|
||||||
StdErr, /**< Undetermined stdout messages */
|
StdErr, /**< Undetermined stdout messages */
|
||||||
MultiMC, /**< MultiMC Messages */
|
MultiMC, /**< MultiMC Messages */
|
||||||
Debug, /**< Debug Messages */
|
Debug, /**< Debug Messages */
|
||||||
Info, /**< Info Messages */
|
Info, /**< Info Messages */
|
||||||
Message, /**< Standard Messages */
|
Message, /**< Standard Messages */
|
||||||
Warning, /**< Warnings */
|
Warning, /**< Warnings */
|
||||||
Error, /**< Errors */
|
Error, /**< Errors */
|
||||||
Fatal, /**< Fatal Errors */
|
Fatal, /**< Fatal Errors */
|
||||||
};
|
};
|
||||||
MessageLevel::Enum getLevel(const QString &levelName);
|
MessageLevel::Enum getLevel(const QString &levelName);
|
||||||
|
|
||||||
|
|||||||
@@ -1,76 +1,93 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
#include "launch/LaunchTask.h"
|
|
||||||
|
|
||||||
class NullInstance: public BaseInstance
|
class NullInstance: public BaseInstance
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
NullInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir)
|
NullInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir)
|
||||||
:BaseInstance(globalSettings, settings, rootDir)
|
:BaseInstance(globalSettings, settings, rootDir)
|
||||||
{
|
{
|
||||||
setVersionBroken(true);
|
setVersionBroken(true);
|
||||||
}
|
}
|
||||||
virtual ~NullInstance() {};
|
virtual ~NullInstance() {};
|
||||||
void saveNow() override
|
virtual bool setIntendedVersionId(QString) override
|
||||||
{
|
{
|
||||||
}
|
return false;
|
||||||
QString getStatusbarDescription() override
|
}
|
||||||
{
|
virtual QString currentVersionId() const override
|
||||||
return tr("Unknown instance type");
|
{
|
||||||
};
|
return "Null";
|
||||||
QSet< QString > traits() const override
|
};
|
||||||
{
|
virtual QString intendedVersionId() const override
|
||||||
return {};
|
{
|
||||||
};
|
return "Null";
|
||||||
QString instanceConfigFolder() const override
|
};
|
||||||
{
|
virtual void init() override
|
||||||
return instanceRoot();
|
{
|
||||||
};
|
};
|
||||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr) override
|
virtual QString getStatusbarDescription() override
|
||||||
{
|
{
|
||||||
return nullptr;
|
return tr("Unknown instance type");
|
||||||
}
|
};
|
||||||
shared_qobject_ptr< Task > createUpdateTask(Net::Mode mode) override
|
virtual bool shouldUpdate() const override
|
||||||
{
|
{
|
||||||
return nullptr;
|
return false;
|
||||||
}
|
};
|
||||||
QProcessEnvironment createEnvironment() override
|
virtual QSet< QString > traits() override
|
||||||
{
|
{
|
||||||
return QProcessEnvironment();
|
return {};
|
||||||
}
|
};
|
||||||
QMap<QString, QString> getVariables() const override
|
virtual QString instanceConfigFolder() const override
|
||||||
{
|
{
|
||||||
return QMap<QString, QString>();
|
return instanceRoot();
|
||||||
}
|
};
|
||||||
IPathMatcher::Ptr getLogFileMatcher() override
|
virtual std::shared_ptr<LaunchTask> createLaunchTask(AuthSessionPtr) override
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
QString getLogFileRoot() override
|
virtual shared_qobject_ptr< Task > createUpdateTask() override
|
||||||
{
|
{
|
||||||
return instanceRoot();
|
return nullptr;
|
||||||
}
|
}
|
||||||
QString typeName() const override
|
virtual std::shared_ptr<Task> createJarModdingTask() override
|
||||||
{
|
{
|
||||||
return "Null";
|
return nullptr;
|
||||||
}
|
}
|
||||||
bool canExport() const override
|
virtual void setShouldUpdate(bool) override
|
||||||
{
|
{
|
||||||
return false;
|
};
|
||||||
}
|
virtual std::shared_ptr< BaseVersionList > versionList() const override
|
||||||
bool canEdit() const override
|
{
|
||||||
{
|
return nullptr;
|
||||||
return false;
|
};
|
||||||
}
|
virtual QProcessEnvironment createEnvironment() override
|
||||||
bool canLaunch() const override
|
{
|
||||||
{
|
return QProcessEnvironment();
|
||||||
return false;
|
}
|
||||||
}
|
virtual QMap<QString, QString> getVariables() const override
|
||||||
QStringList verboseDescription(AuthSessionPtr session) override
|
{
|
||||||
{
|
return QMap<QString, QString>();
|
||||||
QStringList out;
|
}
|
||||||
out << "Null instance - placeholder.";
|
virtual IPathMatcher::Ptr getLogFileMatcher() override
|
||||||
return out;
|
{
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
|
virtual QString getLogFileRoot() override
|
||||||
|
{
|
||||||
|
return instanceRoot();
|
||||||
|
}
|
||||||
|
virtual QString typeName() const override
|
||||||
|
{
|
||||||
|
return "Null";
|
||||||
|
}
|
||||||
|
bool canExport() const override
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QStringList verboseDescription(AuthSessionPtr session) override
|
||||||
|
{
|
||||||
|
QStringList out;
|
||||||
|
out << "Null instance - placeholder.";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
|
||||||
|
|
||||||
enum class ProblemSeverity
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Warning,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PatchProblem
|
|
||||||
{
|
|
||||||
ProblemSeverity m_severity;
|
|
||||||
QString m_description;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT ProblemProvider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~ProblemProvider() {};
|
|
||||||
virtual const QList<PatchProblem> getProblems() const = 0;
|
|
||||||
virtual ProblemSeverity getProblemSeverity() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT ProblemContainer : public ProblemProvider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
const QList<PatchProblem> getProblems() const override
|
|
||||||
{
|
|
||||||
return m_problems;
|
|
||||||
}
|
|
||||||
ProblemSeverity getProblemSeverity() const override
|
|
||||||
{
|
|
||||||
return m_problemSeverity;
|
|
||||||
}
|
|
||||||
virtual void addProblem(ProblemSeverity severity, const QString &description)
|
|
||||||
{
|
|
||||||
if(severity > m_problemSeverity)
|
|
||||||
{
|
|
||||||
m_problemSeverity = severity;
|
|
||||||
}
|
|
||||||
m_problems.append({severity, description});
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<PatchProblem> m_problems;
|
|
||||||
ProblemSeverity m_problemSeverity = ProblemSeverity::None;
|
|
||||||
};
|
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
||||||
struct DeleteQObjectLater
|
struct DeleteQObjectLater
|
||||||
{
|
{
|
||||||
void operator()(QObject *obj) const
|
void operator()(QObject *obj) const
|
||||||
{
|
{
|
||||||
obj->deleteLater();
|
obj->deleteLater();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -28,56 +28,56 @@ template <typename T>
|
|||||||
class shared_qobject_ptr
|
class shared_qobject_ptr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
shared_qobject_ptr(){}
|
shared_qobject_ptr(){}
|
||||||
shared_qobject_ptr(T * wrap)
|
shared_qobject_ptr(T * wrap)
|
||||||
{
|
{
|
||||||
reset(wrap);
|
reset(wrap);
|
||||||
}
|
}
|
||||||
shared_qobject_ptr(const shared_qobject_ptr<T>& other)
|
shared_qobject_ptr(const shared_qobject_ptr<T>& other)
|
||||||
{
|
{
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
}
|
}
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
shared_qobject_ptr(const shared_qobject_ptr<Derived> &other)
|
shared_qobject_ptr(const shared_qobject_ptr<Derived> &other)
|
||||||
{
|
{
|
||||||
m_ptr = other.unwrap();
|
m_ptr = other.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void reset(T * wrap)
|
void reset(T * wrap)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
m_ptr.reset(wrap, std::bind(&QObject::deleteLater, _1));
|
m_ptr.reset(wrap, std::bind(&QObject::deleteLater, _1));
|
||||||
}
|
}
|
||||||
void reset(const shared_qobject_ptr<T> &other)
|
void reset(const shared_qobject_ptr<T> &other)
|
||||||
{
|
{
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
}
|
}
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
m_ptr.reset();
|
m_ptr.reset();
|
||||||
}
|
}
|
||||||
T * get() const
|
T * get() const
|
||||||
{
|
{
|
||||||
return m_ptr.get();
|
return m_ptr.get();
|
||||||
}
|
}
|
||||||
T * operator->() const
|
T * operator->() const
|
||||||
{
|
{
|
||||||
return m_ptr.get();
|
return m_ptr.get();
|
||||||
}
|
}
|
||||||
T & operator*() const
|
T & operator*() const
|
||||||
{
|
{
|
||||||
return *m_ptr.get();
|
return *m_ptr.get();
|
||||||
}
|
}
|
||||||
operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
return m_ptr.get() != nullptr;
|
return m_ptr.get() != nullptr;
|
||||||
}
|
}
|
||||||
const std::shared_ptr <T> unwrap() const
|
const std::shared_ptr <T> unwrap() const
|
||||||
{
|
{
|
||||||
return m_ptr;
|
return m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr <T> m_ptr;
|
std::shared_ptr <T> m_ptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,63 +1,60 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QWriteLocker>
|
|
||||||
#include <QReadLocker>
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
class RWStorage
|
class RWStorage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void add(K key, V value)
|
void add(K key, V value)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&lock);
|
QWriteLocker l(&lock);
|
||||||
cache[key] = value;
|
cache[key] = value;
|
||||||
stale_entries.remove(key);
|
stale_entries.remove(key);
|
||||||
}
|
}
|
||||||
V get(K key)
|
V get(K key)
|
||||||
{
|
{
|
||||||
QReadLocker l(&lock);
|
QReadLocker l(&lock);
|
||||||
if(cache.contains(key))
|
if(cache.contains(key))
|
||||||
{
|
{
|
||||||
return cache[key];
|
return cache[key];
|
||||||
}
|
}
|
||||||
else return V();
|
else return V();
|
||||||
}
|
}
|
||||||
bool get(K key, V& value)
|
bool get(K key, V& value)
|
||||||
{
|
{
|
||||||
QReadLocker l(&lock);
|
QReadLocker l(&lock);
|
||||||
if(cache.contains(key))
|
if(cache.contains(key))
|
||||||
{
|
{
|
||||||
value = cache[key];
|
value = cache[key];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
bool has(K key)
|
bool has(K key)
|
||||||
{
|
{
|
||||||
QReadLocker l(&lock);
|
QReadLocker l(&lock);
|
||||||
return cache.contains(key);
|
return cache.contains(key);
|
||||||
}
|
}
|
||||||
bool stale(K key)
|
bool stale(K key)
|
||||||
{
|
{
|
||||||
QReadLocker l(&lock);
|
QReadLocker l(&lock);
|
||||||
if(!cache.contains(key))
|
if(!cache.contains(key))
|
||||||
return true;
|
return true;
|
||||||
return stale_entries.contains(key);
|
return stale_entries.contains(key);
|
||||||
}
|
}
|
||||||
void setStale(K key)
|
void setStale(K key)
|
||||||
{
|
{
|
||||||
QWriteLocker l(&lock);
|
QReadLocker l(&lock);
|
||||||
if(cache.contains(key))
|
if(cache.contains(key))
|
||||||
{
|
{
|
||||||
stale_entries.insert(key);
|
stale_entries.insert(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
QWriteLocker l(&lock);
|
QWriteLocker l(&lock);
|
||||||
cache.clear();
|
cache.clear();
|
||||||
stale_entries.clear();
|
}
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
QReadWriteLock lock;
|
QReadWriteLock lock;
|
||||||
QMap<K, V> cache;
|
QMap<K, V> cache;
|
||||||
QSet<K> stale_entries;
|
QSet<K> stale_entries;
|
||||||
};
|
};
|
||||||
@@ -4,108 +4,108 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject *parent)
|
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject *parent)
|
||||||
: QObject(parent), m_watcher(new QFileSystemWatcher(this))
|
: QObject(parent), m_watcher(new QFileSystemWatcher(this))
|
||||||
{
|
{
|
||||||
connect(m_watcher, &QFileSystemWatcher::fileChanged, this,
|
connect(m_watcher, &QFileSystemWatcher::fileChanged, this,
|
||||||
&RecursiveFileSystemWatcher::fileChange);
|
&RecursiveFileSystemWatcher::fileChange);
|
||||||
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this,
|
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this,
|
||||||
&RecursiveFileSystemWatcher::directoryChange);
|
&RecursiveFileSystemWatcher::directoryChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecursiveFileSystemWatcher::setRootDir(const QDir &root)
|
void RecursiveFileSystemWatcher::setRootDir(const QDir &root)
|
||||||
{
|
{
|
||||||
bool wasEnabled = m_isEnabled;
|
bool wasEnabled = m_isEnabled;
|
||||||
disable();
|
disable();
|
||||||
m_root = root;
|
m_root = root;
|
||||||
setFiles(scanRecursive(m_root));
|
setFiles(scanRecursive(m_root));
|
||||||
if (wasEnabled)
|
if (wasEnabled)
|
||||||
{
|
{
|
||||||
enable();
|
enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void RecursiveFileSystemWatcher::setWatchFiles(const bool watchFiles)
|
void RecursiveFileSystemWatcher::setWatchFiles(const bool watchFiles)
|
||||||
{
|
{
|
||||||
bool wasEnabled = m_isEnabled;
|
bool wasEnabled = m_isEnabled;
|
||||||
disable();
|
disable();
|
||||||
m_watchFiles = watchFiles;
|
m_watchFiles = watchFiles;
|
||||||
if (wasEnabled)
|
if (wasEnabled)
|
||||||
{
|
{
|
||||||
enable();
|
enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecursiveFileSystemWatcher::enable()
|
void RecursiveFileSystemWatcher::enable()
|
||||||
{
|
{
|
||||||
if (m_isEnabled)
|
if (m_isEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Q_ASSERT(m_root != QDir::root());
|
Q_ASSERT(m_root != QDir::root());
|
||||||
addFilesToWatcherRecursive(m_root);
|
addFilesToWatcherRecursive(m_root);
|
||||||
m_isEnabled = true;
|
m_isEnabled = true;
|
||||||
}
|
}
|
||||||
void RecursiveFileSystemWatcher::disable()
|
void RecursiveFileSystemWatcher::disable()
|
||||||
{
|
{
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_isEnabled = false;
|
m_isEnabled = false;
|
||||||
m_watcher->removePaths(m_watcher->files());
|
m_watcher->removePaths(m_watcher->files());
|
||||||
m_watcher->removePaths(m_watcher->directories());
|
m_watcher->removePaths(m_watcher->directories());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecursiveFileSystemWatcher::setFiles(const QStringList &files)
|
void RecursiveFileSystemWatcher::setFiles(const QStringList &files)
|
||||||
{
|
{
|
||||||
if (files != m_files)
|
if (files != m_files)
|
||||||
{
|
{
|
||||||
m_files = files;
|
m_files = files;
|
||||||
emit filesChanged();
|
emit filesChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir)
|
void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir)
|
||||||
{
|
{
|
||||||
m_watcher->addPath(dir.absolutePath());
|
m_watcher->addPath(dir.absolutePath());
|
||||||
for (const QString &directory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
|
for (const QString &directory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
|
||||||
{
|
{
|
||||||
addFilesToWatcherRecursive(dir.absoluteFilePath(directory));
|
addFilesToWatcherRecursive(dir.absoluteFilePath(directory));
|
||||||
}
|
}
|
||||||
if (m_watchFiles)
|
if (m_watchFiles)
|
||||||
{
|
{
|
||||||
for (const QFileInfo &info : dir.entryInfoList(QDir::Files))
|
for (const QFileInfo &info : dir.entryInfoList(QDir::Files))
|
||||||
{
|
{
|
||||||
m_watcher->addPath(info.absoluteFilePath());
|
m_watcher->addPath(info.absoluteFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &directory)
|
QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &directory)
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
if(!m_matcher)
|
if(!m_matcher)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
for (const QString &dir : directory.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden))
|
for (const QString &dir : directory.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden))
|
||||||
{
|
{
|
||||||
ret.append(scanRecursive(directory.absoluteFilePath(dir)));
|
ret.append(scanRecursive(directory.absoluteFilePath(dir)));
|
||||||
}
|
}
|
||||||
for (const QString &file : directory.entryList(QDir::Files | QDir::Hidden))
|
for (const QString &file : directory.entryList(QDir::Files | QDir::Hidden))
|
||||||
{
|
{
|
||||||
auto relPath = m_root.relativeFilePath(directory.absoluteFilePath(file));
|
auto relPath = m_root.relativeFilePath(directory.absoluteFilePath(file));
|
||||||
if (m_matcher->matches(relPath))
|
if (m_matcher->matches(relPath))
|
||||||
{
|
{
|
||||||
ret.append(relPath);
|
ret.append(relPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecursiveFileSystemWatcher::fileChange(const QString &path)
|
void RecursiveFileSystemWatcher::fileChange(const QString &path)
|
||||||
{
|
{
|
||||||
emit fileChanged(path);
|
emit fileChanged(path);
|
||||||
}
|
}
|
||||||
void RecursiveFileSystemWatcher::directoryChange(const QString &path)
|
void RecursiveFileSystemWatcher::directoryChange(const QString &path)
|
||||||
{
|
{
|
||||||
setFiles(scanRecursive(m_root));
|
setFiles(scanRecursive(m_root));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,56 +8,56 @@
|
|||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT RecursiveFileSystemWatcher : public QObject
|
class MULTIMC_LOGIC_EXPORT RecursiveFileSystemWatcher : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RecursiveFileSystemWatcher(QObject *parent);
|
RecursiveFileSystemWatcher(QObject *parent);
|
||||||
|
|
||||||
void setRootDir(const QDir &root);
|
void setRootDir(const QDir &root);
|
||||||
QDir rootDir() const
|
QDir rootDir() const
|
||||||
{
|
{
|
||||||
return m_root;
|
return m_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WARNING: setting this to true may be bad for performance
|
// WARNING: setting this to true may be bad for performance
|
||||||
void setWatchFiles(const bool watchFiles);
|
void setWatchFiles(const bool watchFiles);
|
||||||
bool watchFiles() const
|
bool watchFiles() const
|
||||||
{
|
{
|
||||||
return m_watchFiles;
|
return m_watchFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatcher(IPathMatcher::Ptr matcher)
|
void setMatcher(IPathMatcher::Ptr matcher)
|
||||||
{
|
{
|
||||||
m_matcher = matcher;
|
m_matcher = matcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList files() const
|
QStringList files() const
|
||||||
{
|
{
|
||||||
return m_files;
|
return m_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filesChanged();
|
void filesChanged();
|
||||||
void fileChanged(const QString &path);
|
void fileChanged(const QString &path);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDir m_root;
|
QDir m_root;
|
||||||
bool m_watchFiles = false;
|
bool m_watchFiles = false;
|
||||||
bool m_isEnabled = false;
|
bool m_isEnabled = false;
|
||||||
IPathMatcher::Ptr m_matcher;
|
IPathMatcher::Ptr m_matcher;
|
||||||
|
|
||||||
QFileSystemWatcher *m_watcher;
|
QFileSystemWatcher *m_watcher;
|
||||||
|
|
||||||
QStringList m_files;
|
QStringList m_files;
|
||||||
void setFiles(const QStringList &files);
|
void setFiles(const QStringList &files);
|
||||||
|
|
||||||
void addFilesToWatcherRecursive(const QDir &dir);
|
void addFilesToWatcherRecursive(const QDir &dir);
|
||||||
QStringList scanRecursive(const QDir &dir);
|
QStringList scanRecursive(const QDir &dir);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void fileChange(const QString &path);
|
void fileChange(const QString &path);
|
||||||
void directoryChange(const QString &path);
|
void directoryChange(const QString &path);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,292 +7,292 @@ template <char Tseparator>
|
|||||||
class SeparatorPrefixTree
|
class SeparatorPrefixTree
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SeparatorPrefixTree(QStringList paths)
|
SeparatorPrefixTree(QStringList paths)
|
||||||
{
|
{
|
||||||
insert(paths);
|
insert(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
SeparatorPrefixTree(bool contained = false)
|
SeparatorPrefixTree(bool contained = false)
|
||||||
{
|
{
|
||||||
m_contained = contained;
|
m_contained = contained;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(QStringList paths)
|
void insert(QStringList paths)
|
||||||
{
|
{
|
||||||
for(auto &path: paths)
|
for(auto &path: paths)
|
||||||
{
|
{
|
||||||
insert(path);
|
insert(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// insert an exact path into the tree
|
/// insert an exact path into the tree
|
||||||
SeparatorPrefixTree & insert(QString path)
|
SeparatorPrefixTree & insert(QString path)
|
||||||
{
|
{
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
children[path] = SeparatorPrefixTree(true);
|
children[path] = SeparatorPrefixTree(true);
|
||||||
return children[path];
|
return children[path];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto prefix = path.left(sepIndex);
|
auto prefix = path.left(sepIndex);
|
||||||
if(!children.contains(prefix))
|
if(!children.contains(prefix))
|
||||||
{
|
{
|
||||||
children[prefix] = SeparatorPrefixTree(false);
|
children[prefix] = SeparatorPrefixTree(false);
|
||||||
}
|
}
|
||||||
return children[prefix].insert(path.mid(sepIndex + 1));
|
return children[prefix].insert(path.mid(sepIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// is the path fully contained in the tree?
|
/// is the path fully contained in the tree?
|
||||||
bool contains(QString path) const
|
bool contains(QString path) const
|
||||||
{
|
{
|
||||||
auto node = find(path);
|
auto node = find(path);
|
||||||
return node != nullptr;
|
return node != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// does the tree cover a path? That means the prefix of the path is contained in the tree
|
/// does the tree cover a path? That means the prefix of the path is contained in the tree
|
||||||
bool covers(QString path) const
|
bool covers(QString path) const
|
||||||
{
|
{
|
||||||
// if we found some valid node, it's good enough. the tree covers the path
|
// if we found some valid node, it's good enough. the tree covers the path
|
||||||
if(m_contained)
|
if(m_contained)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
auto found = children.find(path);
|
auto found = children.find(path);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (*found).covers(QString());
|
return (*found).covers(QString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto prefix = path.left(sepIndex);
|
auto prefix = path.left(sepIndex);
|
||||||
auto found = children.find(prefix);
|
auto found = children.find(prefix);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (*found).covers(path.mid(sepIndex + 1));
|
return (*found).covers(path.mid(sepIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return the contained path that covers the path specified
|
/// return the contained path that covers the path specified
|
||||||
QString cover(QString path) const
|
QString cover(QString path) const
|
||||||
{
|
{
|
||||||
// if we found some valid node, it's good enough. the tree covers the path
|
// if we found some valid node, it's good enough. the tree covers the path
|
||||||
if(m_contained)
|
if(m_contained)
|
||||||
{
|
{
|
||||||
return QString("");
|
return QString("");
|
||||||
}
|
}
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
auto found = children.find(path);
|
auto found = children.find(path);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
auto nested = (*found).cover(QString());
|
auto nested = (*found).cover(QString());
|
||||||
if(nested.isNull())
|
if(nested.isNull())
|
||||||
{
|
{
|
||||||
return nested;
|
return nested;
|
||||||
}
|
}
|
||||||
if(nested.isEmpty())
|
if(nested.isEmpty())
|
||||||
return path;
|
return path;
|
||||||
return path + Tseparator + nested;
|
return path + Tseparator + nested;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto prefix = path.left(sepIndex);
|
auto prefix = path.left(sepIndex);
|
||||||
auto found = children.find(prefix);
|
auto found = children.find(prefix);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
auto nested = (*found).cover(path.mid(sepIndex + 1));
|
auto nested = (*found).cover(path.mid(sepIndex + 1));
|
||||||
if(nested.isNull())
|
if(nested.isNull())
|
||||||
{
|
{
|
||||||
return nested;
|
return nested;
|
||||||
}
|
}
|
||||||
if(nested.isEmpty())
|
if(nested.isEmpty())
|
||||||
return prefix;
|
return prefix;
|
||||||
return prefix + Tseparator + nested;
|
return prefix + Tseparator + nested;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does the path-specified node exist in the tree? It does not have to be contained.
|
/// Does the path-specified node exist in the tree? It does not have to be contained.
|
||||||
bool exists(QString path) const
|
bool exists(QString path) const
|
||||||
{
|
{
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
auto found = children.find(path);
|
auto found = children.find(path);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto prefix = path.left(sepIndex);
|
auto prefix = path.left(sepIndex);
|
||||||
auto found = children.find(prefix);
|
auto found = children.find(prefix);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (*found).exists(path.mid(sepIndex + 1));
|
return (*found).exists(path.mid(sepIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// find a node in the tree by name
|
/// find a node in the tree by name
|
||||||
const SeparatorPrefixTree * find(QString path) const
|
const SeparatorPrefixTree * find(QString path) const
|
||||||
{
|
{
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
auto found = children.find(path);
|
auto found = children.find(path);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return &(*found);
|
return &(*found);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto prefix = path.left(sepIndex);
|
auto prefix = path.left(sepIndex);
|
||||||
auto found = children.find(prefix);
|
auto found = children.find(prefix);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return (*found).find(path.mid(sepIndex + 1));
|
return (*found).find(path.mid(sepIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// is this a leaf node?
|
/// is this a leaf node?
|
||||||
bool leaf() const
|
bool leaf() const
|
||||||
{
|
{
|
||||||
return children.isEmpty();
|
return children.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// is this node actually contained in the tree, or is it purely structural?
|
/// is this node actually contained in the tree, or is it purely structural?
|
||||||
bool contained() const
|
bool contained() const
|
||||||
{
|
{
|
||||||
return m_contained;
|
return m_contained;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a path from the tree
|
/// Remove a path from the tree
|
||||||
bool remove(QString path)
|
bool remove(QString path)
|
||||||
{
|
{
|
||||||
return removeInternal(path) != Failed;
|
return removeInternal(path) != Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all children of this node tree node
|
/// Clear all children of this node tree node
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
children.clear();
|
children.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList toStringList() const
|
QStringList toStringList() const
|
||||||
{
|
{
|
||||||
QStringList collected;
|
QStringList collected;
|
||||||
// collecting these is more expensive.
|
// collecting these is more expensive.
|
||||||
auto iter = children.begin();
|
auto iter = children.begin();
|
||||||
while(iter != children.end())
|
while(iter != children.end())
|
||||||
{
|
{
|
||||||
QStringList list = iter.value().toStringList();
|
QStringList list = iter.value().toStringList();
|
||||||
for(int i = 0; i < list.size(); i++)
|
for(int i = 0; i < list.size(); i++)
|
||||||
{
|
{
|
||||||
list[i] = iter.key() + Tseparator + list[i];
|
list[i] = iter.key() + Tseparator + list[i];
|
||||||
}
|
}
|
||||||
collected.append(list);
|
collected.append(list);
|
||||||
if((*iter).m_contained)
|
if((*iter).m_contained)
|
||||||
{
|
{
|
||||||
collected.append(iter.key());
|
collected.append(iter.key());
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
return collected;
|
return collected;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
enum Removal
|
enum Removal
|
||||||
{
|
{
|
||||||
Failed,
|
Failed,
|
||||||
Succeeded,
|
Succeeded,
|
||||||
HasChildren
|
HasChildren
|
||||||
};
|
};
|
||||||
Removal removeInternal(QString path = QString())
|
Removal removeInternal(QString path = QString())
|
||||||
{
|
{
|
||||||
if(path.isEmpty())
|
if(path.isEmpty())
|
||||||
{
|
{
|
||||||
if(!m_contained)
|
if(!m_contained)
|
||||||
{
|
{
|
||||||
// remove all children - we are removing a prefix
|
// remove all children - we are removing a prefix
|
||||||
clear();
|
clear();
|
||||||
return Succeeded;
|
return Succeeded;
|
||||||
}
|
}
|
||||||
m_contained = false;
|
m_contained = false;
|
||||||
if(children.size())
|
if(children.size())
|
||||||
{
|
{
|
||||||
return HasChildren;
|
return HasChildren;
|
||||||
}
|
}
|
||||||
return Succeeded;
|
return Succeeded;
|
||||||
}
|
}
|
||||||
Removal remStatus = Failed;
|
Removal remStatus = Failed;
|
||||||
QString childToRemove;
|
QString childToRemove;
|
||||||
auto sepIndex = path.indexOf(Tseparator);
|
auto sepIndex = path.indexOf(Tseparator);
|
||||||
if(sepIndex == -1)
|
if(sepIndex == -1)
|
||||||
{
|
{
|
||||||
childToRemove = path;
|
childToRemove = path;
|
||||||
auto found = children.find(childToRemove);
|
auto found = children.find(childToRemove);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
remStatus = (*found).removeInternal();
|
remStatus = (*found).removeInternal();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
childToRemove = path.left(sepIndex);
|
childToRemove = path.left(sepIndex);
|
||||||
auto found = children.find(childToRemove);
|
auto found = children.find(childToRemove);
|
||||||
if(found == children.end())
|
if(found == children.end())
|
||||||
{
|
{
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
remStatus = (*found).removeInternal(path.mid(sepIndex + 1));
|
remStatus = (*found).removeInternal(path.mid(sepIndex + 1));
|
||||||
}
|
}
|
||||||
switch (remStatus)
|
switch (remStatus)
|
||||||
{
|
{
|
||||||
case Failed:
|
case Failed:
|
||||||
case HasChildren:
|
case HasChildren:
|
||||||
{
|
{
|
||||||
return remStatus;
|
return remStatus;
|
||||||
}
|
}
|
||||||
case Succeeded:
|
case Succeeded:
|
||||||
{
|
{
|
||||||
children.remove(childToRemove);
|
children.remove(childToRemove);
|
||||||
if(m_contained)
|
if(m_contained)
|
||||||
{
|
{
|
||||||
return HasChildren;
|
return HasChildren;
|
||||||
}
|
}
|
||||||
if(children.size())
|
if(children.size())
|
||||||
{
|
{
|
||||||
return HasChildren;
|
return HasChildren;
|
||||||
}
|
}
|
||||||
return Succeeded;
|
return Succeeded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString,SeparatorPrefixTree<Tseparator>> children;
|
QMap<QString,SeparatorPrefixTree<Tseparator>> children;
|
||||||
bool m_contained = false;
|
bool m_contained = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,27 +12,27 @@ class Usable;
|
|||||||
*/
|
*/
|
||||||
class Usable
|
class Usable
|
||||||
{
|
{
|
||||||
friend class UseLock;
|
friend class UseLock;
|
||||||
public:
|
public:
|
||||||
std::size_t useCount()
|
std::size_t useCount()
|
||||||
{
|
{
|
||||||
return m_useCount;
|
return m_useCount;
|
||||||
}
|
}
|
||||||
bool isInUse()
|
bool isInUse()
|
||||||
{
|
{
|
||||||
return m_useCount > 0;
|
return m_useCount > 0;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual void decrementUses()
|
virtual void decrementUses()
|
||||||
{
|
{
|
||||||
m_useCount--;
|
m_useCount--;
|
||||||
}
|
}
|
||||||
virtual void incrementUses()
|
virtual void incrementUses()
|
||||||
{
|
{
|
||||||
m_useCount++;
|
m_useCount++;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::size_t m_useCount = 0;
|
std::size_t m_useCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,16 +43,16 @@ private:
|
|||||||
class UseLock
|
class UseLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UseLock(std::shared_ptr<Usable> usable)
|
UseLock(std::shared_ptr<Usable> usable)
|
||||||
: m_usable(usable)
|
: m_usable(usable)
|
||||||
{
|
{
|
||||||
// this doesn't use shared pointer use count, because that wouldn't be correct. this count is separate.
|
// this doesn't use shared pointer use count, because that wouldn't be correct. this count is separate.
|
||||||
m_usable->incrementUses();
|
m_usable->incrementUses();
|
||||||
}
|
}
|
||||||
~UseLock()
|
~UseLock()
|
||||||
{
|
{
|
||||||
m_usable->decrementUses();
|
m_usable->decrementUses();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Usable> m_usable;
|
std::shared_ptr<Usable> m_usable;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,79 +7,134 @@
|
|||||||
|
|
||||||
Version::Version(const QString &str) : m_string(str)
|
Version::Version(const QString &str) : m_string(str)
|
||||||
{
|
{
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Version::operator<(const Version &other) const
|
bool Version::operator<(const Version &other) const
|
||||||
{
|
{
|
||||||
const int size = qMax(m_sections.size(), other.m_sections.size());
|
const int size = qMax(m_sections.size(), other.m_sections.size());
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
||||||
const Section sec2 =
|
const Section sec2 =
|
||||||
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
||||||
if (sec1 != sec2)
|
if (sec1 != sec2)
|
||||||
{
|
{
|
||||||
return sec1 < sec2;
|
return sec1 < sec2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Version::operator<=(const Version &other) const
|
bool Version::operator<=(const Version &other) const
|
||||||
{
|
{
|
||||||
return *this < other || *this == other;
|
return *this < other || *this == other;
|
||||||
}
|
}
|
||||||
bool Version::operator>(const Version &other) const
|
bool Version::operator>(const Version &other) const
|
||||||
{
|
{
|
||||||
const int size = qMax(m_sections.size(), other.m_sections.size());
|
const int size = qMax(m_sections.size(), other.m_sections.size());
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
||||||
const Section sec2 =
|
const Section sec2 =
|
||||||
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
||||||
if (sec1 != sec2)
|
if (sec1 != sec2)
|
||||||
{
|
{
|
||||||
return sec1 > sec2;
|
return sec1 > sec2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Version::operator>=(const Version &other) const
|
bool Version::operator>=(const Version &other) const
|
||||||
{
|
{
|
||||||
return *this > other || *this == other;
|
return *this > other || *this == other;
|
||||||
}
|
}
|
||||||
bool Version::operator==(const Version &other) const
|
bool Version::operator==(const Version &other) const
|
||||||
{
|
{
|
||||||
const int size = qMax(m_sections.size(), other.m_sections.size());
|
const int size = qMax(m_sections.size(), other.m_sections.size());
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
|
||||||
const Section sec2 =
|
const Section sec2 =
|
||||||
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
(i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
|
||||||
if (sec1 != sec2)
|
if (sec1 != sec2)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Version::operator!=(const Version &other) const
|
bool Version::operator!=(const Version &other) const
|
||||||
{
|
{
|
||||||
return !operator==(other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Version::parse()
|
void Version::parse()
|
||||||
{
|
{
|
||||||
m_sections.clear();
|
m_sections.clear();
|
||||||
|
|
||||||
// FIXME: this is bad. versions can contain a lot more separators...
|
QStringList parts = m_string.split('.');
|
||||||
QStringList parts = m_string.split('.');
|
|
||||||
|
|
||||||
for (const auto part : parts)
|
for (const auto part : parts)
|
||||||
{
|
{
|
||||||
m_sections.append(Section(part));
|
m_sections.append(Section(part));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool versionIsInInterval(const QString &version, const QString &interval)
|
||||||
|
{
|
||||||
|
return versionIsInInterval(Version(version), interval);
|
||||||
|
}
|
||||||
|
bool versionIsInInterval(const Version &version, const QString &interval)
|
||||||
|
{
|
||||||
|
if (interval.isEmpty() || version.toString() == interval)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interval notation is used
|
||||||
|
QRegularExpression exp(
|
||||||
|
"(?<start>[\\[\\]\\(\\)])(?<bottom>.*?)(,(?<top>.*?))?(?<end>[\\[\\]\\(\\)]),?");
|
||||||
|
QRegularExpressionMatch match = exp.match(interval);
|
||||||
|
if (match.hasMatch())
|
||||||
|
{
|
||||||
|
const QChar start = match.captured("start").at(0);
|
||||||
|
const QChar end = match.captured("end").at(0);
|
||||||
|
const QString bottom = match.captured("bottom");
|
||||||
|
const QString top = match.captured("top");
|
||||||
|
|
||||||
|
// check if in range (bottom)
|
||||||
|
if (!bottom.isEmpty())
|
||||||
|
{
|
||||||
|
const auto bottomVersion = Version(bottom);
|
||||||
|
if ((start == '[') && !(version >= bottomVersion))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ((start == '(') && !(version > bottomVersion))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if in range (top)
|
||||||
|
if (!top.isEmpty())
|
||||||
|
{
|
||||||
|
const auto topVersion = Version(top);
|
||||||
|
if ((end == ']') && !(version <= topVersion))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ((end == ')') && !(version < topVersion))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,101 +7,104 @@
|
|||||||
|
|
||||||
class QUrl;
|
class QUrl;
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT Version
|
struct MULTIMC_LOGIC_EXPORT Version
|
||||||
{
|
{
|
||||||
public:
|
Version(const QString &str);
|
||||||
Version(const QString &str);
|
Version() {}
|
||||||
Version() {}
|
|
||||||
|
|
||||||
bool operator<(const Version &other) const;
|
bool operator<(const Version &other) const;
|
||||||
bool operator<=(const Version &other) const;
|
bool operator<=(const Version &other) const;
|
||||||
bool operator>(const Version &other) const;
|
bool operator>(const Version &other) const;
|
||||||
bool operator>=(const Version &other) const;
|
bool operator>=(const Version &other) const;
|
||||||
bool operator==(const Version &other) const;
|
bool operator==(const Version &other) const;
|
||||||
bool operator!=(const Version &other) const;
|
bool operator!=(const Version &other) const;
|
||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return m_string;
|
return m_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_string;
|
QString m_string;
|
||||||
struct Section
|
struct Section
|
||||||
{
|
{
|
||||||
explicit Section(const QString &fullString)
|
explicit Section(const QString &fullString)
|
||||||
{
|
{
|
||||||
m_fullString = fullString;
|
m_fullString = fullString;
|
||||||
int cutoff = m_fullString.size();
|
int cutoff = m_fullString.size();
|
||||||
for(int i = 0; i < m_fullString.size(); i++)
|
for(int i = 0; i < m_fullString.size(); i++)
|
||||||
{
|
{
|
||||||
if(!m_fullString[i].isDigit())
|
if(!m_fullString[i].isDigit())
|
||||||
{
|
{
|
||||||
cutoff = i;
|
cutoff = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto numPart = m_fullString.leftRef(cutoff);
|
auto numPart = m_fullString.leftRef(cutoff);
|
||||||
if(numPart.size())
|
if(numPart.size())
|
||||||
{
|
{
|
||||||
numValid = true;
|
numValid = true;
|
||||||
m_numPart = numPart.toInt();
|
m_numPart = numPart.toInt();
|
||||||
}
|
}
|
||||||
auto stringPart = m_fullString.midRef(cutoff);
|
auto stringPart = m_fullString.midRef(cutoff);
|
||||||
if(stringPart.size())
|
if(stringPart.size())
|
||||||
{
|
{
|
||||||
m_stringPart = stringPart.toString();
|
m_stringPart = stringPart.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
explicit Section() {}
|
explicit Section() {}
|
||||||
bool numValid = false;
|
bool numValid = false;
|
||||||
int m_numPart = 0;
|
int m_numPart = 0;
|
||||||
QString m_stringPart;
|
QString m_stringPart;
|
||||||
QString m_fullString;
|
QString m_fullString;
|
||||||
|
|
||||||
inline bool operator!=(const Section &other) const
|
inline bool operator!=(const Section &other) const
|
||||||
{
|
{
|
||||||
if(numValid && other.numValid)
|
if(numValid && other.numValid)
|
||||||
{
|
{
|
||||||
return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
|
return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_fullString != other.m_fullString;
|
return m_fullString != other.m_fullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline bool operator<(const Section &other) const
|
inline bool operator<(const Section &other) const
|
||||||
{
|
{
|
||||||
if(numValid && other.numValid)
|
if(numValid && other.numValid)
|
||||||
{
|
{
|
||||||
if(m_numPart < other.m_numPart)
|
if(m_numPart < other.m_numPart)
|
||||||
return true;
|
return true;
|
||||||
if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart)
|
if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_fullString < other.m_fullString;
|
return m_fullString < other.m_fullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline bool operator>(const Section &other) const
|
inline bool operator>(const Section &other) const
|
||||||
{
|
{
|
||||||
if(numValid && other.numValid)
|
if(numValid && other.numValid)
|
||||||
{
|
{
|
||||||
if(m_numPart > other.m_numPart)
|
if(m_numPart > other.m_numPart)
|
||||||
return true;
|
return true;
|
||||||
if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart)
|
if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_fullString > other.m_fullString;
|
return m_fullString > other.m_fullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
QList<Section> m_sections;
|
QList<Section> m_sections;
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const QString &version, const QString &interval);
|
||||||
|
MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const Version &version, const QString &interval);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -20,64 +20,102 @@
|
|||||||
|
|
||||||
class ModUtilsTest : public QObject
|
class ModUtilsTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
void setupVersions()
|
void setupVersions()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("first");
|
QTest::addColumn<QString>("first");
|
||||||
QTest::addColumn<QString>("second");
|
QTest::addColumn<QString>("second");
|
||||||
QTest::addColumn<bool>("lessThan");
|
QTest::addColumn<bool>("lessThan");
|
||||||
QTest::addColumn<bool>("equal");
|
QTest::addColumn<bool>("equal");
|
||||||
|
|
||||||
QTest::newRow("equal, explicit") << "1.2.0" << "1.2.0" << false << true;
|
QTest::newRow("equal, explicit") << "1.2.0" << "1.2.0" << false << true;
|
||||||
QTest::newRow("equal, implicit 1") << "1.2" << "1.2.0" << false << true;
|
QTest::newRow("equal, implicit 1") << "1.2" << "1.2.0" << false << true;
|
||||||
QTest::newRow("equal, implicit 2") << "1.2.0" << "1.2" << false << true;
|
QTest::newRow("equal, implicit 2") << "1.2.0" << "1.2" << false << true;
|
||||||
QTest::newRow("equal, two-digit") << "1.42" << "1.42" << false << true;
|
QTest::newRow("equal, two-digit") << "1.42" << "1.42" << false << true;
|
||||||
|
|
||||||
QTest::newRow("lessThan, explicit 1") << "1.2.0" << "1.2.1" << true << false;
|
QTest::newRow("lessThan, explicit 1") << "1.2.0" << "1.2.1" << true << false;
|
||||||
QTest::newRow("lessThan, explicit 2") << "1.2.0" << "1.3.0" << true << false;
|
QTest::newRow("lessThan, explicit 2") << "1.2.0" << "1.3.0" << true << false;
|
||||||
QTest::newRow("lessThan, explicit 3") << "1.2.0" << "2.2.0" << true << false;
|
QTest::newRow("lessThan, explicit 3") << "1.2.0" << "2.2.0" << true << false;
|
||||||
QTest::newRow("lessThan, implicit 1") << "1.2" << "1.2.1" << true << false;
|
QTest::newRow("lessThan, implicit 1") << "1.2" << "1.2.1" << true << false;
|
||||||
QTest::newRow("lessThan, implicit 2") << "1.2" << "1.3.0" << true << false;
|
QTest::newRow("lessThan, implicit 2") << "1.2" << "1.3.0" << true << false;
|
||||||
QTest::newRow("lessThan, implicit 3") << "1.2" << "2.2.0" << true << false;
|
QTest::newRow("lessThan, implicit 3") << "1.2" << "2.2.0" << true << false;
|
||||||
QTest::newRow("lessThan, two-digit") << "1.41" << "1.42" << true << false;
|
QTest::newRow("lessThan, two-digit") << "1.41" << "1.42" << true << false;
|
||||||
|
|
||||||
QTest::newRow("greaterThan, explicit 1") << "1.2.1" << "1.2.0" << false << false;
|
QTest::newRow("greaterThan, explicit 1") << "1.2.1" << "1.2.0" << false << false;
|
||||||
QTest::newRow("greaterThan, explicit 2") << "1.3.0" << "1.2.0" << false << false;
|
QTest::newRow("greaterThan, explicit 2") << "1.3.0" << "1.2.0" << false << false;
|
||||||
QTest::newRow("greaterThan, explicit 3") << "2.2.0" << "1.2.0" << false << false;
|
QTest::newRow("greaterThan, explicit 3") << "2.2.0" << "1.2.0" << false << false;
|
||||||
QTest::newRow("greaterThan, implicit 1") << "1.2.1" << "1.2" << false << false;
|
QTest::newRow("greaterThan, implicit 1") << "1.2.1" << "1.2" << false << false;
|
||||||
QTest::newRow("greaterThan, implicit 2") << "1.3.0" << "1.2" << false << false;
|
QTest::newRow("greaterThan, implicit 2") << "1.3.0" << "1.2" << false << false;
|
||||||
QTest::newRow("greaterThan, implicit 3") << "2.2.0" << "1.2" << false << false;
|
QTest::newRow("greaterThan, implicit 3") << "2.2.0" << "1.2" << false << false;
|
||||||
QTest::newRow("greaterThan, two-digit") << "1.42" << "1.41" << false << false;
|
QTest::newRow("greaterThan, two-digit") << "1.42" << "1.41" << false << false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase()
|
void initTestCase()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
void cleanupTestCase()
|
void cleanupTestCase()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_versionCompare_data()
|
void test_versionIsInInterval_data()
|
||||||
{
|
{
|
||||||
setupVersions();
|
QTest::addColumn<QString>("version");
|
||||||
}
|
QTest::addColumn<QString>("interval");
|
||||||
void test_versionCompare()
|
QTest::addColumn<bool>("result");
|
||||||
{
|
|
||||||
QFETCH(QString, first);
|
|
||||||
QFETCH(QString, second);
|
|
||||||
QFETCH(bool, lessThan);
|
|
||||||
QFETCH(bool, equal);
|
|
||||||
|
|
||||||
const auto v1 = Version(first);
|
QTest::newRow("empty, true") << "1.2.3" << "" << true;
|
||||||
const auto v2 = Version(second);
|
QTest::newRow("one version, true") << "1.2.3" << "1.2.3" << true;
|
||||||
|
QTest::newRow("one version, false") << "1.2.3" << "1.2.2" << false;
|
||||||
|
|
||||||
QCOMPARE(v1 < v2, lessThan);
|
QTest::newRow("one version inclusive <-> infinity, true") << "1.2.3" << "[1.2.3,)" << true;
|
||||||
QCOMPARE(v1 > v2, !lessThan && !equal);
|
QTest::newRow("one version exclusive <-> infinity, true") << "1.2.3" << "(1.2.2,)" << true;
|
||||||
QCOMPARE(v1 == v2, equal);
|
QTest::newRow("one version inclusive <-> infitity, false") << "1.2.3" << "[1.2.4,)" << false;
|
||||||
}
|
QTest::newRow("one version exclusive <-> infinity, false") << "1.2.3" << "(1.2.3,)" << false;
|
||||||
|
|
||||||
|
QTest::newRow("infinity <-> one version inclusive, true") << "1.2.3" << "(,1.2.3]" << true;
|
||||||
|
QTest::newRow("infinity <-> one version exclusive, true") << "1.2.3" << "(,1.2.4)" << true;
|
||||||
|
QTest::newRow("infinity <-> one version inclusive, false") << "1.2.3" << "(,1.2.2]" << false;
|
||||||
|
QTest::newRow("infinity <-> one version exclusive, false") << "1.2.3" << "(,1.2.3)" << false;
|
||||||
|
|
||||||
|
QTest::newRow("inclusive <-> inclusive, true") << "1.2.3" << "[1.2.2,1.2.3]" << true;
|
||||||
|
QTest::newRow("inclusive <-> exclusive, true") << "1.2.3" << "[1.2.3,1.2.4)" << true;
|
||||||
|
QTest::newRow("exclusive <-> inclusive, true") << "1.2.3" << "(1.2.2,1.2.3]" << true;
|
||||||
|
QTest::newRow("exclusive <-> exclusive, true") << "1.2.3" << "(1.2.2,1.2.4)" << true;
|
||||||
|
QTest::newRow("inclusive <-> inclusive, false") << "1.2.3" << "[1.0.0,1.2.2]" << false;
|
||||||
|
QTest::newRow("inclusive <-> exclusive, false") << "1.2.3" << "[1.0.0,1.2.3)" << false;
|
||||||
|
QTest::newRow("exclusive <-> inclusive, false") << "1.2.3" << "(1.2.3,2.0.0]" << false;
|
||||||
|
QTest::newRow("exclusive <-> exclusive, false") << "1.2.3" << "(1.0.0,1.2.3)" << false;
|
||||||
|
}
|
||||||
|
void test_versionIsInInterval()
|
||||||
|
{
|
||||||
|
QFETCH(QString, version);
|
||||||
|
QFETCH(QString, interval);
|
||||||
|
QFETCH(bool, result);
|
||||||
|
|
||||||
|
QCOMPARE(versionIsInInterval(version, interval), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_versionCompare_data()
|
||||||
|
{
|
||||||
|
setupVersions();
|
||||||
|
}
|
||||||
|
void test_versionCompare()
|
||||||
|
{
|
||||||
|
QFETCH(QString, first);
|
||||||
|
QFETCH(QString, second);
|
||||||
|
QFETCH(bool, lessThan);
|
||||||
|
QFETCH(bool, equal);
|
||||||
|
|
||||||
|
const auto v1 = Version(first);
|
||||||
|
const auto v2 = Version(second);
|
||||||
|
|
||||||
|
QCOMPARE(v1 < v2, lessThan);
|
||||||
|
QCOMPARE(v1 > v2, !lessThan && !equal);
|
||||||
|
QCOMPARE(v1 == v2, equal);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(ModUtilsTest)
|
QTEST_GUILESS_MAIN(ModUtilsTest)
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QFileSystemWatcher>
|
|
||||||
|
|
||||||
struct WatchLock
|
|
||||||
{
|
|
||||||
WatchLock(QFileSystemWatcher * watcher, const QString& directory)
|
|
||||||
: m_watcher(watcher), m_directory(directory)
|
|
||||||
{
|
|
||||||
m_watcher->removePath(m_directory);
|
|
||||||
}
|
|
||||||
~WatchLock()
|
|
||||||
{
|
|
||||||
m_watcher->addPath(m_directory);
|
|
||||||
}
|
|
||||||
QFileSystemWatcher * m_watcher;
|
|
||||||
QString m_directory;
|
|
||||||
};
|
|
||||||
@@ -6,21 +6,20 @@
|
|||||||
|
|
||||||
enum IconType : unsigned
|
enum IconType : unsigned
|
||||||
{
|
{
|
||||||
Builtin,
|
Builtin,
|
||||||
Transient,
|
Transient,
|
||||||
FileBased,
|
FileBased,
|
||||||
ICONS_TOTAL,
|
ICONS_TOTAL,
|
||||||
ToBeDeleted
|
ToBeDeleted
|
||||||
};
|
};
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT IIconList
|
class MULTIMC_LOGIC_EXPORT IIconList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IIconList();
|
virtual ~IIconList();
|
||||||
virtual bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) = 0;
|
virtual bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) = 0;
|
||||||
virtual bool deleteIcon(const QString &key) = 0;
|
virtual bool deleteIcon(const QString &key) = 0;
|
||||||
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
|
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
|
||||||
virtual bool iconFileExists(const QString &key) const = 0;
|
virtual bool iconFileExists(const QString &key) const = 0;
|
||||||
virtual void installIcons(const QStringList &iconFiles) = 0;
|
virtual void installIcons(const QStringList &iconFiles) = 0;
|
||||||
virtual void installIcon(const QString &file, const QString &name) = 0;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
#include "IconUtils.h"
|
|
||||||
|
|
||||||
#include "FileSystem.h"
|
|
||||||
#include <QDirIterator>
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
std::array<const char *, 6> validIconExtensions = {{
|
|
||||||
"svg",
|
|
||||||
"png",
|
|
||||||
"ico",
|
|
||||||
"gif",
|
|
||||||
"jpg",
|
|
||||||
"jpeg"
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace IconUtils{
|
|
||||||
|
|
||||||
QString findBestIconIn(const QString &folder, const QString & iconKey) {
|
|
||||||
int best_found = validIconExtensions.size();
|
|
||||||
QString best_filename;
|
|
||||||
|
|
||||||
QDirIterator it(folder, QDir::NoDotAndDotDot | QDir::Files, QDirIterator::NoIteratorFlags);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
auto fileInfo = it.fileInfo();
|
|
||||||
|
|
||||||
if(fileInfo.completeBaseName() != iconKey)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto extension = fileInfo.suffix();
|
|
||||||
|
|
||||||
for(int i = 0; i < best_found; i++) {
|
|
||||||
if(extension == validIconExtensions[i]) {
|
|
||||||
best_found = i;
|
|
||||||
qDebug() << i << " : " << fileInfo.fileName();
|
|
||||||
best_filename = fileInfo.fileName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FS::PathCombine(folder, best_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getIconFilter() {
|
|
||||||
QString out;
|
|
||||||
QTextStream stream(&out);
|
|
||||||
stream << '(';
|
|
||||||
for(size_t i = 0; i < validIconExtensions.size() - 1; i++) {
|
|
||||||
if(i > 0) {
|
|
||||||
stream << " ";
|
|
||||||
}
|
|
||||||
stream << "*." << validIconExtensions[i];
|
|
||||||
}
|
|
||||||
stream << " *." << validIconExtensions[validIconExtensions.size() - 1];
|
|
||||||
stream << ')';
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include "multimc_logic_export.h"
|
|
||||||
|
|
||||||
namespace IconUtils {
|
|
||||||
|
|
||||||
// Given a folder and an icon key, find 'best' of the icons with the given key in there and return its path
|
|
||||||
MULTIMC_LOGIC_EXPORT QString findBestIconIn(const QString &folder, const QString & iconKey);
|
|
||||||
|
|
||||||
// Get icon file type filter for file browser dialogs
|
|
||||||
MULTIMC_LOGIC_EXPORT QString getIconFilter();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "JavaChecker.h"
|
#include "JavaChecker.h"
|
||||||
#include "JavaUtils.h"
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
#include <Commandline.h>
|
#include <Commandline.h>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -8,157 +7,154 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "Env.h"
|
|
||||||
|
|
||||||
JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
|
JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::performCheck()
|
void JavaChecker::performCheck()
|
||||||
{
|
{
|
||||||
QString checkerJar = FS::PathCombine(ENV.getJarsPath(), "JavaCheck.jar");
|
QString checkerJar = FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar");
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
|
|
||||||
process.reset(new QProcess());
|
process.reset(new QProcess());
|
||||||
if(m_args.size())
|
if(m_args.size())
|
||||||
{
|
{
|
||||||
auto extraArgs = Commandline::splitArgs(m_args);
|
auto extraArgs = Commandline::splitArgs(m_args);
|
||||||
args.append(extraArgs);
|
args.append(extraArgs);
|
||||||
}
|
}
|
||||||
if(m_minMem != 0)
|
if(m_minMem != 0)
|
||||||
{
|
{
|
||||||
args << QString("-Xms%1m").arg(m_minMem);
|
args << QString("-Xms%1m").arg(m_minMem);
|
||||||
}
|
}
|
||||||
if(m_maxMem != 0)
|
if(m_maxMem != 0)
|
||||||
{
|
{
|
||||||
args << QString("-Xmx%1m").arg(m_maxMem);
|
args << QString("-Xmx%1m").arg(m_maxMem);
|
||||||
}
|
}
|
||||||
if(m_permGen != 64)
|
if(m_permGen != 64)
|
||||||
{
|
{
|
||||||
args << QString("-XX:PermSize=%1m").arg(m_permGen);
|
args << QString("-XX:PermSize=%1m").arg(m_permGen);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.append({"-jar", checkerJar});
|
args.append({"-jar", checkerJar});
|
||||||
process->setArguments(args);
|
process->setArguments(args);
|
||||||
process->setProgram(m_path);
|
process->setProgram(m_path);
|
||||||
process->setProcessChannelMode(QProcess::SeparateChannels);
|
process->setProcessChannelMode(QProcess::SeparateChannels);
|
||||||
process->setProcessEnvironment(CleanEnviroment());
|
qDebug() << "Running java checker: " + m_path + args.join(" ");;
|
||||||
qDebug() << "Running java checker: " + m_path + args.join(" ");;
|
|
||||||
|
|
||||||
connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
|
connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
|
||||||
connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
|
connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
|
||||||
connect(process.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(stdoutReady()));
|
connect(process.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(stdoutReady()));
|
||||||
connect(process.get(), SIGNAL(readyReadStandardError()), this, SLOT(stderrReady()));
|
connect(process.get(), SIGNAL(readyReadStandardError()), this, SLOT(stderrReady()));
|
||||||
connect(&killTimer, SIGNAL(timeout()), SLOT(timeout()));
|
connect(&killTimer, SIGNAL(timeout()), SLOT(timeout()));
|
||||||
killTimer.setSingleShot(true);
|
killTimer.setSingleShot(true);
|
||||||
killTimer.start(15000);
|
killTimer.start(15000);
|
||||||
process->start();
|
process->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::stdoutReady()
|
void JavaChecker::stdoutReady()
|
||||||
{
|
{
|
||||||
QByteArray data = process->readAllStandardOutput();
|
QByteArray data = process->readAllStandardOutput();
|
||||||
QString added = QString::fromLocal8Bit(data);
|
QString added = QString::fromLocal8Bit(data);
|
||||||
added.remove('\r');
|
added.remove('\r');
|
||||||
m_stdout += added;
|
m_stdout += added;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::stderrReady()
|
void JavaChecker::stderrReady()
|
||||||
{
|
{
|
||||||
QByteArray data = process->readAllStandardError();
|
QByteArray data = process->readAllStandardError();
|
||||||
QString added = QString::fromLocal8Bit(data);
|
QString added = QString::fromLocal8Bit(data);
|
||||||
added.remove('\r');
|
added.remove('\r');
|
||||||
m_stderr += added;
|
m_stderr += added;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||||
{
|
{
|
||||||
killTimer.stop();
|
killTimer.stop();
|
||||||
QProcessPtr _process = process;
|
QProcessPtr _process;
|
||||||
process.reset();
|
_process.swap(process);
|
||||||
|
|
||||||
JavaCheckResult result;
|
JavaCheckResult result;
|
||||||
{
|
{
|
||||||
result.path = m_path;
|
result.path = m_path;
|
||||||
result.id = m_id;
|
result.id = m_id;
|
||||||
}
|
}
|
||||||
result.errorLog = m_stderr;
|
result.errorLog = m_stderr;
|
||||||
result.outLog = m_stdout;
|
result.outLog = m_stdout;
|
||||||
qDebug() << "STDOUT" << m_stdout;
|
qDebug() << "STDOUT" << m_stdout;
|
||||||
qWarning() << "STDERR" << m_stderr;
|
qWarning() << "STDERR" << m_stderr;
|
||||||
qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
|
qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
|
||||||
|
|
||||||
if (status == QProcess::CrashExit || exitcode == 1)
|
if (status == QProcess::CrashExit || exitcode == 1)
|
||||||
{
|
{
|
||||||
result.validity = JavaCheckResult::Validity::Errored;
|
result.validity = JavaCheckResult::Validity::Errored;
|
||||||
emit checkFinished(result);
|
emit checkFinished(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
QMap<QString, QString> results;
|
QMap<QString, QString> results;
|
||||||
QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
|
QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
|
||||||
for(QString line : lines)
|
for(QString line : lines)
|
||||||
{
|
{
|
||||||
line = line.trimmed();
|
line = line.trimmed();
|
||||||
|
|
||||||
auto parts = line.split('=', QString::SkipEmptyParts);
|
auto parts = line.split('=', QString::SkipEmptyParts);
|
||||||
if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
|
if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
results.insert(parts[0], parts[1]);
|
results.insert(parts[0], parts[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!results.contains("os.arch") || !results.contains("java.version") || !success)
|
if(!results.contains("os.arch") || !results.contains("java.version") || !success)
|
||||||
{
|
{
|
||||||
result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
|
result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
|
||||||
emit checkFinished(result);
|
emit checkFinished(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto os_arch = results["os.arch"];
|
auto os_arch = results["os.arch"];
|
||||||
auto java_version = results["java.version"];
|
auto java_version = results["java.version"];
|
||||||
bool is_64 = os_arch == "x86_64" || os_arch == "amd64";
|
bool is_64 = os_arch == "x86_64" || os_arch == "amd64";
|
||||||
|
|
||||||
|
|
||||||
result.validity = JavaCheckResult::Validity::Valid;
|
result.validity = JavaCheckResult::Validity::Valid;
|
||||||
result.is_64bit = is_64;
|
result.is_64bit = is_64;
|
||||||
result.mojangPlatform = is_64 ? "64" : "32";
|
result.mojangPlatform = is_64 ? "64" : "32";
|
||||||
result.realPlatform = os_arch;
|
result.realPlatform = os_arch;
|
||||||
result.javaVersion = java_version;
|
result.javaVersion = java_version;
|
||||||
qDebug() << "Java checker succeeded.";
|
qDebug() << "Java checker succeeded.";
|
||||||
emit checkFinished(result);
|
emit checkFinished(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::error(QProcess::ProcessError err)
|
void JavaChecker::error(QProcess::ProcessError err)
|
||||||
{
|
{
|
||||||
if(err == QProcess::FailedToStart)
|
if(err == QProcess::FailedToStart)
|
||||||
{
|
{
|
||||||
killTimer.stop();
|
killTimer.stop();
|
||||||
qDebug() << "Java checker has failed to start.";
|
qDebug() << "Java checker has failed to start.";
|
||||||
JavaCheckResult result;
|
JavaCheckResult result;
|
||||||
{
|
{
|
||||||
result.path = m_path;
|
result.path = m_path;
|
||||||
result.id = m_id;
|
result.id = m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit checkFinished(result);
|
emit checkFinished(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaChecker::timeout()
|
void JavaChecker::timeout()
|
||||||
{
|
{
|
||||||
// NO MERCY. NO ABUSE.
|
// NO MERCY. NO ABUSE.
|
||||||
if(process)
|
if(process)
|
||||||
{
|
{
|
||||||
qDebug() << "Java checker has been killed by timeout.";
|
qDebug() << "Java checker has been killed by timeout.";
|
||||||
process->kill();
|
process->kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "QObjectPtr.h"
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
#include "JavaVersion.h"
|
#include "JavaVersion.h"
|
||||||
@@ -13,50 +11,50 @@ class JavaChecker;
|
|||||||
|
|
||||||
struct MULTIMC_LOGIC_EXPORT JavaCheckResult
|
struct MULTIMC_LOGIC_EXPORT JavaCheckResult
|
||||||
{
|
{
|
||||||
QString path;
|
QString path;
|
||||||
QString mojangPlatform;
|
QString mojangPlatform;
|
||||||
QString realPlatform;
|
QString realPlatform;
|
||||||
JavaVersion javaVersion;
|
JavaVersion javaVersion;
|
||||||
QString outLog;
|
QString outLog;
|
||||||
QString errorLog;
|
QString errorLog;
|
||||||
bool is_64bit = false;
|
bool is_64bit = false;
|
||||||
int id;
|
int id;
|
||||||
enum class Validity
|
enum class Validity
|
||||||
{
|
{
|
||||||
Errored,
|
Errored,
|
||||||
ReturnedInvalidData,
|
ReturnedInvalidData,
|
||||||
Valid
|
Valid
|
||||||
} validity = Validity::Errored;
|
} validity = Validity::Errored;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef shared_qobject_ptr<QProcess> QProcessPtr;
|
typedef std::shared_ptr<QProcess> QProcessPtr;
|
||||||
typedef shared_qobject_ptr<JavaChecker> JavaCheckerPtr;
|
typedef std::shared_ptr<JavaChecker> JavaCheckerPtr;
|
||||||
class MULTIMC_LOGIC_EXPORT JavaChecker : public QObject
|
class MULTIMC_LOGIC_EXPORT JavaChecker : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JavaChecker(QObject *parent = 0);
|
explicit JavaChecker(QObject *parent = 0);
|
||||||
void performCheck();
|
void performCheck();
|
||||||
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
QString m_args;
|
QString m_args;
|
||||||
int m_id = 0;
|
int m_id = 0;
|
||||||
int m_minMem = 0;
|
int m_minMem = 0;
|
||||||
int m_maxMem = 0;
|
int m_maxMem = 0;
|
||||||
int m_permGen = 64;
|
int m_permGen = 64;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkFinished(JavaCheckResult result);
|
void checkFinished(JavaCheckResult result);
|
||||||
private:
|
private:
|
||||||
QProcessPtr process;
|
QProcessPtr process;
|
||||||
QTimer killTimer;
|
QTimer killTimer;
|
||||||
QString m_stdout;
|
QString m_stdout;
|
||||||
QString m_stderr;
|
QString m_stderr;
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
void timeout();
|
void timeout();
|
||||||
void finished(int exitcode, QProcess::ExitStatus);
|
void finished(int exitcode, QProcess::ExitStatus);
|
||||||
void error(QProcess::ProcessError);
|
void error(QProcess::ProcessError);
|
||||||
void stdoutReady();
|
void stdoutReady();
|
||||||
void stderrReady();
|
void stderrReady();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -19,26 +19,27 @@
|
|||||||
|
|
||||||
void JavaCheckerJob::partFinished(JavaCheckResult result)
|
void JavaCheckerJob::partFinished(JavaCheckResult result)
|
||||||
{
|
{
|
||||||
num_finished++;
|
num_finished++;
|
||||||
qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/"
|
qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/"
|
||||||
<< javacheckers.size();
|
<< javacheckers.size();
|
||||||
setProgress(num_finished, javacheckers.size());
|
emit progress(num_finished, javacheckers.size());
|
||||||
|
|
||||||
javaresults.replace(result.id, result);
|
javaresults.replace(result.id, result);
|
||||||
|
|
||||||
if (num_finished == javacheckers.size())
|
if (num_finished == javacheckers.size())
|
||||||
{
|
{
|
||||||
emitSucceeded();
|
emit finished(javaresults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaCheckerJob::executeTask()
|
void JavaCheckerJob::executeTask()
|
||||||
{
|
{
|
||||||
qDebug() << m_job_name.toLocal8Bit() << " started.";
|
qDebug() << m_job_name.toLocal8Bit() << " started.";
|
||||||
for (auto iter : javacheckers)
|
m_running = true;
|
||||||
{
|
for (auto iter : javacheckers)
|
||||||
javaresults.append(JavaCheckResult());
|
{
|
||||||
connect(iter.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
|
javaresults.append(JavaCheckResult());
|
||||||
iter->performCheck();
|
connect(iter.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
|
||||||
}
|
iter->performCheck();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -20,42 +20,65 @@
|
|||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
class JavaCheckerJob;
|
class JavaCheckerJob;
|
||||||
typedef shared_qobject_ptr<JavaCheckerJob> JavaCheckerJobPtr;
|
typedef std::shared_ptr<JavaCheckerJob> JavaCheckerJobPtr;
|
||||||
|
|
||||||
// FIXME: this just seems horribly redundant
|
|
||||||
class JavaCheckerJob : public Task
|
class JavaCheckerJob : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name) {};
|
explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name) {};
|
||||||
virtual ~JavaCheckerJob() {};
|
|
||||||
|
|
||||||
bool addJavaCheckerAction(JavaCheckerPtr base)
|
bool addJavaCheckerAction(JavaCheckerPtr base)
|
||||||
{
|
{
|
||||||
javacheckers.append(base);
|
javacheckers.append(base);
|
||||||
// if this is already running, the action needs to be started right away!
|
total_progress++;
|
||||||
if (isRunning())
|
// if this is already running, the action needs to be started right away!
|
||||||
{
|
if (isRunning())
|
||||||
setProgress(num_finished, javacheckers.size());
|
{
|
||||||
connect(base.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
|
setProgress(current_progress, total_progress);
|
||||||
base->performCheck();
|
connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
|
||||||
}
|
|
||||||
return true;
|
base->performCheck();
|
||||||
}
|
}
|
||||||
QList<JavaCheckResult> getResults()
|
return true;
|
||||||
{
|
}
|
||||||
return javaresults;
|
|
||||||
}
|
JavaCheckerPtr operator[](int index)
|
||||||
|
{
|
||||||
|
return javacheckers[index];
|
||||||
|
}
|
||||||
|
;
|
||||||
|
JavaCheckerPtr first()
|
||||||
|
{
|
||||||
|
if (javacheckers.size())
|
||||||
|
return javacheckers[0];
|
||||||
|
return JavaCheckerPtr();
|
||||||
|
}
|
||||||
|
int size() const
|
||||||
|
{
|
||||||
|
return javacheckers.size();
|
||||||
|
}
|
||||||
|
virtual bool isRunning() const override
|
||||||
|
{
|
||||||
|
return m_running;
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void started();
|
||||||
|
void finished(QList<JavaCheckResult>);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void partFinished(JavaCheckResult result);
|
void partFinished(JavaCheckResult result);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_job_name;
|
QString m_job_name;
|
||||||
QList<JavaCheckerPtr> javacheckers;
|
QList<JavaCheckerPtr> javacheckers;
|
||||||
QList<JavaCheckResult> javaresults;
|
QList<JavaCheckResult> javaresults;
|
||||||
int num_finished = 0;
|
qint64 current_progress = 0;
|
||||||
|
qint64 total_progress = 0;
|
||||||
|
int num_finished = 0;
|
||||||
|
bool m_running = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,26 +3,26 @@
|
|||||||
|
|
||||||
bool JavaInstall::operator<(const JavaInstall &rhs)
|
bool JavaInstall::operator<(const JavaInstall &rhs)
|
||||||
{
|
{
|
||||||
auto archCompare = Strings::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
|
auto archCompare = Strings::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 Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
return Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator==(const JavaInstall &rhs)
|
bool JavaInstall::operator==(const JavaInstall &rhs)
|
||||||
{
|
{
|
||||||
return arch == rhs.arch && id == rhs.id && path == rhs.path;
|
return arch == rhs.arch && id == rhs.id && path == rhs.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator>(const JavaInstall &rhs)
|
bool JavaInstall::operator>(const JavaInstall &rhs)
|
||||||
{
|
{
|
||||||
return (!operator<(rhs)) && (!operator==(rhs));
|
return (!operator<(rhs)) && (!operator==(rhs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,34 +5,34 @@
|
|||||||
|
|
||||||
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()
|
virtual QString descriptor()
|
||||||
{
|
{
|
||||||
return id.toString();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
JavaVersion id;
|
JavaVersion id;
|
||||||
QString arch;
|
QString arch;
|
||||||
QString path;
|
QString path;
|
||||||
bool recommended = false;
|
bool recommended = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<JavaInstall> JavaInstallPtr;
|
typedef std::shared_ptr<JavaInstall> JavaInstallPtr;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -29,113 +29,92 @@ JavaInstallList::JavaInstallList(QObject *parent) : BaseVersionList(parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<Task> JavaInstallList::getLoadTask()
|
Task *JavaInstallList::getLoadTask()
|
||||||
{
|
{
|
||||||
load();
|
return new JavaListLoadTask(this);
|
||||||
return getCurrentTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
shared_qobject_ptr<Task> JavaInstallList::getCurrentTask()
|
|
||||||
{
|
|
||||||
if(m_status == Status::InProgress)
|
|
||||||
{
|
|
||||||
return m_loadTask;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JavaInstallList::load()
|
|
||||||
{
|
|
||||||
if(m_status != Status::InProgress)
|
|
||||||
{
|
|
||||||
m_status = Status::InProgress;
|
|
||||||
m_loadTask = new JavaListLoadTask(this);
|
|
||||||
m_loadTask->start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const BaseVersionPtr JavaInstallList::at(int i) const
|
const BaseVersionPtr JavaInstallList::at(int i) const
|
||||||
{
|
{
|
||||||
return m_vlist.at(i);
|
return m_vlist.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstallList::isLoaded()
|
bool JavaInstallList::isLoaded()
|
||||||
{
|
{
|
||||||
return m_status == JavaInstallList::Status::Done;
|
return m_loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JavaInstallList::count() const
|
int JavaInstallList::count() const
|
||||||
{
|
{
|
||||||
return m_vlist.count();
|
return m_vlist.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant JavaInstallList::data(const QModelIndex &index, int role) const
|
QVariant JavaInstallList::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (index.row() > count())
|
if (index.row() > count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
auto version = std::dynamic_pointer_cast<JavaInstall>(m_vlist[index.row()]);
|
auto version = std::dynamic_pointer_cast<JavaInstall>(m_vlist[index.row()]);
|
||||||
switch (role)
|
switch (role)
|
||||||
{
|
{
|
||||||
case VersionPointerRole:
|
case VersionPointerRole:
|
||||||
return qVariantFromValue(m_vlist[index.row()]);
|
return qVariantFromValue(m_vlist[index.row()]);
|
||||||
case VersionIdRole:
|
case VersionIdRole:
|
||||||
return version->descriptor();
|
return version->descriptor();
|
||||||
case VersionRole:
|
case VersionRole:
|
||||||
return version->id.toString();
|
return version->id.toString();
|
||||||
case RecommendedRole:
|
case RecommendedRole:
|
||||||
return version->recommended;
|
return version->recommended;
|
||||||
case PathRole:
|
case PathRole:
|
||||||
return version->path;
|
return version->path;
|
||||||
case ArchitectureRole:
|
case ArchitectureRole:
|
||||||
return version->arch;
|
return version->arch;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseVersionList::RoleList JavaInstallList::providesRoles() const
|
BaseVersionList::RoleList JavaInstallList::providesRoles() const
|
||||||
{
|
{
|
||||||
return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole};
|
return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
|
void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_vlist = versions;
|
m_vlist = versions;
|
||||||
sortVersions();
|
m_loaded = true;
|
||||||
if(m_vlist.size())
|
sortVersions();
|
||||||
{
|
if(m_vlist.size())
|
||||||
auto best = std::dynamic_pointer_cast<JavaInstall>(m_vlist[0]);
|
{
|
||||||
best->recommended = true;
|
auto best = std::dynamic_pointer_cast<JavaInstall>(m_vlist[0]);
|
||||||
}
|
best->recommended = true;
|
||||||
endResetModel();
|
}
|
||||||
m_status = Status::Done;
|
endResetModel();
|
||||||
m_loadTask.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sortJavas(BaseVersionPtr left, BaseVersionPtr right)
|
bool sortJavas(BaseVersionPtr left, BaseVersionPtr right)
|
||||||
{
|
{
|
||||||
auto rleft = std::dynamic_pointer_cast<JavaInstall>(left);
|
auto rleft = std::dynamic_pointer_cast<JavaInstall>(left);
|
||||||
auto rright = std::dynamic_pointer_cast<JavaInstall>(right);
|
auto rright = std::dynamic_pointer_cast<JavaInstall>(right);
|
||||||
return (*rleft) > (*rright);
|
return (*rleft) > (*rright);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaInstallList::sortVersions()
|
void JavaInstallList::sortVersions()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
std::sort(m_vlist.begin(), m_vlist.end(), sortJavas);
|
std::sort(m_vlist.begin(), m_vlist.end(), sortJavas);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaListLoadTask::JavaListLoadTask(JavaInstallList *vlist) : Task()
|
JavaListLoadTask::JavaListLoadTask(JavaInstallList *vlist) : Task()
|
||||||
{
|
{
|
||||||
m_list = vlist;
|
m_list = vlist;
|
||||||
m_currentRecommended = NULL;
|
m_currentRecommended = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaListLoadTask::~JavaListLoadTask()
|
JavaListLoadTask::~JavaListLoadTask()
|
||||||
@@ -144,65 +123,64 @@ JavaListLoadTask::~JavaListLoadTask()
|
|||||||
|
|
||||||
void JavaListLoadTask::executeTask()
|
void JavaListLoadTask::executeTask()
|
||||||
{
|
{
|
||||||
setStatus(tr("Detecting Java installations..."));
|
setStatus(tr("Detecting Java installations..."));
|
||||||
|
|
||||||
JavaUtils ju;
|
JavaUtils ju;
|
||||||
QList<QString> candidate_paths = ju.FindJavaPaths();
|
QList<QString> candidate_paths = ju.FindJavaPaths();
|
||||||
|
|
||||||
m_job = new JavaCheckerJob("Java detection");
|
m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection"));
|
||||||
connect(m_job.get(), &Task::finished, this, &JavaListLoadTask::javaCheckerFinished);
|
connect(m_job.get(), SIGNAL(finished(QList<JavaCheckResult>)), this, SLOT(javaCheckerFinished(QList<JavaCheckResult>)));
|
||||||
connect(m_job.get(), &Task::progress, this, &Task::setProgress);
|
connect(m_job.get(), &Task::progress, this, &Task::setProgress);
|
||||||
|
|
||||||
qDebug() << "Probing the following Java paths: ";
|
qDebug() << "Probing the following Java paths: ";
|
||||||
int id = 0;
|
int id = 0;
|
||||||
for(QString candidate : candidate_paths)
|
for(QString candidate : candidate_paths)
|
||||||
{
|
{
|
||||||
qDebug() << " " << candidate;
|
qDebug() << " " << candidate;
|
||||||
|
|
||||||
auto candidate_checker = new JavaChecker();
|
auto candidate_checker = new JavaChecker();
|
||||||
candidate_checker->m_path = candidate;
|
candidate_checker->m_path = candidate;
|
||||||
candidate_checker->m_id = id;
|
candidate_checker->m_id = id;
|
||||||
m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
|
m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_job->start();
|
m_job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaListLoadTask::javaCheckerFinished()
|
void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results)
|
||||||
{
|
{
|
||||||
QList<JavaInstallPtr> candidates;
|
QList<JavaInstallPtr> candidates;
|
||||||
auto results = m_job->getResults();
|
|
||||||
|
|
||||||
qDebug() << "Found the following valid Java installations:";
|
qDebug() << "Found the following valid Java installations:";
|
||||||
for(JavaCheckResult result : results)
|
for(JavaCheckResult result : results)
|
||||||
{
|
{
|
||||||
if(result.validity == JavaCheckResult::Validity::Valid)
|
if(result.validity == JavaCheckResult::Validity::Valid)
|
||||||
{
|
{
|
||||||
JavaInstallPtr javaVersion(new JavaInstall());
|
JavaInstallPtr javaVersion(new JavaInstall());
|
||||||
|
|
||||||
javaVersion->id = result.javaVersion;
|
javaVersion->id = result.javaVersion;
|
||||||
javaVersion->arch = result.mojangPlatform;
|
javaVersion->arch = result.mojangPlatform;
|
||||||
javaVersion->path = result.path;
|
javaVersion->path = result.path;
|
||||||
candidates.append(javaVersion);
|
candidates.append(javaVersion);
|
||||||
|
|
||||||
qDebug() << " " << javaVersion->id.toString() << javaVersion->arch << javaVersion->path;
|
qDebug() << " " << javaVersion->id.toString() << javaVersion->arch << javaVersion->path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BaseVersionPtr> javas_bvp;
|
QList<BaseVersionPtr> javas_bvp;
|
||||||
for (auto java : candidates)
|
for (auto java : candidates)
|
||||||
{
|
{
|
||||||
//qDebug() << java->id << java->arch << " at " << java->path;
|
//qDebug() << java->id << java->arch << " at " << java->path;
|
||||||
BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
|
BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
|
||||||
|
|
||||||
if (bp_java)
|
if (bp_java)
|
||||||
{
|
{
|
||||||
javas_bvp.append(java);
|
javas_bvp.append(java);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_list->updateListData(javas_bvp);
|
m_list->updateListData(javas_bvp);
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -24,60 +24,48 @@
|
|||||||
#include "JavaCheckerJob.h"
|
#include "JavaCheckerJob.h"
|
||||||
#include "JavaInstall.h"
|
#include "JavaInstall.h"
|
||||||
|
|
||||||
#include "QObjectPtr.h"
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
class JavaListLoadTask;
|
class JavaListLoadTask;
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList
|
class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
enum class Status
|
|
||||||
{
|
|
||||||
NotDone,
|
|
||||||
InProgress,
|
|
||||||
Done
|
|
||||||
};
|
|
||||||
public:
|
public:
|
||||||
explicit JavaInstallList(QObject *parent = 0);
|
explicit JavaInstallList(QObject *parent = 0);
|
||||||
|
|
||||||
shared_qobject_ptr<Task> getLoadTask() override;
|
virtual Task *getLoadTask() override;
|
||||||
bool isLoaded() override;
|
virtual bool isLoaded() override;
|
||||||
const BaseVersionPtr at(int i) const override;
|
virtual const BaseVersionPtr at(int i) const override;
|
||||||
int count() const override;
|
virtual int count() const override;
|
||||||
void sortVersions() override;
|
virtual void sortVersions() override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||||
RoleList providesRoles() const override;
|
virtual RoleList providesRoles() const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateListData(QList<BaseVersionPtr> versions) override;
|
virtual void updateListData(QList<BaseVersionPtr> versions) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void load();
|
QList<BaseVersionPtr> m_vlist;
|
||||||
shared_qobject_ptr<Task> getCurrentTask();
|
|
||||||
|
|
||||||
protected:
|
bool m_loaded = false;
|
||||||
Status m_status = Status::NotDone;
|
|
||||||
shared_qobject_ptr<JavaListLoadTask> m_loadTask;
|
|
||||||
QList<BaseVersionPtr> m_vlist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class JavaListLoadTask : public Task
|
class JavaListLoadTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit JavaListLoadTask(JavaInstallList *vlist);
|
explicit JavaListLoadTask(JavaInstallList *vlist);
|
||||||
virtual ~JavaListLoadTask();
|
~JavaListLoadTask();
|
||||||
|
|
||||||
void executeTask() override;
|
virtual void executeTask();
|
||||||
public slots:
|
public slots:
|
||||||
void javaCheckerFinished();
|
void javaCheckerFinished(QList<JavaCheckResult> results);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
shared_qobject_ptr<JavaCheckerJob> m_job;
|
std::shared_ptr<JavaCheckerJob> m_job;
|
||||||
JavaInstallList *m_list;
|
JavaInstallList *m_list;
|
||||||
JavaInstall *m_currentRecommended;
|
JavaInstall *m_currentRecommended;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -22,324 +22,231 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "java/JavaUtils.h"
|
#include "java/JavaUtils.h"
|
||||||
|
#include "java/JavaCheckerJob.h"
|
||||||
#include "java/JavaInstallList.h"
|
#include "java/JavaInstallList.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#define IBUS "@im=ibus"
|
|
||||||
|
|
||||||
JavaUtils::JavaUtils()
|
JavaUtils::JavaUtils()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
static QString processLD_LIBRARY_PATH(const QString & LD_LIBRARY_PATH)
|
|
||||||
{
|
|
||||||
QDir mmcBin(QCoreApplication::applicationDirPath());
|
|
||||||
auto items = LD_LIBRARY_PATH.split(':');
|
|
||||||
QStringList final;
|
|
||||||
for(auto & item: items)
|
|
||||||
{
|
|
||||||
QDir test(item);
|
|
||||||
if(test == mmcBin)
|
|
||||||
{
|
|
||||||
qDebug() << "Env:LD_LIBRARY_PATH ignoring path" << item;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final.append(item);
|
|
||||||
}
|
|
||||||
return final.join(':');
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QProcessEnvironment CleanEnviroment()
|
|
||||||
{
|
|
||||||
// prepare the process environment
|
|
||||||
QProcessEnvironment rawenv = QProcessEnvironment::systemEnvironment();
|
|
||||||
QProcessEnvironment env;
|
|
||||||
|
|
||||||
QStringList ignored =
|
|
||||||
{
|
|
||||||
"JAVA_ARGS",
|
|
||||||
"CLASSPATH",
|
|
||||||
"CONFIGPATH",
|
|
||||||
"JAVA_HOME",
|
|
||||||
"JRE_HOME",
|
|
||||||
"_JAVA_OPTIONS",
|
|
||||||
"JAVA_OPTIONS",
|
|
||||||
"JAVA_TOOL_OPTIONS"
|
|
||||||
};
|
|
||||||
for(auto key: rawenv.keys())
|
|
||||||
{
|
|
||||||
auto value = rawenv.value(key);
|
|
||||||
// filter out dangerous java crap
|
|
||||||
if(ignored.contains(key))
|
|
||||||
{
|
|
||||||
qDebug() << "Env: ignoring" << key << value;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// filter MultiMC-related things
|
|
||||||
if(key.startsWith("QT_"))
|
|
||||||
{
|
|
||||||
qDebug() << "Env: ignoring" << key << value;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
// Do not pass LD_* variables to java. They were intended for MultiMC
|
|
||||||
if(key.startsWith("LD_"))
|
|
||||||
{
|
|
||||||
qDebug() << "Env: ignoring" << key << value;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Strip IBus
|
|
||||||
// IBus is a Linux IME framework. For some reason, it breaks MC?
|
|
||||||
if (key == "XMODIFIERS" && value.contains(IBUS))
|
|
||||||
{
|
|
||||||
QString save = value;
|
|
||||||
value.replace(IBUS, "");
|
|
||||||
qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
|
|
||||||
}
|
|
||||||
if(key == "GAME_PRELOAD")
|
|
||||||
{
|
|
||||||
env.insert("LD_PRELOAD", value);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(key == "GAME_LIBRARY_PATH")
|
|
||||||
{
|
|
||||||
env.insert("LD_LIBRARY_PATH", processLD_LIBRARY_PATH(value));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// qDebug() << "Env: " << key << value;
|
|
||||||
env.insert(key, value);
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
// HACK: Workaround for QTBUG42500
|
|
||||||
if(!env.contains("LD_LIBRARY_PATH"))
|
|
||||||
{
|
|
||||||
env.insert("LD_LIBRARY_PATH", "");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return env;
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch)
|
JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch)
|
||||||
{
|
{
|
||||||
JavaInstallPtr javaVersion(new JavaInstall());
|
JavaInstallPtr javaVersion(new JavaInstall());
|
||||||
|
|
||||||
javaVersion->id = id;
|
javaVersion->id = id;
|
||||||
javaVersion->arch = arch;
|
javaVersion->arch = arch;
|
||||||
javaVersion->path = path;
|
javaVersion->path = path;
|
||||||
|
|
||||||
return javaVersion;
|
return javaVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaInstallPtr JavaUtils::GetDefaultJava()
|
JavaInstallPtr JavaUtils::GetDefaultJava()
|
||||||
{
|
{
|
||||||
JavaInstallPtr javaVersion(new JavaInstall());
|
JavaInstallPtr javaVersion(new JavaInstall());
|
||||||
|
|
||||||
javaVersion->id = "java";
|
javaVersion->id = "java";
|
||||||
javaVersion->arch = "unknown";
|
javaVersion->arch = "unknown";
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
javaVersion->path = "javaw";
|
javaVersion->path = "javaw";
|
||||||
#else
|
#else
|
||||||
javaVersion->path = "java";
|
javaVersion->path = "java";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return javaVersion;
|
return javaVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName)
|
QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName)
|
||||||
{
|
{
|
||||||
QList<JavaInstallPtr> javas;
|
QList<JavaInstallPtr> javas;
|
||||||
|
|
||||||
QString archType = "unknown";
|
QString archType = "unknown";
|
||||||
if (keyType == KEY_WOW64_64KEY)
|
if (keyType == KEY_WOW64_64KEY)
|
||||||
archType = "64";
|
archType = "64";
|
||||||
else if (keyType == KEY_WOW64_32KEY)
|
else if (keyType == KEY_WOW64_32KEY)
|
||||||
archType = "32";
|
archType = "32";
|
||||||
|
|
||||||
HKEY jreKey;
|
HKEY jreKey;
|
||||||
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0,
|
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0,
|
||||||
KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS)
|
KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// Read the current type version from the registry.
|
// Read the current type version from the registry.
|
||||||
// This will be used to find any key that contains the JavaHome value.
|
// This will be used to find any key that contains the JavaHome value.
|
||||||
char *value = new char[0];
|
char *value = new char[0];
|
||||||
DWORD valueSz = 0;
|
DWORD valueSz = 0;
|
||||||
if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) ==
|
if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) ==
|
||||||
ERROR_MORE_DATA)
|
ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
value = new char[valueSz];
|
value = new char[valueSz];
|
||||||
RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz);
|
RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString recommended = value;
|
QString recommended = value;
|
||||||
|
|
||||||
TCHAR subKeyName[255];
|
TCHAR subKeyName[255];
|
||||||
DWORD subKeyNameSize, numSubKeys, retCode;
|
DWORD subKeyNameSize, numSubKeys, retCode;
|
||||||
|
|
||||||
// Get the number of subkeys
|
// Get the number of subkeys
|
||||||
RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
|
RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
// Iterate until RegEnumKeyEx fails
|
// Iterate until RegEnumKeyEx fails
|
||||||
if (numSubKeys > 0)
|
if (numSubKeys > 0)
|
||||||
{
|
{
|
||||||
for (DWORD i = 0; i < numSubKeys; i++)
|
for (int i = 0; i < numSubKeys; i++)
|
||||||
{
|
{
|
||||||
subKeyNameSize = 255;
|
subKeyNameSize = 255;
|
||||||
retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
|
retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
if (retCode == ERROR_SUCCESS)
|
if (retCode == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// Now open the registry key for the version that we just got.
|
// Now open the registry key for the version that we just got.
|
||||||
QString newKeyName = keyName + "\\" + subKeyName;
|
QString newKeyName = keyName + "\\" + subKeyName;
|
||||||
|
|
||||||
HKEY newKey;
|
HKEY newKey;
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
|
||||||
KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
|
KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// Read the JavaHome value to find where Java is installed.
|
// Read the JavaHome value to find where Java is installed.
|
||||||
value = new char[0];
|
value = new char[0];
|
||||||
valueSz = 0;
|
valueSz = 0;
|
||||||
if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
|
if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
|
||||||
&valueSz) == ERROR_MORE_DATA)
|
&valueSz) == ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
value = new char[valueSz];
|
value = new char[valueSz];
|
||||||
RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
|
RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
|
||||||
&valueSz);
|
&valueSz);
|
||||||
|
|
||||||
// Now, we construct the version object and add it to the list.
|
// Now, we construct the version object and add it to the list.
|
||||||
JavaInstallPtr javaVersion(new JavaInstall());
|
JavaInstallPtr javaVersion(new JavaInstall());
|
||||||
|
|
||||||
javaVersion->id = subKeyName;
|
javaVersion->id = subKeyName;
|
||||||
javaVersion->arch = archType;
|
javaVersion->arch = archType;
|
||||||
javaVersion->path =
|
javaVersion->path =
|
||||||
QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
|
QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
|
||||||
javas.append(javaVersion);
|
javas.append(javaVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(newKey);
|
RegCloseKey(newKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(jreKey);
|
RegCloseKey(jreKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return javas;
|
return javas;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> JavaUtils::FindJavaPaths()
|
QList<QString> JavaUtils::FindJavaPaths()
|
||||||
{
|
{
|
||||||
QList<JavaInstallPtr> java_candidates;
|
QList<JavaInstallPtr> java_candidates;
|
||||||
|
|
||||||
QList<JavaInstallPtr> JRE64s = this->FindJavaFromRegistryKey(
|
QList<JavaInstallPtr> JRE64s = this->FindJavaFromRegistryKey(
|
||||||
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
||||||
QList<JavaInstallPtr> JDK64s = this->FindJavaFromRegistryKey(
|
QList<JavaInstallPtr> JDK64s = this->FindJavaFromRegistryKey(
|
||||||
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
|
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
|
||||||
QList<JavaInstallPtr> JRE32s = this->FindJavaFromRegistryKey(
|
QList<JavaInstallPtr> JRE32s = this->FindJavaFromRegistryKey(
|
||||||
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
||||||
QList<JavaInstallPtr> JDK32s = this->FindJavaFromRegistryKey(
|
QList<JavaInstallPtr> JDK32s = this->FindJavaFromRegistryKey(
|
||||||
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
|
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
|
||||||
|
|
||||||
java_candidates.append(JRE64s);
|
java_candidates.append(JRE64s);
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe"));
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe"));
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe"));
|
||||||
java_candidates.append(JDK64s);
|
java_candidates.append(JDK64s);
|
||||||
java_candidates.append(JRE32s);
|
java_candidates.append(JRE32s);
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe"));
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe"));
|
||||||
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
|
||||||
java_candidates.append(JDK32s);
|
java_candidates.append(JDK32s);
|
||||||
java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));
|
java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));
|
||||||
|
|
||||||
QList<QString> candidates;
|
QList<QString> candidates;
|
||||||
for(JavaInstallPtr java_candidate : java_candidates)
|
for(JavaInstallPtr java_candidate : java_candidates)
|
||||||
{
|
{
|
||||||
if(!candidates.contains(java_candidate->path))
|
if(!candidates.contains(java_candidate->path))
|
||||||
{
|
{
|
||||||
candidates.append(java_candidate->path);
|
candidates.append(java_candidate->path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(Q_OS_MAC)
|
#elif defined(Q_OS_MAC)
|
||||||
QList<QString> JavaUtils::FindJavaPaths()
|
QList<QString> JavaUtils::FindJavaPaths()
|
||||||
{
|
{
|
||||||
QList<QString> javas;
|
QList<QString> javas;
|
||||||
javas.append(this->GetDefaultJava()->path);
|
javas.append(this->GetDefaultJava()->path);
|
||||||
javas.append("/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java/bin/java");
|
javas.append("/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java/bin/java");
|
||||||
javas.append("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
|
javas.append("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
|
||||||
javas.append("/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java");
|
javas.append("/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java");
|
||||||
QDir libraryJVMDir("/Library/Java/JavaVirtualMachines/");
|
QDir libraryJVMDir("/Library/Java/JavaVirtualMachines/");
|
||||||
QStringList libraryJVMJavas = libraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList libraryJVMJavas = libraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
foreach (const QString &java, libraryJVMJavas) {
|
foreach (const QString &java, libraryJVMJavas) {
|
||||||
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
||||||
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/jre/bin/java");
|
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/jre/bin/java");
|
||||||
}
|
}
|
||||||
QDir systemLibraryJVMDir("/System/Library/Java/JavaVirtualMachines/");
|
QDir systemLibraryJVMDir("/System/Library/Java/JavaVirtualMachines/");
|
||||||
QStringList systemLibraryJVMJavas = systemLibraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList systemLibraryJVMJavas = systemLibraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
foreach (const QString &java, systemLibraryJVMJavas) {
|
foreach (const QString &java, systemLibraryJVMJavas) {
|
||||||
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
||||||
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
|
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
|
||||||
}
|
}
|
||||||
return javas;
|
return javas;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
QList<QString> JavaUtils::FindJavaPaths()
|
QList<QString> JavaUtils::FindJavaPaths()
|
||||||
{
|
{
|
||||||
qDebug() << "Linux Java detection incomplete - defaulting to \"java\"";
|
qDebug() << "Linux Java detection incomplete - defaulting to \"java\"";
|
||||||
|
|
||||||
QList<QString> javas;
|
QList<QString> javas;
|
||||||
javas.append(this->GetDefaultJava()->path);
|
javas.append(this->GetDefaultJava()->path);
|
||||||
auto scanJavaDir = [&](const QString & dirPath)
|
auto scanJavaDir = [&](const QString & dirPath)
|
||||||
{
|
{
|
||||||
QDir dir(dirPath);
|
QDir dir(dirPath);
|
||||||
if(!dir.exists())
|
if(!dir.exists())
|
||||||
return;
|
return;
|
||||||
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||||
for(auto & entry: entries)
|
for(auto & entry: entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
QString prefix;
|
QString prefix;
|
||||||
if(entry.isAbsolute())
|
if(entry.isAbsolute())
|
||||||
{
|
{
|
||||||
prefix = entry.absoluteFilePath();
|
prefix = entry.absoluteFilePath();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prefix = entry.filePath();
|
prefix = entry.filePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
javas.append(FS::PathCombine(prefix, "jre/bin/java"));
|
javas.append(FS::PathCombine(prefix, "jre/bin/java"));
|
||||||
javas.append(FS::PathCombine(prefix, "bin/java"));
|
javas.append(FS::PathCombine(prefix, "bin/java"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// oracle RPMs
|
// oracle RPMs
|
||||||
scanJavaDir("/usr/java");
|
scanJavaDir("/usr/java");
|
||||||
// general locations used by distro packaging
|
// general locations used by distro packaging
|
||||||
scanJavaDir("/usr/lib/jvm");
|
scanJavaDir("/usr/lib/jvm");
|
||||||
scanJavaDir("/usr/lib32/jvm");
|
scanJavaDir("/usr/lib32/jvm");
|
||||||
// javas stored in MultiMC's folder
|
// javas stored in MultiMC's folder
|
||||||
scanJavaDir("java");
|
scanJavaDir("java");
|
||||||
return javas;
|
return javas;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
QList<QString> JavaUtils::FindJavaPaths()
|
QList<QString> JavaUtils::FindJavaPaths()
|
||||||
{
|
{
|
||||||
qDebug() << "Unknown operating system build - defaulting to \"java\"";
|
qDebug() << "Unknown operating system build - defaulting to \"java\"";
|
||||||
|
|
||||||
QList<QString> javas;
|
QList<QString> javas;
|
||||||
javas.append(this->GetDefaultJava()->path);
|
javas.append(this->GetDefaultJava()->path);
|
||||||
|
|
||||||
return javas;
|
return javas;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "JavaCheckerJob.h"
|
||||||
#include "JavaChecker.h"
|
#include "JavaChecker.h"
|
||||||
#include "JavaInstallList.h"
|
#include "JavaInstallList.h"
|
||||||
|
|
||||||
@@ -26,19 +27,17 @@
|
|||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
QProcessEnvironment CleanEnviroment();
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT JavaUtils : public QObject
|
class MULTIMC_LOGIC_EXPORT JavaUtils : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
JavaUtils();
|
JavaUtils();
|
||||||
|
|
||||||
JavaInstallPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown");
|
JavaInstallPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown");
|
||||||
QList<QString> FindJavaPaths();
|
QList<QString> FindJavaPaths();
|
||||||
JavaInstallPtr GetDefaultJava();
|
JavaInstallPtr GetDefaultJava();
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QList<JavaInstallPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName);
|
QList<JavaInstallPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,116 +6,107 @@
|
|||||||
|
|
||||||
JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
|
JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
|
||||||
{
|
{
|
||||||
m_string = javaVersionString;
|
m_string = javaVersionString;
|
||||||
|
|
||||||
auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int
|
auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int
|
||||||
{
|
{
|
||||||
auto str = match.captured(what);
|
auto str = match.captured(what);
|
||||||
if(str.isEmpty())
|
if(str.isEmpty())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return str.toInt();
|
return str.toInt();
|
||||||
};
|
};
|
||||||
|
|
||||||
QRegularExpression pattern;
|
QRegularExpression pattern;
|
||||||
if(javaVersionString.startsWith("1."))
|
if(javaVersionString.startsWith("1."))
|
||||||
{
|
{
|
||||||
pattern = QRegularExpression ("1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
pattern = QRegularExpression ("1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto match = pattern.match(m_string);
|
auto match = pattern.match(m_string);
|
||||||
m_parseable = match.hasMatch();
|
m_parseable = match.hasMatch();
|
||||||
m_major = getCapturedInteger(match, "major");
|
m_major = getCapturedInteger(match, "major");
|
||||||
m_minor = getCapturedInteger(match, "minor");
|
m_minor = getCapturedInteger(match, "minor");
|
||||||
m_security = getCapturedInteger(match, "security");
|
m_security = getCapturedInteger(match, "security");
|
||||||
m_prerelease = match.captured("prerelease");
|
m_prerelease = match.captured("prerelease");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaVersion::JavaVersion(const QString &rhs)
|
JavaVersion::JavaVersion(const QString &rhs)
|
||||||
{
|
{
|
||||||
operator=(rhs);
|
operator=(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JavaVersion::toString()
|
QString JavaVersion::toString()
|
||||||
{
|
{
|
||||||
return m_string;
|
return m_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaVersion::requiresPermGen()
|
bool JavaVersion::requiresPermGen()
|
||||||
{
|
{
|
||||||
if(m_parseable)
|
if(m_parseable)
|
||||||
{
|
{
|
||||||
return m_major < 8;
|
return m_major < 8;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaVersion::operator<(const JavaVersion &rhs)
|
bool JavaVersion::operator<(const JavaVersion &rhs)
|
||||||
{
|
{
|
||||||
if(m_parseable && rhs.m_parseable)
|
if(m_parseable && rhs.m_parseable)
|
||||||
{
|
{
|
||||||
auto major = m_major;
|
if(m_major < rhs.m_major)
|
||||||
auto rmajor = rhs.m_major;
|
return true;
|
||||||
|
if(m_major > rhs.m_major)
|
||||||
|
return false;
|
||||||
|
if(m_minor < rhs.m_minor)
|
||||||
|
return true;
|
||||||
|
if(m_minor > rhs.m_minor)
|
||||||
|
return false;
|
||||||
|
if(m_security < rhs.m_security)
|
||||||
|
return true;
|
||||||
|
if(m_security > rhs.m_security)
|
||||||
|
return false;
|
||||||
|
|
||||||
// HACK: discourage using java 9
|
// everything else being equal, consider prerelease status
|
||||||
if(major > 8)
|
bool thisPre = !m_prerelease.isEmpty();
|
||||||
major = -major;
|
bool rhsPre = !rhs.m_prerelease.isEmpty();
|
||||||
if(rmajor > 8)
|
if(thisPre && !rhsPre)
|
||||||
rmajor = -rmajor;
|
{
|
||||||
|
// this is a prerelease and the other one isn't -> lesser
|
||||||
if(major < rmajor)
|
return true;
|
||||||
return true;
|
}
|
||||||
if(major > rmajor)
|
else if(!thisPre && rhsPre)
|
||||||
return false;
|
{
|
||||||
if(m_minor < rhs.m_minor)
|
// this isn't a prerelease and the other one is -> greater
|
||||||
return true;
|
return false;
|
||||||
if(m_minor > rhs.m_minor)
|
}
|
||||||
return false;
|
else if(thisPre && rhsPre)
|
||||||
if(m_security < rhs.m_security)
|
{
|
||||||
return true;
|
// both are prereleases - use natural compare...
|
||||||
if(m_security > rhs.m_security)
|
return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0;
|
||||||
return false;
|
}
|
||||||
|
// neither is prerelease, so they are the same -> this cannot be less than rhs
|
||||||
// everything else being equal, consider prerelease status
|
return false;
|
||||||
bool thisPre = !m_prerelease.isEmpty();
|
}
|
||||||
bool rhsPre = !rhs.m_prerelease.isEmpty();
|
else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
|
||||||
if(thisPre && !rhsPre)
|
|
||||||
{
|
|
||||||
// this is a prerelease and the other one isn't -> lesser
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(!thisPre && rhsPre)
|
|
||||||
{
|
|
||||||
// this isn't a prerelease and the other one is -> greater
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if(thisPre && rhsPre)
|
|
||||||
{
|
|
||||||
// both are prereleases - use natural compare...
|
|
||||||
return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0;
|
|
||||||
}
|
|
||||||
// neither is prerelease, so they are the same -> this cannot be less than rhs
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaVersion::operator==(const JavaVersion &rhs)
|
bool JavaVersion::operator==(const JavaVersion &rhs)
|
||||||
{
|
{
|
||||||
if(m_parseable && rhs.m_parseable)
|
if(m_parseable && rhs.m_parseable)
|
||||||
{
|
{
|
||||||
return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
|
return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
|
||||||
}
|
}
|
||||||
return m_string == rhs.m_string;
|
return m_string == rhs.m_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaVersion::operator>(const JavaVersion &rhs)
|
bool JavaVersion::operator>(const JavaVersion &rhs)
|
||||||
{
|
{
|
||||||
return (!operator<(rhs)) && (!operator==(rhs));
|
return (!operator<(rhs)) && (!operator==(rhs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,48 +3,40 @@
|
|||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
// NOTE: apparently the GNU C library pollutes the global namespace with these... undef them.
|
|
||||||
#ifdef major
|
|
||||||
#undef major
|
|
||||||
#endif
|
|
||||||
#ifdef minor
|
|
||||||
#undef minor
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT JavaVersion
|
class MULTIMC_LOGIC_EXPORT JavaVersion
|
||||||
{
|
{
|
||||||
friend class JavaVersionTest;
|
friend class JavaVersionTest;
|
||||||
public:
|
public:
|
||||||
JavaVersion() {};
|
JavaVersion() {};
|
||||||
JavaVersion(const QString & rhs);
|
JavaVersion(const QString & rhs);
|
||||||
|
|
||||||
JavaVersion & operator=(const QString & rhs);
|
JavaVersion & operator=(const QString & rhs);
|
||||||
|
|
||||||
bool operator<(const JavaVersion & rhs);
|
bool operator<(const JavaVersion & rhs);
|
||||||
bool operator==(const JavaVersion & rhs);
|
bool operator==(const JavaVersion & rhs);
|
||||||
bool operator>(const JavaVersion & rhs);
|
bool operator>(const JavaVersion & rhs);
|
||||||
|
|
||||||
bool requiresPermGen();
|
bool requiresPermGen();
|
||||||
|
|
||||||
QString toString();
|
QString toString();
|
||||||
|
|
||||||
int major()
|
int major()
|
||||||
{
|
{
|
||||||
return m_major;
|
return m_major;
|
||||||
}
|
}
|
||||||
int minor()
|
int minor()
|
||||||
{
|
{
|
||||||
return m_minor;
|
return m_minor;
|
||||||
}
|
}
|
||||||
int security()
|
int security()
|
||||||
{
|
{
|
||||||
return m_security;
|
return m_security;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QString m_string;
|
QString m_string;
|
||||||
int m_major = 0;
|
int m_major = 0;
|
||||||
int m_minor = 0;
|
int m_minor = 0;
|
||||||
int m_security = 0;
|
int m_security = 0;
|
||||||
bool m_parseable = false;
|
bool m_parseable = false;
|
||||||
QString m_prerelease;
|
QString m_prerelease;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,110 +5,110 @@
|
|||||||
|
|
||||||
class JavaVersionTest : public QObject
|
class JavaVersionTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
void test_Parse_data()
|
void test_Parse_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("string");
|
QTest::addColumn<QString>("string");
|
||||||
QTest::addColumn<int>("major");
|
QTest::addColumn<int>("major");
|
||||||
QTest::addColumn<int>("minor");
|
QTest::addColumn<int>("minor");
|
||||||
QTest::addColumn<int>("security");
|
QTest::addColumn<int>("security");
|
||||||
QTest::addColumn<QString>("prerelease");
|
QTest::addColumn<QString>("prerelease");
|
||||||
|
|
||||||
QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString();
|
QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString();
|
||||||
QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea";
|
QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea";
|
||||||
|
|
||||||
QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString();
|
QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString();
|
||||||
QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString();
|
QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString();
|
||||||
QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString();
|
QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString();
|
||||||
QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea";
|
QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea";
|
||||||
QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea";
|
QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea";
|
||||||
}
|
}
|
||||||
void test_Parse()
|
void test_Parse()
|
||||||
{
|
{
|
||||||
QFETCH(QString, string);
|
QFETCH(QString, string);
|
||||||
QFETCH(int, major);
|
QFETCH(int, major);
|
||||||
QFETCH(int, minor);
|
QFETCH(int, minor);
|
||||||
QFETCH(int, security);
|
QFETCH(int, security);
|
||||||
QFETCH(QString, prerelease);
|
QFETCH(QString, prerelease);
|
||||||
|
|
||||||
JavaVersion test(string);
|
JavaVersion test(string);
|
||||||
QCOMPARE(test.m_string, string);
|
QCOMPARE(test.m_string, string);
|
||||||
QCOMPARE(test.toString(), string);
|
QCOMPARE(test.toString(), string);
|
||||||
QCOMPARE(test.m_major, major);
|
QCOMPARE(test.m_major, major);
|
||||||
QCOMPARE(test.m_minor, minor);
|
QCOMPARE(test.m_minor, minor);
|
||||||
QCOMPARE(test.m_security, security);
|
QCOMPARE(test.m_security, security);
|
||||||
QCOMPARE(test.m_prerelease, prerelease);
|
QCOMPARE(test.m_prerelease, prerelease);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_Sort_data()
|
void test_Sort_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("lhs");
|
QTest::addColumn<QString>("lhs");
|
||||||
QTest::addColumn<QString>("rhs");
|
QTest::addColumn<QString>("rhs");
|
||||||
QTest::addColumn<bool>("smaller");
|
QTest::addColumn<bool>("smaller");
|
||||||
QTest::addColumn<bool>("equal");
|
QTest::addColumn<bool>("equal");
|
||||||
QTest::addColumn<bool>("bigger");
|
QTest::addColumn<bool>("bigger");
|
||||||
|
|
||||||
// old format and new format equivalence
|
// old format and new format equivalence
|
||||||
QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false;
|
QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false;
|
||||||
// old format major version
|
// old format major version
|
||||||
QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false;
|
QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false;
|
||||||
// new format - first release vs first security patch
|
// new format - first release vs first security patch
|
||||||
QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false;
|
QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false;
|
||||||
QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true;
|
QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true;
|
||||||
// new format - first minor vs first release/security patch
|
// new format - first minor vs first release/security patch
|
||||||
QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" << false << false << true;
|
QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" << false << false << true;
|
||||||
QTest::newRow("9.0.1 < 9.1") << "9.0.1" << "9.1" << true << false << false;
|
QTest::newRow("9.0.1 < 9.1") << "9.0.1" << "9.1" << true << false << false;
|
||||||
QTest::newRow("9.1 > 9") << "9.1" << "9" << false << false << true;
|
QTest::newRow("9.1 > 9") << "9.1" << "9" << false << false << true;
|
||||||
QTest::newRow("9 > 9.1") << "9" << "9.1" << true << false << false;
|
QTest::newRow("9 > 9.1") << "9" << "9.1" << true << false << false;
|
||||||
// new format - omitted numbers
|
// new format - omitted numbers
|
||||||
QTest::newRow("9 == 9.0") << "9" << "9.0" << false << true << false;
|
QTest::newRow("9 == 9.0") << "9" << "9.0" << false << true << false;
|
||||||
QTest::newRow("9 == 9.0.0") << "9" << "9.0.0" << false << true << false;
|
QTest::newRow("9 == 9.0.0") << "9" << "9.0.0" << false << true << false;
|
||||||
QTest::newRow("9.0 == 9.0.0") << "9.0" << "9.0.0" << false << true << false;
|
QTest::newRow("9.0 == 9.0.0") << "9.0" << "9.0.0" << false << true << false;
|
||||||
// early access and prereleases compared to final release
|
// early access and prereleases compared to final release
|
||||||
QTest::newRow("9-ea < 9") << "9-ea" << "9" << true << false << false;
|
QTest::newRow("9-ea < 9") << "9-ea" << "9" << true << false << false;
|
||||||
QTest::newRow("9 < 9.0.1-ea") << "9" << "9.0.1-ea" << true << false << false;
|
QTest::newRow("9 < 9.0.1-ea") << "9" << "9.0.1-ea" << true << false << false;
|
||||||
QTest::newRow("9.0.1-ea > 9") << "9.0.1-ea" << "9" << false << false << true;
|
QTest::newRow("9.0.1-ea > 9") << "9.0.1-ea" << "9" << false << false << true;
|
||||||
// prerelease difference only testing
|
// prerelease difference only testing
|
||||||
QTest::newRow("9-1 == 9-1") << "9-1" << "9-1" << false << true << false;
|
QTest::newRow("9-1 == 9-1") << "9-1" << "9-1" << false << true << false;
|
||||||
QTest::newRow("9-1 < 9-2") << "9-1" << "9-2" << true << false << false;
|
QTest::newRow("9-1 < 9-2") << "9-1" << "9-2" << true << false << false;
|
||||||
QTest::newRow("9-5 < 9-20") << "9-5" << "9-20" << true << false << false;
|
QTest::newRow("9-5 < 9-20") << "9-5" << "9-20" << true << false << false;
|
||||||
QTest::newRow("9-rc1 < 9-rc2") << "9-rc1" << "9-rc2" << true << false << false;
|
QTest::newRow("9-rc1 < 9-rc2") << "9-rc1" << "9-rc2" << true << false << false;
|
||||||
QTest::newRow("9-rc5 < 9-rc20") << "9-rc5" << "9-rc20" << true << false << false;
|
QTest::newRow("9-rc5 < 9-rc20") << "9-rc5" << "9-rc20" << true << false << false;
|
||||||
QTest::newRow("9-rc < 9-rc2") << "9-rc" << "9-rc2" << true << false << false;
|
QTest::newRow("9-rc < 9-rc2") << "9-rc" << "9-rc2" << true << false << false;
|
||||||
QTest::newRow("9-ea < 9-rc") << "9-ea" << "9-rc" << true << false << false;
|
QTest::newRow("9-ea < 9-rc") << "9-ea" << "9-rc" << true << false << false;
|
||||||
}
|
}
|
||||||
void test_Sort()
|
void test_Sort()
|
||||||
{
|
{
|
||||||
QFETCH(QString, lhs);
|
QFETCH(QString, lhs);
|
||||||
QFETCH(QString, rhs);
|
QFETCH(QString, rhs);
|
||||||
QFETCH(bool, smaller);
|
QFETCH(bool, smaller);
|
||||||
QFETCH(bool, equal);
|
QFETCH(bool, equal);
|
||||||
QFETCH(bool, bigger);
|
QFETCH(bool, bigger);
|
||||||
JavaVersion lver(lhs);
|
JavaVersion lver(lhs);
|
||||||
JavaVersion rver(rhs);
|
JavaVersion rver(rhs);
|
||||||
QCOMPARE(lver < rver, smaller);
|
QCOMPARE(lver < rver, smaller);
|
||||||
QCOMPARE(lver == rver, equal);
|
QCOMPARE(lver == rver, equal);
|
||||||
QCOMPARE(lver > rver, bigger);
|
QCOMPARE(lver > rver, bigger);
|
||||||
}
|
}
|
||||||
void test_PermGen_data()
|
void test_PermGen_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("version");
|
QTest::addColumn<QString>("version");
|
||||||
QTest::addColumn<bool>("needs_permgen");
|
QTest::addColumn<bool>("needs_permgen");
|
||||||
QTest::newRow("1.6.0_33") << "1.6.0_33" << true;
|
QTest::newRow("1.6.0_33") << "1.6.0_33" << true;
|
||||||
QTest::newRow("1.7.0_60") << "1.7.0_60" << true;
|
QTest::newRow("1.7.0_60") << "1.7.0_60" << true;
|
||||||
QTest::newRow("1.8.0_22") << "1.8.0_22" << false;
|
QTest::newRow("1.8.0_22") << "1.8.0_22" << false;
|
||||||
QTest::newRow("9-ea") << "9-ea" << false;
|
QTest::newRow("9-ea") << "9-ea" << false;
|
||||||
QTest::newRow("9.2.4") << "9.2.4" << false;
|
QTest::newRow("9.2.4") << "9.2.4" << false;
|
||||||
}
|
}
|
||||||
void test_PermGen()
|
void test_PermGen()
|
||||||
{
|
{
|
||||||
QFETCH(QString, version);
|
QFETCH(QString, version);
|
||||||
QFETCH(bool, needs_permgen);
|
QFETCH(bool, needs_permgen);
|
||||||
JavaVersion v(version);
|
JavaVersion v(version);
|
||||||
QCOMPARE(needs_permgen, v.requiresPermGen());
|
QCOMPARE(needs_permgen, v.requiresPermGen());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(JavaVersionTest)
|
QTEST_GUILESS_MAIN(JavaVersionTest)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -22,115 +22,115 @@
|
|||||||
|
|
||||||
void CheckJava::executeTask()
|
void CheckJava::executeTask()
|
||||||
{
|
{
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
auto settings = instance->settings();
|
auto settings = instance->settings();
|
||||||
m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString());
|
m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString());
|
||||||
bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
|
bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
|
||||||
|
|
||||||
auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
|
auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
|
||||||
if (realJavaPath.isEmpty())
|
if (realJavaPath.isEmpty())
|
||||||
{
|
{
|
||||||
if (perInstance)
|
if (perInstance)
|
||||||
{
|
{
|
||||||
emit logLine(
|
emit logLine(
|
||||||
tr("The java binary \"%1\" couldn't be found. Please fix the java path "
|
tr("The java binary \"%1\" couldn't be found. Please fix the java path "
|
||||||
"override in the instance's settings or disable it.").arg(m_javaPath),
|
"override in the instance's settings or disable it.").arg(m_javaPath),
|
||||||
MessageLevel::Warning);
|
MessageLevel::Warning);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit logLine(tr("The java binary \"%1\" couldn't be found. Please set up java in "
|
emit logLine(tr("The java binary \"%1\" couldn't be found. Please set up java in "
|
||||||
"the settings.").arg(m_javaPath),
|
"the settings.").arg(m_javaPath),
|
||||||
MessageLevel::Warning);
|
MessageLevel::Warning);
|
||||||
}
|
}
|
||||||
emitFailed(tr("Java path is not valid."));
|
emitFailed(tr("Java path is not valid."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::MultiMC);
|
emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::MultiMC);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo javaInfo(realJavaPath);
|
QFileInfo javaInfo(realJavaPath);
|
||||||
qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
|
qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
|
||||||
auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
|
auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
|
||||||
auto storedArchitecture = settings->get("JavaArchitecture").toString();
|
auto storedArchitecture = settings->get("JavaArchitecture").toString();
|
||||||
auto storedVersion = settings->get("JavaVersion").toString();
|
auto storedVersion = settings->get("JavaVersion").toString();
|
||||||
m_javaUnixTime = javaUnixTime;
|
m_javaUnixTime = javaUnixTime;
|
||||||
// if timestamps are not the same, or something is missing, check!
|
// if timestamps are not the same, or something is missing, check!
|
||||||
if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0)
|
if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0)
|
||||||
{
|
{
|
||||||
m_JavaChecker = new JavaChecker();
|
m_JavaChecker = std::make_shared<JavaChecker>();
|
||||||
emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC);
|
emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC);
|
||||||
connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
|
connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
|
||||||
m_JavaChecker->m_path = realJavaPath;
|
m_JavaChecker->m_path = realJavaPath;
|
||||||
m_JavaChecker->performCheck();
|
m_JavaChecker->performCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto verString = instance->settings()->get("JavaVersion").toString();
|
auto verString = instance->settings()->get("JavaVersion").toString();
|
||||||
auto archString = instance->settings()->get("JavaArchitecture").toString();
|
auto archString = instance->settings()->get("JavaArchitecture").toString();
|
||||||
printJavaInfo(verString, archString);
|
printJavaInfo(verString, archString);
|
||||||
}
|
}
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckJava::checkJavaFinished(JavaCheckResult result)
|
void CheckJava::checkJavaFinished(JavaCheckResult result)
|
||||||
{
|
{
|
||||||
switch (result.validity)
|
switch (result.validity)
|
||||||
{
|
{
|
||||||
case JavaCheckResult::Validity::Errored:
|
case JavaCheckResult::Validity::Errored:
|
||||||
{
|
{
|
||||||
// Error message displayed if java can't start
|
// Error message displayed if java can't start
|
||||||
emit logLine(tr("Could not start java:"), MessageLevel::Error);
|
emit logLine(tr("Could not start java:"), MessageLevel::Error);
|
||||||
emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
|
emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
|
||||||
emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
|
emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
|
||||||
printSystemInfo(false, false);
|
printSystemInfo(false, false);
|
||||||
emitFailed(tr("Could not start java!"));
|
emitFailed(tr("Could not start java!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case JavaCheckResult::Validity::ReturnedInvalidData:
|
case JavaCheckResult::Validity::ReturnedInvalidData:
|
||||||
{
|
{
|
||||||
emit logLine(tr("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
|
emit logLine(tr("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
|
||||||
emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
|
emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
|
||||||
emit logLine("\nMinecraft might not start properly.", MessageLevel::MultiMC);
|
emit logLine("\nMinecraft might not start properly.", MessageLevel::MultiMC);
|
||||||
printSystemInfo(false, false);
|
printSystemInfo(false, false);
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case JavaCheckResult::Validity::Valid:
|
case JavaCheckResult::Validity::Valid:
|
||||||
{
|
{
|
||||||
auto instance = m_parent->instance();
|
auto instance = m_parent->instance();
|
||||||
printJavaInfo(result.javaVersion.toString(), result.mojangPlatform);
|
printJavaInfo(result.javaVersion.toString(), result.mojangPlatform);
|
||||||
instance->settings()->set("JavaVersion", result.javaVersion.toString());
|
instance->settings()->set("JavaVersion", result.javaVersion.toString());
|
||||||
instance->settings()->set("JavaArchitecture", result.mojangPlatform);
|
instance->settings()->set("JavaArchitecture", result.mojangPlatform);
|
||||||
instance->settings()->set("JavaTimestamp", m_javaUnixTime);
|
instance->settings()->set("JavaTimestamp", m_javaUnixTime);
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckJava::printJavaInfo(const QString& version, const QString& architecture)
|
void CheckJava::printJavaInfo(const QString& version, const QString& architecture)
|
||||||
{
|
{
|
||||||
emit logLine(tr("Java is version %1, using %2-bit architecture.\n\n").arg(version, architecture), MessageLevel::MultiMC);
|
emit logLine(tr("Java is version %1, using %2-bit architecture.\n\n").arg(version, architecture), MessageLevel::MultiMC);
|
||||||
printSystemInfo(true, architecture == "64");
|
printSystemInfo(true, architecture == "64");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit)
|
void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit)
|
||||||
{
|
{
|
||||||
auto cpu64 = Sys::isCPU64bit();
|
auto cpu64 = Sys::isCPU64bit();
|
||||||
auto system64 = Sys::isSystem64bit();
|
auto system64 = Sys::isSystem64bit();
|
||||||
if(cpu64 != system64)
|
if(cpu64 != system64)
|
||||||
{
|
{
|
||||||
emit logLine(tr("Your CPU architecture is not matching your system architecture. You might want to install a 64bit Operating System.\n\n"), MessageLevel::Error);
|
emit logLine(tr("Your CPU architecture is not matching your system architecture. You might want to install a 64bit Operating System.\n\n"), MessageLevel::Error);
|
||||||
}
|
}
|
||||||
if(javaIsKnown)
|
if(javaIsKnown)
|
||||||
{
|
{
|
||||||
if(javaIs64bit != system64)
|
if(javaIs64bit != system64)
|
||||||
{
|
{
|
||||||
emit logLine(tr("Your Java architecture is not matching your system architecture. You might want to install a 64bit Java version.\n\n"), MessageLevel::Error);
|
emit logLine(tr("Your Java architecture is not matching your system architecture. You might want to install a 64bit Java version.\n\n"), MessageLevel::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -21,25 +21,25 @@
|
|||||||
|
|
||||||
class CheckJava: public LaunchStep
|
class CheckJava: public LaunchStep
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CheckJava(LaunchTask *parent) :LaunchStep(parent){};
|
explicit CheckJava(LaunchTask *parent) :LaunchStep(parent){};
|
||||||
virtual ~CheckJava() {};
|
virtual ~CheckJava() {};
|
||||||
|
|
||||||
virtual void executeTask();
|
virtual void executeTask();
|
||||||
virtual bool canAbort() const
|
virtual bool canAbort() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private slots:
|
private slots:
|
||||||
void checkJavaFinished(JavaCheckResult result);
|
void checkJavaFinished(JavaCheckResult result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void printJavaInfo(const QString & version, const QString & architecture);
|
void printJavaInfo(const QString & version, const QString & architecture);
|
||||||
void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
|
void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_javaPath;
|
QString m_javaPath;
|
||||||
qlonglong m_javaUnixTime;
|
qlonglong m_javaUnixTime;
|
||||||
JavaCheckerPtr m_JavaChecker;
|
JavaCheckerPtr m_JavaChecker;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -18,10 +18,10 @@
|
|||||||
|
|
||||||
void LaunchStep::bind(LaunchTask *parent)
|
void LaunchStep::bind(LaunchTask *parent)
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);
|
connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);
|
||||||
connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
|
connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
|
||||||
connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
|
connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
|
||||||
connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
|
connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
|
||||||
connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
|
connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 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.
|
||||||
@@ -23,28 +23,28 @@
|
|||||||
class LaunchTask;
|
class LaunchTask;
|
||||||
class LaunchStep: public Task
|
class LaunchStep: public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
explicit LaunchStep(LaunchTask *parent):Task(nullptr), m_parent(parent)
|
explicit LaunchStep(LaunchTask *parent):Task(nullptr), m_parent(parent)
|
||||||
{
|
{
|
||||||
bind(parent);
|
bind(parent);
|
||||||
};
|
};
|
||||||
virtual ~LaunchStep() {};
|
virtual ~LaunchStep() {};
|
||||||
|
|
||||||
private: /* methods */
|
protected: /* methods */
|
||||||
void bind(LaunchTask *parent);
|
virtual void bind(LaunchTask *parent);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void logLines(QStringList lines, MessageLevel::Enum level);
|
void logLines(QStringList lines, MessageLevel::Enum level);
|
||||||
void logLine(QString line, MessageLevel::Enum level);
|
void logLine(QString line, MessageLevel::Enum level);
|
||||||
void readyForLaunch();
|
void readyForLaunch();
|
||||||
void progressReportingRequest();
|
void progressReportingRequest();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void proceed() {};
|
virtual void proceed() {};
|
||||||
// called in the opposite order than the Task launch(), used to clean up or otherwise undo things after the launch ends
|
// called in the opposite order than the Task launch(), used to clean up or otherwise undo things after the launch ends
|
||||||
virtual void finalize() {};
|
virtual void finalize() {};
|
||||||
|
|
||||||
protected: /* data */
|
protected: /* data */
|
||||||
LaunchTask *m_parent;
|
LaunchTask *m_parent;
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2013-2019 MultiMC Contributors
|
/* Copyright 2013-2017 MultiMC Contributors
|
||||||
*
|
*
|
||||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -30,251 +30,251 @@
|
|||||||
|
|
||||||
void LaunchTask::init()
|
void LaunchTask::init()
|
||||||
{
|
{
|
||||||
m_instance->setRunning(true);
|
m_instance->setRunning(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<LaunchTask> LaunchTask::create(InstancePtr inst)
|
std::shared_ptr<LaunchTask> LaunchTask::create(InstancePtr inst)
|
||||||
{
|
{
|
||||||
shared_qobject_ptr<LaunchTask> proc(new LaunchTask(inst));
|
std::shared_ptr<LaunchTask> proc(new LaunchTask(inst));
|
||||||
proc->init();
|
proc->init();
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchTask::LaunchTask(InstancePtr instance): m_instance(instance)
|
LaunchTask::LaunchTask(InstancePtr instance): m_instance(instance)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::appendStep(shared_qobject_ptr<LaunchStep> step)
|
void LaunchTask::appendStep(std::shared_ptr<LaunchStep> step)
|
||||||
{
|
{
|
||||||
m_steps.append(step);
|
m_steps.append(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::prependStep(shared_qobject_ptr<LaunchStep> step)
|
void LaunchTask::prependStep(std::shared_ptr<LaunchStep> step)
|
||||||
{
|
{
|
||||||
m_steps.prepend(step);
|
m_steps.prepend(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::executeTask()
|
void LaunchTask::executeTask()
|
||||||
{
|
{
|
||||||
m_instance->setCrashed(false);
|
m_instance->setCrashed(false);
|
||||||
if(!m_steps.size())
|
if(!m_steps.size())
|
||||||
{
|
{
|
||||||
state = LaunchTask::Finished;
|
state = LaunchTask::Finished;
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
state = LaunchTask::Running;
|
state = LaunchTask::Running;
|
||||||
onStepFinished();
|
onStepFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::onReadyForLaunch()
|
void LaunchTask::onReadyForLaunch()
|
||||||
{
|
{
|
||||||
state = LaunchTask::Waiting;
|
state = LaunchTask::Waiting;
|
||||||
emit readyForLaunch();
|
emit readyForLaunch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::onStepFinished()
|
void LaunchTask::onStepFinished()
|
||||||
{
|
{
|
||||||
// initial -> just start the first step
|
// initial -> just start the first step
|
||||||
if(currentStep == -1)
|
if(currentStep == -1)
|
||||||
{
|
{
|
||||||
currentStep ++;
|
currentStep ++;
|
||||||
m_steps[currentStep]->start();
|
m_steps[currentStep]->start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto step = m_steps[currentStep];
|
auto step = m_steps[currentStep];
|
||||||
if(step->wasSuccessful())
|
if(step->successful())
|
||||||
{
|
{
|
||||||
// end?
|
// end?
|
||||||
if(currentStep == m_steps.size() - 1)
|
if(currentStep == m_steps.size() - 1)
|
||||||
{
|
{
|
||||||
finalizeSteps(true, QString());
|
finalizeSteps(true, QString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentStep ++;
|
currentStep ++;
|
||||||
step = m_steps[currentStep];
|
step = m_steps[currentStep];
|
||||||
step->start();
|
step->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
finalizeSteps(false, step->failReason());
|
finalizeSteps(false, step->failReason());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::finalizeSteps(bool successful, const QString& error)
|
void LaunchTask::finalizeSteps(bool successful, const QString& error)
|
||||||
{
|
{
|
||||||
for(auto step = currentStep; step >= 0; step--)
|
for(auto step = currentStep; step >= 0; step--)
|
||||||
{
|
{
|
||||||
m_steps[step]->finalize();
|
m_steps[step]->finalize();
|
||||||
}
|
}
|
||||||
if(successful)
|
if(successful)
|
||||||
{
|
{
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emitFailed(error);
|
emitFailed(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::onProgressReportingRequested()
|
void LaunchTask::onProgressReportingRequested()
|
||||||
{
|
{
|
||||||
state = LaunchTask::Waiting;
|
state = LaunchTask::Waiting;
|
||||||
emit requestProgress(m_steps[currentStep].get());
|
emit requestProgress(m_steps[currentStep].get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::setCensorFilter(QMap<QString, QString> filter)
|
void LaunchTask::setCensorFilter(QMap<QString, QString> filter)
|
||||||
{
|
{
|
||||||
m_censorFilter = filter;
|
m_censorFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LaunchTask::censorPrivateInfo(QString in)
|
QString LaunchTask::censorPrivateInfo(QString in)
|
||||||
{
|
{
|
||||||
auto iter = m_censorFilter.begin();
|
auto iter = m_censorFilter.begin();
|
||||||
while (iter != m_censorFilter.end())
|
while (iter != m_censorFilter.end())
|
||||||
{
|
{
|
||||||
in.replace(iter.key(), iter.value());
|
in.replace(iter.key(), iter.value());
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::proceed()
|
void LaunchTask::proceed()
|
||||||
{
|
{
|
||||||
if(state != LaunchTask::Waiting)
|
if(state != LaunchTask::Waiting)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_steps[currentStep]->proceed();
|
m_steps[currentStep]->proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LaunchTask::canAbort() const
|
bool LaunchTask::canAbort() const
|
||||||
{
|
{
|
||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
case LaunchTask::Aborted:
|
case LaunchTask::Aborted:
|
||||||
case LaunchTask::Failed:
|
case LaunchTask::Failed:
|
||||||
case LaunchTask::Finished:
|
case LaunchTask::Finished:
|
||||||
return false;
|
return false;
|
||||||
case LaunchTask::NotStarted:
|
case LaunchTask::NotStarted:
|
||||||
return true;
|
return true;
|
||||||
case LaunchTask::Running:
|
case LaunchTask::Running:
|
||||||
case LaunchTask::Waiting:
|
case LaunchTask::Waiting:
|
||||||
{
|
{
|
||||||
auto step = m_steps[currentStep];
|
auto step = m_steps[currentStep];
|
||||||
return step->canAbort();
|
return step->canAbort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LaunchTask::abort()
|
bool LaunchTask::abort()
|
||||||
{
|
{
|
||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
case LaunchTask::Aborted:
|
case LaunchTask::Aborted:
|
||||||
case LaunchTask::Failed:
|
case LaunchTask::Failed:
|
||||||
case LaunchTask::Finished:
|
case LaunchTask::Finished:
|
||||||
return true;
|
return true;
|
||||||
case LaunchTask::NotStarted:
|
case LaunchTask::NotStarted:
|
||||||
{
|
{
|
||||||
state = LaunchTask::Aborted;
|
state = LaunchTask::Aborted;
|
||||||
emitFailed("Aborted");
|
emitFailed("Aborted");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case LaunchTask::Running:
|
case LaunchTask::Running:
|
||||||
case LaunchTask::Waiting:
|
case LaunchTask::Waiting:
|
||||||
{
|
{
|
||||||
auto step = m_steps[currentStep];
|
auto step = m_steps[currentStep];
|
||||||
if(!step->canAbort())
|
if(!step->canAbort())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(step->abort())
|
if(step->abort())
|
||||||
{
|
{
|
||||||
state = LaunchTask::Aborted;
|
state = LaunchTask::Aborted;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
|
shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
|
||||||
{
|
{
|
||||||
if(!m_logModel)
|
if(!m_logModel)
|
||||||
{
|
{
|
||||||
m_logModel.reset(new LogModel());
|
m_logModel.reset(new LogModel());
|
||||||
m_logModel->setMaxLines(m_instance->getConsoleMaxLines());
|
m_logModel->setMaxLines(m_instance->getConsoleMaxLines());
|
||||||
m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
|
m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
|
||||||
// FIXME: should this really be here?
|
// FIXME: should this really be here?
|
||||||
m_logModel->setOverflowMessage(tr("MultiMC stopped watching the game log because the log length surpassed %1 lines.\n"
|
m_logModel->setOverflowMessage(tr("MultiMC stopped watching the game log because the log length surpassed %1 lines.\n"
|
||||||
"You may have to fix your mods because the game is still logging to files and"
|
"You may have to fix your mods because the game is still logging to files and"
|
||||||
" likely wasting harddrive space at an alarming rate!").arg(m_logModel->getMaxLines()));
|
" likely wasting harddrive space at an alarming rate!").arg(m_logModel->getMaxLines()));
|
||||||
}
|
}
|
||||||
return m_logModel;
|
return m_logModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::onLogLines(const QStringList &lines, MessageLevel::Enum defaultLevel)
|
void LaunchTask::onLogLines(const QStringList &lines, MessageLevel::Enum defaultLevel)
|
||||||
{
|
{
|
||||||
for (auto & line: lines)
|
for (auto & line: lines)
|
||||||
{
|
{
|
||||||
onLogLine(line, defaultLevel);
|
onLogLine(line, defaultLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::onLogLine(QString line, MessageLevel::Enum level)
|
void LaunchTask::onLogLine(QString line, MessageLevel::Enum level)
|
||||||
{
|
{
|
||||||
// if the launcher part set a log level, use it
|
// if the launcher part set a log level, use it
|
||||||
auto innerLevel = MessageLevel::fromLine(line);
|
auto innerLevel = MessageLevel::fromLine(line);
|
||||||
if(innerLevel != MessageLevel::Unknown)
|
if(innerLevel != MessageLevel::Unknown)
|
||||||
{
|
{
|
||||||
level = innerLevel;
|
level = innerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the level is still undetermined, guess level
|
// If the level is still undetermined, guess level
|
||||||
if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown)
|
if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown)
|
||||||
{
|
{
|
||||||
level = m_instance->guessLevel(line, level);
|
level = m_instance->guessLevel(line, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
// censor private user info
|
// censor private user info
|
||||||
line = censorPrivateInfo(line);
|
line = censorPrivateInfo(line);
|
||||||
|
|
||||||
auto &model = *getLogModel();
|
auto &model = *getLogModel();
|
||||||
model.append(level, line);
|
model.append(level, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::emitSucceeded()
|
void LaunchTask::emitSucceeded()
|
||||||
{
|
{
|
||||||
m_instance->setRunning(false);
|
m_instance->setRunning(false);
|
||||||
Task::emitSucceeded();
|
Task::emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::emitFailed(QString reason)
|
void LaunchTask::emitFailed(QString reason)
|
||||||
{
|
{
|
||||||
m_instance->setRunning(false);
|
m_instance->setRunning(false);
|
||||||
m_instance->setCrashed(true);
|
m_instance->setCrashed(true);
|
||||||
Task::emitFailed(reason);
|
Task::emitFailed(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LaunchTask::substituteVariables(const QString &cmd) const
|
QString LaunchTask::substituteVariables(const QString &cmd) const
|
||||||
{
|
{
|
||||||
QString out = cmd;
|
QString out = cmd;
|
||||||
auto variables = m_instance->getVariables();
|
auto variables = m_instance->getVariables();
|
||||||
for (auto it = variables.begin(); it != variables.end(); ++it)
|
for (auto it = variables.begin(); it != variables.end(); ++it)
|
||||||
{
|
{
|
||||||
out.replace("$" + it.key(), it.value());
|
out.replace("$" + it.key(), it.value());
|
||||||
}
|
}
|
||||||
auto env = QProcessEnvironment::systemEnvironment();
|
auto env = QProcessEnvironment::systemEnvironment();
|
||||||
for (auto var : env.keys())
|
for (auto var : env.keys())
|
||||||
{
|
{
|
||||||
out.replace("$" + var, env.value(var));
|
out.replace("$" + var, env.value(var));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user