mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Convert custom HeadSpin integer types to standard types from stdint.h
This commit is contained in:
@ -127,27 +127,27 @@ public:
|
||||
#ifdef HS_BUILD_FOR_WIN32
|
||||
// only implemented on Win32 for now
|
||||
class hsWFolderIterator {
|
||||
wchar fPath[kFolderIterator_MaxPath];
|
||||
wchar_t fPath[kFolderIterator_MaxPath];
|
||||
struct hsWFolderIterator_Data* fData;
|
||||
bool fCustomFilter;
|
||||
public:
|
||||
hsWFolderIterator(const wchar path[] = nil, bool useCustomFilter=false);
|
||||
hsWFolderIterator(const wchar_t path[] = nil, bool useCustomFilter=false);
|
||||
virtual ~hsWFolderIterator();
|
||||
|
||||
const wchar* GetPath() const { return fPath; }
|
||||
void SetPath(const wchar path[]);
|
||||
const wchar_t* GetPath() const { return fPath; }
|
||||
void SetPath(const wchar_t path[]);
|
||||
|
||||
void Reset();
|
||||
hsBool NextFile();
|
||||
hsBool NextFileSuffix(const wchar suffix[]);
|
||||
const wchar* GetFileName() const;
|
||||
int GetPathAndName(wchar pathandname[] = nil);
|
||||
hsBool NextFileSuffix(const wchar_t suffix[]);
|
||||
const wchar_t* GetFileName() const;
|
||||
int GetPathAndName(wchar_t pathandname[] = nil);
|
||||
hsBool IsDirectory( void ) const;
|
||||
|
||||
FILE* OpenFILE(const wchar mode[]);
|
||||
FILE* OpenFILE(const wchar_t mode[]);
|
||||
|
||||
void SetWinSystemDir(const wchar subdir[]); // e.g. "Fonts"
|
||||
void SetFileFilterStr(const wchar filterStr[]); // e.g. "*.*"
|
||||
void SetWinSystemDir(const wchar_t subdir[]); // e.g. "Fonts"
|
||||
void SetFileFilterStr(const wchar_t filterStr[]); // e.g. "*.*"
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -136,7 +136,7 @@ hsBool hsMacFile::Create(OSType creator, OSType fileType, ScriptCode scriptCode)
|
||||
|
||||
#define kFileNotFound_Err -43
|
||||
|
||||
hsBool hsMacFile::OpenDataFork(SInt8 perm, Int16* refnum)
|
||||
hsBool hsMacFile::OpenDataFork(Sint8_t perm, int16_t* refnum)
|
||||
{
|
||||
this->Close();
|
||||
|
||||
@ -177,7 +177,7 @@ hsStream* hsMacFile::OpenStream(const char mode[], hsBool throwIfFailure)
|
||||
hsThrowIfNilParam(mode);
|
||||
|
||||
short refnum;
|
||||
SInt8 perm = 0;
|
||||
Sint8_t perm = 0;
|
||||
|
||||
if (::strchr(mode, 'r'))
|
||||
perm |= fsRdPerm;
|
||||
@ -212,7 +212,7 @@ struct hsFolderIterator_Data {
|
||||
OSType fFileType;
|
||||
OSType fCreator;
|
||||
char fCName[_MAX_PATH];
|
||||
Int16 fCurrIndex;
|
||||
int16_t fCurrIndex;
|
||||
hsBool fValid;
|
||||
};
|
||||
|
||||
@ -266,7 +266,7 @@ void hsFolderIterator::SetMacFolder(OSType folderType)
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void hsFolderIterator::SetMacFolder(Int16 vRefNum, Int32 dirID)
|
||||
void hsFolderIterator::SetMacFolder(int16_t vRefNum, int32_t dirID)
|
||||
{
|
||||
fData->fSpec.vRefNum = vRefNum;
|
||||
fData->fSpec.parID = dirID;
|
||||
|
@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
struct hsFolderIterator_Data {
|
||||
HANDLE fSearchHandle;
|
||||
WIN32_FIND_DATA fFindData;
|
||||
Boolean fValid;
|
||||
bool fValid;
|
||||
};
|
||||
|
||||
hsFolderIterator::hsFolderIterator(const char path[], bool useCustomFilter)
|
||||
@ -185,10 +185,10 @@ const char* hsFolderIterator::GetFileName() const
|
||||
struct hsWFolderIterator_Data {
|
||||
HANDLE fSearchHandle;
|
||||
WIN32_FIND_DATAW fFindData;
|
||||
Boolean fValid;
|
||||
bool fValid;
|
||||
};
|
||||
|
||||
hsWFolderIterator::hsWFolderIterator(const wchar path[], bool useCustomFilter)
|
||||
hsWFolderIterator::hsWFolderIterator(const wchar_t path[], bool useCustomFilter)
|
||||
{
|
||||
fCustomFilter = useCustomFilter;
|
||||
|
||||
@ -207,7 +207,7 @@ hsWFolderIterator::~hsWFolderIterator()
|
||||
delete fData;
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetPath(const wchar path[])
|
||||
void hsWFolderIterator::SetPath(const wchar_t path[])
|
||||
{
|
||||
fCustomFilter = false;
|
||||
fPath[0] = 0;
|
||||
@ -216,7 +216,7 @@ void hsWFolderIterator::SetPath(const wchar path[])
|
||||
wcscpy(fPath, path);
|
||||
|
||||
// Make sure the dir ends with a slash
|
||||
wchar lastchar = fPath[wcslen(fPath)-1];
|
||||
wchar_t lastchar = fPath[wcslen(fPath)-1];
|
||||
if (lastchar != L'\\' && lastchar != L'/')
|
||||
wcscat(fPath, L"\\");
|
||||
}
|
||||
@ -224,7 +224,7 @@ void hsWFolderIterator::SetPath(const wchar path[])
|
||||
Reset();
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetWinSystemDir(const wchar subdir[])
|
||||
void hsWFolderIterator::SetWinSystemDir(const wchar_t subdir[])
|
||||
{
|
||||
int ret = GetWindowsDirectoryW(fPath, _MAX_PATH);
|
||||
hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath");
|
||||
@ -238,7 +238,7 @@ void hsWFolderIterator::SetWinSystemDir(const wchar subdir[])
|
||||
Reset();
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetFileFilterStr(const wchar filterStr[])
|
||||
void hsWFolderIterator::SetFileFilterStr(const wchar_t filterStr[])
|
||||
{
|
||||
fPath[0] = 0;
|
||||
if (filterStr)
|
||||
@ -309,7 +309,7 @@ hsBool hsWFolderIterator::IsDirectory( void ) const
|
||||
return false;
|
||||
}
|
||||
|
||||
const wchar* hsWFolderIterator::GetFileName() const
|
||||
const wchar_t* hsWFolderIterator::GetFileName() const
|
||||
{
|
||||
if (fData->fValid == false)
|
||||
hsThrow( "end of folder");
|
||||
|
@ -46,18 +46,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include <time.h>
|
||||
|
||||
static const UInt32 kDefaultKey[4] = { 0x6c0a5452, 0x3827d0f, 0x3a170b92, 0x16db7fc2 };
|
||||
static const uint32_t kDefaultKey[4] = { 0x6c0a5452, 0x3827d0f, 0x3a170b92, 0x16db7fc2 };
|
||||
static const int kEncryptChunkSize = 8;
|
||||
|
||||
static const char* kOldMagicString = "BriceIsSmart";
|
||||
static const char* kMagicString = "whatdoyousee";
|
||||
static const int kMagicStringLen = 12;
|
||||
|
||||
static const int kFileStartOffset = kMagicStringLen + sizeof(UInt32);
|
||||
static const int kFileStartOffset = kMagicStringLen + sizeof(uint32_t);
|
||||
|
||||
static const int kMaxBufferedFileSize = 10*1024;
|
||||
|
||||
plEncryptedStream::plEncryptedStream(UInt32* key) :
|
||||
plEncryptedStream::plEncryptedStream(uint32_t* key) :
|
||||
fRef(nil),
|
||||
fActualFileSize(0),
|
||||
fBufferedStream(false),
|
||||
@ -86,9 +86,9 @@ plEncryptedStream::~plEncryptedStream()
|
||||
// but frankly, who cares. No one is going to break the encryption, they'll just get the
|
||||
// key out of the exe or memory.
|
||||
//
|
||||
void plEncryptedStream::IEncipher(UInt32* const v)
|
||||
void plEncryptedStream::IEncipher(uint32_t* const v)
|
||||
{
|
||||
register UInt32 y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32;
|
||||
register uint32_t y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
@ -100,9 +100,9 @@ void plEncryptedStream::IEncipher(UInt32* const v)
|
||||
v[0]=y; v[1]=z;
|
||||
}
|
||||
|
||||
void plEncryptedStream::IDecipher(UInt32* const v)
|
||||
void plEncryptedStream::IDecipher(uint32_t* const v)
|
||||
{
|
||||
register UInt32 y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32;
|
||||
register uint32_t y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32;
|
||||
|
||||
// sum = delta<<5, in general sum = delta * n
|
||||
|
||||
@ -118,15 +118,15 @@ void plEncryptedStream::IDecipher(UInt32* const v)
|
||||
|
||||
hsBool plEncryptedStream::Open(const char* name, const char* mode)
|
||||
{
|
||||
wchar* wName = hsStringToWString(name);
|
||||
wchar* wMode = hsStringToWString(mode);
|
||||
wchar_t* wName = hsStringToWString(name);
|
||||
wchar_t* wMode = hsStringToWString(mode);
|
||||
hsBool ret = Open(wName, wMode);
|
||||
delete [] wName;
|
||||
delete [] wMode;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsBool plEncryptedStream::Open(const wchar* name, const wchar* mode)
|
||||
hsBool plEncryptedStream::Open(const wchar_t* name, const wchar_t* mode)
|
||||
{
|
||||
if (wcscmp(mode, L"rb") == 0)
|
||||
{
|
||||
@ -143,7 +143,7 @@ hsBool plEncryptedStream::Open(const wchar* name, const wchar* mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
fread(&fActualFileSize, sizeof(UInt32), 1, fRef);
|
||||
fread(&fActualFileSize, sizeof(uint32_t), 1, fRef);
|
||||
|
||||
// The encrypted stream is inefficient if you do reads smaller than
|
||||
// 8 bytes. Since we do a lot of those, any file under a size threshold
|
||||
@ -158,7 +158,7 @@ hsBool plEncryptedStream::Open(const wchar* name, const wchar* mode)
|
||||
else if (wcscmp(mode, L"wb") == 0)
|
||||
{
|
||||
fRAMStream = TRACKED_NEW hsVectorStream;
|
||||
fWriteFileName = TRACKED_NEW wchar[wcslen(name) + 1];
|
||||
fWriteFileName = TRACKED_NEW wchar_t[wcslen(name) + 1];
|
||||
wcscpy(fWriteFileName, name);
|
||||
fPosition = 0;
|
||||
|
||||
@ -209,7 +209,7 @@ hsBool plEncryptedStream::Close()
|
||||
return rtn;
|
||||
}
|
||||
|
||||
UInt32 plEncryptedStream::IRead(UInt32 bytes, void* buffer)
|
||||
uint32_t plEncryptedStream::IRead(uint32_t bytes, void* buffer)
|
||||
{
|
||||
if (!fRef)
|
||||
return 0;
|
||||
@ -236,7 +236,7 @@ void plEncryptedStream::IBufferFile()
|
||||
char buf[1024];
|
||||
while (!AtEnd())
|
||||
{
|
||||
UInt32 numRead = Read(1024, buf);
|
||||
uint32_t numRead = Read(1024, buf);
|
||||
fRAMStream->Write(numRead, buf);
|
||||
}
|
||||
fRAMStream->Rewind();
|
||||
@ -255,7 +255,7 @@ hsBool plEncryptedStream::AtEnd()
|
||||
return (GetPosition() == fActualFileSize);
|
||||
}
|
||||
|
||||
void plEncryptedStream::Skip(UInt32 delta)
|
||||
void plEncryptedStream::Skip(uint32_t delta)
|
||||
{
|
||||
if (fBufferedStream)
|
||||
{
|
||||
@ -299,31 +299,31 @@ void plEncryptedStream::FastFwd()
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 plEncryptedStream::GetEOF()
|
||||
uint32_t plEncryptedStream::GetEOF()
|
||||
{
|
||||
return fActualFileSize;
|
||||
}
|
||||
|
||||
UInt32 plEncryptedStream::Read(UInt32 bytes, void* buffer)
|
||||
uint32_t plEncryptedStream::Read(uint32_t bytes, void* buffer)
|
||||
{
|
||||
if (fBufferedStream)
|
||||
{
|
||||
UInt32 numRead = fRAMStream->Read(bytes, buffer);
|
||||
uint32_t numRead = fRAMStream->Read(bytes, buffer);
|
||||
fPosition = fRAMStream->GetPosition();
|
||||
return numRead;
|
||||
}
|
||||
|
||||
UInt32 startPos = fPosition;
|
||||
uint32_t startPos = fPosition;
|
||||
|
||||
// Offset into the first buffer (0 if we are aligned on a chunk, which means no extra block read)
|
||||
UInt32 startChunkPos = startPos % kEncryptChunkSize;
|
||||
uint32_t startChunkPos = startPos % kEncryptChunkSize;
|
||||
// Amount of data in the partial first chunk (0 if we're aligned)
|
||||
UInt32 startAmt = (startChunkPos != 0) ? hsMinimum(kEncryptChunkSize - startChunkPos, bytes) : 0;
|
||||
uint32_t startAmt = (startChunkPos != 0) ? hsMinimum(kEncryptChunkSize - startChunkPos, bytes) : 0;
|
||||
|
||||
UInt32 totalNumRead = IRead(bytes, buffer);
|
||||
uint32_t totalNumRead = IRead(bytes, buffer);
|
||||
|
||||
UInt32 numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
|
||||
UInt32 endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
|
||||
uint32_t numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
|
||||
uint32_t endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
|
||||
|
||||
// If the start position is in the middle of a chunk we need to rewind and
|
||||
// read that whole chunk in and decrypt it.
|
||||
@ -334,8 +334,8 @@ UInt32 plEncryptedStream::Read(UInt32 bytes, void* buffer)
|
||||
|
||||
// Read in the chunk and decrypt it
|
||||
char buf[kEncryptChunkSize];
|
||||
UInt32 numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((UInt32*)&buf);
|
||||
uint32_t numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((uint32_t*)&buf);
|
||||
|
||||
// Copy the relevant portion to the output buffer
|
||||
memcpy(buffer, &buf[startChunkPos], startAmt);
|
||||
@ -345,12 +345,12 @@ UInt32 plEncryptedStream::Read(UInt32 bytes, void* buffer)
|
||||
|
||||
if (numMidChunks != 0)
|
||||
{
|
||||
UInt32* bufferPos = (UInt32*)(((char*)buffer)+startAmt);
|
||||
uint32_t* bufferPos = (uint32_t*)(((char*)buffer)+startAmt);
|
||||
for (int i = 0; i < numMidChunks; i++)
|
||||
{
|
||||
// Decrypt chunk
|
||||
IDecipher(bufferPos);
|
||||
bufferPos += (kEncryptChunkSize / sizeof(UInt32));
|
||||
bufferPos += (kEncryptChunkSize / sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,8 +359,8 @@ UInt32 plEncryptedStream::Read(UInt32 bytes, void* buffer)
|
||||
// Read in the final chunk and decrypt it
|
||||
char buf[kEncryptChunkSize];
|
||||
SetPosition(startPos + startAmt + numMidChunks*kEncryptChunkSize);
|
||||
UInt32 numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((UInt32*)&buf);
|
||||
uint32_t numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((uint32_t*)&buf);
|
||||
|
||||
memcpy(((char*)buffer)+totalNumRead-endAmt, &buf, endAmt);
|
||||
|
||||
@ -377,7 +377,7 @@ UInt32 plEncryptedStream::Read(UInt32 bytes, void* buffer)
|
||||
return totalNumRead;
|
||||
}
|
||||
|
||||
UInt32 plEncryptedStream::Write(UInt32 bytes, const void* buffer)
|
||||
uint32_t plEncryptedStream::Write(uint32_t bytes, const void* buffer)
|
||||
{
|
||||
if (fOpenMode != kOpenWrite)
|
||||
{
|
||||
@ -388,7 +388,7 @@ UInt32 plEncryptedStream::Write(UInt32 bytes, const void* buffer)
|
||||
return fRAMStream->Write(bytes, buffer);
|
||||
}
|
||||
|
||||
bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar* outputFile)
|
||||
bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar_t* outputFile)
|
||||
{
|
||||
hsUNIXStream outputStream;
|
||||
|
||||
@ -402,10 +402,10 @@ bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar* outp
|
||||
|
||||
// Write out all the full size encrypted blocks we can
|
||||
char buf[kEncryptChunkSize];
|
||||
UInt32 amtRead;
|
||||
uint32_t amtRead;
|
||||
while ((amtRead = sourceStream->Read(kEncryptChunkSize, &buf)) == kEncryptChunkSize)
|
||||
{
|
||||
IEncipher((UInt32*)&buf);
|
||||
IEncipher((uint32_t*)&buf);
|
||||
outputStream.Write(kEncryptChunkSize, &buf);
|
||||
}
|
||||
|
||||
@ -422,13 +422,13 @@ bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar* outp
|
||||
for (int i = amtRead; i < kEncryptChunkSize; i++)
|
||||
buf[i] = rand();
|
||||
|
||||
IEncipher((UInt32*)&buf);
|
||||
IEncipher((uint32_t*)&buf);
|
||||
|
||||
outputStream.Write(kEncryptChunkSize, &buf);
|
||||
}
|
||||
|
||||
// Write the original file size at the start
|
||||
UInt32 actualSize = sourceStream->GetPosition();
|
||||
uint32_t actualSize = sourceStream->GetPosition();
|
||||
outputStream.Rewind();
|
||||
outputStream.Skip(kMagicStringLen);
|
||||
outputStream.WriteLE32(actualSize);
|
||||
@ -440,13 +440,13 @@ bool plEncryptedStream::IWriteEncypted(hsStream* sourceStream, const wchar* outp
|
||||
|
||||
bool plEncryptedStream::FileEncrypt(const char* fileName)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = FileEncrypt(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plEncryptedStream::FileEncrypt(const wchar* fileName)
|
||||
bool plEncryptedStream::FileEncrypt(const wchar_t* fileName)
|
||||
{
|
||||
hsUNIXStream sIn;
|
||||
if (!sIn.Open(fileName))
|
||||
@ -477,13 +477,13 @@ bool plEncryptedStream::FileEncrypt(const wchar* fileName)
|
||||
|
||||
bool plEncryptedStream::FileDecrypt(const char* fileName)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = FileDecrypt(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plEncryptedStream::FileDecrypt(const wchar* fileName)
|
||||
bool plEncryptedStream::FileDecrypt(const wchar_t* fileName)
|
||||
{
|
||||
plEncryptedStream sIn;
|
||||
if (!sIn.Open(fileName))
|
||||
@ -500,7 +500,7 @@ bool plEncryptedStream::FileDecrypt(const wchar* fileName)
|
||||
|
||||
while (!sIn.AtEnd())
|
||||
{
|
||||
UInt32 numRead = sIn.Read(sizeof(buf), buf);
|
||||
uint32_t numRead = sIn.Read(sizeof(buf), buf);
|
||||
sOut.Write(numRead, buf);
|
||||
}
|
||||
|
||||
@ -523,13 +523,13 @@ bool plEncryptedStream::ICheckMagicString(FILE* fp)
|
||||
|
||||
bool plEncryptedStream::IsEncryptedFile(const char* fileName)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = IsEncryptedFile(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plEncryptedStream::IsEncryptedFile(const wchar* fileName)
|
||||
bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName)
|
||||
{
|
||||
FILE* fp = hsWFopen(fileName, L"rb");
|
||||
if (!fp)
|
||||
@ -542,15 +542,15 @@ bool plEncryptedStream::IsEncryptedFile(const wchar* fileName)
|
||||
return isEncrypted;
|
||||
}
|
||||
|
||||
hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, bool requireEncrypted, UInt32* cryptKey)
|
||||
hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, bool requireEncrypted, uint32_t* cryptKey)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
hsStream* ret = OpenEncryptedFile(wFilename, requireEncrypted, cryptKey);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsStream* plEncryptedStream::OpenEncryptedFile(const wchar* fileName, bool requireEncrypted, UInt32* cryptKey)
|
||||
hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, bool requireEncrypted, uint32_t* cryptKey)
|
||||
{
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
requireEncrypted = false;
|
||||
@ -571,15 +571,15 @@ hsStream* plEncryptedStream::OpenEncryptedFile(const wchar* fileName, bool requi
|
||||
return s;
|
||||
}
|
||||
|
||||
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const char* fileName, UInt32* cryptKey)
|
||||
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
hsStream* ret = OpenEncryptedFileWrite(wFilename, cryptKey);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar* fileName, UInt32* cryptKey)
|
||||
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey)
|
||||
{
|
||||
hsStream* s = nil;
|
||||
#ifdef PLASMA_EXTERNAL_RELEASE
|
||||
|
@ -53,64 +53,64 @@ class plEncryptedStream : public hsStream
|
||||
{
|
||||
protected:
|
||||
FILE* fRef;
|
||||
UInt32 fKey[4];
|
||||
uint32_t fKey[4];
|
||||
|
||||
UInt32 fActualFileSize;
|
||||
uint32_t fActualFileSize;
|
||||
|
||||
bool fBufferedStream;
|
||||
|
||||
hsStream* fRAMStream;
|
||||
|
||||
wchar* fWriteFileName;
|
||||
wchar_t* fWriteFileName;
|
||||
|
||||
enum OpenMode { kOpenRead, kOpenWrite, kOpenFail };
|
||||
OpenMode fOpenMode;
|
||||
|
||||
void IBufferFile();
|
||||
|
||||
UInt32 IRead(UInt32 bytes, void* buffer);
|
||||
uint32_t IRead(uint32_t bytes, void* buffer);
|
||||
|
||||
void IEncipher(UInt32* const v);
|
||||
void IDecipher(UInt32* const v);
|
||||
void IEncipher(uint32_t* const v);
|
||||
void IDecipher(uint32_t* const v);
|
||||
|
||||
bool IWriteEncypted(hsStream* sourceStream, const wchar* outputFile);
|
||||
bool IWriteEncypted(hsStream* sourceStream, const wchar_t* outputFile);
|
||||
|
||||
static bool ICheckMagicString(FILE* fp);
|
||||
|
||||
public:
|
||||
// If you don't pass in a key (4 UInt32's), the default one will be used
|
||||
plEncryptedStream(UInt32* key=nil);
|
||||
// If you don't pass in a key (4 uint32_t's), the default one will be used
|
||||
plEncryptedStream(uint32_t* key=nil);
|
||||
~plEncryptedStream();
|
||||
|
||||
virtual hsBool Open(const char* name, const char* mode = "rb");
|
||||
virtual hsBool Open(const wchar* name, const wchar* mode = L"rb");
|
||||
virtual hsBool Open(const wchar_t* name, const wchar_t* mode = L"rb");
|
||||
virtual hsBool Close();
|
||||
|
||||
virtual UInt32 Read(UInt32 byteCount, void* buffer);
|
||||
virtual UInt32 Write(UInt32 byteCount, const void* buffer);
|
||||
virtual uint32_t Read(uint32_t byteCount, void* buffer);
|
||||
virtual uint32_t Write(uint32_t byteCount, const void* buffer);
|
||||
virtual hsBool AtEnd();
|
||||
virtual void Skip(UInt32 deltaByteCount);
|
||||
virtual void Skip(uint32_t deltaByteCount);
|
||||
virtual void Rewind();
|
||||
virtual void FastFwd();
|
||||
virtual UInt32 GetEOF();
|
||||
virtual uint32_t GetEOF();
|
||||
|
||||
UInt32 GetActualFileSize() const { return fActualFileSize;}
|
||||
uint32_t GetActualFileSize() const { return fActualFileSize;}
|
||||
|
||||
static bool FileEncrypt(const char* fileName);
|
||||
static bool FileEncrypt(const wchar* fileName);
|
||||
static bool FileEncrypt(const wchar_t* fileName);
|
||||
static bool FileDecrypt(const char* fileName);
|
||||
static bool FileDecrypt(const wchar* fileName);
|
||||
static bool FileDecrypt(const wchar_t* fileName);
|
||||
|
||||
static bool IsEncryptedFile(const char* fileName);
|
||||
static bool IsEncryptedFile(const wchar* fileName);
|
||||
static bool IsEncryptedFile(const wchar_t* 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, bool requireEncrypted = true, UInt32* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFile(const wchar* fileName, bool requireEncrypted = true, UInt32* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFileWrite(const char* fileName, UInt32* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFileWrite(const wchar* fileName, UInt32* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFile(const char* fileName, bool requireEncrypted = true, uint32_t* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFile(const wchar_t* fileName, bool requireEncrypted = true, uint32_t* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey = nil);
|
||||
static hsStream* OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey = nil);
|
||||
};
|
||||
|
||||
#endif // plEncryptedStream_h_inc
|
||||
|
@ -97,7 +97,7 @@ hsBool plFileUtils::CreateDir( const char *path )
|
||||
#endif
|
||||
}
|
||||
|
||||
hsBool plFileUtils::CreateDir( const wchar *path )
|
||||
hsBool plFileUtils::CreateDir( const wchar_t *path )
|
||||
{
|
||||
// Create our directory
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
@ -150,7 +150,7 @@ bool plFileUtils::RemoveFile(const char* filename, bool delReadOnly)
|
||||
return (unlink(filename) == 0);
|
||||
}
|
||||
|
||||
bool plFileUtils::RemoveFile(const wchar* filename, bool delReadOnly)
|
||||
bool plFileUtils::RemoveFile(const wchar_t* filename, bool delReadOnly)
|
||||
{
|
||||
#ifdef HS_BUILD_FOR_WIN32
|
||||
if (delReadOnly)
|
||||
@ -167,15 +167,15 @@ bool plFileUtils::RemoveFile(const wchar* filename, bool delReadOnly)
|
||||
|
||||
bool plFileUtils::FileCopy(const char* existingFile, const char* newFile)
|
||||
{
|
||||
wchar* wExisting = hsStringToWString(existingFile);
|
||||
wchar* wNew = hsStringToWString(newFile);
|
||||
wchar_t* wExisting = hsStringToWString(existingFile);
|
||||
wchar_t* wNew = hsStringToWString(newFile);
|
||||
bool ret = FileCopy(wExisting, wNew);
|
||||
delete [] wExisting;
|
||||
delete [] wNew;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plFileUtils::FileCopy(const wchar* existingFile, const wchar* newFile)
|
||||
bool plFileUtils::FileCopy(const wchar_t* existingFile, const wchar_t* newFile)
|
||||
{
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
return (::CopyFileW(existingFile, newFile, FALSE) != 0);
|
||||
@ -223,7 +223,7 @@ bool plFileUtils::FileMove(const char* existingFile, const char* newFile)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool plFileUtils::FileMove(const wchar* existingFile, const wchar* newFile)
|
||||
bool plFileUtils::FileMove(const wchar_t* existingFile, const wchar_t* newFile)
|
||||
{
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
return (::MoveFileW(existingFile, newFile) != 0);
|
||||
@ -236,7 +236,7 @@ bool plFileUtils::FileMove(const wchar* existingFile, const wchar* newFile)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool plFileUtils::FileExists(const wchar* file)
|
||||
bool plFileUtils::FileExists(const wchar_t* file)
|
||||
{
|
||||
FILE* fp = hsWFopen(file, L"rb");
|
||||
bool retVal = (fp != nil);
|
||||
@ -259,18 +259,18 @@ bool plFileUtils::FileExists(const char* file)
|
||||
|
||||
hsBool plFileUtils::EnsureFilePathExists( const char *filename )
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(filename);
|
||||
wchar_t* wFilename = hsStringToWString(filename);
|
||||
hsBool ret = EnsureFilePathExists(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsBool plFileUtils::EnsureFilePathExists( const wchar *filename )
|
||||
hsBool plFileUtils::EnsureFilePathExists( const wchar_t *filename )
|
||||
{
|
||||
hsWStringTokenizer izer( filename, L"\\/" );
|
||||
|
||||
hsBool lastWorked = false;
|
||||
wchar token[ kFolderIterator_MaxPath ];
|
||||
wchar_t token[ kFolderIterator_MaxPath ];
|
||||
|
||||
|
||||
while( izer.Next( token, arrsize( token ) ) && izer.HasMoreTokens() )
|
||||
@ -378,9 +378,9 @@ const char* plFileUtils::GetFileName(const char* path)
|
||||
return c;
|
||||
}
|
||||
|
||||
const wchar* plFileUtils::GetFileName(const wchar* path)
|
||||
const wchar_t* plFileUtils::GetFileName(const wchar_t* path)
|
||||
{
|
||||
const wchar* c = wcsrchr(path, L'/');
|
||||
const wchar_t* c = wcsrchr(path, L'/');
|
||||
if (c == nil)
|
||||
c = wcsrchr(path, L'\\');
|
||||
|
||||
@ -399,9 +399,9 @@ void plFileUtils::StripFile(char* pathAndName)
|
||||
*fileName = '\0';
|
||||
}
|
||||
|
||||
void plFileUtils::StripFile(wchar* pathAndName)
|
||||
void plFileUtils::StripFile(wchar_t* pathAndName)
|
||||
{
|
||||
wchar* fileName = (wchar*)GetFileName(pathAndName);
|
||||
wchar_t* fileName = (wchar_t*)GetFileName(pathAndName);
|
||||
if (fileName != pathAndName)
|
||||
*fileName = L'\0';
|
||||
}
|
||||
@ -413,9 +413,9 @@ void plFileUtils::StripExt(char* fileName)
|
||||
*(ext-1) = '\0';
|
||||
}
|
||||
|
||||
void plFileUtils::StripExt(wchar* fileName)
|
||||
void plFileUtils::StripExt(wchar_t* fileName)
|
||||
{
|
||||
wchar* ext = (wchar*)GetFileExt(fileName);
|
||||
wchar_t* ext = (wchar_t*)GetFileExt(fileName);
|
||||
if (ext)
|
||||
*(ext-1) = L'\0';
|
||||
}
|
||||
@ -433,12 +433,12 @@ const char* plFileUtils::GetFileExt(const char* pathAndName)
|
||||
return nil;
|
||||
}
|
||||
|
||||
const wchar* plFileUtils::GetFileExt(const wchar* pathAndName)
|
||||
const wchar_t* plFileUtils::GetFileExt(const wchar_t* pathAndName)
|
||||
{
|
||||
const wchar* fileName = GetFileName(pathAndName);
|
||||
const wchar_t* fileName = GetFileName(pathAndName);
|
||||
if (fileName)
|
||||
{
|
||||
const wchar* ext = wcsrchr(fileName, L'.');
|
||||
const wchar_t* ext = wcsrchr(fileName, L'.');
|
||||
if (ext)
|
||||
return ext+1;
|
||||
}
|
||||
@ -457,9 +457,9 @@ void plFileUtils::AddSlash(char* path)
|
||||
#endif
|
||||
}
|
||||
|
||||
void plFileUtils::AddSlash(wchar* path)
|
||||
void plFileUtils::AddSlash(wchar_t* path)
|
||||
{
|
||||
wchar lastChar = path[wcslen(path)-1];
|
||||
wchar_t lastChar = path[wcslen(path)-1];
|
||||
if (lastChar != L'\\' && lastChar != L'/')
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
wcscat(path, L"\\");
|
||||
@ -474,7 +474,7 @@ void plFileUtils::ConcatFileName(char* path, const char* fileName)
|
||||
strcat(path, fileName);
|
||||
}
|
||||
|
||||
void plFileUtils::ConcatFileName(wchar* path, const wchar* fileName)
|
||||
void plFileUtils::ConcatFileName(wchar_t* path, const wchar_t* fileName)
|
||||
{
|
||||
AddSlash(path);
|
||||
wcscat(path, fileName);
|
||||
@ -482,17 +482,17 @@ void plFileUtils::ConcatFileName(wchar* path, const wchar* fileName)
|
||||
|
||||
//// GetFileSize /////////////////////////////////////////////////////////////
|
||||
|
||||
UInt32 plFileUtils::GetFileSize( const char *path )
|
||||
uint32_t plFileUtils::GetFileSize( const char *path )
|
||||
{
|
||||
wchar* wPath = hsStringToWString(path);
|
||||
UInt32 ret = GetFileSize(wPath);
|
||||
wchar_t* wPath = hsStringToWString(path);
|
||||
uint32_t ret = GetFileSize(wPath);
|
||||
delete [] wPath;
|
||||
return ret;
|
||||
}
|
||||
|
||||
UInt32 plFileUtils::GetFileSize( const wchar *path )
|
||||
uint32_t plFileUtils::GetFileSize( const wchar_t *path )
|
||||
{
|
||||
UInt32 len = 0;
|
||||
uint32_t len = 0;
|
||||
|
||||
hsUNIXStream str;
|
||||
if (str.Open(path, L"rb"))
|
||||
@ -506,15 +506,15 @@ UInt32 plFileUtils::GetFileSize( const wchar *path )
|
||||
|
||||
//// GetSecureEncryptionKey //////////////////////////////////////////////////
|
||||
|
||||
bool plFileUtils::GetSecureEncryptionKey(const char* filename, UInt32* key, unsigned length)
|
||||
bool plFileUtils::GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(filename);
|
||||
wchar_t* wFilename = hsStringToWString(filename);
|
||||
bool ret = GetSecureEncryptionKey(wFilename, key, length);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plFileUtils::GetSecureEncryptionKey(const wchar* filename, UInt32* key, unsigned length)
|
||||
bool plFileUtils::GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length)
|
||||
{
|
||||
// looks for an encryption key file in the same directory, and reads it
|
||||
std::wstring sFilename = filename;
|
||||
@ -541,8 +541,8 @@ bool plFileUtils::GetSecureEncryptionKey(const wchar* filename, UInt32* key, uns
|
||||
hsUNIXStream file;
|
||||
file.Open(keyFile.c_str(), L"rb");
|
||||
|
||||
unsigned bytesToRead = length * sizeof(UInt32);
|
||||
byte* buffer = (byte*)ALLOC(bytesToRead);
|
||||
unsigned bytesToRead = length * sizeof(uint32_t);
|
||||
uint8_t* buffer = (uint8_t*)ALLOC(bytesToRead);
|
||||
unsigned bytesRead = file.Read(bytesToRead, buffer);
|
||||
|
||||
file.Close();
|
||||
@ -556,7 +556,7 @@ bool plFileUtils::GetSecureEncryptionKey(const wchar* filename, UInt32* key, uns
|
||||
|
||||
// file doesn't exist, use default key
|
||||
unsigned memSize = min(length, arrsize(plSecureStream::kDefaultKey));
|
||||
memSize *= sizeof(UInt32);
|
||||
memSize *= sizeof(uint32_t);
|
||||
memcpy(key, plSecureStream::kDefaultKey, memSize);
|
||||
|
||||
return false;
|
||||
|
@ -57,29 +57,29 @@ class plUnifiedTime;
|
||||
namespace plFileUtils
|
||||
{
|
||||
static const char kKeyFilename[] = "encryption.key";
|
||||
static const wchar kWKeyFilename[] = L"encryption.key";
|
||||
static const wchar_t kWKeyFilename[] = L"encryption.key";
|
||||
|
||||
// Creates the directory specified. Returns false if unsuccessful or directory already exists
|
||||
hsBool CreateDir( const char *path );
|
||||
hsBool CreateDir( const wchar *path );
|
||||
hsBool CreateDir( const wchar_t *path );
|
||||
hsBool RemoveDir(const char* path);
|
||||
hsBool RemoveDirTree(const char * path);
|
||||
|
||||
// delete file from disk
|
||||
bool RemoveFile(const char* filename, bool delReadOnly=false);
|
||||
bool RemoveFile(const wchar* filename, bool delReadOnly=false);
|
||||
bool RemoveFile(const wchar_t* filename, bool delReadOnly=false);
|
||||
|
||||
bool FileCopy(const char* existingFile, const char* newFile);
|
||||
bool FileCopy(const wchar* existingFile, const wchar* newFile);
|
||||
bool FileCopy(const wchar_t* existingFile, const wchar_t* newFile);
|
||||
bool FileMove(const char* existingFile, const char* newFile);
|
||||
bool FileMove(const wchar* existingFile, const wchar* newFile);
|
||||
bool FileMove(const wchar_t* existingFile, const wchar_t* newFile);
|
||||
|
||||
bool FileExists(const char* file);
|
||||
bool FileExists(const wchar* file);
|
||||
bool FileExists(const wchar_t* file);
|
||||
|
||||
// Given a filename with path, makes sure the file's path exists
|
||||
hsBool EnsureFilePathExists( const char *filename );
|
||||
hsBool EnsureFilePathExists( const wchar *filename );
|
||||
hsBool EnsureFilePathExists( const wchar_t *filename );
|
||||
|
||||
// Gets the creation and modification dates of the file specified. Returns false if unsuccessful
|
||||
hsBool GetFileTimes( const char *path, plUnifiedTime *createTimeOut, plUnifiedTime *modifyTimeOut );
|
||||
@ -91,34 +91,34 @@ namespace plFileUtils
|
||||
|
||||
// Return a pointer into the given string at the start of the actual filename (i.e. past any path info)
|
||||
const char* GetFileName(const char* pathAndName);
|
||||
const wchar* GetFileName(const wchar* pathAndName);
|
||||
const wchar_t* GetFileName(const wchar_t* pathAndName);
|
||||
// Get the file extension (without the .), or nil if it doesn't have one
|
||||
const char* GetFileExt(const char* pathAndName);
|
||||
const wchar* GetFileExt(const wchar* pathAndName);
|
||||
const wchar_t* GetFileExt(const wchar_t* pathAndName);
|
||||
|
||||
// Strips the filename off the given full path
|
||||
void StripFile(char* pathAndName);
|
||||
void StripFile(wchar* pathAndName);
|
||||
void StripFile(wchar_t* pathAndName);
|
||||
void StripExt(char* fileName);
|
||||
void StripExt(wchar* fileName);
|
||||
void StripExt(wchar_t* fileName);
|
||||
|
||||
// Get the size of the given file in bytes
|
||||
UInt32 GetFileSize( const char *path );
|
||||
UInt32 GetFileSize( const wchar *path );
|
||||
uint32_t GetFileSize( const char *path );
|
||||
uint32_t GetFileSize( const wchar_t *path );
|
||||
|
||||
// Adds a slash to the end of a filename (or does nothing if it's already there)
|
||||
void AddSlash(char* path);
|
||||
void AddSlash(wchar* path);
|
||||
void AddSlash(wchar_t* path);
|
||||
|
||||
// Concatenates fileName onto path, making sure to add a slash if necessary
|
||||
void ConcatFileName(char* path, const char* fileName);
|
||||
void ConcatFileName(wchar* path, const wchar* fileName);
|
||||
void ConcatFileName(wchar_t* path, const wchar_t* fileName);
|
||||
|
||||
// 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)
|
||||
bool GetSecureEncryptionKey(const char* filename, UInt32* key, unsigned length);
|
||||
bool GetSecureEncryptionKey(const wchar* filename, UInt32* key, unsigned length);
|
||||
bool GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length);
|
||||
bool GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length);
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ plInitSectionTokenReader::plInitSectionTokenReader( const char *separators ) : f
|
||||
{
|
||||
}
|
||||
|
||||
hsBool plInitSectionTokenReader::ParseLine( const char *line, UInt32 userData )
|
||||
hsBool plInitSectionTokenReader::ParseLine( const char *line, uint32_t userData )
|
||||
{
|
||||
hsStringTokenizer izer( line, fSeparators );
|
||||
|
||||
@ -70,7 +70,7 @@ hsBool plInitSectionTokenReader::ParseLine( const char *line, UInt32 userDa
|
||||
|
||||
void plInitFileReader::IInitReaders( plInitSectionReader **readerArray )
|
||||
{
|
||||
UInt32 i;
|
||||
uint32_t i;
|
||||
|
||||
|
||||
for( i = 0; readerArray[ i ] != nil; i++ )
|
||||
@ -81,7 +81,7 @@ void plInitFileReader::IInitReaders( plInitSectionReader **readerArray )
|
||||
fCurrSection = fSections[ 0 ];
|
||||
}
|
||||
|
||||
plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, UInt16 lineSize )
|
||||
plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, uint16_t lineSize )
|
||||
{
|
||||
fRequireEncrypted = true;
|
||||
fCurrLine = nil;
|
||||
@ -91,7 +91,7 @@ plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, UInt16 li
|
||||
fUnhandledSection = nil;
|
||||
}
|
||||
|
||||
plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **readerArray, UInt16 lineSize )
|
||||
plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **readerArray, uint16_t lineSize )
|
||||
{
|
||||
fRequireEncrypted = true;
|
||||
fCurrLine = nil;
|
||||
@ -103,7 +103,7 @@ plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **
|
||||
fUnhandledSection = nil;
|
||||
}
|
||||
|
||||
plInitFileReader::plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, UInt16 lineSize )
|
||||
plInitFileReader::plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize )
|
||||
{
|
||||
fRequireEncrypted = true;
|
||||
fCurrLine = nil;
|
||||
@ -151,7 +151,7 @@ hsBool plInitFileReader::Open( hsStream *stream )
|
||||
return true;
|
||||
}
|
||||
|
||||
hsBool plInitFileReader::Parse( UInt32 userData )
|
||||
hsBool plInitFileReader::Parse( uint32_t userData )
|
||||
{
|
||||
hsAssert( fStream != nil, "Nil stream in initFileReader::Parse(); file not yet open?" );
|
||||
|
||||
@ -171,7 +171,7 @@ hsBool plInitFileReader::Parse( UInt32 userData )
|
||||
if( end != nil )
|
||||
*end = 0;
|
||||
|
||||
UInt32 i;
|
||||
uint32_t i;
|
||||
|
||||
bool foundSection = false;
|
||||
for( i = 0; i < fSections.GetCount(); i++ )
|
||||
|
@ -54,7 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
// reader, and ending with a nil pointer (see below). Finally, create //
|
||||
// a plInitFileReader with the array you created and it'll parse the //
|
||||
// given file (or stream) and call your readers as needed. You can also //
|
||||
// optionally pass in a UInt32 for userData that will be passed on to each //
|
||||
// optionally pass in a uint32_t for userData that will be passed on to each //
|
||||
// reader in turn. //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -77,7 +77,7 @@ class plInitSectionReader
|
||||
virtual const char *GetSectionName( void ) const = 0;
|
||||
|
||||
// Override this to parse each line in your section. Return false to abort parsing
|
||||
virtual hsBool ParseLine( const char *line, UInt32 userData ) = 0;
|
||||
virtual hsBool ParseLine( const char *line, uint32_t userData ) = 0;
|
||||
|
||||
// Override this if you're defining an unhandled section reader
|
||||
virtual void SetSectionName(const char* section) {}
|
||||
@ -96,14 +96,14 @@ class plInitSectionTokenReader : public plInitSectionReader
|
||||
const char *fSeparators;
|
||||
|
||||
// Override this to parse each token in your section. Return false to abort parsing
|
||||
virtual hsBool IParseToken( const char *token, hsStringTokenizer *tokenizer, UInt32 userData ) = 0;
|
||||
virtual hsBool IParseToken( const char *token, hsStringTokenizer *tokenizer, uint32_t userData ) = 0;
|
||||
|
||||
public:
|
||||
|
||||
plInitSectionTokenReader( const char *separators = ",=\t" );
|
||||
|
||||
// Overridden for you. Override IParseToken()
|
||||
virtual hsBool ParseLine( const char *line, UInt32 userData );
|
||||
virtual hsBool ParseLine( const char *line, uint32_t userData );
|
||||
};
|
||||
|
||||
//// Main Reader Class ///////////////////////////////////////////////////////
|
||||
@ -117,7 +117,7 @@ class plInitFileReader
|
||||
hsStream *fStream;
|
||||
hsStream *fOurStream;
|
||||
char *fCurrLine;
|
||||
UInt32 fLineSize;
|
||||
uint32_t fLineSize;
|
||||
bool fRequireEncrypted;
|
||||
|
||||
plInitSectionReader *fCurrSection;
|
||||
@ -133,9 +133,9 @@ class plInitFileReader
|
||||
// element of the array will be the "default" section--i.e. if there is no section
|
||||
// header at the top of the file, that reader will be used.
|
||||
|
||||
plInitFileReader( plInitSectionReader **readerArray, UInt16 lineSize = 256 );
|
||||
plInitFileReader( const char *fileName, plInitSectionReader **readerArray, UInt16 lineSize = 256 );
|
||||
plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, UInt16 lineSize = 256 );
|
||||
plInitFileReader( plInitSectionReader **readerArray, uint16_t lineSize = 256 );
|
||||
plInitFileReader( const char *fileName, plInitSectionReader **readerArray, uint16_t lineSize = 256 );
|
||||
plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize = 256 );
|
||||
virtual ~plInitFileReader();
|
||||
|
||||
void SetRequireEncrypted(bool require) { fRequireEncrypted = require; }
|
||||
@ -144,7 +144,7 @@ class plInitFileReader
|
||||
|
||||
hsBool Open( const char *fileName );
|
||||
hsBool Open( hsStream *stream );
|
||||
hsBool Parse( UInt32 userData = 0 );
|
||||
hsBool Parse( uint32_t userData = 0 );
|
||||
void Close( void );
|
||||
|
||||
hsBool IsOpen( void ) const { return fStream != nil; }
|
||||
|
@ -51,18 +51,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#endif
|
||||
|
||||
// our default encryption key
|
||||
const UInt32 plSecureStream::kDefaultKey[4] = { 0x6c0a5452, 0x3827d0f, 0x3a170b92, 0x16db7fc2 };
|
||||
const uint32_t plSecureStream::kDefaultKey[4] = { 0x6c0a5452, 0x3827d0f, 0x3a170b92, 0x16db7fc2 };
|
||||
|
||||
static const int kEncryptChunkSize = 8;
|
||||
|
||||
static const char* kMagicString = "notthedroids";
|
||||
static const int kMagicStringLen = 12;
|
||||
|
||||
static const int kFileStartOffset = kMagicStringLen + sizeof(UInt32);
|
||||
static const int kFileStartOffset = kMagicStringLen + sizeof(uint32_t);
|
||||
|
||||
static const int kMaxBufferedFileSize = 10*1024;
|
||||
|
||||
plSecureStream::plSecureStream(hsBool deleteOnExit, UInt32* key) :
|
||||
plSecureStream::plSecureStream(hsBool deleteOnExit, uint32_t* key) :
|
||||
fRef(INVALID_HANDLE_VALUE),
|
||||
fActualFileSize(0),
|
||||
fBufferedStream(false),
|
||||
@ -77,7 +77,7 @@ fDeleteOnExit(deleteOnExit)
|
||||
memcpy(&fKey, &kDefaultKey, sizeof(kDefaultKey));
|
||||
}
|
||||
|
||||
plSecureStream::plSecureStream(hsStream* base, UInt32* key) :
|
||||
plSecureStream::plSecureStream(hsStream* base, uint32_t* key) :
|
||||
fRef(INVALID_HANDLE_VALUE),
|
||||
fActualFileSize(0),
|
||||
fBufferedStream(false),
|
||||
@ -107,7 +107,7 @@ plSecureStream::~plSecureStream()
|
||||
|
||||
#define MX (z>>5 ^ y<<2) + (y>>3 ^ z<<4) ^ (sum^y) + (fKey[p&3^e]^z)
|
||||
|
||||
void plSecureStream::IEncipher(UInt32* const v, UInt32 n)
|
||||
void plSecureStream::IEncipher(uint32_t* const v, uint32_t n)
|
||||
{
|
||||
register unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9;
|
||||
register unsigned long q = 6 + 52/n, p, sum = 0;
|
||||
@ -128,7 +128,7 @@ void plSecureStream::IEncipher(UInt32* const v, UInt32 n)
|
||||
}
|
||||
}
|
||||
|
||||
void plSecureStream::IDecipher(UInt32* const v, UInt32 n)
|
||||
void plSecureStream::IDecipher(uint32_t* const v, uint32_t n)
|
||||
{
|
||||
register unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9;
|
||||
register unsigned long q = 6 + 52/n, p, sum = q * delta;
|
||||
@ -151,15 +151,15 @@ void plSecureStream::IDecipher(UInt32* const v, UInt32 n)
|
||||
|
||||
hsBool plSecureStream::Open(const char* name, const char* mode)
|
||||
{
|
||||
wchar* wName = hsStringToWString(name);
|
||||
wchar* wMode = hsStringToWString(mode);
|
||||
wchar_t* wName = hsStringToWString(name);
|
||||
wchar_t* wMode = hsStringToWString(mode);
|
||||
hsBool ret = Open(wName, wMode);
|
||||
delete [] wName;
|
||||
delete [] wMode;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsBool plSecureStream::Open(const wchar* name, const wchar* mode)
|
||||
hsBool plSecureStream::Open(const wchar_t* name, const wchar_t* mode)
|
||||
{
|
||||
if (wcscmp(mode, L"rb") == 0)
|
||||
{
|
||||
@ -199,7 +199,7 @@ hsBool plSecureStream::Open(const wchar* name, const wchar* mode)
|
||||
}
|
||||
|
||||
DWORD numBytesRead;
|
||||
ReadFile(fRef, &fActualFileSize, sizeof(UInt32), &numBytesRead, NULL);
|
||||
ReadFile(fRef, &fActualFileSize, sizeof(uint32_t), &numBytesRead, NULL);
|
||||
#elif HS_BUILD_FOR_UNIX
|
||||
const char* cname = hsWStringToString(name);
|
||||
fRef = fopen(cname, "rb");
|
||||
@ -231,7 +231,7 @@ hsBool plSecureStream::Open(const wchar* name, const wchar* mode)
|
||||
else if (wcscmp(mode, L"wb") == 0)
|
||||
{
|
||||
fRAMStream = TRACKED_NEW hsVectorStream;
|
||||
fWriteFileName = TRACKED_NEW wchar[wcslen(name) + 1];
|
||||
fWriteFileName = TRACKED_NEW wchar_t[wcslen(name) + 1];
|
||||
wcscpy(fWriteFileName, name);
|
||||
fPosition = 0;
|
||||
|
||||
@ -250,26 +250,26 @@ hsBool plSecureStream::Open(const wchar* name, const wchar* mode)
|
||||
|
||||
hsBool plSecureStream::Open(hsStream* stream)
|
||||
{
|
||||
UInt32 pos = stream->GetPosition();
|
||||
uint32_t pos = stream->GetPosition();
|
||||
stream->Rewind();
|
||||
if (!ICheckMagicString(stream))
|
||||
return false;
|
||||
|
||||
fActualFileSize = stream->ReadLE32();
|
||||
UInt32 trimSize = kMagicStringLen + sizeof(UInt32) + fActualFileSize;
|
||||
uint32_t trimSize = kMagicStringLen + sizeof(uint32_t) + fActualFileSize;
|
||||
fRAMStream = new hsRAMStream;
|
||||
while (!stream->AtEnd())
|
||||
{
|
||||
// Don't write out any garbage
|
||||
UInt32 size;
|
||||
uint32_t size;
|
||||
if ((trimSize - stream->GetPosition()) < kEncryptChunkSize)
|
||||
size = (trimSize - stream->GetPosition());
|
||||
else
|
||||
size = kEncryptChunkSize;
|
||||
|
||||
UInt8 buf[kEncryptChunkSize];
|
||||
uint8_t buf[kEncryptChunkSize];
|
||||
stream->Read(kEncryptChunkSize, &buf);
|
||||
IDecipher((UInt32*)&buf, kEncryptChunkSize / sizeof(UInt32));
|
||||
IDecipher((uint32_t*)&buf, kEncryptChunkSize / sizeof(uint32_t));
|
||||
fRAMStream->Write(size, &buf);
|
||||
}
|
||||
|
||||
@ -319,11 +319,11 @@ hsBool plSecureStream::Close()
|
||||
return rtn;
|
||||
}
|
||||
|
||||
UInt32 plSecureStream::IRead(UInt32 bytes, void* buffer)
|
||||
uint32_t plSecureStream::IRead(uint32_t bytes, void* buffer)
|
||||
{
|
||||
if (fRef == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
UInt32 numItems;
|
||||
uint32_t numItems;
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
bool success = (ReadFile(fRef, buffer, bytes, (LPDWORD)&numItems, NULL) != 0);
|
||||
#elif HS_BUILD_FOR_UNIX
|
||||
@ -355,7 +355,7 @@ void plSecureStream::IBufferFile()
|
||||
char buf[1024];
|
||||
while (!AtEnd())
|
||||
{
|
||||
UInt32 numRead = Read(1024, buf);
|
||||
uint32_t numRead = Read(1024, buf);
|
||||
fRAMStream->Write(numRead, buf);
|
||||
}
|
||||
fRAMStream->Rewind();
|
||||
@ -378,7 +378,7 @@ hsBool plSecureStream::AtEnd()
|
||||
return (GetPosition() == fActualFileSize);
|
||||
}
|
||||
|
||||
void plSecureStream::Skip(UInt32 delta)
|
||||
void plSecureStream::Skip(uint32_t delta)
|
||||
{
|
||||
if (fBufferedStream)
|
||||
{
|
||||
@ -433,31 +433,31 @@ void plSecureStream::FastFwd()
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 plSecureStream::GetEOF()
|
||||
uint32_t plSecureStream::GetEOF()
|
||||
{
|
||||
return fActualFileSize;
|
||||
}
|
||||
|
||||
UInt32 plSecureStream::Read(UInt32 bytes, void* buffer)
|
||||
uint32_t plSecureStream::Read(uint32_t bytes, void* buffer)
|
||||
{
|
||||
if (fBufferedStream)
|
||||
{
|
||||
UInt32 numRead = fRAMStream->Read(bytes, buffer);
|
||||
uint32_t numRead = fRAMStream->Read(bytes, buffer);
|
||||
fPosition = fRAMStream->GetPosition();
|
||||
return numRead;
|
||||
}
|
||||
|
||||
UInt32 startPos = fPosition;
|
||||
uint32_t startPos = fPosition;
|
||||
|
||||
// Offset into the first buffer (0 if we are aligned on a chunk, which means no extra block read)
|
||||
UInt32 startChunkPos = startPos % kEncryptChunkSize;
|
||||
uint32_t startChunkPos = startPos % kEncryptChunkSize;
|
||||
// Amount of data in the partial first chunk (0 if we're aligned)
|
||||
UInt32 startAmt = (startChunkPos != 0) ? hsMinimum(kEncryptChunkSize - startChunkPos, bytes) : 0;
|
||||
uint32_t startAmt = (startChunkPos != 0) ? hsMinimum(kEncryptChunkSize - startChunkPos, bytes) : 0;
|
||||
|
||||
UInt32 totalNumRead = IRead(bytes, buffer);
|
||||
uint32_t totalNumRead = IRead(bytes, buffer);
|
||||
|
||||
UInt32 numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
|
||||
UInt32 endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
|
||||
uint32_t numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
|
||||
uint32_t endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
|
||||
|
||||
// If the start position is in the middle of a chunk we need to rewind and
|
||||
// read that whole chunk in and decrypt it.
|
||||
@ -468,8 +468,8 @@ UInt32 plSecureStream::Read(UInt32 bytes, void* buffer)
|
||||
|
||||
// Read in the chunk and decrypt it
|
||||
char buf[kEncryptChunkSize];
|
||||
UInt32 numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((UInt32*)&buf, kEncryptChunkSize / sizeof(UInt32));
|
||||
uint32_t numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((uint32_t*)&buf, kEncryptChunkSize / sizeof(uint32_t));
|
||||
|
||||
// Copy the relevant portion to the output buffer
|
||||
memcpy(buffer, &buf[startChunkPos], startAmt);
|
||||
@ -479,12 +479,12 @@ UInt32 plSecureStream::Read(UInt32 bytes, void* buffer)
|
||||
|
||||
if (numMidChunks != 0)
|
||||
{
|
||||
UInt32* bufferPos = (UInt32*)(((char*)buffer)+startAmt);
|
||||
uint32_t* bufferPos = (uint32_t*)(((char*)buffer)+startAmt);
|
||||
for (int i = 0; i < numMidChunks; i++)
|
||||
{
|
||||
// Decrypt chunk
|
||||
IDecipher(bufferPos, kEncryptChunkSize / sizeof(UInt32));
|
||||
bufferPos += (kEncryptChunkSize / sizeof(UInt32));
|
||||
IDecipher(bufferPos, kEncryptChunkSize / sizeof(uint32_t));
|
||||
bufferPos += (kEncryptChunkSize / sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,8 +493,8 @@ UInt32 plSecureStream::Read(UInt32 bytes, void* buffer)
|
||||
// Read in the final chunk and decrypt it
|
||||
char buf[kEncryptChunkSize];
|
||||
SetPosition(startPos + startAmt + numMidChunks*kEncryptChunkSize);
|
||||
UInt32 numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((UInt32*)&buf, kEncryptChunkSize / sizeof(UInt32));
|
||||
uint32_t numRead = IRead(kEncryptChunkSize, &buf);
|
||||
IDecipher((uint32_t*)&buf, kEncryptChunkSize / sizeof(uint32_t));
|
||||
|
||||
memcpy(((char*)buffer)+totalNumRead-endAmt, &buf, endAmt);
|
||||
|
||||
@ -511,7 +511,7 @@ UInt32 plSecureStream::Read(UInt32 bytes, void* buffer)
|
||||
return totalNumRead;
|
||||
}
|
||||
|
||||
UInt32 plSecureStream::Write(UInt32 bytes, const void* buffer)
|
||||
uint32_t plSecureStream::Write(uint32_t bytes, const void* buffer)
|
||||
{
|
||||
if (fOpenMode != kOpenWrite)
|
||||
{
|
||||
@ -522,7 +522,7 @@ UInt32 plSecureStream::Write(UInt32 bytes, const void* buffer)
|
||||
return fRAMStream->Write(bytes, buffer);
|
||||
}
|
||||
|
||||
bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar* outputFile)
|
||||
bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar_t* outputFile)
|
||||
{
|
||||
hsUNIXStream outputStream;
|
||||
|
||||
@ -536,10 +536,10 @@ bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar* output
|
||||
|
||||
// Write out all the full size encrypted blocks we can
|
||||
char buf[kEncryptChunkSize];
|
||||
UInt32 amtRead;
|
||||
uint32_t amtRead;
|
||||
while ((amtRead = sourceStream->Read(kEncryptChunkSize, &buf)) == kEncryptChunkSize)
|
||||
{
|
||||
IEncipher((UInt32*)&buf, kEncryptChunkSize / sizeof(UInt32));
|
||||
IEncipher((uint32_t*)&buf, kEncryptChunkSize / sizeof(uint32_t));
|
||||
outputStream.Write(kEncryptChunkSize, &buf);
|
||||
}
|
||||
|
||||
@ -556,13 +556,13 @@ bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar* output
|
||||
for (int i = amtRead; i < kEncryptChunkSize; i++)
|
||||
buf[i] = rand();
|
||||
|
||||
IEncipher((UInt32*)&buf, kEncryptChunkSize / sizeof(UInt32));
|
||||
IEncipher((uint32_t*)&buf, kEncryptChunkSize / sizeof(uint32_t));
|
||||
|
||||
outputStream.Write(kEncryptChunkSize, &buf);
|
||||
}
|
||||
|
||||
// Write the original file size at the start
|
||||
UInt32 actualSize = sourceStream->GetPosition();
|
||||
uint32_t actualSize = sourceStream->GetPosition();
|
||||
outputStream.Rewind();
|
||||
outputStream.Skip(kMagicStringLen);
|
||||
outputStream.WriteLE32(actualSize);
|
||||
@ -572,15 +572,15 @@ bool plSecureStream::IWriteEncrypted(hsStream* sourceStream, const wchar* output
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plSecureStream::FileEncrypt(const char* fileName, UInt32* key /* = nil */)
|
||||
bool plSecureStream::FileEncrypt(const char* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = FileEncrypt(wFilename, key);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plSecureStream::FileEncrypt(const wchar* fileName, UInt32* key /* = nil */)
|
||||
bool plSecureStream::FileEncrypt(const wchar_t* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
hsUNIXStream sIn;
|
||||
if (!sIn.Open(fileName))
|
||||
@ -609,15 +609,15 @@ bool plSecureStream::FileEncrypt(const wchar* fileName, UInt32* key /* = nil */)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plSecureStream::FileDecrypt(const char* fileName, UInt32* key /* = nil */)
|
||||
bool plSecureStream::FileDecrypt(const char* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = FileDecrypt(wFilename, key);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plSecureStream::FileDecrypt(const wchar* fileName, UInt32* key /* = nil */)
|
||||
bool plSecureStream::FileDecrypt(const wchar_t* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
plSecureStream sIn(false, key);
|
||||
if (!sIn.Open(fileName))
|
||||
@ -634,7 +634,7 @@ bool plSecureStream::FileDecrypt(const wchar* fileName, UInt32* key /* = nil */)
|
||||
|
||||
while (!sIn.AtEnd())
|
||||
{
|
||||
UInt32 numRead = sIn.Read(sizeof(buf), buf);
|
||||
uint32_t numRead = sIn.Read(sizeof(buf), buf);
|
||||
sOut.Write(numRead, buf);
|
||||
}
|
||||
|
||||
@ -670,13 +670,13 @@ bool plSecureStream::ICheckMagicString(hsFD fp)
|
||||
|
||||
bool plSecureStream::IsSecureFile(const char* fileName)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = IsSecureFile(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plSecureStream::IsSecureFile(const wchar* fileName)
|
||||
bool plSecureStream::IsSecureFile(const wchar_t* fileName)
|
||||
{
|
||||
hsFD fp = INVALID_HANDLE_VALUE;
|
||||
|
||||
@ -708,15 +708,15 @@ bool plSecureStream::IsSecureFile(const wchar* fileName)
|
||||
return isEncrypted;
|
||||
}
|
||||
|
||||
hsStream* plSecureStream::OpenSecureFile(const char* fileName, const UInt32 flags /* = kRequireEncryption */, UInt32* key /* = nil */)
|
||||
hsStream* plSecureStream::OpenSecureFile(const char* fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
hsStream* ret = OpenSecureFile(wFilename, flags, key);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsStream* plSecureStream::OpenSecureFile(const wchar* fileName, const UInt32 flags /* = kRequireEncryption */, UInt32* key /* = nil */)
|
||||
hsStream* plSecureStream::OpenSecureFile(const wchar_t* fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */)
|
||||
{
|
||||
bool requireEncryption = flags & kRequireEncryption;
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
@ -737,15 +737,15 @@ hsStream* plSecureStream::OpenSecureFile(const wchar* fileName, const UInt32 fla
|
||||
return s;
|
||||
}
|
||||
|
||||
hsStream* plSecureStream::OpenSecureFileWrite(const char* fileName, UInt32* key /* = nil */)
|
||||
hsStream* plSecureStream::OpenSecureFileWrite(const char* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
wchar* wFilename = hsStringToWString(fileName);
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
hsStream* ret = OpenSecureFileWrite(wFilename, key);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsStream* plSecureStream::OpenSecureFileWrite(const wchar* fileName, UInt32* key /* = nil */)
|
||||
hsStream* plSecureStream::OpenSecureFileWrite(const wchar_t* fileName, uint32_t* key /* = nil */)
|
||||
{
|
||||
hsStream* s = nil;
|
||||
#ifdef PLASMA_EXTERNAL_RELEASE
|
||||
|
@ -60,15 +60,15 @@ class plSecureStream: public hsStream
|
||||
{
|
||||
protected:
|
||||
hsFD fRef;
|
||||
UInt32 fKey[4];
|
||||
uint32_t fKey[4];
|
||||
|
||||
UInt32 fActualFileSize;
|
||||
uint32_t fActualFileSize;
|
||||
|
||||
bool fBufferedStream;
|
||||
|
||||
hsStream* fRAMStream;
|
||||
|
||||
wchar* fWriteFileName;
|
||||
wchar_t* fWriteFileName;
|
||||
|
||||
enum OpenMode {kOpenRead, kOpenWrite, kOpenFail};
|
||||
OpenMode fOpenMode;
|
||||
@ -77,40 +77,40 @@ protected:
|
||||
|
||||
void IBufferFile();
|
||||
|
||||
UInt32 IRead(UInt32 bytes, void* buffer);
|
||||
uint32_t IRead(uint32_t bytes, void* buffer);
|
||||
|
||||
void IEncipher(UInt32* const v, UInt32 n);
|
||||
void IDecipher(UInt32* const v, UInt32 n);
|
||||
void IEncipher(uint32_t* const v, uint32_t n);
|
||||
void IDecipher(uint32_t* const v, uint32_t n);
|
||||
|
||||
bool IWriteEncrypted(hsStream* sourceStream, const wchar* outputFile);
|
||||
bool IWriteEncrypted(hsStream* sourceStream, const wchar_t* outputFile);
|
||||
|
||||
static bool ICheckMagicString(hsFD fp);
|
||||
static bool ICheckMagicString(hsStream* s);
|
||||
|
||||
public:
|
||||
plSecureStream(hsBool deleteOnExit = false, UInt32* key = nil); // uses default key if you don't pass one in
|
||||
plSecureStream(hsStream* base, UInt32* key = nil);
|
||||
plSecureStream(hsBool deleteOnExit = false, uint32_t* key = nil); // uses default key if you don't pass one in
|
||||
plSecureStream(hsStream* base, uint32_t* key = nil);
|
||||
~plSecureStream();
|
||||
|
||||
virtual hsBool Open(const char* name, const char* mode = "rb");
|
||||
virtual hsBool Open(const wchar* name, const wchar* mode = L"rb");
|
||||
virtual hsBool Open(const wchar_t* name, const wchar_t* mode = L"rb");
|
||||
hsBool Open(hsStream* stream);
|
||||
virtual hsBool Close();
|
||||
|
||||
virtual UInt32 Read(UInt32 byteCount, void* buffer);
|
||||
virtual UInt32 Write(UInt32 byteCount, const void* buffer);
|
||||
virtual uint32_t Read(uint32_t byteCount, void* buffer);
|
||||
virtual uint32_t Write(uint32_t byteCount, const void* buffer);
|
||||
virtual hsBool AtEnd();
|
||||
virtual void Skip(UInt32 deltaByteCount);
|
||||
virtual void Skip(uint32_t deltaByteCount);
|
||||
virtual void Rewind();
|
||||
virtual void FastFwd();
|
||||
virtual UInt32 GetEOF();
|
||||
virtual uint32_t GetEOF();
|
||||
|
||||
UInt32 GetActualFileSize() const {return fActualFileSize;}
|
||||
uint32_t GetActualFileSize() const {return fActualFileSize;}
|
||||
|
||||
static bool FileEncrypt(const char* fileName, UInt32* key = nil);
|
||||
static bool FileEncrypt(const wchar* fileName, UInt32* key = nil);
|
||||
static bool FileDecrypt(const char* fileName, UInt32* key = nil);
|
||||
static bool FileDecrypt(const wchar* fileName, UInt32* key = nil);
|
||||
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);
|
||||
|
||||
enum OpenSecureFileFlags
|
||||
{
|
||||
@ -119,18 +119,18 @@ public:
|
||||
};
|
||||
|
||||
static bool IsSecureFile(const char* fileName);
|
||||
static bool IsSecureFile(const wchar* fileName);
|
||||
static bool IsSecureFile(const wchar_t* 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 flags = kRequireEncryption, UInt32* key = nil);
|
||||
static hsStream* OpenSecureFile(const wchar* fileName, const UInt32 flags = kRequireEncryption, UInt32* key = nil);
|
||||
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);
|
||||
// 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* key = nil);
|
||||
static hsStream* OpenSecureFileWrite(const wchar* fileName, UInt32* key = nil);
|
||||
static hsStream* OpenSecureFileWrite(const char* fileName, uint32_t* key = nil);
|
||||
static hsStream* OpenSecureFileWrite(const wchar_t* fileName, uint32_t* key = nil);
|
||||
|
||||
static const UInt32 kDefaultKey[4]; // our default encryption key
|
||||
static const uint32_t kDefaultKey[4]; // our default encryption key
|
||||
};
|
||||
|
||||
#endif // plSecureStream_h_inc
|
||||
|
@ -56,7 +56,7 @@ void ToLower(std::wstring& str)
|
||||
str[i] = towlower(str[i]);
|
||||
}
|
||||
|
||||
void ReplaceSlashes(std::wstring& path, wchar replaceWith)
|
||||
void ReplaceSlashes(std::wstring& path, wchar_t replaceWith)
|
||||
{
|
||||
for (unsigned i = 0; i < path.length(); i++)
|
||||
{
|
||||
@ -127,7 +127,7 @@ hsStream* plStreamSource::GetFile(std::wstring filename)
|
||||
fFileData[filename].fExt = ext;
|
||||
if (plSecureStream::IsSecureFile(sFilename.c_str()))
|
||||
{
|
||||
UInt32 encryptionKey[4];
|
||||
uint32_t encryptionKey[4];
|
||||
if (!plFileUtils::GetSecureEncryptionKey(sFilename.c_str(), encryptionKey, 4))
|
||||
{
|
||||
FATAL("Hey camper... You need an NTD key file!");
|
||||
|
Reference in New Issue
Block a user