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

Merge pull request #275 from zrax/file-utils

Unify filesystem utilities
This commit is contained in:
2013-01-22 16:27:26 -08:00
148 changed files with 1545 additions and 4225 deletions

View File

@ -115,7 +115,7 @@ bool NameMatches(const char* obName, const char* pKName, bool subString)
return false;
}
plKey plKeyFinder::StupidSearch(const char * age, const char * rm,
plKey plKeyFinder::StupidSearch(const plString & age, const plString & rm,
const char *className, const plString &obName, bool subString)
{
uint16_t ty = plFactory::FindClassIndex(className);
@ -129,7 +129,7 @@ protected:
plString fObjName;
bool fSubstr;
plKey fFoundKey;
const char *fAgeName;
plString fAgeName;
public:
plKey GetFoundKey( void ) const { return fFoundKey; }
@ -137,7 +137,7 @@ public:
plKeyFinderIter( uint16_t classType, const plString &obName, bool substr )
: fFoundKey( nil ), fClassType( classType ), fObjName( obName ), fSubstr( substr ) { }
plKeyFinderIter( uint16_t classType, const plString &obName, bool substr, const char *ageName )
plKeyFinderIter( uint16_t classType, const plString &obName, bool substr, const plString &ageName )
: fFoundKey( nil ), fClassType( classType ), fObjName( obName ), fSubstr( substr ),
fAgeName( ageName ) {}
@ -180,7 +180,7 @@ public:
}
};
plKey plKeyFinder::StupidSearch(const char * age, const char * rm,
plKey plKeyFinder::StupidSearch(const plString & age, const plString & rm,
uint16_t classType, const plString &obName, bool subString)
{
if (obName.IsNull())
@ -196,9 +196,9 @@ plKey plKeyFinder::StupidSearch(const char * age, const char * rm,
if (ty == maxClasses) // error
{ fLastError = kInvalidClass;
return nil;
}
}
if( age != nil && rm != nil )
if (!age.IsNull() && !rm.IsNull())
{
const plLocation &loc = IGetResMgr()->FindLocation( age, rm );
if( !loc.IsValid() )
@ -213,7 +213,7 @@ plKey plKeyFinder::StupidSearch(const char * age, const char * rm,
// Return value of false means it stopped somewhere, i.e. found something
return keyFinder.GetFoundKey();
}
else if( age != nil )
else if (!age.IsNull())
{
plKeyFinderIter keyFinder(classType, obName, subString, age);
@ -335,23 +335,22 @@ class plPageFinder : public plRegistryPageIterator
protected:
plRegistryPageNode **fPagePtr;
const char *fFindString, *fAgeString;
plString fFindString, fAgeString;
public:
plPageFinder( plRegistryPageNode **page, const char *find ) : fPagePtr( page ), fFindString( find ), fAgeString( nil )
plPageFinder( plRegistryPageNode **page, const plString &find ) : fPagePtr( page ), fFindString( find )
{ *fPagePtr = nil; }
plPageFinder( plRegistryPageNode **page, const char *ageS, const char *pageS ) : fPagePtr( page ), fFindString( pageS ), fAgeString( ageS )
plPageFinder( plRegistryPageNode **page, const plString &ageS, const plString &pageS ) : fPagePtr( page ), fFindString( pageS ), fAgeString( ageS )
{ *fPagePtr = nil; }
virtual bool EatPage( plRegistryPageNode *node )
{
static char str[ 512 ];
const plPageInfo &info = node->GetPageInfo();
// Are we searching by age/page?
if( fAgeString != nil )
if (!fAgeString.IsNull())
{
if (info.GetAge().CompareI(fAgeString) == 0 && info.GetPage().CompareI(fFindString) == 0)
{
@ -369,8 +368,7 @@ class plPageFinder : public plRegistryPageIterator
}
// Try for full location
sprintf( str, "%s_%s", info.GetAge().c_str(), info.GetPage().c_str() );
if( stricmp( str, fFindString ) == 0 )
if (plString::Format("%s_%s", info.GetAge().c_str(), info.GetPage().c_str()).CompareI(fFindString) == 0)
{
*fPagePtr = node;
return false;
@ -387,7 +385,7 @@ class plPageFinder : public plRegistryPageIterator
// since the only time we call this function will be to actually load
// the darned thing.
plKey plKeyFinder::FindSceneNodeKey( const char *pageOrFullLocName ) const
plKey plKeyFinder::FindSceneNodeKey( const plString &pageOrFullLocName ) const
{
plRegistryPageNode *pageNode;
plPageFinder pageFinder( &pageNode, pageOrFullLocName );
@ -404,7 +402,7 @@ plKey plKeyFinder::FindSceneNodeKey( const char *pageOrFullLocName ) const
//// FindSceneNodeKey ////////////////////////////////////////////////////////
// Age/page pair version
plKey plKeyFinder::FindSceneNodeKey( const char *ageName, const char *pageName ) const
plKey plKeyFinder::FindSceneNodeKey( const plString &ageName, const plString &pageName ) const
{
plRegistryPageNode *pageNode;
plPageFinder pageFinder( &pageNode, ageName, pageName );
@ -471,12 +469,12 @@ plKey plKeyFinder::IFindSceneNodeKey(plRegistryPageNode* page) const
//// FindLocation ////////////////////////////////////////////////////////////
const plLocation &plKeyFinder::FindLocation( const char *age, const char *page ) const
const plLocation &plKeyFinder::FindLocation(const plString &age, const plString &page) const
{
if (age == nil)
if (age == "")
{
static plLocation invalidLoc;
plRegistryPageNode *pageNode;
plRegistryPageNode *pageNode;
plPageFinder pageFinder( &pageNode, page );
if( IGetResMgr()->IterateAllPages( &pageFinder ) || pageNode == nil )

View File

@ -88,8 +88,8 @@ public:
static plKeyFinder& Instance();
// These are Stupid search because they just do string searchs on the objects.
plKey StupidSearch(const char * age, const char * rm, const char *className, const plString &obName, bool subString=false);
plKey StupidSearch(const char * age, const char * rm, uint16_t objType, const plString &obName, bool subString=false);
plKey StupidSearch(const plString & age, const plString & rm, const char *className, const plString &obName, bool subString=false);
plKey StupidSearch(const plString & age, const plString & rm, uint16_t objType, const plString &obName, bool subString=false);
eErrCodes GetLastErrorCode() { return fLastError; }
const char* GetLastErrorString(); // For Console display
@ -102,11 +102,11 @@ public:
void GetActivatorNames(std::vector<plString>& names);
void GetResponderNames(std::vector<plString>& names);
plKey FindSceneNodeKey(const char* pageOrFullLocName) const;
plKey FindSceneNodeKey(const char* ageName, const char* pageName) const;
plKey FindSceneNodeKey(const plString& pageOrFullLocName) const;
plKey FindSceneNodeKey(const plString& ageName, const plString& pageName) const;
plKey FindSceneNodeKey(const plLocation& location) const;
const plLocation& FindLocation(const char* age, const char* page) const;
const plLocation& FindLocation(const plString& age, const plString& page) const;
const plPageInfo* GetLocationInfo(const plLocation& loc) const;
protected:

View File

@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "plLocalization.h"
#include "plFile/plFileUtils.h"
plLocalization::Language plLocalization::fLanguage = plLocalization::kEnglish;
@ -87,36 +86,28 @@ plLocalization::encodingTypes plLocalization::fUnicodeEncoding[] =
Enc_UTF8, // kJapanese
};
bool plLocalization::IGetLocalized(const char* name, Language lang, char* localizedName)
plFileName plLocalization::IGetLocalized(const plFileName& name, Language lang)
{
const char* underscore = strrchr(name, '_');
if (underscore)
{
char langTag[kLangTagLen+1];
strncpy(langTag,underscore,kLangTagLen);
langTag[kLangTagLen] = '\0';
if (strncmp(langTag, fLangTags[kEnglish], kLangTagLen) == 0)
{
if (localizedName)
{
strcpy(localizedName, name);
int underscorePos = underscore - name;
memcpy(localizedName + underscorePos, fLangTags[lang], kLangTagLen);
}
int underscore = name.AsString().FindLast('_');
return true;
}
if (underscore >= 0)
{
plString langTag = name.AsString().Substr(underscore, kLangTagLen);
if (langTag == fLangTags[kEnglish])
return name.AsString().Left(underscore) + fLangTags[lang];
}
return false;
return "";
}
bool plLocalization::ExportGetLocalized(const char* name, int lang, char* localizedName)
plFileName plLocalization::ExportGetLocalized(const plFileName& name, int lang)
{
return IGetLocalized(name, Language(lang+1), localizedName) &&
plFileUtils::FileExists(localizedName);
plFileName localizedName = IGetLocalized(name, Language(lang+1));
if (plFileInfo(localizedName).Exists())
return localizedName;
return "";
}
std::string plLocalization::LocalToString(const std::vector<std::string> & localizedText)

View File

@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <vector>
#include <string>
#include "plFileSystem.h"
class plLocalization
{
@ -81,7 +82,7 @@ protected:
static bool fUsesUnicode[kNumLanguages];
static encodingTypes fUnicodeEncoding[kNumLanguages];
static bool IGetLocalized(const char* name, Language lang, char* localizedName);
static plFileName IGetLocalized(const plFileName& name, Language lang);
public:
static void SetLanguage(Language lang) { fLanguage = lang; }
@ -97,8 +98,8 @@ public:
static bool IsLocalized() { return fLanguage != kEnglish; }
// Pass in a key name and this will give you the localized name
// Returns false if the original keyname is not for a localized asset
static bool GetLocalized(const char* name, char* localizedName) { return IGetLocalized(name, fLanguage, localizedName); }
// Returns an invalid filename if the original keyname is not for a localized asset
static plFileName GetLocalized(const plFileName& name) { return IGetLocalized(name, fLanguage); }
//
// Export only
@ -116,9 +117,9 @@ public:
// }
//
static int GetNumLocales() { return kNumLanguages - 1; }
static bool ExportGetLocalized(const char* name, int lang, char* localizedName);
static plFileName ExportGetLocalized(const plFileName& name, int lang);
// Just tells us if this is localized, doesn't actually convert it for us
static bool IsLocalizedName(const char* name) { return IGetLocalized(name, kEnglish, nil); }
static bool IsLocalizedName(const plFileName& name) { return IGetLocalized(name, kEnglish).IsValid(); }
// Converts a vector of translated strings to a encoded string that can be decoded by StringToLocal()
// The index in the vector of a string is it's language

View File

@ -47,8 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plKeyImp.h"
#include "plStatusLog/plStatusLog.h"
#include "pnFactory/plFactory.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plVersion.h"

View File

@ -59,8 +59,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnMessage/plObjRefMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "pnMessage/plClientMsg.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "pnFactory/plCreator.h"
#include "pnNetCommon/plSynchedObject.h"
#include "pnNetCommon/plNetApp.h"
@ -131,13 +129,10 @@ bool plResManager::IInit()
{
// We want to go through all the data files in our data path and add new
// plRegistryPageNodes to the regTree for each
hsFolderIterator pathIterator(fDataPath.c_str());
while (pathIterator.NextFileSuffix(".prp"))
std::vector<plFileName> prpFiles = plFileSystem::ListDir(fDataPath, "*.prp");
for (auto iter = prpFiles.begin(); iter != prpFiles.end(); ++iter)
{
char fileName[kFolderIterator_MaxPath];
pathIterator.GetPathAndName(fileName);
plRegistryPageNode* node = new plRegistryPageNode(fileName);
plRegistryPageNode* node = new plRegistryPageNode(*iter);
plPageInfo pi = node->GetPageInfo();
fAllPages[pi.GetLocation()] = node;
}
@ -517,10 +512,10 @@ inline plKeyImp* IFindKeyLocalized(const plUoid& uoid, plRegistryPageNode* page)
// If we're running localized, try to find a localized version first
if ((!objectName.IsNull()) && plLocalization::IsLocalized())
{
char localName[256];
if (plLocalization::GetLocalized(objectName.c_str(), localName))
plFileName localName = plLocalization::GetLocalized(objectName.c_str());
if (localName.IsValid())
{
plKeyImp* localKey = page->FindKey(uoid.GetClassType(), localName);
plKeyImp* localKey = page->FindKey(uoid.GetClassType(), localName.AsString());
if (localKey != nil)
return localKey;
}
@ -585,7 +580,7 @@ plKey plResManager::FindKey(const plUoid& uoid)
return key;
}
const plLocation& plResManager::FindLocation(const char* age, const char* page) const
const plLocation& plResManager::FindLocation(const plString& age, const plString& page) const
{
static plLocation invalidLoc;
@ -596,16 +591,16 @@ const plLocation& plResManager::FindLocation(const char* age, const char* page)
return invalidLoc;
}
void plResManager::GetLocationStrings(const plLocation& loc, char* ageBuffer, char* pageBuffer) const
void plResManager::GetLocationStrings(const plLocation& loc, plString* ageBuffer, plString* pageBuffer) const
{
plRegistryPageNode* page = FindPage(loc);
const plPageInfo& info = page->GetPageInfo();
// Those buffers better be big enough...
if (ageBuffer)
hsStrcpy(ageBuffer, info.GetAge().c_str());
*ageBuffer = info.GetAge();
if (pageBuffer)
hsStrcpy(pageBuffer, info.GetPage().c_str());
*pageBuffer = info.GetPage();
}
bool plResManager::AddViaNotify(plRefMsg* msg, plRefFlags::Type flags)
@ -996,10 +991,10 @@ class plResAgeHolder : public hsRefCnt
{
public:
hsTArray<plKey> fKeys;
std::string fAge;
plString fAge;
plResAgeHolder() {}
plResAgeHolder( const char* age ) : fAge( age ) {}
plResAgeHolder( const plString& age ) : fAge( age ) {}
~plResAgeHolder() { fKeys.Reset(); }
};
@ -1009,11 +1004,11 @@ class plResHolderIterator : public plRegistryPageIterator
{
protected:
hsTArray<plKey>& fKeys;
const char* fAgeName;
plString fAgeName;
plResManager* fResMgr;
public:
plResHolderIterator(const char* age, hsTArray<plKey>& keys, plResManager* resMgr)
plResHolderIterator(const plString& age, hsTArray<plKey>& keys, plResManager* resMgr)
: fAgeName(age), fKeys(keys), fResMgr(resMgr) {}
virtual bool EatPage(plRegistryPageNode* page)
@ -1031,21 +1026,21 @@ public:
//// LoadAndHoldAgeKeys //////////////////////////////////////////////////////
void plResManager::LoadAgeKeys(const char* age)
void plResManager::LoadAgeKeys(const plString& age)
{
hsAssert(age && age[0] != '\0', "age is nil");
hsAssert(!age.IsEmpty(), "age is nil");
HeldAgeKeyMap::const_iterator it = fHeldAgeKeys.find(age);
if (it != fHeldAgeKeys.end())
{
kResMgrLog(1, ILog(1, "Reffing age keys for age %s", age));
hsStatusMessageF("*** Reffing age keys for age %s ***\n", age);
kResMgrLog(1, ILog(1, "Reffing age keys for age %s", age.c_str()));
hsStatusMessageF("*** Reffing age keys for age %s ***\n", age.c_str());
plResAgeHolder* holder = it->second;
holder->Ref();
}
else
{
kResMgrLog(1, ILog(1, "Loading age keys for age %s", age));
hsStatusMessageF("*** Loading age keys for age %s ***\n", age);
kResMgrLog(1, ILog(1, "Loading age keys for age %s", age.c_str()));
hsStatusMessageF("*** Loading age keys for age %s ***\n", age.c_str());
plResAgeHolder* holder = new plResAgeHolder(age);
fHeldAgeKeys[age] = holder;
@ -1057,7 +1052,7 @@ void plResManager::LoadAgeKeys(const char* age)
//// DropAgeKeys /////////////////////////////////////////////////////////////
void plResManager::DropAgeKeys(const char* age)
void plResManager::DropAgeKeys(const plString& age)
{
HeldAgeKeyMap::iterator it = fHeldAgeKeys.find(age);
if (it != fHeldAgeKeys.end())
@ -1066,12 +1061,12 @@ void plResManager::DropAgeKeys(const char* age)
if (holder->RefCnt() == 1)
{
// Found it!
kResMgrLog(1, ILog(1, "Dropping held age keys for age %s", age));
kResMgrLog(1, ILog(1, "Dropping held age keys for age %s", age.c_str()));
fHeldAgeKeys.erase(it);
}
else
{
kResMgrLog(1, ILog(1, "Unreffing age keys for age %s", age));
kResMgrLog(1, ILog(1, "Unreffing age keys for age %s", age.c_str()));
}
holder->UnRef();
@ -1236,11 +1231,11 @@ class plPageInAgeIter : public plRegistryPageIterator
{
private:
plKey fDestKey;
const char* fAgeName;
plString fAgeName;
std::vector<plLocation> fLocations;
public:
plPageInAgeIter(plKey destKey, const char *ageName) : fDestKey(destKey), fAgeName(ageName) {}
plPageInAgeIter(plKey destKey, const plString &ageName) : fDestKey(destKey), fAgeName(ageName) {}
~plPageInAgeIter()
{
plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoomHold);
@ -1263,7 +1258,7 @@ public:
// PageInAge is intended for bulk global ages, like GlobalAnimations or GlobalClothing
// that store a lot of data we always want available. (Used to be known as PageInHold)
void plResManager::PageInAge(const char *age)
void plResManager::PageInAge(const plString &age)
{
plSynchEnabler ps(false); // disable dirty tracking while paging in
plUoid lu(kClient_KEY);
@ -1492,9 +1487,9 @@ void plResManager::DumpUnusedKeys(plRegistryPageNode* page) const
page->IterateKeys(&reffer);
}
plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const char* age, const char* page)
plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const plString& age, const plString& page)
{
plRegistryPageNode* pageNode = new plRegistryPageNode(location, age, page, fDataPath.c_str());
plRegistryPageNode* pageNode = new plRegistryPageNode(location, age, page, fDataPath);
fAllPages[location] = pageNode;
return pageNode;

View File

@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <map>
#include <vector>
#include <string>
#include "plFileSystem.h"
class plRegistryPageNode;
class plRegistryKeyIterator;
@ -55,7 +56,6 @@ 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.
@ -68,7 +68,7 @@ public:
virtual ~plResManager();
// If the ResManager has already been initialized, you should call Reset after setting this
void SetDataPath(const char* path) { fDataPath = path; }
void SetDataPath(const plFileName& path) { fDataPath = path; }
// Mainly for external tools.
void AddSinglePage(const plFileName& path);
@ -87,9 +87,9 @@ public:
//---------------------------
plKey FindOriginalKey(const plUoid&);
virtual plKey FindKey(const plUoid&); // Same as above, but will check the uoid for clones
const plLocation& FindLocation(const char* age, const char* page) const;
const plLocation& FindLocation(const plString& age, const plString& page) const;
// Use nil for any strings you don't need
void GetLocationStrings(const plLocation& loc, char* ageBuffer, char* pageBuffer) const;
void GetLocationStrings(const plLocation& loc, plString* ageBuffer, plString* pageBuffer) const;
//---------------------------
// Establish reference linkage
@ -134,10 +134,10 @@ public:
//---------------------------
// Load optimizations
//---------------------------
void LoadAgeKeys(const char* age);
void DropAgeKeys(const char* age);
void LoadAgeKeys(const plString& age);
void DropAgeKeys(const plString& age);
void PageInRoom(const plLocation& page, uint16_t objClassToRef, plRefMsg* refMsg);
void PageInAge(const char* age);
void PageInAge(const plString& age);
// Usually, a page file is kept open during load because the first keyed object
// read causes all the other objects to be read before it returns. In some
@ -152,7 +152,7 @@ public:
void LogReadTimes(bool logReadTimes);
// All keys version
bool IterateKeys(plRegistryKeyIterator* iterator);
bool IterateKeys(plRegistryKeyIterator* iterator);
// Single page version
bool IterateKeys(plRegistryKeyIterator* iterator, const plLocation& pageToRestrictTo);
// Iterate through loaded pages
@ -185,7 +185,7 @@ protected:
virtual void IKeyReffed(plKeyImp* key);
virtual void IKeyUnreffed(plKeyImp* key);
virtual bool IReset();
virtual bool IReset();
virtual bool IInit();
virtual void IShutdown();
@ -207,7 +207,7 @@ protected:
// Adds a key to the registry. Assumes uoid already set
void AddKey(plKeyImp* key);
plRegistryPageNode* CreatePage(const plLocation& location, const char* age, const char* page);
plRegistryPageNode* CreatePage(const plLocation& location, const plString& age, const plString& page);
bool fInited;
@ -215,7 +215,7 @@ protected:
bool fReadingObject;
std::vector<plKey> fQueuedReads;
std::string fDataPath;
plFileName fDataPath;
plDispatch* fDispatch;
@ -223,7 +223,7 @@ protected:
uint32_t fCurClonePlayerID;
uint32_t fCloningCounter; // Next clone ID to use.
typedef std::map<std::string,plResAgeHolder*> HeldAgeKeyMap;
typedef std::map<plString, plResAgeHolder*> HeldAgeKeyMap;
HeldAgeKeyMap fHeldAgeKeys;
plProgressProc fProgressProc;