Browse Source

Merge pull request #268 from zrax/plFilesystem

plFilesystem
Adam Johnson 12 years ago
parent
commit
6944439591
  1. 57
      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. 8
      Sources/Plasma/Apps/plUruLauncher/Main.cpp
  7. 2
      Sources/Plasma/CoreLib/CMakeLists.txt
  8. 3
      Sources/Plasma/CoreLib/hsSTLStream.h
  9. 34
      Sources/Plasma/CoreLib/hsStream.cpp
  10. 36
      Sources/Plasma/CoreLib/hsStream.h
  11. 368
      Sources/Plasma/CoreLib/plFileSystem.cpp
  12. 284
      Sources/Plasma/CoreLib/plFileSystem.h
  13. 88
      Sources/Plasma/CoreLib/plString.cpp
  14. 102
      Sources/Plasma/CoreLib/plString.h
  15. 2
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  16. 8
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  17. 33
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp
  18. 27
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h
  19. 17
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp
  20. 4
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h
  21. 13
      Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp
  22. 13
      Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp
  23. 18
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp
  24. 18
      Sources/Plasma/FeatureLib/pfPython/pyImage.cpp
  25. 8
      Sources/Plasma/FeatureLib/pfPython/pyImage.h
  26. 47
      Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp
  27. 14
      Sources/Plasma/FeatureLib/pfPython/pyStream.cpp
  28. 3
      Sources/Plasma/FeatureLib/pfPython/pyStream.h
  29. 41
      Sources/Plasma/FeatureLib/pfPython/pyStreamGlue.cpp
  30. 70
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp
  31. 13
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h
  32. 12
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp
  33. 13
      Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h
  34. 4
      Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp
  35. 76
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp
  36. 17
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h
  37. 5
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp
  38. 16
      Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp
  39. 7
      Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h
  40. 107
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  41. 22
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h
  42. 2
      Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp
  43. 144
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp
  44. 26
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.h
  45. 131
      Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp
  46. 15
      Sources/Plasma/PubUtilLib/plFile/plStreamSource.h
  47. 24
      Sources/Plasma/PubUtilLib/plGImage/plJPEG.cpp
  48. 7
      Sources/Plasma/PubUtilLib/plGImage/plJPEG.h
  49. 24
      Sources/Plasma/PubUtilLib/plGImage/plPNG.cpp
  50. 6
      Sources/Plasma/PubUtilLib/plGImage/plPNG.h
  51. 18
      Sources/Plasma/PubUtilLib/plPipeline/plDebugText.h
  52. 8
      Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp
  53. 16
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp
  54. 9
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h
  55. 16
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  56. 7
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.h
  57. 9
      Sources/Plasma/PubUtilLib/plSDL/plSDL.h
  58. 9
      Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h
  59. 79
      Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp
  60. 21
      Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp
  61. 47
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp
  62. 10
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h
  63. 244
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  64. 39
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h
  65. 3
      Sources/Tools/MaxComponent/plMultistageBehComponent.cpp
  66. 5
      Sources/Tools/MaxConvert/plMeshConverter.cpp

57
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);
@ -2408,7 +2402,7 @@ void plClient::IWriteDefaultGraphicsSettings(const wchar_t* destFile)
WriteBool(stream, "Graphics.Windowed", plPipeline::fDefaultPipeParams.Windowed); WriteBool(stream, "Graphics.Windowed", plPipeline::fDefaultPipeParams.Windowed);
WriteInt(stream, "Graphics.AntiAliasAmount", plPipeline::fDefaultPipeParams.AntiAliasingAmount); WriteInt(stream, "Graphics.AntiAliasAmount", plPipeline::fDefaultPipeParams.AntiAliasingAmount);
WriteInt(stream, "Graphics.AnisotropicLevel", plPipeline::fDefaultPipeParams.AnisotropicLevel ); WriteInt(stream, "Graphics.AnisotropicLevel", plPipeline::fDefaultPipeParams.AnisotropicLevel );
WriteInt(stream, "Graphics.TextureQuality",plPipeline::fDefaultPipeParams.TextureQuality); WriteInt(stream, "Graphics.TextureQuality", plPipeline::fDefaultPipeParams.TextureQuality);
WriteInt(stream, "Quality.Level", plPipeline::fDefaultPipeParams.VideoQuality); WriteInt(stream, "Quality.Level", plPipeline::fDefaultPipeParams.VideoQuality);
WriteInt(stream, "Graphics.Shadow.Enable", plPipeline::fDefaultPipeParams.Shadows); WriteInt(stream, "Graphics.Shadow.Enable", plPipeline::fDefaultPipeParams.Shadows);
WriteInt(stream, "Graphics.EnablePlanarReflections", plPipeline::fDefaultPipeParams.PlanarReflections); WriteInt(stream, "Graphics.EnablePlanarReflections", plPipeline::fDefaultPipeParams.PlanarReflections);
@ -2487,25 +2481,24 @@ void plClient::IOnAsyncInitComplete () {
/// Now parse final init files (*.fni). These are files just like ini files, only to be run /// 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
if (fpAuxInitDir) if (fpAuxInitDir)
{ {
dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni" ); // connect to net first dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni"); // connect to net first
dirSrc.ParseDirectory(fpAuxInitDir, "*.fni" ); dirSrc.ParseDirectory(fpAuxInitDir, "*.fni");
} }
fNumLoadingRooms--; fNumLoadingRooms--;

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");

8
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);

2
Sources/Plasma/CoreLib/CMakeLists.txt

@ -41,6 +41,7 @@ set(CoreLib_SOURCES
hsThread.cpp hsThread.cpp
hsWide.cpp hsWide.cpp
pcSmallRect.cpp pcSmallRect.cpp
plFileSystem.cpp
plGeneric.cpp plGeneric.cpp
plLoadMask.cpp plLoadMask.cpp
plProduct.cpp plProduct.cpp
@ -85,6 +86,7 @@ set(CoreLib_HEADERS
hsWide.h hsWide.h
hsWindows.h hsWindows.h
pcSmallRect.h pcSmallRect.h
plFileSystem.h
plGeneric.h plGeneric.h
plLoadMask.h plLoadMask.h
plProduct.h plProduct.h

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");

36
Sources/Plasma/CoreLib/hsStream.h

@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsMemory.h" #include "hsMemory.h"
#include "plString.h" #include "plFileSystem.h"
// Define this for use of Streams with Logging (commonly used w/ a packet sniffer) // Define this for use of Streams with Logging (commonly used w/ a packet sniffer)
@ -83,11 +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.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;
@ -299,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();
@ -334,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();
@ -357,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; }
@ -378,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
@ -403,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);
@ -423,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);
@ -444,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);
@ -479,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();

368
Sources/Plasma/CoreLib/plFileSystem.cpp

