本文整理汇总了C++中FileName::set方法的典型用法代码示例。如果您正苦于以下问题:C++ FileName::set方法的具体用法?C++ FileName::set怎么用?C++ FileName::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileName
的用法示例。
在下文中一共展示了FileName::set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dir_copy
//-------------------------------------------------------------------
// FileName::dir_copy
//-------------------------------------------------------------------
void FileName::dir_copy(const String &strDest, bool bCreateDir, mode_t modeDir, uid_t uid, gid_t gid) throw( Exception )
{
FileName fnDst;
// Create destination path
fnDst.set(strDest);
fnDst.mkdir(modeDir, uid, gid);
if( bCreateDir )
{
// Create source directory name inside destination path
fnDst.set(strDest + dir_name() + SEP_PATH);
fnDst.mkdir(modeDir, uid, gid);
}
if( !fnDst.is_path_name() )
throw BadPathException(PSZ(String::str_format(ERR_BAD_DEST_PATH, PSZ(fnDst.full_name()))),
"FileName::dir_copy");
// Recursively copying sub-directories
FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR);
while( dirEnum.find() )
dirEnum.dir_copy(fnDst.path(), true, modeDir, uid, gid);
// Copying directory files
FileEnum fileEnum(full_name(), FileEnum::ENUM_FILE);
while( fileEnum.find() )
// Copy with metadata
fileEnum.copy(fnDst.path(), true);
}
示例2: getPastedGraphicsFileName
FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
Clipboard::GraphicsType & type) const
{
// create file dialog filter according to the existing types in the clipboard
vector<Clipboard::GraphicsType> types;
if (hasGraphicsContents(Clipboard::EmfGraphicsType))
types.push_back(Clipboard::EmfGraphicsType);
if (hasGraphicsContents(Clipboard::WmfGraphicsType))
types.push_back(Clipboard::WmfGraphicsType);
if (hasGraphicsContents(Clipboard::LinkBackGraphicsType))
types.push_back(Clipboard::LinkBackGraphicsType);
if (hasGraphicsContents(Clipboard::PdfGraphicsType))
types.push_back(Clipboard::PdfGraphicsType);
if (hasGraphicsContents(Clipboard::PngGraphicsType))
types.push_back(Clipboard::PngGraphicsType);
if (hasGraphicsContents(Clipboard::JpegGraphicsType))
types.push_back(Clipboard::JpegGraphicsType);
LASSERT(!types.empty(), /**/);
// select prefered type if AnyGraphicsType was passed
if (type == Clipboard::AnyGraphicsType)
type = types.front();
// which extension?
map<Clipboard::GraphicsType, string> extensions;
map<Clipboard::GraphicsType, docstring> typeNames;
extensions[Clipboard::EmfGraphicsType] = "emf";
extensions[Clipboard::WmfGraphicsType] = "wmf";
extensions[Clipboard::LinkBackGraphicsType] = "linkback";
extensions[Clipboard::PdfGraphicsType] = "pdf";
extensions[Clipboard::PngGraphicsType] = "png";
extensions[Clipboard::JpegGraphicsType] = "jpeg";
typeNames[Clipboard::EmfGraphicsType] = _("Enhanced Metafile");
typeNames[Clipboard::WmfGraphicsType] = _("Windows Metafile");
typeNames[Clipboard::LinkBackGraphicsType] = _("LinkBack PDF");
typeNames[Clipboard::PdfGraphicsType] = _("PDF");
typeNames[Clipboard::PngGraphicsType] = _("PNG");
typeNames[Clipboard::JpegGraphicsType] = _("JPEG");
// find unused filename with primary extension
string document_path = cur.buffer()->fileName().onlyPath().absFileName();
unsigned newfile_number = 0;
FileName filename;
do {
++newfile_number;
filename = FileName(addName(document_path,
to_utf8(_("pasted"))
+ convert<string>(newfile_number) + "."
+ extensions[type]));
} while (filename.isReadableFile());
while (true) {
// create file type filter, putting the prefered on to the front
QStringList filter;
for (size_t i = 0; i != types.size(); ++i) {
docstring s = bformat(_("%1$s Files"), typeNames[types[i]])
+ " (*." + from_ascii(extensions[types[i]]) + ")";
if (types[i] == type)
filter.prepend(toqstr(s));
else
filter.append(toqstr(s));
}
filter = fileFilters(filter.join(";;"));
// show save dialog for the graphic
FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
FileDialog::Result result =
dlg.save(toqstr(filename.onlyPath().absFileName()), filter,
toqstr(filename.onlyFileName()));
if (result.first == FileDialog::Later)
return FileName();
string newFilename = fromqstr(result.second);
if (newFilename.empty()) {
cur.bv().message(_("Canceled."));
return FileName();
}
filename.set(newFilename);
// check the extension (the user could have changed it)
if (!suffixIs(ascii_lowercase(filename.absFileName()),
"." + extensions[type])) {
// the user changed the extension. Check if the type is available
size_t i;
for (i = 1; i != types.size(); ++i) {
if (suffixIs(ascii_lowercase(filename.absFileName()),
"." + extensions[types[i]])) {
type = types[i];
break;
}
}
// invalid extension found, or none at all. In the latter
// case set the default extensions.
if (i == types.size()
&& filename.onlyFileName().find('.') == string::npos) {
//.........这里部分代码省略.........