VpkLib: make regex available to other code and utilize those instead

Prevent copies or similar patterns that might not work as good.
This commit is contained in:
Kawe Mazidjatari 2024-04-23 00:03:31 +02:00
parent da09d8b631
commit 84abfced6a
3 changed files with 11 additions and 11 deletions

View File

@ -9,6 +9,7 @@
#include "tier0/memstd.h"
#include "tier0/jobthread.h"
#include "tier1/fmtstr.h"
#include "tier1/keyvalues.h"
#include "tier2/fileutils.h"
#include "engine/sys_dll2.h"
#include "engine/host_cmd.h"
@ -19,7 +20,7 @@
#include "rtech/pak/paktools.h"
#include "rtech/pak/pakstream.h"
#include "tier1/keyvalues.h"
#include "vpklib/packedstore.h"
#include "datacache/mdlcache.h"
#include "filesystem/filesystem.h"
#ifndef DEDICATED
@ -29,8 +30,6 @@
CUtlVector<CUtlString> g_InstalledMaps;
CFmtStrN<MAX_MAP_NAME> s_CurrentLevelName;
static std::regex s_ArchiveRegex{ R"([^_]*_(.*)(.bsp.pak000_dir).*)" };
static CustomPakData_t s_customPakData;
static KeyValues* s_pLevelSetKV = nullptr;
@ -136,11 +135,11 @@ void Mod_GetAllInstalledMaps()
// slash, as the files are loaded from 'vpk/'.
Assert(pFileName);
std::regex_search(pFileName, regexMatches, s_ArchiveRegex);
std::regex_search(pFileName, regexMatches, g_VpkDirFileRegex);
if (!regexMatches.empty())
{
const std::sub_match<const char*>& match = regexMatches[1];
const std::sub_match<const char*>& match = regexMatches[2];
if (match.compare("frontend") == 0)
continue; // Frontend contains no BSP's.
@ -155,6 +154,7 @@ void Mod_GetAllInstalledMaps()
else
{
const string mapName = match.str();
if (!g_InstalledMaps.HasElement(mapName.c_str()))
g_InstalledMaps.AddToTail(mapName.c_str());
}

View File

@ -35,9 +35,6 @@
extern CFileSystem_Stdio* FileSystem();
static const std::regex s_DirFileRegex{ R"((?:.*\/)?([^_]*)(?:_)(.*)(.bsp.pak000_dir).*)" };
static const std::regex s_BlockFileRegex{ R"(pak000_([0-9]{3}))" };
//-----------------------------------------------------------------------------
// Purpose: gets the LZHAM compression level
// output : lzham_compress_level
@ -98,7 +95,7 @@ CUtlString PackedStore_GetDirBaseName(const CUtlString& dirFileName)
const char* baseFileName = V_UnqualifiedFileName(dirFileName.String());
std::cmatch regexMatches;
std::regex_search(baseFileName, regexMatches, s_DirFileRegex);
std::regex_search(baseFileName, regexMatches, g_VpkDirFileRegex);
CUtlString result;
result.Format("%s_%s", regexMatches[1].str().c_str(), regexMatches[2].str().c_str());
@ -117,7 +114,7 @@ CUtlString PackedStore_GetDirNameParts(const CUtlString& dirFileName, const int
const char* baseFileName = V_UnqualifiedFileName(dirFileName.String());
std::cmatch regexMatches;
std::regex_search(baseFileName, regexMatches, s_DirFileRegex);
std::regex_search(baseFileName, regexMatches, g_VpkDirFileRegex);
return regexMatches[nCaptureGroup].str().c_str();
}
@ -846,7 +843,7 @@ VPKDir_t::VPKDir_t(const CUtlString& dirFilePath, bool bSanitizeName)
}
std::cmatch regexMatches;
std::regex_search(dirFilePath.String(), regexMatches, s_BlockFileRegex);
std::regex_search(dirFilePath.String(), regexMatches, g_VpkPackFileRegex);
if (regexMatches.empty()) // Not a block file, or not following the naming scheme.
{

View File

@ -27,6 +27,9 @@ constexpr int PACKFILEINDEX_SEP = 0x0;
constexpr int PACKFILEINDEX_END = 0xffff;
constexpr const char VPK_IGNORE_FILE[] = ".vpkignore";
static const std::regex g_VpkDirFileRegex{ R"((?:.*\/)?([^_]*)(?:_)(.*)(.bsp.pak000_dir).*)" };
static const std::regex g_VpkPackFileRegex{ R"(pak000_([0-9]{3}))" };
//-----------------------------------------------------------------------------
// KeyValues structure for the VPK manifest file. This struct gets populated by
// the VPK's corresponding manifest file, which ultimately determines how each