mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-13 20:22:13 +00:00
Compare commits
271 Commits
0.4.8
...
0.5.2-fina
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b85d7c0de | ||
|
|
1eb6e77f75 | ||
|
|
f49f8b875a | ||
|
|
23d2a99619 | ||
|
|
170bd677fd | ||
|
|
84e23e2e7a | ||
|
|
aafac3934b | ||
|
|
17fac2e0df | ||
|
|
8bbaab334c | ||
|
|
155de307bc | ||
|
|
2e8d8b60b0 | ||
|
|
c200301673 | ||
|
|
0a6af3cff3 | ||
|
|
c7f89ec6b5 | ||
|
|
cf43abc87e | ||
|
|
c421134d49 | ||
|
|
782384f185 | ||
|
|
ceb5fc6d75 | ||
|
|
201d4ac317 | ||
|
|
85320777c6 | ||
|
|
ba38991c13 | ||
|
|
98e17998fe | ||
|
|
944ff256b2 | ||
|
|
71584fb8cc | ||
|
|
b2dbaaa9e2 | ||
|
|
0a89b04afd | ||
|
|
ffa8792c13 | ||
|
|
fbcbddd4d0 | ||
|
|
a6ef0059cc | ||
|
|
3e81e2cb5b | ||
|
|
858b490c74 | ||
|
|
12c3683ec0 | ||
|
|
f530aae9d3 | ||
|
|
5ea224f8f5 | ||
|
|
e033cf8974 | ||
|
|
8e7330ae54 | ||
|
|
ccb524ed9f | ||
|
|
cff34a14dc | ||
|
|
8421ef622d | ||
|
|
c4ec6bc0f5 | ||
|
|
705a658fef | ||
|
|
6f17183bf0 | ||
|
|
0249bd9eea | ||
|
|
e1bd1c6145 | ||
|
|
4c0db2b99d | ||
|
|
9ca9addad3 | ||
|
|
64723f68e3 | ||
|
|
a666dc0a1a | ||
|
|
722896d41f | ||
|
|
46c5368a78 | ||
|
|
476d641841 | ||
|
|
374710a87b | ||
|
|
2344ee2dcd | ||
|
|
481ecb178c | ||
|
|
123b59e63f | ||
|
|
92bb001787 | ||
|
|
03d2858c62 | ||
|
|
a6882787b0 | ||
|
|
2517d2c84d | ||
|
|
035bdc7576 | ||
|
|
4ca6878743 | ||
|
|
ef73a2bd32 | ||
|
|
5994c47d7c | ||
|
|
66ffab71ae | ||
|
|
ce70407363 | ||
|
|
dccf9d7219 | ||
|
|
dd0c815396 | ||
|
|
55541c387c | ||
|
|
d5fdc23eb2 | ||
|
|
a5fb931e8e | ||
|
|
486d653586 | ||
|
|
121e2fd46c | ||
|
|
295c6e808a | ||
|
|
7a14b63957 | ||
|
|
44805145dc | ||
|
|
00c4aebeaa | ||
|
|
ee6f2f0a8e | ||
|
|
95f961fb61 | ||
|
|
ad25c89ac4 | ||
|
|
905bc2e440 | ||
|
|
2f8c752d1f | ||
|
|
2ec15c32e4 | ||
|
|
69be23c5f6 | ||
|
|
e974950d48 | ||
|
|
9efdd7232c | ||
|
|
9b41986634 | ||
|
|
b09fad9cbf | ||
|
|
fd34ca5a0f | ||
|
|
9cf8b42d89 | ||
|
|
12f6534e77 | ||
|
|
3769897be1 | ||
|
|
590ff82fd1 | ||
|
|
f9d94a45ee | ||
|
|
27e26a656b | ||
|
|
b6f133f579 | ||
|
|
01649f761d | ||
|
|
dae3b06885 | ||
|
|
07589b5114 | ||
|
|
7cff5ba2e1 | ||
|
|
1276ecdbb7 | ||
|
|
8b952b3870 | ||
|
|
37cc59c04d | ||
|
|
bc753859b5 | ||
|
|
13b575f7a9 | ||
|
|
495e752f8a | ||
|
|
87dd951505 | ||
|
|
3780a25d27 | ||
|
|
6ebf6e7785 | ||
|
|
f4de049b13 | ||
|
|
f0b71f989e | ||
|
|
ac66af6c13 | ||
|
|
85b64ad767 | ||
|
|
3a4304d89d | ||
|
|
a9c0d812a6 | ||
|
|
b6b2350e02 | ||
|
|
2e0a45cc2f | ||
|
|
fe68d59460 | ||
|
|
4b03dfcbd7 | ||
|
|
a36c962a31 | ||
|
|
e9949e3a54 | ||
|
|
a717864013 | ||
|
|
54e0b9bc9b | ||
|
|
249e5c13d7 | ||
|
|
412855ae3d | ||
|
|
deabfa78f8 | ||
|
|
2b9017a69c | ||
|
|
172ff47a65 | ||
|
|
b5aaf88f12 | ||
|
|
8731318fef | ||
|
|
dd0e996081 | ||
|
|
3d94fb8d24 | ||
|
|
2c2c1b0a17 | ||
|
|
0493170936 | ||
|
|
2597bde4f9 | ||
|
|
cee53f7f3c | ||
|
|
1b4851a941 | ||
|
|
d66fdcd4cc | ||
|
|
bbe139dce5 | ||
|
|
872cfe036d | ||
|
|
f07496ac6d | ||
|
|
6e80f03409 | ||
|
|
69f3ab019d | ||
|
|
eb747e08b7 | ||
|
|
67eca08b22 | ||
|
|
9aff21c181 | ||
|
|
ec05ca2775 | ||
|
|
042f3ef55c | ||
|
|
2f0441b3c1 | ||
|
|
55544893a3 | ||
|
|
e2f3652a0f | ||
|
|
c60db13af7 | ||
|
|
fc198dd308 | ||
|
|
74b4343c43 | ||
|
|
877d1020db | ||
|
|
bc6d1b5304 | ||
|
|
c44d41ee9b | ||
|
|
cf0694a0cb | ||
|
|
b76d4573cd | ||
|
|
6ec2652b45 | ||
|
|
eec87db86a | ||
|
|
42a98c3661 | ||
|
|
1f2bed2ef1 | ||
|
|
57c84ec2b1 | ||
|
|
2164dc13f4 | ||
|
|
f626fd02c7 | ||
|
|
7da70a75eb | ||
|
|
969418f01f | ||
|
|
6ecfe8546f | ||
|
|
8b74f6dcf0 | ||
|
|
d4109938fe | ||
|
|
be89024d4e | ||
|
|
56394f93e5 | ||
|
|
e07456f4bf | ||
|
|
54e5a98da0 | ||
|
|
a1abbd9e05 | ||
|
|
a750f6e63c | ||
|
|
4440f68e59 | ||
|
|
67b22c8105 | ||
|
|
12413f722d | ||
|
|
5aff10d51d | ||
|
|
377316999e | ||
|
|
f9791a5cc8 | ||
|
|
603b0408ab | ||
|
|
ecd5d3a2db | ||
|
|
898e3cd4e7 | ||
|
|
e1a530f84d | ||
|
|
c50b3cdeec | ||
|
|
b0bfffcd90 | ||
|
|
80b28e7d49 | ||
|
|
16650790d0 | ||
|
|
e32d7238c9 | ||
|
|
771dd6f9ab | ||
|
|
e8ba5dafc6 | ||
|
|
ed3884fd38 | ||
|
|
1be7d57332 | ||
|
|
aa4842a91d | ||
|
|
b6d455a02b | ||
|
|
47e37635f5 | ||
|
|
fcd4a482f7 | ||
|
|
00e5968bd2 | ||
|
|
5ae3b2c114 | ||
|
|
4392abfb8d | ||
|
|
72c92893a5 | ||
|
|
0890a81695 | ||
|
|
432ec74174 | ||
|
|
b795ad5209 | ||
|
|
c44e85c765 | ||
|
|
b29ef49415 | ||
|
|
f184eff71a | ||
|
|
b3e3a6fc88 | ||
|
|
0ff6f3a036 | ||
|
|
bf0f27bd60 | ||
|
|
dd5b07e38d | ||
|
|
ea685651a1 | ||
|
|
53b4bd019f | ||
|
|
f032e32133 | ||
|
|
d587720010 | ||
|
|
2929ca7413 | ||
|
|
ff8f495d44 | ||
|
|
f56983e5ca | ||
|
|
ec6204e447 | ||
|
|
9e3534f2f6 | ||
|
|
b7d8e512f4 | ||
|
|
fb9dfcb951 | ||
|
|
010e07eb45 | ||
|
|
576d808d71 | ||
|
|
f63d1bc99c | ||
|
|
02c1df2c3c | ||
|
|
1854e05e1b | ||
|
|
0c06ab364c | ||
|
|
07608ebc4c | ||
|
|
36f3813ce5 | ||
|
|
f96d20b6f7 | ||
|
|
ead4c17d0a | ||
|
|
d4eacb56b3 | ||
|
|
3d8728f52f | ||
|
|
2e4fa7ec13 | ||
|
|
fd2103d6ee | ||
|
|
94d4684809 | ||
|
|
b54839b897 | ||
|
|
80b81c2c1e | ||
|
|
f53cd55fbb | ||
|
|
a3cd3d5ff1 | ||
|
|
1a9793197f | ||
|
|
9497b7e96c | ||
|
|
a0b47aee5b | ||
|
|
17ad1e64f8 | ||
|
|
71e4b147ec | ||
|
|
f6b2ccb110 | ||
|
|
c943019ab5 | ||
|
|
fc43fd1105 | ||
|
|
401d5b698f | ||
|
|
1a0bbdd9ac | ||
|
|
495d320ce2 | ||
|
|
5e737f42bf | ||
|
|
6e6e2bf262 | ||
|
|
163a3095b1 | ||
|
|
a20e2590da | ||
|
|
1978078662 | ||
|
|
ea08ede4c3 | ||
|
|
b7f75637fa | ||
|
|
4ee1900201 | ||
|
|
ab67d763f4 | ||
|
|
7ca9f92343 | ||
|
|
cbd4b88e91 | ||
|
|
0958bb2fcc | ||
|
|
fbec48080b | ||
|
|
33b6222f9f | ||
|
|
5ecaed21b5 | ||
|
|
9fd66b3bb1 | ||
|
|
47ea2a71c0 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1 +1,2 @@
|
||||
*.pem -crlf
|
||||
**/testdata/** -text -diff
|
||||
|
||||
50
.github/ISSUE_TEMPLATE.md
vendored
Normal file
50
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<!--
|
||||
Before submitting this issue, please make sure you have:
|
||||
|
||||
1. Filled out this form completely, the only optional field is "additional info".
|
||||
- Use as many details as possible and state the problem clearly.
|
||||
2. Proof-read your ENTIRE issue report.
|
||||
- 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.
|
||||
- We provide support for MultiMC, not your modpack. Problems with your modpack will be ignored.
|
||||
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?!".
|
||||
5. Place all information below the ---- of lines.
|
||||
- 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
|
||||
-->
|
||||
|
||||
System Information
|
||||
-----------------------------
|
||||
MultiMC version:
|
||||
|
||||
Operating System:
|
||||
|
||||
Summary of the issue or suggestion:
|
||||
----------------------------------------------
|
||||
|
||||
|
||||
What should happen:
|
||||
------------------------------
|
||||
|
||||
|
||||
Steps to reproduce the issue (Add more if needed):
|
||||
-------------------------------------------------------------
|
||||
1.
|
||||
|
||||
2.
|
||||
|
||||
3.
|
||||
|
||||
Suspected cause:
|
||||
---------------------------
|
||||
|
||||
|
||||
Logs/Screenshots:
|
||||
----------------------------
|
||||
[//]: # (Please refer to https://github.com/MultiMC/MultiMC5/wiki/Log-Upload for instructions on how to attach your logs.)
|
||||
|
||||
|
||||
Additional Info:
|
||||
---------------------------
|
||||
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "depends/libnbtplusplus"]
|
||||
path = depends/libnbtplusplus
|
||||
path = libraries/libnbtplusplus
|
||||
url = https://github.com/MultiMC/libnbtplusplus.git
|
||||
[submodule "libraries/quazip"]
|
||||
path = libraries/quazip
|
||||
url = https://github.com/MultiMC/quazip.git
|
||||
|
||||
24
.travis.yml
24
.travis.yml
@@ -1,9 +1,6 @@
|
||||
# General set up
|
||||
language: cpp
|
||||
cache: apt
|
||||
notifications:
|
||||
irc: "irc.esper.net#MultiMC"
|
||||
email: false
|
||||
|
||||
# Build matrix set up
|
||||
compiler:
|
||||
@@ -13,34 +10,21 @@ os:
|
||||
- linux
|
||||
# - osx
|
||||
env:
|
||||
- QT_VERSION=5.0.2
|
||||
- QT_VERSION=5.1.1
|
||||
- QT_VERSION=5.2.1
|
||||
- QT_VERSION=5.3.2
|
||||
- QT_VERSION=5.4.2
|
||||
- QT_VERSION=5.5.1 # latest
|
||||
- QT_VERSION=5.5.1
|
||||
# - QT_VERSION=5.6.2
|
||||
matrix:
|
||||
exclude:
|
||||
# only use clang on OS X
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
# only use the qt available from homebrew
|
||||
- os: osx
|
||||
env: QT_VERSION=5.0.2
|
||||
- os: osx
|
||||
env: QT_VERSION=5.1.1
|
||||
- os: osx
|
||||
env: QT_VERSION=5.2.1
|
||||
- os: osx
|
||||
env: QT_VERSION=5.3.2
|
||||
- os: osx
|
||||
env: QT_VERSION=5.4.2
|
||||
- os: osx
|
||||
env: QT_VERSION=5.5.1
|
||||
allow_failures:
|
||||
- env: QT_VERSION=5.0.2
|
||||
- env: QT_VERSION=5.1.1
|
||||
- env: QT_VERSION=5.2.1
|
||||
# - os: osx
|
||||
# env: QT_VERSION=5.6
|
||||
|
||||
# Install dependencies
|
||||
install:
|
||||
|
||||
45
BUILD.md
45
BUILD.md
@@ -33,24 +33,45 @@ Getting the project to build and run on Linux is easy if you use any modern and
|
||||
|
||||
## Build dependencies
|
||||
* Ideally a compiler capable of building C++14 code (for example, GCC 5.2 and above).
|
||||
* Qt 5.5.1+ Development tools (http://qt-project.org/downloads) ("Qt Online Installer for Linux (64 bit)") or the equivalent from your package manager
|
||||
* 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
|
||||
* zlib (for example, `zlib1g-dev`)
|
||||
* java (for example, `openjdk-8-jdk`)
|
||||
* GL headers (for example, `libgl1-mesa-dev`)
|
||||
|
||||
### Installing Qt using the installer
|
||||
### Building from command line
|
||||
You need a source folder, a build folder and an install folder.
|
||||
|
||||
Let's say you want everything in `~/MultiMC/`:
|
||||
|
||||
```
|
||||
# make all the folders
|
||||
mkdir ~/MultiMC && cd ~/MultiMC
|
||||
mkdir build
|
||||
mkdir install
|
||||
# clone the complete source
|
||||
git clone --recursive git@github.com:MultiMC/MultiMC5.git src
|
||||
# configure the project
|
||||
cd build
|
||||
cmake -DCMAKE_INSTALL_PREFIX=../install ../src
|
||||
# build & install (use -j with the number of cores your CPU has)
|
||||
make -j8 install
|
||||
```
|
||||
|
||||
You can use IDEs like KDevelop or QtCreator to open the CMake project if you want to work on the code.
|
||||
|
||||
### Installing Qt using the installer (optional)
|
||||
1. Run the Qt installer.
|
||||
2. Choose a place to install Qt.
|
||||
3. Choose the components you want to install.
|
||||
- You need Qt 5.5.1/gcc 64-bit ticked.
|
||||
- You need Qt 5.4.1/gcc 64-bit ticked.
|
||||
- You need Tools/Qt Creator ticked.
|
||||
- Other components are selected by default, you can untick them if you don't need them.
|
||||
4. Accept the license agreements.
|
||||
5. Double check the install details and then click "Install".
|
||||
- Installation can take a very long time, go grab a cup of tea or something and let it work.
|
||||
|
||||
### Loading the project in Qt Creator
|
||||
### Loading the project in Qt Creator (optional)
|
||||
1. Open Qt Creator.
|
||||
2. Choose `File->Open File or Project`.
|
||||
3. Navigate to the MultiMC5 source folder you cloned and choose CMakeLists.txt.
|
||||
@@ -70,7 +91,7 @@ Getting the project to build and run on Linux is easy if you use any modern and
|
||||
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
|
||||
* [Qt 5.5.1+ 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
|
||||
- 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.
|
||||
@@ -120,6 +141,14 @@ Getting the project to build and run on Windows is easy if you use Qt's IDE, Qt
|
||||
- Test OpenSSL by making an instance and trying to log in. If Qt Creator couldn't find OpenSSL during the CMake stage, login will fail and you'll get an error.
|
||||
|
||||
**These build instructions worked for me (Drayshak) on a fresh Windows 8 x64 Professional install. If they don't work for you, let us know on IRC ([Esper/#MultiMC](http://webchat.esper.net/?nick=&channels=MultiMC))!**
|
||||
### Compile from command line on Windows
|
||||
1. If you installed Qt with the web installer, there should be a shortcut called `Qt 5.4 for Desktop (MinGW 4.9 32-bit)` in the Start menu on Windows 7 and 10. Best way to find it is to search for it. Do note you cannot just use cmd.exe, you have to use the shortcut, otherwise the proper MinGW software will not be on the PATH.
|
||||
2. Once that is open, change into your user directory, and clone MultiMC by doing `git clone --recursive https://github.com/MultiMC/MultiMC5.git`, and change directory to the folder you cloned to.
|
||||
3. Make a build directory, and change directory to the directory and do `cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:\Path\that\makes\sense\for\you`. By default, it will install to C:\Program Files (x86), which you might not want, if you want a local installation. If you want to install it to that directory, make sure to run the command window as administrator.
|
||||
3. Do `mingw32-make -jX`, where X is the number of cores your CPU has plus one.
|
||||
4. Now to wait for it to compile. This could take some time. Hopefully it compiles properly.
|
||||
5. Run the command `mingw32-make install`, and it should install MultiMC, to whatever the `-DCMAKE_INSTALL_PREFIX` was.
|
||||
6. In most cases, whenever compiling, the OpenSSL dll's aren't put into the directory to where MultiMC installs, meaning you cannot log in. The best way to fix this is just to do `copy C:\OpenSSL-Win32\*.dll C:\Where\you\installed\MultiMC\to`. This should copy the required OpenSSL dll's to log in.
|
||||
|
||||
# OS X
|
||||
|
||||
@@ -135,6 +164,9 @@ brew install cmake
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
Pick an installation path - this is where the final `.app` will be constructed when you run `make install`. Supply it as the `CMAKE_INSTALL_PREFIX` argument during CMake configuration.
|
||||
|
||||
```
|
||||
git clone https://github.com/MultiMC/MultiMC5.git
|
||||
git submodule init
|
||||
@@ -145,8 +177,9 @@ cd build
|
||||
export CMAKE_PREFIX_PATH=/usr/local/opt/qt5
|
||||
export CC=/usr/local/bin/gcc-4.8
|
||||
export CXX=/usr/local/bin/g++-4.8
|
||||
cmake ..
|
||||
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/Users/YOU/some/path/that/makes/sense/
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
**These build instructions were taken and adapted from https://gist.github.com/number5/7250865 If they don't work for you, let us know on IRC ([Esper/#MultiMC](http://webchat.esper.net/?nick=&channels=MultiMC))!**
|
||||
|
||||
@@ -17,19 +17,13 @@ enable_testing()
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
######## Set module path ########
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
|
||||
|
||||
# Only used for test coverage
|
||||
set(MMC_SRC "${PROJECT_SOURCE_DIR}")
|
||||
set(MMC_BIN "${PROJECT_BINARY_DIR}")
|
||||
|
||||
# Output all executables and shared libs in the main build folder, not in subfolders.
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
if(UNIX)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
|
||||
|
||||
######## Set compiler flags ########
|
||||
@@ -37,13 +31,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||
set(CMAKE_C_STANDARD_REQUIRED true)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
include(Coverage)
|
||||
include(GenerateExportHeader)
|
||||
set(CMAKE_CXX_FLAGS " -Wall -D_GLIBCXX_USE_CXX11_ABI=0 ${CMAKE_CXX_FLAGS}")
|
||||
if(UNIX AND APPLE)
|
||||
set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror=return-type")
|
||||
|
||||
# cmake code needed for the coverity scan upload
|
||||
include(Coverity)
|
||||
|
||||
################################ 3rd Party Libs ################################
|
||||
|
||||
@@ -73,46 +67,28 @@ endif()
|
||||
include(ExternalProject)
|
||||
set_directory_properties(PROPERTIES EP_BASE External)
|
||||
|
||||
# Add quazip
|
||||
add_definitions(-DQUAZIP_STATIC)
|
||||
set(QUAZIP_VERSION "0.7.1")
|
||||
if(NOT EXISTS ${CMAKE_BINARY_DIR}/quazip-${QUAZIP_VERSION}.tar.gz)
|
||||
file(DOWNLOAD http://downloads.sourceforge.net/project/quazip/quazip/${QUAZIP_VERSION}/quazip-${QUAZIP_VERSION}.tar.gz ${CMAKE_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_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_BINARY_DIR}/External/Install/QuaZIP/include/quazip")
|
||||
if(UNIX)
|
||||
set(QUAZIP_LIBRARIES -L"${CMAKE_BINARY_DIR}/External/Install/QuaZIP/lib" quazip z)
|
||||
else()
|
||||
set(QUAZIP_LIBRARIES -L"${CMAKE_BINARY_DIR}/External/Install/QuaZIP/lib" quazip)
|
||||
endif()
|
||||
|
||||
add_subdirectory(depends/hoedown) # markdown parser
|
||||
add_subdirectory(depends/launcher) # java based launcher part for Minecraft
|
||||
add_subdirectory(depends/javacheck) # java compatibility checker
|
||||
add_subdirectory(depends/xz-embedded) # xz compression
|
||||
add_subdirectory(depends/pack200) # java pack200 compression
|
||||
add_subdirectory(depends/rainbow) # Qt extension for colors
|
||||
|
||||
option(NBT_BUILD_SHARED "Build NBT shared library" ON)
|
||||
option(NBT_USE_ZLIB "Build NBT library with zlib support" OFF)
|
||||
option(NBT_BUILD_TESTS "Build NBT library tests" OFF) #FIXME: fix unit tests.
|
||||
add_subdirectory(depends/libnbtplusplus)
|
||||
set(NBT_NAME MultiMC_nbt++)
|
||||
add_subdirectory(libraries/libnbtplusplus)
|
||||
|
||||
######## MultiMC Libs ########
|
||||
|
||||
add_subdirectory(depends/LogicalGui) # GUI -> Logic connection
|
||||
add_subdirectory(depends/iconfix) # fork of Qt's QIcon loader
|
||||
|
||||
include(Coverity)
|
||||
add_subdirectory(libraries/ganalytics) # google analytics library
|
||||
add_subdirectory(libraries/systeminfo) # system information library
|
||||
add_subdirectory(libraries/hoedown) # markdown parser
|
||||
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
||||
add_subdirectory(libraries/javacheck) # java compatibility checker
|
||||
add_subdirectory(libraries/xz-embedded) # xz compression
|
||||
add_subdirectory(libraries/quazip) # zip manipulation library
|
||||
add_subdirectory(libraries/pack200) # java pack200 compression
|
||||
add_subdirectory(libraries/rainbow) # Qt extension for colors
|
||||
add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
|
||||
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
|
||||
|
||||
############################### Built Artifacts ###############################
|
||||
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(logic)
|
||||
add_subdirectory(api/logic)
|
||||
add_subdirectory(api/gui)
|
||||
|
||||
add_subdirectory(application)
|
||||
add_subdirectory(wonkoclient)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#MultiMC
|
||||
|
||||
Copyright 2012-2014 MultiMC Contributors
|
||||
Copyright 2012-2017 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
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
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
502
LICENSE.LPGLv21
@@ -1,502 +0,0 @@
|
||||
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!
|
||||
@@ -38,7 +38,7 @@ Apache covers reasonable use for the name - a mention of the project's origins i
|
||||
|
||||
|
||||
## License
|
||||
Copyright © 2013-2015 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).
|
||||
|
||||
|
||||
28
api/gui/CMakeLists.txt
Normal file
28
api/gui/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
project(MultiMC_gui LANGUAGES CXX)
|
||||
|
||||
set(GUI_SOURCES
|
||||
DesktopServices.h
|
||||
DesktopServices.cpp
|
||||
|
||||
# Icons
|
||||
icons/MMCIcon.h
|
||||
icons/MMCIcon.cpp
|
||||
icons/IconList.h
|
||||
icons/IconList.cpp
|
||||
|
||||
SkinUtils.cpp
|
||||
SkinUtils.h
|
||||
)
|
||||
################################ COMPILE ################################
|
||||
|
||||
add_library(MultiMC_gui SHARED ${GUI_SOURCES})
|
||||
set_target_properties(MultiMC_gui PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
|
||||
|
||||
generate_export_header(MultiMC_gui)
|
||||
|
||||
# Link
|
||||
target_link_libraries(MultiMC_gui iconfix MultiMC_logic)
|
||||
qt5_use_modules(MultiMC_gui Gui)
|
||||
|
||||
# Mark and export headers
|
||||
target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
37
api/gui/DesktopServices.h
Normal file
37
api/gui/DesktopServices.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
#include "multimc_gui_export.h"
|
||||
|
||||
/**
|
||||
* This wraps around QDesktopServices and adds workarounds where needed
|
||||
* Use this instead of QDesktopServices!
|
||||
*/
|
||||
namespace DesktopServices
|
||||
{
|
||||
/**
|
||||
* Open a file in whatever application is applicable
|
||||
*/
|
||||
MULTIMC_GUI_EXPORT bool openFile(const QString &path);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Run an application
|
||||
*/
|
||||
MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0);
|
||||
|
||||
/**
|
||||
* Open a directory
|
||||
*/
|
||||
MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false);
|
||||
|
||||
/**
|
||||
* Open the URL, most likely in a browser. Maybe.
|
||||
*/
|
||||
MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url);
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "minecraft/SkinUtils.h"
|
||||
#include "SkinUtils.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
#include "Env.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
#include "multimc_gui_export.h"
|
||||
|
||||
namespace SkinUtils
|
||||
{
|
||||
QPixmap MULTIMC_LOGIC_EXPORT getFaceFromCache(QString id, int height = 64, int width = 64);
|
||||
QPixmap MULTIMC_GUI_EXPORT getFaceFromCache(QString id, int height = 64, int width = 64);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,15 +25,23 @@
|
||||
|
||||
#define MAX_SIZE 1024
|
||||
|
||||
IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
QSet<QString> builtinNames;
|
||||
|
||||
// add builtin icons
|
||||
QDir instance_icons(builtinPath);
|
||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
||||
for (auto file_info : file_info_list)
|
||||
for(auto & builtinPath: builtinPaths)
|
||||
{
|
||||
QString key = file_info.baseName();
|
||||
addIcon(key, key, file_info.absoluteFilePath(), MMCIcon::Builtin);
|
||||
QDir instance_icons(builtinPath);
|
||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
||||
for (auto file_info : file_info_list)
|
||||
{
|
||||
builtinNames.insert(file_info.baseName());
|
||||
}
|
||||
}
|
||||
for(auto & builtinName : builtinNames)
|
||||
{
|
||||
addThemeIcon(builtinName);
|
||||
}
|
||||
|
||||
m_watcher.reset(new QFileSystemWatcher());
|
||||
@@ -70,9 +78,9 @@ void IconList::directoryChanged(const QString &path)
|
||||
QList<QString> current_list;
|
||||
for (auto &it : icons)
|
||||
{
|
||||
if (!it.has(MMCIcon::FileBased))
|
||||
if (!it.has(IconType::FileBased))
|
||||
continue;
|
||||
current_list.push_back(it.m_images[MMCIcon::FileBased].filename);
|
||||
current_list.push_back(it.m_images[IconType::FileBased].filename);
|
||||
}
|
||||
QSet<QString> current_set = current_list.toSet();
|
||||
|
||||
@@ -90,8 +98,8 @@ void IconList::directoryChanged(const QString &path)
|
||||
int idx = getIconIndex(key);
|
||||
if (idx == -1)
|
||||
continue;
|
||||
icons[idx].remove(MMCIcon::FileBased);
|
||||
if (icons[idx].type() == MMCIcon::ToBeDeleted)
|
||||
icons[idx].remove(IconType::FileBased);
|
||||
if (icons[idx].type() == IconType::ToBeDeleted)
|
||||
{
|
||||
beginRemoveRows(QModelIndex(), idx, idx);
|
||||
icons.remove(idx);
|
||||
@@ -111,7 +119,7 @@ void IconList::directoryChanged(const QString &path)
|
||||
qDebug() << "Adding " << add;
|
||||
QFileInfo addfile(add);
|
||||
QString key = addfile.baseName();
|
||||
if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased))
|
||||
if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
|
||||
{
|
||||
m_watcher->addPath(add);
|
||||
emit iconUpdated(key);
|
||||
@@ -133,7 +141,7 @@ void IconList::fileChanged(const QString &path)
|
||||
if (!icon.availableSizes().size())
|
||||
return;
|
||||
|
||||
icons[idx].m_images[MMCIcon::FileBased].icon = icon;
|
||||
icons[idx].m_images[IconType::FileBased].icon = icon;
|
||||
dataChanged(index(idx), index(idx));
|
||||
emit iconUpdated(key);
|
||||
}
|
||||
@@ -243,7 +251,7 @@ int IconList::rowCount(const QModelIndex &parent) const
|
||||
return icons.size();
|
||||
}
|
||||
|
||||
void IconList::installIcons(QStringList iconFiles)
|
||||
void IconList::installIcons(const QStringList &iconFiles)
|
||||
{
|
||||
for (QString file : iconFiles)
|
||||
{
|
||||
@@ -261,17 +269,17 @@ void IconList::installIcons(QStringList iconFiles)
|
||||
}
|
||||
}
|
||||
|
||||
bool IconList::iconFileExists(QString key)
|
||||
bool IconList::iconFileExists(const QString &key) const
|
||||
{
|
||||
auto iconEntry = icon(key);
|
||||
if(!iconEntry)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return iconEntry->has(MMCIcon::FileBased);
|
||||
return iconEntry->has(IconType::FileBased);
|
||||
}
|
||||
|
||||
const MMCIcon *IconList::icon(QString key)
|
||||
const MMCIcon *IconList::icon(const QString &key) const
|
||||
{
|
||||
int iconIdx = getIconIndex(key);
|
||||
if (iconIdx == -1)
|
||||
@@ -279,20 +287,47 @@ const MMCIcon *IconList::icon(QString key)
|
||||
return &icons[iconIdx];
|
||||
}
|
||||
|
||||
bool IconList::deleteIcon(QString key)
|
||||
bool IconList::deleteIcon(const QString &key)
|
||||
{
|
||||
int iconIdx = getIconIndex(key);
|
||||
if (iconIdx == -1)
|
||||
return false;
|
||||
auto &iconEntry = icons[iconIdx];
|
||||
if (iconEntry.has(MMCIcon::FileBased))
|
||||
if (iconEntry.has(IconType::FileBased))
|
||||
{
|
||||
return QFile::remove(iconEntry.m_images[MMCIcon::FileBased].filename);
|
||||
return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IconList::addIcon(QString key, QString name, QString path, MMCIcon::Type type)
|
||||
bool IconList::addThemeIcon(const QString& key)
|
||||
{
|
||||
auto iter = name_index.find(key);
|
||||
if (iter != name_index.end())
|
||||
{
|
||||
auto &oldOne = icons[*iter];
|
||||
oldOne.replace(Builtin, key);
|
||||
dataChanged(index(*iter), index(*iter));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add a new icon
|
||||
beginInsertRows(QModelIndex(), icons.size(), icons.size());
|
||||
{
|
||||
MMCIcon mmc_icon;
|
||||
mmc_icon.m_name = key;
|
||||
mmc_icon.m_key = key;
|
||||
mmc_icon.replace(Builtin, key);
|
||||
icons.push_back(mmc_icon);
|
||||
name_index[key] = icons.size() - 1;
|
||||
}
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
|
||||
{
|
||||
// replace the icon even? is the input valid?
|
||||
QIcon icon(path);
|
||||
@@ -323,6 +358,14 @@ bool IconList::addIcon(QString key, QString name, QString path, MMCIcon::Type ty
|
||||
}
|
||||
}
|
||||
|
||||
void IconList::saveIcon(const QString &key, const QString &path, const char * format) const
|
||||
{
|
||||
auto icon = getIcon(key);
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(path, format);
|
||||
}
|
||||
|
||||
|
||||
void IconList::reindex()
|
||||
{
|
||||
name_index.clear();
|
||||
@@ -334,7 +377,7 @@ void IconList::reindex()
|
||||
}
|
||||
}
|
||||
|
||||
QIcon IconList::getIcon(QString key)
|
||||
QIcon IconList::getIcon(const QString &key) const
|
||||
{
|
||||
int icon_index = getIconIndex(key);
|
||||
|
||||
@@ -349,15 +392,12 @@ QIcon IconList::getIcon(QString key)
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
QIcon IconList::getBigIcon(QString key)
|
||||
QIcon IconList::getBigIcon(const QString &key) const
|
||||
{
|
||||
int icon_index = getIconIndex(key);
|
||||
|
||||
if (icon_index == -1)
|
||||
key = "infinity";
|
||||
|
||||
// Fallback for icons that don't exist.
|
||||
icon_index = getIconIndex(key);
|
||||
icon_index = getIconIndex(icon_index == -1 ? "infinity" : key);
|
||||
|
||||
if (icon_index == -1)
|
||||
return QIcon();
|
||||
@@ -366,12 +406,9 @@ QIcon IconList::getBigIcon(QString key)
|
||||
return QIcon(bigone);
|
||||
}
|
||||
|
||||
int IconList::getIconIndex(QString key)
|
||||
int IconList::getIconIndex(const QString &key) const
|
||||
{
|
||||
if (key == "default")
|
||||
key = "infinity";
|
||||
|
||||
auto iter = name_index.find(key);
|
||||
auto iter = name_index.find(key == "default" ? "infinity" : key);
|
||||
if (iter != name_index.end())
|
||||
return *iter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,38 +24,40 @@
|
||||
#include "MMCIcon.h"
|
||||
#include "settings/Setting.h"
|
||||
#include "Env.h" // there is a global icon list inside Env.
|
||||
#include <icons/IIconList.h>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
#include "multimc_gui_export.h"
|
||||
|
||||
class QFileSystemWatcher;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT IconList : public QAbstractListModel
|
||||
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IconList(QString builtinPath, QString path, QObject *parent = 0);
|
||||
explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
|
||||
virtual ~IconList() {};
|
||||
|
||||
QIcon getIcon(QString key);
|
||||
QIcon getBigIcon(QString key);
|
||||
int getIconIndex(QString key);
|
||||
QIcon getIcon(const QString &key) const;
|
||||
QIcon getBigIcon(const QString &key) const;
|
||||
int getIconIndex(const QString &key) const;
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool addIcon(QString key, QString name, QString path, MMCIcon::Type type);
|
||||
bool deleteIcon(QString key);
|
||||
bool iconFileExists(QString key);
|
||||
bool addThemeIcon(const QString &key);
|
||||
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;
|
||||
bool deleteIcon(const QString &key) override;
|
||||
bool iconFileExists(const QString &key) const override;
|
||||
|
||||
virtual QStringList mimeTypes() const;
|
||||
virtual Qt::DropActions supportedDropActions() const;
|
||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
|
||||
const QModelIndex &parent);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual QStringList mimeTypes() 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 Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
void installIcons(QStringList iconFiles);
|
||||
void installIcons(const QStringList &iconFiles) override;
|
||||
|
||||
const MMCIcon * icon(QString key);
|
||||
const MMCIcon * icon(const QString &key) const;
|
||||
|
||||
void startWatching();
|
||||
void stopWatching();
|
||||
104
api/gui/icons/MMCIcon.cpp
Normal file
104
api/gui/icons/MMCIcon.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MMCIcon.h"
|
||||
#include <QFileInfo>
|
||||
#include <xdgicon.h>
|
||||
|
||||
IconType operator--(IconType &t, int)
|
||||
{
|
||||
IconType temp = t;
|
||||
switch (t)
|
||||
{
|
||||
case IconType::Builtin:
|
||||
t = IconType::ToBeDeleted;
|
||||
break;
|
||||
case IconType::Transient:
|
||||
t = IconType::Builtin;
|
||||
break;
|
||||
case IconType::FileBased:
|
||||
t = IconType::Transient;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
IconType MMCIcon::type() const
|
||||
{
|
||||
return m_current_type;
|
||||
}
|
||||
|
||||
QString MMCIcon::name() const
|
||||
{
|
||||
if (m_name.size())
|
||||
return m_name;
|
||||
return m_key;
|
||||
}
|
||||
|
||||
bool MMCIcon::has(IconType _type) const
|
||||
{
|
||||
return m_images[_type].present();
|
||||
}
|
||||
|
||||
QIcon MMCIcon::icon() const
|
||||
{
|
||||
if (m_current_type == IconType::ToBeDeleted)
|
||||
return QIcon();
|
||||
auto & icon = m_images[m_current_type].icon;
|
||||
if(!icon.isNull())
|
||||
return icon;
|
||||
// FIXME: inject this.
|
||||
return XdgIcon::fromTheme(m_images[m_current_type].key);
|
||||
}
|
||||
|
||||
void MMCIcon::remove(IconType rm_type)
|
||||
{
|
||||
m_images[rm_type].filename = QString();
|
||||
m_images[rm_type].icon = QIcon();
|
||||
for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--)
|
||||
{
|
||||
if (m_images[iter].present())
|
||||
{
|
||||
m_current_type = iter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_current_type = IconType::ToBeDeleted;
|
||||
}
|
||||
|
||||
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
|
||||
{
|
||||
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
||||
{
|
||||
m_current_type = new_type;
|
||||
}
|
||||
m_images[new_type].icon = icon;
|
||||
m_images[new_type].filename = path;
|
||||
m_images[new_type].key = QString();
|
||||
}
|
||||
|
||||
void MMCIcon::replace(IconType new_type, const QString& key)
|
||||
{
|
||||
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
||||
{
|
||||
m_current_type = new_type;
|
||||
}
|
||||
m_images[new_type].icon = QIcon();
|
||||
m_images[new_type].filename = QString();
|
||||
m_images[new_type].key = key;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,39 +17,33 @@
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QIcon>
|
||||
#include <icons/IIconList.h>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
#include "multimc_gui_export.h"
|
||||
|
||||
struct MULTIMC_LOGIC_EXPORT MMCImage
|
||||
struct MULTIMC_GUI_EXPORT MMCImage
|
||||
{
|
||||
QIcon icon;
|
||||
QString key;
|
||||
QString filename;
|
||||
QDateTime changed;
|
||||
bool present() const
|
||||
{
|
||||
return !icon.isNull();
|
||||
return !icon.isNull() || !key.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
struct MULTIMC_LOGIC_EXPORT MMCIcon
|
||||
struct MULTIMC_GUI_EXPORT MMCIcon
|
||||
{
|
||||
enum Type : unsigned
|
||||
{
|
||||
Builtin,
|
||||
Transient,
|
||||
FileBased,
|
||||
ICONS_TOTAL,
|
||||
ToBeDeleted
|
||||
};
|
||||
QString m_key;
|
||||
QString m_name;
|
||||
MMCImage m_images[ICONS_TOTAL];
|
||||
Type m_current_type = ToBeDeleted;
|
||||
IconType m_current_type = ToBeDeleted;
|
||||
|
||||
Type type() const;
|
||||
IconType type() const;
|
||||
QString name() const;
|
||||
bool has(Type _type) const;
|
||||
bool has(IconType _type) const;
|
||||
QIcon icon() const;
|
||||
void remove(Type rm_type);
|
||||
void replace(Type new_type, QIcon icon, QString path = QString());
|
||||
void remove(IconType rm_type);
|
||||
void replace(IconType new_type, QIcon icon, QString path = QString());
|
||||
void replace(IconType new_type, const QString &key);
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <QFile>
|
||||
|
||||
#include "BaseInstaller.h"
|
||||
#include "minecraft/OneSixInstance.h"
|
||||
#include "minecraft/onesix/OneSixInstance.h"
|
||||
|
||||
BaseInstaller::BaseInstaller()
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,13 +17,13 @@
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "settings/Setting.h"
|
||||
#include "settings/OverrideSetting.h"
|
||||
|
||||
#include "minecraft/MinecraftVersionList.h"
|
||||
#include "icons/IconList.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Commandline.h"
|
||||
|
||||
@@ -35,7 +35,6 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
||||
|
||||
m_settings->registerSetting("name", "Unnamed Instance");
|
||||
m_settings->registerSetting("iconKey", "default");
|
||||
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
m_settings->registerSetting("notes", "");
|
||||
m_settings->registerSetting("lastLaunchTime", 0);
|
||||
m_settings->registerSetting("totalTimePlayed", 0);
|
||||
@@ -50,7 +49,11 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
||||
auto consoleSetting = m_settings->registerSetting("OverrideConsole", false);
|
||||
m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting);
|
||||
m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting);
|
||||
m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting);
|
||||
m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting);
|
||||
|
||||
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr);
|
||||
m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr);
|
||||
}
|
||||
|
||||
QString BaseInstance::getPreLaunchCommand()
|
||||
@@ -68,6 +71,24 @@ QString BaseInstance::getPostExitCommand()
|
||||
return settings()->get("PostExitCommand").toString();
|
||||
}
|
||||
|
||||
int BaseInstance::getConsoleMaxLines() const
|
||||
{
|
||||
auto lineSetting = settings()->getSetting("ConsoleMaxLines");
|
||||
bool conversionOk = false;
|
||||
int maxLines = lineSetting->get().toInt(&conversionOk);
|
||||
if(!conversionOk)
|
||||
{
|
||||
maxLines = lineSetting->defValue().toInt();
|
||||
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
|
||||
}
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
bool BaseInstance::shouldStopOnConsoleOverflow() const
|
||||
{
|
||||
return settings()->get("ConsoleOverflowStop").toBool();
|
||||
}
|
||||
|
||||
void BaseInstance::iconUpdated(QString key)
|
||||
{
|
||||
if(iconKey() == key)
|
||||
@@ -76,10 +97,32 @@ void BaseInstance::iconUpdated(QString key)
|
||||
}
|
||||
}
|
||||
|
||||
void BaseInstance::invalidate()
|
||||
{
|
||||
changeStatus(Status::Gone);
|
||||
qDebug() << "Instance" << id() << "has been invalidated.";
|
||||
}
|
||||
|
||||
void BaseInstance::nuke()
|
||||
{
|
||||
changeStatus(Status::Gone);
|
||||
qDebug() << "Instance" << id() << "has been deleted by MultiMC.";
|
||||
FS::deletePath(instanceRoot());
|
||||
emit nuked(this);
|
||||
}
|
||||
|
||||
void BaseInstance::changeStatus(BaseInstance::Status newStatus)
|
||||
{
|
||||
Status status = currentStatus();
|
||||
if(status != newStatus)
|
||||
{
|
||||
m_status = newStatus;
|
||||
emit statusChanged(status, newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
BaseInstance::Status BaseInstance::currentStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
QString BaseInstance::id() const
|
||||
@@ -94,18 +137,24 @@ bool BaseInstance::isRunning() const
|
||||
|
||||
void BaseInstance::setRunning(bool running)
|
||||
{
|
||||
if(running && !m_isRunning)
|
||||
if(running == m_isRunning)
|
||||
return;
|
||||
|
||||
m_isRunning = running;
|
||||
|
||||
if(running)
|
||||
{
|
||||
m_timeStarted = QDateTime::currentDateTime();
|
||||
}
|
||||
else if(!running && m_isRunning)
|
||||
else
|
||||
{
|
||||
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
||||
QDateTime timeEnded = QDateTime::currentDateTime();
|
||||
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
|
||||
emit propertiesChanged(this);
|
||||
}
|
||||
m_isRunning = running;
|
||||
|
||||
emit runningStatusChanged(running);
|
||||
}
|
||||
|
||||
int64_t BaseInstance::totalTimePlayed() const
|
||||
@@ -144,44 +193,9 @@ SettingsObjectPtr BaseInstance::settings() const
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
BaseInstance::InstanceFlags BaseInstance::flags() const
|
||||
{
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
void BaseInstance::setFlags(const InstanceFlags &flags)
|
||||
{
|
||||
if (flags != m_flags)
|
||||
{
|
||||
m_flags = flags;
|
||||
emit flagsChanged();
|
||||
emit propertiesChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseInstance::setFlag(const BaseInstance::InstanceFlag flag)
|
||||
{
|
||||
// nothing to set?
|
||||
if(flag & m_flags)
|
||||
return;
|
||||
m_flags |= flag;
|
||||
emit flagsChanged();
|
||||
emit propertiesChanged(this);
|
||||
}
|
||||
|
||||
void BaseInstance::unsetFlag(const BaseInstance::InstanceFlag flag)
|
||||
{
|
||||
// nothing to unset?
|
||||
if(!(flag & m_flags))
|
||||
return;
|
||||
m_flags &= ~flag;
|
||||
emit flagsChanged();
|
||||
emit propertiesChanged(this);
|
||||
}
|
||||
|
||||
bool BaseInstance::canLaunch() const
|
||||
{
|
||||
return !(flags() & VersionBrokenFlag);
|
||||
return (!hasVersionBroken() && !isRunning());
|
||||
}
|
||||
|
||||
bool BaseInstance::reload()
|
||||
@@ -270,3 +284,24 @@ QStringList BaseInstance::extraArguments() const
|
||||
{
|
||||
return Commandline::splitArgs(settings()->get("JvmArgs").toString());
|
||||
}
|
||||
|
||||
std::shared_ptr<LaunchTask> BaseInstance::getLaunchTask()
|
||||
{
|
||||
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-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,8 +14,10 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cassert>
|
||||
|
||||
#include <QObject>
|
||||
#include "QObjectPtr.h"
|
||||
#include <QDateTime>
|
||||
#include <QSet>
|
||||
#include <QProcess>
|
||||
@@ -24,8 +26,8 @@
|
||||
|
||||
#include "settings/INIFile.h"
|
||||
#include "BaseVersionList.h"
|
||||
#include "auth/MojangAccount.h"
|
||||
#include "launch/MessageLevel.h"
|
||||
#include "minecraft/auth/MojangAccount.h"
|
||||
#include "MessageLevel.h"
|
||||
#include "pathmatcher/IPathMatcher.h"
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
@@ -34,6 +36,7 @@ class QDir;
|
||||
class Task;
|
||||
class LaunchTask;
|
||||
class BaseInstance;
|
||||
class BaseInstanceProvider;
|
||||
|
||||
// pointer for lazy people
|
||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||
@@ -53,11 +56,18 @@ protected:
|
||||
/// no-touchy!
|
||||
BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
|
||||
|
||||
public: /* types */
|
||||
enum class Status
|
||||
{
|
||||
Present,
|
||||
Gone // either nuked or invalidated
|
||||
};
|
||||
|
||||
public:
|
||||
/// virtual destructor to make sure the destruction is COMPLETE
|
||||
virtual ~BaseInstance() {};
|
||||
|
||||
virtual void copy(const QDir &newDir) {}
|
||||
virtual void copy(SettingsObjectPtr newSettings, const QDir &newDir) {}
|
||||
|
||||
virtual void init() = 0;
|
||||
|
||||
@@ -65,6 +75,14 @@ public:
|
||||
/// responsible of cleaning up the husk
|
||||
void nuke();
|
||||
|
||||
/***
|
||||
* 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
|
||||
/// be unique.
|
||||
virtual QString id() const;
|
||||
@@ -74,6 +92,9 @@ public:
|
||||
int64_t totalTimePlayed() const;
|
||||
void resetTimePlayed();
|
||||
|
||||
void setProvider(BaseInstanceProvider * provider);
|
||||
BaseInstanceProvider * provider() const;
|
||||
|
||||
/// get the type of this instance
|
||||
QString instanceType() const;
|
||||
|
||||
@@ -152,11 +173,14 @@ public:
|
||||
virtual SettingsObjectPtr settings() const;
|
||||
|
||||
/// returns a valid update task
|
||||
virtual std::shared_ptr<Task> createUpdateTask() = 0;
|
||||
virtual shared_qobject_ptr<Task> createUpdateTask() = 0;
|
||||
|
||||
/// returns a valid launcher (task container)
|
||||
virtual std::shared_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) = 0;
|
||||
|
||||
/// returns the current launch task (if any)
|
||||
std::shared_ptr<LaunchTask> getLaunchTask();
|
||||
|
||||
/*!
|
||||
* Returns a task that should be done right before launch
|
||||
* This task should do any extra preparations needed
|
||||
@@ -178,12 +202,6 @@ public:
|
||||
*/
|
||||
virtual QString getLogFileRoot() = 0;
|
||||
|
||||
/*!
|
||||
* does any necessary cleanups after the instance finishes. also runs before\
|
||||
* TODO: turn into a task that can run asynchronously
|
||||
*/
|
||||
virtual void cleanupAfterRun() = 0;
|
||||
|
||||
virtual QString getStatusbarDescription() = 0;
|
||||
|
||||
/// FIXME: this really should be elsewhere...
|
||||
@@ -194,21 +212,63 @@ public:
|
||||
|
||||
virtual QString typeName() const = 0;
|
||||
|
||||
enum InstanceFlag
|
||||
bool hasVersionBroken() const
|
||||
{
|
||||
VersionBrokenFlag = 0x01,
|
||||
UpdateAvailable = 0x02
|
||||
};
|
||||
Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag)
|
||||
InstanceFlags flags() const;
|
||||
void setFlags(const InstanceFlags &flags);
|
||||
void setFlag(const InstanceFlag flag);
|
||||
void unsetFlag(const InstanceFlag flag);
|
||||
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:
|
||||
void changeStatus(Status newStatus);
|
||||
|
||||
signals:
|
||||
/*!
|
||||
* \brief Signal emitted when properties relevant to the instance view change
|
||||
@@ -218,25 +278,33 @@ signals:
|
||||
* \brief Signal emitted when groups are affected in any way
|
||||
*/
|
||||
void groupChanged();
|
||||
/*!
|
||||
* \brief The instance just got nuked. Hurray!
|
||||
*/
|
||||
void nuked(BaseInstance *inst);
|
||||
|
||||
void flagsChanged();
|
||||
void launchTaskChanged(std::shared_ptr<LaunchTask>);
|
||||
|
||||
void runningStatusChanged(bool running);
|
||||
|
||||
void statusChanged(Status from, Status to);
|
||||
|
||||
protected slots:
|
||||
void iconUpdated(QString key);
|
||||
|
||||
protected:
|
||||
protected: /* data */
|
||||
QString m_rootDir;
|
||||
QString m_group;
|
||||
SettingsObjectPtr m_settings;
|
||||
InstanceFlags m_flags;
|
||||
// InstanceFlags m_flags;
|
||||
bool m_isRunning = false;
|
||||
std::shared_ptr<LaunchTask> m_launchProcess;
|
||||
QDateTime m_timeStarted;
|
||||
BaseInstanceProvider * m_provider = nullptr;
|
||||
|
||||
private: /* data */
|
||||
Status m_status = Status::Present;
|
||||
bool m_crashed = false;
|
||||
bool m_hasUpdate = false;
|
||||
bool m_hasBrokenVersion = false;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<BaseInstance>)
|
||||
Q_DECLARE_METATYPE(BaseInstance::InstanceFlag)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)
|
||||
//Q_DECLARE_METATYPE(BaseInstance::InstanceFlag)
|
||||
//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-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,7 +72,7 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
}
|
||||
|
||||
BaseVersionList::RoleList BaseVersionList::providesRoles()
|
||||
BaseVersionList::RoleList BaseVersionList::providesRoles() const
|
||||
{
|
||||
return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
|
||||
}
|
||||
@@ -87,3 +87,18 @@ int BaseVersionList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> BaseVersionList::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
|
||||
roles.insert(VersionRole, "version");
|
||||
roles.insert(VersionIdRole, "versionId");
|
||||
roles.insert(ParentGameVersionRole, "parentGameVersion");
|
||||
roles.insert(RecommendedRole, "recommended");
|
||||
roles.insert(LatestRole, "latest");
|
||||
roles.insert(TypeRole, "type");
|
||||
roles.insert(BranchRole, "branch");
|
||||
roles.insert(PathRole, "path");
|
||||
roles.insert(ArchitectureRole, "architecture");
|
||||
return roles;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,9 +50,10 @@ public:
|
||||
TypeRole,
|
||||
BranchRole,
|
||||
PathRole,
|
||||
ArchitectureRole
|
||||
ArchitectureRole,
|
||||
SortRole
|
||||
};
|
||||
typedef QList<ModelRoles> RoleList;
|
||||
typedef QList<int> RoleList;
|
||||
|
||||
explicit BaseVersionList(QObject *parent = 0);
|
||||
|
||||
@@ -78,9 +79,10 @@ public:
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
virtual int rowCount(const QModelIndex &parent) const;
|
||||
virtual int columnCount(const QModelIndex &parent) const;
|
||||
virtual QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
//! which roles are provided by this version list?
|
||||
virtual RoleList providesRoles();
|
||||
virtual RoleList providesRoles() const;
|
||||
|
||||
/*!
|
||||
* \brief Finds a version by its descriptor.
|
||||
498
api/logic/CMakeLists.txt
Normal file
498
api/logic/CMakeLists.txt
Normal file
@@ -0,0 +1,498 @@
|
||||
project(MultiMC_logic)
|
||||
|
||||
include (UnitTest)
|
||||
|
||||
set(CORE_SOURCES
|
||||
# LOGIC - Base classes and infrastructure
|
||||
BaseInstaller.h
|
||||
BaseInstaller.cpp
|
||||
BaseVersionList.h
|
||||
BaseVersionList.cpp
|
||||
InstanceCreationTask.h
|
||||
InstanceCreationTask.cpp
|
||||
InstanceCopyTask.h
|
||||
InstanceCopyTask.cpp
|
||||
InstanceImportTask.h
|
||||
InstanceImportTask.cpp
|
||||
InstanceList.h
|
||||
InstanceList.cpp
|
||||
LoggedProcess.h
|
||||
LoggedProcess.cpp
|
||||
MessageLevel.cpp
|
||||
MessageLevel.h
|
||||
BaseInstanceProvider.h
|
||||
FolderInstanceProvider.h
|
||||
FolderInstanceProvider.cpp
|
||||
BaseVersion.h
|
||||
BaseInstance.h
|
||||
BaseInstance.cpp
|
||||
NullInstance.h
|
||||
MMCZip.h
|
||||
MMCZip.cpp
|
||||
MMCStrings.h
|
||||
MMCStrings.cpp
|
||||
|
||||
# Use tracking separate from memory management
|
||||
Usable.h
|
||||
|
||||
# Prefix tree where node names are strings between separators
|
||||
SeparatorPrefixTree.h
|
||||
|
||||
# WARNING: globals live here
|
||||
Env.h
|
||||
Env.cpp
|
||||
|
||||
# JSON parsing helpers
|
||||
Json.h
|
||||
Json.cpp
|
||||
|
||||
FileSystem.h
|
||||
FileSystem.cpp
|
||||
|
||||
Exception.h
|
||||
|
||||
# RW lock protected map
|
||||
RWStorage.h
|
||||
|
||||
# A variable that has an implicit default value and keeps track of changes
|
||||
DefaultVariable.h
|
||||
|
||||
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
|
||||
QObjectPtr.h
|
||||
|
||||
# Compression support
|
||||
GZip.h
|
||||
GZip.cpp
|
||||
|
||||
# Command line parameter parsing
|
||||
Commandline.h
|
||||
Commandline.cpp
|
||||
|
||||
# Version number string support
|
||||
Version.h
|
||||
Version.cpp
|
||||
|
||||
# A Recursive file system watcher
|
||||
RecursiveFileSystemWatcher.h
|
||||
RecursiveFileSystemWatcher.cpp
|
||||
)
|
||||
|
||||
add_unit_test(FileSystem
|
||||
SOURCES FileSystem_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
DATA testdata
|
||||
)
|
||||
|
||||
add_unit_test(GZip
|
||||
SOURCES GZip_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
set(PATHMATCHER_SOURCES
|
||||
# Path matchers
|
||||
pathmatcher/FSTreeMatcher.h
|
||||
pathmatcher/IPathMatcher.h
|
||||
pathmatcher/MultiMatcher.h
|
||||
pathmatcher/RegexpMatcher.h
|
||||
)
|
||||
|
||||
set(NET_SOURCES
|
||||
# network stuffs
|
||||
net/ByteArraySink.h
|
||||
net/ChecksumValidator.h
|
||||
net/Download.cpp
|
||||
net/Download.h
|
||||
net/FileSink.cpp
|
||||
net/FileSink.h
|
||||
net/HttpMetaCache.cpp
|
||||
net/HttpMetaCache.h
|
||||
net/MetaCacheSink.cpp
|
||||
net/MetaCacheSink.h
|
||||
net/NetAction.h
|
||||
net/NetJob.cpp
|
||||
net/NetJob.h
|
||||
net/PasteUpload.cpp
|
||||
net/PasteUpload.h
|
||||
net/Sink.h
|
||||
net/URLConstants.cpp
|
||||
net/URLConstants.h
|
||||
net/Validator.h
|
||||
)
|
||||
|
||||
# Game launch logic
|
||||
set(LAUNCH_SOURCES
|
||||
launch/steps/PostLaunchCommand.cpp
|
||||
launch/steps/PostLaunchCommand.h
|
||||
launch/steps/PreLaunchCommand.cpp
|
||||
launch/steps/PreLaunchCommand.h
|
||||
launch/steps/TextPrint.cpp
|
||||
launch/steps/TextPrint.h
|
||||
launch/steps/Update.cpp
|
||||
launch/steps/Update.h
|
||||
launch/LaunchStep.cpp
|
||||
launch/LaunchStep.h
|
||||
launch/LaunchTask.cpp
|
||||
launch/LaunchTask.h
|
||||
launch/LogModel.cpp
|
||||
launch/LogModel.h
|
||||
)
|
||||
|
||||
# Old update system
|
||||
set(UPDATE_SOURCES
|
||||
updater/GoUpdate.h
|
||||
updater/GoUpdate.cpp
|
||||
updater/UpdateChecker.h
|
||||
updater/UpdateChecker.cpp
|
||||
updater/DownloadTask.h
|
||||
updater/DownloadTask.cpp
|
||||
)
|
||||
|
||||
add_unit_test(UpdateChecker
|
||||
SOURCES updater/UpdateChecker_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
DATA updater/testdata
|
||||
)
|
||||
|
||||
add_unit_test(DownloadTask
|
||||
SOURCES updater/DownloadTask_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
DATA updater/testdata
|
||||
)
|
||||
|
||||
# Rarely used notifications
|
||||
set(NOTIFICATIONS_SOURCES
|
||||
# Notifications - short warning messages
|
||||
notifications/NotificationChecker.h
|
||||
notifications/NotificationChecker.cpp
|
||||
)
|
||||
|
||||
# Backend for the news bar... there's usually no news.
|
||||
set(NEWS_SOURCES
|
||||
# News System
|
||||
news/NewsChecker.h
|
||||
news/NewsChecker.cpp
|
||||
news/NewsEntry.h
|
||||
news/NewsEntry.cpp
|
||||
)
|
||||
|
||||
# Icon interface
|
||||
set(ICONS_SOURCES
|
||||
# News System
|
||||
icons/IIconList.h
|
||||
icons/IIconList.cpp
|
||||
)
|
||||
|
||||
# Minecraft services status checker
|
||||
set(STATUS_SOURCES
|
||||
# Status system
|
||||
status/StatusChecker.h
|
||||
status/StatusChecker.cpp
|
||||
)
|
||||
|
||||
# Support for Minecraft instances and launch
|
||||
set(MINECRAFT_SOURCES
|
||||
# Minecraft support
|
||||
minecraft/auth/AuthSession.h
|
||||
minecraft/auth/AuthSession.cpp
|
||||
minecraft/auth/MojangAccountList.h
|
||||
minecraft/auth/MojangAccountList.cpp
|
||||
minecraft/auth/MojangAccount.h
|
||||
minecraft/auth/MojangAccount.cpp
|
||||
minecraft/auth/YggdrasilTask.h
|
||||
minecraft/auth/YggdrasilTask.cpp
|
||||
minecraft/auth/flows/AuthenticateTask.h
|
||||
minecraft/auth/flows/AuthenticateTask.cpp
|
||||
minecraft/auth/flows/RefreshTask.cpp
|
||||
minecraft/auth/flows/RefreshTask.cpp
|
||||
minecraft/auth/flows/ValidateTask.h
|
||||
minecraft/auth/flows/ValidateTask.cpp
|
||||
minecraft/onesix/OneSixUpdate.h
|
||||
minecraft/onesix/OneSixUpdate.cpp
|
||||
minecraft/onesix/OneSixInstance.h
|
||||
minecraft/onesix/OneSixInstance.cpp
|
||||
minecraft/onesix/OneSixProfileStrategy.cpp
|
||||
minecraft/onesix/OneSixProfileStrategy.h
|
||||
minecraft/onesix/OneSixVersionFormat.cpp
|
||||
minecraft/onesix/OneSixVersionFormat.h
|
||||
minecraft/onesix/update/AssetUpdateTask.h
|
||||
minecraft/onesix/update/AssetUpdateTask.cpp
|
||||
minecraft/onesix/update/FMLLibrariesTask.cpp
|
||||
minecraft/onesix/update/FMLLibrariesTask.h
|
||||
minecraft/onesix/update/FoldersTask.cpp
|
||||
minecraft/onesix/update/FoldersTask.h
|
||||
minecraft/onesix/update/LibrariesTask.cpp
|
||||
minecraft/onesix/update/LibrariesTask.h
|
||||
minecraft/launch/ClaimAccount.cpp
|
||||
minecraft/launch/ClaimAccount.h
|
||||
minecraft/launch/CreateServerResourcePacksFolder.cpp
|
||||
minecraft/launch/CreateServerResourcePacksFolder.h
|
||||
minecraft/launch/ModMinecraftJar.cpp
|
||||
minecraft/launch/ModMinecraftJar.h
|
||||
minecraft/launch/DirectJavaLaunch.cpp
|
||||
minecraft/launch/DirectJavaLaunch.h
|
||||
minecraft/launch/ExtractNatives.cpp
|
||||
minecraft/launch/ExtractNatives.h
|
||||
minecraft/launch/LauncherPartLaunch.cpp
|
||||
minecraft/launch/LauncherPartLaunch.h
|
||||
minecraft/launch/PrintInstanceInfo.cpp
|
||||
minecraft/launch/PrintInstanceInfo.h
|
||||
minecraft/legacy/LegacyModList.h
|
||||
minecraft/legacy/LegacyModList.cpp
|
||||
minecraft/legacy/LegacyUpdate.h
|
||||
minecraft/legacy/LegacyUpdate.cpp
|
||||
minecraft/legacy/LegacyInstance.h
|
||||
minecraft/legacy/LegacyInstance.cpp
|
||||
minecraft/legacy/LwjglVersionList.h
|
||||
minecraft/legacy/LwjglVersionList.cpp
|
||||
minecraft/GradleSpecifier.h
|
||||
minecraft/MinecraftProfile.cpp
|
||||
minecraft/MinecraftProfile.h
|
||||
minecraft/MojangVersionFormat.cpp
|
||||
minecraft/MojangVersionFormat.h
|
||||
minecraft/JarMod.h
|
||||
minecraft/MinecraftInstance.cpp
|
||||
minecraft/MinecraftInstance.h
|
||||
minecraft/MinecraftVersion.cpp
|
||||
minecraft/MinecraftVersion.h
|
||||
minecraft/MinecraftVersionList.cpp
|
||||
minecraft/MinecraftVersionList.h
|
||||
minecraft/Rule.cpp
|
||||
minecraft/Rule.h
|
||||
minecraft/OpSys.cpp
|
||||
minecraft/OpSys.h
|
||||
minecraft/ParseUtils.cpp
|
||||
minecraft/ParseUtils.h
|
||||
minecraft/ProfileUtils.cpp
|
||||
minecraft/ProfileUtils.h
|
||||
minecraft/ProfileStrategy.h
|
||||
minecraft/Library.cpp
|
||||
minecraft/Library.h
|
||||
minecraft/MojangDownloadInfo.h
|
||||
minecraft/VersionBuildError.h
|
||||
minecraft/VersionFile.cpp
|
||||
minecraft/VersionFile.h
|
||||
minecraft/ProfilePatch.h
|
||||
minecraft/VersionFilterData.h
|
||||
minecraft/VersionFilterData.cpp
|
||||
minecraft/Mod.h
|
||||
minecraft/Mod.cpp
|
||||
minecraft/ModList.h
|
||||
minecraft/ModList.cpp
|
||||
minecraft/World.h
|
||||
minecraft/World.cpp
|
||||
minecraft/WorldList.h
|
||||
minecraft/WorldList.cpp
|
||||
|
||||
# FTB
|
||||
minecraft/ftb/OneSixFTBInstance.h
|
||||
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
|
||||
|
||||
# Assets
|
||||
minecraft/AssetsUtils.h
|
||||
minecraft/AssetsUtils.cpp
|
||||
|
||||
# Forge and all things forge related
|
||||
minecraft/forge/ForgeVersion.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
|
||||
SOURCES minecraft/GradleSpecifier_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
add_unit_test(MojangVersionFormat
|
||||
SOURCES minecraft/MojangVersionFormat_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
DATA minecraft/testdata
|
||||
)
|
||||
|
||||
add_unit_test(Library
|
||||
SOURCES minecraft/Library_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
# FIXME: shares data with FileSystem test
|
||||
add_unit_test(ModList
|
||||
SOURCES minecraft/ModList_test.cpp
|
||||
DATA testdata
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
add_unit_test(ParseUtils
|
||||
SOURCES minecraft/ParseUtils_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
# the screenshots feature
|
||||
set(SCREENSHOTS_SOURCES
|
||||
screenshots/Screenshot.h
|
||||
screenshots/ImgurUpload.h
|
||||
screenshots/ImgurUpload.cpp
|
||||
screenshots/ImgurAlbumCreation.h
|
||||
screenshots/ImgurAlbumCreation.cpp
|
||||
)
|
||||
|
||||
set(TASKS_SOURCES
|
||||
# Tasks
|
||||
tasks/Task.h
|
||||
tasks/Task.cpp
|
||||
tasks/ThreadTask.h
|
||||
tasks/ThreadTask.cpp
|
||||
tasks/SequentialTask.h
|
||||
tasks/SequentialTask.cpp
|
||||
)
|
||||
|
||||
set(SETTINGS_SOURCES
|
||||
# Settings
|
||||
settings/INIFile.cpp
|
||||
settings/INIFile.h
|
||||
settings/INISettingsObject.cpp
|
||||
settings/INISettingsObject.h
|
||||
settings/OverrideSetting.cpp
|
||||
settings/OverrideSetting.h
|
||||
settings/PassthroughSetting.cpp
|
||||
settings/PassthroughSetting.h
|
||||
settings/Setting.cpp
|
||||
settings/Setting.h
|
||||
settings/SettingsObject.cpp
|
||||
settings/SettingsObject.h
|
||||
)
|
||||
|
||||
add_unit_test(INIFile
|
||||
SOURCES settings/INIFile_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
set(JAVA_SOURCES
|
||||
# Java related code
|
||||
java/launch/CheckJava.cpp
|
||||
java/launch/CheckJava.h
|
||||
java/JavaChecker.h
|
||||
java/JavaChecker.cpp
|
||||
java/JavaCheckerJob.h
|
||||
java/JavaCheckerJob.cpp
|
||||
java/JavaInstall.h
|
||||
java/JavaInstall.cpp
|
||||
java/JavaInstallList.h
|
||||
java/JavaInstallList.cpp
|
||||
java/JavaUtils.h
|
||||
java/JavaUtils.cpp
|
||||
java/JavaVersion.h
|
||||
java/JavaVersion.cpp
|
||||
)
|
||||
|
||||
add_unit_test(JavaVersion
|
||||
SOURCES java/JavaVersion_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
set(TRANSLATIONS_SOURCES
|
||||
translations/TranslationsModel.h
|
||||
translations/TranslationsModel.cpp
|
||||
)
|
||||
|
||||
set(TOOLS_SOURCES
|
||||
# Tools
|
||||
tools/BaseExternalTool.cpp
|
||||
tools/BaseExternalTool.h
|
||||
tools/BaseProfiler.cpp
|
||||
tools/BaseProfiler.h
|
||||
tools/JProfiler.cpp
|
||||
tools/JProfiler.h
|
||||
tools/JVisualVM.cpp
|
||||
tools/JVisualVM.h
|
||||
tools/MCEditTool.cpp
|
||||
tools/MCEditTool.h
|
||||
)
|
||||
|
||||
set(WONKO_SOURCES
|
||||
# Wonko
|
||||
wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp
|
||||
wonko/tasks/BaseWonkoEntityRemoteLoadTask.h
|
||||
wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp
|
||||
wonko/tasks/BaseWonkoEntityLocalLoadTask.h
|
||||
wonko/format/WonkoFormatV1.cpp
|
||||
wonko/format/WonkoFormatV1.h
|
||||
wonko/format/WonkoFormat.cpp
|
||||
wonko/format/WonkoFormat.h
|
||||
wonko/BaseWonkoEntity.cpp
|
||||
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
|
||||
)
|
||||
|
||||
add_unit_test(WonkoIndex
|
||||
SOURCES wonko/WonkoIndex_test.cpp
|
||||
LIBS MultiMC_logic
|
||||
)
|
||||
|
||||
################################ COMPILE ################################
|
||||
|
||||
# we need zlib
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
set(LOGIC_SOURCES
|
||||
${CORE_SOURCES}
|
||||
${PATHMATCHER_SOURCES}
|
||||
${NET_SOURCES}
|
||||
${LAUNCH_SOURCES}
|
||||
${UPDATE_SOURCES}
|
||||
${NOTIFICATIONS_SOURCES}
|
||||
${NEWS_SOURCES}
|
||||
${STATUS_SOURCES}
|
||||
${MINECRAFT_SOURCES}
|
||||
${SCREENSHOTS_SOURCES}
|
||||
${TASKS_SOURCES}
|
||||
${SETTINGS_SOURCES}
|
||||
${JAVA_SOURCES}
|
||||
${TRANSLATIONS_SOURCES}
|
||||
${TOOLS_SOURCES}
|
||||
${WONKO_SOURCES}
|
||||
${ICONS_SOURCES}
|
||||
)
|
||||
|
||||
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
|
||||
set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
|
||||
|
||||
generate_export_header(MultiMC_logic)
|
||||
|
||||
# Link
|
||||
target_link_libraries(MultiMC_logic xz-embedded unpack200 systeminfo MultiMC_quazip ${NBT_NAME} ${ZLIB_LIBRARIES})
|
||||
|
||||
qt5_use_modules(MultiMC_logic Core Xml Network Concurrent)
|
||||
|
||||
# Mark and export headers
|
||||
target_include_directories(MultiMC_logic PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PRIVATE "${ZLIB_INCLUDE_DIRS}")
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||
*
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||
*
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "Env.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
#include "icons/IconList.h"
|
||||
#include "BaseVersion.h"
|
||||
#include "BaseVersionList.h"
|
||||
#include <QDir>
|
||||
@@ -8,104 +7,71 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QDebug>
|
||||
#include "tasks/Task.h"
|
||||
#include "wonko/WonkoIndex.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
class Env::Private
|
||||
{
|
||||
public:
|
||||
QNetworkAccessManager m_qnam;
|
||||
shared_qobject_ptr<HttpMetaCache> m_metacache;
|
||||
std::shared_ptr<IIconList> m_iconlist;
|
||||
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
||||
shared_qobject_ptr<WonkoIndex> m_wonkoIndex;
|
||||
QString m_wonkoRootUrl;
|
||||
};
|
||||
|
||||
static Env * instance;
|
||||
|
||||
/*
|
||||
* The *NEW* global rat nest of an object. Handle with care.
|
||||
*/
|
||||
|
||||
Env::Env()
|
||||
{
|
||||
m_qnam = std::make_shared<QNetworkAccessManager>();
|
||||
d = new Private();
|
||||
}
|
||||
|
||||
void Env::destroy()
|
||||
Env::~Env()
|
||||
{
|
||||
m_metacache.reset();
|
||||
m_qnam.reset();
|
||||
m_icons.reset();
|
||||
m_versionLists.clear();
|
||||
delete d;
|
||||
}
|
||||
|
||||
Env& Env::Env::getInstance()
|
||||
{
|
||||
static Env instance;
|
||||
return instance;
|
||||
if(!instance)
|
||||
{
|
||||
instance = new Env();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
|
||||
std::shared_ptr< HttpMetaCache > Env::metacache()
|
||||
void Env::dispose()
|
||||
{
|
||||
Q_ASSERT(m_metacache != nullptr);
|
||||
return m_metacache;
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr< QNetworkAccessManager > Env::qnam()
|
||||
shared_qobject_ptr< HttpMetaCache > Env::metacache()
|
||||
{
|
||||
return m_qnam;
|
||||
return d->m_metacache;
|
||||
}
|
||||
|
||||
std::shared_ptr<IconList> Env::icons()
|
||||
QNetworkAccessManager& Env::qnam() const
|
||||
{
|
||||
Q_ASSERT(m_icons != nullptr);
|
||||
return m_icons;
|
||||
return d->m_qnam;
|
||||
}
|
||||
/*
|
||||
class NullVersion : public BaseVersion
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual QString name()
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
virtual QString descriptor()
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
virtual QString typeString() const
|
||||
{
|
||||
return "Null";
|
||||
}
|
||||
};
|
||||
|
||||
class NullTask: public Task
|
||||
std::shared_ptr<IIconList> Env::icons()
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual void executeTask()
|
||||
{
|
||||
emitFailed(tr("Nothing to do."));
|
||||
}
|
||||
};
|
||||
return d->m_iconlist;
|
||||
}
|
||||
|
||||
class NullVersionList: public BaseVersionList
|
||||
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual const BaseVersionPtr at(int i) const
|
||||
{
|
||||
return std::make_shared<NullVersion>();
|
||||
}
|
||||
virtual int count() const
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
virtual Task* getLoadTask()
|
||||
{
|
||||
return new NullTask;
|
||||
}
|
||||
virtual bool isLoaded()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void sort()
|
||||
{
|
||||
}
|
||||
virtual void updateListData(QList< BaseVersionPtr >)
|
||||
{
|
||||
}
|
||||
};
|
||||
*/
|
||||
d->m_iconlist = iconlist;
|
||||
}
|
||||
|
||||
BaseVersionPtr Env::getVersion(QString component, QString version)
|
||||
{
|
||||
@@ -119,8 +85,8 @@ BaseVersionPtr Env::getVersion(QString component, QString version)
|
||||
|
||||
std::shared_ptr< BaseVersionList > Env::getVersionList(QString component)
|
||||
{
|
||||
auto iter = m_versionLists.find(component);
|
||||
if(iter != m_versionLists.end())
|
||||
auto iter = d->m_versionLists.find(component);
|
||||
if(iter != d->m_versionLists.end())
|
||||
{
|
||||
return *iter;
|
||||
}
|
||||
@@ -130,12 +96,22 @@ std::shared_ptr< BaseVersionList > Env::getVersionList(QString component)
|
||||
|
||||
void Env::registerVersionList(QString name, std::shared_ptr< BaseVersionList > vlist)
|
||||
{
|
||||
m_versionLists[name] = 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()
|
||||
{
|
||||
auto &m_metacache = d->m_metacache;
|
||||
m_metacache.reset(new HttpMetaCache("metacache"));
|
||||
m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
|
||||
m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
|
||||
@@ -149,6 +125,7 @@ void Env::initHttpMetaCache()
|
||||
m_metacache->addBase("root", QDir::currentPath());
|
||||
m_metacache->addBase("translations", QDir("translations").absolutePath());
|
||||
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
|
||||
m_metacache->addBase("wonko", QDir("cache/wonko").absolutePath());
|
||||
m_metacache->Load();
|
||||
}
|
||||
|
||||
@@ -178,8 +155,7 @@ void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QStr
|
||||
|
||||
qDebug() << "Detecting proxy settings...";
|
||||
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
||||
if (m_qnam.get())
|
||||
m_qnam->setProxy(proxy);
|
||||
d->m_qnam.setProxy(proxy);
|
||||
QString proxyDesc;
|
||||
if (proxy.type() == QNetworkProxy::NoProxy)
|
||||
{
|
||||
@@ -215,4 +191,14 @@ void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QStr
|
||||
qDebug() << proxyDesc;
|
||||
}
|
||||
|
||||
#include "Env.moc"
|
||||
QString Env::wonkoRootUrl() const
|
||||
{
|
||||
return d->m_wonkoRootUrl;
|
||||
}
|
||||
|
||||
void Env::setWonkoRootUrl(const QString& url)
|
||||
{
|
||||
d->m_wonkoRootUrl = url;
|
||||
}
|
||||
|
||||
#include "Env.moc"
|
||||
@@ -1,16 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "icons/IIconList.h"
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
class IconList;
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class HttpMetaCache;
|
||||
class BaseVersionList;
|
||||
class BaseVersion;
|
||||
class WonkoIndex;
|
||||
|
||||
#if defined(ENV)
|
||||
#undef ENV
|
||||
@@ -21,18 +24,18 @@ class MULTIMC_LOGIC_EXPORT Env
|
||||
{
|
||||
friend class MultiMC;
|
||||
private:
|
||||
class Private;
|
||||
Env();
|
||||
~Env();
|
||||
static void dispose();
|
||||
public:
|
||||
static Env& getInstance();
|
||||
|
||||
// call when Qt stuff is being torn down
|
||||
void destroy();
|
||||
QNetworkAccessManager &qnam() const;
|
||||
|
||||
std::shared_ptr<QNetworkAccessManager> qnam();
|
||||
shared_qobject_ptr<HttpMetaCache> metacache();
|
||||
|
||||
std::shared_ptr<HttpMetaCache> metacache();
|
||||
|
||||
std::shared_ptr<IconList> icons();
|
||||
std::shared_ptr<IIconList> icons();
|
||||
|
||||
/// init the cache. FIXME: possible future hook point
|
||||
void initHttpMetaCache();
|
||||
@@ -47,9 +50,14 @@ public:
|
||||
std::shared_ptr<BaseVersion> getVersion(QString component, QString version);
|
||||
|
||||
void registerVersionList(QString name, std::shared_ptr<BaseVersionList> vlist);
|
||||
|
||||
void registerIconList(std::shared_ptr<IIconList> iconlist);
|
||||
|
||||
shared_qobject_ptr<WonkoIndex> wonkoIndex();
|
||||
|
||||
QString wonkoRootUrl() const;
|
||||
void setWonkoRootUrl(const QString &url);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
||||
std::shared_ptr<HttpMetaCache> m_metacache;
|
||||
std::shared_ptr<IconList> m_icons;
|
||||
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
||||
Private * d;
|
||||
};
|
||||
@@ -15,7 +15,7 @@ void ensureExists(const QDir &dir)
|
||||
{
|
||||
if (!QDir().mkpath(dir.absolutePath()))
|
||||
{
|
||||
throw FileSystemException("Unable to create directory " + dir.dirName() + " (" +
|
||||
throw FileSystemException("Unable to create folder " + dir.dirName() + " (" +
|
||||
dir.absolutePath() + ")");
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,25 @@ QByteArray read(const QString &filename)
|
||||
return data;
|
||||
}
|
||||
|
||||
bool updateTimestamp(const QString& filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!file.open(QIODevice::ReadWrite))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const quint64 size = file.size();
|
||||
file.seek(size);
|
||||
file.write( QByteArray(1, '0') );
|
||||
file.resize(size);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool ensureFilePathExists(QString filenamepath)
|
||||
{
|
||||
QFileInfo a(filenamepath);
|
||||
@@ -131,6 +150,7 @@ bool copy::operator()(const QString &offset)
|
||||
}
|
||||
if(!operator()(inner_offset))
|
||||
{
|
||||
qWarning() << "Failed to copy" << inner_offset;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -245,7 +265,7 @@ QString ResolveExecutable(QString path)
|
||||
/**
|
||||
* Normalize path
|
||||
*
|
||||
* Any paths inside the current directory will be normalized to relative paths (to current)
|
||||
* Any paths inside the current folder will be normalized to relative paths (to current)
|
||||
* Other paths will be made absolute
|
||||
*/
|
||||
QString NormalizePath(QString path)
|
||||
@@ -304,7 +324,7 @@ QString DirNameFromString(QString string, QString inDir)
|
||||
return dirName;
|
||||
}
|
||||
|
||||
// Does the directory 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)
|
||||
bool checkProblemticPathJava(QDir folder)
|
||||
{
|
||||
@@ -28,6 +28,11 @@ MULTIMC_LOGIC_EXPORT void write(const QString &filename, const QByteArray &data)
|
||||
*/
|
||||
MULTIMC_LOGIC_EXPORT QByteArray read(const QString &filename);
|
||||
|
||||
/**
|
||||
* Update the last changed timestamp of an existing file
|
||||
*/
|
||||
MULTIMC_LOGIC_EXPORT bool updateTimestamp(const QString & filename);
|
||||
|
||||
/**
|
||||
* Creates all the folders in a path for the specified path
|
||||
* last segment of the path is treated as a file name and is ignored!
|
||||
@@ -43,7 +48,6 @@ MULTIMC_LOGIC_EXPORT bool ensureFolderPathExists(QString filenamepath);
|
||||
class MULTIMC_LOGIC_EXPORT copy
|
||||
{
|
||||
public:
|
||||
copy(const copy&) = delete;
|
||||
copy(const QString & src, const QString & dst)
|
||||
{
|
||||
m_src = src;
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <QTest>
|
||||
#include <QTemporaryDir>
|
||||
#include <QStandardPaths>
|
||||
#include "TestUtil.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
@@ -80,7 +81,7 @@ slots:
|
||||
|
||||
void test_copy()
|
||||
{
|
||||
QString folder = QFINDTESTDATA("tests/data/test_folder");
|
||||
QString folder = QFINDTESTDATA("data/test_folder");
|
||||
auto f = [&folder]()
|
||||
{
|
||||
QTemporaryDir tempDir;
|
||||
@@ -110,8 +111,54 @@ slots:
|
||||
QVERIFY(folder.endsWith('/'));
|
||||
f();
|
||||
}
|
||||
|
||||
void test_getDesktop()
|
||||
{
|
||||
QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
|
||||
}
|
||||
|
||||
// this is only valid on linux
|
||||
// FIXME: implement on windows, OSX, then test.
|
||||
#if defined(Q_OS_LINUX)
|
||||
void test_createShortcut_data()
|
||||
{
|
||||
QTest::addColumn<QString>("location");
|
||||
QTest::addColumn<QString>("dest");
|
||||
QTest::addColumn<QStringList>("args");
|
||||
QTest::addColumn<QString>("name");
|
||||
QTest::addColumn<QString>("iconLocation");
|
||||
QTest::addColumn<QByteArray>("result");
|
||||
|
||||
QTest::newRow("unix") << QDir::currentPath()
|
||||
<< "asdfDest"
|
||||
<< (QStringList() << "arg1" << "arg2")
|
||||
<< "asdf"
|
||||
<< QString()
|
||||
#if defined(Q_OS_LINUX)
|
||||
<< MULTIMC_GET_TEST_FILE("data/FileSystem-test_createShortcut-unix")
|
||||
#elif defined(Q_OS_WIN)
|
||||
<< QByteArray()
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
void test_createShortcut()
|
||||
{
|
||||
QFETCH(QString, location);
|
||||
QFETCH(QString, dest);
|
||||
QFETCH(QStringList, args);
|
||||
QFETCH(QString, name);
|
||||
QFETCH(QString, iconLocation);
|
||||
QFETCH(QByteArray, result);
|
||||
|
||||
QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
|
||||
QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
|
||||
|
||||
//QDir().remove(location);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(FileSystemTest)
|
||||
|
||||
#include "tst_FileSystem.moc"
|
||||
#include "FileSystem_test.moc"
|
||||
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;
|
||||
};
|
||||
@@ -54,4 +54,4 @@ slots:
|
||||
|
||||
QTEST_GUILESS_MAIN(GZipTest)
|
||||
|
||||
#include "tst_GZip.moc"
|
||||
#include "GZip_test.moc"
|
||||
68
api/logic/InstanceCopyTask.cpp
Normal file
68
api/logic/InstanceCopyTask.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "InstanceCopyTask.h"
|
||||
#include "BaseInstanceProvider.h"
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "FileSystem.h"
|
||||
#include "NullInstance.h"
|
||||
#include "pathmatcher/RegexpMatcher.h"
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvider* target, InstancePtr origInstance, const QString& instName, const QString& instIcon, const QString& instGroup, bool copySaves)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_target = target;
|
||||
m_origInstance = origInstance;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
|
||||
if(!copySaves)
|
||||
{
|
||||
// FIXME: get this from the original instance type...
|
||||
auto matcherReal = new RegexpMatcher("[.]?minecraft/saves");
|
||||
matcherReal->caseSensitive(false);
|
||||
m_matcher.reset(matcherReal);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceCopyTask::executeTask()
|
||||
{
|
||||
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());
|
||||
|
||||
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
|
||||
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()
|
||||
{
|
||||
auto successful = m_copyFuture.result();
|
||||
if(!successful)
|
||||
{
|
||||
m_target->destroyStagingPath(m_stagingPath);
|
||||
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"));
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
// FIXME: and this too? errors???
|
||||
m_origInstance->copy(instanceSettings, m_stagingPath);
|
||||
|
||||
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()
|
||||
{
|
||||
m_target->destroyStagingPath(m_stagingPath);
|
||||
emitFailed(tr("Instance folder copy has been aborted."));
|
||||
return;
|
||||
}
|
||||
42
api/logic/InstanceCopyTask.h
Normal file
42
api/logic/InstanceCopyTask.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "BaseVersion.h"
|
||||
#include "BaseInstance.h"
|
||||
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvider * target, InstancePtr origInstance, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup, bool copySaves);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
virtual void executeTask() override;
|
||||
void copyFinished();
|
||||
void copyAborted();
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
BaseInstanceProvider * m_target = nullptr;
|
||||
InstancePtr m_origInstance;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
46
api/logic/InstanceCreationTask.cpp
Normal file
46
api/logic/InstanceCreationTask.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "InstanceCreationTask.h"
|
||||
#include "BaseInstanceProvider.h"
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
//FIXME: remove this
|
||||
#include "minecraft/MinecraftVersion.h"
|
||||
#include "minecraft/onesix/OneSixInstance.h"
|
||||
|
||||
InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider* target, BaseVersionPtr version,
|
||||
const QString& instName, const QString& instIcon, const QString& instGroup)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_target = target;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
m_version = version;
|
||||
}
|
||||
|
||||
void InstanceCreationTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Creating instance from version %1").arg(m_version->name()));
|
||||
auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
|
||||
if(!minecraftVersion)
|
||||
{
|
||||
emitFailed(tr("The supplied version is not a Minecraft version."));
|
||||
return ;
|
||||
}
|
||||
|
||||
QString stagingPath = m_target->getStagedInstancePath();
|
||||
QDir rootDir(stagingPath);
|
||||
|
||||
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(stagingPath, "instance.cfg"));
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
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();
|
||||
}
|
||||
31
api/logic/InstanceCreationTask.h
Normal file
31
api/logic/InstanceCreationTask.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "BaseVersion.h"
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider * target, BaseVersionPtr version, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
virtual void executeTask() override;
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
BaseInstanceProvider * m_target;
|
||||
BaseVersionPtr m_version;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
};
|
||||
|
||||
164
api/logic/InstanceImportTask.cpp
Normal file
164
api/logic/InstanceImportTask.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
|
||||
#include "InstanceImportTask.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "BaseInstanceProvider.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Env.h"
|
||||
#include "MMCZip.h"
|
||||
#include "NullInstance.h"
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "icons/IIconList.h"
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
InstanceImportTask::InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, BaseInstanceProvider * target,
|
||||
const QString &instName, const QString &instIcon, const QString &instGroup)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_sourceUrl = sourceUrl;
|
||||
m_target = target;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
}
|
||||
|
||||
void InstanceImportTask::executeTask()
|
||||
{
|
||||
InstancePtr newInstance;
|
||||
|
||||
if (m_sourceUrl.isLocalFile())
|
||||
{
|
||||
m_archivePath = m_sourceUrl.toLocalFile();
|
||||
extractAndTweak();
|
||||
}
|
||||
else
|
||||
{
|
||||
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
|
||||
m_downloadRequired = true;
|
||||
|
||||
const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path();
|
||||
auto entry = ENV.metacache()->resolveEntry("general", path);
|
||||
entry->setStale(true);
|
||||
m_filesNetJob.reset(new NetJob(tr("Modpack download")));
|
||||
m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
|
||||
m_archivePath = entry->getFullPath();
|
||||
auto job = m_filesNetJob.get();
|
||||
connect(job, &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
|
||||
connect(job, &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
|
||||
connect(job, &NetJob::failed, this, &InstanceImportTask::downloadFailed);
|
||||
m_filesNetJob->start();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceImportTask::downloadSucceeded()
|
||||
{
|
||||
extractAndTweak();
|
||||
}
|
||||
|
||||
void InstanceImportTask::downloadFailed(QString reason)
|
||||
{
|
||||
emitFailed(reason);
|
||||
}
|
||||
|
||||
void InstanceImportTask::downloadProgressChanged(qint64 current, qint64 total)
|
||||
{
|
||||
setProgress(current / 2, total);
|
||||
}
|
||||
|
||||
static QFileInfo findRecursive(const QString &dir, const QString &name)
|
||||
{
|
||||
for (const auto info : QDir(dir).entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files, QDir::DirsLast))
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void InstanceImportTask::extractAndTweak()
|
||||
{
|
||||
setStatus(tr("Extracting modpack"));
|
||||
m_stagingPath = m_target->getStagedInstancePath();
|
||||
QDir extractDir(m_stagingPath);
|
||||
qDebug() << "Attempting to create instance from" << m_archivePath;
|
||||
|
||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, 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()
|
||||
{
|
||||
if (m_extractFuture.result().isEmpty())
|
||||
{
|
||||
m_target->destroyStagingPath(m_stagingPath);
|
||||
emitFailed(tr("Failed to extract modpack"));
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// FIXME: copy from FolderInstanceProvider!!! FIX IT!!!
|
||||
auto instanceSettings = std::make_shared<INISettingsObject>(instanceCfgFile.absoluteFilePath());
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
QString actualDir = instanceCfgFile.absolutePath();
|
||||
NullInstance instance(m_globalSettings, instanceSettings, actualDir);
|
||||
|
||||
// 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 = 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()
|
||||
{
|
||||
m_target->destroyStagingPath(m_stagingPath);
|
||||
emitFailed(tr("Instance import has been aborted."));
|
||||
return;
|
||||
}
|
||||
47
api/logic/InstanceImportTask.h
Normal file
47
api/logic/InstanceImportTask.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, BaseInstanceProvider * target, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
virtual void executeTask() override;
|
||||
|
||||
private:
|
||||
void extractAndTweak();
|
||||
|
||||
private slots:
|
||||
void downloadSucceeded();
|
||||
void downloadFailed(QString reason);
|
||||
void downloadProgressChanged(qint64 current, qint64 total);
|
||||
void extractFinished();
|
||||
void extractAborted();
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
NetJobPtr m_filesNetJob;
|
||||
QUrl m_sourceUrl;
|
||||
BaseInstanceProvider * m_target;
|
||||
QString m_archivePath;
|
||||
bool m_downloadRequired = false;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
QString m_stagingPath;
|
||||
QFuture<QStringList> m_extractFuture;
|
||||
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
||||
};
|
||||
342
api/logic/InstanceList.cpp
Normal file
342
api/logic/InstanceList.cpp
Normal file
@@ -0,0 +1,342 @@
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <QDir>
|
||||
#include <QSet>
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <QTextStream>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QDebug>
|
||||
|
||||
#include "InstanceList.h"
|
||||
#include "BaseInstance.h"
|
||||
|
||||
#include "FolderInstanceProvider.h"
|
||||
|
||||
InstanceList::InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent)
|
||||
: QAbstractListModel(parent), m_instDir(instDir)
|
||||
{
|
||||
m_globalSettings = globalSettings;
|
||||
resumeWatch();
|
||||
}
|
||||
|
||||
InstanceList::~InstanceList()
|
||||
{
|
||||
}
|
||||
|
||||
int InstanceList::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return m_instances.count();
|
||||
}
|
||||
|
||||
QModelIndex InstanceList::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
if (row < 0 || row >= m_instances.size())
|
||||
return QModelIndex();
|
||||
return createIndex(row, column, (void *)m_instances.at(row).get());
|
||||
}
|
||||
|
||||
QVariant InstanceList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
BaseInstance *pdata = static_cast<BaseInstance *>(index.internalPointer());
|
||||
switch (role)
|
||||
{
|
||||
case InstancePointerRole:
|
||||
{
|
||||
QVariant v = qVariantFromValue((void *)pdata);
|
||||
return v;
|
||||
}
|
||||
case InstanceIDRole:
|
||||
{
|
||||
return pdata->id();
|
||||
}
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
return pdata->name();
|
||||
}
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
return pdata->instanceRoot();
|
||||
}
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
return pdata->iconKey();
|
||||
}
|
||||
// HACK: see GroupView.h in gui!
|
||||
case GroupRole:
|
||||
{
|
||||
return pdata->group();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags f;
|
||||
if (index.isValid())
|
||||
{
|
||||
f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
QStringList InstanceList::getGroups()
|
||||
{
|
||||
return m_groups.toList();
|
||||
}
|
||||
|
||||
void InstanceList::deleteGroup(const QString& name)
|
||||
{
|
||||
for(auto & instance: m_instances)
|
||||
{
|
||||
auto instGroupName = instance->group();
|
||||
if(instGroupName == name)
|
||||
{
|
||||
instance->setGroupPost(QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QMap<InstanceId, InstanceLocator> getIdMapping(const QList<InstancePtr> &list)
|
||||
{
|
||||
QMap<InstanceId, InstanceLocator> out;
|
||||
int i = 0;
|
||||
for(auto & item: list)
|
||||
{
|
||||
auto id = item->id();
|
||||
if(out.contains(id))
|
||||
{
|
||||
qWarning() << "Duplicate ID" << id << "in instance list";
|
||||
}
|
||||
out[id] = std::make_pair(item, i);
|
||||
i++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
InstanceList::InstListError InstanceList::loadList(bool complete)
|
||||
{
|
||||
auto existingIds = getIdMapping(m_instances);
|
||||
|
||||
QList<InstancePtr> newList;
|
||||
|
||||
auto processIds = [&](BaseInstanceProvider * provider, QList<InstanceId> ids)
|
||||
{
|
||||
for(auto & id: ids)
|
||||
{
|
||||
if(existingIds.contains(id))
|
||||
{
|
||||
auto instPair = existingIds[id];
|
||||
/*
|
||||
auto & instPtr = instPair.first;
|
||||
auto & instIdx = instPair.second;
|
||||
*/
|
||||
existingIds.remove(id);
|
||||
qDebug() << "Should keep and soft-reload" << id;
|
||||
}
|
||||
else
|
||||
{
|
||||
InstancePtr instPtr = provider->loadInstance(id);
|
||||
if(instPtr)
|
||||
{
|
||||
newList.append(instPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if(complete)
|
||||
{
|
||||
for(auto & item: m_providers)
|
||||
{
|
||||
processIds(item.get(), item->discoverInstances());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto & item: m_updatedProviders)
|
||||
{
|
||||
processIds(item, item->discoverInstances());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: looks like a general algorithm with a few specifics inserted. Do something about it.
|
||||
if(!existingIds.isEmpty())
|
||||
{
|
||||
// get the list of removed instances and sort it by their original index, from last to first
|
||||
auto deadList = existingIds.values();
|
||||
auto orderSortPredicate = [](const InstanceLocator & a, const InstanceLocator & b) -> bool
|
||||
{
|
||||
return a.second > b.second;
|
||||
};
|
||||
std::sort(deadList.begin(), deadList.end(), orderSortPredicate);
|
||||
// remove the contiguous ranges of rows
|
||||
int front_bookmark = -1;
|
||||
int back_bookmark = -1;
|
||||
int currentItem = -1;
|
||||
auto removeNow = [&]()
|
||||
{
|
||||
beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark);
|
||||
m_instances.erase(m_instances.begin() + front_bookmark, m_instances.begin() + back_bookmark + 1);
|
||||
endRemoveRows();
|
||||
front_bookmark = -1;
|
||||
back_bookmark = currentItem;
|
||||
};
|
||||
for(auto & removedItem: deadList)
|
||||
{
|
||||
auto instPtr = removedItem.first;
|
||||
if(!complete && !m_updatedProviders.contains(instPtr->provider()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
instPtr->invalidate();
|
||||
currentItem = removedItem.second;
|
||||
if(back_bookmark == -1)
|
||||
{
|
||||
// no bookmark yet
|
||||
back_bookmark = currentItem;
|
||||
}
|
||||
else if(currentItem == front_bookmark - 1)
|
||||
{
|
||||
// part of contiguous sequence, continue
|
||||
}
|
||||
else
|
||||
{
|
||||
// seam between previous and current item
|
||||
removeNow();
|
||||
}
|
||||
front_bookmark = currentItem;
|
||||
}
|
||||
if(back_bookmark != -1)
|
||||
{
|
||||
removeNow();
|
||||
}
|
||||
}
|
||||
if(newList.size())
|
||||
{
|
||||
add(newList);
|
||||
}
|
||||
m_updatedProviders.clear();
|
||||
return NoError;
|
||||
}
|
||||
|
||||
void InstanceList::add(const QList<InstancePtr> &t)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_instances.count(), m_instances.count() + t.size() - 1);
|
||||
m_instances.append(t);
|
||||
for(auto & ptr : t)
|
||||
{
|
||||
connect(ptr.get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void InstanceList::resumeWatch()
|
||||
{
|
||||
if(m_watchLevel > 0)
|
||||
{
|
||||
qWarning() << "Bad suspend level resume in instance list";
|
||||
return;
|
||||
}
|
||||
m_watchLevel++;
|
||||
if(m_watchLevel > 0 && !m_updatedProviders.isEmpty())
|
||||
{
|
||||
loadList();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::suspendWatch()
|
||||
{
|
||||
m_watchLevel --;
|
||||
}
|
||||
|
||||
void InstanceList::providerUpdated()
|
||||
{
|
||||
auto provider = dynamic_cast<BaseInstanceProvider *>(QObject::sender());
|
||||
if(!provider)
|
||||
{
|
||||
qWarning() << "InstanceList::providerUpdated triggered by a non-provider";
|
||||
return;
|
||||
}
|
||||
m_updatedProviders.insert(provider);
|
||||
if(m_watchLevel == 1)
|
||||
{
|
||||
loadList();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::groupsPublished(QSet<QString> newGroups)
|
||||
{
|
||||
m_groups.unite(newGroups);
|
||||
}
|
||||
|
||||
void InstanceList::addInstanceProvider(BaseInstanceProvider* provider)
|
||||
{
|
||||
connect(provider, &BaseInstanceProvider::instancesChanged, this, &InstanceList::providerUpdated);
|
||||
connect(provider, &BaseInstanceProvider::groupsChanged, this, &InstanceList::groupsPublished);
|
||||
m_providers.append(provider);
|
||||
}
|
||||
|
||||
InstancePtr InstanceList::getInstanceById(QString instId) const
|
||||
{
|
||||
if(instId.isEmpty())
|
||||
return InstancePtr();
|
||||
for(auto & inst: m_instances)
|
||||
{
|
||||
if (inst->id() == instId)
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
return InstancePtr();
|
||||
}
|
||||
|
||||
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const
|
||||
{
|
||||
return index(getInstIndex(getInstanceById(id).get()));
|
||||
}
|
||||
|
||||
int InstanceList::getInstIndex(BaseInstance *inst) const
|
||||
{
|
||||
int count = m_instances.count();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (inst == m_instances[i].get())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
{
|
||||
int i = getInstIndex(inst);
|
||||
if (i != -1)
|
||||
{
|
||||
emit dataChanged(index(i), index(i));
|
||||
}
|
||||
}
|
||||
|
||||
#include "InstanceList.moc"
|
||||
108
api/logic/InstanceList.h
Normal file
108
api/logic/InstanceList.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractListModel>
|
||||
#include <QSet>
|
||||
#include <QList>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
#include "BaseInstanceProvider.h"
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
class QFileSystemWatcher;
|
||||
class BaseInstance;
|
||||
class QDir;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0);
|
||||
virtual ~InstanceList();
|
||||
|
||||
public:
|
||||
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
InstancePtr at(int i) const
|
||||
{
|
||||
return m_instances.at(i);
|
||||
}
|
||||
|
||||
int count() const
|
||||
{
|
||||
return m_instances.count();
|
||||
}
|
||||
|
||||
InstListError loadList(bool complete = false);
|
||||
|
||||
/// Add an instance provider. Takes ownership of it. Should only be done before the first load.
|
||||
void addInstanceProvider(BaseInstanceProvider * provider);
|
||||
|
||||
InstancePtr getInstanceById(QString id) const;
|
||||
QModelIndex getInstanceIndexById(const QString &id) const;
|
||||
QStringList getGroups();
|
||||
|
||||
void deleteGroup(const QString & name);
|
||||
|
||||
signals:
|
||||
void dataIsInvalid();
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
void groupsPublished(QSet<QString>);
|
||||
void providerUpdated();
|
||||
|
||||
private:
|
||||
int getInstIndex(BaseInstance *inst) const;
|
||||
void suspendWatch();
|
||||
void resumeWatch();
|
||||
void add(const QList<InstancePtr> &list);
|
||||
|
||||
protected:
|
||||
int m_watchLevel = 0;
|
||||
QSet<BaseInstanceProvider *> m_updatedProviders;
|
||||
QString m_instDir;
|
||||
QList<InstancePtr> m_instances;
|
||||
QSet<QString> m_groups;
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
QVector<shared_qobject_ptr<BaseInstanceProvider>> m_providers;
|
||||
};
|
||||
@@ -23,16 +23,16 @@ public:
|
||||
};
|
||||
|
||||
/// @throw FileSystemException
|
||||
void write(const QJsonDocument &doc, const QString &filename);
|
||||
MULTIMC_LOGIC_EXPORT void write(const QJsonDocument &doc, const QString &filename);
|
||||
/// @throw FileSystemException
|
||||
void write(const QJsonObject &object, const QString &filename);
|
||||
MULTIMC_LOGIC_EXPORT void write(const QJsonObject &object, const QString &filename);
|
||||
/// @throw FileSystemException
|
||||
void write(const QJsonArray &array, const QString &filename);
|
||||
MULTIMC_LOGIC_EXPORT void write(const QJsonArray &array, const QString &filename);
|
||||
|
||||
QByteArray toBinary(const QJsonObject &obj);
|
||||
QByteArray toBinary(const QJsonArray &array);
|
||||
QByteArray toText(const QJsonObject &obj);
|
||||
QByteArray toText(const QJsonArray &array);
|
||||
MULTIMC_LOGIC_EXPORT QByteArray toBinary(const QJsonObject &obj);
|
||||
MULTIMC_LOGIC_EXPORT QByteArray toBinary(const QJsonArray &array);
|
||||
MULTIMC_LOGIC_EXPORT QByteArray toText(const QJsonObject &obj);
|
||||
MULTIMC_LOGIC_EXPORT QByteArray toText(const QJsonArray &array);
|
||||
|
||||
/// @throw JsonException
|
||||
MULTIMC_LOGIC_EXPORT QJsonDocument requireDocument(const QByteArray &data, const QString &what = "Document");
|
||||
@@ -48,33 +48,6 @@ MULTIMC_LOGIC_EXPORT QJsonArray requireArray(const QJsonDocument &doc, const QSt
|
||||
void writeString(QJsonObject & to, const QString &key, const QString &value);
|
||||
void writeStringList(QJsonObject & to, const QString &key, const QStringList &values);
|
||||
|
||||
template <typename T>
|
||||
void writeObjectList(QJsonObject & to, QString key, QList<std::shared_ptr<T>> values)
|
||||
{
|
||||
if (!values.isEmpty())
|
||||
{
|
||||
QJsonArray array;
|
||||
for (auto value: values)
|
||||
{
|
||||
array.append(value->toJson());
|
||||
}
|
||||
to.insert(key, array);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void writeObjectList(QJsonObject & to, QString key, QList<T> values)
|
||||
{
|
||||
if (!values.isEmpty())
|
||||
{
|
||||
QJsonArray array;
|
||||
for (auto value: values)
|
||||
{
|
||||
array.append(value.toJson());
|
||||
}
|
||||
to.insert(key, array);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QJsonValue toJson(const T &t)
|
||||
{
|
||||
@@ -140,9 +113,9 @@ template<> MULTIMC_LOGIC_EXPORT QUrl requireIsType<QUrl>(const QJsonValue &value
|
||||
// the following functions are higher level functions, that make use of the above functions for
|
||||
// type conversion
|
||||
template <typename T>
|
||||
T ensureIsType(const QJsonValue &value, const T default_, const QString &what = "Value")
|
||||
T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &what = "Value")
|
||||
{
|
||||
if (value.isUndefined())
|
||||
if (value.isUndefined() || value.isNull())
|
||||
{
|
||||
return default_;
|
||||
}
|
||||
@@ -169,7 +142,7 @@ T requireIsType(const QJsonObject &parent, const QString &key, const QString &wh
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, 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 + '\'');
|
||||
if (!parent.contains(key))
|
||||
@@ -180,10 +153,10 @@ T ensureIsType(const QJsonObject &parent, const QString &key, const T default_,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> requireIsArrayOf(const QJsonDocument &doc)
|
||||
QVector<T> requireIsArrayOf(const QJsonDocument &doc)
|
||||
{
|
||||
const QJsonArray array = requireArray(doc);
|
||||
QList<T> out;
|
||||
QVector<T> out;
|
||||
for (const QJsonValue val : array)
|
||||
{
|
||||
out.append(requireIsType<T>(val, "Document"));
|
||||
@@ -192,19 +165,19 @@ QList<T> requireIsArrayOf(const QJsonDocument &doc)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value")
|
||||
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value")
|
||||
{
|
||||
const QJsonArray array = requireIsType<QJsonArray>(value, what);
|
||||
QList<T> out;
|
||||
const QJsonArray array = ensureIsType<QJsonArray>(value, QJsonArray(), what);
|
||||
QVector<T> out;
|
||||
for (const QJsonValue val : array)
|
||||
{
|
||||
out.append(ensureIsType<T>(val, what));
|
||||
out.append(requireIsType<T>(val, what));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonValue &value, const QList<T> default_, const QString &what = "Value")
|
||||
QVector<T> ensureIsArrayOf(const QJsonValue &value, const QVector<T> default_, const QString &what = "Value")
|
||||
{
|
||||
if (value.isUndefined())
|
||||
{
|
||||
@@ -215,19 +188,19 @@ QList<T> ensureIsArrayOf(const QJsonValue &value, const QList<T> default_, const
|
||||
|
||||
/// @throw JsonException
|
||||
template <typename T>
|
||||
QList<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 + '\'');
|
||||
if (!parent.contains(key))
|
||||
{
|
||||
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
||||
}
|
||||
return requireIsArrayOf<T>(parent.value(key), localWhat);
|
||||
return ensureIsArrayOf<T>(parent.value(key), localWhat);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
||||
const QList<T> &default_, const QString &what = "__placeholder__")
|
||||
QVector<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
||||
const QVector<T> &default_ = QVector<T>(), const QString &what = "__placeholder__")
|
||||
{
|
||||
const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\'');
|
||||
if (!parent.contains(key))
|
||||
@@ -243,7 +216,7 @@ QList<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
||||
{ \
|
||||
return requireIsType<TYPE>(value, what); \
|
||||
} \
|
||||
inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_, 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); \
|
||||
} \
|
||||
@@ -251,7 +224,7 @@ QList<T> ensureIsArrayOf(const QJsonObject &parent, const QString &key,
|
||||
{ \
|
||||
return requireIsType<TYPE>(parent, key, what); \
|
||||
} \
|
||||
inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_, 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); \
|
||||
}
|
||||
@@ -12,6 +12,14 @@ LoggedProcess::LoggedProcess(QObject *parent) : QProcess(parent)
|
||||
connect(this, &QProcess::stateChanged, this, &LoggedProcess::on_stateChange);
|
||||
}
|
||||
|
||||
LoggedProcess::~LoggedProcess()
|
||||
{
|
||||
if(m_is_detachable)
|
||||
{
|
||||
setProcessState(QProcess::NotRunning);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList reprocess(const QByteArray & data, QString & leftover)
|
||||
{
|
||||
QString str = leftover + QString::fromLocal8Bit(data);
|
||||
@@ -161,3 +169,8 @@ qint64 LoggedProcess::processId() const
|
||||
return pid();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LoggedProcess::setDetachable(bool detachable)
|
||||
{
|
||||
m_is_detachable = detachable;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
#include <QProcess>
|
||||
#include "MessageLevel.h"
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
/*
|
||||
* This is a basic process.
|
||||
* It has line-based logging support and hides some of the nasty bits.
|
||||
*/
|
||||
class LoggedProcess : public QProcess
|
||||
class MULTIMC_LOGIC_EXPORT LoggedProcess : public QProcess
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -38,13 +39,15 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
explicit LoggedProcess(QObject* parent = 0);
|
||||
virtual ~LoggedProcess() {};
|
||||
explicit LoggedProcess(QObject* parent = 0);
|
||||
virtual ~LoggedProcess();
|
||||
|
||||
State state() const;
|
||||
int exitCode() const;
|
||||
qint64 processId() const;
|
||||
|
||||
void setDetachable(bool detachable);
|
||||
|
||||
signals:
|
||||
void log(QStringList lines, MessageLevel::Enum level);
|
||||
void stateChanged(LoggedProcess::State state);
|
||||
@@ -73,4 +76,5 @@ private:
|
||||
State m_state = NotRunning;
|
||||
int m_exit_code = 0;
|
||||
bool m_is_aborting = false;
|
||||
bool m_is_detachable = false;
|
||||
};
|
||||
@@ -7,16 +7,13 @@ public:
|
||||
NullInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir)
|
||||
:BaseInstance(globalSettings, settings, rootDir)
|
||||
{
|
||||
setFlag(BaseInstance::VersionBrokenFlag);
|
||||
setVersionBroken(true);
|
||||
}
|
||||
virtual ~NullInstance() {};
|
||||
virtual bool setIntendedVersionId(QString) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void cleanupAfterRun() override
|
||||
{
|
||||
}
|
||||
virtual QString currentVersionId() const override
|
||||
{
|
||||
return "Null";
|
||||
@@ -48,7 +45,7 @@ public:
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
virtual std::shared_ptr< Task > createUpdateTask() override
|
||||
virtual shared_qobject_ptr< Task > createUpdateTask() override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -83,4 +80,14 @@ public:
|
||||
{
|
||||
return "Null";
|
||||
}
|
||||
bool canExport() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QStringList verboseDescription(AuthSessionPtr session) override
|
||||
{
|
||||
QStringList out;
|
||||
out << "Null instance - placeholder.";
|
||||
return out;
|
||||
}
|
||||
};
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
|
||||
namespace details
|
||||
{
|
||||
@@ -48,6 +49,10 @@ public:
|
||||
using namespace std::placeholders;
|
||||
m_ptr.reset(wrap, std::bind(&QObject::deleteLater, _1));
|
||||
}
|
||||
void reset(const shared_qobject_ptr<T> &other)
|
||||
{
|
||||
m_ptr = other.m_ptr;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
m_ptr.reset();
|
||||
58
api/logic/Usable.h
Normal file
58
api/logic/Usable.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
class Usable;
|
||||
|
||||
/**
|
||||
* Base class for things that can be used by multiple other things and we want to track the use count.
|
||||
*
|
||||
* @see UseLock
|
||||
*/
|
||||
class Usable
|
||||
{
|
||||
friend class UseLock;
|
||||
public:
|
||||
std::size_t useCount()
|
||||
{
|
||||
return m_useCount;
|
||||
}
|
||||
bool isInUse()
|
||||
{
|
||||
return m_useCount > 0;
|
||||
}
|
||||
protected:
|
||||
virtual void decrementUses()
|
||||
{
|
||||
m_useCount--;
|
||||
}
|
||||
virtual void incrementUses()
|
||||
{
|
||||
m_useCount++;
|
||||
}
|
||||
private:
|
||||
std::size_t m_useCount = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lock class to use for keeping track of uses of other things derived from Usable
|
||||
*
|
||||
* @see Usable
|
||||
*/
|
||||
class UseLock
|
||||
{
|
||||
public:
|
||||
UseLock(std::shared_ptr<Usable> usable)
|
||||
: m_usable(usable)
|
||||
{
|
||||
// this doesn't use shared pointer use count, because that wouldn't be correct. this count is separate.
|
||||
m_usable->incrementUses();
|
||||
}
|
||||
~UseLock()
|
||||
{
|
||||
m_usable->decrementUses();
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<Usable> m_usable;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -120,4 +120,4 @@ private slots:
|
||||
|
||||
QTEST_GUILESS_MAIN(ModUtilsTest)
|
||||
|
||||
#include "tst_modutils.moc"
|
||||
#include "Version_test.moc"
|
||||
7
api/logic/icons/IIconList.cpp
Normal file
7
api/logic/icons/IIconList.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "IIconList.h"
|
||||
|
||||
// blargh
|
||||
IIconList::~IIconList()
|
||||
{
|
||||
}
|
||||
|
||||
25
api/logic/icons/IIconList.h
Normal file
25
api/logic/icons/IIconList.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
enum IconType : unsigned
|
||||
{
|
||||
Builtin,
|
||||
Transient,
|
||||
FileBased,
|
||||
ICONS_TOTAL,
|
||||
ToBeDeleted
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT IIconList
|
||||
{
|
||||
public:
|
||||
virtual ~IIconList();
|
||||
virtual bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) = 0;
|
||||
virtual bool deleteIcon(const QString &key) = 0;
|
||||
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
|
||||
virtual bool iconFileExists(const QString &key) const = 0;
|
||||
virtual void installIcons(const QStringList &iconFiles) = 0;
|
||||
};
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QMap>
|
||||
#include <QTemporaryFile>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -81,13 +80,14 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
result.id = m_id;
|
||||
}
|
||||
result.errorLog = m_stderr;
|
||||
result.outLog = m_stdout;
|
||||
qDebug() << "STDOUT" << m_stdout;
|
||||
qWarning() << "STDERR" << m_stderr;
|
||||
qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
|
||||
|
||||
if (status == QProcess::CrashExit || exitcode == 1)
|
||||
{
|
||||
qDebug() << "Java checker failed!";
|
||||
result.validity = JavaCheckResult::Validity::Errored;
|
||||
emit checkFinished(result);
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
|
||||
if(!results.contains("os.arch") || !results.contains("java.version") || !success)
|
||||
{
|
||||
qDebug() << "Java checker failed - couldn't extract required information.";
|
||||
result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
|
||||
emit checkFinished(result);
|
||||
return;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
bool is_64 = os_arch == "x86_64" || os_arch == "amd64";
|
||||
|
||||
|
||||
result.valid = true;
|
||||
result.validity = JavaCheckResult::Validity::Valid;
|
||||
result.is_64bit = is_64;
|
||||
result.mojangPlatform = is_64 ? "64" : "32";
|
||||
result.realPlatform = os_arch;
|
||||
@@ -15,10 +15,16 @@ struct MULTIMC_LOGIC_EXPORT JavaCheckResult
|
||||
QString mojangPlatform;
|
||||
QString realPlatform;
|
||||
JavaVersion javaVersion;
|
||||
QString outLog;
|
||||
QString errorLog;
|
||||
bool valid = false;
|
||||
bool is_64bit = false;
|
||||
int id;
|
||||
enum class Validity
|
||||
{
|
||||
Errored,
|
||||
ReturnedInvalidData,
|
||||
Valid
|
||||
} validity = Validity::Errored;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<QProcess> QProcessPtr;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtNetwork>
|
||||
#include <QLabel>
|
||||
#include "JavaChecker.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,7 +77,7 @@ QVariant JavaInstallList::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
}
|
||||
|
||||
BaseVersionList::RoleList JavaInstallList::providesRoles()
|
||||
BaseVersionList::RoleList JavaInstallList::providesRoles() const
|
||||
{
|
||||
return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole};
|
||||
}
|
||||
@@ -156,7 +156,7 @@ void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results)
|
||||
qDebug() << "Found the following valid Java installations:";
|
||||
for(JavaCheckResult result : results)
|
||||
{
|
||||
if(result.valid)
|
||||
if(result.validity == JavaCheckResult::Validity::Valid)
|
||||
{
|
||||
JavaInstallPtr javaVersion(new JavaInstall());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
virtual void sortVersions() override;
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||
virtual RoleList providesRoles() override;
|
||||
virtual RoleList providesRoles() const override;
|
||||
|
||||
public slots:
|
||||
virtual void updateListData(QList<BaseVersionPtr> versions) override;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,7 +47,11 @@ JavaInstallPtr JavaUtils::GetDefaultJava()
|
||||
|
||||
javaVersion->id = "java";
|
||||
javaVersion->arch = "unknown";
|
||||
#if defined(Q_OS_WIN32)
|
||||
javaVersion->path = "javaw";
|
||||
#else
|
||||
javaVersion->path = "java";
|
||||
#endif
|
||||
|
||||
return javaVersion;
|
||||
}
|
||||
@@ -150,10 +154,12 @@ QList<QString> JavaUtils::FindJavaPaths()
|
||||
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
|
||||
|
||||
java_candidates.append(JRE64s);
|
||||
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/jre6/bin/javaw.exe"));
|
||||
java_candidates.append(JDK64s);
|
||||
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/jre7/bin/javaw.exe"));
|
||||
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
|
||||
java_candidates.append(JDK32s);
|
||||
@@ -201,9 +207,36 @@ QList<QString> JavaUtils::FindJavaPaths()
|
||||
|
||||
QList<QString> javas;
|
||||
javas.append(this->GetDefaultJava()->path);
|
||||
javas.append("/opt/java/bin/java");
|
||||
javas.append("/usr/bin/java");
|
||||
auto scanJavaDir = [&](const QString & dirPath)
|
||||
{
|
||||
QDir dir(dirPath);
|
||||
if(!dir.exists())
|
||||
return;
|
||||
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||
for(auto & entry: entries)
|
||||
{
|
||||
|
||||
QString prefix;
|
||||
if(entry.isAbsolute())
|
||||
{
|
||||
prefix = entry.absoluteFilePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = entry.filePath();
|
||||
}
|
||||
|
||||
javas.append(FS::PathCombine(prefix, "jre/bin/java"));
|
||||
javas.append(FS::PathCombine(prefix, "bin/java"));
|
||||
}
|
||||
};
|
||||
// oracle RPMs
|
||||
scanJavaDir("/usr/java");
|
||||
// general locations used by distro packaging
|
||||
scanJavaDir("/usr/lib/jvm");
|
||||
scanJavaDir("/usr/lib32/jvm");
|
||||
// javas stored in MultiMC's folder
|
||||
scanJavaDir("java");
|
||||
return javas;
|
||||
}
|
||||
#else
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QStringList>
|
||||
#include <QWidget>
|
||||
|
||||
#include "JavaCheckerJob.h"
|
||||
#include "JavaChecker.h"
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
|
||||
{
|
||||
string = javaVersionString;
|
||||
m_string = javaVersionString;
|
||||
|
||||
auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int
|
||||
{
|
||||
@@ -28,12 +28,12 @@ JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
|
||||
pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
||||
}
|
||||
|
||||
auto match = pattern.match(string);
|
||||
parseable = match.hasMatch();
|
||||
major = getCapturedInteger(match, "major");
|
||||
minor = getCapturedInteger(match, "minor");
|
||||
security = getCapturedInteger(match, "security");
|
||||
prerelease = match.captured("prerelease");
|
||||
auto match = pattern.match(m_string);
|
||||
m_parseable = match.hasMatch();
|
||||
m_major = getCapturedInteger(match, "major");
|
||||
m_minor = getCapturedInteger(match, "minor");
|
||||
m_security = getCapturedInteger(match, "security");
|
||||
m_prerelease = match.captured("prerelease");
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -44,38 +44,38 @@ JavaVersion::JavaVersion(const QString &rhs)
|
||||
|
||||
QString JavaVersion::toString()
|
||||
{
|
||||
return string;
|
||||
return m_string;
|
||||
}
|
||||
|
||||
bool JavaVersion::requiresPermGen()
|
||||
{
|
||||
if(parseable)
|
||||
if(m_parseable)
|
||||
{
|
||||
return major < 8;
|
||||
return m_major < 8;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JavaVersion::operator<(const JavaVersion &rhs)
|
||||
{
|
||||
if(parseable && rhs.parseable)
|
||||
if(m_parseable && rhs.m_parseable)
|
||||
{
|
||||
if(major < rhs.major)
|
||||
if(m_major < rhs.m_major)
|
||||
return true;
|
||||
if(major > rhs.major)
|
||||
if(m_major > rhs.m_major)
|
||||
return false;
|
||||
if(minor < rhs.minor)
|
||||
if(m_minor < rhs.m_minor)
|
||||
return true;
|
||||
if(minor > rhs.minor)
|
||||
if(m_minor > rhs.m_minor)
|
||||
return false;
|
||||
if(security < rhs.security)
|
||||
if(m_security < rhs.m_security)
|
||||
return true;
|
||||
if(security > rhs.security)
|
||||
if(m_security > rhs.m_security)
|
||||
return false;
|
||||
|
||||
// everything else being equal, consider prerelease status
|
||||
bool thisPre = !prerelease.isEmpty();
|
||||
bool rhsPre = !rhs.prerelease.isEmpty();
|
||||
bool thisPre = !m_prerelease.isEmpty();
|
||||
bool rhsPre = !rhs.m_prerelease.isEmpty();
|
||||
if(thisPre && !rhsPre)
|
||||
{
|
||||
// this is a prerelease and the other one isn't -> lesser
|
||||
@@ -89,21 +89,21 @@ bool JavaVersion::operator<(const JavaVersion &rhs)
|
||||
else if(thisPre && rhsPre)
|
||||
{
|
||||
// both are prereleases - use natural compare...
|
||||
return Strings::naturalCompare(prerelease, rhs.prerelease, Qt::CaseSensitive) < 0;
|
||||
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(string, rhs.string, Qt::CaseSensitive) < 0;
|
||||
else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
|
||||
}
|
||||
|
||||
bool JavaVersion::operator==(const JavaVersion &rhs)
|
||||
{
|
||||
if(parseable && rhs.parseable)
|
||||
if(m_parseable && rhs.m_parseable)
|
||||
{
|
||||
return major == rhs.major && minor == rhs.minor && security == rhs.security && prerelease == rhs.prerelease;
|
||||
return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
|
||||
}
|
||||
return string == rhs.string;
|
||||
return m_string == rhs.m_string;
|
||||
}
|
||||
|
||||
bool JavaVersion::operator>(const JavaVersion &rhs)
|
||||
@@ -20,11 +20,23 @@ public:
|
||||
|
||||
QString toString();
|
||||
|
||||
int major()
|
||||
{
|
||||
return m_major;
|
||||
}
|
||||
int minor()
|
||||
{
|
||||
return m_minor;
|
||||
}
|
||||
int security()
|
||||
{
|
||||
return m_security;
|
||||
}
|
||||
private:
|
||||
QString string;
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int security = 0;
|
||||
bool parseable = false;
|
||||
QString prerelease;
|
||||
QString m_string;
|
||||
int m_major = 0;
|
||||
int m_minor = 0;
|
||||
int m_security = 0;
|
||||
bool m_parseable = false;
|
||||
QString m_prerelease;
|
||||
};
|
||||
@@ -34,12 +34,12 @@ slots:
|
||||
QFETCH(QString, prerelease);
|
||||
|
||||
JavaVersion test(string);
|
||||
QCOMPARE(test.string, string);
|
||||
QCOMPARE(test.m_string, string);
|
||||
QCOMPARE(test.toString(), string);
|
||||
QCOMPARE(test.major, major);
|
||||
QCOMPARE(test.minor, minor);
|
||||
QCOMPARE(test.security, security);
|
||||
QCOMPARE(test.prerelease, prerelease);
|
||||
QCOMPARE(test.m_major, major);
|
||||
QCOMPARE(test.m_minor, minor);
|
||||
QCOMPARE(test.m_security, security);
|
||||
QCOMPARE(test.m_prerelease, prerelease);
|
||||
}
|
||||
|
||||
void test_Sort_data()
|
||||
@@ -113,8 +113,4 @@ slots:
|
||||
|
||||
QTEST_GUILESS_MAIN(JavaVersionTest)
|
||||
|
||||
#include "tst_JavaVersion.moc"
|
||||
|
||||
|
||||
// manual testing fakery
|
||||
|
||||
#include "JavaVersion_test.moc"
|
||||
136
api/logic/java/launch/CheckJava.cpp
Normal file
136
api/logic/java/launch/CheckJava.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "CheckJava.h"
|
||||
#include <launch/LaunchTask.h>
|
||||
#include <FileSystem.h>
|
||||
#include <QStandardPaths>
|
||||
#include <QFileInfo>
|
||||
#include <sys.h>
|
||||
|
||||
void CheckJava::executeTask()
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
auto settings = instance->settings();
|
||||
m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString());
|
||||
bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
|
||||
|
||||
auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
|
||||
if (realJavaPath.isEmpty())
|
||||
{
|
||||
if (perInstance)
|
||||
{
|
||||
emit logLine(
|
||||
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),
|
||||
MessageLevel::Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit logLine(tr("The java binary \"%1\" couldn't be found. Please set up java in "
|
||||
"the settings.").arg(m_javaPath),
|
||||
MessageLevel::Warning);
|
||||
}
|
||||
emitFailed(tr("Java path is not valid."));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::MultiMC);
|
||||
}
|
||||
|
||||
QFileInfo javaInfo(realJavaPath);
|
||||
qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
|
||||
auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
|
||||
auto storedArchitecture = settings->get("JavaArchitecture").toString();
|
||||
auto storedVersion = settings->get("JavaVersion").toString();
|
||||
m_javaUnixTime = javaUnixTime;
|
||||
// if timestamps are not the same, or something is missing, check!
|
||||
if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0)
|
||||
{
|
||||
m_JavaChecker = std::make_shared<JavaChecker>();
|
||||
emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC);
|
||||
connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
|
||||
m_JavaChecker->m_path = realJavaPath;
|
||||
m_JavaChecker->performCheck();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto verString = instance->settings()->get("JavaVersion").toString();
|
||||
auto archString = instance->settings()->get("JavaArchitecture").toString();
|
||||
printJavaInfo(verString, archString);
|
||||
}
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void CheckJava::checkJavaFinished(JavaCheckResult result)
|
||||
{
|
||||
switch (result.validity)
|
||||
{
|
||||
case JavaCheckResult::Validity::Errored:
|
||||
{
|
||||
// Error message displayed if java can't start
|
||||
emit logLine(tr("Could not start java:"), MessageLevel::Error);
|
||||
emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
|
||||
emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
|
||||
printSystemInfo(false, false);
|
||||
emitFailed(tr("Could not start java!"));
|
||||
return;
|
||||
}
|
||||
case JavaCheckResult::Validity::ReturnedInvalidData:
|
||||
{
|
||||
emit logLine(tr("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
|
||||
emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
|
||||
emit logLine("\nMinecraft might not start properly.", MessageLevel::MultiMC);
|
||||
printSystemInfo(false, false);
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
case JavaCheckResult::Validity::Valid:
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
printJavaInfo(result.javaVersion.toString(), result.mojangPlatform);
|
||||
instance->settings()->set("JavaVersion", result.javaVersion.toString());
|
||||
instance->settings()->set("JavaArchitecture", result.mojangPlatform);
|
||||
instance->settings()->set("JavaTimestamp", m_javaUnixTime);
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
printSystemInfo(true, architecture == "64");
|
||||
}
|
||||
|
||||
void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit)
|
||||
{
|
||||
auto cpu64 = Sys::isCPU64bit();
|
||||
auto system64 = Sys::isSystem64bit();
|
||||
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);
|
||||
}
|
||||
if(javaIsKnown)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <launch/LoggedProcess.h>
|
||||
#include <LoggedProcess.h>
|
||||
#include <java/JavaChecker.h>
|
||||
|
||||
class CheckJava: public LaunchStep
|
||||
@@ -34,6 +34,10 @@ public:
|
||||
private slots:
|
||||
void checkJavaFinished(JavaCheckResult result);
|
||||
|
||||
private:
|
||||
void printJavaInfo(const QString & version, const QString & architecture);
|
||||
void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
|
||||
|
||||
private:
|
||||
QString m_javaPath;
|
||||
qlonglong m_javaUnixTime;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,6 +42,8 @@ signals:
|
||||
|
||||
public slots:
|
||||
virtual void proceed() {};
|
||||
// called in the opposite order than the Task launch(), used to clean up or otherwise undo things after the launch ends
|
||||
virtual void finalize() {};
|
||||
|
||||
protected: /* data */
|
||||
LaunchTask *m_parent;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||
*
|
||||
@@ -56,6 +56,7 @@ void LaunchTask::prependStep(std::shared_ptr<LaunchStep> step)
|
||||
|
||||
void LaunchTask::executeTask()
|
||||
{
|
||||
m_instance->setCrashed(false);
|
||||
if(!m_steps.size())
|
||||
{
|
||||
state = LaunchTask::Finished;
|
||||
@@ -87,7 +88,7 @@ void LaunchTask::onStepFinished()
|
||||
// end?
|
||||
if(currentStep == m_steps.size() - 1)
|
||||
{
|
||||
emitSucceeded();
|
||||
finalizeSteps(true, QString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -98,7 +99,23 @@ void LaunchTask::onStepFinished()
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(step->failReason());
|
||||
finalizeSteps(false, step->failReason());
|
||||
}
|
||||
}
|
||||
|
||||
void LaunchTask::finalizeSteps(bool successful, const QString& error)
|
||||
{
|
||||
for(auto step = currentStep; step >= 0; step--)
|
||||
{
|
||||
m_steps[step]->finalize();
|
||||
}
|
||||
if(successful)
|
||||
{
|
||||
emitSucceeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +150,26 @@ void LaunchTask::proceed()
|
||||
m_steps[currentStep]->proceed();
|
||||
}
|
||||
|
||||
bool LaunchTask::canAbort() const
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case LaunchTask::Aborted:
|
||||
case LaunchTask::Failed:
|
||||
case LaunchTask::Finished:
|
||||
return false;
|
||||
case LaunchTask::NotStarted:
|
||||
return true;
|
||||
case LaunchTask::Running:
|
||||
case LaunchTask::Waiting:
|
||||
{
|
||||
auto step = m_steps[currentStep];
|
||||
return step->canAbort();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LaunchTask::abort()
|
||||
{
|
||||
switch(state)
|
||||
@@ -167,6 +204,21 @@ bool LaunchTask::abort()
|
||||
return false;
|
||||
}
|
||||
|
||||
shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
|
||||
{
|
||||
if(!m_logModel)
|
||||
{
|
||||
m_logModel.reset(new LogModel());
|
||||
m_logModel->setMaxLines(m_instance->getConsoleMaxLines());
|
||||
m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
|
||||
// FIXME: should this really be here?
|
||||
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"
|
||||
" likely wasting harddrive space at an alarming rate!").arg(m_logModel->getMaxLines()));
|
||||
}
|
||||
return m_logModel;
|
||||
}
|
||||
|
||||
void LaunchTask::onLogLines(const QStringList &lines, MessageLevel::Enum defaultLevel)
|
||||
{
|
||||
for (auto & line: lines)
|
||||
@@ -193,20 +245,20 @@ void LaunchTask::onLogLine(QString line, MessageLevel::Enum level)
|
||||
// censor private user info
|
||||
line = censorPrivateInfo(line);
|
||||
|
||||
emit log(line, level);
|
||||
auto &model = *getLogModel();
|
||||
model.append(level, line);
|
||||
}
|
||||
|
||||
void LaunchTask::emitSucceeded()
|
||||
{
|
||||
m_instance->cleanupAfterRun();
|
||||
m_instance->setRunning(false);
|
||||
Task::emitSucceeded();
|
||||
}
|
||||
|
||||
void LaunchTask::emitFailed(QString reason)
|
||||
{
|
||||
m_instance->cleanupAfterRun();
|
||||
m_instance->setRunning(false);
|
||||
m_instance->setCrashed(true);
|
||||
Task::emitFailed(reason);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
||||
*
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <QProcess>
|
||||
#include <QObjectPtr.h>
|
||||
#include "LogModel.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "MessageLevel.h"
|
||||
#include "LoggedProcess.h"
|
||||
@@ -78,7 +80,11 @@ public: /* methods */
|
||||
/**
|
||||
* @brief abort launch
|
||||
*/
|
||||
virtual bool abort() override;
|
||||
bool abort() override;
|
||||
|
||||
bool canAbort() const override;
|
||||
|
||||
shared_qobject_ptr<LogModel> getLogModel();
|
||||
|
||||
public:
|
||||
QString substituteVariables(const QString &cmd) const;
|
||||
@@ -98,13 +104,6 @@ signals:
|
||||
|
||||
void requestLogging();
|
||||
|
||||
/**
|
||||
* @brief emitted when we want to log something
|
||||
* @param text the text to log
|
||||
* @param level the level to log at
|
||||
*/
|
||||
void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC);
|
||||
|
||||
public slots:
|
||||
void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
|
||||
void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
|
||||
@@ -112,8 +111,12 @@ public slots:
|
||||
void onStepFinished();
|
||||
void onProgressReportingRequested();
|
||||
|
||||
private: /*methods */
|
||||
void finalizeSteps(bool successful, const QString & error);
|
||||
|
||||
protected: /* data */
|
||||
InstancePtr m_instance;
|
||||
shared_qobject_ptr<LogModel> m_logModel;
|
||||
QList <std::shared_ptr<LaunchStep>> m_steps;
|
||||
QMap<QString, QString> m_censorFilter;
|
||||
int currentStep = -1;
|
||||
149
api/logic/launch/LogModel.cpp
Normal file
149
api/logic/launch/LogModel.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
#include "LogModel.h"
|
||||
|
||||
LogModel::LogModel(QObject *parent):QAbstractListModel(parent)
|
||||
{
|
||||
m_content.resize(m_maxLines);
|
||||
}
|
||||
|
||||
int LogModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_numLines;
|
||||
}
|
||||
|
||||
QVariant LogModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_numLines)
|
||||
return QVariant();
|
||||
|
||||
auto row = index.row();
|
||||
auto realRow = (row + m_firstLine) % m_maxLines;
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||
{
|
||||
return m_content[realRow].line;
|
||||
}
|
||||
if(role == LevelRole)
|
||||
{
|
||||
return m_content[realRow].level;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void LogModel::append(MessageLevel::Enum level, QString line)
|
||||
{
|
||||
if(m_suspended)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int lineNum = (m_firstLine + m_numLines) % m_maxLines;
|
||||
// overflow
|
||||
if(m_numLines == m_maxLines)
|
||||
{
|
||||
if(m_stopOnOverflow)
|
||||
{
|
||||
// nothing more to do, the buffer is full
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), 0, 0);
|
||||
m_firstLine = (m_firstLine + 1) % m_maxLines;
|
||||
m_numLines --;
|
||||
endRemoveRows();
|
||||
}
|
||||
else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow)
|
||||
{
|
||||
level = MessageLevel::Fatal;
|
||||
line = m_overflowMessage;
|
||||
}
|
||||
beginInsertRows(QModelIndex(), m_numLines, m_numLines);
|
||||
m_numLines ++;
|
||||
m_content[lineNum].level = level;
|
||||
m_content[lineNum].line = line;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void LogModel::suspend(bool suspend)
|
||||
{
|
||||
m_suspended = suspend;
|
||||
}
|
||||
|
||||
void LogModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
m_firstLine = 0;
|
||||
m_numLines = 0;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QString LogModel::toPlainText()
|
||||
{
|
||||
QString out;
|
||||
out.reserve(m_numLines * 80);
|
||||
for(int i = 0; i < m_numLines; i++)
|
||||
{
|
||||
QString & line = m_content[(m_firstLine + i) % m_maxLines].line;
|
||||
out.append(line + '\n');
|
||||
}
|
||||
out.squeeze();
|
||||
return out;
|
||||
}
|
||||
|
||||
void LogModel::setMaxLines(int maxLines)
|
||||
{
|
||||
// no-op
|
||||
if(maxLines == m_maxLines)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// if it all still fits in the buffer, just resize it
|
||||
if(m_firstLine + m_numLines < m_maxLines)
|
||||
{
|
||||
m_maxLines = maxLines;
|
||||
m_content.resize(maxLines);
|
||||
return;
|
||||
}
|
||||
// otherwise, we need to reorganize the data because it crosses the wrap boundary
|
||||
QVector<entry> newContent;
|
||||
newContent.resize(maxLines);
|
||||
if(m_numLines <= maxLines)
|
||||
{
|
||||
// if it all fits in the new buffer, just copy it over
|
||||
for(int i = 0; i < m_numLines; i++)
|
||||
{
|
||||
newContent[i] = m_content[(m_firstLine + i) % m_maxLines];
|
||||
}
|
||||
m_content.swap(newContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if it doesn't fit, part of the data needs to be thrown away (the oldest log messages)
|
||||
int lead = m_numLines - maxLines;
|
||||
beginRemoveRows(QModelIndex(), 0, lead - 1);
|
||||
for(int i = 0; i < maxLines; i++)
|
||||
{
|
||||
newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines];
|
||||
}
|
||||
m_numLines = m_maxLines;
|
||||
m_content.swap(newContent);
|
||||
endRemoveRows();
|
||||
}
|
||||
m_firstLine = 0;
|
||||
m_maxLines = maxLines;
|
||||
}
|
||||
|
||||
int LogModel::getMaxLines()
|
||||
{
|
||||
return m_maxLines;
|
||||
}
|
||||
|
||||
void LogModel::setStopOnOverflow(bool stop)
|
||||
{
|
||||
m_stopOnOverflow = stop;
|
||||
}
|
||||
|
||||
void LogModel::setOverflowMessage(const QString& overflowMessage)
|
||||
{
|
||||
m_overflowMessage = overflowMessage;
|
||||
}
|
||||
54
api/logic/launch/LogModel.h
Normal file
54
api/logic/launch/LogModel.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QString>
|
||||
#include "MessageLevel.h"
|
||||
|
||||
#include <multimc_logic_export.h>
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT LogModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogModel(QObject *parent = 0);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
|
||||
void append(MessageLevel::Enum, QString line);
|
||||
void clear();
|
||||
void suspend(bool suspend);
|
||||
|
||||
QString toPlainText();
|
||||
|
||||
int getMaxLines();
|
||||
void setMaxLines(int maxLines);
|
||||
void setStopOnOverflow(bool stop);
|
||||
void setOverflowMessage(const QString & overflowMessage);
|
||||
|
||||
enum Roles
|
||||
{
|
||||
LevelRole = Qt::UserRole
|
||||
};
|
||||
|
||||
private /* types */:
|
||||
struct entry
|
||||
{
|
||||
MessageLevel::Enum level;
|
||||
QString line;
|
||||
};
|
||||
|
||||
private: /* data */
|
||||
QVector <entry> m_content;
|
||||
int m_maxLines = 1000;
|
||||
// first line in the circular buffer
|
||||
int m_firstLine = 0;
|
||||
// number of lines occupied in the circular buffer
|
||||
int m_numLines = 0;
|
||||
bool m_stopOnOverflow = false;
|
||||
QString m_overflowMessage = "OVERFLOW";
|
||||
bool m_suspended = false;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(LogModel)
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,20 +34,34 @@ void PostLaunchCommand::executeTask()
|
||||
|
||||
void PostLaunchCommand::on_state(LoggedProcess::State state)
|
||||
{
|
||||
auto getError = [&]()
|
||||
{
|
||||
return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
|
||||
};
|
||||
switch(state)
|
||||
{
|
||||
case LoggedProcess::Aborted:
|
||||
case LoggedProcess::Crashed:
|
||||
case LoggedProcess::FailedToStart:
|
||||
{
|
||||
QString error = tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
|
||||
emit logLine(error, MessageLevel::Error);
|
||||
auto error = getError();
|
||||
emit logLine(error, MessageLevel::Fatal);
|
||||
emitFailed(error);
|
||||
return;
|
||||
}
|
||||
case LoggedProcess::Finished:
|
||||
{
|
||||
emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
|
||||
emitSucceeded();
|
||||
if(m_process.exitCode() != 0)
|
||||
{
|
||||
auto error = getError();
|
||||
emit logLine(error, MessageLevel::Fatal);
|
||||
emitFailed(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
|
||||
emitSucceeded();
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <launch/LoggedProcess.h>
|
||||
#include <LoggedProcess.h>
|
||||
|
||||
class PostLaunchCommand: public LaunchStep
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,21 +35,34 @@ void PreLaunchCommand::executeTask()
|
||||
|
||||
void PreLaunchCommand::on_state(LoggedProcess::State state)
|
||||
{
|
||||
auto getError = [&]()
|
||||
{
|
||||
return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
|
||||
};
|
||||
switch(state)
|
||||
{
|
||||
case LoggedProcess::Aborted:
|
||||
case LoggedProcess::Crashed:
|
||||
case LoggedProcess::FailedToStart:
|
||||
{
|
||||
QString error = tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
|
||||
auto error = getError();
|
||||
emit logLine(error, MessageLevel::Fatal);
|
||||
emitFailed(error);
|
||||
return;
|
||||
}
|
||||
case LoggedProcess::Finished:
|
||||
{
|
||||
emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
|
||||
emitSucceeded();
|
||||
if(m_process.exitCode() != 0)
|
||||
{
|
||||
auto error = getError();
|
||||
emit logLine(error, MessageLevel::Fatal);
|
||||
emitFailed(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
|
||||
emitSucceeded();
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <launch/LoggedProcess.h>
|
||||
#include "launch/LaunchStep.h"
|
||||
#include "LoggedProcess.h"
|
||||
|
||||
class PreLaunchCommand: public LaunchStep
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <launch/LoggedProcess.h>
|
||||
#include <LoggedProcess.h>
|
||||
#include <java/JavaChecker.h>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2013-2015 MultiMC Contributors
|
||||
/* Copyright 2013-2017 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,12 @@
|
||||
|
||||
void Update::executeTask()
|
||||
{
|
||||
m_updateTask = m_parent->instance()->createUpdateTask();
|
||||
if(m_aborted)
|
||||
{
|
||||
emitFailed(tr("Task aborted."));
|
||||
return;
|
||||
}
|
||||
m_updateTask.reset(m_parent->instance()->createUpdateTask());
|
||||
if(m_updateTask)
|
||||
{
|
||||
connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
|
||||
@@ -39,12 +44,37 @@ void Update::updateFinished()
|
||||
{
|
||||
if(m_updateTask->successful())
|
||||
{
|
||||
m_updateTask.reset();
|
||||
emitSucceeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString reason = tr("Instance update failed because: %1.\n\n").arg(m_updateTask->failReason());
|
||||
m_updateTask.reset();
|
||||
emit logLine(reason, MessageLevel::Fatal);
|
||||
emitFailed(reason);
|
||||
}
|
||||
}
|
||||
|
||||
bool Update::canAbort() const
|
||||
{
|
||||
if(m_updateTask)
|
||||
{
|
||||
return m_updateTask->canAbort();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Update::abort()
|
||||
{
|
||||
m_aborted = true;
|
||||
if(m_updateTask)
|
||||
{
|
||||
if(m_updateTask->canAbort())
|
||||
{
|
||||
return m_updateTask->abort();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user