fix: cppcheck (21 troballes)

This commit is contained in:
2026-05-16 13:52:31 +02:00
parent a48fe51f73
commit bf7be3a7f1
13 changed files with 96 additions and 117 deletions
+14 -19
View File
@@ -5,6 +5,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <numeric>
const std::string ResourcePack::DEFAULT_ENCRYPT_KEY = "AEE_RESOURCES__2026";
@@ -21,11 +22,7 @@ ResourcePack::~ResourcePack() {
auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
// djb2-like hash, seed 0x12345678 (idèntic a CCAE).
uint32_t checksum = 0x12345678;
for (unsigned char b : data) {
checksum = ((checksum << 5) + checksum) + b;
}
return checksum;
return std::accumulate(data.begin(), data.end(), uint32_t{0x12345678}, [](uint32_t acc, unsigned char b) { return ((acc << 5) + acc) + b; });
}
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
@@ -163,20 +160,18 @@ auto ResourcePack::addDirectory(const std::string& directory) -> bool {
return false;
}
for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) {
if (!entry.is_regular_file()) {
continue;
}
std::string filepath = entry.path().string();
std::string filename = std::filesystem::relative(entry.path(), directory).string();
std::ranges::replace(filename, '\\', '/');
if (!addFile(filename, filepath)) {
return false;
}
}
return true;
namespace fs = std::filesystem;
return std::all_of(fs::recursive_directory_iterator(directory),
fs::recursive_directory_iterator{},
[&](const fs::directory_entry& entry) {
if (!entry.is_regular_file()) {
return true;
}
std::string filepath = entry.path().string();
std::string filename = fs::relative(entry.path(), directory).string();
std::ranges::replace(filename, '\\', '/');
return addFile(filename, filepath);
});
}
auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8_t> {