本文整理汇总了C++中vfs::Path类的典型用法代码示例。如果您正苦于以下问题:C++ Path类的具体用法?C++ Path怎么用?C++ Path使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool vfs::CVirtualFileSystem::removeFileFromFS(vfs::Path const& sFilePath)
{
vfs::Path sPath,sFile;
sFilePath.splitLast(sPath,sFile);
vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
if(pProf)
{
vfs::IBaseLocation *pBL = pProf->getLocation(sPath);
if(pBL && pBL->implementsWritable())
{
vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pBL);
if(pDir)
{
bool bSuccess = false;
// remove file from virtual structures first
vfs::IBaseFile* file = pDir->getFile(sFilePath);
if(file)
{
vfs::Path sDir,sFile;
sFilePath.splitLast(sDir,sFile);
vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sDir);
if(pVLoc)
{
bSuccess = pVLoc->removeFile(file);
}
}
// delete actual file
return bSuccess && pDir->deleteFileFromDirectory(sFilePath);
}
}
}
return false;
}
示例2:
void vfs::Path::splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const
{
pathSplitFirst(_path, rsFirst._path, rsTail._path, _sep.first, _sep.last);
getFirstLastSeparator(rsFirst.c_str(), rsFirst._sep.first, rsFirst._sep.last);
getFirstLastSeparator(rsTail.c_str(), rsTail._sep.first, rsTail._sep.last);
// no need to check, as the original path is already checked
//rPath.doCheck();
//rFile.doCheck();
}
示例3: GetOneFile
/**
* Downloads a single file from the specified server.
*/
bool GetOneFile(
const launcher::Settings &settings,
const std::string &filename, const Signature crc) {
Trace("Attempting to download " << filename);
core::net::NetClient client(core::net::eConnectionMode::TCP_ASYNC);
std::string hostName;
for (auto server = settings.get_patch_server_begin(); server != settings.get_patch_server_end(); ++server) {
client.start(settings.get_patch_server(0));
if (client.valid()) {
hostName = wrappers::net::http::Uri(server->get_dns_name()).getHost();
break;
}
}
if (!client.valid()) {
Log(LL::Error) << "Unable to connect to any servers." << std::endl;
return false;
}
wrappers::net::http::HttpHeader header = wrappers::net::http::HttpHeader::Builder()
.setRequestType(wrappers::net::http::HttpHeader::eRequestType::HTTP_REQUEST_GET)
.setRequestPath(std::string("/") + settings.get_server_patch_dir() + filename)
.addHeader("host", hostName)
.build();
if (!header.valid()) {
return false;
}
client.send(header.asBlob());
const vfs::Path outputPath = GetOutputPath(filename);
vfs::ofstream outfile(outputPath, std::ios::binary | std::ios::out);
if (!outfile.is_open()) {
Log(LL::Error) << "Unable to open file: " << outputPath.str() << std::endl;
return false;
}
wrappers::net::http::HttpFileHandler fileHandler(outfile);
while (client.valid() && !fileHandler.done()) {
client.update(fileHandler);
core::thread::thisthread::yield();
}
client.stop();
outfile.flush();
if (!fileHandler.success()) {
return false;
}
return CheckSignature(outputPath, crc);
}
示例4: ConstructFromFile
IniFilePtr IniFile::ConstructFromFile(vfs::Path filename)
{
// Start parsing
std::ifstream iniFile(filename.toString().c_str());
if (!iniFile)
{
Logger::warning( "[IniFile]: Cannot open file " + filename.toString() );
return IniFilePtr();
}
return ConstructFromStream(iniFile);
}
示例5: ExportToFile
void IniFile::ExportToFile(vfs::Path file, const std::string& headerComments) const
{
std::ofstream stream(file.toString().c_str());
if (!headerComments.empty())
{
// Split the header text into lines and export it as INI comment
std::vector<std::string> lines = StringHelper::split( headerComments, "\n" );
for (std::size_t i = 0; i < lines.size(); ++i)
{
stream << "# " << lines[i] << std::endl;
}
// add some additional line break after the header
stream << std::endl;
}
for (Sections::const_iterator i = _settings.begin(); i != _settings.end(); ++i)
{
stream << "[" << i->first << "]" << std::endl;
for (Options::const_iterator kv = i->second.begin(); kv != i->second.end(); ++kv)
{
stream << kv->key << " = " << kv->value << std::endl;
}
stream << std::endl;
}
}
示例6: load
VariantMap SaveAdapter::load( const vfs::Path& filename )
{
Logger::warning( "SaveAdapter: try load model from " + filename.toString() );
NFile f = NFile::open( filename );
return load( f );
}
示例7: open
bool Addon::open(vfs::Path path)
{
# ifdef CAESARIA_PLATFORM_WIN
_d->library = ::LoadLibraryA(path.toString().c_str());
# else
_d->library = ::dlopen(path.toString().c_str(), RTLD_LAZY);
# endif
if( _d->library != 0 )
{
_d->isOpened = true;
_d->funcInit = _d->initFunction<addonInitFunctor>( "initialize" );
_d->funcGetVersion = _d->initFunction<addonGetVersionFunctor>( "getVersion" );
_d->funcGetLevel = _d->initFunction<addonGetLevelFunctor>( "getLevel" );
}
return _d->isOpened;
}
示例8: start
void PictureBank::Impl::loadAtlas(const vfs::Path& filePath)
{
if( !filePath.exist() )
{
Logger::warning( "PictureBank: cant find atlas " + filePath.toString() );
return;
}
VariantMap info = config::load( filePath );
vfs::Path texturePath = info.get( "texture" ).toString();
vfs::NFile file = vfs::NFile::open( texturePath );
Picture mainTexture;
if( file.isOpen() )
{
mainTexture = PictureLoader::instance().load( file );
}
else
{
Logger::warning( "PictureBank: load atlas failed for texture" + texturePath.toString() );
mainTexture = Picture::getInvalid();
}
//SizeF mainRectSize = mainTexture.size().toSizeF();
if( !info.empty() )
{
VariantMap items = info.get( framesSection ).toMap();
for( auto& i : items )
{
VariantList rInfo = i.second.toList();
Picture pic = mainTexture;
Point start( rInfo.get( 0 ).toInt(), rInfo.get( 1 ).toInt() );
Size size( rInfo.get( 2 ).toInt(), rInfo.get( 3 ).toInt() );
pic.setOriginRect( Rect( start, size ) );
setPicture( i.first, pic );
}
}
}
示例9: CheckSignature
/**
* @return true if the {@code crc} is 0, or matches the computed CRC of the file
*/
bool CheckSignature(const vfs::Path &filePath, const Signature crc) {
Trace("Checking signature matches [" << crc << "] for file " << filePath.str());
vfs::ifstream infile(filePath, std::ios::binary | std::ios::in);
if (!infile.is_open()) {
return false;
}
const Signature downloadCrc = core::hash::CRC32(
std::istreambuf_iterator<char>(infile.rdbuf()),
std::istreambuf_iterator<char>());
Trace("Crc was: " << downloadCrc);
return (crc == 0 || crc == downloadCrc);
}
示例10: ProgressHandlerPtr
UpdateController::UpdateController(IUpdateView& view, vfs::Path executableName, UpdaterOptions& options) :
_view(view),
_curStep(Init),
_updater(options, executableName.baseName()),
_abortFlag(false),
_differentialUpdatePerformed(false)
{
_progress = ProgressHandlerPtr( new ProgressHandler(_view) );
_progress->drop();
_updater.SetDownloadProgressCallback( ptr_cast<Updater::DownloadProgress>( _progress ));
_updater.SetFileOperationProgressCallback( ptr_cast<Updater::FileOperationProgress>( _progress ));
}
示例11: filename
int BmFontUtil::main() {
g_inputFile.checkSet();
g_outputFile.checkSet();
vfs::Mount("./", "./", std::ios::in | std::ios::out | std::ios::binary);
const vfs::Path filename(g_inputFile.get());
const vfs::Path rootPath(filename.dir());
std::string content;
if (!appshared::parseFileToString(filename, content)) {
Log(LL::Error) << "Unable to open input font set: " << g_inputFile.get() << std::endl;
return eExitCode::BAD_FILE;
}
XmlNode doc;
if (!doc.parse(content)) {
Log(LL::Error) << "Unable to parse XML document." << std::endl;
return eExitCode::BAD_DATA;
}
u32 nodeIndex;
if (!doc.getChild("font", nodeIndex)) {
Log(LL::Error) << "XML is not a valid font file. Missing top level 'font' node." << std::endl;
return eExitCode::BAD_DATA;
}
FontDef def;
if (!ParseDocument(def, rootPath, doc.getChild(nodeIndex), g_exportAsDistanceFont.get())) {
return eExitCode::BAD_DATA;
}
if (!appshared::serializeProtoToFile(vfs::Path(g_outputFile.get()), def)) {
Log(LL::Error) << "Unable to write output." << std::endl;
return eExitCode::EXCEPTION;
}
return eExitCode::OK;
}
示例12: tBaseClass
vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS)
: tBaseClass(), m_VFS(pVFS)
{
if(sPattern() == vfs::Const::STAR())
{
m_sLocPattern = vfs::Path(vfs::Const::STAR());
m_sFilePattern = vfs::Path(vfs::Const::STAR());
}
else
{
sPattern.splitLast(m_sLocPattern,m_sFilePattern);
}
_vloc_iter = m_VFS->m_mapFS.begin();
while(_vloc_iter != m_VFS->m_mapFS.end())
{
if( matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()) )
{
bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
_vfile_iter = _vloc_iter->second->iterate();
while(!_vfile_iter.end())
{
vfs::IBaseFile* pFile = NULL;
if(bExclusiveVLoc)
{
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
}
else
{
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
}
if(pFile)
{
vfs::Path const& filename = pFile->getName();
if( matchPattern(m_sFilePattern(),filename()) )
{
return;
}
}
_vfile_iter.next();
}
}
_vloc_iter++;
}
}
示例13: addFont
void FontCollection::addFont(const int key, const std::string& name, vfs::Path pathFont, const int size, const NColor& color )
{
TTF_Font* ttf = TTF_OpenFont(pathFont.toCString(), size);
if( ttf == NULL )
{
std::string errorStr( TTF_GetError() );
#ifdef CAESARIA_PLATFORM_WIN
errorStr += "\n Is it only latin symbols in path to game?";
#endif
OSystem::error( "CRITICAL!!! ", errorStr );
THROW( errorStr );
}
Font font0;
font0._d->ttfFont = ttf;
SDL_Color c = { color.red(), color.green(), color.blue(), color.alpha() };
font0._d->color = c;
setFont( key, name, font0);
}
示例14: SETTINGS_VALUE
void Saver::save(const vfs::Path& filename, const Game& game )
{
VariantMap vm;
vm[ SaverOptions::version ] = 1;
vm[ "timemultiplier" ] = game.timeMultiplier();
VariantMap vm_scenario;
vm_scenario[ "date" ] = game::Date::current();
vm_scenario[ "events" ] = events::Dispatcher::instance().save();
vm_scenario[ "translation" ] = SETTINGS_VALUE( lastTranslation );
vm_scenario[ "climate" ] = (int)game.city()->climate();
vm[ "scenario" ] = vm_scenario;
vm[ SaverOptions::restartFile ] = Variant( _restartFile );
VariantMap vm_empire;
game.empire()->save( vm_empire );
vm[ "empire" ] = vm_empire;
VariantMap plm;
game.player()->save( plm );
vm[ "player" ] = plm;
VariantMap vm_city;
game.city()->save( vm_city );
vm[ "city" ] = vm_city;
VariantMap vm_pantheon;
religion::rome::Pantheon::instance().save( vm_pantheon );
vm[ "pantheon" ] = vm_pantheon;
gui::Minimap* minimap = gui::findChildA<gui::Minimap*>( true, game.gui()->rootWidget() );
if( minimap )
{
vfs::Path imgPath = filename.changeExtension( "png" );
minimap->saveImage( imgPath.toString() );
}
config::save( vm, filename );
}
示例15: initialize
void PictureInfoBank::initialize(vfs::Path filename)
{
Logger::warning( "PictureInfoBank: start load offsets from " + filename.toString() );
VariantMap m = config::load( filename );
foreach( it, m )
{
Variant v = it->second;
Logger::warning( "Set offset for " + it->first );
if( v.type() == Variant::Map )
{
VariantMap vm = v.toMap();
int startIndex = vm[ "start" ];
int stopIndex = vm[ "stop" ];
std::string rc = vm[ "rc" ].toString();
Point offset = vm[ "offset" ].toPoint();
_d->setRange( rc.empty() ? it->first : rc, startIndex, stopIndex, offset );
}
else if( v.type() == Variant::List )
{
VariantList vl = v.toList();
_d->setOne( it->first, vl.get( idxIndex ), vl.get( idxXOffset ), vl.get( idxYOffset ) );
}
}