aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/qt_sdl/Platform.cpp
diff options
context:
space:
mode:
authorSteveice10 <1269164+Steveice10@users.noreply.github.com>2024-01-24 01:27:25 -0800
committerGitHub <noreply@github.com>2024-01-24 10:27:25 +0100
commit4b576d066e4b0513eacaba5c62018d1a850bbce1 (patch)
treed363d6273181b13cb05ed265fb8ada33e197f8b9 /src/frontend/qt_sdl/Platform.cpp
parent77274735d62b2fe34ee2ad0fc2eb0c37197f3f19 (diff)
Add support for using a portable directory without special build flags. (#1956)
Diffstat (limited to 'src/frontend/qt_sdl/Platform.cpp')
-rw-r--r--src/frontend/qt_sdl/Platform.cpp78
1 files changed, 38 insertions, 40 deletions
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp
index efd3340..222e512 100644
--- a/src/frontend/qt_sdl/Platform.cpp
+++ b/src/frontend/qt_sdl/Platform.cpp
@@ -21,6 +21,7 @@
#include <string.h>
#include <string>
+#include <QCoreApplication>
#include <QStandardPaths>
#include <QString>
#include <QDateTime>
@@ -60,6 +61,42 @@ void emuStop();
namespace melonDS::Platform
{
+void PathInit(int argc, char** argv)
+{
+ // First, check for the portable directory next to the executable.
+ QString appdirpath = QCoreApplication::applicationDirPath();
+ QString portablepath = appdirpath + QDir::separator() + "portable";
+
+#if defined(__APPLE__)
+ // On Apple platforms we may need to navigate outside an app bundle.
+ // The executable directory would be "melonDS.app/Contents/MacOS", so we need to go a total of three steps up.
+ QDir bundledir(appdirpath);
+ if (bundledir.cd("..") && bundledir.cd("..") && bundledir.dirName().endsWith(".app") && bundledir.cd(".."))
+ {
+ portablepath = bundledir.absolutePath() + QDir::separator() + "portable";
+ }
+#endif
+
+ QDir portabledir(portablepath);
+ if (portabledir.exists())
+ {
+ EmuDirectory = portabledir.absolutePath().toStdString();
+ }
+ else
+ {
+ // If no overrides are specified, use the default path.
+#if defined(__WIN32__) && defined(WIN32_PORTABLE)
+ EmuDirectory = appdirpath.toStdString();
+#else
+ QString confdir;
+ QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
+ config.mkdir("melonDS");
+ confdir = config.absolutePath() + QDir::separator() + "melonDS";
+ EmuDirectory = confdir.toStdString();
+#endif
+ }
+}
+
QSharedMemory* IPCBuffer = nullptr;
int IPCInstanceID;
@@ -133,38 +170,7 @@ void IPCDeInit()
void Init(int argc, char** argv)
{
-#if defined(__WIN32__) || defined(PORTABLE)
- if (argc > 0 && strlen(argv[0]) > 0)
- {
- int len = strlen(argv[0]);
- while (len > 0)
- {
- if (argv[0][len] == '/') break;
- if (argv[0][len] == '\\') break;
- len--;
- }
- if (len > 0)
- {
- std::string emudir = argv[0];
- EmuDirectory = emudir.substr(0, len);
- }
- else
- {
- EmuDirectory = ".";
- }
- }
- else
- {
- EmuDirectory = ".";
- }
-#else
- QString confdir;
- QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
- config.mkdir("melonDS");
- confdir = config.absolutePath() + "/melonDS/";
- EmuDirectory = confdir.toStdString();
-#endif
-
+ PathInit(argc, argv);
IPCInit();
}
@@ -284,15 +290,7 @@ FileHandle* OpenLocalFile(const std::string& path, FileMode mode)
}
else
{
-#ifdef PORTABLE
fullpath = QString::fromStdString(EmuDirectory) + QDir::separator() + qpath;
-#else
- // Check user configuration directory
- QDir config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
- config.mkdir("melonDS");
- fullpath = config.absolutePath() + "/melonDS/";
- fullpath.append(qpath);
-#endif
}
return OpenFile(fullpath.toStdString(), mode);