If the most recent input or output directory does not exist anymore, try to find a still existing "ancestor" directory, before falling back to the default directory.

This commit is contained in:
LoRd_MuldeR 2019-10-26 21:59:27 +02:00
parent db8fc5ead3
commit 85e845d83f
2 changed files with 30 additions and 8 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 8 #define VER_LAMEXP_MINOR_LO 8
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 7 #define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 2234 #define VER_LAMEXP_BUILD 2235
#define VER_LAMEXP_CONFG 2188 #define VER_LAMEXP_CONFG 2188
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -176,7 +176,27 @@ quint32 SettingsModel::OPT##Default(void) { return (DEF); }
} \ } \
while(0) while(0)
#define DIR_EXISTS(PATH) (QFileInfo(PATH).exists() && QFileInfo(PATH).isDir()) ////////////////////////////////////////////////////////////
// Utility functions
////////////////////////////////////////////////////////////
static bool dir_exists(const QString &path)
{
const QFileInfo info(path);
return info.exists() && info.isDir();
}
static QString find_existing_ancestor(const QString &path)
{
for (QString parentPath = path; !parentPath.isEmpty(); parentPath = MUtils::parent_path(parentPath))
{
if (dir_exists(parentPath))
{
return parentPath; /*existing parent found*/
}
}
return QString();
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constants // Constants
@ -427,16 +447,18 @@ void SettingsModel::validate(void)
} }
} }
if(this->outputDir().isEmpty() || (!DIR_EXISTS(this->outputDir()))) if(this->outputDir().isEmpty() || (!dir_exists(this->outputDir())))
{ {
qWarning("Output directory not set yet or does NOT exist anymore -> Resetting"); qWarning("Output directory not set yet or does NOT exist anymore -> resetting!");
this->outputDir(defaultDirectory()); const QString outputDir = find_existing_ancestor(this->outputDir());
this->outputDir((!outputDir.isEmpty()) ? outputDir : defaultDirectory());
} }
if(this->mostRecentInputPath().isEmpty() || (!DIR_EXISTS(this->mostRecentInputPath()))) if(this->mostRecentInputPath().isEmpty() || (!dir_exists(this->mostRecentInputPath())))
{ {
qWarning("Most recent input directory not set yet or does NOT exist anymore -> Resetting"); qWarning("Most recent input directory not set yet or does NOT exist anymore -> resetting!");
this->mostRecentInputPath(defaultDirectory()); const QString inputPath = find_existing_ancestor(this->mostRecentInputPath());
this->mostRecentInputPath((!inputPath.isEmpty()) ? inputPath : defaultDirectory());
} }
if(!this->currentLanguageFile().isEmpty()) if(!this->currentLanguageFile().isEmpty())