1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Convert plRegistryNode stuff to plString.

This commit is contained in:
Darryl Pogue
2013-01-05 20:21:33 -08:00
parent b574a583f4
commit 4dd06d1e7e
21 changed files with 114 additions and 115 deletions

View File

@ -34,7 +34,14 @@ set(plResMgr_HEADERS
)
add_library(plResMgr STATIC ${plResMgr_SOURCES} ${plResMgr_HEADERS})
target_link_libraries(plResMgr CoreLib pnDispatch pnFactory pnKeyedObject pnMessage pnTimer plFile plStatusLog)
target_link_libraries(plResMgr CoreLib)
target_link_libraries(plResMgr pnDispatch)
target_link_libraries(plResMgr pnFactory)
target_link_libraries(plResMgr pnKeyedObject)
target_link_libraries(plResMgr pnMessage)
target_link_libraries(plResMgr pnTimer)
target_link_libraries(plResMgr plFile)
target_link_libraries(plResMgr plStatusLog)
source_group("Source Files" FILES ${plResMgr_SOURCES})
source_group("Header Files" FILES ${plResMgr_HEADERS})

View File

@ -159,7 +159,7 @@ public:
try
{
#endif
if( stricmp( pageNode->GetPageInfo().GetAge(), fAgeName ) == 0 )
if (pageNode->GetPageInfo().GetAge().CompareI(fAgeName) == 0)
{
// Try loading and searching thru this page
hsTArray<plKey> keyRefs;
@ -353,8 +353,7 @@ class plPageFinder : public plRegistryPageIterator
// Are we searching by age/page?
if( fAgeString != nil )
{
if( stricmp( info.GetAge(), fAgeString ) == 0 &&
stricmp( info.GetPage(), fFindString ) == 0 )
if (info.GetAge().CompareI(fAgeString) == 0 && info.GetPage().CompareI(fFindString) == 0)
{
*fPagePtr = node;
return false;
@ -363,14 +362,14 @@ class plPageFinder : public plRegistryPageIterator
}
// Try for page only
if( stricmp( info.GetPage(), fFindString ) == 0 )
if (info.GetPage().CompareI(fFindString) == 0)
{
*fPagePtr = node;
return false;
}
// Try for full location
sprintf( str, "%s_%s", info.GetAge(), info.GetPage() );
sprintf( str, "%s_%s", info.GetAge().c_str(), info.GetPage().c_str() );
if( stricmp( str, fFindString ) == 0 )
{
*fPagePtr = node;

View File

@ -98,13 +98,10 @@ void plPageInfo::ISetFrom( const plPageInfo &src )
fIndexStart = src.fIndexStart;
}
void plPageInfo::SetStrings( const char *age, const char *page )
void plPageInfo::SetStrings(const plString& age, const plString& page)
{
delete [] fAge;
delete [] fPage;
fAge = ( age == nil ) ? nil : hsStrcpy( age );
fPage = ( page == nil ) ? nil : hsStrcpy( page );
fAge = age;
fPage = page;
}
void plPageInfo::SetLocation( const plLocation &loc )
@ -122,9 +119,6 @@ void plPageInfo::AddClassVersion(uint16_t classIdx, uint16_t version)
void plPageInfo::Read( hsStream *s )
{
delete [] fAge;
delete [] fPage;
IInit();
// 5 is the earliest version since we began working again on the P20 codebase in Sep 2005,

View File

@ -53,6 +53,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class hsStream;
class plLocation;
class plString;
class plPageInfo
{
public:
@ -61,12 +63,12 @@ public:
protected:
plLocation fLocation;
char* fAge;
char* fPage;
uint16_t fMajorVersion;
plString fAge;
plString fPage;
uint16_t fMajorVersion;
ClassVerVec fClassVersions;
uint32_t fChecksum;
uint32_t fDataStart, fIndexStart;
uint32_t fChecksum;
uint32_t fDataStart, fIndexStart;
void IInit( void );
void ISetFrom( const plPageInfo &src );
@ -78,8 +80,8 @@ public:
plPageInfo( const plPageInfo &src );
virtual ~plPageInfo();
const char* GetAge() const { return fAge; }
const char* GetPage() const { return fPage; }
const plString& GetAge() const { return fAge; }
const plString& GetPage() const { return fPage; }
plPageInfo &operator=( const plPageInfo &src );
@ -87,7 +89,7 @@ public:
void AddClassVersion(uint16_t classIdx, uint16_t version);
const ClassVerVec& GetClassVersions() const { return fClassVersions; }
void SetStrings( const char *age, const char *page );
void SetStrings(const plString& age, const plString& page);
void SetLocation(const plLocation& loc);
const plLocation& GetLocation() const { return fLocation; }

View File

@ -43,23 +43,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plRegistryKeyList.h"
#include "plRegistryHelpers.h"
#include "plString.h"
#include "pnKeyedObject/plKeyImp.h"
#include "plStatusLog/plStatusLog.h"
#include "pnFactory/plFactory.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plVersion.h"
plRegistryPageNode::plRegistryPageNode(const char* path)
plRegistryPageNode::plRegistryPageNode(const plString& path)
: fValid(kPageCorrupt)
, fPath(nil)
, fPath(path)
, fDynLoadedTypes(0)
, fStaticLoadedTypes(0)
, fOpenRequests(0)
, fIsNewPage(false)
{
fPath = hsStrcpy(path);
hsStream* stream = OpenStream();
if (stream)
{
@ -69,7 +69,7 @@ plRegistryPageNode::plRegistryPageNode(const char* path)
}
}
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const char* age, const char* page, const char* dataPath)
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath)
: fValid(kPageOk)
, fPath(nil)
, fPageInfo(location)
@ -80,25 +80,21 @@ plRegistryPageNode::plRegistryPageNode(const plLocation& location, const char* a
{
fPageInfo.SetStrings(age, page);
char filePath[512];
// Copy the path over
strncpy(filePath, dataPath, sizeof(filePath));
plFileUtils::AddSlash(filePath);
plString path = dataPath;
path += PATH_SEPARATOR_STR;
// Time to construct our actual file name. For now, we'll use the same old format
// of age_page.extension
strncat(filePath, fPageInfo.GetAge(), sizeof(filePath));
strncat(filePath, "_District_", sizeof(filePath));
strncat(filePath, fPageInfo.GetPage(), sizeof(filePath));
strncat(filePath, ".prp", sizeof(filePath));
path += fPageInfo.GetAge();
path += "_District_";
path += fPageInfo.GetPage();
path += ".prp";
fPath = hsStrcpy(filePath);
fPath = path;
}
plRegistryPageNode::~plRegistryPageNode()
{
delete [] fPath;
UnloadKeys();
}
@ -141,7 +137,7 @@ hsStream* plRegistryPageNode::OpenStream()
{
if (fOpenRequests == 0)
{
if (!fStream.Open(fPath, "rb"))
if (!fStream.Open(fPath.c_str(), "rb"))
return nil;
}
fOpenRequests++;
@ -168,7 +164,7 @@ void plRegistryPageNode::LoadKeys()
if (!stream)
{
hsAssert(0, plString::Format("plRegistryPageNode::LoadKeysFromSource - bad stream %s,%s",
GetPageInfo().GetAge(), GetPageInfo().GetPage()).c_str());
GetPageInfo().GetAge().c_str(), GetPageInfo().GetPage().c_str()).c_str());
return;
}
@ -232,7 +228,7 @@ void plRegistryPageNode::Write()
{
hsAssert(fOpenRequests == 0, "Trying to write while the page is open for reading");
if (!fStream.Open(fPath, "wb"))
if (!fStream.Open(fPath.c_str(), "wb"))
{
hsAssert(0, "Couldn't open file for writing");
return;
@ -412,6 +408,6 @@ plRegistryKeyList* plRegistryPageNode::IGetKeyList(uint16_t classType) const
void plRegistryPageNode::DeleteSource()
{
hsAssert(fOpenRequests == 0, "Deleting a stream that's open for reading");
plFileUtils::RemoveFile(fPath);
plFileUtils::RemoveFile(fPath.c_str());
}

View File

@ -52,6 +52,7 @@ class plRegistryKeyList;
class hsStream;
class plKeyImp;
class plRegistryKeyIterator;
class plString;
enum PageCond
{
@ -77,7 +78,7 @@ protected:
int fStaticLoadedTypes; // The number of key types that have all their keys loaded
PageCond fValid; // Condition of the page
char* fPath; // Path to the page file
plString fPath; // Path to the page file
plPageInfo fPageInfo; // Info about this page
hsBufferedStream fStream; // Stream for reading/writing our page
@ -92,10 +93,10 @@ protected:
public:
// For reading a page off disk
plRegistryPageNode(const char* path);
plRegistryPageNode(const plString& path);
// For creating a new page.
plRegistryPageNode(const plLocation& location, const char* age, const char* page, const char* dataPath);
plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath);
~plRegistryPageNode();
bool IsValid() const { return fValid == kPageOk; }
@ -142,7 +143,7 @@ public:
void Write();
void DeleteSource();
const char* GetPagePath() const { return fPath; }
const plString& GetPagePath() const { return fPath; }
};
#endif // plRegistryNode_h_inc

View File

@ -243,7 +243,7 @@ plRegistryPageNode* plResManager::FindSinglePage(const char* path) const
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
{
if (stricmp((it->second)->GetPagePath(), path) == 0)
if ((it->second)->GetPagePath().CompareI(path) == 0)
return it->second;
}
@ -626,9 +626,9 @@ void plResManager::GetLocationStrings(const plLocation& loc, char* ageBuffer, ch
// Those buffers better be big enough...
if (ageBuffer)
hsStrcpy(ageBuffer, info.GetAge());
hsStrcpy(ageBuffer, info.GetAge().c_str());
if (pageBuffer)
hsStrcpy(pageBuffer, info.GetPage());
hsStrcpy(pageBuffer, info.GetPage().c_str());
}
bool plResManager::AddViaNotify(plRefMsg* msg, plRefFlags::Type flags)
@ -1041,7 +1041,7 @@ public:
virtual bool EatPage(plRegistryPageNode* page)
{
if (stricmp(page->GetPageInfo().GetAge(), fAgeName) == 0)
if (page->GetPageInfo().GetAge().CompareI(fAgeName) == 0)
{
fResMgr->LoadPageKeys(page);
plKeyCollector collector(fKeys);
@ -1176,25 +1176,25 @@ void plResManager::PageInRoom(const plLocation& page, uint16_t objClassToRef, pl
return;
}
kResMgrLog(2, ILog(2, "...Found, page is ID'd as %s>%s", pageNode->GetPageInfo().GetAge(), pageNode->GetPageInfo().GetPage()));
kResMgrLog(2, ILog(2, "...Found, page is ID'd as %s>%s", pageNode->GetPageInfo().GetAge().c_str(), pageNode->GetPageInfo().GetPage().c_str()));
// Step 0.5: Verify the page, just to make sure we really should be loading it
PageCond cond = pageNode->GetPageCondition();
if (cond != kPageOk)
{
std::string condStr ="Checksum invalid";
if (cond == kPageTooNew)
plString condStr = "Checksum invalid";
if (cond == kPageTooNew) {
condStr = "Page Version too new";
else
if (cond == kPageOutOfDate)
} else if (cond == kPageOutOfDate) {
condStr = "Page Version out of date";
}
kResMgrLog(1, ILog(1, "...IGNORING pageIn request; verification failed! (%s)", condStr.c_str()));
plString msg = plString::Format("Data Problem: Age:%s Page:%s Error:%s",
pageNode->GetPageInfo().GetAge(), pageNode->GetPageInfo().GetPage(), condStr.c_str());
pageNode->GetPageInfo().GetAge().c_str(), pageNode->GetPageInfo().GetPage().c_str(), condStr.c_str());
hsMessageBox(msg.c_str(), "Error", hsMessageBoxNormal, hsMessageBoxIconError);
hsRefCnt_SafeUnRef(refMsg);
return;
}
@ -1250,7 +1250,7 @@ void plResManager::PageInRoom(const plLocation& page, uint16_t objClassToRef, pl
readRoomTime = hsTimer::GetFullTickCount() - readRoomTime;
plStatusLog::AddLineS("readtimings.log", plStatusLog::kWhite, "----- Reading page %s>%s took %.1f ms",
pageNode->GetPageInfo().GetAge(), pageNode->GetPageInfo().GetPage(),
pageNode->GetPageInfo().GetAge().c_str(), pageNode->GetPageInfo().GetPage().c_str(),
hsTimer::FullTicksToMs(readRoomTime));
}
}
@ -1275,7 +1275,7 @@ public:
}
virtual bool EatPage(plRegistryPageNode* page)
{
if (stricmp(page->GetPageInfo().GetAge(), fAgeName) == 0)
if (page->GetPageInfo().GetAge().CompareI(fAgeName) == 0)
{
plUoid uoid(page->GetPageInfo().GetLocation(), 0, "");
fLocations.push_back(uoid.GetLocation());
@ -1406,7 +1406,7 @@ static void ICatPageNames(hsTArray<plRegistryPageNode*>& pages, char* buf, int b
break;
}
const char* pagePath = pages[i]->GetPagePath();
const char* pagePath = pages[i]->GetPagePath().c_str();
const char* pageFile = plFileUtils::GetFileName(pagePath);
if (strlen(buf) + strlen(pageFile) > bufSize - 5)
@ -1578,7 +1578,7 @@ static void sIReportLeak(plKeyImp* key, plRegistryPageNode* page)
if (!alreadyDone)
{
// Print out page header
hsStatusMessageF(" Leaks in page %s>%s[%08x]:\n", lastPage->GetPageInfo().GetAge(), lastPage->GetPageInfo().GetPage(), lastPage->GetPageInfo().GetLocation().GetSequenceNumber());
hsStatusMessageF(" Leaks in page %s>%s[%08x]:\n", lastPage->GetPageInfo().GetAge().c_str(), lastPage->GetPageInfo().GetPage().c_str(), lastPage->GetPageInfo().GetLocation().GetSequenceNumber());
alreadyDone = true;
}
@ -1650,14 +1650,13 @@ plRegistryPageNode* plResManager::FindPage(const plLocation& location) const
//// FindPage ////////////////////////////////////////////////////////////////
plRegistryPageNode* plResManager::FindPage(const char* age, const char* page) const
plRegistryPageNode* plResManager::FindPage(const plString& age, const plString& page) const
{
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); ++it)
{
const plPageInfo& info = (it->second)->GetPageInfo();
if (stricmp(info.GetAge(), age) == 0 &&
stricmp(info.GetPage(), page) == 0)
if (info.GetAge().CompareI(age) == 0 && info.GetPage().CompareI(page) == 0)
return it->second;
}
@ -1760,7 +1759,7 @@ bool plResManager::IterateKeys(plRegistryKeyIterator* iterator, const plLocation
//// IteratePages ////////////////////////////////////////////////////////////
// Iterate through all LOADED pages
bool plResManager::IteratePages(plRegistryPageIterator* iterator, const char* ageToRestrictTo)
bool plResManager::IteratePages(plRegistryPageIterator* iterator, const plString& ageToRestrictTo)
{
ILockPages();
@ -1771,7 +1770,7 @@ bool plResManager::IteratePages(plRegistryPageIterator* iterator, const char* ag
if (page->GetPageInfo().GetLocation() == plLocation::kGlobalFixedLoc)
continue;
if (!ageToRestrictTo || stricmp(page->GetPageInfo().GetAge(), ageToRestrictTo) == 0)
if (!ageToRestrictTo.IsNull() || page->GetPageInfo().GetAge().CompareI(ageToRestrictTo) == 0)
{
if (!iterator->EatPage(page))
{

View File

@ -155,7 +155,7 @@ public:
// Single page version
bool IterateKeys(plRegistryKeyIterator* iterator, const plLocation& pageToRestrictTo);
// Iterate through loaded pages
bool IteratePages(plRegistryPageIterator* iterator, const char* ageToRestrictTo = nil);
bool IteratePages(plRegistryPageIterator* iterator, const plString& ageToRestrictTo = nil);
// Iterate through ALL pages, loaded or not
bool IterateAllPages(plRegistryPageIterator* iterator);
@ -164,7 +164,7 @@ public:
void UnloadPageObjects(plRegistryPageNode* pageNode, uint16_t classIndexHint);
void DumpUnusedKeys(plRegistryPageNode* page) const;
plRegistryPageNode* FindPage(const plLocation& location) const;
plRegistryPageNode* FindPage(const char* age, const char* page) const;
plRegistryPageNode* FindPage(const plString& age, const plString& page) const;
// Runs through all the pages and verifies that the data versions are good
bool VerifyPages();

View File

@ -183,10 +183,10 @@ void plResManagerHelper::LoadAndHoldPageKeys( plRegistryPageNode *page )
// Load and ref the keys
#ifdef HS_DEBUGGING
char msg[ 256 ];
sprintf( msg, "*** Temporarily loading keys for room %s>%s based on FindKey() query, will drop in 1 sec ***", page->GetPageInfo().GetAge(), page->GetPageInfo().GetPage() );
sprintf( msg, "*** Temporarily loading keys for room %s>%s based on FindKey() query, will drop in 1 sec ***", page->GetPageInfo().GetAge().c_str(), page->GetPageInfo().GetPage().c_str());
hsStatusMessage( msg );
#endif
kResMgrLog( 2 ) 0xff80ff80, "Temporarily loading keys for room %s>%s, will drop in 1 sec", page->GetPageInfo().GetAge(), page->GetPageInfo().GetPage() );
kResMgrLog( 2 ) 0xff80ff80, "Temporarily loading keys for room %s>%s, will drop in 1 sec", page->GetPageInfo().GetAge().c_str(), page->GetPageInfo().GetPage().c_str());
// Deliver the message to ourselves!
refferMsg->SetTimeStamp( hsTimer::GetSysSeconds() + 1.f );
@ -359,7 +359,7 @@ class plDebugPrintIterator : public plRegistryPageIterator, plRegistryKeyIterato
fHoldingCount++;
// Changed ages?
if( page == nil || strcmp( fCurrAge, page->GetPageInfo().GetAge() ) != 0 )
if( page == nil || page->GetPageInfo().GetAge() != fCurrAge )
{
// Print some info for the last age we were on
if( fCurrAge[ 0 ] != 0 )
@ -385,7 +385,7 @@ class plDebugPrintIterator : public plRegistryPageIterator, plRegistryKeyIterato
}
fPageCount = 0;
if( page != nil )
strncpy( fCurrAge, page->GetPageInfo().GetAge(), sizeof( fCurrAge ) - 1 );
strncpy( fCurrAge, page->GetPageInfo().GetAge().c_str(), sizeof( fCurrAge ) - 1 );
else
fCurrAge[ 0 ] = 0;
@ -417,9 +417,9 @@ class plDebugPrintIterator : public plRegistryPageIterator, plRegistryKeyIterato
if( fLines < kLogSize - 4 )
{
if( fParent->fDebugDisplayType == plResManagerHelper::kSizes )
fLog->AddLineF( plStatusLog::kWhite, " %s (%d keys @ %4.1fk, %d loaded @ %4.1fk)", page->GetPageInfo().GetPage(), fTotalKeys, fTotalSize / 1024.f, fLoadedKeys, fLoadedSize / 1024.f );
fLog->AddLineF( plStatusLog::kWhite, " %s (%d keys @ %4.1fk, %d loaded @ %4.1fk)", page->GetPageInfo().GetPage().c_str(), fTotalKeys, fTotalSize / 1024.f, fLoadedKeys, fLoadedSize / 1024.f );
else if( fParent->fDebugDisplayType == plResManagerHelper::kPercents )
fLog->AddLineF( plStatusLog::kWhite, " %s (%d%% loaded of %d keys @ %4.1fk)", page->GetPageInfo().GetPage(), fLoadedSize * 100 / ( fTotalSize > 0 ? fTotalSize : -1 ), fTotalKeys, fTotalSize / 1024.f );
fLog->AddLineF( plStatusLog::kWhite, " %s (%d%% loaded of %d keys @ %4.1fk)", page->GetPageInfo().GetPage().c_str(), fLoadedSize * 100 / ( fTotalSize > 0 ? fTotalSize : -1 ), fTotalKeys, fTotalSize / 1024.f );
else //if( fParent->fDebugDisplayType == plResManagerHelper::kBars )
{
const int startPos = 20, length = 32;
@ -427,10 +427,10 @@ class plDebugPrintIterator : public plRegistryPageIterator, plRegistryKeyIterato
char line[ 128 ];
memset( line, ' ', sizeof( line ) - 1 );
line[ 127 ] = 0;
if( strlen( page->GetPageInfo().GetPage() ) < startPos - 2 )
memcpy( line + 2, page->GetPageInfo().GetPage(), strlen( page->GetPageInfo().GetPage() ) );
if(page->GetPageInfo().GetPage().GetSize() < startPos - 2 )
memcpy( line + 2, page->GetPageInfo().GetPage().c_str(), page->GetPageInfo().GetPage().GetSize() );
else
memcpy( line + 2, page->GetPageInfo().GetPage(), startPos - 2 );
memcpy( line + 2, page->GetPageInfo().GetPage().c_str(), startPos - 2 );
line[ startPos ] = '|';
if( fTotalSize == 0 )
@ -490,13 +490,12 @@ void plResManagerHelper::IUpdateDebugScreen( bool force )
if( !fRefreshing )
return;
plRegistry *reg = fResManager->IGetRegistry();
uint32_t loadedCnt, holdingCnt;
fDebugScreen->Clear();
plDebugPrintIterator iter( this, fDebugScreen, loadedCnt, holdingCnt );
reg->IterateAllPages( &iter );
fResManager->IterateAllPages( &iter );
iter.EatPage( nil ); // Force a final update
fDebugScreen->AddLineF( plStatusLog::kGreen, "%d pages loaded, %d holding", loadedCnt, holdingCnt );