OovString const Project::getBinDirectory() { static OovString path; if(path.length() == 0) { OovStatus status(true, SC_File); #ifdef __linux__ char buf[300]; ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf)); if(len >= 0) { buf[len] = '\0'; path = buf; size_t pos = path.rfind('/'); if(pos == std::string::npos) { pos = path.rfind('\\'); } if(pos != std::string::npos) { path.resize(pos+1); } } /* if(FileIsFileOnDisk("./oovaide", status)) { path = "./"; } else if(FileIsFileOnDisk("/usr/local/bin/oovaide", status)) { path = "/usr/local/bin/"; } */ else { path = "/usr/bin"; } #else if(FileIsFileOnDisk("./oovaide.exe", status)) { path = "./"; } else { path = FilePathGetDrivePath(sArgv0); } #endif if(status.needReport()) { status.report(ET_Error, "Unable to get bin directory"); } } return path; }
bool NameValueRecord::getLine(File &file, OovString &str, OovStatus &status) { char lineBuf[1000]; str.resize(0); // Read many times until the \n is found. while(file.getString(lineBuf, sizeof(lineBuf), status)) { str += lineBuf; size_t len = str.length(); if(str[len-1] == '\n') { str.resize(len-1); break; } else if(len > 50000) { break; } } return(str.length() > 0); }
OovStatusReturn FileEnsurePathExists(OovStringRef const path) { OovStatus status(true, SC_File); FilePath fullPath(path, FP_Dir); FilePath existingPath = fullPath; if(fullPath.find('~') == std::string::npos) { // Walk up the tree to find a base that exists. size_t pos = existingPath.getPosEndDir(); while(pos != 0 && pos != std::string::npos) { existingPath.discardTail(pos); OovStatus ignoredStatus(true, SC_File); if(existingPath.isDirOnDisk(ignoredStatus)) break; else pos = existingPath.getPosLeftPathSep(pos, RP_RetPosFailure); } if(pos == std::string::npos) { pos = 0; } while(pos != std::string::npos && status.ok()) { pos = findPathSep(fullPath, pos); if(pos != std::string::npos) { OovString partPathStr = fullPath; partPathStr.resize(pos); if(!FileIsDirOnDisk(partPathStr, status)) { status = FileMakeSubDir(partPathStr); } pos++; } } } else { status.set(false, SC_Logic); } return status; }
void CMaker::appendNames(OovStringVec const &names, char delim, OovString &str) { for(auto const &name : names) { str += name; str += delim; size_t startpos = str.rfind('\n'); if(startpos == std::string::npos) startpos = 0; if(str.length() - startpos > 70) { str += "\n "; } } int len = str.length(); if(len > 0 && str[len-1] == delim) str.resize(len-1); }
bool FileEnsurePathExists(OovStringRef const path) { bool success = true; // Walk up the tree to find a base that exists. FilePath fp(path, FP_File); size_t pos = fp.getPosEndDir(); while(pos != 0) { fp.discardTail(pos); bool ignoredSuccess = true; if(fp.isDirOnDisk(ignoredSuccess)) break; else pos = fp.getPosLeftPathSep(pos, RP_RetPosFailure); } while(pos != std::string::npos && pos != 0 && success) { pos = findPathSep(path, pos); if(pos != std::string::npos) { OovString partPath = path; partPath.resize(pos); if(!FileIsDirOnDisk(partPath, success)) { #ifdef __linux__ success = (mkdir(partPath.getStr(), 0x1FF) == 0); // 0777 #else success = (_mkdir(partPath.getStr()) == 0); #endif } pos++; } } return success; }