@ -0,0 +1,368 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "plFileSystem.h"
#if HS_BUILD_FOR_WIN32
# include "hsWindows.h"
# include <shlobj.h>
#else
# include <limits.h>
# include <unistd.h>
# include <sys/types.h>
# include <cstdlib>
# include <functional>
# include <memory>
#endif
#include <sys/stat.h>
#include "plProduct.h"
/* NOTE For this file: Windows uses UTF-16 filenames, and does not support
* the use of UTF-8 in their ANSI API. In order to ensure proper unicode
* support, we convert the UTF-8 format stored in plString to UTF-16 before
* passing them along to Windows.
*/
plString plFileName::GetFileName() const
{
int end = fName.FindLast('/');
if (end < 0)
end = fName.FindLast('\\');
if (end < 0)
return fName;
return fName.Substr(end + 1);
}
plString plFileName::GetFileExt() const
{
int dot = fName.FindLast('.');
// Be sure not to get a dot in the directory!
int end = fName.FindLast('/');
if (end < 0)
end = fName.FindLast('\\');
if (dot > end)
return fName.Substr(dot + 1);
return plString::Null;
}
plString plFileName::GetFileNameNoExt() const
{
int dot = fName.FindLast('.');
int end = fName.FindLast('/');
if (end < 0)
end = fName.FindLast('\\');
// Be sure not to get a dot in the directory!
if (dot > end)
return fName.Substr(end + 1, dot - end - 1);
return fName.Substr(end + 1);
}
plFileName plFileName::StripFileName() const
{
int end = fName.FindLast('/');
if (end < 0)
end = fName.FindLast('\\');
if (end < 0)
return "";
return fName.Left(end);
}
plFileName plFileName::StripFileExt() const
{
int dot = fName.FindLast('.');
// Be sure not to get a dot in the directory!
int end = fName.FindLast('/');
if (end < 0)
end = fName.FindLast('\\');
if (dot > end)
return fName.Left(dot);
return *this;
}
plFileName plFileName::Normalize(char slash) const
{
plStringBuffer<char> norm;
char *norm_p = norm.CreateWritableBuffer(fName.GetSize());
for (const char *p = fName.c_str(); *p; ++p) {
if (*p == '/' || *p == '\\')
*norm_p++ = slash;
else
*norm_p++ = *p;
}
*norm_p = 0;
return plString(norm);
}
plFileName plFileName::AbsolutePath() const
{
if (!IsValid())
return *this;
plFileName path = Normalize();
#if HS_BUILD_FOR_WIN32
plStringBuffer<wchar_t> wideName = path.fName.ToWchar();
wchar_t path_sm[MAX_PATH];
uint32_t path_length = GetFullPathNameW(wideName, MAX_PATH, path_sm, nullptr);
if (path_length >= MAX_PATH) {
// Buffer not big enough
wchar_t *path_lg = new wchar_t[path_length];
GetFullPathNameW(wideName, path_length, path_lg, nullptr);
path = plString::FromWchar(path_lg);
delete [] path_lg;
} else {
path = plString::FromWchar(path_sm);
}
#else
char *path_a = realpath(path.fName.c_str(), nullptr);
hsAssert(path_a, "Failure to get absolute path (unsupported libc?)");
path = path_a;
free(path_a);
#endif
return path;
}
plFileName plFileName::Join(const plFileName &base, const plFileName &path)
{
if (!base.IsValid())
return path;
if (!path.IsValid())
return base;
char last = base.fName.CharAt(base.GetSize() - 1);
char first = path.fName.CharAt(0);
if (last != '/' && last != '\\') {
if (first != '/' && first != '\\') {
return plString::Format("%s" PATH_SEPARATOR_STR "%s",
base.fName.c_str(), path.fName.c_str());
}
return base.fName + path.fName;
} else if (first != '/' && first != '\\') {
return base.fName + path.fName;
}
// Both have a slash, but we only need one
return base.fName + path.fName.Substr(1);
}
/* plFileInfo */
plFileInfo::plFileInfo(const plFileName &filename)
: fFileSize(-1), fCreateTime(), fModifyTime(), fFlags()
{
if (!filename.IsValid())
return;
#if HS_BUILD_FOR_WIN32
struct __stat64 info;
if (!_wstat64(filename.AsString().ToWchar(), &info) == 0)
return;
#else
struct stat info;
if (!stat(filename.AsString().c_str(), &info) == 0)
return;
#endif
fFlags |= kEntryExists;
fFileSize = info.st_size;
fCreateTime = info.st_ctime;
fModifyTime = info.st_mtime;
if (info.st_mode & S_IFDIR)
fFlags |= kIsDirectory;
if (info.st_mode & S_IFREG)
fFlags |= kIsNormalFile;
}
/* plFileSystem */
plFileName plFileSystem::GetCWD()
{
plFileName cwd;
#if HS_BUILD_FOR_WIN32
wchar_t cwd_sm[MAX_PATH];
uint32_t cwd_length = GetCurrentDirectoryW(MAX_PATH, cwd_sm);
if (cwd_length >= MAX_PATH) {
// Buffer not big enough
wchar_t *cwd_lg = new wchar_t[cwd_length];
GetCurrentDirectoryW(cwd_length, cwd_lg);
cwd = plString::FromWchar(cwd_lg);
delete [] cwd_lg;
} else {
cwd = plString::FromWchar(cwd_sm);
}
#else
char *cwd_a = getcwd(nullptr, 0);
hsAssert(cwd_a, "Failure to get working directory (unsupported libc?)");
cwd = cwd_a;
free(cwd_a);
#endif
return cwd;
}
FILE *plFileSystem::Open(const plFileName &filename, const char *mode)
{
#if HS_BUILD_FOR_WIN32
wchar_t wmode[8];
size_t mlen = strlen(mode);
hsAssert(mlen < arrsize(wmode), "Mode string too long");
// Quick and dirty, because mode should only ever be ANSI chars
for (size_t i = 0; i < mlen; ++i) {
hsAssert(!(mode[i] & 0x80), "I SAID mode should ONLY ever be ANSI chars!");
wmode[i] = static_cast<wchar_t>(mode[i]);
}
wmode[mlen] = 0;
return _wfopen(filename.AsString().ToWchar(), wmode);
#else
return fopen(filename.AsString().c_str(), mode);
#endif
}
bool plFileSystem::Unlink(const plFileName &filename)
{
#if HS_BUILD_FOR_WIN32
return _wunlink(filename.AsString().ToWchar()) == 0;
#else
return unlink(filename.AsString().c_str()) == 0;
#endif
}
bool plFileSystem::Move(const plFileName &from, const plFileName &to)
{
#if HS_BUILD_FOR_WIN32
return MoveFileW(from.AsString().ToWchar(), to.AsString().ToWchar());
#else
if (!Copy(from, to))
return false;
return Unlink(from);
#endif
}
bool plFileSystem::Copy(const plFileName &from, const plFileName &to)
{
#if HS_BUILD_FOR_WIN32
return CopyFileW(from.AsString().ToWchar(), to.AsString().ToWchar(), FALSE);
#else
typedef std::unique_ptr<FILE, std::function<int (FILE *)>> _FileRef;
_FileRef ffrom(Open(from, "rb"), fclose);
_FileRef fto(Open(to, "wb"), fclose);
if (!ffrom.get() || !fto.get())
return false;
size_t count;
uint8_t buffer[4096];
while (!feof(ffrom.get())) {
count = fread(buffer, sizeof(uint8_t), arrsize(buffer), ffrom.get());
if (ferror(ffrom.get()))
return false;
fwrite(buffer, sizeof(uint8_t), count, fto.get());
}
return true;
#endif
}
bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents)
{
if (checkParents) {
plFileName parent = dir.StripFileName();
if (parent.IsValid() && !plFileInfo(parent).Exists() && !CreateDir(parent, true))
return false;
}
if (plFileInfo(dir).Exists())
return true;
#if HS_BUILD_FOR_WIN32
return CreateDirectoryW(dir.AsString().ToWchar(), nullptr);
#else
return (mkdir(dir.AsString().c_str(), 0755) == 0);
#endif
}
plFileName plFileSystem::GetUserDataPath()
{
static plFileName _userData;
if (!_userData.IsValid()) {
#if HS_BUILD_FOR_WIN32
wchar_t path[MAX_PATH];
if (!SHGetSpecialFolderPathW(NULL, path, CSIDL_LOCAL_APPDATA, TRUE))
return "";
_userData = plFileName::Join(plString::FromWchar(path), plProduct::LongName());
#else
_userData = plFileName::Join(getenv("HOME"), "." + plProduct::LongName());
#endif
plFileSystem::CreateDir(_userData);
}
return _userData;
}
plFileName plFileSystem::GetInitPath()
{
static plFileName _initPath = plFileName::Join(GetUserDataPath(), "Init");
plFileSystem::CreateDir(_initPath);
return _initPath;
}
plFileName plFileSystem::GetLogPath()
{
static plFileName _logPath = plFileName::Join(GetUserDataPath(), "Log");
plFileSystem::CreateDir(_logPath);
return _logPath;
}

