本文整理汇总了C++中FilePath::exists方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePath::exists方法的具体用法?C++ FilePath::exists怎么用?C++ FilePath::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLogEntries
void getLogEntries(const FilePath& texPath,
const rnw_concordance::Concordances& concordances,
core::tex::LogEntries* pLogEntries)
{
// latex log file
FilePath logPath = latexLogPath(texPath);
if (logPath.exists())
{
core::tex::LogEntries logEntries;
Error error = core::tex::parseLatexLog(logPath, &logEntries);
if (error)
LOG_ERROR(error);
filterLatexLog(logEntries, pLogEntries);
}
// bibtex log file
core::tex::LogEntries bibtexLogEntries;
logPath = bibtexLogPath(texPath);
if (logPath.exists())
{
Error error = core::tex::parseBibtexLog(logPath, &bibtexLogEntries);
if (error)
LOG_ERROR(error);
}
// concatenate them together
std::copy(bibtexLogEntries.begin(),
bibtexLogEntries.end(),
std::back_inserter(*pLogEntries));
}
示例2: validate
bool validate(const FilePath& userHomePath,
bool projectSharingEnabled) const
{
// ensure the scratch path and properties paths exist
if (!scratchPath_.exists() || !propertiesPath_.exists())
return false;
// ensure the properties are there
if (project().empty() || workingDir().empty() || (lastUsed() == 0))
return false;
// for projects validate that the base directory still exists
std::string theProject = project();
if (theProject != kProjectNone)
{
FilePath projectDir = FilePath::resolveAliasedPath(theProject,
userHomePath);
if (!projectDir.exists())
return false;
// check for project file
FilePath projectPath = r_util::projectFromDirectory(projectDir);
if (!projectPath.exists())
return false;
// if we got this far the scope is valid, do one final check for
// trying to open a shared project if sharing is disabled
if (!projectSharingEnabled &&
r_util::isSharedPath(projectPath.absolutePath(), userHomePath))
return false;
}
// validated!
return true;
}
示例3: readPresentation
bool readPresentation(SlideDeck* pSlideDeck,
std::string* pSlides,
std::string* pInitActions,
std::string* pSlideActions,
std::map<std::string,std::string>* pVars,
std::string* pErrMsg)
{
// look for slides and knit if we need to
FilePath rmdFile = presentation::state::filePath();
std::string ext = rmdFile.extensionLowerCase();
if (rmdFile.exists() && (ext != ".md"))
{
if (!performKnit(rmdFile, pErrMsg))
return false;
}
// look for slides markdown
FilePath slidesFile = rmdFile.parent().childPath(rmdFile.stem() + ".md");
if (!slidesFile.exists())
{
*pErrMsg = slidesFile.absolutePath() + " not found";
return false;
}
// parse the slides
Error error = pSlideDeck->readSlides(slidesFile);
if (error)
{
LOG_ERROR(error);
*pErrMsg = error.summary();
return false;
}
// render the slides
std::string revealConfig;
error = presentation::renderSlides(*pSlideDeck,
pSlides,
&revealConfig,
pInitActions,
pSlideActions);
if (error)
{
LOG_ERROR(error);
*pErrMsg = error.summary();
return false;
}
// build template variables
std::map<std::string,std::string>& vars = *pVars;
vars["title"] = pSlideDeck->title();
vars["slides"] = *pSlides;
vars["slides_css"] = resourceFiles().get("presentation/slides.css");
vars["r_highlight"] = resourceFiles().get("r_highlight.html");
vars["reveal_config"] = revealConfig;
vars["preamble"] = pSlideDeck->preamble();
return true;
}
示例4: wwwDocsPath
FilePath Options::wwwDocsPath() const
{
FilePath supportingFilePath = desktop::options().supportingFilePath();
FilePath wwwDocsPath = supportingFilePath.complete("www/docs");
if (!wwwDocsPath.exists())
wwwDocsPath = supportingFilePath.complete("../gwt/www/docs");
#ifdef __APPLE__
if (!wwwDocsPath.exists())
wwwDocsPath = supportingFilePath.complete("../../../../../gwt/www/docs");
#endif
return wwwDocsPath;
}
示例5: getChunkDefs
Error getChunkDefs(const std::string& docPath, const std::string& docId,
time_t *pDocTime, core::json::Value* pDefs)
{
// try local context first
FilePath defs = chunkDefinitionsPath(docPath, docId, notebookCtxId());
if (!defs.exists())
{
// if no definitions, try the saved context
defs = chunkDefinitionsPath(docPath, docId, kSavedCtx);
if (!defs.exists())
return Success();
}
return getChunkDefs(defs, pDocTime, pDefs);
}
示例6: iconData
// determines the icon data; this could be either a path on disk (if we have
// a suitable icon locally), base64-encoded icon data (if the icon is embedded
// in an R package), or nothing (if we cannot determine an icon at all)
std::string iconData(const std::string& iconGroup,
const std::string& iconName,
const std::string& iconPath)
{
if (iconPath.empty())
{
// convert the icon name into the format of our shipped icons, which is
// all lowercase with no whitespace (e.g. "SQL Server" => "sqlserver.png")
std::string iconFilename(string_utils::toLower(iconName));
iconFilename = boost::regex_replace(iconFilename,
boost::regex("\\s"), "") + ".png";
// the package did not supply an icon; see if there's one baked in
FilePath path = options().rResourcesPath().childPath("connections")
.childPath(iconGroup)
.childPath(iconFilename);
if (path.exists())
return std::string("connections/") + iconGroup + "/" + iconFilename;
if (iconGroup == "drivers")
return std::string("connections/drivers/odbc.png");
// didn't find anything
return std::string();
}
// expand the path
FilePath icon = module_context::resolveAliasedPath(iconPath);
std::string iconData;
// ensure that the icon file exists and is a small GIF, JPG, or PNG image
if (icon.exists() && icon.size() < kMaxIconSize &&
(icon.hasExtensionLowerCase(".gif") ||
icon.hasExtensionLowerCase(".png") ||
icon.hasExtensionLowerCase(".jpg") ||
icon.hasExtensionLowerCase(".jpeg")))
{
Error error = base64::encode(icon, &iconData);
if (error)
LOG_ERROR(error);
else
{
iconData = "data:" + icon.mimeContentType("image/png") +
";base64," + iconData;
}
}
return iconData;
}
示例7: detectZipFileOverwrites
Error detectZipFileOverwrites(const FilePath& uploadedZipFile,
const FilePath& destDir,
json::Array* pOverwritesJson)
{
// query for all of the paths in the zip file
std::vector<std::string> zipFileListing;
r::exec::RFunction listZipFile(".rs.listZipFile",
uploadedZipFile.absolutePath());
Error unzipError = listZipFile.call(&zipFileListing);
if (unzipError)
return unzipError;
// check for overwrites
for (std::vector<std::string>::const_iterator
it = zipFileListing.begin();
it != zipFileListing.end();
++it)
{
FilePath filePath = destDir.complete(*it);
if (filePath.exists())
pOverwritesJson->push_back(module_context::createFileSystemItem(filePath));
}
return Success();
}
示例8: renameFile
// IN: String path, String targetPath
core::Error renameFile(const core::json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// read params
std::string path, targetPath;
Error error = json::readParams(request.params, &path, &targetPath);
if (error)
return error ;
// if the destination already exists then send back file exists
FilePath destPath = module_context::resolveAliasedPath(targetPath) ;
if (destPath.exists())
return fileExistsError(ERROR_LOCATION);
// create file info now before we remove
FilePath sourcePath = module_context::resolveAliasedPath(path);
FileInfo sourceFileInfo(sourcePath);
// move the file
Error renameError = sourcePath.move(destPath);
if (renameError)
return renameError ;
// generate delete event for folders (inotify doesn't do this right now)
if (sourceFileInfo.isDirectory())
enqueFileRemovedEvent(sourceFileInfo);
return Success() ;
}
示例9: createFile
// IN: String path
core::Error createFile(const core::json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
std::string path;
Error error = json::readParam(request.params, 0, &path);
if (error)
return error ;
// calculate file path
FilePath filePath = module_context::resolveAliasedPath(path) ;
if (filePath.exists())
{
return fileExistsError(ERROR_LOCATION);
}
else
{
// create the file
boost::shared_ptr<std::ostream> pOfs;
error = filePath.open_w(&pOfs);
if (error)
return error;
}
return Success() ;
}
示例10: reportHistoryAccessError
void reportHistoryAccessError(const std::string& context,
const FilePath& historyFilePath,
const Error& error)
{
// always log
LOG_ERROR(error);
// default summary
std::string summary = error.summary();
// if the file exists and we still got no such file or directory
// then it is almost always permission denied. this seems to happen
// somewhat frequently on linux systems where the user was root for
// an operation and ended up writing a .Rhistory
if (historyFilePath.exists() &&
(error.code() == boost::system::errc::no_such_file_or_directory))
{
summary = "permission denied (is the .Rhistory file owned by root?)";
}
// notify the user
std::string path = createAliasedPath(historyFilePath);
std::string errmsg = context + " " + path + ": " + summary;
REprintf(("Error attempting to " + errmsg + "\n").c_str());
}
示例11:
std::string Base64ImageFilter::toBase64Image(const boost::cmatch& match)
{
// extract image reference
std::string imgRef = match[3];
// see if this is an image within the base directory. if it is then
// base64 encode it
FilePath imagePath = basePath_.childPath(imgRef);
if (imagePath.exists() &&
boost::algorithm::starts_with(imagePath.mimeContentType(), "image/"))
{
std::string imageBase64;
Error error = core::base64::encode(imagePath, &imageBase64);
if (!error)
{
imgRef = "data:" + imagePath.mimeContentType() + ";base64,";
imgRef.append(imageBase64);
}
else
{
LOG_ERROR(error);
}
}
// return the filtered result
return match[1] + match[2] + imgRef + match[4];
}
示例12: getDefaultWorkingDirectory
FilePath getDefaultWorkingDirectory()
{
// calculate using user settings
FilePath defaultWorkingDir = userSettings().initialWorkingDirectory();
FilePath sessionDefaultWorkingDir = FilePath(session::options().defaultWorkingDir());
// return it if it exists, otherwise use the
// session specified value if it exists
// otherwise, use the default user home path
if (defaultWorkingDir.exists() && defaultWorkingDir.isDirectory())
return defaultWorkingDir;
else if (sessionDefaultWorkingDir.exists() && sessionDefaultWorkingDir.isDirectory())
return sessionDefaultWorkingDir;
else
return session::options().userHomePath();
}
示例13: setCacheableFile
void setCacheableFile(const FilePath& filePath,
const Request& request,
const Filter& filter)
{
// ensure that the file exists
if (!filePath.exists())
{
setError(http::status::NotFound, request.uri() + " not found");
return;
}
// set Last-Modified
using namespace boost::posix_time;
ptime lastModifiedDate = from_time_t(filePath.lastWriteTime());
setHeader("Last-Modified", util::httpDate(lastModifiedDate));
// compare file modified time to If-Modified-Since
if (lastModifiedDate == request.ifModifiedSince())
{
removeHeader("Content-Type"); // upstream code may have set this
setStatusCode(status::NotModified);
}
else
{
setFile(filePath, request, filter);
}
}
示例14: handleFileExportRequest
void handleFileExportRequest(const http::Request& request,
http::Response* pResponse)
{
// see if this is a single or multiple file request
std::string file = request.queryParamValue("file");
if (!file.empty())
{
// resolve alias and ensure that it exists
FilePath filePath = module_context::resolveAliasedPath(file);
if (!filePath.exists())
{
pResponse->setError(http::status::NotFound, "file doesn't exist");
return;
}
// get the name
std::string name = request.queryParamValue("name");
if (name.empty())
{
pResponse->setError(http::status::BadRequest, "name not specified");
return;
}
// download as attachment
setAttachmentResponse(request, name, filePath, pResponse);
}
else
{
handleMultipleFileExportRequest(request, pResponse);
}
}
示例15: projectFromDirectory
FilePath projectFromDirectory(const FilePath& directoryPath)
{
// first use simple heuristic of a case sentitive match between
// directory name and project file name
FilePath projectFile = directoryPath.childPath(
directoryPath.filename() + ".Rproj");
if (projectFile.exists())
return projectFile;
// didn't satisfy it with simple check so do scan of directory
std::vector<FilePath> children;
Error error = directoryPath.children(&children);
if (error)
{
LOG_ERROR(error);
return FilePath();
}
// build a vector of children with .rproj extensions. at the same
// time allow for a case insensitive match with dir name and return that
std::string projFileLower = string_utils::toLower(projectFile.filename());
std::vector<FilePath> rprojFiles;
for (std::vector<FilePath>::const_iterator it = children.begin();
it != children.end();
++it)
{
if (!it->isDirectory() && (it->extensionLowerCase() == ".rproj"))
{
if (string_utils::toLower(it->filename()) == projFileLower)
return *it;
else
rprojFiles.push_back(*it);
}
}
// if we found only one rproj file then return it
if (rprojFiles.size() == 1)
{
return rprojFiles.at(0);
}
// more than one, take most recent
else if (rprojFiles.size() > 1 )
{
projectFile = rprojFiles.at(0);
for (std::vector<FilePath>::const_iterator it = rprojFiles.begin();
it != rprojFiles.end();
++it)
{
if (it->lastWriteTime() > projectFile.lastWriteTime())
projectFile = *it;
}
return projectFile;
}
// didn't find one
else
{
return FilePath();
}
}