Browse Source

use buffer

Laserlicht 1 year ago
parent
commit
2d9843324a
1 changed files with 14 additions and 3 deletions
  1. 14 3
      launcher/firstLaunch/firstlaunch_moc.cpp

+ 14 - 3
launcher/firstLaunch/firstlaunch_moc.cpp

@@ -337,10 +337,21 @@ void FirstLaunchView::extractGogData()
 		if (!is)
 			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)
+			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>());
+
 		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 eos = std::istream_iterator<char>();
-		auto res = std::search(std::istream_iterator<char>(is), eos, magic_id.begin(), magic_id.end());
-		return res != eos;
+
+		auto res = std::search(buffer.begin(), buffer.end(), magic_id.begin(), magic_id.end());
+		return res != buffer.end();
 	};
 
 	QString fileBin = fileSelection("bin", tr("GOG data") + " (*.bin)");