|
|
|
@ -5,13 +5,41 @@
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
#include <components/misc/strings/lower.hpp>
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
std::filesystem::path getBinaryPath()
|
|
|
|
|
{
|
|
|
|
|
uint32_t bufsize = 0;
|
|
|
|
|
_NSGetExecutablePath(nullptr, &bufsize);
|
|
|
|
|
|
|
|
|
|
std::vector<char> buf(bufsize);
|
|
|
|
|
|
|
|
|
|
if (_NSGetExecutablePath(buf.data(), &bufsize) == 0)
|
|
|
|
|
{
|
|
|
|
|
std::filesystem::path path = std::filesystem::path(buf.begin(), buf.end());
|
|
|
|
|
|
|
|
|
|
if (std::filesystem::is_symlink(path))
|
|
|
|
|
{
|
|
|
|
|
return std::filesystem::read_symlink(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log(Debug::Warning) << "Not enough buffer size to get executable path: " << bufsize;
|
|
|
|
|
throw std::runtime_error("Failed to get executable path");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::filesystem::path getUserHome()
|
|
|
|
|
{
|
|
|
|
|
const char* dir = getenv("HOME");
|
|
|
|
@ -36,6 +64,11 @@ namespace Files
|
|
|
|
|
MacOsPath::MacOsPath(const std::string& application_name)
|
|
|
|
|
: mName(application_name)
|
|
|
|
|
{
|
|
|
|
|
std::filesystem::path binary_path = getBinaryPath();
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
std::filesystem::current_path(binary_path.parent_path(), ec);
|
|
|
|
|
if (ec.value() != 0)
|
|
|
|
|
Log(Debug::Warning) << "Error " << ec.message() << " when changing current directory";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::filesystem::path MacOsPath::getUserConfigPath() const
|
|
|
|
|