From 37bec598ea28662462dcaab65d5abd6db8372dbc Mon Sep 17 00:00:00 2001 From: TheKoopaKingdom Date: Wed, 8 Mar 2017 20:21:31 -0500 Subject: 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. --- src/core/core.cpp | 22 +++++++++++++--------- src/core/core.h | 1 - src/core/file_sys/archive_ncch.cpp | 3 ++- src/core/hle/service/fs/archive.cpp | 8 +++----- src/core/hle/service/fs/fs_user.cpp | 7 +++---- src/core/loader/loader.h | 11 ++++++----- src/core/loader/ncch.cpp | 11 ++++------- src/core/loader/ncch.h | 5 ++--- 8 files changed, 33 insertions(+), 35 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 1861bfa9b..2a9664cb4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -3,6 +3,9 @@ // Refer to the license.txt file included. #include +#include + +#include #include "audio_core/audio_core.h" #include "common/logging/log.h" @@ -26,6 +29,7 @@ namespace Core { /*static*/ System System::s_instance; System::ResultStatus System::RunLoop(int tight_loop) { + this->status = ResultStatus::Success; if (!cpu_core) { 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()); return ResultStatus::ErrorGetLoader; } - boost::optional system_mode = boost::none; + std::pair, Loader::ResultStatus> system_mode = + app_loader->LoadKernelSystemMode(); - Loader::ResultStatus load_result{app_loader->LoadKernelSystemMode(system_mode)}; - if (!system_mode) { - LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", load_result); + if (system_mode.second != Loader::ResultStatus::Success) { + LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", system_mode.second); System::Shutdown(); - switch (load_result) { + switch (system_mode.second) { case Loader::ResultStatus::ErrorEncrypted: return ResultStatus::ErrorLoader_ErrorEncrypted; 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) { LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); System::Shutdown(); return init_result; } - load_result = app_loader->Load(); - if (Loader::ResultStatus::Success != load_result) { + Loader::ResultStatus load_result = app_loader->Load(); + if (load_result != Loader::ResultStatus::Success) { LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); System::Shutdown(); @@ -154,7 +158,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { GDBStub::Init(); if (!VideoCore::Init(emu_window)) { - return ResultStatus::ErrorOpenGL; + return ResultStatus::ErrorVideoCore; } LOG_DEBUG(Core, "Initialized OK"); diff --git a/src/core/core.h b/src/core/core.h index 0963f273e..a7b4f8d62 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -43,7 +43,6 @@ public: ErrorSystemFiles, ///< Error in finding system files ErrorSharedFont, ///< Error in finding shared font ErrorVideoCore, ///< Error in the video core - ErrorOpenGL, ///< Error when initializing OpenGL ErrorUnknown ///< Any other error }; diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 89455e39c..bf4e0916b 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -37,7 +37,8 @@ ResultVal> ArchiveFactory_NCCH::Open(const Path& auto file = std::make_shared(file_path, "rb"); 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(); diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 632712f2c..6d1a49d92 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -257,11 +257,9 @@ ResultVal OpenArchive(ArchiveIdCode id_code, FileSys::Path& archi LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code); auto itr = id_code_map.find(id_code); - if (itr == id_code_map.end()) { - // TODO: Verify error against hardware - return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound, - ErrorLevel::Permanent); - } + if (itr == id_code_map.end()) + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, + ErrorLevel::Status); CASCADE_RESULT(std::unique_ptr res, itr->second->Open(archive_path)); diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index 5a4437123..0538ffc9c 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp @@ -133,12 +133,11 @@ static void OpenFileDirectly(Service::Interface* self) { LOG_ERROR(Service_FS, "failed to get a handle for archive archive_id=0x%08X archive_path=%s", static_cast(archive_id), archive_path.DebugStr().c_str()); - if (static_cast(archive_id) == 0x2345678A) { - Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles); - return; - } cmd_buff[1] = archive_handle.Code().raw; cmd_buff[3] = 0; + if (static_cast(archive_id) == ArchiveIdCode::NCCH) { + Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles); + } return; } SCOPE_EXIT({ CloseArchive(*archive_handle); }); diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 21f73503e..0a2d4a10e 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -8,8 +8,11 @@ #include #include #include +#include #include + #include + #include "common/common_types.h" #include "common/file_util.h" @@ -100,13 +103,11 @@ public: * Loads the system mode that this application needs. * This function defaults to 2 (96MB allocated to the application) if it can't read the * information. - * @param boost::optional Reference to Boost optional to store system mode. - * @ return Result of operation. + * @return A pair with the system mode (If found) and the result. */ - virtual ResultStatus LoadKernelSystemMode(boost::optional& system_mode) { + virtual std::pair, ResultStatus> LoadKernelSystemMode() { // 96MB allocated to the application. - system_mode = 2; - return ResultStatus::Success; + return std::make_pair(2, ResultStatus::Success); } /** diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 1a20762e4..ffc019560 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -121,19 +121,16 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_NCCH::LoadKernelSystemMode(boost::optional& system_mode) { +std::pair, ResultStatus> AppLoader_NCCH::LoadKernelSystemMode() { if (!is_loaded) { ResultStatus res = LoadExeFS(); if (res != ResultStatus::Success) { - // Set the system mode as invalid. - system_mode = boost::none; - // Return the error code. - return res; + return std::make_pair(boost::none, res); } } // Set the system mode as the one from the exheader. - system_mode = exheader_header.arm11_system_local_caps.system_mode.Value(); - return ResultStatus::Success; + return std::make_pair(exheader_header.arm11_system_local_caps.system_mode.Value(), + ResultStatus::Success); } ResultStatus AppLoader_NCCH::LoadExec() { diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 269fe4f49..712d496a4 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -179,10 +179,9 @@ public: /** * Loads the Exheader and returns the system mode for this application. - * @param boost::optional Reference to Boost optional to store system mode. - * @return Result of operation. + * @return A pair with the system mode (If found) and the result. */ - ResultStatus LoadKernelSystemMode(boost::optional& system_mode) override; + std::pair, ResultStatus> LoadKernelSystemMode() override; ResultStatus ReadCode(std::vector& buffer) override; -- cgit v1.2.3