From 553a5cc455b65c65db821cbc3bcb691f6cb01026 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 28 Dec 2022 17:59:05 +1000 Subject: [PATCH] CDVD: Remove exceptions --- pcsx2/CDVD/CDVDcommon.cpp | 4 +--- pcsx2/CDVD/CDVDisoReader.cpp | 9 +-------- pcsx2/CDVD/InputIsoFile.cpp | 22 ++++++++++++++-------- pcsx2/CDVD/IsoFileFormats.h | 2 +- pcsx2/CDVD/OutputIsoFile.cpp | 24 ++++++++++-------------- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/pcsx2/CDVD/CDVDcommon.cpp b/pcsx2/CDVD/CDVDcommon.cpp index e13745acad..1bb6bd03b9 100644 --- a/pcsx2/CDVD/CDVDcommon.cpp +++ b/pcsx2/CDVD/CDVDcommon.cpp @@ -430,9 +430,7 @@ bool DoCDVDopen() Host::AddKeyedOSDMessage("BlockDumpCreate", fmt::format("Saving CDVD block dump to '{}'.", temp), Host::OSD_INFO_DURATION); - blockDumpFile.Create(std::move(temp), 2); - - if (blockDumpFile.IsOpened()) + if (blockDumpFile.Create(std::move(temp), 2)) { int blockofs = 0; uint blocksize = CD_FRAMESIZE_RAW; diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 9c3c236755..92ebfc12ca 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -51,15 +51,8 @@ s32 CALLBACK ISOopen(const char* pTitle) return -1; } - try - { - iso.Open(pTitle); - } - catch (BaseException& ex) - { - Console.Error(ex.FormatDiagnosticMessage()); + if (!iso.Open(pTitle)) return -1; - } switch (iso.GetType()) { diff --git a/pcsx2/CDVD/InputIsoFile.cpp b/pcsx2/CDVD/InputIsoFile.cpp index 2787f9bd8b..bbc6ef13f2 100644 --- a/pcsx2/CDVD/InputIsoFile.cpp +++ b/pcsx2/CDVD/InputIsoFile.cpp @@ -15,14 +15,15 @@ #include "PrecompiledHeader.h" -#include "IsoFileFormats.h" + +#include "CDVD/IsoFileFormats.h" +#include "Config.h" +#include "Host.h" + #include "common/Assertions.h" #include "common/Exceptions.h" -#include "Config.h" -#include "fmt/core.h" - -#include +#include "fmt/format.h" static const char* nameFromType(int type) { @@ -246,12 +247,17 @@ bool InputIsoFile::Open(std::string srcfile, bool testOnly) bool detected = Detect(); if (testOnly) + { + Close(); return detected; + } if (!detected) - throw Exception::BadStream() - .SetUserMsg("Unrecognized ISO image file format.") - .SetDiagMsg("ISO mounting failed: PCSX2 is unable to identify the ISO image type."); + { + Host::ReportErrorAsync("Unrecognized ISO image file format", "ISO mounting failed: PCSX2 is unable to identify the ISO image type."); + Close(); + return false; + } if (!isBlockdump && !isCompressed) { diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index 91be1f3134..02e6836c27 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -130,7 +130,7 @@ public: return m_filename; } - void Create(std::string filename, int mode); + bool Create(std::string filename, int mode); void Close(); void WriteHeader(int blockofs, uint blocksize, uint blocks); diff --git a/pcsx2/CDVD/OutputIsoFile.cpp b/pcsx2/CDVD/OutputIsoFile.cpp index 3942d1a017..0ad4b9fe86 100644 --- a/pcsx2/CDVD/OutputIsoFile.cpp +++ b/pcsx2/CDVD/OutputIsoFile.cpp @@ -15,7 +15,9 @@ #include "PrecompiledHeader.h" -#include "IsoFileFormats.h" +#include "CDVD/IsoFileFormats.h" +#include "Host.h" + #include "common/Exceptions.h" #include "common/FileSystem.h" #include "common/StringUtil.h" @@ -44,7 +46,7 @@ void OutputIsoFile::_init() m_blocks = 0; } -void OutputIsoFile::Create(std::string filename, int version) +bool OutputIsoFile::Create(std::string filename, int version) { Close(); m_filename = std::move(filename); @@ -57,11 +59,13 @@ void OutputIsoFile::Create(std::string filename, int version) m_outstream = FileSystem::OpenCFile(m_filename.c_str(), "wb"); if (!m_outstream) { - Console.Error("(OutputIsoFile::Create) Unable to open the file '%s' for writing: %d", m_filename.c_str(), errno); - Exception::FromErrno(filename, errno)->Rethrow(); + Console.Error(fmt::format("(OutputIsoFile::Create) Unable to open the file '{}' for writing: {}", m_filename, errno)); + _init(); + return false; } Console.WriteLn("isoFile create ok: %s ", m_filename.c_str()); + return true; } // Generates format header information for blockdumps. @@ -122,16 +126,8 @@ void OutputIsoFile::WriteBuffer(const void* src, size_t size) { if (std::fwrite(src, size, 1, m_outstream) != 1) { - int err = errno; - if (!err) - { - throw Exception::BadStream(m_filename) - .SetDiagMsg(fmt::format("An error occurred while writing {} bytes to file", size)); - } - - std::unique_ptr ex(Exception::FromErrno(m_filename, err)); - ex->SetDiagMsg(fmt::format("An error occurred while writing {} bytes to file: {}", size, ex->DiagMsg())); - ex->Rethrow(); + Host::ReportErrorAsync("Write Error", fmt::format("errno {} when trying to write {} bytes to block dump file.\n\nClosing file.")); + Close(); } }