static bool AutoExportDir(const char* inputDir, const char* outputDir, const plFileName& groupFiles, std::vector<plFileName>& excludeFiles) { bool exportedFile = false; char outputFileName[MAX_PATH]; sprintf(outputFileName, "%s\\Export.prd", outputDir); char outputLog[MAX_PATH]; sprintf(outputLog, "%s\\AutoExport.log", outputDir); char doneDir[MAX_PATH]; sprintf(doneDir, "%s\\Done\\", inputDir); CreateDirectory(doneDir, NULL); // Don't give missing bitmap warnings TheManager->SetSilentMode(TRUE); std::vector<plFileName> 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.IsValid() && groupFiles != iter->GetFileName()) continue; hsUNIXStream log; if (log.Open(outputLog, "ab")) { log.WriteFmt("%s\r\n", iter->GetFileName().c_str()); log.Close(); } if (GetCOREInterface()->LoadFromFile(iter->AsString().c_str())) { 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.IsValid()) break; } } return exportedFile; }
plStatusLog::plStatusLog( uint8_t numDisplayLines, const plFileName &filename, uint32_t flags ) { fFileHandle = nil; fSema = nil; fSize = 0; fForceLog = false; fMaxNumLines = numDisplayLines; if (filename.IsValid()) { fFilename = filename; fSema = new hsGlobalSemaphore(1, fFilename.AsString().c_str()); } else { fFilename = ""; flags |= kDontWriteFile; fSema = new hsGlobalSemaphore(1); } fOrigFlags = fFlags = flags; IInit(); }
/* plFileInfo */ plFileInfo::plFileInfo(const plFileName &filename) : fFileSize(-1), fCreateTime(), fModifyTime(), fFlags() { if (!filename.IsValid()) return; #if HS_BUILD_FOR_WIN32 struct __stat64 info; if (_wstat64(filename.AsString().ToWchar(), &info) != 0) return; #else struct stat info; if (stat(filename.AsString().c_str(), &info) != 0) return; #endif fFlags |= kEntryExists; fFileSize = info.st_size; fCreateTime = info.st_ctime; fModifyTime = info.st_mtime; if (info.st_mode & S_IFDIR) fFlags |= kIsDirectory; if (info.st_mode & S_IFREG) fFlags |= kIsNormalFile; }
plKey plAvatarMgr::LoadAvatar(plString name, plString accountName, bool isPlayer, plKey spawnPoint, plAvTask *initialTask, const plString &userStr, const plFileName &clothingFile) { // *** account is currently unused. the idea is that eventually an NPC will // *** be able to use a customization account plKey result = nullptr; plKey requestor = GetKey(); // avatar manager is always the requestor for avatar loads plNetClientMgr *netMgr = plNetClientMgr::GetInstance(); if(netMgr) // can't clone without the net manager { hsAssert(!name.IsEmpty(), "name required by LoadPlayer fxn"); netMgr->DebugMsg("Local: Loading player %s", name.c_str()); // look up player by key name provided by user. // this string search should be replaced with some other method of // avatar selection and key lookup. // Get the location for the player first plKey playerKey = nullptr; const plLocation& globalLoc = plKeyFinder::Instance().FindLocation("GlobalAvatars", name); const plLocation& maleLoc = plKeyFinder::Instance().FindLocation("GlobalAvatars", "Male"); const plLocation& custLoc = plKeyFinder::Instance().FindLocation("CustomAvatars", name); #ifdef PLASMA_EXTERNAL_RELEASE // Try global. If that doesn't work, players default to male. // If not a player, try custLoc. If that doesn't work, fall back to male const plLocation& loc = (globalLoc.IsValid() ? globalLoc : isPlayer ? maleLoc : custLoc.IsValid() ? custLoc : maleLoc); #else // Try global. If that doesn't work try custom. Otherwise fall back to male const plLocation& loc = (globalLoc.IsValid() ? globalLoc : custLoc.IsValid() ? custLoc : maleLoc); #endif if (loc == maleLoc) name = "Male"; if (loc.IsValid()) { plUoid uID(loc, plSceneObject::Index(), name); plLoadAvatarMsg *cloneMsg = new plLoadAvatarMsg(uID, requestor, 0, isPlayer, spawnPoint, initialTask, userStr); if (clothingFile.IsValid()) { plLoadClothingMsg *clothingMsg = new plLoadClothingMsg(clothingFile); cloneMsg->SetTriggerMsg(clothingMsg); } result = cloneMsg->GetCloneKey(); // the clone message is automatically addressed to the net client manager // we'll receive the message back (or a similar message) when the clone is loaded cloneMsg->Send(); } } return result; }
plFileName plFileName::Join(const plFileName &base, const plFileName &path) { if (!base.IsValid()) return path; if (!path.IsValid()) return base; char last = base.fName.CharAt(base.GetSize() - 1); char first = path.fName.CharAt(0); if (last != '/' && last != '\\') { if (first != '/' && first != '\\') { return plString::Format("%s" PATH_SEPARATOR_STR "%s", base.fName.c_str(), path.fName.c_str()); } return base.fName + path.fName; } else if (first != '/' && first != '\\') { return base.fName + path.fName; } // Both have a slash, but we only need one return base.fName + path.fName.Substr(1); }
plFileName plFileSystem::GetUserDataPath() { static plFileName _userData; if (!_userData.IsValid()) { #if HS_BUILD_FOR_WIN32 wchar_t path[MAX_PATH]; if (!SHGetSpecialFolderPathW(NULL, path, CSIDL_LOCAL_APPDATA, TRUE)) return ""; _userData = plFileName::Join(plString::FromWchar(path), plProduct::LongName()); #else _userData = plFileName::Join(getenv("HOME"), "." + plProduct::LongName()); #endif plFileSystem::CreateDir(_userData); } return _userData; }
plBufferedFileReader::plBufferedFileReader( const plFileName &path, plAudioCore::ChannelSelect whichChan ) { // Init some stuff fBufferSize = 0; fBuffer = nil; fCursor = 0; 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 plAudioFileReader *reader = plAudioFileReader::CreateReader( path, whichChan ); if( reader == nil || !reader->IsValid() ) { delete reader; IError( "Unable to open file to read in to RAM buffer" ); return; } fHeader = reader->GetHeader(); fBufferSize = reader->GetDataSize(); fBuffer = new uint8_t[ fBufferSize ]; //plProfile_NewMem( SndBufferedMem, fBufferSize ); if( fBuffer == nil ) { delete reader; IError( "Unable to allocate RAM buffer" ); return; } if( !reader->Read( fBufferSize, fBuffer ) ) { delete reader; IError( "Unable to read file into RAM buffer" ); return; } // All done! delete reader; }