1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 02:51:27 +00:00

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

This commit is contained in:
2013-01-17 21:08:21 -08:00
parent 219061c095
commit 6f6ade2636
60 changed files with 509 additions and 982 deletions

View File

@ -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;
}
}

View File

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

View File

@ -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;
plFileName fFile;
plFileName 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);
}
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();
};

View File

@ -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)

View File

@ -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;
}

View File

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

View File

@ -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;
}

View File

@ -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

View File

@ -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();

View File

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

View File

@ -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

View File

@ -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;
}

View File

@ -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();

View File

@ -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)

View File

@ -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; }

View File

@ -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;
}

View File

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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

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

View File

@ -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))

View File

@ -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());
profilePath = plFileName::Join(plFileSystem::GetUserDataPath(), "Profile",
plString::Format("%02d-%02d-%04d_%02d-%02d",
curTime.GetMonth(), curTime.GetDay(),
curTime.GetYear(), curTime.GetHour(),
curTime.GetMinute()));
PathAddFilename(profilePath, profilePath, buff, arrsize(profilePath));
plFileUtils::CreateDir(profilePath);
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 = "";
}

View File

@ -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();

View File

@ -87,21 +87,8 @@ plStatusLogMgr::plStatusLogMgr()
fDrawer = nil;
fLastLogChangeTime = 0;
#if HS_BUILD_FOR_WIN32
SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE);
//#elif HS_BUILD_FOR_DARWIN
// Do some Mac specific thing here eventually
#else
const char* home = getenv("HOME");
if (!home) home = "";
wchar_t* temp = hsStringToWString(home);
swprintf(fBasePath, MAX_PATH, L"%S/.cache", temp);
delete[] temp;
#endif
plFileUtils::ConcatFileName(fBasePath, plProduct::LongName().ToWchar());
plFileUtils::ConcatFileName(fBasePath, L"Log");
plFileUtils::EnsureFilePathExists(fBasePath);
// Ensure the log path is created
plFileSystem::GetLogPath();
}
plStatusLogMgr::~plStatusLogMgr()