Browse Source

Replace hsStream::Open duplicated methods everywhere with a single plFileName interface

Michael Hansen 12 years ago
parent
commit
6f6ade2636
  1. 51
      Sources/Plasma/Apps/plClient/plClient.cpp
  2. 2
      Sources/Plasma/Apps/plClient/plClient.h
  3. 42
      Sources/Plasma/Apps/plClient/winmain.cpp
  4. 3
      Sources/Plasma/Apps/plMD5/Main.cpp
  5. 3
      Sources/Plasma/Apps/plSHA/Main.cpp
  6. 6
      Sources/Plasma/Apps/plUruLauncher/Main.cpp
  7. 3
      Sources/Plasma/CoreLib/hsSTLStream.h
  8. 34
      Sources/Plasma/CoreLib/hsStream.cpp
  9. 35
      Sources/Plasma/CoreLib/hsStream.h
  10. 8
      Sources/Plasma/CoreLib/plString.h
  11. 2
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  12. 4
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  13. 31
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp
  14. 27
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h
  15. 17
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp
  16. 4
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h
  17. 13
      Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp
  18. 13
      Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp
  19. 12
      Sources/Plasma/FeatureLib/pfPython/pyImage.cpp
  20. 8
      Sources/Plasma/FeatureLib/pfPython/pyImage.h
  21. 47
      Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp
  22. 14
      Sources/Plasma/FeatureLib/pfPython/pyStream.cpp
  23. 3
      Sources/Plasma/FeatureLib/pfPython/pyStream.h
  24. 41
      Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp
  25. 70
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp
  26. 13
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h
  27. 12
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp
  28. 13
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h
  29. 4
      Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp
  30. 76
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp
  31. 17
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h
  32. 5
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp
  33. 16
      Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp
  34. 7
      Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h
  35. 107
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  36. 22
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h
  37. 2
      Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp
  38. 144
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp
  39. 26
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.h
  40. 131
      Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp
  41. 15
      Sources/Plasma/PubUtilLib/plFile/plStreamSource.h
  42. 24
      Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp
  43. 7
      Sources/Plasma/PubUtilLib/plGImage/plJPEG.h
  44. 24
      Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp
  45. 6
      Sources/Plasma/PubUtilLib/plGImage/plPNG.h
  46. 16
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp
  47. 9
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h
  48. 16
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  49. 7
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.h
  50. 9
      Sources/Plasma/PubUtilLib/plSDL/plSDL.h
  51. 9
      Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h
  52. 77
      Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp
  53. 21
      Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp
  54. 47
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp
  55. 10
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h
  56. 17
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  57. 3
      Sources/Tools/MaxComponent/plMultistageBehComponent.cpp

51
Sources/Plasma/Apps/plClient/plClient.cpp

