Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class AOApplication : public QApplication {
QString get_current_char();

// implementation in path_functions.cpp
QString get_base_path();
VPath get_theme_path(QString p_file, QString p_theme="");
VPath get_character_path(QString p_char, QString p_file);
VPath get_misc_path(QString p_misc, QString p_file);
Expand Down
2 changes: 2 additions & 0 deletions include/file_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <QDir>
#include <QFileInfo>
#include <QString>
#include <QCoreApplication>

bool file_exists(QString file_path);
bool dir_exists(QString file_path);
bool exists(QString p_path);
QString get_base_path();

#endif // FILE_FUNCTIONS_H
1 change: 1 addition & 0 deletions include/lobby.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class QTreeWidgetItem;

#include <QMainWindow>
#include "networkmanager.h"
#include "file_functions.h"

#ifdef ANDROID
#include <QtAndroidExtras/QtAndroid>
Expand Down
22 changes: 11 additions & 11 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4227,9 +4227,9 @@ void Courtroom::on_ooc_return_pressed()
#else
QStringList command = ooc_message.split(" ", Qt::SkipEmptyParts);
#endif
QDir casefolder("base/cases");
QDir casefolder(get_base_path()+"/cases");
if (!casefolder.exists()) {
QDir::current().mkdir("base/" + casefolder.dirName());
QDir::current().mkdir(get_base_path() + casefolder.dirName());
append_server_chatmessage(
"CLIENT",
tr("You don't have a `base/cases/` folder! It was just made for you, "
Expand Down Expand Up @@ -4266,7 +4266,7 @@ void Courtroom::on_ooc_return_pressed()
return;
}

QSettings casefile("base/cases/" + command[1] + ".ini",
QSettings casefile(get_base_path() + "/cases/" + command[1] + ".ini",
QSettings::IniFormat);

QString caseauth = casefile.value("author", "").value<QString>();
Expand Down Expand Up @@ -4327,9 +4327,9 @@ void Courtroom::on_ooc_return_pressed()
#else
QStringList command = ooc_message.split(" ", Qt::SkipEmptyParts);
#endif
QDir casefolder("base/cases");
QDir casefolder(get_base_path() + "cases");
if (!casefolder.exists()) {
QDir::current().mkdir("base/" + casefolder.dirName());
QDir(get_base_path()).mkdir(casefolder.dirName());
append_server_chatmessage(
"CLIENT",
tr("You don't have a `base/cases/` folder! It was just made for you, "
Expand Down Expand Up @@ -4363,7 +4363,7 @@ void Courtroom::on_ooc_return_pressed()
ui_ooc_chat_message->clear();
return;
}
QSettings casefile("base/cases/" + command[1] + ".ini",
QSettings casefile(get_base_path() + "/cases/" + command[1] + ".ini",
QSettings::IniFormat);
casefile.setValue("author", ui_ooc_chat_name->text());
casefile.setValue("cmdoc", "");
Expand Down Expand Up @@ -4583,7 +4583,7 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
}
QString p_path = ao_app->get_real_path(VPath("iniswaps.ini"));
if (!file_exists(p_path)) {
p_path = ao_app->get_base_path() + "iniswaps.ini";
p_path = get_base_path() + "iniswaps.ini";
}
ao_app->write_to_file(swaplist.join("\n"), p_path);
ui_iniswap_dropdown->blockSignals(true);
Expand Down Expand Up @@ -4733,7 +4733,7 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
menu->addSeparator();
menu->addAction(QString("Open base sounds folder"), this,
[=] {
QString p_path = ao_app->get_base_path() + "sounds/general/";
QString p_path = get_base_path() + "sounds/general/";
if (!dir_exists(p_path)) {
return;
}
Expand All @@ -4760,7 +4760,7 @@ void Courtroom::on_sfx_edit_requested()
}

if (!file_exists(p_path)) {
p_path = ao_app->get_base_path() + "soundlist.ini";
p_path = get_base_path() + "soundlist.ini";
}
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
}
Expand Down Expand Up @@ -5008,7 +5008,7 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
menu->addSeparator();
menu->addAction(QString("Open base music folder"), this,
[=] {
QString p_path = ao_app->get_base_path() + "sounds/music/";
QString p_path = get_base_path() + "sounds/music/";
if (!dir_exists(p_path)) {
return;
}
Expand Down Expand Up @@ -5646,7 +5646,7 @@ void Courtroom::on_evidence_context_menu_requested(const QPoint &pos)
QMenu *menu = new QMenu(this);
menu->addAction(QString("Open base evidence folder"), this,
[=] {
QString p_path = ao_app->get_base_path() + "evidence/";
QString p_path = get_base_path() + "evidence/";
if (!dir_exists(p_path)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/evidence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void Courtroom::on_evidence_image_name_edited()

void Courtroom::on_evidence_image_button_clicked()
{
QDir dir("base/evidence/");
QDir dir(get_base_path() + "/evidence/");
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("Images (*.png)"));
Expand All @@ -418,7 +418,7 @@ void Courtroom::on_evidence_image_button_clicked()

QString filename = filenames.at(0);
QStringList bases = Options::getInstance().mountPaths();
bases.prepend(ao_app->get_base_path());
bases.prepend(get_base_path());
for (const QString &base : bases) {
QDir baseDir(base);
if (filename.startsWith(baseDir.absolutePath() + "/")) {
Expand Down
20 changes: 20 additions & 0 deletions src/file_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ bool exists(QString p_path)

return file.exists();
}

QString get_base_path()
{
QString base_path = "";
#ifdef ANDROID
QString sdcard_storage = getenv("SECONDARY_STORAGE");
if (dir_exists(sdcard_storage + "/base/")) {
base_path = sdcard_storage + "/base/";
}
else {
QString external_storage = getenv("EXTERNAL_STORAGE");
base_path = external_storage + "/base/";
}
#elif defined(__APPLE__)
base_path = QCoreApplication::applicationDirPath() + "/../../../base/";
#else
base_path = QCoreApplication::applicationDirPath() + "/base/";
#endif
return base_path;
}
2 changes: 1 addition & 1 deletion src/lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Lobby::loadUI()
FROM_UI(QTextBrowser, game_changelog_text)
if (ui_game_changelog_text != nullptr) {
QString l_changelog_text = "No changelog found.";
QFile l_changelog(ao_app->get_base_path() + "changelog.md");
QFile l_changelog(get_base_path() + "changelog.md");
if (!l_changelog.open(QFile::ReadOnly)) {
qDebug() << "Unable to locate changelog file. Does it even exist?";
ui_game_changelog_text->setMarkdown(l_changelog_text);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main(int argc, char *argv[])
QResource::registerResource(main_app.get_asset("themes/" + Options::getInstance().theme() + ".rcc"));

QFontDatabase fontDatabase;
QDirIterator it(main_app.get_base_path() + "fonts",
QDirIterator it(get_base_path() + "fonts",
QDirIterator::Subdirectories);
while (it.hasNext())
fontDatabase.addApplicationFont(it.next());
Expand Down
14 changes: 7 additions & 7 deletions src/options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "options.h"
#include "file_functions.h"

#include <QCoreApplication>
#include <QDebug>
Expand All @@ -14,8 +15,7 @@ void Options::migrateCallwords()
QStringList l_callwords;

QFile l_file;
l_file.setFileName(QCoreApplication::applicationDirPath() +
"/base/callwords.ini");
l_file.setFileName(get_base_path() + "callwords.ini");

if (!l_file.open(QIODevice::ReadOnly)) {
qWarning() << "Unable to migrate callwords : File not open.";
Expand All @@ -38,10 +38,10 @@ void Options::migrateCallwords()
}

Options::Options()
: config(QCoreApplication::applicationDirPath() + "/base/config.ini",
: config(get_base_path() + "config.ini",
QSettings::IniFormat, nullptr),
favorite(QCoreApplication::applicationDirPath() +
"/base/favorite_servers.ini",
favorite(get_base_path() +
"favorite_servers.ini",
QSettings::IniFormat, nullptr)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -60,8 +60,8 @@ void Options::migrate()
if (config.contains("show_custom_shownames")) {
config.remove("show_custom_shownames");
}
if (QFile::exists(QCoreApplication::applicationDirPath() +
"/base/callwords.ini")) {
if (QFile::exists(get_base_path() +
"callwords.ini")) {
migrateCallwords();
}
if (config.contains("ooc_name")) {
Expand Down
20 changes: 0 additions & 20 deletions src/path_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ static bool is_power_2(unsigned int n) {
return r == 1;
}

QString AOApplication::get_base_path()
{
QString base_path = "";
#ifdef ANDROID
QString sdcard_storage = getenv("SECONDARY_STORAGE");
if (dir_exists(sdcard_storage + "/base/")) {
base_path = sdcard_storage + "/base/";
}
else {
QString external_storage = getenv("EXTERNAL_STORAGE");
base_path = external_storage + "/base/";
}
#elif defined(__APPLE__)
base_path = applicationDirPath() + "/../../../base/";
#else
base_path = applicationDirPath() + "/base/";
#endif
return base_path;
}

VPath AOApplication::get_theme_path(QString p_file, QString p_theme)
{
if (p_theme == "")
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/aooptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void AOOptionsDialog::updateValues()

QSet<QString> themes;
QStringList bases = Options::getInstance().mountPaths();
bases.push_front(ao_app->get_base_path());
bases.push_front(get_base_path());
for (const QString &base : bases) {
QDirIterator it(base + "/themes", QDir::Dirs | QDir::NoDotAndDotDot,
QDirIterator::NoIteratorFlags);
Expand Down Expand Up @@ -475,7 +475,7 @@ void AOOptionsDialog::setupUI()
// Asset tab
FROM_UI(QListWidget, mount_list)
auto *defaultMount =
new QListWidgetItem(tr("%1 (default)").arg(ao_app->get_base_path()));
new QListWidgetItem(tr("%1 (default)").arg(get_base_path()));
defaultMount->setFlags(Qt::ItemFlag::NoItemFlags);
ui_mount_list->addItem(defaultMount);
registerOption<QListWidget, QStringList>("mount_list", &Options::mountPaths,
Expand Down