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

Fix paths and move GetSecureEncryptionKey so things compile again

This commit is contained in:
2012-02-11 20:14:42 -08:00
parent 403d2a896d
commit 041b1985e4
47 changed files with 129 additions and 127 deletions

View File

@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAgeDescription.h"
#include "hsStlUtils.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "plFile/plInitFileReader.h"
#include "plFile/plEncryptedStream.h"
#include "hsStringTokenizer.h"

View File

@ -51,8 +51,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAgeManifest.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "hsFiles.h"
#include "plFileUtils.h"
#include "plFile/plInitFileReader.h"
#include "hsStringTokenizer.h"

View File

@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAgeLoader/plAgeLoader.h"
#include "plCompression/plZlibStream.h"
#include "pnEncryption/plChecksum.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
#include "plMessage/plResPatcherMsg.h"
#include "pnNetBase/pnNbError.h"
#include "plNetGameLib/plNetGameLib.h"

View File

@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsGeometry3.h"
#include "plgDispatch.h"
#include "plProfile.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "plWin32Sound.h"
#include "plWin32StreamingSound.h"

View File

@ -55,8 +55,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAudioCore.h"
//#include "hsTimer.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "hsFiles.h"
#include "plFileUtils.h"
#include "plUnifiedTime/plUnifiedTime.h"
#include "plBufferedFileReader.h"
#include "plCachedFileReader.h"

View File

@ -49,8 +49,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plgDispatch.h"
#include "hsResMgr.h"
#include "pnMessage/plRefMsg.h"
#include "plFile/plFileUtils.h"
#include "plFile/hsFiles.h"
#include "plFileUtils.h"
#include "hsFiles.h"
#include "plUnifiedTime/plUnifiedTime.h"
#include "plStatusLog/plStatusLog.h"
#include "hsTimer.h"

View File

@ -62,6 +62,9 @@ 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),
fActualFileSize(0),
@ -757,3 +760,61 @@ hsStream* plSecureStream::OpenSecureFileWrite(const wchar_t* fileName, uint32_t*
s->Open(fileName, L"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)
{
// looks for an encryption key file in the same directory, and reads it
std::wstring sFilename = filename;
// grab parent directory
size_t loc = sFilename.rfind(L"\\");
if (loc == std::wstring::npos)
loc = sFilename.rfind(L"/");
std::wstring sDir;
if (loc != std::wstring::npos)
sDir = sFilename.substr(0, loc);
else // no directory
sDir = L"./";
if ((sDir[sDir.length()-1] != L'/') && (sDir[sDir.length()-1] != L'\\'))
sDir += L'/'; // add the slash, if it doesn't has one
// now add the key filename
std::wstring keyFile = sDir + kWKeyFilename;
if (plFileUtils::FileExists(keyFile.c_str()))
{
// file exists, read from it
hsUNIXStream file;
file.Open(keyFile.c_str(), L"rb");
unsigned bytesToRead = length * sizeof(uint32_t);
uint8_t* buffer = (uint8_t*)malloc(bytesToRead);
unsigned bytesRead = file.Read(bytesToRead, buffer);
file.Close();
unsigned memSize = min(bytesToRead, bytesRead);
memcpy(key, buffer, memSize);
free(buffer);
return true;
}
// file doesn't exist, use default key
unsigned memSize = min(length, arrsize(plSecureStream::kDefaultKey));
memSize *= sizeof(uint32_t);
memcpy(key, plSecureStream::kDefaultKey, memSize);
return false;
}

View File

@ -131,6 +131,15 @@ public:
static hsStream* OpenSecureFileWrite(const wchar_t* 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 const char kKeyFilename[];
static const wchar_t kWKeyFilename[];
};
#endif // plSecureStream_h_inc

View File

@ -128,7 +128,7 @@ hsStream* plStreamSource::GetFile(std::wstring filename)
if (plSecureStream::IsSecureFile(sFilename.c_str()))
{
uint32_t encryptionKey[4];
if (!plFileUtils::GetSecureEncryptionKey(sFilename.c_str(), encryptionKey, 4))
if (!plSecureStream::GetSecureEncryptionKey(sFilename.c_str(), encryptionKey, 4))
{
FATAL("Hey camper... You need an NTD key file!");
return nil;

View File

@ -57,7 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plFont.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "pnMessage/plRefMsg.h"
#include "hsResMgr.h"

View File

@ -63,7 +63,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plWinFontCache.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "plGImage/plDynSurfaceWriter.h"
#if HS_BUILD_FOR_WIN32

View File

@ -63,7 +63,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plNetMessage/plNetMessage.h"
#include "plAvatar/plAvatarMgr.h"
#include "plAvatar/plArmatureMod.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
/*****************************************************************************

View File

@ -56,7 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
plNetClientRecorder::plNetClientRecorder(TimeWrapper* timeWrapper) :
fTimeWrapper(timeWrapper)

View File

@ -41,7 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "plLocalization.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
plLocalization::Language plLocalization::fLanguage = plLocalization::kEnglish;

View File

@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plKeyImp.h"
#include "plStatusLog/plStatusLog.h"
#include "pnFactory/plFactory.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
#include "hsStlUtils.h"
#include "plVersion.h"

View File

@ -60,8 +60,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnMessage/plObjRefMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "pnMessage/plClientMsg.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "hsFiles.h"
#include "plFileUtils.h"
#include "pnFactory/plCreator.h"
#include "pnNetCommon/plSynchedObject.h"
#include "pnNetCommon/plNetApp.h"

View File

@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "plSDL.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "plFile/plStreamSource.h"
#include "pnNetCommon/pnNetCommon.h"
#include "pnNetCommon/plNetApp.h"

View File

@ -57,7 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnMessage/plClientMsg.h"
#include "plAgeLoader/plAgeLoader.h"
#include "plProfileManagerFull.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
#include "plPipeline/plDebugText.h"
#include "pnMessage/plTimeMsg.h"

View File

@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
#include "pnUtils/pnUtils.h"
#include "plUnifiedTime/plUnifiedTime.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
plProfileManagerFull::plProfileManagerFull() :
fVars(plProfileManager::Instance().fVars),

View File

@ -61,10 +61,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTemplates.h"
#include "hsTimer.h"
#include "hsStlUtils.h"
#include "plFile/plFileUtils.h"
#include "plFileUtils.h"
#include "plStatusLog.h"
#include "hsStlUtils.h"
#include "plFile/hsFiles.h"
#include "hsFiles.h"
#include "plUnifiedTime/plUnifiedTime.h"
#include "pnProduct/pnProduct.h"