Remove settingsDirectory()
This commit is contained in:
parent
716af584c5
commit
62902f98e8
90
io/path.cpp
90
io/path.cpp
|
@ -84,96 +84,6 @@ void removeInvalidChars(std::string &fileName)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Locates a directory meant to store application settings.
|
||||
* \param result Specifies a string to store the path in.
|
||||
* \param applicationDirectoryName Specifies the name for the application subdirectory.
|
||||
* \param createApplicationDirectory Indicates wheter the application subdirectory should be created if not present.
|
||||
* \returns Returns whether a settings directory could be located.
|
||||
* \deprecated This function has FIXMEs. Since it is not used a good candidate for being removed.
|
||||
*/
|
||||
bool settingsDirectory(std::string &result, std::string applicationDirectoryName, bool createApplicationDirectory)
|
||||
{
|
||||
result.clear();
|
||||
// FIXME: this kind of configuration is not actually used so get rid of it, maybe just read env variable instead
|
||||
fstream pathConfigFile("path.config", ios_base::in);
|
||||
if (pathConfigFile.good()) {
|
||||
for (string line; getline(pathConfigFile, line);) {
|
||||
string::size_type p = line.find('=');
|
||||
if ((p != string::npos) && (p + 1 < line.length())) {
|
||||
string fieldName = line.substr(0, p);
|
||||
if (fieldName == "settings") {
|
||||
result.assign(line.substr(p + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result.empty()) {
|
||||
#if defined(PLATFORM_UNIX)
|
||||
struct stat sb;
|
||||
return (stat(result.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
// FIXME: use UTF-16 API to support unicode, or rewrite using fs abstraction lib
|
||||
DWORD ftyp = GetFileAttributesA(result.c_str());
|
||||
return (ftyp != INVALID_FILE_ATTRIBUTES) && (ftyp & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#endif
|
||||
} else {
|
||||
if (!applicationDirectoryName.empty()) {
|
||||
removeInvalidChars(applicationDirectoryName);
|
||||
}
|
||||
#if defined(PLATFORM_UNIX) || defined(PLATFORM_MAC)
|
||||
if (char *homeDir = getenv("HOME")) {
|
||||
result = homeDir;
|
||||
} else {
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
result = pw->pw_dir;
|
||||
}
|
||||
struct stat sb;
|
||||
result += "/.config";
|
||||
if (createApplicationDirectory && !(stat(result.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
|
||||
if (mkdir(result.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!applicationDirectoryName.empty()) {
|
||||
result += '/';
|
||||
result += applicationDirectoryName;
|
||||
if (createApplicationDirectory && !(stat(result.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
|
||||
if (mkdir(result.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
if (char *appData = getenv("appdata")) {
|
||||
result = appData;
|
||||
if (!applicationDirectoryName.empty()) {
|
||||
result += '\\';
|
||||
result += applicationDirectoryName;
|
||||
if (createApplicationDirectory) {
|
||||
// FIXME: use UTF-16 API to support unicode, or rewrite using fs abstraction lib
|
||||
DWORD ftyp = GetFileAttributesA(result.c_str());
|
||||
if (ftyp == INVALID_FILE_ATTRIBUTES) {
|
||||
return false;
|
||||
} else if (ftyp & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
return true;
|
||||
} else {
|
||||
if (CreateDirectory(result.c_str(), NULL) == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the names of the directory entries in the specified \a path with the specified \a types.
|
||||
* \deprecated This function has FIXMEs. Since it can be replaced by using fs abstraction lib it is a good candidate for being replaced.
|
||||
|
|
|
@ -43,8 +43,6 @@ constexpr DirectoryEntryType operator&(DirectoryEntryType lhs, DirectoryEntryTyp
|
|||
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path);
|
||||
CPP_UTILITIES_EXPORT std::string directory(const std::string &path);
|
||||
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName);
|
||||
CPP_UTILITIES_EXPORT bool settingsDirectory(
|
||||
std::string &result, std::string applicationDirectoryName = std::string(), bool createApplicationDirectory = false);
|
||||
CPP_UTILITIES_EXPORT std::list<std::string> directoryEntries(const char *path, DirectoryEntryType types = DirectoryEntryType::All);
|
||||
} // namespace IoUtilities
|
||||
|
||||
|
|
Loading…
Reference in New Issue