TEST_F(EngineTestParser, parseFile_define__NO__OBFUSCATION) { //create work dir CString strCommand; CString strTestDir(m_strRootPath.c_str()); strTestDir += _T("TestDir\\"); strCommand.Format(_T("/c mkdir %s"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); //copy file with NO__OBFUSCATION CString strSourceFile(m_strRootPath.c_str()); strSourceFile += _T("Parser\\Parser\\ParserEngine.cpp"); CString strDestFile(strTestDir); strDestFile += _T("ParserEngine.cpp"); CopyFile(strSourceFile, strDestFile, TRUE); CString strPath(strTestDir); CString strFilename("ParserEngine.cpp"); bool bCreateTempDir = false; int nRes = m_parser.parseFile(strPath, strFilename, bCreateTempDir); //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_EQ(0, nRes); }
STDMETHODIMP MachineDebugger::DumpGuestCore(IN_BSTR a_bstrFilename, IN_BSTR a_bstrCompression) { CheckComArgStrNotEmptyOrNull(a_bstrFilename); Utf8Str strFilename(a_bstrFilename); if (a_bstrCompression && *a_bstrCompression) return setError(E_INVALIDARG, tr("The compression parameter must be empty")); AutoCaller autoCaller(this); HRESULT hrc = autoCaller.rc(); if (SUCCEEDED(hrc)) { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); Console::SafeVMPtr ptrVM(mParent); hrc = ptrVM.rc(); if (SUCCEEDED(hrc)) { int vrc = DBGFR3CoreWrite(ptrVM, strFilename.c_str(), false /*fReplaceFile*/); if (RT_SUCCESS(vrc)) hrc = S_OK; else hrc = setError(E_FAIL, tr("DBGFR3CoreWrite failed with %Rrc"), vrc); } } return hrc; }
TEST_F(EngineTestParser, restore_noArchFile) { //create work dir CString strCommand; CString strTestDir(m_strRootPath.c_str()); strTestDir += _T("TestDir\\"); strCommand.Format(_T("/c mkdir %s"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); //copy file CString strSourceFile(m_strRootPath.c_str()); strSourceFile += _T("Test\\Test\\Test.cpp"); CString strDestFile(strTestDir); strDestFile += _T("Test.cpp"); CopyFile(strSourceFile, strDestFile, TRUE); CString strFilename(_T("Test.cpp")); std::wstring strPath(strTestDir.GetBuffer()); m_parser.setCurrentPath(strPath); int nRes = m_parser.restore(); CString strPathArchFile = strTestDir; strPathArchFile += _T("arch_obfuscate.obf"); bool bRes = isFileExist(strPathArchFile); //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_TRUE(!nRes && !bRes); }
void CCrashHandler::Init ( const SString& strInServerPath ) { SString strServerPath = strInServerPath; if ( strServerPath == "" ) strServerPath = GetSystemCurrentDirectory(); ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH ); // Set a global filter #ifdef WIN32 SetCrashHandlerFilter ( HandleExceptionGlobal ); #else // Prepare initial dumpfile name time_t pTime = time( NULL ); struct tm* tm = localtime( &pTime ); SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp", MTA_DM_BUILDTAG_LONG, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); ms_strDumpPathFilename = PathJoin( ms_strDumpPath, strFilename ); MakeSureDirExists( ms_strDumpPathFilename ); #ifdef WITH_BACKTRACE_ONLY signal ( SIGSEGV, HandleExceptionGlobal ); #else google_breakpad::MinidumpDescriptor descriptor( ms_strDumpPath ); static google_breakpad::ExceptionHandler eh( descriptor, NULL, DumpCallback, NULL, true, -1 ); #endif #endif }
// Linux crash callback when using google-breakpad bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded ) { // Set inital dump file name (Safeish) File::Rename( descriptor.path(), ms_strDumpPathFilename ); // Set final dump file name (Not so safe) time_t pTime = time( NULL ); struct tm* tm = localtime( &pTime ); SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp", MTA_DM_BUILDTAG_LONG, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); SString strFinalDumpPathFilename = PathJoin( ms_strDumpPath, strFilename ); File::Rename( ms_strDumpPathFilename, strFinalDumpPathFilename ); SaveBacktraceSummary(); FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename ); // Return false to indicate exception has not been handled (and allow core dump?) return false; }
STDMETHODIMP CDirect2DRM::ReleaseImage(BSTR bstrName) { CString strFilename(bstrName); return m_pImageCache->RemoveImage(strFilename); }
TEST_F(EngineTestParser, parseFile_noFileName) { CString strPath(m_strRootPath.c_str()); CString strFilename(_T("")); bool bCreateTempDir = false; int nRes = m_parser.parseFile(strPath, strFilename, bCreateTempDir); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_EQ(-1, nRes); }
static void setCommon(VPLFS_MonitorEvent* cbBuffer, const char* filename) { cbBuffer->moveTo = NULL; std::string strFilename(filename); replaceBackslashWithForwardSlash(strFilename); strncpy((char*)(cbBuffer+1), strFilename.c_str(), MAX_PATH); int nameLen = strFilename.size()+1; // +1 for '\0' cbBuffer->filename = (char*)(cbBuffer+1); cbBuffer->nextEntryOffsetBytes = sizeof(VPLFS_MonitorEvent)+ALIGN(nameLen); }
static bool isBeginWithPeriod(const char* filename) { std::string strFilename(filename); if(strFilename.size()>0 && strFilename[0]=='.') { return true; } if(strFilename.find("\\.") != std::string::npos) { // subdirectory is hidden return true; } return false; }
void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine) { // pcszSourceFile comes from __FILE__ macro, which always contains the full path, // which we don't want to see printed: Utf8Str strFilename(RTPathFilename(pcszSourceFile)); Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n", pcszContext, ulLine, strFilename.c_str()); // print and log RTMsgError("%s", str.c_str()); Log(("%s", str.c_str())); }
/** A file is sent by the host * * \param filename The filename to create * */ void RainbruRPG::Network::Ftp::FtpTransfer:: commandSTOR(const QString& filename){ LOGI("Executing STOR command"); nextCommand=FTC_STOR; std::string strFilename(filename.toLatin1()); GlobalURI gu; std::string strNnextFilename=gu.getQuarantineFile(strFilename); nextFilename=strNnextFilename.c_str(); nextOnlyFilename=filename; QTcpSocket* sock; waitForConnection(sock); }
// Returns true or false whether a specific file exists. bool OTLog::ConfirmExactPath(const char * szFileName) { OT_ASSERT(NULL != szFileName); OTString strFilename(szFileName); OT_ASSERT_MSG(!strFilename.Compare("."), "OTLog::ConfirmExactPath: ASSERT: !strFilename.Compare(\".\")\n"); // FILE IS PRESENT? struct stat st; OTString strPath; OTLog::TransformFilePath(strFilename.Get(), strPath); return (0 == stat(strPath.Get(), &st)); }
// Returns true or false whether a specific file exists. // Adds the main path prior to checking. bool OTLog::ConfirmFile(const char * szFileName) { OT_ASSERT(NULL != szFileName); OTString strFilename(szFileName); // FILE IS PRESENT? struct stat st; OTString strRawPath; if (strFilename.Compare(".")) strRawPath.Format("%s", OTLog::Path()); else strRawPath.Format("%s%s%s", OTLog::Path(), OTLog::PathSeparator(), szFileName); OTString strPath; OTLog::TransformFilePath(strRawPath.Get(), strPath); return (0 == stat(strPath.Get(), &st)); }
TEST_F(EngineTestParser, parseFile_haveNullFileLength) { //create work dir CString strCommand; CString strTestDir(m_strRootPath.c_str()); strTestDir += _T("TestDir\\"); strCommand.Format(_T("/c mkdir %s"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); //create a nul file CString strFilePath(strTestDir); strFilePath += _T("ParserEngine.cpp"); HANDLE hFile = CreateFile(strFilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); ASSERT_TRUE(false); } CloseHandle(hFile); CString strPath(strTestDir); CString strFilename("ParserEngine.cpp"); bool bCreateTempDir = false; int nRes = m_parser.parseFile(strPath, strFilename, bCreateTempDir); //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_EQ(0, nRes); }
static BD_FILE_H *file_open(const char* filename, const char *mode) { BD_FILE_H *file = new BD_FILE_H; CStdString strFilename(filename); if(is_udf_iso_path(filename)) { CURL::Encode(strFilename); strFilename.Format("udf://%s", strFilename); CLog::Log(LOGDEBUG, "CDVDInputStreamBluray - Opening file udf iso file %s... (%p)", strFilename.c_str(), file); } else { CLog::Log(LOGDEBUG, "CDVDInputStreamBluray - Opening file %s... (%p)", strFilename.c_str(), file); } file->close = file_close; file->seek = file_seek; file->read = file_read; file->write = file_write; file->tell = file_tell; file->eof = file_eof; CFile* fp = new CFile(); if(fp->Open(strFilename)) { file->internal = (void*)fp; return file; } delete fp; delete file; CLog::Log(LOGDEBUG, "CDVDInputStreamBluray - Error opening file! (%p)", file); return NULL; }
STDMETHODIMP CDirect2DRM::CreateImageFromImageFileExt(BSTR bstrFilename, DWORD dwFlags, LPDIRECT2DRMIMAGE *ppImage) { MMASSERT(ppImage); if (m_pImageCache == NULL) return E_NOTINITIALIZED; HRESULT hr; LPD2DRMIMAGEPRIVATE pImagePriv = NULL; CMFImage *pmfi = NULL; CString strFilename(bstrFilename); // get a reference to the MFImage from the image cache if (FAILED(hr = m_pImageCache->GetImageFromFile(strFilename, flagUsageMapStatically, &pmfi)) || // CoCreate the D2DRMImage object FAILED(hr = CoCreateInstance( CLSID_CDirect2DRMImage, NULL, CLSCTX_INPROC_SERVER, IID_ID2DRMImagePrivate, (LPVOID *) &pImagePriv)) || // initialize the D2DRMImage with the MFImage FAILED(hr = pImagePriv->InitFromMFImage(this, pmfi, dwFlags))) goto e_CreateImageFromImageFile; *ppImage = (LPDIRECT2DRMIMAGE) pImagePriv; // release the extra reference we had from the LoadImage pmfi->Release(); return S_OK; e_CreateImageFromImageFile: MMRELEASE(pImagePriv); MMRELEASE(pmfi); return hr; }
GXBOOL SceneContext::LoadTextureFromFile(GXLPCWSTR szFilename, GTexture** ppTexture) { if(szFilename == NULL || clstd::strlenT(szFilename) == 0) return FALSE; GXGraphics* pGraphics = m_pMOScene->GetGraphicsUnsafe(); if(SUCCEEDED(pGraphics->CreateTextureFromFileW(ppTexture, szFilename))) { return TRUE; } clsize nPath = clpathfile::FindFileName(m_FileName); clsize nFile = clpathfile::FindFileName(szFilename); clStringW strFilename(m_FileName, nPath); strFilename += &szFilename[nFile]; if(FAILED(pGraphics->CreateTextureFromFileW(ppTexture, strFilename))) { CLOG_ERROR(__FUNCTION__": Can't load texture from:\"%s\" or \"%s\".\n", szFilename, strFilename); return FALSE; } return TRUE; }
TEST_F(EngineTestParser, parseFile_createTempDirError) { //create work dir CString strCommand; CString strTestDir(m_strRootPath.c_str()); strTestDir += _T("TestDir\\"); strCommand.Format(_T("/c mkdir %s"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); //copy file CString strSourceFile(m_strRootPath.c_str()); strSourceFile += _T("Test\\Test\\Test.cpp"); CString strDestFile(strTestDir); strDestFile += _T("Test.cpp"); CopyFile(strSourceFile, strDestFile, TRUE); CString strPath(strTestDir); CString strFilename(_T("Test.cpp")); bool bCreateTempDir = true; //dir created int nRes = m_parser.parseFile(strPath, strFilename, bCreateTempDir); //check CString strPathTempDirFile = strTestDir + g_strNameTempDir; strPathTempDirFile += _T("Test.cpp"); bool bRes = isFileExist(strPathTempDirFile); //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_TRUE(nRes == -1 && !bRes); }
bool BaseSoundBuffer::loadFromFile(const Common::String &filename, bool forceReload) { debugC(kWintermuteDebugAudio, "BSoundBuffer::LoadFromFile(%s,%d)", filename.c_str(), forceReload); // Load a file, but avoid having the File-manager handle the disposal of it. _file = BaseFileManager::getEngineInstance()->openFile(filename, true, false); if (!_file) { _gameRef->LOG(0, "Error opening sound file '%s'", filename.c_str()); return STATUS_FAILED; } Common::String strFilename(filename); strFilename.toLowercase(); if (strFilename.hasSuffix(".ogg")) { _stream = Audio::makeVorbisStream(_file, DisposeAfterUse::YES); } else if (strFilename.hasSuffix(".wav")) { int waveSize, waveRate; byte waveFlags; uint16 waveType; if (Audio::loadWAVFromStream(*_file, waveSize, waveRate, waveFlags, &waveType)) { if (waveType == 1) { // We need to wrap the file in a substream to make sure the size is right. _file = new Common::SeekableSubReadStream(_file, _file->pos(), waveSize + _file->pos(), DisposeAfterUse::YES); _stream = Audio::makeRawStream(_file, waveRate, waveFlags, DisposeAfterUse::YES); } else { error("BSoundBuffer::LoadFromFile - WAVE not supported yet for %s with type %d", filename.c_str(), waveType); } } } else { error("BSoundBuffer::LoadFromFile - Unknown filetype for %s", filename.c_str()); } if (!_stream) { return STATUS_FAILED; } _filename = filename; return STATUS_OK; }
TEST_F(EngineTestParser, parseFile_cannotOpenFile) { //create work dir CString strCommand; CString strTestDir(m_strRootPath.c_str()); strTestDir += _T("TestDir"); strCommand.Format(_T("/c mkdir %s"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); CString strPath(strTestDir); CString strFilename("ParserEngine.cpp"); bool bCreateTempDir = false; int nRes = m_parser.parseFile(strPath, strFilename, bCreateTempDir); //del work dir strCommand = _T(""); strCommand.Format(_T("/c rmdir %s /S /Q"), strTestDir); ShellExecute(NULL, NULL, _T("cmd.exe"), strCommand, NULL, SW_HIDE); Sleep(TEST_DELAY); SetCurrentDirectory(g_strCurrentDir.c_str()); ASSERT_EQ(-1, nRes); }
void CDriveIndex::FindRecursively(wstring &strQuery, const WCHAR* &szQueryLower, DWORDLONG QueryFilter, DWORDLONG QueryLength, wstring* strQueryPath, vector<SearchResultFile> &rgsrfResults, BOOL bEnhancedSearch, int maxResults, int &nResults) { WIN32_FIND_DATA ffd; size_t length_of_arg; HANDLE hFind = INVALID_HANDLE_VALUE; // Check that the input path plus 3 is not longer than MAX_PATH. // Three characters are for the "\*" plus NULL appended below. length_of_arg = strQueryPath->length(); if (length_of_arg > (MAX_PATH - 3)) return; // Prepare string for use with FindFile functions. First, copy the // string to a buffer, then append '\*' to the directory name. wstring strPath = wstring(*strQueryPath); if((*strQueryPath)[strQueryPath->length() - 1] != L'\\') strPath += wstring(TEXT("\\*")); else strPath += wstring(TEXT("*")); const WCHAR* szDir = strPath.c_str(); // Find the first file in the directory. hFind = FindFirstFile(szDir, &ffd); if (hFind == INVALID_HANDLE_VALUE) return; unsigned int nFiles = 0; // List all the files in the directory with some info about them. do { if(ffd.dwFileAttributes & FILE_ATTRIBUTE_VIRTUAL || ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) continue; float MatchQuality; wstring strFilename(ffd.cFileName); if(strFilename.compare(TEXT(".")) == 0 || strFilename.compare(TEXT("..")) == 0) continue; nFiles++; if(bEnhancedSearch) MatchQuality = FuzzySearch(strFilename, strQuery); else { wstring szLower(strFilename); for(unsigned int j = 0; j != szLower.length(); j++) szLower[j] = tolower(szLower[j]); MatchQuality = szLower.find(strQuery) != -1; } if(MatchQuality > 0.6f) { nResults++; if(maxResults != -1 && nResults > maxResults) { nResults = -1; break; } SearchResultFile srf; srf.Filename = strFilename; srf.Path = *strQueryPath + TEXT("\\"); srf.Filter = MAXULONG64; srf.MatchQuality = MatchQuality; rgsrfResults.insert(rgsrfResults.end(), srf); } if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { wstring strSubPath = wstring(*strQueryPath); if((*strQueryPath)[strQueryPath->length() - 1] != L'\\') strSubPath += L'\\'; strSubPath += ffd.cFileName; FindRecursively(strQuery, szQueryLower, QueryFilter, QueryLength, &strSubPath, rgsrfResults, bEnhancedSearch, maxResults, nResults); if(nResults == -1) break; } } while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); }
bool Model::load(const std::string& _strFilename) { // open the model configuration file std::ifstream file; std::string strFilename(core->adjustFilenameCase(_strFilename)); file.open(strFilename.c_str(), std::ios::in | std::ios::binary); if(!file) { std::ostringstream os; os << "Failed to open model configuration file '" << strFilename << "'." << std::endl; errorLog(os.str()); return false; } // initialize the data path std::string strPath = m_path; // initialize the animation count int animationCount; animationCount = 0; // parse all lines from the model configuration file int line; for(line = 1; ; line++) { // read the next model configuration line std::string strBuffer; std::getline(file, strBuffer); // stop if we reached the end of file if(file.eof()) break; // check if an error happend while reading from the file if(!file) { std::cerr << "Error while reading from the model configuration file '" << strFilename << "'." << std::endl; return false; } // find the first non-whitespace character std::string::size_type pos; pos = strBuffer.find_first_not_of(" \t"); // check for empty lines if((pos == std::string::npos) || (strBuffer[pos] == '\n') || (strBuffer[pos] == '\r') || (strBuffer[pos] == 0)) continue; // check for comment lines if(strBuffer[pos] == '#') continue; // get the key std::string strKey; strKey = strBuffer.substr(pos, strBuffer.find_first_of(" =\t\n\r", pos) - pos); pos += strKey.size(); // get the '=' character pos = strBuffer.find_first_not_of(" \t", pos); if((pos == std::string::npos) || (strBuffer[pos] != '=')) { std::cerr << strFilename << "(" << line << "): Invalid syntax." << std::endl; return false; } // find the first non-whitespace character after the '=' character pos = strBuffer.find_first_not_of(" \t", pos + 1); // get the data std::string strData; strData = strBuffer.substr(pos, strBuffer.find_first_of("\n\r", pos) - pos); // handle the model creation if(strKey == "scale") { // set rendering scale factor m_renderScale = atof(strData.c_str()); } else if(strKey == "path") { // set the new path for the data files if one hasn't been set already if (m_path == "") strPath = strData; } else if(strKey == "skeleton") { // load core skeleton std::cout << "Loading skeleton '" << strData << "'..." << std::endl; if(!m_calCoreModel->loadCoreSkeleton(strPath + strData)) { CalError::printLastError(); return false; } } else if(strKey == "animation") { // load core animation std::cout << "Loading animation '" << strData << "'..." << std::endl; m_animationId[animationCount] = m_calCoreModel->loadCoreAnimation(strPath + strData); if(m_animationId[animationCount] == -1) { CalError::printLastError(); return false; } animationCount++; } else if(strKey == "mesh") { // load core mesh std::cout << "Loading mesh '" << strData << "'..." << std::endl; if(m_calCoreModel->loadCoreMesh(strPath + strData) == -1) { CalError::printLastError(); return false; } } else if(strKey == "material") { // load core material std::cout << "Loading material '" << strData << "'..." << std::endl; if(m_calCoreModel->loadCoreMaterial(strPath + strData) == -1) { CalError::printLastError(); return false; } } else { std::cerr << strFilename << "(" << line << "): Invalid syntax." << std::endl; return false; } } // explicitely close the file file.close(); // load all textures and store the opengl texture id in the corresponding map in the material int materialId; for(materialId = 0; materialId < m_calCoreModel->getCoreMaterialCount(); materialId++) { // get the core material CalCoreMaterial *pCoreMaterial; pCoreMaterial = m_calCoreModel->getCoreMaterial(materialId); // loop through all maps of the core material int mapId; for(mapId = 0; mapId < pCoreMaterial->getMapCount(); mapId++) { // get the filename of the texture std::string strFilename; strFilename = pCoreMaterial->getMapFilename(mapId); // load the texture from the file GLuint textureId; pngInfo info; textureId = pngBind((strPath + strFilename).c_str(), PNG_BUILDMIPMAPS, PNG_ALPHA, &info, GL_CLAMP, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); //loadTexture(strPath + strFilename); // store the opengl texture id in the user data of the map pCoreMaterial->setMapUserData(mapId, (Cal::UserData)textureId); } } // make one material thread for each material // NOTE: this is not the right way to do it, but this viewer can't do the right // mapping without further information on the model etc. for(materialId = 0; materialId < m_calCoreModel->getCoreMaterialCount(); materialId++) { // create the a material thread m_calCoreModel->createCoreMaterialThread(materialId); // initialize the material thread m_calCoreModel->setCoreMaterialId(materialId, 0, materialId); } // Calculate Bounding Boxes m_calCoreModel->getCoreSkeleton()->calculateBoundingBoxes(m_calCoreModel); m_calModel = new CalModel(m_calCoreModel); // attach all meshes to the model int meshId; for(meshId = 0; meshId < m_calCoreModel->getCoreMeshCount(); meshId++) { m_calModel->attachMesh(meshId); } // set the material set of the whole model m_calModel->setMaterialSet(0); // set initial animation state /* m_state = STATE_MOTION; m_calModel->getMixer()->blendCycle(m_animationId[STATE_MOTION], m_motionBlend[0], 0.0f); m_calModel->getMixer()->blendCycle(m_animationId[STATE_MOTION + 1], m_motionBlend[1], 0.0f); m_calModel->getMixer()->blendCycle(m_animationId[STATE_MOTION + 2], m_motionBlend[2], 0.0f); */ return true; }
/** * * This function Loads a .ini file * * @Author Carsten Scholz * @param _pcFilename is the name of the file which will be loading * @This function goes through the file and scans through it looking at the sections and the values. * */ bool CINIParser::LoadIniFile(const char* _pcFilename) { bool bResult = true; //Our string values for section and the current line. std::string strLine; std::string strSection; std::string strMapKey; //Setting the filename string std::string strFilename(_pcFilename); m_strFilename = strFilename + ".ini";; m_filestream.open(m_strFilename.c_str()); if (m_filestream.is_open()) { while (!m_filestream.eof()) { bool bReadingKey = true; std::string strKey = ""; std::string strValue = ""; getline( m_filestream, strLine ); if (strLine[0] == ';') { //this line is a comment, ignore it continue; } else if (strLine[0] == '[') { //Its a section, read it strSection = ""; for(int32 i = 0; i < static_cast<int32>(strLine.size()); ++i) { if (strLine[i] == '[' || strLine[i] == ']') { continue; } strSection += strLine[i]; } continue; } else if (strLine.empty()) { //string is empty, read next line continue; } for(int32 i = 0; i < static_cast<int32>(strLine.size()); ++i) { if (strLine[i] == ' ') { continue; } else if (strLine[i] == '"') { continue; } else if (strLine[i] == '=') { bReadingKey = false; continue; } else if (strLine[i] == ';') { //the rest of the line are comments break; } if (bReadingKey) { strKey += strLine[i]; } else { strValue += strLine[i]; } } strMapKey = strSection + "|" + strKey; m_mapPairs[strMapKey] = strValue; } m_filestream.close(); } else { bResult = false; } return (bResult); }
Interpreter::CompilationResult MetaProcessor::readInputFromFile(llvm::StringRef filename, Value* result, bool ignoreOutmostBlock /*=false*/) { { // check that it's not binary: std::ifstream in(filename.str().c_str(), std::ios::in | std::ios::binary); char magic[1024] = {0}; in.read(magic, sizeof(magic)); size_t readMagic = in.gcount(); if (readMagic >= 4) { llvm::StringRef magicStr(magic,in.gcount()); llvm::sys::fs::file_magic fileType = llvm::sys::fs::identify_magic(magicStr); if (fileType != llvm::sys::fs::file_magic::unknown) { llvm::errs() << "Error in cling::MetaProcessor: " "cannot read input from a binary file!\n"; return Interpreter::kFailure; } unsigned printable = 0; for (size_t i = 0; i < readMagic; ++i) if (isprint(magic[i])) ++printable; if (10 * printable < 5 * readMagic) { // 50% printable for ASCII files should be a safe guess. llvm::errs() << "Error in cling::MetaProcessor: " "cannot read input from a (likely) binary file!\n" << printable; return Interpreter::kFailure; } } } std::ifstream in(filename.str().c_str()); in.seekg(0, std::ios::end); size_t size = in.tellg(); std::string content(size, ' '); in.seekg(0); in.read(&content[0], size); if (ignoreOutmostBlock && !content.empty()) { static const char whitespace[] = " \t\r\n"; std::string::size_type posNonWS = content.find_first_not_of(whitespace); // Handle comments before leading { while (content[posNonWS] == '/' && content[posNonWS+1] == '/') { // Remove the comment line posNonWS = content.find_first_of('\n', posNonWS+2)+1; } std::string::size_type replaced = posNonWS; if (posNonWS != std::string::npos) { if (content[posNonWS] == '{') { // hide the curly brace: content[posNonWS] = ' '; // and the matching closing '}' posNonWS = content.find_last_not_of(whitespace); if (posNonWS != std::string::npos) { if (content[posNonWS] == ';' && content[posNonWS-1] == '}') { content[posNonWS--] = ' '; // replace ';' and enter next if } if (content[posNonWS] == '}') { content[posNonWS] = ' '; // replace '}' } else { std::string::size_type posComment = content.find_last_of('}'); if (content[posComment] == '}') { content[posComment] = ' '; // replace '}' } posComment = content.find_first_not_of(whitespace, posComment); if (content[posComment] == '/' && content[posComment+1] == '/') { // More text (comments) are okay after the last '}', but // we can not easily find it to remove it (so we need to upgrade // this code to better handle the case with comments or // preprocessor code before and after the leading { and // trailing }) while (posComment <= posNonWS) { content[posComment++] = ' '; // replace '}' and comment } } else { content[replaced] = '{'; // By putting the '{' back, we keep the code as consistent as // the user wrote it ... but we should still warn that we not // goint to treat this file an unamed macro. llvm::errs() << "Warning in cling::MetaProcessor: can not find the closing '}', " << llvm::sys::path::filename(filename) << " is not handled as an unamed script!\n"; } // did not find '}'' } // remove comments after the trailing '}' } // find '}' } // have '{' } // have non-whitespace } // ignore outmost block std::string strFilename(filename.str()); m_CurrentlyExecutingFile = strFilename; bool topmost = !m_TopExecutingFile.data(); if (topmost) m_TopExecutingFile = m_CurrentlyExecutingFile; Interpreter::CompilationResult ret; // We don't want to value print the results of a unnamed macro. content = "#line 2 \"" + filename.str() + "\" \n" + content; if (process((content + ";").c_str(), ret, result)) { // Input file has to be complete. llvm::errs() << "Error in cling::MetaProcessor: file " << llvm::sys::path::filename(filename) << " is incomplete (missing parenthesis or similar)!\n"; ret = Interpreter::kFailure; } m_CurrentlyExecutingFile = llvm::StringRef(); if (topmost) m_TopExecutingFile = llvm::StringRef(); return ret; }
BOOL PathNameEx::RemoveRecursively(const String_256& rPath) { PORTNOTETRACE("other","PathNameEx::RemoveRecursively - do nothing"); #ifndef EXCLUDE_FROM_XARALX String_256 strFilename(rPath); strFilename.toLower(); // See if the path points to a file (the easy case) or a directory if (strFilename[strFilename.Length() - 1] == chPathSep) { strFilename.Remove(strFilename.Length() - 1, 1); goto DIRECTORY; } struct _stat fileData; if (_stat((TCHAR*) strFilename, &fileData)) { if (errno == ENOENT) { ERROR3("Filename or path not found"); } else { ERROR3("_stat() failed with an unknown error"); } return FALSE; } if (fileData.st_mode & _S_IFDIR) // directory { DIRECTORY: // Make sure the directory is not the current one TCHAR tchbuff[_MAX_PATH]; if (_getcwd(tchbuff, _MAX_PATH) == NULL) { ERROR3("Can't get working directory"); return FALSE; } if (strstr(_strlwr(tchbuff), (TCHAR*) strFilename)) { // change to upper dir (we should never attempt to delete the root directory!) PathName path(strFilename); if (_chdir((TCHAR*) String_256(path.GetLocation(FALSE)))) { ERROR3("Can't change directory"); return FALSE; } } // Try to remove it in the hope that it's empty if (_rmdir((TCHAR*) strFilename) == -1) { if (errno == ENOTEMPTY || errno == EACCES) { _finddata_t findData; String_256 strSearchPattern(strFilename); strSearchPattern += chPathSep; strSearchPattern += _T("*"); // add wildcard INT32 hSearch = _findfirst(strSearchPattern, &findData); if (hSearch == -1) return FALSE; do { if (!(strcmp(findData.name, _T(".")) && strcmp(findData.name, _T("..")))) continue; // skip this directory (.) or its parent (..) String_256 strFoundFile(strFilename); strFoundFile += chPathSep; strFoundFile += findData.name; RemoveRecursively(strFoundFile); } while (_findnext(hSearch, &findData) == 0); _findclose(hSearch); return (_rmdir((TCHAR*) strFilename) != -1); } else { return FALSE; // probably invalid path } } else return TRUE; // succedded } else if (fileData.st_mode & _S_IFREG) // file return (remove((TCHAR*) strFilename) != -1); else #endif return FALSE; }
/******************************************************************************* ** ** Function: import ** ** Description: Import data from an XML file. Fill the databases. ** ** Returns: True if ok. ** *******************************************************************************/ bool RouteDataSet::import () { static const char fn [] = "RouteDataSet::import"; ALOGD ("%s: enter", fn); bool retval = false; #if 0 xmlDocPtr doc; xmlNodePtr node1; std::string strFilename(bcm_nfc_location); strFilename += sConfigFile; deleteDatabase (); doc = xmlParseFile (strFilename.c_str()); if (doc == NULL) { ALOGD ("%s: fail parse", fn); goto TheEnd; } node1 = xmlDocGetRootElement (doc); if (node1 == NULL) { ALOGE ("%s: fail root element", fn); goto TheEnd; } ALOGD ("%s: root=%s", fn, node1->name); node1 = node1->xmlChildrenNode; while (node1) //loop through all elements in <Routes ... { if (xmlStrcmp(node1->name, (const xmlChar*) "Route")==0) { xmlChar* value = xmlGetProp (node1, (const xmlChar*) "Type"); if (value && (xmlStrcmp (value, (const xmlChar*) "SecElemSelectedRoutes") == 0)) { ALOGD ("%s: found SecElemSelectedRoutes", fn); xmlNodePtr node2 = node1->xmlChildrenNode; while (node2) //loop all elements in <Route Type="SecElemSelectedRoutes" ... { if (xmlStrcmp(node2->name, (const xmlChar*) "Proto")==0) importProtocolRoute (node2, mSecElemRouteDatabase); else if (xmlStrcmp(node2->name, (const xmlChar*) "Tech")==0) importTechnologyRoute (node2, mSecElemRouteDatabase); node2 = node2->next; } //loop all elements in <Route Type="SecElemSelectedRoutes" ... } else if (value && (xmlStrcmp (value, (const xmlChar*) "DefaultRoutes") == 0)) { ALOGD ("%s: found DefaultRoutes", fn); xmlNodePtr node2 = node1->xmlChildrenNode; while (node2) //loop all elements in <Route Type="DefaultRoutes" ... { if (xmlStrcmp(node2->name, (const xmlChar*) "Proto")==0) importProtocolRoute (node2, mDefaultRouteDatabase); else if (xmlStrcmp(node2->name, (const xmlChar*) "Tech")==0) importTechnologyRoute (node2, mDefaultRouteDatabase); node2 = node2->next; } //loop all elements in <Route Type="DefaultRoutes" ... } if (value) xmlFree (value); } //check <Route ... node1 = node1->next; } //loop through all elements in <Routes ... retval = true; TheEnd: xmlFreeDoc (doc); xmlCleanupParser (); ALOGD ("%s: exit; return=%u", fn, retval); #endif return retval; }
Interpreter::CompilationResult MetaProcessor::readInputFromFile(llvm::StringRef filename, StoredValueRef* result /* = 0 */, bool ignoreOutmostBlock /*=false*/) { { // check that it's not binary: std::ifstream in(filename.str().c_str(), std::ios::in | std::ios::binary); char magic[1024] = {0}; in.read(magic, sizeof(magic)); size_t readMagic = in.gcount(); if (readMagic >= 4) { llvm::sys::LLVMFileType fileType = llvm::sys::IdentifyFileType(magic, 4); if (fileType != llvm::sys::Unknown_FileType) { llvm::errs() << "Error in cling::MetaProcessor: " "cannot read input from a binary file!\n"; return Interpreter::kFailure; } unsigned printable = 0; for (size_t i = 0; i < readMagic; ++i) if (isprint(magic[i])) ++printable; if (10 * printable < 5 * readMagic) { // 50% printable for ASCII files should be a safe guess. llvm::errs() << "Error in cling::MetaProcessor: " "cannot read input from a (likely) binary file!\n" << printable; return Interpreter::kFailure; } } } std::ifstream in(filename.str().c_str()); in.seekg(0, std::ios::end); size_t size = in.tellg(); std::string content(size, ' '); in.seekg(0); in.read(&content[0], size); if (ignoreOutmostBlock && !content.empty()) { static const char whitespace[] = " \t\r\n"; std::string::size_type posNonWS = content.find_first_not_of(whitespace); std::string::size_type replaced = posNonWS; if (posNonWS != std::string::npos) { if (content[posNonWS] == '{') { // hide the curly brace: content[posNonWS] = ' '; // and the matching closing '}' posNonWS = content.find_last_not_of(whitespace); if (posNonWS != std::string::npos) { if (content[posNonWS] == ';' && content[posNonWS-1] == '}') { content[posNonWS--] = ' '; // replace ';' and enter next if } if (content[posNonWS] == '}') { content[posNonWS] = ' '; // replace '}' } else { // More text (comments) are okay after the last '}', but // we can not easily find it to remove it (so we need to upgrade // this code to better handle the case with comments or // preprocessor code before and after the leading { and // trailing }) content[replaced] = '{'; // By putting the '{' back, we keep the code as consistent as // the user wrote it ... but we should still warn that we not // goint to treat this file an unamed macro. llvm::errs() << "Warning in cling::MetaProcessor: can not find the closing '}', " << llvm::sys::path::filename(filename) << " is not handled as an unamed script!\n"; } } // find '}' } // have '{' } // have non-whitespace } // ignore outmost block std::string strFilename(filename.str()); m_CurrentlyExecutingFile = strFilename; bool topmost = !m_TopExecutingFile.data(); if (topmost) m_TopExecutingFile = m_CurrentlyExecutingFile; Interpreter::CompilationResult ret = Interpreter::kSuccess; process(content.c_str(), result, &ret); m_CurrentlyExecutingFile = llvm::StringRef(); if (topmost) m_TopExecutingFile = llvm::StringRef(); return ret; }
Mesh* MeshFactory::generateMeshFromFile(const char* _filename, Skeleton* _skel){ std::string strFilename(_filename); return generateMeshFromFile(strFilename, _skel); }