void initPlugins ( void ) { customPluginMap.clear(); OSDir dir; std::string path = getAutoLoadDir(); if (getAutoLoadDir().size()) { dir.setOSDir(getAutoLoadDir()); OSFile file; std::string searchdir = "*" + extension; while(dir.getNextFile(file,searchdir.c_str(),false) ) loadPlugin(file.getOSName(),std::string("")); } }
bool DeployMonitor::fileDownload(MonitorWorker *mw, Properties &props) { trace_enter(); string fileName = props.getProperty("file.name"); int fileSize = props.getInt("payloadSize"); int rSize; unsigned char buf[FILE_BUF_SIZE]; string filePath = createDeployPath(fileName); string mode("wb"); OSFile f; trace("[fileDownload] filepath=" << filePath << ", fileSize==" << fileSize); if (f.open(filePath, mode) == false) { trace("File open error"); mw->returnFail("deploy", "file.download", "File open error"); return false; } int wlen = 0; try { while (fileSize > 0) { rSize = fileSize > FILE_BUF_SIZE ? FILE_BUF_SIZE : fileSize; rSize = mw->read(buf, rSize); wlen += f.write(buf, rSize); fileSize -= rSize; } mw->returnOK("deploy", "file.download", "ok"); f.close(); trace("[fileDownload] End : fileSize=" << fileSize << ", writeSize=" << wlen); return true; } catch (exception &ex) { mw->returnFail("deploy", "file.download", ex.what()); } f.close(); return false; }
void FontManager::loadAll(std::string directory) { if (directory.size() == 0) return; OSFile file; OSDir dir(directory.c_str()); while (dir.getNextFile(file, true)) { const char *ext = file.getExtension(); if (ext) { if (strcasecmp(ext, "fmt") == 0) { TextureFont *pFont = new TextureFont; if (pFont) { if (pFont->load(file)) { std::string str = pFont->getFaceName(); GetTypeFaceName((char*)str.c_str()); FontFaceMap::iterator faceItr = faceNames.find(str); int faceID = 0; if (faceItr == faceNames.end()) { // its new FontSizeMap faceList; fontFaces.push_back(faceList); faceID = (int)fontFaces.size() - 1; faceNames[str] = faceID; } else { faceID = faceItr->second; } fontFaces[faceID][pFont->getSize()] = pFont; } else { DEBUG4("Font Texture load failed: %s\n", file.getOSName()); delete(pFont); } } } } } }
bool DeployMonitor::fileUploadTwoWay(MonitorWorker *mw, Properties &props) { trace_enter(); string fileName = props.getProperty("file.name"); string filePath = getDeployPath(fileName); trace("filepath=" << filePath); OSFile f; string mode("rb"); if (f.open(filePath, mode) == false) { mw->returnFail("deploy", "file.download", "File open error"); return false; } unsigned char buf[FILE_BUF_SIZE]; int fileSize; int rSize; fileSize = f.sizeOf(); trace("[fileUpload] filepath=" << filePath << ", fileSize=" << fileSize); int wlen = 0; try { while (fileSize > 0) { rSize = fileSize > FILE_BUF_SIZE ? FILE_BUF_SIZE : fileSize; rSize = f.read(buf, rSize); if (rSize <= 0) break; mw->writeString("ver=1.0;target=deploy;cmd=file.upload;success=ok;ret=ok;payloadSize=" + StringUtil::intToStr(rSize) + "\n"); wlen += mw->write(buf, rSize); fileSize -= rSize; trace("[fileUpload] Write done : fileSize=" << fileSize << ", writeSize=" << wlen); mw->readLine((char *) buf, FILE_BUF_SIZE); } f.close(); mw->writeString("ver=1.0;target=deploy;cmd=file.upload;success=ok;ret=ok;payloadSize=0\n"); trace("[fileUpload] End : fileSize=" << fileSize << ", writeSize=" << wlen); return true; } catch (exception &ex) { log_error(ex.what()); } f.close(); return false; }
bool OSDir::getNextFile(OSFile &oFile, const char* fileMask, bool bRecursive) { #ifdef _WIN32 std::string realMask = "*.*"; //FIXME -- could this also be just '*' ? #else std::string realMask = "*"; #endif if (fileMask) realMask = fileMask; realMask = TextUtils::toupper(realMask); std::string theFileExt; if (info->namePos == -1) { info->nameList.clear(); //FIXME -- just do the #ifdef'ing here? windowsAddFileStack(getFullOSPath(), realMask, bRecursive); linuxAddFileStack(getFullOSPath(), realMask, bRecursive); info->namePos = 0; } int size = info->nameList.size(); if (info->namePos >= size) { info->namePos = -1; return false; } std::string fileName = info->nameList[info->namePos]; if (osBaseDir.size()>1) { std::string temp = &(fileName.c_str()[osBaseDir.size()]); fileName = temp; } oFile.osName(fileName); info->namePos++; return true; }