App: Refactor *nix appData setup with boost::filesystem
This commit is contained in:
@@ -2775,56 +2775,37 @@ void Application::ExtractUserPath()
|
||||
mConfig["UserHomePath"] = userHome.toUtf8().data();
|
||||
}
|
||||
|
||||
std::string path = pwd->pw_dir;
|
||||
if (!userData.isEmpty()) {
|
||||
path = userData.toUtf8().data();
|
||||
}
|
||||
boost::filesystem::path appData(pwd->pw_dir);
|
||||
if (!userData.isEmpty())
|
||||
appData = userData.toUtf8().data();
|
||||
|
||||
std::string appData(path);
|
||||
Base::FileInfo fi(appData.c_str());
|
||||
if (!fi.exists()) {
|
||||
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 into our data path, we must create some directories, first.
|
||||
// If 'AppDataSkipVendor' is defined, the value of 'ExeVendor' must not be part of
|
||||
// the path.
|
||||
appData += PATHSEP;
|
||||
appData += ".";
|
||||
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["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);
|
||||
}
|
||||
appData /= "." + mConfig["ExeVendor"];
|
||||
appData /= mConfig["ExeName"];
|
||||
} else {
|
||||
appData /= "." + mConfig["ExeName"];
|
||||
}
|
||||
|
||||
// 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_MACOSX)
|
||||
// Default paths for the user specific stuff on the platform
|
||||
|
||||
Reference in New Issue
Block a user