int mainprogram (int argc, char *argv[]) { char *outwavhdrfilename,*outwavdatfilename; int len; int result=0; if (parseArgs(argc,argv)!=0) { printusage(); return 0; } len = strlen(wavtool_args.outputfilename)+4+1; outwavhdrfilename = (char *)malloc(len*sizeof(char)); memset(outwavhdrfilename,0,len*sizeof(char)); outwavdatfilename = (char *)malloc(len*sizeof(char)); memset(outwavdatfilename,0,len*sizeof(char)); _snprintf(outwavhdrfilename,len,"%s.whd",wavtool_args.outputfilename); _snprintf(outwavdatfilename,len,"%s.dat",wavtool_args.outputfilename); if (!isFileExist(outwavhdrfilename)) { wfh_init(outwavhdrfilename); } if (!isFileExist(outwavdatfilename)) { wfd_init(outwavdatfilename); } len = wfd_append(outwavdatfilename,wavtool_args.inputfilename,wavtool_args.offset,wavtool_args.length,wavtool_args.ovr,wavtool_args.p,wavtool_args.v); result = wfh_putlength(outwavhdrfilename,len); return 0; }
int DeleteVM::mountNFS() { String logContent; char dirName[1024]; memset(dirName, 0, sizeof(dirName)); strcpy(dirName, nfsDir.c_str()); for(int i=0; i<strlen(dirName); i++) { if( dirName[i] == '/' ) dirName[i] = '-'; } String temp = dirName + 1; temp = nfsIP + "_" + temp; String dir = getCurrentDir() + "/nfs/" + temp; localNFSDir = dir; if( !isFileExist(dir) ) { String mkdir = "mkdir -p " + dir; system(mkdir.c_str()); if( !isFileExist(dir) ) { log.write("create dir " + dir + " error.", Log::ERROR); return 1; } } ///////// String mountPoint = "mountpoint " + dir; bool bMounted = false; int iRet = system( mountPoint.c_str()); if( iRet == 0 ) return 0; String mountSrc = nfsIP+ ":" + nfsDir; logContent = "begin to mount " + mountSrc + " to " + dir; log.write(logContent, Log::INFO); if( mount(mountSrc, dir) == false ) { logContent = "mount " + mountSrc + " to " + dir + " failed."; log.write(logContent, Log::ERROR); return 1; } logContent = "mount " + mountSrc + " to " + dir + " success."; log.write(logContent, Log::INFO); return 0; }
TEST_F(EngineTestParser, restore_fullOperation) { //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); //obfuscation CString strFilename(_T("Test.cpp")); std::wstring strPath(strTestDir.GetBuffer()); m_parser.setCurrentPath(strPath); int nRes = m_parser.obfuscate(); //check CString strPathTempDirFile = strTestDir + g_strNameTempDir; strPathTempDirFile += _T("Test.cpp"); bool bRes1 = isFileExist(strPathTempDirFile); CString strPathArchFile = strTestDir; strPathArchFile += _T("arch_obfuscate.obf"); bool bRes2 = isFileExist(strPathArchFile); bool bRes3 = false; if (!nRes && bRes1 && bRes2) { SetCurrentDirectory(g_strCurrentDir.c_str()); nRes = m_parser.restore(); bRes2 = isFileExist(strPathArchFile); bRes3 = !bRes2 && !nRes; } //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(bRes3); }
void DU_File::listDirectory(const string &path, vector<string> &files, bool bRecursive) { vector<string> tf; scanDir(path, tf, 0, 0); for(size_t i = 0; i < tf.size(); i++) { if(tf[i] == "." || tf[i] == "..") continue; string s = path + "/" + tf[i]; if(isFileExist(s, S_IFDIR)) { files.push_back(simplifyDirectory(s)); if(bRecursive) { listDirectory(s, files, bRecursive); } } else { files.push_back(simplifyDirectory(s)); } } }
void level_processing() { uint32_t modifyTime = 0; StringArray level_file_list; std::string folder = remove_top_folder(g_config->m_inputDir); scan_dir(level_file_list, g_config->m_inputDir.c_str(), EngineNames::LEVEL, SCAN_FILES, true); LOGI("level file num = %d", level_file_list.size()); for (size_t i=0; i<level_file_list.size(); ++i) { LOGI("level %s", level_file_list[i].c_str()); } for (size_t i=0; i<level_file_list.size(); ++i) { const std::string& input = level_file_list[i]; std::string output = input_to_output(input); if(!g_config->is_file_changed(input, modifyTime) && isFileExist(output)) continue; LevelCompiler* level = new LevelCompiler; g_config->m_levels.push_back(level); level->m_input = input; level->m_output = output; level->m_modifyTime = modifyTime; level->preProcess(); level->go(); } }
bool FileUtilsTest::init() { BackLayer::init(); Size visibleSize = Director::getInstance()->getVisibleSize(); auto fileutils = FileUtils::getInstance(); //check file //实际上,读取的是编译后的目录,不是Resources下的 if (fileutils->isFileExist("FileUtilsTest/hellotest.txt")) { log("test.txt is exist"); //read file std::string ret; ret = fileutils->getStringFromFile("FileUtilsTest/hellotest.txt"); log("content: %s", ret.c_str()); } else { log("test.txt is not exist"); } //读取中文字符的例子 auto item = MenuItemFont::create("read chinese text", this, menu_selector(FileUtilsTest::onMenuCallBack)); auto menu = Menu::create(item, nullptr); addChild(menu); return true; }
void autoMountOnBootUp(void) { FILE *fp; int line=0; char buf[512]; char partition[32]; char usbMntCmd[64]; int ret=-1; if(isFileExist(PARTITION_FILE)){ fp= fopen(PARTITION_FILE, "r"); if (!fp) { printf("can not open /proc/partitions\n"); return; } while (fgets(buf, sizeof(buf), fp)) { ret=get_blockDevPartition(buf, &partition); if(ret==0) { if(Check_shouldMount(partition)==0){ sprintf(usbMntCmd, "DEVPATH=/sys/block/sda/%s ACTION=add usbmount block", partition); RunSystemCmd(NULL_FILE, "echo", usbMntCmd, NULL_STR); system(usbMntCmd); } } } fclose(fp); } }
bool AudioRecord::openFile() { bool result = false; _debug ("AudioRecord: Open file()"); if (isFileExist()) { _debug ("AudioRecord: Filename does not exist, creating one"); byteCounter_ = 0; if (fileType_ == FILE_RAW) { result = setRawFile(); } else if (fileType_ == FILE_WAV) { result = setWavFile(); } } else { _debug ("AudioRecord: Filename already exist opening it"); if (fileType_ == FILE_RAW) { result = openExistingRawFile(); } else if (fileType_ == FILE_WAV) { result = openExistingWavFile(); } } return result; }
string MyUtility::getUTF8Char(const string key) { auto sharedFileUtils = FileUtils::getInstance(); std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("utf8_char.plist"); bool isExist = false; isExist = sharedFileUtils->isFileExist(fullPathForFilename); if (!isExist) { log("utf8_char.plist doesn't exist."); return ""; } ValueMap map = sharedFileUtils->getValueMapFromFile(fullPathForFilename); Value value = map[key]; //log("%s - %s",key.c_str(), value.asString().c_str()); if (value.isNull()) { log("%s doesn't exist.",key.c_str()); return ""; } return value.asString(); }
HTREEITEM CGrannyListView::InsertEquipItem(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelTD *model) { const UINT nMask = TVIF_TEXT | TVIF_PARAM; if (!model) return NULL; CString strText; strText.Format("%04d %s", GETID(id), getFileName(model->m_filename).c_str()); HTREEITEM htChar = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0); strText.Format("file: %s%s", isFileExist(model->m_filename) ? "":"(x) ",model->m_filename.c_str()); tree.InsertItem(strText, htChar); strText.Format("id: %d (0x%08x)", id, id); tree.InsertItem(strText, htChar); if (!model->desc.empty()) { strText.Format("desc: %s", model->desc.c_str()); tree.InsertItem(strText, htChar); } strText.Format("hand: %s", getHandName(model->hand).c_str()); tree.InsertItem(strText, htChar); strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone); tree.InsertItem(strText, htChar); return htChar; }
void AppLang::readLocalizationFile() { if (!_hasInit) { _hasInit = true; auto fileUtils = FileUtils::getInstance(); if (!fileUtils->isFileExist(_localizationFileName)) { cocos2d::log("[WARNING]:not find %s", _localizationFileName.c_str()); return; } auto fullFilePath = fileUtils->fullPathForFilename(_localizationFileName); std::string fileContent = FileUtils::getInstance()->getStringFromFile(fullFilePath); if(fileContent.empty()) return; if (_docRootjson.Parse<0>(fileContent.c_str()).HasParseError()) { cocos2d::log("[WARNING]:read json file %s failed because of %d", _localizationFileName.c_str(), _docRootjson.GetParseError()); return; } } }
/** * ファイルDL正常終了コールバック */ void HelloWorld::onHttpRequestCompleted(extension::HttpClient* sender, extension::HttpResponse* response) { Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); auto fileUtils = FileUtils::sharedFileUtils(); std::string filename = fileUtils->getWritablePath() + "hoge.jpg"; if (fileUtils->isFileExist(filename)) { log("file exist. use hoge.jpg."); auto sprite = Sprite::create(filename.c_str()); sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sprite, 0); } else { log("no file exist. use default image, and save the file."); if (response->isSucceed()) { std::vector<char>* buffer = response->getResponseData(); auto* img = new Image(); img->initWithImageData(reinterpret_cast<unsigned char*>(&(buffer->front())), buffer->size()); img->saveToFile(filename.c_str()); auto* texture = new Texture2D(); texture->initWithImage(img); auto sprite = Sprite::createWithTexture(texture); sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sprite, 0); } } }
//初始化数据库 int NoteDAO::initDB() { auto sharedFileUtils = FileUtils::getInstance(); string path = dbDirectoryFile(); bool isExist = false; isExist = sharedFileUtils->isFileExist(path); if (!isExist) { log("NotesList.sqlite3 doesn't exist."); return -1; } sqlite3* db= NULL; if (sqlite3_open(path.c_str(), &db) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "DB open failure."); } else { char *err; string createSQL = "CREATE TABLE IF NOT EXISTS Note (cdate TEXT PRIMARY KEY, content TEXT)"; if (sqlite3_exec(db,createSQL.c_str(),NULL,NULL,&err) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "Create table failure."); } sqlite3_close(db); } return 0; }
veFileData* veFileAndroid::readFileToBuffer(const std::string &filePath) { if (!veFileAndroid::ASSET_MANAGER) return nullptr; std::string fullPath = getFullFilePath(filePath); if (!isFileExist(fullPath)) return nullptr; auto fileIter = _fileDataCache.find(fullPath); if (fileIter != _fileDataCache.end()) return fileIter->second; const char* str = fullPath.c_str() + strlen("assets/"); AAsset* asset = AAssetManager_open(veFileAndroid::ASSET_MANAGER, str, AASSET_MODE_UNKNOWN); if (asset) { off_t fileSize = AAsset_getLength(asset); char *buffer = new char[fileSize + 1]; buffer[fileSize] = '\0'; int bytesread = AAsset_read(asset, (void*)buffer, fileSize); auto fileData = new veFileData(); fileData->buffer = buffer; fileData->size = fileSize + 1; //veLog("filebuffer: %s, size: %d", buffer, fileSize); _fileDataCache[fullPath] = fileData; AAsset_close(asset); return fileData; } return nullptr; }
// 加载ini文件 bool IniParser::load(const char* filename) { if (!isFileExist(filename)) return false; m_filename = filename; return true; }
bool ProjectConfig::validate() const { auto utils = cocos2d::FileUtils::getInstance(); if (!utils->isDirectoryExist(_projectDir)) return false; if (!utils->isDirectoryExist(getWritableRealPath())) return false; if (!utils->isFileExist(getScriptFileRealPath())) return false; return true; }
std::string CCFileUtils::getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) { std::string ret = strDirectory+strFilename; if (!isFileExist(ret)) { ret = ""; } return ret; }
HTREEITEM CGrannyListView::InsertModelTD(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelTD *model) { const UINT nMask = TVIF_TEXT | TVIF_PARAM; if (!model) return NULL; CString strText; strText.Format("%04d %s", GETID(id), getFileName(model->m_filename).c_str()); HTREEITEM htChar = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0); //HTREEITEM htAnim = tree.InsertItem("anim", htChar); HTREEITEM htEquip = IsPlayerModelID(id) ? tree.InsertItem("equip", htChar) : NULL; strText.Format("file: %s%s", isFileExist(model->m_filename) ? "":"(x) ",model->m_filename.c_str()); tree.InsertItem(strText, htChar); if (!model->desc.empty()) { strText.Format("desc: %s", model->desc.c_str()); tree.InsertItem(strText, htChar); } strText.Format("hand: %s", getHandName(model->hand).c_str()); tree.InsertItem(strText, htChar); strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone); tree.InsertItem(strText, htChar); #if 0 strText.Format("%s (default)", getFileName(model->defaultanimname).c_str()); HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(AnimTypeData::GetAnimType("default.animation")), htAnim, 0); strText.Format("file: %s%s", isFileExist(model->defaultanimname) ? "":"(x) ",model->defaultanimname.c_str()); tree.InsertItem(strText, htItem); std::map<int, std::string>& anim_names = model->animation_names; for (std::map<int, std::string>::iterator i = anim_names.begin(); i != anim_names.end(); i++) { strText.Format("%s (%s,%d)", getFileName(i->second).c_str(), AnimTypeData::GetAnimTypeName(i->first).c_str(),i->first); HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(i->first), htAnim,0); strText.Format("file: %s%s", isFileExist(i->second) ? "":"(x) ",i->second.c_str()); tree.InsertItem(strText, htItem); } #endif return htEquip; }
void NM::CDiction::make_dict() { if(isFileExist(m_wordfreqpath.c_str())) return; getstopword(); getwordfreq_dir(m_distdir); wordfreq_savetofile(); }
bool MEngine::doesLevelExist(const char * filename) { M_PROFILE_SCOPE(MEngine::doesLevelExist); if(! filename) return false; char globalFilename[256]; getGlobalFilename(globalFilename, m_systemContext->getWorkingDirectory(), filename); return isFileExist(globalFilename); }
void Seeker::makeInitialSequence() { if (isFileExist(_fileName)) { readInitialSeq(_sequence, _v, _fileName); } else { makeInitialSeq(_sequence, _v, _kp, _km); } }
void Config::load( void ) { conf.clear(); if ( !isFileExist( fileName ) ) throw Exception( std::string( "Config file is not exist: " ).append( fileName ), std::string( "void Config::load( void )" ), Exception::ExcData( fileName.c_str(), fileName.length() + 1 ) ); std::ifstream confFile( fileName.c_str(), std::ifstream::in ); if ( !confFile.good() ) { confFile.close(); throw Exception( std::string( "Error while opening config file: " ).append( fileName ), std::string( "void Config::load( void )" ), Exception::ExcData( fileName.c_str(), fileName.length() + 1 ) ); } std::string buf; while ( !confFile.eof() ) { std::getline( confFile, buf ); size_t found = buf.find_first_of( "//" ); if ( found != std::string::npos ) buf.resize( found ); found = buf.find_first_of( "=" ); if ( found == std::string::npos ) continue; std::string key = cutOff( buf.substr( 0, found ) ); std::string val = cutOff( buf.substr( found + 1, buf.length() - found ) ); if ( !key.length() ) continue; auto foundVal = conf.find( key ); if ( foundVal != conf.end() ) { Log::getLog() << std::string( "config value redefinition: " ).append( key ) \ .append( " = " ) \ .append( conf[ key ] ) \ .append( " <- " ) \ .append( val ); foundVal->second = val; } else conf[ key ] = val; } Log::getLog() << std::string( "config file was loaded" ); confFile.close(); }
levelManager::levelManager() { if (isFileExist("UserDefault.xml")==false) { CCUserDefault::getInstance()->setIntegerForKey("CurLevel", 1); CCUserDefault::getInstance()->setIntegerForKey("MaxLevel", 1); } m_curLvl = CCUserDefault::getInstance()->getIntegerForKey("CurLevel"); m_maxLvl = CCUserDefault::getInstance()->getIntegerForKey("MaxLevel"); }
void TestIsFileExist::onEnter() { FileUtilsDemo::onEnter(); auto s = Director::getInstance()->getWinSize(); auto sharedFileUtils = FileUtils::getInstance(); Label* label = nullptr; bool isExist = false; isExist = sharedFileUtils->isFileExist("Images/grossini.png"); label = Label::createWithSystemFont(isExist ? "Images/grossini.png exists" : "Images/grossini.png doesn't exist", "", 20); label->setPosition(s.width/2, s.height/3); this->addChild(label); isExist = sharedFileUtils->isFileExist("Images/grossini.xcf"); label = Label::createWithSystemFont(isExist ? "Images/grossini.xcf exists" : "Images/grossini.xcf doesn't exist", "", 20); label->setPosition(s.width/2, s.height/3*2); this->addChild(label); }
BOOL CNetRssProtocol::Start() { bStarted=1; CString sFile=GetUserFolder()+"RssLatest.txt"; if(isFileExist(sFile)){ CFile file(sFile, CFile::modeRead); // создать файл CArchive ar(&file, CArchive::load); aLoadedRss.Serialize(ar); } return TRUE; }
HTREEITEM CGrannyListView::InsertModelAOS(CTreeCtrl& tree, HTREEITEM htRoot, Uint32 id, cGrannyModelAOS *model) { const UINT nMask = TVIF_TEXT | TVIF_PARAM; if (!model) return NULL; CString strText; strText.Format("%04d %s", GETID(id), model->desc.c_str()); HTREEITEM htChar = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id), htRoot, 0); HTREEITEM htPart = tree.InsertItem("part", htChar); //HTREEITEM htAnim = tree.InsertItem("anim", htChar); HTREEITEM htEquip = tree.InsertItem("equip", htChar); std::map <int, cGrannyModelTD *> models = model->models; if (models.empty()) return htEquip; for (std::map<int, cGrannyModelTD*>::iterator i = models.begin(); i != models.end(); i++) { cGrannyModelTD *td = i->second; if (!td) continue; UINT id2 = 0xC000 | id<< 4 | i->first; strText.Format("%2d %s", i->first, cGrannyLoader::GetAosBodyName(i->first).c_str()); HTREEITEM htPart2 = tree.InsertItem(nMask, strText, 0,0,0,0, SETCHAR(id2), htPart, 0); strText.Format("file: %s", td->m_filename.c_str()); tree.InsertItem(strText, htPart2); } if (!model->desc.empty()) { strText.Format("desc: %s", model->desc.c_str()); tree.InsertItem(strText, htChar); } strText.Format("hand: %s", getHandName(model->hand).c_str()); tree.InsertItem(strText, htChar); strText.Format("bone left: %d, right: %d", model->left_hand_bone, model->right_hand_bone); tree.InsertItem(strText, htChar); #if 0 // part animation is same. std::map<int, std::string>& anim_names = models.begin()->second->animation_names; for (std::map<int, std::string>::iterator i = anim_names.begin(); i != anim_names.end(); i++) { strText.Format("%s (%s,%d)", getFileName(i->second).c_str(), AnimTypeData::GetAnimTypeName(i->first).c_str(),i->first); HTREEITEM htItem = tree.InsertItem(nMask, strText, 0,0,0,0, SETANIM(i->first), htAnim,0); strText.Format("file: %s%s", isFileExist(i->second) ? "":"(x) ",i->second.c_str()); tree.InsertItem(strText, htItem); } #endif return htEquip; }
bool FileUtil::isExist(const string& relativeFile){ auto it = _dirs.begin(); while (it != _dirs.end()) { auto& dir = (*it); sprintf(_tempBuf,"%s/%s/%s",_baseDir.c_str(),dir.c_str(),relativeFile.c_str()); if (isFileExist(string(_tempBuf))) { return true; } } return false; }
void FileUtilsLayer::OnClickMenu1(Ref* pSender) { auto sharedFileUtils = FileUtils::getInstance(); std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("test.txt"); log("fullPathForFilename path = %s", fullPathForFilename.c_str()); bool isExist = false; isExist = sharedFileUtils->isFileExist("test.txt"); log("%s",isExist ? "test.txt exists" : "test.txt doesn't exist"); }
// 按照 _dirs 里面的顺序进行查找 // 需要检查文件是否存在 string FileUtil::getFullPath(const string& filename){ auto it = _dirs.begin(); while (it != _dirs.end()) { auto& dir = (*it); sprintf(_tempBuf,"%s/%s/%s",_baseDir.c_str(),dir.c_str(),filename.c_str()); if (isFileExist(string(_tempBuf))) { return _tempBuf; } ++it; } printf("can not found file : %s.\n",filename.c_str()); return ""; }
void CRasterDataset::readData() { // if data needs to be read from a file if (m_dataType == VAR) { if(isFileExist(strFile.c_str())) { ifstream ifs (strFile.c_str()); ifs>>*this; ifs.close(); qDebug()<<"reading file finished\n"; } }