Merge pull request #3498 from wwylele/cfg-new-framework

Service/CFG: convert to ServiceFramework
This commit is contained in:
Weiyi Wang 2018-03-17 13:54:29 +02:00 committed by GitHub
commit 171cb4452f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 557 additions and 583 deletions

View file

@ -42,22 +42,16 @@ void ConfigureSystem::setConfiguration() {
enabled = !Core::System::GetInstance().IsPoweredOn();
if (!enabled) {
cfg = Service::CFG::GetCurrentModule();
ReadSystemSettings();
ui->group_system_settings->setEnabled(false);
} else {
// This tab is enabled only when game is not running (i.e. all service are not initialized).
// Temporarily register archive types and load the config savegame file to memory.
Service::FS::RegisterArchiveTypes();
ResultCode result = Service::CFG::LoadConfigNANDSaveFile();
cfg = std::make_shared<Service::CFG::Module>();
Service::FS::UnregisterArchiveTypes();
if (result.IsError()) {
ui->label_disable_info->setText(tr("Failed to load system settings data."));
ui->group_system_settings->setEnabled(false);
enabled = false;
return;
}
ReadSystemSettings();
ui->label_disable_info->hide();
}
@ -65,14 +59,14 @@ void ConfigureSystem::setConfiguration() {
void ConfigureSystem::ReadSystemSettings() {
// set username
username = Service::CFG::GetUsername();
username = cfg->GetUsername();
// TODO(wwylele): Use this when we move to Qt 5.5
// ui->edit_username->setText(QString::fromStdU16String(username));
ui->edit_username->setText(
QString::fromUtf16(reinterpret_cast<const ushort*>(username.data())));
// set birthday
std::tie(birthmonth, birthday) = Service::CFG::GetBirthday();
std::tie(birthmonth, birthday) = cfg->GetBirthday();
ui->combo_birthmonth->setCurrentIndex(birthmonth - 1);
updateBirthdayComboBox(
birthmonth -
@ -80,15 +74,15 @@ void ConfigureSystem::ReadSystemSettings() {
ui->combo_birthday->setCurrentIndex(birthday - 1);
// set system language
language_index = Service::CFG::GetSystemLanguage();
language_index = cfg->GetSystemLanguage();
ui->combo_language->setCurrentIndex(language_index);
// set sound output mode
sound_index = Service::CFG::GetSoundOutputMode();
sound_index = cfg->GetSoundOutputMode();
ui->combo_sound->setCurrentIndex(sound_index);
// set the console id
u64 console_id = Service::CFG::GetConsoleUniqueId();
u64 console_id = cfg->GetConsoleUniqueId();
ui->label_console_id->setText(
tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
}
@ -105,7 +99,7 @@ void ConfigureSystem::applyConfiguration() {
std::u16string new_username(
reinterpret_cast<const char16_t*>(ui->edit_username->text().utf16()));
if (new_username != username) {
Service::CFG::SetUsername(new_username);
cfg->SetUsername(new_username);
modified = true;
}
@ -113,27 +107,27 @@ void ConfigureSystem::applyConfiguration() {
int new_birthmonth = ui->combo_birthmonth->currentIndex() + 1;
int new_birthday = ui->combo_birthday->currentIndex() + 1;
if (birthmonth != new_birthmonth || birthday != new_birthday) {
Service::CFG::SetBirthday(new_birthmonth, new_birthday);
cfg->SetBirthday(new_birthmonth, new_birthday);
modified = true;
}
// apply language
int new_language = ui->combo_language->currentIndex();
if (language_index != new_language) {
Service::CFG::SetSystemLanguage(static_cast<Service::CFG::SystemLanguage>(new_language));
cfg->SetSystemLanguage(static_cast<Service::CFG::SystemLanguage>(new_language));
modified = true;
}
// apply sound
int new_sound = ui->combo_sound->currentIndex();
if (sound_index != new_sound) {
Service::CFG::SetSoundOutputMode(static_cast<Service::CFG::SoundOutputMode>(new_sound));
cfg->SetSoundOutputMode(static_cast<Service::CFG::SoundOutputMode>(new_sound));
modified = true;
}
// update the config savegame if any item is modified.
if (modified)
Service::CFG::UpdateConfigNANDSavegame();
cfg->UpdateConfigNANDSavegame();
}
void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) {
@ -173,9 +167,9 @@ void ConfigureSystem::refreshConsoleID() {
return;
u32 random_number;
u64 console_id;
Service::CFG::GenerateConsoleUniqueId(random_number, console_id);
Service::CFG::SetConsoleUniqueId(random_number, console_id);
Service::CFG::UpdateConfigNANDSavegame();
cfg->GenerateConsoleUniqueId(random_number, console_id);
cfg->SetConsoleUniqueId(random_number, console_id);
cfg->UpdateConfigNANDSavegame();
ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper());
}

View file

@ -11,6 +11,12 @@ namespace Ui {
class ConfigureSystem;
}
namespace Service {
namespace CFG {
class Module;
} // namespace CFG
} // namespace Service
class ConfigureSystem : public QWidget {
Q_OBJECT
@ -32,6 +38,7 @@ private:
std::unique_ptr<Ui::ConfigureSystem> ui;
bool enabled;
std::shared_ptr<Service::CFG::Module> cfg;
std::u16string username;
int birthmonth, birthday;
int language_index;