@ -231,13 +231,12 @@ plClient::plClient()
plAgeLoader::SetInstance(new plAgeLoader); plAgeLoader::SetInstance(new plAgeLoader);
// Use it to parse the init directory // Use it to parse the init directory
wchar_t initFolder[MAX_PATH]; plFileName initFolder = plFileSystem::GetInitPath();
PathGetInitDirectory(initFolder, arrsize(initFolder)); pfConsoleDirSrc dirSrc(fConsoleEngine, initFolder, "*.ini");
pfConsoleDirSrc dirSrc( fConsoleEngine, initFolder, L"*.ini" );
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds also parse the local init folder // internal builds also parse the local init folder
dirSrc.ParseDirectory( L"init", L"*.ini" ); dirSrc.ParseDirectory("init", "*.ini");
#endif #endif
/// End of console stuff /// End of console stuff
@ -467,9 +466,7 @@ void plClient::InitInputs()
void plClient::ISetGraphicsDefaults() void plClient::ISetGraphicsDefaults()
{ {
// couldn't find display mode set defaults write to ini file // couldn't find display mode set defaults write to ini file
wchar_t graphicsIniFile[MAX_PATH]; plFileName graphicsIniFile = plFileName::Join(plFileSystem::GetInitPath(), "graphics.ini");
PathGetInitDirectory(graphicsIniFile, arrsize(graphicsIniFile));
PathAddFilename(graphicsIniFile, graphicsIniFile, L"graphics.ini", arrsize(graphicsIniFile));
IWriteDefaultGraphicsSettings(graphicsIniFile); IWriteDefaultGraphicsSettings(graphicsIniFile);
plPipeline::fInitialPipeParams.Windowed = plPipeline::fDefaultPipeParams.Windowed; plPipeline::fInitialPipeParams.Windowed = plPipeline::fDefaultPipeParams.Windowed;
plPipeline::fInitialPipeParams.AntiAliasingAmount = plPipeline::fDefaultPipeParams.AntiAliasingAmount; plPipeline::fInitialPipeParams.AntiAliasingAmount = plPipeline::fDefaultPipeParams.AntiAliasingAmount;
@ -1624,12 +1621,12 @@ void plClient::IPatchGlobalAgeFiles( void )
plResPatcher* patcher = plResPatcher::GetInstance(); plResPatcher* patcher = plResPatcher::GetInstance();
if (!gDataServerLocal) if (!gDataServerLocal)
{ {
patcher->RequestManifest(L"CustomAvatars"); patcher->RequestManifest("CustomAvatars");
patcher->RequestManifest(L"GlobalAnimations"); patcher->RequestManifest("GlobalAnimations");
patcher->RequestManifest(L"GlobalAvatars"); patcher->RequestManifest("GlobalAvatars");
patcher->RequestManifest(L"GlobalClothing"); patcher->RequestManifest("GlobalClothing");
patcher->RequestManifest(L"GlobalMarkers"); patcher->RequestManifest("GlobalMarkers");
patcher->RequestManifest(L"GUI"); patcher->RequestManifest("GUI");
} }
plgDispatch::Dispatch()->RegisterForExactType(plResPatcherMsg::Index(), GetKey()); plgDispatch::Dispatch()->RegisterForExactType(plResPatcherMsg::Index(), GetKey());
@ -2344,18 +2341,15 @@ void plClient::IDetectAudioVideoSettings()
int val = 0; int val = 0;
hsStream *stream = nil; hsStream *stream = nil;
hsUNIXStream s; hsUNIXStream s;
wchar_t audioIniFile[MAX_PATH], graphicsIniFile[MAX_PATH]; plFileName audioIniFile = plFileName::Join(plFileSystem::GetInitPath(), "audio.ini");
PathGetInitDirectory(audioIniFile, arrsize(audioIniFile)); plFileName graphicsIniFile = plFileName::Join(plFileSystem::GetInitPath(), "graphics.ini");
StrCopy(graphicsIniFile, audioIniFile, arrsize(audioIniFile));
PathAddFilename(audioIniFile, audioIniFile, L"audio.ini", arrsize(audioIniFile));
PathAddFilename(graphicsIniFile, graphicsIniFile, L"graphics.ini", arrsize(graphicsIniFile));
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds can use the local dir // internal builds can use the local dir
if (PathDoesFileExist(L"init//audio.ini")) if (plFileInfo("init//audio.ini").Exists())
StrCopy(audioIniFile, L"init//audio.ini", arrsize(audioIniFile)); audioIniFile = "init//audio.ini";
if (PathDoesFileExist(L"init//graphics.ini")) if (plFileInfo("init//graphics.ini").Exists())
StrCopy(graphicsIniFile, L"init//graphics.ini", arrsize(audioIniFile)); graphicsIniFile = "init//graphics.ini";
#endif #endif
//check to see if audio.ini exists //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); hsStream *stream = plEncryptedStream::OpenEncryptedFileWrite(destFile);
@ -2487,18 +2481,17 @@ void plClient::IOnAsyncInitComplete () {
/// Now parse final init files (*.fni). These are files just like ini files, only to be run /// 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. /// after all hell has broken loose in the client.
wchar_t initFolder[MAX_PATH]; plFileName initFolder = plFileSystem::GetInitPath();
PathGetInitDirectory(initFolder, arrsize(initFolder)); pfConsoleDirSrc dirSrc(fConsoleEngine, initFolder, "net*.fni"); // connect to net first
pfConsoleDirSrc dirSrc( fConsoleEngine, initFolder, L"net*.fni" ); // connect to net first
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds also parse the local init folder // internal builds also parse the local init folder
dirSrc.ParseDirectory( L"init", L"net*.fni" ); dirSrc.ParseDirectory("init", "net*.fni");
#endif #endif
dirSrc.ParseDirectory( initFolder, L"*.fni" ); dirSrc.ParseDirectory(initFolder, "*.fni");
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds also parse the local init folder // internal builds also parse the local init folder
dirSrc.ParseDirectory( L"init", L"*.fni" ); dirSrc.ParseDirectory("init", "*.fni");
#endif #endif
// run fni in the Aux Init dir // run fni in the Aux Init dir

2
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 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 ResizeDisplayDevice(int Width, int Height, bool Windowed);
void IDetectAudioVideoSettings(); void IDetectAudioVideoSettings();
void IWriteDefaultGraphicsSettings(const wchar_t* destFile); void IWriteDefaultGraphicsSettings(const plFileName& destFile);
plAnimDebugList *fAnimDebugList; plAnimDebugList *fAnimDebugList;

42
Sources/Plasma/Apps/plClient/winmain.cpp

@ -843,17 +843,14 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password)
// FIXME: Real OS detection // FIXME: Real OS detection
NetCommSetAuthTokenAndOS(nil, L"win"); NetCommSetAuthTokenAndOS(nil, L"win");
wchar_t fileAndPath[MAX_PATH]; plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat");
PathGetInitDirectory(fileAndPath, arrsize(fileAndPath));
PathAddFilename(fileAndPath, fileAndPath, L"login.dat", arrsize(fileAndPath));
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds can use the local init directory // internal builds can use the local init directory
wchar_t localFileAndPath[MAX_PATH]; plFileName local("init\\login.dat");
StrCopy(localFileAndPath, L"init\\login.dat", arrsize(localFileAndPath)); if (plFileInfo(local).Exists())
if (PathDoesFileExist(localFileAndPath)) loginDat = local;
StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath));
#endif #endif
hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(fileAndPath, cryptKey); hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(loginDat, cryptKey);
if (stream) if (stream)
{ {
stream->Write(sizeof(cryptKey), cryptKey); stream->Write(sizeof(cryptKey), cryptKey);
@ -877,17 +874,14 @@ static void LoadUserPass (LoginDialogParam *pLoginParam)
pLoginParam->remember = false; pLoginParam->remember = false;
pLoginParam->username[0] = '\0'; pLoginParam->username[0] = '\0';
wchar_t fileAndPath[MAX_PATH]; plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat");
PathGetInitDirectory(fileAndPath, arrsize(fileAndPath));
PathAddFilename(fileAndPath, fileAndPath, L"login.dat", arrsize(fileAndPath));
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal builds can use the local init directory // internal builds can use the local init directory
wchar_t localFileAndPath[MAX_PATH]; plFileName local("init\\login.dat");
StrCopy(localFileAndPath, L"init\\login.dat", arrsize(localFileAndPath)); if (plFileInfo(local).Exists())
if (PathDoesFileExist(localFileAndPath)) loginDat = local;
StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath));
#endif #endif
hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileAndPath, cryptKey); hsStream* stream = plEncryptedStream::OpenEncryptedFile(loginDat, cryptKey);
if (stream && !stream->AtEnd()) if (stream && !stream->AtEnd())
{ {
uint32_t savedKey[4]; 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. // 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. // When general.ini gets expanded, this will need to find a proper home somewhere.
{ {
wchar_t gipath[MAX_PATH]; plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
PathGetInitDirectory(gipath, arrsize(gipath));
PathAddFilename(gipath, gipath, L"general.ini", arrsize(gipath));
plString ini_str = plString::Format("App.SetLanguage %s\n", plLocalization::GetLanguageName(new_language)); plString ini_str = plString::Format("App.SetLanguage %s\n", plLocalization::GetLanguageName(new_language));
hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath); hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath);
gini->WriteString(ini_str); gini->WriteString(ini_str);
@ -1215,9 +1207,9 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
gDataServerLocal = true; gDataServerLocal = true;
#endif #endif
const wchar_t *serverIni = L"server.ini"; plFileName serverIni = "server.ini";
if (cmdParser.IsSpecified(kArgServerIni)) if (cmdParser.IsSpecified(kArgServerIni))
serverIni = cmdParser.GetString(kArgServerIni); serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni));
// check to see if we were launched from the patcher // check to see if we were launched from the patcher
bool eventExists = false; bool eventExists = false;
@ -1272,10 +1264,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
#endif #endif
// Load an optional general.ini // Load an optional general.ini
wchar_t gipath[MAX_PATH]; plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
PathGetInitDirectory(gipath, arrsize(gipath)); FILE *generalini = plFileSystem::Open(gipath, "rb");
PathAddFilename(gipath, gipath, L"general.ini", arrsize(gipath));
FILE *generalini = _wfopen(gipath, L"rb");
if (generalini) if (generalini)
{ {
fclose(generalini); fclose(generalini);
@ -1312,7 +1302,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
} }
#endif #endif
FILE *serverIniFile = _wfopen(serverIni, L"rb"); FILE *serverIniFile = plFileSystem::Open(serverIni, "rb");
if (serverIniFile) if (serverIniFile)
{ {
fclose(serverIniFile); fclose(serverIniFile);

3
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 "plProduct.h"
#include "pnEncryption/plChecksum.h" #include "pnEncryption/plChecksum.h"
#include "plFileSystem.h"
#include <stdio.h> #include <stdio.h>
int main (int argc, char ** argv) { int main (int argc, const char ** argv) {
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "ERROR: Please specify filename.\n"); fprintf(stderr, "ERROR: Please specify filename.\n");

3
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 "plProduct.h"
#include "pnEncryption/plChecksum.h" #include "pnEncryption/plChecksum.h"
#include "plFileSystem.h"
#include <stdio.h> #include <stdio.h>
int main (int argc, char** argv) { int main (int argc, const char** argv) {
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "ERROR: Please specify filename.\n"); fprintf(stderr, "ERROR: Please specify filename.\n");

6
Sources/Plasma/Apps/plUruLauncher/Main.cpp

@ -647,12 +647,12 @@ int __stdcall WinMain (
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
const wchar_t *serverIni = L"server.ini"; plFileName serverIni = "server.ini";
if (cmdParser.IsSpecified(kArgServerIni)) if (cmdParser.IsSpecified(kArgServerIni))
serverIni = cmdParser.GetString(kArgServerIni); serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni));
// Load the server.ini so we know what to connect to // 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) if (serverini)
{ {
fclose(serverini); fclose(serverini);

3
Sources/Plasma/CoreLib/hsSTLStream.h

@ -60,8 +60,7 @@ public:
hsVectorStream(uint32_t chunkSize); hsVectorStream(uint32_t chunkSize);
virtual ~hsVectorStream(); virtual ~hsVectorStream();
virtual bool Open(const char *, const char *) { 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 Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsVectorStream::Open Not Implemented"); return false; }
virtual bool Close() { hsAssert(0, "hsVectorStream::Close Not Implemented"); return false; } virtual bool Close() { hsAssert(0, "hsVectorStream::Close Not Implemented"); return false; }
virtual bool AtEnd(); virtual bool AtEnd();

34
Sources/Plasma/CoreLib/hsStream.cpp

@ -684,17 +684,10 @@ hsUNIXStream::~hsUNIXStream()
// Don't Close here, because Sub classes Don't always want that behaviour! // 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; fPosition = 0;
fRef = hsFopen(name, mode); fRef = plFileSystem::Open(name, mode);
return (fRef) ? true : false;
}
bool hsUNIXStream::Open(const wchar_t *name, const wchar_t *mode)
{
fPosition = 0;
fRef = hsWFopen(name, mode);
return (fRef) ? true : false; return (fRef) ? true : false;
} }
@ -1222,23 +1215,15 @@ hsBufferedStream::hsBufferedStream()
, fBufferReadOut(0) , fBufferReadOut(0)
, fReadDirect(0) , fReadDirect(0)
, fLastReadPos(0) , fLastReadPos(0)
, fFilename(nil)
, fCloseReason(nil) , fCloseReason(nil)
#endif #endif
{ {
} }
hsBufferedStream::~hsBufferedStream() bool hsBufferedStream::Open(const plFileName& name, const char* mode)
{
#ifdef LOG_BUFFERED
delete [] fFilename;
#endif // LOG_BUFFERED
}
bool hsBufferedStream::Open(const char* name, const char* mode)
{ {
hsAssert(!fRef, "hsBufferedStream:Open Stream already opened"); hsAssert(!fRef, "hsBufferedStream:Open Stream already opened");
fRef = hsFopen(name, mode); fRef = plFileSystem::Open(name, mode);
if (!fRef) if (!fRef)
return false; return false;
@ -1247,20 +1232,13 @@ bool hsBufferedStream::Open(const char* name, const char* mode)
#ifdef LOG_BUFFERED #ifdef LOG_BUFFERED
fBufferHits = fBufferMisses = 0; fBufferHits = fBufferMisses = 0;
fBufferReadIn = fBufferReadOut = fReadDirect = fLastReadPos = 0; fBufferReadIn = fBufferReadOut = fReadDirect = fLastReadPos = 0;
delete [] fFilename; fFilename = name;
fFilename = hsStrdup(name);
fCloseReason = nil; fCloseReason = nil;
#endif // LOG_BUFFERED #endif // LOG_BUFFERED
return true; 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() bool hsBufferedStream::Close()
{ {
int rtn = true; int rtn = true;
@ -1285,7 +1263,7 @@ bool hsBufferedStream::Close()
wasted -= int((float(fBufferReadOut+fReadDirect) / float(fBufferReadIn+fReadDirect)) * 100.f); wasted -= int((float(fBufferReadOut+fReadDirect) / float(fBufferReadIn+fReadDirect)) * 100.f);
s.WriteFmt("%s,%d,%d,%u,%u,%u,%d,%s\n", 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, wasted,
fCloseReason ? fCloseReason : "Unknown"); fCloseReason ? fCloseReason : "Unknown");

35
Sources/Plasma/CoreLib/hsStream.h

@ -83,12 +83,7 @@ public:
hsStream() : fBytesRead(0), fPosition(0) {} hsStream() : fBytesRead(0), fPosition(0) {}
virtual ~hsStream() { } virtual ~hsStream() { }
// Pre-filename-stringification shortcut: virtual bool Open(const plFileName &, const char * = "rb") = 0;
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 Close()=0; virtual bool Close()=0;
virtual bool AtEnd(); virtual bool AtEnd();
virtual uint32_t Read(uint32_t byteCount, void * buffer) = 0; virtual uint32_t Read(uint32_t byteCount, void * buffer) = 0;
@ -300,8 +295,7 @@ class hsUNIXStream: public hsStream
public: public:
hsUNIXStream(): fRef(0), fBuff(nil) {} hsUNIXStream(): fRef(0), fBuff(nil) {}
~hsUNIXStream(); ~hsUNIXStream();
virtual bool Open(const char* name, const char* mode = "rb"); virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Open(const wchar_t *name, const wchar_t *mode = L"rb");
virtual bool Close(); virtual bool Close();
virtual bool AtEnd(); virtual bool AtEnd();
@ -335,8 +329,7 @@ public:
plReadOnlySubStream(): fBase( nil ), fOffset( 0 ), fLength( 0 ) {} plReadOnlySubStream(): fBase( nil ), fOffset( 0 ), fLength( 0 ) {}
~plReadOnlySubStream(); ~plReadOnlySubStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; } virtual bool Open(const plFileName &, 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; }
void Open( hsStream *base, uint32_t offset, uint32_t length ); void Open( hsStream *base, uint32_t offset, uint32_t length );
virtual bool Close() { fBase = nil; fOffset = 0; fLength = 0; return true; } virtual bool Close() { fBase = nil; fOffset = 0; fLength = 0; return true; }
virtual bool AtEnd(); virtual bool AtEnd();
@ -358,8 +351,7 @@ public:
hsRAMStream(uint32_t chunkSize); hsRAMStream(uint32_t chunkSize);
virtual ~hsRAMStream(); virtual ~hsRAMStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; } virtual bool Open(const plFileName &, 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 Close() { hsAssert(0, "hsRAMStream::Close NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsRAMStream::Close NotImplemented"); return false; }
@ -379,8 +371,7 @@ public:
class hsNullStream : public hsStream { class hsNullStream : public hsStream {
public: public:
virtual bool Open(const char *, const char *) { return true; } virtual bool Open(const plFileName &, const char *) { return true; }
virtual bool Open(const wchar_t *, const wchar_t *) { return true; }
virtual bool Close() { return true; } virtual bool Close() { return true; }
virtual uint32_t Read(uint32_t byteCount, void * buffer); // throw's exception virtual uint32_t Read(uint32_t byteCount, void * buffer); // throw's exception
@ -404,8 +395,7 @@ public:
hsReadOnlyStream() {} hsReadOnlyStream() {}
virtual void Init(int size, const void* data) { fStart=((char*)data); fData=((char*)data); fStop=((char*)data + size); } 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 plFileName &, 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 Close() { hsAssert(0, "hsReadOnlyStream::Close NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsReadOnlyStream::Close NotImplemented"); return false; }
virtual bool AtEnd(); virtual bool AtEnd();
virtual uint32_t Read(uint32_t byteCount, void * buffer); virtual uint32_t Read(uint32_t byteCount, void * buffer);
@ -424,8 +414,7 @@ public:
hsWriteOnlyStream(int size, const void* data) : hsReadOnlyStream(size, data) {} hsWriteOnlyStream(int size, const void* data) : hsReadOnlyStream(size, data) {}
hsWriteOnlyStream() {} hsWriteOnlyStream() {}
virtual bool Open(const char *, const char *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; } virtual bool Open(const plFileName &, 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 Close() { hsAssert(0, "hsWriteOnlyStream::Close 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 Read(uint32_t byteCount, void * buffer); // throws exception
virtual uint32_t Write(uint32_t byteCount, const void* buffer); virtual uint32_t Write(uint32_t byteCount, const void* buffer);
@ -445,8 +434,7 @@ public:
hsQueueStream(int32_t size); hsQueueStream(int32_t size);
~hsQueueStream(); ~hsQueueStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; } virtual bool Open(const plFileName &, 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 Close() { hsAssert(0, "hsQueueStream::Close NotImplemented"); return false; } virtual bool Close() { hsAssert(0, "hsQueueStream::Close NotImplemented"); return false; }
virtual uint32_t Read(uint32_t byteCount, void * buffer); 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 // For doing statistics on how efficient we are
int fBufferHits, fBufferMisses; int fBufferHits, fBufferMisses;
uint32_t fBufferReadIn, fBufferReadOut, fReadDirect, fLastReadPos; uint32_t fBufferReadIn, fBufferReadOut, fReadDirect, fLastReadPos;
char* fFilename; plFileName fFilename;
const char* fCloseReason; const char* fCloseReason;
#endif #endif
public: public:
hsBufferedStream(); hsBufferedStream();
virtual ~hsBufferedStream(); virtual ~hsBufferedStream() { }
virtual bool Open(const char* name, const char* mode = "rb"); virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb");
virtual bool Close(); virtual bool Close();
virtual bool AtEnd(); virtual bool AtEnd();

8
Sources/Plasma/CoreLib/plString.h

@ -284,6 +284,14 @@ public:
return str; 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. */ /** 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) static inline plString FromIso8859_1(const char *astr, size_t size = kSizeAuto)
{ {

2
Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp

@ -283,7 +283,7 @@ bool pfConsole::MsgReceive( plMessage *msg )
{ {
if( cmd->GetCmd() == plConsoleMsg::kExecuteFile ) 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 // Change the following line once we have a better way of reporting
// errors in the parsing // errors in the parsing

4
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" ) PF_CONSOLE_CMD( Age, GetElapsedDays, "string agedefnfile", "Gets the elapsed days and fractions" )
{ {
hsUNIXStream s; hsUNIXStream s;
if (!s.Open(params[0])) if (!s.Open(static_cast<const char *>(params[0])))
{ {
PrintString("Couldn't open age defn file!"); PrintString("Couldn't open age defn file!");
return; 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" ) PF_CONSOLE_CMD( Age, GetTimeOfDay, "string agedefnfile", "Gets the elapsed days and fractions" )
{ {
hsUNIXStream s; hsUNIXStream s;
if (!s.Open(params[0])) if (!s.Open(static_cast<const char *>(params[0])))
{ {
PrintString("Couldn't open age defn file!"); PrintString("Couldn't open age defn file!");
return; return;

31
Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp

@ -57,27 +57,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// ParseDirectory ////////////////////////////////////////////////////////// //// 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; WIN32_FIND_DATAW findInfo;
HANDLE handle; HANDLE handle;
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" ); hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
search << path << L"\\" << mask; handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo);
handle = FindFirstFileW(search.str().c_str(), &findInfo);
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE)
return false; return false;
@ -85,12 +72,12 @@ bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wst
{ {
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{ {
std::wstringstream fileAndPath; plFileName name = plString::FromWchar(findInfo.cFileName);
fileAndPath << path << L"\\" << findInfo.cFileName; plFileName fileAndPath = plFileName::Join(path, name);
if (AlreadyProcessedFile(path, findInfo.cFileName)) if (AlreadyProcessedFile(path, name))
continue; continue;
AddProcessedFile(path, findInfo.cFileName); AddProcessedFile(path, name);
if (!fEngine->ExecuteFile(fileAndPath.str().c_str())) if (!fEngine->ExecuteFile(fileAndPath))
{ {
// Change the following line once we have a better way of reporting // Change the following line once we have a better way of reporting
// errors in the parsing // errors in the parsing
@ -137,7 +124,7 @@ void pfConsoleDirSrc::ResetProcessedFiles()
// note: this n^2 linear search should be replaced with something // 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. // 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) if (fCheckProcessedFiles)
{ {
@ -151,7 +138,7 @@ bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::
return false; 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));
} }

27
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 "HeadSpin.h"
#include <vector> #include <vector>
#include <string>
#include "pfConsoleCore/pfConsoleEngine.h" #include "pfConsoleCore/pfConsoleEngine.h"
#include "plFileSystem.h"
//// pfConsoleDirSrc Class Definition //////////////////////////////////////// //// pfConsoleDirSrc Class Definition ////////////////////////////////////////
@ -69,23 +69,17 @@ class pfConsoleDirSrc
pfConsoleEngine *fEngine; pfConsoleEngine *fEngine;
struct FileName struct FileName
{ {
std::wstring fPath; plFileName fPath;
std::wstring fFile; plFileName fFile;
FileName() : fPath(L""), fFile(L"") {} FileName() : fPath(""), fFile("") {}
FileName(const std::wstring& p, const std::wstring& f) : fPath(p), fFile(f) {} FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {}
}; };
std::vector<FileName*> fProcessedFiles; // list of init files we've already executed std::vector<FileName*> fProcessedFiles; // list of init files we've already executed
bool fCheckProcessedFiles; // set to check and skip files init files we've already executed bool fCheckProcessedFiles; // set to check and skip files init files we've already executed
public: public:
pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; } pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; }
pfConsoleDirSrc(pfConsoleEngine *engine, const std::string& path, const std::string& mask = "*.ini") : pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini")
fCheckProcessedFiles(false) : fCheckProcessedFiles(false)
{
fEngine = engine;
ParseDirectory(path, mask);
}
pfConsoleDirSrc(pfConsoleEngine *engine, const std::wstring& path, const std::wstring& mask = L"*.ini") :
fCheckProcessedFiles(false)
{ {
fEngine = engine; fEngine = engine;
ParseDirectory(path, mask); ParseDirectory(path, mask);
@ -94,12 +88,11 @@ class pfConsoleDirSrc
~pfConsoleDirSrc() { ResetProcessedFiles(); } ~pfConsoleDirSrc() { ResetProcessedFiles(); }
// Steps through the given directory and executes all files with the console engine // 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 plFileName& path, const plString& mask = "*.*");
bool ParseDirectory(const std::wstring& path, const std::wstring& mask = L"*.*");
void ResetProcessedFiles(); void ResetProcessedFiles();
bool AlreadyProcessedFile(const std::wstring& path, const std::wstring& file); bool AlreadyProcessedFile(const plFileName& path, const plFileName& file);
void AddProcessedFile(const std::wstring& path, const std::wstring& file); void AddProcessedFile(const plFileName& path, const plFileName& file);
void SetCheckProcessedFiles(bool c) { fCheckProcessedFiles=c; } void SetCheckProcessedFiles(bool c) { fCheckProcessedFiles=c; }
}; };

17
Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp

@ -247,15 +247,7 @@ void DummyPrintFn( const char *line )
//// ExecuteFile ///////////////////////////////////////////////////////////// //// 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 ]; char string[ 512 ];
int line; int line;
@ -273,13 +265,14 @@ bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName )
return true; 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 ) ) 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 ); ISetErrorMsg( string );
stream->Close(); stream->Close();
delete stream; delete stream;

4
Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h

@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
class plFileName;
//// pfConsoleEngine Class Definition //////////////////////////////////////// //// pfConsoleEngine Class Definition ////////////////////////////////////////
@ -94,8 +95,7 @@ class pfConsoleEngine
bool RunCommand( char *line, void (*PrintFn)( const char * ) ); bool RunCommand( char *line, void (*PrintFn)( const char * ) );
// Executes the given file as a sequence of console commands // Executes the given file as a sequence of console commands
bool ExecuteFile( const char *fileName ); bool ExecuteFile( const plFileName &fileName );
bool ExecuteFile( const wchar_t *fileName );
// Get the last reported error // Get the last reported error
const char *GetErrorMsg( void ) { return fErrorMsg; } const char *GetErrorMsg( void ) { return fErrorMsg; }

13
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 "plCrash_Private.h"
#include "plFile/plFileUtils.h" #include "plFile/plFileUtils.h"
#include "plProduct.h" #include "plProduct.h"
#include "plString.h" #include "plFileSystem.h"
#ifdef HS_BUILD_FOR_WIN32 #ifdef HS_BUILD_FOR_WIN32
@ -78,14 +78,8 @@ plCrashSrv::~plCrashSrv()
void plCrashSrv::IHandleCrash() void plCrashSrv::IHandleCrash()
{ {
// Begin Hackiness plFileName dumpPath = plFileName::Join(plFileSystem::GetLogPath(), "crash.dmp");
wchar_t dumpPath[1024]; HANDLE file = CreateFileW(dumpPath.AsString().ToWchar(),
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,
GENERIC_WRITE, GENERIC_WRITE,
0, 0,
NULL, NULL,
@ -93,7 +87,6 @@ void plCrashSrv::IHandleCrash()
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
NULL NULL
); );
// End Hackiness
MINIDUMP_EXCEPTION_INFORMATION e; MINIDUMP_EXCEPTION_INFORMATION e;
e.ClientPointers = TRUE; e.ClientPointers = TRUE;

13
Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp

@ -43,8 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h> #include <Python.h>
#include <marshal.h> #include <marshal.h>
#include <time.h> #include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string> #include <string>
#include "HeadSpin.h" #include "HeadSpin.h"
@ -125,7 +123,7 @@ bool plPythonPack::Open()
fPackNotFound = true; fPackNotFound = true;
// Get the names of all the pak files // Get the names of all the pak files
std::vector<std::wstring> files = plStreamSource::GetInstance()->GetListOfNames(L"python", L".pak"); std::vector<plFileName> files = plStreamSource::GetInstance()->GetListOfNames("python", "pak");
std::vector<time_t> modTimes; // the modification time for each of the streams (to resolve duplicate file issues) std::vector<time_t> 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 fPackStream->Rewind(); // make sure we're at the beginning of the file
fPackNotFound = false; fPackNotFound = false;
char* tempFilename = hsWStringToString(files[curName].c_str());
struct stat buf;
time_t curModTime = 0; time_t curModTime = 0;
if (stat(tempFilename,&buf)==0) plFileInfo info(files[curName]);
curModTime = buf.st_mtime; if (info.Exists())
curModTime = info.ModifyTime();
modTimes.push_back(curModTime); modTimes.push_back(curModTime);
delete [] tempFilename;
// read the index data // read the index data
int numFiles = fPackStream->ReadLE32(); int numFiles = fPackStream->ReadLE32();
@ -193,7 +189,6 @@ void plPythonPack::Close()
} }
fPackStreams.clear(); fPackStreams.clear();
fFileOffsets.clear(); fFileOffsets.clear();
} }

12
Sources/Plasma/FeatureLib/pfPython/pyImage.cpp

@ -178,7 +178,7 @@ uint32_t pyImage::GetHeight()
return 0; 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) if (quality <= 0 || quality > 100)
{ {
@ -189,13 +189,13 @@ void pyImage::SaveAsJPEG(const wchar_t* fileName, uint8_t quality)
plJPEG::Instance().WriteToFile(fileName, this->GetImage()); 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); plMipmap* theMipmap = plJPEG::Instance().ReadFromFile(filename);
if (theMipmap) 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 // 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); 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; 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); plMipmap* theMipmap = plPNG::Instance().ReadFromFile(filename);
if (theMipmap) 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 // 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); hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);

8
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 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 GetWidth(); // returns the width of the image
uint32_t GetHeight(); // returns the height of the image uint32_t GetHeight(); // returns the height of the image
void SaveAsJPEG(const wchar_t* fileName, uint8_t quality = 75); void SaveAsJPEG(const plFileName& fileName, uint8_t quality = 75);
void SaveAsPNG(const wchar_t* fileName); void SaveAsPNG(const plFileName& fileName);
static PyObject* LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage static PyObject* LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage
static PyObject* LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage static PyObject* LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage
#endif #endif
}; };

47
Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp

@ -152,24 +152,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsJPEG, args)
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
if (PyUnicode_Check(filenameObj)) if (PyString_CheckEx(filenameObj)) {
{ self->fThis->SaveAsJPEG(PyString_AsStringEx(filenameObj), quality);
int strLen = PyUnicode_GetSize(filenameObj); Py_RETURN_NONE;
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;
} }
else else
{ {
@ -187,23 +172,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args)
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
if (PyUnicode_Check(filenameObj)) 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';
self->fThis->SaveAsPNG(text);
delete [] text;
PYTHON_RETURN_NONE;
}
else if (PyString_Check(filenameObj))
{ {
// we'll allow this, just in case something goes weird self->fThis->SaveAsPNG(PyString_AsStringEx(filenameObj));
char* text = PyString_AsString(filenameObj);
wchar_t* wText = hsStringToWString(text);
self->fThis->SaveAsPNG(wText);
delete [] wText;
PYTHON_RETURN_NONE; PYTHON_RETURN_NONE;
} }
else else
@ -290,8 +261,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
if (PyString_CheckEx(filenameObj)) if (PyString_CheckEx(filenameObj))
{ {
plString text = PyString_AsStringEx(filenameObj); plFileName filename = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadJPEGFromDisk(text.ToWchar(), width, height); PyObject* ret = pyImage::LoadJPEGFromDisk(filename, width, height);
return ret; return ret;
} }
else else
@ -312,8 +283,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width
} }
if (PyString_CheckEx(filenameObj)) if (PyString_CheckEx(filenameObj))
{ {
plString text = PyString_AsStringEx(filenameObj); plFileName filename = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadPNGFromDisk(text.ToWchar(), width, height); PyObject* ret = pyImage::LoadPNGFromDisk(filename, width, height);
return ret; return ret;
} }
else else

14
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 // make sure its closed first
Close(); Close();
if (fileName) if (fileName.IsValid())
{ {
if (flags) if (flags)
{ {
@ -74,13 +74,13 @@ bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags)
bool writeflag = false; bool writeflag = false;
bool encryptflag = false; bool encryptflag = false;
int i; 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; readflag = true;
if ( flags[i] == L'w' || flags[i] == L'W' ) if ( flags[i] == 'w' || flags[i] == 'W' )
writeflag = true; writeflag = true;
if ( flags[i] == L'e' || flags[i] == L'E' ) if ( flags[i] == 'e' || flags[i] == 'E' )
encryptflag = true; encryptflag = true;
} }
// if there is a write flag, it takes priorty over read // 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) if (encryptflag)
{ {
fStream = new plEncryptedStream; fStream = new plEncryptedStream;
fStream->Open(fileName, L"wb"); fStream->Open(fileName, "wb");
} }
else else
fStream = plEncryptedStream::OpenEncryptedFileWrite(fileName); fStream = plEncryptedStream::OpenEncryptedFileWrite(fileName);

3
Sources/Plasma/FeatureLib/pfPython/pyStream.h

@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <vector> #include <vector>
class hsStream; class hsStream;
class plFileName;
class pyStream class pyStream
{ {
@ -75,7 +76,7 @@ public:
static void AddPlasmaClasses(PyObject *m); 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<std::string> ReadLines(); virtual std::vector<std::string> ReadLines();
virtual bool WriteLines(const std::vector<std::string> & lines); virtual bool WriteLines(const std::vector<std::string> & lines);
virtual void Close(); virtual void Close();

41
Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp

@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop #pragma hdrstop
#include "pyStream.h" #include "pyStream.h"
#include "plFileSystem.h"
// glue functions // glue functions
@ -67,23 +68,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
std::wstring filename; plFileName filename;
if (PyUnicode_Check(filenameObj)) if (PyString_CheckEx(filenameObj))
{ {
int strLen = PyUnicode_GetSize(filenameObj); filename = PyString_AsStringEx(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;
} }
else else
{ {
@ -91,23 +79,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
std::wstring flags; plString flags;
if (PyUnicode_Check(flagsObj)) if (PyString_CheckEx(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))
{ {
// we'll allow this, just in case something goes weird flags = PyString_AsStringEx(flagsObj);
char* text = PyString_AsString(flagsObj);
wchar_t* wText = hsStringToWString(text);
flags = wText;
delete [] wText;
} }
else else
{ {
@ -115,7 +90,7 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR; 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) PYTHON_METHOD_DEFINITION_NOARGS(ptStream, readlines)

70
Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp

@ -189,28 +189,9 @@ public:
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
pfSecurePreloader::pfSecurePreloader() hsRAMStream* pfSecurePreloader::LoadToMemory(const plFileName& file) const
: fProgress(nil), fLegacyMode(false)
{ }
pfSecurePreloader::~pfSecurePreloader()
{
while (fDownloadEntries.size())
{
free((void*)fDownloadEntries.front());
fDownloadEntries.pop();
}
while (fManifestEntries.size())
{ {
free((void*)fManifestEntries.front()); if (!plFileInfo(file).Exists())
fManifestEntries.pop();
}
}
hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
{
if (!plFileUtils::FileExists(file))
return nil; return nil;
hsUNIXStream s; hsUNIXStream s;
@ -228,10 +209,10 @@ hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
return ram; return ram;
} }
void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const void pfSecurePreloader::SaveFile(hsStream* file, const plFileName& name) const
{ {
hsUNIXStream s; hsUNIXStream s;
s.Open(name, L"wb"); s.Open(name, "wb");
uint32_t pos = file->GetPosition(); uint32_t pos = file->GetPosition();
file->Rewind(); file->Rewind();
@ -244,9 +225,9 @@ void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const
delete[] buf; 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() void pfSecurePreloader::PreloadNextFile()
@ -257,14 +238,14 @@ void pfSecurePreloader::PreloadNextFile()
return; return;
} }
const wchar_t* filename = fDownloadEntries.front(); plFileName filename = fDownloadEntries.front();
hsStream* s = new pfSecurePreloaderStream(fProgress, IsZipped(filename)); hsStream* s = new pfSecurePreloaderStream(fProgress, IsZipped(filename));
// Thankfully, both callbacks have the same arguments // Thankfully, both callbacks have the same arguments
if (fLegacyMode) if (fLegacyMode)
NetCliAuthFileRequest(filename, s, FileDownloaded, this); NetCliAuthFileRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
else else
NetCliFileDownloadRequest(filename, s, FileDownloaded, this); NetCliFileDownloadRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
} }
void pfSecurePreloader::Init() void pfSecurePreloader::Init()
@ -340,15 +321,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliAuthFileInfo manifestEntries
for (uint32_t i = 0; i < entryCount; ++i) for (uint32_t i = 0; i < entryCount; ++i)
{ {
const NetCliAuthFileInfo mfs = manifestEntries[i]; const NetCliAuthFileInfo mfs = manifestEntries[i];
fDownloadEntries.push(wcsdup(mfs.filename)); plFileName filename = plString::FromWchar(mfs.filename);
if (IsZipped(mfs.filename)) fDownloadEntries.push(filename);
{ if (IsZipped(filename))
wchar_t* name = wcsdup(mfs.filename); fManifestEntries.push(filename.StripFileExt());
plFileUtils::StripExt(name); else
fManifestEntries.push(name); fManifestEntries.push(filename);
} else
fManifestEntries.push(wcsdup(mfs.filename));
totalBytes += mfs.filesize; totalBytes += mfs.filesize;
} }
@ -368,10 +346,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
const NetCliFileManifestEntry mfs = manifestEntries[i]; const NetCliFileManifestEntry mfs = manifestEntries[i];
bool fetchMe = true; bool fetchMe = true;
hsRAMStream* s = nil; 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) if (s)
{ {
// Damn this // Damn this
@ -389,15 +369,15 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
if (fetchMe) if (fetchMe)
{ {
fManifestEntries.push(wcsdup(mfs.clientName)); fManifestEntries.push(clientName);
fDownloadEntries.push(wcsdup(mfs.downloadName)); fDownloadEntries.push(downloadName);
if (IsZipped(mfs.downloadName)) if (IsZipped(downloadName))
totalBytes += mfs.zipSize; totalBytes += mfs.zipSize;
else else
totalBytes += mfs.fileSize; totalBytes += mfs.fileSize;
} else { } else {
plSecureStream* ss = new plSecureStream(s, fEncryptionKey); plSecureStream* ss = new plSecureStream(s, fEncryptionKey);
plStreamSource::GetInstance()->InsertFile(mfs.clientName, ss); plStreamSource::GetInstance()->InsertFile(clientName, ss);
} }
if (s) if (s)
@ -418,12 +398,12 @@ void pfSecurePreloader::FilePreloaded(const wchar_t* file, hsStream* stream)
{ {
// Clear out queue // Clear out queue
fDownloadEntries.pop(); fDownloadEntries.pop();
const wchar_t* clientName = fManifestEntries.front(); // Stolen by plStreamSource plFileName clientName = fManifestEntries.front();
fManifestEntries.pop(); fManifestEntries.pop();
if (!fLegacyMode) // AuthSrv data caching is useless if (!fLegacyMode) // AuthSrv data caching is useless
{ {
plFileUtils::EnsureFilePathExists(clientName); plFileSystem::CreateDir(clientName.StripFileName(), true);
SaveFile(stream, clientName); SaveFile(stream, clientName);
} }

13
Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h

@ -60,19 +60,18 @@ class pfSecurePreloader : public hsKeyedObject
private: private:
static pfSecurePreloader* fInstance; static pfSecurePreloader* fInstance;
std::queue<const wchar_t*> fManifestEntries; std::queue<plFileName> fManifestEntries;
std::queue<const wchar_t*> fDownloadEntries; std::queue<plFileName> fDownloadEntries;
plOperationProgress* fProgress; plOperationProgress* fProgress;
uint32_t fEncryptionKey[4]; uint32_t fEncryptionKey[4];
bool fLegacyMode; bool fLegacyMode;
hsRAMStream* LoadToMemory(const wchar_t* file) const; hsRAMStream* LoadToMemory(const plFileName& file) const;
void SaveFile(hsStream* file, const wchar_t* name) const; void SaveFile(hsStream* file, const plFileName& name) const;
bool IsZipped(const wchar_t* filename) const; bool IsZipped(const plFileName& filename) const;
public: public:
pfSecurePreloader(); pfSecurePreloader() : fProgress(nil), fLegacyMode(false) { }
~pfSecurePreloader();
CLASSNAME_REGISTER(pfSecurePreloader); CLASSNAME_REGISTER(pfSecurePreloader);
GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject); GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject);

12
Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp

@ -123,7 +123,7 @@ plMD5Checksum::plMD5Checksum( const plMD5Checksum &rhs )
fValid = rhs.fValid; fValid = rhs.fValid;
} }
plMD5Checksum::plMD5Checksum( const char *fileName ) plMD5Checksum::plMD5Checksum( const plFileName &fileName )
{ {
CalcFromFile( fileName ); CalcFromFile( fileName );
} }
@ -139,7 +139,7 @@ void plMD5Checksum::Clear()
fValid = false; fValid = false;
} }
void plMD5Checksum::CalcFromFile( const char *fileName ) void plMD5Checksum::CalcFromFile( const plFileName &fileName )
{ {
hsUNIXStream s; hsUNIXStream s;
fValid = false; fValid = false;
@ -249,7 +249,7 @@ plSHAChecksum::plSHAChecksum(const plSHAChecksum& rhs)
fValid = rhs.fValid; fValid = rhs.fValid;
} }
plSHAChecksum::plSHAChecksum(const char* fileName) plSHAChecksum::plSHAChecksum(const plFileName& fileName)
{ {
CalcFromFile(fileName); CalcFromFile(fileName);
} }
@ -265,7 +265,7 @@ void plSHAChecksum::Clear()
fValid = false; fValid = false;
} }
void plSHAChecksum::CalcFromFile(const char* fileName) void plSHAChecksum::CalcFromFile(const plFileName& fileName)
{ {
hsUNIXStream s; hsUNIXStream s;
fValid = false; fValid = false;
@ -375,7 +375,7 @@ plSHA1Checksum::plSHA1Checksum(const plSHA1Checksum& rhs)
fValid = rhs.fValid; fValid = rhs.fValid;
} }
plSHA1Checksum::plSHA1Checksum(const char* fileName) plSHA1Checksum::plSHA1Checksum(const plFileName& fileName)
{ {
CalcFromFile(fileName); CalcFromFile(fileName);
} }
@ -391,7 +391,7 @@ void plSHA1Checksum::Clear()
fValid = false; fValid = false;
} }
void plSHA1Checksum::CalcFromFile(const char* fileName) void plSHA1Checksum::CalcFromFile(const plFileName& fileName)
{ {
hsUNIXStream s; hsUNIXStream s;
fValid = false; fValid = false;

13
Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h

@ -60,6 +60,7 @@ public:
}; };
class hsStream; class hsStream;
class plFileName;
class plMD5Checksum class plMD5Checksum
{ {
@ -72,13 +73,13 @@ class plMD5Checksum
plMD5Checksum(size_t size, uint8_t *buffer); plMD5Checksum(size_t size, uint8_t *buffer);
plMD5Checksum(); plMD5Checksum();
plMD5Checksum(const plMD5Checksum &rhs); plMD5Checksum(const plMD5Checksum &rhs);
plMD5Checksum(const char *fileName); plMD5Checksum(const plFileName &fileName);
plMD5Checksum(hsStream* stream); plMD5Checksum(hsStream* stream);
bool IsValid() const { return fValid; } bool IsValid() const { return fValid; }
void Clear(); void Clear();
void CalcFromFile(const char *fileName); void CalcFromFile(const plFileName &fileName);
void CalcFromStream(hsStream* stream); void CalcFromStream(hsStream* stream);
void Start(); void Start();
@ -116,13 +117,13 @@ class plSHAChecksum
plSHAChecksum(size_t size, uint8_t* buffer); plSHAChecksum(size_t size, uint8_t* buffer);
plSHAChecksum(); plSHAChecksum();
plSHAChecksum(const plSHAChecksum& rhs); plSHAChecksum(const plSHAChecksum& rhs);
plSHAChecksum(const char* fileName); plSHAChecksum(const plFileName& fileName);
plSHAChecksum(hsStream* stream); plSHAChecksum(hsStream* stream);
bool IsValid() const { return fValid; } bool IsValid() const { return fValid; }
void Clear(); void Clear();
void CalcFromFile(const char* fileName); void CalcFromFile(const plFileName& fileName);
void CalcFromStream(hsStream* stream); void CalcFromStream(hsStream* stream);
void Start(); void Start();
@ -155,13 +156,13 @@ class plSHA1Checksum
plSHA1Checksum(size_t size, uint8_t* buffer); plSHA1Checksum(size_t size, uint8_t* buffer);
plSHA1Checksum(); plSHA1Checksum();
plSHA1Checksum(const plSHA1Checksum& rhs); plSHA1Checksum(const plSHA1Checksum& rhs);
plSHA1Checksum(const char* fileName); plSHA1Checksum(const plFileName& fileName);
plSHA1Checksum(hsStream* stream); plSHA1Checksum(hsStream* stream);
bool IsValid() const { return fValid; } bool IsValid() const { return fValid; }
void Clear(); void Clear();
void CalcFromFile(const char* fileName); void CalcFromFile(const plFileName& fileName);
void CalcFromStream(hsStream* stream); void CalcFromStream(hsStream* stream);
void Start(); void Start();

4
Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp

@ -178,10 +178,8 @@ void plAgeLoader::UpdateAge(const char ageName[])
plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg); plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg);
else else
{ {
wchar_t* wideAgeName = hsStringToWString(ageName); plResPatcher::GetInstance()->RequestManifest(ageName);
plResPatcher::GetInstance()->RequestManifest(wideAgeName);
plResPatcher::GetInstance()->Start(); plResPatcher::GetInstance()->Start();
delete[] wideAgeName;
} }
} }

76
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 class plResDownloadStream : public plZlibStream
{ {
plOperationProgress* fProgress; plOperationProgress* fProgress;
char* fFilename; plFileName fFilename;
bool fIsZipped; bool fIsZipped;
public: public:
plResDownloadStream(plOperationProgress* prog, const wchar_t* reqFile) plResDownloadStream(plOperationProgress* prog, const plFileName& reqFile)
: fProgress(prog), fFilename(nil) : 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) fFilename = filename;
delete[] fFilename;
}
virtual bool Open(const char* filename, const char* mode)
{
fFilename = hsStrcpy(filename);
return plZlibStream::Open(filename, mode); return plZlibStream::Open(filename, mode);
} }
@ -91,7 +85,7 @@ public:
} }
bool IsZipped() const { return fIsZipped; } bool IsZipped() const { return fIsZipped; }
void Unlink() const { plFileUtils::RemoveFile(fFilename); } void Unlink() const { plFileSystem::Unlink(fFilename); }
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -147,49 +141,44 @@ static void ManifestDownloaded(
uint32_t entryCount) uint32_t entryCount)
{ {
plResPatcher* patcher = (plResPatcher*)param; plResPatcher* patcher = (plResPatcher*)param;
char* name = hsWStringToString(group); plString name = plString::FromWchar(group);
if (IS_NET_SUCCESS(result)) if (IS_NET_SUCCESS(result))
PatcherLog(kInfo, " Downloaded manifest %s", name); PatcherLog(kInfo, " Downloaded manifest %s", name.c_str());
else { else {
PatcherLog(kError, " Failed to download manifest %s", name); PatcherLog(kError, " Failed to download manifest %s", name.c_str());
patcher->Finish(false); patcher->Finish(false);
delete[] name;
return; return;
} }
for (uint32_t i = 0; i < entryCount; ++i) for (uint32_t i = 0; i < entryCount; ++i)
{ {
const NetCliFileManifestEntry mfs = manifest[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 // See if the files are the same
// 1. Check file size before we do time consuming md5 operations // 1. Check file size before we do time consuming md5 operations
// 2. Do wasteful md5. We should consider implementing a CRC instead. // 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 cliMD5(fileName);
plMD5Checksum srvMD5; plMD5Checksum srvMD5;
char* eapSucksString = hsWStringToString(mfs.md5); srvMD5.SetFromHexString(plString::FromWchar(mfs.md5).c_str());
srvMD5.SetFromHexString(eapSucksString);
delete[] eapSucksString;
if (cliMD5 == srvMD5) if (cliMD5 == srvMD5)
{
delete[] fileName;
continue; continue;
else
PatcherLog(kInfo, " Enqueueing %s: MD5 Checksums Differ", fileName.AsString().c_str());
} else } else
PatcherLog(kInfo, " Enqueueing %s: MD5 Checksums Differ", fileName); PatcherLog(kInfo, " Enqueueing %s: File Sizes Differ", fileName.AsString().c_str());
} else
PatcherLog(kInfo, " Enqueueing %s: File Sizes Differ", fileName);
// If we're still here, then we need to update the file. // If we're still here, then we need to update the file.
float size = mfs.zipSize ? (float)mfs.zipSize : (float)mfs.fileSize; float size = mfs.zipSize ? (float)mfs.zipSize : (float)mfs.fileSize;
patcher->GetProgress()->SetLength(size + patcher->GetProgress()->GetMax()); patcher->GetProgress()->SetLength(size + patcher->GetProgress()->GetMax());
patcher->RequestFile(mfs.downloadName, mfs.clientName); patcher->RequestFile(downloadName, fileName);
} }
patcher->IssueRequest(); patcher->IssueRequest();
delete[] name;
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -234,25 +223,24 @@ void plResPatcher::IssueRequest()
plString title; plString title;
if (req.fType == kManifest) if (req.fType == kManifest)
{ {
PatcherLog(kMajorStatus, " Downloading manifest... %S", req.fFile.c_str()); PatcherLog(kMajorStatus, " Downloading manifest... %s", req.fFile.AsString().c_str());
title = plString::Format("Checking %S for updates...", req.fFile.c_str()); title = plString::Format("Checking %s for updates...", req.fFile.AsString().c_str());
NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.c_str()); NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.AsString().ToWchar());
} else if (req.fType == kFile) { } else if (req.fType == kFile) {
PatcherLog(kMajorStatus, " Downloading file... %S", req.fFriendlyName.c_str()); PatcherLog(kMajorStatus, " Downloading file... %s", req.fFriendlyName.AsString().c_str());
title = plString::Format("Downloading... %S", plFileUtils::GetFileName(req.fFriendlyName.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 // If this is a PRP, we need to unload it from the ResManager
plString filename = plString::FromWchar(req.fFriendlyName.c_str()); if (req.fFriendlyName.GetFileExt().CompareI("prp") == 0)
if (stricmp(plFileUtils::GetFileExt(filename.c_str()), "prp") == 0) ((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(req.fFriendlyName);
((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(filename.c_str());
plFileUtils::EnsureFilePathExists(req.fFriendlyName.c_str()); plFileSystem::CreateDir(req.fFriendlyName.StripFileName(), true);
plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile.c_str()); plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile);
if (stream->Open_TEMP(filename, "wb")) if (stream->Open(req.fFriendlyName, "wb"))
NetCliFileDownloadRequest(req.fFile.c_str(), stream, FileDownloaded, this); NetCliFileDownloadRequest(req.fFile.AsString().ToWchar(), stream, FileDownloaded, this);
else { 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); Finish(false);
} }
} }
@ -282,12 +270,12 @@ void plResPatcher::Finish(bool success)
pMsg->Send(); // whoosh... off it goes 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)); fRequests.push(Request(srvName, kFile, cliName));
} }
void plResPatcher::RequestManifest(const wchar_t* age) void plResPatcher::RequestManifest(const plString& age)
{ {
fRequests.push(Request(age, kManifest)); fRequests.push(Request(age, kManifest));
} }

17
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 #define plResPatcher_h_inc
#include "HeadSpin.h" #include "HeadSpin.h"
#include "plFileSystem.h"
#include <queue> #include <queue>
#include <string> #include <string>
@ -53,16 +54,12 @@ class plResPatcher
enum { kManifest, kFile }; enum { kManifest, kFile };
struct Request struct Request
{ {
std::wstring fFile; plFileName fFile;
std::wstring fFriendlyName; plFileName fFriendlyName;
uint8_t fType; uint8_t fType;
Request(const wchar_t* file, uint8_t type, const wchar_t* friendly = nil) Request(const plFileName& file, uint8_t type, const plFileName& friendly = "")
: fFile(file), fType(type) : fFile(file), fFriendlyName(friendly), fType(type) { }
{
if (friendly)
fFriendlyName = std::wstring(friendly);
}
}; };
static plResPatcher* fInstance; static plResPatcher* fInstance;
@ -81,8 +78,8 @@ public:
void Finish(bool success = true); void Finish(bool success = true);
void IssueRequest(); void IssueRequest();
void RequestFile(const wchar_t* file, const wchar_t* friendlyName); void RequestFile(const plFileName& file, const plFileName& friendlyName);
void RequestManifest(const wchar_t* age); void RequestManifest(const plString& age);
void Start(); void Start();
}; };

5
Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp

@ -84,10 +84,9 @@ void plClientResMgr::ILoadResources(const char* resfile)
return; return;
} }
wchar_t* wFilename = hsStringToWString(resfile);
hsUNIXStream in; hsUNIXStream in;
if (in.Open(wFilename, L"rb")) { if (in.Open(resfile, "rb")) {
uint32_t header = in.ReadLE32(); uint32_t header = in.ReadLE32();
uint32_t version = in.ReadLE32(); uint32_t version = in.ReadLE32();
uint32_t num_resources = 0; uint32_t num_resources = 0;
@ -133,8 +132,6 @@ void plClientResMgr::ILoadResources(const char* resfile)
in.Close(); in.Close();
} }
delete wFilename;
} }
plMipmap* plClientResMgr::getResource(const char* resname) plMipmap* plClientResMgr::getResource(const char* resname)

16
Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp

@ -61,23 +61,13 @@ plZlibStream::~plZlibStream()
hsAssert(!fOutput && !fZStream, "plZlibStream not closed"); hsAssert(!fOutput && !fZStream, "plZlibStream not closed");
} }
bool plZlibStream::Open(const char* filename, const char* mode) bool plZlibStream::Open(const plFileName& 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)
{ {
fFilename = filename; fFilename = filename;
fMode = mode; fMode = mode;
fOutput = new hsUNIXStream; fOutput = new hsUNIXStream;
return fOutput->Open(filename, L"wb"); return fOutput->Open(filename, "wb");
} }
bool plZlibStream::Close() 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) // hack so rewind will work (someone thought it would be funny to not implement base class functions)
Close(); Close();
Open(fFilename.c_str(), fMode.c_str()); Open(fFilename, fMode);
fHeader = kNeedMoreData; fHeader = kNeedMoreData;
fDecompressedOk = false; fDecompressedOk = false;
} }

7
Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h

@ -60,7 +60,9 @@ protected:
Validate fHeader; Validate fHeader;
std::vector<uint8_t> fHeaderCache; std::vector<uint8_t> 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); int IValidateGzHeader(uint32_t byteCount, const void* buffer);
@ -68,8 +70,7 @@ public:
plZlibStream(); plZlibStream();
virtual ~plZlibStream(); virtual ~plZlibStream();
virtual bool Open(const char* filename, const char* mode); virtual bool Open(const plFileName& filename, const char* mode);
virtual bool Open(const wchar_t* filename, const wchar_t* mode);
virtual bool Close(); virtual bool Close();
virtual uint32_t Write(uint32_t byteCount, const void* buffer); virtual uint32_t Write(uint32_t byteCount, const void* buffer);

107
Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp

@ -117,21 +117,11 @@ void plEncryptedStream::IDecipher(uint32_t* const v)
v[0]=y; v[1]=z; 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); if (strcmp(mode, "rb") == 0)
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)
{ {
fRef = hsWFopen(name, mode); fRef = plFileSystem::Open(name, mode);
fPosition = 0; fPosition = 0;
if (!fRef) if (!fRef)
@ -156,11 +146,10 @@ bool plEncryptedStream::Open(const wchar_t* name, const wchar_t* mode)
return true; return true;
} }
else if (wcscmp(mode, L"wb") == 0) else if (strcmp(mode, "wb") == 0)
{ {
fRAMStream = new hsVectorStream; fRAMStream = new hsVectorStream;
fWriteFileName = new wchar_t[wcslen(name) + 1]; fWriteFileName = name;
wcscpy(fWriteFileName, name);
fPosition = 0; fPosition = 0;
fOpenMode = kOpenWrite; fOpenMode = kOpenWrite;
@ -197,12 +186,7 @@ bool plEncryptedStream::Close()
fRAMStream = nil; fRAMStream = nil;
} }
if (fWriteFileName) fWriteFileName = plString::Null;
{
delete [] fWriteFileName;
fWriteFileName = nil;
}
fActualFileSize = 0; fActualFileSize = 0;
fBufferedStream = false; fBufferedStream = false;
fOpenMode = kOpenFail; fOpenMode = kOpenFail;
@ -389,11 +373,11 @@ uint32_t plEncryptedStream::Write(uint32_t bytes, const void* buffer)
return fRAMStream->Write(bytes, 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; hsUNIXStream outputStream;
if (!outputStream.Open(outputFile, L"wb")) if (!outputStream.Open(outputFile, "wb"))
return false; return false;
outputStream.Write(kMagicStringLen, kMagicString); outputStream.Write(kMagicStringLen, kMagicString);
@ -439,15 +423,7 @@ bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar_t* ou
return true; return true;
} }
bool plEncryptedStream::FileEncrypt(const char* fileName) bool plEncryptedStream::FileEncrypt(const plFileName& fileName)
{
wchar_t* wFilename = hsStringToWString(fileName);
bool ret = FileEncrypt(wFilename);
delete [] wFilename;
return ret;
}
bool plEncryptedStream::FileEncrypt(const wchar_t* fileName)
{ {
hsUNIXStream sIn; hsUNIXStream sIn;
if (!sIn.Open(fileName)) if (!sIn.Open(fileName))
@ -462,36 +438,28 @@ bool plEncryptedStream::FileEncrypt(const wchar_t* fileName)
sIn.Rewind(); sIn.Rewind();
plEncryptedStream sOut; plEncryptedStream sOut;
bool wroteEncrypted = sOut.IWriteEncypted(&sIn, L"crypt.dat"); bool wroteEncrypted = sOut.IWriteEncypted(&sIn, "crypt.dat");
sIn.Close(); sIn.Close();
sOut.Close(); sOut.Close();
if (wroteEncrypted) if (wroteEncrypted)
{ {
plFileUtils::RemoveFile(fileName); plFileSystem::Unlink(fileName);
plFileUtils::FileMove(L"crypt.dat", fileName); plFileSystem::Move("crypt.dat", fileName);
} }
return true; return true;
} }
bool plEncryptedStream::FileDecrypt(const char* fileName) bool plEncryptedStream::FileDecrypt(const plFileName& fileName)
{
wchar_t* wFilename = hsStringToWString(fileName);
bool ret = FileDecrypt(wFilename);
delete [] wFilename;
return ret;
}
bool plEncryptedStream::FileDecrypt(const wchar_t* fileName)
{ {
plEncryptedStream sIn; plEncryptedStream sIn;
if (!sIn.Open(fileName)) if (!sIn.Open(fileName))
return false; return false;
hsUNIXStream sOut; hsUNIXStream sOut;
if (!sOut.Open(L"crypt.dat", L"wb")) if (!sOut.Open("crypt.dat", "wb"))
{ {
sIn.Close(); sIn.Close();
return false; return false;
@ -508,32 +476,23 @@ bool plEncryptedStream::FileDecrypt(const wchar_t* fileName)
sIn.Close(); sIn.Close();
sOut.Close(); sOut.Close();
plFileUtils::RemoveFile(fileName); plFileSystem::Unlink(fileName);
plFileUtils::FileMove(L"crypt.dat", fileName); plFileSystem::Move("crypt.dat", fileName);
return true; return true;
} }
bool plEncryptedStream::ICheckMagicString(FILE* fp) bool plEncryptedStream::ICheckMagicString(FILE* fp)
{ {
char magicString[kMagicStringLen+1]; char magicString[kMagicStringLen];
fread(&magicString, kMagicStringLen, 1, fp); fread(&magicString, kMagicStringLen, 1, fp);
magicString[kMagicStringLen] = '\0'; return memcmp(magicString, kMagicString, kMagicStringLen) == 0 ||
return strcmp(magicString, kMagicString) == 0 || memcmp(magicString, kOldMagicString, kMagicStringLen) == 0;
strcmp(magicString, kOldMagicString) == 0;
} }
bool plEncryptedStream::IsEncryptedFile(const char* fileName) bool plEncryptedStream::IsEncryptedFile(const plFileName& fileName)
{ {
wchar_t* wFilename = hsStringToWString(fileName); FILE* fp = plFileSystem::Open(fileName, "rb");
bool ret = IsEncryptedFile(wFilename);
delete [] wFilename;
return ret;
}
bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName)
{
FILE* fp = hsWFopen(fileName, L"rb");
if (!fp) if (!fp)
return false; return false;
@ -544,15 +503,7 @@ bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName)
return isEncrypted; return isEncrypted;
} }
hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, uint32_t* cryptKey) hsStream* plEncryptedStream::OpenEncryptedFile(const plFileName& 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)
{ {
bool isEncrypted = IsEncryptedFile(fileName); bool isEncrypted = IsEncryptedFile(fileName);
@ -563,19 +514,11 @@ hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, uint32_t
else else
s = new hsUNIXStream; s = new hsUNIXStream;
s->Open(fileName, L"rb"); s->Open(fileName, "rb");
return s; return s;
} }
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey) hsStream* plEncryptedStream::OpenEncryptedFileWrite(const plFileName& 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* s = nil; hsStream* s = nil;
if (IsEncryptedFile(fileName)) if (IsEncryptedFile(fileName))
@ -583,6 +526,6 @@ hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uin
else else
s = new hsUNIXStream; s = new hsUNIXStream;
s->Open(fileName, L"wb"); s->Open(fileName, "wb");
return s; return s;
} }

22
Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h

@ -61,7 +61,7 @@ protected:
hsStream* fRAMStream; hsStream* fRAMStream;
wchar_t* fWriteFileName; plFileName fWriteFileName;
enum OpenMode { kOpenRead, kOpenWrite, kOpenFail }; enum OpenMode { kOpenRead, kOpenWrite, kOpenFail };
OpenMode fOpenMode; OpenMode fOpenMode;
@ -73,7 +73,7 @@ protected:
void IEncipher(uint32_t* const v); void IEncipher(uint32_t* const v);
void IDecipher(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); static bool ICheckMagicString(FILE* fp);
@ -82,8 +82,7 @@ public:
plEncryptedStream(uint32_t* key=nil); plEncryptedStream(uint32_t* key=nil);
~plEncryptedStream(); ~plEncryptedStream();
virtual bool Open(const char* name, const char* mode = "rb"); virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb");
virtual bool Close(); virtual bool Close();
virtual uint32_t Read(uint32_t byteCount, void* buffer); virtual uint32_t Read(uint32_t byteCount, void* buffer);
@ -96,21 +95,16 @@ public:
uint32_t GetActualFileSize() const { return fActualFileSize;} uint32_t GetActualFileSize() const { return fActualFileSize;}
static bool FileEncrypt(const char* fileName); static bool FileEncrypt(const plFileName& fileName);
static bool FileEncrypt(const wchar_t* fileName); static bool FileDecrypt(const plFileName& fileName);
static bool FileDecrypt(const char* fileName);
static bool FileDecrypt(const wchar_t* fileName);
static bool IsEncryptedFile(const char* fileName); static bool IsEncryptedFile(const plFileName& fileName);
static bool IsEncryptedFile(const wchar_t* fileName);
// Attempts to create a read-binary stream for the requested file. If it's // Attempts to create a read-binary stream for the requested file. If it's
// encrypted, you'll get a plEncryptedStream, otherwise just a standard // encrypted, you'll get a plEncryptedStream, otherwise just a standard
// hsUNIXStream. Remember to delete the stream when you're done with it. // 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 plFileName& fileName, uint32_t* cryptKey = nil);
static hsStream* OpenEncryptedFile(const wchar_t* fileName, uint32_t* cryptKey = nil); static hsStream* OpenEncryptedFileWrite(const plFileName& 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);
}; };
#endif // plEncryptedStream_h_inc #endif // plEncryptedStream_h_inc

2
Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp

@ -493,7 +493,7 @@ uint32_t plFileUtils::GetFileSize( const wchar_t *path )
uint32_t len = 0; uint32_t len = 0;
hsUNIXStream str; hsUNIXStream str;
if (str.Open(path, L"rb")) if (str.Open(plString::FromWchar(path), "rb"))
{ {
len = str.GetEOF(); len = str.GetEOF();
str.Close(); str.Close();

144
Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp

@ -66,7 +66,6 @@ static const int kFileStartOffset = kMagicStringLen + sizeof(uint32_t);
static const int kMaxBufferedFileSize = 10*1024; static const int kMaxBufferedFileSize = 10*1024;
const char plSecureStream::kKeyFilename[] = "encryption.key"; const char plSecureStream::kKeyFilename[] = "encryption.key";
const wchar_t plSecureStream::kWKeyFilename[] = L"encryption.key";
plSecureStream::plSecureStream(bool deleteOnExit, uint32_t* key) : plSecureStream::plSecureStream(bool deleteOnExit, uint32_t* key) :
fRef(INVALID_HANDLE_VALUE), 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); if (strcmp(mode, "rb") == 0)
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 HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
if (fDeleteOnExit) if (fDeleteOnExit)
{ {
fRef = CreateFileW(name, fRef = CreateFileW(name.AsString().ToWchar(),
GENERIC_READ, // open for reading GENERIC_READ, // open for reading
0, // no one can open the file until we're done 0, // no one can open the file until we're done
NULL, // default security NULL, // default security
@ -182,7 +171,7 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode)
} }
else else
{ {
fRef = CreateFileW(name, fRef = CreateFileW(name.AsString().ToWchar(),
GENERIC_READ, // open for reading GENERIC_READ, // open for reading
0, // no one can open the file until we're done 0, // no one can open the file until we're done
NULL, // default security NULL, // default security
@ -207,10 +196,7 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode)
DWORD numBytesRead; DWORD numBytesRead;
ReadFile(fRef, &fActualFileSize, sizeof(uint32_t), &numBytesRead, NULL); ReadFile(fRef, &fActualFileSize, sizeof(uint32_t), &numBytesRead, NULL);
#elif HS_BUILD_FOR_UNIX #elif HS_BUILD_FOR_UNIX
const char* cname = hsWStringToString(name); fRef = plFileSystem::Open(name, "rb");
fRef = fopen(cname, "rb");
delete[] cname;
fPosition = 0; fPosition = 0;
if (fRef == INVALID_HANDLE_VALUE) if (fRef == INVALID_HANDLE_VALUE)
@ -234,11 +220,10 @@ bool plSecureStream::Open(const wchar_t* name, const wchar_t* mode)
return true; return true;
} }
else if (wcscmp(mode, L"wb") == 0) else if (strcmp(mode, "wb") == 0)
{ {
fRAMStream = new hsVectorStream; fRAMStream = new hsVectorStream;
fWriteFileName = new wchar_t[wcslen(name) + 1]; fWriteFileName = name;
wcscpy(fWriteFileName, name);
fPosition = 0; fPosition = 0;
fOpenMode = kOpenWrite; fOpenMode = kOpenWrite;
@ -312,12 +297,7 @@ bool plSecureStream::Close()
fRAMStream = nil; fRAMStream = nil;
} }
if (fWriteFileName) fWriteFileName = plString::Null;
{
delete [] fWriteFileName;
fWriteFileName = nil;
}
fActualFileSize = 0; fActualFileSize = 0;
fBufferedStream = false; fBufferedStream = false;
fOpenMode = kOpenFail; fOpenMode = kOpenFail;
@ -528,11 +508,11 @@ uint32_t plSecureStream::Write(uint32_t bytes, const void* buffer)
return fRAMStream->Write(bytes, 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; hsUNIXStream outputStream;
if (!outputStream.Open(outputFile, L"wb")) if (!outputStream.Open(outputFile, "wb"))
return false; return false;
outputStream.Write(kMagicStringLen, kMagicString); outputStream.Write(kMagicStringLen, kMagicString);
@ -578,15 +558,7 @@ bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar_t* outp
return true; return true;
} }
bool plSecureStream::FileEncrypt(const char* fileName, uint32_t* key /* = nil */) bool plSecureStream::FileEncrypt(const plFileName& 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 */)
{ {
hsUNIXStream sIn; hsUNIXStream sIn;
if (!sIn.Open(fileName)) if (!sIn.Open(fileName))
@ -601,36 +573,28 @@ bool plSecureStream::FileEncrypt(const wchar_t* fileName, uint32_t* key /* = nil
sIn.Rewind(); sIn.Rewind();
plSecureStream sOut(false, key); plSecureStream sOut(false, key);
bool wroteEncrypted = sOut.IWriteEncrypted(&sIn, L"crypt.dat"); bool wroteEncrypted = sOut.IWriteEncrypted(&sIn, "crypt.dat");
sIn.Close(); sIn.Close();
sOut.Close(); sOut.Close();
if (wroteEncrypted) if (wroteEncrypted)
{ {
plFileUtils::RemoveFile(fileName); plFileSystem::Unlink(fileName);
plFileUtils::FileMove(L"crypt.dat", fileName); plFileSystem::Move("crypt.dat", fileName);
} }
return true; return true;
} }
bool plSecureStream::FileDecrypt(const char* fileName, uint32_t* key /* = nil */) bool plSecureStream::FileDecrypt(const plFileName& 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 */)
{ {
plSecureStream sIn(false, key); plSecureStream sIn(false, key);
if (!sIn.Open(fileName)) if (!sIn.Open(fileName))
return false; return false;
hsUNIXStream sOut; hsUNIXStream sOut;
if (!sOut.Open(L"crypt.dat", L"wb")) if (!sOut.Open("crypt.dat", "wb"))
{ {
sIn.Close(); sIn.Close();
return false; return false;
@ -647,8 +611,8 @@ bool plSecureStream::FileDecrypt(const wchar_t* fileName, uint32_t* key /* = nil
sIn.Close(); sIn.Close();
sOut.Close(); sOut.Close();
plFileUtils::RemoveFile(fileName); plFileSystem::Unlink(fileName);
plFileUtils::FileMove(L"crypt.dat", fileName); plFileSystem::Move("crypt.dat", fileName);
return true; return true;
} }
@ -674,20 +638,12 @@ bool plSecureStream::ICheckMagicString(hsFD fp)
return (strcmp(magicString, kMagicString) == 0); return (strcmp(magicString, kMagicString) == 0);
} }
bool plSecureStream::IsSecureFile(const char* fileName) bool plSecureStream::IsSecureFile(const plFileName& fileName)
{
wchar_t* wFilename = hsStringToWString(fileName);
bool ret = IsSecureFile(wFilename);
delete [] wFilename;
return ret;
}
bool plSecureStream::IsSecureFile(const wchar_t* fileName)
{ {
hsFD fp = INVALID_HANDLE_VALUE; hsFD fp = INVALID_HANDLE_VALUE;
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
fp = CreateFileW(fileName, fp = CreateFileW(fileName.AsString().ToWchar(),
GENERIC_READ, // open for reading GENERIC_READ, // open for reading
0, // no one can open the file until we're done 0, // no one can open the file until we're done
NULL, // default security NULL, // default security
@ -695,9 +651,7 @@ bool plSecureStream::IsSecureFile(const wchar_t* fileName)
FILE_ATTRIBUTE_NORMAL, // normal file attributes FILE_ATTRIBUTE_NORMAL, // normal file attributes
NULL); // no template NULL); // no template
#elif HS_BUILD_FOR_UNIX #elif HS_BUILD_FOR_UNIX
const char* cfile = hsWStringToString(fileName); fp = plFileSystem::Open(fileName);
fp = fopen(cfile, "rb");
delete[] cfile;
#endif #endif
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
@ -714,15 +668,7 @@ bool plSecureStream::IsSecureFile(const wchar_t* fileName)
return isEncrypted; return isEncrypted;
} }
hsStream* plSecureStream::OpenSecureFile(const char* 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 */)
{
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 */)
{ {
bool requireEncryption = flags & kRequireEncryption; bool requireEncryption = flags & kRequireEncryption;
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
@ -739,19 +685,11 @@ hsStream* plSecureStream::OpenSecureFile(const wchar_t* fileName, const uint32_t
s = new hsUNIXStream; s = new hsUNIXStream;
if (s) if (s)
s->Open(fileName, L"rb"); s->Open(fileName, "rb");
return s; return s;
} }
hsStream* plSecureStream::OpenSecureFileWrite(const char* fileName, uint32_t* key /* = nil */) hsStream* plSecureStream::OpenSecureFileWrite(const plFileName& 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* s = nil; hsStream* s = nil;
#ifdef PLASMA_EXTERNAL_RELEASE #ifdef PLASMA_EXTERNAL_RELEASE
@ -760,46 +698,22 @@ hsStream* plSecureStream::OpenSecureFileWrite(const wchar_t* fileName, uint32_t*
s = new hsUNIXStream; s = new hsUNIXStream;
#endif #endif
s->Open(fileName, L"wb"); s->Open(fileName, "wb");
return s; return s;
} }
//// GetSecureEncryptionKey ////////////////////////////////////////////////// //// GetSecureEncryptionKey //////////////////////////////////////////////////
bool plSecureStream::GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length) bool plSecureStream::GetSecureEncryptionKey(const plFileName& 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)
{ {
// looks for an encryption key file in the same directory, and reads it // looks for an encryption key file in the same directory, and reads it
std::wstring sFilename = filename; plFileName keyFile = plFileName::Join(filename.StripFileName(), kKeyFilename);
// 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;
if (plFileUtils::FileExists(keyFile.c_str())) if (plFileInfo(keyFile).Exists())
{ {
// file exists, read from it // file exists, read from it
hsUNIXStream file; hsUNIXStream file;
file.Open(keyFile.c_str(), L"rb"); file.Open(keyFile, "rb");
unsigned bytesToRead = length * sizeof(uint32_t); unsigned bytesToRead = length * sizeof(uint32_t);
uint8_t* buffer = (uint8_t*)malloc(bytesToRead); uint8_t* buffer = (uint8_t*)malloc(bytesToRead);

26
Sources/Plasma/PubUtilLib/plFile/plSecureStream.h

@ -69,7 +69,7 @@ protected:
hsStream* fRAMStream; hsStream* fRAMStream;
wchar_t* fWriteFileName; plFileName fWriteFileName;
enum OpenMode {kOpenRead, kOpenWrite, kOpenFail}; enum OpenMode {kOpenRead, kOpenWrite, kOpenFail};
OpenMode fOpenMode; OpenMode fOpenMode;
@ -83,7 +83,7 @@ protected:
void IEncipher(uint32_t* const v, uint32_t n); void IEncipher(uint32_t* const v, uint32_t n);
void IDecipher(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(hsFD fp);
static bool ICheckMagicString(hsStream* s); static bool ICheckMagicString(hsStream* s);
@ -93,8 +93,7 @@ public:
plSecureStream(hsStream* base, uint32_t* key = nil); plSecureStream(hsStream* base, uint32_t* key = nil);
~plSecureStream(); ~plSecureStream();
virtual bool Open(const char* name, const char* mode = "rb"); virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb");
bool Open(hsStream* stream); bool Open(hsStream* stream);
virtual bool Close(); virtual bool Close();
@ -108,10 +107,8 @@ public:
uint32_t GetActualFileSize() const {return fActualFileSize;} uint32_t GetActualFileSize() const {return fActualFileSize;}
static bool FileEncrypt(const char* fileName, uint32_t* key = nil); static bool FileEncrypt(const plFileName& fileName, uint32_t* key = nil);
static bool FileEncrypt(const wchar_t* fileName, uint32_t* key = nil); static bool FileDecrypt(const plFileName& 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);
enum OpenSecureFileFlags enum OpenSecureFileFlags
{ {
@ -119,28 +116,23 @@ public:
kDeleteOnExit = 0x02, kDeleteOnExit = 0x02,
}; };
static bool IsSecureFile(const char* fileName); static bool IsSecureFile(const plFileName& fileName);
static bool IsSecureFile(const wchar_t* fileName);
// Attempts to create a read-binary stream for the requested file (delete the stream // Attempts to create a read-binary stream for the requested file (delete the stream
// when you are done with it!) // 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 plFileName& 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);
// Attempts to create a write-binary stream for the requested file (delete the stream // Attempts to create a write-binary stream for the requested file (delete the stream
// when you are done with it!) // when you are done with it!)
static hsStream* OpenSecureFileWrite(const char* fileName, uint32_t* key = nil); static hsStream* OpenSecureFileWrite(const plFileName& fileName, uint32_t* key = nil);
static hsStream* OpenSecureFileWrite(const wchar_t* fileName, uint32_t* key = nil);
static const uint32_t kDefaultKey[4]; // our default encryption key static const uint32_t kDefaultKey[4]; // our default encryption key
// searches the parent directory of filename for the encryption key file, and reads it // 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 // into the key passed in. Returns false if the key file didn't exist (and sets key to
// the default key) // the default key)
static bool GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length); static bool GetSecureEncryptionKey(const plFileName& filename, uint32_t* key, unsigned length);
static bool GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length);
static const char kKeyFilename[]; static const char kKeyFilename[];
static const wchar_t kWKeyFilename[];
}; };
#endif // plSecureStream_h_inc #endif // plSecureStream_h_inc

131
Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp

@ -51,25 +51,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
# include <wctype.h> # include <wctype.h>
#endif #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() void plStreamSource::ICleanup()
{ {
// loop through all the file data records, and delete the streams // loop through all the file data records, and delete the streams
std::map<std::wstring, fileData>::iterator curData; decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); curData++) for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
{ {
curData->second.fStream->Close(); curData->second.fStream->Close();
@ -80,137 +65,85 @@ void plStreamSource::ICleanup()
fFileData.clear(); 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 plFileName sFilename = filename.Normalize('/');
char* temp = hsWStringToString(filename.c_str()); if (fFileData.find(sFilename) == fFileData.end())
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())
{ {
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// internal releases can pull from disk // internal releases can pull from disk
char* temp = hsWStringToString(filename.c_str()); if (plFileInfo(filename).Exists())
std::string sFilename = temp;
delete [] temp;
if (plFileUtils::FileExists(sFilename.c_str()))
{ {
// file exists on disk, cache it // file exists on disk, cache it
std::wstring dir, ext; fFileData[sFilename].fFilename = sFilename;
IBreakupFilename(filename, dir, ext); fFileData[sFilename].fDir = sFilename.StripFileName();
fFileData[filename].fFilename = filename; fFileData[sFilename].fExt = sFilename.GetFileExt();
fFileData[filename].fDir = dir; if (plSecureStream::IsSecureFile(filename))
fFileData[filename].fExt = ext;
if (plSecureStream::IsSecureFile(sFilename.c_str()))
{ {
uint32_t encryptionKey[4]; 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!"); FATAL("Hey camper... You need an NTD key file!");
return nil; 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 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 #endif // PLASMA_EXTERNAL_RELEASE
return nil; return nil;
} }
return fFileData[filename].fStream; return fFileData[sFilename].fStream;
} }
std::vector<std::wstring> plStreamSource::GetListOfNames(std::wstring dir, std::wstring ext) std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, const plString& ext)
{ {
ToLower(ext); plFileName sDir = dir.Normalize('/');
ToLower(dir); hsAssert(ext.CharAt(0) != '.', "Don't add a dot");
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
// loop through all the file data records, and create the list // loop through all the file data records, and create the list
std::vector<std::wstring> retVal; std::vector<plFileName> retVal;
std::map<std::wstring, fileData>::iterator curData; decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); 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); retVal.push_back(curData->second.fFilename);
} }
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
// in internal releases, we can use on-disk files if they exist // in internal releases, we can use on-disk files if they exist
// Build the search string as "dir/*.ext" // Build the search string as "dir/*.ext"
std::wstring wSearchStr = dir + L"/*." + ext; plString searchStr = plFileName::Join(sDir, "*." + ext).AsString();
char* temp = hsWStringToString(wSearchStr.c_str());
std::string searchStr = temp;
delete [] temp;
hsFolderIterator folderIter(searchStr.c_str(), true); hsFolderIterator folderIter(searchStr.c_str(), true);
while (folderIter.NextFile()) while (folderIter.NextFile())
{ {
const char* filename = folderIter.GetFileName(); plFileName filename = plFileName::Join(sDir, folderIter.GetFileName());
wchar_t* wTemp = hsStringToWString(filename);
std::wstring wFilename = dir + L"/" + wTemp; if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet
delete [] wTemp; retVal.push_back(filename);
ToLower(wFilename);
if (fFileData.find(wFilename) == fFileData.end()) // we haven't added it yet
retVal.push_back(wFilename);
} }
#endif // PLASMA_EXTERNAL_RELEASE #endif // PLASMA_EXTERNAL_RELEASE
return retVal; return retVal;
} }
bool plStreamSource::InsertFile(std::wstring filename, hsStream* stream) bool plStreamSource::InsertFile(const plFileName& filename, hsStream* stream)
{ {
ToLower(filename); plFileName sFilename = filename.Normalize('/');
ReplaceSlashes(filename, L'/');
if (fFileData.find(filename) != fFileData.end()) if (fFileData.find(sFilename) != fFileData.end())
return false; // duplicate entry, return failure 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!) // copy the data over (takes ownership of the stream!)
fFileData[filename].fFilename = filename; fFileData[sFilename].fFilename = sFilename;
fFileData[filename].fDir = dir; fFileData[sFilename].fDir = sFilename.StripFileName();
fFileData[filename].fExt = ext; fFileData[sFilename].fExt = sFilename.GetFileExt();
fFileData[filename].fStream = stream; fFileData[sFilename].fStream = stream;
return true; return true;
} }

15
Sources/Plasma/PubUtilLib/plFile/plStreamSource.h

@ -54,15 +54,14 @@ class plStreamSource
private: private:
struct fileData struct fileData
{ {
std::wstring fFilename; // includes path plFileName fFilename; // includes path
std::wstring fDir; // parent directory plFileName fDir; // parent directory
std::wstring fExt; plString fExt;
hsStream* fStream; // we own this pointer, so clean it up hsStream* fStream; // we own this pointer, so clean it up
}; };
std::map<std::wstring, fileData> fFileData; // key is filename std::map<plFileName, fileData, plFileName::less_i> fFileData; // key is filename
void ICleanup(); // closes all file pointers and cleans up after itself void ICleanup(); // closes all file pointers and cleans up after itself
void IBreakupFilename(std::wstring filename, std::wstring& dir, std::wstring& ext);
plStreamSource() {} plStreamSource() {}
public: public:
@ -72,11 +71,11 @@ public:
void Cleanup() {ICleanup();} void Cleanup() {ICleanup();}
// File access functions // File access functions
hsStream* GetFile(std::wstring filename); // internal builds will read from disk if it doesn't exist hsStream* GetFile(const plFileName& filename); // internal builds will read from disk if it doesn't exist
std::vector<std::wstring> GetListOfNames(std::wstring dir, std::wstring ext); // internal builds merge from disk std::vector<plFileName> 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) // 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 // Instance handling
static plStreamSource* GetInstance(); static plStreamSource* GetInstance();

24
Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp

@ -232,20 +232,12 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
return newMipmap; return newMipmap;
} }
plMipmap* plJPEG::ReadFromFile( const char *fileName ) plMipmap* plJPEG::ReadFromFile( const plFileName &fileName )
{
wchar_t* wFilename = hsStringToWString(fileName);
plMipmap* retVal = ReadFromFile(wFilename);
delete [] wFilename;
return retVal;
}
plMipmap* plJPEG::ReadFromFile( const wchar_t *fileName )
{ {
// we use a stream because the IJL can't handle unicode // we use a stream because the IJL can't handle unicode
hsRAMStream tempstream; hsRAMStream tempstream;
hsUNIXStream in; hsUNIXStream in;
if (!in.Open(fileName, L"rb")) if (!in.Open(fileName, "rb"))
return nil; return nil;
// The stream reader for JPEGs expects a 32-bit size at the start, // 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; return result;
} }
bool plJPEG::WriteToFile( const char *fileName, plMipmap *sourceData ) bool plJPEG::WriteToFile( const plFileName &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 )
{ {
// we use a stream because the IJL can't handle unicode // we use a stream because the IJL can't handle unicode
hsRAMStream tempstream; hsRAMStream tempstream;
hsUNIXStream out; hsUNIXStream out;
if (!out.Open(fileName, L"wb")) if (!out.Open(fileName, "wb"))
return false; return false;
bool ret = IWrite(sourceData, &tempstream); bool ret = IWrite(sourceData, &tempstream);
if (ret) if (ret)

7
Sources/Plasma/PubUtilLib/plGImage/plJPEG.h

@ -58,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plMipmap; class plMipmap;
class hsStream; class hsStream;
class plFileName;
class plJPEG class plJPEG
{ {
@ -74,12 +75,10 @@ class plJPEG
public: public:
plMipmap *ReadFromStream( hsStream *inStream ) { return IRead( inStream ); } plMipmap *ReadFromStream( hsStream *inStream ) { return IRead( inStream ); }
plMipmap *ReadFromFile( const char *fileName ); plMipmap *ReadFromFile( const plFileName &fileName );
plMipmap *ReadFromFile( const wchar_t *fileName );
bool WriteToStream( hsStream *outStream, plMipmap *sourceData ) { return IWrite( sourceData, outStream ); } bool WriteToStream( hsStream *outStream, plMipmap *sourceData ) { return IWrite( sourceData, outStream ); }
bool WriteToFile( const char *fileName, plMipmap *sourceData ); bool WriteToFile( const plFileName &fileName, plMipmap *sourceData );
bool WriteToFile( const wchar_t *fileName, plMipmap *sourceData );
// Range is 0 (worst) to 100 (best) // Range is 0 (worst) to 100 (best)
void SetWriteQuality( uint8_t q ) { fWriteQuality = q; } void SetWriteQuality( uint8_t q ) { fWriteQuality = q; }

24
Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp

@ -178,19 +178,11 @@ plMipmap* plPNG::IRead(hsStream* inStream)
return newMipmap; return newMipmap;
} }
plMipmap* plPNG::ReadFromFile(const char* fileName) plMipmap* plPNG::ReadFromFile(const plFileName& fileName)
{
wchar_t* wFilename = hsStringToWString(fileName);
plMipmap* retVal = ReadFromFile(wFilename);
delete [] wFilename;
return retVal;
}
plMipmap* plPNG::ReadFromFile(const wchar_t* fileName)
{ {
hsUNIXStream in; hsUNIXStream in;
if (!in.Open(fileName, L"rb")) { if (!in.Open(fileName, "rb")) {
return nil; return nil;
} }
@ -248,19 +240,11 @@ bool plPNG::IWrite(plMipmap* source, hsStream* outStream)
return result; return result;
} }
bool plPNG::WriteToFile(const char* fileName, plMipmap* sourceData) bool plPNG::WriteToFile(const plFileName& 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)
{ {
hsUNIXStream out; hsUNIXStream out;
if (!out.Open(fileName, L"wb")) { if (!out.Open(fileName, "wb")) {
return false; return false;
} }

6
Sources/Plasma/PubUtilLib/plGImage/plPNG.h

@ -58,12 +58,10 @@ protected:
public: public:
plMipmap* ReadFromStream(hsStream* inStream) { return IRead(inStream); } plMipmap* ReadFromStream(hsStream* inStream) { return IRead(inStream); }
plMipmap* ReadFromFile(const char* fileName); plMipmap* ReadFromFile(const plFileName& fileName);
plMipmap* ReadFromFile(const wchar_t* fileName);
bool WriteToStream(hsStream* outStream, plMipmap* sourceData) { return IWrite(sourceData, outStream); } bool WriteToStream(hsStream* outStream, plMipmap* sourceData) { return IWrite(sourceData, outStream); }
bool WriteToFile(const char* fileName, plMipmap* sourceData); bool WriteToFile(const plFileName& fileName, plMipmap* sourceData);
bool WriteToFile(const wchar_t* fileName, plMipmap* sourceData);
static plPNG& Instance(void); static plPNG& Instance(void);
}; };

16
Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp

@ -52,7 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plVersion.h" #include "plVersion.h"
plRegistryPageNode::plRegistryPageNode(const plString& path) plRegistryPageNode::plRegistryPageNode(const plFileName& path)
: fValid(kPageCorrupt) : fValid(kPageCorrupt)
, fPath(path) , fPath(path)
, fDynLoadedTypes(0) , 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) : fValid(kPageOk)
, fPath(nil)
, fPageInfo(location) , fPageInfo(location)
, fDynLoadedTypes(0) , fDynLoadedTypes(0)
, fStaticLoadedTypes(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 // Time to construct our actual file name. For now, we'll use the same old format
// of age_page.extension // 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() plRegistryPageNode::~plRegistryPageNode()
@ -129,7 +130,7 @@ hsStream* plRegistryPageNode::OpenStream()
{ {
if (fOpenRequests == 0) if (fOpenRequests == 0)
{ {
if (!fStream.Open_TEMP(fPath, "rb")) if (!fStream.Open(fPath, "rb"))
return nil; return nil;
} }
fOpenRequests++; fOpenRequests++;
@ -220,7 +221,7 @@ void plRegistryPageNode::Write()
{ {
hsAssert(fOpenRequests == 0, "Trying to write while the page is open for reading"); 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"); hsAssert(0, "Couldn't open file for writing");
return; return;
@ -400,6 +401,5 @@ plRegistryKeyList* plRegistryPageNode::IGetKeyList(uint16_t classType) const
void plRegistryPageNode::DeleteSource() void plRegistryPageNode::DeleteSource()
{ {
hsAssert(fOpenRequests == 0, "Deleting a stream that's open for reading"); hsAssert(fOpenRequests == 0, "Deleting a stream that's open for reading");
plFileUtils::RemoveFile(fPath.c_str()); plFileSystem::Unlink(fPath);
} }

9
Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h

@ -78,7 +78,7 @@ protected:
int fStaticLoadedTypes; // The number of key types that have all their keys loaded int fStaticLoadedTypes; // The number of key types that have all their keys loaded
PageCond fValid; // Condition of the page 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 plPageInfo fPageInfo; // Info about this page
hsBufferedStream fStream; // Stream for reading/writing our page hsBufferedStream fStream; // Stream for reading/writing our page
@ -93,10 +93,11 @@ protected:
public: public:
// For reading a page off disk // For reading a page off disk
plRegistryPageNode(const plString& path); plRegistryPageNode(const plFileName& path);
// For creating a new page. // 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(); ~plRegistryPageNode();
bool IsValid() const { return fValid == kPageOk; } bool IsValid() const { return fValid == kPageOk; }
@ -143,7 +144,7 @@ public:
void Write(); void Write();
void DeleteSource(); void DeleteSource();
const plString& GetPagePath() const { return fPath; } const plFileName& GetPagePath() const { return fPath; }
}; };
#endif // plRegistryNode_h_inc #endif // plRegistryNode_h_inc

16
Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp

@ -235,25 +235,25 @@ void plResManager::IShutdown()
fInited = false; fInited = false;
} }
void plResManager::AddSinglePage(const char* pagePath) void plResManager::AddSinglePage(const plFileName& pagePath)
{ {
plRegistryPageNode* node = new plRegistryPageNode(pagePath); plRegistryPageNode* node = new plRegistryPageNode(pagePath);
AddPage(node); AddPage(node);
} }
plRegistryPageNode* plResManager::FindSinglePage(const char* path) const plRegistryPageNode* plResManager::FindSinglePage(const plFileName& path) const
{ {
PageMap::const_iterator it; PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); 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 it->second;
} }
return nil; return nil;
} }
void plResManager::RemoveSinglePage(const char* path) void plResManager::RemoveSinglePage(const plFileName& path)
{ {
plRegistryPageNode* node = FindSinglePage(path); plRegistryPageNode* node = FindSinglePage(path);
if (node) if (node)
@ -1383,16 +1383,14 @@ static void ICatPageNames(hsTArray<plRegistryPageNode*>& pages, char* buf, int b
break; break;
} }
const char* pagePath = pages[i]->GetPagePath().c_str(); plString pageFile = pages[i]->GetPagePath().GetFileName();
const char* pageFile = plFileUtils::GetFileName(pagePath); if (strlen(buf) + pageFile.GetSize() > bufSize - 5)
if (strlen(buf) + strlen(pageFile) > bufSize - 5)
{ {
strcat(buf, "...\n"); strcat(buf, "...\n");
break; break;
} }
strcat(buf, pageFile); strcat(buf, pageFile.c_str());
strcat(buf, "\n"); strcat(buf, "\n");
} }
} }

7
Sources/Plasma/PubUtilLib/plResMgr/plResManager.h

@ -55,6 +55,7 @@ class plRegistryDataStream;
class plResAgeHolder; class plResAgeHolder;
class plResManagerHelper; class plResManagerHelper;
class plDispatch; class plDispatch;
class plFileName;
// plProgressProc is a proc called every time an object loads, to keep a progress bar for // plProgressProc is a proc called every time an object loads, to keep a progress bar for
// loading ages up-to-date. // loading ages up-to-date.
@ -70,9 +71,9 @@ public:
void SetDataPath(const char* path) { fDataPath = path; } void SetDataPath(const char* path) { fDataPath = path; }
// Mainly for external tools. // Mainly for external tools.
void AddSinglePage(const char* path); void AddSinglePage(const plFileName& path);
plRegistryPageNode* FindSinglePage(const char* path) const; plRegistryPageNode* FindSinglePage(const plFileName& path) const;
void RemoveSinglePage(const char* path); void RemoveSinglePage(const plFileName& path);
//--------------------------- //---------------------------
// Load and Unload // Load and Unload

9
Sources/Plasma/PubUtilLib/plSDL/plSDL.h

@ -510,10 +510,11 @@ class plSDLParser
{ {
private: private:
bool IReadDescriptors() const; bool IReadDescriptors() const;
bool ILoadSDLFile(const char* fileName) const; bool ILoadSDLFile(const plFileName& fileName) const;
bool IParseVarDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc, bool IParseVarDesc(const plFileName& fileName, hsStream* stream, char token[],
plVarDescriptor*& curVar) const; plStateDescriptor*& curDesc, plVarDescriptor*& curVar) const;
bool IParseStateDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc) const; bool IParseStateDesc(const plFileName& fileName, hsStream* stream, char token[],
plStateDescriptor*& curDesc) const;
void DebugMsg(const char* fmt, ...) const; void DebugMsg(const char* fmt, ...) const;
void DebugMsgV(const char* fmt, va_list args) const; void DebugMsgV(const char* fmt, va_list args) const;

9
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 "HeadSpin.h"
#include "plString.h" #include "plFileSystem.h"
#include <string>
// //
// Describes a variable in a state descriptor. // Describes a variable in a state descriptor.
@ -226,7 +225,7 @@ private:
VarsList fVarsList; VarsList fVarsList;
int fVersion; int fVersion;
plString fName; plString fName;
std::string fFilename; // the filename this descriptor was read from plFileName fFilename; // the filename this descriptor was read from
void IDeInit(); void IDeInit();
public: public:
@ -238,13 +237,13 @@ public:
int GetNumVars() const { return fVarsList.size(); } int GetNumVars() const { return fVarsList.size(); }
plVarDescriptor* GetVar(int i) const { return fVarsList[i]; } plVarDescriptor* GetVar(int i) const { return fVarsList[i]; }
int GetVersion() const { return fVersion; } int GetVersion() const { return fVersion; }
const char * GetFilename() const { return fFilename.c_str();} plFileName GetFilename() const { return fFilename; }
// setters // setters
void SetVersion(int v) { fVersion=v; } void SetVersion(int v) { fVersion=v; }
void SetName(const plString& n) { fName=n; } void SetName(const plString& n) { fName=n; }
void AddVar(plVarDescriptor* v) { fVarsList.push_back(v); } 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; plVarDescriptor* FindVar(const plString& name, int* idx=nil) const;

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

@ -77,7 +77,8 @@ void plSDLParser::DebugMsgV(const char* fmt, va_list args) const
// read name, version // read name, version
// return true to skip the next token read // 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; plSDL::DescriptorList* descList = &plSDLMgr::GetInstance()->fDescriptors;
@ -108,7 +109,8 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t
if (!strcmp(token, "VERSION")) if (!strcmp(token, "VERSION"))
{ {
// read desc 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)) if (stream->GetToken(token, kTokenLen))
{ {
int v=atoi(token); int v=atoi(token);
@ -119,13 +121,14 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t
else else
{ {
hsAssert(false, plString::Format("Error parsing state desc, missing VERSION, fileName=%s", hsAssert(false, plString::Format("Error parsing state desc, missing VERSION, fileName=%s",
fileName).c_str()); fileName.AsString().c_str()).c_str());
ok = false; ok = false;
} }
} }
else 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; ok = false;
} }
@ -135,7 +138,7 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t
if ( !ok ) if ( !ok )
{ {
plString err = plString::Format("Found duplicate SDL descriptor for %s version %d.\nFailed to parse file: %s", plString err = plString::Format("Found duplicate SDL descriptor for %s version %d.\nFailed to parse file: %s",
curDesc->GetName().c_str(), curDesc->GetVersion(), fileName ); curDesc->GetName().c_str(), curDesc->GetVersion(), fileName.AsString().c_str());
plNetApp::StaticErrorMsg( err.c_str() ); plNetApp::StaticErrorMsg( err.c_str() );
hsAssert( false, 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] // read type, name, count [default]
// return true to skip the next token read // return true to skip the next token read
// //
bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc, bool plSDLParser::IParseVarDesc(const plFileName& fileName, hsStream* stream, char token[],
plVarDescriptor*& curVar) const 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 ) if ( !curDesc )
return false; return false;
@ -181,7 +185,7 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
char* sdlName = token+1; char* sdlName = token+1;
plStateDescriptor* stateDesc = plSDLMgr::GetInstance()->FindDescriptor(sdlName, plSDL::kLatestVersion); plStateDescriptor* stateDesc = plSDLMgr::GetInstance()->FindDescriptor(sdlName, plSDL::kLatestVersion);
hsAssert(stateDesc, plString::Format("can't find nested state desc reference %s, fileName=%s", 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); curVar = new plSDVarDescriptor(stateDesc);
} }
else else
@ -189,7 +193,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
curDesc->AddVar(curVar); curDesc->AddVar(curVar);
bool ok=curVar->SetType(token); 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); 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)) if (stream->GetToken(token, kTokenLen))
{ {
hsAssert(strstr(token, "[") && strstr(token, "]"), plString::Format("invalid var syntax, missing [x], fileName=%s", 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 [ 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); curVar->SetName(token);
// //
// COUNT // COUNT
@ -221,7 +227,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
{ {
if (!strcmp(token, "DEFAULT")) 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 // read state var type
plString defaultStr; plString defaultStr;
@ -248,7 +255,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
else else
if (!strcmp(token, "DISPLAYOPTION")) 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; dbgStr += plString(" ") + token;
bool read=stream->GetToken(token, kTokenLen); bool read=stream->GetToken(token, kTokenLen);
@ -265,13 +273,15 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
} }
else 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 else
if (!strcmp(token, "DEFAULTOPTION")) 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; dbgStr += plString(" ") + token;
bool read=stream->GetToken(token, kTokenLen); bool read=stream->GetToken(token, kTokenLen);
@ -283,7 +293,8 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
} }
else 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 else
if (!strcmp(token, "INTERNAL")) 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); curVar->SetInternal(true);
dbgStr += plString(" ") + token; dbgStr += plString(" ") + token;
} }
else else
if (!strcmp(token, "PHASED")) 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); curVar->SetAlwaysNew(true);
dbgStr += plString(" ") + token; dbgStr += plString(" ") + token;
} }
@ -319,13 +332,11 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
// create state descriptor from sdl file. // create state descriptor from sdl file.
// return false on err. // return false on err.
// //
bool plSDLParser::ILoadSDLFile(const char* fileName) const bool plSDLParser::ILoadSDLFile(const plFileName& fileName) const
{ {
DebugMsg("Parsing SDL file %s", fileName); DebugMsg("Parsing SDL file %s", fileName.AsString().c_str());
wchar_t* temp = hsStringToWString(fileName); hsStream* stream = plStreamSource::GetInstance()->GetFile(fileName);
hsStream* stream = plStreamSource::GetInstance()->GetFile(temp);
delete [] temp;
if (!stream) if (!stream)
return false; return false;
@ -393,33 +404,27 @@ bool plSDLParser::ILoadSDLFile(const char* fileName) const
// //
bool plSDLParser::IReadDescriptors() const bool plSDLParser::IReadDescriptors() const
{ {
std::string sdlDir = plSDLMgr::GetInstance()->GetSDLDir(); plFileName sdlDir = plSDLMgr::GetInstance()->GetSDLDir();
DebugMsg("SDL: Reading latest descriptors from directory %s", sdlDir.c_str()); DebugMsg("SDL: Reading latest descriptors from directory %s", sdlDir.AsString().c_str());
wchar_t* temp = hsStringToWString(sdlDir.c_str());
std::wstring wSDLDir = temp;
delete [] temp;
// Get the names of all the sdl files // Get the names of all the sdl files
std::vector<std::wstring> files = plStreamSource::GetInstance()->GetListOfNames(wSDLDir, L".sdl"); std::vector<plFileName> files = plStreamSource::GetInstance()->GetListOfNames(sdlDir, "sdl");
bool ret=true; bool ret=true;
int cnt=0; int cnt=0;
for (int i = 0; i < files.size(); i++) for (int i = 0; i < files.size(); i++)
{ {
char* str = hsWStringToString(files[i].c_str()); if (!ILoadSDLFile(files[i]))
if (!ILoadSDLFile(str))
{ {
plNetApp* netApp = plSDLMgr::GetInstance()->GetNetApp(); plNetApp* netApp = plSDLMgr::GetInstance()->GetNetApp();
if (netApp) if (netApp)
netApp->ErrorMsg("Error loading SDL file %s", str); netApp->ErrorMsg("Error loading SDL file %s", files[i].AsString().c_str());
else else
hsStatusMessageF("Error loading SDL file %s", str); hsStatusMessageF("Error loading SDL file %s", files[i].AsString().c_str());
ret=false; ret=false;
} }
else else
cnt++; cnt++;
delete [] str;
} }
DebugMsg("Done reading SDL files"); DebugMsg("Done reading SDL files");

21
Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp

@ -174,20 +174,13 @@ void plAutoProfileImp::IInit()
void plAutoProfileImp::IShutdown() void plAutoProfileImp::IShutdown()
{ {
// KLUDGE - Copy the load timing log, in case we used it // KLUDGE - Copy the load timing log, in case we used it
#define kTimingLog L"readtimings.0.log" #define kTimingLog "readtimings.0.log"
#define kAgeTimingLog L"agetimings.0.log" #define kAgeTimingLog "agetimings.0.log"
wchar_t destPath[MAX_PATH];
wchar_t sourcePath[MAX_PATH];
PathAddFilename(destPath, plProfileManagerFull::Instance().GetProfilePath(), kTimingLog, arrsize(destPath)); plFileSystem::Copy(plFileName::Join(plFileSystem::GetLogPath(), kTimingLog),
PathGetLogDirectory(sourcePath, arrsize(sourcePath)); plFileName::Join(plProfileManagerFull::Instance().GetProfilePath(), kTimingLog));
PathAddFilename(sourcePath, sourcePath, kTimingLog, arrsize(sourcePath)); plFileSystem::Copy(plFileName::Join(plFileSystem::GetLogPath(), kAgeTimingLog),
plFileUtils::FileCopy(sourcePath, destPath); plFileName::Join(plProfileManagerFull::Instance().GetProfilePath(), kAgeTimingLog));
PathAddFilename(destPath, plProfileManagerFull::Instance().GetProfilePath(), kAgeTimingLog, arrsize(destPath));
PathGetLogDirectory(sourcePath, arrsize(sourcePath));
PathAddFilename(sourcePath, sourcePath, kAgeTimingLog, arrsize(sourcePath));
plFileUtils::FileCopy(sourcePath, destPath);
#ifdef HS_BUILD_FOR_WIN32 #ifdef HS_BUILD_FOR_WIN32
ShellExecute(nil, nil, "PostRun.bat", nil, nil, SW_SHOWNORMAL); ShellExecute(nil, nil, "PostRun.bat", nil, nil, SW_SHOWNORMAL);
@ -219,7 +212,7 @@ void plAutoProfileImp::INextProfile()
if (!fLastSpawnPointName.IsNull()) if (!fLastSpawnPointName.IsNull())
{ {
const char * ageName = NetCommGetAge()->ageDatasetName; const char * ageName = NetCommGetAge()->ageDatasetName;
plProfileManagerFull::Instance().LogStats(ageName, fLastSpawnPointName.c_str()); plProfileManagerFull::Instance().LogStats(ageName, fLastSpawnPointName);
plMipmap mipmap; plMipmap mipmap;
if (plClient::GetInstance()->GetPipeline()->CaptureScreen(&mipmap)) if (plClient::GetInstance()->GetPipeline()->CaptureScreen(&mipmap))

47
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; fLogStats = true;
wchar_t* temp = hsStringToWString(ageName); fLogAgeName = ageName;
fLogAgeName = temp;
delete [] temp;
fLogSpawnName = spawnName; fLogSpawnName = spawnName;
} }
const wchar_t* plProfileManagerFull::GetProfilePath() plFileName plProfileManagerFull::GetProfilePath()
{ {
static wchar_t profilePath[MAX_PATH]; static plFileName profilePath;
static bool initialized = false;
if (!initialized) if (!profilePath.IsValid())
{ {
initialized = true;
plUnifiedTime curTime = plUnifiedTime::GetCurrent(plUnifiedTime::kLocal); plUnifiedTime curTime = plUnifiedTime::GetCurrent(plUnifiedTime::kLocal);
PathGetUserDirectory(profilePath, arrsize(profilePath)); profilePath = plFileName::Join(plFileSystem::GetUserDataPath(), "Profile",
PathAddFilename(profilePath, profilePath, L"Profile", arrsize(profilePath)); plString::Format("%02d-%02d-%04d_%02d-%02d",
plFileUtils::CreateDir(profilePath); curTime.GetMonth(), curTime.GetDay(),
curTime.GetYear(), curTime.GetHour(),
wchar_t buff[256]; curTime.GetMinute()));
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)); plFileSystem::CreateDir(profilePath, true);
plFileUtils::CreateDir(profilePath);
} }
return profilePath; return profilePath;
@ -459,13 +447,12 @@ const wchar_t* plProfileManagerFull::GetProfilePath()
void plProfileManagerFull::ILogStats() void plProfileManagerFull::ILogStats()
{ {
wchar_t statFilename[256]; plFileName statFilename = plFileName::Join(GetProfilePath(), fLogAgeName + ".csv");
hsSnwprintf(statFilename, 256, L"%s%s.csv", GetProfilePath(), fLogAgeName.c_str());
bool exists = plFileUtils::FileExists(statFilename); bool exists = plFileInfo(statFilename).Exists();
hsUNIXStream s; hsUNIXStream s;
if (s.Open(statFilename, L"ab")) if (s.Open(statFilename, "ab"))
{ {
GroupSet groups; GroupSet groups;
GetGroups(groups); GetGroups(groups);
@ -474,7 +461,7 @@ void plProfileManagerFull::ILogStats()
if (!exists) if (!exists)
{ {
const char* kSpawn = "Spawn"; static const char kSpawn[] = "Spawn";
s.Write(strlen(kSpawn), kSpawn); s.Write(strlen(kSpawn), kSpawn);
s.WriteByte(','); s.WriteByte(',');
@ -487,7 +474,7 @@ void plProfileManagerFull::ILogStats()
s.WriteByte('\n'); s.WriteByte('\n');
} }
s.Write(fLogSpawnName.length(), fLogSpawnName.c_str()); s.Write(fLogSpawnName.GetSize(), fLogSpawnName.c_str());
s.WriteByte(','); s.WriteByte(',');
for (it = groups.begin(); it != groups.end(); it++) for (it = groups.begin(); it != groups.end(); it++)
@ -502,7 +489,7 @@ void plProfileManagerFull::ILogStats()
} }
fLogStats = false; fLogStats = false;
fLogAgeName = L""; fLogAgeName = "";
fLogSpawnName = ""; fLogSpawnName = "";
} }

10
Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h

@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <set> #include <set>
#include <string> #include <string>
#include "plString.h" #include "plFileSystem.h"
#include "plProfileManager.h" #include "plProfileManager.h"
@ -63,8 +63,8 @@ protected:
plProfileManager::VarVec& fVars; plProfileManager::VarVec& fVars;
bool fLogStats; // If true, log the stats at the end of the frame bool fLogStats; // If true, log the stats at the end of the frame
std::wstring fLogAgeName; plString fLogAgeName;
std::string fLogSpawnName; plString fLogSpawnName;
std::vector<plGraphPlate*> fGraphs; std::vector<plGraphPlate*> fGraphs;
plGraphPlate* fDetailGraph; plGraphPlate* fDetailGraph;
@ -120,8 +120,8 @@ public:
void ResetMax(); void ResetMax();
void LogStats(const char* ageName, const char* spawnName); void LogStats(const plString& ageName, const plString& spawnName);
const wchar_t* GetProfilePath(); plFileName GetProfilePath();
// If you're going to call LogStats, make sure to call this first so all stats will be evaluated before logging // If you're going to call LogStats, make sure to call this first so all stats will be evaluated before logging
void ActivateAllStats(); void ActivateAllStats();

17
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -87,21 +87,8 @@ plStatusLogMgr::plStatusLogMgr()
fDrawer = nil; fDrawer = nil;
fLastLogChangeTime = 0; fLastLogChangeTime = 0;
#if HS_BUILD_FOR_WIN32 // Ensure the log path is created
SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE); plFileSystem::GetLogPath();
//#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);
} }
plStatusLogMgr::~plStatusLogMgr() plStatusLogMgr::~plStatusLogMgr()

3
Sources/Tools/MaxComponent/plMultistageBehComponent.cpp

@ -490,8 +490,7 @@ public:
MaxStream(ILoad* iload) : fSave(nil), fLoad(iload) {} MaxStream(ILoad* iload) : fSave(nil), fLoad(iload) {}
// Don't support any of this // Don't support any of this
virtual bool Open(const char *, const char * = "rb") { hsAssert(0, "Not supported"); return false; } virtual bool Open(const plFileName &, 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 Close() { 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 Skip(uint32_t deltaByteCount) { hsAssert(0, "Not supported"); }
virtual void Rewind() { hsAssert(0, "Not supported"); } virtual void Rewind() { hsAssert(0, "Not supported"); }

Loading…
Cancel
Save