Browse Source

Merge pull request #275 from zrax/file-utils

Unify filesystem utilities
Adam Johnson 12 years ago
parent
commit
8f67596686
  1. 12
      Sources/Plasma/Apps/plClient/plClient.cpp
  2. 9
      Sources/Plasma/Apps/plClient/winmain.cpp
  3. 130
      Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp
  4. 2
      Sources/Plasma/Apps/plClientPatcher/UruPlayer.h
  5. 45
      Sources/Plasma/Apps/plFileEncrypt/main.cpp
  6. 57
      Sources/Plasma/Apps/plFileSecure/main.cpp
  7. 31
      Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp
  8. 4
      Sources/Plasma/Apps/plPageOptimizer/main.cpp
  9. 19
      Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.cpp
  10. 7
      Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.h
  11. 33
      Sources/Plasma/Apps/plPythonPack/PythonInterface.cpp
  12. 8
      Sources/Plasma/Apps/plPythonPack/PythonInterface.h
  13. 164
      Sources/Plasma/Apps/plPythonPack/main.cpp
  14. 38
      Sources/Plasma/Apps/plUruLauncher/Main.cpp
  15. 1
      Sources/Plasma/Apps/plUruLauncher/Pch.h
  16. 41
      Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp
  17. 1
      Sources/Plasma/CoreLib/HeadSpin.h
  18. 199
      Sources/Plasma/CoreLib/plFileSystem.cpp
  19. 59
      Sources/Plasma/CoreLib/plFileSystem.h
  20. 1
      Sources/Plasma/CoreLib/plString.cpp
  21. 10
      Sources/Plasma/CoreLib/plString.h
  22. 8
      Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp
  23. 12
      Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp
  24. 137
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  25. 10
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp
  26. 71
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp
  27. 6
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h
  28. 2
      Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp
  29. 1
      Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp
  30. 6
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp
  31. 58
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp
  32. 12
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h
  33. 2
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp
  34. 4
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h
  35. 10
      Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp
  36. 14
      Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.h
  37. 28
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  38. 11
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  39. 44
      Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp
  40. 10
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp
  41. 1
      Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp
  42. 25
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp
  43. 2
      Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h
  44. 4
      Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp
  45. 34
      Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp
  46. 18
      Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.h
  47. 12
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp
  48. 2
      Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp
  49. 7
      Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h
  50. 4
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2File/pnNpCli2File.h
  51. 3
      Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt
  52. 585
      Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp
  53. 1
      Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h
  54. 214
      Sources/Plasma/NucleusLib/pnUtils/pnUtPath.cpp
  55. 219
      Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h
  56. 140
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp
  57. 45
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.h
  58. 15
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp
  59. 17
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h
  60. 4
      Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp
  61. 4
      Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp
  62. 31
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp
  63. 6
      Sources/Plasma/PubUtilLib/plAudio/plSound.cpp
  64. 4
      Sources/Plasma/PubUtilLib/plAudio/plSound.h
  65. 12
      Sources/Plasma/PubUtilLib/plAudio/plWin32GroupedSound.cpp
  66. 43
      Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp
  67. 16
      Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.h
  68. 47
      Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp
  69. 13
      Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.h
  70. 5
      Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp
  71. 8
      Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.h
  72. 18
      Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp
  73. 11
      Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h
  74. 10
      Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.cpp
  75. 11
      Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.h
  76. 10
      Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp
  77. 21
      Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.h
  78. 85
      Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp
  79. 27
      Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h
  80. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp
  81. 12
      Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt
  82. 182
      Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp
  83. 141
      Sources/Plasma/PubUtilLib/plFile/hsFiles.h
  84. 146
      Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp
  85. 320
      Sources/Plasma/PubUtilLib/plFile/hsFiles_Win.cpp
  86. 30
      Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp
  87. 3
      Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.h
  88. 2
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  89. 503
      Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp
  90. 116
      Sources/Plasma/PubUtilLib/plFile/plFileUtils.h
  91. 3
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp
  92. 17
      Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp
  93. 2
      Sources/Plasma/PubUtilLib/plGImage/plFont.cpp
  94. 2
      Sources/Plasma/PubUtilLib/plGImage/plFont.h
  95. 33
      Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp
  96. 7
      Sources/Plasma/PubUtilLib/plGImage/plFontCache.h
  97. 27
      Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp
  98. 5
      Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h
  99. 6
      Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp
  100. 2
      Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.h
  101. Some files were not shown because too many files have changed in this diff Show More

12
Sources/Plasma/Apps/plClient/plClient.cpp

