Browse Source

Merge pull request #268 from zrax/plFilesystem

plFilesystem
Adam Johnson 12 years ago
parent
commit
6944439591
  1. 59
      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. 39
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp
  18. 27
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h
  19. 21
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp
  20. 4
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.h
  21. 13
      Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp
  22. 15
      Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp
  23. 20
      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. 15
      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. 86
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp
  36. 21
      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. 30
      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. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  52. 10
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h
  53. 8
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h
  54. 20
      Sources/Plasma/PubUtilLib/plPipeline/plDebugText.h
  55. 8
      Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp
  56. 16
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp
  57. 9
      Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h
  58. 16
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  59. 7
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.h
  60. 9
      Sources/Plasma/PubUtilLib/plSDL/plSDL.h
  61. 13
      Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h
  62. 81
      Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp
  63. 21
      Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp
  64. 49
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp
  65. 12
      Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h
  66. 246
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  67. 41
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h
  68. 7
      Sources/Tools/MaxComponent/plMultistageBehComponent.cpp
  69. 5
      Sources/Tools/MaxConvert/plMeshConverter.cpp

59
Sources/Plasma/Apps/plClient/plClient.cpp

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

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

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

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

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 "pnEncryption/plChecksum.h"
#include "plFileSystem.h"
#include <stdio.h>
int main (int argc, char ** argv) {
int main (int argc, const char ** argv) {
if (argc < 2) {
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 "pnEncryption/plChecksum.h"
#include "plFileSystem.h"
#include <stdio.h>
int main (int argc, char** argv) {
int main (int argc, const char** argv) {
if (argc < 2) {
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);
const wchar_t *serverIni = L"server.ini";
if(cmdParser.IsSpecified(kArgServerIni))
serverIni = cmdParser.GetString(kArgServerIni);
plFileName serverIni = "server.ini";
if (cmdParser.IsSpecified(kArgServerIni))
serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni));
// Load the server.ini so we know what to connect to
FILE *serverini = _wfopen(serverIni, L"rb");
FILE *serverini = plFileSystem::Open(serverIni, "rb");
if (serverini)
{
fclose(serverini);

2
Sources/Plasma/CoreLib/CMakeLists.txt

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

3
Sources/Plasma/CoreLib/hsSTLStream.h

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

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

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 "hsMemory.h"
#include "plString.h"
#include "plFileSystem.h"
// Define this for use of Streams with Logging (commonly used w/ a packet sniffer)
@ -83,11 +83,7 @@ public:
hsStream() : fBytesRead(0), fPosition(0) {}
virtual ~hsStream() { }
// Pre-filename-stringification shortcut:
bool Open_TEMP(const plFileName & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
virtual bool Open(const char *, const char * = "rb")=0;
virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0;
virtual bool Open(const plFileName &, const char * = "rb") = 0;
virtual bool Close()=0;
virtual bool AtEnd();
virtual uint32_t Read(uint32_t byteCount, void * buffer) = 0;
@ -299,8 +295,7 @@ class hsUNIXStream: public hsStream
public:
hsUNIXStream(): fRef(0), fBuff(nil) {}
~hsUNIXStream();
virtual bool Open(const char* name, const char* mode = "rb");
virtual bool Open(const wchar_t *name, const wchar_t *mode = L"rb");
virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Close();
virtual bool AtEnd();
@ -334,8 +329,7 @@ public:
plReadOnlySubStream(): fBase( nil ), fOffset( 0 ), fLength( 0 ) {}
~plReadOnlySubStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; }
virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; }
virtual bool Open(const plFileName &, const char *) { hsAssert(0, "plReadOnlySubStream::Open NotImplemented"); return false; }
void Open( hsStream *base, uint32_t offset, uint32_t length );
virtual bool Close() { fBase = nil; fOffset = 0; fLength = 0; return true; }
virtual bool AtEnd();
@ -357,8 +351,7 @@ public:
hsRAMStream(uint32_t chunkSize);
virtual ~hsRAMStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; }
virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; }
virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; }
virtual bool Close() { hsAssert(0, "hsRAMStream::Close NotImplemented"); return false; }
@ -378,8 +371,7 @@ public:
class hsNullStream : public hsStream {
public:
virtual bool Open(const char *, const char *) { return true; }
virtual bool Open(const wchar_t *, const wchar_t *) { return true; }
virtual bool Open(const plFileName &, const char *) { return true; }
virtual bool Close() { return true; }
virtual uint32_t Read(uint32_t byteCount, void * buffer); // throw's exception
@ -403,8 +395,7 @@ public:
hsReadOnlyStream() {}
virtual void Init(int size, const void* data) { fStart=((char*)data); fData=((char*)data); fStop=((char*)data + size); }
virtual bool Open(const char *, const char *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; }
virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; }
virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsReadOnlyStream::Open NotImplemented"); return false; }
virtual bool Close() { hsAssert(0, "hsReadOnlyStream::Close NotImplemented"); return false; }
virtual bool AtEnd();
virtual uint32_t Read(uint32_t byteCount, void * buffer);
@ -423,8 +414,7 @@ public:
hsWriteOnlyStream(int size, const void* data) : hsReadOnlyStream(size, data) {}
hsWriteOnlyStream() {}
virtual bool Open(const char *, const char *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; }
virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; }
virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsWriteOnlyStream::Open NotImplemented"); return false; }
virtual bool Close() { hsAssert(0, "hsWriteOnlyStream::Close NotImplemented"); return false; }
virtual uint32_t Read(uint32_t byteCount, void * buffer); // throws exception
virtual uint32_t Write(uint32_t byteCount, const void* buffer);
@ -444,8 +434,7 @@ public:
hsQueueStream(int32_t size);
~hsQueueStream();
virtual bool Open(const char *, const char *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; }
virtual bool Open(const wchar_t *, const wchar_t *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; }
virtual bool Open(const plFileName &, const char *) { hsAssert(0, "hsQueueStream::Open NotImplemented"); return false; }
virtual bool Close() { hsAssert(0, "hsQueueStream::Close NotImplemented"); return false; }
virtual uint32_t Read(uint32_t byteCount, void * buffer);
@ -479,16 +468,15 @@ class hsBufferedStream : public hsStream
// For doing statistics on how efficient we are
int fBufferHits, fBufferMisses;
uint32_t fBufferReadIn, fBufferReadOut, fReadDirect, fLastReadPos;
char* fFilename;
plFileName fFilename;
const char* fCloseReason;
#endif
public:
hsBufferedStream();
virtual ~hsBufferedStream();
virtual ~hsBufferedStream() { }
virtual bool Open(const char* name, const char* mode = "rb");
virtual bool Open(const wchar_t* name, const wchar_t* mode = L"rb");
virtual bool Open(const plFileName& name, const char* mode = "rb");
virtual bool Close();
virtual bool AtEnd();

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;
}
/* 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
* 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. */
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { }
@ -284,6 +284,14 @@ public:
return str;
}
/** Create a new plString object from the UTF-32 formatted data in \a utf32. */
static inline plString FromUtf32(const UniChar *utf32, size_t size = kSizeAuto)
{
plString str;
str.IConvertFromUtf32(utf32, size);
return str;
}
/** Create a new plString object from the ISO-8859-1 formatted data in \a astr. */
static inline plString FromIso8859_1(const char *astr, size_t size = kSizeAuto)
{
@ -539,13 +547,6 @@ public:
static plString Fill(size_t count, char c);
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. */
struct less_i
{
@ -553,13 +554,6 @@ public:
{ 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. */
struct equal_i
{
@ -660,82 +654,4 @@ private:
/** \p strlen implementation for UniChar based C-style string buffers. */
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
#else
# define PATH_SEPARATOR '/'
# define PATH_SEPARATOR_STR "/"
#endif
/** Subclass of plString with specific methods to help deal with common
* filename manipulation tasks.
*/
class plFileName : public plString
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : plString(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString &copy) : plString(copy) { }
/** Copy constructor. */
plFileName(const plFileName &copy) : plString(copy) { }
/** Return the name portion of the path (including extension).
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename.ext"</pre>
*/
plString GetFileName() const;
/** Return the file extension from the filename.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "ext"</pre>
*/
plString GetFileExt() const;
/** Return the name portion of the path, excluding its extension.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "Filename"</pre>
*/
plString GetFileNameNoExt() const;
/** Return the path with the filename portion stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path"</pre>
*/
plFileName StripFileName() const;
/** Return the filename with the extension stripped off.
* For example:
* <pre>plFileName("C:\\Path\\Filename.ext") => "C:\\Path\\Filename"</pre>
*/
plFileName StripFileExt() const;
/** Join two path components together with the correct path separator.
* For example:
* <pre>plFileName::Join("C:\\Path", "Filename.ext") => "C:\\Path\\Filename.ext"</pre>
*/
static plFileName Join(const plFileName &base, const plFileName &path);
/** Join three path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2)
{ return Join(Join(base, path), path2); }
/** Join four path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
};
#endif //plString_Defined

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

@ -283,7 +283,7 @@ bool pfConsole::MsgReceive( plMessage *msg )
{
if( cmd->GetCmd() == plConsoleMsg::kExecuteFile )
{
if( !fEngine->ExecuteFile( (char *)cmd->GetString() ) )
if( !fEngine->ExecuteFile( cmd->GetString() ) )
{
// Change the following line once we have a better way of reporting
// errors in the parsing

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

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

@ -57,40 +57,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// ParseDirectory //////////////////////////////////////////////////////////
bool pfConsoleDirSrc::ParseDirectory(const std::string& path, const std::string& mask /* = "*.*" */)
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */)
{
wchar_t* wPath = hsStringToWString(path.c_str());
wchar_t* wMask = hsStringToWString(mask.c_str());
bool ret = ParseDirectory(wPath, wMask);
delete [] wPath;
delete [] wMask;
return ret;
}
bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wstring& mask /* = L"*.*" */)
{
std::wstringstream search;
std::wstring file;
WIN32_FIND_DATAW findInfo;
HANDLE handle;
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
search << path << L"\\" << mask;
handle = FindFirstFileW(search.str().c_str(), &findInfo);
handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo);
if (handle == INVALID_HANDLE_VALUE)
return false;
do
{
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
std::wstringstream fileAndPath;
fileAndPath << path << L"\\" << findInfo.cFileName;
if (AlreadyProcessedFile(path, findInfo.cFileName))
plFileName name = plString::FromWchar(findInfo.cFileName);
plFileName fileAndPath = plFileName::Join(path, name);
if (AlreadyProcessedFile(path, name))
continue;
AddProcessedFile(path, findInfo.cFileName);
if (!fEngine->ExecuteFile(fileAndPath.str().c_str()))
AddProcessedFile(path, name);
if (!fEngine->ExecuteFile(fileAndPath))
{
// Change the following line once we have a better way of reporting
// errors in the parsing
@ -102,7 +89,7 @@ bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wst
caption << L"Error parsing " << findInfo.cFileName;
error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files.";
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
delete [] errorMsg;
delete [] errorLine;
@ -137,12 +124,12 @@ void pfConsoleDirSrc::ResetProcessedFiles()
// note: this n^2 linear search should be replaced with something
// faster if we have lots of init files and turn on the checkProcessing option.
//
bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::wstring& file)
bool pfConsoleDirSrc::AlreadyProcessedFile(const plFileName& path, const plFileName& file)
{
if (fCheckProcessedFiles)
{
int i;
for(i=0; i<fProcessedFiles.size(); i++)
for (i=0; i<fProcessedFiles.size(); i++)
{
if (file == fProcessedFiles[i]->fFile && path == fProcessedFiles[i]->fPath)
return true;
@ -151,7 +138,7 @@ bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::
return false;
}
void pfConsoleDirSrc::AddProcessedFile(const std::wstring& path, const std::wstring& file)
void pfConsoleDirSrc::AddProcessedFile(const plFileName& path, const plFileName& file)
{
fProcessedFiles.push_back(new FileName(path, file));
fProcessedFiles.push_back(new FileName(path, file));
}

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

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

@ -247,18 +247,10 @@ void DummyPrintFn( const char *line )
//// ExecuteFile /////////////////////////////////////////////////////////////
bool pfConsoleEngine::ExecuteFile( const char *fileName )
bool pfConsoleEngine::ExecuteFile(const plFileName &fileName)
{
wchar_t* wFilename = hsStringToWString(fileName);
bool ret = ExecuteFile(wFilename);
delete [] wFilename;
return ret;
}
bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName )
{
char string[ 512 ];
int line;
char string[ 512 ];
int line;
hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileName);
@ -273,13 +265,14 @@ bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName )
return true;
}
for( line = 1; stream->ReadLn( string, sizeof( string ) ); line++ )
for( line = 1; stream->ReadLn( string, arrsize( string ) ); line++ )
{
strncpy( fLastErrorLine, string, sizeof( fLastErrorLine ) );
strncpy( fLastErrorLine, string, arrsize( fLastErrorLine ) );
if( !RunCommand( string, DummyPrintFn ) )
{
sprintf( string, "Error in console file %S, command line %d: %s", fileName, line, fErrorMsg );
snprintf(string, arrsize(string), "Error in console file %s, command line %d: %s",
fileName.AsString().c_str(), line, fErrorMsg);
ISetErrorMsg( string );
stream->Close();
delete stream;

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"
class plFileName;
//// pfConsoleEngine Class Definition ////////////////////////////////////////
@ -94,8 +95,7 @@ class pfConsoleEngine
bool RunCommand( char *line, void (*PrintFn)( const char * ) );
// Executes the given file as a sequence of console commands
bool ExecuteFile( const char *fileName );
bool ExecuteFile( const wchar_t *fileName );
bool ExecuteFile( const plFileName &fileName );
// Get the last reported error
const char *GetErrorMsg( void ) { return fErrorMsg; }

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

15
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 <marshal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include "HeadSpin.h"
@ -125,7 +123,7 @@ bool plPythonPack::Open()
fPackNotFound = true;
// 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)
@ -139,13 +137,11 @@ bool plPythonPack::Open()
fPackStream->Rewind(); // make sure we're at the beginning of the file
fPackNotFound = false;
char* tempFilename = hsWStringToString(files[curName].c_str());
struct stat buf;
time_t curModTime = 0;
if (stat(tempFilename,&buf)==0)
curModTime = buf.st_mtime;
plFileInfo info(files[curName]);
if (info.Exists())
curModTime = info.ModifyTime();
modTimes.push_back(curModTime);
delete [] tempFilename;
// read the index data
int numFiles = fPackStream->ReadLE32();
@ -191,9 +187,8 @@ void plPythonPack::Close()
// do NOT close or delete the streams, the preloader will do that for us
fPackStreams[i] = nil;
}
fPackStreams.clear();
fPackStreams.clear();
fFileOffsets.clear();
}

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

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

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

@ -178,24 +178,24 @@ uint32_t pyImage::GetHeight()
return 0;
}
void pyImage::SaveAsJPEG(const wchar_t* fileName, uint8_t quality)
void pyImage::SaveAsJPEG(const plFileName& fileName, uint8_t quality)
{
if (quality <= 0 || quality > 100)
{
quality = 75;
}
plJPEG::Instance().SetWriteQuality( quality );
plJPEG::Instance().WriteToFile( fileName, this->GetImage() );
plJPEG::Instance().SetWriteQuality(quality);
plJPEG::Instance().WriteToFile(fileName, this->GetImage());
}
void pyImage::SaveAsPNG(const wchar_t* fileName)
void pyImage::SaveAsPNG(const plFileName& fileName)
{
plPNG::Instance().WriteToFile( fileName, this->GetImage() );
plPNG::Instance().WriteToFile(fileName, this->GetImage());
}
PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height)
PyObject* pyImage::LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height)
{
plMipmap* theMipmap = plJPEG::Instance().ReadFromFile(filename);
if (theMipmap)
@ -210,7 +210,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin
}
// let's create a nice name for this thing based on the filename
plString name = plString::Format("PtImageFromDisk_%S", filename);
plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str());
hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);
@ -220,7 +220,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin
PYTHON_RETURN_NONE;
}
PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height)
PyObject* pyImage::LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height)
{
plMipmap* theMipmap = plPNG::Instance().ReadFromFile(filename);
if (theMipmap)
@ -235,7 +235,7 @@ PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint
}
// let's create a nice name for this thing based on the filename
plString name = plString::Format("PtImageFromDisk_%S", filename);
plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str());
hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);

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

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

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

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

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

