Fix homebrew launching, add user menu

This commit is contained in:
XorTroll 2019-10-25 23:31:09 +02:00
parent 6c6148a2b1
commit d6241ac9c9
5 changed files with 126 additions and 35 deletions

View file

@ -16,6 +16,7 @@ namespace ui
void SetStartMode(am::QMenuStartMode mode);
void LoadMenu();
void LoadStartupMenu();
bool IsSuspended();
bool IsTitleSuspended();

View file

@ -38,6 +38,7 @@ namespace qmenu
fs::CreateDirectory(Q_BASE_SD_DIR);
fs::CreateDirectory(Q_ENTRIES_PATH);
fs::CreateDirectory(Q_THEMES_PATH);
fs::CreateDirectory(Q_BASE_DB_DIR "/user");
fs::CreateDirectory(Q_BASE_SD_DIR "/title");
fs::CreateDirectory(Q_BASE_SD_DIR "/user");
fs::CreateDirectory(Q_BASE_SD_DIR "/nro");

View file

@ -618,8 +618,15 @@ namespace ui
void MenuLayout::HandleHomebrewLaunch(cfg::TitleRecord &rec)
{
int sopt = qapp->CreateShowDialog("Homebrew launch", "How would you like to launch this homebrew?\n\nNOTE: Launching as application might involve BAN RISK, so use it at your own risk!", { "Applet", "Application", "Cancel" }, true);
if(sopt == 0)
u32 launchmode = 0;
if(config.system_title_override_enabled)
{
auto sopt = qapp->CreateShowDialog("Homebrew launch", "How would you like to launch this homebrew?\n\nNOTE: Launching as application might involve BAN RISK, so use it at your own risk!", { "Applet", "Application", "Cancel" }, true);
if(sopt == 0) launchmode = 1;
else if(sopt == 1) launchmode = 2;
}
else launchmode = 1;
if(launchmode == 1)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewLibApplet);
writer.Write<hb::TargetInput>(rec.nro_target);
@ -630,36 +637,123 @@ namespace ui
qapp->CloseWithFadeOut();
return;
}
else if(sopt == 1)
else if(launchmode == 2)
{
if(config.system_title_override_enabled)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewApplication);
writer.Write<hb::TargetInput>(rec.nro_target);
writer.FinishWrite();
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewApplication);
writer.Write<hb::TargetInput>(rec.nro_target);
writer.FinishWrite();
am::QMenuCommandResultReader reader;
if(reader && R_SUCCEEDED(reader.GetReadResult()))
{
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else
{
auto rc = reader.GetReadResult();
qapp->CreateShowDialog("Title launch", "An error ocurred attempting to launch the title:\n" + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
reader.FinishRead();
am::QMenuCommandResultReader reader;
if(reader && R_SUCCEEDED(reader.GetReadResult()))
{
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else qapp->CreateShowDialog("Title launch", "System title launching (via flog) is disabled.\nYou can enable it in settings.\n\nNote that this system (unlike title override) could involve ban risk!\nUse it at your own risk.", { "Ok" }, true);
else
{
auto rc = reader.GetReadResult();
qapp->CreateShowDialog("Title launch", "An error ocurred attempting to launch the title:\n" + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
reader.FinishRead();
}
}
void MenuLayout::HandleUserMenu()
{
qapp->CreateShowDialog("Users", "Users", {"Ok"}, true);
auto uid = qapp->GetSelectedUser();
auto [rc, pass] = db::AccessPassword(uid);
bool has_pass = R_SUCCEEDED(rc);
auto [_rc, name] = os::GetAccountName(uid);
auto sopt = qapp->CreateShowDialog("User settings", "Selected user: " + name + "\nWhat would you like to do with this user?", { has_pass ? "Change password" : "Register password", "Log off", "Cancel" }, true, os::GetIconCacheImagePath(uid));
if(sopt == 0)
{
if(has_pass)
{
auto sopt = qapp->CreateShowDialog("Change password", "What would you like to do with the password?", { "Change", "Remove", "Cancel" }, true);
if((sopt == 0) || (sopt == 1))
{
SwkbdConfig swkbd;
swkbdCreate(&swkbd, 0);
swkbdConfigMakePresetPassword(&swkbd);
swkbdConfigSetStringLenMax(&swkbd, 15);
swkbdConfigSetGuideText(&swkbd, "User password");
swkbdConfigSetHeaderText(&swkbd, "Input user password");
char inpass[0x10] = {0};
auto rc = swkbdShow(&swkbd, inpass, 0x10);
swkbdClose(&swkbd);
if(R_SUCCEEDED(rc))
{
auto rc = db::TryLogUser(qapp->GetSelectedUser(), std::string(inpass));
if(R_FAILED(rc)) qapp->CreateShowDialog("Login", "An invalid password was given.", {"Ok"}, true);
else
{
if(sopt == 0)
{
SwkbdConfig swkbd;
swkbdCreate(&swkbd, 0);
swkbdConfigMakePresetPassword(&swkbd);
swkbdConfigSetStringLenMax(&swkbd, 15);
swkbdConfigSetHeaderText(&swkbd, "Enter new password");
char pass[0x10] = {0};
auto rc = swkbdShow(&swkbd, pass, 0x10);
swkbdClose(&swkbd);
if(R_SUCCEEDED(rc))
{
auto sopt2 = qapp->CreateShowDialog("Change password", "Would you like to change the password?", { "Yes", "Cancel" }, true);
if(sopt2 == 0)
{
auto passfile = db::GetUserPasswordFilePath(qapp->GetSelectedUser());
fs::DeleteFile(passfile);
rc = db::RegisterUserPassword(qapp->GetSelectedUser(), pass);
qapp->CreateShowDialog("Change password", R_SUCCEEDED(rc) ? "The password was successfully changed." : "An error ocurred while attempting to change the password: " + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
}
}
else if(sopt == 1)
{
auto sopt2 = qapp->CreateShowDialog("Remove password", "Would you really like to remove the password?", { "Yes", "Cancel" }, true);
if(sopt2 == 0)
{
auto passfile = db::GetUserPasswordFilePath(qapp->GetSelectedUser());
fs::DeleteFile(passfile);
qapp->CreateShowDialog("Remove password", "The user's password was removed.", { "Ok" }, true);
}
}
}
}
}
}
else
{
SwkbdConfig swkbd;
swkbdCreate(&swkbd, 0);
swkbdConfigMakePresetPassword(&swkbd);
swkbdConfigSetStringLenMax(&swkbd, 15);
swkbdConfigSetHeaderText(&swkbd, "Enter password");
char pass[0x10] = {0};
auto rc = swkbdShow(&swkbd, pass, 0x10);
swkbdClose(&swkbd);
if(R_SUCCEEDED(rc))
{
auto sopt = qapp->CreateShowDialog("Register password", "Would you like to register this password?", { "Yes", "Cancel" }, true);
if(sopt == 0)
{
rc = db::RegisterUserPassword(qapp->GetSelectedUser(), pass);
qapp->CreateShowDialog("Register password", R_SUCCEEDED(rc) ? "The password was successfully registered." : "An error ocurred while attempting to register the password: " + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
}
}
}
else if(sopt == 1)
{
qapp->FadeOut();
qapp->LoadStartupMenu();
qapp->FadeIn();
}
}
void MenuLayout::HandleWebPageOpen()

View file

@ -74,6 +74,12 @@ namespace ui
this->StartPlayBGM();
}
void QMenuApplication::LoadStartupMenu()
{
this->StopPlayBGM();
this->LoadLayout(this->startupLayout);
}
bool QMenuApplication::IsSuspended()
{
return (this->IsTitleSuspended() || this->IsHomebrewSuspended());

View file

@ -54,17 +54,6 @@ namespace ui
this->usersMenu->SetVisible(false);
this->infoText->SetText("Unable to obtain system accounts. Hold power to power off or reboot the console.");
}
this->SetOnInput([&](u64 down, u64 up, u64 held, pu::ui::Touch pos)
{
if(down & KEY_X)
{
fs::DeleteDirectory(Q_BASE_DB_DIR "/user");
fs::CreateDirectory(Q_BASE_DB_DIR "/user");
auto rc = db::RegisterUserPassword(this->userlist[0], "xor");
qapp->CreateShowDialog("Re-register", "0x" + util::FormatApplicationId(rc), {"Ok"}, true);
}
});
this->Add(this->usersMenu);
}