atrooney-online-2/src/path_functions.cpp
in1tiate 894b2b2a0e
Consolidate AOScene, AOMovie, and AOCharMovie into one class, add support for (c) animations, implement emote continuity, add scaling overrides to all layer types, allow for stretch-to-fill images, allow for additional effect configuration (#302)
* Rewrite AOScene and remove the need for AOMovie and AOCharMovie by consolidation

* Rename AOScene to AOLayer, apply suggestions to improve functionality

* Implement suggested change to allocation

* Switch from pointer to field, fix ui_vp_player_char not resetting play_once

* Use the variable gif_name instead of the string "gif_name"
 Oops.

* Total rewrite of AOLayer (again)

* Add support for (c) animations, do some housekeeping

* allow themes to override misc chatboxes

* add support for pulling InterfaceLayer elements from theme/misc

* mistakes were made

* move all frame fx functionality to CharLayer subclass

* virtual functions are cool mkay

* remove evidence of my incompetence

* allow themes to override font design inis under theme/misc

* Proper support for theme/misc chatbox, fixes

* Fix chatbox dimensions not updating and inline color causing missingnos

* rename chat markdown to chat markup

* add missing misc overrides

* quick hotfix for chatblank and misc overrides

* Fix oversight with backgrounds causing them to be culled

* Same as last commit but for FG layer

* amend comment to explain impossible shenanigans

* Adjust ForegroundLayer to take charname rather than miscname, allow for checking in char folder

* fix an incredibly embarrassing pathing bug

* add scaling overrides for all layer types, parent orphaned viewport elements to the viewport

* stupid fix because themes use "custom.png" as a button

* switch to .append()

* Revert "Merge branch 'aoscene_rewrite' of https://github.com/AttorneyOnline/AO2-Client into aoscene_rewrite"

This reverts commit bdeb1bff7639d522031aab3c133a83b0e2a291df, reversing
changes made to 125ee63b97a6f6c156e69525d88fddc625e7a978.

* switch to .append() (again)

* move function call to fix showname length calculation error

* fix nonlooping character animations being broken Again

* unparent elements from the viewport and do fancy masking arithmetic instead

* use override keyword

* move scaling override to char.ini, allow stretching, restructure effect property loading

* fix some redundancy

* unparent chat_arrow from chatbox to prevent accidental masking

* at no point do we want a frozen gif to display

* overhaul how wtce is handled

* oops

* also let sounds be pulled from theme miscs

* i should probably compile before i push

* actually make it work

* don't check a default bg

* readd 1x1 stretch thing

* actually the 1x1 thing was a bad idea

* Add missing parenthesis

* Use load_image instead of play

play is a nonexistent method now

* Remote shout_message and usages because it does nothing

* Remove multiple redefinitions

* Add in missing brackets and indent to fix build

I have know idea what this does but it brings fear

* fix build error

* fix chat arrow and remove duped code

* remove more duped code and fix misc themes

* only update chat_arrow when needed

* consolidate log_chatmessage and display_log_chatmessage

Co-authored-by: scatterflower <marisaposs@gameboyprinter.moe>
Co-authored-by: Skye Deving <76892045+skyedeving@users.noreply.github.com>
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
2021-01-19 14:32:11 +03:00

152 lines
4.2 KiB
C++

#include "aoapplication.h"
#include "courtroom.h"
#include "file_functions.h"
#include <QDir>
#include <QRegExp>
#include <QStandardPaths>
#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 AOApplication::get_base_path()
{
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/";
}
#elif defined(__APPLE__)
base_path = applicationDirPath() + "/../../../base/";
#else
base_path = applicationDirPath() + "/base/";
#endif
return base_path;
}
QString AOApplication::get_data_path() { return get_base_path() + "data/"; }
QString AOApplication::get_default_theme_path(QString p_file)
{
QString path = get_base_path() + "themes/default/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_custom_theme_path(QString p_theme, QString p_file)
{
QString path = get_base_path() + "themes/" + p_theme + "/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_theme_path(QString p_file)
{
QString path = get_base_path() + "themes/" + current_theme + "/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_character_path(QString p_char, QString p_file)
{
QString path = get_base_path() + "characters/" + p_char + "/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_misc_path(QString p_misc, QString p_file)
{
QString path = get_base_path() + "misc/" + p_misc + "/" + p_file;
#ifndef CASE_SENSITIVE_FILESYSTEM
return path;
#else
return get_case_sensitive_path(path);
#endif
}
QString AOApplication::get_sounds_path(QString p_file)
{
QString path = get_base_path() + "sounds/general/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_music_path(QString p_song)
{
if (p_song.startsWith("http")) {
return p_song; // url
}
QString path = get_base_path() + "sounds/music/" + p_song;
return get_case_sensitive_path(path);
}
QString AOApplication::get_background_path(QString p_file)
{
QString path = get_base_path() + "background/" +
w_courtroom->get_current_background() + "/" + p_file;
if (courtroom_constructed) {
return get_case_sensitive_path(path);
}
return get_default_background_path(p_file);
}
QString AOApplication::get_default_background_path(QString p_file)
{
QString path = get_base_path() + "background/default/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_evidence_path(QString p_file)
{
QString path = get_base_path() + "evidence/" + p_file;
return get_case_sensitive_path(path);
}
QString AOApplication::get_case_sensitive_path(QString p_file)
{
QFileInfo file(p_file);
QString file_basename = file.fileName();
// no path traversal above base folder
if (!(file.absolutePath().startsWith(get_base_path())))
return get_base_path() + file_basename;
#ifdef CASE_SENSITIVE_FILESYSTEM
// first, check to see if it's actually there (also serves as base case for
// recursion)
if (exists(p_file))
return p_file;
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, QRegExp::FixedString);
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;
#else
return p_file;
#endif
}