diff options
| author | David Skoland <davidskoland@gmail.com> | 2018-11-16 02:01:08 +0100 |
|---|---|---|
| committer | David Skoland <davidskoland@gmail.com> | 2018-11-16 02:01:08 +0100 |
| commit | 8ffdd2afb84ec483160f156d24cf786165a9506c (patch) | |
| tree | 39212e8d648e458188ce49823963fb1c88b70bd2 /path_functions.cpp | |
| parent | 11c2f258ebf48f515cdba5c7ae9cccec447604dd (diff) | |
refactored path functions and added support for case-sensitive filesystems
Diffstat (limited to 'path_functions.cpp')
| -rw-r--r-- | path_functions.cpp | 141 |
1 files changed, 89 insertions, 52 deletions
diff --git a/path_functions.cpp b/path_functions.cpp index 5c4972f0..83e47521 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -46,91 +46,128 @@ QString AOApplication::get_data_path() return get_base_path() + "data/"; } -QString AOApplication::get_theme_path() +QString AOApplication::get_default_theme_path(QString p_file) { - return get_base_path() + "themes/" + current_theme.toLower() + "/"; + QString path = get_base_path() + "themes/default/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_default_theme_path() +//assume that the capitalization of the theme in config is correct +QString AOApplication::get_theme_path(QString p_file) { - return get_base_path() + "themes/default/"; + QString path = get_base_path() + "themes/" + current_theme + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_character_path(QString p_character) +QString AOApplication::get_character_path(QString p_character, QString p_file) { - return get_base_path() + "characters/" + p_character.toLower() + "/"; + QString char_path = get_base_path() + "characters/" + p_character; +#ifndef CASE_SENSITIVE_FILESYSTEM + return char_path + "/" + p_file; +#else + //need two calls to get_case_sensitive_path because character folder name may be wrong as well as the filename + return get_case_sensitive_path( + get_case_sensitive_path(char_path) + "/" + p_file); +#endif } -QString AOApplication::get_demothings_path() +QString AOApplication::get_character_emotions_path(QString p_character, QString p_file) { - QString default_path = "misc/demothings/"; - QString alt_path = "misc/RosterImages"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; + QString char_path = get_base_path() + "characters/" + p_character; +#ifndef CASE_SENSITIVE_FILESYSTEM + return char_path + "/emotions/" + p_file; +#else + return get_case_sensitive_path( + get_case_sensitive_path(char_path) + "/emotions/" + p_file); +#endif } + QString AOApplication::get_sounds_path() { - return get_base_path() + "sounds/general/"; + QString path = get_base_path() + "sounds/general/"; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } + QString AOApplication::get_music_path(QString p_song) { + QString path = get_base_path() + "sounds/music/" + p_song; #ifndef CASE_SENSITIVE_FILESYSTEM - return get_base_path() + "sounds/music/" + p_song; + return path; #else - return get_case_sensitive_path(get_base_path() + "sounds/music/", p_song); + return get_case_sensitive_path(path); #endif } -QString AOApplication::get_background_path() +QString AOApplication::get_background_path(QString p_file) { - if (courtroom_constructed) - return w_courtroom->get_background_path(); + QString bg_path = get_base_path() + "background/" + w_courtroom->get_current_background(); + if (courtroom_constructed) { +#ifndef CASE_SENSITIVE_FILESYSTEM + return bg_path + "/" + p_file; +#else + return get_case_sensitive_path( + get_case_sensitive_path(bg_path) + "/" + p_file); +#endif + } //this function being called when the courtroom isn't constructed makes no sense return ""; } -QString AOApplication::get_default_background_path() +QString AOApplication::get_default_background_path(QString p_file) { - return get_base_path() + "background/default/"; + QString path = get_base_path() + "background/default/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_evidence_path() +QString AOApplication::get_evidence_path(QString p_file) { - QString default_path = "evidence/"; - QString alt_path = "items/"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; + QString path = get_base_path() + "evidence/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -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); +QString AOApplication::get_case_sensitive_path(QString p_file) { + qDebug() << "calling get_case_sensitive_path: " << p_file; - 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; -} + QFileInfo file(p_file); -QString Courtroom::get_background_path() -{ - return ao_app->get_base_path() + "background/" + current_background.toLower() + "/"; -} + //quick check to see if it's actually there first + if (file.exists()) return p_file; -QString Courtroom::get_default_background_path() -{ - return ao_app->get_base_path() + "background/default/"; + QString file_name = file.fileName(); + + qDebug() << "file_name: " << file_name; + + QString file_path = file.absolutePath(); + + qDebug() << "file_path: " << file_path; + + QRegExp file_rx = QRegExp(file_name, Qt::CaseInsensitive); + QStringList files = QDir(file_path).entryList(); + int result = files.indexOf(file_rx); + + if (result != -1) + return file_path + "/" + files.at(result); + + //if nothing is found, let the caller handle the missing file + return p_file; } |
