OSDN Git Service

If the most recent input or output directory does not exist anymore, try to find...
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 26 Oct 2019 19:59:27 +0000 (21:59 +0200)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 26 Oct 2019 19:59:27 +0000 (21:59 +0200)
src/Config.h
src/Model_Settings.cpp

index 2c32d00..36ceb62 100644 (file)
@@ -35,7 +35,7 @@
 #define VER_LAMEXP_MINOR_LO                                    8
 #define VER_LAMEXP_TYPE                                                Beta
 #define VER_LAMEXP_PATCH                                       7
-#define VER_LAMEXP_BUILD                                       2234
+#define VER_LAMEXP_BUILD                                       2235
 #define VER_LAMEXP_CONFG                                       2188
 
 ///////////////////////////////////////////////////////////////////////////////
index 537fc1c..e686a18 100644 (file)
@@ -176,7 +176,27 @@ quint32 SettingsModel::OPT##Default(void) { return (DEF); }
 } \
 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
@@ -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");
-               this->outputDir(defaultDirectory());
+               qWarning("Output directory not set yet or does NOT exist anymore -> resetting!");
+               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");
-               this->mostRecentInputPath(defaultDirectory());
+               qWarning("Most recent input directory not set yet or does NOT exist anymore -> resetting!");
+               const QString inputPath = find_existing_ancestor(this->mostRecentInputPath());
+               this->mostRecentInputPath((!inputPath.isEmpty()) ? inputPath : defaultDirectory());
        }
 
        if(!this->currentLanguageFile().isEmpty())