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:
parent
392a0e2ba0
commit
557b33a4dd
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user