1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

use QT functions

This commit is contained in:
Laserlicht 2024-06-23 12:55:58 +02:00 committed by GitHub
parent 392a0e2ba0
commit 557b33a4dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -361,25 +361,18 @@ void FirstLaunchView::extractGogData()
QString errorText{};
auto isGogGalaxyExe = [](QString fileExe) {
std::ifstream is(fileExe.toStdString(), std::ios::binary);
if (!is)
return false;
is >> std::noskipws;
is.seekg(0, std::ios::end);
std::streampos fileSize = is.tellg();
is.seekg(0, std::ios::beg);
QFile file(fileExe);
quint64 fileSize = file.size();
if(fileSize > 10 * 1024 * 1024)
return false; // avoid to load big files; galaxy exe is smaller...
std::vector<char> buffer;
buffer.reserve(fileSize);
buffer.insert(buffer.begin(), std::istream_iterator<char>(is), std::istream_iterator<char>());
if(!file.open(QIODevice::ReadOnly))
return false;
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
auto res = std::search(buffer.begin(), buffer.end(), magic_id.begin(), magic_id.end());
return res != buffer.end();
const QByteArray magicId{(const char*)u"GOG Galaxy", 20};
return data.contains(magicId);
};
if(isGogGalaxyExe(tmpFileExe))