mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
use QT functions
This commit is contained in:
@ -361,25 +361,18 @@ void FirstLaunchView::extractGogData()
|
|||||||
QString errorText{};
|
QString errorText{};
|
||||||
|
|
||||||
auto isGogGalaxyExe = [](QString fileExe) {
|
auto isGogGalaxyExe = [](QString fileExe) {
|
||||||
std::ifstream is(fileExe.toStdString(), std::ios::binary);
|
QFile file(fileExe);
|
||||||
if (!is)
|
quint64 fileSize = file.size();
|
||||||
return false;
|
|
||||||
is >> std::noskipws;
|
|
||||||
is.seekg(0, std::ios::end);
|
|
||||||
std::streampos fileSize = is.tellg();
|
|
||||||
is.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
if(fileSize > 10 * 1024 * 1024)
|
if(fileSize > 10 * 1024 * 1024)
|
||||||
return false; // avoid to load big files; galaxy exe is smaller...
|
return false; // avoid to load big files; galaxy exe is smaller...
|
||||||
|
|
||||||
std::vector<char> buffer;
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
buffer.reserve(fileSize);
|
return false;
|
||||||
buffer.insert(buffer.begin(), std::istream_iterator<char>(is), std::istream_iterator<char>());
|
QByteArray data = file.readAll();
|
||||||
|
|
||||||
std::array<char, 20> magic_id{ 0x47, 0x00, 0x4F, 0x00, 0x47, 0x00, 0x20, 0x00, 0x47, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x78, 0x00, 0x79, 0x00 }; //GOG Galaxy
|
const QByteArray magicId{(const char*)u"GOG Galaxy", 20};
|
||||||
|
return data.contains(magicId);
|
||||||
auto res = std::search(buffer.begin(), buffer.end(), magic_id.begin(), magic_id.end());
|
|
||||||
return res != buffer.end();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(isGogGalaxyExe(tmpFileExe))
|
if(isGogGalaxyExe(tmpFileExe))
|
||||||
|
Reference in New Issue
Block a user