From 90d4acd1a1c9abeb31548d152c155491e2cf98fa Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 23 Mar 2022 13:20:14 +0100 Subject: refactor: combine portable and system builds Portable builds now have the same layout as system builds. If you want to build a portable bundle, you now need to additionally install the `portable` component. For example: $ cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install ... $ cmake --build build $ cmake --install build $ cmake --install build --component portable --- launcher/Application.cpp | 53 +++++++++++++++++++++++++----------------------- launcher/Launcher.in | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'launcher') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 9cca534c..a9f7a0f0 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -316,6 +316,26 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) QString origcwdPath = QDir::currentPath(); QString binPath = applicationDirPath(); + + { + // Root path is used for updates and portable data +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) + QDir foo(FS::PathCombine(binPath, "..")); // typically portable-root or /usr + m_rootPath = foo.absolutePath(); +#elif defined(Q_OS_WIN32) + m_rootPath = binPath; +#elif defined(Q_OS_MAC) + QDir foo(FS::PathCombine(binPath, "../..")); + m_rootPath = foo.absolutePath(); + // on macOS, touch the root to force Finder to reload the .app metadata (and fix any icon change issues) + FS::updateTimestamp(m_rootPath); +#endif + +#ifdef LAUNCHER_JARS_LOCATION + m_jarsPath = TOSTRING(LAUNCHER_JARS_LOCATION); +#endif + } + QString adjustedBy; QString dataPath; // change folder @@ -324,15 +344,14 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) { // the dir param. it makes multimc data path point to whatever the user specified // on command line - adjustedBy += "Command line " + dirParam; + adjustedBy = "Command line"; dataPath = dirParam; } else { -#if !defined(LAUNCHER_PORTABLE) || defined(Q_OS_MAC) QDir foo(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), "..")); dataPath = foo.absolutePath(); - adjustedBy += dataPath; + adjustedBy = "Persistent data path"; #ifdef Q_OS_LINUX // TODO: this should be removed in a future version @@ -340,13 +359,14 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) QDir bar(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), "polymc")); if (bar.exists()) { dataPath = bar.absolutePath(); - adjustedBy += "Legacy data path " + dataPath; + adjustedBy = "Legacy data path"; } #endif -#else - dataPath = applicationDirPath(); - adjustedBy += "Fallback to binary path " + dataPath; -#endif + + if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) { + dataPath = m_rootPath; + adjustedBy = "Portable data path"; + } } if (!FS::ensureFolderPathExists(dataPath)) @@ -535,24 +555,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) qDebug() << "<> Log initialized."; } - // Set up paths { - // Root path is used for updates. -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - QDir foo(FS::PathCombine(binPath, "..")); - m_rootPath = foo.absolutePath(); -#elif defined(Q_OS_WIN32) - m_rootPath = binPath; -#elif defined(Q_OS_MAC) - QDir foo(FS::PathCombine(binPath, "../..")); - m_rootPath = foo.absolutePath(); - // on macOS, touch the root to force Finder to reload the .app metadata (and fix any icon change issues) - FS::updateTimestamp(m_rootPath); -#endif - -#ifdef LAUNCHER_JARS_LOCATION - m_jarsPath = TOSTRING(LAUNCHER_JARS_LOCATION); -#endif qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT; qDebug() << "Version : " << BuildConfig.printableVersionString(); diff --git a/launcher/Launcher.in b/launcher/Launcher.in index 5e5e2c2b..528e360e 100755 --- a/launcher/Launcher.in +++ b/launcher/Launcher.in @@ -21,7 +21,7 @@ echo "Launcher Dir: ${LAUNCHER_DIR}" # Set up env - filter out input LD_ variables but pass them in under different names export GAME_LIBRARY_PATH=${GAME_LIBRARY_PATH-${LD_LIBRARY_PATH}} export GAME_PRELOAD=${GAME_PRELOAD-${LD_PRELOAD}} -export LD_LIBRARY_PATH="${LAUNCHER_DIR}/bin":$LAUNCHER_LIBRARY_PATH +export LD_LIBRARY_PATH="${LAUNCHER_DIR}/lib@LIB_SUFFIX@":$LAUNCHER_LIBRARY_PATH export LD_PRELOAD=$LAUNCHER_PRELOAD export QT_PLUGIN_PATH="${LAUNCHER_DIR}/plugins" export QT_FONTPATH="${LAUNCHER_DIR}/fonts" -- cgit From 6ed130fc1610da8d66ed17be9446e8f53bf96db5 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 23 Mar 2022 14:38:58 +0100 Subject: fix: don't allow portable builds on macOS --- launcher/Application.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'launcher') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a9f7a0f0..6e934fa4 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -363,10 +363,12 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) } #endif +#ifndef Q_OS_MACOS if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) { dataPath = m_rootPath; adjustedBy = "Portable data path"; } +#endif } if (!FS::ensureFolderPathExists(dataPath)) -- cgit From b10d4d3b8f68a27434d04ac6c595cea0bc1337af Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 23 Mar 2022 14:42:56 +0100 Subject: fix: drop BUNDLE_DEST_DIR --- launcher/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher') diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 0ab398e8..6ed86726 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -991,7 +991,7 @@ if(DEFINED Launcher_APP_BINARY_DEFS) endif() install(TARGETS ${Launcher_Name} - BUNDLE DESTINATION ${BUNDLE_DEST_DIR} COMPONENT Runtime + BUNDLE DESTINATION "." COMPONENT Runtime LIBRARY DESTINATION ${LIBRARY_DEST_DIR} COMPONENT Runtime RUNTIME DESTINATION ${BINARY_DEST_DIR} COMPONENT Runtime ) -- cgit