2011-08-19 19:06:09 +00:00
|
|
|
#include "macospath.hpp"
|
|
|
|
|
|
|
|
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2022-06-08 21:25:50 +00:00
|
|
|
#include <filesystem>
|
2022-06-23 17:13:10 +00:00
|
|
|
#include <fstream>
|
2011-08-19 19:06:09 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2015-12-07 20:58:30 +00:00
|
|
|
|
2013-12-26 00:24:43 +00:00
|
|
|
namespace
|
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path getUserHome()
|
2013-12-26 00:24:43 +00:00
|
|
|
{
|
|
|
|
const char* dir = getenv("HOME");
|
2018-10-09 06:21:12 +00:00
|
|
|
if (dir == nullptr)
|
2013-12-26 00:24:43 +00:00
|
|
|
{
|
|
|
|
struct passwd* pwd = getpwuid(getuid());
|
2018-10-09 06:21:12 +00:00
|
|
|
if (pwd != nullptr)
|
2013-12-26 00:24:43 +00:00
|
|
|
{
|
|
|
|
dir = pwd->pw_dir;
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 06:21:12 +00:00
|
|
|
if (dir == nullptr)
|
2022-06-08 21:25:50 +00:00
|
|
|
return std::filesystem::path();
|
2013-12-26 00:24:43 +00:00
|
|
|
else
|
2022-06-08 21:25:50 +00:00
|
|
|
return std::filesystem::path(dir);
|
2013-12-26 00:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
namespace Files
|
|
|
|
{
|
|
|
|
|
2012-09-08 16:47:31 +00:00
|
|
|
MacOsPath::MacOsPath(const std::string& application_name)
|
|
|
|
: mName(application_name)
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2013-12-26 00:24:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getUserConfigPath() const
|
2013-12-26 00:24:43 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path userPath(getUserHome());
|
2015-03-18 21:48:03 +00:00
|
|
|
userPath /= "Library/Preferences/";
|
2011-08-19 19:06:09 +00:00
|
|
|
|
2012-09-08 18:34:43 +00:00
|
|
|
return userPath / mName;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getUserDataPath() const
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path userPath(getUserHome());
|
|
|
|
userPath /= "Library/Application Support/";
|
2011-08-19 19:06:09 +00:00
|
|
|
|
2013-12-26 00:24:43 +00:00
|
|
|
return userPath / mName;
|
2012-09-02 17:40:26 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getGlobalConfigPath() const
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path globalPath("/Library/Preferences/");
|
|
|
|
return globalPath / mName;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getCachePath() const
|
2012-01-21 16:58:49 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path userPath(getUserHome());
|
|
|
|
userPath /= "Library/Caches";
|
2012-09-08 16:47:31 +00:00
|
|
|
return userPath / mName;
|
2012-01-21 16:58:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getLocalPath() const
|
2012-01-21 16:58:49 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
return std::filesystem::path("../Resources/");
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path MacOsPath::getGlobalDataPath() const
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path globalDataPath("/Library/Application Support/");
|
|
|
|
return globalDataPath / mName;
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
|
2013-12-26 00:24:43 +00:00
|
|
|
std::filesystem::path MacOsPath::getInstallPath() const
|
2012-01-25 22:55:43 +00:00
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path installPath;
|
2012-01-25 22:55:43 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path homePath = getUserHome();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
if (!homePath.empty())
|
2012-01-25 22:55:43 +00:00
|
|
|
{
|
2022-06-23 17:13:10 +00:00
|
|
|
std::filesystem::path wineDefaultRegistry(homePath);
|
2012-01-25 22:55:43 +00:00
|
|
|
wineDefaultRegistry /= ".wine/system.reg";
|
|
|
|
|
2012-02-23 22:21:17 +00:00
|
|
|
if (std::filesystem::is_regular_file(wineDefaultRegistry))
|
2012-01-25 22:55:43 +00:00
|
|
|
{
|
|
|
|
std::ifstream file(wineDefaultRegistry);
|
2012-02-23 22:21:17 +00:00
|
|
|
bool isRegEntry = false;
|
|
|
|
std::string line;
|
2012-01-25 22:55:43 +00:00
|
|
|
std::string mwpath;
|
2012-02-23 22:21:17 +00:00
|
|
|
|
|
|
|
while (std::getline(file, line))
|
2012-01-25 22:55:43 +00:00
|
|
|
{
|
|
|
|
if (line[0] == '[') // we found an entry
|
|
|
|
{
|
|
|
|
if (isRegEntry)
|
|
|
|
{
|
|
|
|
break;
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
|
|
|
|
isRegEntry = (line.find("Softworks\\\\Morrowind]") != std::string::npos);
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
else if (isRegEntry)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2012-01-25 22:55:43 +00:00
|
|
|
if (line[0] == '"') // empty line means new registry key
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2012-01-25 22:55:43 +00:00
|
|
|
std::string key = line.substr(1, line.find('"', 1) - 1);
|
|
|
|
if (strcasecmp(key.c_str(), "Installed Path") == 0)
|
|
|
|
{
|
|
|
|
std::string::size_type valuePos = line.find('=') + 2;
|
|
|
|
mwpath = line.substr(valuePos, line.rfind('"') - valuePos);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2012-01-25 22:55:43 +00:00
|
|
|
std::string::size_type pos = mwpath.find("\\");
|
|
|
|
while (pos != std::string::npos)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2012-01-25 22:55:43 +00:00
|
|
|
mwpath.replace(pos, 2, "/");
|
|
|
|
pos = mwpath.find("\\", pos + 1);
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-01-25 22:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
if (!mwpath.empty())
|
2012-01-25 22:55:43 +00:00
|
|
|
{
|
|
|
|
// Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks
|
2015-12-07 20:58:30 +00:00
|
|
|
mwpath[0] = Misc::StringUtils::toLower(mwpath[0]);
|
2012-01-25 22:55:43 +00:00
|
|
|
installPath /= homePath;
|
|
|
|
installPath /= ".wine/dosdevices/";
|
|
|
|
installPath /= mwpath;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
if (!std::filesystem::is_directory(installPath))
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2012-01-25 22:55:43 +00:00
|
|
|
installPath.clear();
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 16:58:49 +00:00
|
|
|
|
2012-01-25 22:55:43 +00:00
|
|
|
return installPath;
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2012-01-25 22:55:43 +00:00
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
} /* namespace Files */
|
|
|
|
|
|
|
|
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */
|