From 051c8975eccffc0a0b5b1312e06b2b412590e475 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Thu, 15 Nov 2018 23:56:58 +0100 Subject: [PATCH] added case insensitive path function for those filesystems --- aoapplication.h | 1 + courtroom.cpp | 2 +- main.cpp | 8 -------- path_functions.cpp | 31 ++++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index f69a0ea..0cb2c78 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -107,6 +107,7 @@ public: QString get_background_path(); QString get_default_background_path(); QString get_evidence_path(); + QString get_case_sensitive_path(QString p_dir, QString p_file); ////// Functions for reading and writing files ////// // Implementations file_functions.cpp diff --git a/courtroom.cpp b/courtroom.cpp index 5c552a1..5c3f966 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -748,7 +748,7 @@ void Courtroom::list_music() { ui_music_list->addItem(i_song); - QString song_path = ao_app->get_base_path() + "sounds/music/" + i_song.toLower(); + QString song_path = ao_app->get_music_path(i_song); if (file_exists(song_path)) ui_music_list->item(n_listed_songs)->setBackground(found_brush); diff --git a/main.cpp b/main.cpp index a690f3c..5696e2e 100644 --- a/main.cpp +++ b/main.cpp @@ -8,14 +8,6 @@ #include -//this is a quite broad generalization -//the most common OSes(mac and windows) are _usually_ case insensitive -//however, there do exist mac installations with case sensitive filesystems -//in that case, define CASE_SENSITIVE_FILESYSTEM and compile on a mac -#if (defined (LINUX) || defined (__linux__)) -#define CASE_SENSITIVE_FILESYSTEM -#endif - int main(int argc, char *argv[]) { #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0) diff --git a/path_functions.cpp b/path_functions.cpp index 820c05a..5c4972f 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -4,10 +4,20 @@ #include #include #include +#include #ifdef BASE_OVERRIDE #include "base_override.h" #endif + +//this is a quite broad generalization +//the most common OSes(mac and windows) are _usually_ case insensitive +//however, there do exist mac installations with case sensitive filesystems +//in that case, define CASE_SENSITIVE_FILESYSTEM and compile on a mac +#if (defined (LINUX) || defined (__linux__)) +#define CASE_SENSITIVE_FILESYSTEM +#endif + QString base_path = ""; QString AOApplication::get_base_path() @@ -68,7 +78,11 @@ QString AOApplication::get_sounds_path() } QString AOApplication::get_music_path(QString p_song) { - return get_base_path() + "sounds/music/" + p_song.toLower(); +#ifndef CASE_SENSITIVE_FILESYSTEM + return get_base_path() + "sounds/music/" + p_song; +#else + return get_case_sensitive_path(get_base_path() + "sounds/music/", p_song); +#endif } QString AOApplication::get_background_path() @@ -96,6 +110,21 @@ QString AOApplication::get_evidence_path() return get_base_path() + default_path; } +QString AOApplication::get_case_sensitive_path(QString p_dir, QString p_file) { + qDebug() << "calling get_case_sensitive_path"; + QRegExp file_rx = QRegExp(p_file, Qt::CaseInsensitive); + QStringList files = QDir(p_dir).entryList(); + int result = files.indexOf(file_rx); + + if (result != -1) { + QString path = p_dir + files.at(result); + qDebug() << "returning " << path; + return path; + } + //if nothing is found, let the caller handle the missing file + return p_dir + p_file; +} + QString Courtroom::get_background_path() { return ao_app->get_base_path() + "background/" + current_background.toLower() + "/";