App: Refactor mac appData setup with boost::filesystem
This will make it easier to add support for migration when moving appData from `Library/Preferences` to `Library/Application Support`.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
# include <ctime>
|
||||
# include <csignal>
|
||||
# include <boost/program_options.hpp>
|
||||
# include <boost/filesystem.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_WIN32
|
||||
@@ -2835,57 +2836,38 @@ void Application::ExtractUserPath()
|
||||
mConfig["UserHomePath"] = userHome.toUtf8().data();
|
||||
}
|
||||
|
||||
std::string appData = pwd->pw_dir;
|
||||
if (!userData.isEmpty()) {
|
||||
boost::filesystem::path appData(pwd->pw_dir);
|
||||
if (!userData.isEmpty())
|
||||
appData = userData.toUtf8().data();
|
||||
}
|
||||
appData += PATHSEP;
|
||||
appData += "Library";
|
||||
appData += PATHSEP;
|
||||
appData += "Preferences";
|
||||
Base::FileInfo fi(appData.c_str());
|
||||
if (!fi.exists()) {
|
||||
|
||||
appData = appData / "Library" / "Preferences";
|
||||
|
||||
if (!boost::filesystem::exists(appData)) {
|
||||
// This should never ever happen
|
||||
std::stringstream str;
|
||||
str << "Application data directory " << appData << " does not exist!";
|
||||
throw Base::FileSystemError(str.str());
|
||||
throw Base::FileSystemError("Application data directory " + appData.string() + " does not exist!");
|
||||
}
|
||||
|
||||
// In order to write to our data path, we must create some directories, first.
|
||||
// If 'AppDataSkipVendor' is defined the value of 'ExeVendor' must not be part of
|
||||
// If 'AppDataSkipVendor' is defined, the value of 'ExeVendor' must not be part of
|
||||
// the path.
|
||||
appData += PATHSEP;
|
||||
if (mConfig.find("AppDataSkipVendor") == mConfig.end()) {
|
||||
appData += mConfig["ExeVendor"];
|
||||
fi.setFile(appData.c_str());
|
||||
if (!fi.exists() && !Py_IsInitialized()) {
|
||||
if (!fi.createDirectory()) {
|
||||
std::string error = "Cannot create directory ";
|
||||
error += appData;
|
||||
// Want more details on console
|
||||
std::cerr << error << std::endl;
|
||||
throw Base::FileSystemError(error);
|
||||
}
|
||||
}
|
||||
appData += PATHSEP;
|
||||
appData /= mConfig["ExeVendor"];
|
||||
}
|
||||
appData /= mConfig["ExeName"];
|
||||
|
||||
appData += mConfig["ExeName"];
|
||||
fi.setFile(appData.c_str());
|
||||
if (!fi.exists() && !Py_IsInitialized()) {
|
||||
if (!fi.createDirectory()) {
|
||||
std::string error = "Cannot create directory ";
|
||||
error += appData;
|
||||
// Want more details on console
|
||||
std::cerr << error << std::endl;
|
||||
throw Base::FileSystemError(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Actually the name of the directory where the parameters are stored should be the name of
|
||||
// the application due to branding reasons.
|
||||
appData += PATHSEP;
|
||||
mConfig["UserAppData"] = appData;
|
||||
|
||||
// In order to write to our data path, we must create some directories, first.
|
||||
if (!boost::filesystem::exists(appData) && !Py_IsInitialized()) {
|
||||
try {
|
||||
boost::filesystem::create_directories(appData);
|
||||
} catch (const boost::filesystem::filesystem_error& e) {
|
||||
throw Base::FileSystemError("Could not create app data directories. Failed with: " + e.code().message());
|
||||
}
|
||||
}
|
||||
|
||||
mConfig["UserAppData"] = appData.string() + PATHSEP;
|
||||
|
||||
#elif defined(FC_OS_WIN32)
|
||||
WCHAR szPath[MAX_PATH];
|
||||
|
||||
Reference in New Issue
Block a user