diff --git a/src/framework/file.cpp b/src/framework/file.cpp index 677b6f3..cc054aa 100644 --- a/src/framework/file.cpp +++ b/src/framework/file.cpp @@ -15,10 +15,6 @@ #endif #endif -#ifdef __APPLE__ -#include -#endif - #ifdef WIN32 #define NOMINMAX @@ -344,109 +340,6 @@ std::vector Directory::folders(const std::string& filename) #endif } -#ifdef WIN32 -std::string Directory::exe_path() -{ - WCHAR exe_filename[1024]; - DWORD len = GetModuleFileNameW(nullptr, exe_filename, 1024); - if (len == 0 || len == 1024) - throw std::runtime_error("GetModuleFileName failed!"); - return FilePath::remove_last_component(from_utf16(exe_filename)); -} -#else -std::string Directory::exe_path() -{ - char exe_file[PATH_MAX]; -#ifdef __APPLE__ - CFBundleRef mainBundle = CFBundleGetMainBundle(); - if (mainBundle) - { - CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle); - - if (mainURL) - { - int ok = CFURLGetFileSystemRepresentation( - mainURL, (Boolean)true, (UInt8*)exe_file, PATH_MAX - ); - - if (ok) - { - return std::string(exe_file) + "/"; - } - } - } - - throw std::runtime_error("get_exe_path failed"); - -#else -#ifndef PROC_EXE_PATH -#define PROC_EXE_PATH "/proc/self/exe" -#endif - int size; - struct stat sb; - if (lstat(PROC_EXE_PATH, &sb) < 0) - { -#ifdef EXTERN___PROGNAME - char* pathenv, * name, * end; - char fname[PATH_MAX]; - char cwd[PATH_MAX]; - struct stat sba; - - exe_file[0] = '\0'; - if ((pathenv = getenv("PATH")) != nullptr) - { - for (name = pathenv; name; name = end) - { - if ((end = strchr(name, ':'))) - *end++ = '\0'; - snprintf(fname, sizeof(fname), - "%s/%s", name, (char*)__progname); - if (stat(fname, &sba) == 0) { - snprintf(exe_file, sizeof(exe_file), - "%s/", name); - break; - } - } - } - // if getenv failed or path still not found - // try current directory as last resort - if (!exe_file[0]) - { - if (getcwd(cwd, sizeof(cwd)) != nullptr) - { - snprintf(fname, sizeof(fname), - "%s/%s", cwd, (char*)__progname); - if (stat(fname, &sba) == 0) - snprintf(exe_file, sizeof(exe_file), - "%s/", cwd); - } - } - if (!exe_file[0]) - throw std::runtime_error("get_exe_path: could not find path"); - else - return std::string(exe_file); -#else - throw std::runtime_error("get_exe_path: proc file system not accesible"); -#endif - } - else - { - size = readlink(PROC_EXE_PATH, exe_file, PATH_MAX); - if (size < 0) - { - throw std::runtime_error(strerror(errno)); - } - else - { - exe_file[size] = '\0'; - return std::string(dirname(exe_file)) + "/"; - } - } -#endif - -} -#endif - void Directory::create(const std::string& path) { #ifdef WIN32 diff --git a/src/framework/file.h b/src/framework/file.h index 1f78d64..6099fea 100644 --- a/src/framework/file.h +++ b/src/framework/file.h @@ -48,7 +48,6 @@ class Directory public: static std::vector files(const std::string &filename); static std::vector folders(const std::string& filename); - static std::string exe_path(); static void create(const std::string& path); };