284
Sources/Plasma/CoreLib/plFileSystem.h

@ -0,0 +1,284 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plFileSystem_Defined
#define plFileSystem_Defined
#include "plString.h"
#include <cstdio>
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
#else
# define PATH_SEPARATOR '/'
# define PATH_SEPARATOR_STR "/"
#endif
/** Represents a filename or path, including utilities for manipulating,
* splitting, and joining path components.
* \sa plFileInfo
*/
class plFileName
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : fName(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString &copy) : fName(copy) { }
/** Copy constructor. */
plFileName(const plFileName &copy) : fName(copy.fName) { }
/** Assignment operator. Same as plFileName(const char *). */
plFileName &operator=(const char *cstr)
{
fName.operator=(cstr);
return *this;
}
/** Assignment operator. Same as plFileName(const plString &). */
plFileName &operator=(const plString &copy)
{
fName.operator=(copy);
return *this;
}
/** Assignment operator. Same as plFileName(const plFileName &). */
plFileName &operator=(const plFileName &copy)
{
fName.operator=(copy.fName);
return *this;
}
/** Comparison operator. */
bool operator==(const char *other) const { return fName.operator==(other); }
/** Comparison operator. */
bool operator==(const plFileName &other) const { return fName.operator==(other.fName); }
/** Inverse of operator==(const char *other) const. */
bool operator!=(const char *other) const { return fName.operator!=(other); }
/** Inverse of operator==(const plFileName &other) const. */
bool operator!=(const plFileName &other) const { return fName.operator!=(other.fName); }
/** Operator overload for use in containers which depend on \c std::less. */
bool operator<(const plFileName &other) const { return fName.Compare(other.fName) < 0; }
/** Functor which compares two filenames case-insensitively for sorting. */
struct less_i
{
bool operator()(const plFileName &_L, const plFileName &_R) const
{ return _L.fName.Compare(_R.fName, plString::kCaseInsensitive) < 0; }
};
/** Return whether this filename is valid (not empty). */
bool IsValid() const { return !fName.IsEmpty(); }
/** Return the length of the filename string (UTF-8). */
size_t GetSize() const { return fName.GetSize(); }
/** Convert the filename to a string. This does not resolve relative
* paths or normalize slashes, it just returns the stored name string.
*/
const plString &AsString() const { return fName; }
/** Return the name portion of the path (including extension).
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename.ext"</pre>
*/
plString GetFileName() const;
/** Return the file extension from the filename.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "ext"</pre>
*/
plString GetFileExt() const;
/** Return the name portion of the path, excluding its extension.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename"</pre>
*/
plString GetFileNameNoExt() const;
/** Return the path with the filename portion stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path"</pre>
*/
plFileName StripFileName() const;
/** Return the filename with the extension stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path\\Filename"</pre>
*/
plFileName StripFileExt() const;
/** Normalize slashes to a particular format. By default, we use the
* OS's native slash format.
* For example:
* <pre>plFileName("C:\\Path/Filename.ext").Normalize('\\') => "C:\\Path\\Filename.ext"</pre>
*/
plFileName Normalize(char slash = PATH_SEPARATOR) const;
/** Expand relative filenames and ./.. pieces to an absolute path. */
plFileName AbsolutePath() const;
/** Join two path components together with the correct path separator.
* For example:
* <pre>plFileName::Join("C:\\Path", "Filename.ext") => "C:\\Path\\Filename.ext"</pre>
*/
static plFileName Join(const plFileName &base, const plFileName &path);
/** Join three path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2)
{ return Join(Join(base, path), path2); }
/** Join four path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
private:
plString fName;
};
/** Structure to get information about a file by name.
* \sa plFileName
*/
class plFileInfo
{
public:
/** Construct an invalid plFileInfo which points to no file. */
plFileInfo()
: fFileSize(-1), fCreateTime(), fModifyTime(), fFlags() { }
/** Construct a plFileInfo and fill it with info about the specified
* file, if it exists.
*/
explicit plFileInfo(const plFileName &filename);
/** Retrieve the filename associated with this info structure. */
const plFileName &FileName() const { return fName; }
/** Return whether the plFileInfo has been initialized. */
bool IsValid() const { return fName.IsValid(); }
/** Determine whether the file exists on the filesystem. */
bool Exists() const { return (fFlags & kEntryExists); }
/** Returns the size of the file on the disk, in bytes. */
int64_t FileSize() const { return fFileSize; }
/** Returns the creation time of the file. */
uint64_t CreateTime() const { return fCreateTime; }
/** Returns the last modification time of the file. */
uint64_t ModifyTime() const { return fModifyTime; }
/** Returns \p true if this file is a directory. */
bool IsDirectory() const { return (fFlags & kIsDirectory); }
/** Returns \p true if this file is a regular file. */
bool IsFile() const { return (fFlags & kIsNormalFile); }
private:
plFileName fName;
int64_t fFileSize;
uint64_t fCreateTime, fModifyTime;
enum {
kEntryExists = (1<<0),
kIsDirectory = (1<<1),
kIsNormalFile = (1<<2),
};
uint32_t fFlags;
};
namespace plFileSystem
{
/** Get the current working directory of the application. */
plFileName GetCWD();
/** Open a file using the correct platform fopen API. */
FILE *Open(const plFileName &filename, const char *mode);
/** Delete a file from the filesystem. */
bool Unlink(const plFileName &filename);
/** Move or rename a file. */
bool Move(const plFileName &from, const plFileName &to);
/** Copy a file to a new location. */
bool Copy(const plFileName &from, const plFileName &to);
/** Create a directory. If \a checkParents is \p true, this will also
* check the whole path and create any parent directories as needed.
*/
bool CreateDir(const plFileName &dir, bool checkParents = false);
/** Get the User's data directory. If it doesn't exist, this will
* create it.
*/
plFileName GetUserDataPath();
/** Get the Init script direcotory. If it doesn't exist, this will
* create it. */
plFileName GetInitPath();
/** Get the Log output directory. If it doesn't exist, this will
* create it. */
plFileName GetLogPath();
}
#endif // plFileSystem_Defined

