bool HttpResponse::sendFile(String fileName, bool allowGzipFileCheck /* = true*/) { if (stream != NULL) { SYSTEM_ERROR("Stream already created"); delete stream; stream = NULL; } String compressed = fileName + ".gz"; if (allowGzipFileCheck && fileExist(compressed)) { debugf("found %s", compressed.c_str()); stream = new FileStream(compressed); setHeader("Content-Encoding", "gzip"); } else if (fileExist(fileName)) { debugf("found %s", fileName.c_str()); stream = new FileStream(fileName); } else { notFound(); return false; } if (!hasHeader("Content-Type")) { const char *mime = ContentType::fromFullFileName(fileName); if (mime != NULL) setContentType(mime); } return true; }
/*! * @if jp * @brief Configuration file の検索 * @else * @brief Find the configuration file * @endif */ bool ManagerConfig::findConfigFile() { // Check existance of configuration file given command arg if (m_configFile != "") { if (fileExist(m_configFile)) { return true; } } // Search rtc configuration file from environment variable char* env = getenv(config_file_env); if (env != NULL) { if (fileExist(env)) { m_configFile = env; return true; } } // Search rtc configuration file from default search path int i = 0; while (config_file_path[i] != NULL) { if (fileExist(config_file_path[i])) { m_configFile = config_file_path[i]; return true; } ++i; } return false; }
int XJudgerMain::checkDir(string dir){ for (int i = 0; i < DataConfig -> Problem.size(); i ++){ string name = DataConfig -> Problem[i] -> Source; if (fileExist(dir, name + ".pas") || fileExist(dir, name + ".cpp") || fileExist(dir, name + ".c")) return 1; } return 0; }
/* test create open close unlink */ inline void test1(){ int fd , n; startTestID( 1 ); n = numOpen(); fd = creat( TEST_FILE_NAME0 ); assertTrueID( 0 , fileExist( 0 ) ); assertTrueID( 1 , n + 1 == numOpen() ); close( fd ); assertTrueID( 2 , n == numOpen() ); unlink( TEST_FILE_NAME0 ); assertTrueID( 3 , !fileExist( 0 ) ); }
// Will be called when WiFi station was connected to AP void connectOk() { Serial.println("I'm CONNECTED"); if (!fileExist("index.html") || !fileExist("bootstrap.css.gz") || !fileExist("jquery.js.gz")) { // Download server content at first downloadTimer.initializeMs(3000, downloadContentFiles).start(); } else { startWebServer(); } }
void BigPotUI::init() { _square = engine_->createSquareTexture(30); _fontname = config_->getString("ui_font"); if (!fileExist(_fontname)) { #ifdef _WIN32 _fontname = "c:/windows/fonts/cambria.ttc"; if (!fileExist(_fontname)) _fontname = "c:/windows/fonts/cambria.ttf"; #else _fontname = "/System/Library/Fonts/Palatino.ttc"; #endif } }
MeteoConfig loadConfig() { DynamicJsonBuffer jsonBuffer; MeteoConfig cfg; if (fileExist(METEO_CONFIG_FILE)) { int size = fileGetSize(METEO_CONFIG_FILE); char* jsonString = new char[size + 1]; fileGetContent(METEO_CONFIG_FILE, jsonString, size + 1); JsonObject& root = jsonBuffer.parseObject(jsonString); JsonObject& network = root["network"]; cfg.NetworkSSID = String((const char*)network["ssid"]); cfg.NetworkPassword = String((const char*)network["password"]); JsonObject& correction = root["correction"]; cfg.AddT1 = correction["T1"]; cfg.AddT2 = correction["T2"]; cfg.AddTZ = correction["TZ"]; JsonObject& trigger = root["trigger"]; cfg.Trigger = (TriggerType)(int)trigger["type"]; cfg.RangeMin = trigger["min"]; cfg.RangeMax = trigger["max"]; delete[] jsonString; } else { cfg.NetworkSSID = WIFI_SSID; cfg.NetworkPassword = WIFI_PWD; } return cfg; }
void actionQuickLoadState() { if (fileExist(state.properties->filehistory.quicksave, NULL)) { emulatorStop(); emulatorStart(state.properties->filehistory.quicksave); } archUpdateMenu(0); }
static BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) { ProfileEnumData *ped = (ProfileEnumData*)lParam; CCtrlListView &list = ped->list; TCHAR sizeBuf[64]; bool bFileLocked = true; TCHAR *p = _tcsrchr(profile, '.'); mir_tstrcpy(sizeBuf, _T("0 KB")); if (p != NULL) *p = 0; LVITEM item = { 0 }; item.mask = LVIF_TEXT | LVIF_IMAGE; item.pszText = profile; item.iItem = 0; struct _stat statbuf; if (_tstat(tszFullPath, &statbuf) == 0) { if (statbuf.st_size > 1000000) { mir_sntprintf(sizeBuf, _countof(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1048576.0); mir_tstrcpy(sizeBuf + 5, _T(" MB")); } else { mir_sntprintf(sizeBuf, _countof(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1024.0); mir_tstrcpy(sizeBuf + 5, _T(" KB")); } bFileLocked = !fileExist(tszFullPath); } DATABASELINK *dblink; switch (touchDatabase(tszFullPath, &dblink)) { case ERROR_SUCCESS: item.iImage = bFileLocked; break; case EGROKPRF_OBSOLETE: item.iImage = 2; break; default: item.iImage = 3; } int iItem = list.InsertItem(&item); if (mir_tstrcmpi(ped->szProfile, tszFullPath) == 0) list.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); list.SetItemText(iItem, 2, sizeBuf); if (dblink != NULL) { if (bFileLocked) // file locked list.SetItemText(iItem, 1, TranslateT("<In use>")); else list.SetItemText(iItem, 1, TranslateTS(dblink->szFullName)); } else list.SetItemText(iItem, 1, TranslateT("<Unknown format>")); return TRUE; }
size_t FileStream::write(const uint8_t *buffer, size_t size) { if (!fileExist()) return 0; bool result = fileSeek(handle, 0, eSO_FileEnd); return fileWrite(handle, buffer, size); }
bool LocalRepository::getFile(HttpRequest* request, HttpResponse *response) { bool found=false; const string *alias=NULL, *path=NULL; string url = request->getUrl(); size_t webpageLen; unsigned char *webpage; pthread_mutex_lock( &_mutex ); if (!fileExist(url)) { pthread_mutex_unlock( &_mutex); return false; }; for (std::set< pair<string,string> >::iterator it = aliasesSet.begin(); it != aliasesSet.end() && !found; it++) { alias=&(it->first); if (!(url.compare(0, alias->size(), *alias))) { path=&(it->second); found= true; } } pthread_mutex_unlock( &_mutex); if (!found) return false; string resultat, filename=url; if (alias->size()) filename.replace(0, alias->size(), *path); else filename=*path+'/'+filename; FILE *pFile = fopen ( filename.c_str() , "rb" ); if (pFile==NULL) { char logBuffer[150]; snprintf(logBuffer, 150, "Webserver : Error opening file '%s'", filename.c_str() ); NVJ_LOG->append(NVJ_ERROR, logBuffer); return false; } // obtain file size. fseek (pFile , 0 , SEEK_END); webpageLen = ftell (pFile); rewind (pFile); if ( (webpage = (unsigned char *)malloc( webpageLen+1 * sizeof(char))) == NULL ) return false; size_t nb=fread (webpage,1,webpageLen,pFile); if (nb != webpageLen) { char logBuffer[150]; snprintf(logBuffer, 150, "Webserver : Error accessing file '%s'", filename.c_str() ); NVJ_LOG->append(NVJ_ERROR, logBuffer); return false; } fclose (pFile); response->setContent (webpage, webpageLen); return true; }
//============================================================== static void l_checkFileExist(void) //-------------------------------------------------------------- // ファイルが存在するかチェック //-------------------------------------------------------------- // in: なし //-------------------------------------------------------------- // out: なし //============================================================== { sList *ptr; ptr = pack.top; ptr = ptr->next; // 最初は出力先なのでスキップ while(ptr) { if(ptr->pack) { if(!fileExist(ptr->file)) { printf("No File. '%s'\n", ptr->file); ptr->pack = FALSE; pack.pack_num--; } } ptr = ptr->next; } }
/* write after close the file */ inline void test2(){ int fd , n = -1 ; startTestID( 2 ); fd = creat( TEST_FILE_NAME0 ); assertTrueID( 0 , fileExist( 0 ) ); close( fd ); assertTrueID( 1 , write( fd , &n , sizeof(int) ) == -1 ); }
int get_matrix_rows(char *f1, char *f2) { int m1, m2; if (!fileExist(f1)) Exit("get_matrix_rows(): %s does not exist",f1); if (!fileExist(f2)) Exit("get_matrix_rows(): %s does not exist",f2); m1 = fileNumLines(f1); m2 = fileNumLines(f2); if (m1 != m2) Exit("get_matrix_rows(): A and b are not same row-dimension"); if (m1 < 4) Exit("bp: number of rows less than number of colums"); return(m1); }
int LoadDatabaseModule(void) { TCHAR szProfile[MAX_PATH]; PathToAbsoluteT(_T("."), szProfile); _tchdir(szProfile); szProfile[0] = 0; LoadDatabaseServices(); // find out which profile to load if (!getProfile(szProfile, SIZEOF(szProfile))) return 1; EnsureCheckerLoaded(false); // unload dbchecker if (arDbPlugins.getCount() == 0) { TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile, '\\'); mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_mmap.dll"), p ? ++p : szProfile); MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR); } // find a driver to support the given profile bool retry; int rc; do { retry = false; if ( _taccess(szProfile, 0) && shouldAutoCreate(szProfile)) rc = tryCreateDatabase(szProfile); else rc = tryOpenDatabase(szProfile); if (rc > 0) { // if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it if (fileExist(szProfile)) { // file isn't locked, just no driver could open it. TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile, '\\'); mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DbChecker which should be installed."), p ? ++p : szProfile); MessageBox(0, buf, TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR); } else if (!FindMirandaForProfile(szProfile)) { TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile, '\\'); mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile); retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY; } } } while (retry); if (rc == ERROR_SUCCESS) { InitIni(); return 0; } return rc; }
void startFTP() { if (!fileExist("index.html")) fileSetContent("index.html", "<h3>Please connect to FTP and upload files from folder 'web/build' (details in code)</h3>"); // Start FTP server ftp.listen(21); ftp.addUser("me", "123"); // FTP account }
void connectOk() { debugf("connected"); WifiAccessPoint.enable(false); lcd.clear(); lcd.print("\7 "); lcd.print(WifiStation.getIP().toString()); // Restart main screen output procTimer.restart(); displayTimer.stop(); startWebClock(); // At first run we will download web server content if (!fileExist("index.html") || !fileExist("config.html") || !fileExist("api.html") || !fileExist("bootstrap.css.gz") || !fileExist("jquery.js.gz")) downloadContentFiles(); else startWebServer(); }
// returns 1 if a default profile should be selected instead of showing the manager. static int getProfileAutoRun(TCHAR * szProfile) { TCHAR Mgr[32]; GetPrivateProfileString(_T("Database"), _T("ShowProfileMgr"), _T(""), Mgr, SIZEOF(Mgr), mirandabootini); if (_tcsicmp(Mgr, _T("never"))) return 0; return fileExist(szProfile) || shouldAutoCreate(szProfile); }
void actionVideoCapturePlay() { if (emulatorGetState() != EMU_STOPPED) { emulatorStop(); } if (fileExist(state.properties->filehistory.videocap, NULL)) { emulatorStart(state.properties->filehistory.videocap); } archUpdateMenu(0); }
void chunk::Load(){ create(); #ifndef NEWORLD_DEBUG_NO_FILEIO if (fileExist())LoadFromFile(); else build(); #else build(); #endif if (Empty)destroy(); else updated = true; }
int readImagesOnYearFolderDecider(std::vector<std::string>yearsList, std::string readFolderPath, unsigned char* descs, vl_size &numTotalDesc, vl_size maxTotalDesc, unsigned int dimOfDesc, FeatureType ft, unsigned int sizeOfDescType) { for (int y = 0; y < yearsList.size(); y++) { std::string yearPath = readFolderPath + "/" + yearsList[y]; if (fileExist(yearPath.c_str())) readImagesOnYearFolder(yearPath, descs, numTotalDesc, maxTotalDesc, dimOfDesc, ft, sizeOfDescType); } return 1; }
u32 isAPath(char*path) { if(fileExist(path)) return 1 ; u32 pathSize = strlen(path); if(pathSize>255) return 0; if(path[1]==':' && path[2]=='\\') return 1; char * p = path ; if(pathSize>4) { p += (pathSize-4) ; for(u32 n=0;n<5;n++) if(*p++ == '.') return 1; } return 0 ; }
int LoadDatabaseModule(void) { TCHAR szProfile[MAX_PATH]; pathToAbsoluteT(_T("."), szProfile, NULL); _tchdir(szProfile); szProfile[0] = 0; // load the older basic services of the db InitUtils(); // find out which profile to load if ( !getProfile( szProfile, SIZEOF( szProfile ))) return 1; PLUGIN_DB_ENUM dbe; dbe.cbSize = sizeof(PLUGIN_DB_ENUM); dbe.lParam = (LPARAM)szProfile; if ( _taccess(szProfile, 0) && shouldAutoCreate( szProfile )) dbe.pfnEnumCallback=( int(*) (const char*,void*,LPARAM) )FindDbPluginAutoCreate; else dbe.pfnEnumCallback=( int(*) (const char*,void*,LPARAM) )FindDbPluginForProfile; // find a driver to support the given profile int rc = CallService(MS_PLUGINS_ENUMDBPLUGINS, 0, (LPARAM)&dbe); switch ( rc ) { case -1: { // no plugins at all TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile,'\\'); mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_3x.dll or equivalent."), p ? ++p : szProfile ); MessageBox(0,buf,TranslateT("No profile support installed!"),MB_OK | MB_ICONERROR); break; } case 1: // if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it if (fileExist(szProfile)) { // file isn't locked, just no driver could open it. TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile,'\\'); mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DB-tool which should be installed."), p ? ++p : szProfile); MessageBox(0,buf,TranslateT("Miranda can't understand that profile"),MB_OK | MB_ICONERROR); } else if (!FindMirandaForProfile(szProfile)) { TCHAR buf[256]; TCHAR* p = _tcsrchr(szProfile,'\\'); mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile); MessageBox(0,buf,TranslateT("Miranda can't open that profile"),MB_OK | MB_ICONERROR); } break; } return (rc != 0); }
/* open exceed the stub file system's limit */ inline void test3(){ int i , fd[ FILE_LIMIT ] ; startTestID( 3 ); assertTrueID( 0 , fileExist( 0 ) ); for( i = 0 ; i < FILE_LIMIT ; i ++ ) fd[i] = open( TEST_FILE_NAME0 ); assertTrueID( 1 , open( TEST_FILE_NAME0 ) == -1 ); for( i = 0 ; i < FILE_LIMIT ; i ++ ) if( fd[i] > 0 ) assertTrueID( i + 2 , !close( fd[i] ) ); }
FileInfo::FileInfo(const std::string &_fullname): fullname(_fullname), m_exist(false) { m_exist = fileExist(fullname); if (m_exist) { name = getFilenameFormFullname(fullname); } else fullname = ""; }
void chunk::Load() { //assert(Empty == false); create(); #ifndef NEWORLD_DEBUG_NO_FILEIO if (fileExist()) LoadFromFile(); else build(); #else build(); #endif if (!Empty) updated = true; }
int myFileSafeCreate(char *filePath){ FILE *tmp; if (!fileExist(filePath)) { //will create new file tmp=fopen(filePath,"w"); fclose(tmp); return 0;//create file ok }else{ //means file already exist return -1;//create file failed } }
FileInfo::FileInfo(const std::string& _name, const std::string& _fullname): name(_name), fullname(_fullname), m_exist(false) { m_exist = fileExist(fullname); if (m_exist) { } else fullname = name = ""; }
DirectoryInfo::DirectoryInfo(const std::string& _name, const std::string& _fullname): fullname(_fullname), name(_name), m_exist(false) { m_exist = fileExist(fullname); if (m_exist) { } else fullname = name = ""; }
bool EasySFML::checkConfig(){ XMLNode xMainNode=XMLNode::openFileHelper("conf/compiler.xml","PMML"); XMLNode xcompilers=xMainNode.getChildNode("compilers"); int i = atoi(_compilertype.c_str()); XMLNode xcompiler =xcompilers.getChildNode("compiler",i); bool ok = true; if (!fileExist(_cmakepath+"bin/cmake.exe")){ ok = false; SetColor(RED); cout << "ERROR: Impossible to find cmake '"<< _cmakepath <<"' ." << endl ; SetColor(WHITE); } if (!fileExist(_compilerpath+xcompiler.getChildNode("bin").getText())){ ok = false; SetColor(RED); cout << "ERROR: Impossible to find compiler '"<< _compilerpath <<"' ." << endl << endl; SetColor(WHITE); } return ok; }