void RDOParserRDOItem::parse(const LPRDOParser& pParser) { ASSERT(pParser); std::stringstream in_stream(std::ios_base::in | std::ios_base::out | std::ios_base::binary); switch (m_from) { case sf_repository: { rdo::repository::RDOThreadRepository::FileData fileData(m_type, in_stream); kernel->sendMessage(kernel->repository(), RDOThread::RT_REPOSITORY_LOAD, &fileData); break; } case sf_editor: { rdo::repository::RDOThreadRepository::FileData fileData(m_type, in_stream); kernel->sendMessage(kernel->studio(), RDOThread::RT_STUDIO_MODEL_GET_TEXT, &fileData); break; } } if (in_stream.good()) { parse(pParser, in_stream); } }
// TODO: using this for XPS files results in documents that Microsoft XPS Viewer can't read IStream *OpenDirAsZipStream(const WCHAR *dirPath, bool recursive) { if (!dir::Exists(dirPath)) return NULL; ScopedComPtr<IStream> stream; if (FAILED(CreateStreamOnHGlobal(NULL, TRUE, &stream))) return NULL; zlib_filefunc64_def ffunc; fill_win32s_filefunc64(&ffunc); zipFile zf = zipOpen2_64(stream, 0, NULL, &ffunc); if (!zf) return NULL; size_t dirLen = str::Len(dirPath); if (!path::IsSep(dirPath[dirLen - 1])) dirLen++; bool ok = true; DirIter di(dirPath, recursive); for (const WCHAR *filePath = di.First(); filePath && ok; filePath = di.Next()) { CrashIf(!str::StartsWith(filePath, dirPath)); const WCHAR *nameInZip = filePath + dirLen; size_t fileSize; ScopedMem<char> fileData(file::ReadAll(filePath, &fileSize)); ok = fileData && AppendFileToZip(zf, nameInZip, fileData, fileSize); } int err = zipClose(zf, NULL); if (!ok || err != ZIP_OK) return NULL; stream->AddRef(); return stream; }
QString QAutoGenDialog::GetFileParameter(const QString & strParam, const QString & strFilename, unsigned int iVehicle) { std::map<QString, std::vector<QString> >::iterator iterFileData = m_mapFileData.find(strFilename); if (iterFileData == m_mapFileData.end()) { QFile fileData(strFilename); if (fileData.exists() && fileData.open(QIODevice::ReadOnly | QIODevice::Text)) { Q3TextStream streamData(&fileData); QString strLine; iterFileData = m_mapFileData.insert(std::pair<QString, std::vector<QString> >(strFilename, std::vector<QString>())).first; while (!(strLine = streamData.readLine()).isNull()) { strLine = strLine.stripWhiteSpace(); if (strLine.isEmpty()) continue; iterFileData->second.push_back(strLine); } fileData.close(); } } if (iterFileData == m_mapFileData.end()) return ""; else return iterFileData->second[iVehicle % iterFileData->second.size()]; }
void ResourceSerializer::SerializeToBinary(const char* szReadPath, const char* szSavePath, const char* szFilename) { FileSystem::FileData fileData(255); FileSystem::GetListOfFiles(szReadPath, "*.tga", fileData); SDL_RWops* pRW = NULL; if(szSavePath != NULL) { const size_t uSize = 255; char sFullPath[uSize]; SDL_strlcpy(sFullPath, szSavePath, uSize); SDL_strlcat(sFullPath, szFilename, uSize); pRW = SDL_RWFromFile(sFullPath, "wb"); } else { pRW = SDL_RWFromFile(szFilename, "wb"); } ASSERT(pRW != NULL); SDL_RWwrite(pRW, &s_szWatermark[0], SDL_strlen(s_szWatermark) * sizeof(char), 1); for(auto it = fileData.Begin(); !it.IsEnd(); ++it) { IMGHeader imgHeader; SDL_Surface* pSurface = IMG_tga::Load((*it), &imgHeader); if(pSurface != NULL) { imgHeader.hasPalette = pSurface->format->palette != NULL ? true : false; U8String sName; str::GetFilenameAsIs((*it), sName); StringCRC hash(sName.CStr()); int iSize = (imgHeader.width * imgHeader.height) * 4; uint32 uHashName = hash.Get(); uint32 uBlockSize = (uint32)(sizeof(neko::IMGHeader) + ((size_t)iSize) * sizeof(Uint8)) + (imgHeader.hasPalette ? sizeof(neko::IMGPalette) : (size_t)0); SDL_RWwrite(pRW, &uBlockSize, sizeof(uint32), 1); SDL_RWwrite(pRW, &uHashName, sizeof(uint32), 1); SDL_RWwrite(pRW, &imgHeader, sizeof(neko::IMGHeader), 1); if(imgHeader.hasPalette) { IMGPalette palette; palette.ncolor = pSurface->format->palette->ncolors; Color::Copy(palette.color, *pSurface->format->palette->colors); SDL_RWwrite(pRW, &palette, sizeof(neko::IMGPalette), 1); } SDL_RWwrite(pRW, pSurface->pixels, iSize * sizeof(Uint8), 1); } } uint32 uEnd = 0; SDL_RWwrite(pRW, &uEnd, sizeof(uint32), 1); SDL_RWclose(pRW); }
void onDraw(SkCanvas* canvas) override { SkBitmap bm; SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); SkAutoDataUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); if (nullptr == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); return; } SkAutoMalloc am(fileData->size()); memcpy(am.get(), fileData->data(), fileData->size()); int width, height; if (!slice_etc1_data(am.get(), &width, &height)) { SkDebugf("ETC1 Data is poorly formatted.\n"); return; } SkASSERT(124 == width); SkASSERT(124 == height); size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEADER_SIZE; SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz)); if (!SkInstallDiscardablePixelRef(nonPOTData, &bm)) { SkDebugf("Could not install discardable pixel ref.\n"); return; } canvas->drawBitmap(bm, 0, 0); }
/** * WINDOWS VERSION * Load a resource file from the executable. * The supplied filename must match the supported resource file from the application. */ TFilePtr CNativePosix::GetInternalFile(const std::string& aFilename) { LOG_METHOD(); if (aFilename != internal_cabinet_name) { LOG_ERROR("Unknown resource file %s", aFilename.c_str()); return TFilePtr(); } HRSRC rc = ::FindResource(NULL, MAKEINTRESOURCE(internal_cabinet_resource_id), RT_RCDATA); if (rc != NULL) { HGLOBAL rcData = ::LoadResource(NULL, rc); if (rcData != NULL) { DWORD size = ::SizeofResource(NULL, rc); if (size > 0) { const char* data = static_cast<const char*>(::LockResource(rcData)); if (data != NULL) { TFileData fileData(size); std::copy(data, data+size, fileData.begin()); return std::make_shared<CMemoryFile>(std::move(fileData)); } } } } LOG_ERROR("Could not load internal resource file %s.", aFilename.c_str()); return TFilePtr(); }
bool ZipCreator::SaveAs(const WCHAR *zipFilePath) { if (d->pathsAndZipNames.Count() == 0) return false; zlib_filefunc64_def ffunc; fill_win32_filefunc64(&ffunc); zipFile zf = zipOpen2_64(zipFilePath, 0, NULL, &ffunc); if (!zf) return false; bool result = true; for (size_t i = 0; i < d->pathsAndZipNames.Count(); i += 2) { const WCHAR *fileName = d->pathsAndZipNames.At(i); const WCHAR *nameInZip = d->pathsAndZipNames.At(i + 1); size_t fileSize; ScopedMem<char> fileData(file::ReadAll(fileName, &fileSize)); if (!fileData) { result = false; break; } result = AppendFileToZip(zf, nameInZip, fileData, fileSize); if (!result) break; } int err = zipClose(zf, NULL); if (err != ZIP_OK) result = false; return result; }
void CBspMapResourceProvider::LoadShaders(CPakFile& pakFile) { CPakFile::FileNameList shaderFileNames = pakFile.GetFileNamesMatching(".shader"); for(CPakFile::FileNameList::const_iterator fileNameIterator(shaderFileNames.begin()); fileNameIterator != shaderFileNames.end(); fileNameIterator++) { const std::string& shaderFileName(*fileNameIterator); uint8* fileData(NULL); uint32 fileSize(0); if(!pakFile.ReadFile(shaderFileName.c_str(), &fileData, &fileSize)) { continue; } std::string shaderString(fileData, fileData + fileSize); delete fileData; QuakeShaderList shaders = CQuakeShaderParser::ParseShaders(shaderString.c_str()); for(QuakeShaderList::const_iterator shaderIterator(shaders.begin()); shaderIterator != shaders.end(); shaderIterator++) { m_shaders[shaderIterator->name] = *shaderIterator; } } }
void XercesParser::doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const String& xmlFilename, const String& resourceGroup) { XERCES_CPP_NAMESPACE_USE; // use resource provider to load file data RawDataContainer rawXMLData; System::getSingleton().getResourceProvider()->loadRawDataContainer(xmlFilename, rawXMLData, resourceGroup); MemBufInputSource fileData( rawXMLData.getDataPtr(), static_cast<const unsigned int>(rawXMLData.getSize()), xmlFilename.c_str(), false); // perform parse try { parser->parse(fileData); } catch(...) { // use resource provider to release loaded XML source (if it supports this) System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData); throw; } // use resource provider to release loaded XML source (if it supports this) System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData); }
/** * Finally, make sure that if we get ETC1 data from a PKM file that we can then * accurately write it out into a KTX file (i.e. transferring the ETC1 data from * the PKM to the KTX should produce an identical KTX to the one we have on file) */ DEF_TEST(KtxReexportPKM, reporter) { SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); // Load PKM file into a bitmap SkBitmap etcBitmap; SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(pkmFilename.c_str())); if (nullptr == fileData) { SkDebugf("KtxReexportPKM: can't load test file %s\n", pkmFilename.c_str()); return; } bool installDiscardablePixelRefSuccess = SkDEPRECATED_InstallDiscardablePixelRef(fileData, &etcBitmap); if (!installDiscardablePixelRefSuccess) { ERRORF(reporter, "failed to create discardable pixelRef from KTX file"); return; } // Write the bitmap out to a KTX file. SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::kKTX_Type, 0); SkAutoDataUnref newKtxData(ktxDataPtr); REPORTER_ASSERT(reporter, ktxDataPtr); // See is this data is identical to data in existing ktx file. SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); }
bool StringStore::StorageBin::ReadStringData (iFile* file) { bool okay = true; uint32 diskMagic; if (file->Read ((char*)&diskMagic, sizeof (diskMagic)) != sizeof (diskMagic)) okay = false; if (okay && csLittleEndian::UInt32 (diskMagic) != binFileMagic) okay = false; if (okay) { csRef<iDataBuffer> fileData (file->GetAllData()); csRef<iDataBuffer> strData; strData.AttachNew (new csParasiticDataBuffer (fileData, 4)); stringDataFile.AttachNew (new csMemFile (strData, true)); stringDataFile->SetPos (stringDataFile->GetSize ()); EntryHash::GlobalIterator entriesIt (entries.GetIterator()); while (entriesIt.HasNext ()) { BinID id; BinEntry& entry = entriesIt.Next (id); const char* entryStr = stringDataFile->GetData() + entry.dataOffset; size_t len = strlen (entryStr); entry.crc = CS::Utility::Checksum::CRC32 ((uint8*)entryStr, len); uint hash = csHashCompute (entryStr, len); hashedIDs.Put (hash, id); } } return okay; }
NS_IMETHODIMP nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) { nsCStringKey key(prop); nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key)); if (value) { nsCOMPtr<nsIFile> cloneFile; nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value); NS_ASSERTION(cachedFile, "nsIFile expected"); cachedFile->Clone(getter_AddRefs(cloneFile)); return cloneFile->QueryInterface(uuid, result); } // it is not one of our defaults, lets check any providers FileData fileData(prop, uuid); mProviders->EnumerateBackwards(FindProviderFile, &fileData); if (fileData.data) { if (fileData.persistent) { Set(prop, NS_STATIC_CAST(nsIFile*, fileData.data)); } nsresult rv = (fileData.data)->QueryInterface(uuid, result); NS_RELEASE(fileData.data); // addref occurs in FindProviderFile() return rv; }
void GVolumetricPotential::operator<<(const magnet::xml::Node& XML) { globName = XML.getAttribute("Name"); _fileName = XML.getAttribute("RawFile"); _sampleBytes = XML.getAttribute("SampleBytes").as<size_t>(); //Load the dimensions of the data set (and its subset of data if //only processing a smaller section) auto XMLdim = XML.getNode("Dimensions"); _imageDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}}; _offset = std::array<size_t, 3>{{0, 0, 0}}; if (XML.hasNode("Offset")) { auto XMLdim = XML.getNode("Offset"); _offset = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}}; } std::array<size_t, 3> sampleDimensions = _imageDimensions; if (XML.hasNode("SampleDimensions")) { auto XMLdim = XML.getNode("SampleDimensions"); sampleDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}}; } Ordering fileOrdering(_imageDimensions); std::vector<unsigned char> fileData(fileOrdering.size() * _sampleBytes); dout << "Opening " << _fileName << std::endl; std::ifstream file(_fileName.c_str(), std::ifstream::binary); if (!file.good()) M_throw() << "Failed open the file " << _fileName; dout << "Reading " << fileOrdering.size() * _sampleBytes << " bytes of data into memory" << std::endl; file.read(reinterpret_cast<char*>(fileData.data()), fileOrdering.size() * _sampleBytes); if (!file) M_throw() << "Failed reading volumetric data (read " << file.gcount() << " bytes of an expected " << fileOrdering.size() * _sampleBytes << " from " << _fileName << ")"; file.close(); _ordering = Ordering(sampleDimensions); _volumeData.resize(_ordering.size()); dout << "Resampling " << _ordering.size() << " bytes of data from the file into the simulation" << std::endl; if (_sampleBytes == 1) { if (sampleDimensions == _imageDimensions) std::swap(_volumeData, fileData); else for (size_t z = 0; z < sampleDimensions[2]; ++z) for (size_t y = 0; y < sampleDimensions[1]; ++y) { size_t startindex = fileOrdering.toIndex(std::array<size_t, 3>{{_offset[0], y + _offset[1], z + _offset[2]}}); std::copy(fileData.begin() + startindex, fileData.begin() + startindex + sampleDimensions[0], _volumeData.begin() + _ordering.toIndex(std::array<size_t, 3>{{0, y, z}})); } } else M_throw() << "Do not have an optimised loader for resampling data yet"; dout << "Loading complete" << std::endl; }
bool Terrian::LoadTerrainFromFile(const char* rawFileName,const char* textureName) { //读文件 std::ifstream inFile; inFile.open(rawFileName,std::ios::binary); //得到文件大小 inFile.seekg(0,std::ios::end); std::vector<BYTE> fileData(inFile.tellg()); inFile.seekg(0,std::ios::beg); inFile.read((char*)&fileData[0],fileData.size()); inFile.close(); //保存高度信息 m_HeightInfo.resize(fileData.size()); for (size_t i=0;i<fileData.size();i++) m_HeightInfo[i]=fileData[i]; //加载纹理 HRESULT hr=D3DXCreateTextureFromFile(m_pDevice,textureName,&m_pTexture); if (FAILED(hr)) { PopupError("Create texture in Terrain!"); return false; } return true; }
bool HSGameGuide::Read(const char* fileName) { std::string fullFilePath = CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName); HSFileData fileData(fullFilePath.c_str(),"rb"); if (!m_pGameGuideData) { m_pGameGuideData = GameGuide::default_instance().New(); } m_pGameGuideData->Clear(); bool isOK = m_pGameGuideData->ParseFromArray(fileData.GetBuffer() + 2,fileData.GetSize() - 2); if (isOK) { m_iMaxStep = m_pGameGuideData->guidelist_size(); int count = m_pGameGuideData->battlelayoutlist(0).ballooninfolist_size(); for (int i=0;i<count;++i) { const GameGuide_BattleLayout_BalloonInfo* p = &m_pGameGuideData->battlelayoutlist(0).ballooninfolist(i); int id = p->id(); m_balloons.insert(pair<int,const message::GameGuide_BattleLayout_BalloonInfo*>(id,p)); } CCLog("Read game guide success"); return true; } return false; }
/** * Finally, make sure that if we get ETC1 data from a PKM file that we can then * accurately write it out into a KTX file (i.e. transferring the ETC1 data from * the PKM to the KTX should produce an identical KTX to the one we have on file) */ DEF_TEST(KtxReexportPKM, reporter) { SkString resourcePath = GetResourcePath(); SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm"); // Load PKM file into a bitmap SkBitmap etcBitmap; SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())); REPORTER_ASSERT(reporter, NULL != fileData); bool installDiscardablePixelRefSuccess = SkInstallDiscardablePixelRef( SkDecodingImageGenerator::Create( fileData, SkDecodingImageGenerator::Options()), &etcBitmap); REPORTER_ASSERT(reporter, installDiscardablePixelRefSuccess); // Write the bitmap out to a KTX file. SkData *ktxDataPtr = SkImageEncoder::EncodeData(etcBitmap, SkImageEncoder::kKTX_Type, 0); SkAutoDataUnref newKtxData(ktxDataPtr); REPORTER_ASSERT(reporter, NULL != ktxDataPtr); // See is this data is identical to data in existing ktx file. SkString ktxFilename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.ktx"); SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); }
void CSTLStreamTester::test_istreambuf_iterator() { //把一个文本文件拷贝到一个字符串对象中 std::ifstream inputFile("STLStreamTester.h"); //istream_iterator<char>对象使用operator>>来从输入流中读取单个字符。 //istreambuf_iterator<char>对象进入流的缓冲区并直接读取下一个字符。 //即:一个istreambuf_iterator<char> 对象从一个istream s中读取会调用s.rdbuf()->sgetc()来读s的下一个字符 #if 0 inputFile.unset(ios::skipws); // 关闭inputFile的忽略空格标志 -- 可以读入空格 std::string fileData((istream_iterator<char>(inputFile)), istream_iterator<char>()); //性能差 #endif //istreambuf_iterator 不需要设置空格标志 std::string fileData((std::istreambuf_iterator<char>(inputFile)),std::istreambuf_iterator<char>()); //性能好 TRACE("**********************************************************************\n"); TRACE("%s\n",fileData.c_str()); TRACE("**********************************************************************\n"); }
bool Read_Value_From_Stream( AStreamReader& stream, Json::Value & outValue ) { MemoryBlob fileData(EMemHeap::HeapTemp); CHK_VRET_FALSE_IF_NOT(Util_LoadFileToMemory( stream, fileData )); const char* start = c_cast(const char*) fileData.ToPtr(); const char* end = start + fileData.GetDataSize(); Json::Reader reader; return reader.parse( start, end, outValue, true/*collectComments*/ ); }
bool MwWebServer::GetFileContents(MwWebRequest *request, MwBaseStream *responseContents) { MwString fileName = this->rootPath + "\\" + request->path; if (!this->fileSystem->FileExists(fileName)) return false; MwFileStream fileData(fileName.contents, FileStreamAccessMode_Read); responseContents->WriteStreamData(fileData); return true; }
SoundHandle AudioDevice::createSound(const std::string &name) { // Perform cleanup before creating new sounds audioCleanup(); auto itr = m_audioFiles.find(name); if(itr != m_audioFiles.end()) { // Check if data hasn't been loaded for this file previously if(!alIsBuffer(itr->second.buffer) || itr->second.buffer == 0) { // Open file and save initial data SF_INFO fileInfo; SNDFILE *file = sf_open(itr->second.fileName.c_str(), SFM_READ, &fileInfo); if(file == NULL) { JL_WARNING_LOG("Could not open audio file '%s'", itr->second.fileName.c_str()); return SoundHandle(); } // Create new buffer alGenBuffers(1, &itr->second.buffer); // Read whole file int sampleCount = fileInfo.frames * fileInfo.channels; std::vector<ALshort> fileData(sampleCount); sf_read_short(file, &fileData[0], sampleCount); alBufferData( itr->second.buffer, AudioDevice::getFormatFromChannels(fileInfo.channels), &fileData[0], sampleCount*sizeof(ALushort), fileInfo.samplerate); sf_close(file); } // Create new audio source m_sounds.push_back( SoundHandle(new AudioChunk(itr->second.buffer, itr->second.fileName))); return m_sounds.back(); } else { JL_WARNING_LOG("Couldn't find any sound by the name '%s'", name.c_str()); return SoundHandle(nullptr); } }
Palleon::TexturePtr CLevelSelectionContext::LoadTexture(const char* texturePath) { uint8* fileData(NULL); uint32 fileSize(0); if(!m_pakFile->ReadFile(texturePath, &fileData, &fileSize)) { return Palleon::TexturePtr(); } auto result = Palleon::CTextureLoader::CreateTextureFromMemory(fileData, fileSize); delete fileData; return result; }
ratio::ratio(string title0,reaction* Reaction10, reaction* Reaction20) { title = title0; Reaction1 = Reaction10; Reaction2 = Reaction20; string directory(""); //open data file string filename = directory + title + ".data"; cout << filename << endl; ifstream fileData (filename.c_str(),ios::in); // if one cannot open file quit if (fileData.fail()) { cout << "couldn't open data file" << fileData << endl; abort(); } else { string line; getline(fileData,line); int NN; fileData >> NN; Rdata = new rdata [NN]; Ndata = 0; for (int i=0;i<NN;i++) { fileData >> Rdata[Ndata].energyLab >> Rdata[Ndata].x >> Rdata[Ndata].sigma; if (Rdata[Ndata].energyLab < 5.) continue; //Rdata[Ndata].x /= 200.; //Rdata[Ndata].sigma /= 200.; Rdata[Ndata].energyCM1 = Reaction1-> energyLab2Cm(Rdata[Ndata].energyLab); Rdata[Ndata].energyCM2 = Reaction2-> energyLab2Cm(Rdata[Ndata].energyLab); Ndata++; } fileData.close(); fileData.clear(); } cout << "Ndata = " << Ndata << endl; }
void QQuickQrcSchemeDelegate::readResourceAndSend() { QFile file(m_fileName); QFileInfo fileInfo(file); if (fileInfo.isDir() || !file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) return; QByteArray fileData(file.readAll()); QMimeDatabase mimeDb; QMimeType mimeType = mimeDb.mimeTypeForFileNameAndData(m_fileName, fileData); file.close(); reply()->setData(fileData); reply()->setContentType(mimeType.name()); reply()->send(); }
void CBspMapResourceProvider::LoadTexture(const char* texturePath, CPakFile& pakFile) { if(m_textures.find(texturePath) != m_textures.end()) return; uint8* fileData(NULL); uint32 fileSize(0); if(!pakFile.ReadFile(texturePath, &fileData, &fileSize)) { return; } auto result = Palleon::CTextureLoader::CreateTextureFromMemory(fileData, fileSize); delete fileData; m_textures[texturePath] = result; }
static bool AppendEntry(str::Str<char>& data, str::Str<char>& content, const WCHAR *filePath, const char *inArchiveName, lzma::FileInfo *fi=NULL) { size_t nameLen = str::Len(inArchiveName); CrashIf(nameLen > UINT32_MAX - 25); uint32_t headerSize = 25 + (uint32_t)nameLen; FILETIME ft = file::GetModificationTime(filePath); if (fi && FileTimeEq(ft, fi->ftModified)) { ReusePrevious: ByteWriterLE meta(data.AppendBlanks(24), 24); meta.Write32(headerSize); meta.Write32(fi->compressedSize); meta.Write32(fi->uncompressedSize); meta.Write32(fi->uncompressedCrc32); meta.Write32(ft.dwLowDateTime); meta.Write32(ft.dwHighDateTime); data.Append(inArchiveName, nameLen + 1); return content.AppendChecked(fi->compressedData, fi->compressedSize); } size_t fileDataLen; ScopedMem<char> fileData(file::ReadAll(filePath, &fileDataLen)); if (!fileData || fileDataLen >= UINT32_MAX) { fprintf(stderr, "Failed to read \"%S\" for compression\n", filePath); return false; } uint32_t fileDataCrc = crc32(0, (const uint8_t *)fileData.Get(), (uint32_t)fileDataLen); if (fi && fi->uncompressedCrc32 == fileDataCrc && fi->uncompressedSize == fileDataLen) goto ReusePrevious; size_t compressedSize = fileDataLen + 1; ScopedMem<char> compressed((char *)malloc(compressedSize)); if (!compressed) return false; if (!Compress(fileData, fileDataLen, compressed, &compressedSize)) return false; ByteWriterLE meta(data.AppendBlanks(24), 24); meta.Write32(headerSize); meta.Write32((uint32_t)compressedSize); meta.Write32((uint32_t)fileDataLen); meta.Write32(fileDataCrc); meta.Write32(ft.dwLowDateTime); meta.Write32(ft.dwHighDateTime); data.Append(inArchiveName, nameLen + 1); return content.AppendChecked(compressed, compressedSize); }
void onDraw(SkCanvas* canvas) override { SkBitmap bm; SkString filename = GetResourcePath("mandrill_128."); filename.append(this->fileExtension()); SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())); if (nullptr == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); return; } if (!SkInstallDiscardablePixelRef(fileData, &bm)) { SkDebugf("Could not install discardable pixel ref.\n"); return; } canvas->drawBitmap(bm, 0, 0); }
RTexture RLinuxDataProvider::texture(std::string const & name) { rLogI() << "Loading texture file : " << name << std::endl; RTexture tex; RSmartPointer<FileData> fd = fileData(name); if (!fd.isNull()) { RPNGImageHandler pih; if (pih.load((unsigned char *)fd->mData, fd->mLength)) { tex.set(pih); } else { rLogE() << "loading texture failed " << name << std::endl; } } return tex; }
int mainVerify(const WCHAR *archivePath) { int errorStep = 1; size_t fileDataLen; ScopedMem<char> fileData(file::ReadAll(archivePath, &fileDataLen)); FailIf(!fileData, "Failed to read \"%S\"", archivePath); lzma::SimpleArchive lzsa; bool ok = lzma::ParseSimpleArchive(fileData, fileDataLen, &lzsa); FailIf(!ok, "\"%S\" is no valid LzSA file", archivePath); for (int i = 0; i < lzsa.filesCount; i++) { ScopedMem<char> data(lzma::GetFileDataByIdx(&lzsa, i, NULL)); FailIf(!data, "Failed to extract data for \"%s\"", lzsa.files[i].name); } printf("Verified all %d archive entries\n", lzsa.filesCount); return 0; }
std::shared_ptr<std::vector<unsigned char>> FontManager::loadFontFile( const std::string& fileName) const { std::vector<unsigned char> data; std::ifstream fontFile(fileName, std::ios::binary | std::ios::in | std::ios::ate); if(!fontFile.is_open()) { throw FileIoException(fileName, "Unable to open file"); } size_t fileSize = fontFile.tellg(); //Don't use std::make_shared here so the file data can be deallocated when the //reference count drops to 0, even if there are std::weak_ptrs still referring to the data. std::shared_ptr<std::vector<unsigned char>> fileData(new std::vector<unsigned char>(fileSize)); fontFile.seekg(0, std::ios::beg); fontFile.read(reinterpret_cast<char*>(fileData->data()), fileSize); fontFile.close(); return fileData; }
SimSystemTray::SimSystemTray(QWidget *parent):QSystemTrayIcon(parent){ trayMenu=new QMenu(); QFile menuStyleFile(":/StyleSheet/img/StyleSheet/SimStyleSheet.qss"); if (!menuStyleFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream fileData(&menuStyleFile); QString menuStyleStr=fileData.readAll(); trayMenu->setStyleSheet(menuStyleStr); this->setIcon(QIcon("://img/qq.ico")); createTopWidget(); createContextMenu(); this->setContextMenu(trayMenu); //定义信号连接 connect(restoreAction,SIGNAL(toggled(bool)),this,SIGNAL(restore())); connect(settingAction,SIGNAL(triggered(bool)),this,SIGNAL(setting())); connect(exitAction,SIGNAL(triggered(bool)),qApp,SLOT(quit())); connect(selfStartAction,SIGNAL(triggered()),this,SIGNAL(selfStart())); }