mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
The full executable path, rather than argv[0], is now used when determining whether the executable is fused (resolves issue #1043.)
This commit is contained in:
@@ -26,6 +26,17 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(LOVE_MACOSX)
|
||||
#include "common/OSX.h"
|
||||
#elif defined(LOVE_IOS)
|
||||
#include "common/iOS.h"
|
||||
#elif defined(LOVE_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include "common/utf8.h"
|
||||
#elif defined(LOVE_LINUX)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
@@ -43,8 +54,10 @@ bool Filesystem::isRealDirectory(const std::string &path) const
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
// make sure non-ASCII paths work.
|
||||
std::wstring wpath = to_widestr(path);
|
||||
|
||||
struct _stat buf;
|
||||
if (_wstat(to_widestr(path).c_str(), &buf) != 0)
|
||||
if (_wstat(wpath.c_str(), &buf) != 0)
|
||||
return false;
|
||||
|
||||
return (buf.st_mode & _S_IFDIR) == _S_IFDIR;
|
||||
@@ -58,5 +71,35 @@ bool Filesystem::isRealDirectory(const std::string &path) const
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Filesystem::getExecutablePath() const
|
||||
{
|
||||
#if defined(LOVE_MACOSX)
|
||||
return love::osx::getExecutablePath();
|
||||
#elif defined(LOVE_IOS)
|
||||
return love::ios::getExecutablePath();
|
||||
#elif defined(LOVE_WINDOWS)
|
||||
|
||||
wchar_t buffer[MAX_PATH + 1] = {0};
|
||||
|
||||
if (GetModuleFileNameW(nullptr, buffer, MAX_PATH) == 0)
|
||||
return "";
|
||||
|
||||
return to_utf8(buffer);
|
||||
|
||||
#elif defined(LOVE_LINUX)
|
||||
|
||||
char buffer[2048] = {0};
|
||||
|
||||
ssize_t len = readlink("/proc/self/exe", buffer, 2048);
|
||||
if (len <= 0)
|
||||
return "";
|
||||
|
||||
return std::string(buffer, len);
|
||||
|
||||
#else
|
||||
#error Missing implementation for Filesystem::getExecutablePath!
|
||||
#endif
|
||||
}
|
||||
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user