diff --git a/aoapplication.h b/aoapplication.h index dbda673..a237b8f 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -117,15 +117,15 @@ public: //implementation in path_functions.cpp QString get_base_path(); QString get_data_path(); - QString get_theme_path(); - QString get_default_theme_path(); - QString get_character_path(QString p_character); - QString get_demothings_path(); - QString get_sounds_path(); + QString get_theme_path(QString p_file); + QString get_default_theme_path(QString p_file); + QString get_character_path(QString p_char, QString p_file); + QString get_sounds_path(QString p_file); QString get_music_path(QString p_song); - QString get_background_path(); - QString get_default_background_path(); - QString get_evidence_path(); + QString get_background_path(QString p_file); + QString get_default_background_path(QString p_file); + QString get_evidence_path(QString p_file); + QString get_case_sensitive_path(QString p_file); ////// Functions for reading and writing files ////// // Implementations file_functions.cpp diff --git a/aobutton.cpp b/aobutton.cpp index ded35af..5be2e67 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -15,8 +15,8 @@ AOButton::~AOButton() void AOButton::set_image(QString p_image) { - QString image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); if (file_exists(image_path)) this->setStyleSheet("border-image:url(\"" + image_path + "\")"); diff --git a/aocharbutton.cpp b/aocharbutton.cpp index 2d134b1..23fd0c6 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -56,20 +56,12 @@ void AOCharButton::set_passworded() void AOCharButton::set_image(QString p_character) { - QString image_path = ao_app->get_character_path(p_character) + "char_icon.png"; - QString legacy_path = ao_app->get_demothings_path() + p_character.toLower() + "_char_icon.png"; - QString alt_path = ao_app->get_demothings_path() + p_character.toLower() + "_off.png"; + QString image_path = ao_app->get_character_path(p_character, "char_icon.png"); this->setText(""); if (file_exists(image_path)) this->setStyleSheet("border-image:url(\"" + image_path + "\")"); - else if (file_exists(legacy_path)) - { - this->setStyleSheet("border-image:url(\"" + legacy_path + "\")"); - //ninja optimization - QFile::copy(legacy_path, image_path); - } else { this->setStyleSheet("border-image:url()"); diff --git a/aocharmovie.cpp b/aocharmovie.cpp index e9c88ba..5748723 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -19,11 +19,11 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { - QString original_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".gif"; - QString alt_path = ao_app->get_character_path(p_char) + p_emote.toLower() + ".png"; - QString apng_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".apng"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString placeholder_default_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString original_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".gif"); + QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); + QString apng_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".apng"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString placeholder_default_path = ao_app->get_default_theme_path("placeholder.gif"); QString gif_path; if (file_exists(apng_path)) @@ -61,7 +61,7 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - QString gif_path = ao_app->get_character_path(p_char) + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, p_emote); m_movie->stop(); this->clear(); @@ -78,8 +78,11 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) real_duration += m_movie->nextFrameDelay(); m_movie->jumpToFrame(n_frame + 1); } + +#ifdef DEBUG_GIF qDebug() << "full_duration: " << full_duration; qDebug() << "real_duration: " << real_duration; +#endif double percentage_modifier = 100.0; @@ -91,7 +94,10 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) if (percentage_modifier > 100.0) percentage_modifier = 100.0; } + +#ifdef DEBUG_GIF qDebug() << "% mod: " << percentage_modifier; +#endif if (full_duration == 0 || full_duration >= real_duration) { @@ -110,7 +116,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) void AOCharMovie::play_talking(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(b)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(b)" + p_emote); m_movie->stop(); this->clear(); @@ -123,7 +129,7 @@ void AOCharMovie::play_talking(QString p_char, QString p_emote) void AOCharMovie::play_idle(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(a)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(a)" + p_emote); m_movie->stop(); this->clear(); diff --git a/aoemotebutton.cpp b/aoemotebutton.cpp index 9e3c446..9c1d388 100644 --- a/aoemotebutton.cpp +++ b/aoemotebutton.cpp @@ -16,19 +16,13 @@ AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x void AOEmoteButton::set_image(QString p_char, int p_emote, QString suffix) { QString emotion_number = QString::number(p_emote + 1); - QString image_path = ao_app->get_character_path(p_char) + "emotions/ao2/button" + emotion_number + suffix; - QString alt_path = ao_app->get_character_path(p_char) + "emotions/button" + emotion_number + suffix; + QString image_path = ao_app->get_character_path(p_char, "emotions/button" + emotion_number + suffix); if (file_exists(image_path)) { this->setText(""); this->setStyleSheet("border-image:url(\"" + image_path + "\")"); } - else if (file_exists(alt_path)) - { - this->setText(""); - this->setStyleSheet("border-image:url(\"" + alt_path + "\")"); - } else { this->setText(ao_app->get_emote_comment(p_char, p_emote)); diff --git a/aoevidencebutton.cpp b/aoevidencebutton.cpp index 573b8ef..924aeb8 100644 --- a/aoevidencebutton.cpp +++ b/aoevidencebutton.cpp @@ -37,7 +37,7 @@ void AOEvidenceButton::reset() void AOEvidenceButton::set_image(QString p_image) { - QString image_path = ao_app->get_evidence_path() + p_image; + QString image_path = ao_app->get_evidence_path(p_image); if (file_exists(image_path)) { @@ -53,8 +53,8 @@ void AOEvidenceButton::set_image(QString p_image) void AOEvidenceButton::set_theme_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; diff --git a/aoevidencedisplay.cpp b/aoevidencedisplay.cpp index 5364ffb..9ec105d 100644 --- a/aoevidencedisplay.cpp +++ b/aoevidencedisplay.cpp @@ -21,7 +21,7 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid sfx_player->set_volume(p_volume); - QString f_evidence_path = ao_app->get_evidence_path() + p_evidence_image; + QString f_evidence_path = ao_app->get_evidence_path(p_evidence_image); QPixmap f_pixmap(f_evidence_path); @@ -47,8 +47,8 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid evidence_icon->setPixmap(f_pixmap.scaled(evidence_icon->width(), evidence_icon->height(), Qt::IgnoreAspectRatio)); - QString f_default_gif_path = ao_app->get_default_theme_path() + gif_name; - QString f_gif_path = ao_app->get_theme_path() + gif_name; + QString f_default_gif_path = ao_app->get_default_theme_path(gif_name); + QString f_gif_path = ao_app->get_theme_path(gif_name); if (file_exists(f_gif_path)) final_gif_path = f_gif_path; diff --git a/aoimage.cpp b/aoimage.cpp index 935ba74..7bb56bb 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -15,8 +15,8 @@ AOImage::~AOImage() void AOImage::set_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; @@ -32,7 +32,7 @@ void AOImage::set_image(QString p_image) void AOImage::set_image_from_path(QString p_path) { - QString default_path = ao_app->get_default_theme_path() + "chatmed.png"; + QString default_path = ao_app->get_default_theme_path("chatmed.png"); QString final_path; diff --git a/aomovie.cpp b/aomovie.cpp index 88f81e9..6839eab 100644 --- a/aomovie.cpp +++ b/aomovie.cpp @@ -28,16 +28,16 @@ void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) QString custom_path; if (p_gif == "custom") - custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char) + p_gif); + custom_path = ao_app->get_image_suffix(get_character_path(p_char, p_gif)); else - custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char) + p_gif + "_bubble"); + custom_path = ao_app->get_image_suffix(get_character_path(p_char, p_gif + "_bubble")); QString misc_path = ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble.gif"; QString custom_theme_path = ao_app->get_base_path() + "themes/" + p_custom_theme + "/" + p_gif + ".gif"; - QString theme_path = ao_app->get_theme_path() + p_gif + ".gif"; - QString default_theme_path = ao_app->get_default_theme_path() + p_gif + ".gif"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString default_placeholder_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString theme_path = ao_app->get_theme_path(p_gif + ".gif"); + QString default_theme_path = ao_app->get_default_theme_path(p_gif + ".gif"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString default_placeholder_path = ao_app->get_default_theme_path("placeholder.gif"); if (file_exists(misc_path)) gif_path = misc_path; diff --git a/aoscene.cpp b/aoscene.cpp index dde671f..344522b 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -11,9 +11,9 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) void AOScene::set_image(QString p_image) { - QString background_path = ao_app->get_background_path() + p_image + ".png"; - QString animated_background_path = ao_app->get_background_path() + p_image + ".gif"; - QString default_path = ao_app->get_default_background_path() + p_image; + QString background_path = ao_app->get_background_path(p_image + ".png"); + QString animated_background_path = ao_app->get_background_path(p_image + ".gif"); + QString default_path = ao_app->get_default_background_path(p_image + ".png"); QPixmap background(background_path); QPixmap default_bg(default_path); @@ -48,8 +48,8 @@ void AOScene::set_legacy_desk(QString p_image) //vanilla desks vary in both width and height. in order to make that work with viewport rescaling, //some INTENSE math is needed. - QString desk_path = ao_app->get_background_path() + p_image; - QString default_path = ao_app->get_default_background_path() + p_image; + QString desk_path = ao_app->get_background_path(p_image); + QString default_path = ao_app->get_default_background_path(p_image); QPixmap f_desk; @@ -67,7 +67,7 @@ void AOScene::set_legacy_desk(QString p_image) //int final_y = y_modifier * vp_height; //int final_w = w_modifier * f_desk.width(); - int final_h = h_modifier * f_desk.height(); + int final_h = static_cast(h_modifier * f_desk.height()); //this->resize(final_w, final_h); //this->setPixmap(f_desk.scaled(final_w, final_h)); diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index c616121..d5b5a9e 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -9,16 +9,14 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) { - p_sfx = p_sfx.toLower(); - QString misc_path = ""; QString char_path = ""; - QString sound_path = ao_app->get_sounds_path() + p_sfx; + QString sound_path = ao_app->get_sounds_path(p_sfx); if (shout != "") misc_path = ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx; if (p_char != "") - char_path = ao_app->get_character_path(p_char) + p_sfx; + char_path = ao_app->get_character_path(p_char, p_sfx); QString f_path; diff --git a/charselect.cpp b/charselect.cpp index 54286b2..ce37f85 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -120,12 +120,12 @@ void Courtroom::set_char_select_page() void Courtroom::char_clicked(int n_char) { - QString char_ini_path = ao_app->get_character_path(char_list.at(n_char).name) + "char.ini"; + QString char_ini_path = ao_app->get_character_path(char_list.at(n_char).name, "char.ini"); + qDebug() << "char_ini_path" << char_ini_path; if (!file_exists(char_ini_path)) { - qDebug() << "did not find " << char_ini_path; call_notice("Could not find " + char_ini_path); return; } diff --git a/courtroom.cpp b/courtroom.cpp index dd6bc66..88139e1 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -456,7 +456,7 @@ void Courtroom::set_widgets() //the size of the ui_vp_legacy_desk element relies on various factors and is set in set_scene() double y_modifier = 147.0 / 192.0; - int final_y = y_modifier * ui_viewport->height(); + int final_y = static_cast(y_modifier * ui_viewport->height()); ui_vp_legacy_desk->move(0, final_y); ui_vp_legacy_desk->hide(); @@ -793,11 +793,10 @@ void Courtroom::set_background(QString p_background) testimony_in_progress = false; current_background = p_background; - QString bg_path = get_background_path(); - is_ao2_bg = file_exists(bg_path + "defensedesk.png") && - file_exists(bg_path + "prosecutiondesk.png") && - file_exists(bg_path + "stand.png"); + is_ao2_bg = file_exists(ao_app->get_background_path("defensedesk.png")) && + file_exists(ao_app->get_background_path("prosecutiondesk.png")) && + file_exists(ao_app->get_background_path("stand.png")); if (is_ao2_bg) { @@ -874,11 +873,10 @@ void Courtroom::enter_courtroom(int p_cid) ui_prosecution_plus->hide(); } - QString char_path = ao_app->get_character_path(current_char); - if (ao_app->custom_objection_enabled && - (file_exists(char_path + "custom.gif") || file_exists(char_path + "custom.apng")) && - file_exists(char_path + "custom.wav")) + (file_exists(ao_app->get_character_path(char_path, "custom.gif")) || + file_exists(ao_app->get_character_path(char_path, "custom.apng"))) && + file_exists(ao_app->get_character_path(char_path, "custom.wav"))) ui_custom_objection->show(); else ui_custom_objection->hide(); @@ -936,7 +934,7 @@ void Courtroom::list_music() ui_music_list->addItem(i_song_listname); music_row_to_number.append(n_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); @@ -1557,14 +1555,14 @@ void Courtroom::handle_chatmessage_2() case 1: case 2: case 6: play_preanim(); break; - default: - qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); - //intentional fallthru case 0: case 5: if (m_chatmessage[NONINTERRUPTING_PRE].toInt() == 0) handle_chatmessage_3(); else play_noninterrupting_preanim(); + break; + default: + qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); } } @@ -1638,16 +1636,12 @@ void Courtroom::handle_chatmessage_3() QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; - switch (f_anim_state) - { - case 2: + if (f_anim_state == 2) { ui_vp_player_char->play_talking(f_char, f_emote); anim_state = 2; - break; - default: - qDebug() << "W: invalid anim_state: " << f_anim_state; - // fall through - case 3: + } + else + { ui_vp_player_char->play_idle(f_char, f_emote); anim_state = 3; } diff --git a/courtroom.h b/courtroom.h index dc1c18d..85c454a 100644 --- a/courtroom.h +++ b/courtroom.h @@ -156,13 +156,10 @@ public: //send a message that the player is banned and quits the server void set_ban(int p_cid); - //implementations in path_functions.cpp - QString get_background_path(); - QString get_default_background_path(); - //cid = character id, returns the cid of the currently selected character int get_cid() {return m_cid;} QString get_current_char() {return current_char;} + QString get_current_background() {return current_background;} //properly sets up some varibles: resets user state void enter_courtroom(int p_cid); diff --git a/evidence.cpp b/evidence.cpp index e5ef490..4e79664 100644 --- a/evidence.cpp +++ b/evidence.cpp @@ -192,7 +192,7 @@ void Courtroom::on_evidence_image_button_clicked() dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("Images (*.png)")); dialog.setViewMode(QFileDialog::List); - dialog.setDirectory(ao_app->get_evidence_path()); + dialog.setDirectory(ao_app->get_base_path() + "evidence"); QStringList filenames; diff --git a/file_functions.cpp b/file_functions.cpp index bf2a018..f93ee15 100644 --- a/file_functions.cpp +++ b/file_functions.cpp @@ -13,3 +13,9 @@ bool dir_exists(QString dir_path) return check_dir.exists(); } + +bool exists(QString p_path) { + QFile file(p_path); + + return file.exists(); +} diff --git a/file_functions.h b/file_functions.h index 77e1c20..6937ed8 100644 --- a/file_functions.h +++ b/file_functions.h @@ -7,5 +7,6 @@ bool file_exists(QString file_path); bool dir_exists(QString file_path); +bool exists(QString p_path); #endif // FILE_FUNCTIONS_H diff --git a/path_functions.cpp b/path_functions.cpp index d4238c9..24041e2 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -2,30 +2,39 @@ #include "courtroom.h" #include "file_functions.h" +#include +#include +#include + #ifdef BASE_OVERRIDE #include "base_override.h" #endif -QString base_path = ""; + +//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 AOApplication::get_base_path() { - if (base_path == "") - { -#ifdef BASE_OVERRIDE - base_path = base_override; -#elif defined(ANDROID) - QString sdcard_storage = getenv("SECONDARY_STORAGE"); - if (dir_exists(sdcard_storage + "/AO2/")){ - base_path = sdcard_storage + "/AO2/"; - }else{ - QString external_storage = getenv("EXTERNAL_STORAGE"); - base_path = external_storage + "/AO2/"; - } + QString base_path = ""; +#ifdef ANDROID + QString sdcard_storage = getenv("SECONDARY_STORAGE"); + if (dir_exists(sdcard_storage + "/AO2/")){ + base_path = sdcard_storage + "/AO2/"; + } + else { + QString external_storage = getenv("EXTERNAL_STORAGE"); + base_path = external_storage + "/AO2/"; + } #else base_path = QDir::currentPath() + "/base/"; #endif -} - return base_path; + + return base_path; } QString AOApplication::get_data_path() @@ -33,72 +42,111 @@ 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() +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_char, QString p_file) { - return get_base_path() + "characters/" + p_character.toLower() + "/"; + QString path = get_base_path() + "characters/" + p_char + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_demothings_path() +QString AOApplication::get_sounds_path(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 AOApplication::get_sounds_path() -{ - return get_base_path() + "sounds/general/"; + QString path = get_base_path() + "sounds/general/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } + QString AOApplication::get_music_path(QString p_song) { - return get_base_path() + "sounds/music/" + p_song.toLower(); + QString path = get_base_path() + "sounds/music/" + p_song; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + 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(); - //this function being called when the courtroom isn't constructed makes no sense - return ""; + QString path = get_base_path() + "background/" + w_courtroom->get_current_background() + "/" + p_file; + if (courtroom_constructed) { +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif + } + return get_default_background_path(p_file); } -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 Courtroom::get_background_path() -{ - return ao_app->get_base_path() + "background/" + current_background.toLower() + "/"; -} +QString AOApplication::get_case_sensitive_path(QString p_file) { + //first, check to see if it's actually there (also serves as base case for recursion) + if (exists(p_file)) return p_file; -QString Courtroom::get_default_background_path() -{ - return ao_app->get_base_path() + "background/default/"; + QFileInfo file(p_file); + + QString file_basename = file.fileName(); + QString file_parent_dir = get_case_sensitive_path(file.absolutePath()); + + //second, does it exist in the new parent dir? + if (exists(file_parent_dir + "/" + file_basename)) + return file_parent_dir + "/" + file_basename; + + //last resort, dirlist parent dir and find case insensitive match + QRegExp file_rx = QRegExp(file_basename, Qt::CaseInsensitive); + QStringList files = QDir(file_parent_dir).entryList(); + + int result = files.indexOf(file_rx); + + if (result != -1) + return file_parent_dir + "/" + files.at(result); + + //if nothing is found, let the caller handle the missing file + return file_parent_dir + "/" + file_basename; } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index a633dd9..69c5fab 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -159,8 +159,8 @@ QString AOApplication::read_design_ini(QString p_identifier, QString p_design_pa QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); QPoint return_value; @@ -189,8 +189,8 @@ QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); pos_size_type return_value; @@ -223,8 +223,8 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QStrin int AOApplication::get_font_size(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); if (f_result == "") @@ -240,8 +240,8 @@ int AOApplication::get_font_size(QString p_identifier, QString p_file) QColor AOApplication::get_color(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); QColor return_color(255, 255, 255); @@ -296,8 +296,8 @@ QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat) QString AOApplication::get_sfx(QString p_identifier) { - QString design_ini_path = get_theme_path() + "courtroom_sounds.ini"; - QString default_path = get_default_theme_path() + "courtroom_sounds.ini"; + QString design_ini_path = get_theme_path("courtroom_sounds.ini"); + QString default_path = get_default_theme_path("courtroom_sounds.ini"); QString f_result = read_design_ini(p_identifier, design_ini_path); QString return_sfx = ""; @@ -317,13 +317,13 @@ QString AOApplication::get_sfx(QString p_identifier) QString AOApplication::get_sfx_suffix(QString sound_to_check) { - QString mp3_check = get_sounds_path() + sound_to_check + ".mp3"; - QString opus_check = get_sounds_path() + sound_to_check + ".opus"; - if(file_exists(opus_check)) + QString mp3_check = get_sounds_path(sound_to_check + ".mp3"); + QString opus_check = get_sounds_path(sound_to_check + ".opus"); + if (file_exists(opus_check)) { return sound_to_check + ".opus"; } - if(file_exists(mp3_check)) + else if (file_exists(mp3_check)) { return sound_to_check + ".mp3"; } @@ -332,8 +332,8 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check) QString AOApplication::get_image_suffix(QString path_to_check) { - QString apng_check = path_to_check + ".apng"; - if(file_exists(apng_check)) + QString apng_check = get_sounds_path(path_to_check + ".apng"); + if (file_exists(apng_check)) { return path_to_check + ".apng"; } @@ -396,14 +396,14 @@ QString AOApplication::get_chat(QString p_char) QString f_result = read_char_ini(p_char, "chat", "Options"); //handling the correct order of chat is a bit complicated, we let the caller do it - return f_result.toLower(); + return f_result; } QString AOApplication::get_char_shouts(QString p_char) { QString f_result = read_char_ini(p_char, "shouts", "Options"); - return f_result.toLower(); + return f_result; } int AOApplication::get_preanim_duration(QString p_char, QString p_emote)