diff --git a/.arcconfig b/.arcconfig
index 0e628a13..ab5cbe89 100644
--- a/.arcconfig
+++ b/.arcconfig
@@ -1,5 +1,5 @@
{
- "project_id": "MultiMC5",
- "conduit_uri": "http://ph.multimc.org"
+ "project_id": "MultiMC5",
+ "conduit_uri": "http://ph.multimc.org"
}
diff --git a/.clang-format b/.clang-format
index 8e33c4d1..f4732803 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,4 +1,4 @@
-UseTab: true
+UseTab: false
IndentWidth: 4
TabWidth: 4
ConstructorInitializerIndentWidth: 4
diff --git a/.gitmodules b/.gitmodules
index 5f2a1b8f..bd51ef80 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,6 @@
[submodule "depends/libnbtplusplus"]
- path = libraries/libnbtplusplus
- url = https://github.com/MultiMC/libnbtplusplus.git
+ path = libraries/libnbtplusplus
+ url = https://github.com/MultiMC/libnbtplusplus.git
[submodule "libraries/quazip"]
- path = libraries/quazip
- url = https://github.com/MultiMC/quazip.git
+ path = libraries/quazip
+ url = https://github.com/MultiMC/quazip.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 33a53da0..bfc9527a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.1)
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BUILD_DIR}" IS_IN_SOURCE_BUILD)
if(IS_IN_SOURCE_BUILD)
- message(AUTHOR_WARNING "You are building MultiMC in-source. This is NOT recommended!")
+ message(AUTHOR_WARNING "You are building MultiMC in-source. This is NOT recommended!")
endif()
if(WIN32)
- # In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
- cmake_policy(SET CMP0020 OLD)
+ # In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
+ cmake_policy(SET CMP0020 OLD)
endif()
project(MultiMC)
@@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
# Output all executables and shared libs in the main build folder, not in subfolders.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
if(UNIX)
- set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
@@ -34,7 +34,7 @@ set(CMAKE_C_STANDARD 11)
include(GenerateExportHeader)
set(CMAKE_CXX_FLAGS " -Wall -pedantic -Werror -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong --param=ssp-buffer-size=4 -O3 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS}")
if(UNIX AND APPLE)
- set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
+ set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror=return-type")
@@ -108,124 +108,124 @@ set(MultiMC_LAYOUT "auto" CACHE STRING "The layout for MultiMC installation (aut
set_property(CACHE MultiMC_LAYOUT PROPERTY STRINGS auto win-bundle lin-bundle lin-nodeps lin-system mac-bundle)
if(MultiMC_LAYOUT STREQUAL "auto")
- if(UNIX AND APPLE)
- set(MultiMC_LAYOUT_REAL "mac-bundle")
- elseif(UNIX)
- set(MultiMC_LAYOUT_REAL "lin-nodeps")
- elseif(WIN32)
- set(MultiMC_LAYOUT_REAL "win-bundle")
- else()
- message(FATAL_ERROR "Cannot choose a sensible install layout for your platform.")
- endif()
+ if(UNIX AND APPLE)
+ set(MultiMC_LAYOUT_REAL "mac-bundle")
+ elseif(UNIX)
+ set(MultiMC_LAYOUT_REAL "lin-nodeps")
+ elseif(WIN32)
+ set(MultiMC_LAYOUT_REAL "win-bundle")
+ else()
+ message(FATAL_ERROR "Cannot choose a sensible install layout for your platform.")
+ endif()
else()
- set(MultiMC_LAYOUT_REAL ${MultiMC_LAYOUT})
+ set(MultiMC_LAYOUT_REAL ${MultiMC_LAYOUT})
endif()
if(MultiMC_LAYOUT_REAL STREQUAL "mac-bundle")
- set(BINARY_DEST_DIR "MultiMC.app/Contents/MacOS")
- set(LIBRARY_DEST_DIR "MultiMC.app/Contents/MacOS")
- set(PLUGIN_DEST_DIR "MultiMC.app/Contents/MacOS")
- set(RESOURCES_DEST_DIR "MultiMC.app/Contents/Resources")
- set(JARS_DEST_DIR "MultiMC.app/Contents/MacOS/jars")
+ set(BINARY_DEST_DIR "MultiMC.app/Contents/MacOS")
+ set(LIBRARY_DEST_DIR "MultiMC.app/Contents/MacOS")
+ set(PLUGIN_DEST_DIR "MultiMC.app/Contents/MacOS")
+ set(RESOURCES_DEST_DIR "MultiMC.app/Contents/Resources")
+ set(JARS_DEST_DIR "MultiMC.app/Contents/MacOS/jars")
- set(BUNDLE_DEST_DIR ".")
+ set(BUNDLE_DEST_DIR ".")
- # Apps to bundle
- set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.app")
+ # Apps to bundle
+ set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.app")
- # Mac bundle settings
- set(MACOSX_BUNDLE_BUNDLE_NAME "MultiMC")
- set(MACOSX_BUNDLE_INFO_STRING "MultiMC Minecraft launcher and management utility.")
- set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.MultiMC5")
- set(MACOSX_BUNDLE_BUNDLE_VERSION "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
- set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
- set(MACOSX_BUNDLE_LONG_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
- set(MACOSX_BUNDLE_ICON_FILE MultiMC.icns)
- set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2015-2018 MultiMC Contributors")
+ # Mac bundle settings
+ set(MACOSX_BUNDLE_BUNDLE_NAME "MultiMC")
+ set(MACOSX_BUNDLE_INFO_STRING "MultiMC Minecraft launcher and management utility.")
+ set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.MultiMC5")
+ set(MACOSX_BUNDLE_BUNDLE_VERSION "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
+ set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
+ set(MACOSX_BUNDLE_LONG_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_HOTFIX}.${MultiMC_VERSION_BUILD}")
+ set(MACOSX_BUNDLE_ICON_FILE MultiMC.icns)
+ set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2015-2018 MultiMC Contributors")
- # directories to look for dependencies
- set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+ # directories to look for dependencies
+ set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
- # install as bundle
- set(INSTALL_BUNDLE "full")
+ # install as bundle
+ set(INSTALL_BUNDLE "full")
- # Add the icon
- install(FILES application/resources/MultiMC.icns DESTINATION ${RESOURCES_DEST_DIR})
+ # Add the icon
+ install(FILES application/resources/MultiMC.icns DESTINATION ${RESOURCES_DEST_DIR})
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-bundle")
- set(BINARY_DEST_DIR "bin")
- set(LIBRARY_DEST_DIR "bin")
- set(PLUGIN_DEST_DIR "plugins")
- set(BUNDLE_DEST_DIR ".")
- set(RESOURCES_DEST_DIR ".")
- set(JARS_DEST_DIR "bin/jars")
+ set(BINARY_DEST_DIR "bin")
+ set(LIBRARY_DEST_DIR "bin")
+ set(PLUGIN_DEST_DIR "plugins")
+ set(BUNDLE_DEST_DIR ".")
+ set(RESOURCES_DEST_DIR ".")
+ set(JARS_DEST_DIR "bin/jars")
- # Apps to bundle
- set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/MultiMC")
+ # Apps to bundle
+ set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/MultiMC")
- # directories to look for dependencies
- set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+ # directories to look for dependencies
+ set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
- # install as bundle
- set(INSTALL_BUNDLE "full")
+ # install as bundle
+ set(INSTALL_BUNDLE "full")
- # Set RPATH
- SET(MultiMC_BINARY_RPATH "$ORIGIN/")
+ # Set RPATH
+ SET(MultiMC_BINARY_RPATH "$ORIGIN/")
- # Install basic runner script
- install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
+ # Install basic runner script
+ install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-nodeps")
- set(BINARY_DEST_DIR "bin")
- set(LIBRARY_DEST_DIR "bin")
- set(PLUGIN_DEST_DIR "plugins")
- set(BUNDLE_DEST_DIR ".")
- set(RESOURCES_DEST_DIR ".")
- set(JARS_DEST_DIR "bin/jars")
+ set(BINARY_DEST_DIR "bin")
+ set(LIBRARY_DEST_DIR "bin")
+ set(PLUGIN_DEST_DIR "plugins")
+ set(BUNDLE_DEST_DIR ".")
+ set(RESOURCES_DEST_DIR ".")
+ set(JARS_DEST_DIR "bin/jars")
- # install as bundle with no dependencies included
- set(INSTALL_BUNDLE "nodeps")
+ # install as bundle with no dependencies included
+ set(INSTALL_BUNDLE "nodeps")
- # Set RPATH
- SET(MultiMC_BINARY_RPATH "$ORIGIN/")
+ # Set RPATH
+ SET(MultiMC_BINARY_RPATH "$ORIGIN/")
- # Install basic runner script
- install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
+ # Install basic runner script
+ install(PROGRAMS application/package/linux/MultiMC DESTINATION ${BUNDLE_DEST_DIR})
elseif(MultiMC_LAYOUT_REAL STREQUAL "lin-system")
- set(MultiMC_APP_BINARY_NAME "multimc" CACHE STRING "Name of the MultiMC binary")
- set(MultiMC_BINARY_DEST_DIR "bin" CACHE STRING "Path to the binary directory")
- set(MultiMC_LIBRARY_DEST_DIR "lib${LIB_SUFFIX}" CACHE STRING "Path to the library directory")
- set(MultiMC_SHARE_DEST_DIR "share/multimc" CACHE STRING "Path to the shared data directory")
- set(JARS_DEST_DIR "${MultiMC_SHARE_DEST_DIR}/jars")
+ set(MultiMC_APP_BINARY_NAME "multimc" CACHE STRING "Name of the MultiMC binary")
+ set(MultiMC_BINARY_DEST_DIR "bin" CACHE STRING "Path to the binary directory")
+ set(MultiMC_LIBRARY_DEST_DIR "lib${LIB_SUFFIX}" CACHE STRING "Path to the library directory")
+ set(MultiMC_SHARE_DEST_DIR "share/multimc" CACHE STRING "Path to the shared data directory")
+ set(JARS_DEST_DIR "${MultiMC_SHARE_DEST_DIR}/jars")
- set(BINARY_DEST_DIR ${MultiMC_BINARY_DEST_DIR})
- set(LIBRARY_DEST_DIR ${MultiMC_LIBRARY_DEST_DIR})
+ set(BINARY_DEST_DIR ${MultiMC_BINARY_DEST_DIR})
+ set(LIBRARY_DEST_DIR ${MultiMC_LIBRARY_DEST_DIR})
- MESSAGE(STATUS "Compiling for linux system with ${MultiMC_SHARE_DEST_DIR} and MULTIMC_LINUX_DATADIR")
- SET(MultiMC_APP_BINARY_DEFS "-DMULTIMC_JARS_LOCATION=${CMAKE_INSTALL_PREFIX}/${JARS_DEST_DIR}" "-DMULTIMC_LINUX_DATADIR")
+ MESSAGE(STATUS "Compiling for linux system with ${MultiMC_SHARE_DEST_DIR} and MULTIMC_LINUX_DATADIR")
+ SET(MultiMC_APP_BINARY_DEFS "-DMULTIMC_JARS_LOCATION=${CMAKE_INSTALL_PREFIX}/${JARS_DEST_DIR}" "-DMULTIMC_LINUX_DATADIR")
- # install as bundle with no dependencies included
- set(INSTALL_BUNDLE "nodeps")
+ # install as bundle with no dependencies included
+ set(INSTALL_BUNDLE "nodeps")
elseif(MultiMC_LAYOUT_REAL STREQUAL "win-bundle")
- set(BINARY_DEST_DIR ".")
- set(LIBRARY_DEST_DIR ".")
- set(PLUGIN_DEST_DIR ".")
- set(BUNDLE_DEST_DIR ".")
- set(RESOURCES_DEST_DIR ".")
- set(JARS_DEST_DIR "jars")
+ set(BINARY_DEST_DIR ".")
+ set(LIBRARY_DEST_DIR ".")
+ set(PLUGIN_DEST_DIR ".")
+ set(BUNDLE_DEST_DIR ".")
+ set(RESOURCES_DEST_DIR ".")
+ set(JARS_DEST_DIR "jars")
- # Apps to bundle
- set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.exe")
+ # Apps to bundle
+ set(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.exe")
- # directories to look for dependencies
- set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+ # directories to look for dependencies
+ set(DIRS ${QT_LIBS_DIR} ${QT_LIBEXECS_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
- # install as bundle
- set(INSTALL_BUNDLE "full")
+ # install as bundle
+ set(INSTALL_BUNDLE "full")
else()
- message(FATAL_ERROR "No sensible install layout set.")
+ message(FATAL_ERROR "No sensible install layout set.")
endif()
################################ Included Libs ################################
diff --git a/COPYING.md b/COPYING.md
index ca367df3..21c773b7 100644
--- a/COPYING.md
+++ b/COPYING.md
@@ -1,254 +1,254 @@
# MultiMC
- Copyright 2012-2018 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
+ Copyright 2012-2018 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
+ 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.
+ 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.
# MinGW runtime (Windows)
- Copyright (c) 2012 MinGW.org project
+ Copyright (c) 2012 MinGW.org project
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
- The above copyright notice, this permission notice and the below disclaimer
- shall be included in all copies or substantial portions of the Software.
+ The above copyright notice, this permission notice and the below disclaimer
+ shall be included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
# Qt 5
- Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
- Contact: http://www.qt-project.org/legal
+ Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ Contact: http://www.qt-project.org/legal
- Licensed under LGPL v2.1
+ Licensed under LGPL v2.1
# libnbt++
- libnbt++ - A library for the Minecraft Named Binary Tag format.
- Copyright (C) 2013, 2015 ljfa-ag
+ libnbt++ - A library for the Minecraft Named Binary Tag format.
+ Copyright (C) 2013, 2015 ljfa-ag
- libnbt++ is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
+ libnbt++ is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- libnbt++ 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.
+ libnbt++ 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 libnbt++. If not, see .
+ You should have received a copy of the GNU Lesser General Public License
+ along with libnbt++. If not, see .
# rainbow (KGuiAddons)
- Copyright (C) 2007 Matthew Woehlke
- Copyright (C) 2007 Olaf Schmidt
- Copyright (C) 2007 Thomas Zander
- Copyright (C) 2007 Zack Rusin
- Copyright (C) 2015 Petr Mrazek
+ Copyright (C) 2007 Matthew Woehlke
+ Copyright (C) 2007 Olaf Schmidt
+ Copyright (C) 2007 Thomas Zander
+ Copyright (C) 2007 Zack Rusin
+ Copyright (C) 2015 Petr Mrazek
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 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
- Library General Public License for more details.
+ 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
+ Library General Public License for more details.
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
# Hoedown
- Copyright (c) 2008, Natacha Porté
- Copyright (c) 2011, Vicent Martí
- Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
+ Copyright (c) 2008, Natacha Porté
+ Copyright (c) 2011, Vicent Martí
+ Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
+ Permission to use, copy, modify, and distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Batch icon set
- You are free to use Batch (the "icon set") or any part thereof (the "icons")
- in any personal, open-source or commercial work without obligation of payment
- (monetary or otherwise) or attribution. Do not sell the icon set, host
- the icon set or rent the icon set (either in existing or modified form).
+ You are free to use Batch (the "icon set") or any part thereof (the "icons")
+ in any personal, open-source or commercial work without obligation of payment
+ (monetary or otherwise) or attribution. Do not sell the icon set, host
+ the icon set or rent the icon set (either in existing or modified form).
- While attribution is optional, it is always appreciated.
+ While attribution is optional, it is always appreciated.
- Intellectual property rights are not transferred with the download of the icons.
+ Intellectual property rights are not transferred with the download of the icons.
- EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL ADAM WHITCROFT
- BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL,
- PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THE USE OF THE ICONS,
- EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL ADAM WHITCROFT
+ BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL,
+ PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THE USE OF THE ICONS,
+ EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
# Material Design Icons
- Copyright (c) 2014, Austin Andrews (http://materialdesignicons.com/),
- with Reserved Font Name Material Design Icons.
- Copyright (c) 2014, Google (http://www.google.com/design/)
- uses the license at https://github.com/google/material-design-icons/blob/master/LICENSE
+ Copyright (c) 2014, Austin Andrews (http://materialdesignicons.com/),
+ with Reserved Font Name Material Design Icons.
+ Copyright (c) 2014, Google (http://www.google.com/design/)
+ uses the license at https://github.com/google/material-design-icons/blob/master/LICENSE
- This Font Software is licensed under the SIL Open Font License, Version 1.1.
- This license is copied below, and is also available with a FAQ at:
- http://scripts.sil.org/OFL
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
+ This license is copied below, and is also available with a FAQ at:
+ http://scripts.sil.org/OFL
# Pack200
- The GNU General Public License (GPL)
+ The GNU General Public License (GPL)
- Version 2, June 1991
+ Version 2, June 1991
- + "CLASSPATH" EXCEPTION TO THE GPL
+ + "CLASSPATH" EXCEPTION TO THE GPL
- Certain source files distributed by Oracle America and/or its affiliates are
- subject to the following clarification and special exception to the GPL, but
- only where Oracle has expressly included in the particular source file's header
- the words "Oracle designates this particular file as subject to the "Classpath"
- exception as provided by Oracle in the LICENSE file that accompanied this code."
+ Certain source files distributed by Oracle America and/or its affiliates are
+ subject to the following clarification and special exception to the GPL, but
+ only where Oracle has expressly included in the particular source file's header
+ the words "Oracle designates this particular file as subject to the "Classpath"
+ exception as provided by Oracle in the LICENSE file that accompanied this code."
- Linking this library statically or dynamically with other modules is making
- a combined work based on this library. Thus, the terms and conditions of
- the GNU General Public License cover the whole combination.
+ Linking this library statically or dynamically with other modules is making
+ a combined work based on this library. Thus, the terms and conditions of
+ the GNU General Public License cover the whole combination.
- As a special exception, the copyright holders of this library give you
- permission to link this library with independent modules to produce an
- executable, regardless of the license terms of these independent modules,
- and to copy and distribute the resulting executable under terms of your
- choice, provided that you also meet, for each linked independent module,
- the terms and conditions of the license of that module. An independent
- module is a module which is not derived from or based on this library. If
- you modify this library, you may extend this exception to your version of
- the library, but you are not obligated to do so. If you do not wish to do
- so, delete this exception statement from your version.
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent modules,
+ and to copy and distribute the resulting executable under terms of your
+ choice, provided that you also meet, for each linked independent module,
+ the terms and conditions of the license of that module. An independent
+ module is a module which is not derived from or based on this library. If
+ you modify this library, you may extend this exception to your version of
+ the library, but you are not obligated to do so. If you do not wish to do
+ so, delete this exception statement from your version.
# Quazip
- Copyright (C) 2005-2011 Sergey A. Tachenov
+ Copyright (C) 2005-2011 Sergey A. Tachenov
- This program 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 of the License, or (at
- your option) any later version.
+ This program 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 of the License, or (at
+ your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- General Public License for more details.
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+ General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- See COPYING file for the full LGPL text.
+ See COPYING file for the full LGPL text.
- Original ZIP package is copyrighted by Gilles Vollant, see
- quazip/(un)zip.h files for details, basically it's zlib license.
+ Original ZIP package is copyrighted by Gilles Vollant, see
+ quazip/(un)zip.h files for details, basically it's zlib license.
# xz-minidec
- XZ decompressor
+ XZ decompressor
- Authors: Lasse Collin
- Igor Pavlov
+ Authors: Lasse Collin
+ Igor Pavlov
- This file has been put into the public domain.
- You can do whatever you want with this file.
+ This file has been put into the public domain.
+ You can do whatever you want with this file.
# ColumnResizer
- Copyright (c) 2011-2016 Aurélien Gâteau and contributors.
+ Copyright (c) 2011-2016 Aurélien Gâteau and contributors.
- All rights reserved.
+ All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted (subject to the limitations in the
- disclaimer below) provided that the following conditions are met:
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted (subject to the limitations in the
+ disclaimer below) provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the
- distribution.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the
+ distribution.
- * The name of the contributors may not be used to endorse or
- promote products derived from this software without specific prior
- written permission.
+ * The name of the contributors may not be used to endorse or
+ promote products derived from this software without specific prior
+ written permission.
- NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
- GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
- HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+ GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+ HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# lionshead
- Code has been taken from https://github.com/natefoo/lionshead and loosely
- translated to C++ laced with Qt.
+ Code has been taken from https://github.com/natefoo/lionshead and loosely
+ translated to C++ laced with Qt.
- MIT License
+ MIT License
- Copyright (c) 2017 Nate Coraor
+ Copyright (c) 2017 Nate Coraor
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
diff --git a/api/gui/CMakeLists.txt b/api/gui/CMakeLists.txt
index 9a6ede25..ad116a43 100644
--- a/api/gui/CMakeLists.txt
+++ b/api/gui/CMakeLists.txt
@@ -1,17 +1,17 @@
project(MultiMC_gui LANGUAGES CXX)
set(GUI_SOURCES
- DesktopServices.h
- DesktopServices.cpp
+ DesktopServices.h
+ DesktopServices.cpp
- # Icons
- icons/MMCIcon.h
- icons/MMCIcon.cpp
- icons/IconList.h
- icons/IconList.cpp
+ # Icons
+ icons/MMCIcon.h
+ icons/MMCIcon.cpp
+ icons/IconList.h
+ icons/IconList.cpp
- SkinUtils.cpp
- SkinUtils.h
+ SkinUtils.cpp
+ SkinUtils.h
)
################################ COMPILE ################################
@@ -28,7 +28,7 @@ target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${C
# Install it
install(
- TARGETS MultiMC_gui
- RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
- LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
+ TARGETS MultiMC_gui
+ RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
+ LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
)
\ No newline at end of file
diff --git a/api/gui/DesktopServices.cpp b/api/gui/DesktopServices.cpp
index 3154ea01..5368ddc8 100644
--- a/api/gui/DesktopServices.cpp
+++ b/api/gui/DesktopServices.cpp
@@ -17,132 +17,132 @@
template
bool IndirectOpen(T callable, qint64 *pid_forked = nullptr)
{
- auto pid = fork();
- if(pid_forked)
- {
- if(pid > 0)
- *pid_forked = pid;
- else
- *pid_forked = 0;
- }
- if(pid == -1)
- {
- qWarning() << "IndirectOpen failed to fork: " << errno;
- return false;
- }
- // child - do the stuff
- if(pid == 0)
- {
- // unset all this garbage so it doesn't get passed to the child process
- qunsetenv("LD_PRELOAD");
- qunsetenv("LD_LIBRARY_PATH");
- qunsetenv("LD_DEBUG");
- qunsetenv("QT_PLUGIN_PATH");
- qunsetenv("QT_FONTPATH");
+ auto pid = fork();
+ if(pid_forked)
+ {
+ if(pid > 0)
+ *pid_forked = pid;
+ else
+ *pid_forked = 0;
+ }
+ if(pid == -1)
+ {
+ qWarning() << "IndirectOpen failed to fork: " << errno;
+ return false;
+ }
+ // child - do the stuff
+ if(pid == 0)
+ {
+ // unset all this garbage so it doesn't get passed to the child process
+ qunsetenv("LD_PRELOAD");
+ qunsetenv("LD_LIBRARY_PATH");
+ qunsetenv("LD_DEBUG");
+ qunsetenv("QT_PLUGIN_PATH");
+ qunsetenv("QT_FONTPATH");
- // open the URL
- auto status = callable();
+ // open the URL
+ auto status = callable();
- // detach from the parent process group.
- setsid();
+ // detach from the parent process group.
+ setsid();
- // die. now. do not clean up anything, it would just hang forever.
- _exit(status ? 0 : 1);
- }
- else
- {
- //parent - assume it worked.
- int status;
- while (waitpid(pid, &status, 0))
- {
- if(WIFEXITED(status))
- {
- return WEXITSTATUS(status) == 0;
- }
- if(WIFSIGNALED(status))
- {
- return false;
- }
- }
- return true;
- }
+ // die. now. do not clean up anything, it would just hang forever.
+ _exit(status ? 0 : 1);
+ }
+ else
+ {
+ //parent - assume it worked.
+ int status;
+ while (waitpid(pid, &status, 0))
+ {
+ if(WIFEXITED(status))
+ {
+ return WEXITSTATUS(status) == 0;
+ }
+ if(WIFSIGNALED(status))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
#endif
namespace DesktopServices {
bool openDirectory(const QString &path, bool ensureExists)
{
- qDebug() << "Opening directory" << path;
- QDir parentPath;
- QDir dir(path);
- if (!dir.exists())
- {
- parentPath.mkpath(dir.absolutePath());
- }
- auto f = [&]()
- {
- return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
- };
+ qDebug() << "Opening directory" << path;
+ QDir parentPath;
+ QDir dir(path);
+ if (!dir.exists())
+ {
+ parentPath.mkpath(dir.absolutePath());
+ }
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
+ };
#if defined(Q_OS_LINUX)
- return IndirectOpen(f);
+ return IndirectOpen(f);
#else
- return f();
+ return f();
#endif
}
bool openFile(const QString &path)
{
- qDebug() << "Opening file" << path;
- auto f = [&]()
- {
- return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
- };
+ qDebug() << "Opening file" << path;
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
+ };
#if defined(Q_OS_LINUX)
- return IndirectOpen(f);
+ return IndirectOpen(f);
#else
- return f();
+ return f();
#endif
}
bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid)
{
- qDebug() << "Opening file" << path << "using" << application;
+ qDebug() << "Opening file" << path << "using" << application;
#if defined(Q_OS_LINUX)
- // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
- return IndirectOpen([&]()
- {
- return QProcess::startDetached(application, QStringList() << path, workingDirectory);
- }, pid);
+ // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
+ return IndirectOpen([&]()
+ {
+ return QProcess::startDetached(application, QStringList() << path, workingDirectory);
+ }, pid);
#else
- return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
+ return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
#endif
}
bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid)
{
- qDebug() << "Running" << application << "with args" << args.join(' ');
+ qDebug() << "Running" << application << "with args" << args.join(' ');
#if defined(Q_OS_LINUX)
- // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
- return IndirectOpen([&]()
- {
- return QProcess::startDetached(application, args, workingDirectory);
- }, pid);
+ // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
+ return IndirectOpen([&]()
+ {
+ return QProcess::startDetached(application, args, workingDirectory);
+ }, pid);
#else
- return QProcess::startDetached(application, args, workingDirectory, pid);
+ return QProcess::startDetached(application, args, workingDirectory, pid);
#endif
}
bool openUrl(const QUrl &url)
{
- qDebug() << "Opening URL" << url.toString();
- auto f = [&]()
- {
- return QDesktopServices::openUrl(url);
- };
+ qDebug() << "Opening URL" << url.toString();
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(url);
+ };
#if defined(Q_OS_LINUX)
- return IndirectOpen(f);
+ return IndirectOpen(f);
#else
- return f();
+ return f();
#endif
}
diff --git a/api/gui/DesktopServices.h b/api/gui/DesktopServices.h
index f64a62c5..606fa52c 100644
--- a/api/gui/DesktopServices.h
+++ b/api/gui/DesktopServices.h
@@ -10,28 +10,28 @@
*/
namespace DesktopServices
{
- /**
- * Open a file in whatever application is applicable
- */
- MULTIMC_GUI_EXPORT bool openFile(const QString &path);
+ /**
+ * 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);
+ /**
+ * 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);
+ /**
+ * 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 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);
+ /**
+ * Open the URL, most likely in a browser. Maybe.
+ */
+ MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url);
}
diff --git a/api/gui/SkinUtils.cpp b/api/gui/SkinUtils.cpp
index 3950cbc0..79edb4b9 100644
--- a/api/gui/SkinUtils.cpp
+++ b/api/gui/SkinUtils.cpp
@@ -29,19 +29,19 @@ namespace SkinUtils
*/
QPixmap getFaceFromCache(QString username, int height, int width)
{
- QFile fskin(ENV.metacache()
- ->resolveEntry("skins", username + ".png")
- ->getFullPath());
+ QFile fskin(ENV.metacache()
+ ->resolveEntry("skins", username + ".png")
+ ->getFullPath());
- if (fskin.exists())
- {
- QPixmap skin(fskin.fileName());
- if(!skin.isNull())
- {
- return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
- }
- }
+ if (fskin.exists())
+ {
+ QPixmap skin(fskin.fileName());
+ if(!skin.isNull())
+ {
+ return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
+ }
+ }
- return QPixmap();
+ return QPixmap();
}
}
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp
index 997a03db..870b347e 100644
--- a/api/gui/icons/IconList.cpp
+++ b/api/gui/icons/IconList.cpp
@@ -27,394 +27,394 @@
IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
{
- QSet builtinNames;
+ QSet builtinNames;
- // add builtin icons
- for(auto & builtinPath: builtinPaths)
- {
- 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);
- }
+ // add builtin icons
+ for(auto & builtinPath: builtinPaths)
+ {
+ 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());
- is_watching = false;
- connect(m_watcher.get(), SIGNAL(directoryChanged(QString)),
- SLOT(directoryChanged(QString)));
- connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
+ m_watcher.reset(new QFileSystemWatcher());
+ is_watching = false;
+ connect(m_watcher.get(), SIGNAL(directoryChanged(QString)),
+ SLOT(directoryChanged(QString)));
+ connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
- directoryChanged(path);
+ directoryChanged(path);
}
void IconList::directoryChanged(const QString &path)
{
- QDir new_dir (path);
- if(m_dir.absolutePath() != new_dir.absolutePath())
- {
- m_dir.setPath(path);
- m_dir.refresh();
- if(is_watching)
- stopWatching();
- startWatching();
- }
- if(!m_dir.exists())
- if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
- return;
- m_dir.refresh();
- auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
- for (auto it = new_list.begin(); it != new_list.end(); it++)
- {
- QString &foo = (*it);
- foo = m_dir.filePath(foo);
- }
- auto new_set = new_list.toSet();
- QList current_list;
- for (auto &it : icons)
- {
- if (!it.has(IconType::FileBased))
- continue;
- current_list.push_back(it.m_images[IconType::FileBased].filename);
- }
- QSet current_set = current_list.toSet();
+ QDir new_dir (path);
+ if(m_dir.absolutePath() != new_dir.absolutePath())
+ {
+ m_dir.setPath(path);
+ m_dir.refresh();
+ if(is_watching)
+ stopWatching();
+ startWatching();
+ }
+ if(!m_dir.exists())
+ if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
+ return;
+ m_dir.refresh();
+ auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
+ for (auto it = new_list.begin(); it != new_list.end(); it++)
+ {
+ QString &foo = (*it);
+ foo = m_dir.filePath(foo);
+ }
+ auto new_set = new_list.toSet();
+ QList current_list;
+ for (auto &it : icons)
+ {
+ if (!it.has(IconType::FileBased))
+ continue;
+ current_list.push_back(it.m_images[IconType::FileBased].filename);
+ }
+ QSet current_set = current_list.toSet();
- QSet to_remove = current_set;
- to_remove -= new_set;
+ QSet to_remove = current_set;
+ to_remove -= new_set;
- QSet to_add = new_set;
- to_add -= current_set;
+ QSet to_add = new_set;
+ to_add -= current_set;
- for (auto remove : to_remove)
- {
- qDebug() << "Removing " << remove;
- QFileInfo rmfile(remove);
- QString key = rmfile.baseName();
- int idx = getIconIndex(key);
- if (idx == -1)
- continue;
- icons[idx].remove(IconType::FileBased);
- if (icons[idx].type() == IconType::ToBeDeleted)
- {
- beginRemoveRows(QModelIndex(), idx, idx);
- icons.remove(idx);
- reindex();
- endRemoveRows();
- }
- else
- {
- dataChanged(index(idx), index(idx));
- }
- m_watcher->removePath(remove);
- emit iconUpdated(key);
- }
+ for (auto remove : to_remove)
+ {
+ qDebug() << "Removing " << remove;
+ QFileInfo rmfile(remove);
+ QString key = rmfile.baseName();
+ int idx = getIconIndex(key);
+ if (idx == -1)
+ continue;
+ icons[idx].remove(IconType::FileBased);
+ if (icons[idx].type() == IconType::ToBeDeleted)
+ {
+ beginRemoveRows(QModelIndex(), idx, idx);
+ icons.remove(idx);
+ reindex();
+ endRemoveRows();
+ }
+ else
+ {
+ dataChanged(index(idx), index(idx));
+ }
+ m_watcher->removePath(remove);
+ emit iconUpdated(key);
+ }
- for (auto add : to_add)
- {
- qDebug() << "Adding " << add;
- QFileInfo addfile(add);
- QString key = addfile.baseName();
- if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
- {
- m_watcher->addPath(add);
- emit iconUpdated(key);
- }
- }
+ for (auto add : to_add)
+ {
+ qDebug() << "Adding " << add;
+ QFileInfo addfile(add);
+ QString key = addfile.baseName();
+ if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
+ {
+ m_watcher->addPath(add);
+ emit iconUpdated(key);
+ }
+ }
}
void IconList::fileChanged(const QString &path)
{
- qDebug() << "Checking " << path;
- QFileInfo checkfile(path);
- if (!checkfile.exists())
- return;
- QString key = checkfile.baseName();
- int idx = getIconIndex(key);
- if (idx == -1)
- return;
- QIcon icon(path);
- if (!icon.availableSizes().size())
- return;
+ qDebug() << "Checking " << path;
+ QFileInfo checkfile(path);
+ if (!checkfile.exists())
+ return;
+ QString key = checkfile.baseName();
+ int idx = getIconIndex(key);
+ if (idx == -1)
+ return;
+ QIcon icon(path);
+ if (!icon.availableSizes().size())
+ return;
- icons[idx].m_images[IconType::FileBased].icon = icon;
- dataChanged(index(idx), index(idx));
- emit iconUpdated(key);
+ icons[idx].m_images[IconType::FileBased].icon = icon;
+ dataChanged(index(idx), index(idx));
+ emit iconUpdated(key);
}
void IconList::SettingChanged(const Setting &setting, QVariant value)
{
- if(setting.id() != "IconsDir")
- return;
+ if(setting.id() != "IconsDir")
+ return;
- directoryChanged(value.toString());
+ directoryChanged(value.toString());
}
void IconList::startWatching()
{
- auto abs_path = m_dir.absolutePath();
- FS::ensureFolderPathExists(abs_path);
- is_watching = m_watcher->addPath(abs_path);
- if (is_watching)
- {
- qDebug() << "Started watching " << abs_path;
- }
- else
- {
- qDebug() << "Failed to start watching " << abs_path;
- }
+ auto abs_path = m_dir.absolutePath();
+ FS::ensureFolderPathExists(abs_path);
+ is_watching = m_watcher->addPath(abs_path);
+ if (is_watching)
+ {
+ qDebug() << "Started watching " << abs_path;
+ }
+ else
+ {
+ qDebug() << "Failed to start watching " << abs_path;
+ }
}
void IconList::stopWatching()
{
- m_watcher->removePaths(m_watcher->files());
- m_watcher->removePaths(m_watcher->directories());
- is_watching = false;
+ m_watcher->removePaths(m_watcher->files());
+ m_watcher->removePaths(m_watcher->directories());
+ is_watching = false;
}
QStringList IconList::mimeTypes() const
{
- QStringList types;
- types << "text/uri-list";
- return types;
+ QStringList types;
+ types << "text/uri-list";
+ return types;
}
Qt::DropActions IconList::supportedDropActions() const
{
- return Qt::CopyAction;
+ return Qt::CopyAction;
}
bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
- const QModelIndex &parent)
+ const QModelIndex &parent)
{
- if (action == Qt::IgnoreAction)
- return true;
- // check if the action is supported
- if (!data || !(action & supportedDropActions()))
- return false;
+ if (action == Qt::IgnoreAction)
+ return true;
+ // check if the action is supported
+ if (!data || !(action & supportedDropActions()))
+ return false;
- // files dropped from outside?
- if (data->hasUrls())
- {
- auto urls = data->urls();
- QStringList iconFiles;
- for (auto url : urls)
- {
- // only local files may be dropped...
- if (!url.isLocalFile())
- continue;
- iconFiles += url.toLocalFile();
- }
- installIcons(iconFiles);
- return true;
- }
- return false;
+ // files dropped from outside?
+ if (data->hasUrls())
+ {
+ auto urls = data->urls();
+ QStringList iconFiles;
+ for (auto url : urls)
+ {
+ // only local files may be dropped...
+ if (!url.isLocalFile())
+ continue;
+ iconFiles += url.toLocalFile();
+ }
+ installIcons(iconFiles);
+ return true;
+ }
+ return false;
}
Qt::ItemFlags IconList::flags(const QModelIndex &index) const
{
- Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
- if (index.isValid())
- return Qt::ItemIsDropEnabled | defaultFlags;
- else
- return Qt::ItemIsDropEnabled | defaultFlags;
+ Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
+ if (index.isValid())
+ return Qt::ItemIsDropEnabled | defaultFlags;
+ else
+ return Qt::ItemIsDropEnabled | defaultFlags;
}
QVariant IconList::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
+ if (!index.isValid())
+ return QVariant();
- int row = index.row();
+ int row = index.row();
- if (row < 0 || row >= icons.size())
- return QVariant();
+ if (row < 0 || row >= icons.size())
+ return QVariant();
- switch (role)
- {
- case Qt::DecorationRole:
- return icons[row].icon();
- case Qt::DisplayRole:
- return icons[row].name();
- case Qt::UserRole:
- return icons[row].m_key;
- default:
- return QVariant();
- }
+ switch (role)
+ {
+ case Qt::DecorationRole:
+ return icons[row].icon();
+ case Qt::DisplayRole:
+ return icons[row].name();
+ case Qt::UserRole:
+ return icons[row].m_key;
+ default:
+ return QVariant();
+ }
}
int IconList::rowCount(const QModelIndex &parent) const
{
- return icons.size();
+ return icons.size();
}
void IconList::installIcons(const QStringList &iconFiles)
{
- for (QString file : iconFiles)
- {
- QFileInfo fileinfo(file);
- if (!fileinfo.isReadable() || !fileinfo.isFile())
- continue;
- QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
+ for (QString file : iconFiles)
+ {
+ QFileInfo fileinfo(file);
+ if (!fileinfo.isReadable() || !fileinfo.isFile())
+ continue;
+ QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
- QString suffix = fileinfo.suffix();
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg")
- continue;
+ QString suffix = fileinfo.suffix();
+ if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg")
+ continue;
- if (!QFile::copy(file, target))
- continue;
- }
+ if (!QFile::copy(file, target))
+ continue;
+ }
}
void IconList::installIcon(const QString &file, const QString &name)
{
- QFileInfo fileinfo(file);
- if(!fileinfo.isReadable() || !fileinfo.isFile())
- return;
+ QFileInfo fileinfo(file);
+ if(!fileinfo.isReadable() || !fileinfo.isFile())
+ return;
- QString target = FS::PathCombine(m_dir.dirName(), name);
+ QString target = FS::PathCombine(m_dir.dirName(), name);
- QFile::copy(file, target);
+ QFile::copy(file, target);
}
bool IconList::iconFileExists(const QString &key) const
{
- auto iconEntry = icon(key);
- if(!iconEntry)
- {
- return false;
- }
- return iconEntry->has(IconType::FileBased);
+ auto iconEntry = icon(key);
+ if(!iconEntry)
+ {
+ return false;
+ }
+ return iconEntry->has(IconType::FileBased);
}
const MMCIcon *IconList::icon(const QString &key) const
{
- int iconIdx = getIconIndex(key);
- if (iconIdx == -1)
- return nullptr;
- return &icons[iconIdx];
+ int iconIdx = getIconIndex(key);
+ if (iconIdx == -1)
+ return nullptr;
+ return &icons[iconIdx];
}
bool IconList::deleteIcon(const QString &key)
{
- int iconIdx = getIconIndex(key);
- if (iconIdx == -1)
- return false;
- auto &iconEntry = icons[iconIdx];
- if (iconEntry.has(IconType::FileBased))
- {
- return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
- }
- return false;
+ int iconIdx = getIconIndex(key);
+ if (iconIdx == -1)
+ return false;
+ auto &iconEntry = icons[iconIdx];
+ if (iconEntry.has(IconType::FileBased))
+ {
+ return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
+ }
+ return false;
}
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;
- }
+ 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);
- if (icon.isNull())
- return false;
- auto iter = name_index.find(key);
- if (iter != name_index.end())
- {
- auto &oldOne = icons[*iter];
- oldOne.replace(type, icon, path);
- 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 = name;
- mmc_icon.m_key = key;
- mmc_icon.replace(type, icon, path);
- icons.push_back(mmc_icon);
- name_index[key] = icons.size() - 1;
- }
- endInsertRows();
- return true;
- }
+ // replace the icon even? is the input valid?
+ QIcon icon(path);
+ if (icon.isNull())
+ return false;
+ auto iter = name_index.find(key);
+ if (iter != name_index.end())
+ {
+ auto &oldOne = icons[*iter];
+ oldOne.replace(type, icon, path);
+ 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 = name;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(type, icon, path);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
+ }
+ endInsertRows();
+ return true;
+ }
}
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);
+ auto icon = getIcon(key);
+ auto pixmap = icon.pixmap(128, 128);
+ pixmap.save(path, format);
}
void IconList::reindex()
{
- name_index.clear();
- int i = 0;
- for (auto &iter : icons)
- {
- name_index[iter.m_key] = i;
- i++;
- }
+ name_index.clear();
+ int i = 0;
+ for (auto &iter : icons)
+ {
+ name_index[iter.m_key] = i;
+ i++;
+ }
}
QIcon IconList::getIcon(const QString &key) const
{
- int icon_index = getIconIndex(key);
+ int icon_index = getIconIndex(key);
- if (icon_index != -1)
- return icons[icon_index].icon();
+ if (icon_index != -1)
+ return icons[icon_index].icon();
- // Fallback for icons that don't exist.
- icon_index = getIconIndex("infinity");
+ // Fallback for icons that don't exist.
+ icon_index = getIconIndex("infinity");
- if (icon_index != -1)
- return icons[icon_index].icon();
- return QIcon();
+ if (icon_index != -1)
+ return icons[icon_index].icon();
+ return QIcon();
}
int IconList::getIconIndex(const QString &key) const
{
- auto iter = name_index.find(key == "default" ? "infinity" : key);
- if (iter != name_index.end())
- return *iter;
+ auto iter = name_index.find(key == "default" ? "infinity" : key);
+ if (iter != name_index.end())
+ return *iter;
- return -1;
+ return -1;
}
QString IconList::getDirectory() const
{
- return m_dir.absolutePath();
+ return m_dir.absolutePath();
}
//#include "IconList.moc"
diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h
index fad3336f..97ed3956 100644
--- a/api/gui/icons/IconList.h
+++ b/api/gui/icons/IconList.h
@@ -32,57 +32,57 @@ class QFileSystemWatcher;
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
- virtual ~IconList() {};
+ explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
+ virtual ~IconList() {};
- QIcon getIcon(const QString &key) const;
- int getIconIndex(const QString &key) const;
- QString getDirectory() const;
+ QIcon getIcon(const QString &key) const;
+ int getIconIndex(const QString &key) const;
+ QString getDirectory() const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- 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;
+ 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 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;
+ 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(const QStringList &iconFiles) override;
- void installIcon(const QString &file, const QString &name) override;
+ void installIcons(const QStringList &iconFiles) override;
+ void installIcon(const QString &file, const QString &name) override;
- const MMCIcon * icon(const QString &key) const;
+ const MMCIcon * icon(const QString &key) const;
- void startWatching();
- void stopWatching();
+ void startWatching();
+ void stopWatching();
signals:
- void iconUpdated(QString key);
+ void iconUpdated(QString key);
private:
- // hide copy constructor
- IconList(const IconList &) = delete;
- // hide assign op
- IconList &operator=(const IconList &) = delete;
- void reindex();
+ // hide copy constructor
+ IconList(const IconList &) = delete;
+ // hide assign op
+ IconList &operator=(const IconList &) = delete;
+ void reindex();
public slots:
- void directoryChanged(const QString &path);
+ void directoryChanged(const QString &path);
protected slots:
- void fileChanged(const QString &path);
- void SettingChanged(const Setting & setting, QVariant value);
+ void fileChanged(const QString &path);
+ void SettingChanged(const Setting & setting, QVariant value);
private:
- std::shared_ptr m_watcher;
- bool is_watching;
- QMap name_index;
- QVector icons;
- QDir m_dir;
+ std::shared_ptr m_watcher;
+ bool is_watching;
+ QMap name_index;
+ QVector icons;
+ QDir m_dir;
};
diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp
index 92518e01..a5ab548e 100644
--- a/api/gui/icons/MMCIcon.cpp
+++ b/api/gui/icons/MMCIcon.cpp
@@ -19,86 +19,86 @@
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 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;
+ return m_current_type;
}
QString MMCIcon::name() const
{
- if (m_name.size())
- return m_name;
- return m_key;
+ if (m_name.size())
+ return m_name;
+ return m_key;
}
bool MMCIcon::has(IconType _type) const
{
- return m_images[_type].present();
+ 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);
+ 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;
+ 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();
+ 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;
+ 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;
}
diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h
index 8c6752ea..d7618bee 100644
--- a/api/gui/icons/MMCIcon.h
+++ b/api/gui/icons/MMCIcon.h
@@ -23,27 +23,27 @@
struct MULTIMC_GUI_EXPORT MMCImage
{
- QIcon icon;
- QString key;
- QString filename;
- bool present() const
- {
- return !icon.isNull() || !key.isEmpty();
- }
+ QIcon icon;
+ QString key;
+ QString filename;
+ bool present() const
+ {
+ return !icon.isNull() || !key.isEmpty();
+ }
};
struct MULTIMC_GUI_EXPORT MMCIcon
{
- QString m_key;
- QString m_name;
- MMCImage m_images[ICONS_TOTAL];
- IconType m_current_type = ToBeDeleted;
+ QString m_key;
+ QString m_name;
+ MMCImage m_images[ICONS_TOTAL];
+ IconType m_current_type = ToBeDeleted;
- IconType type() const;
- QString name() const;
- bool has(IconType _type) const;
- QIcon icon() const;
- void remove(IconType rm_type);
- void replace(IconType new_type, QIcon icon, QString path = QString());
- void replace(IconType new_type, const QString &key);
+ IconType type() const;
+ QString name() const;
+ bool has(IconType _type) const;
+ QIcon icon() const;
+ void remove(IconType rm_type);
+ void replace(IconType new_type, QIcon icon, QString path = QString());
+ void replace(IconType new_type, const QString &key);
};
diff --git a/api/logic/BaseInstaller.cpp b/api/logic/BaseInstaller.cpp
index 51f66293..e25683a9 100644
--- a/api/logic/BaseInstaller.cpp
+++ b/api/logic/BaseInstaller.cpp
@@ -25,37 +25,37 @@ BaseInstaller::BaseInstaller()
bool BaseInstaller::isApplied(MinecraftInstance *on)
{
- return QFile::exists(filename(on->instanceRoot()));
+ return QFile::exists(filename(on->instanceRoot()));
}
bool BaseInstaller::add(MinecraftInstance *to)
{
- if (!patchesDir(to->instanceRoot()).exists())
- {
- QDir(to->instanceRoot()).mkdir("patches");
- }
+ if (!patchesDir(to->instanceRoot()).exists())
+ {
+ QDir(to->instanceRoot()).mkdir("patches");
+ }
- if (isApplied(to))
- {
- if (!remove(to))
- {
- return false;
- }
- }
+ if (isApplied(to))
+ {
+ if (!remove(to))
+ {
+ return false;
+ }
+ }
- return true;
+ return true;
}
bool BaseInstaller::remove(MinecraftInstance *from)
{
- return QFile::remove(filename(from->instanceRoot()));
+ return QFile::remove(filename(from->instanceRoot()));
}
QString BaseInstaller::filename(const QString &root) const
{
- return patchesDir(root).absoluteFilePath(id() + ".json");
+ return patchesDir(root).absoluteFilePath(id() + ".json");
}
QDir BaseInstaller::patchesDir(const QString &root) const
{
- return QDir(root + "/patches/");
+ return QDir(root + "/patches/");
}
diff --git a/api/logic/BaseInstaller.h b/api/logic/BaseInstaller.h
index afe11d55..121d35ef 100644
--- a/api/logic/BaseInstaller.h
+++ b/api/logic/BaseInstaller.h
@@ -30,17 +30,17 @@ typedef std::shared_ptr BaseVersionPtr;
class MULTIMC_LOGIC_EXPORT BaseInstaller
{
public:
- BaseInstaller();
- virtual ~BaseInstaller(){};
- bool isApplied(MinecraftInstance *on);
+ BaseInstaller();
+ virtual ~BaseInstaller(){};
+ bool isApplied(MinecraftInstance *on);
- virtual bool add(MinecraftInstance *to);
- virtual bool remove(MinecraftInstance *from);
+ virtual bool add(MinecraftInstance *to);
+ virtual bool remove(MinecraftInstance *from);
- virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
+ virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
protected:
- virtual QString id() const = 0;
- QString filename(const QString &root) const;
- QDir patchesDir(const QString &root) const;
+ virtual QString id() const = 0;
+ QString filename(const QString &root) const;
+ QDir patchesDir(const QString &root) const;
};
diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp
index 7e652e0d..c81b70c6 100644
--- a/api/logic/BaseInstance.cpp
+++ b/api/logic/BaseInstance.cpp
@@ -27,281 +27,281 @@
#include "Commandline.h"
BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
- : QObject()
+ : QObject()
{
- m_settings = settings;
- m_rootDir = rootDir;
+ m_settings = settings;
+ m_rootDir = rootDir;
- m_settings->registerSetting("name", "Unnamed Instance");
- m_settings->registerSetting("iconKey", "default");
- m_settings->registerSetting("notes", "");
- m_settings->registerSetting("lastLaunchTime", 0);
- m_settings->registerSetting("totalTimePlayed", 0);
+ m_settings->registerSetting("name", "Unnamed Instance");
+ m_settings->registerSetting("iconKey", "default");
+ m_settings->registerSetting("notes", "");
+ m_settings->registerSetting("lastLaunchTime", 0);
+ m_settings->registerSetting("totalTimePlayed", 0);
- // Custom Commands
- auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
- m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting);
- m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting);
- m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting);
+ // Custom Commands
+ auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
+ m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting);
+ m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting);
+ m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting);
- // Console
- 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);
+ // Console
+ 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);
+ m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr);
+ m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr);
}
QString BaseInstance::getPreLaunchCommand()
{
- return settings()->get("PreLaunchCommand").toString();
+ return settings()->get("PreLaunchCommand").toString();
}
QString BaseInstance::getWrapperCommand()
{
- return settings()->get("WrapperCommand").toString();
+ return settings()->get("WrapperCommand").toString();
}
QString BaseInstance::getPostExitCommand()
{
- return settings()->get("PostExitCommand").toString();
+ 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;
+ 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();
+ return settings()->get("ConsoleOverflowStop").toBool();
}
void BaseInstance::iconUpdated(QString key)
{
- if(iconKey() == key)
- {
- emit propertiesChanged(this);
- }
+ if(iconKey() == key)
+ {
+ emit propertiesChanged(this);
+ }
}
void BaseInstance::invalidate()
{
- changeStatus(Status::Gone);
- qDebug() << "Instance" << id() << "has been invalidated.";
+ 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());
+ changeStatus(Status::Gone);
+ qDebug() << "Instance" << id() << "has been deleted by MultiMC.";
+ FS::deletePath(instanceRoot());
}
void BaseInstance::changeStatus(BaseInstance::Status newStatus)
{
- Status status = currentStatus();
- if(status != newStatus)
- {
- m_status = newStatus;
- emit statusChanged(status, newStatus);
- }
+ Status status = currentStatus();
+ if(status != newStatus)
+ {
+ m_status = newStatus;
+ emit statusChanged(status, newStatus);
+ }
}
BaseInstance::Status BaseInstance::currentStatus() const
{
- return m_status;
+ return m_status;
}
QString BaseInstance::id() const
{
- return QFileInfo(instanceRoot()).fileName();
+ return QFileInfo(instanceRoot()).fileName();
}
bool BaseInstance::isRunning() const
{
- return m_isRunning;
+ return m_isRunning;
}
void BaseInstance::setRunning(bool running)
{
- if(running == m_isRunning)
- return;
+ if(running == m_isRunning)
+ return;
- m_isRunning = running;
+ m_isRunning = running;
- if(running)
- {
- m_timeStarted = QDateTime::currentDateTime();
- }
- else
- {
- qint64 current = settings()->get("totalTimePlayed").toLongLong();
- QDateTime timeEnded = QDateTime::currentDateTime();
- settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
- emit propertiesChanged(this);
- }
+ if(running)
+ {
+ m_timeStarted = QDateTime::currentDateTime();
+ }
+ else
+ {
+ qint64 current = settings()->get("totalTimePlayed").toLongLong();
+ QDateTime timeEnded = QDateTime::currentDateTime();
+ settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
+ emit propertiesChanged(this);
+ }
- emit runningStatusChanged(running);
+ emit runningStatusChanged(running);
}
int64_t BaseInstance::totalTimePlayed() const
{
- qint64 current = settings()->get("totalTimePlayed").toLongLong();
- if(m_isRunning)
- {
- QDateTime timeNow = QDateTime::currentDateTime();
- return current + m_timeStarted.secsTo(timeNow);
- }
- return current;
+ qint64 current = settings()->get("totalTimePlayed").toLongLong();
+ if(m_isRunning)
+ {
+ QDateTime timeNow = QDateTime::currentDateTime();
+ return current + m_timeStarted.secsTo(timeNow);
+ }
+ return current;
}
void BaseInstance::resetTimePlayed()
{
- settings()->reset("totalTimePlayed");
+ settings()->reset("totalTimePlayed");
}
QString BaseInstance::instanceType() const
{
- return m_settings->get("InstanceType").toString();
+ return m_settings->get("InstanceType").toString();
}
QString BaseInstance::instanceRoot() const
{
- return m_rootDir;
+ return m_rootDir;
}
InstancePtr BaseInstance::getSharedPtr()
{
- return shared_from_this();
+ return shared_from_this();
}
SettingsObjectPtr BaseInstance::settings() const
{
- return m_settings;
+ return m_settings;
}
bool BaseInstance::canLaunch() const
{
- return (!hasVersionBroken() && !isRunning());
+ return (!hasVersionBroken() && !isRunning());
}
bool BaseInstance::reloadSettings()
{
- return m_settings->reload();
+ return m_settings->reload();
}
qint64 BaseInstance::lastLaunch() const
{
- return m_settings->get("lastLaunchTime").value();
+ return m_settings->get("lastLaunchTime").value();
}
void BaseInstance::setLastLaunch(qint64 val)
{
- //FIXME: if no change, do not set. setting involves saving a file.
- m_settings->set("lastLaunchTime", val);
- emit propertiesChanged(this);
+ //FIXME: if no change, do not set. setting involves saving a file.
+ m_settings->set("lastLaunchTime", val);
+ emit propertiesChanged(this);
}
void BaseInstance::setGroupInitial(QString val)
{
- if(m_group == val)
- {
- return;
- }
- m_group = val;
- emit propertiesChanged(this);
+ if(m_group == val)
+ {
+ return;
+ }
+ m_group = val;
+ emit propertiesChanged(this);
}
void BaseInstance::setGroupPost(QString val)
{
- if(m_group == val)
- {
- return;
- }
- setGroupInitial(val);
- emit groupChanged();
+ if(m_group == val)
+ {
+ return;
+ }
+ setGroupInitial(val);
+ emit groupChanged();
}
QString BaseInstance::group() const
{
- return m_group;
+ return m_group;
}
void BaseInstance::setNotes(QString val)
{
- //FIXME: if no change, do not set. setting involves saving a file.
- m_settings->set("notes", val);
+ //FIXME: if no change, do not set. setting involves saving a file.
+ m_settings->set("notes", val);
}
QString BaseInstance::notes() const
{
- return m_settings->get("notes").toString();
+ return m_settings->get("notes").toString();
}
void BaseInstance::setIconKey(QString val)
{
- //FIXME: if no change, do not set. setting involves saving a file.
- m_settings->set("iconKey", val);
- emit propertiesChanged(this);
+ //FIXME: if no change, do not set. setting involves saving a file.
+ m_settings->set("iconKey", val);
+ emit propertiesChanged(this);
}
QString BaseInstance::iconKey() const
{
- return m_settings->get("iconKey").toString();
+ return m_settings->get("iconKey").toString();
}
void BaseInstance::setName(QString val)
{
- //FIXME: if no change, do not set. setting involves saving a file.
- m_settings->set("name", val);
- emit propertiesChanged(this);
+ //FIXME: if no change, do not set. setting involves saving a file.
+ m_settings->set("name", val);
+ emit propertiesChanged(this);
}
QString BaseInstance::name() const
{
- return m_settings->get("name").toString();
+ return m_settings->get("name").toString();
}
QString BaseInstance::windowTitle() const
{
- return "MultiMC: " + name();
+ return "MultiMC: " + name();
}
// FIXME: why is this here? move it to MinecraftInstance!!!
QStringList BaseInstance::extraArguments() const
{
- return Commandline::splitArgs(settings()->get("JvmArgs").toString());
+ return Commandline::splitArgs(settings()->get("JvmArgs").toString());
}
std::shared_ptr BaseInstance::getLaunchTask()
{
- return m_launchProcess;
+ return m_launchProcess;
}
void BaseInstance::setProvider(BaseInstanceProvider* provider)
{
- // only once.
- assert(!m_provider);
- if(m_provider)
- {
- qWarning() << "Provider set more than once for instance" << id();
- }
- m_provider = provider;
+ // 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;
+ return m_provider;
}
diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h
index 282bfb70..f3b15a20 100644
--- a/api/logic/BaseInstance.h
+++ b/api/logic/BaseInstance.h
@@ -53,229 +53,229 @@ typedef std::shared_ptr InstancePtr;
*/
class MULTIMC_LOGIC_EXPORT BaseInstance : public QObject, public std::enable_shared_from_this
{
- Q_OBJECT
+ Q_OBJECT
protected:
- /// no-touchy!
- BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
+ /// no-touchy!
+ BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
public: /* types */
- enum class Status
- {
- Present,
- Gone // either nuked or invalidated
- };
+ enum class Status
+ {
+ Present,
+ Gone // either nuked or invalidated
+ };
public:
- /// virtual destructor to make sure the destruction is COMPLETE
- virtual ~BaseInstance() {};
+ /// virtual destructor to make sure the destruction is COMPLETE
+ virtual ~BaseInstance() {};
- virtual void init() = 0;
- virtual void saveNow() = 0;
+ virtual void init() = 0;
+ virtual void saveNow() = 0;
- /// nuke thoroughly - deletes the instance contents, notifies the list/model which is
- /// responsible of cleaning up the husk
- void nuke();
+ /// nuke thoroughly - deletes the instance contents, notifies the list/model which is
+ /// 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 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;
+ /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to
+ /// be unique.
+ virtual QString id() const;
- void setRunning(bool running);
- bool isRunning() const;
- int64_t totalTimePlayed() const;
- void resetTimePlayed();
+ void setRunning(bool running);
+ bool isRunning() const;
+ int64_t totalTimePlayed() const;
+ void resetTimePlayed();
- void setProvider(BaseInstanceProvider * provider);
- BaseInstanceProvider * provider() const;
+ void setProvider(BaseInstanceProvider * provider);
+ BaseInstanceProvider * provider() const;
- /// get the type of this instance
- QString instanceType() const;
+ /// get the type of this instance
+ QString instanceType() const;
- /// Path to the instance's root directory.
- QString instanceRoot() const;
+ /// Path to the instance's root directory.
+ QString instanceRoot() const;
- QString name() const;
- void setName(QString val);
+ QString name() const;
+ void setName(QString val);
- /// Value used for instance window titles
- QString windowTitle() const;
+ /// Value used for instance window titles
+ QString windowTitle() const;
- QString iconKey() const;
- void setIconKey(QString val);
+ QString iconKey() const;
+ void setIconKey(QString val);
- QString notes() const;
- void setNotes(QString val);
+ QString notes() const;
+ void setNotes(QString val);
- QString group() const;
- void setGroupInitial(QString val);
- void setGroupPost(QString val);
+ QString group() const;
+ void setGroupInitial(QString val);
+ void setGroupPost(QString val);
- QString getPreLaunchCommand();
- QString getPostExitCommand();
- QString getWrapperCommand();
+ QString getPreLaunchCommand();
+ QString getPostExitCommand();
+ QString getWrapperCommand();
- /// guess log level from a line of game log
- virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level)
- {
- return level;
- };
+ /// guess log level from a line of game log
+ virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level)
+ {
+ return level;
+ };
- virtual QStringList extraArguments() const;
+ virtual QStringList extraArguments() const;
- /// Traits. Normally inside the version, depends on instance implementation.
- virtual QSet traits() const = 0;
+ /// Traits. Normally inside the version, depends on instance implementation.
+ virtual QSet traits() const = 0;
- /**
- * Gets the time that the instance was last launched.
- * Stored in milliseconds since epoch.
- */
- qint64 lastLaunch() const;
- /// Sets the last launched time to 'val' milliseconds since epoch
- void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
+ /**
+ * Gets the time that the instance was last launched.
+ * Stored in milliseconds since epoch.
+ */
+ qint64 lastLaunch() const;
+ /// Sets the last launched time to 'val' milliseconds since epoch
+ void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
- InstancePtr getSharedPtr();
+ InstancePtr getSharedPtr();
- /*!
- * \brief Gets this instance's settings object.
- * This settings object stores instance-specific settings.
- * \return A pointer to this instance's settings object.
- */
- virtual SettingsObjectPtr settings() const;
+ /*!
+ * \brief Gets this instance's settings object.
+ * This settings object stores instance-specific settings.
+ * \return A pointer to this instance's settings object.
+ */
+ virtual SettingsObjectPtr settings() const;
- /// returns a valid update task
- virtual shared_qobject_ptr createUpdateTask(Net::Mode mode) = 0;
+ /// returns a valid update task
+ virtual shared_qobject_ptr createUpdateTask(Net::Mode mode) = 0;
- /// returns a valid launcher (task container)
- virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) = 0;
+ /// returns a valid launcher (task container)
+ virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) = 0;
- /// returns the current launch task (if any)
- std::shared_ptr getLaunchTask();
+ /// returns the current launch task (if any)
+ std::shared_ptr getLaunchTask();
- /*!
- * Create envrironment variables for running the instance
- */
- virtual QProcessEnvironment createEnvironment() = 0;
+ /*!
+ * Create envrironment variables for running the instance
+ */
+ virtual QProcessEnvironment createEnvironment() = 0;
- /*!
- * Returns a matcher that can maps relative paths within the instance to whether they are 'log files'
- */
- virtual IPathMatcher::Ptr getLogFileMatcher() = 0;
+ /*!
+ * Returns a matcher that can maps relative paths within the instance to whether they are 'log files'
+ */
+ virtual IPathMatcher::Ptr getLogFileMatcher() = 0;
- /*!
- * Returns the root folder to use for looking up log files
- */
- virtual QString getLogFileRoot() = 0;
+ /*!
+ * Returns the root folder to use for looking up log files
+ */
+ virtual QString getLogFileRoot() = 0;
- virtual QString getStatusbarDescription() = 0;
+ virtual QString getStatusbarDescription() = 0;
- /// FIXME: this really should be elsewhere...
- virtual QString instanceConfigFolder() const = 0;
+ /// FIXME: this really should be elsewhere...
+ virtual QString instanceConfigFolder() const = 0;
- /// get variables this instance exports
- virtual QMap getVariables() const = 0;
+ /// get variables this instance exports
+ virtual QMap getVariables() const = 0;
- virtual QString typeName() const = 0;
+ virtual QString typeName() const = 0;
- bool hasVersionBroken() const
- {
- return m_hasBrokenVersion;
- }
- void setVersionBroken(bool value)
- {
- if(m_hasBrokenVersion != value)
- {
- m_hasBrokenVersion = value;
- emit propertiesChanged(this);
- }
- }
+ bool hasVersionBroken() const
+ {
+ return m_hasBrokenVersion;
+ }
+ void setVersionBroken(bool value)
+ {
+ if(m_hasBrokenVersion != value)
+ {
+ m_hasBrokenVersion = value;
+ emit propertiesChanged(this);
+ }
+ }
- bool hasUpdateAvailable() const
- {
- return m_hasUpdate;
- }
- void setUpdateAvailable(bool value)
- {
- if(m_hasUpdate != value)
- {
- m_hasUpdate = value;
- emit propertiesChanged(this);
- }
- }
+ bool 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 hasCrashed() const
+ {
+ return m_crashed;
+ }
+ void setCrashed(bool value)
+ {
+ if(m_crashed != value)
+ {
+ m_crashed = value;
+ emit propertiesChanged(this);
+ }
+ }
- virtual bool canLaunch() const;
- virtual bool canEdit() const = 0;
- virtual bool canExport() const = 0;
+ virtual bool canLaunch() const;
+ virtual bool canEdit() const = 0;
+ virtual bool canExport() const = 0;
- bool reloadSettings();
+ bool reloadSettings();
- /**
- * 'print' a verbose desription of the instance into a QStringList
- */
- virtual QStringList verboseDescription(AuthSessionPtr session) = 0;
+ /**
+ * 'print' a verbose desription of the instance into a QStringList
+ */
+ virtual QStringList verboseDescription(AuthSessionPtr session) = 0;
- Status currentStatus() const;
+ Status currentStatus() const;
- int getConsoleMaxLines() const;
- bool shouldStopOnConsoleOverflow() const;
+ int getConsoleMaxLines() const;
+ bool shouldStopOnConsoleOverflow() const;
protected:
- void changeStatus(Status newStatus);
+ void changeStatus(Status newStatus);
signals:
- /*!
- * \brief Signal emitted when properties relevant to the instance view change
- */
- void propertiesChanged(BaseInstance *inst);
- /*!
- * \brief Signal emitted when groups are affected in any way
- */
- void groupChanged();
+ /*!
+ * \brief Signal emitted when properties relevant to the instance view change
+ */
+ void propertiesChanged(BaseInstance *inst);
+ /*!
+ * \brief Signal emitted when groups are affected in any way
+ */
+ void groupChanged();
- void launchTaskChanged(std::shared_ptr);
+ void launchTaskChanged(std::shared_ptr);
- void runningStatusChanged(bool running);
+ void runningStatusChanged(bool running);
- void statusChanged(Status from, Status to);
+ void statusChanged(Status from, Status to);
protected slots:
- void iconUpdated(QString key);
+ void iconUpdated(QString key);
protected: /* data */
- QString m_rootDir;
- QString m_group;
- SettingsObjectPtr m_settings;
- // InstanceFlags m_flags;
- bool m_isRunning = false;
- std::shared_ptr m_launchProcess;
- QDateTime m_timeStarted;
- BaseInstanceProvider * m_provider = nullptr;
+ QString m_rootDir;
+ QString m_group;
+ SettingsObjectPtr m_settings;
+ // InstanceFlags m_flags;
+ bool m_isRunning = false;
+ std::shared_ptr 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;
+ Status m_status = Status::Present;
+ bool m_crashed = false;
+ bool m_hasUpdate = false;
+ bool m_hasBrokenVersion = false;
};
Q_DECLARE_METATYPE(std::shared_ptr)
diff --git a/api/logic/BaseInstanceProvider.h b/api/logic/BaseInstanceProvider.h
index 34489c5d..1eee0e4f 100644
--- a/api/logic/BaseInstanceProvider.h
+++ b/api/logic/BaseInstanceProvider.h
@@ -12,46 +12,46 @@ using InstanceLocator = std::pair;
enum class InstCreateError
{
- NoCreateError = 0,
- NoSuchVersion,
- UnknownCreateError,
- InstExists,
- CantCreateDir
+ NoCreateError = 0,
+ NoSuchVersion,
+ UnknownCreateError,
+ InstExists,
+ CantCreateDir
};
class MULTIMC_LOGIC_EXPORT BaseInstanceProvider : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
- BaseInstanceProvider(SettingsObjectPtr settings) : m_globalSettings(settings)
- {
- // nil
- }
+ BaseInstanceProvider(SettingsObjectPtr settings) : m_globalSettings(settings)
+ {
+ // nil
+ }
public:
- virtual QList discoverInstances() = 0;
- virtual InstancePtr loadInstance(const InstanceId &id) = 0;
- virtual void loadGroupList() = 0;
- virtual void saveGroupList() = 0;
+ virtual QList 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 & path, const QString& instanceName, const QString & groupName)
- {
- return false;
- }
- virtual bool destroyStagingPath(const QString & path)
- {
- return true;
- }
+ virtual QString getStagedInstancePath()
+ {
+ return QString();
+ }
+ virtual bool commitStagedInstance(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 groups);
+ // Emit this when the list of provided instances changed
+ void instancesChanged();
+ // Emit when the set of groups your provider supplies changes.
+ void groupsChanged(QSet groups);
protected:
- SettingsObjectPtr m_globalSettings;
+ SettingsObjectPtr m_globalSettings;
};
diff --git a/api/logic/BaseVersion.h b/api/logic/BaseVersion.h
index e49d6277..4f06c3bc 100644
--- a/api/logic/BaseVersion.h
+++ b/api/logic/BaseVersion.h
@@ -25,33 +25,33 @@
class BaseVersion
{
public:
- virtual ~BaseVersion() {}
- /*!
- * A string used to identify this version in config files.
- * This should be unique within the version list or shenanigans will occur.
- */
- virtual QString descriptor() = 0;
+ virtual ~BaseVersion() {}
+ /*!
+ * A string used to identify this version in config files.
+ * This should be unique within the version list or shenanigans will occur.
+ */
+ virtual QString descriptor() = 0;
- /*!
- * The name of this version as it is displayed to the user.
- * For example: "1.5.1"
- */
- virtual QString name() = 0;
+ /*!
+ * The name of this version as it is displayed to the user.
+ * For example: "1.5.1"
+ */
+ virtual QString name() = 0;
- /*!
- * This should return a string that describes
- * the kind of version this is (Stable, Beta, Snapshot, whatever)
- */
- virtual QString typeString() const = 0;
+ /*!
+ * This should return a string that describes
+ * the kind of version this is (Stable, Beta, Snapshot, whatever)
+ */
+ virtual QString typeString() const = 0;
- virtual bool operator<(BaseVersion &a)
- {
- return name() < a.name();
- };
- virtual bool operator>(BaseVersion &a)
- {
- return name() > a.name();
- };
+ virtual bool operator<(BaseVersion &a)
+ {
+ return name() < a.name();
+ };
+ virtual bool operator>(BaseVersion &a)
+ {
+ return name() > a.name();
+ };
};
typedef std::shared_ptr BaseVersionPtr;
diff --git a/api/logic/BaseVersionList.cpp b/api/logic/BaseVersionList.cpp
index 31a635d7..b1f73529 100644
--- a/api/logic/BaseVersionList.cpp
+++ b/api/logic/BaseVersionList.cpp
@@ -22,78 +22,78 @@ BaseVersionList::BaseVersionList(QObject *parent) : QAbstractListModel(parent)
BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
{
- for (int i = 0; i < count(); i++)
- {
- if (at(i)->descriptor() == descriptor)
- return at(i);
- }
- return BaseVersionPtr();
+ for (int i = 0; i < count(); i++)
+ {
+ if (at(i)->descriptor() == descriptor)
+ return at(i);
+ }
+ return BaseVersionPtr();
}
BaseVersionPtr BaseVersionList::getRecommended() const
{
- if (count() <= 0)
- return BaseVersionPtr();
- else
- return at(0);
+ if (count() <= 0)
+ return BaseVersionPtr();
+ else
+ return at(0);
}
QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
+ if (!index.isValid())
+ return QVariant();
- if (index.row() > count())
- return QVariant();
+ if (index.row() > count())
+ return QVariant();
- BaseVersionPtr version = at(index.row());
+ BaseVersionPtr version = at(index.row());
- switch (role)
- {
- case VersionPointerRole:
- return qVariantFromValue(version);
+ switch (role)
+ {
+ case VersionPointerRole:
+ return qVariantFromValue(version);
- case VersionRole:
- return version->name();
+ case VersionRole:
+ return version->name();
- case VersionIdRole:
- return version->descriptor();
+ case VersionIdRole:
+ return version->descriptor();
- case TypeRole:
- return version->typeString();
+ case TypeRole:
+ return version->typeString();
- default:
- return QVariant();
- }
+ default:
+ return QVariant();
+ }
}
BaseVersionList::RoleList BaseVersionList::providesRoles() const
{
- return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
+ return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
}
int BaseVersionList::rowCount(const QModelIndex &parent) const
{
- // Return count
- return count();
+ // Return count
+ return count();
}
int BaseVersionList::columnCount(const QModelIndex &parent) const
{
- return 1;
+ return 1;
}
QHash BaseVersionList::roleNames() const
{
- QHash roles = QAbstractListModel::roleNames();
- roles.insert(VersionRole, "version");
- roles.insert(VersionIdRole, "versionId");
- roles.insert(ParentVersionRole, "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;
+ QHash roles = QAbstractListModel::roleNames();
+ roles.insert(VersionRole, "version");
+ roles.insert(VersionIdRole, "versionId");
+ roles.insert(ParentVersionRole, "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;
}
diff --git a/api/logic/BaseVersionList.h b/api/logic/BaseVersionList.h
index b609e039..a70a414c 100644
--- a/api/logic/BaseVersionList.h
+++ b/api/logic/BaseVersionList.h
@@ -38,85 +38,85 @@
*/
class MULTIMC_LOGIC_EXPORT BaseVersionList : public QAbstractListModel
{
- Q_OBJECT
+ Q_OBJECT
public:
- enum ModelRoles
- {
- VersionPointerRole = Qt::UserRole,
- VersionRole,
- VersionIdRole,
- ParentVersionRole,
- RecommendedRole,
- LatestRole,
- TypeRole,
- BranchRole,
- PathRole,
- ArchitectureRole,
- SortRole
- };
- typedef QList RoleList;
+ enum ModelRoles
+ {
+ VersionPointerRole = Qt::UserRole,
+ VersionRole,
+ VersionIdRole,
+ ParentVersionRole,
+ RecommendedRole,
+ LatestRole,
+ TypeRole,
+ BranchRole,
+ PathRole,
+ ArchitectureRole,
+ SortRole
+ };
+ typedef QList RoleList;
- explicit BaseVersionList(QObject *parent = 0);
+ explicit BaseVersionList(QObject *parent = 0);
- /*!
- * \brief Gets a task that will reload the version list.
- * Simply execute the task to load the list.
- * The task returned by this function should reset the model when it's done.
- * \return A pointer to a task that reloads the version list.
- */
- virtual shared_qobject_ptr getLoadTask() = 0;
+ /*!
+ * \brief Gets a task that will reload the version list.
+ * Simply execute the task to load the list.
+ * The task returned by this function should reset the model when it's done.
+ * \return A pointer to a task that reloads the version list.
+ */
+ virtual shared_qobject_ptr getLoadTask() = 0;
- //! Checks whether or not the list is loaded. If this returns false, the list should be
- //loaded.
- virtual bool isLoaded() = 0;
+ //! Checks whether or not the list is loaded. If this returns false, the list should be
+ //loaded.
+ virtual bool isLoaded() = 0;
- //! Gets the version at the given index.
- virtual const BaseVersionPtr at(int i) const = 0;
+ //! Gets the version at the given index.
+ virtual const BaseVersionPtr at(int i) const = 0;
- //! Returns the number of versions in the list.
- virtual int count() const = 0;
+ //! Returns the number of versions in the list.
+ virtual int count() const = 0;
- //////// List Model Functions ////////
- QVariant data(const QModelIndex &index, int role) const override;
- int rowCount(const QModelIndex &parent) const override;
- int columnCount(const QModelIndex &parent) const override;
- QHash roleNames() const override;
+ //////// List Model Functions ////////
+ QVariant data(const QModelIndex &index, int role) const override;
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QHash roleNames() const override;
- //! which roles are provided by this version list?
- virtual RoleList providesRoles() const;
+ //! which roles are provided by this version list?
+ virtual RoleList providesRoles() const;
- /*!
- * \brief Finds a version by its descriptor.
- * \param descriptor The descriptor of the version to find.
- * \return A const pointer to the version with the given descriptor. NULL if
- * one doesn't exist.
- */
- virtual BaseVersionPtr findVersion(const QString &descriptor);
+ /*!
+ * \brief Finds a version by its descriptor.
+ * \param descriptor The descriptor of the version to find.
+ * \return A const pointer to the version with the given descriptor. NULL if
+ * one doesn't exist.
+ */
+ virtual BaseVersionPtr findVersion(const QString &descriptor);
- /*!
- * \brief Gets the recommended version from this list
- * If the list doesn't support recommended versions, this works exactly as getLatestStable
- */
- virtual BaseVersionPtr getRecommended() const;
+ /*!
+ * \brief Gets the recommended version from this list
+ * If the list doesn't support recommended versions, this works exactly as getLatestStable
+ */
+ virtual BaseVersionPtr getRecommended() const;
- /*!
- * Sorts the version list.
- */
- virtual void sortVersions() = 0;
+ /*!
+ * Sorts the version list.
+ */
+ virtual void sortVersions() = 0;
protected
slots:
- /*!
- * Updates this list with the given list of versions.
- * This is done by copying each version in the given list and inserting it
- * into this one.
- * We need to do this so that we can set the parents of the versions are set to this
- * version list. This can't be done in the load task, because the versions the load
- * task creates are on the load task's thread and Qt won't allow their parents
- * to be set to something created on another thread.
- * To get around that problem, we invoke this method on the GUI thread, which
- * then copies the versions and sets their parents correctly.
- * \param versions List of versions whose parents should be set.
- */
- virtual void updateListData(QList versions) = 0;
+ /*!
+ * Updates this list with the given list of versions.
+ * This is done by copying each version in the given list and inserting it
+ * into this one.
+ * We need to do this so that we can set the parents of the versions are set to this
+ * version list. This can't be done in the load task, because the versions the load
+ * task creates are on the load task's thread and Qt won't allow their parents
+ * to be set to something created on another thread.
+ * To get around that problem, we invoke this method on the GUI thread, which
+ * then copies the versions and sets their parents correctly.
+ * \param versions List of versions whose parents should be set.
+ */
+ virtual void updateListData(QList versions) = 0;
};
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index 769f112e..4c2445f0 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -3,446 +3,446 @@ project(MultiMC_logic)
include (UnitTest)
set(CORE_SOURCES
- # LOGIC - Base classes and infrastructure
- BaseInstaller.h
- BaseInstaller.cpp
- BaseVersionList.h
- BaseVersionList.cpp
- InstanceList.h
- InstanceList.cpp
- InstanceTask.h
- InstanceTask.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
+ # LOGIC - Base classes and infrastructure
+ BaseInstaller.h
+ BaseInstaller.cpp
+ BaseVersionList.h
+ BaseVersionList.cpp
+ InstanceList.h
+ InstanceList.cpp
+ InstanceTask.h
+ InstanceTask.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
- # Basic instance manipulation tasks (derived from InstanceTask)
- InstanceCreationTask.h
- InstanceCreationTask.cpp
- InstanceCopyTask.h
- InstanceCopyTask.cpp
- InstanceImportTask.h
- InstanceImportTask.cpp
+ # Basic instance manipulation tasks (derived from InstanceTask)
+ InstanceCreationTask.h
+ InstanceCreationTask.cpp
+ InstanceCopyTask.h
+ InstanceCopyTask.cpp
+ InstanceImportTask.h
+ InstanceImportTask.cpp
- # Use tracking separate from memory management
- Usable.h
+ # Use tracking separate from memory management
+ Usable.h
- # Prefix tree where node names are strings between separators
- SeparatorPrefixTree.h
+ # Prefix tree where node names are strings between separators
+ SeparatorPrefixTree.h
- # WARNING: globals live here
- Env.h
- Env.cpp
+ # WARNING: globals live here
+ Env.h
+ Env.cpp
- # String filters
- Filter.h
- Filter.cpp
+ # String filters
+ Filter.h
+ Filter.cpp
- # JSON parsing helpers
- Json.h
- Json.cpp
+ # JSON parsing helpers
+ Json.h
+ Json.cpp
- FileSystem.h
- FileSystem.cpp
+ FileSystem.h
+ FileSystem.cpp
- Exception.h
+ Exception.h
- # RW lock protected map
- RWStorage.h
+ # RW lock protected map
+ RWStorage.h
- # A variable that has an implicit default value and keeps track of changes
- DefaultVariable.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
+ # a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
+ QObjectPtr.h
- # Compression support
- GZip.h
- GZip.cpp
+ # Compression support
+ GZip.h
+ GZip.cpp
- # Command line parameter parsing
- Commandline.h
- Commandline.cpp
+ # Command line parameter parsing
+ Commandline.h
+ Commandline.cpp
- # Version number string support
- Version.h
- Version.cpp
+ # Version number string support
+ Version.h
+ Version.cpp
- # A Recursive file system watcher
- RecursiveFileSystemWatcher.h
- RecursiveFileSystemWatcher.cpp
+ # A Recursive file system watcher
+ RecursiveFileSystemWatcher.h
+ RecursiveFileSystemWatcher.cpp
)
add_unit_test(FileSystem
- SOURCES FileSystem_test.cpp
- LIBS MultiMC_logic
- DATA testdata
- )
+ SOURCES FileSystem_test.cpp
+ LIBS MultiMC_logic
+ DATA testdata
+ )
add_unit_test(GZip
- SOURCES GZip_test.cpp
- LIBS MultiMC_logic
- )
+ SOURCES GZip_test.cpp
+ LIBS MultiMC_logic
+ )
set(PATHMATCHER_SOURCES
- # Path matchers
- pathmatcher/FSTreeMatcher.h
- pathmatcher/IPathMatcher.h
- pathmatcher/MultiMatcher.h
- pathmatcher/RegexpMatcher.h
+ # 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
+ # 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
+ 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
+ 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
- )
+ 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
- )
+ 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
+ # 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
+ # 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
+ # News System
+ icons/IIconList.h
+ icons/IIconList.cpp
)
# Minecraft services status checker
set(STATUS_SOURCES
- # Status system
- status/StatusChecker.h
- status/StatusChecker.cpp
+ # 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/update/AssetUpdateTask.h
- minecraft/update/AssetUpdateTask.cpp
- minecraft/update/FMLLibrariesTask.cpp
- minecraft/update/FMLLibrariesTask.h
- minecraft/update/FoldersTask.cpp
- minecraft/update/FoldersTask.h
- minecraft/update/LibrariesTask.cpp
- minecraft/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/LegacyInstance.h
- minecraft/legacy/LegacyInstance.cpp
- minecraft/legacy/LegacyUpgradeTask.h
- minecraft/legacy/LegacyUpgradeTask.cpp
- minecraft/GradleSpecifier.h
- minecraft/MinecraftInstance.cpp
- minecraft/MinecraftInstance.h
- minecraft/LaunchProfile.cpp
- minecraft/LaunchProfile.h
- minecraft/Component.cpp
- minecraft/Component.h
- minecraft/ComponentList.cpp
- minecraft/ComponentList.h
- minecraft/ComponentUpdateTask.cpp
- minecraft/ComponentUpdateTask.h
- minecraft/MinecraftLoadAndCheck.h
- minecraft/MinecraftLoadAndCheck.cpp
- minecraft/MinecraftUpdate.h
- minecraft/MinecraftUpdate.cpp
- minecraft/MojangVersionFormat.cpp
- minecraft/MojangVersionFormat.h
- minecraft/Rule.cpp
- minecraft/Rule.h
- minecraft/OneSixVersionFormat.cpp
- minecraft/OneSixVersionFormat.h
- minecraft/OpSys.cpp
- minecraft/OpSys.h
- minecraft/ParseUtils.cpp
- minecraft/ParseUtils.h
- minecraft/ProfileUtils.cpp
- minecraft/ProfileUtils.h
- minecraft/Library.cpp
- minecraft/Library.h
- minecraft/MojangDownloadInfo.h
- minecraft/VersionFile.cpp
- minecraft/VersionFile.h
- minecraft/VersionFilterData.h
- minecraft/VersionFilterData.cpp
- minecraft/Mod.h
- minecraft/Mod.cpp
- minecraft/ModsModel.h
- minecraft/ModsModel.cpp
- minecraft/SimpleModList.h
- minecraft/SimpleModList.cpp
- minecraft/World.h
- minecraft/World.cpp
- minecraft/WorldList.h
- minecraft/WorldList.cpp
+ # 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/update/AssetUpdateTask.h
+ minecraft/update/AssetUpdateTask.cpp
+ minecraft/update/FMLLibrariesTask.cpp
+ minecraft/update/FMLLibrariesTask.h
+ minecraft/update/FoldersTask.cpp
+ minecraft/update/FoldersTask.h
+ minecraft/update/LibrariesTask.cpp
+ minecraft/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/LegacyInstance.h
+ minecraft/legacy/LegacyInstance.cpp
+ minecraft/legacy/LegacyUpgradeTask.h
+ minecraft/legacy/LegacyUpgradeTask.cpp
+ minecraft/GradleSpecifier.h
+ minecraft/MinecraftInstance.cpp
+ minecraft/MinecraftInstance.h
+ minecraft/LaunchProfile.cpp
+ minecraft/LaunchProfile.h
+ minecraft/Component.cpp
+ minecraft/Component.h
+ minecraft/ComponentList.cpp
+ minecraft/ComponentList.h
+ minecraft/ComponentUpdateTask.cpp
+ minecraft/ComponentUpdateTask.h
+ minecraft/MinecraftLoadAndCheck.h
+ minecraft/MinecraftLoadAndCheck.cpp
+ minecraft/MinecraftUpdate.h
+ minecraft/MinecraftUpdate.cpp
+ minecraft/MojangVersionFormat.cpp
+ minecraft/MojangVersionFormat.h
+ minecraft/Rule.cpp
+ minecraft/Rule.h
+ minecraft/OneSixVersionFormat.cpp
+ minecraft/OneSixVersionFormat.h
+ minecraft/OpSys.cpp
+ minecraft/OpSys.h
+ minecraft/ParseUtils.cpp
+ minecraft/ParseUtils.h
+ minecraft/ProfileUtils.cpp
+ minecraft/ProfileUtils.h
+ minecraft/Library.cpp
+ minecraft/Library.h
+ minecraft/MojangDownloadInfo.h
+ minecraft/VersionFile.cpp
+ minecraft/VersionFile.h
+ minecraft/VersionFilterData.h
+ minecraft/VersionFilterData.cpp
+ minecraft/Mod.h
+ minecraft/Mod.cpp
+ minecraft/ModsModel.h
+ minecraft/ModsModel.cpp
+ minecraft/SimpleModList.h
+ minecraft/SimpleModList.cpp
+ minecraft/World.h
+ minecraft/World.cpp
+ minecraft/WorldList.h
+ minecraft/WorldList.cpp
- # Assets
- minecraft/AssetsUtils.h
- minecraft/AssetsUtils.cpp
+ # Assets
+ minecraft/AssetsUtils.h
+ minecraft/AssetsUtils.cpp
- # Forge and all things forge related
- minecraft/forge/ForgeXzDownload.h
- minecraft/forge/ForgeXzDownload.cpp
+ # Forge and all things forge related
+ minecraft/forge/ForgeXzDownload.h
+ minecraft/forge/ForgeXzDownload.cpp
- # Skin upload utilities
- minecraft/SkinUpload.cpp
- minecraft/SkinUpload.h
- )
+ # Skin upload utilities
+ minecraft/SkinUpload.cpp
+ minecraft/SkinUpload.h
+ )
add_unit_test(GradleSpecifier
- SOURCES minecraft/GradleSpecifier_test.cpp
- LIBS MultiMC_logic
- )
+ SOURCES minecraft/GradleSpecifier_test.cpp
+ LIBS MultiMC_logic
+ )
add_unit_test(MojangVersionFormat
- SOURCES minecraft/MojangVersionFormat_test.cpp
- LIBS MultiMC_logic
- DATA minecraft/testdata
- )
+ SOURCES minecraft/MojangVersionFormat_test.cpp
+ LIBS MultiMC_logic
+ DATA minecraft/testdata
+ )
add_unit_test(Library
- SOURCES minecraft/Library_test.cpp
- LIBS MultiMC_logic
- )
+ SOURCES minecraft/Library_test.cpp
+ LIBS MultiMC_logic
+ )
# FIXME: shares data with FileSystem test
add_unit_test(SimpleModList
- SOURCES minecraft/SimpleModList_test.cpp
- DATA testdata
- LIBS MultiMC_logic
- )
+ SOURCES minecraft/SimpleModList_test.cpp
+ DATA testdata
+ LIBS MultiMC_logic
+ )
add_unit_test(ParseUtils
- SOURCES minecraft/ParseUtils_test.cpp
- LIBS MultiMC_logic
- )
+ 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
+ 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/SequentialTask.h
- tasks/SequentialTask.cpp
+ # Tasks
+ tasks/Task.h
+ tasks/Task.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
+ # 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
- )
+ 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
+ # 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
- )
+ SOURCES java/JavaVersion_test.cpp
+ LIBS MultiMC_logic
+ )
set(TRANSLATIONS_SOURCES
- translations/TranslationsModel.h
- translations/TranslationsModel.cpp
+ 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
+ # 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(META_SOURCES
- # Metadata sources
- meta/JsonFormat.cpp
- meta/JsonFormat.h
- meta/BaseEntity.cpp
- meta/BaseEntity.h
- meta/VersionList.cpp
- meta/VersionList.h
- meta/Version.cpp
- meta/Version.h
- meta/Index.cpp
- meta/Index.h
+ # Metadata sources
+ meta/JsonFormat.cpp
+ meta/JsonFormat.h
+ meta/BaseEntity.cpp
+ meta/BaseEntity.h
+ meta/VersionList.cpp
+ meta/VersionList.h
+ meta/Version.cpp
+ meta/Version.h
+ meta/Index.cpp
+ meta/Index.h
)
set(FTB_SOURCES
- modplatform/ftb/FtbPackFetchTask.h
- modplatform/ftb/FtbPackFetchTask.cpp
- modplatform/ftb/FtbPackInstallTask.h
- modplatform/ftb/FtbPackInstallTask.cpp
+ modplatform/ftb/FtbPackFetchTask.h
+ modplatform/ftb/FtbPackFetchTask.cpp
+ modplatform/ftb/FtbPackInstallTask.h
+ modplatform/ftb/FtbPackInstallTask.cpp
- modplatform/ftb/PackHelpers.h
+ modplatform/ftb/PackHelpers.h
)
set(FLAME_SOURCES
- # Flame
- modplatform/flame/PackManifest.h
- modplatform/flame/PackManifest.cpp
- modplatform/flame/FileResolvingTask.h
- modplatform/flame/FileResolvingTask.cpp
+ # Flame
+ modplatform/flame/PackManifest.h
+ modplatform/flame/PackManifest.cpp
+ modplatform/flame/FileResolvingTask.h
+ modplatform/flame/FileResolvingTask.cpp
)
add_unit_test(Index
- SOURCES meta/Index_test.cpp
- LIBS MultiMC_logic
- )
+ SOURCES meta/Index_test.cpp
+ LIBS MultiMC_logic
+ )
################################ COMPILE ################################
@@ -450,25 +450,25 @@ add_unit_test(Index
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}
- ${META_SOURCES}
- ${ICONS_SOURCES}
- ${FTB_SOURCES}
- ${FLAME_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}
+ ${META_SOURCES}
+ ${ICONS_SOURCES}
+ ${FTB_SOURCES}
+ ${FLAME_SOURCES}
)
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
@@ -485,7 +485,7 @@ target_include_directories(MultiMC_logic PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "$
# Install it
install(
- TARGETS MultiMC_logic
- RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
- LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
+ TARGETS MultiMC_logic
+ RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
+ LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
)
diff --git a/api/logic/Commandline.cpp b/api/logic/Commandline.cpp
index eac9db09..81ae7d0b 100644
--- a/api/logic/Commandline.cpp
+++ b/api/logic/Commandline.cpp
@@ -27,453 +27,453 @@ namespace Commandline
// commandline splitter
QStringList splitArgs(QString args)
{
- QStringList argv;
- QString current;
- bool escape = false;
- QChar inquotes;
- for (int i = 0; i < args.length(); i++)
- {
- QChar cchar = args.at(i);
+ QStringList argv;
+ QString current;
+ bool escape = false;
+ QChar inquotes;
+ for (int i = 0; i < args.length(); i++)
+ {
+ QChar cchar = args.at(i);
- // \ escaped
- if (escape)
- {
- current += cchar;
- escape = false;
- // in "quotes"
- }
- else if (!inquotes.isNull())
- {
- if (cchar == '\\')
- escape = true;
- else if (cchar == inquotes)
- inquotes = 0;
- else
- current += cchar;
- // otherwise
- }
- else
- {
- if (cchar == ' ')
- {
- if (!current.isEmpty())
- {
- argv << current;
- current.clear();
- }
- }
- else if (cchar == '"' || cchar == '\'')
- inquotes = cchar;
- else
- current += cchar;
- }
- }
- if (!current.isEmpty())
- argv << current;
- return argv;
+ // \ escaped
+ if (escape)
+ {
+ current += cchar;
+ escape = false;
+ // in "quotes"
+ }
+ else if (!inquotes.isNull())
+ {
+ if (cchar == '\\')
+ escape = true;
+ else if (cchar == inquotes)
+ inquotes = 0;
+ else
+ current += cchar;
+ // otherwise
+ }
+ else
+ {
+ if (cchar == ' ')
+ {
+ if (!current.isEmpty())
+ {
+ argv << current;
+ current.clear();
+ }
+ }
+ else if (cchar == '"' || cchar == '\'')
+ inquotes = cchar;
+ else
+ current += cchar;
+ }
+ }
+ if (!current.isEmpty())
+ argv << current;
+ return argv;
}
Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle)
{
- m_flagStyle = flagStyle;
- m_argStyle = argStyle;
+ m_flagStyle = flagStyle;
+ m_argStyle = argStyle;
}
// styles setter/getter
void Parser::setArgumentStyle(ArgumentStyle::Enum style)
{
- m_argStyle = style;
+ m_argStyle = style;
}
ArgumentStyle::Enum Parser::argumentStyle()
{
- return m_argStyle;
+ return m_argStyle;
}
void Parser::setFlagStyle(FlagStyle::Enum style)
{
- m_flagStyle = style;
+ m_flagStyle = style;
}
FlagStyle::Enum Parser::flagStyle()
{
- return m_flagStyle;
+ return m_flagStyle;
}
// setup methods
void Parser::addSwitch(QString name, bool def)
{
- if (m_params.contains(name))
- throw "Name not unique";
+ if (m_params.contains(name))
+ throw "Name not unique";
- OptionDef *param = new OptionDef;
- param->type = otSwitch;
- param->name = name;
- param->metavar = QString("<%1>").arg(name);
- param->def = def;
+ OptionDef *param = new OptionDef;
+ param->type = otSwitch;
+ param->name = name;
+ param->metavar = QString("<%1>").arg(name);
+ param->def = def;
- m_options[name] = param;
- m_params[name] = (CommonDef *)param;
- m_optionList.append(param);
+ m_options[name] = param;
+ m_params[name] = (CommonDef *)param;
+ m_optionList.append(param);
}
void Parser::addOption(QString name, QVariant def)
{
- if (m_params.contains(name))
- throw "Name not unique";
+ if (m_params.contains(name))
+ throw "Name not unique";
- OptionDef *param = new OptionDef;
- param->type = otOption;
- param->name = name;
- param->metavar = QString("<%1>").arg(name);
- param->def = def;
+ OptionDef *param = new OptionDef;
+ param->type = otOption;
+ param->name = name;
+ param->metavar = QString("<%1>").arg(name);
+ param->def = def;
- m_options[name] = param;
- m_params[name] = (CommonDef *)param;
- m_optionList.append(param);
+ m_options[name] = param;
+ m_params[name] = (CommonDef *)param;
+ m_optionList.append(param);
}
void Parser::addArgument(QString name, bool required, QVariant def)
{
- if (m_params.contains(name))
- throw "Name not unique";
+ if (m_params.contains(name))
+ throw "Name not unique";
- PositionalDef *param = new PositionalDef;
- param->name = name;
- param->def = def;
- param->required = required;
- param->metavar = name;
+ PositionalDef *param = new PositionalDef;
+ param->name = name;
+ param->def = def;
+ param->required = required;
+ param->metavar = name;
- m_positionals.append(param);
- m_params[name] = (CommonDef *)param;
+ m_positionals.append(param);
+ m_params[name] = (CommonDef *)param;
}
void Parser::addDocumentation(QString name, QString doc, QString metavar)
{
- if (!m_params.contains(name))
- throw "Name does not exist";
+ if (!m_params.contains(name))
+ throw "Name does not exist";
- CommonDef *param = m_params[name];
- param->doc = doc;
- if (!metavar.isNull())
- param->metavar = metavar;
+ CommonDef *param = m_params[name];
+ param->doc = doc;
+ if (!metavar.isNull())
+ param->metavar = metavar;
}
void Parser::addShortOpt(QString name, QChar flag)
{
- if (!m_params.contains(name))
- throw "Name does not exist";
- if (!m_options.contains(name))
- throw "Name is not an Option or Swtich";
+ if (!m_params.contains(name))
+ throw "Name does not exist";
+ if (!m_options.contains(name))
+ throw "Name is not an Option or Swtich";
- OptionDef *param = m_options[name];
- m_flags[flag] = param;
- param->flag = flag;
+ OptionDef *param = m_options[name];
+ m_flags[flag] = param;
+ param->flag = flag;
}
// help methods
QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags)
{
- QStringList help;
- help << compileUsage(progName, useFlags) << "\r\n";
+ QStringList help;
+ help << compileUsage(progName, useFlags) << "\r\n";
- // positionals
- if (!m_positionals.isEmpty())
- {
- help << "\r\n";
- help << "Positional arguments:\r\n";
- QListIterator it2(m_positionals);
- while (it2.hasNext())
- {
- PositionalDef *param = it2.next();
- help << " " << param->metavar;
- help << " " << QString(helpIndent - param->metavar.length() - 1, ' ');
- help << param->doc << "\r\n";
- }
- }
+ // positionals
+ if (!m_positionals.isEmpty())
+ {
+ help << "\r\n";
+ help << "Positional arguments:\r\n";
+ QListIterator it2(m_positionals);
+ while (it2.hasNext())
+ {
+ PositionalDef *param = it2.next();
+ help << " " << param->metavar;
+ help << " " << QString(helpIndent - param->metavar.length() - 1, ' ');
+ help << param->doc << "\r\n";
+ }
+ }
- // Options
- if (!m_optionList.isEmpty())
- {
- help << "\r\n";
- QString optPrefix, flagPrefix;
- getPrefix(optPrefix, flagPrefix);
+ // Options
+ if (!m_optionList.isEmpty())
+ {
+ help << "\r\n";
+ QString optPrefix, flagPrefix;
+ getPrefix(optPrefix, flagPrefix);
- help << "Options & Switches:\r\n";
- QListIterator it(m_optionList);
- while (it.hasNext())
- {
- OptionDef *option = it.next();
- help << " ";
- int nameLength = optPrefix.length() + option->name.length();
- if (!option->flag.isNull())
- {
- nameLength += 3 + flagPrefix.length();
- help << flagPrefix << option->flag << ", ";
- }
- help << optPrefix << option->name;
- if (option->type == otOption)
- {
- QString arg = QString("%1%2").arg(
- ((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar);
- nameLength += arg.length();
- help << arg;
- }
- help << " " << QString(helpIndent - nameLength - 1, ' ');
- help << option->doc << "\r\n";
- }
- }
+ help << "Options & Switches:\r\n";
+ QListIterator it(m_optionList);
+ while (it.hasNext())
+ {
+ OptionDef *option = it.next();
+ help << " ";
+ int nameLength = optPrefix.length() + option->name.length();
+ if (!option->flag.isNull())
+ {
+ nameLength += 3 + flagPrefix.length();
+ help << flagPrefix << option->flag << ", ";
+ }
+ help << optPrefix << option->name;
+ if (option->type == otOption)
+ {
+ QString arg = QString("%1%2").arg(
+ ((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar);
+ nameLength += arg.length();
+ help << arg;
+ }
+ help << " " << QString(helpIndent - nameLength - 1, ' ');
+ help << option->doc << "\r\n";
+ }
+ }
- return help.join("");
+ return help.join("");
}
QString Parser::compileUsage(QString progName, bool useFlags)
{
- QStringList usage;
- usage << "Usage: " << progName;
+ QStringList usage;
+ usage << "Usage: " << progName;
- QString optPrefix, flagPrefix;
- getPrefix(optPrefix, flagPrefix);
+ QString optPrefix, flagPrefix;
+ getPrefix(optPrefix, flagPrefix);
- // options
- QListIterator it(m_optionList);
- while (it.hasNext())
- {
- OptionDef *option = it.next();
- usage << " [";
- if (!option->flag.isNull() && useFlags)
- usage << flagPrefix << option->flag;
- else
- usage << optPrefix << option->name;
- if (option->type == otOption)
- usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar;
- usage << "]";
- }
+ // options
+ QListIterator it(m_optionList);
+ while (it.hasNext())
+ {
+ OptionDef *option = it.next();
+ usage << " [";
+ if (!option->flag.isNull() && useFlags)
+ usage << flagPrefix << option->flag;
+ else
+ usage << optPrefix << option->name;
+ if (option->type == otOption)
+ usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar;
+ usage << "]";
+ }
- // arguments
- QListIterator it2(m_positionals);
- while (it2.hasNext())
- {
- PositionalDef *param = it2.next();
- usage << " " << (param->required ? "<" : "[");
- usage << param->metavar;
- usage << (param->required ? ">" : "]");
- }
+ // arguments
+ QListIterator it2(m_positionals);
+ while (it2.hasNext())
+ {
+ PositionalDef *param = it2.next();
+ usage << " " << (param->required ? "<" : "[");
+ usage << param->metavar;
+ usage << (param->required ? ">" : "]");
+ }
- return usage.join("");
+ return usage.join("");
}
// parsing
QHash Parser::parse(QStringList argv)
{
- QHash map;
+ QHash map;
- QStringListIterator it(argv);
- QString programName = it.next();
+ QStringListIterator it(argv);
+ QString programName = it.next();
- QString optionPrefix;
- QString flagPrefix;
- QListIterator positionals(m_positionals);
- QStringList expecting;
+ QString optionPrefix;
+ QString flagPrefix;
+ QListIterator positionals(m_positionals);
+ QStringList expecting;
- getPrefix(optionPrefix, flagPrefix);
+ getPrefix(optionPrefix, flagPrefix);
- while (it.hasNext())
- {
- QString arg = it.next();
+ while (it.hasNext())
+ {
+ QString arg = it.next();
- if (!expecting.isEmpty())
- // we were expecting an argument
- {
- QString name = expecting.first();
+ if (!expecting.isEmpty())
+ // we were expecting an argument
+ {
+ QString name = expecting.first();
/*
- if (map.contains(name))
- throw ParsingError(
- QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
+ if (map.contains(name))
+ throw ParsingError(
+ QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
*/
- map[name] = QVariant(arg);
+ map[name] = QVariant(arg);
- expecting.removeFirst();
- continue;
- }
+ expecting.removeFirst();
+ continue;
+ }
- if (arg.startsWith(optionPrefix))
- // we have an option
- {
- // qDebug("Found option %s", qPrintable(arg));
+ if (arg.startsWith(optionPrefix))
+ // we have an option
+ {
+ // qDebug("Found option %s", qPrintable(arg));
- QString name = arg.mid(optionPrefix.length());
- QString equals;
+ QString name = arg.mid(optionPrefix.length());
+ QString equals;
- if ((m_argStyle == ArgumentStyle::Equals ||
- m_argStyle == ArgumentStyle::SpaceAndEquals) &&
- name.contains("="))
- {
- int i = name.indexOf("=");
- equals = name.mid(i + 1);
- name = name.left(i);
- }
+ if ((m_argStyle == ArgumentStyle::Equals ||
+ m_argStyle == ArgumentStyle::SpaceAndEquals) &&
+ name.contains("="))
+ {
+ int i = name.indexOf("=");
+ equals = name.mid(i + 1);
+ name = name.left(i);
+ }
- if (m_options.contains(name))
- {
- /*
- if (map.contains(name))
- throw ParsingError(QString("Option %2%1 was given multiple times")
- .arg(name, optionPrefix));
+ if (m_options.contains(name))
+ {
+ /*
+ if (map.contains(name))
+ throw ParsingError(QString("Option %2%1 was given multiple times")
+ .arg(name, optionPrefix));
*/
- OptionDef *option = m_options[name];
- if (option->type == otSwitch)
- map[name] = true;
- else // if (option->type == otOption)
- {
- if (m_argStyle == ArgumentStyle::Space)
- expecting.append(name);
- else if (!equals.isNull())
- map[name] = equals;
- else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
- expecting.append(name);
- else
- throw ParsingError(QString("Option %2%1 reqires an argument.")
- .arg(name, optionPrefix));
- }
+ OptionDef *option = m_options[name];
+ if (option->type == otSwitch)
+ map[name] = true;
+ else // if (option->type == otOption)
+ {
+ if (m_argStyle == ArgumentStyle::Space)
+ expecting.append(name);
+ else if (!equals.isNull())
+ map[name] = equals;
+ else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
+ expecting.append(name);
+ else
+ throw ParsingError(QString("Option %2%1 reqires an argument.")
+ .arg(name, optionPrefix));
+ }
- continue;
- }
+ continue;
+ }
- throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix));
- }
+ throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix));
+ }
- if (arg.startsWith(flagPrefix))
- // we have (a) flag(s)
- {
- // qDebug("Found flags %s", qPrintable(arg));
+ if (arg.startsWith(flagPrefix))
+ // we have (a) flag(s)
+ {
+ // qDebug("Found flags %s", qPrintable(arg));
- QString flags = arg.mid(flagPrefix.length());
- QString equals;
+ QString flags = arg.mid(flagPrefix.length());
+ QString equals;
- if ((m_argStyle == ArgumentStyle::Equals ||
- m_argStyle == ArgumentStyle::SpaceAndEquals) &&
- flags.contains("="))
- {
- int i = flags.indexOf("=");
- equals = flags.mid(i + 1);
- flags = flags.left(i);
- }
+ if ((m_argStyle == ArgumentStyle::Equals ||
+ m_argStyle == ArgumentStyle::SpaceAndEquals) &&
+ flags.contains("="))
+ {
+ int i = flags.indexOf("=");
+ equals = flags.mid(i + 1);
+ flags = flags.left(i);
+ }
- for (int i = 0; i < flags.length(); i++)
- {
- QChar flag = flags.at(i);
+ for (int i = 0; i < flags.length(); i++)
+ {
+ QChar flag = flags.at(i);
- if (!m_flags.contains(flag))
- throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
+ if (!m_flags.contains(flag))
+ throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
- OptionDef *option = m_flags[flag];
+ OptionDef *option = m_flags[flag];
/*
- if (map.contains(option->name))
- throw ParsingError(QString("Option %2%1 was given multiple times")
- .arg(option->name, optionPrefix));
+ if (map.contains(option->name))
+ throw ParsingError(QString("Option %2%1 was given multiple times")
+ .arg(option->name, optionPrefix));
*/
- if (option->type == otSwitch)
- map[option->name] = true;
- else // if (option->type == otOption)
- {
- if (m_argStyle == ArgumentStyle::Space)
- expecting.append(option->name);
- else if (!equals.isNull())
- if (i == flags.length() - 1)
- map[option->name] = equals;
- else
- throw ParsingError(QString("Flag %4%2 of Argument-requiring Option "
- "%1 not last flag in %4%3")
- .arg(option->name, flag, flags, flagPrefix));
- else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
- expecting.append(option->name);
- else
- throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)")
- .arg(option->name, flag, flagPrefix));
- }
- }
+ if (option->type == otSwitch)
+ map[option->name] = true;
+ else // if (option->type == otOption)
+ {
+ if (m_argStyle == ArgumentStyle::Space)
+ expecting.append(option->name);
+ else if (!equals.isNull())
+ if (i == flags.length() - 1)
+ map[option->name] = equals;
+ else
+ throw ParsingError(QString("Flag %4%2 of Argument-requiring Option "
+ "%1 not last flag in %4%3")
+ .arg(option->name, flag, flags, flagPrefix));
+ else if (m_argStyle == ArgumentStyle::SpaceAndEquals)
+ expecting.append(option->name);
+ else
+ throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)")
+ .arg(option->name, flag, flagPrefix));
+ }
+ }
- continue;
- }
+ continue;
+ }
- // must be a positional argument
- if (!positionals.hasNext())
- throw ParsingError(QString("Don't know what to do with '%1'").arg(arg));
+ // must be a positional argument
+ if (!positionals.hasNext())
+ throw ParsingError(QString("Don't know what to do with '%1'").arg(arg));
- PositionalDef *param = positionals.next();
+ PositionalDef *param = positionals.next();
- map[param->name] = arg;
- }
+ map[param->name] = arg;
+ }
- // check if we're missing something
- if (!expecting.isEmpty())
- throw ParsingError(QString("Was still expecting arguments for %2%1").arg(
- expecting.join(QString(", ") + optionPrefix), optionPrefix));
+ // check if we're missing something
+ if (!expecting.isEmpty())
+ throw ParsingError(QString("Was still expecting arguments for %2%1").arg(
+ expecting.join(QString(", ") + optionPrefix), optionPrefix));
- while (positionals.hasNext())
- {
- PositionalDef *param = positionals.next();
- if (param->required)
- throw ParsingError(
- QString("Missing required positional argument '%1'").arg(param->name));
- else
- map[param->name] = param->def;
- }
+ while (positionals.hasNext())
+ {
+ PositionalDef *param = positionals.next();
+ if (param->required)
+ throw ParsingError(
+ QString("Missing required positional argument '%1'").arg(param->name));
+ else
+ map[param->name] = param->def;
+ }
- // fill out gaps
- QListIterator iter(m_optionList);
- while (iter.hasNext())
- {
- OptionDef *option = iter.next();
- if (!map.contains(option->name))
- map[option->name] = option->def;
- }
+ // fill out gaps
+ QListIterator iter(m_optionList);
+ while (iter.hasNext())
+ {
+ OptionDef *option = iter.next();
+ if (!map.contains(option->name))
+ map[option->name] = option->def;
+ }
- return map;
+ return map;
}
// clear defs
void Parser::clear()
{
- m_flags.clear();
- m_params.clear();
- m_options.clear();
+ m_flags.clear();
+ m_params.clear();
+ m_options.clear();
- QMutableListIterator it(m_optionList);
- while (it.hasNext())
- {
- OptionDef *option = it.next();
- it.remove();
- delete option;
- }
+ QMutableListIterator it(m_optionList);
+ while (it.hasNext())
+ {
+ OptionDef *option = it.next();
+ it.remove();
+ delete option;
+ }
- QMutableListIterator it2(m_positionals);
- while (it2.hasNext())
- {
- PositionalDef *arg = it2.next();
- it2.remove();
- delete arg;
- }
+ QMutableListIterator it2(m_positionals);
+ while (it2.hasNext())
+ {
+ PositionalDef *arg = it2.next();
+ it2.remove();
+ delete arg;
+ }
}
// Destructor
Parser::~Parser()
{
- clear();
+ clear();
}
// getPrefix
void Parser::getPrefix(QString &opt, QString &flag)
{
- if (m_flagStyle == FlagStyle::Windows)
- opt = flag = "/";
- else if (m_flagStyle == FlagStyle::Unix)
- opt = flag = "-";
- // else if (m_flagStyle == FlagStyle::GNU)
- else
- {
- opt = "--";
- flag = "-";
- }
+ if (m_flagStyle == FlagStyle::Windows)
+ opt = flag = "/";
+ else if (m_flagStyle == FlagStyle::Unix)
+ opt = flag = "-";
+ // else if (m_flagStyle == FlagStyle::GNU)
+ else
+ {
+ opt = "--";
+ flag = "-";
+ }
}
// ParsingError
diff --git a/api/logic/Commandline.h b/api/logic/Commandline.h
index c8c8be29..586d644f 100644
--- a/api/logic/Commandline.h
+++ b/api/logic/Commandline.h
@@ -51,13 +51,13 @@ namespace FlagStyle
{
enum Enum
{
- GNU, /**< --option and -o (GNU Style) */
- Unix, /**< -option and -o (Unix Style) */
- Windows, /**< /option and /o (Windows Style) */
+ GNU, /**< --option and -o (GNU Style) */
+ Unix, /**< -option and -o (Unix Style) */
+ Windows, /**< /option and /o (Windows Style) */
#ifdef Q_OS_WIN32
- Default = Windows
+ Default = Windows
#else
- Default = GNU
+ Default = GNU
#endif
};
}
@@ -69,13 +69,13 @@ namespace ArgumentStyle
{
enum Enum
{
- Space, /**< --option=value */
- Equals, /**< --option value */
- SpaceAndEquals, /**< --option[= ]value */
+ Space, /**< --option=value */
+ Equals, /**< --option value */
+ SpaceAndEquals, /**< --option[= ]value */
#ifdef Q_OS_WIN32
- Default = Equals
+ Default = Equals
#else
- Default = SpaceAndEquals
+ Default = SpaceAndEquals
#endif
};
}
@@ -86,7 +86,7 @@ enum Enum
class MULTIMC_LOGIC_EXPORT ParsingError : public std::runtime_error
{
public:
- ParsingError(const QString &what);
+ ParsingError(const QString &what);
};
/**
@@ -95,158 +95,158 @@ public:
class MULTIMC_LOGIC_EXPORT Parser
{
public:
- /**
- * @brief Parser constructor
- * @param flagStyle the FlagStyle to use in this Parser
- * @param argStyle the ArgumentStyle to use in this Parser
- */
- Parser(FlagStyle::Enum flagStyle = FlagStyle::Default,
- ArgumentStyle::Enum argStyle = ArgumentStyle::Default);
+ /**
+ * @brief Parser constructor
+ * @param flagStyle the FlagStyle to use in this Parser
+ * @param argStyle the ArgumentStyle to use in this Parser
+ */
+ Parser(FlagStyle::Enum flagStyle = FlagStyle::Default,
+ ArgumentStyle::Enum argStyle = ArgumentStyle::Default);
- /**
- * @brief set the flag style
- * @param style
- */
- void setFlagStyle(FlagStyle::Enum style);
+ /**
+ * @brief set the flag style
+ * @param style
+ */
+ void setFlagStyle(FlagStyle::Enum style);
- /**
- * @brief get the flag style
- * @return
- */
- FlagStyle::Enum flagStyle();
+ /**
+ * @brief get the flag style
+ * @return
+ */
+ FlagStyle::Enum flagStyle();
- /**
- * @brief set the argument style
- * @param style
- */
- void setArgumentStyle(ArgumentStyle::Enum style);
+ /**
+ * @brief set the argument style
+ * @param style
+ */
+ void setArgumentStyle(ArgumentStyle::Enum style);
- /**
- * @brief get the argument style
- * @return
- */
- ArgumentStyle::Enum argumentStyle();
+ /**
+ * @brief get the argument style
+ * @return
+ */
+ ArgumentStyle::Enum argumentStyle();
- /**
- * @brief define a boolean switch
- * @param name the parameter name
- * @param def the default value
- */
- void addSwitch(QString name, bool def = false);
+ /**
+ * @brief define a boolean switch
+ * @param name the parameter name
+ * @param def the default value
+ */
+ void addSwitch(QString name, bool def = false);
- /**
- * @brief define an option that takes an additional argument
- * @param name the parameter name
- * @param def the default value
- */
- void addOption(QString name, QVariant def = QVariant());
+ /**
+ * @brief define an option that takes an additional argument
+ * @param name the parameter name
+ * @param def the default value
+ */
+ void addOption(QString name, QVariant def = QVariant());
- /**
- * @brief define a positional argument
- * @param name the parameter name
- * @param required wether this argument is required
- * @param def the default value
- */
- void addArgument(QString name, bool required = true, QVariant def = QVariant());
+ /**
+ * @brief define a positional argument
+ * @param name the parameter name
+ * @param required wether this argument is required
+ * @param def the default value
+ */
+ void addArgument(QString name, bool required = true, QVariant def = QVariant());
- /**
- * @brief adds a flag to an existing parameter
- * @param name the (existing) parameter name
- * @param flag the flag character
- * @see addSwitch addArgument addOption
- * Note: any one parameter can only have one flag
- */
- void addShortOpt(QString name, QChar flag);
+ /**
+ * @brief adds a flag to an existing parameter
+ * @param name the (existing) parameter name
+ * @param flag the flag character
+ * @see addSwitch addArgument addOption
+ * Note: any one parameter can only have one flag
+ */
+ void addShortOpt(QString name, QChar flag);
- /**
- * @brief adds documentation to a Parameter
- * @param name the parameter name
- * @param metavar a string to be displayed as placeholder for the value
- * @param doc a QString containing the documentation
- * Note: on positional arguments, metavar replaces the name as displayed.
- * on options , metavar replaces the value placeholder
- */
- void addDocumentation(QString name, QString doc, QString metavar = QString());
+ /**
+ * @brief adds documentation to a Parameter
+ * @param name the parameter name
+ * @param metavar a string to be displayed as placeholder for the value
+ * @param doc a QString containing the documentation
+ * Note: on positional arguments, metavar replaces the name as displayed.
+ * on options , metavar replaces the value placeholder
+ */
+ void addDocumentation(QString name, QString doc, QString metavar = QString());
- /**
- * @brief generate a help message
- * @param progName the program name to use in the help message
- * @param helpIndent how much the parameter documentation should be indented
- * @param flagsInUsage whether we should use flags instead of options in the usage
- * @return a help message
- */
- QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true);
+ /**
+ * @brief generate a help message
+ * @param progName the program name to use in the help message
+ * @param helpIndent how much the parameter documentation should be indented
+ * @param flagsInUsage whether we should use flags instead of options in the usage
+ * @return a help message
+ */
+ QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true);
- /**
- * @brief generate a short usage message
- * @param progName the program name to use in the usage message
- * @param useFlags whether we should use flags instead of options
- * @return a usage message
- */
- QString compileUsage(QString progName, bool useFlags = true);
+ /**
+ * @brief generate a short usage message
+ * @param progName the program name to use in the usage message
+ * @param useFlags whether we should use flags instead of options
+ * @return a usage message
+ */
+ QString compileUsage(QString progName, bool useFlags = true);
- /**
- * @brief parse
- * @param argv a QStringList containing the program ARGV
- * @return a QHash mapping argument names to their values
- */
- QHash parse(QStringList argv);
+ /**
+ * @brief parse
+ * @param argv a QStringList containing the program ARGV
+ * @return a QHash mapping argument names to their values
+ */
+ QHash parse(QStringList argv);
- /**
- * @brief clear all definitions
- */
- void clear();
+ /**
+ * @brief clear all definitions
+ */
+ void clear();
- ~Parser();
+ ~Parser();
private:
- FlagStyle::Enum m_flagStyle;
- ArgumentStyle::Enum m_argStyle;
+ FlagStyle::Enum m_flagStyle;
+ ArgumentStyle::Enum m_argStyle;
- enum OptionType
- {
- otSwitch,
- otOption
- };
+ enum OptionType
+ {
+ otSwitch,
+ otOption
+ };
- // Important: the common part MUST BE COMMON ON ALL THREE structs
- struct CommonDef
- {
- QString name;
- QString doc;
- QString metavar;
- QVariant def;
- };
+ // Important: the common part MUST BE COMMON ON ALL THREE structs
+ struct CommonDef
+ {
+ QString name;
+ QString doc;
+ QString metavar;
+ QVariant def;
+ };
- struct OptionDef
- {
- // common
- QString name;
- QString doc;
- QString metavar;
- QVariant def;
- // option
- OptionType type;
- QChar flag;
- };
+ struct OptionDef
+ {
+ // common
+ QString name;
+ QString doc;
+ QString metavar;
+ QVariant def;
+ // option
+ OptionType type;
+ QChar flag;
+ };
- struct PositionalDef
- {
- // common
- QString name;
- QString doc;
- QString metavar;
- QVariant def;
- // positional
- bool required;
- };
+ struct PositionalDef
+ {
+ // common
+ QString name;
+ QString doc;
+ QString metavar;
+ QVariant def;
+ // positional
+ bool required;
+ };
- QHash m_options;
- QHash m_flags;
- QHash m_params;
- QList m_positionals;
- QList m_optionList;
+ QHash m_options;
+ QHash m_flags;
+ QHash m_params;
+ QList m_positionals;
+ QList m_optionList;
- void getPrefix(QString &opt, QString &flag);
+ void getPrefix(QString &opt, QString &flag);
};
}
diff --git a/api/logic/DefaultVariable.h b/api/logic/DefaultVariable.h
index 38d7ecc2..5c069bd3 100644
--- a/api/logic/DefaultVariable.h
+++ b/api/logic/DefaultVariable.h
@@ -4,32 +4,32 @@ template
class DefaultVariable
{
public:
- DefaultVariable(const T & value)
- {
- defaultValue = value;
- }
- DefaultVariable & operator =(const T & value)
- {
- currentValue = value;
- is_default = currentValue == defaultValue;
- is_explicit = true;
- return *this;
- }
- operator const T &() const
- {
- return is_default ? defaultValue : currentValue;
- }
- bool isDefault() const
- {
- return is_default;
- }
- bool isExplicit() const
- {
- return is_explicit;
- }
+ DefaultVariable(const T & value)
+ {
+ defaultValue = value;
+ }
+ DefaultVariable & operator =(const T & value)
+ {
+ currentValue = value;
+ is_default = currentValue == defaultValue;
+ is_explicit = true;
+ return *this;
+ }
+ operator const T &() const
+ {
+ return is_default ? defaultValue : currentValue;
+ }
+ bool isDefault() const
+ {
+ return is_default;
+ }
+ bool isExplicit() const
+ {
+ return is_explicit;
+ }
private:
- T currentValue;
- T defaultValue;
- bool is_default = true;
- bool is_explicit = false;
+ T currentValue;
+ T defaultValue;
+ bool is_default = true;
+ bool is_explicit = false;
};
diff --git a/api/logic/Env.cpp b/api/logic/Env.cpp
index 04a5ab23..73cad2e9 100644
--- a/api/logic/Env.cpp
+++ b/api/logic/Env.cpp
@@ -15,11 +15,11 @@
struct Env::Private
{
- QNetworkAccessManager m_qnam;
- shared_qobject_ptr m_metacache;
- std::shared_ptr m_iconlist;
- shared_qobject_ptr m_metadataIndex;
- QString m_jarsPath;
+ QNetworkAccessManager m_qnam;
+ shared_qobject_ptr m_metacache;
+ std::shared_ptr m_iconlist;
+ shared_qobject_ptr m_metadataIndex;
+ QString m_jarsPath;
};
static Env * instance;
@@ -30,152 +30,152 @@ static Env * instance;
Env::Env()
{
- d = new Private();
+ d = new Private();
}
Env::~Env()
{
- delete d;
+ delete d;
}
Env& Env::Env::getInstance()
{
- if(!instance)
- {
- instance = new Env();
- }
- return *instance;
+ if(!instance)
+ {
+ instance = new Env();
+ }
+ return *instance;
}
void Env::dispose()
{
- delete instance;
- instance = nullptr;
+ delete instance;
+ instance = nullptr;
}
shared_qobject_ptr< HttpMetaCache > Env::metacache()
{
- return d->m_metacache;
+ return d->m_metacache;
}
QNetworkAccessManager& Env::qnam() const
{
- return d->m_qnam;
+ return d->m_qnam;
}
std::shared_ptr Env::icons()
{
- return d->m_iconlist;
+ return d->m_iconlist;
}
void Env::registerIconList(std::shared_ptr iconlist)
{
- d->m_iconlist = iconlist;
+ d->m_iconlist = iconlist;
}
shared_qobject_ptr Env::metadataIndex()
{
- if (!d->m_metadataIndex)
- {
- d->m_metadataIndex.reset(new Meta::Index());
- }
- return d->m_metadataIndex;
+ if (!d->m_metadataIndex)
+ {
+ d->m_metadataIndex.reset(new Meta::Index());
+ }
+ return d->m_metadataIndex;
}
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());
- m_metacache->addBase("versions", QDir("versions").absolutePath());
- m_metacache->addBase("libraries", QDir("libraries").absolutePath());
- m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
- m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
- m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
- m_metacache->addBase("general", QDir("cache").absolutePath());
- m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
- m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
- m_metacache->addBase("root", QDir::currentPath());
- m_metacache->addBase("translations", QDir("translations").absolutePath());
- m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
- m_metacache->addBase("meta", QDir("meta").absolutePath());
- m_metacache->Load();
+ 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());
+ m_metacache->addBase("versions", QDir("versions").absolutePath());
+ m_metacache->addBase("libraries", QDir("libraries").absolutePath());
+ m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
+ m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
+ m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
+ m_metacache->addBase("general", QDir("cache").absolutePath());
+ m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
+ m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
+ m_metacache->addBase("root", QDir::currentPath());
+ m_metacache->addBase("translations", QDir("translations").absolutePath());
+ m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
+ m_metacache->addBase("meta", QDir("meta").absolutePath());
+ m_metacache->Load();
}
void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
{
- // Set the application proxy settings.
- if (proxyTypeStr == "SOCKS5")
- {
- QNetworkProxy::setApplicationProxy(
- QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
- }
- else if (proxyTypeStr == "HTTP")
- {
- QNetworkProxy::setApplicationProxy(
- QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
- }
- else if (proxyTypeStr == "None")
- {
- // If we have no proxy set, set no proxy and return.
- QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
- }
- else
- {
- // If we have "Default" selected, set Qt to use the system proxy settings.
- QNetworkProxyFactory::setUseSystemConfiguration(true);
- }
+ // Set the application proxy settings.
+ if (proxyTypeStr == "SOCKS5")
+ {
+ QNetworkProxy::setApplicationProxy(
+ QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
+ }
+ else if (proxyTypeStr == "HTTP")
+ {
+ QNetworkProxy::setApplicationProxy(
+ QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
+ }
+ else if (proxyTypeStr == "None")
+ {
+ // If we have no proxy set, set no proxy and return.
+ QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
+ }
+ else
+ {
+ // If we have "Default" selected, set Qt to use the system proxy settings.
+ QNetworkProxyFactory::setUseSystemConfiguration(true);
+ }
- qDebug() << "Detecting proxy settings...";
- QNetworkProxy proxy = QNetworkProxy::applicationProxy();
- d->m_qnam.setProxy(proxy);
- QString proxyDesc;
- if (proxy.type() == QNetworkProxy::NoProxy)
- {
- qDebug() << "Using no proxy is an option!";
- return;
- }
- switch (proxy.type())
- {
- case QNetworkProxy::DefaultProxy:
- proxyDesc = "Default proxy: ";
- break;
- case QNetworkProxy::Socks5Proxy:
- proxyDesc = "Socks5 proxy: ";
- break;
- case QNetworkProxy::HttpProxy:
- proxyDesc = "HTTP proxy: ";
- break;
- case QNetworkProxy::HttpCachingProxy:
- proxyDesc = "HTTP caching: ";
- break;
- case QNetworkProxy::FtpCachingProxy:
- proxyDesc = "FTP caching: ";
- break;
- default:
- proxyDesc = "DERP proxy: ";
- break;
- }
- proxyDesc += QString("%3@%1:%2 pass %4")
- .arg(proxy.hostName())
- .arg(proxy.port())
- .arg(proxy.user())
- .arg(proxy.password());
- qDebug() << proxyDesc;
+ qDebug() << "Detecting proxy settings...";
+ QNetworkProxy proxy = QNetworkProxy::applicationProxy();
+ d->m_qnam.setProxy(proxy);
+ QString proxyDesc;
+ if (proxy.type() == QNetworkProxy::NoProxy)
+ {
+ qDebug() << "Using no proxy is an option!";
+ return;
+ }
+ switch (proxy.type())
+ {
+ case QNetworkProxy::DefaultProxy:
+ proxyDesc = "Default proxy: ";
+ break;
+ case QNetworkProxy::Socks5Proxy:
+ proxyDesc = "Socks5 proxy: ";
+ break;
+ case QNetworkProxy::HttpProxy:
+ proxyDesc = "HTTP proxy: ";
+ break;
+ case QNetworkProxy::HttpCachingProxy:
+ proxyDesc = "HTTP caching: ";
+ break;
+ case QNetworkProxy::FtpCachingProxy:
+ proxyDesc = "FTP caching: ";
+ break;
+ default:
+ proxyDesc = "DERP proxy: ";
+ break;
+ }
+ proxyDesc += QString("%3@%1:%2 pass %4")
+ .arg(proxy.hostName())
+ .arg(proxy.port())
+ .arg(proxy.user())
+ .arg(proxy.password());
+ qDebug() << proxyDesc;
}
QString Env::getJarsPath()
{
- if(d->m_jarsPath.isEmpty())
- {
- return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
- }
- return d->m_jarsPath;
+ if(d->m_jarsPath.isEmpty())
+ {
+ return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
+ }
+ return d->m_jarsPath;
}
void Env::setJarsPath(const QString& path)
{
- d->m_jarsPath = path;
+ d->m_jarsPath = path;
}
diff --git a/api/logic/Env.h b/api/logic/Env.h
index 276d762d..4d9ec139 100644
--- a/api/logic/Env.h
+++ b/api/logic/Env.h
@@ -20,40 +20,40 @@ class Index;
}
#if defined(ENV)
- #undef ENV
+ #undef ENV
#endif
#define ENV (Env::getInstance())
class MULTIMC_LOGIC_EXPORT Env
{
- friend class MultiMC;
+ friend class MultiMC;
private:
- struct Private;
- Env();
- ~Env();
- static void dispose();
+ struct Private;
+ Env();
+ ~Env();
+ static void dispose();
public:
- static Env& getInstance();
+ static Env& getInstance();
- QNetworkAccessManager &qnam() const;
+ QNetworkAccessManager &qnam() const;
- shared_qobject_ptr metacache();
+ shared_qobject_ptr metacache();
- std::shared_ptr icons();
+ std::shared_ptr icons();
- /// init the cache. FIXME: possible future hook point
- void initHttpMetaCache();
+ /// init the cache. FIXME: possible future hook point
+ void initHttpMetaCache();
- /// Updates the application proxy settings from the settings object.
- void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
+ /// Updates the application proxy settings from the settings object.
+ void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
- void registerIconList(std::shared_ptr iconlist);
+ void registerIconList(std::shared_ptr iconlist);
- shared_qobject_ptr metadataIndex();
+ shared_qobject_ptr metadataIndex();
- QString getJarsPath();
- void setJarsPath(const QString & path);
+ QString getJarsPath();
+ void setJarsPath(const QString & path);
protected:
- Private * d;
+ Private * d;
};
diff --git a/api/logic/Exception.h b/api/logic/Exception.h
index 30c7aa45..9400b3f8 100644
--- a/api/logic/Exception.h
+++ b/api/logic/Exception.h
@@ -11,24 +11,24 @@
class MULTIMC_LOGIC_EXPORT Exception : public std::exception
{
public:
- Exception(const QString &message) : std::exception(), m_message(message)
- {
- qCritical() << "Exception:" << message;
- }
- Exception(const Exception &other)
- : std::exception(), m_message(other.cause())
- {
- }
- virtual ~Exception() noexcept {}
- const char *what() const noexcept
- {
- return m_message.toLatin1().constData();
- }
- QString cause() const
- {
- return m_message;
- }
+ Exception(const QString &message) : std::exception(), m_message(message)
+ {
+ qCritical() << "Exception:" << message;
+ }
+ Exception(const Exception &other)
+ : std::exception(), m_message(other.cause())
+ {
+ }
+ virtual ~Exception() noexcept {}
+ const char *what() const noexcept
+ {
+ return m_message.toLatin1().constData();
+ }
+ QString cause() const
+ {
+ return m_message;
+ }
private:
- QString m_message;
+ QString m_message;
};
diff --git a/api/logic/FileSystem.cpp b/api/logic/FileSystem.cpp
index aef35375..1d8b290d 100644
--- a/api/logic/FileSystem.cpp
+++ b/api/logic/FileSystem.cpp
@@ -12,262 +12,262 @@
#include
#if defined Q_OS_WIN32
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
#else
- #include
+ #include
#endif
namespace FS {
void ensureExists(const QDir &dir)
{
- if (!QDir().mkpath(dir.absolutePath()))
- {
- throw FileSystemException("Unable to create folder " + dir.dirName() + " (" +
- dir.absolutePath() + ")");
- }
+ if (!QDir().mkpath(dir.absolutePath()))
+ {
+ throw FileSystemException("Unable to create folder " + dir.dirName() + " (" +
+ dir.absolutePath() + ")");
+ }
}
void write(const QString &filename, const QByteArray &data)
{
- ensureExists(QFileInfo(filename).dir());
- QSaveFile file(filename);
- if (!file.open(QSaveFile::WriteOnly))
- {
- throw FileSystemException("Couldn't open " + filename + " for writing: " +
- file.errorString());
- }
- if (data.size() != file.write(data))
- {
- throw FileSystemException("Error writing data to " + filename + ": " +
- file.errorString());
- }
- if (!file.commit())
- {
- throw FileSystemException("Error while committing data to " + filename + ": " +
- file.errorString());
- }
+ ensureExists(QFileInfo(filename).dir());
+ QSaveFile file(filename);
+ if (!file.open(QSaveFile::WriteOnly))
+ {
+ throw FileSystemException("Couldn't open " + filename + " for writing: " +
+ file.errorString());
+ }
+ if (data.size() != file.write(data))
+ {
+ throw FileSystemException("Error writing data to " + filename + ": " +
+ file.errorString());
+ }
+ if (!file.commit())
+ {
+ throw FileSystemException("Error while committing data to " + filename + ": " +
+ file.errorString());
+ }
}
QByteArray read(const QString &filename)
{
- QFile file(filename);
- if (!file.open(QFile::ReadOnly))
- {
- throw FileSystemException("Unable to open " + filename + " for reading: " +
- file.errorString());
- }
- const qint64 size = file.size();
- QByteArray data(int(size), 0);
- const qint64 ret = file.read(data.data(), size);
- if (ret == -1 || ret != size)
- {
- throw FileSystemException("Error reading data from " + filename + ": " +
- file.errorString());
- }
- return data;
+ QFile file(filename);
+ if (!file.open(QFile::ReadOnly))
+ {
+ throw FileSystemException("Unable to open " + filename + " for reading: " +
+ file.errorString());
+ }
+ const qint64 size = file.size();
+ QByteArray data(int(size), 0);
+ const qint64 ret = file.read(data.data(), size);
+ if (ret == -1 || ret != size)
+ {
+ throw FileSystemException("Error reading data from " + filename + ": " +
+ file.errorString());
+ }
+ return data;
}
bool updateTimestamp(const QString& filename)
{
#ifdef Q_OS_WIN32
- std::wstring filename_utf_16 = filename.toStdWString();
- return (_wutime64(filename_utf_16.c_str(), nullptr) == 0);
+ std::wstring filename_utf_16 = filename.toStdWString();
+ return (_wutime64(filename_utf_16.c_str(), nullptr) == 0);
#else
- QByteArray filenameBA = QFile::encodeName(filename);
- return (utime(filenameBA.data(), nullptr) == 0);
+ QByteArray filenameBA = QFile::encodeName(filename);
+ return (utime(filenameBA.data(), nullptr) == 0);
#endif
}
bool ensureFilePathExists(QString filenamepath)
{
- QFileInfo a(filenamepath);
- QDir dir;
- QString ensuredPath = a.path();
- bool success = dir.mkpath(ensuredPath);
- return success;
+ QFileInfo a(filenamepath);
+ QDir dir;
+ QString ensuredPath = a.path();
+ bool success = dir.mkpath(ensuredPath);
+ return success;
}
bool ensureFolderPathExists(QString foldernamepath)
{
- QFileInfo a(foldernamepath);
- QDir dir;
- QString ensuredPath = a.filePath();
- bool success = dir.mkpath(ensuredPath);
- return success;
+ QFileInfo a(foldernamepath);
+ QDir dir;
+ QString ensuredPath = a.filePath();
+ bool success = dir.mkpath(ensuredPath);
+ return success;
}
bool copy::operator()(const QString &offset)
{
- //NOTE always deep copy on windows. the alternatives are too messy.
- #if defined Q_OS_WIN32
- m_followSymlinks = true;
- #endif
+ //NOTE always deep copy on windows. the alternatives are too messy.
+ #if defined Q_OS_WIN32
+ m_followSymlinks = true;
+ #endif
- auto src = PathCombine(m_src.absolutePath(), offset);
- auto dst = PathCombine(m_dst.absolutePath(), offset);
+ auto src = PathCombine(m_src.absolutePath(), offset);
+ auto dst = PathCombine(m_dst.absolutePath(), offset);
- QFileInfo currentSrc(src);
- if (!currentSrc.exists())
- return false;
+ QFileInfo currentSrc(src);
+ if (!currentSrc.exists())
+ return false;
- if(!m_followSymlinks && currentSrc.isSymLink())
- {
- qDebug() << "creating symlink" << src << " - " << dst;
- if (!ensureFilePathExists(dst))
- {
- qWarning() << "Cannot create path!";
- return false;
- }
- return QFile::link(currentSrc.symLinkTarget(), dst);
- }
- else if(currentSrc.isFile())
- {
- qDebug() << "copying file" << src << " - " << dst;
- if (!ensureFilePathExists(dst))
- {
- qWarning() << "Cannot create path!";
- return false;
- }
- return QFile::copy(src, dst);
- }
- else if(currentSrc.isDir())
- {
- qDebug() << "recursing" << offset;
- if (!ensureFolderPathExists(dst))
- {
- qWarning() << "Cannot create path!";
- return false;
- }
- QDir currentDir(src);
- for(auto & f : currentDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
- {
- auto inner_offset = PathCombine(offset, f);
- // ignore and skip stuff that matches the blacklist.
- if(m_blacklist && m_blacklist->matches(inner_offset))
- {
- continue;
- }
- if(!operator()(inner_offset))
- {
- qWarning() << "Failed to copy" << inner_offset;
- return false;
- }
- }
- }
- else
- {
- qCritical() << "Copy ERROR: Unknown filesystem object:" << src;
- return false;
- }
- return true;
+ if(!m_followSymlinks && currentSrc.isSymLink())
+ {
+ qDebug() << "creating symlink" << src << " - " << dst;
+ if (!ensureFilePathExists(dst))
+ {
+ qWarning() << "Cannot create path!";
+ return false;
+ }
+ return QFile::link(currentSrc.symLinkTarget(), dst);
+ }
+ else if(currentSrc.isFile())
+ {
+ qDebug() << "copying file" << src << " - " << dst;
+ if (!ensureFilePathExists(dst))
+ {
+ qWarning() << "Cannot create path!";
+ return false;
+ }
+ return QFile::copy(src, dst);
+ }
+ else if(currentSrc.isDir())
+ {
+ qDebug() << "recursing" << offset;
+ if (!ensureFolderPathExists(dst))
+ {
+ qWarning() << "Cannot create path!";
+ return false;
+ }
+ QDir currentDir(src);
+ for(auto & f : currentDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
+ {
+ auto inner_offset = PathCombine(offset, f);
+ // ignore and skip stuff that matches the blacklist.
+ if(m_blacklist && m_blacklist->matches(inner_offset))
+ {
+ continue;
+ }
+ if(!operator()(inner_offset))
+ {
+ qWarning() << "Failed to copy" << inner_offset;
+ return false;
+ }
+ }
+ }
+ else
+ {
+ qCritical() << "Copy ERROR: Unknown filesystem object:" << src;
+ return false;
+ }
+ return true;
}
bool deletePath(QString path)
{
- bool OK = true;
- QDir dir(path);
+ bool OK = true;
+ QDir dir(path);
- if (!dir.exists())
- {
- return OK;
- }
- auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
- QDir::AllDirs | QDir::Files,
- QDir::DirsFirst);
+ if (!dir.exists())
+ {
+ return OK;
+ }
+ auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
+ QDir::AllDirs | QDir::Files,
+ QDir::DirsFirst);
- for(auto & info: allEntries)
- {
+ for(auto & info: allEntries)
+ {
#if defined Q_OS_WIN32
- QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath());
- auto wString = nativePath.toStdWString();
- DWORD dwAttrs = GetFileAttributesW(wString.c_str());
- // Windows: check for junctions, reparse points and other nasty things of that sort
- if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT)
- {
- if (info.isFile())
- {
- OK &= QFile::remove(info.absoluteFilePath());
- }
- else if (info.isDir())
- {
- OK &= dir.rmdir(info.absoluteFilePath());
- }
- }
+ QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath());
+ auto wString = nativePath.toStdWString();
+ DWORD dwAttrs = GetFileAttributesW(wString.c_str());
+ // Windows: check for junctions, reparse points and other nasty things of that sort
+ if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT)
+ {
+ if (info.isFile())
+ {
+ OK &= QFile::remove(info.absoluteFilePath());
+ }
+ else if (info.isDir())
+ {
+ OK &= dir.rmdir(info.absoluteFilePath());
+ }
+ }
#else
- // We do not trust Qt with reparse points, but do trust it with unix symlinks.
- if(info.isSymLink())
- {
- OK &= QFile::remove(info.absoluteFilePath());
- }
+ // We do not trust Qt with reparse points, but do trust it with unix symlinks.
+ if(info.isSymLink())
+ {
+ OK &= QFile::remove(info.absoluteFilePath());
+ }
#endif
- else if (info.isDir())
- {
- OK &= deletePath(info.absoluteFilePath());
- }
- else if (info.isFile())
- {
- OK &= QFile::remove(info.absoluteFilePath());
- }
- else
- {
- OK = false;
- qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath();
- }
- }
- OK &= dir.rmdir(dir.absolutePath());
- return OK;
+ else if (info.isDir())
+ {
+ OK &= deletePath(info.absoluteFilePath());
+ }
+ else if (info.isFile())
+ {
+ OK &= QFile::remove(info.absoluteFilePath());
+ }
+ else
+ {
+ OK = false;
+ qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath();
+ }
+ }
+ OK &= dir.rmdir(dir.absolutePath());
+ return OK;
}
QString PathCombine(const QString & path1, const QString & path2)
{
- if(!path1.size())
- return path2;
- if(!path2.size())
- return path1;
+ if(!path1.size())
+ return path2;
+ if(!path2.size())
+ return path1;
return QDir::cleanPath(path1 + QDir::separator() + path2);
}
QString PathCombine(const QString & path1, const QString & path2, const QString & path3)
{
- return PathCombine(PathCombine(path1, path2), path3);
+ return PathCombine(PathCombine(path1, path2), path3);
}
QString PathCombine(const QString & path1, const QString & path2, const QString & path3, const QString & path4)
{
- return PathCombine(PathCombine(path1, path2, path3), path4);
+ return PathCombine(PathCombine(path1, path2, path3), path4);
}
QString AbsolutePath(QString path)
{
- return QFileInfo(path).absolutePath();
+ return QFileInfo(path).absolutePath();
}
QString ResolveExecutable(QString path)
{
- if (path.isEmpty())
- {
- return QString();
- }
- if(!path.contains('/'))
- {
- path = QStandardPaths::findExecutable(path);
- }
- QFileInfo pathInfo(path);
- if(!pathInfo.exists() || !pathInfo.isExecutable())
- {
- return QString();
- }
- return pathInfo.absoluteFilePath();
+ if (path.isEmpty())
+ {
+ return QString();
+ }
+ if(!path.contains('/'))
+ {
+ path = QStandardPaths::findExecutable(path);
+ }
+ QFileInfo pathInfo(path);
+ if(!pathInfo.exists() || !pathInfo.isExecutable())
+ {
+ return QString();
+ }
+ return pathInfo.absoluteFilePath();
}
/**
@@ -278,66 +278,66 @@ QString ResolveExecutable(QString path)
*/
QString NormalizePath(QString path)
{
- QDir a = QDir::currentPath();
- QString currentAbsolute = a.absolutePath();
+ QDir a = QDir::currentPath();
+ QString currentAbsolute = a.absolutePath();
- QDir b(path);
- QString newAbsolute = b.absolutePath();
+ QDir b(path);
+ QString newAbsolute = b.absolutePath();
- if (newAbsolute.startsWith(currentAbsolute))
- {
- return a.relativeFilePath(newAbsolute);
- }
- else
- {
- return newAbsolute;
- }
+ if (newAbsolute.startsWith(currentAbsolute))
+ {
+ return a.relativeFilePath(newAbsolute);
+ }
+ else
+ {
+ return newAbsolute;
+ }
}
QString badFilenameChars = "\"\\/?<>:*|!";
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
{
- for (int i = 0; i < string.length(); i++)
- {
- if (badFilenameChars.contains(string[i]))
- {
- string[i] = replaceWith;
- }
- }
- return string;
+ for (int i = 0; i < string.length(); i++)
+ {
+ if (badFilenameChars.contains(string[i]))
+ {
+ string[i] = replaceWith;
+ }
+ }
+ return string;
}
QString DirNameFromString(QString string, QString inDir)
{
- int num = 0;
- QString baseName = RemoveInvalidFilenameChars(string, '-');
- QString dirName;
- do
- {
- if(num == 0)
- {
- dirName = baseName;
- }
- else
- {
- dirName = baseName + QString::number(num);;
- }
+ int num = 0;
+ QString baseName = RemoveInvalidFilenameChars(string, '-');
+ QString dirName;
+ do
+ {
+ if(num == 0)
+ {
+ dirName = baseName;
+ }
+ else
+ {
+ dirName = baseName + QString::number(num);;
+ }
- // If it's over 9000
- if (num > 9000)
- return "";
- num++;
- } while (QFileInfo(PathCombine(inDir, dirName)).exists());
- return dirName;
+ // If it's over 9000
+ if (num > 9000)
+ return "";
+ num++;
+ } while (QFileInfo(PathCombine(inDir, dirName)).exists());
+ return dirName;
}
// Does the folder path contain any '!'? If yes, return true, otherwise false.
// (This is a problem for Java)
bool checkProblemticPathJava(QDir folder)
{
- QString pathfoldername = folder.absolutePath();
- return pathfoldername.contains("!", Qt::CaseInsensitive);
+ QString pathfoldername = folder.absolutePath();
+ return pathfoldername.contains("!", Qt::CaseInsensitive);
}
// Win32 crap
@@ -347,106 +347,106 @@ bool called_coinit = false;
HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args)
{
- HRESULT hres;
+ HRESULT hres;
- if (!called_coinit)
- {
- hres = CoInitialize(NULL);
- called_coinit = true;
+ if (!called_coinit)
+ {
+ hres = CoInitialize(NULL);
+ called_coinit = true;
- if (!SUCCEEDED(hres))
- {
- qWarning("Failed to initialize COM. Error 0x%08lX", hres);
- return hres;
- }
- }
+ if (!SUCCEEDED(hres))
+ {
+ qWarning("Failed to initialize COM. Error 0x%08lX", hres);
+ return hres;
+ }
+ }
- IShellLink *link;
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
- (LPVOID *)&link);
+ IShellLink *link;
+ hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
+ (LPVOID *)&link);
- if (SUCCEEDED(hres))
- {
- IPersistFile *persistFile;
+ if (SUCCEEDED(hres))
+ {
+ IPersistFile *persistFile;
- link->SetPath(targetPath);
- link->SetArguments(args);
+ link->SetPath(targetPath);
+ link->SetArguments(args);
- hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile);
- if (SUCCEEDED(hres))
- {
- WCHAR wstr[MAX_PATH];
+ hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile);
+ if (SUCCEEDED(hres))
+ {
+ WCHAR wstr[MAX_PATH];
- MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
+ MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
- hres = persistFile->Save(wstr, TRUE);
- persistFile->Release();
- }
- link->Release();
- }
- return hres;
+ hres = persistFile->Save(wstr, TRUE);
+ persistFile->Release();
+ }
+ link->Release();
+ }
+ return hres;
}
#endif
QString getDesktopDir()
{
- return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+ return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
}
// Cross-platform Shortcut creation
bool createShortCut(QString location, QString dest, QStringList args, QString name,
- QString icon)
+ QString icon)
{
#if defined Q_OS_LINUX
- location = PathCombine(location, name + ".desktop");
+ location = PathCombine(location, name + ".desktop");
- QFile f(location);
- f.open(QIODevice::WriteOnly | QIODevice::Text);
- QTextStream stream(&f);
+ QFile f(location);
+ f.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream stream(&f);
- QString argstring;
- if (!args.empty())
- argstring = " '" + args.join("' '") + "'";
+ QString argstring;
+ if (!args.empty())
+ argstring = " '" + args.join("' '") + "'";
- stream << "[Desktop Entry]"
- << "\n";
- stream << "Type=Application"
- << "\n";
- stream << "TryExec=" << dest.toLocal8Bit() << "\n";
- stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n";
- stream << "Name=" << name.toLocal8Bit() << "\n";
- stream << "Icon=" << icon.toLocal8Bit() << "\n";
+ stream << "[Desktop Entry]"
+ << "\n";
+ stream << "Type=Application"
+ << "\n";
+ stream << "TryExec=" << dest.toLocal8Bit() << "\n";
+ stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n";
+ stream << "Name=" << name.toLocal8Bit() << "\n";
+ stream << "Icon=" << icon.toLocal8Bit() << "\n";
- stream.flush();
- f.close();
+ stream.flush();
+ f.close();
- f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup |
- QFileDevice::ExeOther);
+ f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup |
+ QFileDevice::ExeOther);
- return true;
+ return true;
#elif defined Q_OS_WIN
- // TODO: Fix
- // QFile file(PathCombine(location, name + ".lnk"));
- // WCHAR *file_w;
- // WCHAR *dest_w;
- // WCHAR *args_w;
- // file.fileName().toWCharArray(file_w);
- // dest.toWCharArray(dest_w);
+ // TODO: Fix
+ // QFile file(PathCombine(location, name + ".lnk"));
+ // WCHAR *file_w;
+ // WCHAR *dest_w;
+ // WCHAR *args_w;
+ // file.fileName().toWCharArray(file_w);
+ // dest.toWCharArray(dest_w);
- // QString argStr;
- // for (int i = 0; i < args.count(); i++)
- // {
- // argStr.append(args[i]);
- // argStr.append(" ");
- // }
- // argStr.toWCharArray(args_w);
+ // QString argStr;
+ // for (int i = 0; i < args.count(); i++)
+ // {
+ // argStr.append(args[i]);
+ // argStr.append(" ");
+ // }
+ // argStr.toWCharArray(args_w);
- // return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
- return false;
+ // return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
+ return false;
#else
- qWarning("Desktop Shortcuts not supported on your platform!");
- return false;
+ qWarning("Desktop Shortcuts not supported on your platform!");
+ return false;
#endif
}
}
diff --git a/api/logic/FileSystem.h b/api/logic/FileSystem.h
index de8774ff..55ec6a58 100644
--- a/api/logic/FileSystem.h
+++ b/api/logic/FileSystem.h
@@ -15,7 +15,7 @@ namespace FS
class MULTIMC_LOGIC_EXPORT FileSystemException : public ::Exception
{
public:
- FileSystemException(const QString &message) : Exception(message) {}
+ FileSystemException(const QString &message) : Exception(message) {}
};
/**
@@ -48,34 +48,34 @@ MULTIMC_LOGIC_EXPORT bool ensureFolderPathExists(QString filenamepath);
class MULTIMC_LOGIC_EXPORT copy
{
public:
- copy(const QString & src, const QString & dst)
- {
- m_src = src;
- m_dst = dst;
- }
- copy & followSymlinks(const bool follow)
- {
- m_followSymlinks = follow;
- return *this;
- }
- copy & blacklist(const IPathMatcher * filter)
- {
- m_blacklist = filter;
- return *this;
- }
- bool operator()()
- {
- return operator()(QString());
- }
+ copy(const QString & src, const QString & dst)
+ {
+ m_src = src;
+ m_dst = dst;
+ }
+ copy & followSymlinks(const bool follow)
+ {
+ m_followSymlinks = follow;
+ return *this;
+ }
+ copy & blacklist(const IPathMatcher * filter)
+ {
+ m_blacklist = filter;
+ return *this;
+ }
+ bool operator()()
+ {
+ return operator()(QString());
+ }
private:
- bool operator()(const QString &offset);
+ bool operator()(const QString &offset);
private:
- bool m_followSymlinks = true;
- const IPathMatcher * m_blacklist = nullptr;
- QDir m_src;
- QDir m_dst;
+ bool m_followSymlinks = true;
+ const IPathMatcher * m_blacklist = nullptr;
+ QDir m_src;
+ QDir m_dst;
};
/**
diff --git a/api/logic/FileSystem_test.cpp b/api/logic/FileSystem_test.cpp
index d5e1eedb..df653ea1 100644
--- a/api/logic/FileSystem_test.cpp
+++ b/api/logic/FileSystem_test.cpp
@@ -7,155 +7,155 @@
class FileSystemTest : public QObject
{
- Q_OBJECT
+ Q_OBJECT
- const QString bothSlash = "/foo/";
- const QString trailingSlash = "foo/";
- const QString leadingSlash = "/foo";
+ const QString bothSlash = "/foo/";
+ const QString trailingSlash = "foo/";
+ const QString leadingSlash = "/foo";
private
slots:
- void test_pathCombine()
- {
- QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash));
- QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash));
- QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash));
+ void test_pathCombine()
+ {
+ QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash));
+ QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash));
+ QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash));
- QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash));
- QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash));
- QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash));
- }
+ QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash));
+ QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash));
+ QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash));
+ }
- void test_PathCombine1_data()
- {
- QTest::addColumn("result");
- QTest::addColumn("path1");
- QTest::addColumn("path2");
+ void test_PathCombine1_data()
+ {
+ QTest::addColumn("result");
+ QTest::addColumn("path1");
+ QTest::addColumn("path2");
- QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl";
- QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl";
+ QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl";
+ QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl";
#if defined(Q_OS_WIN)
- QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc";
- QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl";
- QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl";
+ QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc";
+ QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl";
+ QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl";
#endif
- }
+ }
- void test_PathCombine1()
- {
- QFETCH(QString, result);
- QFETCH(QString, path1);
- QFETCH(QString, path2);
+ void test_PathCombine1()
+ {
+ QFETCH(QString, result);
+ QFETCH(QString, path1);
+ QFETCH(QString, path2);
- QCOMPARE(FS::PathCombine(path1, path2), result);
- }
+ QCOMPARE(FS::PathCombine(path1, path2), result);
+ }
- void test_PathCombine2_data()
- {
- QTest::addColumn("result");
- QTest::addColumn("path1");
- QTest::addColumn("path2");
- QTest::addColumn("path3");
+ void test_PathCombine2_data()
+ {
+ QTest::addColumn("result");
+ QTest::addColumn("path1");
+ QTest::addColumn("path2");
+ QTest::addColumn("path3");
- QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl";
- QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl";
- QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl";
- QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl";
+ QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl";
+ QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl";
+ QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl";
+ QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl";
#if defined(Q_OS_WIN)
- QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl";
- QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
- QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl";
- QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
+ QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl";
+ QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
+ QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl";
+ QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
#endif
- }
+ }
- void test_PathCombine2()
- {
- QFETCH(QString, result);
- QFETCH(QString, path1);
- QFETCH(QString, path2);
- QFETCH(QString, path3);
+ void test_PathCombine2()
+ {
+ QFETCH(QString, result);
+ QFETCH(QString, path1);
+ QFETCH(QString, path2);
+ QFETCH(QString, path3);
- QCOMPARE(FS::PathCombine(path1, path2, path3), result);
- }
+ QCOMPARE(FS::PathCombine(path1, path2, path3), result);
+ }
- void test_copy()
- {
- QString folder = QFINDTESTDATA("data/test_folder");
- auto f = [&folder]()
- {
- QTemporaryDir tempDir;
- tempDir.setAutoRemove(true);
- qDebug() << "From:" << folder << "To:" << tempDir.path();
+ void test_copy()
+ {
+ QString folder = QFINDTESTDATA("data/test_folder");
+ auto f = [&folder]()
+ {
+ QTemporaryDir tempDir;
+ tempDir.setAutoRemove(true);
+ qDebug() << "From:" << folder << "To:" << tempDir.path();
- QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
- qDebug() << tempDir.path();
- qDebug() << target_dir.path();
- FS::copy c(folder, target_dir.path());
- c();
+ QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
+ qDebug() << tempDir.path();
+ qDebug() << target_dir.path();
+ FS::copy c(folder, target_dir.path());
+ c();
- for(auto entry: target_dir.entryList())
- {
- qDebug() << entry;
- }
- QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
- QVERIFY(target_dir.entryList().contains("assets"));
- };
+ for(auto entry: target_dir.entryList())
+ {
+ qDebug() << entry;
+ }
+ QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
+ QVERIFY(target_dir.entryList().contains("assets"));
+ };
- // first try variant without trailing /
- QVERIFY(!folder.endsWith('/'));
- f();
+ // first try variant without trailing /
+ QVERIFY(!folder.endsWith('/'));
+ f();
- // then variant with trailing /
- folder.append('/');
- QVERIFY(folder.endsWith('/'));
- f();
- }
+ // then variant with trailing /
+ folder.append('/');
+ QVERIFY(folder.endsWith('/'));
+ f();
+ }
- void test_getDesktop()
- {
- QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
- }
+ 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("location");
- QTest::addColumn("dest");
- QTest::addColumn("args");
- QTest::addColumn("name");
- QTest::addColumn("iconLocation");
- QTest::addColumn("result");
+ void test_createShortcut_data()
+ {
+ QTest::addColumn("location");
+ QTest::addColumn("dest");
+ QTest::addColumn("args");
+ QTest::addColumn("name");
+ QTest::addColumn("iconLocation");
+ QTest::addColumn("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
- ;
- }
+ 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);
+ 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));
+ QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
+ QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
- //QDir().remove(location);
- }
+ //QDir().remove(location);
+ }
#endif
};
diff --git a/api/logic/Filter.cpp b/api/logic/Filter.cpp
index 7f6667ae..6ec26bcb 100644
--- a/api/logic/Filter.cpp
+++ b/api/logic/Filter.cpp
@@ -6,26 +6,26 @@ ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){}
ContainsFilter::~ContainsFilter(){}
bool ContainsFilter::accepts(const QString& value)
{
- return value.contains(pattern);
+ return value.contains(pattern);
}
ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){}
ExactFilter::~ExactFilter(){}
bool ExactFilter::accepts(const QString& value)
{
- return value.contains(pattern);
+ return value.contains(pattern);
}
RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
- :invert(invert)
+ :invert(invert)
{
- pattern.setPattern(regexp);
- pattern.optimize();
+ pattern.setPattern(regexp);
+ pattern.optimize();
}
RegexpFilter::~RegexpFilter(){}
bool RegexpFilter::accepts(const QString& value)
{
- auto match = pattern.match(value);
- bool matched = match.hasMatch();
- return invert ? (!matched) : (matched);
+ auto match = pattern.match(value);
+ bool matched = match.hasMatch();
+ return invert ? (!matched) : (matched);
}
diff --git a/api/logic/Filter.h b/api/logic/Filter.h
index 8de7d8f9..1ba48e48 100644
--- a/api/logic/Filter.h
+++ b/api/logic/Filter.h
@@ -8,37 +8,37 @@
class MULTIMC_LOGIC_EXPORT Filter
{
public:
- virtual ~Filter();
- virtual bool accepts(const QString & value) = 0;
+ virtual ~Filter();
+ virtual bool accepts(const QString & value) = 0;
};
class MULTIMC_LOGIC_EXPORT ContainsFilter: public Filter
{
public:
- ContainsFilter(const QString &pattern);
- virtual ~ContainsFilter();
- bool accepts(const QString & value) override;
+ ContainsFilter(const QString &pattern);
+ virtual ~ContainsFilter();
+ bool accepts(const QString & value) override;
private:
- QString pattern;
+ QString pattern;
};
class MULTIMC_LOGIC_EXPORT ExactFilter: public Filter
{
public:
- ExactFilter(const QString &pattern);
- virtual ~ExactFilter();
- bool accepts(const QString & value) override;
+ ExactFilter(const QString &pattern);
+ virtual ~ExactFilter();
+ bool accepts(const QString & value) override;
private:
- QString pattern;
+ QString pattern;
};
class MULTIMC_LOGIC_EXPORT RegexpFilter: public Filter
{
public:
- RegexpFilter(const QString ®exp, bool invert);
- virtual ~RegexpFilter();
- bool accepts(const QString & value) override;
+ RegexpFilter(const QString ®exp, bool invert);
+ virtual ~RegexpFilter();
+ bool accepts(const QString & value) override;
private:
- QRegularExpression pattern;
- bool invert = false;
+ QRegularExpression pattern;
+ bool invert = false;
};
diff --git a/api/logic/FolderInstanceProvider.cpp b/api/logic/FolderInstanceProvider.cpp
index cedba408..4f89e5b7 100644
--- a/api/logic/FolderInstanceProvider.cpp
+++ b/api/logic/FolderInstanceProvider.cpp
@@ -18,322 +18,322 @@ 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;
+ 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)
+ : BaseInstanceProvider(settings)
{
- // Create aand normalize path
- if (!QDir::current().exists(instDir))
- {
- QDir::current().mkpath(instDir);
- }
- // NOTE: canonicalPath requires the path to exist. Do not move this above the creation block!
- m_instDir = QDir(instDir).canonicalPath();
- m_watcher = new QFileSystemWatcher(this);
- connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &FolderInstanceProvider::instanceDirContentsChanged);
- m_watcher->addPath(m_instDir);
+ // Create aand normalize path
+ if (!QDir::current().exists(instDir))
+ {
+ QDir::current().mkpath(instDir);
+ }
+ // NOTE: canonicalPath requires the path to exist. Do not move this above the creation block!
+ m_instDir = QDir(instDir).canonicalPath();
+ m_watcher = new QFileSystemWatcher(this);
+ connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &FolderInstanceProvider::instanceDirContentsChanged);
+ m_watcher->addPath(m_instDir);
}
QList< InstanceId > FolderInstanceProvider::discoverInstances()
{
- QList out;
- QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable | QDir::Hidden, 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;
+ QList out;
+ QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable | QDir::Hidden, 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();
- }
+ if(!m_groupsLoaded)
+ {
+ loadGroupList();
+ }
- auto instanceRoot = FS::PathCombine(m_instDir, id);
- auto instanceSettings = std::make_shared(FS::PathCombine(instanceRoot, "instance.cfg"));
- InstancePtr inst;
+ auto instanceRoot = FS::PathCombine(m_instDir, id);
+ auto instanceSettings = std::make_shared(FS::PathCombine(instanceRoot, "instance.cfg"));
+ InstancePtr inst;
- instanceSettings->registerSetting("InstanceType", "Legacy");
+ instanceSettings->registerSetting("InstanceType", "Legacy");
- QString inst_type = instanceSettings->get("InstanceType").toString();
+ QString inst_type = instanceSettings->get("InstanceType").toString();
- if (inst_type == "OneSix" || inst_type == "Nostalgia")
- {
- inst.reset(new MinecraftInstance(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;
+ if (inst_type == "OneSix" || inst_type == "Nostalgia")
+ {
+ inst.reset(new MinecraftInstance(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;
}
void FolderInstanceProvider::saveGroupList()
{
- WatchLock foo(m_watcher, m_instDir);
- QString groupFileName = m_instDir + "/instgroups.json";
- QMap> reverseGroupMap;
- for (auto iter = groupMap.begin(); iter != groupMap.end(); iter++)
- {
- QString id = iter.key();
- QString group = iter.value();
- if (group.isEmpty())
- continue;
+ WatchLock foo(m_watcher, m_instDir);
+ QString groupFileName = m_instDir + "/instgroups.json";
+ QMap> 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 set;
- set.insert(id);
- reverseGroupMap[group] = set;
- }
- else
- {
- QSet &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 (const FS::FileSystemException &e)
- {
- qCritical() << "Failed to write instance group file :" << e.cause();
- }
+ if (!reverseGroupMap.count(group))
+ {
+ QSet set;
+ set.insert(id);
+ reverseGroupMap[group] = set;
+ }
+ else
+ {
+ QSet &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 (const FS::FileSystemException &e)
+ {
+ qCritical() << "Failed to write instance group file :" << e.cause();
+ }
}
void FolderInstanceProvider::loadGroupList()
{
- QSet groupSet;
+ QSet groupSet;
- QString groupFileName = m_instDir + "/instgroups.json";
+ QString groupFileName = m_instDir + "/instgroups.json";
- // if there's no group file, fail
- if (!QFileInfo(groupFileName).exists())
- return;
+ // if there's no group file, fail
+ if (!QFileInfo(groupFileName).exists())
+ return;
- QByteArray jsonData;
- try
- {
- jsonData = FS::read(groupFileName);
- }
- catch (const FS::FileSystemException &e)
- {
- qCritical() << "Failed to read instance group file :" << e.cause();
- return;
- }
+ QByteArray jsonData;
+ try
+ {
+ jsonData = FS::read(groupFileName);
+ }
+ catch (const FS::FileSystemException &e)
+ {
+ qCritical() << "Failed to read instance group file :" << e.cause();
+ return;
+ }
- QJsonParseError error;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error);
+ 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 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;
- }
+ // 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();
+ QJsonObject rootObj = jsonDoc.object();
- // Make sure the format version matches, otherwise fail.
- if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION)
- return;
+ // 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;
- }
+ // 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();
+ 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();
+ // 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;
- }
+ // 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;
- }
+ 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);
+ // 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();
+ // 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);
+ 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();
+ // 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();
+ Q_UNUSED(path);
+ emit instancesChanged();
}
void FolderInstanceProvider::on_InstFolderChanged(const Setting &setting, QVariant value)
{
- QString newInstDir = QDir(value.toString()).canonicalPath();
- if(newInstDir != m_instDir)
- {
- if(m_groupsLoaded)
- {
- saveGroupList();
- }
- m_instDir = newInstDir;
- m_groupsLoaded = false;
- emit instancesChanged();
- }
+ QString newInstDir = QDir(value.toString()).canonicalPath();
+ if(newInstDir != m_instDir)
+ {
+ if(m_groupsLoaded)
+ {
+ saveGroupList();
+ }
+ m_instDir = newInstDir;
+ m_groupsLoaded = false;
+ emit instancesChanged();
+ }
}
template
static void clamp(T& current, T min, T max)
{
- if (current < min)
- {
- current = min;
- }
- else if(current > max)
- {
- current = max;
- }
+ if (current < min)
+ {
+ current = min;
+ }
+ else if(current > max)
+ {
+ current = max;
+ }
}
// List of numbers from min to max. Next is exponent times bigger than previous.
class ExponentialSeries
{
public:
- ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2)
- {
- m_current = m_min = min;
- m_max = max;
- m_exponent = exponent;
- }
- void reset()
- {
- m_current = m_min;
- }
- unsigned operator()()
- {
- unsigned retval = m_current;
- m_current *= m_exponent;
- clamp(m_current, m_min, m_max);
- return retval;
- }
- unsigned m_current;
- unsigned m_min;
- unsigned m_max;
- unsigned m_exponent;
+ ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2)
+ {
+ m_current = m_min = min;
+ m_max = max;
+ m_exponent = exponent;
+ }
+ void reset()
+ {
+ m_current = m_min;
+ }
+ unsigned operator()()
+ {
+ unsigned retval = m_current;
+ m_current *= m_exponent;
+ clamp(m_current, m_min, m_max);
+ return retval;
+ }
+ unsigned m_current;
+ unsigned m_min;
+ unsigned m_max;
+ unsigned m_exponent;
};
/*
@@ -344,121 +344,121 @@ public:
class FolderInstanceStaging : public Task
{
Q_OBJECT
- const unsigned minBackoff = 1;
- const unsigned maxBackoff = 16;
+ const unsigned minBackoff = 1;
+ const unsigned maxBackoff = 16;
public:
- FolderInstanceStaging (
- FolderInstanceProvider * parent,
- Task * child,
- const QString & stagingPath,
- const QString& instanceName,
- const QString& groupName )
- : backoff(minBackoff, maxBackoff)
- {
- m_parent = parent;
- m_child.reset(child);
- connect(child, &Task::succeeded, this, &FolderInstanceStaging::childSucceded);
- connect(child, &Task::failed, this, &FolderInstanceStaging::childFailed);
- connect(child, &Task::status, this, &FolderInstanceStaging::setStatus);
- connect(child, &Task::progress, this, &FolderInstanceStaging::setProgress);
- m_instanceName = instanceName;
- m_groupName = groupName;
- m_stagingPath = stagingPath;
- m_backoffTimer.setSingleShot(true);
- connect(&m_backoffTimer, &QTimer::timeout, this, &FolderInstanceStaging::childSucceded);
- }
+ FolderInstanceStaging (
+ FolderInstanceProvider * parent,
+ Task * child,
+ const QString & stagingPath,
+ const QString& instanceName,
+ const QString& groupName )
+ : backoff(minBackoff, maxBackoff)
+ {
+ m_parent = parent;
+ m_child.reset(child);
+ connect(child, &Task::succeeded, this, &FolderInstanceStaging::childSucceded);
+ connect(child, &Task::failed, this, &FolderInstanceStaging::childFailed);
+ connect(child, &Task::status, this, &FolderInstanceStaging::setStatus);
+ connect(child, &Task::progress, this, &FolderInstanceStaging::setProgress);
+ m_instanceName = instanceName;
+ m_groupName = groupName;
+ m_stagingPath = stagingPath;
+ m_backoffTimer.setSingleShot(true);
+ connect(&m_backoffTimer, &QTimer::timeout, this, &FolderInstanceStaging::childSucceded);
+ }
- virtual ~FolderInstanceStaging() {};
+ virtual ~FolderInstanceStaging() {};
protected:
- virtual void executeTask() override
- {
- m_child->start();
- }
- QStringList warnings() const override
- {
- return m_child->warnings();
- }
+ virtual void executeTask() override
+ {
+ m_child->start();
+ }
+ QStringList warnings() const override
+ {
+ return m_child->warnings();
+ }
private slots:
- void childSucceded()
- {
- unsigned sleepTime = backoff();
- if(m_parent->commitStagedInstance(m_stagingPath, m_instanceName, m_groupName))
- {
- emitSucceeded();
- return;
- }
- // we actually failed, retry?
- if(sleepTime == maxBackoff)
- {
- emitFailed(tr("Failed to commit instance, even after multiple retries. It is being blocked by something."));
- return;
- }
- qDebug() << "Failed to commit instance" << m_instanceName << "Initiating backoff:" << sleepTime;
- m_backoffTimer.start(sleepTime * 500);
- }
- void childFailed(const QString & reason)
- {
- m_parent->destroyStagingPath(m_stagingPath);
- emitFailed(reason);
- }
+ void childSucceded()
+ {
+ unsigned sleepTime = backoff();
+ if(m_parent->commitStagedInstance(m_stagingPath, m_instanceName, m_groupName))
+ {
+ emitSucceeded();
+ return;
+ }
+ // we actually failed, retry?
+ if(sleepTime == maxBackoff)
+ {
+ emitFailed(tr("Failed to commit instance, even after multiple retries. It is being blocked by something."));
+ return;
+ }
+ qDebug() << "Failed to commit instance" << m_instanceName << "Initiating backoff:" << sleepTime;
+ m_backoffTimer.start(sleepTime * 500);
+ }
+ void childFailed(const QString & reason)
+ {
+ m_parent->destroyStagingPath(m_stagingPath);
+ emitFailed(reason);
+ }
private:
- ExponentialSeries backoff;
- QString m_stagingPath;
- FolderInstanceProvider * m_parent;
- unique_qobject_ptr m_child;
- QString m_instanceName;
- QString m_groupName;
- QTimer m_backoffTimer;
+ ExponentialSeries backoff;
+ QString m_stagingPath;
+ FolderInstanceProvider * m_parent;
+ unique_qobject_ptr m_child;
+ QString m_instanceName;
+ QString m_groupName;
+ QTimer m_backoffTimer;
};
#include "InstanceTask.h"
Task * FolderInstanceProvider::wrapInstanceTask(InstanceTask * task)
{
- auto stagingPath = getStagedInstancePath();
- task->setStagingPath(stagingPath);
- task->setParentSettings(m_globalSettings);
- return new FolderInstanceStaging(this, task, stagingPath, task->name(), task->group());
+ auto stagingPath = getStagedInstancePath();
+ task->setStagingPath(stagingPath);
+ task->setParentSettings(m_globalSettings);
+ return new FolderInstanceStaging(this, task, stagingPath, task->name(), task->group());
}
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;
+ 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& path, const QString& instanceName, const QString& groupName)
{
- QDir dir;
- QString instID = FS::DirNameFromString(instanceName, m_instDir);
- {
- WatchLock lock(m_watcher, m_instDir);
- QString destination = FS::PathCombine(m_instDir, instID);
- if(!dir.rename(path, destination))
- {
- qWarning() << "Failed to move" << path << "to" << destination;
- return false;
- }
- groupMap[instID] = groupName;
- emit groupsChanged({groupName});
- emit instancesChanged();
- }
- saveGroupList();
- return true;
+ QDir dir;
+ QString instID = FS::DirNameFromString(instanceName, m_instDir);
+ {
+ WatchLock lock(m_watcher, m_instDir);
+ QString destination = FS::PathCombine(m_instDir, instID);
+ if(!dir.rename(path, destination))
+ {
+ qWarning() << "Failed to move" << path << "to" << destination;
+ return false;
+ }
+ groupMap[instID] = groupName;
+ emit groupsChanged({groupName});
+ emit instancesChanged();
+ }
+ saveGroupList();
+ return true;
}
bool FolderInstanceProvider::destroyStagingPath(const QString& keyPath)
{
- return FS::deletePath(keyPath);
+ return FS::deletePath(keyPath);
}
#include "FolderInstanceProvider.moc"
diff --git a/api/logic/FolderInstanceProvider.h b/api/logic/FolderInstanceProvider.h
index e13dcfe9..fc14ba7a 100644
--- a/api/logic/FolderInstanceProvider.h
+++ b/api/logic/FolderInstanceProvider.h
@@ -8,68 +8,68 @@ class InstanceTask;
class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider
{
- Q_OBJECT
+ Q_OBJECT
public:
- FolderInstanceProvider(SettingsObjectPtr settings, const QString & instDir);
+ FolderInstanceProvider(SettingsObjectPtr settings, const QString & instDir);
public:
- /// used by InstanceList to @return a list of plausible IDs to probe for
- QList discoverInstances() override;
+ /// used by InstanceList to @return a list of plausible IDs to probe for
+ QList discoverInstances() override;
- /// used by InstanceList to (re)load an instance with the given @id.
- InstancePtr loadInstance(const InstanceId& id) 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);
+ /*
+ // 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);
+ // 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);
+ // import zipped instance into this provider
+ Task * zipImportTask(const QUrl sourceUrl, const QString &instName, const QString &instGroup, const QString &instIcon);
- //create FtbInstance
- Task * ftbCreationTask(FtbPackDownloader *downloader, const QString &instName, const QString &instGroup, const QString &instIcon);
+ //create FtbInstance
+ Task * ftbCreationTask(FtbPackDownloader *downloader, const QString &instName, const QString &instGroup, const QString &instIcon);
- // migrate an instance to the current format
- Task * legacyUpgradeTask(const InstancePtr& oldInstance);
+ // migrate an instance to the current format
+ Task * legacyUpgradeTask(const InstancePtr& oldInstance);
*/
- // Wrap an instance creation task in some more task machinery and make it ready to be used
- Task * wrapInstanceTask(InstanceTask * task);
+ // Wrap an instance creation task in some more task machinery and make it ready to be used
+ Task * wrapInstanceTask(InstanceTask * task);
- /**
- * Create a new empty staging area for instance creation and @return a path/key top commit it later.
- * Used by instance manipulation tasks.
- */
- QString getStagedInstancePath() 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& 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;
+ /**
+ * 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& 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);
+ void on_InstFolderChanged(const Setting &setting, QVariant value);
private slots:
- void instanceDirContentsChanged(const QString &path);
- void groupChanged();
+ void instanceDirContentsChanged(const QString &path);
+ void groupChanged();
private: /* methods */
- void loadGroupList() override;
- void saveGroupList() override;
+ void loadGroupList() override;
+ void saveGroupList() override;
private: /* data */
- QString m_instDir;
- QFileSystemWatcher * m_watcher;
- QMap groupMap;
- bool m_groupsLoaded = false;
+ QString m_instDir;
+ QFileSystemWatcher * m_watcher;
+ QMap groupMap;
+ bool m_groupsLoaded = false;
};
diff --git a/api/logic/GZip.cpp b/api/logic/GZip.cpp
index 38605df6..0368c32d 100644
--- a/api/logic/GZip.cpp
+++ b/api/logic/GZip.cpp
@@ -4,112 +4,112 @@
bool GZip::unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes)
{
- if (compressedBytes.size() == 0)
- {
- uncompressedBytes = compressedBytes;
- return true;
- }
+ if (compressedBytes.size() == 0)
+ {
+ uncompressedBytes = compressedBytes;
+ return true;
+ }
- unsigned uncompLength = compressedBytes.size();
- uncompressedBytes.clear();
- uncompressedBytes.resize(uncompLength);
+ unsigned uncompLength = compressedBytes.size();
+ uncompressedBytes.clear();
+ uncompressedBytes.resize(uncompLength);
- z_stream strm;
- memset(&strm, 0, sizeof(strm));
- strm.next_in = (Bytef *)compressedBytes.data();
- strm.avail_in = compressedBytes.size();
+ z_stream strm;
+ memset(&strm, 0, sizeof(strm));
+ strm.next_in = (Bytef *)compressedBytes.data();
+ strm.avail_in = compressedBytes.size();
- bool done = false;
+ bool done = false;
- if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK)
- {
- return false;
- }
+ if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK)
+ {
+ return false;
+ }
- int err = Z_OK;
+ int err = Z_OK;
- while (!done)
- {
- // If our output buffer is too small
- if (strm.total_out >= uncompLength)
- {
- uncompressedBytes.resize(uncompLength * 2);
- uncompLength *= 2;
- }
+ while (!done)
+ {
+ // If our output buffer is too small
+ if (strm.total_out >= uncompLength)
+ {
+ uncompressedBytes.resize(uncompLength * 2);
+ uncompLength *= 2;
+ }
- strm.next_out = (Bytef *)(uncompressedBytes.data() + strm.total_out);
- strm.avail_out = uncompLength - strm.total_out;
+ strm.next_out = (Bytef *)(uncompressedBytes.data() + strm.total_out);
+ strm.avail_out = uncompLength - strm.total_out;
- // Inflate another chunk.
- err = inflate(&strm, Z_SYNC_FLUSH);
- if (err == Z_STREAM_END)
- done = true;
- else if (err != Z_OK)
- {
- break;
- }
- }
+ // Inflate another chunk.
+ err = inflate(&strm, Z_SYNC_FLUSH);
+ if (err == Z_STREAM_END)
+ done = true;
+ else if (err != Z_OK)
+ {
+ break;
+ }
+ }
- if (inflateEnd(&strm) != Z_OK || !done)
- {
- return false;
- }
+ if (inflateEnd(&strm) != Z_OK || !done)
+ {
+ return false;
+ }
- uncompressedBytes.resize(strm.total_out);
- return true;
+ uncompressedBytes.resize(strm.total_out);
+ return true;
}
bool GZip::zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes)
{
- if (uncompressedBytes.size() == 0)
- {
- compressedBytes = uncompressedBytes;
- return true;
- }
+ if (uncompressedBytes.size() == 0)
+ {
+ compressedBytes = uncompressedBytes;
+ return true;
+ }
- unsigned compLength = std::min(uncompressedBytes.size(), 16);
- compressedBytes.clear();
- compressedBytes.resize(compLength);
+ unsigned compLength = std::min(uncompressedBytes.size(), 16);
+ compressedBytes.clear();
+ compressedBytes.resize(compLength);
- z_stream zs;
- memset(&zs, 0, sizeof(zs));
+ z_stream zs;
+ memset(&zs, 0, sizeof(zs));
- if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (16 + MAX_WBITS), 8, Z_DEFAULT_STRATEGY) != Z_OK)
- {
- return false;
- }
+ if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (16 + MAX_WBITS), 8, Z_DEFAULT_STRATEGY) != Z_OK)
+ {
+ return false;
+ }
- zs.next_in = (Bytef*)uncompressedBytes.data();
- zs.avail_in = uncompressedBytes.size();
+ zs.next_in = (Bytef*)uncompressedBytes.data();
+ zs.avail_in = uncompressedBytes.size();
- int ret;
- compressedBytes.resize(uncompressedBytes.size());
+ int ret;
+ compressedBytes.resize(uncompressedBytes.size());
- unsigned offset = 0;
- unsigned temp = 0;
- do
- {
- auto remaining = compressedBytes.size() - offset;
- if(remaining < 1)
- {
- compressedBytes.resize(compressedBytes.size() * 2);
- }
- zs.next_out = (Bytef *) (compressedBytes.data() + offset);
- temp = zs.avail_out = compressedBytes.size() - offset;
- ret = deflate(&zs, Z_FINISH);
- offset += temp - zs.avail_out;
- } while (ret == Z_OK);
+ unsigned offset = 0;
+ unsigned temp = 0;
+ do
+ {
+ auto remaining = compressedBytes.size() - offset;
+ if(remaining < 1)
+ {
+ compressedBytes.resize(compressedBytes.size() * 2);
+ }
+ zs.next_out = (Bytef *) (compressedBytes.data() + offset);
+ temp = zs.avail_out = compressedBytes.size() - offset;
+ ret = deflate(&zs, Z_FINISH);
+ offset += temp - zs.avail_out;
+ } while (ret == Z_OK);
- compressedBytes.resize(offset);
+ compressedBytes.resize(offset);
- if (deflateEnd(&zs) != Z_OK)
- {
- return false;
- }
+ if (deflateEnd(&zs) != Z_OK)
+ {
+ return false;
+ }
- if (ret != Z_STREAM_END)
- {
- return false;
- }
- return true;
+ if (ret != Z_STREAM_END)
+ {
+ return false;
+ }
+ return true;
}
\ No newline at end of file
diff --git a/api/logic/GZip.h b/api/logic/GZip.h
index 6993a222..c7eddbb3 100644
--- a/api/logic/GZip.h
+++ b/api/logic/GZip.h
@@ -6,7 +6,7 @@
class MULTIMC_LOGIC_EXPORT GZip
{
public:
- static bool unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes);
- static bool zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes);
+ static bool unzip(const QByteArray &compressedBytes, QByteArray &uncompressedBytes);
+ static bool zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes);
};
diff --git a/api/logic/GZip_test.cpp b/api/logic/GZip_test.cpp
index f4c9214c..3f4d181c 100644
--- a/api/logic/GZip_test.cpp
+++ b/api/logic/GZip_test.cpp
@@ -6,50 +6,50 @@
void fib(int &prev, int &cur)
{
- auto ret = prev + cur;
- prev = cur;
- cur = ret;
+ auto ret = prev + cur;
+ prev = cur;
+ cur = ret;
}
class GZipTest : public QObject
{
- Q_OBJECT
+ Q_OBJECT
private
slots:
- void test_Through()
- {
- // test up to 10 MB
- static const int size = 10 * 1024 * 1024;
- QByteArray random;
- QByteArray compressed;
- QByteArray decompressed;
- std::default_random_engine eng((std::random_device())());
- std::uniform_int_distribution idis(0, std::numeric_limits::max());
+ void test_Through()
+ {
+ // test up to 10 MB
+ static const int size = 10 * 1024 * 1024;
+ QByteArray random;
+ QByteArray compressed;
+ QByteArray decompressed;
+ std::default_random_engine eng((std::random_device())());
+ std::uniform_int_distribution idis(0, std::numeric_limits::max());
- // initialize random buffer
- for(int i = 0; i < size; i++)
- {
- random.append((char)idis(eng));
- }
+ // initialize random buffer
+ for(int i = 0; i < size; i++)
+ {
+ random.append((char)idis(eng));
+ }
- // initialize fibonacci
- int prev = 1;
- int cur = 1;
+ // initialize fibonacci
+ int prev = 1;
+ int cur = 1;
- // test if fibonacci long random buffers pass through GZip
- do
- {
- QByteArray copy = random;
- copy.resize(cur);
- compressed.clear();
- decompressed.clear();
- QVERIFY(GZip::zip(copy, compressed));
- QVERIFY(GZip::unzip(compressed, decompressed));
- QCOMPARE(decompressed, copy);
- fib(prev, cur);
- } while (cur < size);
- }
+ // test if fibonacci long random buffers pass through GZip
+ do
+ {
+ QByteArray copy = random;
+ copy.resize(cur);
+ compressed.clear();
+ decompressed.clear();
+ QVERIFY(GZip::zip(copy, compressed));
+ QVERIFY(GZip::unzip(compressed, decompressed));
+ QCOMPARE(decompressed, copy);
+ fib(prev, cur);
+ } while (cur < size);
+ }
};
QTEST_GUILESS_MAIN(GZipTest)
diff --git a/api/logic/InstanceCopyTask.cpp b/api/logic/InstanceCopyTask.cpp
index 62c22362..cb2deb29 100644
--- a/api/logic/InstanceCopyTask.cpp
+++ b/api/logic/InstanceCopyTask.cpp
@@ -8,50 +8,50 @@
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves)
{
- m_origInstance = origInstance;
+ m_origInstance = origInstance;
- if(!copySaves)
- {
- // FIXME: get this from the original instance type...
- auto matcherReal = new RegexpMatcher("[.]?minecraft/saves");
- matcherReal->caseSensitive(false);
- m_matcher.reset(matcherReal);
- }
+ 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()));
+ setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
- FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
- folderCopy.followSymlinks(false).blacklist(m_matcher.get());
+ 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::finished, this, &InstanceCopyTask::copyFinished);
- connect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &InstanceCopyTask::copyAborted);
- m_copyFutureWatcher.setFuture(m_copyFuture);
+ m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
+ connect(&m_copyFutureWatcher, &QFutureWatcher::finished, this, &InstanceCopyTask::copyFinished);
+ connect(&m_copyFutureWatcher, &QFutureWatcher::canceled, this, &InstanceCopyTask::copyAborted);
+ m_copyFutureWatcher.setFuture(m_copyFuture);
}
void InstanceCopyTask::copyFinished()
{
- auto successful = m_copyFuture.result();
- if(!successful)
- {
- emitFailed(tr("Instance folder copy failed."));
- return;
- }
- // FIXME: shouldn't this be able to report errors?
- auto instanceSettings = std::make_shared(FS::PathCombine(m_stagingPath, "instance.cfg"));
- instanceSettings->registerSetting("InstanceType", "Legacy");
+ auto successful = m_copyFuture.result();
+ if(!successful)
+ {
+ emitFailed(tr("Instance folder copy failed."));
+ return;
+ }
+ // FIXME: shouldn't this be able to report errors?
+ auto instanceSettings = std::make_shared(FS::PathCombine(m_stagingPath, "instance.cfg"));
+ instanceSettings->registerSetting("InstanceType", "Legacy");
- InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
- inst->setName(m_instName);
- inst->setIconKey(m_instIcon);
- emitSucceeded();
+ InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
+ inst->setName(m_instName);
+ inst->setIconKey(m_instIcon);
+ emitSucceeded();
}
void InstanceCopyTask::copyAborted()
{
- emitFailed(tr("Instance folder copy has been aborted."));
- return;
+ emitFailed(tr("Instance folder copy has been aborted."));
+ return;
}
diff --git a/api/logic/InstanceCopyTask.h b/api/logic/InstanceCopyTask.h
index a8dc9783..0a338f2f 100644
--- a/api/logic/InstanceCopyTask.h
+++ b/api/logic/InstanceCopyTask.h
@@ -15,19 +15,19 @@ class BaseInstanceProvider;
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves);
+ explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves);
protected:
- //! Entry point for tasks.
- virtual void executeTask() override;
- void copyFinished();
- void copyAborted();
+ //! Entry point for tasks.
+ virtual void executeTask() override;
+ void copyFinished();
+ void copyAborted();
private: /* data */
- InstancePtr m_origInstance;
- QFuture m_copyFuture;
- QFutureWatcher m_copyFutureWatcher;
- std::unique_ptr m_matcher;
+ InstancePtr m_origInstance;
+ QFuture m_copyFuture;
+ QFutureWatcher m_copyFutureWatcher;
+ std::unique_ptr m_matcher;
};
diff --git a/api/logic/InstanceCreationTask.cpp b/api/logic/InstanceCreationTask.cpp
index 6dc2496c..7ac474ec 100644
--- a/api/logic/InstanceCreationTask.cpp
+++ b/api/logic/InstanceCreationTask.cpp
@@ -9,25 +9,25 @@
InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version)
{
- m_version = version;
+ m_version = version;
}
void InstanceCreationTask::executeTask()
{
- setStatus(tr("Creating instance from version %1").arg(m_version->name()));
- {
- auto instanceSettings = std::make_shared(FS::PathCombine(m_stagingPath, "instance.cfg"));
- instanceSettings->suspendSave();
- instanceSettings->registerSetting("InstanceType", "Legacy");
- instanceSettings->set("InstanceType", "OneSix");
- MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
- auto components = inst.getComponentList();
- components->buildingFromScratch();
- components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
- inst.setName(m_instName);
- inst.setIconKey(m_instIcon);
- inst.init();
- instanceSettings->resumeSave();
- }
- emitSucceeded();
+ setStatus(tr("Creating instance from version %1").arg(m_version->name()));
+ {
+ auto instanceSettings = std::make_shared(FS::PathCombine(m_stagingPath, "instance.cfg"));
+ instanceSettings->suspendSave();
+ instanceSettings->registerSetting("InstanceType", "Legacy");
+ instanceSettings->set("InstanceType", "OneSix");
+ MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
+ auto components = inst.getComponentList();
+ components->buildingFromScratch();
+ components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
+ inst.setName(m_instName);
+ inst.setIconKey(m_instIcon);
+ inst.init();
+ instanceSettings->resumeSave();
+ }
+ emitSucceeded();
}
diff --git a/api/logic/InstanceCreationTask.h b/api/logic/InstanceCreationTask.h
index e06eacbb..154a854f 100644
--- a/api/logic/InstanceCreationTask.h
+++ b/api/logic/InstanceCreationTask.h
@@ -10,14 +10,14 @@
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public InstanceTask
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit InstanceCreationTask(BaseVersionPtr version);
+ explicit InstanceCreationTask(BaseVersionPtr version);
protected:
- //! Entry point for tasks.
- virtual void executeTask() override;
+ //! Entry point for tasks.
+ virtual void executeTask() override;
private: /* data */
- BaseVersionPtr m_version;
+ BaseVersionPtr m_version;
};
diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp
index 45037908..f3e0858d 100644
--- a/api/logic/InstanceImportTask.cpp
+++ b/api/logic/InstanceImportTask.cpp
@@ -18,394 +18,394 @@
InstanceImportTask::InstanceImportTask(const QUrl sourceUrl)
{
- m_sourceUrl = sourceUrl;
+ m_sourceUrl = sourceUrl;
}
void InstanceImportTask::executeTask()
{
- InstancePtr newInstance;
+ InstancePtr newInstance;
- if (m_sourceUrl.isLocalFile())
- {
- m_archivePath = m_sourceUrl.toLocalFile();
- processZipPack();
- }
- else
- {
- setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
- m_downloadRequired = true;
+ if (m_sourceUrl.isLocalFile())
+ {
+ m_archivePath = m_sourceUrl.toLocalFile();
+ processZipPack();
+ }
+ 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();
- }
+ 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()
{
- processZipPack();
- m_filesNetJob.reset();
+ processZipPack();
+ m_filesNetJob.reset();
}
void InstanceImportTask::downloadFailed(QString reason)
{
- emitFailed(reason);
- m_filesNetJob.reset();
+ emitFailed(reason);
+ m_filesNetJob.reset();
}
void InstanceImportTask::downloadProgressChanged(qint64 current, qint64 total)
{
- setProgress(current / 2, total);
+ setProgress(current / 2, total);
}
void InstanceImportTask::processZipPack()
{
- setStatus(tr("Extracting modpack"));
- QDir extractDir(m_stagingPath);
- qDebug() << "Attempting to create instance from" << m_archivePath;
+ setStatus(tr("Extracting modpack"));
+ QDir extractDir(m_stagingPath);
+ qDebug() << "Attempting to create instance from" << m_archivePath;
- // open the zip and find relevant files in it
- m_packZip.reset(new QuaZip(m_archivePath));
- if (!m_packZip->open(QuaZip::mdUnzip))
- {
- emitFailed(tr("Unable to open supplied modpack zip file."));
- return;
- }
+ // open the zip and find relevant files in it
+ m_packZip.reset(new QuaZip(m_archivePath));
+ if (!m_packZip->open(QuaZip::mdUnzip))
+ {
+ emitFailed(tr("Unable to open supplied modpack zip file."));
+ return;
+ }
- QStringList blacklist = {"instance.cfg", "manifest.json"};
- QString mmcFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg");
- QString flameFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json");
- QString root;
- if(!mmcFound.isNull())
- {
- // process as MultiMC instance/pack
- qDebug() << "MultiMC:" << mmcFound;
- root = mmcFound;
- m_modpackType = ModpackType::MultiMC;
- }
- else if(!flameFound.isNull())
- {
- // process as Flame pack
- qDebug() << "Flame:" << flameFound;
- root = flameFound;
- m_modpackType = ModpackType::Flame;
- }
+ QStringList blacklist = {"instance.cfg", "manifest.json"};
+ QString mmcFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg");
+ QString flameFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json");
+ QString root;
+ if(!mmcFound.isNull())
+ {
+ // process as MultiMC instance/pack
+ qDebug() << "MultiMC:" << mmcFound;
+ root = mmcFound;
+ m_modpackType = ModpackType::MultiMC;
+ }
+ else if(!flameFound.isNull())
+ {
+ // process as Flame pack
+ qDebug() << "Flame:" << flameFound;
+ root = flameFound;
+ m_modpackType = ModpackType::Flame;
+ }
- if(m_modpackType == ModpackType::Unknown)
- {
- emitFailed(tr("Archive does not contain a recognized modpack type."));
- return;
- }
+ if(m_modpackType == ModpackType::Unknown)
+ {
+ emitFailed(tr("Archive does not contain a recognized modpack type."));
+ return;
+ }
- // make sure we extract just the pack
- m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
- connect(&m_extractFutureWatcher, &QFutureWatcher::finished, this, &InstanceImportTask::extractFinished);
- connect(&m_extractFutureWatcher, &QFutureWatcher::canceled, this, &InstanceImportTask::extractAborted);
- m_extractFutureWatcher.setFuture(m_extractFuture);
+ // make sure we extract just the pack
+ m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
+ connect(&m_extractFutureWatcher, &QFutureWatcher::finished, this, &InstanceImportTask::extractFinished);
+ connect(&m_extractFutureWatcher, &QFutureWatcher::canceled, this, &InstanceImportTask::extractAborted);
+ m_extractFutureWatcher.setFuture(m_extractFuture);
}
void InstanceImportTask::extractFinished()
{
- m_packZip.reset();
- if (m_extractFuture.result().isEmpty())
- {
- emitFailed(tr("Failed to extract modpack"));
- return;
- }
- QDir extractDir(m_stagingPath);
+ m_packZip.reset();
+ if (m_extractFuture.result().isEmpty())
+ {
+ emitFailed(tr("Failed to extract modpack"));
+ return;
+ }
+ QDir extractDir(m_stagingPath);
- qDebug() << "Fixing permissions for extracted pack files...";
- QDirIterator it(extractDir, QDirIterator::Subdirectories);
- while (it.hasNext())
- {
- auto filepath = it.next();
- QFileInfo file(filepath);
- auto permissions = QFile::permissions(filepath);
- auto origPermissions = permissions;
- if(file.isDir())
- {
- // Folder +rwx for current user
- permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser;
- }
- else
- {
- // File +rw for current user
- permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser;
- }
- if(origPermissions != permissions)
- {
- if(!QFile::setPermissions(filepath, permissions))
- {
- logWarning(tr("Could not fix permissions for %1").arg(filepath));
- }
- else
- {
- qDebug() << "Fixed" << filepath;
- }
- }
- }
+ qDebug() << "Fixing permissions for extracted pack files...";
+ QDirIterator it(extractDir, QDirIterator::Subdirectories);
+ while (it.hasNext())
+ {
+ auto filepath = it.next();
+ QFileInfo file(filepath);
+ auto permissions = QFile::permissions(filepath);
+ auto origPermissions = permissions;
+ if(file.isDir())
+ {
+ // Folder +rwx for current user
+ permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser;
+ }
+ else
+ {
+ // File +rw for current user
+ permissions |= QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser;
+ }
+ if(origPermissions != permissions)
+ {
+ if(!QFile::setPermissions(filepath, permissions))
+ {
+ logWarning(tr("Could not fix permissions for %1").arg(filepath));
+ }
+ else
+ {
+ qDebug() << "Fixed" << filepath;
+ }
+ }
+ }
- switch(m_modpackType)
- {
- case ModpackType::Flame:
- processFlame();
- return;
- case ModpackType::MultiMC:
- processMultiMC();
- return;
- case ModpackType::Unknown:
- emitFailed(tr("Archive does not contain a recognized modpack type."));
- return;
- }
+ switch(m_modpackType)
+ {
+ case ModpackType::Flame:
+ processFlame();
+ return;
+ case ModpackType::MultiMC:
+ processMultiMC();
+ return;
+ case ModpackType::Unknown:
+ emitFailed(tr("Archive does not contain a recognized modpack type."));
+ return;
+ }
}
void InstanceImportTask::extractAborted()
{
- emitFailed(tr("Instance import has been aborted."));
- return;
+ emitFailed(tr("Instance import has been aborted."));
+ return;
}
void InstanceImportTask::processFlame()
{
- const static QMap forgemap = {
- {"1.2.5", "3.4.9.171"},
- {"1.4.2", "6.0.1.355"},
- {"1.4.7", "6.6.2.534"},
- {"1.5.2", "7.8.1.737"}
- };
- Flame::Manifest pack;
- try
- {
- QString configPath = FS::PathCombine(m_stagingPath, "manifest.json");
- Flame::loadManifest(pack, configPath);
- QFile::remove(configPath);
- }
- catch (const JSONValidationError &e)
- {
- emitFailed(tr("Could not understand pack manifest:\n") + e.cause());
- return;
- }
- if(!pack.overrides.isEmpty())
- {
- QString overridePath = FS::PathCombine(m_stagingPath, pack.overrides);
- if (QFile::exists(overridePath))
- {
- QString mcPath = FS::PathCombine(m_stagingPath, "minecraft");
- if (!QFile::rename(overridePath, mcPath))
- {
- emitFailed(tr("Could not rename the overrides folder:\n") + pack.overrides);
- return;
- }
- }
- else
- {
- logWarning(tr("The specified overrides folder (%1) is missing. Maybe the modpack was already used before?").arg(pack.overrides));
- }
- }
+ const static QMap forgemap = {
+ {"1.2.5", "3.4.9.171"},
+ {"1.4.2", "6.0.1.355"},
+ {"1.4.7", "6.6.2.534"},
+ {"1.5.2", "7.8.1.737"}
+ };
+ Flame::Manifest pack;
+ try
+ {
+ QString configPath = FS::PathCombine(m_stagingPath, "manifest.json");
+ Flame::loadManifest(pack, configPath);
+ QFile::remove(configPath);
+ }
+ catch (const JSONValidationError &e)
+ {
+ emitFailed(tr("Could not understand pack manifest:\n") + e.cause());
+ return;
+ }
+ if(!pack.overrides.isEmpty())
+ {
+ QString overridePath = FS::PathCombine(m_stagingPath, pack.overrides);
+ if (QFile::exists(overridePath))
+ {
+ QString mcPath = FS::PathCombine(m_stagingPath, "minecraft");
+ if (!QFile::rename(overridePath, mcPath))
+ {
+ emitFailed(tr("Could not rename the overrides folder:\n") + pack.overrides);
+ return;
+ }
+ }
+ else
+ {
+ logWarning(tr("The specified overrides folder (%1) is missing. Maybe the modpack was already used before?").arg(pack.overrides));
+ }
+ }
- QString forgeVersion;
- for(auto &loader: pack.minecraft.modLoaders)
- {
- auto id = loader.id;
- if(id.startsWith("forge-"))
- {
- id.remove("forge-");
- forgeVersion = id;
- continue;
- }
- logWarning(tr("Unknown mod loader in manifest: %1").arg(id));
- }
+ QString forgeVersion;
+ for(auto &loader: pack.minecraft.modLoaders)
+ {
+ auto id = loader.id;
+ if(id.startsWith("forge-"))
+ {
+ id.remove("forge-");
+ forgeVersion = id;
+ continue;
+ }
+ logWarning(tr("Unknown mod loader in manifest: %1").arg(id));
+ }
- QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
- auto instanceSettings = std::make_shared(configPath);
- instanceSettings->registerSetting("InstanceType", "Legacy");
- instanceSettings->set("InstanceType", "OneSix");
- MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
- auto mcVersion = pack.minecraft.version;
- // Hack to correct some 'special sauce'...
- if(mcVersion.endsWith('.'))
- {
- mcVersion.remove(QRegExp("[.]+$"));
- logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
- }
- auto components = instance.getComponentList();
- components->buildingFromScratch();
- components->setComponentVersion("net.minecraft", mcVersion, true);
- if(!forgeVersion.isEmpty())
- {
- // FIXME: dirty, nasty, hack. Proper solution requires dependency resolution and knowledge of the metadata.
- if(forgeVersion == "recommended")
- {
- if(forgemap.contains(mcVersion))
- {
- forgeVersion = forgemap[mcVersion];
- }
- else
- {
- logWarning(tr("Could not map recommended forge version for Minecraft %1").arg(mcVersion));
- }
- }
- components->setComponentVersion("net.minecraftforge", forgeVersion);
- }
- if (m_instIcon != "default")
- {
- instance.setIconKey(m_instIcon);
- }
- else
- {
- if(pack.name.contains("Direwolf20"))
- {
- instance.setIconKey("steve");
- }
- else if(pack.name.contains("FTB") || pack.name.contains("Feed The Beast"))
- {
- instance.setIconKey("ftb_logo");
- }
- else
- {
- // default to something other than the MultiMC default to distinguish these
- instance.setIconKey("flame");
- }
- }
- instance.init();
- QString jarmodsPath = FS::PathCombine(m_stagingPath, "minecraft", "jarmods");
- QFileInfo jarmodsInfo(jarmodsPath);
- if(jarmodsInfo.isDir())
- {
- // install all the jar mods
- qDebug() << "Found jarmods:";
- QDir jarmodsDir(jarmodsPath);
- QStringList jarMods;
- for (auto info: jarmodsDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files))
- {
- qDebug() << info.fileName();
- jarMods.push_back(info.absoluteFilePath());
- }
- auto profile = instance.getComponentList();
- profile->installJarMods(jarMods);
- // nuke the original files
- FS::deletePath(jarmodsPath);
- }
- instance.setName(m_instName);
- m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
- connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
- {
- auto results = m_modIdResolver->getResults();
- m_filesNetJob.reset(new NetJob(tr("Mod download")));
- for(auto result: results.files)
- {
- QString filename = result.fileName;
- if(!result.required)
- {
- filename += ".disabled";
- }
+ QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
+ auto instanceSettings = std::make_shared(configPath);
+ instanceSettings->registerSetting("InstanceType", "Legacy");
+ instanceSettings->set("InstanceType", "OneSix");
+ MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
+ auto mcVersion = pack.minecraft.version;
+ // Hack to correct some 'special sauce'...
+ if(mcVersion.endsWith('.'))
+ {
+ mcVersion.remove(QRegExp("[.]+$"));
+ logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
+ }
+ auto components = instance.getComponentList();
+ components->buildingFromScratch();
+ components->setComponentVersion("net.minecraft", mcVersion, true);
+ if(!forgeVersion.isEmpty())
+ {
+ // FIXME: dirty, nasty, hack. Proper solution requires dependency resolution and knowledge of the metadata.
+ if(forgeVersion == "recommended")
+ {
+ if(forgemap.contains(mcVersion))
+ {
+ forgeVersion = forgemap[mcVersion];
+ }
+ else
+ {
+ logWarning(tr("Could not map recommended forge version for Minecraft %1").arg(mcVersion));
+ }
+ }
+ components->setComponentVersion("net.minecraftforge", forgeVersion);
+ }
+ if (m_instIcon != "default")
+ {
+ instance.setIconKey(m_instIcon);
+ }
+ else
+ {
+ if(pack.name.contains("Direwolf20"))
+ {
+ instance.setIconKey("steve");
+ }
+ else if(pack.name.contains("FTB") || pack.name.contains("Feed The Beast"))
+ {
+ instance.setIconKey("ftb_logo");
+ }
+ else
+ {
+ // default to something other than the MultiMC default to distinguish these
+ instance.setIconKey("flame");
+ }
+ }
+ instance.init();
+ QString jarmodsPath = FS::PathCombine(m_stagingPath, "minecraft", "jarmods");
+ QFileInfo jarmodsInfo(jarmodsPath);
+ if(jarmodsInfo.isDir())
+ {
+ // install all the jar mods
+ qDebug() << "Found jarmods:";
+ QDir jarmodsDir(jarmodsPath);
+ QStringList jarMods;
+ for (auto info: jarmodsDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files))
+ {
+ qDebug() << info.fileName();
+ jarMods.push_back(info.absoluteFilePath());
+ }
+ auto profile = instance.getComponentList();
+ profile->installJarMods(jarMods);
+ // nuke the original files
+ FS::deletePath(jarmodsPath);
+ }
+ instance.setName(m_instName);
+ m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
+ connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
+ {
+ auto results = m_modIdResolver->getResults();
+ m_filesNetJob.reset(new NetJob(tr("Mod download")));
+ for(auto result: results.files)
+ {
+ QString filename = result.fileName;
+ if(!result.required)
+ {
+ filename += ".disabled";
+ }
- auto relpath = FS::PathCombine("minecraft", result.targetFolder, filename);
- auto path = FS::PathCombine(m_stagingPath , relpath);
+ auto relpath = FS::PathCombine("minecraft", result.targetFolder, filename);
+ auto path = FS::PathCombine(m_stagingPath , relpath);
- switch(result.type)
- {
- case Flame::File::Type::Folder:
- {
- logWarning(tr("This 'Folder' may need extracting: %1").arg(relpath));
- // fall-through intentional, we treat these as plain old mods and dump them wherever.
- }
- case Flame::File::Type::SingleFile:
- case Flame::File::Type::Mod:
- {
- qDebug() << "Will download" << result.url << "to" << path;
- auto dl = Net::Download::makeFile(result.url, path);
- m_filesNetJob->addNetAction(dl);
- break;
- }
- case Flame::File::Type::Modpack:
- logWarning(tr("Nesting modpacks in modpacks is not implemented, nothing was downloaded: %1").arg(relpath));
- break;
- case Flame::File::Type::Cmod2:
- case Flame::File::Type::Ctoc:
- case Flame::File::Type::Unknown:
- logWarning(tr("Unrecognized/unhandled PackageType for: %1").arg(relpath));
- break;
- }
- }
- m_modIdResolver.reset();
- connect(m_filesNetJob.get(), &NetJob::succeeded, this, [&]()
- {
- m_filesNetJob.reset();
- emitSucceeded();
- }
- );
- connect(m_filesNetJob.get(), &NetJob::failed, [&](QString reason)
- {
- m_filesNetJob.reset();
- emitFailed(reason);
- });
- connect(m_filesNetJob.get(), &NetJob::progress, [&](qint64 current, qint64 total)
- {
- setProgress(current, total);
- });
- setStatus(tr("Downloading mods..."));
- m_filesNetJob->start();
- }
- );
- connect(m_modIdResolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason)
- {
- m_modIdResolver.reset();
- emitFailed(tr("Unable to resolve mod IDs:\n") + reason);
- });
- connect(m_modIdResolver.get(), &Flame::FileResolvingTask::progress, [&](qint64 current, qint64 total)
- {
- setProgress(current, total);
- });
- connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status)
- {
- setStatus(status);
- });
- m_modIdResolver->start();
+ switch(result.type)
+ {
+ case Flame::File::Type::Folder:
+ {
+ logWarning(tr("This 'Folder' may need extracting: %1").arg(relpath));
+ // fall-through intentional, we treat these as plain old mods and dump them wherever.
+ }
+ case Flame::File::Type::SingleFile:
+ case Flame::File::Type::Mod:
+ {
+ qDebug() << "Will download" << result.url << "to" << path;
+ auto dl = Net::Download::makeFile(result.url, path);
+ m_filesNetJob->addNetAction(dl);
+ break;
+ }
+ case Flame::File::Type::Modpack:
+ logWarning(tr("Nesting modpacks in modpacks is not implemented, nothing was downloaded: %1").arg(relpath));
+ break;
+ case Flame::File::Type::Cmod2:
+ case Flame::File::Type::Ctoc:
+ case Flame::File::Type::Unknown:
+ logWarning(tr("Unrecognized/unhandled PackageType for: %1").arg(relpath));
+ break;
+ }
+ }
+ m_modIdResolver.reset();
+ connect(m_filesNetJob.get(), &NetJob::succeeded, this, [&]()
+ {
+ m_filesNetJob.reset();
+ emitSucceeded();
+ }
+ );
+ connect(m_filesNetJob.get(), &NetJob::failed, [&](QString reason)
+ {
+ m_filesNetJob.reset();
+ emitFailed(reason);
+ });
+ connect(m_filesNetJob.get(), &NetJob::progress, [&](qint64 current, qint64 total)
+ {
+ setProgress(current, total);
+ });
+ setStatus(tr("Downloading mods..."));
+ m_filesNetJob->start();
+ }
+ );
+ connect(m_modIdResolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason)
+ {
+ m_modIdResolver.reset();
+ emitFailed(tr("Unable to resolve mod IDs:\n") + reason);
+ });
+ connect(m_modIdResolver.get(), &Flame::FileResolvingTask::progress, [&](qint64 current, qint64 total)
+ {
+ setProgress(current, total);
+ });
+ connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status)
+ {
+ setStatus(status);
+ });
+ m_modIdResolver->start();
}
void InstanceImportTask::processMultiMC()
{
- // FIXME: copy from FolderInstanceProvider!!! FIX IT!!!
- QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
- auto instanceSettings = std::make_shared(configPath);
- instanceSettings->registerSetting("InstanceType", "Legacy");
+ // FIXME: copy from FolderInstanceProvider!!! FIX IT!!!
+ QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg");
+ auto instanceSettings = std::make_shared(configPath);
+ instanceSettings->registerSetting("InstanceType", "Legacy");
- NullInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
+ NullInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
- // reset time played on import... because packs.
- instance.resetTimePlayed();
+ // reset time played on import... because packs.
+ instance.resetTimePlayed();
- // set a new nice name
- instance.setName(m_instName);
+ // 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});
- }
- }
- emitSucceeded();
+ // 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});
+ }
+ }
+ emitSucceeded();
}
diff --git a/api/logic/InstanceImportTask.h b/api/logic/InstanceImportTask.h
index 06778dfe..4156aa48 100644
--- a/api/logic/InstanceImportTask.h
+++ b/api/logic/InstanceImportTask.h
@@ -13,43 +13,43 @@ class QuaZip;
class BaseInstanceProvider;
namespace Flame
{
- class FileResolvingTask;
+ class FileResolvingTask;
}
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public InstanceTask
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit InstanceImportTask(const QUrl sourceUrl);
+ explicit InstanceImportTask(const QUrl sourceUrl);
protected:
- //! Entry point for tasks.
- virtual void executeTask() override;
+ //! Entry point for tasks.
+ virtual void executeTask() override;
private:
- void processZipPack();
- void processMultiMC();
- void processFlame();
+ void processZipPack();
+ void processMultiMC();
+ void processFlame();
private slots:
- void downloadSucceeded();
- void downloadFailed(QString reason);
- void downloadProgressChanged(qint64 current, qint64 total);
- void extractFinished();
- void extractAborted();
+ void downloadSucceeded();
+ void downloadFailed(QString reason);
+ void downloadProgressChanged(qint64 current, qint64 total);
+ void extractFinished();
+ void extractAborted();
private: /* data */
- NetJobPtr m_filesNetJob;
- shared_qobject_ptr m_modIdResolver;
- QUrl m_sourceUrl;
- QString m_archivePath;
- bool m_downloadRequired = false;
- std::unique_ptr m_packZip;
- QFuture m_extractFuture;
- QFutureWatcher m_extractFutureWatcher;
- enum class ModpackType{
- Unknown,
- MultiMC,
- Flame
- } m_modpackType = ModpackType::Unknown;
+ NetJobPtr m_filesNetJob;
+ shared_qobject_ptr m_modIdResolver;
+ QUrl m_sourceUrl;
+ QString m_archivePath;
+ bool m_downloadRequired = false;
+ std::unique_ptr m_packZip;
+ QFuture m_extractFuture;
+ QFutureWatcher m_extractFutureWatcher;
+ enum class ModpackType{
+ Unknown,
+ MultiMC,
+ Flame
+ } m_modpackType = ModpackType::Unknown;
};
diff --git a/api/logic/InstanceList.cpp b/api/logic/InstanceList.cpp
index 75b523e4..c7a22b08 100644
--- a/api/logic/InstanceList.cpp
+++ b/api/logic/InstanceList.cpp
@@ -27,9 +27,9 @@
#include "FolderInstanceProvider.h"
InstanceList::InstanceList(QObject *parent)
- : QAbstractListModel(parent)
+ : QAbstractListModel(parent)
{
- resumeWatch();
+ resumeWatch();
}
InstanceList::~InstanceList()
@@ -38,310 +38,310 @@ InstanceList::~InstanceList()
int InstanceList::rowCount(const QModelIndex &parent) const
{
- Q_UNUSED(parent);
- return m_instances.count();
+ 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());
+ 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(index.internalPointer());
- switch (role)
- {
- case InstancePointerRole:
- {
- QVariant v = qVariantFromValue((void *)pdata);
- return v;
- }
- case InstanceIDRole:
+ if (!index.isValid())
+ {
+ return QVariant();
+ }
+ BaseInstance *pdata = static_cast(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();
+ 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;
+ Qt::ItemFlags f;
+ if (index.isValid())
+ {
+ f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ }
+ return f;
}
QStringList InstanceList::getGroups()
{
- return m_groups.toList();
+ 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());
- }
- }
+ for(auto & instance: m_instances)
+ {
+ auto instGroupName = instance->group();
+ if(instGroupName == name)
+ {
+ instance->setGroupPost(QString());
+ }
+ }
}
static QMap getIdMapping(const QList &list)
{
- QMap 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;
+ QMap 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);
+ auto existingIds = getIdMapping(m_instances);
- QList newList;
+ QList newList;
- auto processIds = [&](BaseInstanceProvider * provider, QList 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());
- }
- }
+ auto processIds = [&](BaseInstanceProvider * provider, QList 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;
+ // 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::saveNow()
{
- for(auto & item: m_instances)
- {
- item->saveNow();
- }
+ for(auto & item: m_instances)
+ {
+ item->saveNow();
+ }
}
void InstanceList::add(const QList &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();
+ 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();
- }
+ 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 --;
+ m_watchLevel --;
}
void InstanceList::providerUpdated()
{
- auto provider = dynamic_cast(QObject::sender());
- if(!provider)
- {
- qWarning() << "InstanceList::providerUpdated triggered by a non-provider";
- return;
- }
- m_updatedProviders.insert(provider);
- if(m_watchLevel == 1)
- {
- loadList();
- }
+ auto provider = dynamic_cast(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 newGroups)
{
- m_groups.unite(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);
+ 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();
+ 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()));
+ 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;
+ 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));
- }
+ int i = getInstIndex(inst);
+ if (i != -1)
+ {
+ emit dataChanged(index(i), index(i));
+ }
}
diff --git a/api/logic/InstanceList.h b/api/logic/InstanceList.h
index bb879c83..7fe5ea34 100644
--- a/api/logic/InstanceList.h
+++ b/api/logic/InstanceList.h
@@ -31,75 +31,75 @@ class BaseInstance;
class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit InstanceList(QObject *parent = 0);
- virtual ~InstanceList();
+ explicit InstanceList(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;
+ 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
- };
+ 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);
- }
+ InstancePtr at(int i) const
+ {
+ return m_instances.at(i);
+ }
- int count() const
- {
- return m_instances.count();
- }
+ int count() const
+ {
+ return m_instances.count();
+ }
- InstListError loadList(bool complete = false);
- void saveNow();
+ InstListError loadList(bool complete = false);
+ void saveNow();
- /// Add an instance provider. Takes ownership of it. Should only be done before the first load.
- void addInstanceProvider(BaseInstanceProvider * provider);
+ /// 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();
+ InstancePtr getInstanceById(QString id) const;
+ QModelIndex getInstanceIndexById(const QString &id) const;
+ QStringList getGroups();
- void deleteGroup(const QString & name);
+ void deleteGroup(const QString & name);
signals:
- void dataIsInvalid();
+ void dataIsInvalid();
private slots:
- void propertiesChanged(BaseInstance *inst);
- void groupsPublished(QSet);
- void providerUpdated();
+ void propertiesChanged(BaseInstance *inst);
+ void groupsPublished(QSet);
+ void providerUpdated();
private:
- int getInstIndex(BaseInstance *inst) const;
- void suspendWatch();
- void resumeWatch();
- void add(const QList &list);
+ int getInstIndex(BaseInstance *inst) const;
+ void suspendWatch();
+ void resumeWatch();
+ void add(const QList &list);
protected:
- int m_watchLevel = 0;
- QSet m_updatedProviders;
- QList m_instances;
- QSet m_groups;
- QVector> m_providers;
+ int m_watchLevel = 0;
+ QSet m_updatedProviders;
+ QList m_instances;
+ QSet m_groups;
+ QVector> m_providers;
};
diff --git a/api/logic/InstanceTask.h b/api/logic/InstanceTask.h
index 8fc98eb7..5face5fc 100644
--- a/api/logic/InstanceTask.h
+++ b/api/logic/InstanceTask.h
@@ -8,48 +8,48 @@ class BaseInstanceProvider;
class MULTIMC_LOGIC_EXPORT InstanceTask : public Task
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit InstanceTask();
- virtual ~InstanceTask();
+ explicit InstanceTask();
+ virtual ~InstanceTask();
- void setParentSettings(SettingsObjectPtr settings)
- {
- m_globalSettings = settings;
- }
+ void setParentSettings(SettingsObjectPtr settings)
+ {
+ m_globalSettings = settings;
+ }
- void setStagingPath(const QString &stagingPath)
- {
- m_stagingPath = stagingPath;
- }
+ void setStagingPath(const QString &stagingPath)
+ {
+ m_stagingPath = stagingPath;
+ }
- void setName(const QString &name)
- {
- m_instName = name;
- }
- QString name() const
- {
- return m_instName;
- }
+ void setName(const QString &name)
+ {
+ m_instName = name;
+ }
+ QString name() const
+ {
+ return m_instName;
+ }
- void setIcon(const QString &icon)
- {
- m_instIcon = icon;
- }
+ void setIcon(const QString &icon)
+ {
+ m_instIcon = icon;
+ }
- void setGroup(const QString &group)
- {
- m_instGroup = group;
- }
- QString group() const
- {
- return m_instGroup;
- }
+ void setGroup(const QString &group)
+ {
+ m_instGroup = group;
+ }
+ QString group() const
+ {
+ return m_instGroup;
+ }
protected: /* data */
- SettingsObjectPtr m_globalSettings;
- QString m_instName;
- QString m_instIcon;
- QString m_instGroup;
- QString m_stagingPath;
+ SettingsObjectPtr m_globalSettings;
+ QString m_instName;
+ QString m_instIcon;
+ QString m_instGroup;
+ QString m_stagingPath;
};
diff --git a/api/logic/Json.cpp b/api/logic/Json.cpp
index f2cbc8a3..37ada1aa 100644
--- a/api/logic/Json.cpp
+++ b/api/logic/Json.cpp
@@ -11,262 +11,262 @@ namespace Json
{
void write(const QJsonDocument &doc, const QString &filename)
{
- FS::write(filename, doc.toJson());
+ FS::write(filename, doc.toJson());
}
void write(const QJsonObject &object, const QString &filename)
{
- write(QJsonDocument(object), filename);
+ write(QJsonDocument(object), filename);
}
void write(const QJsonArray &array, const QString &filename)
{
- write(QJsonDocument(array), filename);
+ write(QJsonDocument(array), filename);
}
QByteArray toBinary(const QJsonObject &obj)
{
- return QJsonDocument(obj).toBinaryData();
+ return QJsonDocument(obj).toBinaryData();
}
QByteArray toBinary(const QJsonArray &array)
{
- return QJsonDocument(array).toBinaryData();
+ return QJsonDocument(array).toBinaryData();
}
QByteArray toText(const QJsonObject &obj)
{
- return QJsonDocument(obj).toJson(QJsonDocument::Compact);
+ return QJsonDocument(obj).toJson(QJsonDocument::Compact);
}
QByteArray toText(const QJsonArray &array)
{
- return QJsonDocument(array).toJson(QJsonDocument::Compact);
+ return QJsonDocument(array).toJson(QJsonDocument::Compact);
}
static bool isBinaryJson(const QByteArray &data)
{
- decltype(QJsonDocument::BinaryFormatTag) tag = QJsonDocument::BinaryFormatTag;
- return memcmp(data.constData(), &tag, sizeof(QJsonDocument::BinaryFormatTag)) == 0;
+ decltype(QJsonDocument::BinaryFormatTag) tag = QJsonDocument::BinaryFormatTag;
+ return memcmp(data.constData(), &tag, sizeof(QJsonDocument::BinaryFormatTag)) == 0;
}
QJsonDocument requireDocument(const QByteArray &data, const QString &what)
{
- if (isBinaryJson(data))
- {
- QJsonDocument doc = QJsonDocument::fromBinaryData(data);
- if (doc.isNull())
- {
- throw JsonException(what + ": Invalid JSON (binary JSON detected)");
- }
- return doc;
- }
- else
- {
- QJsonParseError error;
- QJsonDocument doc = QJsonDocument::fromJson(data, &error);
- if (error.error != QJsonParseError::NoError)
- {
- throw JsonException(what + ": Error parsing JSON: " + error.errorString());
- }
- return doc;
- }
+ if (isBinaryJson(data))
+ {
+ QJsonDocument doc = QJsonDocument::fromBinaryData(data);
+ if (doc.isNull())
+ {
+ throw JsonException(what + ": Invalid JSON (binary JSON detected)");
+ }
+ return doc;
+ }
+ else
+ {
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &error);
+ if (error.error != QJsonParseError::NoError)
+ {
+ throw JsonException(what + ": Error parsing JSON: " + error.errorString());
+ }
+ return doc;
+ }
}
QJsonDocument requireDocument(const QString &filename, const QString &what)
{
- return requireDocument(FS::read(filename), what);
+ return requireDocument(FS::read(filename), what);
}
QJsonObject requireObject(const QJsonDocument &doc, const QString &what)
{
- if (!doc.isObject())
- {
- throw JsonException(what + " is not an object");
- }
- return doc.object();
+ if (!doc.isObject())
+ {
+ throw JsonException(what + " is not an object");
+ }
+ return doc.object();
}
QJsonArray requireArray(const QJsonDocument &doc, const QString &what)
{
- if (!doc.isArray())
- {
- throw JsonException(what + " is not an array");
- }
- return doc.array();
+ if (!doc.isArray())
+ {
+ throw JsonException(what + " is not an array");
+ }
+ return doc.array();
}
void writeString(QJsonObject &to, const QString &key, const QString &value)
{
- if (!value.isEmpty())
- {
- to.insert(key, value);
- }
+ if (!value.isEmpty())
+ {
+ to.insert(key, value);
+ }
}
void writeStringList(QJsonObject &to, const QString &key, const QStringList &values)
{
- if (!values.isEmpty())
- {
- QJsonArray array;
- for(auto value: values)
- {
- array.append(value);
- }
- to.insert(key, array);
- }
+ if (!values.isEmpty())
+ {
+ QJsonArray array;
+ for(auto value: values)
+ {
+ array.append(value);
+ }
+ to.insert(key, array);
+ }
}
template<>
QJsonValue toJson(const QUrl &url)
{
- return QJsonValue(url.toString(QUrl::FullyEncoded));
+ return QJsonValue(url.toString(QUrl::FullyEncoded));
}
template<>
QJsonValue toJson(const QByteArray &data)
{
- return QJsonValue(QString::fromLatin1(data.toHex()));
+ return QJsonValue(QString::fromLatin1(data.toHex()));
}
template<>
QJsonValue toJson(const QDateTime &datetime)
{
- return QJsonValue(datetime.toString(Qt::ISODate));
+ return QJsonValue(datetime.toString(Qt::ISODate));
}
template<>
QJsonValue toJson(const QDir &dir)
{
- return QDir::current().relativeFilePath(dir.absolutePath());
+ return QDir::current().relativeFilePath(dir.absolutePath());
}
template<>
QJsonValue toJson(const QUuid &uuid)
{
- return uuid.toString();
+ return uuid.toString();
}
template<>
QJsonValue toJson(const QVariant &variant)
{
- return QJsonValue::fromVariant(variant);
+ return QJsonValue::fromVariant(variant);
}
template<> QByteArray requireIsType(const QJsonValue &value, const QString &what)
{
- const QString string = ensureIsType(value, what);
- // ensure that the string can be safely cast to Latin1
- if (string != QString::fromLatin1(string.toLatin1()))
- {
- throw JsonException(what + " is not encodable as Latin1");
- }
- return QByteArray::fromHex(string.toLatin1());
+ const QString string = ensureIsType