From b919719aebd2cb91af3346b1c68d5a9ce82cecf7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 23 May 2022 00:05:41 +1000 Subject: [PATCH] GzippedFileReader: Fix index creation --- common/StringUtil.cpp | 13 +++++++++---- common/StringUtil.h | 1 + pcsx2/CDVD/GzippedFileReader.cpp | 27 +++++++++++++-------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index 1d6443fc1c..b5388aff85 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -315,16 +315,21 @@ namespace StringUtil std::string ReplaceAll(const std::string_view& subject, const std::string_view& search, const std::string_view& replacement) { std::string ret(subject); - if (!ret.empty()) + ReplaceAll(&ret, search, replacement); + return ret; + } + + void ReplaceAll(std::string* subject, const std::string_view& search, const std::string_view& replacement) + { + if (!subject->empty()) { std::string::size_type start_pos = 0; - while ((start_pos = ret.find(search, start_pos)) != std::string::npos) + while ((start_pos = subject->find(search, start_pos)) != std::string::npos) { - ret.replace(start_pos, search.length(), replacement); + subject->replace(start_pos, search.length(), replacement); start_pos += replacement.length(); } } - return ret; } bool ParseAssignmentString(const std::string_view& str, std::string_view* key, std::string_view* value) diff --git a/common/StringUtil.h b/common/StringUtil.h index aaa59ba411..f2b684b0d7 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -196,6 +196,7 @@ namespace StringUtil /// Replaces all instances of search in subject with replacement. std::string ReplaceAll(const std::string_view& subject, const std::string_view& search, const std::string_view& replacement); + void ReplaceAll(std::string* subject, const std::string_view& search, const std::string_view& replacement); /// Parses an assignment string (Key = Value) into its two components. bool ParseAssignmentString(const std::string_view& str, std::string_view* key, std::string_view* value); diff --git a/pcsx2/CDVD/GzippedFileReader.cpp b/pcsx2/CDVD/GzippedFileReader.cpp index 2bc8485ab0..ce02e83555 100644 --- a/pcsx2/CDVD/GzippedFileReader.cpp +++ b/pcsx2/CDVD/GzippedFileReader.cpp @@ -23,6 +23,12 @@ #include "GzippedFileReader.h" #include "zlib_indexed.h" +#ifndef PCSX2_CORE +#include "gui/StringHelpers.h" +#include "gui/wxDirName.h" +#include +#endif + #define CLAMP(val, minval, maxval) (std::min(maxval, std::max(minval, val))) #define GZIP_ID "PCSX2.index.gzip.v1|" @@ -137,8 +143,8 @@ static std::string ApplyTemplate(const std::string& name, const std::string& bas if (first > 0) fname = Path::GetFileName(fname); // without path - StringUtil::ReplaceAll(trimmedTemplate, INDEX_TEMPLATE_KEY, fname); - if (first > 0) + StringUtil::ReplaceAll(&trimmedTemplate, INDEX_TEMPLATE_KEY, fname); + if (!Path::IsAbsolute(trimmedTemplate)) trimmedTemplate = Path::Combine(base, trimmedTemplate); // ignores appRoot if tem is absolute return trimmedTemplate; @@ -173,23 +179,16 @@ static void TestTemplate(const wxDirName &base, const wxString &fname, bool canE static std::string iso2indexname(const std::string& isoname) { -#if 0 #ifndef PCSX2_CORE - //testTemplate(isoname); - wxDirName appRoot = // TODO: have only one of this in PCSX2. Right now have few... - (wxDirName)(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath()); + std::string appRoot = // TODO: have only one of this in PCSX2. Right now have few... + StringUtil::wxStringToUTF8String(((wxDirName)(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath())).ToString()); #else - const wxDirName& appRoot = EmuFolders::DataRoot; -#endif - //TestTemplate(appRoot, isoname, false); - return StringUtil::wxStringToUTF8String(ApplyTemplate("gzip index", appRoot, EmuConfig.GzipIsoIndexTemplate, isoname, false)); -#else - //FIXME - abort(); - return {}; + const std::string& appRoot = EmuFolders::DataRoot; #endif + return ApplyTemplate("gzip index", appRoot, EmuConfig.GzipIsoIndexTemplate, isoname, false); } + GzippedFileReader::GzippedFileReader(void) : mBytesRead(0) , m_pIndex(0)