mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Replace hsStream::Open duplicated methods everywhere with a single plFileName interface
This commit is contained in:
@ -52,7 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "plVersion.h"
|
||||
|
||||
plRegistryPageNode::plRegistryPageNode(const plString& path)
|
||||
plRegistryPageNode::plRegistryPageNode(const plFileName& path)
|
||||
: fValid(kPageCorrupt)
|
||||
, fPath(path)
|
||||
, fDynLoadedTypes(0)
|
||||
@ -69,9 +69,9 @@ plRegistryPageNode::plRegistryPageNode(const plString& path)
|
||||
}
|
||||
}
|
||||
|
||||
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath)
|
||||
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plString& age,
|
||||
const plString& page, const plFileName& dataPath)
|
||||
: fValid(kPageOk)
|
||||
, fPath(nil)
|
||||
, fPageInfo(location)
|
||||
, fDynLoadedTypes(0)
|
||||
, fStaticLoadedTypes(0)
|
||||
@ -82,7 +82,8 @@ plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plStrin
|
||||
|
||||
// Time to construct our actual file name. For now, we'll use the same old format
|
||||
// of age_page.extension
|
||||
fPath = plString::Format("%s" PATH_SEPARATOR_STR "%s_District_%s.prp", dataPath.c_str(), fPageInfo.GetAge().c_str(), fPageInfo.GetPage().c_str());
|
||||
fPath = plFileName::Join(dataPath, plString::Format("%s_District_%s.prp",
|
||||
fPageInfo.GetAge().c_str(), fPageInfo.GetPage().c_str()));
|
||||
}
|
||||
|
||||
plRegistryPageNode::~plRegistryPageNode()
|
||||
@ -129,7 +130,7 @@ hsStream* plRegistryPageNode::OpenStream()
|
||||
{
|
||||
if (fOpenRequests == 0)
|
||||
{
|
||||
if (!fStream.Open_TEMP(fPath, "rb"))
|
||||
if (!fStream.Open(fPath, "rb"))
|
||||
return nil;
|
||||
}
|
||||
fOpenRequests++;
|
||||
@ -220,7 +221,7 @@ void plRegistryPageNode::Write()
|
||||
{
|
||||
hsAssert(fOpenRequests == 0, "Trying to write while the page is open for reading");
|
||||
|
||||
if (!fStream.Open(fPath.c_str(), "wb"))
|
||||
if (!fStream.Open(fPath, "wb"))
|
||||
{
|
||||
hsAssert(0, "Couldn't open file for writing");
|
||||
return;
|
||||
@ -400,6 +401,5 @@ plRegistryKeyList* plRegistryPageNode::IGetKeyList(uint16_t classType) const
|
||||
void plRegistryPageNode::DeleteSource()
|
||||
{
|
||||
hsAssert(fOpenRequests == 0, "Deleting a stream that's open for reading");
|
||||
plFileUtils::RemoveFile(fPath.c_str());
|
||||
plFileSystem::Unlink(fPath);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ protected:
|
||||
int fStaticLoadedTypes; // The number of key types that have all their keys loaded
|
||||
|
||||
PageCond fValid; // Condition of the page
|
||||
plString fPath; // Path to the page file
|
||||
plFileName fPath; // Path to the page file
|
||||
plPageInfo fPageInfo; // Info about this page
|
||||
|
||||
hsBufferedStream fStream; // Stream for reading/writing our page
|
||||
@ -93,10 +93,11 @@ protected:
|
||||
|
||||
public:
|
||||
// For reading a page off disk
|
||||
plRegistryPageNode(const plString& path);
|
||||
plRegistryPageNode(const plFileName& path);
|
||||
|
||||
// For creating a new page.
|
||||
plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath);
|
||||
plRegistryPageNode(const plLocation& location, const plString& age,
|
||||
const plString& page, const plFileName& dataPath);
|
||||
~plRegistryPageNode();
|
||||
|
||||
bool IsValid() const { return fValid == kPageOk; }
|
||||
@ -143,7 +144,7 @@ public:
|
||||
void Write();
|
||||
void DeleteSource();
|
||||
|
||||
const plString& GetPagePath() const { return fPath; }
|
||||
const plFileName& GetPagePath() const { return fPath; }
|
||||
};
|
||||
|
||||
#endif // plRegistryNode_h_inc
|
||||
|
@ -235,25 +235,25 @@ void plResManager::IShutdown()
|
||||
fInited = false;
|
||||
}
|
||||
|
||||
void plResManager::AddSinglePage(const char* pagePath)
|
||||
void plResManager::AddSinglePage(const plFileName& pagePath)
|
||||
{
|
||||
plRegistryPageNode* node = new plRegistryPageNode(pagePath);
|
||||
AddPage(node);
|
||||
}
|
||||
|
||||
plRegistryPageNode* plResManager::FindSinglePage(const char* path) const
|
||||
plRegistryPageNode* plResManager::FindSinglePage(const plFileName& path) const
|
||||
{
|
||||
PageMap::const_iterator it;
|
||||
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
|
||||
{
|
||||
if ((it->second)->GetPagePath().CompareI(path) == 0)
|
||||
if (it->second->GetPagePath().AsString().CompareI(path.AsString()) == 0)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
void plResManager::RemoveSinglePage(const char* path)
|
||||
void plResManager::RemoveSinglePage(const plFileName& path)
|
||||
{
|
||||
plRegistryPageNode* node = FindSinglePage(path);
|
||||
if (node)
|
||||
@ -1383,16 +1383,14 @@ static void ICatPageNames(hsTArray<plRegistryPageNode*>& pages, char* buf, int b
|
||||
break;
|
||||
}
|
||||
|
||||
const char* pagePath = pages[i]->GetPagePath().c_str();
|
||||
const char* pageFile = plFileUtils::GetFileName(pagePath);
|
||||
|
||||
if (strlen(buf) + strlen(pageFile) > bufSize - 5)
|
||||
plString pageFile = pages[i]->GetPagePath().GetFileName();
|
||||
if (strlen(buf) + pageFile.GetSize() > bufSize - 5)
|
||||
{
|
||||
strcat(buf, "...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
strcat(buf, pageFile);
|
||||
strcat(buf, pageFile.c_str());
|
||||
strcat(buf, "\n");
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ class plRegistryDataStream;
|
||||
class plResAgeHolder;
|
||||
class plResManagerHelper;
|
||||
class plDispatch;
|
||||
class plFileName;
|
||||
|
||||
// plProgressProc is a proc called every time an object loads, to keep a progress bar for
|
||||
// loading ages up-to-date.
|
||||
@ -70,9 +71,9 @@ public:
|
||||
void SetDataPath(const char* path) { fDataPath = path; }
|
||||
|
||||
// Mainly for external tools.
|
||||
void AddSinglePage(const char* path);
|
||||
plRegistryPageNode* FindSinglePage(const char* path) const;
|
||||
void RemoveSinglePage(const char* path);
|
||||
void AddSinglePage(const plFileName& path);
|
||||
plRegistryPageNode* FindSinglePage(const plFileName& path) const;
|
||||
void RemoveSinglePage(const plFileName& path);
|
||||
|
||||
//---------------------------
|
||||
// Load and Unload
|
||||
|
Reference in New Issue
Block a user