diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index a3d7ca34..57b1294b 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" @@ -84,7 +83,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfConsole/pfConsoleDirSrc.h" #include "plScene/plPageTreeMgr.h" #include "plScene/plVisMgr.h" -#include "plFile/hsFiles.h" #include "pfKI/pfKI.h" @@ -1636,19 +1634,17 @@ void plClient::IPatchGlobalAgeFiles( void ) void plClient::InitDLLs() { hsStatusMessage("Init dlls client\n"); - char str[255]; typedef void (*PInitGlobalsFunc) (hsResMgr *, plFactory *, plTimerCallbackManager *, plTimerShare*, plNetClientApp*); - hsFolderIterator modDllFolder("ModDLL\\"); - while (modDllFolder.NextFileSuffix(".dll")) + std::vector dlls = plFileSystem::ListDir("ModDLL", "*.dll"); + for (auto iter = dlls.begin(); iter != dlls.end(); ++iter) { - modDllFolder.GetPathAndName(str); - HMODULE hMod = LoadLibrary(str); + HMODULE hMod = LoadLibraryW(iter->AsString().ToWchar()); if (hMod) { PInitGlobalsFunc initGlobals = (PInitGlobalsFunc)GetProcAddress(hMod, "InitGlobals"); - initGlobals(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(), + (*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(), hsTimer::GetTheTimer(), plNetClientApp::GetInstance()); fLoadedDLLs.Append(hMod); } @@ -2496,7 +2492,7 @@ void plClient::IOnAsyncInitComplete () { // run fni in the Aux Init dir if (fpAuxInitDir) - { + { dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni"); // connect to net first dirSrc.ParseDirectory(fpAuxInitDir, "*.fni"); } diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 0575e6bc..a4c0e5a7 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; @@ -817,10 +816,10 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) // loaded the namePassHash from the file if (thePass.Compare(FAKE_PASS_STRING) != 0) { - wchar_t domain[15]; - PathSplitEmail(theUser.ToWchar(), nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0); + // Regex search for primary email domain + std::vector match = theUser.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+"); - if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) { + if (match.empty() || match[2].CompareI("gametap") == 0) { plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password); uint32_t* dest = reinterpret_cast(pLoginParam->namePassHash); const uint32_t* from = reinterpret_cast(shasum.GetValue()); 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/plFileEncrypt/main.cpp b/Sources/Plasma/Apps/plFileEncrypt/main.cpp index 0fc2b74b..502119f2 100644 --- a/Sources/Plasma/Apps/plFileEncrypt/main.cpp +++ b/Sources/Plasma/Apps/plFileEncrypt/main.cpp @@ -39,25 +39,25 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#include "plFile/hsFiles.h" #include "plFile/plEncryptedStream.h" #include "plProduct.h" -void EncryptFiles(const char* dir, const char* ext, bool encrypt); +void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt); void print_version() { - printf("%s\n\n", plProduct::ProductString().c_str()); + puts(plProduct::ProductString().c_str()); + puts(""); } void print_help() { - printf("plFileEncrypt - Encrypts and Decrypts Uru Files.\n\n"); + puts("plFileEncrypt - Encrypts and Decrypts Uru Files.\n"); print_version(); - printf("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]\n"); - printf("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n"); - printf("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n"); - printf("\t--help|-h|-?|/h\t - Prints Help. This Screen.\n"); - printf("\t-v|--version\t - Prints build version information\n"); + puts("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]"); + puts("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder."); + puts("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder."); + puts("\t--help|-h|-?|/h\t - Prints Help. This Screen."); + puts("\t-v|--version\t - Prints build version information"); } int main(int argc, char *argv[]) @@ -87,37 +87,34 @@ int main(int argc, char *argv[]) } else if (ARGCMP("-v") || ARGCMP("--version")) { - print_version(); + print_version(); return 0; } } #undef ARGCMP - EncryptFiles(dir, ".age", encrypt); - EncryptFiles(dir, ".fni", encrypt); - EncryptFiles(dir, ".ini", encrypt); - EncryptFiles(dir, ".sdl", encrypt); - EncryptFiles(dir, ".csv", encrypt); + EncryptFiles(dir, "*.age", encrypt); + EncryptFiles(dir, "*.fni", encrypt); + EncryptFiles(dir, "*.ini", encrypt); + EncryptFiles(dir, "*.sdl", encrypt); + EncryptFiles(dir, "*.csv", encrypt); return 0; } -void EncryptFiles(const char* dir, const char* ext, bool encrypt) +void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt) { - char filePath[256]; - - hsFolderIterator folder(dir); - while (folder.NextFileSuffix(ext)) + std::vector files = plFileSystem::ListDir(dir, ext); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - folder.GetPathAndName(filePath); if (encrypt) { - printf("encrypting: %s\n", folder.GetFileName()); - plEncryptedStream::FileEncrypt(filePath); + printf("encrypting: %s\n", iter->GetFileName().c_str()); + plEncryptedStream::FileEncrypt(*iter); } else { - printf("decrypting: %s\n", folder.GetFileName()); - plEncryptedStream::FileDecrypt(filePath); + printf("decrypting: %s\n", iter->GetFileName().c_str()); + plEncryptedStream::FileDecrypt(*iter); } } } diff --git a/Sources/Plasma/Apps/plFileSecure/main.cpp b/Sources/Plasma/Apps/plFileSecure/main.cpp index 8a2347da..bbe5fbda 100644 --- a/Sources/Plasma/Apps/plFileSecure/main.cpp +++ b/Sources/Plasma/Apps/plFileSecure/main.cpp @@ -39,8 +39,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plFile/plSecureStream.h" #include "plProduct.h" @@ -49,26 +47,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include void print_version() { - printf("%s\n\n", plProduct::ProductString().c_str()); + puts(plProduct::ProductString().c_str()); + puts(""); } void print_help() { - printf("plFileSecure - Secures Uru files and generates encryption.key files.\n\n"); + puts ("plFileSecure - Secures Uru files and generates encryption.key files.\n"); print_version(); - printf("Usage:\n"); - printf("\tplFileSecure ( )|[/generate /default]\n"); - printf("\n"); - printf(" : The directory and extension of files to secure. Cannot\n"); + puts ("Usage:"); + puts ("\tplFileSecure ( )|[/generate /default]"); + puts (""); + puts (" : The directory and extension of files to secure. Cannot"); printf(" be used with /generate. Uses the %s file in\n", plSecureStream::kKeyFilename); - printf(" the current directory (or default key if no file exists)\n"); + puts (" the current directory (or default key if no file exists)"); printf("/generate : Generates a random key and writes it to a %s\n", plSecureStream::kKeyFilename); - printf(" file in the current directory. Cannot be used with\n"); - printf(" \n"); + puts (" file in the current directory. Cannot be used with"); + puts (" "); printf("/default : If used with /generate, creates a %s file\n", plSecureStream::kKeyFilename); - printf(" with the default key. If used with , it\n"); - printf(" secures with the default key instead of the\n"); + puts (" with the default key. If used with , it"); + puts (" secures with the default key instead of the"); printf(" %s file's key\n", plSecureStream::kKeyFilename); - printf("\n"); + puts (""); } void GenerateKey(bool useDefault) @@ -106,16 +105,13 @@ void GenerateKey(bool useDefault) out.Close(); } -void SecureFiles(std::string dir, std::string ext, uint32_t* key) +void SecureFiles(const plFileName& dir, const plString& ext, uint32_t* key) { - char filePath[256]; - - hsFolderIterator folder(dir.c_str()); - while (folder.NextFileSuffix(ext.c_str())) + std::vector files = plFileSystem::ListDir(dir, ext.c_str()); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - folder.GetPathAndName(filePath); - printf("securing: %s\n", folder.GetFileName()); - plSecureStream::FileEncrypt(filePath, key); + printf("securing: %s\n", iter->GetFileName()); + plSecureStream::FileEncrypt(*iter, key); } } @@ -123,8 +119,8 @@ int main(int argc, char *argv[]) { bool generatingKey = false; bool useDefault = false; - std::string directory; - std::string ext; + plFileName directory; + plString ext; if (argc > 1) { @@ -164,9 +160,9 @@ int main(int argc, char *argv[]) else { // else it is a directory or extension - if (directory == "") + if (!directory.IsValid()) directory = argv[i]; - else if (ext == "") + else if (ext.IsEmpty()) ext = argv[i]; else { @@ -176,7 +172,7 @@ int main(int argc, char *argv[]) } } - if (generatingKey && ((directory != "") || (ext != ""))) + if (generatingKey && ((directory.IsValid()) || (!ext.IsEmpty()))) { print_help(); return 0; @@ -194,8 +190,11 @@ int main(int argc, char *argv[]) return 0; } - if (ext[0] != '.') - ext = "." + ext; // tack on the dot if necessary + // Make sure ext is a real pattern, or we won't find anything + if (ext.CharAt(0) == '.') + ext = "*" + ext; + else if (ext.CharAt(0) != '*') + ext = "*." + ext; if (useDefault) SecureFiles(directory, ext, nil); diff --git a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp index 46084506..945a15d6 100644 --- a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp +++ b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp @@ -41,8 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "hsTimer.h" -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plResMgr/plResManager.h" #include "plResMgr/plResMgrSettings.h" @@ -61,7 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com plResManager* gResMgr = nil; -bool DumpStats(const char* patchDir); +bool DumpStats(const plFileName& patchDir); bool DumpSounds(); //// PrintVersion /////////////////////////////////////////////////////////////// @@ -117,7 +115,7 @@ int main(int argc, char* argv[]) } // Make sure we have 1 arg left after getting the options - char* pageFile = nil; + plFileName pageFile; if (arg < argc) pageFile = argv[arg]; else @@ -134,12 +132,7 @@ int main(int argc, char* argv[]) if (sounds) DumpSounds(); if (stats) - { - char path[256]; - strcpy(path, pageFile); - plFileUtils::StripFile(path); - DumpStats(path); - } + DumpStats(pageFile.StripFileName()); hsgResMgr::Shutdown(); @@ -180,12 +173,12 @@ bool DumpSounds() buffer->GetKey()->RefObject(); // Get the filename from it and add that file if necessary - const char* filename = buffer->GetFileName(); - if (filename) + plFileName filename = buffer->GetFileName(); + if (filename.IsValid()) { uint32_t flags = 0; - if (stricmp(plFileUtils::GetFileExt(filename), "wav") != 0) + if (filename.GetFileExt().CompareI("wav") != 0) { if (buffer->HasFlag(plSoundBuffer::kOnlyLeftChannel) || buffer->HasFlag(plSoundBuffer::kOnlyRightChannel)) @@ -196,9 +189,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 +211,11 @@ bool DumpSounds() class plStatDumpIterator : public plRegistryPageIterator, public plRegistryKeyIterator { protected: - const char* fOutputDir; + plFileName fOutputDir; hsUNIXStream fStream; public: - plStatDumpIterator(const char* outputDir) : fOutputDir(outputDir) {} + plStatDumpIterator(const plFileName& outputDir) : fOutputDir(outputDir) {} bool EatKey(const plKey& key) { @@ -246,8 +239,8 @@ public: { const plPageInfo& info = page->GetPageInfo(); - char fileName[256]; - sprintf(fileName, "%s%s_%s.csv", fOutputDir, info.GetAge().c_str(), info.GetPage().c_str()); + plFileName fileName = plFileName::Join(fOutputDir, + plString::Format("%s_%s.csv", info.GetAge().c_str(), info.GetPage().c_str())); fStream.Open(fileName, "wt"); page->LoadKeys(); @@ -259,7 +252,7 @@ public: } }; -bool DumpStats(const char* patchDir) +bool DumpStats(const plFileName& patchDir) { plStatDumpIterator statDump(patchDir); gResMgr->IterateAllPages(&statDump); 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/plPythonPack/PythonInterface.cpp b/Sources/Plasma/Apps/plPythonPack/PythonInterface.cpp index fea64c96..b0449f71 100644 --- a/Sources/Plasma/Apps/plPythonPack/PythonInterface.cpp +++ b/Sources/Plasma/Apps/plPythonPack/PythonInterface.cpp @@ -45,10 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "eval.h" #include "marshal.h" #include "cStringIO.h" +#include "plFileSystem.h" static PyObject* stdFile; // python object of the stdout and err file -void PythonInterface::initPython(std::string rootDir) +void PythonInterface::initPython(const plFileName& rootDir) { // if haven't been initialized then do it if ( Py_IsInitialized() == 0 ) @@ -77,27 +78,27 @@ void PythonInterface::initPython(std::string rootDir) PyObject* sys_dict = PyModule_GetDict(sysmod); if (stdFile != nil) { - PyDict_SetItemString(sys_dict,"stdout", stdFile); - PyDict_SetItemString(sys_dict,"stderr", stdFile); + PyDict_SetItemString(sys_dict, "stdout", stdFile); + PyDict_SetItemString(sys_dict, "stderr", stdFile); } // NOTE: we will reset the path to not include paths // ...that Python may have found in the registery PyObject* path_list = PyList_New(0); printf("Setting up include dirs:\n"); - printf("%s\n",rootDir.c_str()); - PyObject* more_path = PyString_FromString(rootDir.c_str()); + printf("%s\n", rootDir.AsString().c_str()); + PyObject* more_path = PyString_FromString(rootDir.AsString().c_str()); PyList_Append(path_list, more_path); // make sure that our plasma libraries are gotten before the system ones - std::string temp = rootDir + "plasma"; - printf("%s\n",temp.c_str()); - PyObject* more_path3 = PyString_FromString(temp.c_str()); + plFileName temp = plFileName::Join(rootDir, "plasma"); + printf("%s\n", temp.AsString().c_str()); + PyObject* more_path3 = PyString_FromString(temp.AsString().c_str()); PyList_Append(path_list, more_path3); - temp = rootDir + "system"; - printf("%s\n\n",temp.c_str()); + temp = plFileName::Join(rootDir, "system"); + printf("%s\n\n", temp.AsString().c_str()); PyObject* more_path2 = PyString_FromString("system"); PyList_Append(path_list, more_path2); // set the path to be this one - PyDict_SetItemString(sys_dict,"path",path_list); + PyDict_SetItemString(sys_dict, "path", path_list); Py_DECREF(sysmod); @@ -106,7 +107,7 @@ void PythonInterface::initPython(std::string rootDir) // initialized++; } -void PythonInterface::addPythonPath(std::string path) +void PythonInterface::addPythonPath(const plFileName& path) { PyObject* sysmod = PyImport_ImportModule("sys"); if (sysmod != NULL) @@ -114,8 +115,8 @@ void PythonInterface::addPythonPath(std::string path) PyObject* sys_dict = PyModule_GetDict(sysmod); PyObject* path_list = PyDict_GetItemString(sys_dict, "path"); - printf("Adding path %s\n", path.c_str()); - PyObject* more_path = PyString_FromString(path.c_str()); + printf("Adding path %s\n", path.AsString().c_str()); + PyObject* more_path = PyString_FromString(path.AsString().c_str()); PyList_Append(path_list, more_path); Py_DECREF(sysmod); @@ -138,9 +139,9 @@ void PythonInterface::finiPython() // // PURPOSE : run a python string in a specific module name // -PyObject* PythonInterface::CompileString(const char *command, const char* filename) +PyObject* PythonInterface::CompileString(const char *command, const plFileName& filename) { - PyObject* pycode = Py_CompileString(command, filename, Py_file_input); + PyObject* pycode = Py_CompileString(command, filename.AsString().c_str(), Py_file_input); return pycode; } diff --git a/Sources/Plasma/Apps/plPythonPack/PythonInterface.h b/Sources/Plasma/Apps/plPythonPack/PythonInterface.h index dcf17f52..edce7ace 100644 --- a/Sources/Plasma/Apps/plPythonPack/PythonInterface.h +++ b/Sources/Plasma/Apps/plPythonPack/PythonInterface.h @@ -44,14 +44,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include +class plFileName; + namespace PythonInterface { - void initPython(std::string rootDir); + void initPython(const plFileName& rootDir); void finiPython(); // So the Python packer can add extra paths - void addPythonPath(std::string dir); + void addPythonPath(const plFileName& dir); - PyObject* CompileString(const char *command, const char* filename); + PyObject* CompileString(const char *command, const plFileName& filename); bool DumpObject(PyObject* pyobj, char** pickle, int32_t* size); int getOutputAndReset(char** line=nil); PyObject* CreateModule(const char* module); diff --git a/Sources/Plasma/Apps/plPythonPack/main.cpp b/Sources/Plasma/Apps/plPythonPack/main.cpp index e2df0ca2..6498aea6 100644 --- a/Sources/Plasma/Apps/plPythonPack/main.cpp +++ b/Sources/Plasma/Apps/plPythonPack/main.cpp @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "PythonInterface.h" #include "hsStream.h" -#include "plFile/hsFiles.h" #include #include @@ -71,25 +70,24 @@ static const char* kPackFileName = "python.pak"; #endif static char* glueFile = (char*)kGlueFile; -void WritePythonFile(std::string fileName, std::string path, hsStream *s) +void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStream *s) { hsUNIXStream pyStream, glueStream; - std::string filePath; - size_t filestart = fileName.find_last_of('.'); - if(filestart != std::string::npos) - filePath = fileName.substr(filestart+1, std::string::npos); + plFileName filePath; + size_t filestart = fileName.AsString().FindLast('.'); + if (filestart >= 0) + filePath = fileName.AsString().Substr(filestart+1); else filePath = fileName; - filePath += ".py"; - filePath = path + filePath; + filePath = plFileName::Join(path, filePath + ".py"); - if (!pyStream.Open(filePath.c_str()) || !glueStream.Open(glueFile)) + if (!pyStream.Open(filePath) || !glueStream.Open(glueFile)) { - printf("Unable to open path %s, ",filePath.c_str()); + printf("Unable to open path %s, ", filePath.AsString().c_str()); return; } - printf("==Packing %s, ",fileName.c_str()); + printf("==Packing %s, ", fileName.AsString().c_str()); pyStream.FastFwd(); uint32_t pyFileSize = pyStream.GetPosition(); @@ -124,20 +122,20 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s) } // import the module first, to make packages work correctly - PyImport_ImportModule(fileName.c_str()); - PyObject* pythonCode = PythonInterface::CompileString(code, fileName.c_str()); + PyImport_ImportModule(fileName.AsString().c_str()); + PyObject* pythonCode = PythonInterface::CompileString(code, fileName); if (pythonCode) { // we need to find out if this is PythonFile module // create a module name... with the '.' as an X // and create a python file name that is without the ".py" - PyObject* fModule = PythonInterface::CreateModule(fileName.c_str()); + PyObject* fModule = PythonInterface::CreateModule(fileName.AsString().c_str()); // run the code if (PythonInterface::RunPYC(pythonCode, fModule) ) { // set the name of the file (in the global dictionary of the module) PyObject* dict = PyModule_GetDict(fModule); - PyObject* pfilename = PyString_FromString(fileName.c_str()); + PyObject* pfilename = PyString_FromString(fileName.AsString().c_str()); PyDict_SetItemString(dict, "glue_name", pfilename); // next we need to: // - create instance of class @@ -167,7 +165,7 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s) // else // skip the CRs } - pythonCode = PythonInterface::CompileString(code, fileName.c_str()); + pythonCode = PythonInterface::CompileString(code, fileName); hsAssert(pythonCode,"Not sure why this didn't compile the second time???"); printf("an import file "); } @@ -227,23 +225,15 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s) glueStream.Close(); } -void FindFiles(std::vector &filenames, std::vector &pathnames, const char* path) +void FindFiles(std::vector &filenames, std::vector &pathnames, const plFileName& path) { // Get the names of all the python files - hsFolderIterator folder; + std::vector pys = plFileSystem::ListDir(path, "*.py"); - // if there is a path... set it - if ( path ) - folder.SetPath(path); - - while (folder.NextFileSuffix(".py")) + for (auto iter = pys.begin(); iter != pys.end(); ++iter) { - const char *fileName = folder.GetFileName(); - filenames.push_back(fileName); - if ( path ) - pathnames.push_back(path); - else - pathnames.push_back(""); + filenames.push_back(iter->GetFileName()); + pathnames.push_back(path); } } @@ -260,22 +250,13 @@ std::string ToLowerCase(std::string str) return retVal; } -void FindSubDirs(std::vector &dirnames, const char *path) +void FindSubDirs(std::vector &dirnames, const plFileName &path) { - hsFolderIterator folder; - if (path) - folder.SetPath(path); - - while (folder.NextFile()) - { - if (folder.IsDirectory()) - { - std::string dirName = folder.GetFileName(); - if ((dirName != ".")&&(dirName != "..")&&(ToLowerCase(dirName) != "system") && (ToLowerCase(dirName) != "plasma")) - { - dirnames.push_back(dirName); - } - } + std::vector subdirs = plFileSystem::ListSubdirs(path); + for (auto iter = subdirs.begin(); iter != subdirs.end(); ++iter) { + plString name = iter->GetFileName(); + if (name.CompareI("system") != 0 && name.CompareI("plasma") != 0) + dirnames.push_back(name); } } @@ -343,66 +324,62 @@ std::string ConcatDirs(std::string fullPath, std::string partialPath) return retVal; } -void FindPackages(std::vector& fileNames, std::vector& pathNames, const char* path, std::string parent_package="") +void FindPackages(std::vector& fileNames, std::vector& pathNames, const plFileName& path, const plString& parent_package="") { - std::vector packages; + std::vector packages; FindSubDirs(packages, path); for (int i = 0; i < packages.size(); i++) { - std::string packageName; - if(!parent_package.empty()) + plString packageName; + if (!parent_package.IsEmpty()) packageName = parent_package + "."; - packageName += packages[i]; - std::vector packageFileNames; - std::vector packagePathNames; - std::string packagePath = path; - packagePath += "/" + packages[i]; - FindFiles(packageFileNames, packagePathNames, packagePath.c_str()); + packageName += packages[i].AsString(); + std::vector packageFileNames; + std::vector packagePathNames; + plFileName packagePath = plFileName::Join(path, packages[i]); + FindFiles(packageFileNames, packagePathNames, packagePath); for (int j = 0; j < packageFileNames.size(); j++) { - fileNames.push_back(packageName+"."+packageFileNames[j]); - pathNames.push_back(packagePathNames[j]+"/"); + fileNames.push_back(packageName+"."+packageFileNames[j].AsString()); + pathNames.push_back(packagePathNames[j]); } - FindPackages(fileNames, pathNames, packagePath.c_str(), packageName); + FindPackages(fileNames, pathNames, packagePath, packageName); } } -void PackDirectory(std::string dir, std::string rootPath, std::string pakName, std::vector& extraDirs, bool packSysAndPlasma = false) +void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector& extraDirs, bool packSysAndPlasma = false) { - // make sure the dir ends in a slash - dir = AdjustEndingSlash(dir,true); - - printf("\nCreating %s using the contents of %s\n",pakName.c_str(),dir.c_str()); - printf("Changing working directory to %s\n",rootPath.c_str()); - if (chdir(rootPath.c_str())) + printf("\nCreating %s using the contents of %s\n", pakName.AsString().c_str(), dir.AsString().c_str()); + printf("Changing working directory to %s\n", rootPath.AsString().c_str()); + if (!plFileSystem::SetCWD(rootPath)) { - printf("ERROR: Directory change to %s failed for some reason\n",rootPath.c_str()); + printf("ERROR: Directory change to %s failed for some reason\n", rootPath.AsString().c_str()); printf("Unable to continue with the packing of this directory, aborting...\n"); return; } else - printf("Directory changed to %s\n",rootPath.c_str()); + printf("Directory changed to %s\n", rootPath.AsString().c_str()); - std::vector fileNames; - std::vector pathNames; + std::vector fileNames; + std::vector pathNames; - FindFiles(fileNames,pathNames,dir.c_str()); - FindPackages(fileNames,pathNames,dir.c_str()); + FindFiles(fileNames, pathNames, dir); + FindPackages(fileNames, pathNames, dir); if (packSysAndPlasma) { printf("Adding the system and plasma directories to this pack file\n"); - std::string tempPath; - tempPath = dir + "system/"; - FindFiles(fileNames,pathNames,tempPath.c_str()); - FindPackages(fileNames,pathNames,tempPath.c_str()); - tempPath = dir + "plasma/"; - FindFiles(fileNames,pathNames,tempPath.c_str()); - FindPackages(fileNames,pathNames,tempPath.c_str()); + plFileName tempPath; + tempPath = plFileName::Join(dir, "system"); + FindFiles(fileNames, pathNames, tempPath); + FindPackages(fileNames, pathNames, tempPath); + tempPath = plFileName::Join(dir, "plasma"); + FindFiles(fileNames, pathNames, tempPath); + FindPackages(fileNames, pathNames, tempPath); } // ok, we know how many files we're gonna pack, so make a fake index (we'll fill in later) hsUNIXStream s; - if (!s.Open(pakName.c_str(), "wb")) + if (!s.Open(pakName, "wb")) return; s.WriteLE32(fileNames.size()); @@ -410,13 +387,13 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s int i; for (i = 0; i < fileNames.size(); i++) { - s.WriteSafeString(fileNames[i].c_str()); + s.WriteSafeString(fileNames[i].AsString()); s.WriteLE32(0); } PythonInterface::initPython(rootPath); for (i = 0; i < extraDirs.size(); i++) - PythonInterface::addPythonPath(rootPath + extraDirs[i]); + PythonInterface::addPythonPath(plFileName::Join(rootPath, extraDirs[i])); // set to maximum optimization (includes removing __doc__ strings) Py_OptimizeFlag = 2; @@ -427,7 +404,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s for (i = 0; i < fileNames.size(); i++) { // strip '.py' from the file name - std::string properFileName = fileNames[i].substr(0, fileNames[i].size()-3); + plFileName properFileName = fileNames[i].StripFileExt(); uint32_t initialPos = s.GetPosition(); WritePythonFile(properFileName, pathNames[i], &s); uint32_t endPos = s.GetPosition(); @@ -438,7 +415,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s s.SetPosition(sizeof(uint32_t)); for (i = 0; i < fileNames.size(); i++) { - s.WriteSafeString(fileNames[i].c_str()); + s.WriteSafeString(fileNames[i].AsString()); s.WriteLE32(filePositions[i]); } @@ -459,9 +436,7 @@ int main(int argc, char *argv[]) { printf("The Python Pack Utility\n"); - char buffer[MAXPATHLEN]; - getcwd(buffer, MAXPATHLEN); - std::string baseWorkingDir = buffer; + plFileName baseWorkingDir = plFileSystem::GetCWD(); // are they asking for usage? if (argc == 2) @@ -482,26 +457,25 @@ int main(int argc, char *argv[]) return -1; } - std::vector dirNames; - std::string rootPath; + std::vector dirNames; + plFileName rootPath; if (argc == 1) { - FindSubDirs(dirNames,nil); - rootPath = AdjustEndingSlash(baseWorkingDir,true); + FindSubDirs(dirNames, ""); + rootPath = baseWorkingDir; } else { - std::string path = argv[1]; - FindSubDirs(dirNames,argv[1]); - rootPath = ConcatDirs(baseWorkingDir,path); - rootPath = AdjustEndingSlash(rootPath,true); + plFileName path = argv[1]; + FindSubDirs(dirNames, argv[1]); + rootPath = plFileName::Join(baseWorkingDir, path); } - - PackDirectory(rootPath,rootPath,rootPath+kPackFileName,dirNames,true); + + PackDirectory(rootPath, rootPath, plFileName::Join(rootPath, kPackFileName), dirNames, true); for (int i=0; i #pragma hdrstop @@ -128,7 +129,7 @@ static hsSemaphore s_dialogCreateEvent(0); static hsMutex s_critsect; static LISTDECL(WndEvent, link) s_eventQ; static hsSemaphore s_shutdownEvent(0); -static wchar_t s_workingDir[MAX_PATH]; +static plFileName s_workingDir; static hsSemaphore s_statusEvent(0); static char s_curlError[CURL_ERROR_SIZE]; @@ -601,7 +602,7 @@ static const CmdArgDef s_cmdLineArgs[] = { PF_CONSOLE_LINK_FILE(Core) //============================================================================ -int __stdcall WinMain ( +int __stdcall WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, @@ -619,26 +620,23 @@ 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; } CCmdParser cmdParser(s_cmdLineArgs, arrsize(s_cmdLineArgs)); cmdParser.Parse(); - + if (!cmdParser.IsSpecified(kArgCwd)) - PathGetProgramDirectory(s_workingDir, arrsize(s_workingDir)); + s_workingDir = plFileSystem::GetCurrentAppPath().StripFileName(); s_hInstance = hInstance; memset(&s_launcherInfo, 0, sizeof(s_launcherInfo)); @@ -683,12 +681,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 +699,7 @@ int __stdcall WinMain ( // Wait for the other process to exit Sleep(1000); - if (!plFileUtils::RemoveFile(newPatcherFile)) { + if (!plFileSystem::Unlink(newPatcherFile)) { wchar_t error[256]; DWORD errorCode = GetLastError(); wchar_t *msg = TranslateErrorCode(errorCode); @@ -711,7 +709,7 @@ int __stdcall WinMain ( LocalFree(msg); break; } - if (!plFileUtils::FileMove(curPatcherFile, newPatcherFile)) { + if (!plFileSystem::Move(curPatcherFile, newPatcherFile)) { wchar_t error[256]; DWORD errorCode = GetLastError(); wchar_t *msg = TranslateErrorCode(errorCode); @@ -719,7 +717,7 @@ int __stdcall WinMain ( StrPrintf(error, arrsize(error), L"Failed to replace old patcher executable. %s", msg); MessageBoxW(GetTopWindow(nil), error, L"Error", MB_OK); // attempt to clean up this tmp file - plFileUtils::RemoveFile(curPatcherFile); + plFileSystem::Unlink(curPatcherFile); LocalFree(msg); break; } @@ -732,7 +730,7 @@ int __stdcall WinMain ( si.cb = sizeof(si); wchar_t cmdline[MAX_PATH]; - StrPrintf(cmdline, arrsize(cmdline), L"%s %s", newPatcherFile, s_launcherInfo.cmdLine); + StrPrintf(cmdline, arrsize(cmdline), L"%S %s", newPatcherFile.AsString().c_str(), s_launcherInfo.cmdLine); // we have only successfully patched if we actually launch the new version of the patcher (void)CreateProcessW( @@ -757,13 +755,11 @@ int __stdcall WinMain ( } // Clean up old temp files - ARRAY(PathFind) paths; - wchar_t fileSpec[MAX_PATH]; - PathGetProgramDirectory(fileSpec, arrsize(fileSpec)); - PathAddFilename(fileSpec, fileSpec, L"*.tmp", arrsize(fileSpec)); - PathFindFiles(&paths, fileSpec, kPathFlagFile); - for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path) - plFileUtils::RemoveFile(path->name); + plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName(); + std::vector tmpFiles = plFileSystem::ListDir(fileSpec, "*.tmp"); + std::for_each(tmpFiles.begin(), tmpFiles.end(), [](const plFileName &tmp) { + plFileSystem::Unlink(tmp); + }); SetConsoleCtrlHandler(CtrlHandler, TRUE); InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server @@ -772,7 +768,7 @@ int __stdcall WinMain ( ENetError selfPatchResult; if (false == (SelfPatch(cmdParser.IsSpecified(kArgNoSelfPatch), &s_shutdown, &selfPatchResult, &s_launcherInfo)) && IS_NET_SUCCESS(selfPatchResult)) { // We didn't self-patch, so check for client updates and download them, then exec the client - StrCopy(s_launcherInfo.path, s_workingDir, arrsize(s_launcherInfo.path)); + StrCopy(s_launcherInfo.path, s_workingDir.AsString().ToWchar(), arrsize(s_launcherInfo.path)); s_launcherInfo.prepCallback = PrepCallback; s_launcherInfo.initCallback = InitCallback; s_launcherInfo.startCallback = StartCallback; 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/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index ac0e6975..d6817cb8 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -440,6 +440,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wch # include # define MAX_PATH PATH_MAX #endif +#define MAX_EXT (256) // Useful floating point utilities inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); } diff --git a/Sources/Plasma/CoreLib/plFileSystem.cpp b/Sources/Plasma/CoreLib/plFileSystem.cpp index f0dfcd9a..9c1ac1ff 100644 --- a/Sources/Plasma/CoreLib/plFileSystem.cpp +++ b/Sources/Plasma/CoreLib/plFileSystem.cpp @@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ +#include "HeadSpin.h" #include "plFileSystem.h" #if HS_BUILD_FOR_WIN32 @@ -49,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # include # include # include +# include +# include # include # include # include @@ -250,6 +253,15 @@ plFileName plFileSystem::GetCWD() return cwd; } +bool plFileSystem::SetCWD(const plFileName &cwd) +{ +#if HS_BUILD_FOR_WIN32 + return SetCurrentDirectoryW(cwd.AsString().ToWchar()); +#else + return (chdir(cwd.AsString().c_str()) == 0); +#endif +} + FILE *plFileSystem::Open(const plFileName &filename, const char *mode) { #if HS_BUILD_FOR_WIN32 @@ -273,8 +285,11 @@ FILE *plFileSystem::Open(const plFileName &filename, const char *mode) bool plFileSystem::Unlink(const plFileName &filename) { #if HS_BUILD_FOR_WIN32 - return _wunlink(filename.AsString().ToWchar()) == 0; + plStringBuffer wfilename = filename.AsString().ToWchar(); + _wchmod(wfilename, S_IWRITE); + return _wunlink(wfilename) == 0; #else + chmod(filename.AsString().c_str(), S_IWRITE); return unlink(filename.AsString().c_str()) == 0; #endif } @@ -282,7 +297,8 @@ bool plFileSystem::Unlink(const plFileName &filename) bool plFileSystem::Move(const plFileName &from, const plFileName &to) { #if HS_BUILD_FOR_WIN32 - return MoveFileW(from.AsString().ToWchar(), to.AsString().ToWchar()); + return MoveFileExW(from.AsString().ToWchar(), to.AsString().ToWchar(), + MOVEFILE_REPLACE_EXISTING); #else if (!Copy(from, to)) return false; @@ -333,6 +349,95 @@ bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents) #endif } +std::vector plFileSystem::ListDir(const plFileName &path, const char *pattern) +{ + std::vector contents; + +#if HS_BUILD_FOR_WIN32 + if (!pattern || !pattern[0]) + pattern = "*"; + plFileName searchPattern = plFileName::Join(path, pattern); + + WIN32_FIND_DATAW findData; + HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData); + if (hFind == INVALID_HANDLE_VALUE) + return contents; + + do { + if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + // Should also handle . and .. + continue; + } + + contents.push_back(plFileName::Join(path, plString::FromWchar(findData.cFileName))); + } while (FindNextFileW(hFind, &findData)); + + FindClose(hFind); +#else + DIR *dir = opendir(path.AsString().c_str()); + if (!dir) + return contents; + + struct dirent *de; + while (de = readdir(dir)) { + if (plFileInfo(de->d_name).IsDirectory()) { + // Should also handle . and .. + continue; + } + + if (pattern && pattern[0] && fnmatch(pattern, de->d_name)) + contents.push_back(plFileName::Join(path, de->d_name)); + else if (!pattern || !pattern[0]) + contents.push_back(plFileName::Join(path, de->d_name)); + } + + closedir(dir); +#endif + + return contents; +} + +std::vector plFileSystem::ListSubdirs(const plFileName &path) +{ + std::vector contents; + +#if HS_BUILD_FOR_WIN32 + plFileName searchPattern = plFileName::Join(path, "*"); + + WIN32_FIND_DATAW findData; + HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData); + if (hFind == INVALID_HANDLE_VALUE) + return contents; + + do { + if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + plFileName name = plString::FromWchar(findData.cFileName); + if (name != "." && name != "..") + contents.push_back(plFileName::Join(path, name)); + } + } while (FindNextFileW(hFind, &findData)); + + FindClose(hFind); +#else + DIR *dir = opendir(path.AsString().c_str()); + if (!dir) + return contents; + + struct dirent *de; + while (de = readdir(dir)) { + if (plFileInfo(de->d_name).IsDirectory()) { + plFileName name = de->d_name; + if (name != "." && name != "..") + contents.push_back(plFileName::Join(path, name); + } + } + + closedir(dir); +#endif + + return contents; +} + plFileName plFileSystem::GetUserDataPath() { static plFileName _userData; @@ -366,3 +471,93 @@ plFileName plFileSystem::GetLogPath() plFileSystem::CreateDir(_logPath); return _logPath; } + +#if !HS_BUILD_FOR_WIN32 +static plFileName _CheckReadlink(const char *link_path) +{ + plFileInfo info(link_path); + if (info.Exists()) { + char *path = new char[info.FileSize()]; + readlink(link_path, path, info.FileSize()); + plFileName appPath = plString::FromUtf8(path, info.FileSize()); + delete [] path; + return appPath; + } + + return ""; +} +#endif + +plFileName plFileSystem::GetCurrentAppPath() +{ + plFileName appPath; + + // Neither OS makes this one simple... +#if HS_BUILD_FOR_WIN32 + wchar_t path[MAX_PATH]; + size_t size = GetModuleFileNameW(nullptr, path, MAX_PATH); + if (size >= MAX_PATH) { + // Buffer not big enough + size_t bigger = MAX_PATH; + do { + bigger *= 2; + wchar_t *path_lg = new wchar_t[bigger]; + size = GetModuleFileNameW(nullptr, path_lg, bigger); + if (size < bigger) + appPath = plString::FromWchar(path_lg); + delete [] path_lg; + } while (!appPath.IsValid()); + } else { + appPath = plString::FromWchar(path); + } + + return appPath; +#else + // Look for /proc/self/exe (Linux), /proc/curproc/file (FreeBSD / Mac), + // then /proc/self/path/a.out (Solaris). If none were found, you're SOL + appPath = _CheckReadlink("/proc/self/exe"); + if (appPath.IsValid()) + return appPath; + + appPath = _CheckReadlink("/proc/curproc/file"); + if (appPath.IsValid()) + return appPath; + + appPath = _CheckReadlink("/proc/self/path/a.out"); + if (appPath.IsValid()) + return appPath; + + hsAssert(0, "Your OS doesn't make life easy, does it?"); +#endif +} + +plFileName plFileSystem::GetTempFilename(const char *prefix, const plFileName &path) +{ +#if HS_BUILD_FOR_WIN32 + // GetTempFileName() never uses more than 3 chars for the prefix + wchar_t wprefix[4]; + for (size_t i=0; i<4; ++i) + wprefix[i] = prefix[i]; + wprefix[3] = 0; + + wchar_t temp[MAX_PATH]; + if (GetTempFileNameW(path.AsString().ToWchar(), wprefix, 0, temp)) + return plString::FromWchar(temp); + + return ""; +#else + plFileName tmpdir = path; + if (!tmpdir.IsValid()) + tmpdir = "/tmp"; + + // "/tmp/prefixXXXXXX" + size_t temp_len = tmpdir.GetSize() + strlen(prefix) + 7; + char *temp = new char[temp_len + 1]; + snprintf(temp, temp_len + 1, "%s/%sXXXXXX", tmpdir.AsString().c_str(), prefix); + mktemp(temp); + plFileName result = temp; + delete [] temp; + + return result; +#endif +} diff --git a/Sources/Plasma/CoreLib/plFileSystem.h b/Sources/Plasma/CoreLib/plFileSystem.h index 2654bb0d..1b0bcb32 100644 --- a/Sources/Plasma/CoreLib/plFileSystem.h +++ b/Sources/Plasma/CoreLib/plFileSystem.h @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plString.h" #include +#include #if HS_BUILD_FOR_WIN32 # define PATH_SEPARATOR '\\' @@ -187,10 +188,42 @@ public: const plFileName& path2, const plFileName &path3) { return Join(Join(Join(base, path), path2), path3); } + /** Append UTF-8 data from a C-style string pointer to the end of this + * filename object. Not to be confused with Join() -- do not use this + * for joining path components, or you will be shot by Zrax. + */ + plFileName &operator+=(const char *cstr) { return operator=(fName + cstr); } + + /** Append the string \a str to the end of this filename object. + * Not to be confused with Join() -- do not use this for joining path + * components, or you will be shot by Zrax. + */ + plFileName &operator+=(const plString &str) { return operator=(fName + str); } + private: plString fName; + + // See the comments in plString's nullptr_t constructors for more info: + plFileName(std::nullptr_t) { } + void operator=(std::nullptr_t) { } + void operator==(std::nullptr_t) const { } + void operator!=(std::nullptr_t) const { } }; +/** Concatentate a plFileName with a string constant. Not to be confused with + * plFileName::Join() -- do not use this for joining path components, or you + * will be shot by Zrax. + */ +inline plFileName operator+(const plFileName &left, const char *right) +{ return left.AsString() + right; } + +/** Concatentate a plFileName with a string constant. Not to be confused with + * plFileName::Join() -- do not use this for joining path components, or you + * will be shot by Zrax. + */ +inline plFileName operator+(const char *left, const plFileName &right) +{ return left + right.AsString(); } + /** Structure to get information about a file by name. * \sa plFileName @@ -250,6 +283,9 @@ namespace plFileSystem /** Get the current working directory of the application. */ plFileName GetCWD(); + /** Change the current working directory. */ + bool SetCWD(const plFileName &cwd); + /** Open a file using the correct platform fopen API. */ FILE *Open(const plFileName &filename, const char *mode); @@ -267,6 +303,20 @@ namespace plFileSystem */ bool CreateDir(const plFileName &dir, bool checkParents = false); + /** Fetch a list of files contained in the supplied \a path. + * If \a pattern is specified (e.g. "*.tmp"), use that to filter + * matches. Otherwise, all files in the path will be returned. + * Note that returned filenames include the provided path -- to + * get only the filename, call .GetFileName() on an entry. + */ + std::vector ListDir(const plFileName &path, + const char *pattern = nullptr); + + /** Fetch a list of subdirectories in the specified \a path. + * The returned list does not include the "." or ".." entries. + */ + std::vector ListSubdirs(const plFileName &path); + /** Get the User's data directory. If it doesn't exist, this will * create it. */ @@ -279,6 +329,15 @@ namespace plFileSystem /** Get the Log output directory. If it doesn't exist, this will * create it. */ plFileName GetLogPath(); + + /** Get the full path and filename of the current process. */ + plFileName GetCurrentAppPath(); + + /** Create a temporary filename. If path is specified, the returned + * filename will be relative to the supplied path -- otherwise, the + * system temp path is used. + */ + plFileName GetTempFilename(const char *prefix = "tmp", const plFileName &path = ""); } #endif // plFileSystem_Defined diff --git a/Sources/Plasma/CoreLib/plString.cpp b/Sources/Plasma/CoreLib/plString.cpp index 29e21f5e..57e92de4 100644 --- a/Sources/Plasma/CoreLib/plString.cpp +++ b/Sources/Plasma/CoreLib/plString.cpp @@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ +#include "HeadSpin.h" #include "plString.h" #include diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index c52850fd..acdeb0ed 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef plString_Defined #define plString_Defined -#include "HeadSpin.h" +#include #include /** Single Unicode character code unit */ @@ -416,8 +416,8 @@ public: */ int Compare(const char *str, CaseSensitivity sense = kCaseSensitive) const { - return (sense == kCaseSensitive) ? strcmp(c_str(), str) - : stricmp(c_str(), str); + return (sense == kCaseSensitive) ? strcmp(c_str(), str ? str : "") + : stricmp(c_str(), str ? str : ""); } /** Compare up to but never exceeding the first \a count bytes of this @@ -436,8 +436,8 @@ public: */ int CompareN(const char *str, size_t count, CaseSensitivity sense = kCaseSensitive) const { - return (sense == kCaseSensitive) ? strncmp(c_str(), str, count) - : strnicmp(c_str(), str, count); + return (sense == kCaseSensitive) ? strncmp(c_str(), str ? str : "", count) + : strnicmp(c_str(), str ? str : "", count); } /** Shortcut for Compare(str, kCaseInsensitive). */ 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..2fbe3617 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -155,7 +155,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plUnifiedTime/plUnifiedTime.h" //end for agedefn test -#include "plFile/hsFiles.h" #include "pnSceneObject/plAudioInterface.h" #include "plStatusLog/plStatusLog.h" @@ -263,9 +262,9 @@ PF_CONSOLE_FILE_DUMMY(Main) // utility functions // ////////////////////////////////////////////////////////////////////////////// -plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString=false); -plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString=false); -plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName, +plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString=false); +plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString=false); +plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName, char* statusStr, bool subString=false); void PrintStringF(void pfun(const char *),const char * fmt, ...); @@ -273,7 +272,7 @@ void PrintStringF(void pfun(const char *),const char * fmt, ...); // Find an object from name, type (int), and optionally age. // Name can be an alias specified by saying $foo // -plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString) +plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString) { if (name.IsNull()) { @@ -293,22 +292,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 +333,7 @@ plKey FindObjectByName(const plString& name, int type, const char* ageName, char // Name can be an alias specified by saying $foo. // Will load the object if necessary. // -plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString) +plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString) { plKey key=FindObjectByName(name, plSceneObject::Index(), ageName, statusStr, subString); @@ -352,7 +351,7 @@ plKey FindSceneObjectByName(const plString& name, const char* ageName, char* sta // Find an object from name, type (string) and optionally age. // Name can be an alias specified by saying $foo // -plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName, +plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName, char* statusStr, bool subString) { if (!typeName) @@ -1579,8 +1578,8 @@ PF_CONSOLE_CMD( Graphics_Renderer, GrabCubeMap, "Take cubemap from sceneObject's position and name it prefix_XX.jpg") { char str[512]; - plString objName = plString::FromUtf8(params[0]); - plKey key = FindSceneObjectByName(objName, nil, str); + plString objName = static_cast(params[0]); + plKey key = FindSceneObjectByName(objName, "", str); PrintString( str ); if( !key ) return; @@ -1841,7 +1840,7 @@ PF_CONSOLE_CMD( Graphics_Show, SingleSound, { char str[ 512 ]; - const char *ageName = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName(); + plString ageName = plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName(); plKey key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), ageName, str, true ); plSceneObject *obj = ( key != nil ) ? plSceneObject::ConvertNoRef( key->GetObjectPtr() ) : nil; @@ -2175,7 +2174,7 @@ PF_CONSOLE_CMD( App, { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str); plSceneObject* obj = plSceneObject::ConvertNoRef(key->GetObjectPtr()); if( !obj ) { @@ -2252,7 +2251,7 @@ PF_CONSOLE_CMD( App, { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str); plSceneObject* obj = plSceneObject::ConvertNoRef(key->GetObjectPtr()); if( !obj ) { @@ -2307,7 +2306,7 @@ PF_CONSOLE_CMD( App, { char str[256]; plString name = plString::FromUtf8(params[0]); - plKey key = FindSceneObjectByName(name, nil, str); + plKey key = FindSceneObjectByName(name, "", str); if( !key ) { sprintf(str, "%s - Not Found!", name.c_str()); @@ -2773,7 +2772,7 @@ PF_CONSOLE_CMD( Registry, ListRefs, "string keyType, string keyName", "For the g "the objects who currently have active refs on it." ) { char result[ 256 ]; - plKey obj = FindObjectByNameAndType( plString::FromUtf8( params[ 1 ] ), params[ 0 ], nil, result); + plKey obj = FindObjectByNameAndType( plString::FromUtf8( params[ 1 ] ), params[ 0 ], "", result); if( obj == nil ) { PrintString( result ); @@ -2950,7 +2949,7 @@ PF_CONSOLE_CMD( Camera, SwitchTo, "string cameraName", "Switch to the named came { char str[256]; plString foo = plString::Format("%s_", (char*)params[0]); - plKey key = FindObjectByNameAndType(foo, "plCameraModifier1", nil, str, true); + plKey key = FindObjectByNameAndType(foo, "plCameraModifier1", "", str, true); PrintString(str); if (key) @@ -3076,7 +3075,7 @@ PF_CONSOLE_GROUP( Logic ) static plLogicModBase *FindLogicMod(const plString &name) { char str[256]; - plKey key = FindObjectByNameAndType(name, "plLogicModifier", nil, str, true); + plKey key = FindObjectByNameAndType(name, "plLogicModifier", "", str, true); pfConsole::AddLine(str); if (key) @@ -3173,7 +3172,7 @@ PF_CONSOLE_CMD( Logic, TriggerResponderNum, "int responderNum, ...", "Triggers t } char str[256]; - plKey key = FindObjectByNameAndType(responderNames[responderNum-1], "plResponderModifier", nil, str, true); + plKey key = FindObjectByNameAndType(responderNames[responderNum-1], "plResponderModifier", "", str, true); PrintString(str); if (key) @@ -3189,7 +3188,7 @@ PF_CONSOLE_CMD( Logic, TriggerResponder, "string responderComp, ...", "Triggers } char str[256]; - plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", nil, str, true); + plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", "", str, true); PrintString(str); int responderState = -1; @@ -3211,7 +3210,7 @@ PF_CONSOLE_CMD( Logic, FastForwardResponder, "string responderComp, ...", "Fastf } char str[256]; - plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", nil, str, true); + plKey key = FindObjectByNameAndType(plString::FromUtf8(params[0]), "plResponderModifier", "", str, true); PrintString(str); int responderState = -1; @@ -3522,7 +3521,7 @@ PF_CONSOLE_CMD( Audio, SetVolume, "string obj, float vol", "Sets the volume on a given object. 1 is max volume, 0 is silence" ) { char str[ 256 ]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[ 0 ]), nil, str); + plKey key = FindSceneObjectByName(plString::FromUtf8(params[ 0 ]), "", str); if( key == nil ) return; @@ -3551,7 +3550,7 @@ PF_CONSOLE_CMD( Audio, IsolateSound, plKey key; plAudioSysMsg *asMsg; - key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), nil, str ); + key = FindSceneObjectByName( plString::FromUtf8( params[ 0 ] ), "", str ); if( key == nil ) { sprintf( str, "Cannot find sound %s", (char *)params[ 0 ] ); @@ -3928,36 +3927,10 @@ PF_CONSOLE_CMD( Nav, PageInNode, // Group name, Function name plSynchEnabler ps(false); // disable dirty tracking while paging in plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoom); pMsg1->AddReceiver( plClient::GetInstance()->GetKey() ); - pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, params[0])); + pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", static_cast(params[0]))); plgDispatch::MsgSend(pMsg1); } -PF_CONSOLE_CMD( Nav, PageInNodeList, // Group name, Function name - "string roomNameBase", // Params - "Pages in all scene nodes that start with name." ) // Help string -{ -/* This is really old and hasn't worked since 2002 anyways. */ -#if HS_BUILD_FOR_WIN32 - plSynchEnabler ps(false); // disable dirty tracking while paging in - - std::string pageInNodesStr; - pageInNodesStr += "dat\\"; - pageInNodesStr += (char*)params[0]; - pageInNodesStr += "*.prx"; - hsFolderIterator pageInNodesIter(pageInNodesStr.data(), true); - - plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kLoadRoom); - while (pageInNodesIter.NextFile()) - { - char nodeName[255]; - _splitpath(pageInNodesIter.GetFileName(), NULL, NULL, nodeName, NULL); - pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, nodeName)); - } - pMsg1->AddReceiver( plClient::GetInstance()->GetKey() ); - plgDispatch::MsgSend(pMsg1); -#endif -} - #ifndef LIMIT_CONSOLE_COMMANDS @@ -3968,7 +3941,7 @@ PF_CONSOLE_CMD( Nav, PageOutNode, // Group name, Function name plSynchEnabler ps(false); // disable dirty tracking while paging out plClientMsg* pMsg1 = new plClientMsg(plClientMsg::kUnloadRoom); pMsg1->AddReceiver( plClient::GetInstance()->GetKey() ); - pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation(nil, params[0])); + pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", static_cast(params[0]))); plgDispatch::MsgSend(pMsg1); } @@ -3977,7 +3950,7 @@ PF_CONSOLE_CMD( Nav, UnloadPlayer, // Group name, Function name "unloads a named player" ) // Help string { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str); PrintString("UnloadPlayer (console version) is currently broken. Hassle Matt."); // plNetClientMgr::UnloadPlayer(key); } @@ -3995,12 +3968,12 @@ PF_CONSOLE_CMD( Nav, MovePlayer, // Group name, Function name "moves a player from one paging unit to another" ) // Help string { char str[256]; - plKey playerKey = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey playerKey = FindSceneObjectByName(static_cast(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 +4280,7 @@ PF_CONSOLE_CMD( Access, char str[256]; char* preFix = params[0]; plString name = plString::Format("%s_plMorphSequence_0", preFix); - plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str); + plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str); PrintString(str); if (!key) return; @@ -4332,7 +4305,7 @@ PF_CONSOLE_CMD( Access, char str[256]; char* preFix = params[0]; plString name = plString::Format("%s_plMorphSequence_2", preFix); - plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str); + plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str); PrintString(str); if (!key) return; @@ -4353,7 +4326,7 @@ PF_CONSOLE_CMD( Access, char str[256]; char* preFix = params[0]; plString name = plString::Format("%s_plMorphSequence_2", preFix); - plKey key = FindObjectByName(name, plMorphSequence::Index(), nil, str); + plKey key = FindObjectByName(name, plMorphSequence::Index(), "", str); PrintString(str); if (!key) return; @@ -4572,7 +4545,7 @@ PF_CONSOLE_CMD( Access, "Test fading on visibility" ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), "", str); PrintString(str); if( !key ) return; @@ -4604,7 +4577,7 @@ PF_CONSOLE_CMD( Access, "Set the los test marker" ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if( !key ) return; @@ -4618,7 +4591,7 @@ PF_CONSOLE_CMD( Access, "Set the Los hack marker" ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); plSceneObject* so = nil; @@ -4693,7 +4666,7 @@ PF_CONSOLE_CMD( Access, "Fire shot along gun's z-axis, creating decal of radius , 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 +4747,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 +4755,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 +4955,7 @@ static void IDisplayWaveVal(PrintFunk PrintString, plWaveSet7* wave, plWaveCmd:: static plWaveSet7* IGetWaveSet(PrintFunk PrintString, const plString& name) { char str[256]; - plKey waveKey = FindObjectByName(name, plWaveSet7::Index(), nil, str, false); + plKey waveKey = FindObjectByName(name, plWaveSet7::Index(), "", str, false); PrintString(str); if (!waveKey) return nil; @@ -5463,7 +5436,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Drawable, // Group name, Function name "Enable or disable drawing of a sceneobject" ) // Help string { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if (!key) return; @@ -5482,7 +5455,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Physical, // Group name, Function name "Enable or disable the physical of a sceneobject" ) // Help string { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if (!key) return; @@ -5524,7 +5497,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, Audible, // Group name, Function name "Enable or disable the audible of a sceneobject" ) // Help string { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if (!key) return; @@ -5543,7 +5516,7 @@ PF_CONSOLE_CMD( SceneObject_SetEnable, All, // Group name, Function name "Enable or disable all fxns of a sceneobject" ) // Help string { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); PrintString(str); if (!key) return; @@ -5563,10 +5536,10 @@ PF_CONSOLE_CMD( SceneObject, Attach, // Group name, Function name { char str[256]; - plString childName = plString::FromUtf8(params[0]); - plString parentName = plString::FromUtf8(params[1]); + plString childName = static_cast(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 +5553,7 @@ PF_CONSOLE_CMD( SceneObject, Attach, // Group name, Function name return; } - plKey parentKey = FindSceneObjectByName(parentName, nil, str); + plKey parentKey = FindSceneObjectByName(parentName, "", str); if( !parentKey ) { PrintString(str); @@ -5601,9 +5574,9 @@ PF_CONSOLE_CMD( SceneObject, Detach, // Group name, Function name { char str[256]; - plString childName = plString::FromUtf8(params[0]); + plString childName = static_cast(params[0]); - plKey childKey = FindSceneObjectByName(childName, nil, str); + plKey childKey = FindSceneObjectByName(childName, "", str); if( !childKey ) { PrintString(str); @@ -6186,7 +6159,7 @@ PF_CONSOLE_GROUP( ParticleSystem ) // Defines a main command group void UpdateParticleParam(const plString &objName, int32_t paramID, float value, void (*PrintString)(const char *)) { char str[256]; - plKey key = FindSceneObjectByName(objName, nil, str); + plKey key = FindSceneObjectByName(objName, "", str); PrintString(str); if (key == nil) return; @@ -6309,7 +6282,7 @@ PF_CONSOLE_CMD( ParticleSystem, "Creates a system (if necessary) on the avatar, and transfers particles" ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); if (key == nil) return; @@ -6317,7 +6290,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 +6301,7 @@ PF_CONSOLE_CMD( ParticleSystem, "Flag some particles for death." ) { char str[256]; - plKey key = FindSceneObjectByName(plString::FromUtf8(params[0]), nil, str); + plKey key = FindSceneObjectByName(static_cast(params[0]), "", str); if (key == nil) return; @@ -6350,7 +6323,7 @@ PF_CONSOLE_SUBGROUP( ParticleSystem, Flock ) static plParticleFlockEffect *FindFlock(const plString &objName) { char str[256]; - plKey key = FindSceneObjectByName(objName, nil, str); + plKey key = FindSceneObjectByName(objName, "", str); if (key == nil) return nil; @@ -6528,7 +6501,7 @@ PF_CONSOLE_GROUP( Animation ) // Defines a main command group void SendAnimCmdMsg(const plString &objName, plMessage *msg) { char str[256]; - plKey key = FindSceneObjectByName(objName, nil, str); + plKey key = FindSceneObjectByName(objName, "", str); if (key != nil) { msg->AddReceiver(key); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index ac7a72b1..16d38969 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -84,8 +84,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plUnifiedTime/plUnifiedTime.h" //end for agedefn test -#include "plFile/hsFiles.h" - #include "plStatusLog/plStatusLog.h" #include "hsTemplates.h" @@ -196,9 +194,9 @@ PF_CONSOLE_FILE_DUMMY(Net) // utility functions // ////////////////////////////////////////////////////////////////////////////// -plKey FindSceneObjectByName(const plString& name, const char* ageName, char* statusStr, bool subString=false); -plKey FindObjectByName(const plString& name, int type, const char* ageName, char* statusStr, bool subString=false); -plKey FindObjectByNameAndType(const plString& name, const char* typeName, const char* ageName, +plKey FindSceneObjectByName(const plString& name, const plString& ageName, char* statusStr, bool subString=false); +plKey FindObjectByName(const plString& name, int type, const plString& ageName, char* statusStr, bool subString=false); +plKey FindObjectByNameAndType(const plString& name, const char* typeName, const plString& ageName, char* statusStr, bool subString=false); void PrintStringF(void pfun(const char *),const char * fmt, ...); @@ -507,9 +505,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/pfConsole/pfConsoleDirSrc.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp index 86124c50..af2f9ad6 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp @@ -49,75 +49,46 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsExceptions.h" -#ifdef HS_BUILD_FOR_WIN32 - -#include "hsWindows.h" -#include - - //// ParseDirectory ////////////////////////////////////////////////////////// -bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */) +bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* = L"*.*" */) { - WIN32_FIND_DATAW findInfo; - HANDLE handle; - hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" ); - handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo); - if (handle == INVALID_HANDLE_VALUE) - return false; - - do + std::vector files = plFileSystem::ListDir(path, mask); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + plFileName name = iter->GetFileName(); + if (AlreadyProcessedFile(path, name)) + continue; + AddProcessedFile(path, name); + if (!fEngine->ExecuteFile(*iter)) { - plFileName name = plString::FromWchar(findInfo.cFileName); - plFileName fileAndPath = plFileName::Join(path, name); - if (AlreadyProcessedFile(path, name)) - continue; - AddProcessedFile(path, name); - if (!fEngine->ExecuteFile(fileAndPath)) - { - // Change the following line once we have a better way of reporting - // errors in the parsing - std::wstringstream error; - std::wstringstream caption; - wchar_t* errorMsg = hsStringToWString(fEngine->GetErrorMsg()); - wchar_t* errorLine = hsStringToWString(fEngine->GetLastErrorLine()); - - caption << L"Error parsing " << findInfo.cFileName; - error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files."; - - hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal); - - delete [] errorMsg; - delete [] errorLine; - - FindClose(handle); - SetCheckProcessedFiles(true); - return false; - } + // Change the following line once we have a better way of reporting + // errors in the parsing + plStringStream error, caption; + + caption << "Error parsing " << name.AsString(); + error << fEngine->GetErrorMsg() << ":\n\nCommand: '" << fEngine->GetLastErrorLine() + << "'\n\nPress OK to continue parsing files."; + + hsMessageBox(error.GetString().c_str(), caption.GetString().c_str(), hsMessageBoxNormal); + + SetCheckProcessedFiles(true); + return false; } - } while (FindNextFileW(handle, &findInfo) != 0); + } - FindClose(handle); SetCheckProcessedFiles(true); return true; } -#else - -#error This needs to be implemented for this platform!!!! - -#endif - void pfConsoleDirSrc::ResetProcessedFiles() { int i; for(i=0;i fProcessedFiles; // list of init files we've already executed bool fCheckProcessedFiles; // set to check and skip files init files we've already executed public: pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; } - pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini") + pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const char* mask = "*.ini") : fCheckProcessedFiles(false) { fEngine = engine; @@ -88,7 +88,7 @@ class pfConsoleDirSrc ~pfConsoleDirSrc() { ResetProcessedFiles(); } // Steps through the given directory and executes all files with the console engine - bool ParseDirectory(const plFileName& path, const plString& mask = "*.*"); + bool ParseDirectory(const plFileName& path, const char* mask = "*.*"); void ResetProcessedFiles(); bool AlreadyProcessedFile(const plFileName& path, const plFileName& file); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp index ffc5cf29..96bd4c19 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp @@ -305,7 +305,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, plString& info) case plClientMsg::kLoadAgeKeys: case plClientMsg::kReleaseAgeKeys: - info += plString::Format(" - Age: %s", clientMsg->GetAgeName()); + info += plString::Format(" - Age: %s", clientMsg->GetAgeName().c_str()); break; } return true; 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..125a0f61 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plLocalization.h" -#include "plFile/hsFiles.h" #include "plFile/plEncryptedStream.h" #include "plStatusLog/plStatusLog.h" @@ -94,7 +93,7 @@ public: protected: bool fWeExploded; // alternative to massive error stack - plString fFilename; + plFileName fFilename; XML_Parser fParser; struct tagInfo @@ -121,7 +120,7 @@ protected: public: LocalizationXMLFile() : fWeExploded(false) { } - bool Parse(const plString & fileName); // returns false on failure + bool Parse(const plFileName & fileName); // returns false on failure void AddError(const plString & errorText); }; @@ -354,7 +353,7 @@ void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagIn //// Parse() ///////////////////////////////////////////////////////// -bool LocalizationXMLFile::Parse(const plString& fileName) +bool LocalizationXMLFile::Parse(const plFileName& fileName) { fFilename = fileName; @@ -382,10 +381,10 @@ bool LocalizationXMLFile::Parse(const plString& fileName) XML_SetCharacterDataHandler(fParser, HandleData); XML_SetUserData(fParser, (void*)this); - hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str()); + hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName); if (!xmlStream) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.c_str()); + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.AsString().c_str()); return false; } @@ -437,15 +436,15 @@ void LocalizationXMLFile::AddError(const plString& errorText) class LocalizationDatabase { protected: - plString fDirectory; // the directory we're supposed to parse + plFileName fDirectory; // the directory we're supposed to parse std::vector fFiles; // the various XML files in that directory LocalizationXMLFile::ageMap fData; - LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path); - LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path); - LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path); + LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plFileName & fileName, const plString & path); + LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plFileName & fileName, const plString & path); + LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plFileName & fileName, const plString & path); void IMergeData(); // merge all localization data in the files void IVerifyElement(const plString &ageName, const plString &setName, LocalizationXMLFile::set::iterator& curElement); @@ -456,7 +455,7 @@ protected: public: LocalizationDatabase() {} - void Parse(const plString & directory); + void Parse(const plFileName & directory); LocalizationXMLFile::ageMap GetData() {return fData;} }; @@ -466,7 +465,7 @@ public: //// IMergeElementData /////////////////////////////////////////////// -LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path) +LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plFileName & fileName, const plString & path) { // copy the data over, alerting the user to any duplicate translations LocalizationXMLFile::element::iterator curTranslation; @@ -475,7 +474,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio if (firstElement.find(curTranslation->first) != firstElement.end()) { pfLocalizationDataMgr::GetLog()->AddLineF("Duplicate %s translation for %s found in file %s. Ignoring second translation.", - curTranslation->first.c_str(), path.c_str(), fileName.c_str()); + curTranslation->first.c_str(), path.c_str(), fileName.AsString().c_str()); } else firstElement[curTranslation->first] = curTranslation->second; @@ -486,7 +485,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio //// IMergeSetData /////////////////////////////////////////////////// -LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path) +LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plFileName & fileName, const plString & path) { // Merge all the elements LocalizationXMLFile::set::iterator curElement; @@ -505,7 +504,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile //// IMergeAgeData /////////////////////////////////////////////////// -LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path) +LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plFileName & fileName, const plString & path) { // Merge all the sets LocalizationXMLFile::age::iterator curSet; @@ -640,24 +639,21 @@ void LocalizationDatabase::IVerifyData() //// Parse() ///////////////////////////////////////////////////////// -void LocalizationDatabase::Parse(const plString & directory) +void LocalizationDatabase::Parse(const plFileName & directory) { fDirectory = directory; fFiles.clear(); - char filename[255]; - hsFolderIterator xmlFolder((directory + PATH_SEPARATOR_STR).c_str()); - while(xmlFolder.NextFileSuffix(".loc")) + std::vector locFiles = plFileSystem::ListDir(directory, "*.loc"); + for (auto iter = locFiles.begin(); iter != locFiles.end(); ++iter) { - xmlFolder.GetPathAndName(filename); - LocalizationXMLFile newFile; - bool retVal = newFile.Parse(filename); + bool retVal = newFile.Parse(*iter); if (!retVal) - pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Errors in file %s", filename); + pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Errors in file %s", iter->GetFileName().c_str()); fFiles.push_back(newFile); - pfLocalizationDataMgr::GetLog()->AddLineF("File %s parsed and added to database", filename); + pfLocalizationDataMgr::GetLog()->AddLineF("File %s parsed and added to database", iter->GetFileName().c_str()); } IMergeData(); @@ -822,7 +818,7 @@ plStatusLog *pfLocalizationDataMgr::fLog = nil; // output logfile //// Constructor/Destructor ////////////////////////////////////////// -pfLocalizationDataMgr::pfLocalizationDataMgr(const plString & path) +pfLocalizationDataMgr::pfLocalizationDataMgr(const plFileName & path) { hsAssert(!fInstance, "Tried to create the localization data manager more than once!"); fInstance = this; @@ -932,7 +928,7 @@ void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const plString & cu //// IWriteText ////////////////////////////////////////////////////// -void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString & ageName, const plString & languageName) +void pfLocalizationDataMgr::IWriteText(const plFileName & filename, const plString & ageName, const plString & languageName) { bool weWroteData = false; // did we actually write any data of consequence? bool setEmpty = true; @@ -980,7 +976,7 @@ void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString if (weWroteData) { // now spit the results out to the file - hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename.c_str()); + hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename); xmlStream->Write(fileData.GetLength(), fileData.GetString().c_str()); xmlStream->Close(); delete xmlStream; @@ -989,7 +985,7 @@ void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString //// Initialize ////////////////////////////////////////////////////// -void pfLocalizationDataMgr::Initialize(const plString & path) +void pfLocalizationDataMgr::Initialize(const plFileName & path) { if (fInstance) return; @@ -1194,7 +1190,7 @@ bool pfLocalizationDataMgr::DeleteElement(const plString & name) //// WriteDatabaseToDisk ///////////////////////////////////////////// -void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) +void pfLocalizationDataMgr::WriteDatabaseToDisk(const plFileName & path) { std::vector ageNames = GetAgeList(); std::vector languageNames = IGetAllLanguageNames(); @@ -1202,7 +1198,9 @@ void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) { for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++) { - IWriteText(plString::Format("%s/%s%s.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]); + plFileName locPath = plFileName::Join(path, plString::Format("%s%s.loc", + ageNames[curAge].c_str(), languageNames[curLanguage].c_str())); + IWriteText(locPath, ageNames[curAge], languageNames[curLanguage]); } } } 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/pfPython/plPythonPack.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp index 4c1d82d6..7e943fb9 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp @@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plPythonPack.h" -#include "plFile/hsFiles.h" #include "plFile/plSecureStream.h" #include "plFile/plStreamSource.h" 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/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 87f74fdf..f12bda90 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -805,17 +805,15 @@ static void StartListenThread () { #ifdef HS_DEBUGGING #include static void __cdecl DumpInvalidData ( - const wchar_t filename[], + const plFileName & filename, unsigned bytes, const uint8_t data[], const char fmt[], ... ) { - wchar_t path[MAX_PATH]; - PathGetProgramDirectory(path, arrsize(path)); - PathAddFilename(path, path, L"Log", arrsize(path)); - PathAddFilename(path, path, filename, arrsize(path)); - if (FILE * f = _wfopen(path, L"wb")) { + plFileName path = plFileSystem::GetCurrentAppPath().StripFileName(); + path = plFileName::Join(path, "Log", filename); + if (FILE * f = plFileSystem::Open(path, "wb")) { va_list args; va_start(args, fmt); vfprintf(f, fmt, args); @@ -1027,7 +1025,7 @@ void INtSocketOpCompleteSocketRead ( static long s_once; if (!AtomicAdd(&s_once, 1)) { DumpInvalidData( - L"NtSockErr.log", + "NtSockErr.log", sizeof(sock->buffer), sock->buffer, "SocketDispatchRead error for %p: %d %d %d\r\n", 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/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index ab6c127e..87603e88 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -12,7 +12,6 @@ set(pnUtils_HEADERS pnUtHash.h pnUtList.h pnUtMisc.h - pnUtPath.h pnUtPragma.h pnUtPriQ.h pnUtRef.h @@ -28,7 +27,6 @@ set(pnUtils_SOURCES pnUtHash.cpp pnUtList.cpp pnUtMisc.cpp - pnUtPath.cpp pnUtStr.cpp pnUtTime.cpp ) @@ -36,7 +34,6 @@ set(pnUtils_SOURCES if(WIN32) set(pnUtils_WIN32 Win32/pnUtW32Misc.cpp - Win32/pnUtW32Path.cpp Win32/pnUtW32Str.cpp ) else() diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp deleted file mode 100644 index 286a2099..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp +++ /dev/null @@ -1,585 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Path.cpp -* -***/ - -#include "../pnUtils.h" -#include "plProduct.h" - - -/***************************************************************************** -* -* Local functions -* -***/ - -// make sure our definition is at least as big as the compiler's definition -static_assert(MAX_PATH >= _MAX_PATH, "Windows and STDlib MAX_PATH constants differ"); - - -//=========================================================================== -static inline bool IsSlash (wchar_t c) { - return (c == L'\\') || (c == L'/'); -} - -//=========================================================================== -static inline wchar_t ConvertSlash (wchar_t c) { - return c != L'/' ? c : L'\\'; -} - -//=========================================================================== -static inline bool IsUncPath (const wchar_t path[]) { - return IsSlash(path[0]) && IsSlash(path[1]); -} - -//=========================================================================== -static const wchar_t * SkipUncDrive (const wchar_t path[]) { - // UNC drive: "//server/share" - - // skip over leading "//" - path += 2; - - // scan forward to end of server name - for (;; ++path) { - if (!*path) - return path; - if (IsSlash(*path)) - break; - } - - // skip over '/' - ++path; - - // skip over share name - for (;; ++path) { - if (!*path) - return path; - if (IsSlash(*path)) - return path; - } -} - -//=========================================================================== -static wchar_t * PathSkipOverSeparator (wchar_t * path) { - for (; *path; ++path) { - if (IsSlash(*path)) - return path + 1; - } - - return path; -} - -//=========================================================================== -const wchar_t * PathFindFilename ( - const wchar_t path[] -) { - ASSERT(path); - - if (IsUncPath(path)) - path = SkipUncDrive(path); - - const wchar_t * last_slash = path; - for (const wchar_t * p = path; *p; p++) { - if ((*p == L'/') || (*p == L'\\') || (*p == L':')) - last_slash = p + 1; - } - - return last_slash; -} - -//=========================================================================== -static void GetProgramName ( - void * instance, - wchar_t * dst, - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - - if (!GetModuleFileNameW((HINSTANCE) instance, dst, dstChars)) { - ErrorAssert(__LINE__, __FILE__, "GetModuleName failed"); - *dst = 0; - } -} - -//============================================================================ -bool PathDoesDirectoryExist (const wchar_t directory[]) { - uint32_t attributes = GetFileAttributesW(directory); - if (attributes == (uint32_t) -1) - return false; - if (attributes & FILE_ATTRIBUTE_DIRECTORY) - return true; - return false; -} - - -/**************************************************************************** -* -* Exports -* -***/ - -//=========================================================================== -void PathGetProgramName ( - wchar_t * dst, - unsigned dstChars -) { - GetProgramName(nil, dst, dstChars); -} - -//=========================================================================== -bool PathFromString ( - wchar_t * dst, - const wchar_t src[], - unsigned dstChars -) { - ASSERT(dst); - ASSERT(src); - ASSERT(dstChars); - - for (;;) { - // enable src and dst to be the same buffer - wchar_t temp[MAX_PATH]; - if (dst == src) { - StrCopy(temp, src, arrsize(temp)); - src = temp; - } - - DWORD const result = GetFullPathNameW(src, dstChars, dst, 0); - if (!result) - break; - if (dstChars < result) - break; - if (!dst[0]) - break; - - return true; - } - - *dst = 0; - return false; -} - -//=========================================================================== -// this function was originally derived from _tsplitpath in the MSVCRT library, -// but has been updated to support UNC paths and to avoid blasting off the end -// of the buffers. -void PathSplitPath ( - const wchar_t path[], - wchar_t * drive, - wchar_t * dir, - wchar_t * fname, - wchar_t * ext -) { - ASSERT(path); - ASSERT(path != drive); - ASSERT(path != dir); - ASSERT(path != fname); - ASSERT(path != ext); - - // check for UNC path - if (IsUncPath(path)) { - const wchar_t * pathStart = path; - path = SkipUncDrive(path); - - if (drive) - StrCopy(drive, pathStart, min(MAX_DRIVE, path - pathStart + 1)); - } - // regular DOS path - else if (path[0] && (path[1] == L':')) { - if (drive) { - ASSERT(MAX_DRIVE >= 3); - drive[0] = path[0]; - drive[1] = L':'; - drive[2] = L'\0'; - } - - path += 2; // skip over 'C' ':' - } - else if (drive) { - *drive = 0; - } - - // extract path string, if any. Path now points to the first character - // of the path, if any, or the filename or extension, if no path was - // specified. Scan ahead for the last occurence, if any, of a '/' or - // '\' path separator character. If none is found, there is no path. - // We will also note the last '.' character found, if any, to aid in - // handling the extension. - const wchar_t *last_slash = nil, *last_dot = nil, *p = path; - for (; *p; p++) { - if (IsSlash(*p)) - last_slash = p + 1; // point to one beyond for later copy - else if (*p == L'.') - last_dot = p; - } - - if (last_slash) { - if (dir) - StrCopy(dir, path, min(MAX_DIR, last_slash - path + 1)); - path = last_slash; - } - else if (dir) { - *dir = 0; - } - - // extract file name and extension, if any. Path now points to the - // first character of the file name, if any, or the extension if no - // file name was given. Dot points to the '.' beginning the extension, - // if any. - if (last_dot && (last_dot >= path)) { - if (fname) - StrCopy(fname, path, min(MAX_FNAME, last_dot - path + 1)); - if (ext) - StrCopy(ext, last_dot, MAX_EXT); - } - else { - if (fname) - StrCopy(fname, path, MAX_FNAME); - if (ext) - *ext = 0; - } -} - -//=========================================================================== -void PathMakePath ( - wchar_t * path, - unsigned chars, - const wchar_t drive[], - const wchar_t dir[], - const wchar_t fname[], - const wchar_t ext[] -) { - ASSERT(path); - ASSERT(path != drive); - ASSERT(path != dir); - ASSERT(path != fname); - ASSERT(path != ext); - - // save space for string terminator - if (!chars--) - return; - - // copy drive - if (drive && *drive && chars) { - do { - *path++ = ConvertSlash(*drive++); - } while (--chars && *drive); - ASSERT(!IsSlash(path[-1])); - } - - // copy directory - if (dir && *dir && chars) { - do { - *path++ = ConvertSlash(*dir++); - } while (--chars && *dir); - - // add trailing backslash - if (chars && (path[-1] != '\\')) { - *path++ = L'\\'; - chars--; - } - } - - // copy filename - if (fname && *fname && chars) { - // skip leading backslash - if (IsSlash(*fname)) - ++fname; - - do { - *path++ = ConvertSlash(*fname++); - } while (--chars && *fname); - } - - // copy extension - if (ext && *ext && chars) { - if (*ext != L'.') { - *path++ = L'.'; - chars--; - } - while (chars-- && *ext) - *path++ = ConvertSlash(*ext++); - } - - // add string terminator - *path = L'\0'; -} - -//=========================================================================== -void PathGetUserDirectory ( - wchar_t * dst, - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - - wchar_t temp[MAX_PATH]; // GetSpecialFolder path requires a buffer of MAX_PATH size or larger - if (SHGetSpecialFolderPathW(NULL, temp, CSIDL_LOCAL_APPDATA, TRUE) == FALSE) - StrCopy(temp, L"C:\\", arrsize(temp)); - - // append the product name - PathAddFilename(dst, temp, plProduct::LongName().ToWchar(), dstChars); - - // ensure it exists - if (!PathDoesDirectoryExist(dst)) - PathCreateDirectory(dst, kPathCreateDirFlagEntireTree); -} - -//============================================================================ -void PathGetLogDirectory ( - wchar_t * dst, - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - PathGetUserDirectory(dst, dstChars); - PathAddFilename(dst, dst, L"Log", dstChars); - if (!PathDoesDirectoryExist(dst)) - PathCreateDirectory(dst, kPathCreateDirFlagEntireTree); -} - -//============================================================================ -void PathGetInitDirectory ( - wchar_t * dst, - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - PathGetUserDirectory(dst, dstChars); - PathAddFilename(dst, dst, L"Init", dstChars); - if (!PathDoesDirectoryExist(dst)) - PathCreateDirectory(dst, kPathCreateDirFlagEntireTree); -} - -//=========================================================================== -void PathFindFiles ( - ARRAY(PathFind) * paths, - const wchar_t fileSpec[], - unsigned pathFlags -) { - ASSERT(paths); - ASSERT(fileSpec); - - HANDLE find; - WIN32_FIND_DATAW fd; - wchar_t directory[MAX_PATH]; - PathRemoveFilename(directory, fileSpec, arrsize(directory)); - if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(fileSpec, &fd))) { - DWORD err = GetLastError(); - if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)) - ASSERTMSG(err, "PathFindFiles failed"); - } - else { - // find all the items in the current directory - do { - unsigned fileFlags = 0; - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (! (pathFlags & kPathFlagDirectory)) - continue; - - // don't add "." and ".." - if (fd.cFileName[0] == L'.') { - if (!fd.cFileName[1]) - continue; - if (fd.cFileName[1] == L'.' && !fd.cFileName[2]) - continue; - } - - fileFlags = kPathFlagDirectory; - } - else { - if (! (pathFlags & kPathFlagFile)) - continue; - fileFlags = kPathFlagFile; - } - if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { - if (! (pathFlags & kPathFlagHidden)) - continue; - fileFlags |= kPathFlagHidden; - } - if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) { - if (! (pathFlags & kPathFlagSystem)) - continue; - fileFlags |= kPathFlagSystem; - } - - // add this one to the list of found files - PathFind * pf = paths->New(); - pf->flags = fileFlags; - pf->fileLength = ((uint64_t) fd.nFileSizeHigh << 32) | fd.nFileSizeLow; - pf->lastWriteTime = * (const uint64_t *) &fd.ftLastWriteTime; - PathAddFilename(pf->name, directory, fd.cFileName, arrsize(pf->name)); - } while (FindNextFileW(find, &fd)); - FindClose(find); - } - - // check for directory recursing - if ((pathFlags & kPathFlagRecurse) || StrStr(fileSpec, L"**")) { - // recurse directories - } - else { - return; - } - - wchar_t dirSpec[MAX_PATH]; - PathAddFilename(dirSpec, directory, L"*", arrsize(dirSpec)); - if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(dirSpec, &fd))) { - DWORD err = GetLastError(); - if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)) - ErrorAssert(__LINE__, __FILE__, "PathFindFiles failed"); - return; - } - - // find all the directories in the current directory - const wchar_t * spec = PathFindFilename(fileSpec); - do { - if (! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - continue; - } - if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { - if (! (pathFlags & kPathFlagHidden)) - continue; - } - if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) { - if (! (pathFlags & kPathFlagSystem)) - continue; - } - - // don't recurse "." and ".." - if (fd.cFileName[0] == L'.') { - if (!fd.cFileName[1]) - continue; - if (fd.cFileName[1] == L'.' && !fd.cFileName[2]) - continue; - } - - // recursively search subdirectory - PathAddFilename(dirSpec, directory, fd.cFileName, arrsize(dirSpec)); - PathAddFilename(dirSpec, dirSpec, spec, arrsize(dirSpec)); - PathFindFiles(paths, dirSpec, pathFlags); - - } while (FindNextFileW(find, &fd)); - FindClose(find); -} - -//=========================================================================== -EPathCreateDirError PathCreateDirectory (const wchar_t path[], unsigned flags) { - ASSERT(path); - - // convert from relative path to full path - wchar_t dir[MAX_PATH]; - if (!PathFromString(dir, path, arrsize(dir))) { - return kPathCreateDirErrInvalidPath; - } - - // are we going to build the entire directory tree? - wchar_t * dirEnd; - if (flags & kPathCreateDirFlagEntireTree) { - dirEnd = dir; - - // skip over leading slashes in UNC paths - while (IsSlash(*dirEnd)) - ++dirEnd; - - // skip forward to first directory - dirEnd = PathSkipOverSeparator(dirEnd); - } - // we're only creating the very last entry in the path - else { - dirEnd = dir + StrLen(dir); - } - - bool result = true; - for (wchar_t saveChar = L' '; saveChar; *dirEnd++ = saveChar) { - // find the end of the current directory string and terminate it - dirEnd = PathSkipOverSeparator(dirEnd); - saveChar = *dirEnd; - *dirEnd = 0; - - // create the directory and track the result from the last call - result = CreateDirectoryW(dir, (LPSECURITY_ATTRIBUTES) nil); - } - - // if we successfully created the directory then we're done - if (result) { - // Avoid check for kPathCreateDirFlagOsError - static_assert(kPathCreateDirSuccess == NO_ERROR, "Path creation success and NO_ERROR constants differ"); - return kPathCreateDirSuccess; - } - - unsigned error = GetLastError(); - switch (error) { - case ERROR_ACCESS_DENIED: - return kPathCreateDirErrAccessDenied; - - case ERROR_ALREADY_EXISTS: { - DWORD attrib; - if (0xffffffff == (attrib = GetFileAttributesW(dir))) - return kPathCreateDirErrInvalidPath; - - if (! (attrib & FILE_ATTRIBUTE_DIRECTORY)) - return kPathCreateDirErrFileWithSameName; - - if (flags & kPathCreateDirFlagCreateNew) - return kPathCreateDirErrDirExists; - } - return kPathCreateDirSuccess; - - default: - return kPathCreateDirErrInvalidPath; - } -} - -//=========================================================================== -bool PathDoesFileExist (const wchar_t fileName[]) { - uint32_t attributes = GetFileAttributesW(fileName); - if (attributes == (uint32_t) -1) - return false; - if (attributes & FILE_ATTRIBUTE_DIRECTORY) - return false; - return true; -} - diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h index fc83886e..b0e2fc9c 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h @@ -59,7 +59,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtTime.h" #include "pnUtStr.h" #include "pnUtRef.h" -#include "pnUtPath.h" #include "pnUtCmd.h" #include "pnUtMisc.h" #include "pnUtCrypt.h" diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.cpp deleted file mode 100644 index 95df9bb7..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.cpp -* -***/ - -#include "pnUtPath.h" -#include "pnUtStr.h" - - -/**************************************************************************** -* -* Exported functions -* -***/ - -//=========================================================================== -void PathGetProgramDirectory ( - wchar_t *dst, - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - - PathGetProgramName(dst, dstChars); - PathRemoveFilename(dst, dst, dstChars); -} - -//=========================================================================== -void PathAddFilename ( - wchar_t *dst, - const wchar_t src[], - const wchar_t fname[], - unsigned dstChars -) { - ASSERT(dst); - ASSERT(dstChars); - - wchar_t temp[MAX_PATH]; - if (dst == src) { - StrCopy(temp, src, arrsize(temp)); - src = temp; - } - else if (dst == fname) { - StrCopy(temp, fname, arrsize(temp)); - fname = temp; - } - - PathMakePath(dst, dstChars, 0, src, fname, 0); -} - -//=========================================================================== -void PathRemoveFilename ( - wchar_t *dst, - const wchar_t src[], - unsigned dstChars -) { - ASSERT(dst); - ASSERT(src); - ASSERT(dstChars); - - wchar_t drive[MAX_DRIVE]; - wchar_t dir[MAX_DIR]; - PathSplitPath(src, drive, dir, 0, 0); - PathMakePath(dst, dstChars, drive, dir, 0, 0); -} - -/***************************************************************************** -* -* Email formatting functions -* -***/ - -//============================================================================ -void PathSplitEmail ( - const wchar_t emailAddr[], - wchar_t * user, - unsigned userChars, - wchar_t * domain, - unsigned domainChars, - wchar_t * tld, - unsigned tldChars, - wchar_t * subDomains, - unsigned subDomainChars, - unsigned subDomainCount -) { - ASSERT(emailAddr); - - #define SUB_DOMAIN(i) subDomains[(i) * subDomainChars] - - // null-terminate all output parameters - if (userChars) { - ASSERT(user); - user[0] = 0; - } - if (domainChars) { - ASSERT(domain); - domain[0] = 0; - } - if (tldChars) { - ASSERT(tld); - tld[0] = 0; - } - if (subDomainChars || subDomainCount) { - ASSERT(subDomains); - for (unsigned i = 0; i < subDomainCount; ++i) - SUB_DOMAIN(i) = 0; - } - - // bail now if email address is zero-length - unsigned len = StrLen(emailAddr); - if (!len) - return; - - // copy email address so we can tokenize it - wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1)); - StrCopy(tmp, emailAddr, len + 1); - const wchar_t * work = tmp; - - // parse user - wchar_t token[MAX_PATH]; - if (!StrTokenize(&work, token, arrsize(token), L"@")) - return; - - // copy user to output parameter - if (userChars) - StrCopy(user, token, userChars); - - // skip past the '@' symbol - if (!*work++) - return; - - // parse all domains - ARRAY(wchar_t *) arr; - while (StrTokenize(&work, token, arrsize(token), L".")) { - unsigned toklen = StrLen(token); - wchar_t * str = (wchar_t*)malloc(sizeof(wchar_t) * (toklen + 1)); - StrCopy(str, token, toklen + 1); - arr.Add(str); - - free(str); - } - - // copy domains to output parameters - unsigned index = 0; - if (arr.Count() > 2) { - // all domains except for the last two are sub-domains - for (index = 0; index < arr.Count() - 2; ++index) { - if (index < subDomainCount) - if (subDomains) - StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars); - } - } - if (arr.Count() > 1) { - // second to last domain is the primary domain - if (domain) - StrCopy(domain, arr[index], domainChars); - // last comes the top level domain - ++index; - if (tld) - StrCopy(tld, arr[index], tldChars); - } - else if (arr.Count() == 1) { - // if only one domain, return it as a sub-domain - if (index < subDomainCount) - if (subDomains) - StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars); - } - - free(tmp); - - #undef SUB_DOMAIN -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h deleted file mode 100644 index 63310dcf..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtPath.h +++ /dev/null @@ -1,219 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H - -#include "Pch.h" -#include "pnUtArray.h" - -/***************************************************************************** -* -* Path definitions -* -***/ - -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - -#define MAX_DRIVE 256 -#define MAX_DIR 256 -#define MAX_FNAME 256 -#define MAX_EXT 256 - - - -const unsigned kPathFlagFile = 1<<0; -const unsigned kPathFlagDirectory = 1<<1; -const unsigned kPathFlagHidden = 1<<2; -const unsigned kPathFlagSystem = 1<<3; -const unsigned kPathFlagRecurse = 1<<4; // also set if "**" used in filespec - -struct PathFind { - unsigned flags; - uint64_t fileLength; - uint64_t lastWriteTime; - wchar_t name[MAX_PATH]; -}; - - -/***************************************************************************** -* -* Path "get" functions -* -***/ - -void PathFindFiles ( - ARRAY(PathFind) * paths, - const wchar_t fileSpec[], - unsigned pathFlags -); -void PathGetProgramName ( - wchar_t * dst, - unsigned dstChars -); - -bool PathDoesFileExist ( - const wchar_t fileName[] -); - - -/***************************************************************************** -* -* Path building functions -* -***/ - -void PathSplitPath ( - const wchar_t path[], - wchar_t * drive, - wchar_t * dir, - wchar_t * fname, - wchar_t * ext -); - -void PathMakePath ( - wchar_t * path, - unsigned chars, - const wchar_t drive[], - const wchar_t dir[], - const wchar_t fname[], - const wchar_t ext[] -); - -// c:\dir1 + dir2\file.txt => c:\dir1\dir2\file.txt -void PathAddFilename ( - wchar_t * dst, - const wchar_t src[], - const wchar_t fname[], - unsigned dstChars -); - -// c:\dir1\dir2\file.txt => c:\dir1\dir2\ * note trailing backslash -void PathRemoveFilename ( - wchar_t * dst, - const wchar_t src[], - unsigned dstChars -); - - -/***************************************************************************** -* -* Directory functions -* -***/ - -// Create directory -enum EPathCreateDirError { - kPathCreateDirSuccess, - kPathCreateDirErrInvalidPath, - kPathCreateDirErrAccessDenied, - kPathCreateDirErrFileWithSameName, - kPathCreateDirErrDirExists, // Directory exists and kPathCreateDirFlagCreateNew was specified -}; - -// Setting this flag causes the function to create the entire directory -// tree from top to bottom. Clearing this flag causes the function to -// create only the last entry in the path. -const unsigned kPathCreateDirFlagEntireTree = 1<<0; - -// Setting this flag causes the function to create the last entry in the path -// ONLY if it doesn't already exist. If it does exist the function will return -// kPathCreateDirErrDirExistes. -const unsigned kPathCreateDirFlagCreateNew = 1<<1; - - -EPathCreateDirError PathCreateDirectory ( - const wchar_t path[], - unsigned flags -); - - - -// Get directory -void PathGetProgramDirectory ( - wchar_t * dst, - unsigned dstChars -); - - -// Product and user-specific common directory locations -void PathGetUserDirectory ( - wchar_t * dst, - unsigned dstChars -); -void PathGetLogDirectory ( - wchar_t * dst, - unsigned dstChars -); -void PathGetInitDirectory ( - wchar_t * dst, - unsigned dstChars -); - - -/***************************************************************************** -* -* Email formatting functions -* -***/ - -// you may send nil for any fields you don't care about -void PathSplitEmail ( - const wchar_t emailAddr[], - wchar_t * user, - unsigned userChars, - wchar_t * domain, - unsigned domainChars, - wchar_t * tld, - unsigned tldChars, - wchar_t * subDomains, // (wchar_t *)&subs --> wchar_t subs[16][256]; - unsigned subDomainChars, // arrsize(subs[0]) --> 256 - unsigned subDomainCount // arrsize(subs) --> 16 -); -#endif diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp index c18d46ea..d8278073 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp @@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "plAgeDescription.h" -#include "plFile/hsFiles.h" #include "plFile/plInitFileReader.h" #include "plFile/plEncryptedStream.h" #include "hsStringTokenizer.h" @@ -53,44 +52,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 +96,31 @@ void plAgePage::SetFlags(uint8_t f, bool on) } // now preservs original string -bool plAgePage::SetFromString( const char *stringIn ) +bool plAgePage::SetFromString( const plString &stringIn ) { - char *c, seps[] = ", \n"; - std::string string = stringIn; - // Parse. Format is going to be "pageName[,seqSuffix[,flags]]" - c = strtok( (char*)string.c_str(), seps ); - if( c == nil ) + std::vector 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 +149,9 @@ plAgeDescription::~plAgeDescription() void plAgeDescription::IDeInit() { ClearPageList(); - delete [] fName; } -plAgeDescription::plAgeDescription( const char *fileNameToReadFrom ) : plInitSectionTokenReader() +plAgeDescription::plAgeDescription( const plFileName &fileNameToReadFrom ) : plInitSectionTokenReader() { ReadFromFile(fileNameToReadFrom); } @@ -190,7 +159,7 @@ plAgeDescription::plAgeDescription( const char *fileNameToReadFrom ) : plInitSec // // Reads from a file, returns false if failed. // -bool plAgeDescription::ReadFromFile( const char *fileNameToReadFrom ) +bool plAgeDescription::ReadFromFile( const plFileName &fileNameToReadFrom ) { IInit(); @@ -206,38 +175,20 @@ bool plAgeDescription::ReadFromFile( const char *fileNameToReadFrom ) return true; } -void plAgeDescription::SetAgeNameFromPath( const char *path ) +void plAgeDescription::SetAgeNameFromPath( const plFileName &path ) { - delete [] fName; - - if( path == nil ) + if (!path.IsValid()) { - fName = nil; + fName = ""; return; } - // Construct our name from the path - const char *pathSep1 = strrchr( path, '\\' ); - const char *pathSep2 = strrchr( path, '/' ); - if( pathSep2 > pathSep1 ) - pathSep1 = pathSep2; - if( pathSep1 == nil ) - pathSep1 = (char *)path; - else - pathSep1++; // Get past the actual character we found - - char temp[ 512 ]; - strcpy( temp, pathSep1 ); - char *end = strrchr( temp, '.' ); - if( end != nil ) - *end = 0; - - fName = hsStrcpy( temp ); + fName = path.GetFileNameNoExt(); } -void plAgeDescription::IInit( void ) +void plAgeDescription::IInit( void ) { - fName = nil; + fName = ""; fDayLength = 24.0f; fMaxCapacity = -1; fLingerTime = 180; // seconds @@ -248,14 +199,12 @@ void plAgeDescription::IInit( void ) fPageIterator = -1; } -struct SzDelete { void operator()(char * str) { delete [] str;} }; void plAgeDescription::ClearPageList() { fPages.Reset(); } - -void plAgeDescription::AppendPage( const char *name, int seqSuffix, uint8_t flags ) +void plAgeDescription::AppendPage( const plString &name, int seqSuffix, uint8_t flags ) { fPages.Append( plAgePage( name, ( seqSuffix == -1 ) ? fPages.GetCount() : (uint32_t)seqSuffix, flags ) ); } @@ -280,35 +229,30 @@ plAgePage *plAgeDescription::GetNextPage( void ) return ret; } -void plAgeDescription::RemovePage( const char *page ) +void plAgeDescription::RemovePage( const plString &page ) { - int i; - - for( i = 0; i < fPages.GetCount(); i++ ) + for (int i = 0; i < fPages.GetCount(); i++) { - if( strcmp( page, fPages[ i ].GetName() ) == 0 ) + if (page == fPages[i].GetName()) { - fPages.Remove( i ); + fPages.Remove(i); return; } } } -plAgePage *plAgeDescription::FindPage( const char *name ) const +plAgePage *plAgeDescription::FindPage( const plString &name ) const { - int i; - - - for( i = 0; i < fPages.GetCount(); i++ ) + for (int i = 0; i < fPages.GetCount(); i++) { - if( strcmp( name, fPages[ i ].GetName() ) == 0 ) - return &fPages[ i ]; + if (name == fPages[i].GetName()) + return &fPages[i]; } return nil; } -plLocation plAgeDescription::CalcPageLocation( const char *page ) const +plLocation plAgeDescription::CalcPageLocation( const plString &page ) const { plAgePage *ap = FindPage( page ); if( ap != nil ) @@ -334,10 +278,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 +324,7 @@ void plAgeDescription::Write(hsStream* stream) const int i; for( i = 0; i < fPages.GetCount(); i++ ) { - sprintf(buf, "Page=%s\n", fPages[ i ].GetAsString() ); + sprintf(buf, "Page=%s\n", fPages[ i ].GetAsString().c_str() ); stream->WriteString(buf); } } @@ -537,7 +481,7 @@ void plAgeDescription::AppendCommonPages( void ) void plAgeDescription::CopyFrom(const plAgeDescription& other) { IDeInit(); - fName = hsStrcpy(other.GetAgeName()); + fName = other.GetAgeName(); int i; for(i=0;i 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..eac3f999 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp @@ -51,24 +51,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAgeManifest.h" -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plFile/plInitFileReader.h" #include "hsStringTokenizer.h" //// plManifestFile /////////////////////////////////////////////////////// -plManifestFile::plManifestFile(const char* name, const char* serverPath, const plMD5Checksum& check, uint32_t size, uint32_t zippedSize, uint32_t flags, bool md5Now) : +plManifestFile::plManifestFile(const plFileName& name, const plFileName& serverPath, + const plMD5Checksum& check, uint32_t size, uint32_t zippedSize, + uint32_t flags, bool md5Now) : + fName(name), + fServerPath(serverPath), fChecksum(check), fSize(size), fZippedSize(zippedSize), fFlags(flags), fMd5Checked(md5Now) { - fName = name; - fServerPath = serverPath; - if (md5Now) { DoMd5Check(); @@ -81,9 +80,9 @@ plManifestFile::~plManifestFile() void plManifestFile::DoMd5Check() { - if (plFileUtils::FileExists(fName.c_str())) + if (plFileInfo(fName).Exists()) { - plMD5Checksum localFile(fName.c_str()); + plMD5Checksum localFile(fName); fIsLocalUpToDate = (localFile == fChecksum); fLocalExists = true; } 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..8cb3b69e 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plWin32StreamingSound.cpp @@ -44,7 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsGeometry3.h" #include "plgDispatch.h" #include "plProfile.h" -#include "plFile/hsFiles.h" #include "plWin32Sound.h" #include "plWin32StreamingSound.h" @@ -91,9 +90,6 @@ plWin32StreamingSound::~plWin32StreamingSound() IUnloadDataBuffer(); delete fDataStream; - fDataStream = nil; - fSrcFilename[ 0 ] = 0; - delete fDeswizzler; } @@ -117,11 +113,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 +127,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh return plSoundBuffer::kError; // The databuffer also needs to know if the source is compressed or not - if(fNewFilename.length()) + if (fNewFilename.IsValid()) { - buffer->SetFileName(fNewFilename.c_str()); + buffer->SetFileName(fNewFilename); buffer->SetFlag(plSoundBuffer::kStreamCompressed, fIsCompressed); - fNewFilename.clear(); + fNewFilename = ""; if(fReallyPlaying) { fPlayWhenStopped = true; @@ -172,8 +168,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh } } - char str[ 256 ]; - strncpy( fSrcFilename, buffer->GetFileName(), sizeof( fSrcFilename ) ); + fSrcFilename = buffer->GetFileName(); bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0); delete fDataStream; @@ -185,20 +180,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 +195,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh return plSoundBuffer::kError; } - sprintf( str, " Readied file %s for streaming", fSrcFilename ); - IPrintDbgMessage( str ); + IPrintDbgMessage(plString::Format(" Readied file %s for streaming", fSrcFilename.AsString().c_str()).c_str()); // dont free sound data until we have a chance to use it in load sound @@ -227,11 +215,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 +291,10 @@ bool plWin32StreamingSound::LoadSound( bool is3D ) delete fDSoundBuffer; fDSoundBuffer = nil; - char str[256]; - sprintf(str, "Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file. Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.", GetFileName()); - IPrintDbgMessage( str, true ); + plString str = plString::Format("Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file." + " Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.", + GetFileName().AsString().c_str()); + IPrintDbgMessage(str.c_str(), true); fFailed = true; return false; } 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..db125f4b 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plAudioFileReader.cpp @@ -55,8 +55,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAudioCore.h" //#include "hsTimer.h" -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "plUnifiedTime/plUnifiedTime.h" #include "plBufferedFileReader.h" #include "plCachedFileReader.h" @@ -66,20 +64,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define kCacheDirName "temp" -plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore::ChannelSelect whichChan, StreamType type) +plAudioFileReader* plAudioFileReader::CreateReader(const plFileName& path, plAudioCore::ChannelSelect whichChan, StreamType type) { - const char* ext = plFileUtils::GetFileExt(path); + plString ext = path.GetFileExt(); if (type == kStreamWAV) { - bool isWav = (stricmp(ext, "wav") == 0); + bool isWav = (ext.CompareI("wav") == 0); // We want to stream a wav off disk, but this is a compressed file. // Get the uncompressed path. Ignore the requested channel, since it // will have already been split into two files if that is necessary. if (!isWav) { - char cachedPath[256]; - IGetCachedPath(path, cachedPath, whichChan); + plFileName cachedPath = IGetCachedPath(path, whichChan); plAudioFileReader *r = new plCachedFileReader(cachedPath, plAudioCore::kAll); if (!r->IsValid()) { // So we tried to play a cached file and it didn't exist @@ -102,43 +99,37 @@ plAudioFileReader* plAudioFileReader::CreateReader(const char* path, plAudioCore return nil; } -plAudioFileReader* plAudioFileReader::CreateWriter(const char* path, plWAVHeader& header) +plAudioFileReader* plAudioFileReader::CreateWriter(const plFileName& path, plWAVHeader& header) { - const char* ext = plFileUtils::GetFileExt(path); - plAudioFileReader* writer = new plCachedFileReader(path, plAudioCore::kAll); writer->OpenForWriting(path, header); return writer; } -void plAudioFileReader::IGetCachedPath(const char* path, char* cachedPath, plAudioCore::ChannelSelect whichChan) +plFileName plAudioFileReader::IGetCachedPath(const plFileName& path, plAudioCore::ChannelSelect whichChan) { // Get the file's path and add our streaming cache folder to it - strcpy(cachedPath, path); - plFileUtils::StripFile(cachedPath); - strcat(cachedPath, kCacheDirName"\\"); + plFileName cachedPath = plFileName::Join(path.StripFileName(), kCacheDirName); // Create the directory first - plFileUtils::CreateDir(cachedPath); - - // Get the path to the cached version of the file, without the extension - const char* fileName = plFileUtils::GetFileName(path); - const char* fileExt = plFileUtils::GetFileExt(fileName); - strncat(cachedPath, fileName, fileExt-fileName-1); + plFileSystem::CreateDir(cachedPath); + const char *suffix = ""; if (whichChan == plAudioCore::kLeft) - strcat(cachedPath, "-Left.tmp"); + suffix = "-Left.tmp"; else if (whichChan == plAudioCore::kRight) - strcat(cachedPath, "-Right.tmp"); + suffix = "-Right.tmp"; else if (whichChan == plAudioCore::kAll) - strcat(cachedPath, ".tmp"); + suffix = ".tmp"; + + // Get the path to the cached version of the file, without the extension + return plFileName::Join(cachedPath, path.GetFileNameNoExt() + suffix); } -void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCore::ChannelSelect whichChan) +void plAudioFileReader::ICacheFile(const plFileName& path, bool noOverwrite, plAudioCore::ChannelSelect whichChan) { - char cachedPath[256]; - IGetCachedPath(path, cachedPath, whichChan); - if (!noOverwrite || !plFileUtils::FileExists(cachedPath)) + plFileName cachedPath = IGetCachedPath(path, whichChan); + if (!noOverwrite || !plFileInfo(cachedPath).Exists()) { plAudioFileReader* reader = plAudioFileReader::CreateReader(path, whichChan, kStreamNative); if (!reader || !reader->IsValid()) @@ -169,7 +160,7 @@ void plAudioFileReader::ICacheFile(const char* path, bool noOverwrite, plAudioCo } } -void plAudioFileReader::CacheFile(const char* path, bool splitChannels, bool noOverwrite) +void plAudioFileReader::CacheFile(const plFileName& path, bool splitChannels, bool noOverwrite) { if (splitChannels) { 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..0b8ca2cc 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp @@ -49,35 +49,30 @@ 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 +110,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 +161,7 @@ plSoundBuffer::plSoundBuffer() IInitBuffer(); } -plSoundBuffer::plSoundBuffer( const char *fileName, uint32_t flags ) +plSoundBuffer::plSoundBuffer( const plFileName &fileName, uint32_t flags ) { IInitBuffer(); SetFileName( fileName ); @@ -186,7 +181,6 @@ plSoundBuffer::~plSoundBuffer() } } - delete [] fFileName; UnLoad(); } @@ -194,7 +188,7 @@ void plSoundBuffer::IInitBuffer() { fError = false; fValid = false; - fFileName = nil; + fFileName = ""; fData = nil; fDataLength = 0; fFlags = 0; @@ -225,7 +219,7 @@ void plSoundBuffer::Read( hsStream *s, hsResMgr *mgr ) s->ReadLE( &fFlags ); s->ReadLE( &fDataLength ); - fFileName = s->ReadSafeString(); + fFileName = s->ReadSafeString_TEMP(); s->ReadLE( &fHeader.fFormatTag ); s->ReadLE( &fHeader.fNumChannels ); @@ -266,16 +260,10 @@ void plSoundBuffer::Write( hsStream *s, hsResMgr *mgr ) s->WriteLE( fDataLength ); // Truncate the path to just a file name on write - if( fFileName != nil ) - { - char *nameOnly = strrchr( fFileName, '\\' ); - if( nameOnly != nil ) - s->WriteSafeString( nameOnly + 1 ); - else - s->WriteSafeString( fFileName ); - } + if (fFileName.IsValid()) + s->WriteSafeString(fFileName.GetFileName()); else - s->WriteSafeString( "" ); + s->WriteSafeString(""); s->WriteLE( fHeader.fFormatTag ); s->WriteLE( fHeader.fNumChannels ); @@ -290,7 +278,7 @@ void plSoundBuffer::Write( hsStream *s, hsResMgr *mgr ) //// SetFileName ///////////////////////////////////////////////////////////// -void plSoundBuffer::SetFileName( const char *name ) +void plSoundBuffer::SetFileName( const plFileName &name ) { if(fLoading) { @@ -298,11 +286,7 @@ void plSoundBuffer::SetFileName( const char *name ) return; } - delete [] fFileName; - if( name != nil ) - fFileName = hsStrcpy( name ); - else - fFileName = nil; + fFileName = name; // Data is no longer valid UnLoad(); @@ -325,22 +309,17 @@ plAudioCore::ChannelSelect plSoundBuffer::GetReaderSelect( void ) const //// IGetFullPath //////////////////////////////////////////////////////////// // Construct our current full path to our sound. -void plSoundBuffer::IGetFullPath( char *destStr ) +plFileName plSoundBuffer::IGetFullPath() { - if(!fFileName) + if (!fFileName.IsValid()) { - *destStr = 0; - return; + return plFileName(); } - char path[ kFolderIterator_MaxPath ]; - - if( strchr( fFileName, '\\' ) != nil ) - strcpy( path, fFileName ); - else - sprintf( path, "sfx\\%s", fFileName ); + if (fFileName.StripFileName().IsValid()) + return fFileName; - strcpy( destStr, path ); + return plFileName::Join("sfx", fFileName); } @@ -459,8 +438,9 @@ void plSoundBuffer::SetLoaded(bool loaded) void plSoundBuffer::SetInternalData( plWAVHeader &header, uint32_t length, uint8_t *data ) { - if(fLoading) return; - fFileName = nil; + if (fLoading) + return; + fFileName = ""; fHeader = header; fFlags = 0; @@ -509,11 +489,9 @@ plSoundBuffer::ELoadReturnVal plSoundBuffer::EnsureInternal() //// IGrabHeaderInfo ///////////////////////////////////////////////////////// bool plSoundBuffer::IGrabHeaderInfo( void ) { - static char path[ 512 ]; - - if( fFileName != nil ) + if (fFileName.IsValid()) { - IGetFullPath( path ); + plFileName path = IGetFullPath(); // Go grab from the WAV file if(!fReader) @@ -545,10 +523,11 @@ bool plSoundBuffer::IGrabHeaderInfo( void ) // fullpath tells the function whether to append 'sfx' to the path or not (we don't want to do this if were providing the full path) plAudioFileReader *plSoundBuffer::IGetReader( bool fullpath ) { - char path[512]; - if(fullpath) IGetFullPath(path); + plFileName path; + if (fullpath) + path = IGetFullPath(); else - strcpy(path, fFileName); + path = fFileName; // Go grab from the WAV file plAudioFileReader::StreamType type = plAudioFileReader::kStreamWAV; 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..05a735af 100644 --- a/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plFile/CMakeLists.txt @@ -5,28 +5,16 @@ include_directories("../../PubUtilLib") include_directories(${ZLIB_INCLUDE_DIR}) set(plFile_SOURCES - hsFiles.cpp plBrowseFolder.cpp plEncryptedStream.cpp - plFileUtils.cpp plInitFileReader.cpp plSecureStream.cpp plStreamSource.cpp ) -if(WIN32 AND NOT CYGWIN) - set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Win.cpp) -endif(WIN32 AND NOT CYGWIN) - -if(UNIX) - set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Unix.cpp) -endif(UNIX) - set(plFile_HEADERS - hsFiles.h plBrowseFolder.h plEncryptedStream.h - plFileUtils.h plInitFileReader.h plSecureStream.h plStreamSource.h diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp b/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp deleted file mode 100644 index 0f97be96..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "hsFiles.h" -#include - - -#include "hsExceptions.h" - -#if HS_BUILD_FOR_WIN32 - #define kDirChar '\\' -#else - #define kDirChar '/' -#endif - - -static const char* FindNameInPath(const char path[]) -{ - const char* name = ::strrchr(path, kDirChar); - - if (name == nil) - name = path; - return name; -} - -/////////////////////////////////////////////////////////////////////// - -hsFile::hsFile() : fPathAndName(nil), fFILE(nil) -{ -} - -hsFile::hsFile(const char pathAndName[]) : fPathAndName(nil), fFILE(nil) -{ - if (pathAndName) - fPathAndName = hsStrcpy(pathAndName); -} - -hsFile::~hsFile() -{ - this->SetPathAndName(nil); -} - -const char* hsFile::GetPathAndName() -{ - return fPathAndName; -} - -void hsFile::SetPathAndName(const char pathAndName[]) -{ - this->Close(); - - if (fPathAndName) - { delete[] fPathAndName; - fPathAndName = nil; - } - if (pathAndName) - fPathAndName = hsStrcpy(pathAndName); -} - -const char* hsFile::GetName() -{ - return FindNameInPath(this->GetPathAndName()); -} - -FILE* hsFile::OpenFILE(const char mode[], bool throwIfFailure) -{ - this->Close(); - - // We call the virtual method here rather than using - // fPathAndName directly, allowing a subclass to construct - // the name if necessary - // - const char* name = this->GetPathAndName(); - if (name) - fFILE = ::fopen(name, mode); - - hsThrowIfTrue(throwIfFailure && fFILE == nil); - return fFILE; -} - -hsStream* hsFile::OpenStream(const char mode[], bool throwIfFailure) -{ - FILE* file = this->OpenFILE(mode, throwIfFailure); - - if (file) - { hsUNIXStream* stream = new hsUNIXStream; - stream->SetFILE(file); - return stream; - } - return nil; -} - -void hsFile::Close() -{ - if (fFILE) - { int err = ::fflush(fFILE); - hsIfDebugMessage(err != 0, "fflush failed", err); - err = ::fclose(fFILE); - hsIfDebugMessage(err != 0, "fclose failed", err); - fFILE = nil; - } -} - -/////////////////////////////////////////////////////////////////////// - -bool hsFolderIterator::NextFileSuffix(const char suffix[]) -{ - while (this->NextFile()) - { const char* fileSuffix = ::strrchr(this->GetFileName(), '.'); - if (fileSuffix != nil && stricmp(fileSuffix, suffix) == 0) - return true; - } - return false; -} - -int hsFolderIterator::GetPathAndName(char pathandname[]) -{ - hsAssert(pathandname, "NULL path string"); - const char* name = this->GetFileName(); - int pathLen = strlen(fPath); - - // add 1 for null terminator - int totalLen = pathLen + sizeof(kDirChar) + strlen(name) + 1; - hsAssert(totalLen <= kFolderIterator_MaxPath, "Overrun kFolderIterator_MaxPath"); - - if (pathandname) - { - strcpy(pathandname, fPath); - if (pathLen > 0 && pathandname[pathLen - 1] != kDirChar) - pathandname[pathLen++] = kDirChar; - strcpy(pathandname + pathLen, name); - } - return totalLen; -} - -FILE* hsFolderIterator::OpenFILE(const char mode[]) -{ - char fileName[kFolderIterator_MaxPath]; - - (void)this->GetPathAndName(fileName); - - return ::fopen(fileName, mode); -} - diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles.h b/Sources/Plasma/PubUtilLib/plFile/hsFiles.h deleted file mode 100644 index 2217e734..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles.h +++ /dev/null @@ -1,141 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef hsFiles_Defined -#define hsFiles_Defined - -#include "hsStream.h" -#include - -#if HS_BUILD_FOR_UNIX - #include - #define kFolderIterator_MaxPath PATH_MAX - #define SetCurrentDirectory chdir -#else - #define kFolderIterator_MaxPath _MAX_PATH -#endif - - -/////////////////////////////////////////////////////////////////////// - -class hsFile { - hsFile& operator=(const hsFile&); // disallow assignment -protected: - char* fPathAndName; - FILE* fFILE; -public: - hsFile(); - hsFile(const char pathAndName[]); - virtual ~hsFile(); - - const char* GetName(); - virtual const char* GetPathAndName(); - virtual void SetPathAndName(const char pathAndName[]); - - virtual FILE* OpenFILE(const char mode[], bool throwIfFailure = false); - virtual hsStream* OpenStream(const char mode[], bool throwIfFailure = false); - - virtual void Close(); // called automatically in the destructor -}; -typedef hsFile hsUnixFile; // for compatibility -typedef hsFile hsOSFile; - -/////////////////////////////////////////////////////////////////////// - -class hsFolderIterator { - char fPath[kFolderIterator_MaxPath]; - struct hsFolderIterator_Data* fData; - bool fCustomFilter; -public: -#ifdef HS_BUILD_FOR_WIN32 - hsFolderIterator(const char path[] = nil, bool useCustomFilter=false); -#else - hsFolderIterator(const char path[] = nil, bool unused=true); - hsFolderIterator(const struct FSSpec* spec); // Alt constructor -#endif - virtual ~hsFolderIterator(); - - const char* GetPath() const { return fPath; } - void SetPath(const char path[]); - - void Reset(); - bool NextFile(); - bool NextFileSuffix(const char suffix[]); - const char* GetFileName() const; - int GetPathAndName(char pathandname[] = nil); - bool IsDirectory( void ) const; - - FILE* OpenFILE(const char mode[]); - -#if HS_BUILD_FOR_WIN32 - void SetWinSystemDir(const char subdir[]); // e.g. "Fonts" - void SetFileFilterStr(const char filterStr[]); // e.g. "*.*" -#endif -}; - -#ifdef HS_BUILD_FOR_WIN32 -// only implemented on Win32 for now -class hsWFolderIterator { - wchar_t fPath[kFolderIterator_MaxPath]; - struct hsWFolderIterator_Data* fData; - bool fCustomFilter; -public: - hsWFolderIterator(const wchar_t path[] = nil, bool useCustomFilter=false); - virtual ~hsWFolderIterator(); - - const wchar_t* GetPath() const { return fPath; } - void SetPath(const wchar_t path[]); - - void Reset(); - bool NextFile(); - bool NextFileSuffix(const wchar_t suffix[]); - const wchar_t* GetFileName() const; - int GetPathAndName(wchar_t pathandname[] = nil); - bool IsDirectory( void ) const; - - FILE* OpenFILE(const wchar_t mode[]); - - void SetWinSystemDir(const wchar_t subdir[]); // e.g. "Fonts" - void SetFileFilterStr(const wchar_t filterStr[]); // e.g. "*.*" -}; -#endif - -#endif diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp b/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp deleted file mode 100644 index 5864f42a..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "hsFiles.h" - -#if HS_BUILD_FOR_UNIX - -#include -#include -#include -#include -#include -#include -#include -#include -#include "hsTemplates.h" -#include "plFileUtils.h" - -struct hsFolderIterator_Data { - glob_t fGlobBuf; - bool fInited; - int fCnt; - hsFolderIterator_Data() : fInited(false), fCnt(0) {} - // ~hsFolderIterator_Data() { fInited=false; globfree(&fData->fGlobBuf); } -}; - -hsFolderIterator::hsFolderIterator(const char path[], bool) -{ - fData = new hsFolderIterator_Data; - - this->SetPath(path); -} - -hsFolderIterator::~hsFolderIterator() -{ - this->Reset(); - delete fData; -} - -void hsFolderIterator::SetPath(const char path[]) -{ - fPath[0] = 0; - if (path) - { - ::strcpy(fPath, path); - } - this->Reset(); -} - -void hsFolderIterator::Reset() -{ - if (fData->fInited) - { - globfree(&fData->fGlobBuf); - fData->fCnt = 0; - fData->fInited=false; - } -} -bool hsFolderIterator::NextFile() -{ - if (fData->fInited == false) - { - std::string path=fPath; - if(!(strchr(fPath,'*') || strchr(fPath,'?') || strchr(fPath,'['))) - { - if (fPath[strlen(fPath)-1] != PATH_SEPARATOR) - path = path + PATH_SEPARATOR_STR + "*"; - else - path = path + "*"; - } - - if(glob(path.c_str(), 0, NULL, &fData->fGlobBuf) != 0 ) { - return false; - } - fData->fInited=true; - fData->fCnt = 0; - } - - return fData->fCnt++ < fData->fGlobBuf.gl_pathc; -} - -const char* hsFolderIterator::GetFileName() const -{ - if (!fData->fInited || fData->fCnt > fData->fGlobBuf.gl_pathc) - throw "end of folder"; - - const char* fn=fData->fGlobBuf.gl_pathv[fData->fCnt-1]; - return plFileUtils::GetFileName(fn); -} - -bool hsFolderIterator::IsDirectory( void ) const -{ - // rob, please forgive me, this is my best attempt... - if(fData->fCnt > fData->fGlobBuf.gl_pathc ) - return false; - - struct stat info; - const char* fn=fData->fGlobBuf.gl_pathv[fData->fCnt-1]; - if( stat( fn, &info ) ) - { - printf("Error calling stat(): %s errno=%d\n", strerror(errno), errno); - return false; - } - return ( info.st_mode & S_IFDIR ) ? true : false; -} - -#endif - diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Win.cpp b/Sources/Plasma/PubUtilLib/plFile/hsFiles_Win.cpp deleted file mode 100644 index 002682db..00000000 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles_Win.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "hsFiles.h" -#include "HeadSpin.h" -#include "hsWindows.h" - -#if HS_BUILD_FOR_WIN32 - -#include "hsExceptions.h" - -struct hsFolderIterator_Data { - HANDLE fSearchHandle; - WIN32_FIND_DATA fFindData; - bool fValid; -}; - -hsFolderIterator::hsFolderIterator(const char path[], bool useCustomFilter) -{ - fCustomFilter = useCustomFilter; - - fData = new hsFolderIterator_Data; - fData->fSearchHandle = nil; - fData->fValid = true; - - if(useCustomFilter) - { - this->SetFileFilterStr(path); - } - else - { - this->SetPath(path); - } -} - -hsFolderIterator::~hsFolderIterator() -{ - delete fData; -} - -void hsFolderIterator::SetPath(const char path[]) -{ - fCustomFilter = false; - fPath[0] = 0; - if (path) - { - ::strcpy(fPath, path); - - // Make sure the dir ends with a slash - char lastchar = fPath[strlen(fPath)-1]; - if (lastchar != '\\' && lastchar != '/') - strcat(fPath, "\\"); - } - - this->Reset(); -} - -void hsFolderIterator::SetWinSystemDir(const char subdir[]) -{ - int ret = GetWindowsDirectory(fPath, _MAX_PATH); - hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath"); - - if (subdir) - { ::strcat(fPath, "\\"); - ::strcat(fPath, subdir); - ::strcat(fPath, "\\"); - } - this->Reset(); -} - -void hsFolderIterator::SetFileFilterStr(const char filterStr[]) -{ - fPath[0] = 0; - if (filterStr) - { - fCustomFilter = true; - ::strcpy(fPath, filterStr); - } - - this->Reset(); -} - -/////////////////////////////////////////////////////////////////////////////// - -void hsFolderIterator::Reset() -{ - if (fData->fSearchHandle) - { FindClose(fData->fSearchHandle); - fData->fSearchHandle = nil; - } - fData->fValid = true; -} - -bool hsFolderIterator::NextFile() -{ - if (fData->fValid == false) - return false; - - if (fData->fSearchHandle == nil) - { int len = ::strlen(fPath); - - if(fCustomFilter == false) - { - fPath[len] = '*'; - fPath[len+1] = 0; - } - - fData->fSearchHandle = FindFirstFile(fPath, &fData->fFindData); - fPath[len] = 0; - - if (fData->fSearchHandle == INVALID_HANDLE_VALUE) - { fData->fSearchHandle = nil; - fData->fValid = false; - return false; - } - } - else - { if (FindNextFile(fData->fSearchHandle, &fData->fFindData) == false) - { FindClose(fData->fSearchHandle); - fData->fSearchHandle = nil; - fData->fValid = false; - return false; - } - } - - return true; -} - -bool hsFolderIterator::IsDirectory( void ) const -{ - if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) - return true; - - return false; -} - -const char* hsFolderIterator::GetFileName() const -{ - if (fData->fValid == false) - hsThrow( "end of folder"); - - return fData->fFindData.cFileName; -} - -/////////////////////////////////////////////////////////////////////////////// - -struct hsWFolderIterator_Data { - HANDLE fSearchHandle; - WIN32_FIND_DATAW fFindData; - bool fValid; -}; - -hsWFolderIterator::hsWFolderIterator(const wchar_t path[], bool useCustomFilter) -{ - fCustomFilter = useCustomFilter; - - fData = new hsWFolderIterator_Data; - fData->fSearchHandle = nil; - fData->fValid = true; - - if(useCustomFilter) - SetFileFilterStr(path); - else - SetPath(path); -} - -hsWFolderIterator::~hsWFolderIterator() -{ - delete fData; -} - -void hsWFolderIterator::SetPath(const wchar_t path[]) -{ - fCustomFilter = false; - fPath[0] = 0; - if (path) - { - wcscpy(fPath, path); - - // Make sure the dir ends with a slash - wchar_t lastchar = fPath[wcslen(fPath)-1]; - if (lastchar != L'\\' && lastchar != L'/') - wcscat(fPath, L"\\"); - } - - Reset(); -} - -void hsWFolderIterator::SetWinSystemDir(const wchar_t subdir[]) -{ - int ret = GetWindowsDirectoryW(fPath, _MAX_PATH); - hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath"); - - if (subdir) - { - wcscat(fPath, L"\\"); - wcscat(fPath, subdir); - wcscat(fPath, L"\\"); - } - Reset(); -} - -void hsWFolderIterator::SetFileFilterStr(const wchar_t filterStr[]) -{ - fPath[0] = 0; - if (filterStr) - { - fCustomFilter = true; - wcscpy(fPath, filterStr); - } - - Reset(); -} - -/////////////////////////////////////////////////////////////////////////////// - -void hsWFolderIterator::Reset() -{ - if (fData->fSearchHandle) - { - FindClose(fData->fSearchHandle); - fData->fSearchHandle = nil; - } - fData->fValid = true; -} - -bool hsWFolderIterator::NextFile() -{ - if (fData->fValid == false) - return false; - - if (fData->fSearchHandle == nil) - { - int len = wcslen(fPath); - - if(fCustomFilter == false) - { - fPath[len] = L'*'; - fPath[len+1] = L'\0'; - } - - fData->fSearchHandle = FindFirstFileW(fPath, &fData->fFindData); - fPath[len] = 0; - - if (fData->fSearchHandle == INVALID_HANDLE_VALUE) - { - fData->fSearchHandle = nil; - fData->fValid = false; - return false; - } - } - else - { - if (FindNextFileW(fData->fSearchHandle, &fData->fFindData) == false) - { - FindClose(fData->fSearchHandle); - fData->fSearchHandle = nil; - fData->fValid = false; - return false; - } - } - - return true; -} - -bool hsWFolderIterator::IsDirectory( void ) const -{ - if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) - return true; - - return false; -} - -const wchar_t* hsWFolderIterator::GetFileName() const -{ - if (fData->fValid == false) - hsThrow( "end of folder"); - - return fData->fFindData.cFileName; -} - -#endif // HS_BUILD_FOR_WIN32 \ No newline at end of file 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 63cefc63..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 @@ -63,7 +62,6 @@ plEncryptedStream::plEncryptedStream(uint32_t* key) : fActualFileSize(0), fBufferedStream(false), fRAMStream(nil), - fWriteFileName(nil), fOpenMode(kOpenFail) { if (key) 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 8a43a260..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 @@ -72,7 +71,6 @@ fRef(INVALID_HANDLE_VALUE), fActualFileSize(0), fBufferedStream(false), fRAMStream(nil), -fWriteFileName(nil), fOpenMode(kOpenFail), fDeleteOnExit(deleteOnExit) { @@ -87,7 +85,6 @@ fRef(INVALID_HANDLE_VALUE), fActualFileSize(0), fBufferedStream(false), fRAMStream(nil), -fWriteFileName(nil), fOpenMode(kOpenFail), fDeleteOnExit(false) { diff --git a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp index d9d82580..adf125f6 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plStreamSource.cpp @@ -41,11 +41,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include -#include "hsFiles.h" #include "plStreamSource.h" #include "plSecureStream.h" #include "plEncryptedStream.h" -#include "plFileUtils.h" #if HS_BUILD_FOR_UNIX # include @@ -107,8 +105,7 @@ std::vector plStreamSource::GetListOfNames(const plFileName& dir, co // loop through all the file data records, and create the list std::vector retVal; - decltype(fFileData.begin()) curData; - for (curData = fFileData.begin(); curData != fFileData.end(); curData++) + for (auto curData = fFileData.begin(); curData != fFileData.end(); curData++) { if ((curData->second.fDir == sDir) && (curData->second.fExt == ext)) retVal.push_back(curData->second.fFilename); @@ -117,15 +114,11 @@ std::vector plStreamSource::GetListOfNames(const plFileName& dir, co #ifndef PLASMA_EXTERNAL_RELEASE // in internal releases, we can use on-disk files if they exist // Build the search string as "dir/*.ext" - plString searchStr = plFileName::Join(sDir, "*." + ext).AsString(); - - hsFolderIterator folderIter(searchStr.c_str(), true); - while (folderIter.NextFile()) + std::vector files = plFileSystem::ListDir(sDir, ("*." + ext).c_str()); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - plFileName filename = plFileName::Join(sDir, folderIter.GetFileName()); - - if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet - retVal.push_back(filename); + if (fFileData.find(*iter) == fFileData.end()) // we haven't added it yet + retVal.push_back(*iter); } #endif // PLASMA_EXTERNAL_RELEASE diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index 155f2ec0..8d3bf86a 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -1063,7 +1063,7 @@ uint8_t *plFont::IGetFreeCharData( uint32_t &newOffset ) //// LoadFromP2FFile ////////////////////////////////////////////////////////// // Handy quick wrapper -bool plFont::LoadFromP2FFile( const char *path ) +bool plFont::LoadFromP2FFile( const plFileName &path ) { hsUNIXStream stream; if( stream.Open( path, "rb" ) ) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.h b/Sources/Plasma/PubUtilLib/plGImage/plFont.h index 43212f5a..9a121ef1 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.h @@ -289,7 +289,7 @@ class plFont : public hsKeyedObject bool LoadFromBDF( const char *path, plBDFConvertCallback *callback ); bool LoadFromBDFStream( hsStream *stream, plBDFConvertCallback *callback ); - bool LoadFromP2FFile( const char *path ); + bool LoadFromP2FFile( const plFileName &path ); bool ReadRaw( hsStream *stream ); bool WriteRaw( hsStream *stream ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp index 069ba79c..dcaa3801 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp @@ -57,7 +57,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plFont.h" #include "plStatusLog/plStatusLog.h" -#include "plFile/hsFiles.h" #include "pnMessage/plRefMsg.h" #include "hsResMgr.h" @@ -71,7 +70,6 @@ plFontCache *plFontCache::fInstance = nil; plFontCache::plFontCache() { - fCustFontDir = nil; RegisterAs( kFontCache_KEY ); fInstance = this; } @@ -79,7 +77,6 @@ plFontCache::plFontCache() plFontCache::~plFontCache() { Clear(); - delete [] fCustFontDir; fInstance = nil; } @@ -151,46 +148,38 @@ plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlag return nil; } -void plFontCache::LoadCustomFonts( const char *dir ) +void plFontCache::LoadCustomFonts( const plFileName &dir ) { - delete [] fCustFontDir; - fCustFontDir = ( dir != nil ) ? hsStrcpy( dir ) : nil; - + fCustFontDir = dir; ILoadCustomFonts(); } -void plFontCache::ILoadCustomFonts( void ) +void plFontCache::ILoadCustomFonts( void ) { - if( fCustFontDir == nil ) + if (!fCustFontDir.IsValid()) return; // Iterate through all the custom fonts in our dir - hsFolderIterator iter( fCustFontDir ); - char fileName[ kFolderIterator_MaxPath ]; - - - hsFolderIterator iter2( fCustFontDir ); - while( iter2.NextFileSuffix( ".p2f" ) ) + std::vector fonts = plFileSystem::ListDir(fCustFontDir, "*.p2f"); + for (auto iter = fonts.begin(); iter != fonts.end(); ++iter) { - iter2.GetPathAndName( fileName ); - plFont *font = new plFont; - if( !font->LoadFromP2FFile( fileName ) ) + if (!font->LoadFromP2FFile(*iter)) delete font; else { plString keyName; - if( font->GetKey() == nil ) + if (font->GetKey() == nil) { keyName = plString::Format( "%s-%d", font->GetFace(), font->GetSize() ); hsgResMgr::ResMgr()->NewKey( keyName, font, plLocation::kGlobalFixedLoc ); } - hsgResMgr::ResMgr()->AddViaNotify( font->GetKey(), - new plGenRefMsg( GetKey(), plRefMsg::kOnCreate, 0, -1 ), - plRefFlags::kActiveRef ); + hsgResMgr::ResMgr()->AddViaNotify( font->GetKey(), + new plGenRefMsg( GetKey(), plRefMsg::kOnCreate, 0, -1 ), + plRefFlags::kActiveRef ); - //plStatusLog::AddLineS( "pipeline.log", "FontCache: Added custom font %s", keyName ); + //plStatusLog::AddLineS( "pipeline.log", "FontCache: Added custom font %s", keyName.c_str() ); } } diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h index 65b6b839..528e4c8c 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h @@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsTemplates.h" #include "pnKeyedObject/hsKeyedObject.h" +#include "plFileSystem.h" //// Class Definition ///////////////////////////////////////////////////////// @@ -69,9 +70,9 @@ class plFontCache : public hsKeyedObject protected: hsTArray fCache; - char *fCustFontDir; + plFileName fCustFontDir; - static plFontCache *fInstance; + static plFontCache *fInstance; void ILoadCustomFonts( void ); @@ -96,7 +97,7 @@ class plFontCache : public hsKeyedObject // void FreeFont( HFONT font ); void Clear( void ); - void LoadCustomFonts( const char *dir ); + void LoadCustomFonts( const plFileName &dir ); // Our custom font extension static const char* kCustFontExtension; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp index 968a40c1..c4a57b15 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp @@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plWinFontCache.h" #include "plStatusLog/plStatusLog.h" -#include "plFile/hsFiles.h" #include "plGImage/plDynSurfaceWriter.h" #if HS_BUILD_FOR_WIN32 @@ -234,11 +233,11 @@ void plWinFontCache::Clear( void ) for( i = 0; i < fCustFonts.GetCount(); i++ ) { #if (_WIN32_WINNT >= 0x0500) - if( plDynSurfaceWriter::CanHandleLotsOfThem() ) - RemoveFontResourceEx( fCustFonts[ i ]->fFilename, FR_PRIVATE, 0 ); + if (plDynSurfaceWriter::CanHandleLotsOfThem()) + RemoveFontResourceExW(fCustFonts[i]->fFilename.AsString().ToWchar(), FR_PRIVATE, 0); else #endif - if( RemoveFontResource( fCustFonts[ i ]->fFilename ) == 0 ) + if (RemoveFontResourceW(fCustFonts[i]->fFilename.AsString().ToWchar()) == 0) { int q= 0; DWORD e = GetLastError(); @@ -267,31 +266,27 @@ void plWinFontCache::ILoadCustomFonts( void ) return; // Iterate through all the custom fonts in our dir - hsFolderIterator iter( fCustFontDir ); - char fileName[ kFolderIterator_MaxPath ]; - int numAdded; - + int numAdded; - while( iter.NextFileSuffix( kCustFontExtension ) ) + std::vector fonts = plFileSystem::ListDir(fCustFontDir, kCustFontExtension); + for (auto iter = fonts.begin(); iter != fonts.end(); ++iter) { - iter.GetPathAndName( fileName ); - // Note that this call can be translated as "does my OS suck?" #if (_WIN32_WINNT >= 0x0500) if( plDynSurfaceWriter::CanHandleLotsOfThem() ) - numAdded = AddFontResourceEx( fileName, FR_PRIVATE, 0 ); + numAdded = AddFontResourceExW(iter->AsString().ToWchar(), FR_PRIVATE, 0); else #endif - numAdded = AddFontResource( fileName ); + numAdded = AddFontResourceW(iter->AsString().ToWchar()); if( numAdded > 0 ) { - plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Added custom font %s, %d fonts", fileName, numAdded ); - fCustFonts.Append( new plCustFont( fileName ) ); + plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Added custom font %s, %d fonts", iter->GetFileName().c_str(), numAdded ); + fCustFonts.Append(new plCustFont(*iter)); } else { - plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Unable to load custom font %s", fileName ); + plStatusLog::AddLineS( "pipeline.log", "WinFontCache: Unable to load custom font %s", iter->GetFileName().c_str() ); } } } diff --git a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h index 6c97cf2b..1ede70bb 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h @@ -90,10 +90,9 @@ class plWinFontCache class plCustFont { public: - char *fFilename; + plFileName fFilename; - plCustFont( const char *c ) { fFilename = hsStrcpy( c ); } - ~plCustFont() { delete [] fFilename; } + plCustFont(const plFileName &c) { fFilename = c; } }; bool fInShutdown; 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 47b12c74..649fbb2b 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/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index a4aacc75..7a767f5d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetMessage/plNetMessage.h" #include "plAvatar/plAvatarMgr.h" #include "plAvatar/plArmatureMod.h" -#include "plFile/hsFiles.h" /***************************************************************************** @@ -305,15 +304,14 @@ void plNetLinkingMgr::SetEnabled( bool b ) //////////////////////////////////////////////////////////////////// // static -std::string plNetLinkingMgr::GetProperAgeName( const char * ageName ) +plString plNetLinkingMgr::GetProperAgeName( const plString & ageName ) { plNetClientMgr * nc = plNetClientMgr::GetInstance(); - hsFolderIterator it("dat" PATH_SEPARATOR_STR "*.age", true); - while ( it.NextFile() ) + std::vector files = plFileSystem::ListDir("dat", "*.age"); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - std::string work = it.GetFileName(); - work.erase( work.find( ".age" ) ); - if ( stricmp( ageName, work.c_str() )==0 ) + plString work = iter->GetFileNameNoExt(); + if (ageName.CompareI(work) == 0) return work; } return ageName; diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h index 6997c3fb..e0322c1d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h @@ -158,7 +158,7 @@ public: const plNetServerSessionInfo * GetLobbyServerInfo( void ) const { return &fLobbyInfo;} // helpers - static std::string GetProperAgeName( const char * ageName ); // attempt to fix wrong case age name. + static plString GetProperAgeName( const plString & ageName ); // attempt to fix wrong case age name. private: bool fLinkingEnabled; diff --git a/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp b/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp index 94b7f2cd..0b9b1b4b 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientRecorder/plNetClientRecorder.cpp @@ -57,7 +57,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plAgeLoadedMsg.h" #include "plStatusLog/plStatusLog.h" -#include "plFile/hsFiles.h" plNetClientRecorder::plNetClientRecorder(TimeWrapper* timeWrapper) : fTimeWrapper(timeWrapper) diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index f0f063bc..a0d8eda9 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 ); @@ -1203,14 +1203,14 @@ static bool s_running; static CCritSect s_critsect; static LISTDECL(CliAuConn, link) s_conns; static CliAuConn * s_active; -static wchar_t s_accountName[kMaxAccountNameLength]; +static wchar_t s_accountName[kMaxAccountNameLength]; static ShaDigest s_accountNamePassHash; -static wchar_t s_authToken[kMaxPublisherAuthKeyLength]; -static wchar_t s_os[kMaxGTOSIdLength]; +static wchar_t s_authToken[kMaxPublisherAuthKeyLength]; +static wchar_t s_os[kMaxGTOSIdLength]; static long s_perf[kNumPerf]; -static uint32_t s_encryptionKey[4]; +static uint32_t s_encryptionKey[4]; static FNetCliAuthRecvBufferHandler s_bufRcvdCb; static FNetCliAuthConnectCallback s_connectedCb; @@ -2635,13 +2635,11 @@ bool LoginRequestTrans::Send () { ShaDigest challengeHash; uint32_t clientChallenge = 0; - wchar_t domain[15]; - PathSplitEmail(s_accountName, nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0); - - if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) { + // Regex search for primary email domain + std::vector match = plString::FromWchar(s_accountName).RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+"); + if (match.empty() || match[2].CompareI("gametap") == 0) { memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest)); - } - else { + } else { CryptCreateRandomSeed( sizeof(clientChallenge), (uint8_t *) &clientChallenge @@ -3572,14 +3570,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 +3591,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)); @@ -5242,10 +5240,10 @@ void NetCliAuthAccountExistsRequest ( //============================================================================ void NetCliAuthLoginRequest ( - const wchar_t accountName[], + const wchar_t accountName[], const ShaDigest * accountNamePassHash, - const wchar_t authToken[], - const wchar_t os[], + const wchar_t authToken[], + const wchar_t os[], FNetCliAuthLoginRequestCallback callback, void * param ) { @@ -5529,7 +5527,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..18826649 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -135,10 +135,10 @@ typedef void (*FNetCliAuthLoginRequestCallback)( unsigned playerCount ); void NetCliAuthLoginRequest ( - const wchar_t accountName[], // nil --> reuse previous acct name + const wchar_t accountName[], // nil --> reuse previous acct name const ShaDigest * accountNamePassHash, // nil --> reuse previous acct pass - const wchar_t authToken[], // nil --> reuse previous auth token - const wchar_t os[], // nil --> reuse previous os + const wchar_t authToken[], // nil --> reuse previous auth token + const wchar_t os[], // nil --> reuse previous os FNetCliAuthLoginRequestCallback callback, void * param ); @@ -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..fc2291d4 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp @@ -47,8 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnKeyedObject/plKeyImp.h" #include "plStatusLog/plStatusLog.h" #include "pnFactory/plFactory.h" -#include "plFile/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 92805291..6d170b16 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -59,8 +59,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnMessage/plObjRefMsg.h" #include "plMessage/plAgeLoadedMsg.h" #include "pnMessage/plClientMsg.h" -#include "plFile/hsFiles.h" -#include "plFile/plFileUtils.h" #include "pnFactory/plCreator.h" #include "pnNetCommon/plSynchedObject.h" #include "pnNetCommon/plNetApp.h" @@ -131,13 +129,10 @@ 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()); - while (pathIterator.NextFileSuffix(".prp")) + std::vector prpFiles = plFileSystem::ListDir(fDataPath, "*.prp"); + for (auto iter = prpFiles.begin(); iter != prpFiles.end(); ++iter) { - char fileName[kFolderIterator_MaxPath]; - pathIterator.GetPathAndName(fileName); - - plRegistryPageNode* node = new plRegistryPageNode(fileName); + plRegistryPageNode* node = new plRegistryPageNode(*iter); plPageInfo pi = node->GetPageInfo(); fAllPages[pi.GetLocation()] = node; } @@ -517,10 +512,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 +580,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 +591,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 +991,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 +1004,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 +1026,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 +1052,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 +1061,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 +1231,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 +1258,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 +1487,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/plSDL/plSDLParser.cpp b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp index 5adda74f..296a8c65 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plSDLParser.cpp @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" #include "plSDL.h" -#include "plFile/hsFiles.h" #include "plFile/plStreamSource.h" #include "pnNetCommon/pnNetCommon.h" #include "pnNetCommon/plNetApp.h" diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index 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..12a65185 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -60,9 +60,7 @@ 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" #include "plProduct.h" @@ -220,7 +218,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; @@ -253,29 +251,12 @@ bool plStatusLogMgr::DumpLogs( const plFileName &newFolderName ) newPath = newFolderName; plFileSystem::CreateDir(newPath, true); -#if HS_BUILD_FOR_WIN32 - hsWFolderIterator folderIterator; - if (basePath.IsValid()) - folderIterator.SetPath(basePath.AsString().ToWchar()); - else - folderIterator.SetPath(L"."); - - while (folderIterator.NextFile()) - { - if (folderIterator.IsDirectory()) - continue; - - plFileName baseFilename = plString::FromWchar(folderIterator.GetFileName()); - plFileName source; - if (basePath.IsValid()) - source = plFileName::Join(basePath, baseFilename); - else - source = baseFilename; - - plFileName destination = plFileName::Join(newPath, baseFilename); - retVal = (plFileSystem::Copy(source, destination) != 0); + std::vector files = plFileSystem::ListDir(basePath); + for (auto iter = files.begin(); iter != files.end(); ++iter) { + plFileName destination = plFileName::Join(newPath, iter->GetFileName()); + retVal = plFileSystem::Copy(*iter, destination); } -#endif + return retVal; } @@ -753,4 +734,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..42566e6f 100644 --- a/Sources/Tools/MaxComponent/Pch.h +++ b/Sources/Tools/MaxComponent/Pch.h @@ -60,8 +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" #include "hsMatrix44.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..f88581bd 100644 --- a/Sources/Tools/MaxComponent/plGUIComponents.cpp +++ b/Sources/Tools/MaxComponent/plGUIComponents.cpp @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "plgDispatch.h" -#include "plFile/hsFiles.h" #include "hsTemplates.h" #include "plComponent.h" @@ -1449,8 +1448,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 ); } @@ -1464,19 +1463,17 @@ BOOL plGUIDialogProc::DlgProc( TimeValue t, IParamMap2 *pmap, HWND hWnd, UINT ms case WM_INITDIALOG: // Load the age combo box { - int i, idx, selIdx = 0; - HWND ageCombo = GetDlgItem( hWnd, IDC_GUIDLG_AGE ); - hsTArray ageList; + int i, idx, selIdx = 0; + HWND ageCombo = GetDlgItem( hWnd, IDC_GUIDLG_AGE ); - plAgeDescInterface::BuildAgeFileList( ageList ); + hsTArray ageList = plAgeDescInterface::BuildAgeFileList(); ComboBox_ResetContent( ageCombo ); for( i = 0; i < ageList.GetCount(); i++ ) { - char ageName[ _MAX_FNAME ]; - _splitpath( ageList[ i ], nil, nil, ageName, nil ); + plString ageName = ageList[i].GetFileNameNoExt(); - idx = ComboBox_AddString( ageCombo, ageName ); - if( stricmp( ageName, pmap->GetParamBlock()->GetStr( plGUIDialogComponent::kRefAgeName ) ) == 0 ) + idx = ComboBox_AddString( ageCombo, ageName.c_str() ); + if( ageName.CompareI( pmap->GetParamBlock()->GetStr( plGUIDialogComponent::kRefAgeName ) ) == 0 ) { selIdx = idx; } diff --git a/Sources/Tools/MaxComponent/plMiscComponents.cpp b/Sources/Tools/MaxComponent/plMiscComponents.cpp index afdbf340..594f7d90 100644 --- a/Sources/Tools/MaxComponent/plMiscComponents.cpp +++ b/Sources/Tools/MaxComponent/plMiscComponents.cpp @@ -43,8 +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" #include "plMiscComponents.h" @@ -237,8 +235,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() ); } @@ -260,8 +258,7 @@ protected: HWND hAgeCombo = GetDlgItem(fhDlg, IDC_COMP_LOCATION_AGECOMBO); IClearAges( hAgeCombo ); - hsTArray ageFiles; - plAgeDescInterface::BuildAgeFileList( ageFiles ); + hsTArray ageFiles = plAgeDescInterface::BuildAgeFileList(); const char *curAge = fPB->GetStr(plPageInfoComponent::kInfoAge); if (!curAge || *curAge == '\0') @@ -269,14 +266,13 @@ protected: for( int i = 0; i < ageFiles.GetCount(); i++ ) { - char ageName[_MAX_FNAME]; - _splitpath( ageFiles[ i ], nil, nil, ageName, nil ); + plString ageName = ageFiles[i].GetFileNameNoExt(); - int idx = ComboBox_AddString( hAgeCombo, ageName ); + int idx = ComboBox_AddString( hAgeCombo, ageName.c_str() ); // Store the pathas the item data for later (so don't free it yet!) - ComboBox_SetItemData( hAgeCombo, idx, (LPARAM)ageFiles[ i ] ); + ComboBox_SetItemData( hAgeCombo, idx, (LPARAM)ageFiles[i].AsString().c_str() ); - if( !strcmp( ageName, curAge ) ) + if (ageName == curAge) ComboBox_SetCurSel( hAgeCombo, idx ); } @@ -576,33 +572,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 +620,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 +646,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 +692,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 +713,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 +774,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 +786,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..b3caf4c4 100644 --- a/Sources/Tools/MaxComponent/plResponderLink.cpp +++ b/Sources/Tools/MaxComponent/plResponderLink.cpp @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" -#include "plFile/hsFiles.h" #include "hsResMgr.h" #include "plComponentBase.h" @@ -318,30 +317,23 @@ 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); - while (ageFolder.NextFileSuffix(".age")) + std::vector ages = plFileSystem::ListDir(agePath, "*.age"); + for (auto iter = ages.begin(); iter != ages.end(); ++iter) { - char ageFile[MAX_PATH]; - ageFolder.GetPathAndName(ageFile); - - char name[_MAX_FNAME]; - _splitpath(ageFile, nil, nil, name, nil); - - int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)name); + int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)iter->GetFileNameNoExt().c_str()); - if (strcmp(name, savedName) == 0) + if (iter->GetFileNameNoExt() == savedName) SendMessage(hAge, CB_SETCURSEL, idx, 0); } } @@ -355,30 +347,22 @@ 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); - while (ageFolder.NextFileSuffix(".age")) + std::vector ages = plFileSystem::ListDir(agePath, "*.age"); + for (auto iter = ages.begin(); iter != ages.end(); ++iter) { - char ageFile[MAX_PATH]; - ageFolder.GetPathAndName(ageFile); - - char name[_MAX_FNAME]; - _splitpath(ageFile, nil, nil, name, nil); - - int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)name); + int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)iter->GetFileNameNoExt().c_str()); - if (strcmp(name, savedName) == 0) + if (iter->GetFileNameNoExt() == savedName) SendMessage(hAge, CB_SETCURSEL, idx, 0); } } 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..b3fa69d5 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsWindows.h" +#include "hsStream.h" #include #include @@ -58,6 +59,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 +71,7 @@ protected: bool fPhysicalsOnly; bool fLightMap; char fExportPage[256]; - char fExportSourceDir[MAX_PATH]; + plFileName fExportSourceDir; bool fExporting; bool fAutoExporting; bool fExportFile; @@ -108,30 +110,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 +191,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 +238,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 +286,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 +298,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; } } @@ -326,8 +331,6 @@ void plExportDlgImp::IExportCurrentFile(const char* exportPath) GetCOREInterface()->ExportToFile(exportPath); } -#include "plFile/hsFiles.h" - void plExportDlgImp::IDoExport() { fExporting = true; @@ -347,13 +350,10 @@ void plExportDlgImp::IDoExport() IExportCurrentFile(exportPath); else { - hsFolderIterator sourceDir(fExportSourceDir); - while (sourceDir.NextFileSuffix(".max")) + std::vector sources = plFileSystem::ListDir(fExportSourceDir, "*.max"); + for (auto iter = sources.begin(); iter != sources.end(); ++iter) { - char exportFile[MAX_PATH]; - sourceDir.GetPathAndName(exportFile); - - if (GetCOREInterface()->LoadFromFile(exportFile)) + if (GetCOREInterface()->LoadFromFile(iter->AsString().c_str())) IExportCurrentFile(exportPath); } } @@ -386,18 +386,18 @@ void plExportDlgImp::Show() fDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_EXPORT), GetCOREInterface()->GetMAXHWnd(), ForwardDlgProc); } -static bool IsExcluded(const char* fileName, std::vector& excludeFiles) +static bool IsExcluded(const plFileName& fileName, std::vector& excludeFiles) { for (int i = 0; i < excludeFiles.size(); i++) { - if (!strcmp(fileName, excludeFiles[i].c_str())) + if (fileName == excludeFiles[i]) return true; } return false; } -static bool AutoExportDir(const char* inputDir, const char* outputDir, const char* groupFiles, std::vector& excludeFiles) +static bool AutoExportDir(const char* inputDir, const char* outputDir, const plFileName& groupFiles, std::vector& excludeFiles) { bool exportedFile = false; @@ -413,37 +413,33 @@ static bool AutoExportDir(const char* inputDir, const char* outputDir, const cha // Don't give missing bitmap warnings TheManager->SetSilentMode(TRUE); - - hsFolderIterator sourceDir(inputDir); - while (sourceDir.NextFileSuffix(".max")) - { - char exportFile[MAX_PATH]; - sourceDir.GetPathAndName(exportFile); - if (IsExcluded(sourceDir.GetFileName(), excludeFiles)) + std::vector sources = plFileSystem::ListDir(inputDir, "*.max"); + for (auto iter = sources.begin(); iter != sources.end(); ++iter) + { + if (IsExcluded(iter->GetFileName(), excludeFiles)) continue; // If we're doing grouped files, and this isn't one, keep looking - if (groupFiles && strncmp(sourceDir.GetFileName(), groupFiles, strlen(groupFiles)) != 0) + if (groupFiles.IsValid() && groupFiles != iter->GetFileName()) continue; hsUNIXStream log; if (log.Open(outputLog, "ab")) { - log.WriteFmt("%s\r\n", sourceDir.GetFileName()); + log.WriteFmt("%s\r\n", iter->GetFileName().c_str()); log.Close(); } - if (GetCOREInterface()->LoadFromFile(exportFile)) + if (GetCOREInterface()->LoadFromFile(iter->AsString().c_str())) { - sprintf(doneDir, "%s\\Done\\%s", inputDir, sourceDir.GetFileName()); - MoveFileEx(exportFile, doneDir, MOVEFILE_REPLACE_EXISTING); + plFileSystem::Move(*iter, plFileName::Join(inputDir, "Done", iter->GetFileName())); GetCOREInterface()->ExportToFile(outputFileName, TRUE); exportedFile = true; // If we're not doing grouped files, this is it, we exported our one file - if (!groupFiles) + if (!groupFiles.IsValid()) break; } } @@ -467,7 +463,7 @@ static void ShutdownMax() PostMessage(GetCOREInterface()->GetMAXHWnd(), WM_CLOSE, 0, 0); } -static void GetStringSection(const char* configFile, const char* keyName, std::vector& strings) +static void GetFileNameSection(const char* configFile, const char* keyName, std::vector& strings) { char source[256]; GetPrivateProfileString("Settings", keyName, "", source, sizeof(source), configFile); @@ -502,18 +498,18 @@ void plExportDlgImp::StartAutoExport() hsMessageBox_SuppressPrompts = true; // Files to ignore - std::vector excludeFiles; - GetStringSection(configFile, "ExcludeFiles", excludeFiles); + std::vector excludeFiles; + GetFileNameSection(configFile, "ExcludeFiles", excludeFiles); // // Get the file substrings to export in one session // - std::vector groupedFiles; - GetStringSection(configFile, "GroupedFiles", groupedFiles); + std::vector groupedFiles; + GetFileNameSection(configFile, "GroupedFiles", groupedFiles); for (int i = 0; i < groupedFiles.size(); i++) { - if (AutoExportDir(inputDir, outputDir, groupedFiles[i].c_str(), excludeFiles)) + if (AutoExportDir(inputDir, outputDir, groupedFiles[i], excludeFiles)) { ShutdownMax(); fAutoExporting = false; @@ -521,7 +517,7 @@ void plExportDlgImp::StartAutoExport() } } - if (AutoExportDir(inputDir, outputDir, NULL, excludeFiles)) + if (AutoExportDir(inputDir, outputDir, "", excludeFiles)) { ShutdownMax(); fAutoExporting = false; 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/Pch.h b/Sources/Tools/MaxMain/Pch.h index a22f5224..31b44f0b 100644 --- a/Sources/Tools/MaxMain/Pch.h +++ b/Sources/Tools/MaxMain/Pch.h @@ -61,7 +61,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsColorRGBA.h" #include "plgDispatch.h" #include "hsFastMath.h" -#include "plFile/hsFiles.h" #include "hsGeometry3.h" #include "pnKeyedObject/plKey.h" #include "plLoadMask.h" @@ -71,6 +70,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "hsStringTokenizer.h" #include "hsTemplates.h" +#include "plFileSystem.h" // Windows #include "hsWindows.h" diff --git a/Sources/Tools/MaxMain/main.cpp b/Sources/Tools/MaxMain/main.cpp index 3149eb35..f473201f 100644 --- a/Sources/Tools/MaxMain/main.cpp +++ b/Sources/Tools/MaxMain/main.cpp @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" -#include "plFile/hsFiles.h" #include "hsTemplates.h" #include "MaxComponent/plComponentMgr.h" @@ -168,16 +167,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..d4fe393a 100644 --- a/Sources/Tools/MaxMain/plAgeDescInterface.cpp +++ b/Sources/Tools/MaxMain/plAgeDescInterface.cpp @@ -40,14 +40,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" -#include "plFile/hsFiles.h" #include "hsStream.h" #include "hsTemplates.h" #include "hsWindows.h" #include -#include -#include #include "resource.h" #pragma hdrstop @@ -63,8 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #include "plMaxAccelerators.h" -using std::string; - extern HINSTANCE hInstance; //// Tree Data Wrapper Class ////////////////////////////////////////////////// @@ -72,19 +67,17 @@ extern HINSTANCE hInstance; class plAgeFile { protected: - void IGetAgeName(const char* path) + void IGetAgeName(const plFileName& path) { - char name[_MAX_FNAME]; - _splitpath(path, nil, nil, name, nil); - fAgeName = name; + fAgeName = path.GetFileNameNoExt(); } public: #ifdef MAXASS_VAILABLE jvUniqueId fAssetID; #endif - string fPath; - string fAgeName; + plFileName fPath; + plString fAgeName; enum Types { @@ -93,17 +86,16 @@ public: }; Types fType; - plAgeFile(Types type) : fType(type), fPath(nil) { } - plAgeFile(Types type, const char *path) : fType(type) + plAgeFile(Types type) : fType(type) { } + plAgeFile(Types type, const plFileName &path) : fPath(path), fType(type) { - fPath = path; IGetAgeName(path); } #ifdef MAXASS_AVAILABLE - plAgeFile(Types type, const char *path, jvUniqueId& id) : fType(type), fAssetID(id) + plAgeFile(Types type, const plFileName &path, jvUniqueId& id) + : fPath(path), fType(type), fAssetID(id) { - fPath = path; IGetAgeName(path); } #endif @@ -716,7 +708,7 @@ void plAgeDescInterface::IUpdateCurAge( void ) else #endif // Load the local age, also check its sequence #s - ILoadAge( currAge->fPath.c_str(), true ); + ILoadAge( currAge->fPath, true ); } static const int kDefaultCapacity = 10; @@ -823,20 +815,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) @@ -852,19 +843,15 @@ void plAgeDescInterface::IGetAgeFiles(std::vector& ageFiles) { IClearAgeFiles(ageFiles); - char agePath[MAX_PATH]; - // 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); - while (ageFolder.NextFileSuffix(".age")) + std::vector files = plFileSystem::ListDir(localPath, "*.age"); + for (auto iter = files.begin(); iter != files.end(); ++iter) { - ageFolder.GetPathAndName(agePath); - - plAgeFile* age = new plAgeFile(plAgeFile::kLocalFile, agePath); + plAgeFile* age = new plAgeFile(plAgeFile::kLocalFile, *iter); ageFiles.push_back(age); } } @@ -882,6 +869,7 @@ void plAgeDescInterface::IGetAgeFiles(std::vector& ageFiles) { if( doneAssets.Find( (*assets)[ i ] ) == doneAssets.kMissingIndex ) { + char agePath[MAX_PATH]; if (assetMan->GetLatestVersionFile((*assets)[i], agePath, sizeof(agePath))) { plAgeFile* age = new plAgeFile(plAgeFile::kAssetFile, agePath, (*assets)[i]); @@ -912,16 +900,19 @@ void plAgeDescInterface::IClearAgeFiles(std::vector& ageFiles) ageFiles.clear(); } -void plAgeDescInterface::BuildAgeFileList( hsTArray &ageList ) +hsTArray plAgeDescInterface::BuildAgeFileList() { std::vector tempAgeFiles; IGetAgeFiles(tempAgeFiles); + hsTArray ageList; for (int i = 0; i < tempAgeFiles.size(); i++) { - ageList.Push(hsStrcpy(tempAgeFiles[i]->fPath.c_str())); + ageList.Push(tempAgeFiles[i]->fPath); delete tempAgeFiles[ i ]; } + + return ageList; } //// IFillAgeTree ///////////////////////////////////////////////////////////// @@ -960,22 +951,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 +1002,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 +1028,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 +1059,7 @@ void plAgeDescInterface::INewAge() fForceSeqNumLocal = false; if( makeAsset ) - (*fAssetManIface)->AddNewAsset(newAssetFilename); + (*fAssetManIface)->AddNewAsset(newAssetFilename.AsString().c_str()); #endif // Refresh the tree now @@ -1075,15 +1068,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 +1087,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 +1123,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 +1189,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 +1203,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 +1213,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 +1279,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 ) ); } } @@ -1311,7 +1302,7 @@ uint32_t plAgeDescInterface::IGetNextFreeSequencePrefix( bool getReservedPrefix for( i = 0; i < fAgeFiles.size(); i++ ) { hsUNIXStream stream; - if( stream.Open( fAgeFiles[ i ]->fPath.c_str(), "rt" ) ) + if( stream.Open( fAgeFiles[ i ]->fPath, "rt" ) ) { ages[ i ].Read( &stream ); stream.Close(); diff --git a/Sources/Tools/MaxMain/plAgeDescInterface.h b/Sources/Tools/MaxMain/plAgeDescInterface.h index 96a81126..d5574959 100644 --- a/Sources/Tools/MaxMain/plAgeDescInterface.h +++ b/Sources/Tools/MaxMain/plAgeDescInterface.h @@ -84,7 +84,7 @@ public: static BOOL CALLBACK ForwardDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); - static void BuildAgeFileList( hsTArray &ageList ); + static hsTArray BuildAgeFileList(); protected: static int IFindAge(const char* ageName, std::vector& ageFiles); @@ -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..e877c4ea 100644 --- a/Sources/Tools/MaxMain/plPythonMgr.cpp +++ b/Sources/Tools/MaxMain/plPythonMgr.cpp @@ -40,9 +40,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" -#include "plFile/hsFiles.h" #include "plgDispatch.h" #include "hsWindows.h" +#include "plFileSystem.h" #include #include @@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +#include #pragma hdrstop #include "plPythonMgr.h" @@ -229,7 +230,7 @@ void IExtractVisInfo(PyObject* tuple, int* id, std::vector* vec) } } -bool plPythonMgr::IQueryPythonFile(char *fileName) +bool plPythonMgr::IQueryPythonFile(const char *fileName) { PyObject *module = PyImport_ImportModule(fileName); if (module) @@ -596,39 +597,32 @@ void plPythonMgr::IAddGrassComponent(plAutoUIBlock *autoUI, PyObject *objTuple, autoUI->AddPickGrassComponentButton(id, nil, paramName.c_str(), vid, vstates); } -#include - 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); - while (folder.NextFileSuffix(".py")) + std::vector pys = plFileSystem::ListDir(pythonPath, "*.py"); + for (auto iter = pys.begin(); iter != pys.end(); ++iter) { // Get the filename without the ".py" (module name) - const char *fullFileName = folder.GetFileName(); - char fileName[_MAX_FNAME]; - _splitpath(fullFileName, NULL, NULL, fileName, NULL); + plString fileName = iter->GetFileNameNoExt(); - IQueryPythonFile(fileName); + IQueryPythonFile(fileName.c_str()); } PythonInterface::finiPython(); - _chdir(oldCwd); + plFileSystem::SetCWD(oldCwd); } } diff --git a/Sources/Tools/MaxMain/plPythonMgr.h b/Sources/Tools/MaxMain/plPythonMgr.h index 3b0a9fbb..0c23473c 100644 --- a/Sources/Tools/MaxMain/plPythonMgr.h +++ b/Sources/Tools/MaxMain/plPythonMgr.h @@ -48,7 +48,7 @@ class plPythonMgr protected: plPythonMgr(); - bool IQueryPythonFile(char *fileName); + bool IQueryPythonFile(const char *fileName); void IAddBool(plAutoUIBlock *autoUI, PyObject *tuple, char *paramName, int id, int vid, std::vector* vstates); void IAddInt(plAutoUIBlock *autoUI, PyObject *tuple, char *paramName, int id, int vid, std::vector* vstates); diff --git a/Sources/Tools/MaxSceneViewer/SceneSync.cpp b/Sources/Tools/MaxSceneViewer/SceneSync.cpp index 9a82e2d5..24edc739 100644 --- a/Sources/Tools/MaxSceneViewer/SceneSync.cpp +++ b/Sources/Tools/MaxSceneViewer/SceneSync.cpp @@ -279,8 +279,6 @@ void SceneSync::IClearDirtyRecur(plMaxNode *node) IClearDirtyRecur((plMaxNode*)node->GetChildNode(i)); } -#include "../plFile/hsFiles.h" - void SceneSync::IDeletePath(const char *path) { // Remove any files in the dat directory diff --git a/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp b/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp index 89868361..2e44a90c 100644 --- a/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp +++ b/Sources/Tools/plResBrowser/plResBrowserWndProc.cpp @@ -53,7 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plResManager.h" #include "plResMgr/plResMgrSettings.h" #include "plWinRegistryTools.h" -#include "plFile/hsFiles.h" #define IDC_REGTREEVIEW 1000 @@ -139,14 +138,10 @@ LRESULT CALLBACK HandleCommand( HWND hWnd, WPARAM wParam, LPARAM lParam ) // Load that source plResManager *mgr = (plResManager *)hsgResMgr::ResMgr(); - hsFolderIterator pathIterator(path); - while (pathIterator.NextFileSuffix(".prp")) - { - char fileName[kFolderIterator_MaxPath]; - pathIterator.GetPathAndName(fileName); - mgr->AddSinglePage(fileName); - } - + std::vector prpFiles = plFileSystem::ListDir(path, "*.prp"); + for (auto iter = prpFiles.begin(); iter != prpFiles.end(); ++iter) + mgr->AddSinglePage(*iter); + plResTreeView::FillTreeViewFromRegistry( gTreeView ); SetWindowTitle( hWnd, path ); @@ -388,13 +383,9 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ( (char *)PathFindExtension( path ) )[ 0 ] == 0 ) { // Must be a directory - hsFolderIterator pathIterator(path); - while (pathIterator.NextFileSuffix(".prp")) - { - char fileName[kFolderIterator_MaxPath]; - pathIterator.GetPathAndName(fileName); - mgr->AddSinglePage(fileName); - } + std::vector prpFiles = plFileSystem::ListDir(path, "*.prp"); + for (auto iter = prpFiles.begin(); iter != prpFiles.end(); ++iter) + mgr->AddSinglePage(*iter); } else {