From 6f6ade26361ef590f912df9f42b3daf63d951b1c Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 17 Jan 2013 21:08:21 -0800 Subject: [PATCH] Replace hsStream::Open duplicated methods everywhere with a single plFileName interface --- Sources/Plasma/Apps/plClient/plClient.cpp | 59 ++++--- Sources/Plasma/Apps/plClient/plClient.h | 2 +- Sources/Plasma/Apps/plClient/winmain.cpp | 42 ++--- Sources/Plasma/Apps/plMD5/Main.cpp | 3 +- Sources/Plasma/Apps/plSHA/Main.cpp | 3 +- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 8 +- Sources/Plasma/CoreLib/hsSTLStream.h | 3 +- Sources/Plasma/CoreLib/hsStream.cpp | 34 +---- Sources/Plasma/CoreLib/hsStream.h | 35 ++--- Sources/Plasma/CoreLib/plString.h | 8 + .../Plasma/FeatureLib/pfConsole/pfConsole.cpp | 2 +- .../pfConsole/pfConsoleCommands.cpp | 4 +- .../FeatureLib/pfConsole/pfConsoleDirSrc.cpp | 39 ++--- .../FeatureLib/pfConsole/pfConsoleDirSrc.h | 27 ++-- .../pfConsoleCore/pfConsoleEngine.cpp | 21 +-- .../pfConsoleCore/pfConsoleEngine.h | 4 +- .../FeatureLib/pfCrashHandler/plCrashSrv.cpp | 13 +- .../FeatureLib/pfPython/plPythonPack.cpp | 15 +- .../Plasma/FeatureLib/pfPython/pyImage.cpp | 18 +-- Sources/Plasma/FeatureLib/pfPython/pyImage.h | 8 +- .../FeatureLib/pfPython/pyImageGlue.cpp | 47 ++---- .../Plasma/FeatureLib/pfPython/pyStream.cpp | 14 +- Sources/Plasma/FeatureLib/pfPython/pyStream.h | 3 +- .../FeatureLib/pfPython/pyStreamGlue.cpp | 41 +---- .../pfSecurePreloader/pfSecurePreloader.cpp | 70 +++------ .../pfSecurePreloader/pfSecurePreloader.h | 15 +- .../NucleusLib/pnEncryption/plChecksum.cpp | 12 +- .../NucleusLib/pnEncryption/plChecksum.h | 13 +- .../PubUtilLib/plAgeLoader/plAgeLoader.cpp | 4 +- .../PubUtilLib/plAgeLoader/plResPatcher.cpp | 86 +++++------ .../PubUtilLib/plAgeLoader/plResPatcher.h | 21 ++- .../plClientResMgr/plClientResMgr.cpp | 5 +- .../PubUtilLib/plCompression/plZlibStream.cpp | 16 +- .../PubUtilLib/plCompression/plZlibStream.h | 7 +- .../PubUtilLib/plFile/plEncryptedStream.cpp | 107 +++---------- .../PubUtilLib/plFile/plEncryptedStream.h | 22 +-- .../Plasma/PubUtilLib/plFile/plFileUtils.cpp | 2 +- .../PubUtilLib/plFile/plSecureStream.cpp | 144 ++++-------------- .../Plasma/PubUtilLib/plFile/plSecureStream.h | 30 ++-- .../PubUtilLib/plFile/plStreamSource.cpp | 131 ++++------------ .../Plasma/PubUtilLib/plFile/plStreamSource.h | 15 +- Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp | 24 +-- Sources/Plasma/PubUtilLib/plGImage/plJPEG.h | 7 +- Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp | 24 +-- Sources/Plasma/PubUtilLib/plGImage/plPNG.h | 6 +- .../plNetGameLib/Private/plNglAuth.cpp | 6 +- .../plNetGameLib/Private/plNglAuth.h | 10 +- .../plNetGameLib/Private/plNglFile.h | 8 +- .../PubUtilLib/plResMgr/plRegistryNode.cpp | 16 +- .../PubUtilLib/plResMgr/plRegistryNode.h | 9 +- .../PubUtilLib/plResMgr/plResManager.cpp | 16 +- .../Plasma/PubUtilLib/plResMgr/plResManager.h | 7 +- Sources/Plasma/PubUtilLib/plSDL/plSDL.h | 9 +- .../Plasma/PubUtilLib/plSDL/plSDLDescriptor.h | 13 +- .../Plasma/PubUtilLib/plSDL/plSDLParser.cpp | 81 +++++----- .../PubUtilLib/plStatGather/plAutoProfile.cpp | 21 +-- .../plStatGather/plProfileManagerFull.cpp | 49 +++--- .../plStatGather/plProfileManagerFull.h | 12 +- .../PubUtilLib/plStatusLog/plStatusLog.cpp | 17 +-- .../MaxComponent/plMultistageBehComponent.cpp | 7 +- 60 files changed, 511 insertions(+), 984 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index a1dc8e5c..bc51c341 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -231,13 +231,12 @@ plClient::plClient() plAgeLoader::SetInstance(new plAgeLoader); // Use it to parse the init directory - wchar_t initFolder[MAX_PATH]; - PathGetInitDirectory(initFolder, arrsize(initFolder)); - pfConsoleDirSrc dirSrc( fConsoleEngine, initFolder, L"*.ini" ); - + plFileName initFolder = plFileSystem::GetInitPath(); + pfConsoleDirSrc dirSrc(fConsoleEngine, initFolder, "*.ini"); + #ifndef PLASMA_EXTERNAL_RELEASE // internal builds also parse the local init folder - dirSrc.ParseDirectory( L"init", L"*.ini" ); + dirSrc.ParseDirectory("init", "*.ini"); #endif /// End of console stuff @@ -467,9 +466,7 @@ void plClient::InitInputs() void plClient::ISetGraphicsDefaults() { // couldn't find display mode set defaults write to ini file - wchar_t graphicsIniFile[MAX_PATH]; - PathGetInitDirectory(graphicsIniFile, arrsize(graphicsIniFile)); - PathAddFilename(graphicsIniFile, graphicsIniFile, L"graphics.ini", arrsize(graphicsIniFile)); + plFileName graphicsIniFile = plFileName::Join(plFileSystem::GetInitPath(), "graphics.ini"); IWriteDefaultGraphicsSettings(graphicsIniFile); plPipeline::fInitialPipeParams.Windowed = plPipeline::fDefaultPipeParams.Windowed; plPipeline::fInitialPipeParams.AntiAliasingAmount = plPipeline::fDefaultPipeParams.AntiAliasingAmount; @@ -1624,12 +1621,12 @@ void plClient::IPatchGlobalAgeFiles( void ) plResPatcher* patcher = plResPatcher::GetInstance(); if (!gDataServerLocal) { - patcher->RequestManifest(L"CustomAvatars"); - patcher->RequestManifest(L"GlobalAnimations"); - patcher->RequestManifest(L"GlobalAvatars"); - patcher->RequestManifest(L"GlobalClothing"); - patcher->RequestManifest(L"GlobalMarkers"); - patcher->RequestManifest(L"GUI"); + patcher->RequestManifest("CustomAvatars"); + patcher->RequestManifest("GlobalAnimations"); + patcher->RequestManifest("GlobalAvatars"); + patcher->RequestManifest("GlobalClothing"); + patcher->RequestManifest("GlobalMarkers"); + patcher->RequestManifest("GUI"); } plgDispatch::Dispatch()->RegisterForExactType(plResPatcherMsg::Index(), GetKey()); @@ -2344,18 +2341,15 @@ void plClient::IDetectAudioVideoSettings() int val = 0; hsStream *stream = nil; hsUNIXStream s; - wchar_t audioIniFile[MAX_PATH], graphicsIniFile[MAX_PATH]; - PathGetInitDirectory(audioIniFile, arrsize(audioIniFile)); - StrCopy(graphicsIniFile, audioIniFile, arrsize(audioIniFile)); - PathAddFilename(audioIniFile, audioIniFile, L"audio.ini", arrsize(audioIniFile)); - PathAddFilename(graphicsIniFile, graphicsIniFile, L"graphics.ini", arrsize(graphicsIniFile)); + plFileName audioIniFile = plFileName::Join(plFileSystem::GetInitPath(), "audio.ini"); + plFileName graphicsIniFile = plFileName::Join(plFileSystem::GetInitPath(), "graphics.ini"); #ifndef PLASMA_EXTERNAL_RELEASE // internal builds can use the local dir - if (PathDoesFileExist(L"init//audio.ini")) - StrCopy(audioIniFile, L"init//audio.ini", arrsize(audioIniFile)); - if (PathDoesFileExist(L"init//graphics.ini")) - StrCopy(graphicsIniFile, L"init//graphics.ini", arrsize(audioIniFile)); + if (plFileInfo("init//audio.ini").Exists()) + audioIniFile = "init//audio.ini"; + if (plFileInfo("init//graphics.ini").Exists()) + graphicsIniFile = "init//graphics.ini"; #endif //check to see if audio.ini exists @@ -2398,7 +2392,7 @@ void plClient::IDetectAudioVideoSettings() } } -void plClient::IWriteDefaultGraphicsSettings(const wchar_t* destFile) +void plClient::IWriteDefaultGraphicsSettings(const plFileName& destFile) { hsStream *stream = plEncryptedStream::OpenEncryptedFileWrite(destFile); @@ -2408,7 +2402,7 @@ void plClient::IWriteDefaultGraphicsSettings(const wchar_t* destFile) WriteBool(stream, "Graphics.Windowed", plPipeline::fDefaultPipeParams.Windowed); WriteInt(stream, "Graphics.AntiAliasAmount", plPipeline::fDefaultPipeParams.AntiAliasingAmount); WriteInt(stream, "Graphics.AnisotropicLevel", plPipeline::fDefaultPipeParams.AnisotropicLevel ); - WriteInt(stream, "Graphics.TextureQuality",plPipeline::fDefaultPipeParams.TextureQuality); + WriteInt(stream, "Graphics.TextureQuality", plPipeline::fDefaultPipeParams.TextureQuality); WriteInt(stream, "Quality.Level", plPipeline::fDefaultPipeParams.VideoQuality); WriteInt(stream, "Graphics.Shadow.Enable", plPipeline::fDefaultPipeParams.Shadows); WriteInt(stream, "Graphics.EnablePlanarReflections", plPipeline::fDefaultPipeParams.PlanarReflections); @@ -2487,25 +2481,24 @@ void plClient::IOnAsyncInitComplete () { /// Now parse final init files (*.fni). These are files just like ini files, only to be run /// after all hell has broken loose in the client. - wchar_t initFolder[MAX_PATH]; - PathGetInitDirectory(initFolder, arrsize(initFolder)); - pfConsoleDirSrc dirSrc( fConsoleEngine, initFolder, L"net*.fni" ); // connect to net first + plFileName initFolder = plFileSystem::GetInitPath(); + pfConsoleDirSrc dirSrc(fConsoleEngine, initFolder, "net*.fni"); // connect to net first #ifndef PLASMA_EXTERNAL_RELEASE // internal builds also parse the local init folder - dirSrc.ParseDirectory( L"init", L"net*.fni" ); + dirSrc.ParseDirectory("init", "net*.fni"); #endif - dirSrc.ParseDirectory( initFolder, L"*.fni" ); + dirSrc.ParseDirectory(initFolder, "*.fni"); #ifndef PLASMA_EXTERNAL_RELEASE // internal builds also parse the local init folder - dirSrc.ParseDirectory( L"init", L"*.fni" ); + dirSrc.ParseDirectory("init", "*.fni"); #endif // run fni in the Aux Init dir if (fpAuxInitDir) { - dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni" ); // connect to net first - dirSrc.ParseDirectory(fpAuxInitDir, "*.fni" ); + dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni"); // connect to net first + dirSrc.ParseDirectory(fpAuxInitDir, "*.fni"); } fNumLoadingRooms--; diff --git a/Sources/Plasma/Apps/plClient/plClient.h b/Sources/Plasma/Apps/plClient/plClient.h index 474e135d..cdc482c0 100644 --- a/Sources/Plasma/Apps/plClient/plClient.h +++ b/Sources/Plasma/Apps/plClient/plClient.h @@ -296,7 +296,7 @@ public: void ResetDisplayDevice(int Width, int Height, int ColorDepth, bool Windowed, int NumAASamples, int MaxAnisotropicSamples, bool VSync = false); void ResizeDisplayDevice(int Width, int Height, bool Windowed); void IDetectAudioVideoSettings(); - void IWriteDefaultGraphicsSettings(const wchar_t* destFile); + void IWriteDefaultGraphicsSettings(const plFileName& destFile); plAnimDebugList *fAnimDebugList; diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 5fee20ee..0575e6bc 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -843,17 +843,14 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) // FIXME: Real OS detection NetCommSetAuthTokenAndOS(nil, L"win"); - wchar_t fileAndPath[MAX_PATH]; - PathGetInitDirectory(fileAndPath, arrsize(fileAndPath)); - PathAddFilename(fileAndPath, fileAndPath, L"login.dat", arrsize(fileAndPath)); + plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat"); #ifndef PLASMA_EXTERNAL_RELEASE // internal builds can use the local init directory - wchar_t localFileAndPath[MAX_PATH]; - StrCopy(localFileAndPath, L"init\\login.dat", arrsize(localFileAndPath)); - if (PathDoesFileExist(localFileAndPath)) - StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath)); + plFileName local("init\\login.dat"); + if (plFileInfo(local).Exists()) + loginDat = local; #endif - hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(fileAndPath, cryptKey); + hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(loginDat, cryptKey); if (stream) { stream->Write(sizeof(cryptKey), cryptKey); @@ -877,17 +874,14 @@ static void LoadUserPass (LoginDialogParam *pLoginParam) pLoginParam->remember = false; pLoginParam->username[0] = '\0'; - wchar_t fileAndPath[MAX_PATH]; - PathGetInitDirectory(fileAndPath, arrsize(fileAndPath)); - PathAddFilename(fileAndPath, fileAndPath, L"login.dat", arrsize(fileAndPath)); + plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat"); #ifndef PLASMA_EXTERNAL_RELEASE // internal builds can use the local init directory - wchar_t localFileAndPath[MAX_PATH]; - StrCopy(localFileAndPath, L"init\\login.dat", arrsize(localFileAndPath)); - if (PathDoesFileExist(localFileAndPath)) - StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath)); + plFileName local("init\\login.dat"); + if (plFileInfo(local).Exists()) + loginDat = local; #endif - hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileAndPath, cryptKey); + hsStream* stream = plEncryptedStream::OpenEncryptedFile(loginDat, cryptKey); if (stream && !stream->AtEnd()) { uint32_t savedKey[4]; @@ -1062,9 +1056,7 @@ BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM // The code to write general.ini really doesn't belong here, but it works... for now. // When general.ini gets expanded, this will need to find a proper home somewhere. { - wchar_t gipath[MAX_PATH]; - PathGetInitDirectory(gipath, arrsize(gipath)); - PathAddFilename(gipath, gipath, L"general.ini", arrsize(gipath)); + plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini"); plString ini_str = plString::Format("App.SetLanguage %s\n", plLocalization::GetLanguageName(new_language)); hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath); gini->WriteString(ini_str); @@ -1215,9 +1207,9 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC gDataServerLocal = true; #endif - const wchar_t *serverIni = L"server.ini"; + plFileName serverIni = "server.ini"; if (cmdParser.IsSpecified(kArgServerIni)) - serverIni = cmdParser.GetString(kArgServerIni); + serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni)); // check to see if we were launched from the patcher bool eventExists = false; @@ -1272,10 +1264,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC #endif // Load an optional general.ini - wchar_t gipath[MAX_PATH]; - PathGetInitDirectory(gipath, arrsize(gipath)); - PathAddFilename(gipath, gipath, L"general.ini", arrsize(gipath)); - FILE *generalini = _wfopen(gipath, L"rb"); + plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini"); + FILE *generalini = plFileSystem::Open(gipath, "rb"); if (generalini) { fclose(generalini); @@ -1312,7 +1302,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC } #endif - FILE *serverIniFile = _wfopen(serverIni, L"rb"); + FILE *serverIniFile = plFileSystem::Open(serverIni, "rb"); if (serverIniFile) { fclose(serverIniFile); diff --git a/Sources/Plasma/Apps/plMD5/Main.cpp b/Sources/Plasma/Apps/plMD5/Main.cpp index e567e95b..02000986 100644 --- a/Sources/Plasma/Apps/plMD5/Main.cpp +++ b/Sources/Plasma/Apps/plMD5/Main.cpp @@ -42,10 +42,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plProduct.h" #include "pnEncryption/plChecksum.h" +#include "plFileSystem.h" #include -int main (int argc, char ** argv) { +int main (int argc, const char ** argv) { if (argc < 2) { fprintf(stderr, "ERROR: Please specify filename.\n"); diff --git a/Sources/Plasma/Apps/plSHA/Main.cpp b/Sources/Plasma/Apps/plSHA/Main.cpp index a463c1be..26d90cf1 100644 --- a/Sources/Plasma/Apps/plSHA/Main.cpp +++ b/Sources/Plasma/Apps/plSHA/Main.cpp @@ -42,10 +42,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plProduct.h" #include "pnEncryption/plChecksum.h" +#include "plFileSystem.h" #include -int main (int argc, char** argv) { +int main (int argc, const char** argv) { if (argc < 2) { fprintf(stderr, "ERROR: Please specify filename.\n"); diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 29152822..b4cbbda1 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -647,12 +647,12 @@ int __stdcall WinMain ( curl_global_init(CURL_GLOBAL_ALL); - const wchar_t *serverIni = L"server.ini"; - if(cmdParser.IsSpecified(kArgServerIni)) - serverIni = cmdParser.GetString(kArgServerIni); + plFileName serverIni = "server.ini"; + if (cmdParser.IsSpecified(kArgServerIni)) + serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni)); // Load the server.ini so we know what to connect to - FILE *serverini = _wfopen(serverIni, L"rb"); + FILE *serverini = plFileSystem::Open(serverIni, "rb"); if (serverini) { fclose(serverini); diff --git a/Sources/Plasma/CoreLib/hsSTLStream.h b/Sources/Plasma/CoreLib/hsSTLStream.h index 84add5da..45822b70 100644 --- a/Sources/Plasma/CoreLib/hsSTLStream.h +++ b/Sources/Plasma/CoreLib/hsSTLStream.h @@ -60,8 +60,7 @@ public: hsVectorStream(uint32_t chunkSize); virtual ~hsVectorStream(); - virtual bool Open(const char *, const char *) { hsAssert(0, "hsVectorStream::Open Not Implemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsVectorStream::Open Not Implemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsVectorStream::Open Not Implemented"); return false; } virtual bool Close() { hsAssert(0, "hsVectorStream::Close Not Implemented"); return false; } virtual bool AtEnd(); diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index f0fd4caa..c7971b74 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -684,17 +684,10 @@ hsUNIXStream::~hsUNIXStream() // Don't Close here, because Sub classes Don't always want that behaviour! } -bool hsUNIXStream::Open(const char *name, const char *mode) +bool hsUNIXStream::Open(const plFileName &name, const char *mode) { fPosition = 0; - fRef = hsFopen(name, mode); - return (fRef) ? true : false; -} - -bool hsUNIXStream::Open(const wchar_t *name, const wchar_t *mode) -{ - fPosition = 0; - fRef = hsWFopen(name, mode); + fRef = plFileSystem::Open(name, mode); return (fRef) ? true : false; } @@ -1222,23 +1215,15 @@ hsBufferedStream::hsBufferedStream() , fBufferReadOut(0) , fReadDirect(0) , fLastReadPos(0) -, fFilename(nil) , fCloseReason(nil) #endif { } -hsBufferedStream::~hsBufferedStream() -{ -#ifdef LOG_BUFFERED - delete [] fFilename; -#endif // LOG_BUFFERED -} - -bool hsBufferedStream::Open(const char* name, const char* mode) +bool hsBufferedStream::Open(const plFileName& name, const char* mode) { hsAssert(!fRef, "hsBufferedStream:Open Stream already opened"); - fRef = hsFopen(name, mode); + fRef = plFileSystem::Open(name, mode); if (!fRef) return false; @@ -1247,20 +1232,13 @@ bool hsBufferedStream::Open(const char* name, const char* mode) #ifdef LOG_BUFFERED fBufferHits = fBufferMisses = 0; fBufferReadIn = fBufferReadOut = fReadDirect = fLastReadPos = 0; - delete [] fFilename; - fFilename = hsStrdup(name); + fFilename = name; fCloseReason = nil; #endif // LOG_BUFFERED return true; } -bool hsBufferedStream::Open(const wchar_t *name, const wchar_t *mode) -{ - hsAssert(0, "hsFileStream::Open NotImplemented for wchar_t"); - return false; -} - bool hsBufferedStream::Close() { int rtn = true; @@ -1285,7 +1263,7 @@ bool hsBufferedStream::Close() wasted -= int((float(fBufferReadOut+fReadDirect) / float(fBufferReadIn+fReadDirect)) * 100.f); s.WriteFmt("%s,%d,%d,%u,%u,%u,%d,%s\n", - fFilename, fBufferHits, fBufferMisses, fBufferReadIn, fBufferReadOut, fReadDirect, + fFilename.c_str(), fBufferHits, fBufferMisses, fBufferReadIn, fBufferReadOut, fReadDirect, wasted, fCloseReason ? fCloseReason : "Unknown"); diff --git a/Sources/Plasma/CoreLib/hsStream.h b/Sources/Plasma/CoreLib/hsStream.h index f74d294a..83351954 100644 --- a/Sources/Plasma/CoreLib/hsStream.h +++ b/Sources/Plasma/CoreLib/hsStream.h @@ -83,12 +83,7 @@ public: hsStream() : fBytesRead(0), fPosition(0) {} virtual ~hsStream() { } - // Pre-filename-stringification shortcut: - bool Open_TEMP(const plFileName & filename, const char * mode = "rb") - { return Open(filename.AsString().c_str(), mode); } - - virtual bool Open(const char *, const char * = "rb")=0; - virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0; + virtual bool Open(const plFileName &, const char * = "rb") = 0; virtual bool Close()=0; virtual bool AtEnd(); virtual uint32_t Read(uint32_t byteCount, void * buffer) = 0; @@ -300,8 +295,7 @@ class hsUNIXStream: public hsStream public: hsUNIXStream(): fRef(0), fBuff(nil) {} ~hsUNIXStream(); - virtual bool Open(const char* name, const char* mode = "rb"); - virtual bool Open(const wchar_t *name, const wchar_t *mode = L"rb"); + virtual bool Open(const plFileName& name, const char* mode = "rb"); virtual bool Close(); virtual bool AtEnd(); @@ -335,8 +329,7 @@ public: plReadOnlySubStream(): fBase( nil ), fOffset( 0 ), fLength( 0 ) {} ~plReadOnlySubStream(); - virtual bool Open(const char *, const char *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; } void Open( hsStream *base, uint32_t offset, uint32_t length ); virtual bool Close() { fBase = nil; fOffset = 0; fLength = 0; return true; } virtual bool AtEnd(); @@ -358,8 +351,7 @@ public: hsRAMStream(uint32_t chunkSize); virtual ~hsRAMStream(); - virtual bool Open(const char *, const char *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsRAMStream::Close NotImplemented"); return false; } @@ -379,8 +371,7 @@ public: class hsNullStream : public hsStream { public: - virtual bool Open(const char *, const char *) { return true; } - virtual bool Open(const wchar_t *, const wchar_t *) { return true; } + virtual bool Open(const plFileName &, const char *) { return true; } virtual bool Close() { return true; } virtual uint32_t Read(uint32_t byteCount, void * buffer); // throw's exception @@ -404,8 +395,7 @@ public: hsReadOnlyStream() {} virtual void Init(int size, const void* data) { fStart=((char*)data); fData=((char*)data); fStop=((char*)data + size); } - virtual bool Open(const char *, const char *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsReadOnlyStream::Close NotImplemented"); return false; } virtual bool AtEnd(); virtual uint32_t Read(uint32_t byteCount, void * buffer); @@ -424,8 +414,7 @@ public: hsWriteOnlyStream(int size, const void* data) : hsReadOnlyStream(size, data) {} hsWriteOnlyStream() {} - virtual bool Open(const char *, const char *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsWriteOnlyStream::Close NotImplemented"); return false; } virtual uint32_t Read(uint32_t byteCount, void * buffer); // throws exception virtual uint32_t Write(uint32_t byteCount, const void* buffer); @@ -445,8 +434,7 @@ public: hsQueueStream(int32_t size); ~hsQueueStream(); - virtual bool Open(const char *, const char *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; } - virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; } + virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsQueueStream::Close NotImplemented"); return false; } virtual uint32_t Read(uint32_t byteCount, void * buffer); @@ -480,16 +468,15 @@ class hsBufferedStream : public hsStream // For doing statistics on how efficient we are int fBufferHits, fBufferMisses; uint32_t fBufferReadIn, fBufferReadOut, fReadDirect, fLastReadPos; - char* fFilename; + plFileName fFilename; const char* fCloseReason; #endif public: hsBufferedStream(); - virtual ~hsBufferedStream(); + virtual ~hsBufferedStream() { } - virtual bool Open(const char* name, const char* mode = "rb"); - virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb"); + virtual bool Open(const plFileName& name, const char* mode = "rb"); virtual bool Close(); virtual bool AtEnd(); diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 38ac1a51..66467297 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -284,6 +284,14 @@ public: return str; } + /** Create a new plString object from the UTF-32 formatted data in \a utf32. */ + static inline plString FromUtf32(const UniChar *utf32, size_t size = kSizeAuto) + { + plString str; + str.IConvertFromUtf32(utf32, size); + return str; + } + /** Create a new plString object from the ISO-8859-1 formatted data in \a astr. */ static inline plString FromIso8859_1(const char *astr, size_t size = kSizeAuto) { diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp index 92e0821c..da17981b 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp @@ -283,7 +283,7 @@ bool pfConsole::MsgReceive( plMessage *msg ) { if( cmd->GetCmd() == plConsoleMsg::kExecuteFile ) { - if( !fEngine->ExecuteFile( (char *)cmd->GetString() ) ) + if( !fEngine->ExecuteFile( cmd->GetString() ) ) { // Change the following line once we have a better way of reporting // errors in the parsing diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index c43ba3aa..d4095016 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -6064,7 +6064,7 @@ PF_CONSOLE_CMD(Age, ShowSDL, "", "Prints the age SDL values") PF_CONSOLE_CMD( Age, GetElapsedDays, "string agedefnfile", "Gets the elapsed days and fractions" ) { hsUNIXStream s; - if (!s.Open(params[0])) + if (!s.Open(static_cast(params[0]))) { PrintString("Couldn't open age defn file!"); return; @@ -6085,7 +6085,7 @@ PF_CONSOLE_CMD( Age, GetElapsedDays, "string agedefnfile", "Gets the elapsed day PF_CONSOLE_CMD( Age, GetTimeOfDay, "string agedefnfile", "Gets the elapsed days and fractions" ) { hsUNIXStream s; - if (!s.Open(params[0])) + if (!s.Open(static_cast(params[0]))) { PrintString("Couldn't open age defn file!"); return; diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp index 1e80ed3e..86124c50 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp @@ -57,40 +57,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// ParseDirectory ////////////////////////////////////////////////////////// -bool pfConsoleDirSrc::ParseDirectory(const std::string& path, const std::string& mask /* = "*.*" */) +bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */) { - wchar_t* wPath = hsStringToWString(path.c_str()); - wchar_t* wMask = hsStringToWString(mask.c_str()); - bool ret = ParseDirectory(wPath, wMask); - delete [] wPath; - delete [] wMask; - return ret; -} - -bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wstring& mask /* = L"*.*" */) -{ - std::wstringstream search; - std::wstring file; WIN32_FIND_DATAW findInfo; HANDLE handle; hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" ); - search << path << L"\\" << mask; - handle = FindFirstFileW(search.str().c_str(), &findInfo); + handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo); if (handle == INVALID_HANDLE_VALUE) return false; do { - if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - std::wstringstream fileAndPath; - fileAndPath << path << L"\\" << findInfo.cFileName; - if (AlreadyProcessedFile(path, findInfo.cFileName)) + plFileName name = plString::FromWchar(findInfo.cFileName); + plFileName fileAndPath = plFileName::Join(path, name); + if (AlreadyProcessedFile(path, name)) continue; - AddProcessedFile(path, findInfo.cFileName); - if (!fEngine->ExecuteFile(fileAndPath.str().c_str())) + AddProcessedFile(path, name); + if (!fEngine->ExecuteFile(fileAndPath)) { // Change the following line once we have a better way of reporting // errors in the parsing @@ -102,7 +89,7 @@ bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wst caption << L"Error parsing " << findInfo.cFileName; error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files."; - hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal); + hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal); delete [] errorMsg; delete [] errorLine; @@ -137,12 +124,12 @@ void pfConsoleDirSrc::ResetProcessedFiles() // note: this n^2 linear search should be replaced with something // faster if we have lots of init files and turn on the checkProcessing option. // -bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::wstring& file) +bool pfConsoleDirSrc::AlreadyProcessedFile(const plFileName& path, const plFileName& file) { if (fCheckProcessedFiles) { int i; - for(i=0; ifFile && path == fProcessedFiles[i]->fPath) return true; @@ -151,7 +138,7 @@ bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std:: return false; } -void pfConsoleDirSrc::AddProcessedFile(const std::wstring& path, const std::wstring& file) +void pfConsoleDirSrc::AddProcessedFile(const plFileName& path, const plFileName& file) { - fProcessedFiles.push_back(new FileName(path, file)); + fProcessedFiles.push_back(new FileName(path, file)); } diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h index 4b968ab0..d7882ca7 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h @@ -57,9 +57,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include -#include #include "pfConsoleCore/pfConsoleEngine.h" +#include "plFileSystem.h" //// pfConsoleDirSrc Class Definition //////////////////////////////////////// @@ -69,23 +69,17 @@ class pfConsoleDirSrc pfConsoleEngine *fEngine; struct FileName { - std::wstring fPath; - std::wstring fFile; - FileName() : fPath(L""), fFile(L"") {} - FileName(const std::wstring& p, const std::wstring& f) : fPath(p), fFile(f) {} + plFileName fPath; + plFileName fFile; + FileName() : fPath(""), fFile("") {} + FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {} }; std::vector fProcessedFiles; // list of init files we've already executed bool fCheckProcessedFiles; // set to check and skip files init files we've already executed public: pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; } - pfConsoleDirSrc(pfConsoleEngine *engine, const std::string& path, const std::string& mask = "*.ini") : - fCheckProcessedFiles(false) - { - fEngine = engine; - ParseDirectory(path, mask); - } - pfConsoleDirSrc(pfConsoleEngine *engine, const std::wstring& path, const std::wstring& mask = L"*.ini") : - fCheckProcessedFiles(false) + pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini") + : fCheckProcessedFiles(false) { fEngine = engine; ParseDirectory(path, mask); @@ -94,12 +88,11 @@ class pfConsoleDirSrc ~pfConsoleDirSrc() { ResetProcessedFiles(); } // Steps through the given directory and executes all files with the console engine - bool ParseDirectory(const std::string& path, const std::string& mask = "*.*"); - bool ParseDirectory(const std::wstring& path, const std::wstring& mask = L"*.*"); + bool ParseDirectory(const plFileName& path, const plString& mask = "*.*"); void ResetProcessedFiles(); - bool AlreadyProcessedFile(const std::wstring& path, const std::wstring& file); - void AddProcessedFile(const std::wstring& path, const std::wstring& file); + bool AlreadyProcessedFile(const plFileName& path, const plFileName& file); + void AddProcessedFile(const plFileName& path, const plFileName& file); void SetCheckProcessedFiles(bool c) { fCheckProcessedFiles=c; } }; diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp index 551cf44c..9ef50326 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp @@ -247,18 +247,10 @@ void DummyPrintFn( const char *line ) //// ExecuteFile ///////////////////////////////////////////////////////////// -bool pfConsoleEngine::ExecuteFile( const char *fileName ) +bool pfConsoleEngine::ExecuteFile(const plFileName &fileName) { - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = ExecuteFile(wFilename); - delete [] wFilename; - return ret; -} - -bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName ) -{ - char string[ 512 ]; - int line; + char string[ 512 ]; + int line; hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileName); @@ -273,13 +265,14 @@ bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName ) return true; } - for( line = 1; stream->ReadLn( string, sizeof( string ) ); line++ ) + for( line = 1; stream->ReadLn( string, arrsize( string ) ); line++ ) { - strncpy( fLastErrorLine, string, sizeof( fLastErrorLine ) ); + strncpy( fLastErrorLine, string, arrsize( fLastErrorLine ) ); if( !RunCommand( string, DummyPrintFn ) ) { - sprintf( string, "Error in console file %S, command line %d: %s", fileName, line, fErrorMsg ); + snprintf(string, arrsize(string), "Error in console file %s, command line %d: %s", + fileName.AsString().c_str(), line, fErrorMsg); ISetErrorMsg( string ); stream->Close(); delete stream; diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h index cf1f112c..e8de87cb 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h @@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" +class plFileName; //// pfConsoleEngine Class Definition //////////////////////////////////////// @@ -94,8 +95,7 @@ class pfConsoleEngine bool RunCommand( char *line, void (*PrintFn)( const char * ) ); // Executes the given file as a sequence of console commands - bool ExecuteFile( const char *fileName ); - bool ExecuteFile( const wchar_t *fileName ); + bool ExecuteFile( const plFileName &fileName ); // Get the last reported error const char *GetErrorMsg( void ) { return fErrorMsg; } diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp index 0d57f296..ef63aae0 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp @@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plCrash_Private.h" #include "plFile/plFileUtils.h" #include "plProduct.h" -#include "plString.h" +#include "plFileSystem.h" #ifdef HS_BUILD_FOR_WIN32 @@ -78,14 +78,8 @@ plCrashSrv::~plCrashSrv() void plCrashSrv::IHandleCrash() { - // Begin Hackiness - wchar_t dumpPath[1024]; - SHGetSpecialFolderPathW(NULL, dumpPath, CSIDL_LOCAL_APPDATA, TRUE); - plFileUtils::ConcatFileName(dumpPath, plProduct::LongName().ToWchar()); - plFileUtils::ConcatFileName(dumpPath, L"Log"); - plFileUtils::EnsureFilePathExists(dumpPath); - plFileUtils::ConcatFileName(dumpPath, L"crash.dmp"); - HANDLE file = CreateFileW(dumpPath, + plFileName dumpPath = plFileName::Join(plFileSystem::GetLogPath(), "crash.dmp"); + HANDLE file = CreateFileW(dumpPath.AsString().ToWchar(), GENERIC_WRITE, 0, NULL, @@ -93,7 +87,6 @@ void plCrashSrv::IHandleCrash() FILE_ATTRIBUTE_NORMAL, NULL ); - // End Hackiness MINIDUMP_EXCEPTION_INFORMATION e; e.ClientPointers = TRUE; diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp index 960e59f7..4c1d82d6 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp @@ -43,8 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include -#include -#include #include #include "HeadSpin.h" @@ -125,7 +123,7 @@ bool plPythonPack::Open() fPackNotFound = true; // Get the names of all the pak files - std::vector files = plStreamSource::GetInstance()->GetListOfNames(L"python", L".pak"); + std::vector files = plStreamSource::GetInstance()->GetListOfNames("python", "pak"); std::vector modTimes; // the modification time for each of the streams (to resolve duplicate file issues) @@ -139,13 +137,11 @@ bool plPythonPack::Open() fPackStream->Rewind(); // make sure we're at the beginning of the file fPackNotFound = false; - char* tempFilename = hsWStringToString(files[curName].c_str()); - struct stat buf; time_t curModTime = 0; - if (stat(tempFilename,&buf)==0) - curModTime = buf.st_mtime; + plFileInfo info(files[curName]); + if (info.Exists()) + curModTime = info.ModifyTime(); modTimes.push_back(curModTime); - delete [] tempFilename; // read the index data int numFiles = fPackStream->ReadLE32(); @@ -191,9 +187,8 @@ void plPythonPack::Close() // do NOT close or delete the streams, the preloader will do that for us fPackStreams[i] = nil; } - - fPackStreams.clear(); + fPackStreams.clear(); fFileOffsets.clear(); } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp b/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp index 7b7ac940..62fb68b4 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp @@ -178,24 +178,24 @@ uint32_t pyImage::GetHeight() return 0; } -void pyImage::SaveAsJPEG(const wchar_t* fileName, uint8_t quality) +void pyImage::SaveAsJPEG(const plFileName& fileName, uint8_t quality) { if (quality <= 0 || quality > 100) { quality = 75; } - plJPEG::Instance().SetWriteQuality( quality ); - plJPEG::Instance().WriteToFile( fileName, this->GetImage() ); + plJPEG::Instance().SetWriteQuality(quality); + plJPEG::Instance().WriteToFile(fileName, this->GetImage()); } -void pyImage::SaveAsPNG(const wchar_t* fileName) +void pyImage::SaveAsPNG(const plFileName& fileName) { - plPNG::Instance().WriteToFile( fileName, this->GetImage() ); + plPNG::Instance().WriteToFile(fileName, this->GetImage()); } -PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height) +PyObject* pyImage::LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height) { plMipmap* theMipmap = plJPEG::Instance().ReadFromFile(filename); if (theMipmap) @@ -210,7 +210,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin } // let's create a nice name for this thing based on the filename - plString name = plString::Format("PtImageFromDisk_%S", filename); + plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str()); hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc); @@ -220,7 +220,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin PYTHON_RETURN_NONE; } -PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height) +PyObject* pyImage::LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height) { plMipmap* theMipmap = plPNG::Instance().ReadFromFile(filename); if (theMipmap) @@ -235,7 +235,7 @@ PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint } // let's create a nice name for this thing based on the filename - plString name = plString::Format("PtImageFromDisk_%S", filename); + plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str()); hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyImage.h b/Sources/Plasma/FeatureLib/pfPython/pyImage.h index 6eab711f..921012dd 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyImage.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyImage.h @@ -143,10 +143,10 @@ public: PyObject *GetColorLoc(const pyColor &color); // returns the x,y position of a color (x and y from 0 to 1) - returns pyPoint3 uint32_t GetWidth(); // returns the width of the image uint32_t GetHeight(); // returns the height of the image - void SaveAsJPEG(const wchar_t* fileName, uint8_t quality = 75); - void SaveAsPNG(const wchar_t* fileName); - static PyObject* LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage - static PyObject* LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage + void SaveAsJPEG(const plFileName& fileName, uint8_t quality = 75); + void SaveAsPNG(const plFileName& fileName); + static PyObject* LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage + static PyObject* LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage #endif }; diff --git a/Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp index b5567e1d..e70e037f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp @@ -152,24 +152,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsJPEG, args) PYTHON_RETURN_ERROR; } - if (PyUnicode_Check(filenameObj)) - { - int strLen = PyUnicode_GetSize(filenameObj); - wchar_t* text = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen); - text[strLen] = L'\0'; - self->fThis->SaveAsJPEG(text, quality); - delete [] text; - PYTHON_RETURN_NONE; - } - else if (PyString_Check(filenameObj)) - { - // we'll allow this, just in case something goes weird - char* text = PyString_AsString(filenameObj); - wchar_t* wText = hsStringToWString(text); - self->fThis->SaveAsJPEG(wText, quality); - delete [] wText; - PYTHON_RETURN_NONE; + if (PyString_CheckEx(filenameObj)) { + self->fThis->SaveAsJPEG(PyString_AsStringEx(filenameObj), quality); + Py_RETURN_NONE; } else { @@ -187,23 +172,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args) PYTHON_RETURN_ERROR; } - if (PyUnicode_Check(filenameObj)) - { - int strLen = PyUnicode_GetSize(filenameObj); - wchar_t* text = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen); - text[strLen] = L'\0'; - self->fThis->SaveAsPNG(text); - delete [] text; - PYTHON_RETURN_NONE; - } - else if (PyString_Check(filenameObj)) + if (PyString_CheckEx(filenameObj)) { - // we'll allow this, just in case something goes weird - char* text = PyString_AsString(filenameObj); - wchar_t* wText = hsStringToWString(text); - self->fThis->SaveAsPNG(wText); - delete [] wText; + self->fThis->SaveAsPNG(PyString_AsStringEx(filenameObj)); PYTHON_RETURN_NONE; } else @@ -290,8 +261,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt if (PyString_CheckEx(filenameObj)) { - plString text = PyString_AsStringEx(filenameObj); - PyObject* ret = pyImage::LoadJPEGFromDisk(text.ToWchar(), width, height); + plFileName filename = PyString_AsStringEx(filenameObj); + PyObject* ret = pyImage::LoadJPEGFromDisk(filename, width, height); return ret; } else @@ -312,8 +283,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width } if (PyString_CheckEx(filenameObj)) { - plString text = PyString_AsStringEx(filenameObj); - PyObject* ret = pyImage::LoadPNGFromDisk(text.ToWchar(), width, height); + plFileName filename = PyString_AsStringEx(filenameObj); + PyObject* ret = pyImage::LoadPNGFromDisk(filename, width, height); return ret; } else diff --git a/Sources/Plasma/FeatureLib/pfPython/pyStream.cpp b/Sources/Plasma/FeatureLib/pfPython/pyStream.cpp index 982018b4..fdb9a8ea 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyStream.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyStream.cpp @@ -61,12 +61,12 @@ pyStream::~pyStream() } -bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags) +bool pyStream::Open(const plFileName& fileName, const char* flags) { // make sure its closed first Close(); - if (fileName) + if (fileName.IsValid()) { if (flags) { @@ -74,13 +74,13 @@ bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags) bool writeflag = false; bool encryptflag = false; int i; - for (i=0 ; i < wcslen(flags) ; i++ ) + for (i=0 ; i < strlen(flags) ; i++ ) { - if ( flags[i] == L'r' || flags[i] == L'R' ) + if ( flags[i] == 'r' || flags[i] == 'R' ) readflag = true; - if ( flags[i] == L'w' || flags[i] == L'W' ) + if ( flags[i] == 'w' || flags[i] == 'W' ) writeflag = true; - if ( flags[i] == L'e' || flags[i] == L'E' ) + if ( flags[i] == 'e' || flags[i] == 'E' ) encryptflag = true; } // if there is a write flag, it takes priorty over read @@ -90,7 +90,7 @@ bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags) if (encryptflag) { fStream = new plEncryptedStream; - fStream->Open(fileName, L"wb"); + fStream->Open(fileName, "wb"); } else fStream = plEncryptedStream::OpenEncryptedFileWrite(fileName); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyStream.h b/Sources/Plasma/FeatureLib/pfPython/pyStream.h index be77458f..8e3803b2 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyStream.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyStream.h @@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include class hsStream; +class plFileName; class pyStream { @@ -75,7 +76,7 @@ public: static void AddPlasmaClasses(PyObject *m); - virtual bool Open(const wchar_t* fileName, const wchar_t* flags); + virtual bool Open(const plFileName& fileName, const char* flags); virtual std::vector ReadLines(); virtual bool WriteLines(const std::vector & lines); virtual void Close(); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp index 9a80344d..31abf921 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #pragma hdrstop #include "pyStream.h" +#include "plFileSystem.h" // glue functions @@ -67,23 +68,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args) PYTHON_RETURN_ERROR; } - std::wstring filename; - if (PyUnicode_Check(filenameObj)) + plFileName filename; + if (PyString_CheckEx(filenameObj)) { - int strLen = PyUnicode_GetSize(filenameObj); - wchar_t* text = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen); - text[strLen] = L'\0'; - filename = text; - delete [] text; - } - else if (PyString_Check(filenameObj)) - { - // we'll allow this, just in case something goes weird - char* text = PyString_AsString(filenameObj); - wchar_t* wText = hsStringToWString(text); - filename = wText; - delete [] wText; + filename = PyString_AsStringEx(filenameObj); } else { @@ -91,23 +79,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args) PYTHON_RETURN_ERROR; } - std::wstring flags; - if (PyUnicode_Check(flagsObj)) - { - int strLen = PyUnicode_GetSize(flagsObj); - wchar_t* text = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)flagsObj, text, strLen); - text[strLen] = L'\0'; - flags = text; - delete [] text; - } - else if (PyString_Check(flagsObj)) + plString flags; + if (PyString_CheckEx(flagsObj)) { - // we'll allow this, just in case something goes weird - char* text = PyString_AsString(flagsObj); - wchar_t* wText = hsStringToWString(text); - flags = wText; - delete [] wText; + flags = PyString_AsStringEx(flagsObj); } else { @@ -115,7 +90,7 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args) PYTHON_RETURN_ERROR; } - PYTHON_RETURN_BOOL(self->fThis->Open(filename.c_str(), flags.c_str())); + PYTHON_RETURN_BOOL(self->fThis->Open(filename, flags.c_str())); } PYTHON_METHOD_DEFINITION_NOARGS(ptStream, readlines) diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp index c9e1469b..e9f7bf15 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp +++ b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp @@ -189,28 +189,9 @@ public: ///////////////////////////////////////////////////////////////////// -pfSecurePreloader::pfSecurePreloader() - : fProgress(nil), fLegacyMode(false) -{ } - -pfSecurePreloader::~pfSecurePreloader() +hsRAMStream* pfSecurePreloader::LoadToMemory(const plFileName& file) const { - while (fDownloadEntries.size()) - { - free((void*)fDownloadEntries.front()); - fDownloadEntries.pop(); - } - - while (fManifestEntries.size()) - { - free((void*)fManifestEntries.front()); - fManifestEntries.pop(); - } -} - -hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const -{ - if (!plFileUtils::FileExists(file)) + if (!plFileInfo(file).Exists()) return nil; hsUNIXStream s; @@ -228,10 +209,10 @@ hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const return ram; } -void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const +void pfSecurePreloader::SaveFile(hsStream* file, const plFileName& name) const { hsUNIXStream s; - s.Open(name, L"wb"); + s.Open(name, "wb"); uint32_t pos = file->GetPosition(); file->Rewind(); @@ -244,9 +225,9 @@ void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const delete[] buf; } -bool pfSecurePreloader::IsZipped(const wchar_t* filename) const +bool pfSecurePreloader::IsZipped(const plFileName& filename) const { - return wcscmp(plFileUtils::GetFileExt(filename), L"gz") == 0; + return filename.GetFileExt().CompareI("gz") == 0; } void pfSecurePreloader::PreloadNextFile() @@ -257,14 +238,14 @@ void pfSecurePreloader::PreloadNextFile() return; } - const wchar_t* filename = fDownloadEntries.front(); + plFileName filename = fDownloadEntries.front(); hsStream* s = new pfSecurePreloaderStream(fProgress, IsZipped(filename)); // Thankfully, both callbacks have the same arguments if (fLegacyMode) - NetCliAuthFileRequest(filename, s, FileDownloaded, this); + NetCliAuthFileRequest(filename.AsString().ToWchar(), s, FileDownloaded, this); else - NetCliFileDownloadRequest(filename, s, FileDownloaded, this); + NetCliFileDownloadRequest(filename.AsString().ToWchar(), s, FileDownloaded, this); } void pfSecurePreloader::Init() @@ -340,15 +321,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliAuthFileInfo manifestEntries for (uint32_t i = 0; i < entryCount; ++i) { const NetCliAuthFileInfo mfs = manifestEntries[i]; - fDownloadEntries.push(wcsdup(mfs.filename)); - if (IsZipped(mfs.filename)) - { - wchar_t* name = wcsdup(mfs.filename); - plFileUtils::StripExt(name); - fManifestEntries.push(name); - - } else - fManifestEntries.push(wcsdup(mfs.filename)); + plFileName filename = plString::FromWchar(mfs.filename); + fDownloadEntries.push(filename); + if (IsZipped(filename)) + fManifestEntries.push(filename.StripFileExt()); + else + fManifestEntries.push(filename); totalBytes += mfs.filesize; } @@ -368,10 +346,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn const NetCliFileManifestEntry mfs = manifestEntries[i]; bool fetchMe = true; hsRAMStream* s = nil; + plFileName clientName = plString::FromWchar(mfs.clientName); + plFileName downloadName = plString::FromWchar(mfs.downloadName); - if (plFileUtils::FileExists(mfs.clientName)) + if (plFileInfo(clientName).Exists()) { - s = LoadToMemory(mfs.clientName); + s = LoadToMemory(clientName); if (s) { // Damn this @@ -389,15 +369,15 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn if (fetchMe) { - fManifestEntries.push(wcsdup(mfs.clientName)); - fDownloadEntries.push(wcsdup(mfs.downloadName)); - if (IsZipped(mfs.downloadName)) + fManifestEntries.push(clientName); + fDownloadEntries.push(downloadName); + if (IsZipped(downloadName)) totalBytes += mfs.zipSize; else totalBytes += mfs.fileSize; } else { plSecureStream* ss = new plSecureStream(s, fEncryptionKey); - plStreamSource::GetInstance()->InsertFile(mfs.clientName, ss); + plStreamSource::GetInstance()->InsertFile(clientName, ss); } if (s) @@ -418,12 +398,12 @@ void pfSecurePreloader::FilePreloaded(const wchar_t* file, hsStream* stream) { // Clear out queue fDownloadEntries.pop(); - const wchar_t* clientName = fManifestEntries.front(); // Stolen by plStreamSource + plFileName clientName = fManifestEntries.front(); fManifestEntries.pop(); if (!fLegacyMode) // AuthSrv data caching is useless { - plFileUtils::EnsureFilePathExists(clientName); + plFileSystem::CreateDir(clientName.StripFileName(), true); SaveFile(stream, clientName); } diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h index e7356f94..1f131ffa 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h +++ b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h @@ -60,19 +60,18 @@ class pfSecurePreloader : public hsKeyedObject private: static pfSecurePreloader* fInstance; - std::queue fManifestEntries; - std::queue fDownloadEntries; + std::queue fManifestEntries; + std::queue fDownloadEntries; plOperationProgress* fProgress; - uint32_t fEncryptionKey[4]; + uint32_t fEncryptionKey[4]; bool fLegacyMode; - hsRAMStream* LoadToMemory(const wchar_t* file) const; - void SaveFile(hsStream* file, const wchar_t* name) const; - bool IsZipped(const wchar_t* filename) const; + hsRAMStream* LoadToMemory(const plFileName& file) const; + void SaveFile(hsStream* file, const plFileName& name) const; + bool IsZipped(const plFileName& filename) const; public: - pfSecurePreloader(); - ~pfSecurePreloader(); + pfSecurePreloader() : fProgress(nil), fLegacyMode(false) { } CLASSNAME_REGISTER(pfSecurePreloader); GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject); diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp index e22b6ee9..6745c182 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp @@ -123,7 +123,7 @@ plMD5Checksum::plMD5Checksum( const plMD5Checksum &rhs ) fValid = rhs.fValid; } -plMD5Checksum::plMD5Checksum( const char *fileName ) +plMD5Checksum::plMD5Checksum( const plFileName &fileName ) { CalcFromFile( fileName ); } @@ -139,7 +139,7 @@ void plMD5Checksum::Clear() fValid = false; } -void plMD5Checksum::CalcFromFile( const char *fileName ) +void plMD5Checksum::CalcFromFile( const plFileName &fileName ) { hsUNIXStream s; fValid = false; @@ -249,7 +249,7 @@ plSHAChecksum::plSHAChecksum(const plSHAChecksum& rhs) fValid = rhs.fValid; } -plSHAChecksum::plSHAChecksum(const char* fileName) +plSHAChecksum::plSHAChecksum(const plFileName& fileName) { CalcFromFile(fileName); } @@ -265,7 +265,7 @@ void plSHAChecksum::Clear() fValid = false; } -void plSHAChecksum::CalcFromFile(const char* fileName) +void plSHAChecksum::CalcFromFile(const plFileName& fileName) { hsUNIXStream s; fValid = false; @@ -375,7 +375,7 @@ plSHA1Checksum::plSHA1Checksum(const plSHA1Checksum& rhs) fValid = rhs.fValid; } -plSHA1Checksum::plSHA1Checksum(const char* fileName) +plSHA1Checksum::plSHA1Checksum(const plFileName& fileName) { CalcFromFile(fileName); } @@ -391,7 +391,7 @@ void plSHA1Checksum::Clear() fValid = false; } -void plSHA1Checksum::CalcFromFile(const char* fileName) +void plSHA1Checksum::CalcFromFile(const plFileName& fileName) { hsUNIXStream s; fValid = false; diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h index 16fff204..a0c628bf 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h @@ -60,6 +60,7 @@ public: }; class hsStream; +class plFileName; class plMD5Checksum { @@ -72,13 +73,13 @@ class plMD5Checksum plMD5Checksum(size_t size, uint8_t *buffer); plMD5Checksum(); plMD5Checksum(const plMD5Checksum &rhs); - plMD5Checksum(const char *fileName); + plMD5Checksum(const plFileName &fileName); plMD5Checksum(hsStream* stream); bool IsValid() const { return fValid; } void Clear(); - void CalcFromFile(const char *fileName); + void CalcFromFile(const plFileName &fileName); void CalcFromStream(hsStream* stream); void Start(); @@ -116,13 +117,13 @@ class plSHAChecksum plSHAChecksum(size_t size, uint8_t* buffer); plSHAChecksum(); plSHAChecksum(const plSHAChecksum& rhs); - plSHAChecksum(const char* fileName); + plSHAChecksum(const plFileName& fileName); plSHAChecksum(hsStream* stream); bool IsValid() const { return fValid; } void Clear(); - void CalcFromFile(const char* fileName); + void CalcFromFile(const plFileName& fileName); void CalcFromStream(hsStream* stream); void Start(); @@ -155,13 +156,13 @@ class plSHA1Checksum plSHA1Checksum(size_t size, uint8_t* buffer); plSHA1Checksum(); plSHA1Checksum(const plSHA1Checksum& rhs); - plSHA1Checksum(const char* fileName); + plSHA1Checksum(const plFileName& fileName); plSHA1Checksum(hsStream* stream); bool IsValid() const { return fValid; } void Clear(); - void CalcFromFile(const char* fileName); + void CalcFromFile(const plFileName& fileName); void CalcFromStream(hsStream* stream); void Start(); diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp index 32b560be..e6d88c1a 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp @@ -178,10 +178,8 @@ void plAgeLoader::UpdateAge(const char ageName[]) plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg); else { - wchar_t* wideAgeName = hsStringToWString(ageName); - plResPatcher::GetInstance()->RequestManifest(wideAgeName); + plResPatcher::GetInstance()->RequestManifest(ageName); plResPatcher::GetInstance()->Start(); - delete[] wideAgeName; } } diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index 330fe267..1e599ca3 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp @@ -59,25 +59,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com class plResDownloadStream : public plZlibStream { plOperationProgress* fProgress; - char* fFilename; + plFileName fFilename; bool fIsZipped; public: - plResDownloadStream(plOperationProgress* prog, const wchar_t* reqFile) - : fProgress(prog), fFilename(nil) + plResDownloadStream(plOperationProgress* prog, const plFileName& reqFile) + : fProgress(prog) { - fIsZipped = wcscmp(plFileUtils::GetFileExt(reqFile), L"gz") == 0; + fIsZipped = reqFile.GetFileExt().CompareI("gz") == 0; } - virtual ~plResDownloadStream() + virtual bool Open(const plFileName& filename, const char* mode) { - if (fFilename) - delete[] fFilename; - } - - virtual bool Open(const char* filename, const char* mode) - { - fFilename = hsStrcpy(filename); + fFilename = filename; return plZlibStream::Open(filename, mode); } @@ -91,7 +85,7 @@ public: } bool IsZipped() const { return fIsZipped; } - void Unlink() const { plFileUtils::RemoveFile(fFilename); } + void Unlink() const { plFileSystem::Unlink(fFilename); } }; ///////////////////////////////////////////////////////////////////////////// @@ -140,56 +134,51 @@ static void FileDownloaded( } static void ManifestDownloaded( - ENetError result, - void* param, - const wchar_t group[], - const NetCliFileManifestEntry manifest[], - uint32_t entryCount) + ENetError result, + void* param, + const wchar_t group[], + const NetCliFileManifestEntry manifest[], + uint32_t entryCount) { plResPatcher* patcher = (plResPatcher*)param; - char* name = hsWStringToString(group); + plString name = plString::FromWchar(group); if (IS_NET_SUCCESS(result)) - PatcherLog(kInfo, " Downloaded manifest %s", name); + PatcherLog(kInfo, " Downloaded manifest %s", name.c_str()); else { - PatcherLog(kError, " Failed to download manifest %s", name); + PatcherLog(kError, " Failed to download manifest %s", name.c_str()); patcher->Finish(false); - delete[] name; return; } for (uint32_t i = 0; i < entryCount; ++i) { const NetCliFileManifestEntry mfs = manifest[i]; - char* fileName = hsWStringToString(mfs.clientName); + plFileName fileName = plString::FromWchar(mfs.clientName); + plFileName downloadName = plString::FromWchar(mfs.downloadName); // See if the files are the same // 1. Check file size before we do time consuming md5 operations // 2. Do wasteful md5. We should consider implementing a CRC instead. - if (plFileUtils::GetFileSize(fileName) == mfs.fileSize) + if (plFileInfo(fileName).FileSize() == mfs.fileSize) { plMD5Checksum cliMD5(fileName); plMD5Checksum srvMD5; - char* eapSucksString = hsWStringToString(mfs.md5); - srvMD5.SetFromHexString(eapSucksString); - delete[] eapSucksString; + srvMD5.SetFromHexString(plString::FromWchar(mfs.md5).c_str()); if (cliMD5 == srvMD5) - { - delete[] fileName; continue; - } else - PatcherLog(kInfo, " Enqueueing %s: MD5 Checksums Differ", fileName); + else + PatcherLog(kInfo, " Enqueueing %s: MD5 Checksums Differ", fileName.AsString().c_str()); } else - PatcherLog(kInfo, " Enqueueing %s: File Sizes Differ", fileName); + PatcherLog(kInfo, " Enqueueing %s: File Sizes Differ", fileName.AsString().c_str()); // If we're still here, then we need to update the file. float size = mfs.zipSize ? (float)mfs.zipSize : (float)mfs.fileSize; patcher->GetProgress()->SetLength(size + patcher->GetProgress()->GetMax()); - patcher->RequestFile(mfs.downloadName, mfs.clientName); + patcher->RequestFile(downloadName, fileName); } patcher->IssueRequest(); - delete[] name; } ///////////////////////////////////////////////////////////////////////////// @@ -234,25 +223,24 @@ void plResPatcher::IssueRequest() plString title; if (req.fType == kManifest) { - PatcherLog(kMajorStatus, " Downloading manifest... %S", req.fFile.c_str()); - title = plString::Format("Checking %S for updates...", req.fFile.c_str()); - NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.c_str()); + PatcherLog(kMajorStatus, " Downloading manifest... %s", req.fFile.AsString().c_str()); + title = plString::Format("Checking %s for updates...", req.fFile.AsString().c_str()); + NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.AsString().ToWchar()); } else if (req.fType == kFile) { - PatcherLog(kMajorStatus, " Downloading file... %S", req.fFriendlyName.c_str()); - title = plString::Format("Downloading... %S", plFileUtils::GetFileName(req.fFriendlyName.c_str())); + PatcherLog(kMajorStatus, " Downloading file... %s", req.fFriendlyName.AsString().c_str()); + title = plString::Format("Downloading... %s", req.fFriendlyName.GetFileName().c_str()); // If this is a PRP, we need to unload it from the ResManager - plString filename = plString::FromWchar(req.fFriendlyName.c_str()); - if (stricmp(plFileUtils::GetFileExt(filename.c_str()), "prp") == 0) - ((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(filename.c_str()); + if (req.fFriendlyName.GetFileExt().CompareI("prp") == 0) + ((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(req.fFriendlyName); - plFileUtils::EnsureFilePathExists(req.fFriendlyName.c_str()); - plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile.c_str()); - if (stream->Open_TEMP(filename, "wb")) - NetCliFileDownloadRequest(req.fFile.c_str(), stream, FileDownloaded, this); + plFileSystem::CreateDir(req.fFriendlyName.StripFileName(), true); + plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile); + if (stream->Open(req.fFriendlyName, "wb")) + NetCliFileDownloadRequest(req.fFile.AsString().ToWchar(), stream, FileDownloaded, this); else { - PatcherLog(kError, " Unable to create file %s", filename.c_str()); + PatcherLog(kError, " Unable to create file %s", req.fFriendlyName.AsString().c_str()); Finish(false); } } @@ -282,12 +270,12 @@ void plResPatcher::Finish(bool success) pMsg->Send(); // whoosh... off it goes } -void plResPatcher::RequestFile(const wchar_t* srvName, const wchar_t* cliName) +void plResPatcher::RequestFile(const plFileName& srvName, const plFileName& cliName) { fRequests.push(Request(srvName, kFile, cliName)); } -void plResPatcher::RequestManifest(const wchar_t* age) +void plResPatcher::RequestManifest(const plString& age) { fRequests.push(Request(age, kManifest)); } diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h index 0a4d9c75..4de86111 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plResPatcher_h_inc #include "HeadSpin.h" +#include "plFileSystem.h" #include #include @@ -53,16 +54,12 @@ class plResPatcher enum { kManifest, kFile }; struct Request { - std::wstring fFile; - std::wstring fFriendlyName; - uint8_t fType; - - Request(const wchar_t* file, uint8_t type, const wchar_t* friendly = nil) - : fFile(file), fType(type) - { - if (friendly) - fFriendlyName = std::wstring(friendly); - } + plFileName fFile; + plFileName fFriendlyName; + uint8_t fType; + + Request(const plFileName& file, uint8_t type, const plFileName& friendly = "") + : fFile(file), fFriendlyName(friendly), fType(type) { } }; static plResPatcher* fInstance; @@ -81,8 +78,8 @@ public: void Finish(bool success = true); void IssueRequest(); - void RequestFile(const wchar_t* file, const wchar_t* friendlyName); - void RequestManifest(const wchar_t* age); + void RequestFile(const plFileName& file, const plFileName& friendlyName); + void RequestManifest(const plString& age); void Start(); }; diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp index cabbf31f..9512380e 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp @@ -84,10 +84,9 @@ void plClientResMgr::ILoadResources(const char* resfile) return; } - wchar_t* wFilename = hsStringToWString(resfile); hsUNIXStream in; - if (in.Open(wFilename, L"rb")) { + if (in.Open(resfile, "rb")) { uint32_t header = in.ReadLE32(); uint32_t version = in.ReadLE32(); uint32_t num_resources = 0; @@ -133,8 +132,6 @@ void plClientResMgr::ILoadResources(const char* resfile) in.Close(); } - - delete wFilename; } plMipmap* plClientResMgr::getResource(const char* resname) diff --git a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp index 9d108458..ce2ee4b8 100644 --- a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp +++ b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp @@ -61,23 +61,13 @@ plZlibStream::~plZlibStream() hsAssert(!fOutput && !fZStream, "plZlibStream not closed"); } -bool plZlibStream::Open(const char* filename, const char* mode) -{ - wchar_t* wFilename = hsStringToWString(filename); - wchar_t* wMode = hsStringToWString(mode); - bool ret = Open(wFilename, wMode); - delete [] wFilename; - delete [] wMode; - return ret; -} - -bool plZlibStream::Open(const wchar_t* filename, const wchar_t* mode) +bool plZlibStream::Open(const plFileName& filename, const char* mode) { fFilename = filename; fMode = mode; fOutput = new hsUNIXStream; - return fOutput->Open(filename, L"wb"); + return fOutput->Open(filename, "wb"); } bool plZlibStream::Close() @@ -298,7 +288,7 @@ void plZlibStream::Rewind() { // hack so rewind will work (someone thought it would be funny to not implement base class functions) Close(); - Open(fFilename.c_str(), fMode.c_str()); + Open(fFilename, fMode); fHeader = kNeedMoreData; fDecompressedOk = false; } diff --git a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h index a387402e..d7d1b40b 100644 --- a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h +++ b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h @@ -60,7 +60,9 @@ protected: Validate fHeader; std::vector fHeaderCache; - std::wstring fFilename, fMode; // needed for rewind function + // needed for rewind function + plFileName fFilename; + const char* fMode; int IValidateGzHeader(uint32_t byteCount, const void* buffer); @@ -68,8 +70,7 @@ public: plZlibStream(); virtual ~plZlibStream(); - virtual bool Open(const char* filename, const char* mode); - virtual bool Open(const wchar_t* filename, const wchar_t* mode); + virtual bool Open(const plFileName& filename, const char* mode); virtual bool Close(); virtual uint32_t Write(uint32_t byteCount, const void* buffer); diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index 60367d58..63cefc63 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp @@ -117,21 +117,11 @@ void plEncryptedStream::IDecipher(uint32_t* const v) v[0]=y; v[1]=z; } -bool plEncryptedStream::Open(const char* name, const char* mode) +bool plEncryptedStream::Open(const plFileName& name, const char* mode) { - wchar_t* wName = hsStringToWString(name); - wchar_t* wMode = hsStringToWString(mode); - bool ret = Open(wName, wMode); - delete [] wName; - delete [] wMode; - return ret; -} - -bool plEncryptedStream::Open(const wchar_t* name, const wchar_t* mode) -{ - if (wcscmp(mode, L"rb") == 0) + if (strcmp(mode, "rb") == 0) { - fRef = hsWFopen(name, mode); + fRef = plFileSystem::Open(name, mode); fPosition = 0; if (!fRef) @@ -156,11 +146,10 @@ bool plEncryptedStream::Open(const wchar_t* name, const wchar_t* mode) return true; } - else if (wcscmp(mode, L"wb") == 0) + else if (strcmp(mode, "wb") == 0) { fRAMStream = new hsVectorStream; - fWriteFileName = new wchar_t[wcslen(name) + 1]; - wcscpy(fWriteFileName, name); + fWriteFileName = name; fPosition = 0; fOpenMode = kOpenWrite; @@ -197,12 +186,7 @@ bool plEncryptedStream::Close() fRAMStream = nil; } - if (fWriteFileName) - { - delete [] fWriteFileName; - fWriteFileName = nil; - } - + fWriteFileName = plString::Null; fActualFileSize = 0; fBufferedStream = false; fOpenMode = kOpenFail; @@ -389,11 +373,11 @@ uint32_t plEncryptedStream::Write(uint32_t bytes, const void* buffer) return fRAMStream->Write(bytes, buffer); } -bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar_t* outputFile) +bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const plFileName& outputFile) { hsUNIXStream outputStream; - if (!outputStream.Open(outputFile, L"wb")) + if (!outputStream.Open(outputFile, "wb")) return false; outputStream.Write(kMagicStringLen, kMagicString); @@ -439,15 +423,7 @@ bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar_t* ou return true; } -bool plEncryptedStream::FileEncrypt(const char* fileName) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = FileEncrypt(wFilename); - delete [] wFilename; - return ret; -} - -bool plEncryptedStream::FileEncrypt(const wchar_t* fileName) +bool plEncryptedStream::FileEncrypt(const plFileName& fileName) { hsUNIXStream sIn; if (!sIn.Open(fileName)) @@ -462,36 +438,28 @@ bool plEncryptedStream::FileEncrypt(const wchar_t* fileName) sIn.Rewind(); plEncryptedStream sOut; - bool wroteEncrypted = sOut.IWriteEncypted(&sIn, L"crypt.dat"); + bool wroteEncrypted = sOut.IWriteEncypted(&sIn, "crypt.dat"); sIn.Close(); sOut.Close(); if (wroteEncrypted) { - plFileUtils::RemoveFile(fileName); - plFileUtils::FileMove(L"crypt.dat", fileName); + plFileSystem::Unlink(fileName); + plFileSystem::Move("crypt.dat", fileName); } return true; } -bool plEncryptedStream::FileDecrypt(const char* fileName) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = FileDecrypt(wFilename); - delete [] wFilename; - return ret; -} - -bool plEncryptedStream::FileDecrypt(const wchar_t* fileName) +bool plEncryptedStream::FileDecrypt(const plFileName& fileName) { plEncryptedStream sIn; if (!sIn.Open(fileName)) return false; hsUNIXStream sOut; - if (!sOut.Open(L"crypt.dat", L"wb")) + if (!sOut.Open("crypt.dat", "wb")) { sIn.Close(); return false; @@ -508,32 +476,23 @@ bool plEncryptedStream::FileDecrypt(const wchar_t* fileName) sIn.Close(); sOut.Close(); - plFileUtils::RemoveFile(fileName); - plFileUtils::FileMove(L"crypt.dat", fileName); + plFileSystem::Unlink(fileName); + plFileSystem::Move("crypt.dat", fileName); return true; } bool plEncryptedStream::ICheckMagicString(FILE* fp) { - char magicString[kMagicStringLen+1]; + char magicString[kMagicStringLen]; fread(&magicString, kMagicStringLen, 1, fp); - magicString[kMagicStringLen] = '\0'; - return strcmp(magicString, kMagicString) == 0 || - strcmp(magicString, kOldMagicString) == 0; + return memcmp(magicString, kMagicString, kMagicStringLen) == 0 || + memcmp(magicString, kOldMagicString, kMagicStringLen) == 0; } -bool plEncryptedStream::IsEncryptedFile(const char* fileName) +bool plEncryptedStream::IsEncryptedFile(const plFileName& fileName) { - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = IsEncryptedFile(wFilename); - delete [] wFilename; - return ret; -} - -bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName) -{ - FILE* fp = hsWFopen(fileName, L"rb"); + FILE* fp = plFileSystem::Open(fileName, "rb"); if (!fp) return false; @@ -544,15 +503,7 @@ bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName) return isEncrypted; } -hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, uint32_t* cryptKey) -{ - wchar_t* wFilename = hsStringToWString(fileName); - hsStream* ret = OpenEncryptedFile(wFilename, cryptKey); - delete [] wFilename; - return ret; -} - -hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, uint32_t* cryptKey) +hsStream* plEncryptedStream::OpenEncryptedFile(const plFileName& fileName, uint32_t* cryptKey) { bool isEncrypted = IsEncryptedFile(fileName); @@ -563,19 +514,11 @@ hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, uint32_t else s = new hsUNIXStream; - s->Open(fileName, L"rb"); + s->Open(fileName, "rb"); return s; } -hsStream* plEncryptedStream::OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey) -{ - wchar_t* wFilename = hsStringToWString(fileName); - hsStream* ret = OpenEncryptedFileWrite(wFilename, cryptKey); - delete [] wFilename; - return ret; -} - -hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey) +hsStream* plEncryptedStream::OpenEncryptedFileWrite(const plFileName& fileName, uint32_t* cryptKey) { hsStream* s = nil; if (IsEncryptedFile(fileName)) @@ -583,6 +526,6 @@ hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uin else s = new hsUNIXStream; - s->Open(fileName, L"wb"); + s->Open(fileName, "wb"); return s; } diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h index 86ca0f5f..60c65fab 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h @@ -61,7 +61,7 @@ protected: hsStream* fRAMStream; - wchar_t* fWriteFileName; + plFileName fWriteFileName; enum OpenMode { kOpenRead, kOpenWrite, kOpenFail }; OpenMode fOpenMode; @@ -73,7 +73,7 @@ protected: void IEncipher(uint32_t* const v); void IDecipher(uint32_t* const v); - bool IWriteEncypted(hsStream* sourceStream, const wchar_t* outputFile); + bool IWriteEncypted(hsStream* sourceStream, const plFileName& outputFile); static bool ICheckMagicString(FILE* fp); @@ -82,8 +82,7 @@ public: plEncryptedStream(uint32_t* key=nil); ~plEncryptedStream(); - virtual bool Open(const char* name, const char* mode = "rb"); - virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb"); + virtual bool Open(const plFileName& name, const char* mode = "rb"); virtual bool Close(); virtual uint32_t Read(uint32_t byteCount, void* buffer); @@ -96,21 +95,16 @@ public: uint32_t GetActualFileSize() const { return fActualFileSize;} - static bool FileEncrypt(const char* fileName); - static bool FileEncrypt(const wchar_t* fileName); - static bool FileDecrypt(const char* fileName); - static bool FileDecrypt(const wchar_t* fileName); + static bool FileEncrypt(const plFileName& fileName); + static bool FileDecrypt(const plFileName& fileName); - static bool IsEncryptedFile(const char* fileName); - static bool IsEncryptedFile(const wchar_t* fileName); + static bool IsEncryptedFile(const plFileName& fileName); // Attempts to create a read-binary stream for the requested file. If it's // encrypted, you'll get a plEncryptedStream, otherwise just a standard // hsUNIXStream. Remember to delete the stream when you're done with it. - static hsStream* OpenEncryptedFile(const char* fileName, uint32_t* cryptKey = nil); - static hsStream* OpenEncryptedFile(const wchar_t* fileName, uint32_t* cryptKey = nil); - static hsStream* OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey = nil); - static hsStream* OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey = nil); + static hsStream* OpenEncryptedFile(const plFileName& fileName, uint32_t* cryptKey = nil); + static hsStream* OpenEncryptedFileWrite(const plFileName& fileName, uint32_t* cryptKey = nil); }; #endif // plEncryptedStream_h_inc diff --git a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp b/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp index 81a176d6..ba17aea7 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp @@ -493,7 +493,7 @@ uint32_t plFileUtils::GetFileSize( const wchar_t *path ) uint32_t len = 0; hsUNIXStream str; - if (str.Open(path, L"rb")) + if (str.Open(plString::FromWchar(path), "rb")) { len = str.GetEOF(); str.Close(); diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index 2b138543..caa42557 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -66,7 +66,6 @@ static const int kFileStartOffset = kMagicStringLen + sizeof(uint32_t); static const int kMaxBufferedFileSize = 10*1024; const char plSecureStream::kKeyFilename[] = "encryption.key"; -const wchar_t plSecureStream::kWKeyFilename[] = L"encryption.key"; plSecureStream::plSecureStream(bool deleteOnExit, uint32_t* key) : fRef(INVALID_HANDLE_VALUE), @@ -155,24 +154,14 @@ void plSecureStream::IDecipher(uint32_t* const v, uint32_t n) } } -bool plSecureStream::Open(const char* name, const char* mode) +bool plSecureStream::Open(const plFileName& name, const char* mode) { - wchar_t* wName = hsStringToWString(name); - wchar_t* wMode = hsStringToWString(mode); - bool ret = Open(wName, wMode); - delete [] wName; - delete [] wMode; - return ret; -} - -bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode) -{ - if (wcscmp(mode, L"rb") == 0) + if (strcmp(mode, "rb") == 0) { #if HS_BUILD_FOR_WIN32 if (fDeleteOnExit) { - fRef = CreateFileW(name, + fRef = CreateFileW(name.AsString().ToWchar(), GENERIC_READ, // open for reading 0, // no one can open the file until we're done NULL, // default security @@ -182,7 +171,7 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode) } else { - fRef = CreateFileW(name, + fRef = CreateFileW(name.AsString().ToWchar(), GENERIC_READ, // open for reading 0, // no one can open the file until we're done NULL, // default security @@ -207,10 +196,7 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode) DWORD numBytesRead; ReadFile(fRef, &fActualFileSize, sizeof(uint32_t), &numBytesRead, NULL); #elif HS_BUILD_FOR_UNIX - const char* cname = hsWStringToString(name); - fRef = fopen(cname, "rb"); - delete[] cname; - + fRef = plFileSystem::Open(name, "rb"); fPosition = 0; if (fRef == INVALID_HANDLE_VALUE) @@ -234,11 +220,10 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode) return true; } - else if (wcscmp(mode, L"wb") == 0) + else if (strcmp(mode, "wb") == 0) { fRAMStream = new hsVectorStream; - fWriteFileName = new wchar_t[wcslen(name) + 1]; - wcscpy(fWriteFileName, name); + fWriteFileName = name; fPosition = 0; fOpenMode = kOpenWrite; @@ -312,12 +297,7 @@ bool plSecureStream::Close() fRAMStream = nil; } - if (fWriteFileName) - { - delete [] fWriteFileName; - fWriteFileName = nil; - } - + fWriteFileName = plString::Null; fActualFileSize = 0; fBufferedStream = false; fOpenMode = kOpenFail; @@ -528,11 +508,11 @@ uint32_t plSecureStream::Write(uint32_t bytes, const void* buffer) return fRAMStream->Write(bytes, buffer); } -bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar_t* outputFile) +bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const plFileName& outputFile) { hsUNIXStream outputStream; - if (!outputStream.Open(outputFile, L"wb")) + if (!outputStream.Open(outputFile, "wb")) return false; outputStream.Write(kMagicStringLen, kMagicString); @@ -578,15 +558,7 @@ bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar_t* outp return true; } -bool plSecureStream::FileEncrypt(const char* fileName, uint32_t* key /* = nil */) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = FileEncrypt(wFilename, key); - delete [] wFilename; - return ret; -} - -bool plSecureStream::FileEncrypt(const wchar_t* fileName, uint32_t* key /* = nil */) +bool plSecureStream::FileEncrypt(const plFileName& fileName, uint32_t* key /* = nil */) { hsUNIXStream sIn; if (!sIn.Open(fileName)) @@ -601,36 +573,28 @@ bool plSecureStream::FileEncrypt(const wchar_t* fileName, uint32_t* key /* = nil sIn.Rewind(); plSecureStream sOut(false, key); - bool wroteEncrypted = sOut.IWriteEncrypted(&sIn, L"crypt.dat"); + bool wroteEncrypted = sOut.IWriteEncrypted(&sIn, "crypt.dat"); sIn.Close(); sOut.Close(); if (wroteEncrypted) { - plFileUtils::RemoveFile(fileName); - plFileUtils::FileMove(L"crypt.dat", fileName); + plFileSystem::Unlink(fileName); + plFileSystem::Move("crypt.dat", fileName); } return true; } -bool plSecureStream::FileDecrypt(const char* fileName, uint32_t* key /* = nil */) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = FileDecrypt(wFilename, key); - delete [] wFilename; - return ret; -} - -bool plSecureStream::FileDecrypt(const wchar_t* fileName, uint32_t* key /* = nil */) +bool plSecureStream::FileDecrypt(const plFileName& fileName, uint32_t* key /* = nil */) { plSecureStream sIn(false, key); if (!sIn.Open(fileName)) return false; hsUNIXStream sOut; - if (!sOut.Open(L"crypt.dat", L"wb")) + if (!sOut.Open("crypt.dat", "wb")) { sIn.Close(); return false; @@ -647,8 +611,8 @@ bool plSecureStream::FileDecrypt(const wchar_t* fileName, uint32_t* key /* = nil sIn.Close(); sOut.Close(); - plFileUtils::RemoveFile(fileName); - plFileUtils::FileMove(L"crypt.dat", fileName); + plFileSystem::Unlink(fileName); + plFileSystem::Move("crypt.dat", fileName); return true; } @@ -674,20 +638,12 @@ bool plSecureStream::ICheckMagicString(hsFD fp) return (strcmp(magicString, kMagicString) == 0); } -bool plSecureStream::IsSecureFile(const char* fileName) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool ret = IsSecureFile(wFilename); - delete [] wFilename; - return ret; -} - -bool plSecureStream::IsSecureFile(const wchar_t* fileName) +bool plSecureStream::IsSecureFile(const plFileName& fileName) { hsFD fp = INVALID_HANDLE_VALUE; #if HS_BUILD_FOR_WIN32 - fp = CreateFileW(fileName, + fp = CreateFileW(fileName.AsString().ToWchar(), GENERIC_READ, // open for reading 0, // no one can open the file until we're done NULL, // default security @@ -695,9 +651,7 @@ bool plSecureStream::IsSecureFile(const wchar_t* fileName) FILE_ATTRIBUTE_NORMAL, // normal file attributes NULL); // no template #elif HS_BUILD_FOR_UNIX - const char* cfile = hsWStringToString(fileName); - fp = fopen(cfile, "rb"); - delete[] cfile; + fp = plFileSystem::Open(fileName); #endif if (fp == INVALID_HANDLE_VALUE) @@ -714,15 +668,7 @@ bool plSecureStream::IsSecureFile(const wchar_t* fileName) return isEncrypted; } -hsStream* plSecureStream::OpenSecureFile(const char* fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */) -{ - wchar_t* wFilename = hsStringToWString(fileName); - hsStream* ret = OpenSecureFile(wFilename, flags, key); - delete [] wFilename; - return ret; -} - -hsStream* plSecureStream::OpenSecureFile(const wchar_t* fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */) +hsStream* plSecureStream::OpenSecureFile(const plFileName& fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */) { bool requireEncryption = flags & kRequireEncryption; #ifndef PLASMA_EXTERNAL_RELEASE @@ -739,19 +685,11 @@ hsStream* plSecureStream::OpenSecureFile(const wchar_t* fileName, const uint32_t s = new hsUNIXStream; if (s) - s->Open(fileName, L"rb"); + s->Open(fileName, "rb"); return s; } -hsStream* plSecureStream::OpenSecureFileWrite(const char* fileName, uint32_t* key /* = nil */) -{ - wchar_t* wFilename = hsStringToWString(fileName); - hsStream* ret = OpenSecureFileWrite(wFilename, key); - delete [] wFilename; - return ret; -} - -hsStream* plSecureStream::OpenSecureFileWrite(const wchar_t* fileName, uint32_t* key /* = nil */) +hsStream* plSecureStream::OpenSecureFileWrite(const plFileName& fileName, uint32_t* key /* = nil */) { hsStream* s = nil; #ifdef PLASMA_EXTERNAL_RELEASE @@ -760,46 +698,22 @@ hsStream* plSecureStream::OpenSecureFileWrite(const wchar_t* fileName, uint32_t* s = new hsUNIXStream; #endif - s->Open(fileName, L"wb"); + s->Open(fileName, "wb"); return s; } //// GetSecureEncryptionKey ////////////////////////////////////////////////// -bool plSecureStream::GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length) -{ - wchar_t* wFilename = hsStringToWString(filename); - bool ret = GetSecureEncryptionKey(wFilename, key, length); - delete [] wFilename; - return ret; -} - -bool plSecureStream::GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length) +bool plSecureStream::GetSecureEncryptionKey(const plFileName& filename, uint32_t* key, unsigned length) { // looks for an encryption key file in the same directory, and reads it - std::wstring sFilename = filename; - - // grab parent directory - size_t loc = sFilename.rfind(L"\\"); - if (loc == std::wstring::npos) - loc = sFilename.rfind(L"/"); - - std::wstring sDir; - if (loc != std::wstring::npos) - sDir = sFilename.substr(0, loc); - else // no directory - sDir = L"./"; - if ((sDir[sDir.length()-1] != L'/') && (sDir[sDir.length()-1] != L'\\')) - sDir += L'/'; // add the slash, if it doesn't has one - - // now add the key filename - std::wstring keyFile = sDir + kWKeyFilename; + plFileName keyFile = plFileName::Join(filename.StripFileName(), kKeyFilename); - if (plFileUtils::FileExists(keyFile.c_str())) + if (plFileInfo(keyFile).Exists()) { // file exists, read from it hsUNIXStream file; - file.Open(keyFile.c_str(), L"rb"); + file.Open(keyFile, "rb"); unsigned bytesToRead = length * sizeof(uint32_t); uint8_t* buffer = (uint8_t*)malloc(bytesToRead); diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h index 2f986fda..48ee2449 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h @@ -68,8 +68,8 @@ protected: bool fBufferedStream; hsStream* fRAMStream; - - wchar_t* fWriteFileName; + + plFileName fWriteFileName; enum OpenMode {kOpenRead, kOpenWrite, kOpenFail}; OpenMode fOpenMode; @@ -83,7 +83,7 @@ protected: void IEncipher(uint32_t* const v, uint32_t n); void IDecipher(uint32_t* const v, uint32_t n); - bool IWriteEncrypted(hsStream* sourceStream, const wchar_t* outputFile); + bool IWriteEncrypted(hsStream* sourceStream, const plFileName& outputFile); static bool ICheckMagicString(hsFD fp); static bool ICheckMagicString(hsStream* s); @@ -93,9 +93,8 @@ public: plSecureStream(hsStream* base, uint32_t* key = nil); ~plSecureStream(); - virtual bool Open(const char* name, const char* mode = "rb"); - virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb"); - bool Open(hsStream* stream); + virtual bool Open(const plFileName& name, const char* mode = "rb"); + bool Open(hsStream* stream); virtual bool Close(); virtual uint32_t Read(uint32_t byteCount, void* buffer); @@ -108,10 +107,8 @@ public: uint32_t GetActualFileSize() const {return fActualFileSize;} - static bool FileEncrypt(const char* fileName, uint32_t* key = nil); - static bool FileEncrypt(const wchar_t* fileName, uint32_t* key = nil); - static bool FileDecrypt(const char* fileName, uint32_t* key = nil); - static bool FileDecrypt(const wchar_t* fileName, uint32_t* key = nil); + static bool FileEncrypt(const plFileName& fileName, uint32_t* key = nil); + static bool FileDecrypt(const plFileName& fileName, uint32_t* key = nil); enum OpenSecureFileFlags { @@ -119,28 +116,23 @@ public: kDeleteOnExit = 0x02, }; - static bool IsSecureFile(const char* fileName); - static bool IsSecureFile(const wchar_t* fileName); + static bool IsSecureFile(const plFileName& fileName); // Attempts to create a read-binary stream for the requested file (delete the stream // when you are done with it!) - static hsStream* OpenSecureFile(const char* fileName, const uint32_t flags = kRequireEncryption, uint32_t* key = nil); - static hsStream* OpenSecureFile(const wchar_t* fileName, const uint32_t flags = kRequireEncryption, uint32_t* key = nil); + static hsStream* OpenSecureFile(const plFileName& fileName, const uint32_t flags = kRequireEncryption, uint32_t* key = nil); // Attempts to create a write-binary stream for the requested file (delete the stream // when you are done with it!) - static hsStream* OpenSecureFileWrite(const char* fileName, uint32_t* key = nil); - static hsStream* OpenSecureFileWrite(const wchar_t* fileName, uint32_t* key = nil); + static hsStream* OpenSecureFileWrite(const plFileName& fileName, uint32_t* key = nil); static const uint32_t kDefaultKey[4]; // our default encryption key // searches the parent directory of filename for the encryption key file, and reads it // into the key passed in. Returns false if the key file didn't exist (and sets key to // the default key) - static bool GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length); - static bool GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length); + static bool GetSecureEncryptionKey(const plFileName& filename, uint32_t* key, unsigned length); static const char kKeyFilename[]; - static const wchar_t kWKeyFilename[]; }; #endif // plSecureStream_h_inc diff --git a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp index d7b18dfd..d9d82580 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp @@ -51,25 +51,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # include #endif -void ToLower(std::wstring& str) -{ - for (unsigned i = 0; i < str.length(); i++) - str[i] = towlower(str[i]); -} - -void ReplaceSlashes(std::wstring& path, wchar_t replaceWith) -{ - for (unsigned i = 0; i < path.length(); i++) - { - if ((path[i] == L'\\') || (path[i] == L'/')) - path[i] = replaceWith; - } -} - void plStreamSource::ICleanup() { // loop through all the file data records, and delete the streams - std::map::iterator curData; + decltype(fFileData.begin()) curData; for (curData = fFileData.begin(); curData != fFileData.end(); curData++) { curData->second.fStream->Close(); @@ -80,137 +65,85 @@ void plStreamSource::ICleanup() fFileData.clear(); } -void plStreamSource::IBreakupFilename(std::wstring filename, std::wstring& dir, std::wstring& ext) +hsStream* plStreamSource::GetFile(const plFileName& filename) { - // break the filename up into its parts - char* temp = hsWStringToString(filename.c_str()); - std::string sFilename = temp; - std::string sExt = plFileUtils::GetFileExt(temp); - plFileUtils::StripFile(temp); - std::string sDir = temp; - delete [] temp; - - if (sDir == sFilename) // no directory - sDir = ""; - if (sDir != "") - if ((sDir[sDir.length()-1] == '/') || (sDir[sDir.length()-1] == '\\')) - sDir = sDir.substr(0, sDir.length() - 1); // trim the slash, if it has one - - wchar_t* wTemp; - wTemp = hsStringToWString(sDir.c_str()); - dir = wTemp; - delete [] wTemp; - wTemp = hsStringToWString(sExt.c_str()); - ext = wTemp; - delete [] wTemp; -} - -hsStream* plStreamSource::GetFile(std::wstring filename) -{ - ToLower(filename); - ReplaceSlashes(filename, L'/'); - - if (fFileData.find(filename) == fFileData.end()) + plFileName sFilename = filename.Normalize('/'); + if (fFileData.find(sFilename) == fFileData.end()) { #ifndef PLASMA_EXTERNAL_RELEASE // internal releases can pull from disk - char* temp = hsWStringToString(filename.c_str()); - std::string sFilename = temp; - delete [] temp; - - if (plFileUtils::FileExists(sFilename.c_str())) + if (plFileInfo(filename).Exists()) { // file exists on disk, cache it - std::wstring dir, ext; - IBreakupFilename(filename, dir, ext); - fFileData[filename].fFilename = filename; - fFileData[filename].fDir = dir; - fFileData[filename].fExt = ext; - if (plSecureStream::IsSecureFile(sFilename.c_str())) + fFileData[sFilename].fFilename = sFilename; + fFileData[sFilename].fDir = sFilename.StripFileName(); + fFileData[sFilename].fExt = sFilename.GetFileExt(); + if (plSecureStream::IsSecureFile(filename)) { uint32_t encryptionKey[4]; - if (!plSecureStream::GetSecureEncryptionKey(sFilename.c_str(), encryptionKey, 4)) + if (!plSecureStream::GetSecureEncryptionKey(filename, encryptionKey, 4)) { FATAL("Hey camper... You need an NTD key file!"); return nil; } - fFileData[filename].fStream = plSecureStream::OpenSecureFile(sFilename.c_str(), 0, encryptionKey); + fFileData[sFilename].fStream = plSecureStream::OpenSecureFile(filename, 0, encryptionKey); } else // otherwise it is an encrypted or plain stream, this call handles both - fFileData[filename].fStream = plEncryptedStream::OpenEncryptedFile(sFilename.c_str()); + fFileData[sFilename].fStream = plEncryptedStream::OpenEncryptedFile(filename); - return fFileData[filename].fStream; + return fFileData[sFilename].fStream; } #endif // PLASMA_EXTERNAL_RELEASE return nil; } - return fFileData[filename].fStream; + return fFileData[sFilename].fStream; } -std::vector plStreamSource::GetListOfNames(std::wstring dir, std::wstring ext) +std::vector plStreamSource::GetListOfNames(const plFileName& dir, const plString& ext) { - ToLower(ext); - ToLower(dir); - ReplaceSlashes(dir, L'/'); - - if (ext[0] == L'.') - ext = ext.substr(1, ext.length()); // trim the dot, if it has one - if (dir != L"") - if ((dir[dir.length()-1] == L'/') || (dir[dir.length()-1] == L'\\')) - dir = dir.substr(0, dir.length() - 1); // trim the slash, if it has one + plFileName sDir = dir.Normalize('/'); + hsAssert(ext.CharAt(0) != '.', "Don't add a dot"); // loop through all the file data records, and create the list - std::vector retVal; - std::map::iterator curData; + std::vector retVal; + decltype(fFileData.begin()) curData; for (curData = fFileData.begin(); curData != fFileData.end(); curData++) { - if ((curData->second.fDir == dir.c_str()) && (curData->second.fExt == ext)) + if ((curData->second.fDir == sDir) && (curData->second.fExt == ext)) retVal.push_back(curData->second.fFilename); } #ifndef PLASMA_EXTERNAL_RELEASE // in internal releases, we can use on-disk files if they exist // Build the search string as "dir/*.ext" - std::wstring wSearchStr = dir + L"/*." + ext; - char* temp = hsWStringToString(wSearchStr.c_str()); - std::string searchStr = temp; - delete [] temp; + plString searchStr = plFileName::Join(sDir, "*." + ext).AsString(); hsFolderIterator folderIter(searchStr.c_str(), true); while (folderIter.NextFile()) { - const char* filename = folderIter.GetFileName(); - wchar_t* wTemp = hsStringToWString(filename); - std::wstring wFilename = dir + L"/" + wTemp; - delete [] wTemp; - ToLower(wFilename); - - if (fFileData.find(wFilename) == fFileData.end()) // we haven't added it yet - retVal.push_back(wFilename); + plFileName filename = plFileName::Join(sDir, folderIter.GetFileName()); + + if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet + retVal.push_back(filename); } #endif // PLASMA_EXTERNAL_RELEASE return retVal; } -bool plStreamSource::InsertFile(std::wstring filename, hsStream* stream) +bool plStreamSource::InsertFile(const plFileName& filename, hsStream* stream) { - ToLower(filename); - ReplaceSlashes(filename, L'/'); + plFileName sFilename = filename.Normalize('/'); - if (fFileData.find(filename) != fFileData.end()) + if (fFileData.find(sFilename) != fFileData.end()) return false; // duplicate entry, return failure - // break the filename up into its parts - std::wstring dir, ext; - IBreakupFilename(filename, dir, ext); - // copy the data over (takes ownership of the stream!) - fFileData[filename].fFilename = filename; - fFileData[filename].fDir = dir; - fFileData[filename].fExt = ext; - fFileData[filename].fStream = stream; + fFileData[sFilename].fFilename = sFilename; + fFileData[sFilename].fDir = sFilename.StripFileName(); + fFileData[sFilename].fExt = sFilename.GetFileExt(); + fFileData[sFilename].fStream = stream; return true; } diff --git a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.h b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.h index 817e2901..a565ad95 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.h +++ b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.h @@ -54,15 +54,14 @@ class plStreamSource private: struct fileData { - std::wstring fFilename; // includes path - std::wstring fDir; // parent directory - std::wstring fExt; + plFileName fFilename; // includes path + plFileName fDir; // parent directory + plString fExt; hsStream* fStream; // we own this pointer, so clean it up }; - std::map fFileData; // key is filename + std::map fFileData; // key is filename void ICleanup(); // closes all file pointers and cleans up after itself - void IBreakupFilename(std::wstring filename, std::wstring& dir, std::wstring& ext); plStreamSource() {} public: @@ -72,11 +71,11 @@ public: void Cleanup() {ICleanup();} // File access functions - hsStream* GetFile(std::wstring filename); // internal builds will read from disk if it doesn't exist - std::vector GetListOfNames(std::wstring dir, std::wstring ext); // internal builds merge from disk + hsStream* GetFile(const plFileName& filename); // internal builds will read from disk if it doesn't exist + std::vector GetListOfNames(const plFileName& dir, const plString& ext); // internal builds merge from disk // For other classes to insert files (takes ownership of the stream if successful) - bool InsertFile(std::wstring filename, hsStream* stream); + bool InsertFile(const plFileName& filename, hsStream* stream); // Instance handling static plStreamSource* GetInstance(); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp b/Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp index e7796b1b..13d64af8 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp @@ -232,20 +232,12 @@ plMipmap *plJPEG::IRead( hsStream *inStream ) return newMipmap; } -plMipmap* plJPEG::ReadFromFile( const char *fileName ) -{ - wchar_t* wFilename = hsStringToWString(fileName); - plMipmap* retVal = ReadFromFile(wFilename); - delete [] wFilename; - return retVal; -} - -plMipmap* plJPEG::ReadFromFile( const wchar_t *fileName ) +plMipmap* plJPEG::ReadFromFile( const plFileName &fileName ) { // we use a stream because the IJL can't handle unicode hsRAMStream tempstream; hsUNIXStream in; - if (!in.Open(fileName, L"rb")) + if (!in.Open(fileName, "rb")) return nil; // The stream reader for JPEGs expects a 32-bit size at the start, @@ -360,20 +352,12 @@ bool plJPEG::IWrite( plMipmap *source, hsStream *outStream ) return result; } -bool plJPEG::WriteToFile( const char *fileName, plMipmap *sourceData ) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool retVal = WriteToFile(wFilename, sourceData); - delete [] wFilename; - return retVal; -} - -bool plJPEG::WriteToFile( const wchar_t *fileName, plMipmap *sourceData ) +bool plJPEG::WriteToFile( const plFileName &fileName, plMipmap *sourceData ) { // we use a stream because the IJL can't handle unicode hsRAMStream tempstream; hsUNIXStream out; - if (!out.Open(fileName, L"wb")) + if (!out.Open(fileName, "wb")) return false; bool ret = IWrite(sourceData, &tempstream); if (ret) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plJPEG.h b/Sources/Plasma/PubUtilLib/plGImage/plJPEG.h index cdf7478c..7804a5fb 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plJPEG.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plJPEG.h @@ -58,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com class plMipmap; class hsStream; +class plFileName; class plJPEG { @@ -74,12 +75,10 @@ class plJPEG public: plMipmap *ReadFromStream( hsStream *inStream ) { return IRead( inStream ); } - plMipmap *ReadFromFile( const char *fileName ); - plMipmap *ReadFromFile( const wchar_t *fileName ); + plMipmap *ReadFromFile( const plFileName &fileName ); bool WriteToStream( hsStream *outStream, plMipmap *sourceData ) { return IWrite( sourceData, outStream ); } - bool WriteToFile( const char *fileName, plMipmap *sourceData ); - bool WriteToFile( const wchar_t *fileName, plMipmap *sourceData ); + bool WriteToFile( const plFileName &fileName, plMipmap *sourceData ); // Range is 0 (worst) to 100 (best) void SetWriteQuality( uint8_t q ) { fWriteQuality = q; } diff --git a/Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp b/Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp index dba495c8..9e8c3253 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp @@ -178,19 +178,11 @@ plMipmap* plPNG::IRead(hsStream* inStream) return newMipmap; } -plMipmap* plPNG::ReadFromFile(const char* fileName) -{ - wchar_t* wFilename = hsStringToWString(fileName); - plMipmap* retVal = ReadFromFile(wFilename); - delete [] wFilename; - return retVal; -} - -plMipmap* plPNG::ReadFromFile(const wchar_t* fileName) +plMipmap* plPNG::ReadFromFile(const plFileName& fileName) { hsUNIXStream in; - if (!in.Open(fileName, L"rb")) { + if (!in.Open(fileName, "rb")) { return nil; } @@ -248,19 +240,11 @@ bool plPNG::IWrite(plMipmap* source, hsStream* outStream) return result; } -bool plPNG::WriteToFile(const char* fileName, plMipmap* sourceData) -{ - wchar_t* wFilename = hsStringToWString(fileName); - bool retVal = WriteToFile(wFilename, sourceData); - delete [] wFilename; - return retVal; -} - -bool plPNG::WriteToFile(const wchar_t* fileName, plMipmap* sourceData) +bool plPNG::WriteToFile(const plFileName& fileName, plMipmap* sourceData) { hsUNIXStream out; - if (!out.Open(fileName, L"wb")) { + if (!out.Open(fileName, "wb")) { return false; } diff --git a/Sources/Plasma/PubUtilLib/plGImage/plPNG.h b/Sources/Plasma/PubUtilLib/plGImage/plPNG.h index 96ced26b..d2f9be4d 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plPNG.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plPNG.h @@ -58,12 +58,10 @@ protected: public: plMipmap* ReadFromStream(hsStream* inStream) { return IRead(inStream); } - plMipmap* ReadFromFile(const char* fileName); - plMipmap* ReadFromFile(const wchar_t* fileName); + plMipmap* ReadFromFile(const plFileName& fileName); bool WriteToStream(hsStream* outStream, plMipmap* sourceData) { return IWrite(sourceData, outStream); } - bool WriteToFile(const char* fileName, plMipmap* sourceData); - bool WriteToFile(const wchar_t* fileName, plMipmap* sourceData); + bool WriteToFile(const plFileName& fileName, plMipmap* sourceData); static plPNG& Instance(void); }; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 4b931b43..107c8f66 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -5514,8 +5514,8 @@ void NetCliAuthAccountActivateRequest ( //============================================================================ void NetCliAuthFileListRequest ( - const wchar_t dir[], - const wchar_t ext[], + const wchar_t dir[], + const wchar_t ext[], FNetCliAuthFileListRequestCallback callback, void * param ) { @@ -5530,7 +5530,7 @@ void NetCliAuthFileListRequest ( //============================================================================ void NetCliAuthFileRequest ( - const wchar_t filename[], + const wchar_t filename[], hsStream * writer, FNetCliAuthFileRequestCallback callback, void * param diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index a8080cbb..71c4d0e3 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -348,7 +348,7 @@ void NetCliAuthGetEncryptionKey ( // File List //============================================================================ struct NetCliAuthFileInfo { - wchar_t filename[MAX_PATH]; + wchar_t filename[MAX_PATH]; unsigned filesize; }; typedef void (*FNetCliAuthFileListRequestCallback)( @@ -358,8 +358,8 @@ typedef void (*FNetCliAuthFileListRequestCallback)( unsigned infoCount ); void NetCliAuthFileListRequest ( - const wchar_t dir[], - const wchar_t ext[], + const wchar_t dir[], + const wchar_t ext[], FNetCliAuthFileListRequestCallback callback, void * param ); @@ -370,11 +370,11 @@ void NetCliAuthFileListRequest ( typedef void (*FNetCliAuthFileRequestCallback)( ENetError result, void * param, - const wchar_t filename[], + const wchar_t filename[], hsStream * writer ); void NetCliAuthFileRequest ( - const wchar_t filename[], + const wchar_t filename[], hsStream * writer, FNetCliAuthFileRequestCallback callback, void * param diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h index 845e8dc6..d6ab0ceb 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h @@ -97,10 +97,10 @@ void NetCliFileRegisterBuildIdUpdate (FNetCliFileBuildIdUpdateCallback callback) // Manifest //============================================================================ struct NetCliFileManifestEntry { - wchar_t clientName[MAX_PATH]; // path and file on client side (for comparison) - wchar_t downloadName[MAX_PATH]; // path and file on server side (for download) - wchar_t md5[MAX_PATH]; - wchar_t md5compressed[MAX_PATH]; // md5 for the compressed file + wchar_t clientName[MAX_PATH]; // path and file on client side (for comparison) + wchar_t downloadName[MAX_PATH]; // path and file on server side (for download) + wchar_t md5[MAX_PATH]; + wchar_t md5compressed[MAX_PATH]; // md5 for the compressed file unsigned fileSize; unsigned zipSize; unsigned flags; diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp index e9a1f4e8..9b9b0462 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp @@ -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); } - diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h index 917adbc9..431f5d58 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h @@ -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 diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 8bb7c0e2..de0b574b 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -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& 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"); } } diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h index 8d36e9a5..e6e6e073 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h @@ -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 diff --git a/Sources/Plasma/PubUtilLib/plSDL/plSDL.h b/Sources/Plasma/PubUtilLib/plSDL/plSDL.h index d02d2365..eca6473d 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDL.h +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDL.h @@ -510,10 +510,11 @@ class plSDLParser { private: bool IReadDescriptors() const; - bool ILoadSDLFile(const char* fileName) const; - bool IParseVarDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc, - plVarDescriptor*& curVar) const; - bool IParseStateDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc) const; + bool ILoadSDLFile(const plFileName& fileName) const; + bool IParseVarDesc(const plFileName& fileName, hsStream* stream, char token[], + plStateDescriptor*& curDesc, plVarDescriptor*& curVar) const; + bool IParseStateDesc(const plFileName& fileName, hsStream* stream, char token[], + plStateDescriptor*& curDesc) const; void DebugMsg(const char* fmt, ...) const; void DebugMsgV(const char* fmt, va_list args) const; diff --git a/Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h b/Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h index 12dff703..b496386b 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h @@ -48,8 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // #include "HeadSpin.h" -#include "plString.h" -#include +#include "plFileSystem.h" // // Describes a variable in a state descriptor. @@ -226,7 +225,7 @@ private: VarsList fVarsList; int fVersion; plString fName; - std::string fFilename; // the filename this descriptor was read from + plFileName fFilename; // the filename this descriptor was read from void IDeInit(); public: @@ -238,14 +237,14 @@ public: int GetNumVars() const { return fVarsList.size(); } plVarDescriptor* GetVar(int i) const { return fVarsList[i]; } int GetVersion() const { return fVersion; } - const char * GetFilename() const { return fFilename.c_str();} - + plFileName GetFilename() const { return fFilename; } + // setters void SetVersion(int v) { fVersion=v; } void SetName(const plString& n) { fName=n; } void AddVar(plVarDescriptor* v) { fVarsList.push_back(v); } - void SetFilename( const char * n ) { fFilename=n;} - + void SetFilename(const plFileName& n) { fFilename=n;} + plVarDescriptor* FindVar(const plString& name, int* idx=nil) const; // IO diff --git a/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp index 7b0a9a0e..c01f036b 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp @@ -77,7 +77,8 @@ void plSDLParser::DebugMsgV(const char* fmt, va_list args) const // read name, version // return true to skip the next token read // -bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc) const +bool plSDLParser::IParseStateDesc(const plFileName& fileName, hsStream* stream, char token[], + plStateDescriptor*& curDesc) const { plSDL::DescriptorList* descList = &plSDLMgr::GetInstance()->fDescriptors; @@ -108,7 +109,8 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t if (!strcmp(token, "VERSION")) { // read desc version - hsAssert(curDesc, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curDesc, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); if (stream->GetToken(token, kTokenLen)) { int v=atoi(token); @@ -119,13 +121,14 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t else { hsAssert(false, plString::Format("Error parsing state desc, missing VERSION, fileName=%s", - fileName).c_str()); + fileName.AsString().c_str()).c_str()); ok = false; } } else { - hsAssert(false, plString::Format("Error parsing state desc, fileName=%s", fileName).c_str()); + hsAssert(false, plString::Format("Error parsing state desc, fileName=%s", + fileName.AsString().c_str()).c_str()); ok = false; } @@ -134,8 +137,8 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t ok = ( plSDLMgr::GetInstance()->FindDescriptor(curDesc->GetName(), curDesc->GetVersion())==nil ); if ( !ok ) { - plString err = plString::Format( "Found duplicate SDL descriptor for %s version %d.\nFailed to parse file: %s", - curDesc->GetName().c_str(), curDesc->GetVersion(), fileName ); + plString err = plString::Format("Found duplicate SDL descriptor for %s version %d.\nFailed to parse file: %s", + curDesc->GetName().c_str(), curDesc->GetVersion(), fileName.AsString().c_str()); plNetApp::StaticErrorMsg( err.c_str() ); hsAssert( false, err.c_str() ); } @@ -159,10 +162,11 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t // read type, name, count [default] // return true to skip the next token read // -bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc, - plVarDescriptor*& curVar) const +bool plSDLParser::IParseVarDesc(const plFileName& fileName, hsStream* stream, char token[], + plStateDescriptor*& curDesc, plVarDescriptor*& curVar) const { - hsAssert(curDesc, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curDesc, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); if ( !curDesc ) return false; @@ -181,7 +185,7 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok char* sdlName = token+1; plStateDescriptor* stateDesc = plSDLMgr::GetInstance()->FindDescriptor(sdlName, plSDL::kLatestVersion); hsAssert(stateDesc, plString::Format("can't find nested state desc reference %s, fileName=%s", - sdlName, fileName).c_str()); + sdlName, fileName.AsString().c_str()).c_str()); curVar = new plSDVarDescriptor(stateDesc); } else @@ -189,7 +193,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok curDesc->AddVar(curVar); bool ok=curVar->SetType(token); - hsAssert(ok, plString::Format("Variable 'type' syntax problem with .sdl file, type=%s, fileName=%s", token, fileName).c_str()); + hsAssert(ok, plString::Format("Variable 'type' syntax problem with .sdl file, type=%s, fileName=%s", + token, fileName.AsString().c_str()).c_str()); dbgStr = plString::Format("\tVAR Type=%s ", token); // @@ -198,10 +203,11 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok if (stream->GetToken(token, kTokenLen)) { hsAssert(strstr(token, "[") && strstr(token, "]"), plString::Format("invalid var syntax, missing [x], fileName=%s", - fileName).c_str()); + fileName.AsString().c_str()).c_str()); char* ptr = strtok( token, seps ); // skip [ - hsAssert(curVar, plString::Format("Missing current var. Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Missing current var. Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); curVar->SetName(token); // // COUNT @@ -221,7 +227,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok { if (!strcmp(token, "DEFAULT")) { - hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); // read state var type plString defaultStr; @@ -248,7 +255,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok else if (!strcmp(token, "DISPLAYOPTION")) { - hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); dbgStr += plString(" ") + token; bool read=stream->GetToken(token, kTokenLen); @@ -265,13 +273,15 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok } else { - hsAssert(false, plString::Format("missing displayOption string, fileName=%s", fileName).c_str()); + hsAssert(false, plString::Format("missing displayOption string, fileName=%s", + fileName.AsString().c_str()).c_str()); } } else if (!strcmp(token, "DEFAULTOPTION")) { - hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); dbgStr += plString(" ") + token; bool read=stream->GetToken(token, kTokenLen); @@ -283,7 +293,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok } else { - hsAssert(false, plString::Format("missing defaultOption string, fileName=%s", fileName).c_str()); + hsAssert(false, plString::Format("missing defaultOption string, fileName=%s", + fileName.AsString().c_str()).c_str()); } } @@ -291,14 +302,16 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok else if (!strcmp(token, "INTERNAL")) { - hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); curVar->SetInternal(true); dbgStr += plString(" ") + token; } else if (!strcmp(token, "PHASED")) { - hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str()); + hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", + fileName.AsString().c_str()).c_str()); curVar->SetAlwaysNew(true); dbgStr += plString(" ") + token; } @@ -319,13 +332,11 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok // create state descriptor from sdl file. // return false on err. // -bool plSDLParser::ILoadSDLFile(const char* fileName) const +bool plSDLParser::ILoadSDLFile(const plFileName& fileName) const { - DebugMsg("Parsing SDL file %s", fileName); - - wchar_t* temp = hsStringToWString(fileName); - hsStream* stream = plStreamSource::GetInstance()->GetFile(temp); - delete [] temp; + DebugMsg("Parsing SDL file %s", fileName.AsString().c_str()); + + hsStream* stream = plStreamSource::GetInstance()->GetFile(fileName); if (!stream) return false; @@ -393,33 +404,27 @@ bool plSDLParser::ILoadSDLFile(const char* fileName) const // bool plSDLParser::IReadDescriptors() const { - std::string sdlDir = plSDLMgr::GetInstance()->GetSDLDir(); - DebugMsg("SDL: Reading latest descriptors from directory %s", sdlDir.c_str()); - - wchar_t* temp = hsStringToWString(sdlDir.c_str()); - std::wstring wSDLDir = temp; - delete [] temp; + plFileName sdlDir = plSDLMgr::GetInstance()->GetSDLDir(); + DebugMsg("SDL: Reading latest descriptors from directory %s", sdlDir.AsString().c_str()); // Get the names of all the sdl files - std::vector files = plStreamSource::GetInstance()->GetListOfNames(wSDLDir, L".sdl"); + std::vector files = plStreamSource::GetInstance()->GetListOfNames(sdlDir, "sdl"); bool ret=true; int cnt=0; for (int i = 0; i < files.size(); i++) { - char* str = hsWStringToString(files[i].c_str()); - if (!ILoadSDLFile(str)) + if (!ILoadSDLFile(files[i])) { plNetApp* netApp = plSDLMgr::GetInstance()->GetNetApp(); if (netApp) - netApp->ErrorMsg("Error loading SDL file %s", str); + netApp->ErrorMsg("Error loading SDL file %s", files[i].AsString().c_str()); else - hsStatusMessageF("Error loading SDL file %s", str); + hsStatusMessageF("Error loading SDL file %s", files[i].AsString().c_str()); ret=false; } else cnt++; - delete [] str; } DebugMsg("Done reading SDL files"); diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index 57b0353d..e213916f 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp @@ -174,20 +174,13 @@ void plAutoProfileImp::IInit() void plAutoProfileImp::IShutdown() { // KLUDGE - Copy the load timing log, in case we used it - #define kTimingLog L"readtimings.0.log" - #define kAgeTimingLog L"agetimings.0.log" - wchar_t destPath[MAX_PATH]; - wchar_t sourcePath[MAX_PATH]; + #define kTimingLog "readtimings.0.log" + #define kAgeTimingLog "agetimings.0.log" - PathAddFilename(destPath, plProfileManagerFull::Instance().GetProfilePath(), kTimingLog, arrsize(destPath)); - PathGetLogDirectory(sourcePath, arrsize(sourcePath)); - PathAddFilename(sourcePath, sourcePath, kTimingLog, arrsize(sourcePath)); - plFileUtils::FileCopy(sourcePath, destPath); - - PathAddFilename(destPath, plProfileManagerFull::Instance().GetProfilePath(), kAgeTimingLog, arrsize(destPath)); - PathGetLogDirectory(sourcePath, arrsize(sourcePath)); - PathAddFilename(sourcePath, sourcePath, kAgeTimingLog, arrsize(sourcePath)); - plFileUtils::FileCopy(sourcePath, destPath); + plFileSystem::Copy(plFileName::Join(plFileSystem::GetLogPath(), kTimingLog), + plFileName::Join(plProfileManagerFull::Instance().GetProfilePath(), kTimingLog)); + plFileSystem::Copy(plFileName::Join(plFileSystem::GetLogPath(), kAgeTimingLog), + plFileName::Join(plProfileManagerFull::Instance().GetProfilePath(), kAgeTimingLog)); #ifdef HS_BUILD_FOR_WIN32 ShellExecute(nil, nil, "PostRun.bat", nil, nil, SW_SHOWNORMAL); @@ -219,7 +212,7 @@ void plAutoProfileImp::INextProfile() if (!fLastSpawnPointName.IsNull()) { const char * ageName = NetCommGetAge()->ageDatasetName; - plProfileManagerFull::Instance().LogStats(ageName, fLastSpawnPointName.c_str()); + plProfileManagerFull::Instance().LogStats(ageName, fLastSpawnPointName); plMipmap mipmap; if (plClient::GetInstance()->GetPipeline()->CaptureScreen(&mipmap)) diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 6b07d00b..d5e09e71 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -418,40 +418,28 @@ void plProfileManagerFull::IPrintGroup(hsStream* s, const char* groupName, bool } } -void plProfileManagerFull::LogStats(const char* ageName, const char* spawnName) +void plProfileManagerFull::LogStats(const plString& ageName, const plString& spawnName) { fLogStats = true; - wchar_t* temp = hsStringToWString(ageName); - fLogAgeName = temp; - delete [] temp; + fLogAgeName = ageName; fLogSpawnName = spawnName; } -const wchar_t* plProfileManagerFull::GetProfilePath() +plFileName plProfileManagerFull::GetProfilePath() { - static wchar_t profilePath[MAX_PATH]; - static bool initialized = false; + static plFileName profilePath; - if (!initialized) + if (!profilePath.IsValid()) { - initialized = true; - plUnifiedTime curTime = plUnifiedTime::GetCurrent(plUnifiedTime::kLocal); - PathGetUserDirectory(profilePath, arrsize(profilePath)); - PathAddFilename(profilePath, profilePath, L"Profile", arrsize(profilePath)); - plFileUtils::CreateDir(profilePath); - - wchar_t buff[256]; - hsSnwprintf(buff, 256, L"%02d-%02d-%04d_%02d-%02d//", - curTime.GetMonth(), - curTime.GetDay(), - curTime.GetYear(), - curTime.GetHour(), - curTime.GetMinute()); - - PathAddFilename(profilePath, profilePath, buff, arrsize(profilePath)); - plFileUtils::CreateDir(profilePath); + profilePath = plFileName::Join(plFileSystem::GetUserDataPath(), "Profile", + plString::Format("%02d-%02d-%04d_%02d-%02d", + curTime.GetMonth(), curTime.GetDay(), + curTime.GetYear(), curTime.GetHour(), + curTime.GetMinute())); + + plFileSystem::CreateDir(profilePath, true); } return profilePath; @@ -459,13 +447,12 @@ const wchar_t* plProfileManagerFull::GetProfilePath() void plProfileManagerFull::ILogStats() { - wchar_t statFilename[256]; - hsSnwprintf(statFilename, 256, L"%s%s.csv", GetProfilePath(), fLogAgeName.c_str()); + plFileName statFilename = plFileName::Join(GetProfilePath(), fLogAgeName + ".csv"); - bool exists = plFileUtils::FileExists(statFilename); + bool exists = plFileInfo(statFilename).Exists(); hsUNIXStream s; - if (s.Open(statFilename, L"ab")) + if (s.Open(statFilename, "ab")) { GroupSet groups; GetGroups(groups); @@ -474,7 +461,7 @@ void plProfileManagerFull::ILogStats() if (!exists) { - const char* kSpawn = "Spawn"; + static const char kSpawn[] = "Spawn"; s.Write(strlen(kSpawn), kSpawn); s.WriteByte(','); @@ -487,7 +474,7 @@ void plProfileManagerFull::ILogStats() s.WriteByte('\n'); } - s.Write(fLogSpawnName.length(), fLogSpawnName.c_str()); + s.Write(fLogSpawnName.GetSize(), fLogSpawnName.c_str()); s.WriteByte(','); for (it = groups.begin(); it != groups.end(); it++) @@ -502,7 +489,7 @@ void plProfileManagerFull::ILogStats() } fLogStats = false; - fLogAgeName = L""; + fLogAgeName = ""; fLogSpawnName = ""; } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h index 167851eb..159005c3 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h @@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -#include "plString.h" +#include "plFileSystem.h" #include "plProfileManager.h" @@ -63,8 +63,8 @@ protected: plProfileManager::VarVec& fVars; bool fLogStats; // If true, log the stats at the end of the frame - std::wstring fLogAgeName; - std::string fLogSpawnName; + plString fLogAgeName; + plString fLogSpawnName; std::vector fGraphs; plGraphPlate* fDetailGraph; @@ -119,9 +119,9 @@ public: void UpdateDetailLabels(); void ResetMax(); - - void LogStats(const char* ageName, const char* spawnName); - const wchar_t* GetProfilePath(); + + void LogStats(const plString& ageName, const plString& spawnName); + plFileName GetProfilePath(); // If you're going to call LogStats, make sure to call this first so all stats will be evaluated before logging void ActivateAllStats(); diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 038e38c8..20140b34 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -87,21 +87,8 @@ plStatusLogMgr::plStatusLogMgr() fDrawer = nil; fLastLogChangeTime = 0; -#if HS_BUILD_FOR_WIN32 - SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE); -//#elif HS_BUILD_FOR_DARWIN -// Do some Mac specific thing here eventually -#else - const char* home = getenv("HOME"); - if (!home) home = ""; - wchar_t* temp = hsStringToWString(home); - swprintf(fBasePath, MAX_PATH, L"%S/.cache", temp); - delete[] temp; -#endif - - plFileUtils::ConcatFileName(fBasePath, plProduct::LongName().ToWchar()); - plFileUtils::ConcatFileName(fBasePath, L"Log"); - plFileUtils::EnsureFilePathExists(fBasePath); + // Ensure the log path is created + plFileSystem::GetLogPath(); } plStatusLogMgr::~plStatusLogMgr() diff --git a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp index 29483a79..8e329c1c 100644 --- a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp +++ b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp @@ -490,11 +490,10 @@ public: MaxStream(ILoad* iload) : fSave(nil), fLoad(iload) {} // Don't support any of this - virtual bool Open(const char *, const char * = "rb") { hsAssert(0, "Not supported"); return false; } - virtual bool Open(const wchar_t *, const wchar_t * = L"rb") { hsAssert(0, "Not supported"); return false; } + virtual bool Open(const plFileName &, const char * = "rb") { hsAssert(0, "Not supported"); return false; } virtual bool Close() { hsAssert(0, "Not supported"); return false; } - virtual void Skip(uint32_t deltaByteCount) { hsAssert(0, "Not supported"); } - virtual void Rewind() { hsAssert(0, "Not supported"); } + virtual void Skip(uint32_t deltaByteCount) { hsAssert(0, "Not supported"); } + virtual void Rewind() { hsAssert(0, "Not supported"); } virtual uint32_t GetEOF() { return (uint32_t)fLoad->CurChunkLength(); }