Made some changes from review comments:

- Made LoadKernelSystemMode return a pair consisting of a system mode and a result code (Could use review).
- Deleted ErrorOpenGL error code in favor of just having ErrorVideoCore.
- Made dialog messages more clear.
- Compared archive ID in fs_user.cpp to ArchiveIdCode::NCCH as opposed to hex magic.
- Cleaned up some other stuff.
This commit is contained in:
TheKoopaKingdom 2017-03-08 20:21:31 -05:00
parent 1ecb322daa
commit 37bec598ea
10 changed files with 55 additions and 53 deletions

View file

@ -40,7 +40,6 @@ void EmuThread::run() {
Core::System::ResultStatus result = Core::System::GetInstance().RunLoop(); Core::System::ResultStatus result = Core::System::GetInstance().RunLoop();
if (result != Core::System::ResultStatus::Success) { if (result != Core::System::ResultStatus::Success) {
emit ErrorThrown(result); emit ErrorThrown(result);
break;
} }
was_active = running || exec_step; was_active = running || exec_step;

View file

@ -300,7 +300,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
render_window->MakeCurrent(); render_window->MakeCurrent();
if (!gladLoadGL()) { if (!gladLoadGL()) {
QMessageBox::critical(this, tr("Error while starting Citra!"), QMessageBox::critical(this, tr("Error while initializing OpenGL 3.3 Core!"),
tr("Your GPU may not support OpenGL 3.3, or you do not" tr("Your GPU may not support OpenGL 3.3, or you do not"
"have the latest graphics driver.")); "have the latest graphics driver."));
return false; return false;
@ -329,7 +329,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
QMessageBox::critical( QMessageBox::critical(
this, tr("Error while loading ROM!"), this, tr("Error while loading ROM!"),
tr("The game that you are trying to load must be decrypted before being used with " tr("The game that you are trying to load must be decrypted before being used with "
"Citra.<br/><br/>" "Citra. A real 3DS is required.<br/><br/>"
"For more information on dumping and decrypting games, please see the following " "For more information on dumping and decrypting games, please see the following "
"wiki pages: <ul>" "wiki pages: <ul>"
"<li><a href='https://citra-emu.org/wiki/Dumping-Game-Cartridges/'>Dumping Game " "<li><a href='https://citra-emu.org/wiki/Dumping-Game-Cartridges/'>Dumping Game "
@ -344,10 +344,17 @@ bool GMainWindow::LoadROM(const QString& filename) {
tr("The ROM format is not supported.")); tr("The ROM format is not supported."));
break; break;
case Core::System::ResultStatus::ErrorOpenGL: case Core::System::ResultStatus::ErrorVideoCore:
QMessageBox::critical(this, tr("Error while loading OpenGL!"), QMessageBox::critical(
tr("Your GPU may not support OpenGL 3.3, or you do not " this, tr("An error occured in the video core."),
"have the latest graphics driver.")); tr("Citra has encountered an error while running the video core, please see the "
"log for more details."
"For more information on accessing the log, please see the following page: "
"<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How "
"to "
"Upload the Log File</a>."
"Ensure that you have the latest graphics drivers for your GPU."));
break; break;
default: default:
@ -632,9 +639,6 @@ void GMainWindow::UpdateStatusBar() {
} }
void GMainWindow::OnCoreError(Core::System::ResultStatus result) { void GMainWindow::OnCoreError(Core::System::ResultStatus result) {
// Waiting for the dialog to be closed before shutting down causes a segfault, maybe because of
// the profiler
ShutdownGame();
switch (result) { switch (result) {
case Core::System::ResultStatus::ErrorSystemFiles: case Core::System::ResultStatus::ErrorSystemFiles:
QMessageBox::critical( QMessageBox::critical(
@ -664,13 +668,13 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result) {
"."); ".");
break; break;
case Core::System::ResultStatus::ErrorUnknown: default:
QMessageBox::critical( QMessageBox::critical(
this, "Fatal Error", this, "Fatal Error",
"Citra has encountered a fatal error, please see the log for more details."); "Citra has encountered a fatal error, please see the log for more details. "
break; "For more information on accessing the log, please see the following page: "
"<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to "
default: "Upload the Log File</a>.");
break; break;
} }
} }
@ -679,9 +683,10 @@ bool GMainWindow::ConfirmClose() {
if (emu_thread == nullptr || !UISettings::values.confirm_before_closing) if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
return true; return true;
return QMessageBox::question(this, tr("Citra"), tr("Are you sure you want to close Citra?"), auto answer =
QMessageBox::Yes | QMessageBox::No, QMessageBox::question(this, tr("Citra"), tr("Are you sure you want to close Citra?"),
QMessageBox::No) != QMessageBox::No; QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
return answer != QMessageBox::No;
} }
void GMainWindow::closeEvent(QCloseEvent* event) { void GMainWindow::closeEvent(QCloseEvent* event) {

View file

@ -3,6 +3,9 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <memory> #include <memory>
#include <utility>
#include <boost/optional.hpp>
#include "audio_core/audio_core.h" #include "audio_core/audio_core.h"
#include "common/logging/log.h" #include "common/logging/log.h"
@ -26,6 +29,7 @@ namespace Core {
/*static*/ System System::s_instance; /*static*/ System System::s_instance;
System::ResultStatus System::RunLoop(int tight_loop) { System::ResultStatus System::RunLoop(int tight_loop) {
this->status = ResultStatus::Success;
if (!cpu_core) { if (!cpu_core) {
return ResultStatus::ErrorNotInitialized; return ResultStatus::ErrorNotInitialized;
} }
@ -73,14 +77,14 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str()); LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str());
return ResultStatus::ErrorGetLoader; return ResultStatus::ErrorGetLoader;
} }
boost::optional<u32> system_mode = boost::none; std::pair<boost::optional<u32>, Loader::ResultStatus> system_mode =
app_loader->LoadKernelSystemMode();
Loader::ResultStatus load_result{app_loader->LoadKernelSystemMode(system_mode)}; if (system_mode.second != Loader::ResultStatus::Success) {
if (!system_mode) { LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", system_mode.second);
LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", load_result);
System::Shutdown(); System::Shutdown();
switch (load_result) { switch (system_mode.second) {
case Loader::ResultStatus::ErrorEncrypted: case Loader::ResultStatus::ErrorEncrypted:
return ResultStatus::ErrorLoader_ErrorEncrypted; return ResultStatus::ErrorLoader_ErrorEncrypted;
case Loader::ResultStatus::ErrorInvalidFormat: case Loader::ResultStatus::ErrorInvalidFormat:
@ -90,15 +94,15 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
} }
} }
ResultStatus init_result{Init(emu_window, system_mode.get())}; ResultStatus init_result{Init(emu_window, system_mode.first.get())};
if (init_result != ResultStatus::Success) { if (init_result != ResultStatus::Success) {
LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result);
System::Shutdown(); System::Shutdown();
return init_result; return init_result;
} }
load_result = app_loader->Load(); Loader::ResultStatus load_result = app_loader->Load();
if (Loader::ResultStatus::Success != load_result) { if (load_result != Loader::ResultStatus::Success) {
LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result);
System::Shutdown(); System::Shutdown();
@ -154,7 +158,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
GDBStub::Init(); GDBStub::Init();
if (!VideoCore::Init(emu_window)) { if (!VideoCore::Init(emu_window)) {
return ResultStatus::ErrorOpenGL; return ResultStatus::ErrorVideoCore;
} }
LOG_DEBUG(Core, "Initialized OK"); LOG_DEBUG(Core, "Initialized OK");

View file

@ -43,7 +43,6 @@ public:
ErrorSystemFiles, ///< Error in finding system files ErrorSystemFiles, ///< Error in finding system files
ErrorSharedFont, ///< Error in finding shared font ErrorSharedFont, ///< Error in finding shared font
ErrorVideoCore, ///< Error in the video core ErrorVideoCore, ///< Error in the video core
ErrorOpenGL, ///< Error when initializing OpenGL
ErrorUnknown ///< Any other error ErrorUnknown ///< Any other error
}; };

View file

@ -37,7 +37,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb"); auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb");
if (!file->IsOpen()) { if (!file->IsOpen()) {
return ResultCode(-1); // TODO(Subv): Find the right error code return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
ErrorLevel::Status);
} }
auto size = file->GetSize(); auto size = file->GetSize();

View file

@ -257,11 +257,9 @@ ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archi
LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code); LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);
auto itr = id_code_map.find(id_code); auto itr = id_code_map.find(id_code);
if (itr == id_code_map.end()) { if (itr == id_code_map.end())
// TODO: Verify error against hardware return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status);
ErrorLevel::Permanent);
}
CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path)); CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));

