feat(pack): alinear sortida i build amb projectes germans

This commit is contained in:
2026-05-25 07:50:29 +02:00
parent 99b18d208d
commit 2d073b6055
3 changed files with 314 additions and 317 deletions
+4 -1
View File
@@ -110,7 +110,10 @@ add_executable(pack_resources EXCLUDE_FROM_ALL
tools/pack_resources/pack_resources.cpp
source/core/resources/resource_pack.cpp
)
target_include_directories(pack_resources PRIVATE "${CMAKE_SOURCE_DIR}/source")
target_include_directories(pack_resources PRIVATE
"${CMAKE_SOURCE_DIR}/source"
"${CMAKE_BINARY_DIR}"
)
target_compile_options(pack_resources PRIVATE -Wall -Wextra -Wpedantic)
# --- REGENERACIÓ AUTOMÀTICA DE build/resources.pack ---
-13
View File
@@ -72,8 +72,6 @@ auto Pack::addFile(const std::string& filepath, const std::string& pack_name) ->
resources_[pack_name] = entry;
std::cout << "[ResourcePack] Añadido: " << pack_name << " (" << file_data.size()
<< " bytes)\n";
return true;
}
@@ -105,7 +103,6 @@ auto Pack::addDirectory(const std::string& dir_path,
relative_path.find(".tsx") != std::string::npos ||
relative_path.find(".DS_Store") != std::string::npos ||
relative_path.find(".git") != std::string::npos) {
std::cout << "[ResourcePack] Saltant: " << relative_path << '\n';
continue;
}
@@ -154,9 +151,6 @@ auto Pack::savePack(const std::string& pack_file) -> bool {
file.write(reinterpret_cast<const char*>(&data_size), sizeof(data_size));
file.write(reinterpret_cast<const char*>(encrypted_data.data()), encrypted_data.size());
std::cout << "[ResourcePack] Guardat: " << pack_file << " (" << resources_.size()
<< " recursos, " << data_size << " bytes)\n";
return true;
}
@@ -219,9 +213,6 @@ auto Pack::loadPack(const std::string& pack_file) -> bool {
// Desencriptar
decryptData(data_, DEFAULT_ENCRYPT_KEY);
std::cout << "[ResourcePack] Carregat: " << pack_file << " (" << resources_.size()
<< " recursos)\n";
return true;
}
@@ -299,10 +290,6 @@ auto Pack::validatePack() const -> bool {
}
}
if (valid) {
std::cout << "[ResourcePack] Validació OK (" << resources_.size() << " recursos)\n";
}
return valid;
}
+72 -65
View File
@@ -1,92 +1,99 @@
// pack_resources.cpp - Utilitat per crear paquets de recursos
// © 2026 JailDesigner
#include "../../source/core/resources/resource_pack.hpp"
#include <filesystem>
#include <iostream>
#include <string>
void print_usage(const char* program_name) {
std::cout << "Ús: " << program_name << " [opcions] [directori_entrada] [fitxer_sortida]\n";
std::cout << "\nOpcions:\n";
std::cout << " --list <fitxer> Llistar contingut d'un paquet\n";
std::cout << "\nExemples:\n";
std::cout << " " << program_name << " data resources.pack\n";
std::cout << " " << program_name << " --list resources.pack\n";
std::cout << "\nSi no s'especifiquen arguments, empaqueta 'data/' a 'resources.pack'\n";
#include "core/resources/resource_pack.hpp"
#include "project.h"
namespace {
void showHelp() {
std::cout << Project::LONG_NAME << " - Resource Packer\n";
std::cout << "==============================================\n";
std::cout << "Usage: pack_resources [options] [input_dir] [output_file]\n\n";
std::cout << "Options:\n";
std::cout << " --help Show this help message\n";
std::cout << " --list List contents of an existing pack file\n\n";
std::cout << "Arguments:\n";
std::cout << " input_dir Directory to pack (default: data)\n";
std::cout << " output_file Pack file name (default: resources.pack)\n";
}
void listPackContents(const std::string& pack_file) {
Resource::Pack pack;
if (!pack.loadPack(pack_file)) {
std::cerr << "Error: cannot open pack file: " << pack_file << '\n';
return;
}
auto resources = pack.getResourceList();
std::cout << "Pack file: " << pack_file << '\n';
std::cout << "Resources: " << resources.size() << '\n';
for (const auto& r : resources) { std::cout << " " << r << '\n'; }
}
} // namespace
int main(int argc, char* argv[]) {
std::string input_dir = "data";
std::string data_dir = "data";
std::string output_file = "resources.pack";
bool list_mode = false;
bool data_dir_set = false;
// Processar arguments
if (argc == 2 && std::string(argv[1]) == "--help") {
print_usage(argv[0]);
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help" || arg == "-h") {
showHelp();
return 0;
}
if (arg == "--list") {
list_mode = true;
if (i + 1 < argc) { output_file = argv[++i]; }
continue;
}
if (!arg.empty() && arg[0] != '-') {
if (!data_dir_set) {
data_dir = arg;
data_dir_set = true;
} else {
output_file = arg;
}
}
}
if (list_mode) {
listPackContents(output_file);
return 0;
}
// Mode --list
if (argc == 3 && std::string(argv[1]) == "--list") {
Resource::Pack pack;
if (!pack.loadPack(argv[2])) {
std::cerr << "ERROR: No es pot carregar " << argv[2] << "\n";
std::cout << Project::LONG_NAME << " - Resource Packer\n";
std::cout << "==============================================\n";
std::cout << "Input directory: " << data_dir << '\n';
std::cout << "Output file: " << output_file << '\n';
if (!std::filesystem::exists(data_dir)) {
std::cerr << "Error: input directory does not exist: " << data_dir << '\n';
return 1;
}
std::cout << "Contingut de " << argv[2] << ":\n";
auto resources = pack.getResourceList();
std::cout << "Total: " << resources.size() << " recursos\n\n";
for (const auto& name : resources) {
std::cout << " " << name << "\n";
}
return 0;
}
// Mode empaquetar
if (argc >= 3) {
input_dir = argv[1];
output_file = argv[2];
}
// Verificar que existeix el directori
if (!std::filesystem::exists(input_dir)) {
std::cerr << "ERROR: Directori no trobat: " << input_dir << "\n";
return 1;
}
if (!std::filesystem::is_directory(input_dir)) {
std::cerr << "ERROR: " << input_dir << " no és un directori\n";
return 1;
}
// Crear paquet
std::cout << "Creant paquet de recursos...\n";
std::cout << " Entrada: " << input_dir << "\n";
std::cout << " Sortida: " << output_file << "\n\n";
Resource::Pack pack;
if (!pack.addDirectory(input_dir)) {
std::cerr << "ERROR: No s'ha pogut afegir el directori\n";
std::cout << "Scanning and packing resources...\n";
if (!pack.addDirectory(data_dir)) {
std::cerr << "Error: failed to add directory to pack\n";
return 1;
}
std::cout << "Found " << pack.getResourceList().size() << " resources\n";
std::cout << "Saving pack file...\n";
if (!pack.savePack(output_file)) {
std::cerr << "ERROR: No s'ha pogut guardar el paquet\n";
std::cerr << "Error: failed to save pack file\n";
return 1;
}
// Resum
auto resources = pack.getResourceList();
std::cout << "\n";
std::cout << "✓ Paquet creat amb èxit!\n";
std::cout << " Recursos: " << resources.size() << "\n";
// Mostrar mida del fitxer
auto file_size = std::filesystem::file_size(output_file);
std::cout << " Mida: " << (file_size / 1024) << " KB\n";
auto file_size = std::filesystem::file_size(std::filesystem::path(output_file));
std::cout << "Pack file created: " << output_file << " ("
<< (static_cast<double>(file_size) / 1024.0 / 1024.0) << " MB)\n";
return 0;
}