From c486a09c2c35b3314482278bc6e7200fcd88079b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Oct 2013 22:14:15 -0700 Subject: [PATCH] Use a better default font path on Linux/Mac OS X. This way people don't have to copy to ~/.ppsspp/flash0. The override in ~/.ppsspp/PSP/flash0 still works. --- Qt/QtHost.cpp | 16 ++++++++++++++-- UI/NativeApp.cpp | 44 ++++++++++++++++++++++++++++++++++--------- headless/Headless.cpp | 5 +++-- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Qt/QtHost.cpp b/Qt/QtHost.cpp index 2b8dbfa922..bc03fb1ee2 100644 --- a/Qt/QtHost.cpp +++ b/Qt/QtHost.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "QtHost.h" #include "LogManager.h" @@ -313,8 +314,19 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co g_Config.currentDirectory = QDir::homePath().toStdString(); } - g_Config.memCardDirectory = QDir::homePath().toStdString()+"/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory+"/flash0/"; + g_Config.memCardDirectory = QDir::homePath().toStdString() + "/.ppsspp/"; + +#if defined(Q_OS_LINUX) && !defined(ARM) + std::string program_path = QCoreApplication::applicationDirPath().toStdString(); + if (File::Exists(program_path + "/flash0")) + g_Config.flash0Directory = program_path + "/flash0/"; + else if (File::Exists(program_path + "/../flash0")) + g_Config.flash0Directory = program_path + "/../flash0/"; + else + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; +#else + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; +#endif LogManager::Init(); if (fileToLog != NULL) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 4a265e9a22..222bf51a0d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -215,6 +215,28 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo #endif } +const std::string NativeProgramPath() { +#if (defined(__APPLE__) && !defined(IOS)) || defined(__linux__) + char program_path[4096]; + uint32_t program_path_size = sizeof(program_path) - 1; +#if defined(__linux__) + if (readlink("/proc/self/exe", program_path, 4095) > 0) { +#elif defined(__APPLE__) && !defined(IOS) + if (_NSGetExecutablePath(program_path, &program_path_size) == 0) { +#else +#error Unmatched ifdef. +#endif + program_path[sizeof(program_path) - 1] = '\0'; + char *last_slash = strrchr(program_path, '/'); + if (last_slash != NULL) + *(last_slash + 1) = '\0'; + return program_path; + } +#endif + + return ""; +} + void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID) { bool skipLogo = false; @@ -226,13 +248,11 @@ void NativeInit(int argc, const char *argv[], #ifdef IOS user_data_path += "/"; #elif defined(__APPLE__) - char program_path[4090]; - uint32_t program_path_size = sizeof(program_path); - _NSGetExecutablePath(program_path,&program_path_size); - *(strrchr(program_path, '/')+1) = '\0'; - char assets_path[4096]; - sprintf(assets_path,"%sassets/",program_path); - VFSRegister("", new DirectoryAssetReader(assets_path)); + if (File::Exists(NativeProgramPath() + "assets")) + VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "assets/").c_str())); + // It's common to be in a build-xyz/ directory. + else + VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "../assets/").c_str())); #endif // We want this to be FIRST. @@ -259,9 +279,15 @@ void NativeInit(int argc, const char *argv[], g_Config.memCardDirectory = user_data_path; g_Config.flash0Directory = std::string(external_directory) + "/flash0/"; #elif !defined(_WIN32) - // Linux, Mac. Does this path really make sense? g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; + std::string program_path = NativeProgramPath(); + if (program_path.empty()) + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; + else if (File::Exists(program_path + "flash0")) + g_Config.flash0Directory = program_path + "flash0/"; + // It's common to be in a build-xyz/ directory. + else + g_Config.flash0Directory = program_path + "../flash0/"; #endif #ifndef _WIN32 diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 71784cb441..f5223b0fd7 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -329,8 +329,9 @@ int main(int argc, const char* argv[]) #if defined(ANDROID) #elif defined(BLACKBERRY) || defined(__SYMBIAN32__) #elif !defined(_WIN32) - g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory+"/flash/"; + g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/"; + // TODO: This isn't a great place. + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; #endif if (screenshotFilename != 0)