@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <vector>
class hsStream;
class plFileName;
class pyStream
{
@ -75,7 +76,7 @@ public:
static void AddPlasmaClasses(PyObject *m);
virtual bool Open(const wchar_t* fileName, const wchar_t* flags);
virtual bool Open(const plFileName& fileName, const char* flags);
virtual std::vector<std::string> ReadLines();
virtual bool WriteLines(const std::vector<std::string> & lines);
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
#include "pyStream.h"
#include "plFileSystem.h"
// glue functions
@ -67,23 +68,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR;
}
std::wstring filename;
if (PyUnicode_Check(filenameObj))
plFileName filename;
if (PyString_CheckEx(filenameObj))
{
int strLen = PyUnicode_GetSize(filenameObj);
wchar_t* text = new wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
text[strLen] = L'\0';
filename = text;
delete [] text;
}
else if (PyString_Check(filenameObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(filenameObj);
wchar_t* wText = hsStringToWString(text);
filename = wText;
delete [] wText;
filename = PyString_AsStringEx(filenameObj);
}
else
{
@ -91,23 +79,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR;
}
std::wstring flags;
if (PyUnicode_Check(flagsObj))
{
int strLen = PyUnicode_GetSize(flagsObj);
wchar_t* text = new wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)flagsObj, text, strLen);
text[strLen] = L'\0';
flags = text;
delete [] text;
}
else if (PyString_Check(flagsObj))
plString flags;
if (PyString_CheckEx(flagsObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(flagsObj);
wchar_t* wText = hsStringToWString(text);
flags = wText;
delete [] wText;
flags = PyString_AsStringEx(flagsObj);
}
else
{
@ -115,7 +90,7 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->Open(filename.c_str(), flags.c_str()));
PYTHON_RETURN_BOOL(self->fThis->Open(filename, flags.c_str()));
}
PYTHON_METHOD_DEFINITION_NOARGS(ptStream, readlines)

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

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

