Bladeren bron

make case insensitive path conversion optional for *nix systems

Sonnix 4 jaren geleden
bovenliggende
commit
3ec40615d5
6 gewijzigde bestanden met toevoegingen van 62 en 22 verwijderingen
  1. 29 22
      comtools.cpp
  2. 2 0
      comtools.h
  3. 14 0
      mainwindow.cpp
  4. 2 0
      mainwindow.h
  5. 5 0
      optionsdialog.cpp
  6. 10 0
      optionsdialog.ui

+ 29 - 22
comtools.cpp

@@ -6,6 +6,7 @@
 
 QHash<QString, QString> QSPTools::file_list;
 QString QSPTools::file_path;
+bool QSPTools::useCaseInsensitiveFilePath = true;
 
 QString QSPTools::GetHexColor(const QColor color)
 {
@@ -165,20 +166,23 @@ QString QSPTools::GetCaseInsensitiveFilePath(QString  searchDir, QString origina
     if(new_name.startsWith("/"))
         new_name = new_name.remove(0, 1);
 #ifndef _WIN32
-    QDir itDir(searchDir);
-    if(file_path != searchDir && !searchDir.isEmpty())
+    if(useCaseInsensitiveFilePath)
     {
-        file_list.clear();
-        QDirIterator it(searchDir, QDir::Files, QDirIterator::Subdirectories);
-        while (it.hasNext())
+        QDir itDir(searchDir);
+        if(file_path != searchDir && !searchDir.isEmpty())
         {
-            it.next();
-            file_list.insert(itDir.relativeFilePath(it.filePath()).toLower(), itDir.relativeFilePath(it.filePath()));
+            file_list.clear();
+            QDirIterator it(searchDir, QDir::Files, QDirIterator::Subdirectories);
+            while (it.hasNext())
+            {
+                it.next();
+                file_list.insert(itDir.relativeFilePath(it.filePath()).toLower(), itDir.relativeFilePath(it.filePath()));
+            }
+            file_path = searchDir;
         }
-        file_path = searchDir;
+        if (file_list.contains(new_name.toLower()))
+            return itDir.relativeFilePath(file_list.value(new_name.toLower()));
     }
-    if (file_list.contains(new_name.toLower()))
-        return itDir.relativeFilePath(file_list.value(new_name.toLower()));
 #endif
     return new_name;
 }
@@ -187,22 +191,25 @@ QString QSPTools::GetCaseInsensitiveAbsoluteFilePath(QString  searchDir, QString
 {
     QString new_name = originalPath.replace("\\", "/");
 #ifndef _WIN32
-    QDir itDir(searchDir);
-    if(originalPath.startsWith(searchDir))
-        new_name = new_name.remove(0, searchDir.length());
-    if(file_path != searchDir && !searchDir.isEmpty())
+    if(useCaseInsensitiveFilePath)
     {
-        file_list.clear();
-        QDirIterator it(searchDir, QDir::Files, QDirIterator::Subdirectories);
-        while (it.hasNext())
+        QDir itDir(searchDir);
+        if(originalPath.startsWith(searchDir))
+            new_name = new_name.remove(0, searchDir.length());
+        if(file_path != searchDir && !searchDir.isEmpty())
         {
-            it.next();
-            file_list.insert(itDir.relativeFilePath(it.filePath()).toLower(), itDir.relativeFilePath(it.filePath()));
+            file_list.clear();
+            QDirIterator it(searchDir, QDir::Files, QDirIterator::Subdirectories);
+            while (it.hasNext())
+            {
+                it.next();
+                file_list.insert(itDir.relativeFilePath(it.filePath()).toLower(), itDir.relativeFilePath(it.filePath()));
+            }
+            file_path = searchDir;
         }
-        file_path = searchDir;
+        if (file_list.contains(new_name.toLower()))
+            return itDir.absoluteFilePath(file_list.value(new_name.toLower()));
     }
-    if (file_list.contains(new_name.toLower()))
-        return itDir.absoluteFilePath(file_list.value(new_name.toLower()));
 #endif
     return new_name;
 }

+ 2 - 0
comtools.h

@@ -18,6 +18,8 @@ public:
     static QString GetCaseInsensitiveAbsoluteFilePath(QString  searchDir, QString originalPath);
     static QString qspStrToQt(const QSP_CHAR *str);
     static QColor wxtoQColor(int wxColor);
+
+    static bool useCaseInsensitiveFilePath;
 private:
     static QHash<QString, QString> file_list;
     static QString file_path;

+ 14 - 0
mainwindow.cpp

@@ -459,6 +459,16 @@ void MainWindow::SetAllowHTML5Extras(bool HTML5Extras)
     QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
 }
 
+void MainWindow::SetUseCaseInsensitiveFilePath(bool CaseInsensitiveFilePath)
+{
+    QSPTools::useCaseInsensitiveFilePath = CaseInsensitiveFilePath;
+}
+
+bool MainWindow::GetUseCaseInsensitiveFilePath()
+{
+    return QSPTools::useCaseInsensitiveFilePath;
+}
+
 void MainWindow::LoadSettings(QString filePath)
 {
     QSettings *settings;
@@ -518,6 +528,8 @@ void MainWindow::LoadSettings(QString filePath)
 
     m_isAllowHTML5Extras = settings->value("application/isAllowHTML5Extras", m_isAllowHTML5Extras).toBool();
 
+    QSPTools::useCaseInsensitiveFilePath = settings->value("application/useCaseInsensitiveFilePath", QSPTools::useCaseInsensitiveFilePath).toBool();
+
     langid = settings->value("application/language", langid).toString();
 
     RefreshUI();
@@ -571,6 +583,8 @@ void MainWindow::SaveSettings(QString filePath)
 
     settings->setValue("application/isAllowHTML5Extras", m_isAllowHTML5Extras);
 
+    settings->setValue("application/useCaseInsensitiveFilePath", QSPTools::useCaseInsensitiveFilePath);
+
     settings->setValue("application/language", langid);
 
     settings->sync();

+ 2 - 0
mainwindow.h

@@ -128,6 +128,8 @@ public:
     void SetVideoFix(bool isFix);
     void SetAllowHTML5Extras(bool HTML5Extras);
     bool GetAllowHTML5Extras() { return m_isAllowHTML5Extras; }
+    void SetUseCaseInsensitiveFilePath(bool CaseInsensitiveFilePath);
+    bool GetUseCaseInsensitiveFilePath();
 
 private:
     void CreateMenuBar();

+ 5 - 0
optionsdialog.cpp

@@ -39,6 +39,10 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
     ui->horizontalSlider_volume->setValue((int)(mw->GetOverallVolume() * 100));
     ui->checkBox_videoFix->setChecked(mw->GetVideoFix());
     ui->checkBox_HTML5Extras->setChecked(mw->GetAllowHTML5Extras());
+    ui->checkBox_CaseInsensitiveFilePath->setChecked(mw->GetUseCaseInsensitiveFilePath());
+#ifdef _WIN32
+    ui->checkBox_CaseInsensitiveFilePath->setVisible(false);
+#endif
 
     QDirIterator qmIt(QCoreApplication::applicationDirPath(), QStringList() << "*.qm", QDir::Files);
     while(qmIt.hasNext())
@@ -145,6 +149,7 @@ void OptionsDialog::on_pushButton_ok_clicked()
     mw->SetAutostart(ui->checkBox_autostart->isChecked());
     mw->SetVideoFix(ui->checkBox_videoFix->isChecked());
     mw->SetAllowHTML5Extras(ui->checkBox_HTML5Extras->isChecked());
+    mw->SetUseCaseInsensitiveFilePath(ui->checkBox_CaseInsensitiveFilePath->isChecked());
     if(ui->comboBox_language->count() > 0)
         mw->SetLangID(ui->comboBox_language->itemData(ui->comboBox_language->currentIndex()).toString());
     if(mw->GetOverallVolume() != ui->horizontalSlider_volume->value() / 100.0f)

+ 10 - 0
optionsdialog.ui

@@ -307,6 +307,16 @@
        </property>
       </widget>
      </item>
+     <item row="12" column="0">
+      <widget class="QCheckBox" name="checkBox_CaseInsensitiveFilePath">
+       <property name="text">
+        <string>Use case insensitive paths</string>
+       </property>
+       <property name="checked">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>