本文整理汇总了C++中FileReader::ReadMagic方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::ReadMagic方法的具体用法?C++ FileReader::ReadMagic怎么用?C++ FileReader::ReadMagic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::ReadMagic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadITQ
bool CSoundFile::ReadITQ(FileReader &file, ModLoadingFlags loadFlags)
//------------------------------------------------------------------
{
file.Rewind();
ITFileHeader fileHeader;
if(!file.ReadConvertEndianness(fileHeader)
|| (memcmp(fileHeader.id, "ITQM", 4))
|| fileHeader.insnum > 0xFF
|| fileHeader.smpnum >= MAX_SAMPLES
|| !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
InitializeGlobals();
bool interpretModPlugMade = false;
// OpenMPT crap at the end of file
file.Seek(file.GetLength() - 4);
size_t mptStartPos = file.ReadUint32LE();
if(mptStartPos >= file.GetLength() || mptStartPos < 0x100)
{
mptStartPos = file.GetLength();
}
if(!memcmp(fileHeader.id, "tpm.", 4))
{
// Legacy MPTM files (old 1.17.02.xx releases)
ChangeModTypeTo(MOD_TYPE_MPT);
} else
{
if(mptStartPos <= file.GetLength() - 3 && fileHeader.cwtv > 0x888 && fileHeader.cwtv <= 0xFFF)
{
file.Seek(mptStartPos);
ChangeModTypeTo(file.ReadMagic("228") ? MOD_TYPE_MPT : MOD_TYPE_IT);
} else
{
ChangeModTypeTo(MOD_TYPE_IT);
}
if(GetType() == MOD_TYPE_IT)
{
// Which tracker was used to made this?
if((fileHeader.cwtv & 0xF000) == 0x5000)
{
// OpenMPT Version number (Major.Minor)
// This will only be interpreted as "made with ModPlug" (i.e. disable compatible playback etc) if the "reserved" field is set to "OMPT" - else, compatibility was used.
m_dwLastSavedWithVersion = (fileHeader.cwtv & 0x0FFF) << 16;
if(!memcmp(fileHeader.reserved, "OMPT", 4))
interpretModPlugMade = true;
} else if(fileHeader.cmwt == 0x888 || fileHeader.cwtv == 0x888)
{
// OpenMPT 1.17 and 1.18 (raped IT format)
// Exact version number will be determined later.
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0217 && fileHeader.cmwt == 0x0200 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
if(memchr(fileHeader.chnpan, 0xFF, sizeof(fileHeader.chnpan)) != NULL)
{
// ModPlug Tracker 1.16 (semi-raped IT format)
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 16, 00, 00);
madeWithTracker = "ModPlug tracker 1.09 - 1.16";
} else
{
// OpenMPT 1.17 disguised as this in compatible mode,
// but never writes 0xFF in the pan map for unused channels (which is an invalid value).
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 17, 00, 00);
madeWithTracker = "OpenMPT 1.17 (compatibility export)";
}
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0202 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
// ModPlug Tracker b3.3 - 1.09, instruments 557 bytes apart
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 09, 00, 00);
madeWithTracker = "ModPlug tracker b3.3 - 1.09";
interpretModPlugMade = true;
}
} else // case: type == MOD_TYPE_MPT
{
if (fileHeader.cwtv >= verMptFileVerLoadLimit)
{
AddToLog(str_LoadingIncompatibleVersion);
return false;
}
else if (fileHeader.cwtv > verMptFileVer)
{
AddToLog(str_LoadingMoreRecentVersion);
}
}
}
if(GetType() == MOD_TYPE_IT) mptStartPos = file.GetLength();
// Read row highlights
if((fileHeader.special & ITFileHeader::embedPatternHighlights))
//.........这里部分代码省略.........
示例2: void
OPENMPT_NAMESPACE_BEGIN
bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
//-------------------------------------------------------------------
{
file.Rewind();
// No valid MO3 file (magic bytes: "MO3")
if(!file.CanRead(8) || !file.ReadMagic("MO3"))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
#ifdef NO_MO3
// As of November 2013, the format revision is 5; Versions > 31 are unlikely to exist in the next few years,
// so we will just ignore those if there's no UNMO3 library to tell us if the file is valid or not
// (avoid log entry with .MOD files that have a song name starting with "MO3".
if(file.ReadUint8() > 31)
{
return false;
}
AddToLog(GetStrI18N("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."));
return false;
#else
bool result = false; // Result of trying to load the module, false == fail.
// Try to load unmo3 dynamically.
mpt::Library unmo3 = mpt::Library(mpt::LibraryPath::App(MPT_PATHSTRING("unmo3")));
if(!unmo3.IsValid())
{
// Didn't succeed.
AddToLog(GetStrI18N("Loading MO3 file failed because unmo3.dll could not be loaded."));
} else
{
// Library loaded successfully.
#if MPT_OS_WINDOWS
#define UNMO3_API __stdcall
#else
#define UNMO3_API
#endif
typedef uint32 (UNMO3_API * UNMO3_GETVERSION)();
// Decode a MO3 file (returns the same "exit codes" as UNMO3.EXE, eg. 0=success)
// IN: data/len = MO3 data/len
// OUT: data/len = decoded data/len (if successful)
// flags & 1: Don't load samples
typedef int32 (UNMO3_API * UNMO3_DECODE_OLD)(const void **data, uint32 *len);
typedef int32 (UNMO3_API * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags);
// Free the data returned by UNMO3_Decode
typedef void (UNMO3_API * UNMO3_FREE)(const void *data);
#undef UNMO3_API
UNMO3_GETVERSION UNMO3_GetVersion = nullptr;
UNMO3_DECODE_OLD UNMO3_Decode_Old = nullptr;
UNMO3_DECODE UNMO3_Decode = nullptr;
UNMO3_FREE UNMO3_Free = nullptr;
unmo3.Bind(UNMO3_GetVersion, "UNMO3_GetVersion");
if(UNMO3_GetVersion == nullptr)
{
// Old API version: No "flags" parameter.
unmo3.Bind(UNMO3_Decode_Old, "UNMO3_Decode");
} else
{
unmo3.Bind(UNMO3_Decode, "UNMO3_Decode");
}
unmo3.Bind(UNMO3_Free, "UNMO3_Free");
if((UNMO3_Decode != nullptr || UNMO3_Decode_Old != nullptr) && UNMO3_Free != nullptr)
{
file.Rewind();
const void *stream = file.GetRawData();
uint32 length = mpt::saturate_cast<uint32>(file.GetLength());
int32 unmo3result;
if(UNMO3_Decode != nullptr)
{
unmo3result = UNMO3_Decode(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1);
} else
{
// Old API version: No "flags" parameter.
unmo3result = UNMO3_Decode_Old(&stream, &length);
}
if(unmo3result == 0)
{
// If decoding was successful, stream and length will keep the new pointers now.
FileReader unpackedFile(stream, length);
result = ReadXM(unpackedFile, loadFlags)
|| ReadIT(unpackedFile, loadFlags)
|| ReadS3M(unpackedFile, loadFlags)
|| ReadMTM(unpackedFile, loadFlags)
|| ReadMod(unpackedFile, loadFlags)
|| ReadM15(unpackedFile, loadFlags);
//.........这里部分代码省略.........