//+----------------------------------------------------------------------------- //| Reads BLP data //+----------------------------------------------------------------------------- bool BLP::Read(const BUFFER& SourceBuffer, BUFFER& TargetBuffer, int* Width, int* Height) { BLP_HEADER Header; memcpy(reinterpret_cast<char*>(&Header), SourceBuffer.GetData(), sizeof(BLP_HEADER)); if (Header.MagicNumber != '1PLB') { LOG("The file is not a BLP file!"); return false; } switch(Header.Compression) { case 0: { if(!LoadCompressed(Header, SourceBuffer, TargetBuffer)) return false; break; } case 1: { if(!LoadUncompressed(Header, SourceBuffer, TargetBuffer)) return false; break; } default: { LOG("Unable to load blp file, unknown compression method!"); return false; } } if(Width != NULL) (*Width) = Header.Width; if(Height != NULL) (*Height) = Header.Height; return true; }
//+----------------------------------------------------------------------------- //| Loads a texture from a buffer //+----------------------------------------------------------------------------- BOOL TEXTURE_LOADER_BLP::Load(TEXTURE& Texture, CONST std::string& FileName, BUFFER& Buffer) { BLP_HEADER Header; CurrentFileName = FileName; std::memcpy(reinterpret_cast<CHAR*>(&Header), &Buffer[0], sizeof(BLP_HEADER)); if (Header.MagicNumber != '1PLB') { Error.SetMessage("The file is not a BLP texture!"); return FALSE; } switch (Header.Compression) { case 0: { if (!LoadCompressed(Texture, Header, Buffer)) return FALSE; break; } case 1: { if (!LoadUncompressed(Texture, Header, Buffer)) return FALSE; break; } default: { Error.SetMessage("Unable to load \"" + FileName + "\", unknown compression method!"); return FALSE; } } return TRUE; }
bool TextureDescriptor::Load(const FilePath &filePathname) { File *file = File::Create(filePathname, File::READ | File::OPEN); if(!file) { Logger::Error("[TextureDescriptor::Load] Can't open file: %s", filePathname.GetAbsolutePathname().c_str()); return false; } pathname = filePathname; int32 signature; file->Read(&signature, sizeof(signature)); int8 version = 0; file->Read(&version, sizeof(version)); if(version != CURRENT_VERSION) { ConvertToCurrentVersion(version, signature, file); SafeRelease(file); return true; } isCompressedFile = (COMPRESSED_FILE == signature); if(isCompressedFile) { LoadCompressed(file); } else if(NOTCOMPRESSED_FILE == signature) { LoadNotCompressed(file); } else { Logger::Error("[TextureDescriptor::Load] Wrong descriptor file: %s", filePathname.GetAbsolutePathname().c_str()); SafeRelease(file); return false; } SafeRelease(file); return true; }
DWORD CNWCFile::Load(wxFile& in, FILE* out, FILELOAD fl) { char buf[64]; if ( sizeof(szNWCHeader) != in.Read(buf, sizeof(szNWCHeader)) || memcmp(szNWCHeader, buf, sizeof(szNWCHeader)) != 0 ) { if ( memcmp(szCompressHeader1, buf, sizeof(szCompressHeader1)) == 0 ) { return LoadCompressed(in, out, fl); } wxFprintf(stderr, _T("invalid szNWCHeader\n")); return ERROR_INVALID_DATA; } if ( !ReadLEShort(in, nVersion) ) { wxFprintf(stderr, _T("unexpected EOF while reading version\n")); wxASSERT(false); return ERROR_INVALID_DATA; } if ( IsValidVersion(nVersion) ) { wxFprintf(out, _T("version:%d.%d\n"), nVerMajor, nVerMinor); } else { wxFprintf(stderr, _T("unknown version number\n")); return ERROR_INVALID_VERSION; } long nPos = in.Tell(); char _szHeader2[4] = "\x02\x00\x00"; // implies NUL at last if ( !ReadBytes(in, btUnknown2) || btUnknown2[0] != _szHeader2[0] || btUnknown2[1] != _szHeader2[1] || btUnknown2[3] != _szHeader2[3] ) { //wxFprintf(stderr, "invalid btUnknown2 at 0x%08x\n", nPos); //wxASSERT(false); } if ( btUnknown2[2] == 5 ) { wxFprintf(out, _T("saved by unregistered version\n")); } else if ( btUnknown2[2] != 0 ) { //wxFprintf(stderr, "invalid btUnknown2 at 0x%08x\n", nPos); } strUser = LoadStringNULTerminated(in); strUnknown1 = LoadStringNULTerminated(in); wxFprintf(out, _T("user:'******', '%s'\n"), strUser.c_str(), strUnknown1.c_str()); nPos = in.Tell(); char szHeader3[8] = "\x00\x00\x00\x00\x00\x00\x00"; // implies NUL at last if ( sizeof(szHeader3) != in.Read(buf, sizeof(szHeader3)) || memcmp(szHeader3, buf, sizeof(szHeader3)) != 0 ) { wxFprintf(stderr, _T("invalid btUnknown2 at 0x%08x\n"), nPos); //wxASSERT(false); } short nUnknown4; if ( !ReadBytes(in, nUnknown4) ) { wxFprintf(stderr, _T("unexpected EOF while reading\n")); wxASSERT(false); return ERROR_INVALID_DATA; } strTitle = LoadStringNULTerminated(in); strAuthor = LoadStringNULTerminated(in); if ( nVersion >= NWC_Version200 ) strLyricist = LoadStringNULTerminated(in); strCopyright1 = LoadStringNULTerminated(in); strCopyright2 = LoadStringNULTerminated(in); strComment = LoadStringNULTerminated(in); wxFprintf(out, _T("title:'%s'\n"), strTitle.c_str()); wxFprintf(out, _T("author:'%s'\n"), strAuthor.c_str()); if ( nVersion >= NWC_Version200 ) wxFprintf(out, _T("lyricist:'%s'\n"), strLyricist.c_str()); wxFprintf(out, _T("copyright1:'%s'\n"), strCopyright1.c_str()); wxFprintf(out, _T("copyright2:'%s'\n"), strCopyright2.c_str()); wxFprintf(out, _T("comment:'%s'\n"), strComment.c_str()); nPos = in.Tell(); char _szReserved5[] = "\x5F\x00\x46\x32\x00"; bool bResult = ReadBytes(in, chExtendLastSystem) && ReadBytes(in, chIncreaseNoteSpacing) && ReadBytes(in, btUnknown3) && ReadBytes(in, btMeasureNumbers) && ReadBytes(in, btUnknown4) && ReadLEShort(in, nMeasureStart); if ( !bResult || memcmp(_szReserved5, btUnknown3, sizeof(btUnknown3)) != 0 ) { // wxFprintf(stderr, "invalid szReserved5 at 0x%08x\n", nPos); // wxASSERT(false); // return ERROR_INVALID_DATA; } wxFprintf(out, _T("extend last system:'%c'\n"), chExtendLastSystem); wxFprintf(out, _T("increase note spacing:'%c'\n"), chIncreaseNoteSpacing); wxFprintf(out, _T("measurenumbers:'%s'\n"), GetMeasureNumbersAsString(btMeasureNumbers)); wxFprintf(out, _T("measurestart:%d\n"), nMeasureStart); if ( nVersion >= NWC_Version130 ) { strMarginTop = LoadStringSpaceTerminated(in); strMarginInside = LoadStringSpaceTerminated(in); strMarginOutside = LoadStringSpaceTerminated(in); strMarginBottom = LoadStringSpaceTerminated(in); } wxFprintf(out, _T("margin:%s %s %s %s\n"), strMarginTop.c_str(), strMarginInside.c_str(), strMarginOutside.c_str(), strMarginBottom.c_str()); ReadBytes(in, bMirrorMargin); wxFprintf(out, _T("mirrormargin:%d\n"), bMirrorMargin); nPos = in.Tell(); if ( !ReadBytes(in, btUnknown5) ) { return ERROR_INVALID_DATA; } if ( nVersion > NWC_Version130 ) { ReadBytes(in, nGroupVisibility); ReadBytes(in, bAllowLayering); wxFprintf(out, _T("group visibility:")); CObj::DumpBinary(out, nGroupVisibility, sizeof(nGroupVisibility), false); wxFprintf(out, _T("\nallowlayering:%d\n"), bAllowLayering); } nPos = in.Tell(); if ( nVersion >= NWC_Version200 ) { strNotationTypeface = LoadStringNULTerminated(in); wxFprintf(out, _T("notationtypeface:%s\n"), strNotationTypeface.c_str()); } ReadLEShort(in, nStaffHeight); wxFprintf(out, _T("staffheight=%d\n"), nStaffHeight); nPos = in.Tell(); int nFontCount = 0; if ( nVersion > NWC_Version130 ) nFontCount = ( nVersion <= NWC_Version170 ? 10 : 12 ); mFontInfos.SetCount(nFontCount); int i; for ( i=0; i<nFontCount; i++ ) { mFontInfos[i].Load(in); } // some 1.70 version have 12 fontinfo if ( nVersion == NWC_Version170 ) { nPos = in.Tell(); unsigned char ch; if ( in.Read(&ch, 1) != 1 ) return ERROR_INVALID_DATA; in.Seek(nPos, wxFromStart); if ( ch == 0 || ch == 0xFF ) { } else { nFontCount += 2; mFontInfos.SetCount(nFontCount); for ( ; i<nFontCount; i++ ) { mFontInfos[i].Load(in); } } } wxFprintf(out, _T("#font=%d\n"), nFontCount); for ( i=0; i<nFontCount; i++ ) { mFontInfos[i].Dump(out, i); } ReadBytes(in, btTitlePageInfo); ReadBytes(in, btStaffLabels); // index of [None, First Systems, Top Systems, All Systems] ReadLEShort(in, nStartPageNo); if ( nVersion >= NWC_Version200 ) { unsigned char ch; if ( in.Read(&ch, 1) != 1 ) return ERROR_INVALID_DATA; if ( ch != 0xFF ) in.Seek(-1, wxFromCurrent); //ReadBytes(in, btJustifyPrintedSystemVertically); } ReadLEShort(in, nStaffCount); wxFprintf(out, _T("titlepageinfo=%d\n"), btTitlePageInfo); wxFprintf(out, _T("stafflabels=%s\n"), GetStaffLabelsAsString(btStaffLabels)); wxFprintf(out, _T("startpageno=%d\n"), nStartPageNo); //if ( nVersion >= NWC_Version200 ) // wxFprintf(out, _T("justifyprintedsystemvertically=%d\n"), btJustifyPrintedSystemVertically); wxFprintf(out, _T("staffcount=%d\n"), nStaffCount); fflush(out); for ( i=0; i<nStaffCount; i++ ) { nPos = in.Tell(); CStaff* pStaff = new CStaff; pStaff->SetParent(this); wxFprintf(out, _T("\nstaff%d\n"), i); if ( false == pStaff->Load(in, out, fl) ) { delete pStaff; return ERROR_INVALID_STAFF; } mStaffs.Add(pStaff); fflush(out); // load until staff which has lyric //if ( fl == FILELOAD_INFO && pStaff->m_strLyric.size() ) // break; } return ERROR_SUCCESS; }