port DateTime

This commit is contained in:
Arisotura
2024-05-24 23:40:24 +02:00
parent 038f7a9171
commit b5996f5ab6
6 changed files with 15 additions and 9 deletions

View File

@ -78,8 +78,6 @@ int MPRecvTimeout;
std::string LANDevice; std::string LANDevice;
bool DirectLAN; bool DirectLAN;
int64_t RTCOffset;
bool DSBatteryLevelOkay; bool DSBatteryLevelOkay;
int DSiBatteryLevel; int DSiBatteryLevel;
bool DSiBatteryCharging; bool DSiBatteryCharging;

View File

@ -192,8 +192,6 @@ extern int MPRecvTimeout;
extern std::string LANDevice; extern std::string LANDevice;
extern bool DirectLAN; extern bool DirectLAN;
extern int64_t RTCOffset;
extern bool DSBatteryLevelOkay; extern bool DSBatteryLevelOkay;
extern int DSiBatteryLevel; extern int DSiBatteryLevel;
extern bool DSiBatteryCharging; extern bool DSiBatteryCharging;

View File

@ -20,6 +20,7 @@
#include "types.h" #include "types.h"
#include "Config.h" #include "Config.h"
#include "main.h"
#include "DateTimeDialog.h" #include "DateTimeDialog.h"
#include "ui_DateTimeDialog.h" #include "ui_DateTimeDialog.h"
@ -32,8 +33,11 @@ DateTimeDialog::DateTimeDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Da
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
emuInstance = ((MainWindow*)parent)->getEmuInstance();
auto& cfg = emuInstance->getLocalConfig();
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
customTime = now.addSecs(Config::RTCOffset); customTime = now.addSecs(cfg.GetInt64("RTC.Offset"));
ui->chkChangeTime->setChecked(false); ui->chkChangeTime->setChecked(false);
ui->chkResetTime->setChecked(false); ui->chkResetTime->setChecked(false);
@ -59,13 +63,15 @@ void DateTimeDialog::done(int r)
{ {
if (r == QDialog::Accepted) if (r == QDialog::Accepted)
{ {
auto& cfg = emuInstance->getLocalConfig();
if (ui->chkChangeTime->isChecked()) if (ui->chkChangeTime->isChecked())
{ {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
Config::RTCOffset = now.secsTo(ui->txtNewCustomTime->dateTime()); cfg.SetInt64("RTC.Offset", now.secsTo(ui->txtNewCustomTime->dateTime()));
} }
else if (ui->chkResetTime->isChecked()) else if (ui->chkResetTime->isChecked())
Config::RTCOffset = 0; cfg.SetInt64("RTC.Offset", 0);
Config::Save(); Config::Save();
} }

View File

@ -26,6 +26,8 @@
namespace Ui {class DateTimeDialog; } namespace Ui {class DateTimeDialog; }
class DateTimeDialog; class DateTimeDialog;
class EmuInstance;
class DateTimeDialog : public QDialog class DateTimeDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -63,6 +65,7 @@ private slots:
private: private:
Ui::DateTimeDialog* ui; Ui::DateTimeDialog* ui;
EmuInstance* emuInstance;
QDateTime customTime; QDateTime customTime;
}; };

View File

@ -925,7 +925,7 @@ void EmuInstance::setBatteryLevels()
void EmuInstance::setDateTime() void EmuInstance::setDateTime()
{ {
QDateTime hosttime = QDateTime::currentDateTime(); QDateTime hosttime = QDateTime::currentDateTime();
QDateTime time = hosttime.addSecs(Config::RTCOffset); QDateTime time = hosttime.addSecs(localCfg.GetInt64("RTC.Offset"));
nds->RTC.SetDateTime(time.date().year(), time.date().month(), time.date().day(), nds->RTC.SetDateTime(time.date().year(), time.date().month(), time.date().day(),
time.time().hour(), time.time().minute(), time.time().second()); time.time().hour(), time.time().minute(), time.time().second());

View File

@ -597,8 +597,9 @@ void WriteDateTime(int year, int month, int day, int hour, int minute, int secon
{ {
QDateTime hosttime = QDateTime::currentDateTime(); QDateTime hosttime = QDateTime::currentDateTime();
QDateTime time = QDateTime(QDate(year, month, day), QTime(hour, minute, second)); QDateTime time = QDateTime(QDate(year, month, day), QTime(hour, minute, second));
auto& cfg = testinst->getLocalConfig();
Config::RTCOffset = hosttime.secsTo(time); cfg.SetInt64("RTC.Offset", hosttime.secsTo(time));
Config::Save(); Config::Save();
} }