Skip to content

Commit

Permalink
add config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ElBread3 committed Oct 10, 2024
1 parent 712db04 commit 38128b2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static bool vkMarkers = false;
static bool vkCrashDiagnostic = false;
static s16 cursorState = HideCursorState::Idle;
static int cursorHideTimeout = 5; // 5 seconds (default)
static bool separateupdatefolder = false;

// Gui
std::vector<std::filesystem::path> settings_install_dirs = {};
Expand Down Expand Up @@ -207,6 +208,10 @@ bool vkCrashDiagnosticEnabled() {
return vkCrashDiagnostic;
}

bool getSeparateUpdateEnabled() {
return separateupdatefolder;
}

void setGpuId(s32 selectedGpuId) {
gpuId = selectedGpuId;
}
Expand Down Expand Up @@ -319,6 +324,10 @@ void setSpecialPadClass(int type) {
specialPadClass = type;
}

void setSeparateUpdateEnabled(bool use) {
separateupdatefolder = use;
}

void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
main_window_geometry_x = x;
main_window_geometry_y = y;
Expand Down Expand Up @@ -473,6 +482,7 @@ void load(const std::filesystem::path& path) {
}
isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
separateupdatefolder = toml::find_or<bool>(general, "separateUpdateEnabled", false);
}

if (data.contains("Input")) {
Expand Down Expand Up @@ -592,6 +602,7 @@ void save(const std::filesystem::path& path) {
data["General"]["updateChannel"] = updateChannel;
data["General"]["showSplash"] = isShowSplash;
data["General"]["autoUpdate"] = isAutoUpdate;
data["General"]["separateUpdateEnabled"] = separateupdatefolder;
data["Input"]["cursorState"] = cursorState;
data["Input"]["cursorHideTimeout"] = cursorHideTimeout;
data["Input"]["backButtonBehavior"] = backButtonBehavior;
Expand Down
2 changes: 2 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bool isFullscreenMode();
bool getPlayBGM();
int getBGMvolume();
bool getEnableDiscordRPC();
bool getSeparateUpdateEnabled();

std::string getLogFilter();
std::string getLogType();
Expand Down Expand Up @@ -62,6 +63,7 @@ void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type);
void setSeparateUpdateEnabled(bool use);

void setCursorState(s16 cursorState);
void setCursorHideTimeout(int newcursorHideTimeout);
Expand Down
3 changes: 2 additions & 1 deletion src/core/file_sys/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <algorithm>
#include "common/config.h"
#include "common/string_util.h"
#include "core/file_sys/fs.h"

Expand Down Expand Up @@ -56,7 +57,7 @@ std::filesystem::path MntPoints::GetHostPath(std::string_view guest_directory, b
std::filesystem::path host_path = mount->host_path / rel_path;

std::filesystem::path patch_path = mount->host_path.string() + "-UPDATE";
if (std::filesystem::exists(patch_path / rel_path)) {
if (std::filesystem::exists(patch_path / rel_path) && Config::getSeparateUpdateEnabled()) {
host_path = patch_path / rel_path;
}

Expand Down
7 changes: 4 additions & 3 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ void Emulator::Run(const std::filesystem::path& file) {
u32 fw_version;

std::filesystem::path game_patch_folder = file.parent_path().concat("-UPDATE");
std::filesystem::path sce_sys_folder = std::filesystem::exists(game_patch_folder / "sce_sys")
? game_patch_folder / "sce_sys"
: file.parent_path() / "sce_sys";
bool use_game_patch = std::filesystem::exists(game_patch_folder / "sce_sys") &&
Config::getSeparateUpdateEnabled();
std::filesystem::path sce_sys_folder =
use_game_patch ? game_patch_folder / "sce_sys" : file.parent_path() / "sce_sys";
if (std::filesystem::is_directory(sce_sys_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_sys_folder)) {
if (entry.path().filename() == "param.sfo") {
Expand Down
3 changes: 2 additions & 1 deletion src/qt_gui/game_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class GameInfoClass : public QObject {
std::filesystem::path sce_folder_path = filePath / "sce_sys" / "param.sfo";
std::filesystem::path game_update_path =
std::filesystem::path(filePath.string() + "-UPDATE");
if (std::filesystem::exists(game_update_path / "sce_sys" / "param.sfo")) {
if (std::filesystem::exists(game_update_path / "sce_sys" / "param.sfo") &&
Config::getSeparateUpdateEnabled()) {
sce_folder_path = game_update_path / "sce_sys" / "param.sfo";
}

Expand Down
9 changes: 8 additions & 1 deletion src/qt_gui/gui_context_menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,14 @@ class GuiContextMenus : public QObject {
Common::FS::PathToQString(game_update_path, m_games[itemID].path.concat("-UPDATE"));
QString message_type = tr("Game");
if (selected == deleteUpdate) {
if (!std::filesystem::exists(m_games[itemID].path.concat("-UPDATE"))) {
if (!Config::getSeparateUpdateEnabled()) {
QMessageBox::critical(
nullptr, tr("Error"),
QString(tr("This feature requires the 'Enable Separate Update Folder' "
"config option "
"to work. If you want to use this feature, please enable it.")));
error = true;
} else if (!std::filesystem::exists(m_games[itemID].path.concat("-UPDATE"))) {
QMessageBox::critical(nullptr, tr("Error"),
QString(tr("This game has no update to delete!")));
error = true;
Expand Down
8 changes: 4 additions & 4 deletions src/qt_gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int
auto game_install_dir = ids.getSelectedDirectory();
auto game_folder_path = game_install_dir / pkg.GetTitleID();
QString pkgType = QString::fromStdString(pkg.GetPkgFlags());
auto game_update_path =
pkgType.contains("Patch")
? Config::getGameInstallDir() / (std::string(pkg.GetTitleID()) + "-UPDATE")
: game_folder_path;
bool use_game_update = pkgType.contains("Patch") && Config::getSeparateUpdateEnabled();
auto game_update_path = use_game_update ? Config::getGameInstallDir() /
(std::string(pkg.GetTitleID()) + "-UPDATE")
: game_folder_path;
if (!std::filesystem::exists(game_update_path)) {
std::filesystem::create_directory(game_update_path);
}
Expand Down
7 changes: 7 additions & 0 deletions src/qt_gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
connect(ui->ps4proCheckBox, &QCheckBox::stateChanged, this,
[](int val) { Config::setNeoMode(val); });

connect(ui->separateUpdatesCheckBox, &QCheckBox::stateChanged, this,
[](int val) { Config::setSeparateUpdateEnabled(val); });

connect(ui->logTypeComboBox, &QComboBox::currentTextChanged, this,
[](const QString& text) { Config::setLogType(text.toStdString()); });

Expand Down Expand Up @@ -284,6 +287,7 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
ui->fullscreenCheckBox->installEventFilter(this);
ui->showSplashCheckBox->installEventFilter(this);
ui->ps4proCheckBox->installEventFilter(this);
ui->separateUpdatesCheckBox->installEventFilter(this);
ui->userName->installEventFilter(this);
ui->logTypeGroupBox->installEventFilter(this);
ui->logFilter->installEventFilter(this);
Expand Down Expand Up @@ -343,6 +347,7 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->logTypeComboBox->setCurrentText(QString::fromStdString(Config::getLogType()));
ui->logFilterLineEdit->setText(QString::fromStdString(Config::getLogFilter()));
ui->userNameLineEdit->setText(QString::fromStdString(Config::getUserName()));
ui->separateUpdatesCheckBox->setChecked(Config::getSeparateUpdateEnabled());

ui->debugDump->setChecked(Config::debugDump());
ui->vkValidationCheckBox->setChecked(Config::vkValidationEnabled());
Expand Down Expand Up @@ -433,6 +438,8 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) {
text = tr("showSplashCheckBox");
} else if (elementName == "ps4proCheckBox") {
text = tr("ps4proCheckBox");
} else if (elementName == "separateUpdatesCheckBox") {
text = tr("separateUpdatesCheckBox");
} else if (elementName == "userName") {
text = tr("userName");
} else if (elementName == "logTypeGroupBox") {
Expand Down
7 changes: 7 additions & 0 deletions src/qt_gui/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="separateUpdatesCheckBox">
<property name="text">
<string>Enable Separate Update Folder</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showSplashCheckBox">
<property name="text">
Expand Down

0 comments on commit 38128b2

Please sign in to comment.