unificats els resources en un namespace

This commit is contained in:
2025-11-11 10:04:57 +01:00
parent 1821b84e73
commit 54fc6d2902
35 changed files with 356 additions and 341 deletions
+14 -14
View File
@@ -10,10 +10,10 @@
#include <fstream>
#include <iostream>
namespace Jdd {
namespace Resource {
// Calculate CRC32 checksum for data verification
auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
auto Pack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
uint32_t checksum = 0x12345678;
for (unsigned char byte : data) {
checksum = ((checksum << 5) + checksum) + byte;
@@ -22,7 +22,7 @@ auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32
}
// XOR encryption (symmetric - same function for encrypt/decrypt)
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
void Pack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
if (key.empty()) {
return;
}
@@ -31,13 +31,13 @@ void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& ke
}
}
void ResourcePack::decryptData(std::vector<uint8_t>& data, const std::string& key) {
void Pack::decryptData(std::vector<uint8_t>& data, const std::string& key) {
// XOR is symmetric
encryptData(data, key);
}
// Read entire file into memory
auto ResourcePack::readFile(const std::string& filepath) -> std::vector<uint8_t> {
auto Pack::readFile(const std::string& filepath) -> std::vector<uint8_t> {
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
if (!file) {
std::cerr << "ResourcePack: Failed to open file: " << filepath << '\n';
@@ -57,7 +57,7 @@ auto ResourcePack::readFile(const std::string& filepath) -> std::vector<uint8_t>
}
// Add a single file to the pack
auto ResourcePack::addFile(const std::string& filepath, const std::string& pack_name)
auto Pack::addFile(const std::string& filepath, const std::string& pack_name)
-> bool {
auto file_data = readFile(filepath);
if (file_data.empty()) {
@@ -80,7 +80,7 @@ auto ResourcePack::addFile(const std::string& filepath, const std::string& pack_
}
// Add all files from a directory recursively
auto ResourcePack::addDirectory(const std::string& dir_path,
auto Pack::addDirectory(const std::string& dir_path,
const std::string& base_path) -> bool {
namespace fs = std::filesystem;
@@ -117,7 +117,7 @@ auto ResourcePack::addDirectory(const std::string& dir_path,
}
// Save the pack to a file
auto ResourcePack::savePack(const std::string& pack_file) -> bool {
auto Pack::savePack(const std::string& pack_file) -> bool {
std::ofstream file(pack_file, std::ios::binary);
if (!file) {
std::cerr << "ResourcePack: Failed to create pack file: " << pack_file << '\n';
@@ -162,7 +162,7 @@ auto ResourcePack::savePack(const std::string& pack_file) -> bool {
}
// Load a pack from a file
auto ResourcePack::loadPack(const std::string& pack_file) -> bool {
auto Pack::loadPack(const std::string& pack_file) -> bool {
std::ifstream file(pack_file, std::ios::binary);
if (!file) {
std::cerr << "ResourcePack: Failed to open pack file: " << pack_file << '\n';
@@ -229,7 +229,7 @@ auto ResourcePack::loadPack(const std::string& pack_file) -> bool {
}
// Get a resource by name
auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8_t> {
auto Pack::getResource(const std::string& filename) -> std::vector<uint8_t> {
auto it = resources_.find(filename);
if (it == resources_.end()) {
return {};
@@ -258,12 +258,12 @@ auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8
}
// Check if a resource exists
auto ResourcePack::hasResource(const std::string& filename) const -> bool {
auto Pack::hasResource(const std::string& filename) const -> bool {
return resources_.find(filename) != resources_.end();
}
// Get list of all resources
auto ResourcePack::getResourceList() const -> std::vector<std::string> {
auto Pack::getResourceList() const -> std::vector<std::string> {
std::vector<std::string> list;
list.reserve(resources_.size());
for (const auto& [name, entry] : resources_) {
@@ -274,7 +274,7 @@ auto ResourcePack::getResourceList() const -> std::vector<std::string> {
}
// Calculate overall pack checksum for validation
auto ResourcePack::calculatePackChecksum() const -> uint32_t {
auto Pack::calculatePackChecksum() const -> uint32_t {
if (!loaded_ || data_.empty()) {
return 0;
}
@@ -300,4 +300,4 @@ auto ResourcePack::calculatePackChecksum() const -> uint32_t {
return global_checksum;
}
} // namespace Jdd
} // namespace Resource