@ -58,7 +58,6 @@ 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 "plInputCore/plInputManager.h"
#include "plInputCore/plInputInterfaceMgr.h"
#include "plInputCore/plInputDevice.h"
@ -84,7 +83,6 @@ 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 "pfKI/pfKI.h"
@ -1636,19 +1634,17 @@ void plClient::IPatchGlobalAgeFiles( void )
void plClient::InitDLLs()
{
hsStatusMessage("Init dlls client\n");
char str[255];
typedef void (*PInitGlobalsFunc) (hsResMgr *, plFactory *, plTimerCallbackManager *, plTimerShare*,
plNetClientApp*);
hsFolderIterator modDllFolder("ModDLL\\");
while (modDllFolder.NextFileSuffix(".dll"))
std::vector<plFileName> dlls = plFileSystem::ListDir("ModDLL", "*.dll");
for (auto iter = dlls.begin(); iter != dlls.end(); ++iter)
{
modDllFolder.GetPathAndName(str);
HMODULE hMod = LoadLibrary(str);
HMODULE hMod = LoadLibraryW(iter->AsString().ToWchar());
if (hMod)
{
PInitGlobalsFunc initGlobals = (PInitGlobalsFunc)GetProcAddress(hMod, "InitGlobals");
initGlobals(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(),
(*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(),
hsTimer::GetTheTimer(), plNetClientApp::GetInstance());
fLoadedDLLs.Append(hMod);
}

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

@ -75,7 +75,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plStatusLog/plStatusLog.h"
#include "plProduct.h"
#include "plNetGameLib/plNetGameLib.h"
#include "plFile/plFileUtils.h"
#include "plPhysX/plSimulationMgr.h"
@ -542,7 +541,7 @@ bool InitClient( HWND hWnd )
resMgr->SetDataPath("dat");
hsgResMgr::Init(resMgr);
if(!plFileUtils::FileExists("resource.dat"))
if (!plFileInfo("resource.dat").Exists())
{
hsMessageBox("Required file 'resource.dat' not found.", "Error", hsMessageBoxNormal);
return false;
@ -817,10 +816,10 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password)
// loaded the namePassHash from the file
if (thePass.Compare(FAKE_PASS_STRING) != 0)
{
wchar_t domain[15];
PathSplitEmail(theUser.ToWchar(), nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0);
// Regex search for primary email domain
std::vector<plString> match = theUser.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+");
if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) {
if (match.empty() || match[2].CompareI("gametap") == 0) {
plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password);
uint32_t* dest = reinterpret_cast<uint32_t*>(pLoginParam->namePassHash);
const uint32_t* from = reinterpret_cast<const uint32_t*>(shasum.GetValue());

130
Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp

@ -66,19 +66,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
struct ManifestFile
{
ManifestFile(const wchar_t clientName[], const wchar_t downloadName[], const wchar_t md5val[], int flags, plLauncherInfo *info)
ManifestFile(const plFileName &clientName, const plFileName &downloadName, const plString &md5val, int flags, plLauncherInfo *info)
{
StrCopy(filename, clientName, arrsize(filename));
StrCopy(zipName, downloadName, arrsize(zipName));
StrCopy(md5, md5val, arrsize(md5));
filename = clientName;
zipName = downloadName;
md5 = md5val;
this->flags = flags;
this->info = info;
md5failed = false;
}
wchar_t filename[MAX_PATH];
wchar_t zipName[MAX_PATH];
wchar_t md5[MAX_PATH];
plFileName filename;
plFileName zipName;
plString md5;
int flags;
bool md5failed;
plLauncherInfo *info;
@ -117,10 +117,10 @@ struct ManifestResult {
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
);
@ -140,7 +140,7 @@ static unsigned s_fileListRequests;
static bool s_patchComplete;
static PROCESS_INFORMATION s_pi;
static long s_numFiles;
static char s_workingDir[MAX_PATH];
static plFileName s_workingDir;
static bool s_patchError;
static long s_asyncCoreInitCount;
static long s_numConnectFailures;
@ -179,9 +179,9 @@ double ProcessManifestEntryParam::startTime = 0;
// leaving clients with older patchers "dead in the water", without
// a way to play Uru.
#ifdef PLASMA_EXTERNAL_RELEASE
const wchar_t kPatcherExeFilename[] = L"UruLauncher.exe";
plFileName kPatcherExeFilename = "UruLauncher.exe";
#else
const wchar_t kPatcherExeFilename[] = L"plUruLauncher.exe";
plFileName kPatcherExeFilename = "plUruLauncher.exe";
#endif
@ -285,14 +285,11 @@ static void WaitUruExitProc (void * param) {
*/
//============================================================================
static bool MD5Check (const char filename[], const wchar_t md5[]) {
// Do md5 check
char md5copy[MAX_PATH];
static bool MD5Check (const plFileName& filename, const char *md5) {
plMD5Checksum existingMD5(filename);
plMD5Checksum latestMD5;
StrToAnsi(md5copy, md5, arrsize(md5copy));
latestMD5.SetFromHexString(md5copy);
latestMD5.SetFromHexString(md5);
return (existingMD5 == latestMD5);
}
@ -304,8 +301,7 @@ static void DecompressOgg (ManifestFile *mf) {
// decompress ogg if necessary
if ( (hsCheckBits(flags, plManifestFile::kSndFlagCacheSplit) || hsCheckBits(flags, plManifestFile::kSndFlagCacheStereo)) )
{
char path[MAX_PATH];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, mf->filename);
plFileName path = plFileName::Join(s_workingDir, mf->filename);
plAudioFileReader* reader = plAudioFileReader::CreateReader(path, plAudioCore::kAll, plAudioFileReader::kStreamNative);
if (!reader)
@ -355,12 +351,8 @@ static void RequestNextManifestFile () {
ManifestFile* nextfile = manifestQueue.front();
manifestQueue.pop();
char path[MAX_PATH];
wchar_t basePath[MAX_PATH];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, nextfile->filename);
StrToUnicode(basePath, path, arrsize(basePath));
PathRemoveFilename(basePath, basePath, arrsize(basePath));
PathCreateDirectory(basePath, kPathCreateDirFlagEntireTree);
plFileName path = plFileName::Join(s_workingDir, nextfile->filename);
plFileSystem::CreateDir(path.StripFileName(), true);
ProgressStream *writer = new ProgressStream(); // optimization: dont delete and recreate. Doesn't seem to be working currently, ZLibStream is breaking
if(!writer->Open(path, "wb"))
@ -374,7 +366,7 @@ static void RequestNextManifestFile () {
{
#ifndef PLASMA_EXTERNAL_RELEASE
char text[256];
StrPrintf(text, arrsize(text), "Updating URU... %S", nextfile->filename);
StrPrintf(text, arrsize(text), "Updating URU... %s", nextfile->filename.AsString().c_str());
nextfile->info->SetText(text);
#endif
NetCliFileDownloadRequest(nextfile->zipName, writer, DownloadCallback, nextfile, nextfile->info->buildId);
@ -383,19 +375,18 @@ static void RequestNextManifestFile () {
//============================================================================
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
) {
s_numConnectFailures = 0;
ManifestFile *mf = (ManifestFile *)param;
if (IS_NET_ERROR(result) && s_running && !s_patchError) {
if (result == kNetErrFileNotFound) {
char str[256];
StrPrintf(str, arrsize(str), "File not found on server: %S", filename);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
plString str = plString::Format("File not found on server: %s", filename.AsString().c_str());
MessageBox(nil, str.c_str(), "URU Launcher", MB_ICONERROR);
s_patchError = true;
}
else if (result == kNetErrRemoteShutdown) {
@ -414,24 +405,17 @@ static void DownloadCallback (
writer->Close();
delete writer; // delete our stream
char path[MAX_PATH];
StrPrintf(
path,
arrsize(path),
"%s%S",
s_workingDir,
mf->filename
);
if(s_running)
plFileName path = plFileName::Join(s_workingDir, mf->filename);
if (s_running)
{
if(!MD5Check(path, mf->md5)) {
if(mf->md5failed)
if (!MD5Check(path, mf->md5.c_str())) {
if (mf->md5failed)
{
#ifdef PLASMA_EXTERNAL_RELEASE
MessageBox(nil, s_md5CheckError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s ", path, s_md5CheckError);
StrPrintf(str, arrsize(str), "%s %s ", path.AsString().c_str(), s_md5CheckError);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif // PLASMA_EXTERNAL_RELEASE
Shutdown(mf->info);
@ -442,7 +426,7 @@ static void DownloadCallback (
MessageBox(nil, s_fileOpenError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s", s_fileOpenError, path);
StrPrintf(str, arrsize(str), "%s %s", s_fileOpenError, path.AsString().c_str());
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif // PLASMA_EXTERNAL_RELEASE
Shutdown(mf->info);
@ -456,11 +440,9 @@ static void DownloadCallback (
AtomicAdd(&s_numFiles, -1);
if(s_running)
if (s_running)
{
wchar_t ext[MAX_EXT];
PathSplitPath(mf->filename, nil, nil, nil, ext);
if(!StrCmpI(L".ogg", ext))
if (!mf->filename.GetFileExt().CompareI("ogg"))
{
DecompressOgg(mf);
}
@ -490,16 +472,9 @@ static void ProcessManifestEntry (void * param, ENetError error) {
StrPrintf(text, arrsize(text), "Checking for updates... %S", p->mr->manifest[p->index].clientName);
p->mr->info->SetText(text);
#endif
char path[MAX_PATH];
StrPrintf(
path,
arrsize(path),
"%s%S",
s_workingDir,
p->mr->manifest[p->index].clientName
);
plFileName path = plFileName::Join(s_workingDir, p->mr->manifest[p->index].clientName);
uint32_t start = (uint32_t)(TimeGetTime() / kTimeIntervalsPerMs);
if(!MD5Check(path, p->mr->manifest[p->index].md5)) {
if (!MD5Check(path, p->mr->manifest[p->index].md5.c_str())) {
p->mr->critsect.Lock();
p->mr->indices.Add(p->index);
p->mr->critsect.Unlock();
@ -547,8 +522,6 @@ static void ProcessManifest (void * param) {
VLDEnable();
#endif
wchar_t basePath[MAX_PATH];
char path[MAX_PATH];
AtomicAdd(&s_perf[kPerfThreadTaskCount], 1);
ManifestResult * mr = (ManifestResult *)param;
@ -574,14 +547,13 @@ static void ProcessManifest (void * param) {
p->index = i;
p->mr = mr;
p->exists = false;
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, mr->manifest[i].clientName);
fd = fopen(path, "r");
if(fd)
plFileName path = plFileName::Join(s_workingDir, mr->manifest[i].clientName);
fd = plFileSystem::Open(path, "r");
if (fd)
{
p->exists = true;
p->totalSize += p->mr->manifest[i].zipSize;
fclose(fd);
}
}
@ -617,10 +589,8 @@ static void ProcessManifest (void * param) {
if(s_running)
{
unsigned index = mr->indices[i];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, manifest[index].clientName);
StrToUnicode(basePath, path, arrsize(basePath));
PathRemoveFilename(basePath, basePath, arrsize(basePath));
PathCreateDirectory(basePath, kPathCreateDirFlagEntireTree);
plFileName path = plFileName::Join(s_workingDir, manifest[index].clientName);
plFileSystem::CreateDir(path.StripFileName(), true);
ManifestFile* mf = new ManifestFile(
manifest[index].clientName,
@ -637,7 +607,7 @@ static void ProcessManifest (void * param) {
MessageBox(nil, s_fileOpenError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s", path, s_fileOpenError);
StrPrintf(str, arrsize(str), "%s %s", path.AsString().c_str(), s_fileOpenError);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif
Shutdown(mr->info);
@ -711,7 +681,7 @@ static void ManifestCallback (
noDuplicates.Reserve(mr->manifest.Count());
for(unsigned i = 0; i < entryCount - 1; ++i)
{
if(StrCmp(mr->manifest[i].clientName, mr->manifest[i+1].clientName))
if (mr->manifest[i].clientName != mr->manifest[i+1].clientName)
{
noDuplicates.Add(mr->manifest[i]);
}
@ -759,11 +729,12 @@ static void ThinManifestCallback (
return;
}
s_patchComplete = true;
char path[MAX_PATH];
for (unsigned i = 0; i < entryCount; ++i) {
if(!s_running) return;
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, manifest[i].clientName);
if(!MD5Check(path, manifest[i].md5)){
if (!s_running)
return;
plFileName path = plFileName::Join(s_workingDir, manifest[i].clientName);
if (!MD5Check(path, manifest[i].md5.c_str())) {
s_patchComplete = false;
NetCliFileManifestRequest(ManifestCallback, info, s_manifest, info->buildId);
break;
@ -775,7 +746,7 @@ static void ThinManifestCallback (
info->progressCallback(kStatusPending, &patchInfo);
#ifndef PLASMA_EXTERNAL_RELEASE
char text[256];
StrPrintf(text, arrsize(text), "Checking for updates... %S", manifest[i].clientName);
StrPrintf(text, arrsize(text), "Checking for updates... %s", manifest[i].clientName.AsString().c_str());
info->SetText(text);
#endif
}
@ -894,8 +865,7 @@ void UruPrepProc (void * param) {
s_running = true;
plLauncherInfo *info = (plLauncherInfo *) param;
StrToAnsi(s_workingDir, info->path, arrsize(s_workingDir));
s_workingDir = plString::FromWchar(info->path);
InitAsyncCore();
NetClientInitialize();

2
Sources/Plasma/Apps/plClientPatcher/UruPlayer.h

@ -64,4 +64,4 @@ void UruStartProc (void * param);
void PlayerTerminateProc (void * param);
void PlayerStopProc (void * param);
extern const wchar_t kPatcherExeFilename[];
extern plFileName kPatcherExeFilename;

45
Sources/Plasma/Apps/plFileEncrypt/main.cpp

@ -39,25 +39,25 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include "plFile/hsFiles.h"
#include "plFile/plEncryptedStream.h"
#include "plProduct.h"
void EncryptFiles(const char* dir, const char* ext, bool encrypt);
void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt);
void print_version() {
printf("%s\n\n", plProduct::ProductString().c_str());
puts(plProduct::ProductString().c_str());
puts("");
}
void print_help() {
printf("plFileEncrypt - Encrypts and Decrypts Uru Files.\n\n");
puts("plFileEncrypt - Encrypts and Decrypts Uru Files.\n");
print_version();
printf("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]\n");
printf("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n");
printf("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n");
printf("\t--help|-h|-?|/h\t - Prints Help. This Screen.\n");
printf("\t-v|--version\t - Prints build version information\n");
puts("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]");
puts("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.");
puts("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.");
puts("\t--help|-h|-?|/h\t - Prints Help. This Screen.");
puts("\t-v|--version\t - Prints build version information");
}
int main(int argc, char *argv[])
@ -93,31 +93,28 @@ int main(int argc, char *argv[])
}
#undef ARGCMP
EncryptFiles(dir, ".age", encrypt);
EncryptFiles(dir, ".fni", encrypt);
EncryptFiles(dir, ".ini", encrypt);
EncryptFiles(dir, ".sdl", encrypt);
EncryptFiles(dir, ".csv", encrypt);
EncryptFiles(dir, "*.age", encrypt);
EncryptFiles(dir, "*.fni", encrypt);
EncryptFiles(dir, "*.ini", encrypt);
EncryptFiles(dir, "*.sdl", encrypt);
EncryptFiles(dir, "*.csv", encrypt);
return 0;
}
void EncryptFiles(const char* dir, const char* ext, bool encrypt)
void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt)
{
char filePath[256];
hsFolderIterator folder(dir);
while (folder.NextFileSuffix(ext))
std::vector<plFileName> files = plFileSystem::ListDir(dir, ext);
for (auto iter = files.begin(); iter != files.end(); ++iter)
{
folder.GetPathAndName(filePath);
if (encrypt)
{
printf("encrypting: %s\n", folder.GetFileName());
plEncryptedStream::FileEncrypt(filePath);
printf("encrypting: %s\n", iter->GetFileName().c_str());
plEncryptedStream::FileEncrypt(*iter);
}
else
{
printf("decrypting: %s\n", folder.GetFileName());
plEncryptedStream::FileDecrypt(filePath);
printf("decrypting: %s\n", iter->GetFileName().c_str());
plEncryptedStream::FileDecrypt(*iter);
}
}
}

57
Sources/Plasma/Apps/plFileSecure/main.cpp

@ -39,8 +39,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plFile/plSecureStream.h"
#include "plProduct.h"
@ -49,26 +47,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <string>
void print_version() {
printf("%s\n\n", plProduct::ProductString().c_str());
puts(plProduct::ProductString().c_str());
puts("");
}
void print_help() {
printf("plFileSecure - Secures Uru files and generates encryption.key files.\n\n");
puts ("plFileSecure - Secures Uru files and generates encryption.key files.\n");
print_version();
printf("Usage:\n");
printf("\tplFileSecure (<directory> <ext>)|[/generate /default]\n");
printf("\n");
printf("<directory> <ext> : The directory and extension of files to secure. Cannot\n");
puts ("Usage:");
puts ("\tplFileSecure (<directory> <ext>)|[/generate /default]");
puts ("");
puts ("<directory> <ext> : The directory and extension of files to secure. Cannot");
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");
puts (" the current directory (or default key if no file exists)");
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(" <directory> <ext>\n");
puts (" file in the current directory. Cannot be used with");
puts (" <directory> <ext>");
printf("/default : If used with /generate, creates a %s file\n", plSecureStream::kKeyFilename);
printf(" with the default key. If used with <directory> <ext>, it\n");
printf(" secures with the default key instead of the\n");
puts (" with the default key. If used with <directory> <ext>, it");
puts (" secures with the default key instead of the");
printf(" %s file's key\n", plSecureStream::kKeyFilename);
printf("\n");
puts ("");
}
void GenerateKey(bool useDefault)
@ -106,16 +105,13 @@ void GenerateKey(bool useDefault)
out.Close();
}
void SecureFiles(std::string dir, std::string ext, uint32_t* key)
void SecureFiles(const plFileName& dir, const plString& ext, uint32_t* key)
{
char filePath[256];
hsFolderIterator folder(dir.c_str());
while (folder.NextFileSuffix(ext.c_str()))
std::vector<plFileName> files = plFileSystem::ListDir(dir, ext.c_str());
for (auto iter = files.begin(); iter != files.end(); ++iter)
{
folder.GetPathAndName(filePath);
printf("securing: %s\n", folder.GetFileName());
plSecureStream::FileEncrypt(filePath, key);
printf("securing: %s\n", iter->GetFileName());
plSecureStream::FileEncrypt(*iter, key);
}
}
@ -123,8 +119,8 @@ int main(int argc, char *argv[])
{
bool generatingKey = false;
bool useDefault = false;
std::string directory;
std::string ext;
plFileName directory;
plString ext;
if (argc > 1)
{
@ -164,9 +160,9 @@ int main(int argc, char *argv[])
else
{
// else it is a directory or extension
if (directory == "")
if (!directory.IsValid())
directory = argv[i];
else if (ext == "")
else if (ext.IsEmpty())
ext = argv[i];
else
{
@ -176,7 +172,7 @@ int main(int argc, char *argv[])
}
}
if (generatingKey && ((directory != "") || (ext != "")))
if (generatingKey && ((directory.IsValid()) || (!ext.IsEmpty())))
{
print_help();
return 0;
@ -194,8 +190,11 @@ int main(int argc, char *argv[])
return 0;
}
if (ext[0] != '.')
ext = "." + ext; // tack on the dot if necessary
// Make sure ext is a real pattern, or we won't find anything
if (ext.CharAt(0) == '.')
ext = "*" + ext;
else if (ext.CharAt(0) != '*')
ext = "*." + ext;
if (useDefault)
SecureFiles(directory, ext, nil);

31
Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp

@ -41,8 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "hsTimer.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plResMgr/plResManager.h"
#include "plResMgr/plResMgrSettings.h"
@ -61,7 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
plResManager* gResMgr = nil;
bool DumpStats(const char* patchDir);
bool DumpStats(const plFileName& patchDir);
bool DumpSounds();
//// PrintVersion ///////////////////////////////////////////////////////////////
@ -117,7 +115,7 @@ int main(int argc, char* argv[])
}
// Make sure we have 1 arg left after getting the options
char* pageFile = nil;
plFileName pageFile;
if (arg < argc)
pageFile = argv[arg];
else
@ -134,12 +132,7 @@ int main(int argc, char* argv[])
if (sounds)
DumpSounds();
if (stats)
{
char path[256];
strcpy(path, pageFile);
plFileUtils::StripFile(path);
DumpStats(path);
}
DumpStats(pageFile.StripFileName());
hsgResMgr::Shutdown();
@ -180,12 +173,12 @@ bool DumpSounds()
buffer->GetKey()->RefObject();
// Get the filename from it and add that file if necessary
const char* filename = buffer->GetFileName();
if (filename)
plFileName filename = buffer->GetFileName();
if (filename.IsValid())
{
uint32_t flags = 0;
if (stricmp(plFileUtils::GetFileExt(filename), "wav") != 0)
if (filename.GetFileExt().CompareI("wav") != 0)
{
if (buffer->HasFlag(plSoundBuffer::kOnlyLeftChannel) ||
buffer->HasFlag(plSoundBuffer::kOnlyRightChannel))
@ -196,7 +189,7 @@ bool DumpSounds()
hsSetBits(flags, plManifestFile::kSndFlagCacheStereo);
}
printf("%s,%u\n", filename, flags);
printf("%s,%u\n", filename.AsString().c_str(), flags);
}
// Unref the object so it goes away
@ -218,11 +211,11 @@ bool DumpSounds()
class plStatDumpIterator : public plRegistryPageIterator, public plRegistryKeyIterator
{
protected:
const char* fOutputDir;
plFileName fOutputDir;
hsUNIXStream fStream;
public:
plStatDumpIterator(const char* outputDir) : fOutputDir(outputDir) {}
plStatDumpIterator(const plFileName& outputDir) : fOutputDir(outputDir) {}
bool EatKey(const plKey& key)
{
@ -246,8 +239,8 @@ public:
{
const plPageInfo& info = page->GetPageInfo();
char fileName[256];
sprintf(fileName, "%s%s_%s.csv", fOutputDir, info.GetAge().c_str(), info.GetPage().c_str());
plFileName fileName = plFileName::Join(fOutputDir,
plString::Format("%s_%s.csv", info.GetAge().c_str(), info.GetPage().c_str()));
fStream.Open(fileName, "wt");
page->LoadKeys();
@ -259,7 +252,7 @@ public:
}
};
bool DumpStats(const char* patchDir)
bool DumpStats(const plFileName& patchDir)
{
plStatDumpIterator statDump(patchDir);
gResMgr->IterateAllPages(&statDump);

4
Sources/Plasma/Apps/plPageOptimizer/main.cpp

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plResMgr/plResManager.h"
#include "plPageOptimizer.h"
#include "plFile/plFileUtils.h"
#include "pnNetCommon/plSynchedObject.h"
int main(int argc, char* argv[])
@ -53,7 +52,8 @@ int main(int argc, char* argv[])
return 1;
}
printf("Optimizing %s...", plFileUtils::GetFileName(argv[1]));
plFileName filename = argv[1];
printf("Optimizing %s...", filename.GetFileName().c_str());
#ifndef _DEBUG
try {

19
Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.cpp

@ -50,21 +50,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKeyImp.h"
#include "plFile/plFileUtils.h"
#include "hsStream.h"
plPageOptimizer* plPageOptimizer::fInstance = nil;
plPageOptimizer::plPageOptimizer(const char* pagePath) :
plPageOptimizer::plPageOptimizer(const plFileName& pagePath) :
fOptimized(true),
fPageNode(nil),
fPagePath(pagePath)
{
fInstance = this;
strcpy(fTempPagePath, fPagePath);
plFileUtils::StripExt(fTempPagePath);
strcat(fTempPagePath, "_opt.prp");
fTempPagePath = fPagePath.StripFileExt() + "_opt.prp";
fResMgr = (plResManager*)hsgResMgr::ResMgr();
}
@ -135,8 +132,8 @@ void plPageOptimizer::Optimize()
if (loaded)
IRewritePage();
uint32_t oldSize = plFileUtils::GetFileSize(fPagePath);
uint32_t newSize = plFileUtils::GetFileSize(fTempPagePath);
uint64_t oldSize = plFileInfo(fPagePath).FileSize();
uint64_t newSize = plFileInfo(fTempPagePath).FileSize();
if (!loaded)
{
@ -144,19 +141,19 @@ void plPageOptimizer::Optimize()
}
else if (fOptimized)
{
plFileUtils::RemoveFile(fTempPagePath);
plFileSystem::Unlink(fTempPagePath);
puts("already optimized.");
}
else if (oldSize == newSize)
{
plFileUtils::RemoveFile(fPagePath, true);
plFileUtils::FileMove(fTempPagePath, fPagePath);
plFileSystem::Unlink(fPagePath);
plFileSystem::Move(fTempPagePath, fPagePath);
puts("complete");
}
else
{
plFileUtils::RemoveFile(fTempPagePath);
plFileSystem::Unlink(fTempPagePath);
puts("failed. File sizes different");
}
}

7
Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.h

@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plKey.h"
#include "pnKeyedObject/plUoid.h"
#include "plFileSystem.h"
#include <vector>
#include <set>
@ -63,8 +64,8 @@ protected:
bool fOptimized; // True after optimization if the page was already optimized
const char* fPagePath; // Path to our page
char fTempPagePath[512]; // Path to the temp output page
plFileName fPagePath; // Path to our page
plFileName fTempPagePath; // Path to the temp output page
plLocation fLoc; // Location of our page
plRegistryPageNode* fPageNode; // PageNode for our page
@ -78,7 +79,7 @@ protected:
void IRewritePage();
public:
plPageOptimizer(const char* pagePath);
plPageOptimizer(const plFileName& pagePath);
void Optimize();
};

33
Sources/Plasma/Apps/plPythonPack/PythonInterface.cpp

@ -45,10 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "eval.h"
#include "marshal.h"
#include "cStringIO.h"
#include "plFileSystem.h"
static PyObject* stdFile; // python object of the stdout and err file
void PythonInterface::initPython(std::string rootDir)
void PythonInterface::initPython(const plFileName& rootDir)
{
// if haven't been initialized then do it
if ( Py_IsInitialized() == 0 )
@ -77,27 +78,27 @@ void PythonInterface::initPython(std::string rootDir)
PyObject* sys_dict = PyModule_GetDict(sysmod);
if (stdFile != nil)
{
PyDict_SetItemString(sys_dict,"stdout", stdFile);
PyDict_SetItemString(sys_dict,"stderr", stdFile);
PyDict_SetItemString(sys_dict, "stdout", stdFile);
PyDict_SetItemString(sys_dict, "stderr", stdFile);
}
// NOTE: we will reset the path to not include paths
// ...that Python may have found in the registery
PyObject* path_list = PyList_New(0);
printf("Setting up include dirs:\n");
printf("%s\n",rootDir.c_str());
PyObject* more_path = PyString_FromString(rootDir.c_str());
printf("%s\n", rootDir.AsString().c_str());
PyObject* more_path = PyString_FromString(rootDir.AsString().c_str());
PyList_Append(path_list, more_path);
// make sure that our plasma libraries are gotten before the system ones
std::string temp = rootDir + "plasma";
printf("%s\n",temp.c_str());
PyObject* more_path3 = PyString_FromString(temp.c_str());
plFileName temp = plFileName::Join(rootDir, "plasma");
printf("%s\n", temp.AsString().c_str());
PyObject* more_path3 = PyString_FromString(temp.AsString().c_str());
PyList_Append(path_list, more_path3);
temp = rootDir + "system";
printf("%s\n\n",temp.c_str());
temp = plFileName::Join(rootDir, "system");
printf("%s\n\n", temp.AsString().c_str());
PyObject* more_path2 = PyString_FromString("system");
PyList_Append(path_list, more_path2);
// set the path to be this one
PyDict_SetItemString(sys_dict,"path",path_list);
PyDict_SetItemString(sys_dict, "path", path_list);
Py_DECREF(sysmod);
@ -106,7 +107,7 @@ void PythonInterface::initPython(std::string rootDir)
// initialized++;
}
void PythonInterface::addPythonPath(std::string path)
void PythonInterface::addPythonPath(const plFileName& path)
{
PyObject* sysmod = PyImport_ImportModule("sys");
if (sysmod != NULL)
@ -114,8 +115,8 @@ void PythonInterface::addPythonPath(std::string path)
PyObject* sys_dict = PyModule_GetDict(sysmod);
PyObject* path_list = PyDict_GetItemString(sys_dict, "path");
printf("Adding path %s\n", path.c_str());
PyObject* more_path = PyString_FromString(path.c_str());
printf("Adding path %s\n", path.AsString().c_str());
PyObject* more_path = PyString_FromString(path.AsString().c_str());
PyList_Append(path_list, more_path);
Py_DECREF(sysmod);
@ -138,9 +139,9 @@ void PythonInterface::finiPython()
//
// PURPOSE : run a python string in a specific module name
//
PyObject* PythonInterface::CompileString(const char *command, const char* filename)
PyObject* PythonInterface::CompileString(const char *command, const plFileName& filename)
{
PyObject* pycode = Py_CompileString(command, filename, Py_file_input);
PyObject* pycode = Py_CompileString(command, filename.AsString().c_str(), Py_file_input);
return pycode;
}

8
Sources/Plasma/Apps/plPythonPack/PythonInterface.h

@ -44,14 +44,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <string>
class plFileName;
namespace PythonInterface
{
void initPython(std::string rootDir);
void initPython(const plFileName& rootDir);
void finiPython();
// So the Python packer can add extra paths
void addPythonPath(std::string dir);
void addPythonPath(const plFileName& dir);
PyObject* CompileString(const char *command, const char* filename);
PyObject* CompileString(const char *command, const plFileName& filename);
bool DumpObject(PyObject* pyobj, char** pickle, int32_t* size);
int getOutputAndReset(char** line=nil);
PyObject* CreateModule(const char* module);

164
Sources/Plasma/Apps/plPythonPack/main.cpp

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "PythonInterface.h"
#include "hsStream.h"
#include "plFile/hsFiles.h"
#include <vector>
#include <string>
@ -71,25 +70,24 @@ static const char* kPackFileName = "python.pak";
#endif
static char* glueFile = (char*)kGlueFile;
void WritePythonFile(std::string fileName, std::string path, hsStream *s)
void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStream *s)
{
hsUNIXStream pyStream, glueStream;
std::string filePath;
size_t filestart = fileName.find_last_of('.');
if(filestart != std::string::npos)
filePath = fileName.substr(filestart+1, std::string::npos);
plFileName filePath;
size_t filestart = fileName.AsString().FindLast('.');
if (filestart >= 0)
filePath = fileName.AsString().Substr(filestart+1);
else
filePath = fileName;
filePath += ".py";
filePath = path + filePath;
filePath = plFileName::Join(path, filePath + ".py");
if (!pyStream.Open(filePath.c_str()) || !glueStream.Open(glueFile))
if (!pyStream.Open(filePath) || !glueStream.Open(glueFile))
{
printf("Unable to open path %s, ",filePath.c_str());
printf("Unable to open path %s, ", filePath.AsString().c_str());
return;
}
printf("==Packing %s, ",fileName.c_str());
printf("==Packing %s, ", fileName.AsString().c_str());
pyStream.FastFwd();
uint32_t pyFileSize = pyStream.GetPosition();
@ -124,20 +122,20 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
}
// import the module first, to make packages work correctly
PyImport_ImportModule(fileName.c_str());
PyObject* pythonCode = PythonInterface::CompileString(code, fileName.c_str());
PyImport_ImportModule(fileName.AsString().c_str());
PyObject* pythonCode = PythonInterface::CompileString(code, fileName);
if (pythonCode)
{
// we need to find out if this is PythonFile module
// create a module name... with the '.' as an X
// and create a python file name that is without the ".py"
PyObject* fModule = PythonInterface::CreateModule(fileName.c_str());
PyObject* fModule = PythonInterface::CreateModule(fileName.AsString().c_str());
// run the code
if (PythonInterface::RunPYC(pythonCode, fModule) )
{
// set the name of the file (in the global dictionary of the module)
PyObject* dict = PyModule_GetDict(fModule);
PyObject* pfilename = PyString_FromString(fileName.c_str());
PyObject* pfilename = PyString_FromString(fileName.AsString().c_str());
PyDict_SetItemString(dict, "glue_name", pfilename);
// next we need to:
// - create instance of class
@ -167,7 +165,7 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
// else
// skip the CRs
}
pythonCode = PythonInterface::CompileString(code, fileName.c_str());
pythonCode = PythonInterface::CompileString(code, fileName);
hsAssert(pythonCode,"Not sure why this didn't compile the second time???");
printf("an import file ");
}
@ -227,23 +225,15 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
glueStream.Close();
}
void FindFiles(std::vector<std::string> &filenames, std::vector<std::string> &pathnames, const char* path)
void FindFiles(std::vector<plFileName> &filenames, std::vector<plFileName> &pathnames, const plFileName& path)
{
// Get the names of all the python files
hsFolderIterator folder;
std::vector<plFileName> pys = plFileSystem::ListDir(path, "*.py");
// if there is a path... set it
if ( path )
folder.SetPath(path);
while (folder.NextFileSuffix(".py"))
for (auto iter = pys.begin(); iter != pys.end(); ++iter)
{
const char *fileName = folder.GetFileName();
filenames.push_back(fileName);
if ( path )
pathnames.push_back(path);
else
pathnames.push_back("");
filenames.push_back(iter->GetFileName());
pathnames.push_back(path);
}
}
@ -260,22 +250,13 @@ std::string ToLowerCase(std::string str)
return retVal;
}
void FindSubDirs(std::vector<std::string> &dirnames, const char *path)
void FindSubDirs(std::vector<plFileName> &dirnames, const plFileName &path)
{
hsFolderIterator folder;
if (path)
folder.SetPath(path);
while (folder.NextFile())
{
if (folder.IsDirectory())
{
std::string dirName = folder.GetFileName();
if ((dirName != ".")&&(dirName != "..")&&(ToLowerCase(dirName) != "system") && (ToLowerCase(dirName) != "plasma"))
{
dirnames.push_back(dirName);
}
}
std::vector<plFileName> subdirs = plFileSystem::ListSubdirs(path);
for (auto iter = subdirs.begin(); iter != subdirs.end(); ++iter) {
plString name = iter->GetFileName();
if (name.CompareI("system") != 0 && name.CompareI("plasma") != 0)
dirnames.push_back(name);
}
}
@ -343,66 +324,62 @@ std::string ConcatDirs(std::string fullPath, std::string partialPath)
return retVal;
}
void FindPackages(std::vector<std::string>& fileNames, std::vector<std::string>& pathNames, const char* path, std::string parent_package="")
void FindPackages(std::vector<plFileName>& fileNames, std::vector<plFileName>& pathNames, const plFileName& path, const plString& parent_package="")
{
std::vector<std::string> packages;
std::vector<plFileName> packages;
FindSubDirs(packages, path);
for (int i = 0; i < packages.size(); i++)
{
std::string packageName;
if(!parent_package.empty())
plString packageName;
if (!parent_package.IsEmpty())
packageName = parent_package + ".";
packageName += packages[i];
std::vector<std::string> packageFileNames;
std::vector<std::string> packagePathNames;
std::string packagePath = path;
packagePath += "/" + packages[i];
FindFiles(packageFileNames, packagePathNames, packagePath.c_str());
packageName += packages[i].AsString();
std::vector<plFileName> packageFileNames;
std::vector<plFileName> packagePathNames;
plFileName packagePath = plFileName::Join(path, packages[i]);
FindFiles(packageFileNames, packagePathNames, packagePath);
for (int j = 0; j < packageFileNames.size(); j++) {
fileNames.push_back(packageName+"."+packageFileNames[j]);
pathNames.push_back(packagePathNames[j]+"/");
fileNames.push_back(packageName+"."+packageFileNames[j].AsString());
pathNames.push_back(packagePathNames[j]);
}
FindPackages(fileNames, pathNames, packagePath.c_str(), packageName);
FindPackages(fileNames, pathNames, packagePath, packageName);
}
}
void PackDirectory(std::string dir, std::string rootPath, std::string pakName, std::vector<std::string>& extraDirs, bool packSysAndPlasma = false)
void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector<plFileName>& extraDirs, bool packSysAndPlasma = false)
{
// make sure the dir ends in a slash
dir = AdjustEndingSlash(dir,true);
printf("\nCreating %s using the contents of %s\n",pakName.c_str(),dir.c_str());
printf("Changing working directory to %s\n",rootPath.c_str());
if (chdir(rootPath.c_str()))
printf("\nCreating %s using the contents of %s\n", pakName.AsString().c_str(), dir.AsString().c_str());
printf("Changing working directory to %s\n", rootPath.AsString().c_str());
if (!plFileSystem::SetCWD(rootPath))
{
printf("ERROR: Directory change to %s failed for some reason\n",rootPath.c_str());
printf("ERROR: Directory change to %s failed for some reason\n", rootPath.AsString().c_str());
printf("Unable to continue with the packing of this directory, aborting...\n");
return;
}
else
printf("Directory changed to %s\n",rootPath.c_str());
printf("Directory changed to %s\n", rootPath.AsString().c_str());
std::vector<std::string> fileNames;
std::vector<std::string> pathNames;
std::vector<plFileName> fileNames;
std::vector<plFileName> pathNames;
FindFiles(fileNames,pathNames,dir.c_str());
FindPackages(fileNames,pathNames,dir.c_str());
FindFiles(fileNames, pathNames, dir);
FindPackages(fileNames, pathNames, dir);
if (packSysAndPlasma)
{
printf("Adding the system and plasma directories to this pack file\n");
std::string tempPath;
tempPath = dir + "system/";
FindFiles(fileNames,pathNames,tempPath.c_str());
FindPackages(fileNames,pathNames,tempPath.c_str());
tempPath = dir + "plasma/";
FindFiles(fileNames,pathNames,tempPath.c_str());
FindPackages(fileNames,pathNames,tempPath.c_str());
plFileName tempPath;
tempPath = plFileName::Join(dir, "system");
FindFiles(fileNames, pathNames, tempPath);
FindPackages(fileNames, pathNames, tempPath);
tempPath = plFileName::Join(dir, "plasma");
FindFiles(fileNames, pathNames, tempPath);
FindPackages(fileNames, pathNames, tempPath);
}
// ok, we know how many files we're gonna pack, so make a fake index (we'll fill in later)
hsUNIXStream s;
if (!s.Open(pakName.c_str(), "wb"))
if (!s.Open(pakName, "wb"))
return;
s.WriteLE32(fileNames.size());
@ -410,13 +387,13 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
int i;
for (i = 0; i < fileNames.size(); i++)
{
s.WriteSafeString(fileNames[i].c_str());
s.WriteSafeString(fileNames[i].AsString());
s.WriteLE32(0);
}
PythonInterface::initPython(rootPath);
for (i = 0; i < extraDirs.size(); i++)
PythonInterface::addPythonPath(rootPath + extraDirs[i]);
PythonInterface::addPythonPath(plFileName::Join(rootPath, extraDirs[i]));
// set to maximum optimization (includes removing __doc__ strings)
Py_OptimizeFlag = 2;
@ -427,7 +404,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
for (i = 0; i < fileNames.size(); i++)
{
// strip '.py' from the file name
std::string properFileName = fileNames[i].substr(0, fileNames[i].size()-3);
plFileName properFileName = fileNames[i].StripFileExt();
uint32_t initialPos = s.GetPosition();
WritePythonFile(properFileName, pathNames[i], &s);
uint32_t endPos = s.GetPosition();
@ -438,7 +415,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
s.SetPosition(sizeof(uint32_t));
for (i = 0; i < fileNames.size(); i++)
{
s.WriteSafeString(fileNames[i].c_str());
s.WriteSafeString(fileNames[i].AsString());
s.WriteLE32(filePositions[i]);
}
@ -459,9 +436,7 @@ int main(int argc, char *argv[])
{
printf("The Python Pack Utility\n");
char buffer[MAXPATHLEN];
getcwd(buffer, MAXPATHLEN);
std::string baseWorkingDir = buffer;
plFileName baseWorkingDir = plFileSystem::GetCWD();
// are they asking for usage?
if (argc == 2)
@ -482,26 +457,25 @@ int main(int argc, char *argv[])
return -1;
}
std::vector<std::string> dirNames;
std::string rootPath;
std::vector<plFileName> dirNames;
plFileName rootPath;
if (argc == 1)
{
FindSubDirs(dirNames,nil);
rootPath = AdjustEndingSlash(baseWorkingDir,true);
FindSubDirs(dirNames, "");
rootPath = baseWorkingDir;
}
else
{
std::string path = argv[1];
FindSubDirs(dirNames,argv[1]);
rootPath = ConcatDirs(baseWorkingDir,path);
rootPath = AdjustEndingSlash(rootPath,true);
plFileName path = argv[1];
FindSubDirs(dirNames, argv[1]);
rootPath = plFileName::Join(baseWorkingDir, path);
}
PackDirectory(rootPath,rootPath,rootPath+kPackFileName,dirNames,true);
PackDirectory(rootPath, rootPath, plFileName::Join(rootPath, kPackFileName), dirNames, true);
for (int i=0; i<dirNames.size(); i++)
{
PackDirectory(dirNames[i],rootPath,rootPath+dirNames[i]+".pak",dirNames);
PackDirectory(dirNames[i], rootPath, plFileName::Join(rootPath, dirNames[i]+".pak"), dirNames);
}
return 0;

38
Sources/Plasma/Apps/plUruLauncher/Main.cpp

@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h"
#include "hsThread.h"
#include <algorithm>
#pragma hdrstop
@ -128,7 +129,7 @@ static hsSemaphore s_dialogCreateEvent(0);
static hsMutex s_critsect;
static LISTDECL(WndEvent, link) s_eventQ;
static hsSemaphore s_shutdownEvent(0);
static wchar_t s_workingDir[MAX_PATH];
static plFileName s_workingDir;
static hsSemaphore s_statusEvent(0);
static char s_curlError[CURL_ERROR_SIZE];
@ -619,18 +620,15 @@ int __stdcall WinMain (
while (*appCmdLine == L' ')
++appCmdLine;
wchar_t curPatcherFile[MAX_PATH];
wchar_t newPatcherFile[MAX_PATH];
bool isTempPatcher = false;
PathGetProgramName(curPatcherFile, arrsize(curPatcherFile));
PathRemoveFilename(newPatcherFile, curPatcherFile, arrsize(newPatcherFile));
PathAddFilename(newPatcherFile, newPatcherFile, kPatcherExeFilename, arrsize(newPatcherFile));
plFileName curPatcherFile = plFileSystem::GetCurrentAppPath();
plFileName newPatcherFile = plFileName::Join(curPatcherFile.StripFileName(), kPatcherExeFilename);
// If our exe name doesn't match the "real" patcher exe name, then we are a newly
// downloaded patcher that needs to be copied over to the "real" exe.. so do that,
// exec it, and exit.
if (0 != StrCmpI(curPatcherFile, newPatcherFile)) {
if (0 != curPatcherFile.AsString().CompareI(newPatcherFile.AsString())) {
isTempPatcher = true;
}
@ -638,7 +636,7 @@ int __stdcall WinMain (
cmdParser.Parse();
if (!cmdParser.IsSpecified(kArgCwd))
PathGetProgramDirectory(s_workingDir, arrsize(s_workingDir));
s_workingDir = plFileSystem::GetCurrentAppPath().StripFileName();
s_hInstance = hInstance;
memset(&s_launcherInfo, 0, sizeof(s_launcherInfo));
@ -683,7 +681,7 @@ int __stdcall WinMain (
for (;;) {
// Wait for previous process to exit. This will happen if we just patched.
HANDLE mutex = CreateMutexW(NULL, TRUE, kPatcherExeFilename);
HANDLE mutex = CreateMutexW(NULL, TRUE, kPatcherExeFilename.AsString().ToWchar());
DWORD wait = WaitForSingleObject(mutex, 0);
while(!s_shutdown && wait != WAIT_OBJECT_0)
wait = WaitForSingleObject(mutex, 100);
@ -701,7 +699,7 @@ int __stdcall WinMain (
// Wait for the other process to exit
Sleep(1000);
if (!plFileUtils::RemoveFile(newPatcherFile)) {
if (!plFileSystem::Unlink(newPatcherFile)) {
wchar_t error[256];
DWORD errorCode = GetLastError();
wchar_t *msg = TranslateErrorCode(errorCode);
@ -711,7 +709,7 @@ int __stdcall WinMain (
LocalFree(msg);
break;
}
if (!plFileUtils::FileMove(curPatcherFile, newPatcherFile)) {
if (!plFileSystem::Move(curPatcherFile, newPatcherFile)) {
wchar_t error[256];
DWORD errorCode = GetLastError();
wchar_t *msg = TranslateErrorCode(errorCode);
@ -719,7 +717,7 @@ int __stdcall WinMain (
StrPrintf(error, arrsize(error), L"Failed to replace old patcher executable. %s", msg);
MessageBoxW(GetTopWindow(nil), error, L"Error", MB_OK);
// attempt to clean up this tmp file
plFileUtils::RemoveFile(curPatcherFile);
plFileSystem::Unlink(curPatcherFile);
LocalFree(msg);
break;
}
@ -732,7 +730,7 @@ int __stdcall WinMain (
si.cb = sizeof(si);
wchar_t cmdline[MAX_PATH];
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", newPatcherFile, s_launcherInfo.cmdLine);
StrPrintf(cmdline, arrsize(cmdline), L"%S %s", newPatcherFile.AsString().c_str(), s_launcherInfo.cmdLine);
// we have only successfully patched if we actually launch the new version of the patcher
(void)CreateProcessW(
@ -757,13 +755,11 @@ int __stdcall WinMain (
}
// Clean up old temp files
ARRAY(PathFind) paths;
wchar_t fileSpec[MAX_PATH];
PathGetProgramDirectory(fileSpec, arrsize(fileSpec));
PathAddFilename(fileSpec, fileSpec, L"*.tmp", arrsize(fileSpec));
PathFindFiles(&paths, fileSpec, kPathFlagFile);
for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path)
plFileUtils::RemoveFile(path->name);
plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName();
std::vector<plFileName> tmpFiles = plFileSystem::ListDir(fileSpec, "*.tmp");
std::for_each(tmpFiles.begin(), tmpFiles.end(), [](const plFileName &tmp) {
plFileSystem::Unlink(tmp);
});
SetConsoleCtrlHandler(CtrlHandler, TRUE);
InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server
@ -772,7 +768,7 @@ int __stdcall WinMain (
ENetError selfPatchResult;
if (false == (SelfPatch(cmdParser.IsSpecified(kArgNoSelfPatch), &s_shutdown, &selfPatchResult, &s_launcherInfo)) && IS_NET_SUCCESS(selfPatchResult)) {
// We didn't self-patch, so check for client updates and download them, then exec the client
StrCopy(s_launcherInfo.path, s_workingDir, arrsize(s_launcherInfo.path));
StrCopy(s_launcherInfo.path, s_workingDir.AsString().ToWchar(), arrsize(s_launcherInfo.path));
s_launcherInfo.prepCallback = PrepCallback;
s_launcherInfo.initCallback = InitCallback;
s_launcherInfo.startCallback = StartCallback;

1
Sources/Plasma/Apps/plUruLauncher/Pch.h

@ -63,7 +63,6 @@ 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 "plCompression/plZlibStream.h"
#include "plClientPatcher/UruPlayer.h"

41
Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp

@ -77,7 +77,7 @@ static bool s_downloadComplete;
static long s_numFiles;
static ENetError s_patchResult;
static bool s_updated;
static wchar_t s_newPatcherFile[MAX_PATH];
static plFileName s_newPatcherFile;
/*****************************************************************************
@ -106,10 +106,10 @@ static void NetErrorHandler (ENetProtocol protocol, ENetError error) {
//============================================================================
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
) {
if(IS_NET_ERROR(result)) {
switch (result) {
@ -140,14 +140,12 @@ static void DownloadCallback (
}
//============================================================================
static bool MD5Check (const char filename[], const wchar_t md5[]) {
static bool MD5Check (const plFileName &filename, const char *md5) {
// Do md5 check
char md5copy[MAX_PATH];
plMD5Checksum existingMD5(filename);
plMD5Checksum latestMD5;
StrToAnsi(md5copy, md5, arrsize(md5copy));
latestMD5.SetFromHexString(md5copy);
latestMD5.SetFromHexString(md5);
return (existingMD5 == latestMD5);
}
@ -155,7 +153,7 @@ static bool MD5Check (const char filename[], const wchar_t md5[]) {
static void ManifestCallback (
ENetError result,
void * param,
const wchar_t group[],
const wchar_t group[],
const NetCliFileManifestEntry manifest[],
unsigned entryCount
) {
@ -183,24 +181,19 @@ static void ManifestCallback (
}
#endif
char ansi[MAX_PATH];
// MD5 check current patcher against value in manifest
ASSERT(entryCount == 1);
wchar_t curPatcherFile[MAX_PATH];
PathGetProgramName(curPatcherFile, arrsize(curPatcherFile));
StrToAnsi(ansi, curPatcherFile, arrsize(ansi));
if (!MD5Check(ansi, manifest[0].md5)) {
plFileName curPatcherFile = plFileSystem::GetCurrentAppPath();
if (!MD5Check(curPatcherFile, manifest[0].md5.c_str())) {
// MessageBox(GetTopWindow(nil), "MD5 failed", "Msg", MB_OK);
SelfPatcherStream::totalBytes += manifest[0].zipSize;
AtomicAdd(&s_numFiles, 1);
SetText("Downloading new patcher...");
StrToAnsi(ansi, s_newPatcherFile, arrsize(ansi));
SelfPatcherStream * stream = new SelfPatcherStream;
if (!stream->Open(ansi, "wb"))
ErrorAssert(__LINE__, __FILE__, "Failed to create file: %s, errno: %u", ansi, errno);
if (!stream->Open(s_newPatcherFile, "wb"))
ErrorAssert(__LINE__, __FILE__, "Failed to create file: %s, errno: %u", s_newPatcherFile.AsString().c_str(), errno);
NetCliFileDownloadRequest(manifest[0].downloadName, stream, DownloadCallback, nil);
}
@ -213,7 +206,7 @@ static void ManifestCallback (
static void FileSrvIpAddressCallback (
ENetError result,
void * param,
const wchar_t addr[]
const wchar_t addr[]
) {
NetCliGateKeeperDisconnect();
@ -230,9 +223,9 @@ static void FileSrvIpAddressCallback (
NetCliFileStartConnect(&caddr, 1, true);
delete[] caddr;
PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile));
GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile);
plFileUtils::RemoveFile(s_newPatcherFile);
s_newPatcherFile = plFileSystem::GetCurrentAppPath().StripFileName();
s_newPatcherFile = plFileSystem::GetTempFilename(kPatcherExeFilename.AsString().c_str(), s_newPatcherFile);
plFileSystem::Unlink(s_newPatcherFile);
NetCliFileManifestRequest(ManifestCallback, nil, s_manifest);
}
@ -279,7 +272,7 @@ static bool SelfPatcherProc (bool * abort, plLauncherInfo *info) {
si.cb = sizeof(si);
wchar_t cmdline[MAX_PATH];
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", s_newPatcherFile, info->cmdLine);
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", s_newPatcherFile.AsString().ToWchar(), info->cmdLine);
// we have only successfully patched if we actually launch the new version of the patcher
patched = CreateProcessW(

1
Sources/Plasma/CoreLib/HeadSpin.h

@ -440,6 +440,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wch
# include <limits.h>
# define MAX_PATH PATH_MAX
#endif
#define MAX_EXT (256)
// Useful floating point utilities
inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); }

199
Sources/Plasma/CoreLib/plFileSystem.cpp

@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "plFileSystem.h"
#if HS_BUILD_FOR_WIN32
@ -49,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
# include <limits.h>
# include <unistd.h>
# include <sys/types.h>
# include <dirent.h>
# include <fnmatch.h>
# include <cstdlib>
# include <functional>
# include <memory>
@ -250,6 +253,15 @@ plFileName plFileSystem::GetCWD()
return cwd;
}
bool plFileSystem::SetCWD(const plFileName &cwd)
{
#if HS_BUILD_FOR_WIN32
return SetCurrentDirectoryW(cwd.AsString().ToWchar());
#else
return (chdir(cwd.AsString().c_str()) == 0);
#endif
}
FILE *plFileSystem::Open(const plFileName &filename, const char *mode)
{
#if HS_BUILD_FOR_WIN32
@ -273,8 +285,11 @@ FILE *plFileSystem::Open(const plFileName &filename, const char *mode)
bool plFileSystem::Unlink(const plFileName &filename)
{
#if HS_BUILD_FOR_WIN32
return _wunlink(filename.AsString().ToWchar()) == 0;
plStringBuffer<wchar_t> wfilename = filename.AsString().ToWchar();
_wchmod(wfilename, S_IWRITE);
return _wunlink(wfilename) == 0;
#else
chmod(filename.AsString().c_str(), S_IWRITE);
return unlink(filename.AsString().c_str()) == 0;
#endif
}
@ -282,7 +297,8 @@ bool plFileSystem::Unlink(const plFileName &filename)
bool plFileSystem::Move(const plFileName &from, const plFileName &to)
{
#if HS_BUILD_FOR_WIN32
return MoveFileW(from.AsString().ToWchar(), to.AsString().ToWchar());
return MoveFileExW(from.AsString().ToWchar(), to.AsString().ToWchar(),
MOVEFILE_REPLACE_EXISTING);
#else
if (!Copy(from, to))
return false;
@ -333,6 +349,95 @@ bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents)
#endif
}
std::vector<plFileName> plFileSystem::ListDir(const plFileName &path, const char *pattern)
{
std::vector<plFileName> contents;
#if HS_BUILD_FOR_WIN32
if (!pattern || !pattern[0])
pattern = "*";
plFileName searchPattern = plFileName::Join(path, pattern);
WIN32_FIND_DATAW findData;
HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData);
if (hFind == INVALID_HANDLE_VALUE)
return contents;
do {
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Should also handle . and ..
continue;
}
contents.push_back(plFileName::Join(path, plString::FromWchar(findData.cFileName)));
} while (FindNextFileW(hFind, &findData));
FindClose(hFind);
#else
DIR *dir = opendir(path.AsString().c_str());
if (!dir)
return contents;
struct dirent *de;
while (de = readdir(dir)) {
if (plFileInfo(de->d_name).IsDirectory()) {
// Should also handle . and ..
continue;
}
if (pattern && pattern[0] && fnmatch(pattern, de->d_name))
contents.push_back(plFileName::Join(path, de->d_name));
else if (!pattern || !pattern[0])
contents.push_back(plFileName::Join(path, de->d_name));
}
closedir(dir);
#endif
return contents;
}
std::vector<plFileName> plFileSystem::ListSubdirs(const plFileName &path)
{
std::vector<plFileName> contents;
#if HS_BUILD_FOR_WIN32
plFileName searchPattern = plFileName::Join(path, "*");
WIN32_FIND_DATAW findData;
HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData);
if (hFind == INVALID_HANDLE_VALUE)
return contents;
do {
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
plFileName name = plString::FromWchar(findData.cFileName);
if (name != "." && name != "..")
contents.push_back(plFileName::Join(path, name));
}
} while (FindNextFileW(hFind, &findData));
FindClose(hFind);
#else
DIR *dir = opendir(path.AsString().c_str());
if (!dir)
return contents;
struct dirent *de;
while (de = readdir(dir)) {
if (plFileInfo(de->d_name).IsDirectory()) {
plFileName name = de->d_name;
if (name != "." && name != "..")
contents.push_back(plFileName::Join(path, name);
}
}
closedir(dir);
#endif
return contents;
}
plFileName plFileSystem::GetUserDataPath()
{
static plFileName _userData;
@ -366,3 +471,93 @@ plFileName plFileSystem::GetLogPath()
plFileSystem::CreateDir(_logPath);
return _logPath;
}
#if !HS_BUILD_FOR_WIN32
static plFileName _CheckReadlink(const char *link_path)
{
plFileInfo info(link_path);
if (info.Exists()) {
char *path = new char[info.FileSize()];
readlink(link_path, path, info.FileSize());
plFileName appPath = plString::FromUtf8(path, info.FileSize());
delete [] path;
return appPath;
}
return "";
}
#endif
plFileName plFileSystem::GetCurrentAppPath()
{
plFileName appPath;
// Neither OS makes this one simple...
#if HS_BUILD_FOR_WIN32
wchar_t path[MAX_PATH];
size_t size = GetModuleFileNameW(nullptr, path, MAX_PATH);
if (size >= MAX_PATH) {
// Buffer not big enough
size_t bigger = MAX_PATH;
do {
bigger *= 2;
wchar_t *path_lg = new wchar_t[bigger];
size = GetModuleFileNameW(nullptr, path_lg, bigger);
if (size < bigger)
appPath = plString::FromWchar(path_lg);
delete [] path_lg;
} while (!appPath.IsValid());
} else {
appPath = plString::FromWchar(path);
}
return appPath;
#else
// Look for /proc/self/exe (Linux), /proc/curproc/file (FreeBSD / Mac),
// then /proc/self/path/a.out (Solaris). If none were found, you're SOL
appPath = _CheckReadlink("/proc/self/exe");
if (appPath.IsValid())
return appPath;
appPath = _CheckReadlink("/proc/curproc/file");
if (appPath.IsValid())
return appPath;
appPath = _CheckReadlink("/proc/self/path/a.out");
if (appPath.IsValid())
return appPath;
hsAssert(0, "Your OS doesn't make life easy, does it?");
#endif
}
plFileName plFileSystem::GetTempFilename(const char *prefix, const plFileName &path)
{
#if HS_BUILD_FOR_WIN32
// GetTempFileName() never uses more than 3 chars for the prefix
wchar_t wprefix[4];
for (size_t i=0; i<4; ++i)
wprefix[i] = prefix[i];
wprefix[3] = 0;
wchar_t temp[MAX_PATH];
if (GetTempFileNameW(path.AsString().ToWchar(), wprefix, 0, temp))
return plString::FromWchar(temp);
return "";
#else
plFileName tmpdir = path;
if (!tmpdir.IsValid())
tmpdir = "/tmp";
// "/tmp/prefixXXXXXX"
size_t temp_len = tmpdir.GetSize() + strlen(prefix) + 7;
char *temp = new char[temp_len + 1];
snprintf(temp, temp_len + 1, "%s/%sXXXXXX", tmpdir.AsString().c_str(), prefix);
mktemp(temp);
plFileName result = temp;
delete [] temp;
return result;
#endif
}

59
Sources/Plasma/CoreLib/plFileSystem.h

@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plString.h"
#include <cstdio>
#include <cstddef>
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
@ -187,10 +188,42 @@ public:
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
/** Append UTF-8 data from a C-style string pointer to the end of this
* filename object. Not to be confused with Join() -- do not use this
* for joining path components, or you will be shot by Zrax.
*/
plFileName &operator+=(const char *cstr) { return operator=(fName + cstr); }
/** Append the string \a str to the end of this filename object.
* Not to be confused with Join() -- do not use this for joining path
* components, or you will be shot by Zrax.
*/
plFileName &operator+=(const plString &str) { return operator=(fName + str); }
private:
plString fName;
// See the comments in plString's nullptr_t constructors for more info:
plFileName(std::nullptr_t) { }
void operator=(std::nullptr_t) { }
void operator==(std::nullptr_t) const { }
void operator!=(std::nullptr_t) const { }
};
/** Concatentate a plFileName with a string constant. Not to be confused with
* plFileName::Join() -- do not use this for joining path components, or you
* will be shot by Zrax.
*/
inline plFileName operator+(const plFileName &left, const char *right)
{ return left.AsString() + right; }
/** Concatentate a plFileName with a string constant. Not to be confused with
* plFileName::Join() -- do not use this for joining path components, or you
* will be shot by Zrax.
*/
inline plFileName operator+(const char *left, const plFileName &right)
{ return left + right.AsString(); }
/** Structure to get information about a file by name.
* \sa plFileName
@ -250,6 +283,9 @@ namespace plFileSystem
/** Get the current working directory of the application. */
plFileName GetCWD();
/** Change the current working directory. */
bool SetCWD(const plFileName &cwd);
/** Open a file using the correct platform fopen API. */
FILE *Open(const plFileName &filename, const char *mode);
@ -267,6 +303,20 @@ namespace plFileSystem
*/
bool CreateDir(const plFileName &dir, bool checkParents = false);
/** Fetch a list of files contained in the supplied \a path.
* If \a pattern is specified (e.g. "*.tmp"), use that to filter
* matches. Otherwise, all files in the path will be returned.
* Note that returned filenames include the provided path -- to
* get only the filename, call .GetFileName() on an entry.
*/
std::vector<plFileName> ListDir(const plFileName &path,
const char *pattern = nullptr);
/** Fetch a list of subdirectories in the specified \a path.
* The returned list does not include the "." or ".." entries.
*/
std::vector<plFileName> ListSubdirs(const plFileName &path);
/** Get the User's data directory. If it doesn't exist, this will
* create it.
*/
@ -279,6 +329,15 @@ namespace plFileSystem
/** Get the Log output directory. If it doesn't exist, this will
* create it. */
plFileName GetLogPath();
/** Get the full path and filename of the current process. */
plFileName GetCurrentAppPath();
/** Create a temporary filename. If path is specified, the returned
* filename will be relative to the supplied path -- otherwise, the
* system temp path is used.
*/
plFileName GetTempFilename(const char *prefix = "tmp", const plFileName &path = "");
}
#endif // plFileSystem_Defined

1
Sources/Plasma/CoreLib/plString.cpp

@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "plString.h"
#include <cstring>

10
Sources/Plasma/CoreLib/plString.h

@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plString_Defined
#define plString_Defined
#include "HeadSpin.h"
#include <stdint.h>
#include <vector>
/** Single Unicode character code unit */
@ -416,8 +416,8 @@ public:
*/
int Compare(const char *str, CaseSensitivity sense = kCaseSensitive) const
{
return (sense == kCaseSensitive) ? strcmp(c_str(), str)
: stricmp(c_str(), str);
return (sense == kCaseSensitive) ? strcmp(c_str(), str ? str : "")
: stricmp(c_str(), str ? str : "");
}
/** Compare up to but never exceeding the first \a count bytes of this
@ -436,8 +436,8 @@ public:
*/
int CompareN(const char *str, size_t count, CaseSensitivity sense = kCaseSensitive) const
{
return (sense == kCaseSensitive) ? strncmp(c_str(), str, count)
: strnicmp(c_str(), str, count);
return (sense == kCaseSensitive) ? strncmp(c_str(), str ? str : "", count)
: strnicmp(c_str(), str ? str : "", count);
}
/** Shortcut for Compare(str, kCaseInsensitive). */

8
Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp

@ -187,16 +187,10 @@ plVirtualCam1::plVirtualCam1()
#ifndef PLASMA_EXTERNAL_RELEASE
// only open log file if logging is on
if ( !plStatusLog::fLoggingOff )
{
wchar_t fileAndPath[MAX_PATH];
PathGetLogDirectory(fileAndPath, arrsize(fileAndPath));
PathAddFilename(fileAndPath, fileAndPath, L"camLog.txt", arrsize(fileAndPath));
foutLog = hsWFopen( fileAndPath, L"wt" );
}
foutLog = plFileSystem::Open(plFileName::Join(plFileSystem::GetLogPath(), "camLog.txt"), "wt");
#endif
SetFlags(kFirstPersonEnabled);
}
plVirtualCam1::~plVirtualCam1()

12
Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp

@ -112,9 +112,9 @@ PF_CONSOLE_FILE_DUMMY(Avatar)
//
/////////////////////////////////////////////////////////////////
plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName,
plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName,
char* statusStr, bool subString=false);
void PrintStringF(void pfun(const char *),const char * fmt, ...);
@ -361,7 +361,7 @@ PF_CONSOLE_CMD( Avatar_Turn, SetMouseTurnSensitivity, "float sensitivity", "Set
PF_CONSOLE_CMD( Avatar_Multistage, Trigger, "string multiComp", "Triggers the named Multistage Animation component")
{
char str[256];
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plMultistageBehMod", nil, str, true);
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plMultistageBehMod", "", str, true);
PrintString(str);
if (key)
@ -499,7 +499,7 @@ PF_CONSOLE_CMD( Avatar, SeekPoint, "string seekpoint", "Move to the given seekpo
if(avatar)
{
char buff[256];
plKey seekKey = FindSceneObjectByName(spName, nil, buff);
plKey seekKey = FindSceneObjectByName(spName, "", buff);
plSeekPointMod *mod = plAvatarMgr::GetInstance()->FindSeekPoint(spName);
if(mod)
@ -596,7 +596,7 @@ PF_CONSOLE_CMD( Avatar, FakeLinkToObj, "string objName", "Pseudo-Link the avatar
{
plString spName = plString::FromUtf8(params[0]);
char buff[256];
plKey seekKey = FindSceneObjectByName(spName, nil, buff);
plKey seekKey = FindSceneObjectByName(spName, "", buff);
if (!seekKey)
{
PrintString("Can't find object with that name, fake link failed.");

137
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -155,7 +155,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plUnifiedTime/plUnifiedTime.h"
//end for agedefn test
#include "plFile/hsFiles.h"
#include "pnSceneObject/plAudioInterface.h"
#include "plStatusLog/plStatusLog.h"
@ -263,9 +262,9 @@ PF_CONSOLE_FILE_DUMMY(Main)
// utility functions
//
//////////////////////////////////////////////////////////////////////////////
plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName,
plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName,
char* statusStr, bool subString=false);
void PrintStringF(void pfun(const char *),const char * fmt, ...);
@ -273,7 +272,7 @@ void PrintStringF(void pfun(const char *),const char * fmt, ...);
// Find an object from name, type (int), and optionally age.
// Name can be an alias specified by saying $foo
//
plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString)
plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString)
{
if (name.IsNull())
{
@ -293,12 +292,12 @@ plKey FindObjectByName(const plString& name, int type, const char* ageName, char
// Try restricted to our age first, if we're not given an age name. This works
// around most of the problems associated with unused keys in pages causing the pages to be marked
// as not loaded and thus screwing up our searches
if( ageName == nil && plNetClientMgr::GetInstance() != nil )
if (ageName.IsNull() && plNetClientMgr::GetInstance() != nil)
{
const char *thisAge = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
if (thisAge != nil)
plString thisAge = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
if (!thisAge.IsNull())
{
key = plKeyFinder::Instance().StupidSearch(thisAge, nil, type, name, subString);
key = plKeyFinder::Instance().StupidSearch(thisAge, "", type, name, subString);
if (key != nil)
{
if (statusStr)
@ -308,7 +307,7 @@ plKey FindObjectByName(const plString& name, int type, const char* ageName, char
}
}
// Fallback
key = plKeyFinder::Instance().StupidSearch(ageName,nil,type, name, subString);
key = plKeyFinder::Instance().StupidSearch(ageName, "", type, name, subString);
if (!key)
{
@ -334,7 +333,7 @@ plKey FindObjectByName(const plString& name, int type, const char* ageName, char
// Name can be an alias specified by saying $foo.
// Will load the object if necessary.
//
plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString)
plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString)
{
plKey key=FindObjectByName(name, plSceneObject::Index(), ageName, statusStr, subString);
@ -352,7 +351,7 @@ plKey FindSceneObjectByName(const plString& name, const char* ageName, char* sta
// Find an object from name, type (string) and optionally age.
// Name can be an alias specified by saying $foo
//
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName,
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName,
char* statusStr, bool subString)
{
if (!typeName)
@ -1579,8 +1578,8 @@ PF_CONSOLE_CMD( Graphics_Renderer, GrabCubeMap,
"Take cubemap from sceneObject's position and name it prefix_XX.jpg")
{
char str[512];
plString objName = plString::FromUtf8(params[0]);
plKey key = FindSceneObjectByName(objName, nil, str);
plString objName = static_cast<const char *>(params[0]);
plKey key = FindSceneObjectByName(objName, "", str);
PrintString( str );
if( !key )
return;
@ -1841,7 +1840,7 @@ PF_CONSOLE_CMD( Graphics_Show, SingleSound,
{
char str[ 512 ];
const char *ageName = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
plString ageName = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
plKey key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), ageName, str, true );
plSceneObject *obj = ( key != nil ) ? plSceneObject::ConvertNoRef( key->GetObjectPtr() ) : nil;
@ -2175,7 +2174,7 @@ PF_CONSOLE_CMD( App,
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str);
plSceneObject* obj = plSceneObject::ConvertNoRef(key->GetObjectPtr());
if( !obj )
{
@ -2252,7 +2251,7 @@ PF_CONSOLE_CMD( App,
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str);
plSceneObject* obj = plSceneObject::ConvertNoRef(key->GetObjectPtr());
if( !obj )
{
@ -2307,7 +2306,7 @@ PF_CONSOLE_CMD( App,
{
char str[256];
plString name = plString::FromUtf8(params[0]);
plKey key = FindSceneObjectByName(name, nil, str);
plKey key = FindSceneObjectByName(name, "", str);
if( !key )
{
sprintf(str, "%s - Not Found!", name.c_str());
@ -2773,7 +2772,7 @@ PF_CONSOLE_CMD( Registry, ListRefs, "string keyType, string keyName", "For the g
"the objects who currently have active refs on it." )
{
char result[ 256 ];
plKey obj = FindObjectByNameAndType( plString::FromUtf8( params[ 1 ] ), params[ 0 ], nil, result);
plKey obj = FindObjectByNameAndType( plString::FromUtf8( params[ 1 ] ), params[ 0 ], "", result);
if( obj == nil )
{
PrintString( result );
@ -2950,7 +2949,7 @@ PF_CONSOLE_CMD( Camera, SwitchTo, "string cameraName", "Switch to the named came
{
char str[256];
plString foo = plString::Format("%s_", (char*)params[0]);
plKey key = FindObjectByNameAndType(foo, "plCameraModifier1", nil, str, true);
plKey key = FindObjectByNameAndType(foo, "plCameraModifier1", "", str, true);
PrintString(str);
if (key)
@ -3076,7 +3075,7 @@ PF_CONSOLE_GROUP( Logic )
static plLogicModBase *FindLogicMod(const plString &name)
{
char str[256];
plKey key = FindObjectByNameAndType(name, "plLogicModifier", nil, str, true);
plKey key = FindObjectByNameAndType(name, "plLogicModifier", "", str, true);
pfConsole::AddLine(str);
if (key)
@ -3173,7 +3172,7 @@ PF_CONSOLE_CMD( Logic, TriggerResponderNum, "int responderNum, ...", "Triggers t
}
char str[256];
plKey key = FindObjectByNameAndType(responderNames[responderNum-1], "plResponderModifier", nil, str, true);
plKey key = FindObjectByNameAndType(responderNames[responderNum-1], "plResponderModifier", "", str, true);
PrintString(str);
if (key)
@ -3189,7 +3188,7 @@ PF_CONSOLE_CMD( Logic, TriggerResponder, "string responderComp, ...", "Triggers
}
char str[256];
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", nil, str, true);
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", "", str, true);
PrintString(str);
int responderState = -1;
@ -3211,7 +3210,7 @@ PF_CONSOLE_CMD( Logic, FastForwardResponder, "string responderComp, ...", "Fastf
}
char str[256];
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", nil, str, true);
plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", "", str, true);
PrintString(str);
int responderState = -1;
@ -3522,7 +3521,7 @@ PF_CONSOLE_CMD( Audio, SetVolume,
"string obj, float vol", "Sets the volume on a given object. 1 is max volume, 0 is silence" )
{
char str[ 256 ];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[ 0 ]), nil, str);
plKey key = FindSceneObjectByName(plString::FromUtf8(params[ 0 ]), "", str);
if( key == nil )
return;
@ -3551,7 +3550,7 @@ PF_CONSOLE_CMD( Audio, IsolateSound,
plKey key;
plAudioSysMsg *asMsg;
key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), nil, str );
key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), "", str );
if( key == nil )
{
sprintf( str, "Cannot find sound %s", (char *)params[ 0 ] );
@ -3928,36 +3927,10 @@ PF_CONSOLE_CMD( Nav, PageInNode, // Group name, Function name
plSynchEnabler ps(false); // disable dirty tracking while paging in
plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoom);
pMsg1->AddReceiver( plClient::GetInstance()->GetKey() );
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, params[0]));
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", static_cast<const char *>(params[0])));
plgDispatch::MsgSend(pMsg1);
}
PF_CONSOLE_CMD( Nav, PageInNodeList, // Group name, Function name
"string roomNameBase", // Params
"Pages in all scene nodes that start with name." ) // Help string
{
/* This is really old and hasn't worked since 2002 anyways. */
#if HS_BUILD_FOR_WIN32
plSynchEnabler ps(false); // disable dirty tracking while paging in
std::string pageInNodesStr;
pageInNodesStr += "dat\\";
pageInNodesStr += (char*)params[0];
pageInNodesStr += "*.prx";
hsFolderIterator pageInNodesIter(pageInNodesStr.data(), true);
plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoom);
while (pageInNodesIter.NextFile())
{
char nodeName[255];
_splitpath(pageInNodesIter.GetFileName(), NULL, NULL, nodeName, NULL);
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, nodeName));
}
pMsg1->AddReceiver( plClient::GetInstance()->GetKey() );
plgDispatch::MsgSend(pMsg1);
#endif
}
#ifndef LIMIT_CONSOLE_COMMANDS
@ -3968,7 +3941,7 @@ PF_CONSOLE_CMD( Nav, PageOutNode, // Group name, Function name
plSynchEnabler ps(false); // disable dirty tracking while paging out
plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kUnloadRoom);
pMsg1->AddReceiver( plClient::GetInstance()->GetKey() );
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, params[0]));
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", static_cast<const char *>(params[0])));
plgDispatch::MsgSend(pMsg1);
}
@ -3977,7 +3950,7 @@ PF_CONSOLE_CMD( Nav, UnloadPlayer, // Group name, Function name
"unloads a named player" ) // Help string
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str);
PrintString("UnloadPlayer (console version) is currently broken. Hassle Matt.");
// plNetClientMgr::UnloadPlayer(key);
}
@ -3995,12 +3968,12 @@ PF_CONSOLE_CMD( Nav, MovePlayer, // Group name, Function name
"moves a player from one paging unit to another" ) // Help string
{
char str[256];
plKey playerKey = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey playerKey = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if( !playerKey )
return;
plKey nodeKey = FindObjectByName(plString::FromUtf8(params[1]), plSceneNode::Index(), nil, str);
plKey nodeKey = FindObjectByName(static_cast<const char *>(params[1]), plSceneNode::Index(), "", str);
PrintString(str);
if( !nodeKey )
return;
@ -4307,7 +4280,7 @@ PF_CONSOLE_CMD( Access,
char str[256];
char* preFix = params[0];
plString name = plString::Format("%s_plMorphSequence_0", preFix);
plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str);
plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str);
PrintString(str);
if (!key)
return;
@ -4332,7 +4305,7 @@ PF_CONSOLE_CMD( Access,
char str[256];
char* preFix = params[0];
plString name = plString::Format("%s_plMorphSequence_2", preFix);
plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str);
plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str);
PrintString(str);
if (!key)
return;
@ -4353,7 +4326,7 @@ PF_CONSOLE_CMD( Access,
char str[256];
char* preFix = params[0];
plString name = plString::Format("%s_plMorphSequence_2", preFix);
plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str);
plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str);
PrintString(str);
if (!key)
return;
@ -4572,7 +4545,7 @@ PF_CONSOLE_CMD( Access,
"Test fading on visibility" )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str);
PrintString(str);
if( !key )
return;
@ -4604,7 +4577,7 @@ PF_CONSOLE_CMD( Access,
"Set the los test marker" )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if( !key )
return;
@ -4618,7 +4591,7 @@ PF_CONSOLE_CMD( Access,
"Set the Los hack marker" )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
plSceneObject* so = nil;
@ -4693,7 +4666,7 @@ PF_CONSOLE_CMD( Access,
"Fire shot along gun's z-axis, creating decal of radius <radius>, with optional max-range (def 1000)" )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if( !key )
return;
@ -4774,7 +4747,7 @@ PF_CONSOLE_CMD( Access,
"Add particle system <psys> to bulletMgr <bull>")
{
char str[256];
plKey bullKey = FindObjectByName(plString::FromUtf8(params[0]), plDynaBulletMgr::Index(), nil, str, false);
plKey bullKey = FindObjectByName(static_cast<const char *>(params[0]), plDynaBulletMgr::Index(), "", str, false);
PrintString(str);
if( !(bullKey && bullKey->GetObjectPtr()) )
{
@ -4782,7 +4755,7 @@ PF_CONSOLE_CMD( Access,
return;
}
plKey sysKey = FindSceneObjectByName(plString::FromUtf8(params[1]), nil, str);
plKey sysKey = FindSceneObjectByName(static_cast<const char *>(params[1]), "", str);
if( !(sysKey && sysKey->GetObjectPtr()) )
{
PrintString("Psys not found");
@ -4982,7 +4955,7 @@ static void IDisplayWaveVal(PrintFunk PrintString, plWaveSet7* wave, plWaveCmd::
static plWaveSet7* IGetWaveSet(PrintFunk PrintString, const plString& name)
{
char str[256];
plKey waveKey = FindObjectByName(name, plWaveSet7::Index(), nil, str, false);
plKey waveKey = FindObjectByName(name, plWaveSet7::Index(), "", str, false);
PrintString(str);
if (!waveKey)
return nil;
@ -5463,7 +5436,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Drawable, // Group name, Function name
"Enable or disable drawing of a sceneobject" ) // Help string
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if (!key)
return;
@ -5482,7 +5455,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Physical, // Group name, Function name
"Enable or disable the physical of a sceneobject" ) // Help string
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if (!key)
return;
@ -5524,7 +5497,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Audible, // Group name, Function name
"Enable or disable the audible of a sceneobject" ) // Help string
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if (!key)
return;
@ -5543,7 +5516,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, All, // Group name, Function name
"Enable or disable all fxns of a sceneobject" ) // Help string
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if (!key)
return;
@ -5563,10 +5536,10 @@ PF_CONSOLE_CMD( SceneObject, Attach, // Group name, Function name
{
char str[256];
plString childName = plString::FromUtf8(params[0]);
plString parentName = plString::FromUtf8(params[1]);
plString childName = static_cast<const char *>(params[0]);
plString parentName = static_cast<const char *>(params[1]);
plKey childKey = FindSceneObjectByName(childName, nil, str);
plKey childKey = FindSceneObjectByName(childName, "", str);
if( !childKey )
{
PrintString(str);
@ -5580,7 +5553,7 @@ PF_CONSOLE_CMD( SceneObject, Attach, // Group name, Function name
return;
}
plKey parentKey = FindSceneObjectByName(parentName, nil, str);
plKey parentKey = FindSceneObjectByName(parentName, "", str);
if( !parentKey )
{
PrintString(str);
@ -5601,9 +5574,9 @@ PF_CONSOLE_CMD( SceneObject, Detach, // Group name, Function name
{
char str[256];
plString childName = plString::FromUtf8(params[0]);
plString childName = static_cast<const char *>(params[0]);
plKey childKey = FindSceneObjectByName(childName, nil, str);
plKey childKey = FindSceneObjectByName(childName, "", str);
if( !childKey )
{
PrintString(str);
@ -6186,7 +6159,7 @@ PF_CONSOLE_GROUP( ParticleSystem ) // Defines a main command group
void UpdateParticleParam(const plString &objName, int32_t paramID, float value, void (*PrintString)(const char *))
{
char str[256];
plKey key = FindSceneObjectByName(objName, nil, str);
plKey key = FindSceneObjectByName(objName, "", str);
PrintString(str);
if (key == nil) return;
@ -6309,7 +6282,7 @@ PF_CONSOLE_CMD( ParticleSystem,
"Creates a system (if necessary) on the avatar, and transfers particles" )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
if (key == nil)
return;
@ -6328,7 +6301,7 @@ PF_CONSOLE_CMD( ParticleSystem,
"Flag some particles for death." )
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
if (key == nil)
return;
@ -6350,7 +6323,7 @@ PF_CONSOLE_SUBGROUP( ParticleSystem, Flock )
static plParticleFlockEffect *FindFlock(const plString &objName)
{
char str[256];
plKey key = FindSceneObjectByName(objName, nil, str);
plKey key = FindSceneObjectByName(objName, "", str);
if (key == nil)
return nil;
@ -6528,7 +6501,7 @@ PF_CONSOLE_GROUP( Animation ) // Defines a main command group
void SendAnimCmdMsg(const plString &objName, plMessage *msg)
{
char str[256];
plKey key = FindSceneObjectByName(objName, nil, str);
plKey key = FindSceneObjectByName(objName, "", str);
if (key != nil)
{
msg->AddReceiver(key);

10
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp

@ -84,8 +84,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plUnifiedTime/plUnifiedTime.h"
//end for agedefn test
#include "plFile/hsFiles.h"
#include "plStatusLog/plStatusLog.h"
#include "hsTemplates.h"
@ -196,9 +194,9 @@ PF_CONSOLE_FILE_DUMMY(Net)
// utility functions
//
//////////////////////////////////////////////////////////////////////////////
plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName,
plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString=false);
plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName,
char* statusStr, bool subString=false);
void PrintStringF(void pfun(const char *),const char * fmt, ...);
@ -509,7 +507,7 @@ PF_CONSOLE_CMD( Net, // groupName
"Instructs the server to only send me updates about this object periodically" ) // helpString
{
char str[256];
plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str);
plKey key = FindSceneObjectByName(static_cast<const char *>(params[0]), "", str);
PrintString(str);
if (!key)
return;

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

@ -49,69 +49,40 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsExceptions.h"
#ifdef HS_BUILD_FOR_WIN32
#include "hsWindows.h"
#include <sstream>
//// ParseDirectory //////////////////////////////////////////////////////////
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */)
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* = L"*.*" */)
{
WIN32_FIND_DATAW findInfo;
HANDLE handle;
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo);
if (handle == INVALID_HANDLE_VALUE)
return false;
do
std::vector<plFileName> files = plFileSystem::ListDir(path, mask);
for (auto iter = files.begin(); iter != files.end(); ++iter)
{
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
plFileName name = iter->GetFileName();
if (AlreadyProcessedFile(path, name))
continue;
AddProcessedFile(path, name);
if (!fEngine->ExecuteFile(*iter))
{
plFileName name = plString::FromWchar(findInfo.cFileName);
plFileName fileAndPath = plFileName::Join(path, name);
if (AlreadyProcessedFile(path, name))
continue;
AddProcessedFile(path, name);
if (!fEngine->ExecuteFile(fileAndPath))
{
// Change the following line once we have a better way of reporting
// errors in the parsing
std::wstringstream error;
std::wstringstream caption;
wchar_t* errorMsg = hsStringToWString(fEngine->GetErrorMsg());
wchar_t* errorLine = hsStringToWString(fEngine->GetLastErrorLine());
caption << L"Error parsing " << findInfo.cFileName;
error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files.";
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
delete [] errorMsg;
delete [] errorLine;
FindClose(handle);
SetCheckProcessedFiles(true);
return false;
}
// Change the following line once we have a better way of reporting
// errors in the parsing
plStringStream error, caption;
caption << "Error parsing " << name.AsString();
error << fEngine->GetErrorMsg() << ":\n\nCommand: '" << fEngine->GetLastErrorLine()
<< "'\n\nPress OK to continue parsing files.";
hsMessageBox(error.GetString().c_str(), caption.GetString().c_str(), hsMessageBoxNormal);
SetCheckProcessedFiles(true);
return false;
}
} while (FindNextFileW(handle, &findInfo) != 0);
}
FindClose(handle);
SetCheckProcessedFiles(true);
return true;
}
#else
#error This needs to be implemented for this platform!!!!
#endif
void pfConsoleDirSrc::ResetProcessedFiles()
{
int i;

6
Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h

@ -71,14 +71,14 @@ class pfConsoleDirSrc
{
plFileName fPath;
plFileName fFile;
FileName() : fPath(""), fFile("") {}
FileName() {}
FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {}
};
std::vector<FileName*> fProcessedFiles; // list of init files we've already executed
bool fCheckProcessedFiles; // set to check and skip files init files we've already executed
public:
pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; }
pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini")
pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const char* mask = "*.ini")
: fCheckProcessedFiles(false)
{
fEngine = engine;
@ -88,7 +88,7 @@ class pfConsoleDirSrc
~pfConsoleDirSrc() { ResetProcessedFiles(); }
// Steps through the given directory and executes all files with the console engine
bool ParseDirectory(const plFileName& path, const plString& mask = "*.*");
bool ParseDirectory(const plFileName& path, const char* mask = "*.*");
void ResetProcessedFiles();
bool AlreadyProcessedFile(const plFileName& path, const plFileName& file);

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

@ -305,7 +305,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, plString& info)
case plClientMsg::kLoadAgeKeys:
case plClientMsg::kReleaseAgeKeys:
info += plString::Format(" - Age: %s", clientMsg->GetAgeName());
info += plString::Format(" - Age: %s", clientMsg->GetAgeName().c_str());
break;
}
return true;

1
Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plCrashSrv.h"
#include "plCrash_Private.h"
#include "plFile/plFileUtils.h"
#include "plProduct.h"
#include "plFileSystem.h"

6
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp

@ -2535,10 +2535,10 @@ plKey pfJournalBook::IGetMipmapKey( const wchar_t *name, const plLocation &loc
// Do a search through our current age with just the name given
if( plNetClientMgr::GetInstance() != nil )
{
const char *thisAge = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
if( thisAge != nil )
plString thisAge = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName();
if (!thisAge.IsNull())
{
key = plKeyFinder::Instance().StupidSearch( thisAge, nil, plMipmap::Index(), cName, true );
key = plKeyFinder::Instance().StupidSearch( thisAge, "", plMipmap::Index(), cName, true );
if( key != nil )
{
return key;

58
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp

@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plResMgr/plLocalization.h"
#include "plFile/hsFiles.h"
#include "plFile/plEncryptedStream.h"
#include "plStatusLog/plStatusLog.h"
@ -94,7 +93,7 @@ public:
protected:
bool fWeExploded; // alternative to massive error stack
plString fFilename;
plFileName fFilename;
XML_Parser fParser;
struct tagInfo
@ -121,7 +120,7 @@ protected:
public:
LocalizationXMLFile() : fWeExploded(false) { }
bool Parse(const plString & fileName); // returns false on failure
bool Parse(const plFileName & fileName); // returns false on failure
void AddError(const plString & errorText);
};
@ -354,7 +353,7 @@ void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagIn
//// Parse() /////////////////////////////////////////////////////////
bool LocalizationXMLFile::Parse(const plString& fileName)
bool LocalizationXMLFile::Parse(const plFileName& fileName)
{
fFilename = fileName;
@ -382,10 +381,10 @@ bool LocalizationXMLFile::Parse(const plString& fileName)
XML_SetCharacterDataHandler(fParser, HandleData);
XML_SetUserData(fParser, (void*)this);
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str());
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName);
if (!xmlStream)
{
pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.c_str());
pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.AsString().c_str());
return false;
}
@ -437,15 +436,15 @@ void LocalizationXMLFile::AddError(const plString& errorText)
class LocalizationDatabase
{
protected:
plString fDirectory; // the directory we're supposed to parse
plFileName fDirectory; // the directory we're supposed to parse
std::vector<LocalizationXMLFile> fFiles; // the various XML files in that directory
LocalizationXMLFile::ageMap fData;
LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path);
LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path);
LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path);
LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plFileName & fileName, const plString & path);
LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plFileName & fileName, const plString & path);
LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plFileName & fileName, const plString & path);
void IMergeData(); // merge all localization data in the files
void IVerifyElement(const plString &ageName, const plString &setName, LocalizationXMLFile::set::iterator& curElement);
@ -456,7 +455,7 @@ protected:
public:
LocalizationDatabase() {}
void Parse(const plString & directory);
void Parse(const plFileName & directory);
LocalizationXMLFile::ageMap GetData() {return fData;}
};
@ -466,7 +465,7 @@ public:
//// IMergeElementData ///////////////////////////////////////////////
LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path)
LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plFileName & fileName, const plString & path)
{
// copy the data over, alerting the user to any duplicate translations
LocalizationXMLFile::element::iterator curTranslation;
@ -475,7 +474,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio
if (firstElement.find(curTranslation->first) != firstElement.end())
{
pfLocalizationDataMgr::GetLog()->AddLineF("Duplicate %s translation for %s found in file %s. Ignoring second translation.",
curTranslation->first.c_str(), path.c_str(), fileName.c_str());
curTranslation->first.c_str(), path.c_str(), fileName.AsString().c_str());
}
else
firstElement[curTranslation->first] = curTranslation->second;
@ -486,7 +485,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio
//// IMergeSetData ///////////////////////////////////////////////////
LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path)
LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plFileName & fileName, const plString & path)
{
// Merge all the elements
LocalizationXMLFile::set::iterator curElement;
@ -505,7 +504,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile
//// IMergeAgeData ///////////////////////////////////////////////////
LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path)
LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plFileName & fileName, const plString & path)
{
// Merge all the sets
LocalizationXMLFile::age::iterator curSet;
@ -640,24 +639,21 @@ void LocalizationDatabase::IVerifyData()
//// Parse() /////////////////////////////////////////////////////////
void LocalizationDatabase::Parse(const plString & directory)
void LocalizationDatabase::Parse(const plFileName & directory)
{
fDirectory = directory;
fFiles.clear();
char filename[255];
hsFolderIterator xmlFolder((directory + PATH_SEPARATOR_STR).c_str());
while(xmlFolder.NextFileSuffix(".loc"))
std::vector<plFileName> locFiles = plFileSystem::ListDir(directory, "*.loc");
for (auto iter = locFiles.begin(); iter != locFiles.end(); ++iter)
{
xmlFolder.GetPathAndName(filename);
LocalizationXMLFile newFile;
bool retVal = newFile.Parse(filename);
bool retVal = newFile.Parse(*iter);
if (!retVal)
pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Errors in file %s", filename);
pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Errors in file %s", iter->GetFileName().c_str());
fFiles.push_back(newFile);
pfLocalizationDataMgr::GetLog()->AddLineF("File %s parsed and added to database", filename);
pfLocalizationDataMgr::GetLog()->AddLineF("File %s parsed and added to database", iter->GetFileName().c_str());
}
IMergeData();
@ -822,7 +818,7 @@ plStatusLog *pfLocalizationDataMgr::fLog = nil; // output logfile
//// Constructor/Destructor //////////////////////////////////////////
pfLocalizationDataMgr::pfLocalizationDataMgr(const plString & path)
pfLocalizationDataMgr::pfLocalizationDataMgr(const plFileName & path)
{
hsAssert(!fInstance, "Tried to create the localization data manager more than once!");
fInstance = this;
@ -932,7 +928,7 @@ void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const plString & cu
//// IWriteText //////////////////////////////////////////////////////
void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString & ageName, const plString & languageName)
void pfLocalizationDataMgr::IWriteText(const plFileName & filename, const plString & ageName, const plString & languageName)
{
bool weWroteData = false; // did we actually write any data of consequence?
bool setEmpty = true;
@ -980,7 +976,7 @@ void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString
if (weWroteData)
{
// now spit the results out to the file
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename.c_str());
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename);
xmlStream->Write(fileData.GetLength(), fileData.GetString().c_str());
xmlStream->Close();
delete xmlStream;
@ -989,7 +985,7 @@ void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString
//// Initialize //////////////////////////////////////////////////////
void pfLocalizationDataMgr::Initialize(const plString & path)
void pfLocalizationDataMgr::Initialize(const plFileName & path)
{
if (fInstance)
return;
@ -1194,7 +1190,7 @@ bool pfLocalizationDataMgr::DeleteElement(const plString & name)
//// WriteDatabaseToDisk /////////////////////////////////////////////
void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path)
void pfLocalizationDataMgr::WriteDatabaseToDisk(const plFileName & path)
{
std::vector<plString> ageNames = GetAgeList();
std::vector<plString> languageNames = IGetAllLanguageNames();
@ -1202,7 +1198,9 @@ void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path)
{
for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++)
{
IWriteText(plString::Format("%s/%s%s.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]);
plFileName locPath = plFileName::Join(path, plString::Format("%s%s.loc",
ageNames[curAge].c_str(), languageNames[curLanguage].c_str()));
IWriteText(locPath, ageNames[curAge], languageNames[curLanguage]);
}
}
}

12
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h

@ -53,9 +53,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <map>
#include "pfLocalizedString.h"
#include "plFileSystem.h"
class plStatusLog;
class plString;
// Helper classes/structs that are only used in this main class
class LocalizationDatabase;
@ -106,7 +106,7 @@ protected:
// Contains all localized strings, the key is the Age.Set.Name specified by XML, in localizedElement, the key is the language string
pf3PartMap<localizedElement> fLocalizedElements;
plString fDataPath;
plFileName fDataPath;
localizedElement ICreateLocalizedElement(); // ease of use function that creates a basic localized element object
@ -117,13 +117,13 @@ protected:
void IConvertSet(LocSetInfo *setInfo, const plString & curPath);
void IConvertAge(LocAgeInfo *ageInfo, const plString & curPath);
void IWriteText(const plString & filename, const plString & ageName, const plString & languageName); // Write localization text to the specified file
void IWriteText(const plFileName & filename, const plString & ageName, const plString & languageName); // Write localization text to the specified file
pfLocalizationDataMgr(const plString & path);
pfLocalizationDataMgr(const plFileName & path);
public:
virtual ~pfLocalizationDataMgr();
static void Initialize(const plString & path);
static void Initialize(const plFileName & path);
static void Shutdown();
static pfLocalizationDataMgr &Instance(void) {return *fInstance;}
static bool InstanceValid(void) {return fInstance != nil;}
@ -162,7 +162,7 @@ public:
bool DeleteElement(const plString & name);
// Writes the current database to the disk (editor only). It will create all the files and put them into path
void WriteDatabaseToDisk(const plString & path);
void WriteDatabaseToDisk(const plFileName & path);
void OutputTreeToLog(); // prints the localization tree to the log file
};

2
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp

@ -73,7 +73,7 @@ pfLocalizationMgr::~pfLocalizationMgr()
//// Initialize //////////////////////////////////////////////////////
void pfLocalizationMgr::Initialize(const plString & dataPath)
void pfLocalizationMgr::Initialize(const plFileName & dataPath)
{
if (fInstance)
return;

4
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h

@ -51,6 +51,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
class plFileName;
class pfLocalizationMgr
{
private:
@ -60,7 +62,7 @@ protected:
public:
virtual ~pfLocalizationMgr();
static void Initialize(const plString & dataPath);
static void Initialize(const plFileName & dataPath);
static void Shutdown();
static pfLocalizationMgr &Instance(void) {return *fInstance;}
static bool InstanceValid(void) {return fInstance != nil;}

10
Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp

@ -43,19 +43,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
pfMovieEventMsg::~pfMovieEventMsg()
{
delete [] fMovieName;
}
void pfMovieEventMsg::Read(hsStream* stream, hsResMgr* mgr)
{
plMessage::IMsgRead(stream, mgr);
fReason = (Reason)stream->ReadByte();
fMovieName = stream->ReadSafeString();
fMovieName = stream->ReadSafeString_TEMP();
}
void pfMovieEventMsg::Write(hsStream* stream, hsResMgr* mgr)
@ -64,6 +58,6 @@ void pfMovieEventMsg::Write(hsStream* stream, hsResMgr* mgr)
stream->WriteByte(fReason);
stream->WriteSafeString(fMovieName);
stream->WriteSafeString(fMovieName.AsString());
}

14
Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.h

@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define pfMovieEventMsg_h_inc
#include "pnMessage/plMessage.h"
#include "plFileSystem.h"
class pfMovieEventMsg : public plMessage
{
@ -54,23 +55,18 @@ public:
Reason fReason;
char* fMovieName;
plFileName fMovieName;
pfMovieEventMsg(const char* movieName, Reason reason=kMovieDone) : plMessage(nil, nil, nil)
pfMovieEventMsg(const plFileName& movieName, Reason reason=kMovieDone) : plMessage(nil, nil, nil)
{
fReason = reason;
if (movieName)
fMovieName = hsStrcpy(movieName);
else
fMovieName = nil;
fMovieName = movieName;
}
pfMovieEventMsg() : plMessage(nil, nil, nil), fMovieName(nil), fReason(kMovieDone)
pfMovieEventMsg() : plMessage(nil, nil, nil), fReason(kMovieDone)
{
}
virtual ~pfMovieEventMsg();
CLASSNAME_REGISTER(pfMovieEventMsg);
GETINTERFACE_ANY(pfMovieEventMsg, plMessage);

28
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -208,7 +208,7 @@ PyObject* cyMisc::FindSceneObject(const plString& name, const char* ageName)
const char* theAge = ageName;
if ( ageName[0] == 0 )
theAge = nil;
key=plKeyFinder::Instance().StupidSearch(theAge,nil,plSceneObject::Index(), name, false);
key=plKeyFinder::Instance().StupidSearch(theAge, "", plSceneObject::Index(), name, false);
}
if ( key == nil )
@ -1457,7 +1457,7 @@ void cyMisc::PageOutNode(const char* nodeName)
plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kUnloadRoom);
plKey clientKey = hsgResMgr::ResMgr()->FindKey( kClient_KEY );
pMsg1->AddReceiver( clientKey );
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, nodeName));
pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", nodeName));
plgDispatch::MsgSend(pMsg1);
}
}
@ -2484,7 +2484,7 @@ void cyMisc::RebuildCameraStack(const plString& name, const char* ageName)
if ( !name.IsEmpty() )
{
key=plKeyFinder::Instance().StupidSearch(nil,nil,plSceneObject::Index(), name, false);
key=plKeyFinder::Instance().StupidSearch("", "", plSceneObject::Index(), name, false);
}
if ( key == nil )
{
@ -2685,7 +2685,7 @@ void cyMisc::FakeLinkToObjectNamed(const plString& name)
plKey key = nil;
if ( !name.IsEmpty() )
{
key = plKeyFinder::Instance().StupidSearch(nil,nil,plSceneObject::Index(), name, false);
key = plKeyFinder::Instance().StupidSearch("", "", plSceneObject::Index(), name, false);
}
if (!key)
@ -2790,28 +2790,24 @@ bool cyMisc::DumpLogs(const std::wstring & folder)
return retVal;
}
bool cyMisc::FileExists(const std::wstring & filename)
bool cyMisc::FileExists(const plFileName & filename)
{
return PathDoesFileExist(filename.c_str());
return plFileInfo(filename).Exists();
}
bool cyMisc::CreateDir(const std::wstring & directory)
bool cyMisc::CreateDir(const plFileName & directory)
{
return PathCreateDirectory(directory.c_str(), kPathCreateDirFlagEntireTree) == kPathCreateDirSuccess;
return plFileSystem::CreateDir(directory, true);
}
std::wstring cyMisc::GetUserPath()
plFileName cyMisc::GetUserPath()
{
wchar_t path[MAX_PATH];
PathGetUserDirectory(path, arrsize(path));
return path;
return plFileSystem::GetUserDataPath();
}
std::wstring cyMisc::GetInitPath()
plFileName cyMisc::GetInitPath()
{
wchar_t path[MAX_PATH];
PathGetInitDirectory(path, arrsize(path));
return path;
return plFileSystem::GetInitPath();
}
void cyMisc::SetBehaviorNetFlags(pyKey & behKey, bool netForce, bool netProp)

11
Sources/Plasma/FeatureLib/pfPython/cyMisc.h

@ -42,8 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef cyMisc_h
#define cyMisc_h
#include <string>
/////////////////////////////////////////////////////////////////////////////
//
// NAME: cyMisc
@ -67,6 +65,7 @@ class pyGUIDialog;
class plPipeline;
class plDisplayMode;
class plUUID;
class plFileName;
struct PipelineParams;
typedef struct _object PyObject;
@ -934,11 +933,11 @@ public:
static bool DumpLogs(const std::wstring & folder);
static bool FileExists(const std::wstring & filename);
static bool CreateDir(const std::wstring & directory);
static bool FileExists(const plFileName & filename);
static bool CreateDir(const plFileName & directory);
static std::wstring GetUserPath();
static std::wstring GetInitPath();
static plFileName GetUserPath();
static plFileName GetInitPath();
static void SetBehaviorNetFlags(pyKey & behKey, bool netForce, bool netProp);
static void SendFriendInvite(const wchar_t email[], const wchar_t toName[]);

44
Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp

@ -632,24 +632,9 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtFileExists, args, "Params: filename\nReturns t
PYTHON_RETURN_ERROR;
}
if (PyUnicode_Check(filenameObj))
if (PyString_CheckEx(filenameObj))
{
int strLen = PyUnicode_GetSize(filenameObj);
wchar_t* text = new wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
text[strLen] = L'\0';
bool retVal = cyMisc::FileExists(text);
delete [] text;
PYTHON_RETURN_BOOL(retVal);
}
else if (PyString_Check(filenameObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(filenameObj);
wchar_t* wText = hsStringToWString(text);
bool retVal = cyMisc::FileExists(wText);
delete [] wText;
PYTHON_RETURN_BOOL(retVal);
PYTHON_RETURN_BOOL(cyMisc::FileExists(PyString_AsStringEx(filenameObj)));
}
else
{
@ -667,24 +652,9 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtCreateDir, args, "Params: directory\nCreates t
PYTHON_RETURN_ERROR;
}
if (PyUnicode_Check(directoryObj))
{
int strLen = PyUnicode_GetSize(directoryObj);
wchar_t* text = new wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)directoryObj, text, strLen);
text[strLen] = L'\0';
bool retVal = cyMisc::CreateDir(text);
delete [] text;
PYTHON_RETURN_BOOL(retVal);
}
else if (PyString_Check(directoryObj))
if (PyString_CheckEx(directoryObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(directoryObj);
wchar_t* wText = hsStringToWString(text);
bool retVal = cyMisc::CreateDir(wText);
delete [] wText;
PYTHON_RETURN_BOOL(retVal);
PYTHON_RETURN_BOOL(cyMisc::CreateDir(PyString_AsStringEx(directoryObj)));
}
else
{
@ -695,14 +665,12 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtCreateDir, args, "Params: directory\nCreates t
PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetUserPath, "Returns the unicode path to the client's root user directory. Do NOT convert to a standard string.")
{
std::wstring val = cyMisc::GetUserPath();
return PyUnicode_FromWideChar(val.c_str(), val.length());
return PyUnicode_FromStringEx(cyMisc::GetUserPath().AsString());
}
PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetInitPath, "Returns the unicode path to the client's init directory. Do NOT convert to a standard string.")
{
std::wstring val = cyMisc::GetInitPath();
return PyUnicode_FromWideChar(val.c_str(), val.length());
return PyUnicode_FromStringEx(cyMisc::GetInitPath().AsString());
}
///////////////////////////////////////////////////////////////////////////

10
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp

@ -438,12 +438,8 @@ bool plPythonFileMod::ILoadPythonCode()
#ifndef PLASMA_EXTERNAL_RELEASE
// get code from file and execute in module
// see if the file exists first before trying to import it
char pathandfile[256];
sprintf(pathandfile, ".\\python\\%s.py",fPythonFile);
wchar_t *wPathandfile = hsStringToWString(pathandfile);
bool exists = PathDoesFileExist(wPathandfile);
delete [] wPathandfile;
if (exists)
plFileName pyfile = plFileName::Join(".", "python", plString::Format("%s.py", fPythonFile));
if (plFileInfo(pyfile).Exists())
{
char fromLoad[256];
//sprintf(fromLoad,"from %s import *", fPythonFile);
@ -453,7 +449,7 @@ bool plPythonFileMod::ILoadPythonCode()
if ( PythonInterface::RunString( fromLoad, fModule) )
{
// we've loaded the code into our module
// now attach the glue python code to the end
// now attach the glue python code to the end
if ( !PythonInterface::RunString("execfile('.\\\\python\\\\plasma\\\\glue.py')", fModule) )
{
// display any output (NOTE: this would be disabled in production)

1
Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp

@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plPythonPack.h"
#include "plFile/hsFiles.h"
#include "plFile/plSecureStream.h"
#include "plFile/plStreamSource.h"

25
Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp

@ -46,7 +46,6 @@ 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 "plFile/plSecureStream.h"
#include "plFile/plStreamSource.h"
#include "plMessage/plNetCommMsgs.h"
@ -96,7 +95,7 @@ void GotFileSrvManifest(
void* param,
const wchar_t group[],
const NetCliFileManifestEntry manifest[],
uint32_t entryCount
uint32_t entryCount
) {
pfSecurePreloader* sp = (pfSecurePreloader*)param;
if (result == kNetErrFileNotFound)
@ -116,10 +115,10 @@ void GotFileSrvManifest(
}
void FileDownloaded(
ENetError result,
void* param,
const wchar_t filename[],
hsStream* writer
ENetError result,
void* param,
const plFileName & filename,
hsStream* writer
) {
pfSecurePreloader* sp = (pfSecurePreloader*)param;
if (IS_NET_ERROR(result))
@ -243,9 +242,9 @@ void pfSecurePreloader::PreloadNextFile()
// Thankfully, both callbacks have the same arguments
if (fLegacyMode)
NetCliAuthFileRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
NetCliAuthFileRequest(filename, s, FileDownloaded, this);
else
NetCliFileDownloadRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
NetCliFileDownloadRequest(filename, s, FileDownloaded, this);
}
void pfSecurePreloader::Init()
@ -346,8 +345,8 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
const NetCliFileManifestEntry mfs = manifestEntries[i];
bool fetchMe = true;
hsRAMStream* s = nil;
plFileName clientName = plString::FromWchar(mfs.clientName);
plFileName downloadName = plString::FromWchar(mfs.downloadName);
plFileName clientName = mfs.clientName;
plFileName downloadName = mfs.downloadName;
if (plFileInfo(clientName).Exists())
{
@ -355,10 +354,8 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
if (s)
{
// Damn this
const char* md5 = hsWStringToString(mfs.md5);
plMD5Checksum srvHash;
srvHash.SetFromHexString(md5);
delete[] md5;
srvHash.SetFromHexString(mfs.md5.c_str());
// Now actually copare the hashes
plMD5Checksum lclHash;
@ -394,7 +391,7 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
PreloadNextFile();
}
void pfSecurePreloader::FilePreloaded(const wchar_t* file, hsStream* stream)
void pfSecurePreloader::FilePreloaded(const plFileName& file, hsStream* stream)
{
// Clear out queue
fDownloadEntries.pop();

2
Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h

@ -85,7 +85,7 @@ public:
void PreloadManifest(const NetCliFileManifestEntry manifestEntries[], uint32_t entryCount);
void PreloadManifest(const NetCliAuthFileInfo manifestEntries[], uint32_t entryCount);
void PreloadNextFile();
void FilePreloaded(const wchar_t* filename, hsStream* stream);
void FilePreloaded(const plFileName& filename, hsStream* stream);
plOperationProgress* GetProgressBar() { return fProgress; }

4
Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp

@ -85,8 +85,8 @@ plLayerAVI::~plLayerAVI()
bool plLayerAVI::IInit()
{
#if HS_BUILD_FOR_WIN32
int ret = AVIStreamOpenFromFile( &fAVIInfo->fAVIStream,
fMovieName,
int ret = AVIStreamOpenFromFileW( &fAVIInfo->fAVIStream,
fMovieName.AsString().ToWchar(),
streamtypeVIDEO,
0,
OF_READ,

34
Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp

@ -51,8 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plPipeline/hsGDeviceRef.h"
plLayerMovie::plLayerMovie()
: fMovieName(nil),
fCurrentFrame(-1),
: fCurrentFrame(-1),
fLength(0),
fWidth(32),
fHeight(32)
@ -66,8 +65,6 @@ plLayerMovie::plLayerMovie()
plLayerMovie::~plLayerMovie()
{
delete [] fMovieName;
delete *fTexture;
}
@ -75,10 +72,10 @@ bool plLayerMovie::ISetFault(const char* errStr)
{
#ifdef HS_DEBUGGING
char buff[256];
sprintf(buff, "ERROR %s: %s\n", fMovieName, errStr);
sprintf(buff, "ERROR %s: %s\n", fMovieName.AsString().c_str(), errStr);
hsStatusMessage(buff);
#endif // HS_DEBUGGING
*fMovieName = 0;
fMovieName = "";
return true;
}
@ -115,7 +112,7 @@ bool plLayerMovie::ISetupBitmap()
memset(b->GetImage(), 0x10, b->GetHeight() * b->GetRowBytes() );
b->SetFlags( b->GetFlags() | plMipmap::kDontThrowAwayImage );
plString name = plString::Format( "%s_BMap", fMovieName );
plString name = plString::Format( "%s_BMap", fMovieName.AsString().c_str() );
hsgResMgr::ResMgr()->NewKey( name, b, plLocation::kGlobalFixedLoc );
*fTexture = (plBitmap *)b;
@ -183,18 +180,19 @@ void plLayerMovie::Read(hsStream* s, hsResMgr* mgr)
{
plLayerAnimation::Read(s, mgr);
delete [] fMovieName;
int len = s->ReadLE32();
if( len )
{
fMovieName = new char[len+1];
s->Read(len, fMovieName);
fMovieName[len] = 0;
plStringBuffer<char> movieName;
char *buf = movieName.CreateWritableBuffer(len);
s->Read(len, buf);
buf[len] = 0;
fMovieName = plString(movieName);
}
else
{
hsAssert(false, "Reading empty string for movie name");
fMovieName = nil;
fMovieName = "";
}
}
@ -202,16 +200,8 @@ void plLayerMovie::Write(hsStream* s, hsResMgr* mgr)
{
plLayerAnimation::Write(s, mgr);
int len = (fMovieName) ? strlen(fMovieName) : 0;
s->WriteLE32(len);
if( len )
s->Write(len, fMovieName);
}
void plLayerMovie::SetMovieName(const char* n)
{
delete [] fMovieName;
fMovieName = hsStrcpy(n);
s->WriteLE32(fMovieName.GetSize());
s->Write(fMovieName.GetSize(), fMovieName.AsString().c_str());
}
bool plLayerMovie::MsgReceive(plMessage* msg)

18
Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.h

@ -53,17 +53,17 @@ class hsResMgr;
class plLayerMovie : public plLayerAnimation
{
protected:
char* fMovieName;
plFileName fMovieName;
// plAnimTimeConvert fTimeConvert;
int32_t fCurrentFrame;
float fLength;
uint32_t fWidth, fHeight;
int32_t fCurrentFrame;
float fLength;
uint32_t fWidth, fHeight;
virtual int32_t ISecsToFrame(float secs) = 0;
virtual int32_t ISecsToFrame(float secs) = 0;
bool IGetFault() const { return !(fMovieName && *fMovieName); }
bool IGetFault() const { return !fMovieName.IsValid(); }
bool ISetFault(const char* errStr);
bool ICheckBitmap();
bool IMovieIsIdle(); // will call IRelease();
@ -82,15 +82,15 @@ public:
CLASSNAME_REGISTER( plLayerMovie );
GETINTERFACE_ANY( plLayerMovie, plLayerAnimation );
virtual uint32_t Eval(double secs, uint32_t frame, uint32_t ignore);
virtual uint32_t Eval(double secs, uint32_t frame, uint32_t ignore);
virtual void Read(hsStream* s, hsResMgr* mgr);
virtual void Write(hsStream* s, hsResMgr* mgr);
bool IsStopped() { return fTimeConvert.IsStopped(); }
void SetMovieName(const char* n);
const char* GetMovieName() const { return fMovieName; }
void SetMovieName(const plFileName& n) { fMovieName = n; }
const plFileName& GetMovieName() const { return fMovieName; }
virtual bool MsgReceive(plMessage* msg);

12
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp

@ -805,17 +805,15 @@ static void StartListenThread () {
#ifdef HS_DEBUGGING
#include <StdIo.h>
static void __cdecl DumpInvalidData (
const wchar_t filename[],
const plFileName & filename,
unsigned bytes,
const uint8_t data[],
const char fmt[],
...
) {
wchar_t path[MAX_PATH];
PathGetProgramDirectory(path, arrsize(path));
PathAddFilename(path, path, L"Log", arrsize(path));
PathAddFilename(path, path, filename, arrsize(path));
if (FILE * f = _wfopen(path, L"wb")) {
plFileName path = plFileSystem::GetCurrentAppPath().StripFileName();
path = plFileName::Join(path, "Log", filename);
if (FILE * f = plFileSystem::Open(path, "wb")) {
va_list args;
va_start(args, fmt);
vfprintf(f, fmt, args);
@ -1027,7 +1025,7 @@ void INtSocketOpCompleteSocketRead (
static long s_once;
if (!AtomicAdd(&s_once, 1)) {
DumpInvalidData(
L"NtSockErr.log",
"NtSockErr.log",
sizeof(sock->buffer),
sock->buffer,
"SocketDispatchRead error for %p: %d %d %d\r\n",

2
Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp

@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
void plClientMsg::IReset()
{
fMsgFlag = 0;
fAgeName = nil;
fAgeName = "";
}
void plClientMsg::AddRoomLoc(plLocation loc)

7
Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h

@ -56,7 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plClientMsg : public plMessage
{
int fMsgFlag;
char* fAgeName;
plString fAgeName;
std::vector<plLocation> fRoomLocs;
void IReset();
@ -105,7 +105,6 @@ public:
plClientMsg(const plKey &s) { IReset();}
plClientMsg(int i) { IReset(); fMsgFlag = i; }
plClientMsg(const plKey &s, const plKey &r, const double* t) { IReset(); }
~plClientMsg() { delete [] fAgeName; }
CLASSNAME_REGISTER(plClientMsg);
GETINTERFACE_ANY(plClientMsg, plMessage);
@ -115,8 +114,8 @@ public:
void AddRoomLoc(plLocation loc);
// Used for kLoadAgeKeys, kLetGoOfAgeKeys only
const char* GetAgeName() const { return fAgeName; }
void SetAgeName(const char* age) { delete [] fAgeName; fAgeName = hsStrcpy(age); }
plString GetAgeName() const { return fAgeName; }
void SetAgeName(const plString& age) { fAgeName = age; }
int GetNumRoomLocs() { return fRoomLocs.size(); }
const plLocation& GetRoomLoc(int i) const { return fRoomLocs[i]; }

4
Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2File/pnNpCli2File.h

@ -151,8 +151,8 @@ struct Cli2File_ManifestEntryAck : Cli2File_MsgHeader {
// FileDownloadRequest
struct Cli2File_FileDownloadRequest : Cli2File_MsgHeader {
uint32_t transId;
wchar_t filename[MAX_PATH];
uint32_t transId;
wchar_t filename[MAX_PATH];
unsigned buildId; // 0 = newest
};
struct Cli2File_FileDownloadChunkAck : Cli2File_MsgHeader {

3
Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt

@ -12,7 +12,6 @@ set(pnUtils_HEADERS
pnUtHash.h
pnUtList.h
pnUtMisc.h
pnUtPath.h
pnUtPragma.h
pnUtPriQ.h
pnUtRef.h
@ -28,7 +27,6 @@ set(pnUtils_SOURCES
pnUtHash.cpp
pnUtList.cpp
pnUtMisc.cpp
pnUtPath.cpp
pnUtStr.cpp
pnUtTime.cpp
)
@ -36,7 +34,6 @@ set(pnUtils_SOURCES
if(WIN32)
set(pnUtils_WIN32
Win32/pnUtW32Misc.cpp
Win32/pnUtW32Path.cpp
Win32/pnUtW32Str.cpp
)
else()

585
Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp

@ -1,585 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Path.cpp
*
***/
#include "../pnUtils.h"
#include "plProduct.h"
/*****************************************************************************
*
* Local functions
*
***/
// make sure our definition is at least as big as the compiler's definition
static_assert(MAX_PATH >= _MAX_PATH, "Windows and STDlib MAX_PATH constants differ");
//===========================================================================
static inline bool IsSlash (wchar_t c) {
return (c == L'\\') || (c == L'/');
}
//===========================================================================
static inline wchar_t ConvertSlash (wchar_t c) {
return c != L'/' ? c : L'\\';
}
//===========================================================================
static inline bool IsUncPath (const wchar_t path[]) {
return IsSlash(path[0]) && IsSlash(path[1]);
}
//===========================================================================
static const wchar_t * SkipUncDrive (const wchar_t path[]) {
// UNC drive: "//server/share"
// skip over leading "//"
path += 2;
// scan forward to end of server name
for (;; ++path) {
if (!*path)
return path;
if (IsSlash(*path))
break;
}
// skip over '/'
++path;
// skip over share name
for (;; ++path) {
if (!*path)
return path;
if (IsSlash(*path))
return path;
}
}
//===========================================================================
static wchar_t * PathSkipOverSeparator (wchar_t * path) {
for (; *path; ++path) {
if (IsSlash(*path))
return path + 1;
}
return path;
}
//===========================================================================
const wchar_t * PathFindFilename (
const wchar_t path[]
) {
ASSERT(path);
if (IsUncPath(path))
path = SkipUncDrive(path);
const wchar_t * last_slash = path;
for (const wchar_t * p = path; *p; p++) {
if ((*p == L'/') || (*p == L'\\') || (*p == L':'))
last_slash = p + 1;
}
return last_slash;
}
//===========================================================================
static void GetProgramName (
void * instance,
wchar_t * dst,
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
if (!GetModuleFileNameW((HINSTANCE) instance, dst, dstChars)) {
ErrorAssert(__LINE__, __FILE__, "GetModuleName failed");
*dst = 0;
}
}
//============================================================================
bool PathDoesDirectoryExist (const wchar_t directory[]) {
uint32_t attributes = GetFileAttributesW(directory);
if (attributes == (uint32_t) -1)
return false;
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
return true;
return false;
}
/****************************************************************************
*
* Exports
*
***/
//===========================================================================
void PathGetProgramName (
wchar_t * dst,
unsigned dstChars
) {
GetProgramName(nil, dst, dstChars);
}
//===========================================================================
bool PathFromString (
wchar_t * dst,
const wchar_t src[],
unsigned dstChars
) {
ASSERT(dst);
ASSERT(src);
ASSERT(dstChars);
for (;;) {
// enable src and dst to be the same buffer
wchar_t temp[MAX_PATH];
if (dst == src) {
StrCopy(temp, src, arrsize(temp));
src = temp;
}
DWORD const result = GetFullPathNameW(src, dstChars, dst, 0);
if (!result)
break;
if (dstChars < result)
break;
if (!dst[0])
break;
return true;
}
*dst = 0;
return false;
}
//===========================================================================
// this function was originally derived from _tsplitpath in the MSVCRT library,
// but has been updated to support UNC paths and to avoid blasting off the end
// of the buffers.
void PathSplitPath (
const wchar_t path[],
wchar_t * drive,
wchar_t * dir,
wchar_t * fname,
wchar_t * ext
) {
ASSERT(path);
ASSERT(path != drive);
ASSERT(path != dir);
ASSERT(path != fname);
ASSERT(path != ext);
// check for UNC path
if (IsUncPath(path)) {
const wchar_t * pathStart = path;
path = SkipUncDrive(path);
if (drive)
StrCopy(drive, pathStart, min(MAX_DRIVE, path - pathStart + 1));
}
// regular DOS path
else if (path[0] && (path[1] == L':')) {
if (drive) {
ASSERT(MAX_DRIVE >= 3);
drive[0] = path[0];
drive[1] = L':';
drive[2] = L'\0';
}
path += 2; // skip over 'C' ':'
}
else if (drive) {
*drive = 0;
}
// extract path string, if any. Path now points to the first character
// of the path, if any, or the filename or extension, if no path was
// specified. Scan ahead for the last occurence, if any, of a '/' or
// '\' path separator character. If none is found, there is no path.
// We will also note the last '.' character found, if any, to aid in
// handling the extension.
const wchar_t *last_slash = nil, *last_dot = nil, *p = path;
for (; *p; p++) {
if (IsSlash(*p))
last_slash = p + 1; // point to one beyond for later copy
else if (*p == L'.')
last_dot = p;
}
if (last_slash) {
if (dir)
StrCopy(dir, path, min(MAX_DIR, last_slash - path + 1));
path = last_slash;
}
else if (dir) {
*dir = 0;
}
// extract file name and extension, if any. Path now points to the
// first character of the file name, if any, or the extension if no
// file name was given. Dot points to the '.' beginning the extension,
// if any.
if (last_dot && (last_dot >= path)) {
if (fname)
StrCopy(fname, path, min(MAX_FNAME, last_dot - path + 1));
if (ext)
StrCopy(ext, last_dot, MAX_EXT);
}
else {
if (fname)
StrCopy(fname, path, MAX_FNAME);
if (ext)
*ext = 0;
}
}
//===========================================================================
void PathMakePath (
wchar_t * path,
unsigned chars,
const wchar_t drive[],
const wchar_t dir[],
const wchar_t fname[],
const wchar_t ext[]
) {
ASSERT(path);
ASSERT(path != drive);
ASSERT(path != dir);
ASSERT(path != fname);
ASSERT(path != ext);
// save space for string terminator
if (!chars--)
return;
// copy drive
if (drive && *drive && chars) {
do {
*path++ = ConvertSlash(*drive++);
} while (--chars && *drive);
ASSERT(!IsSlash(path[-1]));
}
// copy directory
if (dir && *dir && chars) {
do {
*path++ = ConvertSlash(*dir++);
} while (--chars && *dir);
// add trailing backslash
if (chars && (path[-1] != '\\')) {
*path++ = L'\\';
chars--;
}
}
// copy filename
if (fname && *fname && chars) {
// skip leading backslash
if (IsSlash(*fname))
++fname;
do {
*path++ = ConvertSlash(*fname++);
} while (--chars && *fname);
}
// copy extension
if (ext && *ext && chars) {
if (*ext != L'.') {
*path++ = L'.';
chars--;
}
while (chars-- && *ext)
*path++ = ConvertSlash(*ext++);
}
// add string terminator
*path = L'\0';
}
//===========================================================================
void PathGetUserDirectory (
wchar_t * dst,
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
wchar_t temp[MAX_PATH]; // GetSpecialFolder path requires a buffer of MAX_PATH size or larger
if (SHGetSpecialFolderPathW(NULL, temp, CSIDL_LOCAL_APPDATA, TRUE) == FALSE)
StrCopy(temp, L"C:\\", arrsize(temp));
// append the product name
PathAddFilename(dst, temp, plProduct::LongName().ToWchar(), dstChars);
// ensure it exists
if (!PathDoesDirectoryExist(dst))
PathCreateDirectory(dst, kPathCreateDirFlagEntireTree);
}
//============================================================================
void PathGetLogDirectory (
wchar_t * dst,
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
PathGetUserDirectory(dst, dstChars);
PathAddFilename(dst, dst, L"Log", dstChars);
if (!PathDoesDirectoryExist(dst))
PathCreateDirectory(dst, kPathCreateDirFlagEntireTree);
}
//============================================================================
void PathGetInitDirectory (
wchar_t * dst,
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
PathGetUserDirectory(dst, dstChars);
PathAddFilename(dst, dst, L"Init", dstChars);
if (!PathDoesDirectoryExist(dst))
PathCreateDirectory(dst, kPathCreateDirFlagEntireTree);
}
//===========================================================================
void PathFindFiles (
ARRAY(PathFind) * paths,
const wchar_t fileSpec[],
unsigned pathFlags
) {
ASSERT(paths);
ASSERT(fileSpec);
HANDLE find;
WIN32_FIND_DATAW fd;
wchar_t directory[MAX_PATH];
PathRemoveFilename(directory, fileSpec, arrsize(directory));
if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(fileSpec, &fd))) {
DWORD err = GetLastError();
if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND))
ASSERTMSG(err, "PathFindFiles failed");
}
else {
// find all the items in the current directory
do {
unsigned fileFlags = 0;
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (! (pathFlags & kPathFlagDirectory))
continue;
// don't add "." and ".."
if (fd.cFileName[0] == L'.') {
if (!fd.cFileName[1])
continue;
if (fd.cFileName[1] == L'.' && !fd.cFileName[2])
continue;
}
fileFlags = kPathFlagDirectory;
}
else {
if (! (pathFlags & kPathFlagFile))
continue;
fileFlags = kPathFlagFile;
}
if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
if (! (pathFlags & kPathFlagHidden))
continue;
fileFlags |= kPathFlagHidden;
}
if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
if (! (pathFlags & kPathFlagSystem))
continue;
fileFlags |= kPathFlagSystem;
}
// add this one to the list of found files
PathFind * pf = paths->New();
pf->flags = fileFlags;
pf->fileLength = ((uint64_t) fd.nFileSizeHigh << 32) | fd.nFileSizeLow;
pf->lastWriteTime = * (const uint64_t *) &fd.ftLastWriteTime;
PathAddFilename(pf->name, directory, fd.cFileName, arrsize(pf->name));
} while (FindNextFileW(find, &fd));
FindClose(find);
}
// check for directory recursing
if ((pathFlags & kPathFlagRecurse) || StrStr(fileSpec, L"**")) {
// recurse directories
}
else {
return;
}
wchar_t dirSpec[MAX_PATH];
PathAddFilename(dirSpec, directory, L"*", arrsize(dirSpec));
if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(dirSpec, &fd))) {
DWORD err = GetLastError();
if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND))
ErrorAssert(__LINE__, __FILE__, "PathFindFiles failed");
return;
}
// find all the directories in the current directory
const wchar_t * spec = PathFindFilename(fileSpec);
do {
if (! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
continue;
}
if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
if (! (pathFlags & kPathFlagHidden))
continue;
}
if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
if (! (pathFlags & kPathFlagSystem))
continue;
}
// don't recurse "." and ".."
if (fd.cFileName[0] == L'.') {
if (!fd.cFileName[1])
continue;
if (fd.cFileName[1] == L'.' && !fd.cFileName[2])
continue;
}
// recursively search subdirectory
PathAddFilename(dirSpec, directory, fd.cFileName, arrsize(dirSpec));
PathAddFilename(dirSpec, dirSpec, spec, arrsize(dirSpec));
PathFindFiles(paths, dirSpec, pathFlags);
} while (FindNextFileW(find, &fd));
FindClose(find);
}
//===========================================================================
EPathCreateDirError PathCreateDirectory (const wchar_t path[], unsigned flags) {
ASSERT(path);
// convert from relative path to full path
wchar_t dir[MAX_PATH];
if (!PathFromString(dir, path, arrsize(dir))) {
return kPathCreateDirErrInvalidPath;
}
// are we going to build the entire directory tree?
wchar_t * dirEnd;
if (flags & kPathCreateDirFlagEntireTree) {
dirEnd = dir;
// skip over leading slashes in UNC paths
while (IsSlash(*dirEnd))
++dirEnd;
// skip forward to first directory
dirEnd = PathSkipOverSeparator(dirEnd);
}
// we're only creating the very last entry in the path
else {
dirEnd = dir + StrLen(dir);
}
bool result = true;
for (wchar_t saveChar = L' '; saveChar; *dirEnd++ = saveChar) {
// find the end of the current directory string and terminate it
dirEnd = PathSkipOverSeparator(dirEnd);
saveChar = *dirEnd;
*dirEnd = 0;
// create the directory and track the result from the last call
result = CreateDirectoryW(dir, (LPSECURITY_ATTRIBUTES) nil);
}
// if we successfully created the directory then we're done
if (result) {
// Avoid check for kPathCreateDirFlagOsError
static_assert(kPathCreateDirSuccess == NO_ERROR, "Path creation success and NO_ERROR constants differ");
return kPathCreateDirSuccess;
}
unsigned error = GetLastError();
switch (error) {
case ERROR_ACCESS_DENIED:
return kPathCreateDirErrAccessDenied;
case ERROR_ALREADY_EXISTS: {
DWORD attrib;
if (0xffffffff == (attrib = GetFileAttributesW(dir)))
return kPathCreateDirErrInvalidPath;
if (! (attrib & FILE_ATTRIBUTE_DIRECTORY))
return kPathCreateDirErrFileWithSameName;
if (flags & kPathCreateDirFlagCreateNew)
return kPathCreateDirErrDirExists;
}
return kPathCreateDirSuccess;
default:
return kPathCreateDirErrInvalidPath;
}
}
//===========================================================================
bool PathDoesFileExist (const wchar_t fileName[]) {
uint32_t attributes = GetFileAttributesW(fileName);
if (attributes == (uint32_t) -1)
return false;
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
return false;
return true;
}

1
Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h

@ -59,7 +59,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtTime.h"
#include "pnUtStr.h"
#include "pnUtRef.h"
#include "pnUtPath.h"
#include "pnUtCmd.h"
#include "pnUtMisc.h"
#include "pnUtCrypt.h"

214
Sources/Plasma/NucleusLib/pnUtils/pnUtPath.cpp

@ -1,214 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.cpp
*
***/
#include "pnUtPath.h"
#include "pnUtStr.h"
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
void PathGetProgramDirectory (
wchar_t *dst,
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
PathGetProgramName(dst, dstChars);
PathRemoveFilename(dst, dst, dstChars);
}
//===========================================================================
void PathAddFilename (
wchar_t *dst,
const wchar_t src[],
const wchar_t fname[],
unsigned dstChars
) {
ASSERT(dst);
ASSERT(dstChars);
wchar_t temp[MAX_PATH];
if (dst == src) {
StrCopy(temp, src, arrsize(temp));
src = temp;
}
else if (dst == fname) {
StrCopy(temp, fname, arrsize(temp));
fname = temp;
}
PathMakePath(dst, dstChars, 0, src, fname, 0);
}
//===========================================================================
void PathRemoveFilename (
wchar_t *dst,
const wchar_t src[],
unsigned dstChars
) {
ASSERT(dst);
ASSERT(src);
ASSERT(dstChars);
wchar_t drive[MAX_DRIVE];
wchar_t dir[MAX_DIR];
PathSplitPath(src, drive, dir, 0, 0);
PathMakePath(dst, dstChars, drive, dir, 0, 0);
}
/*****************************************************************************
*
* Email formatting functions
*
***/
//============================================================================
void PathSplitEmail (
const wchar_t emailAddr[],
wchar_t * user,
unsigned userChars,
wchar_t * domain,
unsigned domainChars,
wchar_t * tld,
unsigned tldChars,
wchar_t * subDomains,
unsigned subDomainChars,
unsigned subDomainCount
) {
ASSERT(emailAddr);
#define SUB_DOMAIN(i) subDomains[(i) * subDomainChars]
// null-terminate all output parameters
if (userChars) {
ASSERT(user);
user[0] = 0;
}
if (domainChars) {
ASSERT(domain);
domain[0] = 0;
}
if (tldChars) {
ASSERT(tld);
tld[0] = 0;
}
if (subDomainChars || subDomainCount) {
ASSERT(subDomains);
for (unsigned i = 0; i < subDomainCount; ++i)
SUB_DOMAIN(i) = 0;
}
// bail now if email address is zero-length
unsigned len = StrLen(emailAddr);
if (!len)
return;
// copy email address so we can tokenize it
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1));
StrCopy(tmp, emailAddr, len + 1);
const wchar_t * work = tmp;
// parse user
wchar_t token[MAX_PATH];
if (!StrTokenize(&work, token, arrsize(token), L"@"))
return;
// copy user to output parameter
if (userChars)
StrCopy(user, token, userChars);
// skip past the '@' symbol
if (!*work++)
return;
// parse all domains
ARRAY(wchar_t *) arr;
while (StrTokenize(&work, token, arrsize(token), L".")) {
unsigned toklen = StrLen(token);
wchar_t * str = (wchar_t*)malloc(sizeof(wchar_t) * (toklen + 1));
StrCopy(str, token, toklen + 1);
arr.Add(str);
free(str);
}
// copy domains to output parameters
unsigned index = 0;
if (arr.Count() > 2) {
// all domains except for the last two are sub-domains
for (index = 0; index < arr.Count() - 2; ++index) {
if (index < subDomainCount)
if (subDomains)
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars);
}
}
if (arr.Count() > 1) {
// second to last domain is the primary domain
if (domain)
StrCopy(domain, arr[index], domainChars);
// last comes the top level domain
++index;
if (tld)
StrCopy(tld, arr[index], tldChars);
}
else if (arr.Count() == 1) {
// if only one domain, return it as a sub-domain
if (index < subDomainCount)
if (subDomains)
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars);
}
free(tmp);
#undef SUB_DOMAIN
}

219
Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h

@ -1,219 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H
#include "Pch.h"
#include "pnUtArray.h"
/*****************************************************************************
*
* Path definitions
*
***/
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#define MAX_DRIVE 256
#define MAX_DIR 256
#define MAX_FNAME 256
#define MAX_EXT 256
const unsigned kPathFlagFile = 1<<0;
const unsigned kPathFlagDirectory = 1<<1;
const unsigned kPathFlagHidden = 1<<2;
const unsigned kPathFlagSystem = 1<<3;
const unsigned kPathFlagRecurse = 1<<4; // also set if "**" used in filespec
struct PathFind {
unsigned flags;
uint64_t fileLength;
uint64_t lastWriteTime;
wchar_t name[MAX_PATH];
};
/*****************************************************************************
*
* Path "get" functions
*
***/
void PathFindFiles (
ARRAY(PathFind) * paths,
const wchar_t fileSpec[],
unsigned pathFlags
);
void PathGetProgramName (
wchar_t * dst,
unsigned dstChars
);
bool PathDoesFileExist (
const wchar_t fileName[]
);
/*****************************************************************************
*
* Path building functions
*
***/
void PathSplitPath (
const wchar_t path[],
wchar_t * drive,
wchar_t * dir,
wchar_t * fname,
wchar_t * ext
);
void PathMakePath (
wchar_t * path,
unsigned chars,
const wchar_t drive[],
const wchar_t dir[],
const wchar_t fname[],
const wchar_t ext[]
);
// c:\dir1 + dir2\file.txt => c:\dir1\dir2\file.txt
void PathAddFilename (
wchar_t * dst,
const wchar_t src[],
const wchar_t fname[],
unsigned dstChars
);
// c:\dir1\dir2\file.txt => c:\dir1\dir2\ * note trailing backslash
void PathRemoveFilename (
wchar_t * dst,
const wchar_t src[],
unsigned dstChars
);
/*****************************************************************************
*
* Directory functions
*
***/
// Create directory
enum EPathCreateDirError {
kPathCreateDirSuccess,
kPathCreateDirErrInvalidPath,
kPathCreateDirErrAccessDenied,
kPathCreateDirErrFileWithSameName,
kPathCreateDirErrDirExists, // Directory exists and kPathCreateDirFlagCreateNew was specified
};
// Setting this flag causes the function to create the entire directory
// tree from top to bottom. Clearing this flag causes the function to
// create only the last entry in the path.
const unsigned kPathCreateDirFlagEntireTree = 1<<0;
// Setting this flag causes the function to create the last entry in the path
// ONLY if it doesn't already exist. If it does exist the function will return
// kPathCreateDirErrDirExistes.
const unsigned kPathCreateDirFlagCreateNew = 1<<1;
EPathCreateDirError PathCreateDirectory (
const wchar_t path[],
unsigned flags
);
// Get directory
void PathGetProgramDirectory (
wchar_t * dst,
unsigned dstChars
);
// Product and user-specific common directory locations
void PathGetUserDirectory (
wchar_t * dst,
unsigned dstChars
);
void PathGetLogDirectory (
wchar_t * dst,
unsigned dstChars
);
void PathGetInitDirectory (
wchar_t * dst,
unsigned dstChars
);
/*****************************************************************************
*
* Email formatting functions
*
***/
// you may send nil for any fields you don't care about
void PathSplitEmail (
const wchar_t emailAddr[],
wchar_t * user,
unsigned userChars,
wchar_t * domain,
unsigned domainChars,
wchar_t * tld,
unsigned tldChars,
wchar_t * subDomains, // (wchar_t *)&subs --> wchar_t subs[16][256];
unsigned subDomainChars, // arrsize(subs[0]) --> 256
unsigned subDomainCount // arrsize(subs) --> 16
);
#endif

140
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
#include "plAgeDescription.h"
#include "plFile/hsFiles.h"
#include "plFile/plInitFileReader.h"
#include "plFile/plEncryptedStream.h"
#include "hsStringTokenizer.h"
@ -53,41 +52,35 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
const uint32_t plAgePage::kInvalidSeqSuffix = (uint32_t)-1;
plAgePage::plAgePage( const char *name, uint32_t seqSuffix, uint8_t flags )
plAgePage::plAgePage( const plString &name, uint32_t seqSuffix, uint8_t flags )
{
fName = name != nil ? hsStrcpy( name ) : nil;
fName = name;
fSeqSuffix = seqSuffix;
fFlags = flags;
}
plAgePage::plAgePage( char *stringFrom ) : fName(nil)
plAgePage::plAgePage( const plString &stringFrom )
{
SetFromString( stringFrom );
}
plAgePage::plAgePage()
{
fName = nil;
fName = "";
fFlags = 0;
fSeqSuffix = 0;
}
plAgePage::plAgePage( const plAgePage &src ) : fName(nil)
plAgePage::plAgePage( const plAgePage &src )
{
fName = src.fName != nil ? hsStrcpy( src.fName ) : nil;
fName = src.fName;
fSeqSuffix = src.fSeqSuffix;
fFlags = src.fFlags;
}
plAgePage::~plAgePage()
{
delete [] fName;
}
plAgePage &plAgePage::operator=( const plAgePage &src )
{
delete [] fName;
fName = src.fName != nil ? hsStrcpy( src.fName ) : nil;
fName = src.fName;
fSeqSuffix = src.fSeqSuffix;
fFlags = src.fFlags;
@ -103,54 +96,31 @@ void plAgePage::SetFlags(uint8_t f, bool on)
}
// now preservs original string
bool plAgePage::SetFromString( const char *stringIn )
bool plAgePage::SetFromString( const plString &stringIn )
{
char *c, seps[] = ", \n";
std::string string = stringIn;
// Parse. Format is going to be "pageName[,seqSuffix[,flags]]"
c = strtok( (char*)string.c_str(), seps );
if( c == nil )
std::vector<plString> toks = stringIn.Tokenize(", \n");
if (toks.size() == 0)
return false;
delete [] fName;
fName = hsStrcpy( c );
// Look for seqSuffix
c = strtok( nil, seps );
if( c != nil )
{
fSeqSuffix = atoi( c );
fName = toks[0];
fSeqSuffix = kInvalidSeqSuffix;
fFlags = 0;
// Look for flags
c = strtok( nil, seps );
if( c != nil )
{
fFlags = atoi( c );
}
else
fFlags = 0;
}
else
{
fSeqSuffix = kInvalidSeqSuffix;
fFlags = 0;
}
if (toks.size() > 1)
fSeqSuffix = toks[1].ToUInt();
if (toks.size() > 2)
fFlags = toks[2].ToUInt();
return true;
}
char *plAgePage::GetAsString( void ) const
plString plAgePage::GetAsString( void ) const
{
static char str[ 256 ];
if (fFlags)
return plString::Format("%s,%d,%d", fName.c_str(), fSeqSuffix, fFlags);
// Format is "pageName[,seqSuffix[,flags]]"
if( fFlags != 0 )
sprintf( str, "%s,%d,%d", fName, fSeqSuffix, fFlags );
else
sprintf( str, "%s,%d", fName, fSeqSuffix );
return str;
return plString::Format("%s,%d", fName.c_str(), fSeqSuffix);
}
@ -179,10 +149,9 @@ plAgeDescription::~plAgeDescription()
void plAgeDescription::IDeInit()
{
ClearPageList();
delete [] fName;
}
plAgeDescription::plAgeDescription( const char *fileNameToReadFrom ) : plInitSectionTokenReader()
plAgeDescription::plAgeDescription( const plFileName &fileNameToReadFrom ) : plInitSectionTokenReader()
{
ReadFromFile(fileNameToReadFrom);
}
@ -190,7 +159,7 @@ plAgeDescription::plAgeDescription( const char *fileNameToReadFrom ) : plInitSec
//
// Reads from a file, returns false if failed.
//
bool plAgeDescription::ReadFromFile( const char *fileNameToReadFrom )
bool plAgeDescription::ReadFromFile( const plFileName &fileNameToReadFrom )
{
IInit();
@ -206,38 +175,20 @@ bool plAgeDescription::ReadFromFile( const char *fileNameToReadFrom )
return true;
}
void plAgeDescription::SetAgeNameFromPath( const char *path )
void plAgeDescription::SetAgeNameFromPath( const plFileName &path )
{
delete [] fName;
if( path == nil )
if (!path.IsValid())
{
fName = nil;
fName = "";
return;
}
// Construct our name from the path
const char *pathSep1 = strrchr( path, '\\' );
const char *pathSep2 = strrchr( path, '/' );
if( pathSep2 > pathSep1 )
pathSep1 = pathSep2;
if( pathSep1 == nil )
pathSep1 = (char *)path;
else
pathSep1++; // Get past the actual character we found
char temp[ 512 ];
strcpy( temp, pathSep1 );
char *end = strrchr( temp, '.' );
if( end != nil )
*end = 0;
fName = hsStrcpy( temp );
fName = path.GetFileNameNoExt();
}
void plAgeDescription::IInit( void )
void plAgeDescription::IInit( void )
{
fName = nil;
fName = "";
fDayLength = 24.0f;
fMaxCapacity = -1;
fLingerTime = 180; // seconds
@ -248,14 +199,12 @@ void plAgeDescription::IInit( void )
fPageIterator = -1;
}
struct SzDelete { void operator()(char * str) { delete [] str;} };
void plAgeDescription::ClearPageList()
{
fPages.Reset();
}
void plAgeDescription::AppendPage( const char *name, int seqSuffix, uint8_t flags )
void plAgeDescription::AppendPage( const plString &name, int seqSuffix, uint8_t flags )
{
fPages.Append( plAgePage( name, ( seqSuffix == -1 ) ? fPages.GetCount() : (uint32_t)seqSuffix, flags ) );
}
@ -280,35 +229,30 @@ plAgePage *plAgeDescription::GetNextPage( void )
return ret;
}
void plAgeDescription::RemovePage( const char *page )
void plAgeDescription::RemovePage( const plString &page )
{
int i;
for( i = 0; i < fPages.GetCount(); i++ )
for (int i = 0; i < fPages.GetCount(); i++)
{
if( strcmp( page, fPages[ i ].GetName() ) == 0 )
if (page == fPages[i].GetName())
{
fPages.Remove( i );
fPages.Remove(i);
return;
}
}
}
plAgePage *plAgeDescription::FindPage( const char *name ) const
plAgePage *plAgeDescription::FindPage( const plString &name ) const
{
int i;
for( i = 0; i < fPages.GetCount(); i++ )
for (int i = 0; i < fPages.GetCount(); i++)
{
if( strcmp( name, fPages[ i ].GetName() ) == 0 )
return &fPages[ i ];
if (name == fPages[i].GetName())
return &fPages[i];
}
return nil;
}
plLocation plAgeDescription::CalcPageLocation( const char *page ) const
plLocation plAgeDescription::CalcPageLocation( const plString &page ) const
{
plAgePage *ap = FindPage( page );
if( ap != nil )
@ -334,7 +278,7 @@ plLocation plAgeDescription::CalcPageLocation( const char *page ) const
else
{
plLocation ret = plLocation::MakeNormal( combined );
if (page && !stricmp(page, "builtin"))
if (!page.CompareI("builtin"))
ret.SetFlags(plLocation::kBuiltIn);
return ret;
}
@ -380,7 +324,7 @@ void plAgeDescription::Write(hsStream* stream) const
int i;
for( i = 0; i < fPages.GetCount(); i++ )
{
sprintf(buf, "Page=%s\n", fPages[ i ].GetAsString() );
sprintf(buf, "Page=%s\n", fPages[ i ].GetAsString().c_str() );
stream->WriteString(buf);
}
}
@ -537,7 +481,7 @@ void plAgeDescription::AppendCommonPages( void )
void plAgeDescription::CopyFrom(const plAgeDescription& other)
{
IDeInit();
fName = hsStrcpy(other.GetAgeName());
fName = other.GetAgeName();
int i;
for(i=0;i<other.fPages.GetCount(); i++)
fPages.Append( other.fPages[ i ] );

45
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.h

@ -57,9 +57,9 @@ class hsStream;
class plAgePage
{
protected:
char *fName;
uint32_t fSeqSuffix;
uint8_t fFlags;
plString fName;
uint32_t fSeqSuffix;
uint8_t fFlags;
public:
@ -73,21 +73,20 @@ class plAgePage
kIsVolatile = 0x08,
};
plAgePage( const char *name, uint32_t seqSuffix, uint8_t flags );
plAgePage( char *stringFrom );
plAgePage( const plString &name, uint32_t seqSuffix, uint8_t flags );
plAgePage( const plString &stringFrom );
plAgePage( const plAgePage &src );
plAgePage();
~plAgePage();
const char *GetName( void ) const { return fName; }
uint32_t GetSeqSuffix( void ) const { return fSeqSuffix; }
uint8_t GetFlags( void ) const { return fFlags; }
plString GetName( void ) const { return fName; }
uint32_t GetSeqSuffix( void ) const { return fSeqSuffix; }
uint8_t GetFlags( void ) const { return fFlags; }
void SetSeqSuffix( uint32_t s ) { fSeqSuffix = s; }
void SetFlags(uint8_t f, bool on=true);
bool SetFromString( const char *string );
char *GetAsString( void ) const;
bool SetFromString( const plString &string );
plString GetAsString( void ) const;
plAgePage &operator=( const plAgePage &src );
};
@ -98,16 +97,16 @@ class plAgeDescription : public plInitSectionTokenReader
{
private:
char *fName;
plString fName;
int32_t fPageIterator;
int32_t fPageIterator;
hsTArray<plAgePage> fPages;
plUnifiedTime fStart;
float fDayLength;
short fMaxCapacity;
short fLingerTime; // seconds game instance should linger after last player leaves. -1 means never exit.
short fLingerTime; // seconds game instance should linger after last player leaves. -1 means never exit.
int32_t fSeqPrefix;
uint32_t fReleaseVersion; // 0 for pre-release, 1+ for actual released ages
@ -124,7 +123,7 @@ public:
static char kAgeDescPath[];
plAgeDescription();
plAgeDescription( const char *fileNameToReadFrom );
plAgeDescription( const plFileName &fileNameToReadFrom );
plAgeDescription( const plAgeDescription &src )
{
IInit();
@ -132,28 +131,28 @@ public:
}
~plAgeDescription();
bool ReadFromFile( const char *fileNameToReadFrom ) ;
bool ReadFromFile( const plFileName &fileNameToReadFrom );
void Read(hsStream* stream);
void Write(hsStream* stream) const;
// Overload for plInitSectionTokenReader
virtual const char *GetSectionName( void ) const;
const char *GetAgeName( void ) const { return fName; }
void SetAgeNameFromPath( const char *path );
void SetAgeName(const char* ageName) { delete [] fName; fName=hsStrcpy(ageName); }
plString GetAgeName( void ) const { return fName; }
void SetAgeNameFromPath( const plFileName &path );
void SetAgeName(const plString& ageName) { fName = ageName; }
// Page list
void ClearPageList();
void RemovePage( const char *page );
void AppendPage( const char *name, int seqSuffix = -1, uint8_t flags = 0 );
void RemovePage( const plString &page );
void AppendPage( const plString &name, int seqSuffix = -1, uint8_t flags = 0 );
void SeekFirstPage( void );
plAgePage *GetNextPage( void );
int GetNumPages() const { return fPages.GetCount(); }
plAgePage *FindPage( const char *name ) const;
plAgePage *FindPage( const plString &name ) const;
bool FindLocation(const plLocation& loc) const;
plLocation CalcPageLocation( const char *page ) const;
plLocation CalcPageLocation( const plString &page ) const;
// Getters
short GetStartMonth() const { return fStart.GetMonth(); }

15
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp

@ -51,24 +51,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAgeManifest.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plFile/plInitFileReader.h"
#include "hsStringTokenizer.h"
//// plManifestFile ///////////////////////////////////////////////////////
plManifestFile::plManifestFile(const char* name, const char* serverPath, const plMD5Checksum& check, uint32_t size, uint32_t zippedSize, uint32_t flags, bool md5Now) :
plManifestFile::plManifestFile(const plFileName& name, const plFileName& serverPath,
const plMD5Checksum& check, uint32_t size, uint32_t zippedSize,
uint32_t flags, bool md5Now) :
fName(name),
fServerPath(serverPath),
fChecksum(check),
fSize(size),
fZippedSize(zippedSize),
fFlags(flags),
fMd5Checked(md5Now)
{
fName = name;
fServerPath = serverPath;
if (md5Now)
{
DoMd5Check();
@ -81,9 +80,9 @@ plManifestFile::~plManifestFile()
void plManifestFile::DoMd5Check()
{
if (plFileUtils::FileExists(fName.c_str()))
if (plFileInfo(fName).Exists())
{
plMD5Checksum localFile(fName.c_str());
plMD5Checksum localFile(fName);
fIsLocalUpToDate = (localFile == fChecksum);
fLocalExists = true;
}

17
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h

@ -63,12 +63,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plManifestFile
{
protected:
std::string fName;
std::string fServerPath;
plFileName fName;
plFileName fServerPath;
plMD5Checksum fChecksum;
uint32_t fSize;
uint32_t fZippedSize;
uint32_t fFlags;
uint32_t fSize;
uint32_t fZippedSize;
uint32_t fFlags;
bool fMd5Checked;
bool fIsLocalUpToDate;
@ -86,11 +86,12 @@ public:
kFlagZipped = 1<<3,
};
plManifestFile(const char* name, const char* serverPath, const plMD5Checksum& check, uint32_t size, uint32_t zippedSize, uint32_t flags, bool md5Now = true);
plManifestFile(const plFileName& name, const plFileName& serverPath, const plMD5Checksum& check,
uint32_t size, uint32_t zippedSize, uint32_t flags, bool md5Now = true);
virtual ~plManifestFile();
const char* GetName() const { return fName.c_str(); }
const char* GetServerPath() const { return fServerPath.c_str(); }
const plFileName &GetName() const { return fName; }
const plFileName &GetServerPath() const { return fServerPath; }
const plMD5Checksum& GetChecksum() const { return fChecksum; }
uint32_t GetDiskSize() const { return fSize; }
uint32_t GetDownloadSize() const { return hsCheckBits(fFlags, kFlagZipped) ? fZippedSize : fSize; }

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

@ -294,14 +294,14 @@ bool plAgeLoader::ILoadAge(const char ageName[])
{
if( IsPageExcluded( page, fAgeName) )
{
nc->DebugMsg( "\tExcluding page %s\n", page->GetName() );
nc->DebugMsg("\tExcluding page %s\n", page->GetName().c_str());
continue;
}
nPages++;
pMsg1->AddRoomLoc(ad.CalcPageLocation(page->GetName()));
nc->DebugMsg("\tPaging in room %s\n", page->GetName());
nc->DebugMsg("\tPaging in room %s\n", page->GetName().c_str());
}
pMsg1->Send(clientKey);

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

@ -301,11 +301,11 @@ bool plAgeLoader::IsPageExcluded( const plAgePage *page, const char *ageName
return true;
// check exclude list
const char* pageName = page->GetName();
plString pageName = page->GetName();
int i;
for( i = 0; i < sExcludeList.GetCount(); i++ )
{
if( stricmp( pageName, sExcludeList[ i ].fPageName ) == 0 )
if( pageName.CompareI( sExcludeList[ i ].fPageName ) == 0 )
{
if( ageName == nil || sExcludeList[ i ].fAgeName == nil ||
stricmp( ageName, sExcludeList[ i ].fAgeName ) == 0 )

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

@ -46,7 +46,6 @@ 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 "plMessage/plResPatcherMsg.h"
#include "pnNetBase/pnNbError.h"
#include "plNetGameLib/plNetGameLib.h"
@ -91,33 +90,32 @@ public:
/////////////////////////////////////////////////////////////////////////////
static void FileDownloaded(
ENetError result,
void* param,
const wchar_t filename[],
hsStream* writer)
ENetError result,
void* param,
const plFileName & filename,
hsStream* writer)
{
plResPatcher* patcher = (plResPatcher*)param;
char* name = hsWStringToString(filename);
plFileName file = filename;
if (((plResDownloadStream*)writer)->IsZipped())
plFileUtils::StripExt(name); // Kill off .gz
file = file.StripFileExt(); // Kill off .gz
writer->Close();
switch (result)
{
case kNetSuccess:
PatcherLog(kStatus, " Download Complete: %s", name);
PatcherLog(kStatus, " Download Complete: %s", file.AsString().c_str());
// If this is a PRP, then we need to add it to the ResManager
if (stricmp(plFileUtils::GetFileExt(name), "prp") == 0)
((plResManager*)hsgResMgr::ResMgr())->AddSinglePage(name);
if (file.AsString().CompareI("prp") == 0)
((plResManager*)hsgResMgr::ResMgr())->AddSinglePage(file);
// Continue down the warpath
patcher->IssueRequest();
delete[] name;
delete writer;
return;
case kNetErrFileNotFound:
PatcherLog(kError, " Download Failed: %s not found", name);
PatcherLog(kError, " Download Failed: %s not found", file.AsString().c_str());
break;
default:
char* error = hsWStringToString(NetErrorToString(result));
@ -129,7 +127,6 @@ static void FileDownloaded(
// Failure case
((plResDownloadStream*)writer)->Unlink();
patcher->Finish(false);
delete[] name;
delete writer;
}
@ -153,8 +150,8 @@ static void ManifestDownloaded(
for (uint32_t i = 0; i < entryCount; ++i)
{
const NetCliFileManifestEntry mfs = manifest[i];
plFileName fileName = plString::FromWchar(mfs.clientName);
plFileName downloadName = plString::FromWchar(mfs.downloadName);
plFileName fileName = mfs.clientName;
plFileName downloadName = mfs.downloadName;
// See if the files are the same
// 1. Check file size before we do time consuming md5 operations
@ -163,7 +160,7 @@ static void ManifestDownloaded(
{
plMD5Checksum cliMD5(fileName);
plMD5Checksum srvMD5;
srvMD5.SetFromHexString(plString::FromWchar(mfs.md5).c_str());
srvMD5.SetFromHexString(mfs.md5.c_str());
if (cliMD5 == srvMD5)
continue;
@ -238,7 +235,7 @@ void plResPatcher::IssueRequest()
plFileSystem::CreateDir(req.fFriendlyName.StripFileName(), true);
plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile);
if (stream->Open(req.fFriendlyName, "wb"))
NetCliFileDownloadRequest(req.fFile.AsString().ToWchar(), stream, FileDownloaded, this);
NetCliFileDownloadRequest(req.fFile, stream, FileDownloaded, this);
else {
PatcherLog(kError, " Unable to create file %s", req.fFriendlyName.AsString().c_str());
Finish(false);

6
Sources/Plasma/PubUtilLib/plAudio/plSound.cpp

@ -868,14 +868,14 @@ plSoundBuffer::ELoadReturnVal plSound::IPreLoadBuffer( bool playWhenLoaded, bool
}
}
const char *plSound::GetFileName( void ) const
plFileName plSound::GetFileName( void ) const
{
if(fDataBufferKey->ObjectIsLoaded())
if (fDataBufferKey->ObjectIsLoaded())
{
return ((plSoundBuffer *)fDataBufferKey->ObjectIsLoaded())->GetFileName();
}
return nil;
return "";
}
/////////////////////////////////////////////////////////////////////////

4
Sources/Plasma/PubUtilLib/plAudio/plSound.h

@ -211,9 +211,9 @@ public:
virtual void Update();
plSoundBuffer * GetDataBuffer( void ) const { return (plSoundBuffer *)fDataBufferKey->ObjectIsLoaded(); }
float QueryCurrVolume( void ) const; // Returns the current volume, attenuated
float QueryCurrVolume( void ) const; // Returns the current volume, attenuated
const char * GetFileName( void ) const;
plFileName GetFileName( void ) const;
virtual double GetLength();
void SetProperty( Property prop, bool on ) { if( on ) fProperties |= prop; else fProperties &= ~prop; }

12
Sources/Plasma/PubUtilLib/plAudio/plWin32GroupedSound.cpp

@ -228,14 +228,14 @@ bool plWin32GroupedSound::LoadSound( bool is3D )
IFillCurrentSound( 0 );
// Logging
plString str = plString::Format(" Grouped %s %s allocated (%d msec).", buffer->GetFileName() != nil ? "file" : "buffer",
buffer->GetFileName() != nil ? buffer->GetFileName() : buffer->GetKey()->GetUoid().GetObjectName().c_str(),
//fDSoundBuffer->IsHardwareAccelerated() ? "hardware" : "software",
//fDSoundBuffer->IsStaticVoice() ? "static" : "dynamic",
plString str = plString::Format(" Grouped %s %s allocated (%d msec).", buffer->GetFileName().IsValid() ? "file" : "buffer",
buffer->GetFileName().IsValid() ? buffer->GetFileName().AsString().c_str() : buffer->GetKey()->GetUoid().GetObjectName().c_str(),
//fDSoundBuffer->IsHardwareAccelerated() ? "hardware" : "software",
//fDSoundBuffer->IsStaticVoice() ? "static" : "dynamic",
#ifdef PL_PROFILE_ENABLED
gProfileVarStaticSndShoveTime.GetValue() );
gProfileVarStaticSndShoveTime.GetValue() );
#else
0 );
0 );
#endif
IPrintDbgMessage( str.c_str() );
if( GetKey() != nil && GetKeyName().Find( "Footstep" ) >= 0 )

43
Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp

@ -44,7 +44,6 @@ 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 "plWin32Sound.h"
#include "plWin32StreamingSound.h"
@ -91,9 +90,6 @@ plWin32StreamingSound::~plWin32StreamingSound()
IUnloadDataBuffer();
delete fDataStream;
fDataStream = nil;
fSrcFilename[ 0 ] = 0;
delete fDeswizzler;
}
@ -117,9 +113,9 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
{
if(fPlayWhenStopped)
return plSoundBuffer::kPending;
bool sfxPath = fNewFilename.size() ? false : true;
bool sfxPath = fNewFilename.IsValid() ? false : true;
if( fDataStream != nil && fNewFilename.size() == 0)
if (fDataStream != nil && !fNewFilename.IsValid())
return plSoundBuffer::kSuccess; // Already loaded
if(!ILoadDataBuffer())
@ -131,11 +127,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
return plSoundBuffer::kError;
// The databuffer also needs to know if the source is compressed or not
if(fNewFilename.length())
if (fNewFilename.IsValid())
{
buffer->SetFileName(fNewFilename.c_str());
buffer->SetFileName(fNewFilename);
buffer->SetFlag(plSoundBuffer::kStreamCompressed, fIsCompressed);
fNewFilename.clear();
fNewFilename = "";
if(fReallyPlaying)
{
fPlayWhenStopped = true;
@ -172,8 +168,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
}
}
char str[ 256 ];
strncpy( fSrcFilename, buffer->GetFileName(), sizeof( fSrcFilename ) );
fSrcFilename = buffer->GetFileName();
bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0);
delete fDataStream;
@ -185,17 +180,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0);
/// Open da file
char strPath[ kFolderIterator_MaxPath ];
plFileName strPath = plFileSystem::GetCWD();
getcwd(strPath, kFolderIterator_MaxPath);
if(sfxPath)
strcat( strPath, "\\sfx\\" );
else
{
// if we've changing the filename don't append 'sfx', just append a '\' since a path to the folder is expected
strcat( strPath, "\\");
}
strcat( strPath, fSrcFilename );
if (sfxPath)
strPath = plFileName::Join(strPath, "sfx");
strPath = plFileName::Join(strPath, fSrcFilename);
fDataStream = plAudioFileReader::CreateReader(strPath, select,type);
}
@ -206,8 +195,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
return plSoundBuffer::kError;
}
sprintf( str, " Readied file %s for streaming", fSrcFilename );
IPrintDbgMessage( str );
IPrintDbgMessage(plString::Format(" Readied file %s for streaming", fSrcFilename.AsString().c_str()).c_str());
// dont free sound data until we have a chance to use it in load sound
@ -231,7 +219,7 @@ void plWin32StreamingSound::IFreeBuffers( void )
delete fDataStream;
fDataStream = nil;
}
fSrcFilename[ 0 ] = 0;
fSrcFilename = "";
}
}
@ -303,9 +291,10 @@ bool plWin32StreamingSound::LoadSound( bool is3D )
delete fDSoundBuffer;
fDSoundBuffer = nil;
char str[256];
sprintf(str, "Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file. Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.", GetFileName());
IPrintDbgMessage( str, true );
plString str = plString::Format("Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file."
" Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.",
GetFileName().AsString().c_str());
IPrintDbgMessage(str.c_str(), true);
fFailed = true;
return false;
}

16
Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.h

@ -70,15 +70,15 @@ public:
virtual bool MsgReceive( plMessage *pMsg );
protected:
float fTimeAtBufferStart;
plAudioFileReader *fDataStream;
float fBufferLengthInSecs;
uint8_t fBlankBufferFillCounter;
plSoundDeswizzler *fDeswizzler;
char fSrcFilename[ 256 ];
float fTimeAtBufferStart;
plAudioFileReader *fDataStream;
float fBufferLengthInSecs;
uint8_t fBlankBufferFillCounter;
plSoundDeswizzler *fDeswizzler;
plFileName fSrcFilename;
StreamType fStreamType;
bool fIsCompressed; // this applies only to the new sound file specified in fNewFilename, so we can play both ogg's and wav's
std::string fNewFilename; // allow the filename to be changed so we can play from a different source.
plFileName fNewFilename; // allow the filename to be changed so we can play from a different source.
// ultimately this filename will be given to fDataBuffer, but since it's not always around we'll store it here
bool fStopping;
@ -86,7 +86,7 @@ protected:
bool fPlayWhenStopped;
unsigned fStartPos;
float IGetTimeAtBufferStart( void ) { return fTimeAtBufferStart; }
float IGetTimeAtBufferStart( void ) { return fTimeAtBufferStart; }
virtual void SetStartPos(unsigned bytes);
virtual void IDerivedActuallyPlay( void );

47
Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp

@ -55,8 +55,6 @@ 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 "plUnifiedTime/plUnifiedTime.h"
#include "plBufferedFileReader.h"
#include "plCachedFileReader.h"
@ -66,20 +64,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define kCacheDirName "temp"
plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore::ChannelSelect whichChan, StreamType type)
plAudioFileReader* plAudioFileReader::CreateReader(const plFileName& path, plAudioCore::ChannelSelect whichChan, StreamType type)
{
const char* ext = plFileUtils::GetFileExt(path);
plString ext = path.GetFileExt();
if (type == kStreamWAV)
{
bool isWav = (stricmp(ext, "wav") == 0);
bool isWav = (ext.CompareI("wav") == 0);
// We want to stream a wav off disk, but this is a compressed file.
// Get the uncompressed path. Ignore the requested channel, since it
// will have already been split into two files if that is necessary.
if (!isWav)
{
char cachedPath[256];
IGetCachedPath(path, cachedPath, whichChan);
plFileName cachedPath = IGetCachedPath(path, whichChan);
plAudioFileReader *r = new plCachedFileReader(cachedPath, plAudioCore::kAll);
if (!r->IsValid()) {
// So we tried to play a cached file and it didn't exist
@ -102,43 +99,37 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore
return nil;
}
plAudioFileReader* plAudioFileReader::CreateWriter(const char* path, plWAVHeader& header)
plAudioFileReader* plAudioFileReader::CreateWriter(const plFileName& path, plWAVHeader& header)
{
const char* ext = plFileUtils::GetFileExt(path);
plAudioFileReader* writer = new plCachedFileReader(path, plAudioCore::kAll);
writer->OpenForWriting(path, header);
return writer;
}
void plAudioFileReader::IGetCachedPath(const char* path, char* cachedPath, plAudioCore::ChannelSelect whichChan)
plFileName plAudioFileReader::IGetCachedPath(const plFileName& path, plAudioCore::ChannelSelect whichChan)
{
// Get the file's path and add our streaming cache folder to it
strcpy(cachedPath, path);
plFileUtils::StripFile(cachedPath);
strcat(cachedPath, kCacheDirName"\\");
plFileName cachedPath = plFileName::Join(path.StripFileName(), kCacheDirName);
// Create the directory first
plFileUtils::CreateDir(cachedPath);
// Get the path to the cached version of the file, without the extension
const char* fileName = plFileUtils::GetFileName(path);
const char* fileExt = plFileUtils::GetFileExt(fileName);
strncat(cachedPath, fileName, fileExt-fileName-1);
plFileSystem::CreateDir(cachedPath);
const char *suffix = "";
if (whichChan == plAudioCore::kLeft)
strcat(cachedPath, "-Left.tmp");
suffix = "-Left.tmp";
else if (whichChan == plAudioCore::kRight)
strcat(cachedPath, "-Right.tmp");
suffix = "-Right.tmp";
else if (whichChan == plAudioCore::kAll)
strcat(cachedPath, ".tmp");
suffix = ".tmp";
// Get the path to the cached version of the file, without the extension
return plFileName::Join(cachedPath, path.GetFileNameNoExt() + suffix);
}
void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan)
void plAudioFileReader::ICacheFile(const plFileName& path, bool noOverwrite, plAudioCore::ChannelSelect whichChan)
{
char cachedPath[256];
IGetCachedPath(path, cachedPath, whichChan);
if (!noOverwrite || !plFileUtils::FileExists(cachedPath))
plFileName cachedPath = IGetCachedPath(path, whichChan);
if (!noOverwrite || !plFileInfo(cachedPath).Exists())
{
plAudioFileReader* reader = plAudioFileReader::CreateReader(path, whichChan, kStreamNative);
if (!reader || !reader->IsValid())
@ -169,7 +160,7 @@ void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCo
}
}
void plAudioFileReader::CacheFile(const char* path, bool splitChannels, bool noOverwrite)
void plAudioFileReader::CacheFile(const plFileName& path, bool splitChannels, bool noOverwrite)
{
if (splitChannels)
{

13
Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.h

@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// Class Definition ////////////////////////////////////////////////////////
class plFileName;
class plUnifiedTime;
class plWAVHeader;
class plAudioFileReader
@ -80,20 +81,20 @@ public:
virtual bool Read( uint32_t numBytes, void *buffer ) = 0;
virtual uint32_t NumBytesLeft( void ) = 0;
virtual bool OpenForWriting( const char *path, plWAVHeader &header ) { return false; }
virtual bool OpenForWriting( const plFileName& path, plWAVHeader &header ) { return false; }
virtual uint32_t Write( uint32_t bytes, void *buffer ) { return 0; }
virtual bool IsValid( void ) = 0;
static plAudioFileReader* CreateReader(const char* path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll, StreamType type = kStreamWAV);
static plAudioFileReader* CreateWriter(const char* path, plWAVHeader& header);
static plAudioFileReader* CreateReader(const plFileName& path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll, StreamType type = kStreamWAV);
static plAudioFileReader* CreateWriter(const plFileName& path, plWAVHeader& header);
// Decompresses a compressed file to the cache directory
static void CacheFile(const char* path, bool splitChannels=false, bool noOverwrite=false);
static void CacheFile(const plFileName& path, bool splitChannels=false, bool noOverwrite=false);
protected:
static void IGetCachedPath(const char* path, char* cachedPath, plAudioCore::ChannelSelect whichChan);
static void ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan);
static plFileName IGetCachedPath(const plFileName& path, plAudioCore::ChannelSelect whichChan);
static void ICacheFile(const plFileName& path, bool noOverwrite, plAudioCore::ChannelSelect whichChan);
};
#endif //_plAudioFileReader_h

5
Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp

@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <string.h>
#include "HeadSpin.h"
#include "plBufferedFileReader.h"
#include "plFileSystem.h"
//#include "plProfile.h"
@ -64,14 +65,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// Constructor/Destructor //////////////////////////////////////////////////
plBufferedFileReader::plBufferedFileReader( const char *path, plAudioCore::ChannelSelect whichChan )
plBufferedFileReader::plBufferedFileReader( const plFileName &path, plAudioCore::ChannelSelect whichChan )
{
// Init some stuff
fBufferSize = 0;
fBuffer = nil;
fCursor = 0;
hsAssert( path != nil, "Invalid path specified in plBufferedFileReader" );
hsAssert( path.IsValid(), "Invalid path specified in plBufferedFileReader" );
// Ask plAudioFileReader for another reader to get this file
// Note: have this reader do the chanSelect for us

8
Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.h

@ -59,7 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plBufferedFileReader : public plAudioFileReader
{
public:
plBufferedFileReader( const char *path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
plBufferedFileReader( const plFileName &path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
virtual ~plBufferedFileReader();
virtual plWAVHeader &GetHeader( void );
@ -72,10 +72,10 @@ public:
virtual bool IsValid( void ) { return ( fBuffer != nil ) ? true : false; }
protected:
uint32_t fBufferSize;
uint8_t *fBuffer;
uint32_t fBufferSize;
uint8_t *fBuffer;
plWAVHeader fHeader;
uint32_t fCursor;
uint32_t fCursor;
void IError( const char *msg );
};

18
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp

@ -55,16 +55,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//// Constructor/Destructor //////////////////////////////////////////////////
plCachedFileReader::plCachedFileReader(const char *path,
plCachedFileReader::plCachedFileReader(const plFileName &path,
plAudioCore::ChannelSelect whichChan)
: fFileHandle(nil), fCurPosition(0)
: fFilename(path), fFileHandle(nil), fCurPosition(0)
{
hsAssert(path != nil, "Invalid path specified in plCachedFileReader");
strncpy(fFilename, path, sizeof(fFilename));
hsAssert(path.IsValid(), "Invalid path specified in plCachedFileReader");
/// Open the file as a plain binary stream
fFileHandle = fopen(path, "rb");
fFileHandle = plFileSystem::Open(path, "rb");
if (fFileHandle != nil)
{
if (fread(&fHeader, 1, sizeof(plWAVHeader), fFileHandle)
@ -162,17 +160,17 @@ uint32_t plCachedFileReader::NumBytesLeft()
return fDataLength - fCurPosition;
}
bool plCachedFileReader::OpenForWriting(const char *path, plWAVHeader &header)
bool plCachedFileReader::OpenForWriting(const plFileName &path, plWAVHeader &header)
{
hsAssert(path != nil, "Invalid path specified in plCachedFileReader");
hsAssert(path.IsValid(), "Invalid path specified in plCachedFileReader");
fHeader = header;
fCurPosition = 0;
fDataLength = 0;
strncpy(fFilename, path, sizeof(fFilename));
fFilename = path;
/// Open the file as a plain binary stream
fFileHandle = fopen(path, "wb");
fFileHandle = plFileSystem::Open(path, "wb");
if (fFileHandle != nil)
{

11
Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h

@ -54,13 +54,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plcachedfilereader_h
#include "plAudioFileReader.h"
#include "plFileSystem.h"
//// Class Definition ////////////////////////////////////////////////////////
class plCachedFileReader : public plAudioFileReader
{
public:
plCachedFileReader(const char *path,
plCachedFileReader(const plFileName &path,
plAudioCore::ChannelSelect whichChan = plAudioCore::kAll);
virtual ~plCachedFileReader();
@ -75,7 +76,7 @@ public:
virtual bool Read(uint32_t numBytes, void *buffer);
virtual uint32_t NumBytesLeft();
virtual bool OpenForWriting(const char *path, plWAVHeader &header);
virtual bool OpenForWriting(const plFileName &path, plWAVHeader &header);
virtual uint32_t Write(uint32_t bytes, void *buffer);
virtual bool IsValid() { return fFileHandle != nil; }
@ -86,11 +87,11 @@ protected:
kPCMFormatTag = 1
};
char fFilename[512];
plFileName fFilename;
FILE * fFileHandle;
plWAVHeader fHeader;
uint32_t fDataLength;
uint32_t fCurPosition;
uint32_t fDataLength;
uint32_t fCurPosition;
void IError(const char *msg);
};

10
Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.cpp

@ -112,14 +112,14 @@ class plRIFFHeader
//// Constructor/Destructor //////////////////////////////////////////////////
plFastWAV::plFastWAV( const char *path, plAudioCore::ChannelSelect whichChan ) : fFileHandle( nil )
plFastWAV::plFastWAV( const plFileName &path, plAudioCore::ChannelSelect whichChan ) : fFileHandle( nil )
{
hsAssert( path != nil, "Invalid path specified in plFastWAV reader" );
hsAssert(path.IsValid(), "Invalid path specified in plFastWAV reader");
strncpy( fFilename, path, sizeof( fFilename ) );
fFilename = path;
fWhichChannel = whichChan;
fFileHandle = fopen( path, "rb" );
fFileHandle = plFileSystem::Open(path, "rb");
if( fFileHandle != nil )
{
/// Read in our header and calc our start position
@ -227,7 +227,7 @@ void plFastWAV::Open()
if(fFileHandle)
return;
fFileHandle = fopen( fFilename, "rb" );
fFileHandle = plFileSystem::Open(fFilename, "rb");
if(!fFileHandle)
return;

11
Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.h

@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plFastWavReader_h
#include "plAudioFileReader.h"
#include "plFileSystem.h"
//// Class Definition ////////////////////////////////////////////////////////
@ -60,7 +61,7 @@ class plRIFFChunk;
class plFastWAV : public plAudioFileReader
{
public:
plFastWAV( const char *path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
plFastWAV( const plFileName &path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
virtual ~plFastWAV();
virtual plWAVHeader &GetHeader( void );
@ -83,13 +84,13 @@ protected:
kPCMFormatTag = 1
};
char fFilename[ 512 ];
plFileName fFilename;
FILE * fFileHandle;
plWAVHeader fHeader, fFakeHeader;
uint32_t fDataStartPos, fCurrDataPos, fDataSize;
uint32_t fChunkStart;
uint32_t fDataStartPos, fCurrDataPos, fDataSize;
uint32_t fChunkStart;
plAudioCore::ChannelSelect fWhichChannel;
uint32_t fChannelAdjust, fChannelOffset;
uint32_t fChannelAdjust, fChannelOffset;
void IError( const char *msg );
bool ISeekToChunk( const char *type, plRIFFChunk *c );

10
Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp

@ -65,7 +65,7 @@ uint8_t plOGGCodec::fDecodeFlags = 0;
//// Constructor/Destructor //////////////////////////////////////////////////
plOGGCodec::plOGGCodec( const char *path, plAudioCore::ChannelSelect whichChan ) : fFileHandle( nil )
plOGGCodec::plOGGCodec( const plFileName &path, plAudioCore::ChannelSelect whichChan ) : fFileHandle( nil )
{
fOggFile = nil;
IOpen( path, whichChan );
@ -112,17 +112,17 @@ bool plOGGCodec::ReadFromHeader(int numBytes, void *data)
return false;
}
void plOGGCodec::IOpen( const char *path, plAudioCore::ChannelSelect whichChan )
void plOGGCodec::IOpen( const plFileName &path, plAudioCore::ChannelSelect whichChan )
{
hsAssert( path != nil, "Invalid path specified in plOGGCodec reader" );
hsAssert( path.IsValid(), "Invalid path specified in plOGGCodec reader" );
// plNetClientApp::StaticDebugMsg("Ogg Open %s, t=%f, start", path, hsTimer::GetSeconds());
strncpy( fFilename, path, sizeof( fFilename ) );
fFilename = path;
fWhichChannel = whichChan;
/// Open the file as a plain binary stream
fFileHandle = fopen( path, "rb" );
fFileHandle = plFileSystem::Open(path, "rb");
if( fFileHandle != nil )
{
/// Create the OGG data struct

21
Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plOGGCodec_h
#include "plAudioFileReader.h"
#include "plFileSystem.h"
//// Class Definition ////////////////////////////////////////////////////////
@ -59,7 +60,7 @@ class plOGGCodec : public plAudioFileReader
{
public:
plOGGCodec( const char *path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
plOGGCodec( const plFileName &path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
virtual ~plOGGCodec();
enum DecodeFormat
@ -88,7 +89,7 @@ public:
static void SetDecodeFormat( DecodeFormat f ) { fDecodeFormat = f; }
static void SetDecodeFlag( uint8_t flag, bool on ) { if( on ) fDecodeFlags |= flag; else fDecodeFlags &= ~flag; }
static uint8_t GetDecodeFlags( void ) { return fDecodeFlags; }
static uint8_t GetDecodeFlags( void ) { return fDecodeFlags; }
void ResetWaveHeaderRef() { fCurHeaderPos = 0; }
void BuildActualWaveHeader();
bool ReadFromHeader(int numBytes, void *data); // read from Actual wave header
@ -100,23 +101,23 @@ protected:
kPCMFormatTag = 1
};
char fFilename[ 512 ];
FILE *fFileHandle;
OggVorbis_File *fOggFile;
plFileName fFilename;
FILE *fFileHandle;
OggVorbis_File *fOggFile;
plWAVHeader fHeader, fFakeHeader;
uint32_t fDataStartPos, fCurrDataPos, fDataSize;
uint32_t fDataStartPos, fCurrDataPos, fDataSize;
plAudioCore::ChannelSelect fWhichChannel;
uint32_t fChannelAdjust, fChannelOffset;
uint32_t fChannelAdjust, fChannelOffset;
static DecodeFormat fDecodeFormat;
static uint8_t fDecodeFlags;
uint8_t * fHeadBuf;
static uint8_t fDecodeFlags;
uint8_t * fHeadBuf;
int fCurHeaderPos;
void IError( const char *msg );
void IOpen( const char *path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
void IOpen( const plFileName &path, plAudioCore::ChannelSelect whichChan = plAudioCore::kAll );
};
#endif //_plOGGCodec_h

85
Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp

@ -49,34 +49,29 @@ 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 "plUnifiedTime/plUnifiedTime.h"
#include "plStatusLog/plStatusLog.h"
#include "hsTimer.h"
static void GetFullPath( const char filename[], char *destStr )
static plFileName GetFullPath(const plFileName &filename)
{
char path[ kFolderIterator_MaxPath ];
if (filename.StripFileName().IsValid())
return filename;
if( strchr( filename, '\\' ) != nil )
strcpy( path, filename );
else
sprintf( path, "sfx\\%s", filename );
strcpy( destStr, path );
return plFileName::Join("sfx", filename);
}
//// IGetReader //////////////////////////////////////////////////////////////
// Makes sure the sound is ready to load without any extra processing (like
// decompression or the like), then opens a reader for it.
// fullpath tells the function whether to append 'sfx' to the path or not (we don't want to do this if were providing the full path)
static plAudioFileReader *CreateReader( bool fullpath, const char filename[], plAudioFileReader::StreamType type, plAudioCore::ChannelSelect channel )
static plAudioFileReader *CreateReader( bool fullpath, const plFileName &filename, plAudioFileReader::StreamType type, plAudioCore::ChannelSelect channel )
{
char path[512];
if(fullpath) GetFullPath(filename, path);
plFileName path;
if (fullpath)
path = GetFullPath(filename);
else
strcpy(path, filename);
path = filename;
plAudioFileReader* reader = plAudioFileReader::CreateReader(path, channel, type);
@ -166,7 +161,7 @@ plSoundBuffer::plSoundBuffer()
IInitBuffer();
}
plSoundBuffer::plSoundBuffer( const char *fileName, uint32_t flags )
plSoundBuffer::plSoundBuffer( const plFileName &fileName, uint32_t flags )
{
IInitBuffer();
SetFileName( fileName );
@ -186,7 +181,6 @@ plSoundBuffer::~plSoundBuffer()
}
}
delete [] fFileName;
UnLoad();
}
@ -194,7 +188,7 @@ void plSoundBuffer::IInitBuffer()
{
fError = false;
fValid = false;
fFileName = nil;
fFileName = "";
fData = nil;
fDataLength = 0;
fFlags = 0;
@ -225,7 +219,7 @@ void plSoundBuffer::Read( hsStream *s, hsResMgr *mgr )
s->ReadLE( &fFlags );
s->ReadLE( &fDataLength );
fFileName = s->ReadSafeString();
fFileName = s->ReadSafeString_TEMP();
s->ReadLE( &fHeader.fFormatTag );
s->ReadLE( &fHeader.fNumChannels );
@ -266,16 +260,10 @@ void plSoundBuffer::Write( hsStream *s, hsResMgr *mgr )
s->WriteLE( fDataLength );
// Truncate the path to just a file name on write
if( fFileName != nil )
{
char *nameOnly = strrchr( fFileName, '\\' );
if( nameOnly != nil )
s->WriteSafeString( nameOnly + 1 );
else
s->WriteSafeString( fFileName );
}
if (fFileName.IsValid())
s->WriteSafeString(fFileName.GetFileName());
else
s->WriteSafeString( "" );
s->WriteSafeString("");
s->WriteLE( fHeader.fFormatTag );
s->WriteLE( fHeader.fNumChannels );
@ -290,7 +278,7 @@ void plSoundBuffer::Write( hsStream *s, hsResMgr *mgr )
//// SetFileName /////////////////////////////////////////////////////////////
void plSoundBuffer::SetFileName( const char *name )
void plSoundBuffer::SetFileName( const plFileName &name )
{
if(fLoading)
{
@ -298,11 +286,7 @@ void plSoundBuffer::SetFileName( const char *name )
return;
}
delete [] fFileName;
if( name != nil )
fFileName = hsStrcpy( name );
else
fFileName = nil;
fFileName = name;
// Data is no longer valid
UnLoad();
@ -325,22 +309,17 @@ plAudioCore::ChannelSelect plSoundBuffer::GetReaderSelect( void ) const
//// IGetFullPath ////////////////////////////////////////////////////////////
// Construct our current full path to our sound.
void plSoundBuffer::IGetFullPath( char *destStr )
plFileName plSoundBuffer::IGetFullPath()
{
if(!fFileName)
if (!fFileName.IsValid())
{
*destStr = 0;
return;
return plFileName();
}
char path[ kFolderIterator_MaxPath ];
if( strchr( fFileName, '\\' ) != nil )
strcpy( path, fFileName );
else
sprintf( path, "sfx\\%s", fFileName );
if (fFileName.StripFileName().IsValid())
return fFileName;
strcpy( destStr, path );
return plFileName::Join("sfx", fFileName);
}
@ -459,8 +438,9 @@ void plSoundBuffer::SetLoaded(bool loaded)
void plSoundBuffer::SetInternalData( plWAVHeader &header, uint32_t length, uint8_t *data )
{
if(fLoading) return;
fFileName = nil;
if (fLoading)
return;
fFileName = "";
fHeader = header;
fFlags = 0;
@ -509,11 +489,9 @@ plSoundBuffer::ELoadReturnVal plSoundBuffer::EnsureInternal()
//// IGrabHeaderInfo /////////////////////////////////////////////////////////
bool plSoundBuffer::IGrabHeaderInfo( void )
{
static char path[ 512 ];
if( fFileName != nil )
if (fFileName.IsValid())
{
IGetFullPath( path );
plFileName path = IGetFullPath();
// Go grab from the WAV file
if(!fReader)
@ -545,10 +523,11 @@ bool plSoundBuffer::IGrabHeaderInfo( void )
// fullpath tells the function whether to append 'sfx' to the path or not (we don't want to do this if were providing the full path)
plAudioFileReader *plSoundBuffer::IGetReader( bool fullpath )
{
char path[512];
if(fullpath) IGetFullPath(path);
plFileName path;
if (fullpath)
path = IGetFullPath();
else
strcpy(path, fFileName);
path = fFileName;
// Go grab from the WAV file
plAudioFileReader::StreamType type = plAudioFileReader::kStreamWAV;

27
Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h

@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAudioCore.h"
#include "plAudioFileReader.h"
#include "hsThread.h"
#include "plFileSystem.h"
//// Class Definition ////////////////////////////////////////////////////////
@ -65,7 +66,7 @@ class plSoundBuffer : public hsKeyedObject
{
public:
plSoundBuffer();
plSoundBuffer( const char *fileName, uint32_t flags = 0 );
plSoundBuffer( const plFileName &fileName, uint32_t flags = 0 );
~plSoundBuffer();
CLASSNAME_REGISTER( plSoundBuffer );
@ -93,14 +94,14 @@ public:
virtual void Write( hsStream *s, hsResMgr *mgr );
plWAVHeader &GetHeader( void ) { return fHeader; }
uint32_t GetDataLength( void ) const { return fDataLength; }
uint32_t GetDataLength( void ) const { return fDataLength; }
void SetDataLength(unsigned length) { fDataLength = length; }
void *GetData( void ) const { return fData; }
const char *GetFileName( void ) const { return fFileName; }
void *GetData( void ) const { return fData; }
plFileName GetFileName( void ) const { return fFileName; }
bool IsValid( void ) const { return fValid; }
float GetDataLengthInSecs( void ) const;
float GetDataLengthInSecs( void ) const;
void SetFileName( const char *name );
void SetFileName( const plFileName &name );
bool HasFlag( uint32_t flag ) { return ( fFlags & flag ) ? true : false; }
void SetFlag( uint32_t flag, bool yes = true ) { if( yes ) fFlags |= flag; else fFlags &= ~flag; }
@ -135,22 +136,22 @@ protected:
bool IGrabHeaderInfo( void );
void IAddBuffers( void *base, void *toAdd, uint32_t lengthInBytes, uint8_t bitsPerSample );
void IGetFullPath( char *destStr );
plFileName IGetFullPath();
uint32_t fFlags;
uint32_t fFlags;
bool fValid;
uint32_t fDataRead;
char *fFileName;
uint32_t fDataRead;
plFileName fFileName;
bool fLoaded;
bool fLoading;
bool fError;
plAudioFileReader * fReader;
uint8_t * fData;
uint8_t * fData;
plWAVHeader fHeader;
uint32_t fDataLength;
uint32_t fAsyncLoadLength;
uint32_t fDataLength;
uint32_t fAsyncLoadLength;
plAudioFileReader::StreamType fStreamType;
// for plugins only

2
Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp

@ -277,7 +277,7 @@ void plClothingItem::Write(hsStream *s, hsResMgr *mgr)
if (fAccessoryName)
{
plString strBuf = plString::Format("CItm_%s", fAccessoryName);
accessoryKey = plKeyFinder::Instance().StupidSearch("GlobalClothing", nil, plClothingItem::Index(), strBuf);
accessoryKey = plKeyFinder::Instance().StupidSearch("GlobalClothing", "", plClothingItem::Index(), strBuf);
if (accessoryKey == nil)
{
strBuf = plString::Format("Couldn't find accessory \"%s\". It won't show at runtime.", fAccessoryName);

12
Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt

@ -5,28 +5,16 @@ include_directories("../../PubUtilLib")
include_directories(${ZLIB_INCLUDE_DIR})
set(plFile_SOURCES
hsFiles.cpp
plBrowseFolder.cpp
plEncryptedStream.cpp
plFileUtils.cpp
plInitFileReader.cpp
plSecureStream.cpp
plStreamSource.cpp
)
if(WIN32 AND NOT CYGWIN)
set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Win.cpp)
endif(WIN32 AND NOT CYGWIN)
if(UNIX)
set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Unix.cpp)
endif(UNIX)
set(plFile_HEADERS
hsFiles.h
plBrowseFolder.h
plEncryptedStream.h
plFileUtils.h
plInitFileReader.h
plSecureStream.h
plStreamSource.h

182
Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp

@ -1,182 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsFiles.h"
#include <string.h>
#include "hsExceptions.h"
#if HS_BUILD_FOR_WIN32
#define kDirChar '\\'
#else
#define kDirChar '/'
#endif
static const char* FindNameInPath(const char path[])
{
const char* name = ::strrchr(path, kDirChar);
if (name == nil)
name = path;
return name;
}
///////////////////////////////////////////////////////////////////////
hsFile::hsFile() : fPathAndName(nil), fFILE(nil)
{
}
hsFile::hsFile(const char pathAndName[]) : fPathAndName(nil), fFILE(nil)
{
if (pathAndName)
fPathAndName = hsStrcpy(pathAndName);
}
hsFile::~hsFile()
{
this->SetPathAndName(nil);
}
const char* hsFile::GetPathAndName()
{
return fPathAndName;
}
void hsFile::SetPathAndName(const char pathAndName[])
{
this->Close();
if (fPathAndName)
{ delete[] fPathAndName;
fPathAndName = nil;
}
if (pathAndName)
fPathAndName = hsStrcpy(pathAndName);
}
const char* hsFile::GetName()
{
return FindNameInPath(this->GetPathAndName());
}
FILE* hsFile::OpenFILE(const char mode[], bool throwIfFailure)
{
this->Close();
// We call the virtual method here rather than using
// fPathAndName directly, allowing a subclass to construct
// the name if necessary
//
const char* name = this->GetPathAndName();
if (name)
fFILE = ::fopen(name, mode);
hsThrowIfTrue(throwIfFailure && fFILE == nil);
return fFILE;
}
hsStream* hsFile::OpenStream(const char mode[], bool throwIfFailure)
{
FILE* file = this->OpenFILE(mode, throwIfFailure);
if (file)
{ hsUNIXStream* stream = new hsUNIXStream;
stream->SetFILE(file);
return stream;
}
return nil;
}
void hsFile::Close()
{
if (fFILE)
{ int err = ::fflush(fFILE);
hsIfDebugMessage(err != 0, "fflush failed", err);
err = ::fclose(fFILE);
hsIfDebugMessage(err != 0, "fclose failed", err);
fFILE = nil;
}
}
///////////////////////////////////////////////////////////////////////
bool hsFolderIterator::NextFileSuffix(const char suffix[])
{
while (this->NextFile())
{ const char* fileSuffix = ::strrchr(this->GetFileName(), '.');
if (fileSuffix != nil && stricmp(fileSuffix, suffix) == 0)
return true;
}
return false;
}
int hsFolderIterator::GetPathAndName(char pathandname[])
{
hsAssert(pathandname, "NULL path string");
const char* name = this->GetFileName();
int pathLen = strlen(fPath);
// add 1 for null terminator
int totalLen = pathLen + sizeof(kDirChar) + strlen(name) + 1;
hsAssert(totalLen <= kFolderIterator_MaxPath, "Overrun kFolderIterator_MaxPath");
if (pathandname)
{
strcpy(pathandname, fPath);
if (pathLen > 0 && pathandname[pathLen - 1] != kDirChar)
pathandname[pathLen++] = kDirChar;
strcpy(pathandname + pathLen, name);
}
return totalLen;
}
FILE* hsFolderIterator::OpenFILE(const char mode[])
{
char fileName[kFolderIterator_MaxPath];
(void)this->GetPathAndName(fileName);
return ::fopen(fileName, mode);
}

141
Sources/Plasma/PubUtilLib/plFile/hsFiles.h

@ -1,141 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsFiles_Defined
#define hsFiles_Defined
#include "hsStream.h"
#include <stdio.h>
#if HS_BUILD_FOR_UNIX
#include <limits.h>
#define kFolderIterator_MaxPath PATH_MAX
#define SetCurrentDirectory chdir
#else
#define kFolderIterator_MaxPath _MAX_PATH
#endif
///////////////////////////////////////////////////////////////////////
class hsFile {
hsFile& operator=(const hsFile&); // disallow assignment
protected:
char* fPathAndName;
FILE* fFILE;
public:
hsFile();
hsFile(const char pathAndName[]);
virtual ~hsFile();
const char* GetName();
virtual const char* GetPathAndName();
virtual void SetPathAndName(const char pathAndName[]);
virtual FILE* OpenFILE(const char mode[], bool throwIfFailure = false);
virtual hsStream* OpenStream(const char mode[], bool throwIfFailure = false);
virtual void Close(); // called automatically in the destructor
};
typedef hsFile hsUnixFile; // for compatibility
typedef hsFile hsOSFile;
///////////////////////////////////////////////////////////////////////
class hsFolderIterator {
char fPath[kFolderIterator_MaxPath];
struct hsFolderIterator_Data* fData;
bool fCustomFilter;
public:
#ifdef HS_BUILD_FOR_WIN32
hsFolderIterator(const char path[] = nil, bool useCustomFilter=false);
#else
hsFolderIterator(const char path[] = nil, bool unused=true);
hsFolderIterator(const struct FSSpec* spec); // Alt constructor
#endif
virtual ~hsFolderIterator();
const char* GetPath() const { return fPath; }
void SetPath(const char path[]);
void Reset();
bool NextFile();
bool NextFileSuffix(const char suffix[]);
const char* GetFileName() const;
int GetPathAndName(char pathandname[] = nil);
bool IsDirectory( void ) const;
FILE* OpenFILE(const char mode[]);
#if HS_BUILD_FOR_WIN32
void SetWinSystemDir(const char subdir[]); // e.g. "Fonts"
void SetFileFilterStr(const char filterStr[]); // e.g. "*.*"
#endif
};
#ifdef HS_BUILD_FOR_WIN32
// only implemented on Win32 for now
class hsWFolderIterator {
wchar_t fPath[kFolderIterator_MaxPath];
struct hsWFolderIterator_Data* fData;
bool fCustomFilter;
public:
hsWFolderIterator(const wchar_t path[] = nil, bool useCustomFilter=false);
virtual ~hsWFolderIterator();
const wchar_t* GetPath() const { return fPath; }
void SetPath(const wchar_t path[]);
void Reset();
bool NextFile();
bool NextFileSuffix(const wchar_t suffix[]);
const wchar_t* GetFileName() const;
int GetPathAndName(wchar_t pathandname[] = nil);
bool IsDirectory( void ) const;
FILE* OpenFILE(const wchar_t mode[]);
void SetWinSystemDir(const wchar_t subdir[]); // e.g. "Fonts"
void SetFileFilterStr(const wchar_t filterStr[]); // e.g. "*.*"
};
#endif
#endif

146
Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp

@ -1,146 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsFiles.h"
#if HS_BUILD_FOR_UNIX
#include <errno.h>
#include <dirent.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <glob.h>
#include <string>
#include "hsTemplates.h"
#include "plFileUtils.h"
struct hsFolderIterator_Data {
glob_t fGlobBuf;
bool fInited;
int fCnt;
hsFolderIterator_Data() : fInited(false), fCnt(0) {}
// ~hsFolderIterator_Data() { fInited=false; globfree(&fData->fGlobBuf); }
};
hsFolderIterator::hsFolderIterator(const char path[], bool)
{
fData = new hsFolderIterator_Data;
this->SetPath(path);
}
hsFolderIterator::~hsFolderIterator()
{
this->Reset();
delete fData;
}
void hsFolderIterator::SetPath(const char path[])
{
fPath[0] = 0;
if (path)
{
::strcpy(fPath, path);
}
this->Reset();
}
void hsFolderIterator::Reset()
{
if (fData->fInited)
{
globfree(&fData->fGlobBuf);
fData->fCnt = 0;
fData->fInited=false;
}
}
bool hsFolderIterator::NextFile()
{
if (fData->fInited == false)
{
std::string path=fPath;
if(!(strchr(fPath,'*') || strchr(fPath,'?') || strchr(fPath,'[')))
{
if (fPath[strlen(fPath)-1] != PATH_SEPARATOR)
path = path + PATH_SEPARATOR_STR + "*";
else
path = path + "*";
}
if(glob(path.c_str(), 0, NULL, &fData->fGlobBuf) != 0 ) {
return false;
}
fData->fInited=true;
fData->fCnt = 0;
}
return fData->fCnt++ < fData->fGlobBuf.gl_pathc;
}
const char* hsFolderIterator::GetFileName() const
{
if (!fData->fInited || fData->fCnt > fData->fGlobBuf.gl_pathc)
throw "end of folder";
const char* fn=fData->fGlobBuf.gl_pathv[fData->fCnt-1];
return plFileUtils::GetFileName(fn);
}
bool hsFolderIterator::IsDirectory( void ) const
{
// rob, please forgive me, this is my best attempt...
if(fData->fCnt > fData->fGlobBuf.gl_pathc )
return false;
struct stat info;
const char* fn=fData->fGlobBuf.gl_pathv[fData->fCnt-1];
if( stat( fn, &info ) )
{
printf("Error calling stat(): %s errno=%d\n", strerror(errno), errno);
return false;
}
return ( info.st_mode & S_IFDIR ) ? true : false;
}
#endif

320
Sources/Plasma/PubUtilLib/plFile/hsFiles_Win.cpp

@ -1,320 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsFiles.h"
#include "HeadSpin.h"
#include "hsWindows.h"
#if HS_BUILD_FOR_WIN32
#include "hsExceptions.h"
struct hsFolderIterator_Data {
HANDLE fSearchHandle;
WIN32_FIND_DATA fFindData;
bool fValid;
};
hsFolderIterator::hsFolderIterator(const char path[], bool useCustomFilter)
{
fCustomFilter = useCustomFilter;
fData = new hsFolderIterator_Data;
fData->fSearchHandle = nil;
fData->fValid = true;
if(useCustomFilter)
{
this->SetFileFilterStr(path);
}
else
{
this->SetPath(path);
}
}
hsFolderIterator::~hsFolderIterator()
{
delete fData;
}
void hsFolderIterator::SetPath(const char path[])
{
fCustomFilter = false;
fPath[0] = 0;
if (path)
{
::strcpy(fPath, path);
// Make sure the dir ends with a slash
char lastchar = fPath[strlen(fPath)-1];
if (lastchar != '\\' && lastchar != '/')
strcat(fPath, "\\");
}
this->Reset();
}
void hsFolderIterator::SetWinSystemDir(const char subdir[])
{
int ret = GetWindowsDirectory(fPath, _MAX_PATH);
hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath");
if (subdir)
{ ::strcat(fPath, "\\");
::strcat(fPath, subdir);
::strcat(fPath, "\\");
}
this->Reset();
}
void hsFolderIterator::SetFileFilterStr(const char filterStr[])
{
fPath[0] = 0;
if (filterStr)
{
fCustomFilter = true;
::strcpy(fPath, filterStr);
}
this->Reset();
}
///////////////////////////////////////////////////////////////////////////////
void hsFolderIterator::Reset()
{
if (fData->fSearchHandle)
{ FindClose(fData->fSearchHandle);
fData->fSearchHandle = nil;
}
fData->fValid = true;
}
bool hsFolderIterator::NextFile()
{
if (fData->fValid == false)
return false;
if (fData->fSearchHandle == nil)
{ int len = ::strlen(fPath);
if(fCustomFilter == false)
{
fPath[len] = '*';
fPath[len+1] = 0;
}
fData->fSearchHandle = FindFirstFile(fPath, &fData->fFindData);
fPath[len] = 0;
if (fData->fSearchHandle == INVALID_HANDLE_VALUE)
{ fData->fSearchHandle = nil;
fData->fValid = false;
return false;
}
}
else
{ if (FindNextFile(fData->fSearchHandle, &fData->fFindData) == false)
{ FindClose(fData->fSearchHandle);
fData->fSearchHandle = nil;
fData->fValid = false;
return false;
}
}
return true;
}
bool hsFolderIterator::IsDirectory( void ) const
{
if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
return true;
return false;
}
const char* hsFolderIterator::GetFileName() const
{
if (fData->fValid == false)
hsThrow( "end of folder");
return fData->fFindData.cFileName;
}
///////////////////////////////////////////////////////////////////////////////
struct hsWFolderIterator_Data {
HANDLE fSearchHandle;
WIN32_FIND_DATAW fFindData;
bool fValid;
};
hsWFolderIterator::hsWFolderIterator(const wchar_t path[], bool useCustomFilter)
{
fCustomFilter = useCustomFilter;
fData = new hsWFolderIterator_Data;
fData->fSearchHandle = nil;
fData->fValid = true;
if(useCustomFilter)
SetFileFilterStr(path);
else
SetPath(path);
}
hsWFolderIterator::~hsWFolderIterator()
{
delete fData;
}
void hsWFolderIterator::SetPath(const wchar_t path[])
{
fCustomFilter = false;
fPath[0] = 0;
if (path)
{
wcscpy(fPath, path);
// Make sure the dir ends with a slash
wchar_t lastchar = fPath[wcslen(fPath)-1];
if (lastchar != L'\\' && lastchar != L'/')
wcscat(fPath, L"\\");
}
Reset();
}
void hsWFolderIterator::SetWinSystemDir(const wchar_t subdir[])
{
int ret = GetWindowsDirectoryW(fPath, _MAX_PATH);
hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath");
if (subdir)
{
wcscat(fPath, L"\\");
wcscat(fPath, subdir);
wcscat(fPath, L"\\");
}
Reset();
}
void hsWFolderIterator::SetFileFilterStr(const wchar_t filterStr[])
{
fPath[0] = 0;
if (filterStr)
{
fCustomFilter = true;
wcscpy(fPath, filterStr);
}
Reset();
}
///////////////////////////////////////////////////////////////////////////////
void hsWFolderIterator::Reset()
{
if (fData->fSearchHandle)
{
FindClose(fData->fSearchHandle);
fData->fSearchHandle = nil;
}
fData->fValid = true;
}
bool hsWFolderIterator::NextFile()
{
if (fData->fValid == false)
return false;
if (fData->fSearchHandle == nil)
{
int len = wcslen(fPath);
if(fCustomFilter == false)
{
fPath[len] = L'*';
fPath[len+1] = L'\0';
}
fData->fSearchHandle = FindFirstFileW(fPath, &fData->fFindData);
fPath[len] = 0;
if (fData->fSearchHandle == INVALID_HANDLE_VALUE)
{
fData->fSearchHandle = nil;
fData->fValid = false;
return false;
}
}
else
{
if (FindNextFileW(fData->fSearchHandle, &fData->fFindData) == false)
{
FindClose(fData->fSearchHandle);
fData->fSearchHandle = nil;
fData->fValid = false;
return false;
}
}
return true;
}
bool hsWFolderIterator::IsDirectory( void ) const
{
if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
return true;
return false;
}
const wchar_t* hsWFolderIterator::GetFileName() const
{
if (fData->fValid == false)
hsThrow( "end of folder");
return fData->fFindData.cFileName;
}
#endif // HS_BUILD_FOR_WIN32

30
Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp

@ -45,22 +45,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <shlobj.h>
bool plBrowseFolder::GetFolder(char *path, const char *startPath, const char *title, HWND hwndOwner)
plFileName plBrowseFolder::GetFolder(const plFileName &startPath, const plString &title, HWND hwndOwner)
{
BROWSEINFO bi;
BROWSEINFOW bi;
memset(&bi, 0, sizeof(bi));
bi.hwndOwner = hwndOwner;
bi.lpszTitle = title;
bi.lpszTitle = title.ToWchar();
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM) startPath;
ITEMIDLIST *iil = SHBrowseForFolder(&bi);
// Browse failed, or cancel was selected
if (!iil)
return false;
// Browse succeded. Get the path.
else
SHGetPathFromIDList(iil, path);
bi.lParam = (LPARAM) startPath.AsString().ToWchar().GetData();
LPITEMIDLIST iil = SHBrowseForFolderW(&bi);
plFileName path;
if (!iil) {
// Browse failed, or cancel was selected
path = "";
} else {
// Browse succeded. Get the path.
wchar_t buffer[MAX_PATH];
SHGetPathFromIDListW(iil, buffer);
path = plString::FromWchar(buffer);
}
// Free the memory allocated by SHBrowseForFolder
LPMALLOC pMalloc;
@ -68,7 +72,7 @@ bool plBrowseFolder::GetFolder(char *path, const char *startPath, const char *ti
pMalloc->Free(iil);
pMalloc->Release();
return true;
return path;
}
int CALLBACK plBrowseFolder::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)

3
Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.h

@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsWindows.h"
#include "plFileSystem.h"
//
// Gets a directory using the "Browse for Folder" dialog.
@ -63,7 +64,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plBrowseFolder
{
public:
static bool GetFolder(char *path, const char *startPath = NULL, const char *title = NULL, HWND hwndOwner = NULL);
static plFileName GetFolder(const plFileName &startPath = "", const plString &title = "", HWND hwndOwner = NULL);
protected:
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);

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

@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "plEncryptedStream.h"
#include "plFileUtils.h"
#include "hsSTLStream.h"
#include <time.h>
@ -63,7 +62,6 @@ plEncryptedStream::plEncryptedStream(uint32_t* key) :
fActualFileSize(0),
fBufferedStream(false),
fRAMStream(nil),
fWriteFileName(nil),
fOpenMode(kOpenFail)
{
if (key)

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

@ -1,503 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/////////////////////////////////////////////////////////////////////////////
//
// plFileUtils - Namespace of fun file utilities
//
//// History /////////////////////////////////////////////////////////////////
//
// 5.7.2002 mcn - Created
// 4.8.2003 chip - added FileCopy and FileMove for Unix
//
//////////////////////////////////////////////////////////////////////////////
#include "HeadSpin.h"
#include "hsWindows.h"
#include "plFileUtils.h"
#include "hsFiles.h"
#include "hsStringTokenizer.h"
#include "plUnifiedTime/plUnifiedTime.h"
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#if HS_BUILD_FOR_WIN32
#include <direct.h>
#include <io.h>
#define mkdir _mkdir
#define chdir _chdir
#define chmod _chmod
#define rmdir _rmdir
#define unlink _unlink
#endif
#if HS_BUILD_FOR_UNIX
#include <unistd.h>
#include <utime.h>
#endif
//// CreateDir ///////////////////////////////////////////////////////////////
// Creates the directory specified. Returns false if unsuccessful or
// directory already exists
bool plFileUtils::CreateDir( const char *path )
{
// Create our directory
#if HS_BUILD_FOR_WIN32
return ( mkdir( path ) == 0 ) ? true : ( errno==EEXIST );
#elif HS_BUILD_FOR_UNIX
return ( mkdir( path, 0777 ) == 0 ) ? true : ( errno==EEXIST );
#endif
}
bool plFileUtils::CreateDir( const wchar_t *path )
{
// Create our directory
#if HS_BUILD_FOR_WIN32
return ( _wmkdir( path ) == 0 ) ? true : ( errno==EEXIST );
#elif HS_BUILD_FOR_UNIX
const char* cpath = hsWStringToString(path);
bool ret = CreateDir(cpath);
delete[] cpath; /* Free the string */
return ret;
#endif
}
bool plFileUtils::RemoveDir(const char* path)
{
return (rmdir(path) == 0);
}
bool plFileUtils::RemoveDirTree(const char * path)
{
hsFolderIterator it(path);
while (it.NextFile())
{
const char * fname = it.GetFileName();
if ( fname[0]=='.' )
continue;
char pathAndName[128];
it.GetPathAndName(pathAndName);
if ( it.IsDirectory() )
{
RemoveDirTree( pathAndName );
RemoveDir( pathAndName );
}
else
{
RemoveFile( pathAndName );
}
}
RemoveDir( path );
return 1;
}
//// RemoveFile ////////////////////////////////////////////////////////////
bool plFileUtils::RemoveFile(const char* filename, bool delReadOnly)
{
if (delReadOnly)
chmod(filename, S_IWRITE);
return (unlink(filename) == 0);
}
bool plFileUtils::RemoveFile(const wchar_t* filename, bool delReadOnly)
{
#ifdef HS_BUILD_FOR_WIN32
if (delReadOnly)
_wchmod(filename, S_IWRITE);
return (_wunlink(filename) == 0);
#elif HS_BUILD_FOR_UNIX
const char* cfilename = hsWStringToString(filename);
bool ret = RemoveFile(cfilename, delReadOnly);
delete[] cfilename; /* Free the string */
return ret;
#endif
}
bool plFileUtils::FileCopy(const char* existingFile, const char* 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_t* existingFile, const wchar_t* newFile)
{
#if HS_BUILD_FOR_WIN32
return (::CopyFileW(existingFile, newFile, FALSE) != 0);
#elif HS_BUILD_FOR_UNIX
char data[1500];
const char* cexisting = hsWStringToString(existingFile);
const char* cnew = hsWStringToString(newFile);
FILE* fp = fopen(cexisting, "rb");
FILE* fw = fopen(cnew, "w");
delete[] cexisting;
delete[] cnew;
int num = 0;
bool retVal = true;
if (fp && fw){
while(!feof(fp)){
num = fread(data, sizeof( char ), 1500, fp);
if( ferror( fp ) ) {
retVal = false;
break;
}
fwrite(data, sizeof( char ), num, fw);
}
fclose(fp);
fclose(fw);
} else {
retVal = false;
}
return retVal;
#else
hsAssert(0, "Not implemented");
return false;
#endif
}
bool plFileUtils::FileMove(const char* existingFile, const char* newFile)
{
#if HS_BUILD_FOR_WIN32
return (::MoveFile(existingFile, newFile) != 0);
#elif HS_BUILD_FOR_UNIX
FileCopy(existingFile,newFile);
return( RemoveFile( existingFile )==0);
#else
hsAssert(0, "Not implemented");
return false;
#endif
}
bool plFileUtils::FileMove(const wchar_t* existingFile, const wchar_t* newFile)
{
#if HS_BUILD_FOR_WIN32
return (::MoveFileW(existingFile, newFile) != 0);
#elif HS_BUILD_FOR_UNIX
FileCopy(existingFile,newFile);
return( RemoveFile( existingFile )==0);
#else
hsAssert(0, "Not implemented");
return false;
#endif
}
bool plFileUtils::FileExists(const wchar_t* file)
{
FILE* fp = hsWFopen(file, L"rb");
bool retVal = (fp != nil);
if (fp)
fclose(fp);
return retVal;
}
bool plFileUtils::FileExists(const char* file)
{
FILE* fp = fopen(file, "rb");
bool retVal = (fp != nil);
if (fp)
fclose(fp);
return retVal;
}
//// EnsureFilePathExists ////////////////////////////////////////////////////
// Given a filename with path, makes sure the file's path exists
bool plFileUtils::EnsureFilePathExists( const char *filename )
{
wchar_t* wFilename = hsStringToWString(filename);
bool ret = EnsureFilePathExists(wFilename);
delete [] wFilename;
return ret;
}
bool plFileUtils::EnsureFilePathExists( const wchar_t *filename )
{
hsWStringTokenizer izer( filename, L"\\/" );
bool lastWorked = false;
wchar_t token[ kFolderIterator_MaxPath ];
while( izer.Next( token, arrsize( token ) ) && izer.HasMoreTokens() )
{
// Want the full path from the start of the string
lastWorked = CreateDir( izer.fString );
izer.RestoreLastTerminator();
}
return lastWorked;
}
//// GetFileTimes ////////////////////////////////////////////////////////////
// Gets the creation and modification dates of the file specified. Returns
// false if unsuccessful
bool plFileUtils::GetFileTimes( const char *path, plUnifiedTime *createTimeOut, plUnifiedTime *modifyTimeOut )
{
struct stat fileInfo;
int result = stat( path, &fileInfo );
if( result != 0 )
return false;
if( createTimeOut != nil )
*createTimeOut = plUnifiedTime( fileInfo.st_ctime );
if( modifyTimeOut != nil )
*modifyTimeOut = plUnifiedTime( fileInfo.st_mtime );
return true;
}
plFileUtils::Modify plFileUtils::CompareModifyTimes(const char* file1, const char* file2)
{
plUnifiedTime modTime1, modTime2;
if (GetFileTimes(file1, nil, &modTime1) &&
GetFileTimes(file2, nil, &modTime2))
{
double diff = plUnifiedTime::GetTimeDifference(modTime1, modTime2);
if (hsABS(diff) <= 2)
return kFilesEqual;
else if (diff > 0)
return kFile1Newer;
else
return kFile2Newer;
}
return kFileError;
}
bool plFileUtils::SetModifyTime( const char * filename, const plUnifiedTime & timestamp )
{
#ifdef HS_BUILD_FOR_WIN32
HANDLE hFile = CreateFile(filename,
GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,
nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,nil);
if (hFile==INVALID_HANDLE_VALUE)
return false;
SYSTEMTIME systime;
systime.wDay = timestamp.GetDay();
systime.wDayOfWeek = timestamp.GetDayOfWeek();
systime.wHour = timestamp.GetHour();
systime.wMilliseconds = 0;
systime.wMinute = timestamp.GetMinute();
systime.wMonth = timestamp.GetMonth();
systime.wSecond = timestamp.GetSecond();
systime.wYear = timestamp.GetYear();
FILETIME localFileTime, filetime;
SystemTimeToFileTime(&systime,&localFileTime);
LocalFileTimeToFileTime(&localFileTime,&filetime);
SetFileTime(hFile,nil,nil,&filetime);
CloseHandle(hFile);
return true;
#elif HS_BUILD_FOR_UNIX
struct stat sbuf;
int result = stat( filename, &sbuf );
if( result )
return false;
struct utimbuf utb;
utb.actime = sbuf.st_atime;
utb.modtime = timestamp.GetSecs();
result = utime( filename, &utb );
if( result )
return false;
return true;
#endif
}
//// StripPath ///////////////////////////////////////////////////////////////
const char* plFileUtils::GetFileName(const char* path)
{
const char* c = strrchr(path, '/');
if (c == nil)
c = strrchr(path, '\\');
if (c == nil)
c = path;
else
c++;
return c;
}
const wchar_t* plFileUtils::GetFileName(const wchar_t* path)
{
const wchar_t* c = wcsrchr(path, L'/');
if (c == nil)
c = wcsrchr(path, L'\\');
if (c == nil)
c = path;
else
c++;
return c;
}
void plFileUtils::StripFile(char* pathAndName)
{
char* fileName = (char*)GetFileName(pathAndName);
if (fileName != pathAndName)
*fileName = '\0';
}
void plFileUtils::StripFile(wchar_t* pathAndName)
{
wchar_t* fileName = (wchar_t*)GetFileName(pathAndName);
if (fileName != pathAndName)
*fileName = L'\0';
}
void plFileUtils::StripExt(char* fileName)
{
char* ext = (char*)GetFileExt(fileName);
if (ext)
*(ext-1) = '\0';
}
void plFileUtils::StripExt(wchar_t* fileName)
{
wchar_t* ext = (wchar_t*)GetFileExt(fileName);
if (ext)
*(ext-1) = L'\0';
}
const char* plFileUtils::GetFileExt(const char* pathAndName)
{
const char* fileName = GetFileName(pathAndName);
if (fileName)
{
const char* ext = strrchr(fileName, '.');
if (ext)
return ext+1;
}
return nil;
}
const wchar_t* plFileUtils::GetFileExt(const wchar_t* pathAndName)
{
const wchar_t* fileName = GetFileName(pathAndName);
if (fileName)
{
const wchar_t* ext = wcsrchr(fileName, L'.');
if (ext)
return ext+1;
}
return nil;
}
void plFileUtils::AddSlash(char* path)
{
char lastChar = path[strlen(path)-1];
if (lastChar != '\\' && lastChar != '/')
#if HS_BUILD_FOR_WIN32
strcat(path, "\\");
#else
strcat(path, "/");
#endif
}
void plFileUtils::AddSlash(wchar_t* path)
{
wchar_t lastChar = path[wcslen(path)-1];
if (lastChar != L'\\' && lastChar != L'/')
#if HS_BUILD_FOR_WIN32
wcscat(path, L"\\");
#else
wcscat(path, L"/");
#endif
}
void plFileUtils::ConcatFileName(char* path, const char* fileName)
{
AddSlash(path);
strcat(path, fileName);
}
void plFileUtils::ConcatFileName(wchar_t* path, const wchar_t* fileName)
{
AddSlash(path);
wcscat(path, fileName);
}
//// GetFileSize /////////////////////////////////////////////////////////////
uint32_t plFileUtils::GetFileSize( const char *path )
{
wchar_t* wPath = hsStringToWString(path);
uint32_t ret = GetFileSize(wPath);
delete [] wPath;
return ret;
}
uint32_t plFileUtils::GetFileSize( const wchar_t *path )
{
uint32_t len = 0;
hsUNIXStream str;
if (str.Open(plString::FromWchar(path), "rb"))
{
len = str.GetEOF();
str.Close();
}
return len;
}

116
Sources/Plasma/PubUtilLib/plFile/plFileUtils.h

@ -1,116 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
//////////////////////////////////////////////////////////////////////////////
//
// plFileUtils - Namespace of fun file utilities
//
//// History /////////////////////////////////////////////////////////////////
//
// 5.7.2002 mcn - Created
//
//////////////////////////////////////////////////////////////////////////////
#ifndef _plFileUtils_h
#define _plFileUtils_h
class plUnifiedTime;
namespace plFileUtils
{
// Creates the directory specified. Returns false if unsuccessful or directory already exists
bool CreateDir( const char *path );
bool CreateDir( const wchar_t *path );
bool RemoveDir(const char* path);
bool RemoveDirTree(const char * path);
// delete file from disk
bool RemoveFile(const char* 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_t* existingFile, const wchar_t* newFile);
bool FileMove(const char* existingFile, const char* newFile);
bool FileMove(const wchar_t* existingFile, const wchar_t* newFile);
bool FileExists(const char* file);
bool FileExists(const wchar_t* file);
// Given a filename with path, makes sure the file's path exists
bool EnsureFilePathExists( const char *filename );
bool EnsureFilePathExists( const wchar_t *filename );
// Gets the creation and modification dates of the file specified. Returns false if unsuccessful
bool GetFileTimes( const char *path, plUnifiedTime *createTimeOut, plUnifiedTime *modifyTimeOut );
// Compares file times, taking into account NTFS/FAT32 time issues
enum Modify { kFileError, kFilesEqual, kFile1Newer, kFile2Newer };
Modify CompareModifyTimes(const char* file1, const char* file2);
// Set file modify time
bool SetModifyTime( const char * filename, const plUnifiedTime & time );
// 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_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_t* GetFileExt(const wchar_t* pathAndName);
// Strips the filename off the given full path
void StripFile(char* pathAndName);
void StripFile(wchar_t* pathAndName);
void StripExt(char* fileName);
void StripExt(wchar_t* fileName);
// Get the size of the given file in bytes
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_t* path);
// 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);
};
#endif // _plFileUtils_h

3
Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp

@ -44,7 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plSecureStream.h"
#include "hsWindows.h"
#include "plFileUtils.h"
#include "hsSTLStream.h"
#include <time.h>
@ -72,7 +71,6 @@ fRef(INVALID_HANDLE_VALUE),
fActualFileSize(0),
fBufferedStream(false),
fRAMStream(nil),
fWriteFileName(nil),
fOpenMode(kOpenFail),
fDeleteOnExit(deleteOnExit)
{
@ -87,7 +85,6 @@ fRef(INVALID_HANDLE_VALUE),
fActualFileSize(0),
fBufferedStream(false),
fRAMStream(nil),
fWriteFileName(nil),
fOpenMode(kOpenFail),
fDeleteOnExit(false)
{

17
Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp

@ -41,11 +41,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include <string>
#include "hsFiles.h"
#include "plStreamSource.h"
#include "plSecureStream.h"
#include "plEncryptedStream.h"
#include "plFileUtils.h"
#if HS_BUILD_FOR_UNIX
# include <wctype.h>
@ -107,8 +105,7 @@ std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, co
// loop through all the file data records, and create the list
std::vector<plFileName> retVal;
decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
for (auto curData = fFileData.begin(); curData != fFileData.end(); curData++)
{
if ((curData->second.fDir == sDir) && (curData->second.fExt == ext))
retVal.push_back(curData->second.fFilename);
@ -117,15 +114,11 @@ std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, co
#ifndef PLASMA_EXTERNAL_RELEASE
// in internal releases, we can use on-disk files if they exist
// Build the search string as "dir/*.ext"
plString searchStr = plFileName::Join(sDir, "*." + ext).AsString();
hsFolderIterator folderIter(searchStr.c_str(), true);
while (folderIter.NextFile())
std::vector<plFileName> files = plFileSystem::ListDir(sDir, ("*." + ext).c_str());
for (auto iter = files.begin(); iter != files.end(); ++iter)
{
plFileName filename = plFileName::Join(sDir, folderIter.GetFileName());
if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet
retVal.push_back(filename);
if (fFileData.find(*iter) == fFileData.end()) // we haven't added it yet
retVal.push_back(*iter);
}
#endif // PLASMA_EXTERNAL_RELEASE

2
Sources/Plasma/PubUtilLib/plGImage/plFont.cpp

@ -1063,7 +1063,7 @@ uint8_t *plFont::IGetFreeCharData( uint32_t &newOffset )
//// LoadFromP2FFile //////////////////////////////////////////////////////////
// Handy quick wrapper
bool plFont::LoadFromP2FFile( const char *path )
bool plFont::LoadFromP2FFile( const plFileName &path )
{
hsUNIXStream stream;
if( stream.Open( path, "rb" ) )

2
Sources/Plasma/PubUtilLib/plGImage/plFont.h

@ -289,7 +289,7 @@ class plFont : public hsKeyedObject
bool LoadFromBDF( const char *path, plBDFConvertCallback *callback );
bool LoadFromBDFStream( hsStream *stream, plBDFConvertCallback *callback );
bool LoadFromP2FFile( const char *path );
bool LoadFromP2FFile( const plFileName &path );
bool ReadRaw( hsStream *stream );
bool WriteRaw( hsStream *stream );

33
Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp

@ -57,7 +57,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plFont.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
#include "pnMessage/plRefMsg.h"
#include "hsResMgr.h"
@ -71,7 +70,6 @@ plFontCache *plFontCache::fInstance = nil;
plFontCache::plFontCache()
{
fCustFontDir = nil;
RegisterAs( kFontCache_KEY );
fInstance = this;
}
@ -79,7 +77,6 @@ plFontCache::plFontCache()
plFontCache::~plFontCache()
{
Clear();
delete [] fCustFontDir;
fInstance = nil;
}
@ -151,46 +148,38 @@ plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlag
return nil;
}
void plFontCache::LoadCustomFonts( const char *dir )
void plFontCache::LoadCustomFonts( const plFileName &dir )
{
delete [] fCustFontDir;
fCustFontDir = ( dir != nil ) ? hsStrcpy( dir ) : nil;
fCustFontDir = dir;
ILoadCustomFonts();
}
void plFontCache::ILoadCustomFonts( void )
void plFontCache::ILoadCustomFonts( void )
{
if( fCustFontDir == nil )
if (!fCustFontDir.IsValid())
return;
// Iterate through all the custom fonts in our dir
hsFolderIterator iter( fCustFontDir );
char fileName[ kFolderIterator_MaxPath ];
hsFolderIterator iter2( fCustFontDir );
while( iter2.NextFileSuffix( ".p2f" ) )
std::vector<plFileName> fonts = plFileSystem::ListDir(fCustFontDir, "*.p2f");
for (auto iter = fonts.begin(); iter != fonts.end(); ++iter)
{
iter2.GetPathAndName( fileName );
plFont *font = new plFont;
if( !font->LoadFromP2FFile( fileName ) )
if (!font->LoadFromP2FFile(*iter))
delete font;
else
{
plString keyName;
if( font->GetKey() == nil )
if (font->GetKey() == nil)
{
keyName = plString::Format( "%s-%d", font->GetFace(), font->GetSize() );
hsgResMgr::ResMgr()->NewKey( keyName, font, plLocation::kGlobalFixedLoc );
}
hsgResMgr::ResMgr()->AddViaNotify( font->GetKey(),
new plGenRefMsg( GetKey(), plRefMsg::kOnCreate, 0, -1 ),
plRefFlags::kActiveRef );
new plGenRefMsg( GetKey(), plRefMsg::kOnCreate, 0, -1 ),
plRefFlags::kActiveRef );
//plStatusLog::AddLineS( "pipeline.log", "FontCache: Added custom font %s", keyName );
//plStatusLog::AddLineS( "pipeline.log", "FontCache: Added custom font %s", keyName.c_str() );
}
}

7
Sources/Plasma/PubUtilLib/plGImage/plFontCache.h

@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsTemplates.h"
#include "pnKeyedObject/hsKeyedObject.h"
#include "plFileSystem.h"
//// Class Definition /////////////////////////////////////////////////////////
@ -69,9 +70,9 @@ class plFontCache : public hsKeyedObject
protected:
hsTArray<plFont *> fCache;
char *fCustFontDir;
plFileName fCustFontDir;
static plFontCache *fInstance;
static plFontCache *fInstance;
void ILoadCustomFonts( void );
@ -96,7 +97,7 @@ class plFontCache : public hsKeyedObject
// void FreeFont( HFONT font );
void Clear( void );
void LoadCustomFonts( const char *dir );
void LoadCustomFonts( const plFileName &dir );
// Our custom font extension
static const char* kCustFontExtension;

27
Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp

@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plWinFontCache.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
#include "plGImage/plDynSurfaceWriter.h"
#if HS_BUILD_FOR_WIN32
@ -234,11 +233,11 @@ void plWinFontCache::Clear( void )
for( i = 0; i < fCustFonts.GetCount(); i++ )
{
#if (_WIN32_WINNT >= 0x0500)
if( plDynSurfaceWriter::CanHandleLotsOfThem() )
RemoveFontResourceEx( fCustFonts[ i ]->fFilename, FR_PRIVATE, 0 );
if (plDynSurfaceWriter::CanHandleLotsOfThem())
RemoveFontResourceExW(fCustFonts[i]->fFilename.AsString().ToWchar(), FR_PRIVATE, 0);
else
#endif
if( RemoveFontResource( fCustFonts[ i ]->fFilename ) == 0 )
if (RemoveFontResourceW(fCustFonts[i]->fFilename.AsString().ToWchar()) == 0)
{
int q= 0;
DWORD e = GetLastError();
@ -267,31 +266,27 @@ void plWinFontCache::ILoadCustomFonts( void )
return;
// Iterate through all the custom fonts in our dir
hsFolderIterator iter( fCustFontDir );
char fileName[ kFolderIterator_MaxPath ];
int numAdded;
int numAdded;
while( iter.NextFileSuffix( kCustFontExtension ) )
std::vector<plFileName> fonts = plFileSystem::ListDir(fCustFontDir, kCustFontExtension);
for (auto iter = fonts.begin(); iter != fonts.end(); ++iter)
{
iter.GetPathAndName( fileName );
// Note that this call can be translated as "does my OS suck?"
#if (_WIN32_WINNT >= 0x0500)
if( plDynSurfaceWriter::CanHandleLotsOfThem() )
numAdded = AddFontResourceEx( fileName, FR_PRIVATE, 0 );
numAdded = AddFontResourceExW(iter->AsString().ToWchar(), FR_PRIVATE, 0);
else
#endif
numAdded = AddFontResource( fileName );
numAdded = AddFontResourceW(iter->AsString().ToWchar());
if( numAdded > 0 )
{
plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Added custom font %s, %d fonts", fileName, numAdded );
fCustFonts.Append( new plCustFont( fileName ) );
plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Added custom font %s, %d fonts", iter->GetFileName().c_str(), numAdded );
fCustFonts.Append(new plCustFont(*iter));
}
else
{
plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Unable to load custom font %s", fileName );
plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Unable to load custom font %s", iter->GetFileName().c_str() );
}
}
}

5
Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h

@ -90,10 +90,9 @@ class plWinFontCache
class plCustFont
{
public:
char *fFilename;
plFileName fFilename;
plCustFont( const char *c ) { fFilename = hsStrcpy( c ); }
~plCustFont() { delete [] fFilename; }
plCustFont(const plFileName &c) { fFilename = c; }
};
bool fInShutdown;

6
Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp

@ -89,8 +89,8 @@ void plCloneSpawnModifier::SetTarget(plSceneObject* so)
{
// Assume the clone template is in the same age we are
const plLocation& loc = GetKey()->GetUoid().GetLocation();
char ageName[256];
((plResManager*)hsgResMgr::ResMgr())->GetLocationStrings(loc, ageName, nil);
plString ageName;
((plResManager*)hsgResMgr::ResMgr())->GetLocationStrings(loc, &ageName, nil);
// Spawn the clone
plKey cloneKey = SpawnClone(fTemplateName, ageName, GetTarget()->GetLocalToWorld(), GetKey());
@ -98,7 +98,7 @@ void plCloneSpawnModifier::SetTarget(plSceneObject* so)
}
plKey plCloneSpawnModifier::SpawnClone(const char* cloneName, const char* cloneAge, const hsMatrix44& pos, plKey requestor)
plKey plCloneSpawnModifier::SpawnClone(const plString& cloneName, const plString& cloneAge, const hsMatrix44& pos, plKey requestor)
{
plResManager* resMgr = (plResManager*)hsgResMgr::ResMgr();

2
Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.h

@ -71,7 +71,7 @@ public:
void SetExportTime() { fExportTime = true; }
// Console backdoor
static plKey SpawnClone(const char* cloneName, const char* cloneAge, const hsMatrix44& pos, plKey requestor);
static plKey SpawnClone(const plString& cloneName, const plString& cloneAge, const hsMatrix44& pos, plKey requestor);
};
#endif // plCloneSpawnModifier_inc

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save