GzippedFileReader: Fix index creation

This commit is contained in:
Connor McLaughlin 2022-05-23 00:05:41 +10:00 committed by refractionpcsx2
parent ea051c6d5f
commit b919719aeb
3 changed files with 23 additions and 18 deletions

View File

@ -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 ReplaceAll(const std::string_view& subject, const std::string_view& search, const std::string_view& replacement)
{ {
std::string ret(subject); 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; 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(); start_pos += replacement.length();
} }
} }
return ret;
} }
bool ParseAssignmentString(const std::string_view& str, std::string_view* key, std::string_view* value) bool ParseAssignmentString(const std::string_view& str, std::string_view* key, std::string_view* value)

View File

@ -196,6 +196,7 @@ namespace StringUtil
/// Replaces all instances of search in subject with replacement. /// 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); 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. /// 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); bool ParseAssignmentString(const std::string_view& str, std::string_view* key, std::string_view* value);

View File

@ -23,6 +23,12 @@
#include "GzippedFileReader.h" #include "GzippedFileReader.h"
#include "zlib_indexed.h" #include "zlib_indexed.h"
#ifndef PCSX2_CORE
#include "gui/StringHelpers.h"
#include "gui/wxDirName.h"
#include <wx/stdpaths.h>
#endif
#define CLAMP(val, minval, maxval) (std::min(maxval, std::max(minval, val))) #define CLAMP(val, minval, maxval) (std::min(maxval, std::max(minval, val)))
#define GZIP_ID "PCSX2.index.gzip.v1|" #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) if (first > 0)
fname = Path::GetFileName(fname); // without path fname = Path::GetFileName(fname); // without path
StringUtil::ReplaceAll(trimmedTemplate, INDEX_TEMPLATE_KEY, fname); StringUtil::ReplaceAll(&trimmedTemplate, INDEX_TEMPLATE_KEY, fname);
if (first > 0) if (!Path::IsAbsolute(trimmedTemplate))
trimmedTemplate = Path::Combine(base, trimmedTemplate); // ignores appRoot if tem is absolute trimmedTemplate = Path::Combine(base, trimmedTemplate); // ignores appRoot if tem is absolute
return trimmedTemplate; 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) static std::string iso2indexname(const std::string& isoname)
{ {
#if 0
#ifndef PCSX2_CORE #ifndef PCSX2_CORE
//testTemplate(isoname); std::string appRoot = // TODO: have only one of this in PCSX2. Right now have few...
wxDirName appRoot = // TODO: have only one of this in PCSX2. Right now have few... StringUtil::wxStringToUTF8String(((wxDirName)(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath())).ToString());
(wxDirName)(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath());
#else #else
const wxDirName& appRoot = EmuFolders::DataRoot; const std::string& appRoot = EmuFolders::DataRoot;
#endif
//TestTemplate(appRoot, isoname, false);
return StringUtil::wxStringToUTF8String(ApplyTemplate("gzip index", appRoot, EmuConfig.GzipIsoIndexTemplate, isoname, false));
#else
//FIXME
abort();
return {};
#endif #endif
return ApplyTemplate("gzip index", appRoot, EmuConfig.GzipIsoIndexTemplate, isoname, false);
} }
GzippedFileReader::GzippedFileReader(void) GzippedFileReader::GzippedFileReader(void)
: mBytesRead(0) : mBytesRead(0)
, m_pIndex(0) , m_pIndex(0)