Browse Source

Merge pull request #259 from zrax/plFileName

Add plFileName
Adam Johnson 12 years ago
parent
commit
13489eb1bb
  1. 2
      Doxyfile
  2. 2
      Sources/Plasma/CoreLib/hsStream.h
  3. 88
      Sources/Plasma/CoreLib/plString.cpp
  4. 78
      Sources/Plasma/CoreLib/plString.h
  5. 2
      Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp
  6. 2
      Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
  7. 2
      Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp
  8. 13
      Sources/Plasma/PubUtilLib/plFile/hsFiles.h
  9. 2
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  10. 2
      Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp
  11. 2
      Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.h
  12. 2
      Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp
  13. 8
      Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp
  14. 7
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  15. 2
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

2
Doxyfile

@ -353,7 +353,7 @@ TYPEDEF_HIDES_STRUCT = NO
# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
# corresponding to a cache size of 2^16 = 65536 symbols.
SYMBOL_CACHE_SIZE = 0
SYMBOL_CACHE_SIZE = 4
# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be
# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given

2
Sources/Plasma/CoreLib/hsStream.h

@ -84,7 +84,7 @@ public:
virtual ~hsStream() { }
// Pre-filename-stringification shortcut:
bool Open_TEMP(const plString & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
bool Open_TEMP(const plFileName & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
virtual bool Open(const char *, const char * = "rb")=0;
virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0;

88
Sources/Plasma/CoreLib/plString.cpp

@ -877,3 +877,91 @@ size_t ustrlen(const UniChar *ustr, size_t max)
;
return length;
}
/* plFileName */
plString plFileName::GetFileName() const
{
int end = FindLast('/');
if (end < 0)
end = FindLast('\\');
if (end < 0)
return *this;
return Substr(end + 1);
}
plString plFileName::GetFileExt() const
{
int dot = FindLast('.');
// Be sure not to get a dot in the directory!
int end = FindLast('/');
if (end < 0)
end = FindLast('\\');
if (dot > end)
return Substr(dot + 1);
return plString::Null;
}
plString plFileName::GetFileNameNoExt() const
{
int dot = FindLast('.');
int end = FindLast('/');
if (end < 0)
end = FindLast('\\');
// Be sure not to get a dot in the directory!
if (dot > end)
return Substr(end + 1, dot - end - 1);
return Substr(end + 1);
}
plFileName plFileName::StripFileName() const
{
int end = FindLast('/');
if (end < 0)
end = FindLast('\\');
if (end < 0)
return *this;
return Left(end);
}
plFileName plFileName::StripFileExt() const
{
int dot = FindLast('.');
// Be sure not to get a dot in the directory!
int end = FindLast('/');
if (end < 0)
end = FindLast('\\');
if (dot > end)
return Left(dot);
return *this;
}
plFileName plFileName::Join(const plFileName &base, const plFileName &path)
{
if (base.IsEmpty())
return path;
if (path.IsEmpty())
return base;
char last = base.CharAt(base.GetSize() - 1);
char first = path.CharAt(0);
if (last != '/' && last != '\\') {
if (first != '/' && first != '\\')
return plString::Format("%s" PATH_SEPARATOR_STR "%s", base.c_str(), path.c_str());
return base + path;
} else if (first != '/' && first != '\\') {
return base + path;
}
// Both have a slash, but we only need one
return base + path.Substr(1);
}

78
Sources/Plasma/CoreLib/plString.h

@ -660,4 +660,82 @@ private:
/** \p strlen implementation for UniChar based C-style string buffers. */
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
#else
# define PATH_SEPARATOR '/'
# define PATH_SEPARATOR_STR "/"
#endif
/** Subclass of plString with specific methods to help deal with common
* filename manipulation tasks.
*/
class plFileName : public plString
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : plString(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString &copy) : plString(copy) { }
/** Copy constructor. */
plFileName(const plFileName &copy) : plString(copy) { }
/** Return the name portion of the path (including extension).
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename.ext"</pre>
*/
plString GetFileName() const;
/** Return the file extension from the filename.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "ext"</pre>
*/
plString GetFileExt() const;
/** Return the name portion of the path, excluding its extension.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename"</pre>
*/
plString GetFileNameNoExt() const;
/** Return the path with the filename portion stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path"</pre>
*/
plFileName StripFileName() const;
/** Return the filename with the extension stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path\\Filename"</pre>
*/
plFileName StripFileExt() const;
/** Join two path components together with the correct path separator.
* For example:
* <pre>plFileName::Join("C:\\Path", "Filename.ext") => "C:\\Path\\Filename.ext"</pre>
*/
static plFileName Join(const plFileName &base, const plFileName &path);
/** Join three path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2)
{ return Join(Join(base, path), path2); }
/** Join four path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
};
#endif //plString_Defined

2
Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp

@ -275,7 +275,7 @@ void plSoundBuffer::Write( hsStream *s, hsResMgr *mgr )
s->WriteSafeString( fFileName );
}
else
s->WriteSafeString( nil );
s->WriteSafeString( "" );
s->WriteLE( fHeader.fFormatTag );
s->WriteLE( fHeader.fNumChannels );

2
Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp

@ -1735,7 +1735,7 @@ void plArmatureMod::Write(hsStream *stream, hsResMgr *mgr)
stream->WriteLEFloat(fPhysHeight);
stream->WriteLEFloat(fPhysWidth);
stream->WriteSafeString(fAnimationPrefix.c_str());
stream->WriteSafeString(fAnimationPrefix);
stream->WriteSafeString(fBodyAgeName.c_str());
stream->WriteSafeString(fBodyFootstepSoundPage.c_str());
}

2
Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp

@ -1116,7 +1116,7 @@ bool plWWWAuthenticateConfigSource::ReadInto(plConfigInfo & configInfo, KAddValu
end = i;
plString buf = fAuth.Substr(begin, end-begin);
if(!ReadString(buf.c_str()))
if (!ReadString(buf))
{
// TODO log warning here
}

13
Sources/Plasma/PubUtilLib/plFile/hsFiles.h

@ -54,19 +54,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define WPATH_SEPARATOR L'\\'
# define PATH_SEPARATOR_STR "\\"
# define WPATH_SEPARATOR_STR L"\\"
#elif HS_BUILD_FOR_UNIX
# define PATH_SEPARATOR '/'
# define WPATH_SEPARATOR L'/'
# define PATH_SEPARATOR_STR "/"
# define WPATH_SEPARATOR_STR L"/"
#endif
///////////////////////////////////////////////////////////////////////
class hsFile {

2
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -601,7 +601,7 @@ static void INetCliAuthAgeRequestCallback (
LogMsg(
kLogPerf,
L"Connecting to game server %s, ageInstId %s",
L"Connecting to game server %S, ageInstId %S",
gameAddrStr.c_str(),
ageInstIdStr.c_str()
);

2
Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp

@ -472,7 +472,7 @@ void D3DSURF_MEMDEL(IDirect3DCubeTexture9* cTex) {}
#endif // PLASMA_EXTERNAL_RELEASE
#ifndef PLASMA_EXTERNAL_RELEASE
void plDXPipeline::ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, char *id)
void plDXPipeline::ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const char *id)
{
switch( poolType )
{

2
Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.h

@ -709,7 +709,7 @@ public:
static void AllocManagedVertex(uint32_t sz) { fVtxManaged += sz; }
#ifndef PLASMA_EXTERNAL_RELEASE
static void ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, char *id);
static void ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const char *id);
#endif // PLASMA_EXTERNAL_RELEASE
// From a D3DFORMAT enumeration, return the bit depth associated with it.

2
Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp

@ -310,7 +310,7 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
}
}
DebugMsg((char*)dbgStr.c_str());
DebugMsg(dbgStr.c_str());
return skipNext;
}

8
Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp

@ -116,7 +116,7 @@ void plStateVarNotificationInfo::Write(hsStream* s, uint32_t writeOptions) const
{
uint8_t saveFlags=0; // unused
s->WriteLE(saveFlags);
s->WriteSafeString(fHintString.c_str());
s->WriteSafeString(fHintString);
}
/////////////////////////////////////////////////////
@ -2325,7 +2325,7 @@ void plSimpleStateVariable::DumpToStream(hsStream* stream, bool dirtyOnly, int l
plString logMsg = plString::Format( "%sSimpleVar, name:%s[%d]", pad.c_str(), GetName().c_str(), GetCount());
if (GetCount()>1)
{
stream->WriteString(logMsg.c_str()); // it's going to be a long msg, so print it on its own line
stream->WriteString(logMsg); // it's going to be a long msg, so print it on its own line
logMsg = "";
}
@ -2348,7 +2348,7 @@ void plSimpleStateVariable::DumpToStream(hsStream* stream, bool dirtyOnly, int l
if ( !dirtyOnly )
logMsg += plString::Format( " dirty:%d", IsDirty() );
stream->WriteString(logMsg.c_str());
stream->WriteString(logMsg);
logMsg = "";
}
}
@ -2704,7 +2704,7 @@ void plSDStateVariable::DumpToStream(hsStream* stream, bool dirtyOnly, int level
int cnt = dirtyOnly ? GetDirtyCount() : GetUsedCount();
stream->WriteString(plString::Format( "%sSDVar, name:%s dirtyOnly:%d count:%d",
pad.c_str(), GetName().c_str(), dirtyOnly, cnt).c_str());
pad.c_str(), GetName().c_str(), dirtyOnly, cnt));
for(i=0;i<GetCount();i++)
{

7
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -145,13 +145,13 @@ void plStatusLogMgr::IPathAppend( wchar_t *base, const wchar_t *extra, unsign
bool needsSeparator = false;
if (baseLen >= 1)
needsSeparator = (base[baseLen - 1] != WPATH_SEPARATOR);
needsSeparator = (base[baseLen - 1] != PATH_SEPARATOR);
if (needsSeparator)
{
if ((baseLen + 1 + 1) >= maxLen)
return; // abort, buffer isn't big enough
base[baseLen] = WPATH_SEPARATOR;
base[baseLen] = PATH_SEPARATOR;
++baseLen;
base[baseLen] = '\0';
}
@ -533,12 +533,11 @@ void plStatusLog::IFini( void )
delete [] fColors;
}
void plStatusLog::IParseFileName(wchar_t* file, size_t fnsize, wchar_t* fileNoExt, wchar_t** ext) const
{
const wchar_t *base = plStatusLogMgr::IGetBasePath();
if( wcslen( base ) != nil )
hsSnwprintf( file, fnsize, L"%s%s%s", base, WPATH_SEPARATOR_STR, fFilename.c_str() );
hsSnwprintf( file, fnsize, L"%s%S%s", base, PATH_SEPARATOR_STR, fFilename.c_str() );
else
wcscpy( file, fFilename.c_str() );

2
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

@ -455,7 +455,7 @@ void VaultAgeLinkNode::AddSpawnPoint (const plSpawnPointInfo & point) {
plSpawnPointVec points;
GetSpawnPoints( &points );
if ( std::find_if( points.begin(), points.end(), MatchesSpawnPointTitle( point.fTitle.c_str() ) )!=points.end() )
if ( std::find_if( points.begin(), points.end(), MatchesSpawnPointTitle( point.fTitle ) )!=points.end() )
return;
// only check to see if the titles are the same...

Loading…
Cancel
Save