/** @shared * Takes a path and tries to find it based on the * system's case-sensitivity. * @param base Base unaltered path. * @param path Full path to check for casing. * @return Correct foldername or "" if it doesn't exist. * @note There's no actual method for figuring out the correct * foldername on case-sensitive systems, this is just a workaround. */ std::string caseInsensitiveFolder(const std::string &base, const std::string &path) { std::string fullPath = base + path, newPath = path; // Try all various case mutations // Normal unmangled if (folderExists(fullPath.c_str())) { return fullPath; } // UPPERCASE std::transform(newPath.begin(), newPath.end(), newPath.begin(), toupper); fullPath = base + newPath; if (folderExists(fullPath.c_str())) { return fullPath; } // lowercase std::transform(newPath.begin(), newPath.end(), newPath.begin(), tolower); fullPath = base + newPath; if (folderExists(fullPath.c_str())) { return fullPath; } // If we got here nothing can help us return ""; }
std::string searchDataFolder(const std::string &foldername) { // Correct folder separator std::string name = foldername; #ifdef _WIN32 std::replace(name.begin(), name.end(), '/', PATH_SEPARATOR); #endif // Check current data path std::string path = Options::getDataFolder() + name; if (folderExists(path)) { return path; } // Check every other path for (std::vector<std::string>::const_iterator i = Options::getDataList().begin(); i != Options::getDataList().end(); ++i) { path = *i + name; if (folderExists(path)) { Options::setDataFolder(*i); return path; } } // Give up return foldername; }
void Frame::searchStart() { QString path = _panel->_ledtSearchPath->displayText(); if (path == QString("")) { _panel->_lblSearchResult->setText( Config::PanelTxtAttention + Config::PanelTxtNoSearchPath); return ; } if (!folderExists(path)) { _panel->_lblSearchResult->setText( Config::PanelTxtAttention + Config::PanelTxtInvalidSearchPath); return; } QString pattern = _panel->_ledtPattern->displayText(); if (pattern == QString("")) { _panel->_lblSearchResult->setText( Config::PanelTxtAttention + Config::PanelTxtNoSearchPath); return ; } _panel->_lblSearchResult->setText(Config::PanelTxtSearchInprocess); qDebug() << "searchpath = " + path + ", pattern = " + pattern; _panel->_lstLogs->clear(); _panel->_btnSearchStart->setEnabled(false); _panel->_btnSearchCancel->setEnabled(true); emit onSearchStart(path, pattern); }
bool CCompiler::setSupportCodeFolder(const string& path) { if(!folderExists(path)) { Log(Logger::LOG_ERROR)<<"Tried to set invalid path: "<<path<<" for compiler location"; return false; } mSupportCodeFolder = path; return true; }
bool CCompiler::setupCompiler(const string& supportCodeFolder) { mSupportCodeFolder = supportCodeFolder; if(!folderExists(mSupportCodeFolder)) { Log(Logger::LOG_ERROR)<<"The roadrunner support code folder : "<<mSupportCodeFolder<<" does not exist."; return false; } return true; }
/************************************************************************ * Function : checkMoveFolder * * Parameters: * * * Description: * This function ensure moved folder exist. * * Returns: * 0 if successful else appropriate error ***************************************************************************/ int checkMoveFolder() { char cmd[1024]; sprintf (cmd, "mkdir %s", MVOEDFOLDER ); if(folderExists(MVOEDFOLDER)){ if (executeCMD (cmd) != 0) { ZError (DBG_MISC, "Create extracted folder failed->%s", cmd); return -1; } return 0; } else return 0; }
bool et::createDirectory(const std::string& name, bool recursive) { if (recursive) { char delim[] = {pathDelimiter, 0}; bool gotError = false; StringList components = split(name, std::string(delim)); std::string path; for (auto& dir : components) { path += dir + "\\"; if (!folderExists(path)) gotError |= ::CreateDirectory(ET_STRING_TO_PARAM_TYPE(path).c_str(), nullptr) == 0; } return !gotError; } return ::CreateDirectory(ET_STRING_TO_PARAM_TYPE(name).c_str(), nullptr) == 0; }
void Guys::configurationFileCheck() { if( configFileExists("guys/twitter") ) { //std::cout << "file exists" << std::endl; FILE *pFile; char buffer [100]; std::string result; std::string command = "cd ~/ && pwd"; std::string file; pFile = popen(command.c_str(), "r"); if (pFile == NULL) { std::cout << "handle error" << std::endl; return; } else { while ( !feof(pFile) ) { fgets (buffer , 100 , pFile); } pclose (pFile); } result = buffer; configPath = result + "/.config/guys/"; //accessible to all functions std::string::iterator it; for ( it=configPath.begin() ; it < configPath.end(); it++ ) if (*it == 10) configPath.erase(it); //erase return characters } else { if( folderExists("~/.config/guys") ) { std::cout << "creating config files in ~/.config/guys/" << std::endl; //but not the file makeConfigFile("guys/twitter"); //create the file configurationFileCheck(); } else { makeConfigDir("guys"); configurationFileCheck(); } } return; }
void Frame::backupStart() { QString path = _panel->_ledtBackupPath->displayText(); if (path == QString("")) { _panel->_lblBackupInfo->setText( Config::PanelTxtAttention + Config::PanelTxtNoBackupPath); return ; } if (!folderExists(path)) { _panel->_lblBackupInfo->setText( Config::PanelTxtAttention + Config::PanelTxtInvalidBackupPath); return; } qDebug() << "backuppath = " + path; _panel->_btnBackupStart->setEnabled(false); _panel->_btnBackupCancel->setEnabled(true); _panel->_lblBackupInfo->setText(Config::PanelTxtBackupInprocess); emit onBackupStart(path); }
/********************************************************** * function:PicasaDownLoadPhoto * description:download a photo by photoID * * IN char *objID: * * return: * 0 ok else error * * * ********************************************************/ int PicasaDownLoadPhoto(char *objID) { #if 0 char url[512] = {0}; char sessionID[512] = {0}; struct MemoryStruct chunk; CURL *curl; CURLcode cret; long httpRspCode = 0; struct curl_slist *slist = NULL; char *retxml = NULL; char photoName[1024] = {0}; char photoType[128]={0}; char photoURL[1024] = {0}; char fileFullPath[1024]; char folderPath[1024]={0}; char CMD[1024]={0}; DIR *dir; struct dirent *ptr; char errxml[1024]; char hostAddr[128] = {0}; char title[128]={0}; char usrname[128]={0}; char sessionID[1024]={0}; /* get the download file's url and title by objID */ if(getURLByID(objID,photoURL,title,sessionID)<0) { return -1; } ZError(DBG_MISC,"the photo URL is %s",photoURL); /* get the usrname by objID*/ GetPicasaUsrName(objID,usrname); strcpy(url, photoURL); sprintf(request, "GET /%s HTTP/1.0\r\nHost: %s:%d\r\nContent-Length: %d\r\nContent-Type: application/atom+xml\r\nAuthorization: GoogleLogin auth=%s\r\n\r\n", host_file, hostAddr, portnumber, 0, sessionID); sprintf(errxml,"<ret op=\"downLoadPhoto\"><error></error></ret>"); /*get download file's name*/ sprintf(photoName,"%s%s",title,photoType); /* check the directory("/data/OnlineSync/Picasa") exist the folder*/ if(folderExists("/data/OnlineSync/Picasa")<0) { //new a named usrname folder sprintf(CMD,"mkdir /data/OnlineSync/Picasa"); if(executeCMD(CMD)<0) goto failed; } else ZError(DBG_MISC,"Picasa folder exists!"); /* check the directory("/data/OnlineSync/Picasa/usrDir") exist the folder*/ sprintf(folderPath,"/data/OnlineSync/Picasa/%s/",usrname); if(folderExists(folderPath)<0) { //new a named usrname folder sprintf(CMD,"mkdir %s",folderPath); if(executeCMD(CMD)<0) goto failed; } else ZError(DBG_MISC,"user folder exists!"); /* check the filename at the specify directory */ dir =opendir(folderPath); while((ptr = readdir(dir))!=NULL) { if(!strcmp(ptr->d_name,photoName)) { ZError(DBG_MISC,"Please rename the photo name!!.....\n"); closedir(dir); goto failed; } } closedir(dir); /* put the binary image into the specify file */ memset(fileFullPath,0,1024); sprintf(fileFullPath,"%s%s",folderPath,photoName); ZError(DBG_MISC,"fileFullPath-->%s",fileFullPath); ZError(DBG_MISC,"\nthe http.content-->%s",http.content); memset(CMD,0,1024); sprintf(CMD,"wget %s -O %s",photoURL,fileFullPath); if(executeCMD(CMD)<0) goto failed; #endif return 0; }