various: consolidated dir exists+mkpath into one function

This commit is contained in:
itsmattkc
2022-04-07 17:11:50 -07:00
parent 20f74919a3
commit 48adb159b8
8 changed files with 14 additions and 30 deletions
+3 -20
View File
@@ -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)