mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 00:19:20 +00:00
An attempt to fix executable path resolution in Linux.
This commit is contained in:
parent
e4eb083aca
commit
ab12416976
@ -41,8 +41,17 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#include <boost/format.hpp>
|
||||||
#include <mach-o/dyld.h>
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/* nothing special for Win32 */
|
||||||
|
#elif __APPLE__
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string musik::core::GetPluginDirectory() {
|
std::string musik::core::GetPluginDirectory() {
|
||||||
@ -70,7 +79,12 @@ std::string musik::core::GetApplicationDirectory() {
|
|||||||
size_t last = result.find_last_of("/");
|
size_t last = result.find_last_of("/");
|
||||||
result = result.substr(0, last); /* remove filename component */
|
result = result.substr(0, last); /* remove filename component */
|
||||||
#else
|
#else
|
||||||
/* linux */
|
std::string pathToProc = boost::str(boost::format("/proc/%d/exe") % (int) getpid());
|
||||||
|
char pathbuf[PATH_MAX + 1];
|
||||||
|
readlink(pathToProc.c_str(), pathbuf, PATH_MAX);
|
||||||
|
result.assign(pathbuf);
|
||||||
|
size_t last = result.find_last_of("/");
|
||||||
|
result = result.substr(0, last); /* remove filename component */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -80,12 +94,12 @@ std::string musik::core::GetDataDirectory() {
|
|||||||
std::string directory;
|
std::string directory;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
DWORD iBufferSize = GetEnvironmentVariable(_T("APPDATA"), 0, 0);
|
DWORD bufferSize = GetEnvironmentVariable(_T("APPDATA"), 0, 0);
|
||||||
wchar_t *sBuffer = new wchar_t[iBufferSize + 2];
|
wchar_t *buffer = new wchar_t[bufferSize + 2];
|
||||||
GetEnvironmentVariable(_T("APPDATA"), sBuffer, iBufferSize);
|
GetEnvironmentVariable(_T("APPDATA"), buffer, bufferSize);
|
||||||
directory.assign(u16to8(sBuffer));
|
directory.assign(u16to8(buffer));
|
||||||
directory.append("/mC2/");
|
directory.append("/mC2/");
|
||||||
delete [] sBuffer;
|
delete[] buffer;
|
||||||
#else
|
#else
|
||||||
directory = std::string(std::getenv("HOME"));
|
directory = std::string(std::getenv("HOME"));
|
||||||
directory.append("/.mC2/");
|
directory.append("/.mC2/");
|
||||||
|
Loading…
Reference in New Issue
Block a user