2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-11-23 03:02:36 +01:00
|
|
|
|
|
|
|
#include <cstring>
|
2018-11-23 17:00:33 +01:00
|
|
|
|
2018-11-23 03:02:36 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/string_util.h"
|
|
|
|
#include "core/core.h"
|
2018-12-24 22:22:07 +01:00
|
|
|
#include "core/frontend/applets/profile_select.h"
|
2018-11-23 03:02:36 +01:00
|
|
|
#include "core/hle/service/am/am.h"
|
2021-07-14 06:38:24 +02:00
|
|
|
#include "core/hle/service/am/applets/applet_profile_select.h"
|
2018-11-23 03:02:36 +01:00
|
|
|
|
|
|
|
namespace Service::AM::Applets {
|
|
|
|
|
|
|
|
constexpr ResultCode ERR_USER_CANCELLED_SELECTION{ErrorModule::Account, 1};
|
|
|
|
|
2021-02-06 08:31:13 +01:00
|
|
|
ProfileSelect::ProfileSelect(Core::System& system_, LibraryAppletMode applet_mode_,
|
2019-07-11 06:53:55 +02:00
|
|
|
const Core::Frontend::ProfileSelectApplet& frontend_)
|
2021-04-17 15:19:02 +02:00
|
|
|
: Applet{system_, applet_mode_}, frontend{frontend_}, system{system_} {}
|
2019-03-12 00:35:01 +01:00
|
|
|
|
2018-11-23 03:02:36 +01:00
|
|
|
ProfileSelect::~ProfileSelect() = default;
|
|
|
|
|
|
|
|
void ProfileSelect::Initialize() {
|
|
|
|
complete = false;
|
2021-05-21 07:05:04 +02:00
|
|
|
status = ResultSuccess;
|
2018-11-23 03:02:36 +01:00
|
|
|
final_data.clear();
|
|
|
|
|
|
|
|
Applet::Initialize();
|
|
|
|
|
|
|
|
const auto user_config_storage = broker.PopNormalDataToApplet();
|
|
|
|
ASSERT(user_config_storage != nullptr);
|
|
|
|
const auto& user_config = user_config_storage->GetData();
|
|
|
|
|
|
|
|
ASSERT(user_config.size() >= sizeof(UserSelectionConfig));
|
|
|
|
std::memcpy(&config, user_config.data(), sizeof(UserSelectionConfig));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProfileSelect::TransactionComplete() const {
|
|
|
|
return complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode ProfileSelect::GetStatus() const {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileSelect::ExecuteInteractive() {
|
2022-06-07 23:02:29 +02:00
|
|
|
ASSERT_MSG(false, "Attempted to call interactive execution on non-interactive applet.");
|
2018-11-23 03:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileSelect::Execute() {
|
|
|
|
if (complete) {
|
2020-11-26 21:19:08 +01:00
|
|
|
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(final_data)));
|
2018-11-23 03:02:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-05 18:35:39 +01:00
|
|
|
frontend.SelectProfile([this](std::optional<Common::UUID> uuid) { SelectionComplete(uuid); });
|
2018-11-23 03:02:36 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 18:35:39 +01:00
|
|
|
void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) {
|
2018-11-23 03:02:36 +01:00
|
|
|
UserSelectionOutput output{};
|
|
|
|
|
2021-09-22 23:52:37 +02:00
|
|
|
if (uuid.has_value() && uuid->IsValid()) {
|
2018-11-23 03:02:36 +01:00
|
|
|
output.result = 0;
|
2022-02-05 18:29:09 +01:00
|
|
|
output.uuid_selected = *uuid;
|
2018-11-23 03:02:36 +01:00
|
|
|
} else {
|
|
|
|
status = ERR_USER_CANCELLED_SELECTION;
|
|
|
|
output.result = ERR_USER_CANCELLED_SELECTION.raw;
|
2022-02-05 18:29:09 +01:00
|
|
|
output.uuid_selected = Common::InvalidUUID;
|
2018-11-23 03:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
final_data = std::vector<u8>(sizeof(UserSelectionOutput));
|
|
|
|
std::memcpy(final_data.data(), &output, final_data.size());
|
2020-11-26 21:19:08 +01:00
|
|
|
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(final_data)));
|
2018-11-23 03:02:36 +01:00
|
|
|
broker.SignalStateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::AM::Applets
|