ImplNetCaffe(const std::string& caffeProto, const std::string& caffeTrainedModel, const int gpuId, const bool enableGoogleLogging, const std::string& lastBlobName) : mGpuId{gpuId}, mCaffeProto{caffeProto}, mCaffeTrainedModel{caffeTrainedModel}, mLastBlobName{lastBlobName} { const std::string message{".\nPossible causes:\n\t1. Not downloading the OpenPose trained models." "\n\t2. Not running OpenPose from the same directory where the `model`" " folder is located.\n\t3. Using paths with spaces."}; if (!existFile(mCaffeProto)) error("Prototxt file not found: " + mCaffeProto + message, __LINE__, __FUNCTION__, __FILE__); if (!existFile(mCaffeTrainedModel)) error("Caffe trained model file not found: " + mCaffeTrainedModel + message, __LINE__, __FUNCTION__, __FILE__); // Double if condition in order to speed up the program if it is called several times if (enableGoogleLogging && !sGoogleLoggingInitialized) { std::lock_guard<std::mutex> lock{sMutexNetCaffe}; if (enableGoogleLogging && !sGoogleLoggingInitialized) { google::InitGoogleLogging("OpenPose"); sGoogleLoggingInitialized = true; } } }
static void GetCryptoSeed(uchar *seed, uint seed_size, char *seed_file) { if(isFactoryDirEnabled()) { autoBlock_t gab; mutex(); // zantei > if(existFile(seed_file) && getFileSize(seed_file) != (uint64)seed_size) { cout("#########################################################\n"); cout("## SEED_FILE SIZE ERROR -- どっかに古い exe があるで! ##\n"); cout("#########################################################\n"); removeFile(seed_file); } // < zantei if(existFile(seed_file)) { FILE *fp; uint index; fp = fileOpen(seed_file, "rb"); fileRead(fp, gndBlockVar(seed, seed_size, gab)); fileClose(fp); for(index = 0; index < seed_size; index++) { if(seed[index] < 0xff) { seed[index]++; break; } seed[index] = 0x00; } } else getCryptoBlock_MS(seed, seed_size); writeBinary(seed_file, gndBlockVar(seed, seed_size, gab)); unmutex(); } else getCryptoBlock_MS(seed, seed_size); }
TEST(testIndexP, generateNames) { // this will avoid overriding previously generated names and keep consistent the results if (!existFile("names.txt")) { FileInputStream* fisNames = new FileInputStream("names.csv", "r"); const char* fullNames = fisNames->readFull(); FileInputStream* fisLastNames = new FileInputStream("last.csv", "r"); const char* fullLast = fisLastNames->readFull(); std::vector<string> names = split(fullNames, "\r"); cout << names.size() << endl; std::vector<string> lastNames = split(fullLast, "\r"); cout << lastNames.size() << endl; FileOutputStream* fos = new FileOutputStream("names.txt", "w+"); for (int x = 0; x < 10000000; x++) { int i = rand() % names.size(); std::string name = names.at(i); i = rand() % lastNames.size(); std::string lastName = lastNames.at(i); std::string fullName = name + " " + lastName; fos->writeString(fullName); } fos->close(); fisNames->close(); fisLastNames->close(); delete fos; delete fisNames; delete fisLastNames; } }
static char *FindUserTemplate(void) { char *dir = getCwd(); for(; ; ) { char *tmplDir = combine(dir, "Template"); char *tmplSln; tmplSln = combine(tmplDir, "UUUUTMPL.sln"); if(existFile(tmplSln)) { memFree(dir); memFree(tmplSln); cout("User_Template: %s\n", tmplDir); return tmplDir; } memFree(tmplDir); memFree(tmplSln); dir = changeLocal_xc(dir, ""); errorCase(strlen(dir) == 2); UTIntoParentStep++; } error(); // never return NULL; }
void BufferManager::dropBuffer(Buffer* buffer) { if (_log->isDebug()) _log->debug(2, "dropBuffer(buffer: fileName %s)", buffer->fileName().c_str()); // Removes the file if the buffermanager does not have more buffers of the same file std::map<std::string, int*>::iterator it = _buffersByLog->find(buffer->fileName()); // If the file counter is zero it means there're no references to it and should be // deleted from disk (pe. commit), if the file is not referenced this will mean the // buffer comes from other buffermanager and should be removed. bool dropFile = false; if (it != _buffersByLog->end()) { int* count = it->second; if (*count <= 0) { dropFile = true; delete count; _buffersByLog->erase(it); } } else { dropFile = true; } if (dropFile) { std::string file = buffer->fileName(); std::string datadir = getSetting("DATA_DIR"); char* fullFilePath = combinePath(datadir.c_str(), file.c_str()); if (_log->isDebug()) _log->debug(2, "removing the log file: %s", fullFilePath); if (existFile(fullFilePath)) { if (!removeFile(fullFilePath)) { _log->error("An error ocurred removing the file: %s. Error Number: %d, Error description: %s", fullFilePath, errno, strerror(errno)); } } free(fullFilePath); } delete buffer; }
static void LoadSaveData(void) { char *file = GetSaveDataFile(); if(existFile(file)) { autoBlock_t *fileData = readBinary(file); char *fileText; autoList_t *lines; autoList_t *sVals; DoMask(fileData); fileText = unbindBlock2Line(fileData); fileText = replaceLine(fileText, "\r\n", "\n", 0); lines = tokenize(fileText, '\n'); sVals = tokenize(getLine(lines, 1), ','); StageNo = toValue(refLine(sVals, 0)); HiScore = toValue(refLine(sVals, 1)); ExtraOpened = getCount(lines) == 3; memFree(fileText); releaseDim(lines, 1); releaseDim(sVals, 1); } memFree(file); }
int deleteFile(char *fileName) { if (existFile(fileName)) { return remove(fileName); } return 0; }
Rank::Rank(){ string rankFile; rankFile.append("/home/vijay/workplace/Resources/ranking.txt"); if(existFile(rankFile)){ readBin(rankList,rankFile); } }
ImplNetCaffe(const std::string& caffeProto, const std::string& caffeTrainedModel, const int gpuId, const bool enableGoogleLogging, const std::string& lastBlobName) : mGpuId{gpuId}, mCaffeProto{caffeProto}, mCaffeTrainedModel{caffeTrainedModel}, mLastBlobName{lastBlobName} { const std::string message{".\nPossible causes:\n\t1. Not downloading the OpenPose trained models." "\n\t2. Not running OpenPose from the same directory where the `model`" " folder is located.\n\t3. Using paths with spaces."}; if (!existFile(mCaffeProto)) error("Prototxt file not found: " + mCaffeProto + message, __LINE__, __FUNCTION__, __FILE__); if (!existFile(mCaffeTrainedModel)) error("Caffe trained model file not found: " + mCaffeTrainedModel + message, __LINE__, __FUNCTION__, __FILE__); // Double if condition in order to speed up the program if it is called several times if (enableGoogleLogging && !sGoogleLoggingInitialized) { std::lock_guard<std::mutex> lock{sMutexNetCaffe}; if (enableGoogleLogging && !sGoogleLoggingInitialized) { google::InitGoogleLogging("OpenPose"); sGoogleLoggingInitialized = true; } } #ifdef USE_OPENCL // Initialize OpenCL if (!sOpenCLInitialized) { std::lock_guard<std::mutex> lock{sMutexNetCaffe}; if (!sOpenCLInitialized) { caffe::Caffe::set_mode(caffe::Caffe::GPU); std::vector<int> devices; const int maxNumberGpu = OpenCL::getTotalGPU(); for (auto i = 0; i < maxNumberGpu; i++) devices.emplace_back(i); caffe::Caffe::SetDevices(devices); if (mGpuId >= maxNumberGpu) error("Unexpected error. Please, notify us.", __LINE__, __FUNCTION__, __FILE__); sOpenCLInitialized = true; } } #endif }
void BufferManager::openLogFile() { bool existLogFile = existFile(_logFileName); char* flags = NULL; if (existLogFile) { flags = "rb+"; } else { flags = "wb+"; } }
void BufferManager::initialize(const char* file) { std::string controlFileName = std::string(file) + ".trc"; char* fullcontrolFileName = combinePath(_dataDir.c_str(), controlFileName.c_str()); std::string fileName = std::string(file); char* fullLogFileName = combinePath(_dataDir.c_str(), fileName.c_str()); _logFileName = strcpy(const_cast<char*>(fileName.c_str()), fileName.length()); bool existControl = existFile(fullcontrolFileName); char* flags; if (existControl) { flags = "rb+"; } else { flags = "wb+"; } _controlFile = (InputOutputStream*)new FileInputOutputStream(fullcontrolFileName, flags); if (_log->isDebug()) _log->debug(3, "_controlFile->acquireLock();"); _controlFile->acquireLock(); _controlFile->seek(0); bool existLogFile = existFile(fullLogFileName); if (existLogFile) { flags = "rb+"; } else { flags = "wb+"; } if (existControl) { _buffersSize = _controlFile->readLong(); loadBuffers(); } else { _controlFile->writeLong(_buffersSize); __int64 pos = _controlFile->currentPos(); _controlFile->writeInt(0); _controlFile->seek(pos); loadBuffers(); } if (_log->isDebug()) _log->debug(3, "_controlFile->releaseLock();"); _controlFile->releaseLock(); free(fullcontrolFileName); free(fullLogFileName); }
int DBInit::copyDB(){ QFile dfile("assets:/sights.sqlite"); QFile existFile("./sights.sqlite"); //Если файл с БД скопирован, то пропускаем следующие шаги if (existFile.exists()) existFile.remove(); // return 0; if (dfile.exists()) { dfile.copy("./sights.sqlite"); QFile::setPermissions("./sights.sqlite",QFile::WriteOwner | QFile::ReadOwner); } return 1; }
static void Main2(char *tmplProject, char *tmplDir, int utFlag, int m2Flag) { char *project = nextArg(); errorCase(!existDir(tmplDir)); // 2bs ? errorCase_m(!lineExp("<1,30,__09AZaz>", project), "不正なプロジェクト名です。"); errorCase_m(existPath(project), "既に存在します。"); createDir(project); copyDir(tmplDir, project); addCwd(project); { coExecute("qq -f"); RenamePaths(tmplProject, project); addCwd(existDir(TESTER_PROJ_LDIR) ? TESTER_PROJ_LDIR : project); { ChangeAppIdent("Program.cs"); if(utFlag) { char *csprojFile = xcout("%s.csproj", project); if(existFile(csprojFile)) { ResolveRelHintPath(csprojFile); } memFree(csprojFile); } } unaddCwd(); removeFileIfExist("C:\\Factory\\tmp\\Sections.txt"); // 意図しない検索結果を trep しないように、念のため検索結果をクリア coExecute_x(xcout("Search.exe %s", tmplProject)); coExecute_x(xcout("trep.exe /F %s", project)); // execute("START ."); execute_x(xcout("%s.sln", project)); if(m2Flag) execute("START C:\\Dev\\CSharp\\Module2\\Module2"); } unaddCwd(); }
/**Lauch external tool ScyllaDumper to dump the process with PID pid scylla: string containing the path to the scyllaDumper executable pid: pid of the process to dump (Current PID if you want to use the Pin Instrumented Binary) curEip: curre **/ UINT32 ScyllaWrapperInterface::launchScyllaDumpAndFix(std::string scylla,int pid, int curEip,std::string outputFile){ MYINFO("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); MYINFO("LAUNCHING SCYLLADUMP AS AN EXTERNAL PROCESS!!"); MYINFO("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); MYINFO("CURR EIP %x",curEip); W::DWORD exitCode; //Creating the string containing the arguments to pass to the ScyllaTest.exe std::stringstream scyllaArgsStream; scyllaArgsStream << scylla << " "; scyllaArgsStream << pid << " "; scyllaArgsStream << std::hex << curEip << " "; scyllaArgsStream << outputFile << " "; std::string scyllaArgs = scyllaArgsStream.str(); //sprintf(scyllaArgs,"%s %d %x %s",scylla,pid,curEip,outputFile); //argv[0] is the name of the program MYINFO("Scylla cmd %s %s",scylla.c_str(),scyllaArgs.c_str()); //Running external Scyllatest.exe executable W::STARTUPINFO si ={0}; W::PROCESS_INFORMATION pi ={0}; si.cb=sizeof(si); if(!W::CreateProcess(scylla.c_str(),(char *)scyllaArgs.c_str(),NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)){ MYERRORE("(INITFUNCTIONCALL)Can't launch Scylla"); return -5; } W::GetExitCodeProcess(pi.hProcess, &exitCode); W::WaitForSingleObject(pi.hProcess,INFINITE); W::CloseHandle(pi.hProcess); W::CloseHandle(pi.hThread); if(!existFile(outputFile)){ MYERRORE("Scylla Can't dump the process"); return exitCode; } MYINFO("Scylla Finished"); return exitCode; }
UINT32 InitFunctionCall::run(ADDRINT curEip,WriteInterval wi){ string idap_res_file = Config::getInstance()->getCurrentDetectedListPath(); string dumpFile = Config::getInstance()->getCurrentDumpFilePath(); if(!existFile(dumpFile)){ MYERRORE("Dump file hasn't been created"); return -1; } launchIdaScript(Config::IDA_PATH, Config::IDAP_BAD_IMPORTS_CHECKER, Config::BAD_IMPORTS_LIST, idap_res_file, dumpFile); //Read the result of IdaPython script FILE *fd = fopen(idap_res_file.c_str(),"r"); UINT32 file_size = getFileSize(fd); char * init_func_detected = (char *)malloc(file_size); fread(init_func_detected,file_size,1,fd); fclose(fd); MYWARN("Found init functions %s\n",init_func_detected); return 0; }
int main(int argc, char *argv[]) { std::string port; if(argc == 1) { port = DEVICE; } if(argc == 2) { port = argv[1]; } if(argc > 2) { printf("Zu viele Parameter.\n"); printf("Default Serial Port is /dev/ttyUSB0.\n"); printf("Starten sie das Programm mit einem Parameter um eine anderes device zu benutzen.\n"); printf("Aufrufbeispiel: enocedia /dev/ttyUSB0\n"); } if (!existFile(port.c_str())) { printf("Die Datei %s scheint nicht zu existieren.\n", port.c_str()); printf("Default Serial Port is /dev/ttyUSB0.\n"); printf("Starten sie das Programm mit einem Parameter um eine anderes device zu benutzen.\n"); printf("Aufrufbeispiel: enocedia /dev/ttyUSB0\n"); return (1); } EnOcean TheOcean; if (TheOcean.addSensor("008281C9", 0, 40) != 0) { printf("Error can not add Sensor ID, ID %s is not a valid ID", "008281C9"); } printf("Start programm on serial device %s.\n", port.c_str()); TheOcean.start(port.c_str()); while (1); }
void UpdateManager::checkVersion() { std::string tempFileName = *getTempDir() + "/version.conf"; _isLastVersion = true; if (existFile(tempFileName.c_str())) { std::string versioncont = std::string(readFile(const_cast<char*>(tempFileName.c_str()))); if (versioncont.find("version:") == -1) { versioncont = "version:" + versioncont + ";\nreleaseNotesURL:http://d-jon.com/downloads/releasenotes.php?version=" + VERSION + ";"; } const char* cwebLastVersion = readValue(versioncont, "version"); if (strlen(cwebLastVersion) > 0) { Version webVersion = getVersion(cwebLastVersion); Version currentVersion = getCurrentVersion(); if (webVersion > currentVersion) { _isLastVersion = false; } if (!_isLastVersion) { QMessageBox box; box.setWindowTitle("d-jon update available"); box.setTextFormat(Qt::RichText); std::stringstream ss; ss << "A new version of d-jon is available at <a href=\"http://d-jon.com/downloads.html\">http://d-jon.com/downloads.html</a><br/>"; ss << "please take a look of the <a href=\""; std::string releaseNotesURL = readValue(versioncont, "releaseNotesURL"); ss << releaseNotesURL << "\">release notes</a> to know what is new in this release."; std::string message = ss.str(); box.setText(message.c_str()); box.exec(); } } _file->remove(); delete(_file); _file = NULL; } }
char * get_suggested_filename (char *src, char *dst_ext) { char *tmp = NULL; char *base = NULL; char *dir_name = NULL; #ifdef __APPLE__ char bname[FILENAME_MAX]; char dname[FILENAME_MAX]; #else char saved[FILENAME_MAX]; int copylen; #endif char *ext = NULL; int len = FILENAME_MAX; if (!src) { printf("[%s] Invalid argument.\n", __FUNCTION__); return tmp_name; } if (!dst_ext) dst_ext = dfl_ext; #ifdef __APPLE__ base = basename_r(src, bname); dir_name = dirname_r (src, dname); #else copylen = strlen(src); if (copylen >= FILENAME_MAX) copylen = FILENAME_MAX-1; strncpy (saved, src, copylen); saved[copylen] = '\0'; base = basename(saved); dir_name = dirname (saved); #endif ext = get_extension(src); NIL_DEBUG("Dirname: %s\n", dir_name); NIL_DEBUG("Basename: %s\n", base); NIL_DEBUG("Extension: %s\n", ext?ext:"(nil)"); NIL_DEBUG("Remove extenstion [%s] --> ", base); tmp = strrchr(base, '.'); if (tmp) { *tmp = 0x00; NIL_DEBUG("[%s]: changed\n", base); } else { NIL_DEBUG("[%s]: Not changed.\n", base); } tmp = (char *)malloc(FILENAME_MAX); if (tmp) { int i = 0; snprintf (tmp,FILENAME_MAX,"%s/%s.%s",dir_name, base, dst_ext); NIL_DEBUG ("Temporary Filename: %s\n", tmp); while (existFile(tmp)){ snprintf (tmp,len,"%s/%s_%d.%s",dir_name, base, i, dst_ext); NIL_DEBUG ("Temporary Filename: %s\n", tmp); i++; } } else { tmp = tmp_name; } #if 0 { char *p = dir_name; p += strlen(dir_name); printf ("%p(p+strlen) %p(base) \n", p, base); if ( base == p+1 ){ *p = '/'; } } #endif return tmp; }
int main(int argc, char **argv) { int changed = 0; if(argIs("/D")) { GameDir = nextArg(); goto readArgs; } // Check 'GameDir' { char *file; errorCase_m(!existDir(GameDir), "Wrong Game-Dir"); file = combine(GameDir, "koumajou.exe"); errorCase_m(!existFile(file), "Wrong Game-Dir, koumajou.exe does not exist!"); memFree(file); file = combine(GameDir, "data"); errorCase_m(!existDir(file), "Wrong Game-Dir, data does not exist!"); memFree(file); } LoadSaveData(); ShowSaveData(); readArgs: if(argIs("/S")) { StageNo = toValue(nextArg()); changed = 1; goto readArgs; } if(argIs("/H")) { HiScore = toValue(nextArg()); changed = 1; goto readArgs; } if(argIs("/E+")) { ExtraOpened = 1; changed = 1; goto readArgs; } if(argIs("/E-")) { ExtraOpened = 0; changed = 1; goto readArgs; } if(changed) { cout(">\n"); ShowSaveData(); OutputSaveData(); } }
ImgBookRAR::ImgBookRAR(string file) : ImgBook(file) { HANDLE rarFile; int RHCode = 0, PFCode = 0; struct RARHeaderDataEx header; struct RAROpenArchiveDataEx flags; string page, new_password; PV_LOGPRINTF("full Name %s", file.c_str()); string nom = getFileName(file); PV_LOGPRINTF("fileName %s", nom.c_str()); string nouNom; nouNom.assign(file); nouNom.append("/"); nouNom.append(nom); if (existFile(nouNom) == true) file.assign(nouNom); PV_LOGPRINTF("file name prepared %s", nouNom.c_str()); PV_LOGPRINTF("full Name %s", file.c_str()); filename = file; open_rar: rarFile = openRar(file, &flags, &header, RAR_OM_LIST); if (rarFile == NULL) { PV_LOGPRINTF("error open RarFile"); return; } PV_LOGPRINTF("rarFile opened"); if (flags.Flags & 0x0080) { // if the headers are encrypted PV_LOGPRINTF("rarFile encrypted"); return; } PV_LOGPRINTF("reading file name"); while ((RHCode = RARReadHeaderEx(rarFile, &header)) == 0) { PV_LOGPRINTF("while"); page = string(header.FileName); if (testFile (page) == TRUE) { PV_LOGPRINTF("imageAdded %s", header.FileName); imagenes->addEnd(page); } if ((PFCode = RARProcessFile(rarFile, RAR_SKIP, NULL, NULL)) != 0) { closeRar(rarFile, &flags); perror("error al abrir fichero\n"); return; } } PV_LOGPRINTF("close rar"); closeRar(rarFile, &flags); PV_LOGPRINTF("rar closed"); // Wrong return code + needs password = wrong password given if (RHCode != ERAR_END_ARCHIVE && flags.Flags & 0x0080) goto open_rar; currentPage = 1; PV_LOGPRINTF("currentPage %d", currentPage); pageCount = imagenes->getCount();
static void MainLoop(void) { uint ip = 0; if(!DoLock()) return; removeFileIfExist(ParamsFile); removeFileIfExist(AnswerFile); mutexRelease(MutexHandle); SockStartup(); cout("START\n"); while(!collectEvents(StopAppEventHandle, 0)) { collectEvents(StartEventHandle, 3000); if(!DoLock()) break; if(existFile(ParamsFile)) { char *ansFile; if(Serializer) { char *wrkFile = makeTempFile(NULL); Serializer(ParamsFile, wrkFile); removeFile(ParamsFile); moveFile(wrkFile, ParamsFile); memFree(wrkFile); } removeFileIfExist(AnswerFile); // Cleanup mutexRelease(MutexHandle); cout("REQUEST START %I64u\n", getFileSize(ParamsFile)); ansFile = sockClient((uchar *)&ip, ServerDomain, ServerPort, ParamsFile, Idle); cout("REQUEST END %08x\n", ansFile); if(StopAppEventCaught || !DoLock()) { if(ansFile) { removeFile(ansFile); memFree(ansFile); } break; } removeFileIfExist(AnswerFile); // Cleanup (2bs) if(ansFile) { if(Deserializer) { Deserializer(ansFile, AnswerFile); removeFile(ansFile); } else moveFile(ansFile, AnswerFile); memFree(ansFile); cout("ANSWER %I64u\n", getFileSize(AnswerFile)); } removeFileIfExist(ParamsFile); // Cleanup eventSet(AnswerEventHandle); // リクエストの完了(応答)を通知 } mutexRelease(MutexHandle); } cout("END\n"); SockCleanup(); if(handleWaitForMillis(MutexHandle, 2000)) { // Cleanup removeFileIfExist(ParamsFile); removeFileIfExist(AnswerFile); mutexRelease(MutexHandle); } }
//get a file from the chord network void chordService::getFile(std::string basename) { if (!existFile(basename)) { return; } serviceChordNode->fetchKeyValue(basename); }