View file

@ -133,12 +133,11 @@ static void OpenFileDirectly(Service::Interface* self) {
LOG_ERROR(Service_FS, LOG_ERROR(Service_FS,
"failed to get a handle for archive archive_id=0x%08X archive_path=%s", "failed to get a handle for archive archive_id=0x%08X archive_path=%s",
static_cast<u32>(archive_id), archive_path.DebugStr().c_str()); static_cast<u32>(archive_id), archive_path.DebugStr().c_str());
if (static_cast<u32>(archive_id) == 0x2345678A) {
Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles);
return;
}
cmd_buff[1] = archive_handle.Code().raw; cmd_buff[1] = archive_handle.Code().raw;
cmd_buff[3] = 0; cmd_buff[3] = 0;
if (static_cast<FS::ArchiveIdCode>(archive_id) == ArchiveIdCode::NCCH) {
Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles);
}
return; return;
} }
SCOPE_EXIT({ CloseArchive(*archive_handle); }); SCOPE_EXIT({ CloseArchive(*archive_handle); });

View file

@ -8,8 +8,11 @@
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
@ -100,13 +103,11 @@ public:
* Loads the system mode that this application needs. * Loads the system mode that this application needs.
* This function defaults to 2 (96MB allocated to the application) if it can't read the * This function defaults to 2 (96MB allocated to the application) if it can't read the
* information. * information.
* @param boost::optional<u32> Reference to Boost optional to store system mode. * @return A pair with the system mode (If found) and the result.
* @ return Result of operation.
*/ */
virtual ResultStatus LoadKernelSystemMode(boost::optional<u32>& system_mode) { virtual std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() {
// 96MB allocated to the application. // 96MB allocated to the application.
system_mode = 2; return std::make_pair(2, ResultStatus::Success);
return ResultStatus::Success;
} }
/** /**

View file

@ -121,19 +121,16 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) {
return FileType::Error; return FileType::Error;
} }
ResultStatus AppLoader_NCCH::LoadKernelSystemMode(boost::optional<u32>& system_mode) { std::pair<boost::optional<u32>, ResultStatus> AppLoader_NCCH::LoadKernelSystemMode() {
if (!is_loaded) { if (!is_loaded) {
ResultStatus res = LoadExeFS(); ResultStatus res = LoadExeFS();
if (res != ResultStatus::Success) { if (res != ResultStatus::Success) {
// Set the system mode as invalid. return std::make_pair(boost::none, res);
system_mode = boost::none;
// Return the error code.
return res;
} }
} }
// Set the system mode as the one from the exheader. // Set the system mode as the one from the exheader.
system_mode = exheader_header.arm11_system_local_caps.system_mode.Value(); return std::make_pair(exheader_header.arm11_system_local_caps.system_mode.Value(),
return ResultStatus::Success; ResultStatus::Success);
} }
ResultStatus AppLoader_NCCH::LoadExec() { ResultStatus AppLoader_NCCH::LoadExec() {

View file

@ -179,10 +179,9 @@ public:
/** /**
* Loads the Exheader and returns the system mode for this application. * Loads the Exheader and returns the system mode for this application.
* @param boost::optional<u32> Reference to Boost optional to store system mode. * @return A pair with the system mode (If found) and the result.
* @return Result of operation.
*/ */
ResultStatus LoadKernelSystemMode(boost::optional<u32>& system_mode) override; std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() override;
ResultStatus ReadCode(std::vector<u8>& buffer) override; ResultStatus ReadCode(std::vector<u8>& buffer) override;