From 041b1985e47a766d208ad0eea2c0dc8df2670905 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Feb 2012 20:14:42 -0800 Subject: [PATCH] Fix paths and move GetSecureEncryptionKey so things compile again --- Sources/Plasma/Apps/plClient/plClient.cpp | 4 +- Sources/Plasma/Apps/plClient/winmain.cpp | 2 +- Sources/Plasma/Apps/plFileEncrypt/main.cpp | 2 +- Sources/Plasma/Apps/plFileSecure/main.cpp | 16 ++--- Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp | 4 +- Sources/Plasma/Apps/plPythonPack/main.cpp | 2 +- Sources/Plasma/Apps/plUruLauncher/Pch.h | 2 +- Sources/Plasma/CoreLib/CMakeLists.txt | 1 + Sources/Plasma/CoreLib/plFileUtils.cpp | 62 +------------------ Sources/Plasma/CoreLib/plFileUtils.h | 9 --- .../pfConsole/pfConsoleCommands.cpp | 2 +- .../pfConsole/pfConsoleCommandsNet.cpp | 2 +- .../FeatureLib/pfCrashHandler/plCrashSrv.cpp | 2 +- .../pfLocalizationDataMgr.cpp | 2 +- .../FeatureLib/pfPython/plPythonPack.cpp | 2 +- .../pfSecurePreloader/pfSecurePreloader.cpp | 2 +- .../plAgeDescription/plAgeDescription.cpp | 2 +- .../plAgeDescription/plAgeManifest.cpp | 4 +- .../PubUtilLib/plAgeLoader/plResPatcher.cpp | 2 +- .../plAudio/plWin32StreamingSound.cpp | 2 +- .../plAudioCore/plAudioFileReader.cpp | 4 +- .../PubUtilLib/plAudioCore/plSoundBuffer.cpp | 4 +- .../PubUtilLib/plFile/plSecureStream.cpp | 61 ++++++++++++++++++ .../Plasma/PubUtilLib/plFile/plSecureStream.h | 9 +++ .../PubUtilLib/plFile/plStreamSource.cpp | 2 +- .../PubUtilLib/plGImage/plFontCache.cpp | 2 +- .../PubUtilLib/plGImage/plWinFontCache.cpp | 2 +- .../plNetClient/plNetLinkingMgr.cpp | 2 +- .../plNetClientRecorder.cpp | 2 +- .../PubUtilLib/plResMgr/plLocalization.cpp | 2 +- .../PubUtilLib/plResMgr/plRegistryNode.cpp | 2 +- .../PubUtilLib/plResMgr/plResManager.cpp | 4 +- .../Plasma/PubUtilLib/plSDL/plSDLParser.cpp | 2 +- .../PubUtilLib/plStatGather/plAutoProfile.cpp | 2 +- .../plStatGather/plProfileManagerFull.cpp | 2 +- .../PubUtilLib/plStatusLog/plStatusLog.cpp | 4 +- .../Tools/MaxComponent/plAudioComponents.cpp | 2 +- .../Tools/MaxComponent/plGUIComponents.cpp | 2 +- .../Tools/MaxComponent/plMiscComponents.cpp | 4 +- .../Tools/MaxComponent/plResponderLink.cpp | 2 +- .../Tools/MaxConvert/hsMaterialConverter.cpp | 2 +- Sources/Tools/MaxExport/SimpleExport.cpp | 2 +- Sources/Tools/MaxExport/plExportDlg.cpp | 2 +- Sources/Tools/MaxMain/main.cpp | 2 +- Sources/Tools/MaxMain/plAgeDescInterface.cpp | 2 +- Sources/Tools/MaxMain/plPythonMgr.cpp | 2 +- .../plResBrowser/plResBrowserWndProc.cpp | 2 +- 47 files changed, 129 insertions(+), 127 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 77173c1c..2c49a608 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -57,7 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTimer.h" #include "plPipeline/hsG3DDeviceSelector.h" #include "plFile/plEncryptedStream.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "plInputCore/plInputManager.h" #include "plInputCore/plInputInterfaceMgr.h" #include "plInputCore/plInputDevice.h" @@ -83,7 +83,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfConsole/pfConsoleDirSrc.h" #include "plScene/plPageTreeMgr.h" #include "plScene/plVisMgr.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "pfKI/pfKI.h" diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 36ef2cf6..fc69b11e 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -71,7 +71,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plStatusLog/plStatusLog.h" #include "pnProduct/pnProduct.h" #include "plNetGameLib/plNetGameLib.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "plPhysX/plSimulationMgr.h" diff --git a/Sources/Plasma/Apps/plFileEncrypt/main.cpp b/Sources/Plasma/Apps/plFileEncrypt/main.cpp index 2a52b1b1..b1002da2 100644 --- a/Sources/Plasma/Apps/plFileEncrypt/main.cpp +++ b/Sources/Plasma/Apps/plFileEncrypt/main.cpp @@ -39,7 +39,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plFile/plEncryptedStream.h" #include "pnProduct/pnProduct.h" diff --git a/Sources/Plasma/Apps/plFileSecure/main.cpp b/Sources/Plasma/Apps/plFileSecure/main.cpp index 4d8172ed..5b8bd6be 100644 --- a/Sources/Plasma/Apps/plFileSecure/main.cpp +++ b/Sources/Plasma/Apps/plFileSecure/main.cpp @@ -39,8 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" +#include "hsFiles.h" +#include "plFileUtils.h" #include "plFile/plSecureStream.h" #include "pnProduct/pnProduct.h" @@ -61,15 +61,15 @@ void print_help() { printf("\tplFileSecure ( )|[/generate /default]\n"); printf("\n"); printf(" : The directory and extension of files to secure. Cannot\n"); - printf(" be used with /generate. Uses the %s file in\n", plFileUtils::kKeyFilename); + printf(" be used with /generate. Uses the %s file in\n", plSecureStream::kKeyFilename); printf(" the current directory (or default key if no file exists)\n"); - printf("/generate : Generates a random key and writes it to a %s\n", plFileUtils::kKeyFilename); + printf("/generate : Generates a random key and writes it to a %s\n", plSecureStream::kKeyFilename); printf(" file in the current directory. Cannot be used with\n"); printf(" \n"); - printf("/default : If used with /generate, creates a %s file\n", plFileUtils::kKeyFilename); + printf("/default : If used with /generate, creates a %s file\n", plSecureStream::kKeyFilename); printf(" with the default key. If used with , it\n"); printf(" secures with the default key instead of the\n"); - printf(" %s file's key\n", plFileUtils::kKeyFilename); + printf(" %s file's key\n", plSecureStream::kKeyFilename); printf("\n"); } @@ -103,7 +103,7 @@ void GenerateKey(bool useDefault) } hsUNIXStream out; - out.Open(plFileUtils::kKeyFilename, "wb"); + out.Open(plSecureStream::kKeyFilename, "wb"); out.Write(sizeof(uint32_t) * arrsize(key), (void*)key); out.Close(); } @@ -204,7 +204,7 @@ int main(int argc, char *argv[]) else { uint32_t key[4]; - plFileUtils::GetSecureEncryptionKey(plFileUtils::kKeyFilename, key, arrsize(key)); + plSecureStream::GetSecureEncryptionKey(plSecureStream::kKeyFilename, key, arrsize(key)); SecureFiles(directory, ext, key); } return 0; diff --git a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp index 0ec17dc2..1337d955 100644 --- a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp +++ b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp @@ -41,8 +41,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "hsTimer.h" -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" +#include "hsFiles.h" +#include "plFileUtils.h" #include "plResMgr/plResManager.h" #include "plResMgr/plResMgrSettings.h" diff --git a/Sources/Plasma/Apps/plPythonPack/main.cpp b/Sources/Plasma/Apps/plPythonPack/main.cpp index ea5b33f4..65442f27 100644 --- a/Sources/Plasma/Apps/plPythonPack/main.cpp +++ b/Sources/Plasma/Apps/plPythonPack/main.cpp @@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "PythonInterface.h" #include "hsStream.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include #include diff --git a/Sources/Plasma/Apps/plUruLauncher/Pch.h b/Sources/Plasma/Apps/plUruLauncher/Pch.h index 990524d8..3f425a06 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Pch.h +++ b/Sources/Plasma/Apps/plUruLauncher/Pch.h @@ -62,7 +62,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnNetCli/pnNetCli.h" #include "plNetGameLib/plNetGameLib.h" #include "pnEncryption/plChecksum.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "plCompression/plZlibStream.h" #include "plClientPatcher/UruPlayer.h" diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index a770fba9..c632ef18 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(../PubUtilLib/plUnifiedTime) # EVIL: For plFileUtils.cpp add_definitions(-D_LIB) if(NOT WCHAR_BYTES) diff --git a/Sources/Plasma/CoreLib/plFileUtils.cpp b/Sources/Plasma/CoreLib/plFileUtils.cpp index 9f3b91cf..0250ef40 100644 --- a/Sources/Plasma/CoreLib/plFileUtils.cpp +++ b/Sources/Plasma/CoreLib/plFileUtils.cpp @@ -57,9 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStringTokenizer.h" -#include "plUnifiedTime/plUnifiedTime.h" - -#include "plSecureStream.h" // for the default key +#include "plUnifiedTime.h" #include #include @@ -503,61 +501,3 @@ uint32_t plFileUtils::GetFileSize( const wchar_t *path ) return len; } - -//// GetSecureEncryptionKey ////////////////////////////////////////////////// - -bool plFileUtils::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 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; - - // 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 (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; -} diff --git a/Sources/Plasma/CoreLib/plFileUtils.h b/Sources/Plasma/CoreLib/plFileUtils.h index 29f6d13f..fff955b0 100644 --- a/Sources/Plasma/CoreLib/plFileUtils.h +++ b/Sources/Plasma/CoreLib/plFileUtils.h @@ -56,9 +56,6 @@ class plUnifiedTime; namespace plFileUtils { - static const char kKeyFilename[] = "encryption.key"; - static const wchar_t kWKeyFilename[] = L"encryption.key"; - // Creates the directory specified. Returns false if unsuccessful or directory already exists bool CreateDir( const char *path ); bool CreateDir( const wchar_t *path ); @@ -113,12 +110,6 @@ namespace plFileUtils // Concatenates fileName onto path, making sure to add a slash if necessary void ConcatFileName(char* path, const char* 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_t* key, unsigned length); - bool GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length); }; diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index 616a0c7d..45b7c192 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -155,7 +155,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plUnifiedTime/plUnifiedTime.h" //end for agedefn test -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "pnSceneObject/plAudioInterface.h" #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index 14cee051..992c809e 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -84,7 +84,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plUnifiedTime/plUnifiedTime.h" //end for agedefn test -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp index 5d5926e2..22fc9430 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp @@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plCrashSrv.h" #include "plCrash_Private.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "pnProduct/pnProduct.h" #ifdef HS_BUILD_FOR_WIN32 diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index f73c74d0..205e8ec6 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plLocalization.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plFile/plEncryptedStream.h" #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp index b23d3483..e6a4a253 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp @@ -54,7 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plPythonPack.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plFile/plSecureStream.h" #include "plFile/plStreamSource.h" diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp index 33f0405a..0c264fb7 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp +++ b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp @@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plgDispatch.h" #include "plCompression/plZlibStream.h" #include "pnEncryption/plChecksum.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "plFile/plSecureStream.h" #include "plFile/plStreamSource.h" #include "plMessage/plNetCommMsgs.h" diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp index e7ae52e6..4d026bfc 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp index 3922a853..6569aa14 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index ed421c79..752ea1be 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp index 43034cd8..b9d3253c 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index d175f66c..50049644 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp index 6b37058d..dd902a33 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index 263bced5..c090e7f8 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -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; +} diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h index a1981642..59b30d6f 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h @@ -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 diff --git a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp index 4ec95793..8c57804c 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp @@ -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; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp index 069ba79c..ebbf6558 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp index 968a40c1..16e959a8 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp @@ -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 diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index d06c3c0e..d6bf5a97 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -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" /***************************************************************************** diff --git a/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp b/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp index dc43052d..67d68dad 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp @@ -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) diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp index 1ff2851c..46afb922 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp @@ -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; diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp index 31f70703..c1c173f6 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 66278a2a..6ccc25bc 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp index f08a95e6..1f8994d4 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index ae8b4dd1..8942ba25 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp @@ -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" diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 28922a0f..93f520bd 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -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), diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 00193189..6a729327 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -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" diff --git a/Sources/Tools/MaxComponent/plAudioComponents.cpp b/Sources/Tools/MaxComponent/plAudioComponents.cpp index 1411869b..f57821fa 100644 --- a/Sources/Tools/MaxComponent/plAudioComponents.cpp +++ b/Sources/Tools/MaxComponent/plAudioComponents.cpp @@ -92,7 +92,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAudio/plWin32StreamingSound.h" #include "plAudio/plWin32GroupedSound.h" #include "plAudioCore/plSoundBuffer.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" // Valdez Asset Manager Related #ifdef MAXASS_AVAILABLE diff --git a/Sources/Tools/MaxComponent/plGUIComponents.cpp b/Sources/Tools/MaxComponent/plGUIComponents.cpp index a6797d8a..69b88ea1 100644 --- a/Sources/Tools/MaxComponent/plGUIComponents.cpp +++ b/Sources/Tools/MaxComponent/plGUIComponents.cpp @@ -115,7 +115,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAgeDescription/plAgeDescription.h" #include "MaxMain/plMaxCFGFile.h" #include "MaxMain/plAgeDescInterface.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "MaxConvert/plConvert.h" #include "MaxPlasmaMtls/Layers/plDynamicTextLayer.h" #include "MaxPlasmaMtls/Layers/plLayerTexBitmapPB.h" diff --git a/Sources/Tools/MaxComponent/plMiscComponents.cpp b/Sources/Tools/MaxComponent/plMiscComponents.cpp index 8ad72831..4a494477 100644 --- a/Sources/Tools/MaxComponent/plMiscComponents.cpp +++ b/Sources/Tools/MaxComponent/plMiscComponents.cpp @@ -70,7 +70,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plInterp/plController.h" #include "MaxMain/plMaxNode.h" #include "pnKeyedObject/plKey.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" // Follow mod #include "plInterp/plAnimPath.h" @@ -95,7 +95,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAgeDescription/plAgeDescription.h" #include "MaxMain/plMaxCFGFile.h" #include "MaxMain/plAgeDescInterface.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plResMgr/plPageInfo.h" #include "plDrawable/plGeometrySpan.h" diff --git a/Sources/Tools/MaxComponent/plResponderLink.cpp b/Sources/Tools/MaxComponent/plResponderLink.cpp index 1c97d009..0ad774e1 100644 --- a/Sources/Tools/MaxComponent/plResponderLink.cpp +++ b/Sources/Tools/MaxComponent/plResponderLink.cpp @@ -49,7 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMiscComponents.h" // Needed for the dialog #include "MaxMain/plMaxCFGFile.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plAgeDescription/plAgeDescription.h" // Needed to create the message diff --git a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp index 27365129..76831243 100644 --- a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp +++ b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp @@ -62,7 +62,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plSurface/hsGMaterial.h" #include "pnSceneObject/plSceneObject.h" #include "UserPropMgr.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "hsConverterUtils.h" #include "hsControlConverter.h" diff --git a/Sources/Tools/MaxExport/SimpleExport.cpp b/Sources/Tools/MaxExport/SimpleExport.cpp index 54a29075..a3a9faf2 100644 --- a/Sources/Tools/MaxExport/SimpleExport.cpp +++ b/Sources/Tools/MaxExport/SimpleExport.cpp @@ -79,7 +79,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plExportDlg.h" #include "plStatusLog/plStatusLog.h" -#include "plFile/plFileUtils.h" +#include "plFileUtils.h" #include "plAvatar/plAvatarMgr.h" diff --git a/Sources/Tools/MaxExport/plExportDlg.cpp b/Sources/Tools/MaxExport/plExportDlg.cpp index 2bfe7811..db36091e 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -325,7 +325,7 @@ void plExportDlgImp::IExportCurrentFile(const char* exportPath) GetCOREInterface()->ExportToFile(exportPath); } -#include "plFile/hsFiles.h" +#include "hsFiles.h" void plExportDlgImp::IDoExport() { diff --git a/Sources/Tools/MaxMain/main.cpp b/Sources/Tools/MaxMain/main.cpp index 06a79654..d435c367 100644 --- a/Sources/Tools/MaxMain/main.cpp +++ b/Sources/Tools/MaxMain/main.cpp @@ -138,7 +138,7 @@ __declspec(dllexport) ULONG LibVersion() #include "plSDL/plSDL.h" #include "plMaxCFGFile.h" #include -#include "plFile/hsFiles.h" +#include "hsFiles.h" // // DLLMAIN diff --git a/Sources/Tools/MaxMain/plAgeDescInterface.cpp b/Sources/Tools/MaxMain/plAgeDescInterface.cpp index b06f1a1c..54b1c03b 100644 --- a/Sources/Tools/MaxMain/plAgeDescInterface.cpp +++ b/Sources/Tools/MaxMain/plAgeDescInterface.cpp @@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAgeDescInterface.h" #include "max.h" #include "resource.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plAgeDescription/plAgeDescription.h" #include "plMaxCFGFile.h" #include "hsStream.h" diff --git a/Sources/Tools/MaxMain/plPythonMgr.cpp b/Sources/Tools/MaxMain/plPythonMgr.cpp index 24d82ce6..88dbf883 100644 --- a/Sources/Tools/MaxMain/plPythonMgr.cpp +++ b/Sources/Tools/MaxMain/plPythonMgr.cpp @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "MaxComponent/plAutoUIBlock.h" //#include "Python.h" #include "plMaxCFGFile.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #include "plgDispatch.h" #include "pfPython/cyPythonInterface.h" diff --git a/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp b/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp index b71a514a..54482223 100644 --- a/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp +++ b/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp @@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plResManager.h" #include "plResMgr/plResMgrSettings.h" #include "plWinRegistryTools.h" -#include "plFile/hsFiles.h" +#include "hsFiles.h" #define IDC_REGTREEVIEW 1000