refactor(log): migra core/resources i core/system a Log::
- resource_pack.cpp i resource_cache.cpp: tots els std::cerr passen a Log::error. - director.cpp: std::cout/cerr/fprintf → Log::info / error / critical segons severitat. - printWithDots (utils.cpp): ara és un wrapper sobre Log::info que manté l'amplada total (~50 chars) reproduint l'alineació de punts. Els callers pasen el tag sense " : " (ja l'afegeix el logger). - pack_resources: afegit log.cpp i SDL3 al target perquè resource_pack.cpp ara depèn de Log::. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1243b457be
commit
6e99fd0a8b
8 files changed
+51
-44
No files matched your search
@@ -4,7 +4,8 @@
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
namespace Resource {
|
||||
|
||||
@@ -40,14 +41,14 @@ namespace Resource {
|
||||
std::array<char, 4> header{};
|
||||
file.read(header.data(), 4);
|
||||
if (std::string(header.data(), 4) != MAGIC) {
|
||||
std::cerr << "Resource::Pack: invalid pack file format (bad magic): " << pack_file << '\n';
|
||||
Log::error("Resource::Pack", "invalid pack file format (bad magic): {}", pack_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::uint32_t version = 0;
|
||||
file.read(reinterpret_cast<char*>(&version), sizeof(version));
|
||||
if (version != VERSION) {
|
||||
std::cerr << "Resource::Pack: unsupported pack version: " << version << '\n';
|
||||
Log::error("Resource::Pack", "unsupported pack version: {}", version);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace Resource {
|
||||
auto Pack::savePack(const std::string& pack_file) const -> bool {
|
||||
std::ofstream file(pack_file, std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "Resource::Pack: could not create pack file: " << pack_file << '\n';
|
||||
Log::error("Resource::Pack", "could not create pack file: {}", pack_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ namespace Resource {
|
||||
auto Pack::addFile(const std::string& filename, const std::string& filepath) -> bool {
|
||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||
if (!file) {
|
||||
std::cerr << "Resource::Pack: could not open file: " << filepath << '\n';
|
||||
Log::error("Resource::Pack", "could not open file: {}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ namespace Resource {
|
||||
|
||||
std::vector<std::uint8_t> file_data(file_size);
|
||||
if (!file.read(reinterpret_cast<char*>(file_data.data()), file_size)) {
|
||||
std::cerr << "Resource::Pack: could not read file: " << filepath << '\n';
|
||||
Log::error("Resource::Pack", "could not read file: {}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ namespace Resource {
|
||||
|
||||
auto Pack::addDirectory(const std::string& directory) -> bool {
|
||||
if (!std::filesystem::exists(directory)) {
|
||||
std::cerr << "Resource::Pack: directory does not exist: " << directory << '\n';
|
||||
Log::error("Resource::Pack", "directory does not exist: {}", directory);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ namespace Resource {
|
||||
|
||||
const PackEntry& entry = it->second;
|
||||
if (entry.offset + entry.size > data_.size()) {
|
||||
std::cerr << "Resource::Pack: invalid resource data: " << filename << '\n';
|
||||
Log::error("Resource::Pack", "invalid resource data: {}", filename);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -179,7 +180,7 @@ namespace Resource {
|
||||
|
||||
std::uint32_t checksum = calculateChecksum(result);
|
||||
if (checksum != entry.checksum) {
|
||||
std::cerr << "Resource::Pack: checksum mismatch for: " << filename << '\n';
|
||||
Log::error("Resource::Pack", "checksum mismatch for: {}", filename);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user