resource.pack
This commit is contained in:
52
tools/pack_resources/Makefile
Normal file
52
tools/pack_resources/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile para la herramienta de empaquetado de Coffee Crisis
|
||||
# =============================================================
|
||||
|
||||
CXX := g++
|
||||
CXXFLAGS := -std=c++20 -Wall -Os -I../../source
|
||||
SOURCES := pack_resources.cpp ../../source/resource_pack.cpp
|
||||
TARGET := pack_resources
|
||||
CLEAN_FILES := pack_resources *.pack *.o
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
DETECTED_OS := Windows
|
||||
TARGET := $(TARGET).exe
|
||||
CLEAN_CMD := del /Q
|
||||
FixPath = $(subst /,\\,$1)
|
||||
else
|
||||
DETECTED_OS := $(shell uname -s)
|
||||
CLEAN_CMD := rm -f
|
||||
FixPath = $1
|
||||
endif
|
||||
|
||||
.PHONY: all pack_tool pack clean help
|
||||
|
||||
all: pack_tool
|
||||
|
||||
pack_tool:
|
||||
@echo "Compilando herramienta de empaquetado para $(DETECTED_OS)..."
|
||||
$(CXX) $(CXXFLAGS) $(SOURCES) -o $(TARGET)
|
||||
@echo "Herramienta compilada: $(TARGET)"
|
||||
|
||||
clean:
|
||||
@echo "Limpiando archivos generados..."
|
||||
$(CLEAN_CMD) $(call FixPath,$(CLEAN_FILES))
|
||||
@echo "Archivos limpiados"
|
||||
|
||||
# Crear pack final (invocado desde el Makefile raíz)
|
||||
pack: pack_tool
|
||||
ifeq ($(OS),Windows_NT)
|
||||
.\$(TARGET) ..\..\data ..\..\resources.pack
|
||||
else
|
||||
./$(TARGET) ../../data ../../resources.pack
|
||||
endif
|
||||
|
||||
help:
|
||||
@echo "Makefile para herramientas de Coffee Crisis"
|
||||
@echo "==========================================="
|
||||
@echo ""
|
||||
@echo "Comandos disponibles:"
|
||||
@echo " all - Compilar herramienta de empaquetado (por defecto)"
|
||||
@echo " pack_tool - Compilar herramienta de empaquetado"
|
||||
@echo " pack - Crear pack final en ../../resources.pack"
|
||||
@echo " clean - Limpiar archivos generados"
|
||||
@echo " help - Mostrar esta ayuda"
|
||||
104
tools/pack_resources/pack_resources.cpp
Normal file
104
tools/pack_resources/pack_resources.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include "resource_pack.h"
|
||||
|
||||
static constexpr const char* APP_NAME = "Coffee Crisis";
|
||||
|
||||
void showHelp() {
|
||||
std::cout << APP_NAME << " - Resource Packer" << '\n';
|
||||
std::cout << "===============================================" << '\n';
|
||||
std::cout << "Usage: pack_resources [options] [input_dir] [output_file]" << '\n';
|
||||
std::cout << '\n';
|
||||
std::cout << "Options:" << '\n';
|
||||
std::cout << " --help Show this help message" << '\n';
|
||||
std::cout << " --list List contents of an existing pack file" << '\n';
|
||||
std::cout << '\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& packFile) {
|
||||
ResourcePack pack;
|
||||
if (!pack.loadPack(packFile)) {
|
||||
std::cerr << "Error: Cannot open pack file: " << packFile << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
auto resources = pack.getResourceList();
|
||||
std::cout << "Pack file: " << packFile << '\n';
|
||||
std::cout << "Resources: " << resources.size() << '\n';
|
||||
std::cout << "Contents:" << '\n';
|
||||
|
||||
for (const auto& resource : resources) {
|
||||
std::cout << " " << resource << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string dataDir = "data";
|
||||
std::string outputFile = "resources.pack";
|
||||
bool listMode = false;
|
||||
bool dataDirSet = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::string arg = argv[i];
|
||||
if (arg == "--help" || arg == "-h") {
|
||||
showHelp();
|
||||
return 0;
|
||||
} else if (arg == "--list") {
|
||||
listMode = true;
|
||||
if (i + 1 < argc) {
|
||||
outputFile = argv[++i];
|
||||
}
|
||||
} else if (!arg.empty() && arg[0] != '-') {
|
||||
if (!dataDirSet) {
|
||||
dataDir = arg;
|
||||
dataDirSet = true;
|
||||
} else {
|
||||
outputFile = arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listMode) {
|
||||
listPackContents(outputFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << APP_NAME << " - Resource Packer" << '\n';
|
||||
std::cout << "===============================================" << '\n';
|
||||
std::cout << "Input directory: " << dataDir << '\n';
|
||||
std::cout << "Output file: " << outputFile << '\n';
|
||||
std::cout << '\n';
|
||||
|
||||
if (!std::filesystem::exists(dataDir)) {
|
||||
std::cerr << "Error: Input directory does not exist: " << dataDir << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
ResourcePack pack;
|
||||
|
||||
std::cout << "Scanning and packing resources..." << '\n';
|
||||
if (!pack.addDirectory(dataDir)) {
|
||||
std::cerr << "Error: Failed to add directory to pack" << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Found " << pack.getResourceCount() << " resources" << '\n';
|
||||
|
||||
std::cout << "Saving pack file..." << '\n';
|
||||
if (!pack.savePack(outputFile)) {
|
||||
std::cerr << "Error: Failed to save pack file" << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path packPath(outputFile);
|
||||
auto fileSize = std::filesystem::file_size(packPath);
|
||||
|
||||
std::cout << "Pack file created successfully!" << '\n';
|
||||
std::cout << "File size: " << (fileSize / 1024.0 / 1024.0) << " MB" << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user