Used shared pointers and string streams to read data from the CEterPackManager

This commit is contained in:
2024-12-24 06:54:43 +02:00
parent 603f2207ef
commit c21c99393d
50 changed files with 363 additions and 3668 deletions

View File

@ -14,10 +14,8 @@ void Folder::ListFiles(const std::string& directory, const std::string& relative
// Start searching for files and directories
hFind = FindFirstFile(searchPath.c_str(), &findData);
if (hFind == INVALID_HANDLE_VALUE) {
std::cerr << L"Failed to open directory: " << directory << L"\n";
return;
}
if (hFind == INVALID_HANDLE_VALUE)
throw std::runtime_error("Failed to open directory: " + directory);
do {
const std::string fileOrDirName = findData.cFileName;
@ -86,26 +84,15 @@ bool Folder::getFile(const std::string& fileName, std::shared_ptr<std::vector<ch
realFileName = this->folderPath + "/" + realFileName;
// open the file:
// Try to open the file
std::ifstream file(realFileName, std::ios::binary);
if (!file.is_open())
return false;
// Stop eating new lines in binary mode!!!
file.unsetf(std::ios::skipws);
// get its size:
std::streampos fileSize;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
// reserve capacity
fileData->reserve(fileSize);
// read the data:
fileData->insert(fileData->begin(),
std::istream_iterator<BYTE>(file),
std::istream_iterator<BYTE>());
return true;
// Read the file's contents
fileData = std::make_shared<std::vector<char>>(
std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()
);
return true;
}