TestingSetup() { fPrintToDebugger = true; // don't want to write to debug.log file noui_connect(); bitdb.MakeMock(); pathTemp = GetTempPath() / strprintf("test_crunchcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); pblocktree = new CBlockTreeDB(1 << 20, true); pcoinsdbview = new CCoinsViewDB(1 << 23, true); pcoinsTip = new CCoinsViewCache(*pcoinsdbview); InitBlockIndex(); bool fFirstRun; pwalletMain = new CWallet("wallet.dat"); pwalletMain->LoadWallet(fFirstRun); RegisterWallet(pwalletMain); nScriptCheckThreads = 3; for (int i=0; i < nScriptCheckThreads-1; i++) threadGroup.create_thread(&ThreadScriptCheck); }
// TEXTURE2D vgd::Shp< vgd::node::Texture2D > createTexture2D( const vgio::Media & media, const boost::filesystem::path pathFilename, const int index, const aiString aiImagePath, const aiTextureMapMode mapU, const aiTextureMapMode mapV ) { // Compute image path std::string imagePathFilenameStr; namespace bfs = boost::filesystem; const bfs::path imagePathFilename = aiImagePath.C_Str(); if ( imagePathFilename.is_absolute() ) { imagePathFilenameStr = imagePathFilename.string(); } else // relative path { const bfs::path rootPath = pathFilename.parent_path(); imagePathFilenameStr = (rootPath / imagePathFilename).string(); } // Texture node using vgd::node::Texture2D; vgd::Shp< Texture2D > texture = Texture2D::create( imagePathFilename.filename().string(), (int8)index ); // IMAGE // Gathers the image from the cache. vgd::Shp< vgd::basic::IImage > image; image = vgio::ImageCache::load( media, imagePathFilenameStr ); texture->setImage( image ); // Default values texture->setMipmap( true ); texture->setMinFilter( Texture2D::LINEAR_MIPMAP_LINEAR ); texture->setMagFilter( Texture2D::LINEAR ); // WRAPPING texture->setWrapS( toEnum(mapU) ); texture->setWrapT( toEnum(mapV) ); // FUNCTION texture->sethFunction( vgd::node::Texture2D::FUN_MODULATE ); // @todo return texture; }
TestingSetup() { fPrintToDebugLog = false; // don't want to write to debug.log file noui_connect(); #ifdef ENABLE_WALLET bitcoin_bitdb.MakeMock(); bitcredit_bitdb.MakeMock(); deposit_bitdb.MakeMock(); #endif pathTemp = GetTempPath() / strprintf("test_credits_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); bitcredit_pblocktree = new Credits_CBlockTreeDB(1 << 20, true); bitcredit_pcoinsdbview = new Credits_CCoinsViewDB(1 << 23, true); credits_pcoinsTip = new Credits_CCoinsViewCache(*bitcredit_pcoinsdbview); bitcoin_pblocktree = new Bitcoin_CBlockTreeDB(1 << 20, true); bitcoin_pcoinsdbview = new Bitcoin_CCoinsViewDB(1 << 23, true); bitcoin_pcoinsTip = new Bitcoin_CCoinsViewCache(*bitcoin_pcoinsdbview); Bitcoin_InitBlockIndex(); Credits_InitBlockIndex(); #ifdef ENABLE_WALLET bool fFirstRun; bitcoin_pwalletMain = new Bitcoin_CWallet("bitcoin_wallet.dat"); bitcoin_pwalletMain->LoadWallet(fFirstRun); Bitcoin_RegisterWallet(bitcoin_pwalletMain); bitcredit_pwalletMain = new Credits_CWallet("credits_wallet.dat", &bitcredit_bitdb); bitcredit_pwalletMain->LoadWallet(fFirstRun, bitcredit_nAccountingEntryNumber); Bitcredit_RegisterWallet(bitcredit_pwalletMain); deposit_pwalletMain = new Credits_CWallet("deposit_wallet.dat", &deposit_bitdb); deposit_pwalletMain->LoadWallet(fFirstRun, deposit_nAccountingEntryNumber); Bitcredit_RegisterWallet(deposit_pwalletMain); #endif bitcredit_nScriptCheckThreads = 3; for (int i=0; i < bitcredit_nScriptCheckThreads-1; i++) threadGroup.create_thread(&Bitcredit_ThreadScriptCheck); Bitcredit_RegisterNodeSignals(Credits_NetParams()->GetNodeSignals()); }
size_t IOFactory::loadFile( std::list<Chunk> &ret, const boost::filesystem::path &filename, util::istring suffix_override, util::istring dialect ) { FileFormatList formatReader; formatReader = getFileFormatList( filename.string(), suffix_override, dialect ); const util::istring with_dialect = dialect.empty() ? util::istring( "" ) : util::istring( " with dialect \"" ) + dialect + "\""; if ( formatReader.empty() ) { if( !boost::filesystem::exists( filename ) ) { LOG( Runtime, error ) << util::MSubject( filename ) << " does not exist as file, and no suitable plugin was found to generate data from " << ( suffix_override.empty() ? util::istring( "that name" ) : util::istring( "the suffix \"" ) + suffix_override + "\"" ); } else if( suffix_override.empty() ) { LOG( Runtime, error ) << "No plugin found to read " << filename << with_dialect; } else { LOG( Runtime, error ) << "No plugin supporting the requested suffix " << suffix_override << with_dialect << " was found"; } } else { BOOST_FOREACH( FileFormatList::const_reference it, formatReader ) { LOG( ImageIoDebug, info ) << "plugin to load file" << with_dialect << " " << util::MSubject( filename ) << ": " << it->getName(); try { int loaded=it->load( ret, filename.native(), dialect, m_feedback ); BOOST_FOREACH( Chunk & ref, ret ) { if ( ! ref.hasProperty( "source" ) ) ref.setPropertyAs( "source", filename.native() ); } return loaded; } catch ( std::runtime_error &e ) { if( suffix_override.empty() ) { LOG( Runtime, formatReader.size() > 1 ? warning : error ) << "Failed to load " << filename << " using " << it->getName() << with_dialect << " ( " << e.what() << " )"; } else { LOG( Runtime, warning ) << "The enforced format " << it->getName() << " failed to read " << filename << with_dialect << " ( " << e.what() << " ), maybe it just wasn't the right format"; } } } LOG_IF( boost::filesystem::exists( filename ) && formatReader.size() > 1, Runtime, error ) << "No plugin was able to load: " << util::MSubject( filename ) << with_dialect; }
void sc_ugen_factory::load_plugin ( boost::filesystem::path const & path ) { using namespace std; void * handle = dlopen(path.string().c_str(), RTLD_NOW | RTLD_LOCAL); if (handle == NULL) return; typedef int (*info_function)(); info_function api_version = reinterpret_cast<info_function>(dlsym(handle, "api_version")); int plugin_api_version = 1; // default if (api_version) plugin_api_version = (*api_version)(); if (plugin_api_version != sc_api_version) { cerr << "API Version Mismatch: " << path << endl; dlclose(handle); return; } info_function supernova_check = reinterpret_cast<info_function>(dlsym(handle, "server_type")); if (!supernova_check || (*supernova_check)() == sc_server_scsynth) { // silently ignore dlclose(handle); return; } void * load_symbol = dlsym(handle, "load"); if (!load_symbol) { cerr << "Problem when loading plugin: \"load\" function undefined" << path << endl; dlclose(handle); return; } open_handles.push_back(handle); LoadPlugInFunc load_func = reinterpret_cast<LoadPlugInFunc>(load_symbol); (*load_func)(&sc_interface); /* don't close the handle */ return; }
std::vector<std::string> psi_util::load_text(fs::path const& file) { // try to open input stream std::ifstream in_file(file.c_str()); if (!in_file.good()) { in_file.close(); throw std::runtime_error("Failed to open text file " + file.string() + "."); } // read line by line std::string line; std::vector<std::string> contents; while (in_file.good()) { getline(in_file, line); contents.push_back(line + "\n"); } // close file and return contents in_file.close(); return contents; }
bool OpenCascStorage(int locale) { try { boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data"); CascStorage = CASC::OpenStorage(storage_dir, WowLocaleToCascLocaleFlags[locale]); if (!CascStorage) { printf("error opening casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]); return false; } return true; } catch (boost::filesystem::filesystem_error& error) { printf("error opening casc storage : %s\n", error.what()); return false; } }
void FSSnatSource::deleted(const fs::path& filePath) { try { string pathstr = filePath.string(); snat_map_t::iterator it = knownSnats.find(pathstr); if (it != knownSnats.end()) { LOG(INFO) << "Removed snat-ip " << it->second << " at " << filePath; removeSnat(it->second); knownSnats.erase(it); } } catch (const std::exception& ex) { LOG(ERROR) << "Could not delete snat for " << filePath << ": " << ex.what(); } catch (...) { LOG(ERROR) << "Unknown error while deleting snat information for " << filePath; } }
bool writeVectorToFile(boost::filesystem::path path, const std::vector<T>& vec) { { bool binary = std::is_same<T, std::string>::value; auto flags = std::ios_base::out | std::ios_base::binary; boost::iostreams::filtering_ostream out; out.push(boost::iostreams::gzip_compressor(6)); out.push(boost::iostreams::file_sink(path.string(), flags)); size_t num = vec.size(); size_t elemSize = sizeof(typename std::vector<T>::value_type); // We have to get rid of constness below, but this should be OK out.write(reinterpret_cast<char*>(const_cast<T*>(vec.data())), num * elemSize); out.reset(); } return true; }
bool GameScene::Save(boost::filesystem::path file) { m_filepath = file; using namespace ld3d; DataStream_File stream; if(false == stream.OpenStream(file.string().c_str(), false)) { return false; } if(false == m_pCore->GetScene()->Serialize(&stream)) { return false; } stream.Close(); return true; }
ProcessResults processFile(fs::path file, Params& params) { ProcessResults result; Pex::Binary pex; try { Pex::FileReader reader(file.string()); reader.read(pex); } catch(std::exception& ex) { result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what())); return result; } if (params.outputAssembly) { fs::path asmFile = params.assemblyDir / file.filename().replace_extension(".pas"); try { std::ofstream asmStream(asmFile.string()); Decompiler::AsmCoder asmCoder(new Decompiler::StreamWriter(asmStream)); asmCoder.code(pex); result.push_back(boost::str(boost::format("%1% dissassembled to %2%") % file.string() % asmFile.string())); } catch(std::exception& ex) { result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what())); fs::remove(asmFile); } } fs::path pscFile = params.papyrusDir / file.filename().replace_extension(".psc"); try { std::ofstream pscStream(pscFile.string()); Decompiler::PscCoder pscCoder(new Decompiler::StreamWriter(pscStream)); pscCoder.outputAsmComment(params.outputComment).code(pex); result.push_back(boost::str(boost::format("%1% decompiled to %2%") % file.string() % pscFile.string())); } catch(std::exception& ex) { result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what())); fs::remove(pscFile); } return result; }
void DatasetManager::openFileHelper( boost::filesystem::path aPath, ProgressNotifier::Ptr aProgressNotifier, DatasetID aDatasetId, bool aUseAsCurrent ) { M4D::Imaging::AImage::Ptr image; if ( aPath.extension() == ".dcm" || aPath.extension() == ".DCM" ) { M4D::Dicom::DicomObjSetPtr dicomObjSet = M4D::Dicom::DicomObjSetPtr( new M4D::Dicom::DicomObjSet() ); M4D::Dicom::DcmProvider::LoadSerieThatFileBelongsTo( aPath, aPath.parent_path(), *dicomObjSet, aProgressNotifier ); image = M4D::Dicom::DcmProvider::CreateImageFromDICOM( dicomObjSet ); } else { image = M4D::Imaging::ImageFactory::LoadDumpedImage( aPath.string() ); } if (image) { registerImage( aDatasetId, aPath, image, aUseAsCurrent ); } if( aProgressNotifier ) { aProgressNotifier->finished(); } //mProdconn.PutDataset( image ); }
void run_scripts(const boost::filesystem::path &p, PyObject *m) { std::regex filePattern("^.+\\.py$"); if (!boost::filesystem::is_directory(p)) { if (std::regex_match(p.leaf().string(), filePattern)) { std::ifstream input(p.string().c_str()); if (input.is_open()) { std::string str((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>()); PyRun_String(str.c_str(), Py_file_input, m, m); input.close(); } } } }
/*! * Find somewhere safe to write the file. * * We work on the assumption that the user's own home directory * is always writeable. Strictly speaking this is not always * true but is true enough for most realistic cases. * * This function may create empty files as a side-effect. It should * only be called when we know if will use the resulting file. */ static file::path makeWriteable(const file::path& path) { if (hbcxx::touch(path.string())) return file::path{path}; auto home = std::getenv("HOME"); if (nullptr == home) throw PrePreProcessorError{}; auto filename = file::path{home}; filename /= ".hbcxx"; filename /= file::absolute(path); (void) file::create_directories(filename.parent_path()); if (hbcxx::touch(filename.string())) return filename; throw PrePreProcessorError{}; }
/** * \brief Create the configuration file, if it does not exists. * \return true if the file already exists or if it has been created. */ bool bf::configuration::create_config_file() const { bool result = false; const boost::filesystem::path path ( path_configuration::get_instance().get_config_directory() + s_config_file_name ); if ( !boost::filesystem::exists( path ) ) { std::ofstream f( path.string().c_str() ); f << s_comment << " Configuration file for Bear Factory - Animation editor\n"; } if ( boost::filesystem::exists( path ) ) result = !boost::filesystem::is_directory( path ); return result; } // configuration::create_config_file()
void ObjModelLoader::parseMtl(fs::path file) { //TODO parse Mtl-File and put the materials into the (hash)map // within the model. // remember: 1 object = 1 material = 1 vbo // mööööp -wrong! if (!exists(file)) cerr << "Material-File '" << file.string() << "' does not exist!" << endl; Material* matPtr = 0; fs::ifstream mtlFile; mtlFile.open(file, ios::in); char line[200]; vector<string> tokens; while (mtlFile.getline(line, 200)) { tokens = splitSpace(string(line)); if (tokens[0] == ("newmtl")) { string longName(""); for (unsigned int i = 1; i < tokens.size(); ++i) { longName.append(tokens[i]); longName.append(" "); } longName.erase(longName.end() - 1); matPtr = new Material(); matPtr->kdR = ooctools::defaultColorF.getX(); matPtr->kdG = ooctools::defaultColorF.getY(); matPtr->kdB = ooctools::defaultColorF.getZ(); mPriMatMap.insert(make_pair(longName, matPtr)); // cout << "found MaterialDefinition '" << tokens[1] << "'!" << endl; } else if (!strcasecmp("kd", tokens[0].c_str())) { matPtr->kdR = atof(tokens[1].c_str()); matPtr->kdG = atof(tokens[2].c_str()); matPtr->kdB = atof(tokens[3].c_str()); } } mtlFile.close(); }
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ bool XMLConfiguration::parse(const boost::filesystem::path& _configFile) { xmlDocPtr const pDoc = xmlParseFile(_configFile.string().c_str()); // Check to see if the config file could be parsed. if (pDoc == NULL) { // TODO Thrown an exception or something? return false; } xmlNodePtr pNode = xmlDocGetRootElement(pDoc); if (pNode == NULL) { xmlFreeDoc(pDoc); return false; } // Loop through all of the nodes while(pNode != NULL) { // Create a configuration element out of this node config_element_ptr_type pElement(new XMLConfigurationElement(*this, NULL, pNode)); m_config.insert(config_pair_type(pElement->getName(), pElement)); // Call the callback function passing the new element //_function(pElement); // Dispatch event if necessary dispatchEvent(pElement); pNode = pNode->next; } xmlFreeDoc(pDoc); return true; }
async_image_check_and_download_op( boost::asio::io_service & _io_service, boost::filesystem::path item, Handler _handler ) : handler( _handler ), io_service( _io_service ) { using namespace boost::filesystem; using namespace boost::asio::detail; using namespace boost::system::errc; if( !exists( item ) ) { // 这事实上应该算是严重的错误了 :) io_service.post( bind_handler( handler, make_error_code(no_such_file_or_directory))); } else { std::vector<char> content( boost::filesystem::file_size( item ) ); // 读取文件,然后执行 MD5 校验. std::ifstream imgfile( item.string().c_str(), std::ifstream::openmode(std::ifstream::binary | std::ifstream::in) ); imgfile.read( &content[0], content.capacity() ); boost::hashes::md5::digest_type md5 = boost::hashes::compute_digest<boost::hashes::md5>( content ); std::string imgfilename = boost::filesystem::basename( item.filename() ); std::string imgfilemd5 = md5.str(); if( compare_image_degest_and_filename( imgfilename, imgfilemd5 ) ) { // do nothing io_service.post( bind_handler( handler, boost::system::error_code() ) ); } else { // 重新下载图片. std::string cface = basename( item ) + extension( item ); // 重新执行图片下载. webqq::async_fetch_cface( io_service, cface, boost::bind( *this, _1, _2, cface ) ); } } }
/// recursive void push_tree_impl( client::vtrc_client_sptr &client, interfaces::remote_fs &impl, const fs::path &remote_root, const fs::path &root, const fs::path &path ) { /// create remote directory impl.mkdir( path.string( ) ); fs::directory_iterator begin( root / path ); const fs::directory_iterator end; for( ;begin != end; ++begin ) { if( fs::is_regular_file(*begin) ) { fs::path remote_path( remote_root / path / begin->path( ).leaf( ) ); std::cout << "Push file: " << "\"" << begin->path( ).string( ) << "\"" << " -> " << "\"" << remote_path.string( ) << "\"" << "\n"; /// upload file push_file( client, begin->path( ).string( ), remote_path.string( ), 44000 ); } else if( fs::is_directory( *begin ) ) { std::cout << "Next directory: " << begin->path( ) << "\n"; push_tree_impl( client, impl, remote_root, root, path / begin->path( ).leaf( ) ); } } }
std::vector<char> psi_util::load_binary(fs::path const& file) { // might throw, pass exception if it does auto size = fs::file_size(file); // allocate memory of file size std::vector<char> bin(size); // try to open binary input stream std::ifstream in_file(file.c_str(), std::ios::in | std::ios::binary); if (!in_file.good()) { in_file.close(); throw std::runtime_error("Failed to open binary file " + file.string() + "."); } // copy whole file into vector in_file.read(bin.data(), size); // close file and return contents in_file.close(); return bin; }
inline bool __is_directory(const boost::filesystem::path& path) { if (path.empty()) return false; struct stat statbuf; #if BOOST_FILESYSTEM_VERSION == 2 if (::lstat(path.file_string().c_str(), &statbuf) >= 0) return ! S_ISLNK(statbuf.st_mode) && S_ISDIR(statbuf.st_mode); else { errno = 0; return false; } #else if (::lstat(path.string().c_str(), &statbuf) >= 0) return ! S_ISLNK(statbuf.st_mode) && S_ISDIR(statbuf.st_mode); else { errno = 0; return false; } #endif }
inline bool __exists(const boost::filesystem::path& path) { if (path.empty()) return false; struct stat statbuf; #if BOOST_FILESYSTEM_VERSION == 2 if (::lstat(path.file_string().c_str(), &statbuf) >= 0) return true; else { errno = 0; return false; } #else if (::lstat(path.string().c_str(), &statbuf) >= 0) return true; else { errno = 0; return false; } #endif }
OpenReadableFile(const fs::path& path) { // Obtain a file descriptor for the requested file read. int pfd = open(path.parent_path().string().c_str(), O_RDONLY | O_NONBLOCK); if (pfd < 0) { fd = -1; return; } struct stat file; // If the process is running as root, drop privileges before reading. // The process may have already dropped (if within a table), so act on E. if (geteuid() == 0 && fstat(pfd, &file) >= 0 && file.st_uid != 0) { dropped = true; seteuid(file.st_uid); setegid(file.st_gid); } close(pfd); // Open the file descriptor and allow caller to perform error checking. fd = open(path.string().c_str(), O_RDONLY | O_NONBLOCK); }
std::vector<std::string> loadFileToVector( const boost::filesystem::path& fileName) { std::vector<std::string> lines; boost::filesystem::ifstream ifs(fileName); if (!ifs.is_open()) { throw std::runtime_error( std::string("Cannot file find ") + fileName.string()); } std::string line; while(!ifs.eof()) { std::getline(ifs, line); lines.push_back(line); } // Remove the extra newline lines.pop_back(); return lines; }
logger(fs::path const& logpath, fs::path const& filename, int instance, bool append = true) { #if TORRENT_USE_IOSTREAM #ifndef BOOST_NO_EXCEPTIONS try { #endif fs::path dir(fs::complete(logpath / ("libtorrent_logs" + boost::lexical_cast<std::string>(instance)))); if (!fs::exists(dir)) fs::create_directories(dir); m_file.open((dir / filename).string().c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::out)); *this << "\n\n\n*** starting log ***\n"; #ifndef BOOST_NO_EXCEPTIONS } catch (std::exception& e) { std::cerr << "failed to create log '" << filename.string() << "': " << e.what() << std::endl; } #endif #endif }
Temporary::Temporary(const boost::filesystem::path &path) : PATH_(path), eraser_(path), stream_(path.string( ).c_str( )) { if (PATH_.empty( )) { throw PathError("Invalid path", path); } if (boost::filesystem::exists(PATH_) && boost::filesystem::is_directory(PATH_)) { throw PathError("Directory path not accepted", path); } if (!stream_.is_open( )) { throw PathError("Cannot open file", PATH_); } }
//-------------------------------------------------------------- std::vector<Leaf::Leaf_identifier::feature_vector> read_vectors(const Fs::path& p) { assert(Fs::exists(p)); std::ifstream in(p.string()); assert(in); std::vector<Leaf::Leaf_identifier::feature_vector> fvs; std::string line; while (std::getline(in, line)) { Leaf::Leaf_identifier::feature_vector fv; std::istringstream iss(line); float f = 0.f; while (iss >> f) { fv.push_back(f); } if (fv.empty()) break; //if (fv.size() != 14) break; fvs.push_back(std::move(fv)); } return fvs; }
void do_module(const std::string& moduleName, const boost::filesystem::path& path) { boost::filesystem::path const modulePath (path / std::string(&moduleName[0], 2) / std::string(&moduleName[2], 2)); boost::filesystem::path const module(modulePath / moduleName); if (!boost::filesystem::exists(module)) { std::cout << "Base module doesn't exist, downloading it...\n"; if (!boost::filesystem::exists(modulePath)) boost::filesystem::create_directories(modulePath); std::ofstream outFile(module.string(), std::ofstream::out | std::ofstream::binary); GetFile("xx.depot.battle.net", 1119, "/" + moduleName, outFile); outFile.close(); std::cout << "Done.\n"; } PatchModule<PATCH, PATTERN>(module, path); }
std::pair<model, std::list<animation>> load (const boost::filesystem::path& file) { auto file_size (boost::filesystem::file_size(file)); if (file_size < sizeof(header)) throw std::runtime_error("iqm::read: file too small"); if (file_size > 16000000) throw std::runtime_error("iqm::read: file too large"); std::ifstream str (file.string(), std::ios::binary); if (!str) throw std::runtime_error("iqm::read: cannot open file"); std::vector<char> buf; buf.resize(file_size + 1); str.read(&buf[0], sizeof(header)); const header& hdr (*(header*)&buf[0]); if (!std::equal(std::begin(hdr.magic), std::end(hdr.magic), "INTERQUAKEMODEL")) throw std::runtime_error("iqm::read: not an IQM file"); if (hdr.filesize > file_size) throw std::runtime_error("iqm::read: file is incomplete"); if (hdr.ofs_vertexarrays + hdr.num_vertexarrays * sizeof(vertexarray) > hdr.filesize) throw std::runtime_error("iqm::read: vertex array out of bounds"); if (hdr.ofs_meshes + hdr.num_meshes * sizeof(mesh) > hdr.filesize) throw std::runtime_error("iqm::read: mesh array out of bounds"); if (hdr.ofs_triangles + hdr.num_triangles * sizeof(triangle) > hdr.filesize) throw std::runtime_error("iqm::read: triangle array out of bounds"); auto remaining (hdr.filesize - sizeof(hdr)); str.read(&buf[sizeof(header)], remaining); buf[hdr.filesize] = 0; return std::make_pair(load_meshes(buf), load_anims(buf)); }
bool Project::Save(const boost::filesystem::path& file) { QFile qfile(QString::fromStdString(file.string())); SCOPE_EXIT(qfile.close()); if (!qfile.open(QIODevice::WriteOnly | QIODevice::Text)) return false; QXmlStreamWriter writer(&qfile); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(-1); writer.writeStartDocument(); { writer.writeStartElement("project"); { writer.writeTextElement("scene", QString::fromStdString(m_pScene->GetFileName().string())); writer.writeTextElement("clear_color", "0, 0, 0"); writer.writeStartElement("camera"); { writer.writeTextElement("eye_pos", "0, 0, -100"); writer.writeTextElement("focus_pos", "0, 0, 0"); } writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndDocument(); m_filePath = file; RestoreProjectRoot(); return true; }