port FirmwareSettings

This commit is contained in:
Arisotura 2024-05-25 00:08:02 +02:00
parent b5996f5ab6
commit 449d3b342a
6 changed files with 82 additions and 75 deletions

View File

@ -62,16 +62,6 @@ int GL_ScaleFactor;
bool GL_BetterPolygons; bool GL_BetterPolygons;
bool GL_HiresCoordinates; bool GL_HiresCoordinates;
bool FirmwareOverrideSettings;
std::string FirmwareUsername;
int FirmwareLanguage;
int FirmwareBirthdayMonth;
int FirmwareBirthdayDay;
int FirmwareFavouriteColour;
std::string FirmwareMessage;
std::string FirmwareMAC;
std::string WifiSettingsPath = "wfcsettings.bin"; // Should this be configurable?
int MPAudioMode; int MPAudioMode;
int MPRecvTimeout; int MPRecvTimeout;

View File

@ -176,16 +176,6 @@ extern int GL_ScaleFactor;
extern bool GL_BetterPolygons; extern bool GL_BetterPolygons;
extern bool GL_HiresCoordinates; extern bool GL_HiresCoordinates;
extern bool FirmwareOverrideSettings;
extern std::string FirmwareUsername;
extern int FirmwareLanguage;
extern int FirmwareBirthdayMonth;
extern int FirmwareBirthdayDay;
extern int FirmwareFavouriteColour;
extern std::string FirmwareMessage;
extern std::string FirmwareMAC;
//extern std::string WifiSettingsPath;
extern int MPAudioMode; extern int MPAudioMode;
extern int MPRecvTimeout; extern int MPRecvTimeout;

View File

