Try to find the flash0 directory in headless.

This commit is contained in:
Unknown W. Brackets 2013-11-17 10:15:49 -08:00
parent c1c1b5213e
commit fa7467f03d
5 changed files with 60 additions and 44 deletions

View File

@ -641,21 +641,50 @@ bool SetCurrentDir(const std::string &directory)
return __chdir(directory.c_str()) == 0;
}
#ifdef _WIN32
std::wstring &GetExeDirectory()
const std::string &GetExeDirectory()
{
static std::wstring DolphinPath;
if (DolphinPath.empty())
static std::string ExePath;
if (ExePath.empty())
{
wchar_t Dolphin_exe_Path[2048];
GetModuleFileName(NULL, Dolphin_exe_Path, 2048);
DolphinPath = Dolphin_exe_Path;
DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
}
return DolphinPath;
}
#ifdef _WIN32
TCHAR program_path[4096] = {0};
GetModuleFileName(NULL, program_path, ARRAY_SIZE(program_path) - 1);
program_path[ARRAY_SIZE(program_path) - 1] = '\0';
TCHAR *last_slash = _tcsrchr(program_path, '\\');
if (last_slash != NULL)
*(last_slash + 1) = '\0';
#ifdef UNICODE
ExePath = ConvertWStringToUTF8(program_path);
#else
ExePath = program_path;
#endif
#elif (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';
ExePath = program_path;
}
#endif
}
return ExePath;
}
IOFile::IOFile()
: m_file(NULL), m_good(true)
{}

View File

@ -103,7 +103,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path);
bool SetCurrentDir(const std::string &directory);
#ifdef _WIN32
std::wstring &GetExeDirectory();
const std::string &GetExeDirectory();
#endif
// simple wrapper for cstdlib file functions to

View File

@ -392,17 +392,17 @@ void InitSysDirectories() {
if (!g_Config.memCardDirectory.empty() && !g_Config.flash0Directory.empty())
return;
const std::string path = ConvertWStringToUTF8(File::GetExeDirectory());
const std::string path = File::GetExeDirectory();
// Mount a filesystem
g_Config.flash0Directory = path + "/flash0/";
g_Config.flash0Directory = path + "flash0/";
// Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder.
wchar_t myDocumentsPath[MAX_PATH];
const HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath);
const std::string myDocsPath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
const std::string installedFile = path + "/installed.txt";
const std::string installedFile = path + "installed.txt";
const bool installed = File::Exists(installedFile);
// If installed.txt exists(and we can determine the Documents directory)
@ -430,7 +430,7 @@ void InitSysDirectories() {
if (lastSlash != (g_Config.memCardDirectory.length() - 1))
g_Config.memCardDirectory.append("/");
} else {
g_Config.memCardDirectory = path + "/memstick/";
g_Config.memCardDirectory = path + "memstick/";
}
// Create the memstickpath before trying to write to it, and fall back on Documents yet again

View File

@ -222,28 +222,6 @@ 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) {
#ifdef ANDROID_NDK_PROFILER
@ -261,11 +239,11 @@ void NativeInit(int argc, const char *argv[],
#ifdef IOS
user_data_path += "/";
#elif defined(__APPLE__)
if (File::Exists(NativeProgramPath() + "assets"))
VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "assets/").c_str()));
if (File::Exists(File::GetExeDirectory() + "assets"))
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory() + "assets/").c_str()));
// It's common to be in a build-xyz/ directory.
else
VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "../assets/").c_str()));
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory() + "../assets/").c_str()));
#endif
// We want this to be FIRST.
@ -293,7 +271,7 @@ void NativeInit(int argc, const char *argv[],
g_Config.flash0Directory = std::string(external_directory) + "/flash0/";
#elif !defined(_WIN32)
g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/";
std::string program_path = NativeProgramPath();
std::string program_path = File::GetExeDirectory();
if (program_path.empty())
g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/";
else if (File::Exists(program_path + "flash0"))

View File

@ -6,6 +6,7 @@
#include <cstdlib>
#include <limits>
#include "Common/FileUtil.h"
#include "Core/Config.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
@ -346,10 +347,18 @@ int main(int argc, const char* argv[])
#elif defined(BLACKBERRY) || defined(__SYMBIAN32__)
#elif !defined(_WIN32)
g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/";
// TODO: This isn't a great place.
g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/";
#endif
// Try to find the flash0 directory. Often this is from a subdirectory.
for (int i = 0; i < 3; ++i)
{
if (!File::Exists(g_Config.flash0Directory))
g_Config.flash0Directory += "../../flash0/";
}
// Or else, maybe in the executable's dir.
if (!File::Exists(g_Config.flash0Directory))
g_Config.flash0Directory = File::GetExeDirectory() + "flash0/";
if (screenshotFilename != 0)
headlessHost->SetComparisonScreenshot(screenshotFilename);