2022-05-12 15:24:25 -07:00
|
|
|
#define SATDUMP_DLL_EXPORT 1
|
2022-05-12 16:56:46 +02:00
|
|
|
#include "satdump_vars.h"
|
|
|
|
|
|
2023-09-19 22:04:40 -04:00
|
|
|
#if defined (__APPLE__)
|
2023-08-25 20:52:41 -04:00
|
|
|
#include <filesystem>
|
2023-08-27 13:39:57 -04:00
|
|
|
#include <mach-o/dyld.h>
|
2023-09-19 22:04:40 -04:00
|
|
|
#include <libgen.h>
|
2023-09-19 23:38:27 -04:00
|
|
|
#define LIBRARIES_SEARCH_PATH "/../Resources/"
|
|
|
|
|
#define RESOURCES_SEARCH_PATH "/../Resources/"
|
2023-09-19 22:04:40 -04:00
|
|
|
#elif defined (_WIN32)
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <shlwapi.h>
|
2023-09-19 23:38:27 -04:00
|
|
|
#define LIBRARIES_SEARCH_PATH "\\..\\lib\\satdump\\"
|
|
|
|
|
#define RESOURCES_SEARCH_PATH "\\..\\share\\satdump\\"
|
2023-08-25 20:52:41 -04:00
|
|
|
#endif
|
|
|
|
|
|
2022-05-12 16:56:46 +02:00
|
|
|
namespace satdump
|
|
|
|
|
{
|
2023-08-27 13:39:57 -04:00
|
|
|
#if defined (__APPLE__)
|
2023-09-19 22:04:40 -04:00
|
|
|
std::string get_search_path(const char *target)
|
2023-08-27 13:39:57 -04:00
|
|
|
{
|
|
|
|
|
uint32_t bufsize = PATH_MAX;
|
2023-09-19 23:38:27 -04:00
|
|
|
char exec_path[bufsize], ret_val[bufsize], search_dir[bufsize];
|
|
|
|
|
char *exec_dir;
|
2023-08-27 13:39:57 -04:00
|
|
|
_NSGetExecutablePath(exec_path, &bufsize);
|
2023-09-19 23:38:27 -04:00
|
|
|
exec_dir = dirname(exec_path);
|
|
|
|
|
strcpy(search_dir, exec_dir);
|
|
|
|
|
strcat(search_dir, target);
|
|
|
|
|
realpath(search_dir, ret_val);
|
|
|
|
|
return std::string(ret_val) + "/";
|
2023-09-19 22:04:40 -04:00
|
|
|
}
|
|
|
|
|
#elif defined (_WIN32)
|
|
|
|
|
std::string get_search_path(const char *target)
|
|
|
|
|
{
|
|
|
|
|
char exe_path[MAX_PATH], ret_val[MAX_PATH];
|
|
|
|
|
GetModuleFileNameA(NULL, exe_path, MAX_PATH);
|
|
|
|
|
PathRemoveFileSpecA(exe_path);
|
|
|
|
|
strcat_s(exe_path, MAX_PATH, target);
|
|
|
|
|
PathCanonicalizeA(ret_val, exe_path);
|
|
|
|
|
return std::string(ret_val);
|
2023-08-27 13:39:57 -04:00
|
|
|
}
|
2023-09-19 23:38:27 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined (__APPLE__) || defined (_WIN32)
|
2023-08-02 01:47:38 +02:00
|
|
|
std::string init_res_path()
|
|
|
|
|
{
|
2023-09-19 23:38:27 -04:00
|
|
|
std::string search_dir = get_search_path(RESOURCES_SEARCH_PATH);
|
2023-09-19 22:04:40 -04:00
|
|
|
if (std::filesystem::exists(search_dir) && std::filesystem::is_directory(search_dir))
|
|
|
|
|
return search_dir;
|
2023-08-27 13:39:57 -04:00
|
|
|
else
|
2024-03-03 00:20:57 -05:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
return get_search_path("\\");
|
|
|
|
|
#else
|
2023-10-24 10:11:10 -04:00
|
|
|
return std::string(RESOURCES_PATH);
|
2024-03-03 00:20:57 -05:00
|
|
|
#endif
|
2023-08-02 01:47:38 +02:00
|
|
|
}
|
|
|
|
|
std::string init_lib_path()
|
|
|
|
|
{
|
2023-09-19 23:38:27 -04:00
|
|
|
std::string search_dir = get_search_path(LIBRARIES_SEARCH_PATH);
|
2023-09-19 22:04:40 -04:00
|
|
|
if (std::filesystem::exists(search_dir) && std::filesystem::is_directory(search_dir))
|
|
|
|
|
return search_dir;
|
2023-08-27 13:39:57 -04:00
|
|
|
else
|
2024-03-03 00:20:57 -05:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
return get_search_path("\\");
|
|
|
|
|
#else
|
2023-10-24 10:11:10 -04:00
|
|
|
return std::string(LIBRARIES_PATH);
|
2024-03-03 00:20:57 -05:00
|
|
|
#endif
|
2023-08-27 13:39:57 -04:00
|
|
|
}
|
|
|
|
|
#elif defined (__ANDROID__)
|
|
|
|
|
std::string init_res_path()
|
|
|
|
|
{
|
|
|
|
|
return "./";
|
|
|
|
|
}
|
|
|
|
|
std::string init_lib_path()
|
|
|
|
|
{
|
|
|
|
|
return "./";
|
|
|
|
|
}
|
2023-08-02 01:47:38 +02:00
|
|
|
#else
|
2023-08-27 13:39:57 -04:00
|
|
|
std::string init_res_path()
|
|
|
|
|
{
|
2023-10-24 10:11:10 -04:00
|
|
|
return std::string(RESOURCES_PATH);
|
2023-08-02 01:47:38 +02:00
|
|
|
}
|
2023-08-27 13:39:57 -04:00
|
|
|
std::string init_lib_path()
|
|
|
|
|
{
|
2023-10-24 10:11:10 -04:00
|
|
|
return std::string(LIBRARIES_PATH);
|
2023-08-27 13:39:57 -04:00
|
|
|
}
|
|
|
|
|
#endif
|
2023-08-02 01:47:38 +02:00
|
|
|
std::string RESPATH = init_res_path();
|
|
|
|
|
std::string LIBPATH = init_lib_path();
|
2022-05-12 16:56:46 +02:00
|
|
|
}
|