@ -777,7 +777,7 @@ std::optional<Firmware> EmuInstance::loadFirmware(int type) noexcept
return std::nullopt; return std::nullopt;
} }
customizeFirmware(firmware, Config::FirmwareOverrideSettings); customizeFirmware(firmware, localCfg.GetBool("Firmware.OverrideSettings"));
return firmware; return firmware;
} }
@ -816,29 +816,31 @@ std::optional<DSi_NAND::NANDImage> EmuInstance::loadNAND(const std::array<u8, DS
} }
// override user settings, if needed // override user settings, if needed
if (Config::FirmwareOverrideSettings) if (localCfg.GetBool("Firmware.OverrideSettings"))
{ {
auto firmcfg = localCfg.GetTable("Firmware");
// we store relevant strings as UTF-8, so we need to convert them to UTF-16 // we store relevant strings as UTF-8, so we need to convert them to UTF-16
auto converter = wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}; auto converter = wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{};
// setting up username // setting up username
std::u16string username = converter.from_bytes(Config::FirmwareUsername); std::u16string username = converter.from_bytes(firmcfg.GetString("Username"));
size_t usernameLength = std::min(username.length(), (size_t) 10); size_t usernameLength = std::min(username.length(), (size_t) 10);
memset(&settings.Nickname, 0, sizeof(settings.Nickname)); memset(&settings.Nickname, 0, sizeof(settings.Nickname));
memcpy(&settings.Nickname, username.data(), usernameLength * sizeof(char16_t)); memcpy(&settings.Nickname, username.data(), usernameLength * sizeof(char16_t));
// setting language // setting language
settings.Language = static_cast<Firmware::Language>(Config::FirmwareLanguage); settings.Language = static_cast<Firmware::Language>(firmcfg.GetInt("Language"));
// setting up color // setting up color
settings.FavoriteColor = Config::FirmwareFavouriteColour; settings.FavoriteColor = firmcfg.GetInt("FavouriteColour");
// setting up birthday // setting up birthday
settings.BirthdayMonth = Config::FirmwareBirthdayMonth; settings.BirthdayMonth = firmcfg.GetInt("BirthdayMonth");
settings.BirthdayDay = Config::FirmwareBirthdayDay; settings.BirthdayDay = firmcfg.GetInt("BirthdayDay");
// setup message // setup message
std::u16string message = converter.from_bytes(Config::FirmwareMessage); std::u16string message = converter.from_bytes(firmcfg.GetString("Message"));
size_t messageLength = std::min(message.length(), (size_t) 26); size_t messageLength = std::min(message.length(), (size_t) 26);
memset(&settings.Message, 0, sizeof(settings.Message)); memset(&settings.Message, 0, sizeof(settings.Message));
memcpy(&settings.Message, message.data(), messageLength * sizeof(char16_t)); memcpy(&settings.Message, message.data(), messageLength * sizeof(char16_t));
@ -1328,7 +1330,7 @@ pair<unique_ptr<Firmware>, string> EmuInstance::generateDefaultFirmware()
bool EmuInstance::parseMacAddress(void* data) bool EmuInstance::parseMacAddress(void* data)
{ {
const std::string& mac_in = Config::FirmwareMAC; const std::string mac_in = localCfg.GetString("Firmware.MAC");
u8* mac_out = (u8*)data; u8* mac_out = (u8*)data;
int o = 0; int o = 0;
@ -1362,8 +1364,10 @@ void EmuInstance::customizeFirmware(Firmware& firmware, bool overridesettings) n
{ {
auto &currentData = firmware.GetEffectiveUserData(); auto &currentData = firmware.GetEffectiveUserData();
auto firmcfg = localCfg.GetTable("Firmware");
// setting up username // setting up username
std::string orig_username = Config::FirmwareUsername; std::string orig_username = firmcfg.GetString("Username");
if (!orig_username.empty()) if (!orig_username.empty())
{ // If the frontend defines a username, take it. If not, leave the existing one. { // If the frontend defines a username, take it. If not, leave the existing one.
std::u16string username = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes( std::u16string username = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(
@ -1373,7 +1377,7 @@ void EmuInstance::customizeFirmware(Firmware& firmware, bool overridesettings) n
memcpy(currentData.Nickname, username.data(), usernameLength * sizeof(char16_t)); memcpy(currentData.Nickname, username.data(), usernameLength * sizeof(char16_t));
} }
auto language = static_cast<Firmware::Language>(Config::FirmwareLanguage); auto language = static_cast<Firmware::Language>(firmcfg.GetInt("Language"));
if (language != Firmware::Language::Reserved) if (language != Firmware::Language::Reserved)
{ // If the frontend specifies a language (rather than using the existing value)... { // If the frontend specifies a language (rather than using the existing value)...
currentData.Settings &= ~Firmware::Language::Reserved; // ..clear the existing language... currentData.Settings &= ~Firmware::Language::Reserved; // ..clear the existing language...
@ -1381,26 +1385,26 @@ void EmuInstance::customizeFirmware(Firmware& firmware, bool overridesettings) n
} }
// setting up color // setting up color
u8 favoritecolor = Config::FirmwareFavouriteColour; u8 favoritecolor = firmcfg.GetInt("FavouriteColour");
if (favoritecolor != 0xFF) if (favoritecolor != 0xFF)
{ {
currentData.FavoriteColor = favoritecolor; currentData.FavoriteColor = favoritecolor;
} }
u8 birthmonth = Config::FirmwareBirthdayMonth; u8 birthmonth = firmcfg.GetInt("BirthdayMonth");
if (birthmonth != 0) if (birthmonth != 0)
{ // If the frontend specifies a birth month (rather than using the existing value)... { // If the frontend specifies a birth month (rather than using the existing value)...
currentData.BirthdayMonth = birthmonth; currentData.BirthdayMonth = birthmonth;
} }
u8 birthday = Config::FirmwareBirthdayDay; u8 birthday = firmcfg.GetInt("BirthdayDay");
if (birthday != 0) if (birthday != 0)
{ // If the frontend specifies a birthday (rather than using the existing value)... { // If the frontend specifies a birthday (rather than using the existing value)...
currentData.BirthdayDay = birthday; currentData.BirthdayDay = birthday;
} }
// setup message // setup message
std::string orig_message = Config::FirmwareMessage; std::string orig_message = firmcfg.GetString("Message");
if (!orig_message.empty()) if (!orig_message.empty())
{ {
std::u16string message = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes( std::u16string message = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(

View File

@ -20,6 +20,7 @@
#include "Platform.h" #include "Platform.h"
#include "Config.h" #include "Config.h"
#include "main.h"
#include "FirmwareSettingsDialog.h" #include "FirmwareSettingsDialog.h"
#include "ui_FirmwareSettingsDialog.h" #include "ui_FirmwareSettingsDialog.h"
@ -38,10 +39,15 @@ FirmwareSettingsDialog::FirmwareSettingsDialog(QWidget* parent) : QDialog(parent
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
ui->usernameEdit->setText(QString::fromStdString(Config::FirmwareUsername)); emuInstance = ((MainWindow*)parent)->getEmuInstance();
auto& cfg = emuInstance->getLocalConfig();
auto firmcfg = cfg.GetTable("Firmware");
ui->usernameEdit->setText(firmcfg.GetQString("Username"));
ui->languageBox->addItems(languages); ui->languageBox->addItems(languages);
ui->languageBox->setCurrentIndex(Config::FirmwareLanguage); ui->languageBox->setCurrentIndex(firmcfg.GetInt("Language"));
for (int i = 1; i <= 31; i++) for (int i = 1; i <= 31; i++)
{ {
@ -49,9 +55,9 @@ FirmwareSettingsDialog::FirmwareSettingsDialog(QWidget* parent) : QDialog(parent
} }
ui->cbxBirthdayMonth->addItems(months); ui->cbxBirthdayMonth->addItems(months);
ui->cbxBirthdayMonth->setCurrentIndex(Config::FirmwareBirthdayMonth - 1); ui->cbxBirthdayMonth->setCurrentIndex(firmcfg.GetInt("BirthdayMonth") - 1);
ui->cbxBirthdayDay->setCurrentIndex(Config::FirmwareBirthdayDay - 1); ui->cbxBirthdayDay->setCurrentIndex(firmcfg.GetInt("BirthdayDay") - 1);
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
@ -60,21 +66,31 @@ FirmwareSettingsDialog::FirmwareSettingsDialog(QWidget* parent) : QDialog(parent
QIcon icon(QPixmap::fromImage(image.copy())); QIcon icon(QPixmap::fromImage(image.copy()));
ui->colorsEdit->addItem(icon, colornames[i]); ui->colorsEdit->addItem(icon, colornames[i]);
} }
ui->colorsEdit->setCurrentIndex(Config::FirmwareFavouriteColour); ui->colorsEdit->setCurrentIndex(firmcfg.GetInt("FavouriteColour"));
ui->messageEdit->setText(QString::fromStdString(Config::FirmwareMessage)); ui->messageEdit->setText(firmcfg.GetQString("Message"));
ui->overrideFirmwareBox->setChecked(Config::FirmwareOverrideSettings); ui->overrideFirmwareBox->setChecked(firmcfg.GetBool("OverrideSettings"));
ui->txtMAC->setText(QString::fromStdString(Config::FirmwareMAC)); ui->txtMAC->setText(firmcfg.GetQString("MAC"));
on_overrideFirmwareBox_toggled(); on_overrideFirmwareBox_toggled();
int inst = Platform::InstanceID(); int inst = emuInstance->getInstanceID();
if (inst > 0) if (inst > 0)
ui->lblInstanceNum->setText(QString("Configuring settings for instance %1").arg(inst+1)); ui->lblInstanceNum->setText(QString("Configuring settings for instance %1").arg(inst+1));
else else
ui->lblInstanceNum->hide(); ui->lblInstanceNum->hide();
#define SET_ORIGVAL(type, val) \
for (type* w : findChildren<type*>(nullptr)) \
w->setProperty("user_originalValue", w->val());
SET_ORIGVAL(QLineEdit, text);
SET_ORIGVAL(QComboBox, currentIndex);
SET_ORIGVAL(QCheckBox, isChecked);
#undef SET_ORIGVAL
} }
FirmwareSettingsDialog::~FirmwareSettingsDialog() FirmwareSettingsDialog::~FirmwareSettingsDialog()
@ -132,25 +148,26 @@ void FirmwareSettingsDialog::done(int r)
return; return;
} }
bool newOverride = ui->overrideFirmwareBox->isChecked(); bool modified = false;
std::string newName = ui->usernameEdit->text().toStdString(); #define CHECK_ORIGVAL(type, val) \
int newLanguage = ui->languageBox->currentIndex(); if (!modified) for (type* w : findChildren<type*>(nullptr)) \
int newFavColor = ui->colorsEdit->currentIndex(); { \
int newBirthdayDay = ui->cbxBirthdayDay->currentIndex() + 1; QVariant v = w->val(); \
int newBirthdayMonth = ui->cbxBirthdayMonth->currentIndex() + 1; if (v != w->property("user_originalValue")) \
std::string newMessage = ui->messageEdit->text().toStdString(); { \
modified = true; \
break; \
}\
}
std::string newMAC = ui->txtMAC->text().toStdString(); CHECK_ORIGVAL(QLineEdit, text);
CHECK_ORIGVAL(QComboBox, currentIndex);
CHECK_ORIGVAL(QCheckBox, isChecked);
if ( newOverride != Config::FirmwareOverrideSettings #undef CHECK_ORIGVAL
|| newName != Config::FirmwareUsername
|| newLanguage != Config::FirmwareLanguage if (modified)
|| newFavColor != Config::FirmwareFavouriteColour
|| newBirthdayDay != Config::FirmwareBirthdayDay
|| newBirthdayMonth != Config::FirmwareBirthdayMonth
|| newMessage != Config::FirmwareMessage
|| newMAC != Config::FirmwareMAC)
{ {
if (RunningSomething if (RunningSomething
&& QMessageBox::warning(this, "Reset necessary to apply changes", && QMessageBox::warning(this, "Reset necessary to apply changes",
@ -158,16 +175,19 @@ void FirmwareSettingsDialog::done(int r)
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
return; return;
Config::FirmwareOverrideSettings = newOverride; auto& cfg = emuInstance->getLocalConfig();
auto firmcfg = cfg.GetTable("Firmware");
Config::FirmwareUsername = newName; firmcfg.SetBool("OverrideSettings", ui->overrideFirmwareBox->isChecked());
Config::FirmwareLanguage = newLanguage;
Config::FirmwareFavouriteColour = newFavColor;
Config::FirmwareBirthdayDay = newBirthdayDay;
Config::FirmwareBirthdayMonth = newBirthdayMonth;
Config::FirmwareMessage = newMessage;
Config::FirmwareMAC = newMAC; firmcfg.SetQString("Username", ui->usernameEdit->text());
firmcfg.SetInt("Language", ui->languageBox->currentIndex());
firmcfg.SetInt("FavouriteColour", ui->colorsEdit->currentIndex());
firmcfg.SetInt("BirthdayDay", ui->cbxBirthdayDay->currentIndex() + 1);
firmcfg.SetInt("BirthdayMonth", ui->cbxBirthdayMonth->currentIndex() + 1);
firmcfg.SetQString("Message", ui->messageEdit->text());
firmcfg.SetQString("MAC", ui->txtMAC->text());
Config::Save(); Config::Save();

View File

@ -25,6 +25,8 @@
namespace Ui { class FirmwareSettingsDialog; } namespace Ui { class FirmwareSettingsDialog; }
class FirmwareSettingsDialog; class FirmwareSettingsDialog;
class EmuInstance;
class FirmwareSettingsDialog : public QDialog class FirmwareSettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -129,6 +131,7 @@ private:
bool verifyMAC(); bool verifyMAC();
Ui::FirmwareSettingsDialog* ui; Ui::FirmwareSettingsDialog* ui;
EmuInstance* emuInstance;
}; };
#endif // FIRMWARESETTINGSDIALOG_H #endif // FIRMWARESETTINGSDIALOG_H

View File

@ -600,7 +600,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
resize(Config::WindowWidth, Config::WindowHeight); resize(Config::WindowWidth, Config::WindowHeight);
if (Config::FirmwareUsername == "Arisotura") if (localCfg.GetString("Firmware.Username") == "Arisotura")
actMPNewInstance->setText("Fart"); actMPNewInstance->setText("Fart");
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -620,7 +620,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actEjectCart->setEnabled(false); actEjectCart->setEnabled(false);
actEjectGBACart->setEnabled(false); actEjectGBACart->setEnabled(false);
if (emuInstance->globalCfg.GetInt("Emu.ConsoleType") == 1) if (globalCfg.GetInt("Emu.ConsoleType") == 1)
{ {
actInsertGBACart->setEnabled(false); actInsertGBACart->setEnabled(false);
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
@ -644,7 +644,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actPowerManagement->setEnabled(false); actPowerManagement->setEnabled(false);
actSetupCheats->setEnabled(false); actSetupCheats->setEnabled(false);
actTitleManager->setEnabled(!emuInstance->globalCfg.GetString("DSi.NANDPath").empty()); actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());
actEnableCheats->setChecked(localCfg.GetBool("EnableCheats")); actEnableCheats->setChecked(localCfg.GetBool("EnableCheats"));
@ -1168,7 +1168,7 @@ void MainWindow::updateCartInserted(bool gba)
bool inserted; bool inserted;
if (gba) if (gba)
{ {
inserted = emuInstance->gbaCartInserted() && (emuInstance->globalCfg.GetInt("Emu.ConsoleType") == 0); inserted = emuInstance->gbaCartInserted() && (globalCfg.GetInt("Emu.ConsoleType") == 0);
actCurrentGBACart->setText("GBA slot: " + emuInstance->gbaCartLabel()); actCurrentGBACart->setText("GBA slot: " + emuInstance->gbaCartLabel());
actEjectGBACart->setEnabled(inserted); actEjectGBACart->setEnabled(inserted);
} }
@ -1702,7 +1702,7 @@ void MainWindow::onEmuSettingsDialogFinished(int res)
{ {
emuThread->emuUnpause(); emuThread->emuUnpause();
if (emuInstance->globalCfg.GetInt("Emu.ConsoleType") == 1) if (globalCfg.GetInt("Emu.ConsoleType") == 1)
{ {
actInsertGBACart->setEnabled(false); actInsertGBACart->setEnabled(false);
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
@ -1723,7 +1723,7 @@ void MainWindow::onEmuSettingsDialogFinished(int res)
actCurrentGBACart->setText("GBA slot: " + emuInstance->gbaCartLabel()); actCurrentGBACart->setText("GBA slot: " + emuInstance->gbaCartLabel());
if (!RunningSomething) if (!RunningSomething)
actTitleManager->setEnabled(!emuInstance->globalCfg.GetString("DSi.NANDPath").empty()); actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());
} }
void MainWindow::onOpenInputConfig() void MainWindow::onOpenInputConfig()
@ -2090,7 +2090,7 @@ void MainWindow::onEmuStop()
actDateTime->setEnabled(true); actDateTime->setEnabled(true);
actPowerManagement->setEnabled(false); actPowerManagement->setEnabled(false);
actTitleManager->setEnabled(!emuInstance->globalCfg.GetString("DSi.NANDPath").empty()); actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());
} }
void MainWindow::onUpdateVideoSettings(bool glchange) void MainWindow::onUpdateVideoSettings(bool glchange)