88
Sources/Plasma/CoreLib/plString.cpp

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

102
Sources/Plasma/CoreLib/plString.h

@ -223,7 +223,7 @@ public:
* \note This constructor expects the input to be UTF-8 encoded. For * \note This constructor expects the input to be UTF-8 encoded. For
* conversion from ISO-8859-1 8-bit data, use FromIso8859_1(). * conversion from ISO-8859-1 8-bit data, use FromIso8859_1().
*/ */
plString(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); } plString(const char *cstr, size_t size = kSizeAuto) { IConvertFromUtf8(cstr, size); }
/** Copy constructor. */ /** Copy constructor. */
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { } plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { }
@ -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)
{ {
@ -539,13 +547,6 @@ public:
static plString Fill(size_t count, char c); static plString Fill(size_t count, char c);
public: public:
/** Functor which compares two strings case-sensitively for sorting. */
struct less
{
bool operator()(const plString &_L, const plString &_R) const
{ return _L.Compare(_R, kCaseSensitive) < 0; }
};
/** Functor which compares two strings case-insensitively for sorting. */ /** Functor which compares two strings case-insensitively for sorting. */
struct less_i struct less_i
{ {
@ -553,13 +554,6 @@ public:
{ return _L.Compare(_R, kCaseInsensitive) < 0; } { return _L.Compare(_R, kCaseInsensitive) < 0; }
}; };
/** Functor which compares two strings case-sensitively for equality. */
struct equal
{
bool operator()(const plString &_L, const plString &_R) const
{ return _L.Compare(_R, kCaseSensitive) == 0; }
};
/** Functor which compares two strings case-insensitively for equality. */ /** Functor which compares two strings case-insensitively for equality. */
struct equal_i struct equal_i
{ {
@ -660,82 +654,4 @@ private:
/** \p strlen implementation for UniChar based C-style string buffers. */ /** \p strlen implementation for UniChar based C-style string buffers. */
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto); size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
#else
# define PATH_SEPARATOR '/'
# define PATH_SEPARATOR_STR "/"
#endif
/** Subclass of plString with specific methods to help deal with common
* filename manipulation tasks.
*/
class plFileName : public plString
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : plString(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString &copy) : plString(copy) { }
/** Copy constructor. */
plFileName(const plFileName &copy) : plString(copy) { }
/** Return the name portion of the path (including extension).
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename.ext"</pre>
*/
plString GetFileName() const;
/** Return the file extension from the filename.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "ext"</pre>
*/
plString GetFileExt() const;
/** Return the name portion of the path, excluding its extension.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename"</pre>
*/
plString GetFileNameNoExt() const;
/** Return the path with the filename portion stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path"</pre>
*/
plFileName StripFileName() const;
/** Return the filename with the extension stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path\\Filename"</pre>
*/
plFileName StripFileExt() const;
/** Join two path components together with the correct path separator.
* For example:
* <pre>plFileName::Join("C:\\Path", "Filename.ext") => "C:\\Path\\Filename.ext"</pre>
*/
static plFileName Join(const plFileName &base, const plFileName &path);
/** Join three path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2)
{ return Join(Join(base, path), path2); }
/** Join four path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
};
#endif //plString_Defined #endif //plString_Defined

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

8
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -462,7 +462,7 @@ PF_CONSOLE_BASE_CMD( PrevStatusLog, "", "Cycles backwards through the status log
PF_CONSOLE_BASE_CMD( ShowStatusLog, "string logName", "Advances the status log display to the given log" ) PF_CONSOLE_BASE_CMD( ShowStatusLog, "string logName", "Advances the status log display to the given log" )
{ {
plStatusLogMgr::GetInstance().SetCurrStatusLog( params[ 0 ] ); plStatusLogMgr::GetInstance().SetCurrStatusLog(static_cast<const char *>(params[0]));
} }
#endif // LIMIT_CONSOLE_COMMANDS #endif // LIMIT_CONSOLE_COMMANDS
@ -481,7 +481,7 @@ PF_CONSOLE_BASE_CMD( EnableLogging, "", "Turns on logging" )
PF_CONSOLE_BASE_CMD( DumpLogs, "string folderName", "Dumps all current logs to the folder specified, relative to the log folder" ) PF_CONSOLE_BASE_CMD( DumpLogs, "string folderName", "Dumps all current logs to the folder specified, relative to the log folder" )
{ {
plStatusLogMgr::GetInstance().DumpLogs( params[ 0 ] ); plStatusLogMgr::GetInstance().DumpLogs(static_cast<const char *>(params[0]));
} }
@ -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;

33
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,12 +124,12 @@ 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)
{ {
int i; int i;
for(i=0; i<fProcessedFiles.size(); i++) for (i=0; i<fProcessedFiles.size(); i++)
{ {
if (file == fProcessedFiles[i]->fFile && path == fProcessedFiles[i]->fPath) if (file == fProcessedFiles[i]->fFile && path == fProcessedFiles[i]->fPath)
return true; return true;
@ -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();
} }

18
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

@ -49,13 +49,17 @@ plString PyString_AsStringEx(PyObject* obj)
{ {
if (PyString_Check(obj)) if (PyString_Check(obj))
return plString::FromUtf8(PyString_AsString(obj)); return plString::FromUtf8(PyString_AsString(obj));
else if (PyUnicode_Check(obj))
{ if (PyUnicode_Check(obj)) {
PyObject* utf8 = PyUnicode_AsUTF8String(obj); #if (Py_UNICODE_SIZE == 2)
plString str = plString::FromUtf8(PyString_AsString(utf8)); return plString::FromUtf16(reinterpret_cast<const uint16_t *>(PyUnicode_AsUnicode(obj)));
Py_DECREF(utf8); #elif (Py_UNICODE_SIZE == 4)
return str; return plString::FromUtf32(reinterpret_cast<const UniChar *>(PyUnicode_AsUnicode(obj)));
} else #else
# error "Py_UNICODE is an unexpected size"
#endif
}
return plString::Null; return plString::Null;
} }

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

@ -178,24 +178,24 @@ 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)
{ {
quality = 75; quality = 75;
} }
plJPEG::Instance().SetWriteQuality( quality ); plJPEG::Instance().SetWriteQuality(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()) if (!plFileInfo(file).Exists())
{
free((void*)fDownloadEntries.front());
fDownloadEntries.pop();
}
while (fManifestEntries.size())
{
free((void*)fManifestEntries.front());
fManifestEntries.pop();
}
}
hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
{
if (!plFileUtils::FileExists(file))
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, "rb");
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);
}; };

18
Sources/Plasma/PubUtilLib/plPipeline/plDebugText.h

@ -97,11 +97,17 @@ class plDebugText
static plDebugText &Instance( void ) { return fInstance; } static plDebugText &Instance( void ) { return fInstance; }
uint32_t CalcStringWidth( const char *string ); uint32_t CalcStringWidth(const char *string);
uint32_t CalcStringWidth_TEMP(const plString &string) { return CalcStringWidth(string.c_str()); }
void DrawString(uint16_t x, uint16_t y, const char *string, uint32_t hexColor, uint8_t style = 0);
void DrawString( uint16_t x, uint16_t y, const char *string, uint32_t hexColor, uint8_t style = 0 ); void DrawString_TEMP(uint16_t x, uint16_t y, const plString &string, uint32_t hexColor, uint8_t style = 0)
{
DrawString(x, y, string.c_str(), hexColor, style);
}
void DrawString( uint16_t x, uint16_t y, const char *string, hsColorRGBA &color, uint8_t style = 0 ) void DrawString(uint16_t x, uint16_t y, const plString &string, hsColorRGBA &color, uint8_t style = 0)
{ {
uint32_t hex; uint32_t hex;
uint8_t r, g, b, a; uint8_t r, g, b, a;
@ -113,12 +119,12 @@ class plDebugText
a = (uint8_t)( color.a * 255.0 ); a = (uint8_t)( color.a * 255.0 );
hex = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | ( b ); hex = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | ( b );
DrawString( x, y, string, hex, style ); DrawString_TEMP(x, y, string, hex, style);
} }
void DrawString( uint16_t x, uint16_t y, const char *string, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t a = 255, uint8_t style = 0 ) void DrawString(uint16_t x, uint16_t y, const plString &string, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t a = 255, uint8_t style = 0)
{ {
DrawString( x, y, string, (uint32_t)( ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | ( b ) ), style ); DrawString_TEMP(x, y, string, (uint32_t)( ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | ( b ) ), style);
} }
void SetDrawOnTopMode( bool enable ) { fDrawOnTopMode = enable; } void SetDrawOnTopMode( bool enable ) { fDrawOnTopMode = enable; }

8
Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp

@ -62,7 +62,7 @@ void plStatusLogDrawer::IDrawLogNames(plStatusLog* curLog, plStatusLog* firstLog
plStatusLog* iLog = firstLog; plStatusLog* iLog = firstLog;
while (iLog) while (iLog)
{ {
width = hsMaximum(drawText.CalcStringWidth(iLog->GetFileName()) + 4, width); width = hsMaximum(drawText.CalcStringWidth_TEMP(iLog->GetFileName().AsString()) + 4, width);
iLog = iLog->fNext; iLog = iLog->fNext;
numLogs++; numLogs++;
} }
@ -75,9 +75,9 @@ void plStatusLogDrawer::IDrawLogNames(plStatusLog* curLog, plStatusLog* firstLog
while (iLog) while (iLog)
{ {
if (iLog == curLog) if (iLog == curLog)
drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName(), 0, 255, 0); drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName().AsString(), 0, 255, 0);
else else
drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName()); drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName().AsString());
iLog = iLog->fNext; iLog = iLog->fNext;
yPos += height; yPos += height;
@ -110,7 +110,7 @@ void plStatusLogDrawer::Draw(plStatusLog* curLog, plStatusLog* firstLog)
if( IGetFlags( curLog ) & plStatusLog::kFilledBackground ) if( IGetFlags( curLog ) & plStatusLog::kFilledBackground )
drawText.DrawRect( x, y, x + width, y + height, 0, 0, 0, 127 ); drawText.DrawRect( x, y, x + width, y + height, 0, 0, 0, 127 );
drawText.DrawString( x + 2, y + ( lineHt >> 1 ), IGetFilename( curLog ), 127, 127, 255, 255, plDebugText::kStyleBold ); drawText.DrawString( x + 2, y + ( lineHt >> 1 ), IGetFilename( curLog ).AsString(), 127, 127, 255, 255, plDebugText::kStyleBold );
drawText.DrawRect( x + 2, y + ( lineHt << 1 ) + 1, drawText.DrawRect( x + 2, y + ( lineHt << 1 ) + 1,
x + width - 8, y + ( lineHt << 1 ) + 2, 127, 127, 255, 255 ); x + width - 8, y + ( lineHt << 1 ) + 2, 127, 127, 255, 255 );

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;

79
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;
} }
@ -134,8 +137,8 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t
ok = ( plSDLMgr::GetInstance()->FindDescriptor(curDesc->GetName(), curDesc->GetVersion())==nil ); ok = ( plSDLMgr::GetInstance()->FindDescriptor(curDesc->GetName(), curDesc->GetVersion())==nil );
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();

244
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -76,7 +76,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// plStatusLogMgr Stuff //////////////////////////////////////////////////// //// plStatusLogMgr Stuff ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
wchar_t plStatusLogMgr::fBasePath[ MAX_PATH ] = L""; plFileName plStatusLogMgr::IGetBasePath()
{
static plFileName _basePath = plFileSystem::GetLogPath();
return _basePath;
}
//// Constructor & Destructor //////////////////////////////////////////////// //// Constructor & Destructor ////////////////////////////////////////////////
@ -86,22 +90,6 @@ plStatusLogMgr::plStatusLogMgr()
fCurrDisplay = nil; fCurrDisplay = nil;
fDrawer = nil; fDrawer = nil;
fLastLogChangeTime = 0; fLastLogChangeTime = 0;
#if HS_BUILD_FOR_WIN32
SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE);
//#elif HS_BUILD_FOR_DARWIN
// Do some Mac specific thing here eventually
#else
const char* home = getenv("HOME");
if (!home) home = "";
wchar_t* temp = hsStringToWString(home);
swprintf(fBasePath, MAX_PATH, L"%S/.cache", temp);
delete[] temp;
#endif
plFileUtils::ConcatFileName(fBasePath, plProduct::LongName().ToWchar());
plFileUtils::ConcatFileName(fBasePath, L"Log");
plFileUtils::EnsureFilePathExists(fBasePath);
} }
plStatusLogMgr::~plStatusLogMgr() plStatusLogMgr::~plStatusLogMgr()
@ -124,52 +112,6 @@ plStatusLogMgr &plStatusLogMgr::GetInstance( void )
return theManager; return theManager;
} }
//// IEnsurePathExists ///////////////////////////////////////////////////////
void plStatusLogMgr::IEnsurePathExists( const wchar_t *dirName )
{
// Note: this creates the directory if it doesn't exist, or if it does,
// returns false
plFileUtils::CreateDir( dirName );
}
//// IPathAppend /////////////////////////////////////////////////////////////
void plStatusLogMgr::IPathAppend( wchar_t *base, const wchar_t *extra, unsigned maxLen )
{
if (!base || !extra)
return;
unsigned baseLen = wcslen(base);
unsigned extraLen = wcslen(extra);
bool needsSeparator = false;
if (baseLen >= 1)
needsSeparator = (base[baseLen - 1] != PATH_SEPARATOR);
if (needsSeparator)
{
if ((baseLen + 1 + 1) >= maxLen)
return; // abort, buffer isn't big enough
base[baseLen] = PATH_SEPARATOR;
++baseLen;
base[baseLen] = '\0';
}
// concat the strings, making sure not to overrun the buffer
unsigned curExtraPos = 0;
for (unsigned curBasePos = baseLen; curBasePos < maxLen; ++curBasePos)
{
base[curBasePos] = extra[curExtraPos];
if (extra[curExtraPos] == '\0')
break; // done
++curExtraPos;
}
// ensure we are null-terminated
base[maxLen - 1] = '\0';
}
//// Draw //////////////////////////////////////////////////////////////////// //// Draw ////////////////////////////////////////////////////////////////////
void plStatusLogMgr::Draw( void ) void plStatusLogMgr::Draw( void )
@ -187,24 +129,16 @@ void plStatusLogMgr::Draw( void )
//// CreateStatusLog ///////////////////////////////////////////////////////// //// CreateStatusLog /////////////////////////////////////////////////////////
plStatusLog *plStatusLogMgr::CreateStatusLog( uint8_t numDisplayLines, const char *filename, uint32_t flags ) plStatusLog *plStatusLogMgr::CreateStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags )
{ {
wchar_t* wFilename = hsStringToWString(filename); plFileSystem::CreateDir(IGetBasePath(), true);
plStatusLog* ret = CreateStatusLog(numDisplayLines, wFilename, flags);
delete [] wFilename;
return ret;
}
plStatusLog *plStatusLogMgr::CreateStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint32_t flags )
{
IEnsurePathExists( fBasePath );
plStatusLog *log = new plStatusLog( numDisplayLines, filename, flags ); plStatusLog *log = new plStatusLog( numDisplayLines, filename, flags );
// Put the new log in its alphabetical position // Put the new log in its alphabetical position
plStatusLog** nextLog = &fDisplays; plStatusLog** nextLog = &fDisplays;
while (*nextLog) while (*nextLog)
{ {
if (wcsicmp(filename, (*nextLog)->GetFileNameW()) <= 0) if (filename.AsString().CompareI((*nextLog)->GetFileName().AsString()) <= 0)
break; break;
nextLog = &(*nextLog)->fNext; nextLog = &(*nextLog)->fNext;
} }
@ -229,14 +163,7 @@ void plStatusLogMgr::ToggleStatusLog( plStatusLog *logToDisplay )
//// SetCurrStatusLog //////////////////////////////////////////////////////// //// SetCurrStatusLog ////////////////////////////////////////////////////////
void plStatusLogMgr::SetCurrStatusLog(const char* logName) void plStatusLogMgr::SetCurrStatusLog(const plFileName& logName)
{
wchar_t* wLogName = hsStringToWString(logName);
SetCurrStatusLog(wLogName);
delete [] wLogName;
}
void plStatusLogMgr::SetCurrStatusLog(const wchar_t* logName)
{ {
plStatusLog* log = FindLog(logName, false); plStatusLog* log = FindLog(logName, false);
if (log != nil) if (log != nil)
@ -277,21 +204,13 @@ void plStatusLogMgr::PrevStatusLog( void )
//// FindLog //////////////////////////////////////////////////////////////// //// FindLog ////////////////////////////////////////////////////////////////
plStatusLog *plStatusLogMgr::FindLog( const char *filename, bool createIfNotFound ) plStatusLog *plStatusLogMgr::FindLog( const plFileName &filename, bool createIfNotFound )
{
wchar_t* wFilename = hsStringToWString(filename);
plStatusLog* ret = FindLog(wFilename, createIfNotFound);
delete [] wFilename;
return ret;
}
plStatusLog *plStatusLogMgr::FindLog( const wchar_t *filename, bool createIfNotFound )
{ {
plStatusLog *log = fDisplays; plStatusLog *log = fDisplays;
while( log != nil ) while( log != nil )
{ {
if( wcsicmp( log->GetFileNameW(), filename ) == 0 ) if (log->GetFileName().AsString().CompareI(filename.AsString()) == 0)
return log; return log;
log = log->fNext; log = log->fNext;
@ -307,21 +226,6 @@ plStatusLog *plStatusLogMgr::FindLog( const wchar_t *filename, bool createIfNotF
return log; return log;
} }
//// SetBasePath ////////////////////////////////////////////////////////////////
void plStatusLogMgr::SetBasePath( const char * path )
{
wchar_t* wPath = hsStringToWString(path);
SetBasePath(wPath);
delete [] wPath;
}
void plStatusLogMgr::SetBasePath( const wchar_t * path )
{
wcscpy( fBasePath, path );
}
//// BounceLogs /////////////////////////////////////////////////////////////// //// BounceLogs ///////////////////////////////////////////////////////////////
void plStatusLogMgr::BounceLogs() void plStatusLogMgr::BounceLogs()
@ -338,34 +242,21 @@ void plStatusLogMgr::BounceLogs()
//// DumpLogs //////////////////////////////////////////////////////////////// //// DumpLogs ////////////////////////////////////////////////////////////////
bool plStatusLogMgr::DumpLogs( const char *newFolderName ) bool plStatusLogMgr::DumpLogs( const plFileName &newFolderName )
{
wchar_t* wFolderName = hsStringToWString(newFolderName);
bool ret = DumpLogs(wFolderName);
delete [] wFolderName;
return ret;
}
bool plStatusLogMgr::DumpLogs( const wchar_t *newFolderName )
{ {
bool retVal = true; // assume success bool retVal = true; // assume success
// create root path and make sure it exists plFileName newPath;
wchar_t temp[MAX_PATH]; plFileName basePath = IGetBasePath();
std::wstring newPath = L""; if (basePath.IsValid())
if (fBasePath) newPath = plFileName::Join(basePath, newFolderName);
{
wcsncpy(temp, fBasePath, MAX_PATH);
IPathAppend(temp, newFolderName, MAX_PATH);
newPath = temp;
}
else else
newPath = newFolderName; newPath = newFolderName;
IEnsurePathExists(newPath.c_str()); plFileSystem::CreateDir(newPath, true);
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
hsWFolderIterator folderIterator; hsWFolderIterator folderIterator;
if (fBasePath) if (basePath.IsValid())
folderIterator.SetPath(fBasePath); folderIterator.SetPath(basePath.AsString().ToWchar());
else else
folderIterator.SetPath(L"."); folderIterator.SetPath(L".");
@ -374,24 +265,15 @@ bool plStatusLogMgr::DumpLogs( const wchar_t *newFolderName )
if (folderIterator.IsDirectory()) if (folderIterator.IsDirectory())
continue; continue;
std::wstring baseFilename = folderIterator.GetFileName(); plFileName baseFilename = plString::FromWchar(folderIterator.GetFileName());
std::wstring source; plFileName source;
if (fBasePath) if (basePath.IsValid())
{ source = plFileName::Join(basePath, baseFilename);
wcsncpy(temp, fBasePath, MAX_PATH);
IPathAppend(temp, baseFilename.c_str(), MAX_PATH);
source = temp;
}
else else
source = baseFilename; source = baseFilename;
std::wstring destination; plFileName destination = plFileName::Join(newPath, baseFilename);
wcsncpy(temp, newPath.c_str(), MAX_PATH); retVal = (plFileSystem::Copy(source, destination) != 0);
IPathAppend(temp, baseFilename.c_str(), MAX_PATH);
destination = temp;
bool succeeded = (CopyFileW(source.c_str(), destination.c_str(), FALSE) != 0);
retVal = retVal && succeeded;
} }
#endif #endif
return retVal; return retVal;
@ -403,7 +285,7 @@ bool plStatusLogMgr::DumpLogs( const wchar_t *newFolderName )
uint32_t plStatusLog::fLoggingOff = false; uint32_t plStatusLog::fLoggingOff = false;
plStatusLog::plStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint32_t flags ) plStatusLog::plStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags )
{ {
fFileHandle = nil; fFileHandle = nil;
fSema = nil; fSema = nil;
@ -411,19 +293,14 @@ plStatusLog::plStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint
fForceLog = false; fForceLog = false;
fMaxNumLines = numDisplayLines; fMaxNumLines = numDisplayLines;
if( filename != nil ) if (filename.IsValid())
{ {
fFilename = filename; fFilename = filename;
char* temp = hsWStringToString(filename); fSema = new hsSemaphore(1, fFilename.AsString().c_str());
fCFilename = temp;
delete [] temp;
fSema = new hsSemaphore(1, fCFilename.c_str());
} }
else else
{ {
fFilename = L""; fFilename = "";
fCFilename = "";
flags |= kDontWriteFile; flags |= kDontWriteFile;
fSema = new hsSemaphore(1); fSema = new hsSemaphore(1);
@ -469,31 +346,29 @@ bool plStatusLog::IReOpen( void )
// Open the file, clearing it, if necessary // Open the file, clearing it, if necessary
if(!(fFlags & kDontWriteFile)) if(!(fFlags & kDontWriteFile))
{ {
wchar_t file[ MAX_PATH ]; plFileName fileNoExt;
wchar_t fileNoExt[MAX_PATH]; plString ext;
wchar_t* ext=nil; IParseFileName(fileNoExt, ext);
IParseFileName(file, MAX_PATH, fileNoExt, &ext); plFileName fileToOpen = plString::Format("%s.0.%s", fileNoExt.AsString().c_str(), ext.c_str());
wchar_t fileToOpen[MAX_PATH];
hsSnwprintf(fileToOpen, MAX_PATH, L"%s.0%s", fileNoExt, ext);
if (!(fFlags & kDontRotateLogs)) if (!(fFlags & kDontRotateLogs))
{ {
wchar_t work[MAX_PATH], work2[MAX_PATH]; plFileName work, work2;
hsSnwprintf(work, MAX_PATH, L"%s.3%s",fileNoExt,ext); work = plString::Format("%s.3.%s", fileNoExt.AsString().c_str(), ext.c_str());
plFileUtils::RemoveFile(work); plFileSystem::Unlink(work);
hsSnwprintf(work2, MAX_PATH, L"%s.2%s",fileNoExt,ext); work2 = plString::Format("%s.2.%s", fileNoExt.AsString().c_str(), ext.c_str());
plFileUtils::FileMove(work2, work); plFileSystem::Move(work2, work);
hsSnwprintf(work, MAX_PATH, L"%s.1%s",fileNoExt,ext); work = plString::Format("%s.1.%s", fileNoExt.AsString().c_str(), ext.c_str());
plFileUtils::FileMove(work, work2); plFileSystem::Move(work, work2);
plFileUtils::FileMove(fileToOpen, work); plFileSystem::Move(fileToOpen, work);
} }
if (fFlags & kAppendToLast) if (fFlags & kAppendToLast)
{ {
fFileHandle = hsWFopen( fileToOpen, L"at" ); fFileHandle = plFileSystem::Open(fileToOpen, "at");
} }
else else
{ {
fFileHandle = hsWFopen( fileToOpen, L"wt" ); fFileHandle = plFileSystem::Open(fileToOpen, "wt");
// if we need to reopen lets just append // if we need to reopen lets just append
fFlags |= kAppendToLast; fFlags |= kAppendToLast;
} }
@ -533,31 +408,20 @@ void plStatusLog::IFini( void )
delete [] fColors; delete [] fColors;
} }
void plStatusLog::IParseFileName(wchar_t* file, size_t fnsize, wchar_t* fileNoExt, wchar_t** ext) const void plStatusLog::IParseFileName(plFileName& fileNoExt, plString& ext) const
{ {
const wchar_t *base = plStatusLogMgr::IGetBasePath(); plFileName base = plStatusLogMgr::IGetBasePath();
if( wcslen( base ) != nil ) plFileName file;
hsSnwprintf( file, fnsize, L"%s%S%s", base, PATH_SEPARATOR_STR, fFilename.c_str() ); if (base.IsValid())
file = plFileName::Join(base, fFilename);
else else
wcscpy( file, fFilename.c_str() ); file = fFilename;
plFileUtils::EnsureFilePathExists( file ); plFileSystem::CreateDir(file.StripFileName(), true);
// apache-style file backup // apache-style file backup
fileNoExt = file.StripFileExt();
*ext = wcsrchr(file, L'.'); ext = file.GetFileExt();
if (*ext)
{
int fileLen = *ext - file;
wcsncpy(fileNoExt, file, fileLen);
fileNoExt[fileLen] = L'\0';
}
else
{
wcscpy(fileNoExt, file);
*ext = L'\0';
}
} }
//// IUnlink ///////////////////////////////////////////////////////////////// //// IUnlink /////////////////////////////////////////////////////////////////
@ -716,7 +580,7 @@ bool plStatusLog::AddLineF( uint32_t color, const char *format, ... )
//// AddLine Static Variations /////////////////////////////////////////////// //// AddLine Static Variations ///////////////////////////////////////////////
bool plStatusLog::AddLineS( const char *filename, const char *format, ... ) bool plStatusLog::AddLineS( const plFileName &filename, const char *format, ... )
{ {
plStatusLog *log = plStatusLogMgr::GetInstance().FindLog( filename ); plStatusLog *log = plStatusLogMgr::GetInstance().FindLog( filename );
if (!log) if (!log)
@ -731,7 +595,7 @@ bool plStatusLog::AddLineS( const char *filename, const char *format, ... )
return log->AddLineV( format, arguments ); return log->AddLineV( format, arguments );
} }
bool plStatusLog::AddLineS( const char *filename, uint32_t color, const char *format, ... ) bool plStatusLog::AddLineS( const plFileName &filename, uint32_t color, const char *format, ... )
{ {
plStatusLog *log = plStatusLogMgr::GetInstance().FindLog( filename ); plStatusLog *log = plStatusLogMgr::GetInstance().FindLog( filename );
if (!log) if (!log)

39
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

@ -58,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsThread.h" #include "hsThread.h"
#include "plFileSystem.h"
#include <string> #include <string>
@ -83,8 +84,7 @@ class plStatusLog
uint32_t fOrigFlags; uint32_t fOrigFlags;
uint32_t fMaxNumLines; uint32_t fMaxNumLines;
std::string fCFilename; // used ONLY by GetFileName() plFileName fFilename;
std::wstring fFilename;
char** fLines; char** fLines;
uint32_t* fColors; uint32_t* fColors;
hsSemaphore* fSema; hsSemaphore* fSema;
@ -101,13 +101,13 @@ class plStatusLog
bool IAddLine( const char *line, int32_t count, uint32_t color ); bool IAddLine( const char *line, int32_t count, uint32_t color );
bool IPrintLineToFile( const char *line, uint32_t count ); bool IPrintLineToFile( const char *line, uint32_t count );
void IParseFileName(wchar_t* file, size_t fnsize, wchar_t* fileNoExt, wchar_t** ext) const; void IParseFileName(plFileName &fileNoExt, plString &ext) const;
void IInit( void ); void IInit( void );
void IFini( void ); void IFini( void );
bool IReOpen( void ); bool IReOpen( void );
plStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint32_t flags ); plStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags );
public: public:
@ -170,16 +170,15 @@ class plStatusLog
/// Static functions that you give a filename to and it searches for a log based on that /// Static functions that you give a filename to and it searches for a log based on that
/// (or creates one if it isn't available) /// (or creates one if it isn't available)
static bool AddLineS( const char *filename, const char *format, ... ); static bool AddLineS( const plFileName &filename, const char *format, ... );
static bool AddLineS( const char *filename, uint32_t color, const char *format, ... ); static bool AddLineS( const plFileName &filename, uint32_t color, const char *format, ... );
void Clear( void ); void Clear( void );
// Clear and open a new file. // Clear and open a new file.
void Bounce( uint32_t flags=0 ); void Bounce( uint32_t flags=0 );
const char* GetFileName() const {return fCFilename.c_str();} const plFileName &GetFileName() const { return fFilename; }
const wchar_t* GetFileNameW() const {return fFilename.c_str();}
void SetForceLog(bool force) { fForceLog = force; } void SetForceLog(bool force) { fForceLog = force; }
}; };
@ -205,12 +204,7 @@ class plStatusLogMgr
double fLastLogChangeTime; double fLastLogChangeTime;
static wchar_t fBasePath[]; static plFileName IGetBasePath();
static const wchar_t *IGetBasePath( void ) { return fBasePath; }
void IEnsurePathExists( const wchar_t *dirName );
void IPathAppend( wchar_t *base, const wchar_t *extra, unsigned maxLen );
hsMutex fMutex; // To make multithreaded-safe hsMutex fMutex; // To make multithreaded-safe
@ -227,25 +221,19 @@ class plStatusLogMgr
void Draw( void ); void Draw( void );
plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const char *filename, uint32_t flags = plStatusLog::kFilledBackground ); plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags = plStatusLog::kFilledBackground );
plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint32_t flags = plStatusLog::kFilledBackground );
void ToggleStatusLog( plStatusLog *logToDisplay ); void ToggleStatusLog( plStatusLog *logToDisplay );
void NextStatusLog( void ); void NextStatusLog( void );
void PrevStatusLog( void ); void PrevStatusLog( void );
void SetCurrStatusLog( const char *logName ); void SetCurrStatusLog( const plFileName &logName );
void SetCurrStatusLog( const wchar_t *logName ); plStatusLog *FindLog( const plFileName &filename, bool createIfNotFound = true );
plStatusLog *FindLog( const char *filename, bool createIfNotFound = true );
plStatusLog *FindLog( const wchar_t *filename, bool createIfNotFound = true );
void SetDrawer( plStatusLogDrawerStub *drawer ) { fDrawer = drawer; } void SetDrawer( plStatusLogDrawerStub *drawer ) { fDrawer = drawer; }
void SetBasePath( const char * path );
void SetBasePath( const wchar_t * path );
void BounceLogs(); void BounceLogs();
// Create a new folder and copy all log files into it (returns false on failure) // Create a new folder and copy all log files into it (returns false on failure)
bool DumpLogs( const char *newFolderName ); bool DumpLogs( const plFileName &newFolderName );
bool DumpLogs( const wchar_t *newFolderName );
}; };
//// plStatusLogDrawerStub Class //////////////////////////////////////////// //// plStatusLogDrawerStub Class ////////////////////////////////////////////
@ -261,8 +249,7 @@ class plStatusLogDrawerStub
uint32_t IGetMaxNumLines( plStatusLog *log ) const { return log->fMaxNumLines; } uint32_t IGetMaxNumLines( plStatusLog *log ) const { return log->fMaxNumLines; }
char **IGetLines( plStatusLog *log ) const { return log->fLines; } char **IGetLines( plStatusLog *log ) const { return log->fLines; }
const char *IGetFilename( plStatusLog *log ) const { return log->GetFileName(); } plFileName IGetFilename( plStatusLog *log ) const { return log->GetFileName(); }
const wchar_t *IGetFilenameW( plStatusLog *log ) const { return log->GetFileNameW(); }
uint32_t *IGetColors( plStatusLog *log ) const { return log->fColors; } uint32_t *IGetColors( plStatusLog *log ) const { return log->fColors; }
uint32_t IGetFlags( plStatusLog *log ) const { return log->fFlags; } uint32_t IGetFlags( plStatusLog *log ) const { return log->fFlags; }

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"); }

5
Sources/Tools/MaxConvert/plMeshConverter.cpp

@ -494,12 +494,9 @@ bool plMeshConverter::IValidateUVs(plMaxNode* node)
if (uvsAreBad) if (uvsAreBad)
{ {
TSTR logfile = "UV_"; plFileName logfile = plString::Format("UV_%s.log", GetCOREInterface()->GetCurFileName().data());
logfile += GetCOREInterface()->GetCurFileName();
logfile += ".log";
plStatusLog::AddLineS(logfile, "%s has suspicious UVs", node->GetName()); plStatusLog::AddLineS(logfile, "%s has suspicious UVs", node->GetName());
if (fWarnSuspiciousUVs) if (fWarnSuspiciousUVs)
{ {
/// We're missing some UV channels on our object. We'll handle it later; warn the user here /// We're missing some UV channels on our object. We'll handle it later; warn the user here

Loading…
Cancel
Save