reworked get_case_sensitive_path to be recursive
This commit is contained in:
parent
06c7a95bc2
commit
fddb72950e
@ -100,8 +100,7 @@ public:
|
|||||||
QString get_data_path();
|
QString get_data_path();
|
||||||
QString get_theme_path(QString p_file);
|
QString get_theme_path(QString p_file);
|
||||||
QString get_default_theme_path(QString p_file);
|
QString get_default_theme_path(QString p_file);
|
||||||
QString get_character_path(QString p_character, QString p_file);
|
QString get_character_path(QString p_char, QString p_file);
|
||||||
QString get_character_emotions_path(QString p_character, QString p_file);
|
|
||||||
QString get_sounds_path(QString p_file);
|
QString get_sounds_path(QString p_file);
|
||||||
QString get_music_path(QString p_song);
|
QString get_music_path(QString p_song);
|
||||||
QString get_background_path(QString p_file);
|
QString get_background_path(QString p_file);
|
||||||
|
@ -16,7 +16,7 @@ AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x
|
|||||||
void AOEmoteButton::set_image(QString p_char, int p_emote, QString suffix)
|
void AOEmoteButton::set_image(QString p_char, int p_emote, QString suffix)
|
||||||
{
|
{
|
||||||
QString emotion_number = QString::number(p_emote + 1);
|
QString emotion_number = QString::number(p_emote + 1);
|
||||||
QString image_path = ao_app->get_character_emotions_path(p_char, "button" + emotion_number + suffix);
|
QString image_path = ao_app->get_character_path(p_char, "emotions/button" + emotion_number + suffix);
|
||||||
|
|
||||||
if (file_exists(image_path))
|
if (file_exists(image_path))
|
||||||
{
|
{
|
||||||
|
@ -16,3 +16,9 @@ bool dir_exists(QString dir_path)
|
|||||||
|
|
||||||
return check_dir.exists();
|
return check_dir.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool exists(QString p_path) {
|
||||||
|
QFile file(p_path);
|
||||||
|
|
||||||
|
return file.exists();
|
||||||
|
}
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
bool file_exists(QString file_path);
|
bool file_exists(QString file_path);
|
||||||
bool dir_exists(QString file_path);
|
bool dir_exists(QString file_path);
|
||||||
|
bool exists(QString p_path);
|
||||||
|
|
||||||
#endif // FILE_FUNCTIONS_H
|
#endif // FILE_FUNCTIONS_H
|
||||||
|
@ -63,26 +63,13 @@ QString AOApplication::get_theme_path(QString p_file)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AOApplication::get_character_path(QString p_character, QString p_file)
|
QString AOApplication::get_character_path(QString p_char, QString p_file)
|
||||||
{
|
{
|
||||||
QString char_path = get_base_path() + "characters/" + p_character;
|
QString path = get_base_path() + "characters/" + p_char + "/" + p_file;
|
||||||
#ifndef CASE_SENSITIVE_FILESYSTEM
|
#ifndef CASE_SENSITIVE_FILESYSTEM
|
||||||
return char_path + "/" + p_file;
|
return path;
|
||||||
#else
|
#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(path);
|
||||||
return get_case_sensitive_path(
|
|
||||||
get_case_sensitive_path(char_path) + "/" + p_file);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AOApplication::get_character_emotions_path(QString p_character, QString p_file)
|
|
||||||
{
|
|
||||||
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,31 +129,27 @@ QString AOApplication::get_evidence_path(QString p_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString AOApplication::get_case_sensitive_path(QString p_file) {
|
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;
|
||||||
|
|
||||||
QFileInfo file(p_file);
|
QFileInfo file(p_file);
|
||||||
|
|
||||||
//quick check to see if it's actually there first(also serves as base case for recursion)
|
|
||||||
if (file.exists()) return p_file;
|
|
||||||
|
|
||||||
QString file_basename = file.fileName();
|
QString file_basename = file.fileName();
|
||||||
QString file_parent_dir = file.absolutePath();
|
QString file_parent_dir = get_case_sensitive_path(file.absolutePath());
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_FUNCTIONS
|
//second, does it exist in the new parent dir?
|
||||||
qDebug() << "file_basename: " << file_basename;
|
if (exists(file_parent_dir + "/" + file_basename))
|
||||||
qDebug() << "file_parent_dir: " << file_parent_dir;
|
return file_parent_dir + "/" + file_basename;
|
||||||
#endif
|
|
||||||
|
|
||||||
//if parent directory does not exist, recurse
|
|
||||||
//if (!file_exists(file_parent_dir)) {
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
//last resort, dirlist parent dir and find case insensitive match
|
||||||
QRegExp file_rx = QRegExp(file_basename, Qt::CaseInsensitive);
|
QRegExp file_rx = QRegExp(file_basename, Qt::CaseInsensitive);
|
||||||
QStringList files = QDir(file_parent_dir).entryList();
|
QStringList files = QDir(file_parent_dir).entryList();
|
||||||
|
|
||||||
int result = files.indexOf(file_rx);
|
int result = files.indexOf(file_rx);
|
||||||
|
|
||||||
if (result != -1)
|
if (result != -1)
|
||||||
return file_parent_dir + "/" + files.at(result);
|
return file_parent_dir + "/" + files.at(result);
|
||||||
|
|
||||||
//if nothing is found, let the caller handle the missing file
|
//if nothing is found, let the caller handle the missing file
|
||||||
return p_file;
|
return file_parent_dir + "/" + file_basename;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user