mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +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:
@@ -64,7 +64,9 @@ bool DroppedFile::open(Mode newmode)
|
||||
#ifdef LOVE_WINDOWS
|
||||
// make sure non-ASCII filenames work.
|
||||
std::wstring modestr = to_widestr(getModeString(newmode));
|
||||
file = _wfopen(to_widestr(filename).c_str(), modestr.c_str());
|
||||
std::wstring wfilename = to_widestr(filename);
|
||||
|
||||
file = _wfopen(wfilename.c_str(), modestr.c_str());
|
||||
#else
|
||||
file = fopen(filename.c_str(), getModeString(newmode));
|
||||
#endif
|
||||
@@ -105,8 +107,10 @@ int64 DroppedFile::getSize()
|
||||
#ifdef LOVE_WINDOWS
|
||||
|
||||
// make sure non-ASCII filenames work.
|
||||
std::wstring wfilename = to_widestr(filename);
|
||||
|
||||
struct _stat buf;
|
||||
if (_wstat(to_widestr(filename).c_str(), &buf) != 0)
|
||||
if (_wstat(wfilename.c_str(), &buf) != 0)
|
||||
return -1;
|
||||
|
||||
return (int64) buf.st_size;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -252,6 +252,11 @@ public:
|
||||
**/
|
||||
virtual bool isRealDirectory(const std::string &path) const;
|
||||
|
||||
/**
|
||||
* Gets the full platform-dependent path to the executable.
|
||||
**/
|
||||
virtual std::string getExecutablePath() const;
|
||||
|
||||
}; // Filesystem
|
||||
|
||||
} // filesystem
|
||||
|
||||
@@ -301,6 +301,12 @@ int w_getRealDirectory(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getExecutablePath(lua_State *L)
|
||||
{
|
||||
luax_pushstring(L, instance()->getExecutablePath());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_isDirectory(lua_State *L)
|
||||
{
|
||||
const char *arg = luaL_checkstring(L, 1);
|
||||
@@ -699,6 +705,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getSaveDirectory", w_getSaveDirectory },
|
||||
{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
|
||||
{ "getRealDirectory", w_getRealDirectory },
|
||||
{ "getExecutablePath", w_getExecutablePath },
|
||||
{ "isDirectory", w_isDirectory },
|
||||
{ "isFile", w_isFile },
|
||||
{ "createDirectory", w_createDirectory },
|
||||
|
||||
@@ -57,6 +57,7 @@ int w_getAppdataDirectory(lua_State *L);
|
||||
int w_getSaveDirectory(lua_State *L);
|
||||
int w_getSourceBaseDirectory(lua_State *L);
|
||||
int w_getRealDirectory(lua_State *L);
|
||||
int w_getExecutablePath(lua_State *L);
|
||||
int w_isDirectory(lua_State *L);
|
||||
int w_isFile(lua_State *L);
|
||||
int w_createDirectory(lua_State *L);
|
||||
|
||||
@@ -84,7 +84,6 @@ bool System::openURL(const std::string &url) const
|
||||
#if defined(LOVE_MACOSX)
|
||||
|
||||
bool success = false;
|
||||
// We could be lazy and use system("open " + url), but this is safer.
|
||||
CFURLRef cfurl = CFURLCreateWithBytes(nullptr,
|
||||
(const UInt8 *) url.c_str(),
|
||||
url.length(),
|
||||
|
||||
Reference in New Issue
Block a user