15
Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h

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

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

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

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

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

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

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

86
Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp

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

21
Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.h

@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plResPatcher_h_inc
#include "HeadSpin.h"
#include "plFileSystem.h"
#include <queue>
#include <string>
@ -53,16 +54,12 @@ class plResPatcher
enum { kManifest, kFile };
struct Request
{
std::wstring fFile;
std::wstring fFriendlyName;
uint8_t fType;
Request(const wchar_t* file, uint8_t type, const wchar_t* friendly = nil)
: fFile(file), fType(type)
{
if (friendly)
fFriendlyName = std::wstring(friendly);
}
plFileName fFile;
plFileName fFriendlyName;
uint8_t fType;
Request(const plFileName& file, uint8_t type, const plFileName& friendly = "")
: fFile(file), fFriendlyName(friendly), fType(type) { }
};
static plResPatcher* fInstance;
@ -81,8 +78,8 @@ public:
void Finish(bool success = true);
void IssueRequest();
void RequestFile(const wchar_t* file, const wchar_t* friendlyName);
void RequestManifest(const wchar_t* age);
void RequestFile(const plFileName& file, const plFileName& friendlyName);
void RequestManifest(const plString& age);
void Start();
};

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

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

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

@ -61,23 +61,13 @@ plZlibStream::~plZlibStream()
hsAssert(!fOutput && !fZStream, "plZlibStream not closed");
}
bool plZlibStream::Open(const char* filename, const char* mode)
{
wchar_t* wFilename = hsStringToWString(filename);
wchar_t* wMode = hsStringToWString(mode);
bool ret = Open(wFilename, wMode);
delete [] wFilename;
delete [] wMode;
return ret;
}
bool plZlibStream::Open(const wchar_t* filename, const wchar_t* mode)
bool plZlibStream::Open(const plFileName& filename, const char* mode)
{
fFilename = filename;
fMode = mode;
fOutput = new hsUNIXStream;
return fOutput->Open(filename, L"wb");
return fOutput->Open(filename, "wb");
}
bool plZlibStream::Close()
@ -298,7 +288,7 @@ void plZlibStream::Rewind()
{
// hack so rewind will work (someone thought it would be funny to not implement base class functions)
Close();
Open(fFilename.c_str(), fMode.c_str());
Open(fFilename, fMode);
fHeader = kNeedMoreData;
fDecompressedOk = false;
}

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

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

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

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

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

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

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

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

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

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

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

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>
#endif
void ToLower(std::wstring& str)
{
for (unsigned i = 0; i < str.length(); i++)
str[i] = towlower(str[i]);
}
void ReplaceSlashes(std::wstring& path, wchar_t replaceWith)
{
for (unsigned i = 0; i < path.length(); i++)
{
if ((path[i] == L'\\') || (path[i] == L'/'))
path[i] = replaceWith;
}
}
void plStreamSource::ICleanup()
{
// loop through all the file data records, and delete the streams
std::map<std::wstring, fileData>::iterator curData;
decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
{
curData->second.fStream->Close();
@ -80,137 +65,85 @@ void plStreamSource::ICleanup()
fFileData.clear();
}
void plStreamSource::IBreakupFilename(std::wstring filename, std::wstring& dir, std::wstring& ext)
hsStream* plStreamSource::GetFile(const plFileName& filename)
{
// break the filename up into its parts
char* temp = hsWStringToString(filename.c_str());
std::string sFilename = temp;
std::string sExt = plFileUtils::GetFileExt(temp);
plFileUtils::StripFile(temp);
std::string sDir = temp;
delete [] temp;
if (sDir == sFilename) // no directory
sDir = "";
if (sDir != "")
if ((sDir[sDir.length()-1] == '/') || (sDir[sDir.length()-1] == '\\'))
sDir = sDir.substr(0, sDir.length() - 1); // trim the slash, if it has one
wchar_t* wTemp;
wTemp = hsStringToWString(sDir.c_str());
dir = wTemp;
delete [] wTemp;
wTemp = hsStringToWString(sExt.c_str());
ext = wTemp;
delete [] wTemp;
}
hsStream* plStreamSource::GetFile(std::wstring filename)
{
ToLower(filename);
ReplaceSlashes(filename, L'/');
if (fFileData.find(filename) == fFileData.end())
plFileName sFilename = filename.Normalize('/');
if (fFileData.find(sFilename) == fFileData.end())
{
#ifndef PLASMA_EXTERNAL_RELEASE
// internal releases can pull from disk
char* temp = hsWStringToString(filename.c_str());
std::string sFilename = temp;
delete [] temp;
if (plFileUtils::FileExists(sFilename.c_str()))
if (plFileInfo(filename).Exists())
{
// file exists on disk, cache it
std::wstring dir, ext;
IBreakupFilename(filename, dir, ext);
fFileData[filename].fFilename = filename;
fFileData[filename].fDir = dir;
fFileData[filename].fExt = ext;
if (plSecureStream::IsSecureFile(sFilename.c_str()))
fFileData[sFilename].fFilename = sFilename;
fFileData[sFilename].fDir = sFilename.StripFileName();
fFileData[sFilename].fExt = sFilename.GetFileExt();
if (plSecureStream::IsSecureFile(filename))
{
uint32_t encryptionKey[4];
if (!plSecureStream::GetSecureEncryptionKey(sFilename.c_str(), encryptionKey, 4))
if (!plSecureStream::GetSecureEncryptionKey(filename, encryptionKey, 4))
{
FATAL("Hey camper... You need an NTD key file!");
return nil;
}
fFileData[filename].fStream = plSecureStream::OpenSecureFile(sFilename.c_str(), 0, encryptionKey);
fFileData[sFilename].fStream = plSecureStream::OpenSecureFile(filename, 0, encryptionKey);
}
else // otherwise it is an encrypted or plain stream, this call handles both
fFileData[filename].fStream = plEncryptedStream::OpenEncryptedFile(sFilename.c_str());
fFileData[sFilename].fStream = plEncryptedStream::OpenEncryptedFile(filename);
return fFileData[filename].fStream;
return fFileData[sFilename].fStream;
}
#endif // PLASMA_EXTERNAL_RELEASE
return nil;
}
return fFileData[filename].fStream;
return fFileData[sFilename].fStream;
}
std::vector<std::wstring> plStreamSource::GetListOfNames(std::wstring dir, std::wstring ext)
std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, const plString& ext)
{
ToLower(ext);
ToLower(dir);
ReplaceSlashes(dir, L'/');
if (ext[0] == L'.')
ext = ext.substr(1, ext.length()); // trim the dot, if it has one
if (dir != L"")
if ((dir[dir.length()-1] == L'/') || (dir[dir.length()-1] == L'\\'))
dir = dir.substr(0, dir.length() - 1); // trim the slash, if it has one
plFileName sDir = dir.Normalize('/');
hsAssert(ext.CharAt(0) != '.', "Don't add a dot");
// loop through all the file data records, and create the list
std::vector<std::wstring> retVal;
std::map<std::wstring, fileData>::iterator curData;
std::vector<plFileName> retVal;
decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
{
if ((curData->second.fDir == dir.c_str()) && (curData->second.fExt == ext))
if ((curData->second.fDir == sDir) && (curData->second.fExt == ext))
retVal.push_back(curData->second.fFilename);
}
#ifndef PLASMA_EXTERNAL_RELEASE
// in internal releases, we can use on-disk files if they exist
// Build the search string as "dir/*.ext"
std::wstring wSearchStr = dir + L"/*." + ext;
char* temp = hsWStringToString(wSearchStr.c_str());
std::string searchStr = temp;
delete [] temp;
plString searchStr = plFileName::Join(sDir, "*." + ext).AsString();
hsFolderIterator folderIter(searchStr.c_str(), true);
while (folderIter.NextFile())
{
const char* filename = folderIter.GetFileName();
wchar_t* wTemp = hsStringToWString(filename);
std::wstring wFilename = dir + L"/" + wTemp;
delete [] wTemp;
ToLower(wFilename);
if (fFileData.find(wFilename) == fFileData.end()) // we haven't added it yet
retVal.push_back(wFilename);
plFileName filename = plFileName::Join(sDir, folderIter.GetFileName());
if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet
retVal.push_back(filename);
}
#endif // PLASMA_EXTERNAL_RELEASE
return retVal;
}
bool plStreamSource::InsertFile(std::wstring filename, hsStream* stream)
bool plStreamSource::InsertFile(const plFileName& filename, hsStream* stream)
{
ToLower(filename);
ReplaceSlashes(filename, L'/');
plFileName sFilename = filename.Normalize('/');
if (fFileData.find(filename) != fFileData.end())
if (fFileData.find(sFilename) != fFileData.end())
return false; // duplicate entry, return failure
// break the filename up into its parts
std::wstring dir, ext;
IBreakupFilename(filename, dir, ext);
// copy the data over (takes ownership of the stream!)
fFileData[filename].fFilename = filename;
fFileData[filename].fDir = dir;
fFileData[filename].fExt = ext;
fFileData[filename].fStream = stream;
fFileData[sFilename].fFilename = sFilename;
fFileData[sFilename].fDir = sFilename.StripFileName();
fFileData[sFilename].fExt = sFilename.GetFileExt();
fFileData[sFilename].fStream = stream;
return true;
}

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

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

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

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

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 hsStream;
class plFileName;
class plJPEG
{
@ -74,12 +75,10 @@ class plJPEG
public:
plMipmap *ReadFromStream( hsStream *inStream ) { return IRead( inStream ); }
plMipmap *ReadFromFile( const char *fileName );
plMipmap *ReadFromFile( const wchar_t *fileName );
plMipmap *ReadFromFile( const plFileName &fileName );
bool WriteToStream( hsStream *outStream, plMipmap *sourceData ) { return IWrite( sourceData, outStream ); }
bool WriteToFile( const char *fileName, plMipmap *sourceData );
bool WriteToFile( const wchar_t *fileName, plMipmap *sourceData );
bool WriteToFile( const plFileName &fileName, plMipmap *sourceData );
// Range is 0 (worst) to 100 (best)
void SetWriteQuality( uint8_t q ) { fWriteQuality = q; }

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

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

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

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

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -5514,8 +5514,8 @@ void NetCliAuthAccountActivateRequest (
//============================================================================
void NetCliAuthFileListRequest (
const wchar_t dir[],
const wchar_t ext[],
const wchar_t dir[],
const wchar_t ext[],
FNetCliAuthFileListRequestCallback callback,
void * param
) {
@ -5530,7 +5530,7 @@ void NetCliAuthFileListRequest (
//============================================================================
void NetCliAuthFileRequest (
const wchar_t filename[],
const wchar_t filename[],
hsStream * writer,
FNetCliAuthFileRequestCallback callback,
void * param

10
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

@ -348,7 +348,7 @@ void NetCliAuthGetEncryptionKey (
// File List
//============================================================================
struct NetCliAuthFileInfo {
wchar_t filename[MAX_PATH];
wchar_t filename[MAX_PATH];
unsigned filesize;
};
typedef void (*FNetCliAuthFileListRequestCallback)(
@ -358,8 +358,8 @@ typedef void (*FNetCliAuthFileListRequestCallback)(
unsigned infoCount
);
void NetCliAuthFileListRequest (
const wchar_t dir[],
const wchar_t ext[],
const wchar_t dir[],
const wchar_t ext[],
FNetCliAuthFileListRequestCallback callback,
void * param
);
@ -370,11 +370,11 @@ void NetCliAuthFileListRequest (
typedef void (*FNetCliAuthFileRequestCallback)(
ENetError result,
void * param,
const wchar_t filename[],
const wchar_t filename[],
hsStream * writer
);
void NetCliAuthFileRequest (
const wchar_t filename[],
const wchar_t filename[],
hsStream * writer,
FNetCliAuthFileRequestCallback callback,
void * param

8
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h

@ -97,10 +97,10 @@ void NetCliFileRegisterBuildIdUpdate (FNetCliFileBuildIdUpdateCallback callback)
// Manifest
//============================================================================
struct NetCliFileManifestEntry {
wchar_t clientName[MAX_PATH]; // path and file on client side (for comparison)
wchar_t downloadName[MAX_PATH]; // path and file on server side (for download)
wchar_t md5[MAX_PATH];
wchar_t md5compressed[MAX_PATH]; // md5 for the compressed file
wchar_t clientName[MAX_PATH]; // path and file on client side (for comparison)
wchar_t downloadName[MAX_PATH]; // path and file on server side (for download)
wchar_t md5[MAX_PATH];
wchar_t md5compressed[MAX_PATH]; // md5 for the compressed file
unsigned fileSize;
unsigned zipSize;
unsigned flags;

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

@ -97,11 +97,17 @@ class plDebugText
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;
uint8_t r, g, b, a;
@ -113,12 +119,12 @@ class plDebugText
a = (uint8_t)( color.a * 255.0 );
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; }
@ -138,7 +144,7 @@ class plDebugText
void SetManager( plDebugTextManager *m ) { fManager = m; }
void SetFont(const char *face, uint16_t size ) { hsStrncpy( fFontFace, face, sizeof( fFontFace ) ); fFontSize = size; }
const char *GetFontFace( void ) { return fFontFace; }
const char *GetFontFace( void ) { return fFontFace; }
uint16_t GetFontSize( void ) { return fFontSize; }
uint16_t GetFontHeight();

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

@ -62,7 +62,7 @@ void plStatusLogDrawer::IDrawLogNames(plStatusLog* curLog, plStatusLog* firstLog
plStatusLog* iLog = firstLog;
while (iLog)
{
width = hsMaximum(drawText.CalcStringWidth(iLog->GetFileName()) + 4, width);
width = hsMaximum(drawText.CalcStringWidth_TEMP(iLog->GetFileName().AsString()) + 4, width);
iLog = iLog->fNext;
numLogs++;
}
@ -75,9 +75,9 @@ void plStatusLogDrawer::IDrawLogNames(plStatusLog* curLog, plStatusLog* firstLog
while (iLog)
{
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
drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName());
drawText.DrawString(2, (uint16_t)yPos, iLog->GetFileName().AsString());
iLog = iLog->fNext;
yPos += height;
@ -110,7 +110,7 @@ void plStatusLogDrawer::Draw(plStatusLog* curLog, plStatusLog* firstLog)
if( IGetFlags( curLog ) & plStatusLog::kFilledBackground )
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,
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"
plRegistryPageNode::plRegistryPageNode(const plString& path)
plRegistryPageNode::plRegistryPageNode(const plFileName& path)
: fValid(kPageCorrupt)
, fPath(path)
, fDynLoadedTypes(0)
@ -69,9 +69,9 @@ plRegistryPageNode::plRegistryPageNode(const plString& path)
}
}
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath)
plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plString& age,
const plString& page, const plFileName& dataPath)
: fValid(kPageOk)
, fPath(nil)
, fPageInfo(location)
, fDynLoadedTypes(0)
, fStaticLoadedTypes(0)
@ -82,7 +82,8 @@ plRegistryPageNode::plRegistryPageNode(const plLocation& location, const plStrin
// Time to construct our actual file name. For now, we'll use the same old format
// of age_page.extension
fPath = plString::Format("%s" PATH_SEPARATOR_STR "%s_District_%s.prp", dataPath.c_str(), fPageInfo.GetAge().c_str(), fPageInfo.GetPage().c_str());
fPath = plFileName::Join(dataPath, plString::Format("%s_District_%s.prp",
fPageInfo.GetAge().c_str(), fPageInfo.GetPage().c_str()));
}
plRegistryPageNode::~plRegistryPageNode()
@ -129,7 +130,7 @@ hsStream* plRegistryPageNode::OpenStream()
{
if (fOpenRequests == 0)
{
if (!fStream.Open_TEMP(fPath, "rb"))
if (!fStream.Open(fPath, "rb"))
return nil;
}
fOpenRequests++;
@ -220,7 +221,7 @@ void plRegistryPageNode::Write()
{
hsAssert(fOpenRequests == 0, "Trying to write while the page is open for reading");
if (!fStream.Open(fPath.c_str(), "wb"))
if (!fStream.Open(fPath, "wb"))
{
hsAssert(0, "Couldn't open file for writing");
return;
@ -400,6 +401,5 @@ plRegistryKeyList* plRegistryPageNode::IGetKeyList(uint16_t classType) const
void plRegistryPageNode::DeleteSource()
{
hsAssert(fOpenRequests == 0, "Deleting a stream that's open for reading");
plFileUtils::RemoveFile(fPath.c_str());
plFileSystem::Unlink(fPath);
}

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
PageCond fValid; // Condition of the page
plString fPath; // Path to the page file
plFileName fPath; // Path to the page file
plPageInfo fPageInfo; // Info about this page
hsBufferedStream fStream; // Stream for reading/writing our page
@ -93,10 +93,11 @@ protected:
public:
// For reading a page off disk
plRegistryPageNode(const plString& path);
plRegistryPageNode(const plFileName& path);
// For creating a new page.
plRegistryPageNode(const plLocation& location, const plString& age, const plString& page, const plString& dataPath);
plRegistryPageNode(const plLocation& location, const plString& age,
const plString& page, const plFileName& dataPath);
~plRegistryPageNode();
bool IsValid() const { return fValid == kPageOk; }
@ -143,7 +144,7 @@ public:
void Write();
void DeleteSource();
const plString& GetPagePath() const { return fPath; }
const plFileName& GetPagePath() const { return fPath; }
};
#endif // plRegistryNode_h_inc

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

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

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

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

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

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

13
Sources/Plasma/PubUtilLib/plSDL/plSDLDescriptor.h

@ -48,8 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
#include "HeadSpin.h"
#include "plString.h"
#include <string>
#include "plFileSystem.h"
//
// Describes a variable in a state descriptor.
@ -226,7 +225,7 @@ private:
VarsList fVarsList;
int fVersion;
plString fName;
std::string fFilename; // the filename this descriptor was read from
plFileName fFilename; // the filename this descriptor was read from
void IDeInit();
public:
@ -238,14 +237,14 @@ public:
int GetNumVars() const { return fVarsList.size(); }
plVarDescriptor* GetVar(int i) const { return fVarsList[i]; }
int GetVersion() const { return fVersion; }
const char * GetFilename() const { return fFilename.c_str();}
plFileName GetFilename() const { return fFilename; }
// setters
void SetVersion(int v) { fVersion=v; }
void SetName(const plString& n) { fName=n; }
void AddVar(plVarDescriptor* v) { fVarsList.push_back(v); }
void SetFilename( const char * n ) { fFilename=n;}
void SetFilename(const plFileName& n) { fFilename=n;}
plVarDescriptor* FindVar(const plString& name, int* idx=nil) const;
// IO

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

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

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

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

49
Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp

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

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

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

246
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

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

41
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 "hsThread.h"
#include "plFileSystem.h"
#include <string>
@ -83,8 +84,7 @@ class plStatusLog
uint32_t fOrigFlags;
uint32_t fMaxNumLines;
std::string fCFilename; // used ONLY by GetFileName()
std::wstring fFilename;
plFileName fFilename;
char** fLines;
uint32_t* fColors;
hsSemaphore* fSema;
@ -101,13 +101,13 @@ class plStatusLog
bool IAddLine( const char *line, int32_t count, uint32_t color );
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 IFini( 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:
@ -170,16 +170,15 @@ class plStatusLog
/// 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)
static bool AddLineS( const char *filename, const char *format, ... );
static bool AddLineS( const char *filename, uint32_t color, const char *format, ... );
static bool AddLineS( const plFileName &filename, const char *format, ... );
static bool AddLineS( const plFileName &filename, uint32_t color, const char *format, ... );
void Clear( void );
// Clear and open a new file.
void Bounce( uint32_t flags=0 );
const char* GetFileName() const {return fCFilename.c_str();}
const wchar_t* GetFileNameW() const {return fFilename.c_str();}
const plFileName &GetFileName() const { return fFilename; }
void SetForceLog(bool force) { fForceLog = force; }
};
@ -205,12 +204,7 @@ class plStatusLogMgr
double fLastLogChangeTime;
static wchar_t fBasePath[];
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 );
static plFileName IGetBasePath();
hsMutex fMutex; // To make multithreaded-safe
@ -227,25 +221,19 @@ class plStatusLogMgr
void Draw( void );
plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const char *filename, uint32_t flags = plStatusLog::kFilledBackground );
plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const wchar_t *filename, uint32_t flags = plStatusLog::kFilledBackground );
plStatusLog *CreateStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags = plStatusLog::kFilledBackground );
void ToggleStatusLog( plStatusLog *logToDisplay );
void NextStatusLog( void );
void PrevStatusLog( void );
void SetCurrStatusLog( const char *logName );
void SetCurrStatusLog( const wchar_t *logName );
plStatusLog *FindLog( const char *filename, bool createIfNotFound = true );
plStatusLog *FindLog( const wchar_t *filename, bool createIfNotFound = true );
void SetCurrStatusLog( const plFileName &logName );
plStatusLog *FindLog( const plFileName &filename, bool createIfNotFound = true );
void SetDrawer( plStatusLogDrawerStub *drawer ) { fDrawer = drawer; }
void SetBasePath( const char * path );
void SetBasePath( const wchar_t * path );
void BounceLogs();
// Create a new folder and copy all log files into it (returns false on failure)
bool DumpLogs( const char *newFolderName );
bool DumpLogs( const wchar_t *newFolderName );
bool DumpLogs( const plFileName &newFolderName );
};
//// plStatusLogDrawerStub Class ////////////////////////////////////////////
@ -261,9 +249,8 @@ class plStatusLogDrawerStub
uint32_t IGetMaxNumLines( plStatusLog *log ) const { return log->fMaxNumLines; }
char **IGetLines( plStatusLog *log ) const { return log->fLines; }
const char *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; }
plFileName IGetFilename( plStatusLog *log ) const { return log->GetFileName(); }
uint32_t *IGetColors( plStatusLog *log ) const { return log->fColors; }
uint32_t IGetFlags( plStatusLog *log ) const { return log->fFlags; }
public:

7
Sources/Tools/MaxComponent/plMultistageBehComponent.cpp

@ -490,11 +490,10 @@ public:
MaxStream(ILoad* iload) : fSave(nil), fLoad(iload) {}
// Don't support any of this
virtual bool Open(const char *, const char * = "rb") { hsAssert(0, "Not supported"); return false; }
virtual bool Open(const wchar_t *, const wchar_t * = L"rb") { hsAssert(0, "Not supported"); return false; }
virtual bool Open(const plFileName &, const char * = "rb") { hsAssert(0, "Not supported"); return false; }
virtual bool Close() { hsAssert(0, "Not supported"); return false; }
virtual void Skip(uint32_t deltaByteCount) { hsAssert(0, "Not supported"); }
virtual void Rewind() { hsAssert(0, "Not supported"); }
virtual void Skip(uint32_t deltaByteCount) { hsAssert(0, "Not supported"); }
virtual void Rewind() { hsAssert(0, "Not supported"); }
virtual uint32_t GetEOF() { return (uint32_t)fLoad->CurChunkLength(); }

5
Sources/Tools/MaxConvert/plMeshConverter.cpp

@ -494,11 +494,8 @@ bool plMeshConverter::IValidateUVs(plMaxNode* node)
if (uvsAreBad)
{
TSTR logfile = "UV_";
logfile += GetCOREInterface()->GetCurFileName();
logfile += ".log";
plFileName logfile = plString::Format("UV_%s.log", GetCOREInterface()->GetCurFileName().data());
plStatusLog::AddLineS(logfile, "%s has suspicious UVs", node->GetName());
if (fWarnSuspiciousUVs)
{

Loading…
Cancel
Save