various: consolidated dir exists+mkpath into one function
This commit is contained in:
@@ -150,27 +150,10 @@ void FileFunctions::CopyDirectory(const QString &source, const QString &dest, bo
|
||||
}
|
||||
}
|
||||
|
||||
bool FileFunctions::DirectoryIsValid(const QString &dir, bool try_to_create)
|
||||
bool FileFunctions::DirectoryIsValid(const QDir &d, bool try_to_create_if_not_exists)
|
||||
{
|
||||
// Empty string is invalid
|
||||
if (dir.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDir d(dir);
|
||||
|
||||
// If directory already exists, this is valid
|
||||
if (d.exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we can create and creation is successful, this is valid
|
||||
if (try_to_create && d.mkpath(".")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, invalid
|
||||
return false;
|
||||
// Return whether the directory exists, or whether it could be created if it doesn't
|
||||
return d.exists() || d.mkpath(QStringLiteral("."));
|
||||
}
|
||||
|
||||
QString FileFunctions::EnsureFilenameExtension(QString fn, const QString &extension)
|
||||
|
||||
Reference in New Issue
Block a user