diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index a3d7ca34..9ab811a2 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/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" diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 0575e6bc..c4175088 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/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; diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index bf887bb5..837a21d4 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -66,21 +66,21 @@ 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; + 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; + 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,9 +301,8 @@ 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,10 +522,8 @@ 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; PatchInfo patchInfo; @@ -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,10 +681,10 @@ 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]); - } + } } noDuplicates.Add(mr->manifest[entryCount - 1]); @@ -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,9 +865,8 @@ void UruPrepProc (void * param) { s_running = true; plLauncherInfo *info = (plLauncherInfo *) param; + s_workingDir = plString::FromWchar(info->path); - StrToAnsi(s_workingDir, info->path, arrsize(s_workingDir)); - InitAsyncCore(); NetClientInitialize(); NetClientSetErrorHandler(NetErrorHandler); diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.h b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.h index 1a15d9be..b769ed53 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.h +++ b/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; diff --git a/Sources/Plasma/Apps/plFileSecure/main.cpp b/Sources/Plasma/Apps/plFileSecure/main.cpp index 8a2347da..6264dfe2 100644 --- a/Sources/Plasma/Apps/plFileSecure/main.cpp +++ b/Sources/Plasma/Apps/plFileSecure/main.cpp @@ -40,7 +40,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plFile/plSecureStream.h" #include "plProduct.h" diff --git a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp index 46084506..d5910803 100644 --- a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp +++ b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTimer.h" #include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plResMgr/plResManager.h" #include "plResMgr/plResMgrSettings.h" @@ -61,7 +60,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 +116,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 +133,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 +174,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,9 +190,9 @@ 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 buffer->GetKey()->UnRefObject(); } @@ -218,11 +212,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 +240,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 +253,7 @@ public: } }; -bool DumpStats(const char* patchDir) +bool DumpStats(const plFileName& patchDir) { plStatDumpIterator statDump(patchDir); gResMgr->IterateAllPages(&statDump); diff --git a/Sources/Plasma/Apps/plPageOptimizer/main.cpp b/Sources/Plasma/Apps/plPageOptimizer/main.cpp index 57cbaf0e..4aa284b4 100644 --- a/Sources/Plasma/Apps/plPageOptimizer/main.cpp +++ b/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 { diff --git a/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.cpp b/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.cpp index 67bfeefe..9b9598cf 100644 --- a/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.cpp +++ b/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"); } } diff --git a/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.h b/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.h index 56877c38..96f3a3d7 100644 --- a/Sources/Plasma/Apps/plPageOptimizer/plPageOptimizer.h +++ b/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 #include @@ -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(); }; diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index b4cbbda1..ff937407 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -601,7 +601,7 @@ static const CmdArgDef s_cmdLineArgs[] = { PF_CONSOLE_LINK_FILE(Core) //============================================================================ -int __stdcall WinMain ( +int __stdcall WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, @@ -619,18 +619,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; } @@ -683,12 +680,12 @@ 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); - // User canceled + // User canceled if (s_shutdown) break; @@ -701,7 +698,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 +708,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 +716,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 +729,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( @@ -758,12 +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); + plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName(); + fileSpec = plFileName::Join(fileSpec, "*.tmp"); + PathFindFiles(&paths, fileSpec.AsString().ToWchar(), kPathFlagFile); for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path) - plFileUtils::RemoveFile(path->name); + plFileSystem::Unlink(plString::FromWchar(path->name)); SetConsoleCtrlHandler(CtrlHandler, TRUE); InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server diff --git a/Sources/Plasma/Apps/plUruLauncher/Pch.h b/Sources/Plasma/Apps/plUruLauncher/Pch.h index ea420453..2df3767d 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Pch.h +++ b/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" diff --git a/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp b/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp index 1b461ace..55af87aa 100644 --- a/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp +++ b/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( diff --git a/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp b/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp index e42d4a59..63c23665 100644 --- a/Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp +++ b/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() diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp index 35623df8..e1693837 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp +++ b/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."); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index d27bcca5..ed9d8abf 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -263,9 +263,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 +273,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,22 +293,22 @@ 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) + if (statusStr) sprintf(statusStr, "Found Object"); return key; } } } // Fallback - key = plKeyFinder::Instance().StupidSearch(ageName,nil,type, name, subString); + key = plKeyFinder::Instance().StupidSearch(ageName, "", type, name, subString); if (!key) { @@ -334,7 +334,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 +352,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 +1579,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(params[0]); + plKey key = FindSceneObjectByName(objName, "", str); PrintString( str ); if( !key ) return; @@ -1841,7 +1841,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 +2175,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 +2252,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 +2307,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 +2773,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 +2950,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 +3076,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 +3173,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 +3189,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 +3211,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 +3522,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 +3551,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,7 +3928,7 @@ 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(params[0]))); plgDispatch::MsgSend(pMsg1); } @@ -3951,7 +3951,7 @@ PF_CONSOLE_CMD( Nav, PageInNodeList, // Group name, Function name { char nodeName[255]; _splitpath(pageInNodesIter.GetFileName(), NULL, NULL, nodeName, NULL); - pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, nodeName)); + pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", nodeName)); } pMsg1->AddReceiver( plClient::GetInstance()->GetKey() ); plgDispatch::MsgSend(pMsg1); @@ -3968,7 +3968,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(params[0]))); plgDispatch::MsgSend(pMsg1); } @@ -3977,7 +3977,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 +3995,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(params[0]), "", str); PrintString(str); if( !playerKey ) return; - plKey nodeKey = FindObjectByName(plString::FromUtf8(params[1]), plSceneNode::Index(), nil, str); + plKey nodeKey = FindObjectByName(static_cast(params[1]), plSceneNode::Index(), "", str); PrintString(str); if( !nodeKey ) return; @@ -4307,7 +4307,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 +4332,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 +4353,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 +4572,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 +4604,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(params[0]), "", str); PrintString(str); if( !key ) return; @@ -4618,7 +4618,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(params[0]), "", str); PrintString(str); plSceneObject* so = nil; @@ -4693,7 +4693,7 @@ PF_CONSOLE_CMD( Access, "Fire shot along gun's z-axis, creating decal of radius , with optional max-range (def 1000)" ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if( !key ) return; @@ -4774,7 +4774,7 @@ PF_CONSOLE_CMD( Access, "Add particle system to bulletMgr ") { char str[256]; - plKey bullKey = FindObjectByName(plString::FromUtf8(params[0]), plDynaBulletMgr::Index(), nil, str, false); + plKey bullKey = FindObjectByName(static_cast(params[0]), plDynaBulletMgr::Index(), "", str, false); PrintString(str); if( !(bullKey && bullKey->GetObjectPtr()) ) { @@ -4782,7 +4782,7 @@ PF_CONSOLE_CMD( Access, return; } - plKey sysKey = FindSceneObjectByName(plString::FromUtf8(params[1]), nil, str); + plKey sysKey = FindSceneObjectByName(static_cast(params[1]), "", str); if( !(sysKey && sysKey->GetObjectPtr()) ) { PrintString("Psys not found"); @@ -4982,7 +4982,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 +5463,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(params[0]), "", str); PrintString(str); if (!key) return; @@ -5482,7 +5482,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(params[0]), "", str); PrintString(str); if (!key) return; @@ -5524,7 +5524,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(params[0]), "", str); PrintString(str); if (!key) return; @@ -5543,7 +5543,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(params[0]), "", str); PrintString(str); if (!key) return; @@ -5563,10 +5563,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(params[0]); + plString parentName = static_cast(params[1]); - plKey childKey = FindSceneObjectByName(childName, nil, str); + plKey childKey = FindSceneObjectByName(childName, "", str); if( !childKey ) { PrintString(str); @@ -5580,7 +5580,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 +5601,9 @@ PF_CONSOLE_CMD( SceneObject, Detach, // Group name, Function name { char str[256]; - plString childName = plString::FromUtf8(params[0]); + plString childName = static_cast(params[0]); - plKey childKey = FindSceneObjectByName(childName, nil, str); + plKey childKey = FindSceneObjectByName(childName, "", str); if( !childKey ) { PrintString(str); @@ -6186,7 +6186,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 +6309,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(params[0]), "", str); if (key == nil) return; @@ -6317,7 +6317,7 @@ PF_CONSOLE_CMD( ParticleSystem, if (so == nil) return; - plArmatureMod *avMod = plAvatarMgr::GetInstance()->GetLocalAvatar(); + plArmatureMod *avMod = plAvatarMgr::GetInstance()->GetLocalAvatar(); if (avMod) (new plParticleTransferMsg(nil, avMod->GetKey(), 0, so->GetKey(), (int)params[1]))->Send(); } @@ -6328,7 +6328,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(params[0]), "", str); if (key == nil) return; @@ -6350,7 +6350,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 +6528,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); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index ac7a72b1..7eb222b5 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -196,9 +196,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, ...); @@ -507,9 +507,9 @@ PF_CONSOLE_CMD( Net, // groupName SetObjUpdateFreq, // fxnName "string objName, float freqInSecs", // paramList "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(params[0]), "", str); PrintString(str); if (!key) return; diff --git a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp b/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp index ef63aae0..7f1cd111 100644 --- a/Sources/Plasma/FeatureLib/pfCrashHandler/plCrashSrv.cpp +++ b/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" diff --git a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp b/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp index 91b7de9a..3178b3c9 100644 --- a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp +++ b/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; diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index 60513871..f7da3c33 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -94,7 +94,7 @@ public: protected: bool fWeExploded; // alternative to massive error stack - plString fFilename; + plFileName fFilename; XML_Parser fParser; struct tagInfo @@ -121,7 +121,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 +354,7 @@ void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagIn //// Parse() ///////////////////////////////////////////////////////// -bool LocalizationXMLFile::Parse(const plString& fileName) +bool LocalizationXMLFile::Parse(const plFileName& fileName) { fFilename = fileName; @@ -382,10 +382,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 +437,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 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 +456,7 @@ protected: public: LocalizationDatabase() {} - void Parse(const plString & directory); + void Parse(const plFileName & directory); LocalizationXMLFile::ageMap GetData() {return fData;} }; @@ -466,7 +466,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 +475,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 +486,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 +505,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,14 +640,14 @@ 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")) + hsFolderIterator xmlFolder(directory.AsString().c_str()); + while (xmlFolder.NextFileSuffix(".loc")) { xmlFolder.GetPathAndName(filename); @@ -822,7 +822,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 +932,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 +980,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 +989,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 +1194,7 @@ bool pfLocalizationDataMgr::DeleteElement(const plString & name) //// WriteDatabaseToDisk ///////////////////////////////////////////// -void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) +void pfLocalizationDataMgr::WriteDatabaseToDisk(const plFileName & path) { std::vector ageNames = GetAgeList(); std::vector languageNames = IGetAllLanguageNames(); @@ -1202,7 +1202,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]); } } } diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h index 52b2ec03..4ce1175f 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h @@ -53,9 +53,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #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 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 }; diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp index e6de8c66..93b5f6fa 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp +++ b/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; diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h index 7fc99964..c504a85c 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h +++ b/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;} diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp b/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp index 97780b15..10a5848c 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp +++ b/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()); } diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.h b/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.h index 0f692b90..e6ba9d00 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.h +++ b/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); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 763aab23..d88b0d53 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/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) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index 0b0d8454..4f9090ba 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/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 - ///////////////////////////////////////////////////////////////////////////// // // 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[]); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp index e763aef8..15016870 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp +++ b/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()); } /////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index 57b012ed..34005576 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/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) diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp index e9f7bf15..b1686cca 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp +++ b/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(); diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h index 1f131ffa..a4660fe4 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.h +++ b/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; } diff --git a/Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp b/Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp index 9d4020f6..99e9b1d2 100644 --- a/Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp +++ b/Sources/Plasma/FeatureLib/pfSurface/plLayerAVI.cpp @@ -85,10 +85,10 @@ plLayerAVI::~plLayerAVI() bool plLayerAVI::IInit() { #if HS_BUILD_FOR_WIN32 - int ret = AVIStreamOpenFromFile( &fAVIInfo->fAVIStream, - fMovieName, - streamtypeVIDEO, - 0, + int ret = AVIStreamOpenFromFileW( &fAVIInfo->fAVIStream, + fMovieName.AsString().ToWchar(), + streamtypeVIDEO, + 0, OF_READ, NULL); diff --git a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp b/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp index 33ca05e2..f44048e6 100644 --- a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp +++ b/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 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) diff --git a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.h b/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.h index 6d81fc0d..46ffaf3c 100644 --- a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.h +++ b/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); diff --git a/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp b/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp index bf5ba078..7350bd73 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp +++ b/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.cpp @@ -42,10 +42,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plClientMsg.h" #include "HeadSpin.h" -void plClientMsg::IReset() +void plClientMsg::IReset() { - fMsgFlag = 0; - fAgeName = nil; + fMsgFlag = 0; + fAgeName = ""; } void plClientMsg::AddRoomLoc(plLocation loc) diff --git a/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h b/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h index a7c8f8ad..7a18bd4d 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h +++ b/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 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]; } diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2File/pnNpCli2File.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2File/pnNpCli2File.h index df08897c..44683643 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2File/pnNpCli2File.h +++ b/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 { diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp index 286a2099..f0b4d3df 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp @@ -101,16 +101,6 @@ static const wchar_t * SkipUncDrive (const wchar_t 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[] @@ -144,16 +134,6 @@ static void GetProgramName ( } } -//============================================================================ -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; -} - /**************************************************************************** * @@ -169,39 +149,6 @@ void PathGetProgramName ( 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 @@ -348,52 +295,6 @@ void PathMakePath ( *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, @@ -504,82 +405,3 @@ void PathFindFiles ( } 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; -} - diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h index 63310dcf..c2dd512e 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h @@ -76,9 +76,9 @@ const unsigned kPathFlagRecurse = 1<<4; // also set if "**" used in filesp struct PathFind { unsigned flags; - uint64_t fileLength; - uint64_t lastWriteTime; - wchar_t name[MAX_PATH]; + uint64_t fileLength; + uint64_t lastWriteTime; + wchar_t name[MAX_PATH]; }; @@ -90,18 +90,14 @@ struct PathFind { void PathFindFiles ( ARRAY(PathFind) * paths, - const wchar_t fileSpec[], + const wchar_t fileSpec[], unsigned pathFlags ); void PathGetProgramName ( - wchar_t * dst, + wchar_t * dst, unsigned dstChars ); -bool PathDoesFileExist ( - const wchar_t fileName[] -); - /***************************************************************************** * @@ -110,20 +106,20 @@ bool PathDoesFileExist ( ***/ void PathSplitPath ( - const wchar_t path[], - wchar_t * drive, - wchar_t * dir, - wchar_t * fname, - wchar_t * ext + const wchar_t path[], + wchar_t * drive, + wchar_t * dir, + wchar_t * fname, + wchar_t * ext ); void PathMakePath ( - wchar_t * path, + wchar_t * path, unsigned chars, - const wchar_t drive[], - const wchar_t dir[], - const wchar_t fname[], - const wchar_t ext[] + 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 @@ -148,51 +144,9 @@ void PathRemoveFilename ( * ***/ -// 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, + wchar_t * dst, unsigned dstChars ); @@ -206,13 +160,13 @@ void PathGetInitDirectory ( // you may send nil for any fields you don't care about void PathSplitEmail ( const wchar_t emailAddr[], - wchar_t * user, + wchar_t * user, unsigned userChars, - wchar_t * domain, + wchar_t * domain, unsigned domainChars, - wchar_t * tld, + wchar_t * tld, unsigned tldChars, - wchar_t * subDomains, // (wchar_t *)&subs --> wchar_t subs[16][256]; + wchar_t * subDomains, // (wchar_t *)&subs --> wchar_t subs[16][256]; unsigned subDomainChars, // arrsize(subs[0]) --> 256 unsigned subDomainCount // arrsize(subs) --> 16 ); diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp index c18d46ea..184d9e88 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp @@ -53,44 +53,38 @@ 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; - + return *this; } @@ -103,54 +97,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 toks = stringIn.Tokenize(", \n"); + if (toks.size() == 0) return false; - delete [] fName; - fName = hsStrcpy( c ); + fName = toks[0]; + fSeqSuffix = kInvalidSeqSuffix; + fFlags = 0; - // Look for seqSuffix - c = strtok( nil, seps ); - if( c != nil ) - { - fSeqSuffix = atoi( c ); - - // 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 +150,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 +160,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 +176,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 +200,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 +230,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,10 +279,10 @@ 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; - } + } } // Just make a blank (invalid) one @@ -380,7 +325,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 +482,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 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(); } diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp index 62309f9e..cd6f1a9d 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp @@ -52,23 +52,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #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 +81,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; } diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h index 40c47f26..4ae9468d 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h +++ b/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; } diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp index e6d88c1a..25ba08a2 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.cpp +++ b/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); diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp index 0f209580..c5aa42ee 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp +++ b/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 ) diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index 1e599ca3..bf1abbe4 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/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); diff --git a/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp index e835d1db..48dbc57a 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp +++ b/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 ""; } ///////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plAudio/plSound.h b/Sources/Plasma/PubUtilLib/plAudio/plSound.h index e811b5e8..55a4a57e 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plSound.h +++ b/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; } diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWin32GroupedSound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plWin32GroupedSound.cpp index 84b1a381..fdb29fd6 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32GroupedSound.cpp +++ b/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 ) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp index 43034cd8..d17449be 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp @@ -91,9 +91,6 @@ plWin32StreamingSound::~plWin32StreamingSound() IUnloadDataBuffer(); delete fDataStream; - fDataStream = nil; - fSrcFilename[ 0 ] = 0; - delete fDeswizzler; } @@ -117,11 +114,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh { if(fPlayWhenStopped) return plSoundBuffer::kPending; - bool sfxPath = fNewFilename.size() ? false : true; - - if( fDataStream != nil && fNewFilename.size() == 0) + bool sfxPath = fNewFilename.IsValid() ? false : true; + + if (fDataStream != nil && !fNewFilename.IsValid()) return plSoundBuffer::kSuccess; // Already loaded - + if(!ILoadDataBuffer()) { return plSoundBuffer::kError; @@ -131,11 +128,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 +169,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,20 +181,14 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0); /// Open da file - char strPath[ kFolderIterator_MaxPath ]; - - 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 ); + plFileName strPath = plFileSystem::GetCWD(); + + if (sfxPath) + strPath = plFileName::Join(strPath, "sfx"); + strPath = plFileName::Join(strPath, fSrcFilename); fDataStream = plAudioFileReader::CreateReader(strPath, select,type); - } - + } + if( fDataStream == nil || !fDataStream->IsValid() ) { delete fDataStream; @@ -206,8 +196,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 @@ -227,11 +216,11 @@ void plWin32StreamingSound::IFreeBuffers( void ) if(!plgAudioSys::IsRestarting()) { // we are deleting the stream, we must release the sound data. - FreeSoundData(); + FreeSoundData(); delete fDataStream; fDataStream = nil; } - fSrcFilename[ 0 ] = 0; + fSrcFilename = ""; } } @@ -303,9 +292,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; } diff --git a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.h b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.h index 0d0a5f24..b118228f 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.h +++ b/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 ); diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp index d175f66c..0cdff8e3 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -56,7 +56,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //#include "hsTimer.h" #include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plUnifiedTime/plUnifiedTime.h" #include "plBufferedFileReader.h" #include "plCachedFileReader.h" @@ -66,20 +65,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 +100,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 +161,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) { diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.h index 3a2ce2d7..c02705ad 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.h +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp index 6bc092b2..6b08fb69 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.cpp @@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #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 diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.h index db1e16da..cda8e3e9 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plBufferedFileReader.h +++ b/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 ); }; diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp index 36dc89e6..66bcae60 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.cpp +++ b/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) { diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h index baf4392b..fafcfc59 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plCachedFileReader.h +++ b/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); }; diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.cpp index 7c44e9ee..d19615fb 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.cpp +++ b/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 @@ -226,8 +226,8 @@ void plFastWAV::Open() { if(fFileHandle) return; - - fFileHandle = fopen( fFilename, "rb" ); + + fFileHandle = plFileSystem::Open(fFilename, "rb"); if(!fFileHandle) return; diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.h b/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.h index 38e83626..287bf56f 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plFastWavReader.h +++ b/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 ); diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp index 142a6c32..41db9c4e 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.cpp +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.h b/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.h index 97ec52e3..c9052aec 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plOGGCodec.h +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp index 9bc4c3b6..7d8a79ec 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp @@ -49,35 +49,31 @@ 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); if( reader == nil || !reader->IsValid() ) @@ -115,11 +111,11 @@ hsError plSoundPreloader::Run() if (buf->GetData()) { - reader = CreateReader(true, buf->GetFileName(), buf->GetAudioReaderType(), buf->GetReaderSelect()); + reader = CreateReader(true, buf->GetFileName(), buf->GetAudioReaderType(), buf->GetReaderSelect()); if( reader ) { - unsigned readLen = buf->GetAsyncLoadLength() ? buf->GetAsyncLoadLength() : buf->GetDataLength(); + unsigned readLen = buf->GetAsyncLoadLength() ? buf->GetAsyncLoadLength() : buf->GetDataLength(); reader->Read( readLen, buf->GetData() ); buf->SetAudioReader(reader); // give sound buffer reader, since we may need it later } @@ -166,7 +162,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 +182,6 @@ plSoundBuffer::~plSoundBuffer() } } - delete [] fFileName; UnLoad(); } @@ -194,7 +189,7 @@ void plSoundBuffer::IInitBuffer() { fError = false; fValid = false; - fFileName = nil; + fFileName = ""; fData = nil; fDataLength = 0; fFlags = 0; @@ -225,7 +220,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 +261,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 +279,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 +287,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 +310,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 +439,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 +490,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 +524,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; diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h index 24851eee..44cea75f 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.h @@ -56,16 +56,17 @@ 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 //////////////////////////////////////////////////////// class plUnifiedTime; class plAudioFileReader; 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 ); - - uint32_t fFlags; + plFileName IGetFullPath(); + + 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; + plAudioFileReader * fReader; + uint8_t * fData; plWAVHeader fHeader; - uint32_t fDataLength; - uint32_t fAsyncLoadLength; + uint32_t fDataLength; + uint32_t fAsyncLoadLength; plAudioFileReader::StreamType fStreamType; // for plugins only diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index 4c7cb181..8dc7df66 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/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); diff --git a/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt index 8498ca5e..2d04fff7 100644 --- a/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt @@ -8,7 +8,6 @@ set(plFile_SOURCES hsFiles.cpp plBrowseFolder.cpp plEncryptedStream.cpp - plFileUtils.cpp plInitFileReader.cpp plSecureStream.cpp plStreamSource.cpp @@ -26,7 +25,6 @@ set(plFile_HEADERS hsFiles.h plBrowseFolder.h plEncryptedStream.h - plFileUtils.h plInitFileReader.h plSecureStream.h plStreamSource.h diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp b/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp index 5864f42a..7414ea81 100644 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp @@ -52,7 +52,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include "hsTemplates.h" -#include "plFileUtils.h" struct hsFolderIterator_Data { glob_t fGlobBuf; @@ -122,8 +121,8 @@ 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); + plFileName fn = fData->fGlobBuf.gl_pathv[fData->fCnt-1]; + return fn.GetFileName().c_str(); } bool hsFolderIterator::IsDirectory( void ) const diff --git a/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp b/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp index 3d4dbb82..586199e6 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.cpp @@ -45,22 +45,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include -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) diff --git a/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.h b/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.h index 517dcf6b..90b42e21 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plBrowseFolder.h +++ b/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); diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index 6a4bc7f4..3dd3a4d9 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp b/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp deleted file mode 100644 index ba17aea7..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.cpp +++ /dev/null @@ -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 . - -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 -#include -#include -#include - - -#if HS_BUILD_FOR_WIN32 -#include -#include -#define mkdir _mkdir -#define chdir _chdir -#define chmod _chmod -#define rmdir _rmdir -#define unlink _unlink -#endif - -#if HS_BUILD_FOR_UNIX -#include -#include -#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; -} diff --git a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.h b/Sources/Plasma/PubUtilLib/plFile/plFileUtils.h deleted file mode 100644 index fff955b0..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/plFileUtils.h +++ /dev/null @@ -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 . - -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 diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index 4f751299..44e211b9 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp index d9d82580..75c72a99 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp @@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plStreamSource.h" #include "plSecureStream.h" #include "plEncryptedStream.h" -#include "plFileUtils.h" #if HS_BUILD_FOR_UNIX # include diff --git a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp b/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp index 47102826..cf04761e 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp +++ b/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(); diff --git a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.h b/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.h index d134c2ac..b77261f4 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.h +++ b/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 diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index 12af8812..5b9ca68a 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -1474,8 +1474,7 @@ plUoid plNetClientMgr::GetAgeSDLObjectUoid(const char* ageName) const if (!loc.IsValid()) { // check current age des - if (plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName() && - !strcmp(plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName(), ageName)) + if (plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName() == ageName) loc=plAgeLoader::GetInstance()->GetCurrAgeDesc().CalcPageLocation("BuiltIn"); if (!loc.IsValid()) diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 107c8f66..cd9b0b01 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -555,13 +555,13 @@ struct FileDownloadRequestTrans : NetAuthTrans { FNetCliAuthFileRequestCallback m_callback; void * m_param; - wchar_t m_filename[MAX_PATH]; + plFileName m_filename; hsStream * m_writer; FileDownloadRequestTrans ( FNetCliAuthFileRequestCallback callback, void * param, - const wchar_t filename[], + const plFileName & filename, hsStream * writer ); @@ -3572,14 +3572,14 @@ bool FileListRequestTrans::Recv ( FileDownloadRequestTrans::FileDownloadRequestTrans ( FNetCliAuthFileRequestCallback callback, void * param, - const wchar_t filename[], + const plFileName & filename, hsStream * writer ) : NetAuthTrans(kFileDownloadRequestTrans) , m_callback(callback) , m_param(param) +, m_filename(filename) , m_writer(writer) { - StrCopy(m_filename, filename, arrsize(m_filename)); // This transaction issues "sub transactions" which must complete // before this one even though they were issued after us. m_hasSubTrans = true; @@ -3593,7 +3593,7 @@ bool FileDownloadRequestTrans::Send () { const uintptr_t msg[] = { kCli2Auth_FileDownloadRequest, m_transId, - (uintptr_t) m_filename, + reinterpret_cast(m_filename.AsString().ToWchar().GetData()), }; m_conn->Send(msg, arrsize(msg)); @@ -5530,7 +5530,7 @@ void NetCliAuthFileListRequest ( //============================================================================ void NetCliAuthFileRequest ( - const wchar_t filename[], + const plFileName & filename, hsStream * writer, FNetCliAuthFileRequestCallback callback, void * param diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 71c4d0e3..d71fc264 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -368,13 +368,13 @@ void NetCliAuthFileListRequest ( // File Download //============================================================================ typedef void (*FNetCliAuthFileRequestCallback)( - ENetError result, - void * param, - const wchar_t filename[], - hsStream * writer + ENetError result, + void * param, + const plFileName & filename, + hsStream * writer ); void NetCliAuthFileRequest ( - const wchar_t filename[], + const plFileName & filename, hsStream * writer, FNetCliAuthFileRequestCallback callback, void * param diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp index 04a12d48..04c8013f 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp @@ -145,7 +145,7 @@ struct BuildIdRequestTrans : NetFileTrans { struct ManifestRequestTrans : NetFileTrans { FNetCliFileManifestRequestCallback m_callback; void * m_param; - wchar_t m_group[MAX_PATH]; + wchar_t m_group[MAX_PATH]; unsigned m_buildId; ARRAY(NetCliFileManifestEntry) m_manifest; @@ -154,7 +154,7 @@ struct ManifestRequestTrans : NetFileTrans { ManifestRequestTrans ( FNetCliFileManifestRequestCallback callback, void * param, - const wchar_t group[], + const wchar_t group[], unsigned buildId ); @@ -173,7 +173,7 @@ struct DownloadRequestTrans : NetFileTrans { FNetCliFileDownloadRequestCallback m_callback; void * m_param; - wchar_t m_filename[MAX_PATH]; + plFileName m_filename; hsStream * m_writer; unsigned m_buildId; @@ -182,7 +182,7 @@ struct DownloadRequestTrans : NetFileTrans { DownloadRequestTrans ( FNetCliFileDownloadRequestCallback callback, void * param, - const wchar_t filename[], + const plFileName & filename, hsStream * writer, unsigned buildId ); @@ -943,11 +943,9 @@ void ManifestRequestTrans::Post () { } //============================================================================ -void ReadStringFromMsg(const wchar_t* curMsgPtr, wchar_t str[], unsigned maxStrLen, unsigned* length) { - StrCopy(str, curMsgPtr, maxStrLen); - str[maxStrLen - 1] = L'\0'; // make sure it's terminated - - (*length) = StrLen(str); +plString ReadStringFromMsg(const wchar_t* curMsgPtr, unsigned* length) { + (*length) = wcslen(curMsgPtr); + return plString::FromWchar(curMsgPtr, *length); } //============================================================================ @@ -1004,7 +1002,7 @@ bool ManifestRequestTrans::Recv ( // -------------------------------------------------------------------- // read in the clientFilename unsigned filenameLen; - ReadStringFromMsg(curChar, entry.clientName, arrsize(entry.clientName), &filenameLen); + entry.clientName = ReadStringFromMsg(curChar, &filenameLen); curChar += filenameLen; // advance the pointer wchar_tCount -= filenameLen; // keep track of the amount remaining if ((*curChar != L'\0') || (wchar_tCount <= 0)) @@ -1016,7 +1014,7 @@ bool ManifestRequestTrans::Recv ( // -------------------------------------------------------------------- // read in the downloadFilename - ReadStringFromMsg(curChar, entry.downloadName, arrsize(entry.downloadName), &filenameLen); + entry.downloadName = ReadStringFromMsg(curChar, &filenameLen); curChar += filenameLen; // advance the pointer wchar_tCount -= filenameLen; // keep track of the amount remaining if ((*curChar != L'\0') || (wchar_tCount <= 0)) @@ -1028,7 +1026,7 @@ bool ManifestRequestTrans::Recv ( // -------------------------------------------------------------------- // read in the md5 - ReadStringFromMsg(curChar, entry.md5, arrsize(entry.md5), &filenameLen); + entry.md5 = ReadStringFromMsg(curChar, &filenameLen); curChar += filenameLen; // advance the pointer wchar_tCount -= filenameLen; // keep track of the amount remaining if ((*curChar != L'\0') || (wchar_tCount <= 0)) @@ -1040,7 +1038,7 @@ bool ManifestRequestTrans::Recv ( // -------------------------------------------------------------------- // read in the md5 for compressed files - ReadStringFromMsg(curChar, entry.md5compressed, arrsize(entry.md5compressed), &filenameLen); + entry.md5compressed = ReadStringFromMsg(curChar, &filenameLen); curChar += filenameLen; // advance the pointer wchar_tCount -= filenameLen; // keep track of the amount remaining if ((*curChar != L'\0') || (wchar_tCount <= 0)) @@ -1129,17 +1127,17 @@ bool ManifestRequestTrans::Recv ( DownloadRequestTrans::DownloadRequestTrans ( FNetCliFileDownloadRequestCallback callback, void * param, - const wchar_t filename[], + const plFileName & filename, hsStream * writer, unsigned buildId ) : NetFileTrans(kDownloadRequestTrans) , m_callback(callback) , m_param(param) +, m_filename(filename) , m_writer(writer) , m_totalBytesReceived(0) , m_buildId(buildId) { - StrCopy(m_filename, filename, arrsize(m_filename)); // This transaction issues "sub transactions" which must complete // before this one even though they were issued after us. m_hasSubTrans = true; @@ -1151,7 +1149,7 @@ bool DownloadRequestTrans::Send () { return false; Cli2File_FileDownloadRequest filedownloadReq; - StrCopy(filedownloadReq.filename, m_filename, arrsize(m_filename)); + StrCopy(filedownloadReq.filename, m_filename.AsString().ToWchar(), arrsize(filedownloadReq.filename)); filedownloadReq.messageId = kCli2File_FileDownloadRequest; filedownloadReq.transId = m_transId; filedownloadReq.messageBytes = sizeof(filedownloadReq); @@ -1443,7 +1441,7 @@ void NetCliFileRegisterBuildIdUpdate (FNetCliFileBuildIdUpdateCallback callback) void NetCliFileManifestRequest ( FNetCliFileManifestRequestCallback callback, void * param, - const wchar_t group[], + const wchar_t group[], unsigned buildId /* = 0 */ ) { ManifestRequestTrans * trans = new ManifestRequestTrans( @@ -1457,7 +1455,7 @@ void NetCliFileManifestRequest ( //============================================================================ void NetCliFileDownloadRequest ( - const wchar_t filename[], + const plFileName & filename, hsStream * writer, FNetCliFileDownloadRequestCallback callback, void * param, diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h index d6ab0ceb..68227d7e 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h @@ -97,10 +97,10 @@ void NetCliFileRegisterBuildIdUpdate (FNetCliFileBuildIdUpdateCallback callback) // Manifest //============================================================================ struct NetCliFileManifestEntry { - wchar_t clientName[MAX_PATH]; // path and file on client side (for comparison) - wchar_t downloadName[MAX_PATH]; // path and file on server side (for download) - wchar_t md5[MAX_PATH]; - wchar_t md5compressed[MAX_PATH]; // md5 for the compressed file + plFileName clientName; // path and file on client side (for comparison) + plFileName downloadName; // path and file on server side (for download) + plString md5; + plString md5compressed; // md5 for the compressed file unsigned fileSize; unsigned zipSize; unsigned flags; @@ -108,14 +108,14 @@ struct NetCliFileManifestEntry { typedef void (*FNetCliFileManifestRequestCallback)( ENetError result, void * param, - const wchar_t group[], + const wchar_t group[], const NetCliFileManifestEntry manifest[], unsigned entryCount ); void NetCliFileManifestRequest ( FNetCliFileManifestRequestCallback callback, void * param, - const wchar_t group[], // the group of files you want (empty or nil = all) + const wchar_t group[], // the group of files you want (empty or nil = all) unsigned buildId = 0 // 0 = get latest, other = get particular build (servers only) ); @@ -123,13 +123,13 @@ void NetCliFileManifestRequest ( // File Download //============================================================================ typedef void (*FNetCliFileDownloadRequestCallback)( - ENetError result, - void * param, - const wchar_t filename[], - hsStream * writer + ENetError result, + void * param, + const plFileName & filename, + hsStream * writer ); void NetCliFileDownloadRequest ( - const wchar_t filename[], + const plFileName & filename, hsStream * writer, FNetCliFileDownloadRequestCallback callback, void * param, diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp index 3237f75c..80153e34 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp @@ -439,7 +439,7 @@ void plDynamicEnvMap::Read(hsStream* s, hsResMgr* mgr) nVis = s->ReadLE32(); for( i = 0; i < nVis; i++) { - plKey key = plKeyFinder::Instance().StupidSearch(nil, nil, plVisRegion::Index(), s->ReadSafeString_TEMP()); + plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString_TEMP()); if (key) hsgResMgr::ResMgr()->AddViaNotify(key, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, kRefVisSet), plRefFlags::kActiveRef); } @@ -912,7 +912,7 @@ void plDynamicCamMap::Read(hsStream* s, hsResMgr* mgr) nVis = s->ReadLE32(); for( i = 0; i < nVis; i++) { - plKey key = plKeyFinder::Instance().StupidSearch(nil, nil, plVisRegion::Index(), s->ReadSafeString_TEMP()); + plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString_TEMP()); if (key) hsgResMgr::ResMgr()->AddViaNotify(key, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, kRefVisSet), plRefFlags::kActiveRef); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp index 5a5ca3ac..8a996b79 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plStatusLogDrawer.cpp @@ -111,8 +111,8 @@ void plStatusLogDrawer::Draw(plStatusLog* curLog, plStatusLog* firstLog) drawText.DrawRect( x, y, x + width, y + height, 0, 0, 0, 127 ); drawText.DrawString( x + 2, y + ( lineHt >> 1 ), IGetFilename( curLog ).AsString(), 127, 127, 255, 255, plDebugText::kStyleBold ); - drawText.DrawRect( x + 2, y + ( lineHt << 1 ) + 1, - x + width - 8, y + ( lineHt << 1 ) + 2, 127, 127, 255, 255 ); + drawText.DrawRect( x + 2, y + ( lineHt << 1 ) + 1, + x + width - 8, y + ( lineHt << 1 ) + 2, 127, 127, 255, 255 ); y += lineHt * 2; for( i = 0; i < IGetMaxNumLines( curLog ); i++ ) diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp index 248c42da..1906bccc 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp @@ -115,7 +115,7 @@ bool NameMatches(const char* obName, const char* pKName, bool subString) return false; } -plKey plKeyFinder::StupidSearch(const char * age, const char * rm, +plKey plKeyFinder::StupidSearch(const plString & age, const plString & rm, const char *className, const plString &obName, bool subString) { uint16_t ty = plFactory::FindClassIndex(className); @@ -129,7 +129,7 @@ protected: plString fObjName; bool fSubstr; plKey fFoundKey; - const char *fAgeName; + plString fAgeName; public: plKey GetFoundKey( void ) const { return fFoundKey; } @@ -137,7 +137,7 @@ public: plKeyFinderIter( uint16_t classType, const plString &obName, bool substr ) : fFoundKey( nil ), fClassType( classType ), fObjName( obName ), fSubstr( substr ) { } - plKeyFinderIter( uint16_t classType, const plString &obName, bool substr, const char *ageName ) + plKeyFinderIter( uint16_t classType, const plString &obName, bool substr, const plString &ageName ) : fFoundKey( nil ), fClassType( classType ), fObjName( obName ), fSubstr( substr ), fAgeName( ageName ) {} @@ -180,7 +180,7 @@ public: } }; -plKey plKeyFinder::StupidSearch(const char * age, const char * rm, +plKey plKeyFinder::StupidSearch(const plString & age, const plString & rm, uint16_t classType, const plString &obName, bool subString) { if (obName.IsNull()) @@ -196,9 +196,9 @@ plKey plKeyFinder::StupidSearch(const char * age, const char * rm, if (ty == maxClasses) // error { fLastError = kInvalidClass; return nil; - } + } - if( age != nil && rm != nil ) + if (!age.IsNull() && !rm.IsNull()) { const plLocation &loc = IGetResMgr()->FindLocation( age, rm ); if( !loc.IsValid() ) @@ -213,7 +213,7 @@ plKey plKeyFinder::StupidSearch(const char * age, const char * rm, // Return value of false means it stopped somewhere, i.e. found something return keyFinder.GetFoundKey(); } - else if( age != nil ) + else if (!age.IsNull()) { plKeyFinderIter keyFinder(classType, obName, subString, age); @@ -335,23 +335,22 @@ class plPageFinder : public plRegistryPageIterator protected: plRegistryPageNode **fPagePtr; - const char *fFindString, *fAgeString; + plString fFindString, fAgeString; public: - plPageFinder( plRegistryPageNode **page, const char *find ) : fPagePtr( page ), fFindString( find ), fAgeString( nil ) + plPageFinder( plRegistryPageNode **page, const plString &find ) : fPagePtr( page ), fFindString( find ) { *fPagePtr = nil; } - plPageFinder( plRegistryPageNode **page, const char *ageS, const char *pageS ) : fPagePtr( page ), fFindString( pageS ), fAgeString( ageS ) + plPageFinder( plRegistryPageNode **page, const plString &ageS, const plString &pageS ) : fPagePtr( page ), fFindString( pageS ), fAgeString( ageS ) { *fPagePtr = nil; } virtual bool EatPage( plRegistryPageNode *node ) { - static char str[ 512 ]; const plPageInfo &info = node->GetPageInfo(); // Are we searching by age/page? - if( fAgeString != nil ) + if (!fAgeString.IsNull()) { if (info.GetAge().CompareI(fAgeString) == 0 && info.GetPage().CompareI(fFindString) == 0) { @@ -369,8 +368,7 @@ class plPageFinder : public plRegistryPageIterator } // Try for full location - sprintf( str, "%s_%s", info.GetAge().c_str(), info.GetPage().c_str() ); - if( stricmp( str, fFindString ) == 0 ) + if (plString::Format("%s_%s", info.GetAge().c_str(), info.GetPage().c_str()).CompareI(fFindString) == 0) { *fPagePtr = node; return false; @@ -387,7 +385,7 @@ class plPageFinder : public plRegistryPageIterator // since the only time we call this function will be to actually load // the darned thing. -plKey plKeyFinder::FindSceneNodeKey( const char *pageOrFullLocName ) const +plKey plKeyFinder::FindSceneNodeKey( const plString &pageOrFullLocName ) const { plRegistryPageNode *pageNode; plPageFinder pageFinder( &pageNode, pageOrFullLocName ); @@ -404,7 +402,7 @@ plKey plKeyFinder::FindSceneNodeKey( const char *pageOrFullLocName ) const //// FindSceneNodeKey //////////////////////////////////////////////////////// // Age/page pair version -plKey plKeyFinder::FindSceneNodeKey( const char *ageName, const char *pageName ) const +plKey plKeyFinder::FindSceneNodeKey( const plString &ageName, const plString &pageName ) const { plRegistryPageNode *pageNode; plPageFinder pageFinder( &pageNode, ageName, pageName ); @@ -471,12 +469,12 @@ plKey plKeyFinder::IFindSceneNodeKey(plRegistryPageNode* page) const //// FindLocation //////////////////////////////////////////////////////////// -const plLocation &plKeyFinder::FindLocation( const char *age, const char *page ) const +const plLocation &plKeyFinder::FindLocation(const plString &age, const plString &page) const { - if (age == nil) + if (age == "") { static plLocation invalidLoc; - plRegistryPageNode *pageNode; + plRegistryPageNode *pageNode; plPageFinder pageFinder( &pageNode, page ); if( IGetResMgr()->IterateAllPages( &pageFinder ) || pageNode == nil ) diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.h b/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.h index 5fe471d2..55e02571 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.h @@ -88,8 +88,8 @@ public: static plKeyFinder& Instance(); // These are Stupid search because they just do string searchs on the objects. - plKey StupidSearch(const char * age, const char * rm, const char *className, const plString &obName, bool subString=false); - plKey StupidSearch(const char * age, const char * rm, uint16_t objType, const plString &obName, bool subString=false); + plKey StupidSearch(const plString & age, const plString & rm, const char *className, const plString &obName, bool subString=false); + plKey StupidSearch(const plString & age, const plString & rm, uint16_t objType, const plString &obName, bool subString=false); eErrCodes GetLastErrorCode() { return fLastError; } const char* GetLastErrorString(); // For Console display @@ -102,11 +102,11 @@ public: void GetActivatorNames(std::vector& names); void GetResponderNames(std::vector& names); - plKey FindSceneNodeKey(const char* pageOrFullLocName) const; - plKey FindSceneNodeKey(const char* ageName, const char* pageName) const; + plKey FindSceneNodeKey(const plString& pageOrFullLocName) const; + plKey FindSceneNodeKey(const plString& ageName, const plString& pageName) const; plKey FindSceneNodeKey(const plLocation& location) const; - const plLocation& FindLocation(const char* age, const char* page) const; + const plLocation& FindLocation(const plString& age, const plString& page) const; const plPageInfo* GetLocationInfo(const plLocation& loc) const; protected: diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp index 1ff2851c..60734df8 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" #include "plLocalization.h" -#include "plFile/plFileUtils.h" plLocalization::Language plLocalization::fLanguage = plLocalization::kEnglish; @@ -87,36 +86,28 @@ plLocalization::encodingTypes plLocalization::fUnicodeEncoding[] = Enc_UTF8, // kJapanese }; -bool plLocalization::IGetLocalized(const char* name, Language lang, char* localizedName) +plFileName plLocalization::IGetLocalized(const plFileName& name, Language lang) { - const char* underscore = strrchr(name, '_'); - - if (underscore) + int underscore = name.AsString().FindLast('_'); + + if (underscore >= 0) { - char langTag[kLangTagLen+1]; - strncpy(langTag,underscore,kLangTagLen); - langTag[kLangTagLen] = '\0'; - - if (strncmp(langTag, fLangTags[kEnglish], kLangTagLen) == 0) - { - if (localizedName) - { - strcpy(localizedName, name); - int underscorePos = underscore - name; - memcpy(localizedName + underscorePos, fLangTags[lang], kLangTagLen); - } - - return true; - } + plString langTag = name.AsString().Substr(underscore, kLangTagLen); + + if (langTag == fLangTags[kEnglish]) + return name.AsString().Left(underscore) + fLangTags[lang]; } - return false; + return ""; } -bool plLocalization::ExportGetLocalized(const char* name, int lang, char* localizedName) +plFileName plLocalization::ExportGetLocalized(const plFileName& name, int lang) { - return IGetLocalized(name, Language(lang+1), localizedName) && - plFileUtils::FileExists(localizedName); + plFileName localizedName = IGetLocalized(name, Language(lang+1)); + if (plFileInfo(localizedName).Exists()) + return localizedName; + + return ""; } std::string plLocalization::LocalToString(const std::vector & localizedText) diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h index a73011c5..c474562b 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +#include "plFileSystem.h" class plLocalization { @@ -81,7 +82,7 @@ protected: static bool fUsesUnicode[kNumLanguages]; static encodingTypes fUnicodeEncoding[kNumLanguages]; - static bool IGetLocalized(const char* name, Language lang, char* localizedName); + static plFileName IGetLocalized(const plFileName& name, Language lang); public: static void SetLanguage(Language lang) { fLanguage = lang; } @@ -97,8 +98,8 @@ public: static bool IsLocalized() { return fLanguage != kEnglish; } // Pass in a key name and this will give you the localized name - // Returns false if the original keyname is not for a localized asset - static bool GetLocalized(const char* name, char* localizedName) { return IGetLocalized(name, fLanguage, localizedName); } + // Returns an invalid filename if the original keyname is not for a localized asset + static plFileName GetLocalized(const plFileName& name) { return IGetLocalized(name, fLanguage); } // // Export only @@ -116,9 +117,9 @@ public: // } // static int GetNumLocales() { return kNumLanguages - 1; } - static bool ExportGetLocalized(const char* name, int lang, char* localizedName); + static plFileName ExportGetLocalized(const plFileName& name, int lang); // Just tells us if this is localized, doesn't actually convert it for us - static bool IsLocalizedName(const char* name) { return IGetLocalized(name, kEnglish, nil); } + static bool IsLocalizedName(const plFileName& name) { return IGetLocalized(name, kEnglish).IsValid(); } // Converts a vector of translated strings to a encoded string that can be decoded by StringToLocal() // The index in the vector of a string is it's language diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp index 8728692e..663c7c55 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp @@ -48,7 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plStatusLog/plStatusLog.h" #include "pnFactory/plFactory.h" #include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plVersion.h" diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index de0b574b..45fb821f 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -60,7 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plAgeLoadedMsg.h" #include "pnMessage/plClientMsg.h" #include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "pnFactory/plCreator.h" #include "pnNetCommon/plSynchedObject.h" #include "pnNetCommon/plNetApp.h" @@ -131,7 +130,7 @@ bool plResManager::IInit() { // We want to go through all the data files in our data path and add new // plRegistryPageNodes to the regTree for each - hsFolderIterator pathIterator(fDataPath.c_str()); + hsFolderIterator pathIterator(fDataPath.AsString().c_str()); while (pathIterator.NextFileSuffix(".prp")) { char fileName[kFolderIterator_MaxPath]; @@ -517,10 +516,10 @@ inline plKeyImp* IFindKeyLocalized(const plUoid& uoid, plRegistryPageNode* page) // If we're running localized, try to find a localized version first if ((!objectName.IsNull()) && plLocalization::IsLocalized()) { - char localName[256]; - if (plLocalization::GetLocalized(objectName.c_str(), localName)) + plFileName localName = plLocalization::GetLocalized(objectName.c_str()); + if (localName.IsValid()) { - plKeyImp* localKey = page->FindKey(uoid.GetClassType(), localName); + plKeyImp* localKey = page->FindKey(uoid.GetClassType(), localName.AsString()); if (localKey != nil) return localKey; } @@ -585,7 +584,7 @@ plKey plResManager::FindKey(const plUoid& uoid) return key; } -const plLocation& plResManager::FindLocation(const char* age, const char* page) const +const plLocation& plResManager::FindLocation(const plString& age, const plString& page) const { static plLocation invalidLoc; @@ -596,16 +595,16 @@ const plLocation& plResManager::FindLocation(const char* age, const char* page) return invalidLoc; } -void plResManager::GetLocationStrings(const plLocation& loc, char* ageBuffer, char* pageBuffer) const +void plResManager::GetLocationStrings(const plLocation& loc, plString* ageBuffer, plString* pageBuffer) const { plRegistryPageNode* page = FindPage(loc); const plPageInfo& info = page->GetPageInfo(); // Those buffers better be big enough... if (ageBuffer) - hsStrcpy(ageBuffer, info.GetAge().c_str()); + *ageBuffer = info.GetAge(); if (pageBuffer) - hsStrcpy(pageBuffer, info.GetPage().c_str()); + *pageBuffer = info.GetPage(); } bool plResManager::AddViaNotify(plRefMsg* msg, plRefFlags::Type flags) @@ -996,10 +995,10 @@ class plResAgeHolder : public hsRefCnt { public: hsTArray fKeys; - std::string fAge; + plString fAge; plResAgeHolder() {} - plResAgeHolder( const char* age ) : fAge( age ) {} + plResAgeHolder( const plString& age ) : fAge( age ) {} ~plResAgeHolder() { fKeys.Reset(); } }; @@ -1009,11 +1008,11 @@ class plResHolderIterator : public plRegistryPageIterator { protected: hsTArray& fKeys; - const char* fAgeName; + plString fAgeName; plResManager* fResMgr; public: - plResHolderIterator(const char* age, hsTArray& keys, plResManager* resMgr) + plResHolderIterator(const plString& age, hsTArray& keys, plResManager* resMgr) : fAgeName(age), fKeys(keys), fResMgr(resMgr) {} virtual bool EatPage(plRegistryPageNode* page) @@ -1031,21 +1030,21 @@ public: //// LoadAndHoldAgeKeys ////////////////////////////////////////////////////// -void plResManager::LoadAgeKeys(const char* age) +void plResManager::LoadAgeKeys(const plString& age) { - hsAssert(age && age[0] != '\0', "age is nil"); + hsAssert(!age.IsEmpty(), "age is nil"); HeldAgeKeyMap::const_iterator it = fHeldAgeKeys.find(age); if (it != fHeldAgeKeys.end()) { - kResMgrLog(1, ILog(1, "Reffing age keys for age %s", age)); - hsStatusMessageF("*** Reffing age keys for age %s ***\n", age); + kResMgrLog(1, ILog(1, "Reffing age keys for age %s", age.c_str())); + hsStatusMessageF("*** Reffing age keys for age %s ***\n", age.c_str()); plResAgeHolder* holder = it->second; holder->Ref(); } else { - kResMgrLog(1, ILog(1, "Loading age keys for age %s", age)); - hsStatusMessageF("*** Loading age keys for age %s ***\n", age); + kResMgrLog(1, ILog(1, "Loading age keys for age %s", age.c_str())); + hsStatusMessageF("*** Loading age keys for age %s ***\n", age.c_str()); plResAgeHolder* holder = new plResAgeHolder(age); fHeldAgeKeys[age] = holder; @@ -1057,7 +1056,7 @@ void plResManager::LoadAgeKeys(const char* age) //// DropAgeKeys ///////////////////////////////////////////////////////////// -void plResManager::DropAgeKeys(const char* age) +void plResManager::DropAgeKeys(const plString& age) { HeldAgeKeyMap::iterator it = fHeldAgeKeys.find(age); if (it != fHeldAgeKeys.end()) @@ -1066,12 +1065,12 @@ void plResManager::DropAgeKeys(const char* age) if (holder->RefCnt() == 1) { // Found it! - kResMgrLog(1, ILog(1, "Dropping held age keys for age %s", age)); + kResMgrLog(1, ILog(1, "Dropping held age keys for age %s", age.c_str())); fHeldAgeKeys.erase(it); } else { - kResMgrLog(1, ILog(1, "Unreffing age keys for age %s", age)); + kResMgrLog(1, ILog(1, "Unreffing age keys for age %s", age.c_str())); } holder->UnRef(); @@ -1236,11 +1235,11 @@ class plPageInAgeIter : public plRegistryPageIterator { private: plKey fDestKey; - const char* fAgeName; + plString fAgeName; std::vector fLocations; public: - plPageInAgeIter(plKey destKey, const char *ageName) : fDestKey(destKey), fAgeName(ageName) {} + plPageInAgeIter(plKey destKey, const plString &ageName) : fDestKey(destKey), fAgeName(ageName) {} ~plPageInAgeIter() { plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoomHold); @@ -1263,7 +1262,7 @@ public: // PageInAge is intended for bulk global ages, like GlobalAnimations or GlobalClothing // that store a lot of data we always want available. (Used to be known as PageInHold) -void plResManager::PageInAge(const char *age) +void plResManager::PageInAge(const plString &age) { plSynchEnabler ps(false); // disable dirty tracking while paging in plUoid lu(kClient_KEY); @@ -1492,9 +1491,9 @@ void plResManager::DumpUnusedKeys(plRegistryPageNode* page) const page->IterateKeys(&reffer); } -plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const char* age, const char* page) +plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const plString& age, const plString& page) { - plRegistryPageNode* pageNode = new plRegistryPageNode(location, age, page, fDataPath.c_str()); + plRegistryPageNode* pageNode = new plRegistryPageNode(location, age, page, fDataPath); fAllPages[location] = pageNode; return pageNode; diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h index e6e6e073..9096a827 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.h @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include +#include "plFileSystem.h" class plRegistryPageNode; class plRegistryKeyIterator; @@ -55,7 +56,6 @@ class plRegistryDataStream; class plResAgeHolder; class plResManagerHelper; class plDispatch; -class plFileName; // plProgressProc is a proc called every time an object loads, to keep a progress bar for // loading ages up-to-date. @@ -68,7 +68,7 @@ public: virtual ~plResManager(); // If the ResManager has already been initialized, you should call Reset after setting this - void SetDataPath(const char* path) { fDataPath = path; } + void SetDataPath(const plFileName& path) { fDataPath = path; } // Mainly for external tools. void AddSinglePage(const plFileName& path); @@ -87,9 +87,9 @@ public: //--------------------------- plKey FindOriginalKey(const plUoid&); virtual plKey FindKey(const plUoid&); // Same as above, but will check the uoid for clones - const plLocation& FindLocation(const char* age, const char* page) const; + const plLocation& FindLocation(const plString& age, const plString& page) const; // Use nil for any strings you don't need - void GetLocationStrings(const plLocation& loc, char* ageBuffer, char* pageBuffer) const; + void GetLocationStrings(const plLocation& loc, plString* ageBuffer, plString* pageBuffer) const; //--------------------------- // Establish reference linkage @@ -134,10 +134,10 @@ public: //--------------------------- // Load optimizations //--------------------------- - void LoadAgeKeys(const char* age); - void DropAgeKeys(const char* age); + void LoadAgeKeys(const plString& age); + void DropAgeKeys(const plString& age); void PageInRoom(const plLocation& page, uint16_t objClassToRef, plRefMsg* refMsg); - void PageInAge(const char* age); + void PageInAge(const plString& age); // Usually, a page file is kept open during load because the first keyed object // read causes all the other objects to be read before it returns. In some @@ -152,7 +152,7 @@ public: void LogReadTimes(bool logReadTimes); // All keys version - bool IterateKeys(plRegistryKeyIterator* iterator); + bool IterateKeys(plRegistryKeyIterator* iterator); // Single page version bool IterateKeys(plRegistryKeyIterator* iterator, const plLocation& pageToRestrictTo); // Iterate through loaded pages @@ -185,7 +185,7 @@ protected: virtual void IKeyReffed(plKeyImp* key); virtual void IKeyUnreffed(plKeyImp* key); - virtual bool IReset(); + virtual bool IReset(); virtual bool IInit(); virtual void IShutdown(); @@ -207,7 +207,7 @@ protected: // Adds a key to the registry. Assumes uoid already set void AddKey(plKeyImp* key); - plRegistryPageNode* CreatePage(const plLocation& location, const char* age, const char* page); + plRegistryPageNode* CreatePage(const plLocation& location, const plString& age, const plString& page); bool fInited; @@ -215,7 +215,7 @@ protected: bool fReadingObject; std::vector fQueuedReads; - std::string fDataPath; + plFileName fDataPath; plDispatch* fDispatch; @@ -223,7 +223,7 @@ protected: uint32_t fCurClonePlayerID; uint32_t fCloningCounter; // Next clone ID to use. - typedef std::map HeldAgeKeyMap; + typedef std::map HeldAgeKeyMap; HeldAgeKeyMap fHeldAgeKeys; plProgressProc fProgressProc; diff --git a/Sources/Plasma/PubUtilLib/plSDL/plSDL.h b/Sources/Plasma/PubUtilLib/plSDL/plSDL.h index eca6473d..48053314 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDL.h +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDL.h @@ -533,10 +533,10 @@ class plSDLMgr { friend class plSDLParser; private: - std::string fSDLDir; + plFileName fSDLDir; plSDL::DescriptorList fDescriptors; plNetApp* fNetApp; - uint32_t fBehaviorFlags; + uint32_t fBehaviorFlags; void IDeleteDescriptors(plSDL::DescriptorList* dl); public: @@ -548,8 +548,8 @@ public: const plSDL::DescriptorList * GetDescriptors( void ) const { return &fDescriptors;} - void SetSDLDir(const char* s) { fSDLDir=s; } - const char* GetSDLDir() const { return fSDLDir.c_str(); } + void SetSDLDir(const plFileName& s) { fSDLDir=s; } + plFileName GetSDLDir() const { return fSDLDir; } void SetNetApp(plNetApp* a) { fNetApp=a; } plNetApp* GetNetApp() const { return fNetApp; } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index e213916f..a153bbc1 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp @@ -57,7 +57,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnMessage/plClientMsg.h" #include "plAgeLoader/plAgeLoader.h" #include "plProfileManagerFull.h" -#include "plFile/plFileUtils.h" #include "plPipeline/plDebugText.h" #include "pnMessage/plTimeMsg.h" diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index d5e09e71..8bb74a15 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -50,7 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "pnUtils/pnUtils.h" #include "plUnifiedTime/plUnifiedTime.h" -#include "plFile/plFileUtils.h" plProfileManagerFull::plProfileManagerFull() : fVars(plProfileManager::Instance().fVars), diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 59b2e383..da9ae62c 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -60,7 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsThread.h" #include "hsTemplates.h" #include "hsTimer.h" -#include "plFile/plFileUtils.h" #include "plStatusLog.h" #include "plFile/hsFiles.h" #include "plUnifiedTime/plUnifiedTime.h" @@ -220,7 +219,7 @@ plStatusLog *plStatusLogMgr::FindLog( const plFileName &filename, bool createIfN return nil; // Didn't find one, so create one! (make it a nice default one :) - log = CreateStatusLog( kDefaultNumLines, filename, plStatusLog::kFilledBackground | + log = CreateStatusLog( kDefaultNumLines, filename, plStatusLog::kFilledBackground | plStatusLog::kDeleteForMe ); return log; @@ -753,4 +752,3 @@ bool plStatusLog::IPrintLineToFile( const char *line, uint32_t count ) return ret; } - diff --git a/Sources/Tools/MaxComponent/Pch.h b/Sources/Tools/MaxComponent/Pch.h index b287a30b..d4f41b00 100644 --- a/Sources/Tools/MaxComponent/Pch.h +++ b/Sources/Tools/MaxComponent/Pch.h @@ -60,7 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAudible.h" #include "plCreatableIndex.h" #include "plgDispatch.h" -#include "plFile/plFileUtils.h" #include "plFile/hsFiles.h" #include "hsGeometry3.h" #include "plLoadMask.h" diff --git a/Sources/Tools/MaxComponent/plAudioComponents.cpp b/Sources/Tools/MaxComponent/plAudioComponents.cpp index d19866a7..da85365f 100644 --- a/Sources/Tools/MaxComponent/plAudioComponents.cpp +++ b/Sources/Tools/MaxComponent/plAudioComponents.cpp @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "plgDispatch.h" -#include "plFile/plFileUtils.h" #include "plAnimComponent.h" #include "plAudioComponents.h" @@ -588,21 +587,20 @@ uint32_t plBaseSoundEmitterComponent::ICalcSourceBufferFlags( void ) const return bufferFlags; } -plSoundBuffer *plBaseSoundEmitterComponent::GetSourceBuffer( const char *fileName, plMaxNode *srcNode, uint32_t srcBufferFlags ) +plSoundBuffer *plBaseSoundEmitterComponent::GetSourceBuffer( const plFileName &fileName, plMaxNode *srcNode, uint32_t srcBufferFlags ) { plSoundBuffer* sb = IGetSourceBuffer(fileName, srcNode, srcBufferFlags); - const char* plasmaDir = plMaxConfig::GetClientPath(); - if (plasmaDir) + plFileName plasmaDir = plMaxConfig::GetClientPath(); + if (plasmaDir.IsValid()) { - char sfxPath[MAX_PATH]; - sprintf(sfxPath, "%ssfx\\%s", plasmaDir, plFileUtils::GetFileName(fileName)); - + plFileName sfxPath = plFileName::Join(plasmaDir, "sfx", fileName.GetFileName()); + // Export any localized versions as well for (int i = 0; i < plLocalization::GetNumLocales(); i++) { - char localName[MAX_PATH]; - if (plLocalization::ExportGetLocalized(sfxPath, i, localName)) + plFileName localName = plLocalization::ExportGetLocalized(sfxPath, i); + if (localName.IsValid()) { IGetSourceBuffer(localName, srcNode, srcBufferFlags); } @@ -612,58 +610,45 @@ plSoundBuffer *plBaseSoundEmitterComponent::GetSourceBuffer( const char *fileN return sb; } -plSoundBuffer *plBaseSoundEmitterComponent::IGetSourceBuffer( const char *fileName, plMaxNode *srcNode, uint32_t srcBufferFlags ) +plSoundBuffer *plBaseSoundEmitterComponent::IGetSourceBuffer(const plFileName &fileName, plMaxNode *srcNode, uint32_t srcBufferFlags) { plKey key; - plString keyName; - char fullPath[ MAX_PATH ]; - - - // ***TEMP plString REVISIT*** - char tempPath[ MAX_PATH ]; - strncpy(tempPath, fileName, MAX_PATH); - ::PathStripPath( tempPath ); - keyName = tempPath; + plString keyName = fileName.GetFileName(); // TEMP HACK until we get packed sounds: // Given the source filename, we check to see if it's in our plasma game directory. If not, or if // it's out of date, we copy it over. We'll truncate the filename inside plSoundBuffer when we're ready. - const char *plasmaDir = plMaxConfig::GetClientPath(); - if( plasmaDir != nil ) + plFileName plasmaDir = plMaxConfig::GetClientPath(); + plFileName rfilename = fileName; + if (plasmaDir.IsValid()) { - strcpy( fullPath, plasmaDir ); - strcat( fullPath, "sfx\\" ); + plFileName fullPath = plFileName::Join(plasmaDir, "sfx"); // Before we finish our path, make sure that directory EXISTS - plFileUtils::CreateDir( fullPath ); + plFileSystem::CreateDir(fullPath); // Now finish the path... - strcat( fullPath, keyName.c_str() ); + fullPath = plFileName::Join(fullPath, keyName); // Check filestamp - WIN32_FILE_ATTRIBUTE_DATA oldFileAttrib, newFileAttrib; - BOOL oldOK, newOK; - - oldOK = GetFileAttributesEx( fileName, GetFileExInfoStandard, &oldFileAttrib ); - newOK = GetFileAttributesEx( fullPath, GetFileExInfoStandard, &newFileAttrib ); + plFileInfo oldInfo(fileName); + plFileInfo newInfo(fullPath); - if( oldOK && newOK ) + if (oldInfo.Exists() && newInfo.Exists()) { // Only copy if the file is newer - if( ::CompareFileTime( &oldFileAttrib.ftLastWriteTime, &newFileAttrib.ftLastWriteTime ) > 0 ) - { - ::CopyFile( fileName, fullPath, FALSE ); - } + if (oldInfo.ModifyTime() > newInfo.ModifyTime()) + plFileSystem::Copy(fileName, fullPath); } else { // Can't compare, so either there was an error or the target file doesn't exist. Copy no matter what. - ::CopyFile( fileName, fullPath, FALSE ); + plFileSystem::Copy(fileName, fullPath); } // Point to our new sound file - fileName = fullPath; + rfilename = fullPath; } // Additional info for the keyName--need some flag mangling, specifically for the left/right channel mangling @@ -672,12 +657,12 @@ plSoundBuffer *plBaseSoundEmitterComponent::IGetSourceBuffer( const char *file else if( srcBufferFlags & plSoundBuffer::kOnlyRightChannel ) keyName += ":R"; - key = srcNode->FindPageKey( plSoundBuffer::Index(), keyName ); + key = srcNode->FindPageKey( plSoundBuffer::Index(), keyName ); if( key != nil ) return plSoundBuffer::ConvertNoRef( key->GetObjectPtr() ); // Not yet created, so make a new one - plSoundBuffer *buffer = new plSoundBuffer( fileName, srcBufferFlags ); + plSoundBuffer *buffer = new plSoundBuffer( rfilename, srcBufferFlags ); if( !buffer->IsValid() ) { // Invalid, so delete and return nil @@ -2258,29 +2243,18 @@ bool plSound3DEmitterComponent::ConvertGrouped( plMaxNode *baseNode, hsTArray } // Grab the buffer for this sound directly from the original source - const char *fileName = groupArray[ i ]->GetSoundFileName( kBaseSound ); + plFileName fileName = groupArray[ i ]->GetSoundFileName( kBaseSound ); plSoundBuffer *buffer = new plSoundBuffer( fileName ); if( !buffer->IsValid() || !buffer->EnsureInternal() ) { // OK, because some *cough* machines are completely stupid and don't load AssetMan scenes with // AssetMan plugins, we need to do a really stupid fallback search to the current exporting directory. - const char *plasmaDir = plMaxConfig::GetClientPath(); + plFileName plasmaDir = plMaxConfig::GetClientPath(); bool worked = false; - if( plasmaDir != nil ) + if (plasmaDir.IsValid()) { - char newPath[ MAX_PATH ]; - strcpy( newPath, plasmaDir ); - strcat( newPath, "sfx\\" ); - - const char* c = strrchr( fileName, '\\' ); - if( c == nil ) - c = strrchr( fileName, '/' ); - if( c == nil ) - c = fileName; - else - c++; - strcat( newPath, c ); + plFileName newPath = plFileName::Join(plasmaDir, "sfx", fileName.GetFileName()); // Got a path to try, so try it! delete buffer; @@ -2292,7 +2266,7 @@ bool plSound3DEmitterComponent::ConvertGrouped( plMaxNode *baseNode, hsTArray if( !worked ) { char msg[ 512 ]; - sprintf( msg, "The sound file %s cannot be loaded for component %s.", fileName, groupArray[ i ]->GetINode()->GetName() ); + sprintf( msg, "The sound file %s cannot be loaded for component %s.", fileName.AsString().c_str(), groupArray[ i ]->GetINode()->GetName() ); IShowError( kSrcBufferInvalid, msg, baseNode->GetName(), pErrMsg ); delete buffer; @@ -2312,7 +2286,7 @@ bool plSound3DEmitterComponent::ConvertGrouped( plMaxNode *baseNode, hsTArray { char msg[ 512 ]; sprintf( msg, "The format for sound file %s does not match the format for the other grouped sounds on node %s. " - "Make sure the sounds are all the same format.", fileName, baseNode->GetName() ); + "Make sure the sounds are all the same format.", fileName.AsString().c_str(), baseNode->GetName() ); IShowError( kMergeSourceFormatMismatch, msg, baseNode->GetName(), pErrMsg ); delete buffer; diff --git a/Sources/Tools/MaxComponent/plAudioComponents.h b/Sources/Tools/MaxComponent/plAudioComponents.h index 9bc4d797..0c22849d 100644 --- a/Sources/Tools/MaxComponent/plAudioComponents.h +++ b/Sources/Tools/MaxComponent/plAudioComponents.h @@ -65,6 +65,7 @@ class plMaxNode; class plSoundBuffer; class plSound; class plAudioBaseComponentProc; +class plFileName; namespace plAudioComp { @@ -117,7 +118,7 @@ class plBaseSoundEmitterComponent : public plComponent return -1; } - static plSoundBuffer *GetSourceBuffer( const char *fileName, plMaxNode *node, uint32_t srcBufferFlags ); + static plSoundBuffer *GetSourceBuffer( const plFileName &fileName, plMaxNode *node, uint32_t srcBufferFlags ); static bool LookupLatestAsset( const char *waveName, char *retPath, plErrorMsg *errMsg ); virtual void UpdateSoundFileSelection( void ); @@ -177,7 +178,7 @@ class plBaseSoundEmitterComponent : public plComponent virtual uint32_t ICalcSourceBufferFlags() const; - static plSoundBuffer *IGetSourceBuffer( const char *fileName, plMaxNode *srcNode, uint32_t srcBufferFlags ); + static plSoundBuffer *IGetSourceBuffer( const plFileName &fileName, plMaxNode *srcNode, uint32_t srcBufferFlags ); plSoundBuffer *IProcessSourceBuffer( plMaxNode *maxNode, plErrorMsg *errMsg ); diff --git a/Sources/Tools/MaxComponent/plGUIComponents.cpp b/Sources/Tools/MaxComponent/plGUIComponents.cpp index e02ab0f3..98fc7057 100644 --- a/Sources/Tools/MaxComponent/plGUIComponents.cpp +++ b/Sources/Tools/MaxComponent/plGUIComponents.cpp @@ -1449,8 +1449,8 @@ void plGUIDialogProc::ILoadPages( HWND hWnd, IParamBlock2 *pb ) while( ( page = aged->GetNextPage() ) != nil ) { - int idx = ComboBox_AddString( hWnd, page->GetName() ); - if( selPageName && stricmp( page->GetName(), selPageName ) == 0 ) + int idx = ComboBox_AddString( hWnd, page->GetName().c_str() ); + if( selPageName && page->GetName().CompareI( selPageName ) == 0 ) ComboBox_SetCurSel( hWnd, idx ); } diff --git a/Sources/Tools/MaxComponent/plMiscComponents.cpp b/Sources/Tools/MaxComponent/plMiscComponents.cpp index afdbf340..e8afdfe1 100644 --- a/Sources/Tools/MaxComponent/plMiscComponents.cpp +++ b/Sources/Tools/MaxComponent/plMiscComponents.cpp @@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "plCreatableIndex.h" #include "plgDispatch.h" -#include "plFile/plFileUtils.h" #include "plFile/hsFiles.h" #include "plComponentReg.h" @@ -237,8 +236,8 @@ protected: aged.SeekFirstPage(); while( ( page = aged.GetNextPage() ) != nil ) { - int idx = ComboBox_AddString(hPageCombo, page->GetName() ); - if (curPage && !strcmp(page->GetName(), curPage)) + int idx = ComboBox_AddString(hPageCombo, page->GetName().c_str() ); + if (curPage && (page->GetName() == curPage)) ComboBox_SetCurSel(hPageCombo, idx); ComboBox_SetItemData( hPageCombo, idx, (int)page->GetSeqSuffix() ); } @@ -576,33 +575,32 @@ const char *plPageInfoComponent::GetAgeName() // Checks in assetMan to make sure we have the latest .age file to export // with. -void plPageInfoComponent::IVerifyLatestAgeAsset( const char *ageName, const char *localPath, plErrorMsg *errMsg ) +void plPageInfoComponent::IVerifyLatestAgeAsset( const plString &ageName, const plFileName &localPath, plErrorMsg *errMsg ) { #ifdef MAXASS_AVAILABLE - char ageFileName[ MAX_PATH ], assetPath[ MAX_PATH ]; - + plFileName ageFileName, assetPath; MaxAssInterface *assetMan = GetMaxAssInterface(); if( assetMan == nil ) return; // No AssetMan available // Try to find it in assetMan - sprintf( ageFileName, "%s.age", ageName ); + ageFileName = ageName + ".age"; jvUniqueId assetId; - if (assetMan->FindAssetByFilename(ageFileName, assetId)) + if (assetMan->FindAssetByFilename(ageFileName.AsString().c_str(), assetId)) { // Get the latest version if (!assetMan->GetLatestVersionFile(assetId, assetPath, sizeof(assetPath))) { errMsg->Set( true, "PageInfo Convert Error", - "Unable to update age file for '%s' because AssetMan was unable to get the latest version. Using local copy instead.", ageName ).Show(); + "Unable to update age file for '%s' because AssetMan was unable to get the latest version. Using local copy instead.", ageName.c_str() ).Show(); errMsg->Set( false ); return; } // Got the latest version, just copy over and roll! - plFileUtils::RemoveFile( localPath ); - plFileUtils::FileCopy( assetPath, localPath ); + plFileSystem::Unlink(localPath); + plFileSystem::Copy(assetPath, localPath); } else { @@ -625,10 +623,8 @@ void plPageInfoComponent::IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ) // Mark us as updated fCompPB->SetValue( kRefVolatile_PageInfoUpdated, 0, (int)true ); - char path[MAX_PATH]; - - const char *ageFolder = plPageInfoUtils::GetAgeFolder(); - if( ageFolder == nil ) + plFileName ageFolder = plPageInfoUtils::GetAgeFolder(); + if (!ageFolder.IsValid()) { errMsg->Set( true, "PageInfo Convert Error", @@ -653,7 +649,7 @@ void plPageInfoComponent::IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ) fCompPB->SetValue( kInfoSeqSuffix, 0, 0 ); return; } - sprintf(path, "%s%s.age", ageFolder, curAge); + plFileName path = plFileName::Join(ageFolder, plString::Format("%s.age", curAge)); IVerifyLatestAgeAsset( curAge, path, errMsg ); @@ -699,12 +695,12 @@ void plPageInfoComponent::IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ) while( ( page = aged.GetNextPage() ) != nil ) { - if( stricmp( page->GetName(), compPBPageName ) == 0 ) + if( page->GetName().CompareI( compPBPageName ) == 0 ) { fCompPB->SetValue( kInfoSeqSuffix, 0, (int)page->GetSeqSuffix() ); // Also re-copy the page name, just to make sure the case is correct - fCompPB->SetValue( kInfoPage, 0, (char *)page->GetName() ); + fCompPB->SetValue( kInfoPage, 0, (const char *)page->GetName().c_str() ); return; } } @@ -720,28 +716,20 @@ void plPageInfoComponent::IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ) fCompPB->SetValue( kInfoSeqSuffix, 0, 0 ); } -const char *plPageInfoUtils::GetAgeFolder() +plFileName plPageInfoUtils::GetAgeFolder() { - static char ageFolder[MAX_PATH]; - static bool initialized = false; + static plFileName ageFolder; - if (!initialized) + if (!ageFolder.IsValid()) { - initialized = true; - ageFolder[0] = '\0'; + plFileName plasmaPath = plMaxConfig::GetClientPath(); + if (!plasmaPath.IsValid()) + return ""; - const char *plasmaPath = plMaxConfig::GetClientPath(); - if (!plasmaPath) - return nil; - - strcpy(ageFolder, plasmaPath); - strcat(ageFolder, plAgeDescription::kAgeDescPath); + ageFolder = plFileName::Join(plasmaPath, plAgeDescription::kAgeDescPath); } - if (ageFolder[0] != '\0') - return ageFolder; - else - return nil; + return ageFolder; } int32_t plPageInfoUtils::CombineSeqNum( int prefix, int suffix ) @@ -789,7 +777,7 @@ int32_t plPageInfoUtils::GetSeqNumFromAgeDesc( const char *ageName, const char aged->SeekFirstPage(); while( ( page = aged->GetNextPage() ) != nil ) { - if( stricmp( pageName, page->GetName() ) == 0 ) + if (page->GetName().CompareI(pageName) == 0) { seqSuffix = page->GetSeqSuffix(); break; @@ -801,18 +789,14 @@ int32_t plPageInfoUtils::GetSeqNumFromAgeDesc( const char *ageName, const char return CombineSeqNum( seqPrefix, seqSuffix ); } -plAgeDescription *plPageInfoUtils::GetAgeDesc( const char *ageName ) +plAgeDescription *plPageInfoUtils::GetAgeDesc( const plString &ageName ) { - char path[ MAX_PATH ]; - - const char *ageFolder = plPageInfoUtils::GetAgeFolder(); - if( ageFolder == nil || ageName == nil ) + plFileName ageFolder = plPageInfoUtils::GetAgeFolder(); + if (!ageFolder.IsValid() || ageName.IsNull()) return nil; - sprintf( path, "%s%s.age", ageFolder, ageName ); - hsUNIXStream s; - if( !s.Open( path ) ) + if (!s.Open(plFileName::Join(ageFolder, ageName + ".age"))) return nil; // Create and read the age desc diff --git a/Sources/Tools/MaxComponent/plMiscComponents.h b/Sources/Tools/MaxComponent/plMiscComponents.h index 7fb4a5eb..a2536513 100644 --- a/Sources/Tools/MaxComponent/plMiscComponents.h +++ b/Sources/Tools/MaxComponent/plMiscComponents.h @@ -52,6 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define CIRCLE_CAM_CID Class_ID(0x66f85282, 0x4daa1b8e) #define IMAGE_LIB_CID Class_ID(0x736c18d3, 0x6a6d5dde) +class plFileName; class plAgeDescription; class plComponentBase; struct NotifyInfo; @@ -60,12 +61,12 @@ const char* LocCompGetPage(plComponentBase* comp); namespace plPageInfoUtils { - const char *GetAgeFolder(); - int32_t GetSeqNumFromAgeDesc( const char *ageName, const char *pageName ); - int32_t CombineSeqNum( int prefix, int suffix ); - int32_t GetCommonSeqNumFromNormal( int32_t normalSeqNumber, int whichCommonPage ); + plFileName GetAgeFolder(); + int32_t GetSeqNumFromAgeDesc( const char *ageName, const char *pageName ); + int32_t CombineSeqNum( int prefix, int suffix ); + int32_t GetCommonSeqNumFromNormal( int32_t normalSeqNumber, int whichCommonPage ); - plAgeDescription *GetAgeDesc( const char *ageName ); + plAgeDescription *GetAgeDesc( const plString &ageName ); }; // PageInfo component definition, here so other components can get to the static function(s) @@ -76,8 +77,8 @@ protected: bool fItinerant; static char fCurrExportedAge[ 256 ]; - void IVerifyLatestAgeAsset( const char *ageName, const char *localPath, plErrorMsg *errMsg ); - void IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ); + void IVerifyLatestAgeAsset( const plString &ageName, const plFileName &localPath, plErrorMsg *errMsg ); + void IUpdateSeqNumbersFromAgeFile( plErrorMsg *errMsg ); public: plPageInfoComponent(); diff --git a/Sources/Tools/MaxComponent/plResponderLink.cpp b/Sources/Tools/MaxComponent/plResponderLink.cpp index 902664a6..26365e86 100644 --- a/Sources/Tools/MaxComponent/plResponderLink.cpp +++ b/Sources/Tools/MaxComponent/plResponderLink.cpp @@ -318,19 +318,18 @@ void plResponderLinkProc::ILoadAgeFilenamesCombo(HWND hWnd, IParamBlock2 *pb) SendMessage(hAge, CB_RESETCONTENT, 0, 0); // Get the path to the description folder - char agePath[MAX_PATH]; - const char *plasmaPath = plMaxConfig::GetClientPath(); - if (!plasmaPath) + plFileName plasmaPath = plMaxConfig::GetClientPath(); + if (!plasmaPath.IsValid()) return; - strcpy(agePath, plasmaPath); - strcat(agePath, plAgeDescription::kAgeDescPath); + + plFileName agePath = plFileName::Join(plasmaPath, plAgeDescription::kAgeDescPath); const char *savedName = pb->GetStr(kLinkAgeFilename); if (!savedName) savedName = ""; // Iterate through the age descriptions - hsFolderIterator ageFolder(agePath); + hsFolderIterator ageFolder(agePath.AsString().c_str()); while (ageFolder.NextFileSuffix(".age")) { char ageFile[MAX_PATH]; @@ -355,19 +354,17 @@ void plResponderLinkProc::ILoadParentAgeFilenamesCombo(HWND hWnd, IParamBlock2 * SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)""); // Get the path to the description folder - char agePath[MAX_PATH]; - const char *plasmaPath = plMaxConfig::GetClientPath(); - if (!plasmaPath) + plFileName plasmaPath = plMaxConfig::GetClientPath(); + if (!plasmaPath.IsValid()) return; - strcpy(agePath, plasmaPath); - strcat(agePath, plAgeDescription::kAgeDescPath); + plFileName agePath = plFileName::Join(plasmaPath, plAgeDescription::kAgeDescPath); const char *savedName = pb->GetStr(kLinkParentAgeFilename); if (!savedName) savedName = ""; // Iterate through the age descriptions - hsFolderIterator ageFolder(agePath); + hsFolderIterator ageFolder(agePath.AsString().c_str()); while (ageFolder.NextFileSuffix(".age")) { char ageFile[MAX_PATH]; diff --git a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp index d0b4a8a9..0c7f7356 100644 --- a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp +++ b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp @@ -71,7 +71,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plSurface/hsGMaterial.h" #include "pnSceneObject/plSceneObject.h" #include "UserPropMgr.h" -#include "plFile/plFileUtils.h" #include "hsConverterUtils.h" #include "hsControlConverter.h" @@ -1981,18 +1980,17 @@ static plLayerInterface* IProcessLayerMovie(plPassMtlBase* mtl, plLayerTex* layT if( !bi || !bi->Name() || !*bi->Name() ) return layerIFace; - const char* fileName = bi->Name(); + plFileName fileName = bi->Name(); plAnimStealthNode* stealth = IGetEntireAnimation(mtl); - const char* ext = plFileUtils::GetFileExt(fileName); - bool isBink = ext && (stricmp(ext, "bik") == 0); - bool isAvi = ext &&(stricmp(ext, "avi") == 0); + plString ext = fileName.GetFileExt(); + bool isBink = (ext.CompareI("bik") == 0); + bool isAvi = (ext.CompareI("avi") == 0); if (isBink || isAvi) { - char movieName[256]; - sprintf(movieName, "avi/%s", plFileUtils::GetFileName(fileName)); + plFileName movieName = plFileName::Join("avi", fileName.GetFileName()); plLayerMovie* movieLayer = nil; plString moviePostfix; diff --git a/Sources/Tools/MaxConvert/plBitmapCreator.cpp b/Sources/Tools/MaxConvert/plBitmapCreator.cpp index e814a765..e9b119e1 100644 --- a/Sources/Tools/MaxConvert/plBitmapCreator.cpp +++ b/Sources/Tools/MaxConvert/plBitmapCreator.cpp @@ -134,7 +134,7 @@ plMipmap *plBitmapCreator::ICreateBitmap(plBitmapData *bd) // Load the bitmap BitmapInfo bi; - bi.SetName(bd->fileName); + bi.SetName(bd->fileName.AsString().c_str()); #if 0 // This isn't really an issue since the textures are packed -Colin const int kMaxFileNameLength = 30; @@ -267,20 +267,20 @@ plMipmap *plBitmapCreator::ICreateBitmap(plBitmapData *bd) // // Verify that bitmap is the correct type/size // -void plBitmapCreator::ICheckOutBitmap(BitmapInfo* bInfo, Bitmap* bm, const char *fileName) +void plBitmapCreator::ICheckOutBitmap(BitmapInfo* bInfo, Bitmap* bm, const plFileName& fileName) { hsGuardBegin("hsConverterUtils::ICheckOutBitmap"); // Check out bitmap if (bm->Flags() & MAP_FLIPPED) - MessageBox(GetActiveWindow(), "Bitmap is flipped horizontally", fileName, MB_OK); + MessageBox(GetActiveWindow(), "Bitmap is flipped horizontally", fileName.AsString().c_str(), MB_OK); if (bm->Flags() & MAP_INVERTED) - MessageBox(GetActiveWindow(), "Bitmap is inverted vertically", fileName, MB_OK); + MessageBox(GetActiveWindow(), "Bitmap is inverted vertically", fileName.AsString().c_str(), MB_OK); if (bInfo->Flags() & MAP_FLIPPED) - MessageBox(GetActiveWindow(), "BI:Bitmap is flipped horizontally", fileName, MB_OK); + MessageBox(GetActiveWindow(), "BI:Bitmap is flipped horizontally", fileName.AsString().c_str(), MB_OK); if (bInfo->Flags() & MAP_INVERTED) - MessageBox(GetActiveWindow(), "BI:Bitmap is inverted vertically", fileName, MB_OK); + MessageBox(GetActiveWindow(), "BI:Bitmap is inverted vertically", fileName.AsString().c_str(), MB_OK); hsGuardEnd; } @@ -480,10 +480,10 @@ plBitmap *plBitmapCreator::CreateTexture(plBitmapData *bd, const plLocation &loc for (int i = 0; i < plLocalization::GetNumLocales(); i++) { - char localName[MAX_PATH]; - if (plLocalization::ExportGetLocalized(bd->fileName, i, localName)) + plFileName localName = plLocalization::ExportGetLocalized(bd->fileName, i); + if (localName.IsValid()) { - const char* oldName = bd->fileName; + plFileName oldName = bd->fileName; bd->fileName = localName; ICreateTexture(bd, loc, clipID); bd->fileName = oldName; @@ -517,40 +517,39 @@ plBitmap *plBitmapCreator::ICreateTexture( plBitmapData *bd, const plLocation &l return nil; } - if( bd->fileName == nil || bd->fileName[ 0 ] == 0 ) + if (!bd->fileName.IsValid()) { fErrorMsg->Set( true, "Bitmap Error", "Material texture has null bitmap name." ).Show(); - fErrorMsg->Set(); + fErrorMsg->Set(); return nil; } // Get and mangle key name plString name; - char temp[ 256 ]; - _splitpath(bd->fileName, NULL, NULL, temp, NULL); + plString temp = bd->fileName.GetFileNameNoExt(); // Somehow, sometimes, we get the same file in with different cases. So we need to force the // case identical all the time, else the patching process for dat files will think they're // "different" when they're really not - strlwr( temp ); + temp = temp.ToLower(); /// Mangle name for detail textures, so we don't end up overwriting settings elsewhere if( bd->createFlags & plMipmap::kCreateDetailMask ) { // Mangle of the form: name@dropStart&dropStop&max&min if( clipID != -1 ) - name = plString::Format( "%s*%x#%d@%s&%3.2f&%3.2f&%3.2f&%3.2f", temp, bd->texFlags, clipID, + name = plString::Format( "%s*%x#%d@%s&%3.2f&%3.2f&%3.2f&%3.2f", temp.c_str(), bd->texFlags, clipID, bd->createFlags & plMipmap::kCreateDetailAlpha ? "al" : ( bd->createFlags & plMipmap::kCreateDetailAdd ? "ad" : "mu" ), bd->detailDropoffStart, bd->detailDropoffStop, bd->detailMax, bd->detailMin ); else - name = plString::Format( "%s*%x@%s&%3.2f&%3.2f&%3.2f&%3.2f", temp, bd->texFlags, + name = plString::Format( "%s*%x@%s&%3.2f&%3.2f&%3.2f&%3.2f", temp.c_str(), bd->texFlags, bd->createFlags & plMipmap::kCreateDetailAlpha ? "al" : ( bd->createFlags == plMipmap::kCreateDetailAdd ? "ad" : "mu" ), bd->detailDropoffStart, bd->detailDropoffStop, bd->detailMax, bd->detailMin ); } else if( clipID != -1 ) - name = plString::Format( "%s*%x#%d", temp, bd->texFlags, clipID ); + name = plString::Format( "%s*%x#%d", temp.c_str(), bd->texFlags, clipID ); else - name = plString::Format( "%s*%x", temp, bd->texFlags ); + name = plString::Format( "%s*%x", temp.c_str(), bd->texFlags ); if( bd->invertAlpha ) name += "_inva"; name += ".hsm"; @@ -566,7 +565,7 @@ plBitmap *plBitmapCreator::ICreateTexture( plBitmapData *bd, const plLocation &l if( texture ) { WIN32_FILE_ATTRIBUTE_DATA fileAttrib; - GetFileAttributesEx(bd->fileName, GetFileExInfoStandard, &fileAttrib); + GetFileAttributesExW(bd->fileName.AsString().ToWchar(), GetFileExInfoStandard, &fileAttrib); FILETIME &fileTime = fileAttrib.ftLastWriteTime; // If this texture has been modified since the last export, delete the old version but reuse the key @@ -652,7 +651,7 @@ plBitmap *plBitmapCreator::ICreateTexture( plBitmapData *bd, const plLocation &l // Texture reuse optimization WIN32_FILE_ATTRIBUTE_DATA fileAttrib; - GetFileAttributesEx(bd->fileName, GetFileExInfoStandard, &fileAttrib); + GetFileAttributesExW(bd->fileName.AsString().ToWchar(), GetFileExInfoStandard, &fileAttrib); FILETIME &fileTime = fileAttrib.ftLastWriteTime; texture->SetModifiedTime(fileTime.dwLowDateTime, fileTime.dwHighDateTime); diff --git a/Sources/Tools/MaxConvert/plBitmapCreator.h b/Sources/Tools/MaxConvert/plBitmapCreator.h index 7fa18561..4cc717f4 100644 --- a/Sources/Tools/MaxConvert/plBitmapCreator.h +++ b/Sources/Tools/MaxConvert/plBitmapCreator.h @@ -40,6 +40,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ +#include "plFileSystem.h" + class BitmapInfo; class Bitmap; class plBitmap; @@ -59,7 +61,7 @@ public: kClampV = 0x02 }; - const char *fileName; + plFileName fileName; uint32_t texFlags; uint32_t createFlags; float detailDropoffStart; @@ -76,7 +78,6 @@ public: plBitmapData() { - fileName = nil; texFlags = 0; createFlags = 0; detailDropoffStart = detailDropoffStop = 0.f; @@ -119,7 +120,7 @@ class plBitmapCreator plBitmap *ICreateTexture( plBitmapData *bd, const plLocation &loc, int clipID = -1 ); plMipmap *ICreateBitmap( plBitmapData *bd ); - void ICheckOutBitmap( BitmapInfo *bInfo, Bitmap *bm, const char *fileName ); + void ICheckOutBitmap( BitmapInfo *bInfo, Bitmap *bm, const plFileName &fileName ); int IResampBitmap( Bitmap *bm, plMipmap &hBitmap ); int ICopyBitmap( Bitmap *bm, plMipmap &hBitmap ); int IInvertAlpha( plMipmap &hBitmap ); diff --git a/Sources/Tools/MaxConvert/plLayerConverter.cpp b/Sources/Tools/MaxConvert/plLayerConverter.cpp index f69dbce5..0373606a 100644 --- a/Sources/Tools/MaxConvert/plLayerConverter.cpp +++ b/Sources/Tools/MaxConvert/plLayerConverter.cpp @@ -1062,7 +1062,7 @@ plLayer *plLayerConverter::IAssignTexture( plBitmapData *bd, plMaxNode *maxNode, { if( upperLayer ) { - if( fErrorMsg->Set( !( fWarned & kWarnedUpperTextureMissing ), "Plasma Export Error", sWarnUpperTextureMissing, maxNode->GetName(), bd->fileName ).CheckAskOrCancel() ) + if( fErrorMsg->Set( !( fWarned & kWarnedUpperTextureMissing ), "Plasma Export Error", sWarnUpperTextureMissing, maxNode->GetName(), bd->fileName.AsString().c_str() ).CheckAskOrCancel() ) fWarned |= kWarnedUpperTextureMissing; fErrorMsg->Set( false ); @@ -1071,7 +1071,7 @@ plLayer *plLayerConverter::IAssignTexture( plBitmapData *bd, plMaxNode *maxNode, } else { - if( fErrorMsg->Set( !( fWarned & kWarnedNoBaseTexture ), "Plasma Export Error", sWarnBaseTextureMissing, maxNode->GetName(), bd->fileName ).CheckAskOrCancel() ) + if( fErrorMsg->Set( !( fWarned & kWarnedNoBaseTexture ), "Plasma Export Error", sWarnBaseTextureMissing, maxNode->GetName(), bd->fileName.AsString().c_str() ).CheckAskOrCancel() ) fWarned |= kWarnedNoBaseTexture; fErrorMsg->Set( false ); diff --git a/Sources/Tools/MaxExport/Pch.h b/Sources/Tools/MaxExport/Pch.h index ea01e765..c58286d8 100644 --- a/Sources/Tools/MaxExport/Pch.h +++ b/Sources/Tools/MaxExport/Pch.h @@ -58,7 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsExceptionStack.h" #include "hsExceptions.h" -#include "plFile/plFileUtils.h" #include "hsStream.h" // Windows diff --git a/Sources/Tools/MaxExport/SimpleExport.cpp b/Sources/Tools/MaxExport/SimpleExport.cpp index 5e3a6256..8af0793e 100644 --- a/Sources/Tools/MaxExport/SimpleExport.cpp +++ b/Sources/Tools/MaxExport/SimpleExport.cpp @@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsExceptionStack.h" -#include "plFile/plFileUtils.h" #include "hsStream.h" #include @@ -319,19 +318,13 @@ int HSExport2::DoExport(const TCHAR *name,ExpInterface *ei,Interface *gi, BOOL s // We want to incorporate any SDL changes since the last export, so we DeInit() // and re-initialize. - char buf[MAX_PATH]; - strcpy(buf, plMaxConfig::GetClientPath()); - strcat(buf, "sdl"); - plSDLMgr::GetInstance()->SetSDLDir(buf); + plSDLMgr::GetInstance()->SetSDLDir(plFileName::Join(plMaxConfig::GetClientPath(), "sdl")); plSDLMgr::GetInstance()->DeInit(); plSDLMgr::GetInstance()->Init(); // Add disk source for writing - char datPath[MAX_PATH]; - strcpy(datPath, out_path); - plFileUtils::AddSlash(datPath); - strcat(datPath, "dat\\"); - CreateDirectory(datPath, NULL); + plFileName datPath = plFileName::Join(out_path, "dat"); + CreateDirectoryW(datPath.AsString().ToWchar(), NULL); plPluginResManager::ResMgr()->SetDataPath(datPath); if (hsgResMgr::Reset()) diff --git a/Sources/Tools/MaxExport/plExportDlg.cpp b/Sources/Tools/MaxExport/plExportDlg.cpp index f85605e8..53c221e6 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -58,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "MaxMain/resource.h" #include "MaxMain/plMaxCFGFile.h" #include "MaxMain/plMaxNode.h" +#include "plFileSystem.h" extern HINSTANCE hInstance; @@ -69,7 +70,7 @@ protected: bool fPhysicalsOnly; bool fLightMap; char fExportPage[256]; - char fExportSourceDir[MAX_PATH]; + plFileName fExportSourceDir; bool fExporting; bool fAutoExporting; bool fExportFile; @@ -108,30 +109,34 @@ public: plExportDlgImp::plExportDlgImp() : fDlg(NULL), fPreshade(true), fPhysicalsOnly(false), fLightMap(true), fLastExportTime(0), fExporting(false), fAutoExporting(false) { - const char* path = plMaxConfig::GetPluginIni(); - fXPos = GetPrivateProfileInt("Export", "X", 0, path); - fYPos = GetPrivateProfileInt("Export", "Y", 30, path); + plFileName path = plMaxConfig::GetPluginIni(); + fXPos = GetPrivateProfileIntW(L"Export", L"X", 0, path.AsString().ToWchar()); + fYPos = GetPrivateProfileIntW(L"Export", L"Y", 30, path.AsString().ToWchar()); - GetPrivateProfileString("Export", "Dir", "", fExportSourceDir, sizeof(fExportSourceDir), path); + wchar_t buffer[MAX_PATH]; + GetPrivateProfileStringW(L"Export", L"Dir", L"", buffer, sizeof(buffer), + path.AsString().ToWchar()); + fExportSourceDir = plString::FromWchar(buffer); memset(fExportPage, 0, sizeof(fExportPage)); } -BOOL WritePrivateProfileInt(LPCSTR lpAppName, LPCSTR lpKeyName, int val, LPCSTR lpFileName) +BOOL WritePrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, int val, LPCWSTR lpFileName) { - char buf[30]; - itoa(val, buf, 10); + wchar_t buf[12]; + snwprintf(buf, 12, L"%d", val); - return WritePrivateProfileString(lpAppName, lpKeyName, buf, lpFileName); + return WritePrivateProfileStringW(lpAppName, lpKeyName, buf, lpFileName); } plExportDlgImp::~plExportDlgImp() { - const char* path = plMaxConfig::GetPluginIni(); - WritePrivateProfileInt("Export", "X", fXPos, path); - WritePrivateProfileInt("Export", "Y", fYPos, path); + plFileName path = plMaxConfig::GetPluginIni(); + WritePrivateProfileIntW(L"Export", L"X", fXPos, path.AsString().ToWchar()); + WritePrivateProfileIntW(L"Export", L"Y", fYPos, path.AsString().ToWchar()); - WritePrivateProfileString("Export", "Dir", fExportSourceDir, path); + WritePrivateProfileStringW(L"Export", L"Dir", fExportSourceDir.AsString().ToWchar(), + path.AsString().ToWchar()); } plExportDlg& plExportDlg::Instance() @@ -185,8 +190,8 @@ void plExportDlgImp::IGetRadio(HWND hDlg) void plExportDlgImp::IInitDlg(HWND hDlg) { // Set the client path - const char* path = plMaxConfig::GetClientPath(false, true); - SetDlgItemText(hDlg, IDC_CLIENT_PATH, path); + plFileName path = plMaxConfig::GetClientPath(false, true); + SetDlgItemText(hDlg, IDC_CLIENT_PATH, path.AsString().c_str()); // Set the preshade button CheckDlgButton(hDlg, IDC_PRESHADE_CHECK, fPreshade ? BST_CHECKED : BST_UNCHECKED); @@ -232,7 +237,7 @@ void plExportDlgImp::IInitDlg(HWND hDlg) CheckRadioButton(hDlg, IDC_RADIO_FILE, IDC_RADIO_DIR, IDC_RADIO_FILE); IGetRadio(hDlg); - SetDlgItemText(hDlg, IDC_EXPORT_PATH, fExportSourceDir); + SetDlgItemTextW(hDlg, IDC_EXPORT_PATH, fExportSourceDir.AsString().ToWchar()); } #include "plFile/plBrowseFolder.h" @@ -280,9 +285,9 @@ BOOL plExportDlgImp::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) else if (resID == IDC_DIR) { // Get a new client path - const char* path = plMaxConfig::GetClientPath(true); - if (path) - SetDlgItemText(hDlg, IDC_CLIENT_PATH, path); + plFileName path = plMaxConfig::GetClientPath(true); + if (path.IsValid()) + SetDlgItemText(hDlg, IDC_CLIENT_PATH, path.AsString().c_str()); return TRUE; } else if (resID == IDC_RADIO_FILE || resID == IDC_RADIO_DIR) @@ -292,11 +297,10 @@ BOOL plExportDlgImp::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) } else if (resID == IDC_BROWSE_EXPORT) { - plBrowseFolder::GetFolder(fExportSourceDir, - fExportSourceDir, - "Choose the source directory", - hDlg); - SetDlgItemText(hDlg, IDC_EXPORT_PATH, fExportSourceDir); + fExportSourceDir = plBrowseFolder::GetFolder(fExportSourceDir, + "Choose the source directory", + hDlg); + SetDlgItemTextW(hDlg, IDC_EXPORT_PATH, fExportSourceDir.AsString().ToWchar()); return TRUE; } } @@ -347,7 +351,7 @@ void plExportDlgImp::IDoExport() IExportCurrentFile(exportPath); else { - hsFolderIterator sourceDir(fExportSourceDir); + hsFolderIterator sourceDir(fExportSourceDir.AsString().c_str()); while (sourceDir.NextFileSuffix(".max")) { char exportFile[MAX_PATH]; diff --git a/Sources/Tools/MaxMain/GlobalUtility.cpp b/Sources/Tools/MaxMain/GlobalUtility.cpp index a85c679b..9ffd9176 100644 --- a/Sources/Tools/MaxMain/GlobalUtility.cpp +++ b/Sources/Tools/MaxMain/GlobalUtility.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsResMgr.h" +#include "plFileSystem.h" #include "MaxComponent/plComponentBase.h" #include "plMaxNode.h" @@ -94,7 +95,7 @@ ClassDesc* GetGUPDesc() { return &PlasmaMaxCD; } ////////////////////////////////////////// // This function is from the console. This dummy version is here so that plNetLinkingMgr will build. -plKey FindSceneObjectByName(const char* name, const char* ageName, char* statusStr, bool subString) +plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString) { return nil; } @@ -221,16 +222,15 @@ DWORD PlasmaMax::Start() // Setup the localization mgr // Dirty hacks are because Cyan sucks... - const char* pathTemp = plMaxConfig::GetClientPath(false, true); - if (pathTemp == nil) + plFileName pathTemp = plMaxConfig::GetClientPath(false, true); + if (!pathTemp.IsValid()) { hsMessageBox("PlasmaMAX2.ini is missing or invalid", "Plasma/2.0 Error", hsMessageBoxNormal); - } - else + } + else { - std::string clientPath(pathTemp); - clientPath += "dat"; - pfLocalizationMgr::Initialize(clientPath.c_str()); + plFileName clientPath = plFileName::Join(pathTemp, "dat"); + pfLocalizationMgr::Initialize(clientPath); } return GUPRESULT_KEEP; diff --git a/Sources/Tools/MaxMain/main.cpp b/Sources/Tools/MaxMain/main.cpp index 3149eb35..d9082eba 100644 --- a/Sources/Tools/MaxMain/main.cpp +++ b/Sources/Tools/MaxMain/main.cpp @@ -168,16 +168,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) plPythonMgr::Instance().LoadPythonFiles(); - const char *clientPath = plMaxConfig::GetClientPath(false, true); - if (clientPath) + plFileName clientPath = plMaxConfig::GetClientPath(false, true); + if (clientPath.IsValid()) { - char oldCwd[kFolderIterator_MaxPath]; - _getcwd(oldCwd, sizeof(oldCwd)); - _chdir(clientPath); + plFileName oldCwd = plFileSystem::GetCWD(); + plFileSystem::SetCWD(clientPath); plSDLMgr::GetInstance()->Init(); - _chdir(oldCwd); + plFileSystem::SetCWD(oldCwd); } - + // Initialize the ResManager plResManager* pRmgr = new plPluginResManager; hsgResMgr::Init(pRmgr); diff --git a/Sources/Tools/MaxMain/plAgeDescInterface.cpp b/Sources/Tools/MaxMain/plAgeDescInterface.cpp index dc3c1688..61cdeed0 100644 --- a/Sources/Tools/MaxMain/plAgeDescInterface.cpp +++ b/Sources/Tools/MaxMain/plAgeDescInterface.cpp @@ -823,20 +823,19 @@ void plAgeDescInterface::IEnablePageControls(bool enable) EnableWindow(GetDlgItem(fhDlg, IDC_ADM_VOLATILE), enable); } -bool plAgeDescInterface::IGetLocalAgePath(char *path) +plFileName plAgeDescInterface::IGetLocalAgePath() { // Get the path to the description folder - const char *plasmaPath = plMaxConfig::GetClientPath(); - if (!plasmaPath) - return false; + plFileName plasmaPath = plMaxConfig::GetClientPath(); + if (!plasmaPath.IsValid()) + return ""; - strcpy(path, plasmaPath); - strcat(path, plAgeDescription::kAgeDescPath); + plFileName path = plFileName::Join(plasmaPath, plAgeDescription::kAgeDescPath); // Make sure the desc folder exists - CreateDirectory(path, NULL); + plFileSystem::CreateDir(path); - return true; + return path; } int plAgeDescInterface::IFindAge(const char* ageName, std::vector& ageFiles) @@ -856,10 +855,10 @@ void plAgeDescInterface::IGetAgeFiles(std::vector& ageFiles) // Make list of "local" ages. This might contain copies of those in AssetMan, so we make the // list first and take out the ones that are in AssetMan - char localPath[MAX_PATH]; - if (IGetLocalAgePath(localPath)) + plFileName localPath = IGetLocalAgePath(); + if (localPath.IsValid()) { - hsFolderIterator ageFolder(localPath); + hsFolderIterator ageFolder(localPath.AsString().c_str()); while (ageFolder.NextFileSuffix(".age")) { ageFolder.GetPathAndName(agePath); @@ -960,22 +959,25 @@ void plAgeDescInterface::IFillAgeTree( void ) BOOL CALLBACK NewAgeDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static char *name = nil; + static plString *name = nil; switch (msg) { case WM_INITDIALOG: - name = (char*)lParam; - SetWindowText(hDlg, name); + name = reinterpret_cast(lParam); + SetWindowText(hDlg, name->c_str()); return TRUE; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK) { - if (GetDlgItemText(hDlg, IDC_AGE_NAME, name, _MAX_FNAME) > 0) + char buffer[_MAX_FNAME]; + if (GetDlgItemText(hDlg, IDC_AGE_NAME, buffer, _MAX_FNAME) > 0) { EndDialog(hDlg, 1); - else + *name = buffer; + } else { EndDialog(hDlg, 0); + } return TRUE; } else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL) @@ -1008,7 +1010,7 @@ BOOL CALLBACK NewSeqNumberProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam case WM_INITDIALOG: SetDlgItemText( hDlg, IDC_INFOMSG, msg1 ); SetDlgItemText( hDlg, IDC_ADMMSG, msg2 ); - sprintf( msg3, "Age: %s", (char *)lParam ); + sprintf( msg3, "Age: %s", (const char *)lParam ); SetDlgItemText( hDlg, IDC_AGEMSG, msg3 ); return TRUE; @@ -1034,29 +1036,28 @@ void plAgeDescInterface::INewAge() makeAsset = false; #endif - char newAssetFilename[ MAX_PATH ]; + plFileName newAssetFilename; #ifdef MAXASS_AVAILABLE if (!fAssetManIface) makeAsset = false; #endif - if( !IGetLocalAgePath( newAssetFilename ) ) + newAssetFilename = IGetLocalAgePath(); + if (!newAssetFilename.IsValid()) return; - char name[_MAX_FNAME]; - strcpy(name, "New Age Name"); + plString name = "New Age Name"; // Get the name of the new age from the user int ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_AGE_NAME), GetCOREInterface()->GetMAXHWnd(), NewAgeDlgProc, - (LPARAM)name); + (LPARAM)&name); if (ret != 1) return; - strcat(newAssetFilename, name); - strcat(newAssetFilename, ".age"); + newAssetFilename = plFileName::Join(newAssetFilename, name + ".age"); #ifdef MAXASS_AVAILABLE if( !makeAsset ) @@ -1066,7 +1067,7 @@ void plAgeDescInterface::INewAge() fForceSeqNumLocal = false; if( makeAsset ) - (*fAssetManIface)->AddNewAsset(newAssetFilename); + (*fAssetManIface)->AddNewAsset(newAssetFilename.AsString().c_str()); #endif // Refresh the tree now @@ -1075,15 +1076,14 @@ void plAgeDescInterface::INewAge() void plAgeDescInterface::INewPage() { - char name[256]; - strcpy(name, "New Page Name"); + plString name = "New Page Name"; // Get the name of the new age from the user int ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_AGE_NAME), GetCOREInterface()->GetMAXHWnd(), NewAgeDlgProc, - (LPARAM)name); + (LPARAM)&name); if (ret != 1) return; @@ -1095,12 +1095,12 @@ void plAgeDescInterface::INewPage() { char pageName[256]; ListBox_GetText(hPages, i, pageName); - if (!strcmp(pageName, name)) + if (!name.CompareI(pageName)) return; } // Add the new page and select it - int idx = ListBox_AddString(hPages, name); + int idx = ListBox_AddString(hPages, name.c_str()); // Choose a new sequence suffix for it plAgePage *newPage = new plAgePage( name, IGetFreePageSeqSuffix( hPages ), 0 ); @@ -1131,7 +1131,7 @@ uint32_t plAgeDescInterface::IGetFreePageSeqSuffix( HWND pageCombo ) return searchSeq; } -void plAgeDescInterface::ISaveCurAge( const char *path, bool checkSeqNum ) +void plAgeDescInterface::ISaveCurAge( const plFileName &path, bool checkSeqNum ) { hsUNIXStream s; if( !s.Open( path, "wt" ) ) @@ -1197,7 +1197,7 @@ void plAgeDescInterface::ICheckSequenceNumber( plAgeDescription &aged ) // Ask about the sequence # int ret = DialogBoxParam( hInstance, MAKEINTRESOURCE( IDD_AGE_SEQNUM ), GetCOREInterface()->GetMAXHWnd(), - NewSeqNumberProc, (LPARAM)aged.GetAgeName() ); + NewSeqNumberProc, (LPARAM)aged.GetAgeName().c_str() ); if( ret == IDYES ) { aged.SetSequencePrefix( IGetNextFreeSequencePrefix( false ) ); @@ -1211,7 +1211,7 @@ void plAgeDescInterface::ICheckSequenceNumber( plAgeDescription &aged ) } } -void plAgeDescInterface::ILoadAge( const char *path, bool checkSeqNum ) +void plAgeDescInterface::ILoadAge( const plFileName &path, bool checkSeqNum ) { ISetControlDefaults(); @@ -1221,15 +1221,14 @@ void plAgeDescInterface::ILoadAge( const char *path, bool checkSeqNum ) plAgeDescription aged( path ); // Get the name of the age - char ageName[_MAX_FNAME]; - _splitpath( path, nil, nil, ageName, nil ); + plString ageName = path.GetFileNameNoExt(); // Check the sequence prefix # if( checkSeqNum ) ICheckSequenceNumber( aged ); char str[ _MAX_FNAME + 30 ]; - sprintf( str, "Description for %s", ageName ); + sprintf( str, "Description for %s", ageName.c_str() ); SetDlgItemText( fhDlg, IDC_AGEDESC, str ); // Set up the Dlgs @@ -1288,7 +1287,7 @@ void plAgeDescInterface::ILoadAge( const char *path, bool checkSeqNum ) HWND hPage = GetDlgItem(fhDlg, IDC_PAGE_LIST); while( ( page = aged.GetNextPage() ) != nil ) { - int idx = ListBox_AddString( hPage, page->GetName() ); + int idx = ListBox_AddString( hPage, page->GetName().c_str() ); ListBox_SetItemData( hPage, idx, (LPARAM)new plAgePage( *page ) ); } } diff --git a/Sources/Tools/MaxMain/plAgeDescInterface.h b/Sources/Tools/MaxMain/plAgeDescInterface.h index 96a81126..31bb4320 100644 --- a/Sources/Tools/MaxMain/plAgeDescInterface.h +++ b/Sources/Tools/MaxMain/plAgeDescInterface.h @@ -101,10 +101,10 @@ protected: // Save the settings for the last age and load the settings for the currently one void IUpdateCurAge(); - void ISaveCurAge( const char *path, bool checkSeqNum = false ); - void ILoadAge( const char *path, bool checkSeqNum = false ); + void ISaveCurAge( const plFileName &path, bool checkSeqNum = false ); + void ILoadAge( const plFileName &path, bool checkSeqNum = false ); - static bool IGetLocalAgePath(char *path); + static plFileName IGetLocalAgePath(); // Fill out the age tree view void IFillAgeTree( void ); diff --git a/Sources/Tools/MaxMain/plMaxCFGFile.cpp b/Sources/Tools/MaxMain/plMaxCFGFile.cpp index 69efae87..45c13d8f 100644 --- a/Sources/Tools/MaxMain/plMaxCFGFile.cpp +++ b/Sources/Tools/MaxMain/plMaxCFGFile.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsWindows.h" +#include "plFileSystem.h" #include #pragma hdrstop @@ -49,53 +50,42 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMaxCFGFile.h" #include "plFile/plBrowseFolder.h" -const char *plMaxConfig::GetPluginIni() +plFileName plMaxConfig::GetPluginIni() { // Get the plugin CFG dir - static char plugDir[MAX_PATH]; - strcpy(plugDir, GetCOREInterface()->GetDir(APP_PLUGCFG_DIR)); - strcat(plugDir, "\\PlasmaMAX2.ini"); - - return plugDir; + return plFileName::Join(GetCOREInterface()->GetDir(APP_PLUGCFG_DIR), "PlasmaMAX2.ini"); } -const char *plMaxConfig::GetClientPath(bool getNew, bool quiet) +plFileName plMaxConfig::GetClientPath(bool getNew, bool quiet) { - static char plasmaPath[MAX_PATH]; - plasmaPath[0] = '\0'; - // Get the plugin CFG dir - const char *plugDir = GetPluginIni(); + plFileName plugDir = GetPluginIni(); // Get the saved path - uint32_t len = GetPrivateProfileString("SceneViewer", "Directory", "", plasmaPath, MAX_PATH, plugDir); + wchar_t buffer[MAX_PATH]; + uint32_t len = GetPrivateProfileStringW(L"SceneViewer", L"Directory", L"", buffer, MAX_PATH, + plugDir.AsString().ToWchar()); + plFileName plasmaPath = plString::FromWchar(buffer); // If we didn't find a path, or we want a new one, ask the user for one if ((len == 0 || getNew) && !quiet) { // If the user selects one, save it - if (plBrowseFolder::GetFolder(plasmaPath, plasmaPath, "Specify your client folder")) - WritePrivateProfileString("SceneViewer", "Directory", plasmaPath, plugDir); + plasmaPath = plBrowseFolder::GetFolder(plasmaPath, "Specify your client folder"); + if (plasmaPath.IsValid()) + WritePrivateProfileStringW(L"SceneViewer", L"Directory", plasmaPath.AsString().ToWchar(), + plugDir.AsString().ToWchar()); } // Return the path if we got one - if (plasmaPath[0] != '\0') - { - // Make sure the path ends with a slash - char lastChar = plasmaPath[strlen(plasmaPath)-1]; - if (lastChar != '/' && lastChar != '\\') - strcat(plasmaPath, "\\"); - - return plasmaPath; - } - - return nil; + return plasmaPath; } -void plMaxConfig::SetClientPath(const char *path) +void plMaxConfig::SetClientPath(const plFileName &path) { - const char *plugDir = GetPluginIni(); - WritePrivateProfileString("SceneViewer", "Directory", path, plugDir); + plFileName plugDir = GetPluginIni(); + WritePrivateProfileStringW(L"SceneViewer", L"Directory", path.AsString().ToWchar(), + plugDir.AsString().ToWchar()); } bool plMaxConfig::AssetManInterfaceDisabled() @@ -105,13 +95,14 @@ bool plMaxConfig::AssetManInterfaceDisabled() if (!inited) { - char configstr[MAX_PATH]; + wchar_t configstr[MAX_PATH]; configstr[0] = '\0'; - - const char *plugDir = GetPluginIni(); - uint32_t len = GetPrivateProfileString("AssetMan", "Disable", "", configstr, MAX_PATH, plugDir); - if (strcmp(configstr, "1") == 0 || stricmp(configstr, "true") == 0) + plFileName plugDir = GetPluginIni(); + uint32_t len = GetPrivateProfileStringW(L"AssetMan", L"Disable", L"", configstr, MAX_PATH, + plugDir.AsString().ToWchar()); + + if (wcscmp(configstr, L"1") == 0 || wcsicmp(configstr, L"true") == 0) disabled = true; else disabled = false; diff --git a/Sources/Tools/MaxMain/plMaxCFGFile.h b/Sources/Tools/MaxMain/plMaxCFGFile.h index 4d9133ad..1d32dc9a 100644 --- a/Sources/Tools/MaxMain/plMaxCFGFile.h +++ b/Sources/Tools/MaxMain/plMaxCFGFile.h @@ -39,18 +39,21 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ + +class plFileName; + namespace plMaxConfig { // Get the full path to the ini file to write settings to - const char *GetPluginIni(); + plFileName GetPluginIni(); // Gets the path to the Plasma working directory // If the user hasn't set one before, it prompts them to // Set getNew to true to force the user to set a new path // If a path is returned, it will end with a slash - const char *GetClientPath(bool getNew=false, bool quiet=false); + plFileName GetClientPath(bool getNew=false, bool quiet=false); // For the rare case where you need to set the client path manually - void SetClientPath(const char *path); + void SetClientPath(const plFileName &path); // option to disable the plugin's assetman interface bool AssetManInterfaceDisabled(); diff --git a/Sources/Tools/MaxMain/plMaxMenu.cpp b/Sources/Tools/MaxMain/plMaxMenu.cpp index cb7b7d0b..a762c66d 100644 --- a/Sources/Tools/MaxMain/plMaxMenu.cpp +++ b/Sources/Tools/MaxMain/plMaxMenu.cpp @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnKeyedObject/plKey.h" #include "hsTemplates.h" #include "hsWindows.h" +#include "plFileSystem.h" #include #include @@ -324,7 +325,7 @@ void plCreateMenu() bool newlyRegistered = pMenuMan->RegisterMenuBarContext(kMyMenuContextId, kMenuName); // Is the Max menu version the most recent? - bool wrongVersion = GetPrivateProfileInt("Menu", "Version", 0, plMaxConfig::GetPluginIni()) < kMenuVersion; + bool wrongVersion = GetPrivateProfileIntW(L"Menu", L"Version", 0, plMaxConfig::GetPluginIni().AsString().ToWchar()) < kMenuVersion; if (wrongVersion) { // Delete the old version of the menu @@ -333,8 +334,9 @@ void plCreateMenu() pMenuMan->UnRegisterMenu(oldMenu); // Update the menu version - char buf[30]; - WritePrivateProfileString("Menu", "Version", itoa(kMenuVersion, buf, 10), plMaxConfig::GetPluginIni()); + wchar_t buf[12]; + snwprintf(buf, arrsize(buf), L"%d", kMenuVersion); + WritePrivateProfileStringW(L"Menu", L"Version", buf, plMaxConfig::GetPluginIni().AsString().ToWchar()); } if (wrongVersion || newlyRegistered) diff --git a/Sources/Tools/MaxMain/plPythonMgr.cpp b/Sources/Tools/MaxMain/plPythonMgr.cpp index 69207869..7158fe3e 100644 --- a/Sources/Tools/MaxMain/plPythonMgr.cpp +++ b/Sources/Tools/MaxMain/plPythonMgr.cpp @@ -600,22 +600,19 @@ void plPythonMgr::IAddGrassComponent(plAutoUIBlock *autoUI, PyObject *objTuple, void plPythonMgr::LoadPythonFiles() { - const char *clientPath = plMaxConfig::GetClientPath(false, true); - if (clientPath) + plFileName clientPath = plMaxConfig::GetClientPath(false, true); + if (clientPath.IsValid()) { - char oldCwd[MAX_PATH]; - _getcwd(oldCwd, sizeof(oldCwd)); - _chdir(clientPath); + plFileName oldCwd = plFileSystem::GetCWD(); + plFileSystem::SetCWD(clientPath); // Get the path to the Python subdirectory of the client - char pythonPath[MAX_PATH]; - strcpy(pythonPath, clientPath); - strcat(pythonPath, "Python"); + plFileName pythonPath = plFileName::Join(clientPath, "Python"); PythonInterface::initPython(); // Iterate through all the Python files in the folder - hsFolderIterator folder(pythonPath); + hsFolderIterator folder(pythonPath.AsString().c_str()); while (folder.NextFileSuffix(".py")) { // Get the filename without the ".py" (module name) @@ -628,7 +625,7 @@ void plPythonMgr::LoadPythonFiles() PythonInterface::finiPython(); - _chdir(oldCwd); + plFileSystem::SetCWD(oldCwd); } }