diff --git a/source/resource.cpp b/source/resource.cpp index 1ee6426..b440efb 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -4,7 +4,7 @@ #include // Para find_if, max, find #include // Para array -#include // Para exit +#include // Para exit, getenv #include // Para runtime_error #include // Para move #include // Para ofstream @@ -26,10 +26,18 @@ struct JA_Sound_t; // lines 12-12 // Helper para cargar archivos de audio desde pack o filesystem namespace { std::string createTempAudioFile(const std::string& file_path) { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "DEBUG: Trying to load audio file: %s", file_path.c_str()); auto resource_data = ResourceHelper::loadFile(file_path); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "DEBUG: Resource data size: %u", static_cast(resource_data.size())); if (!resource_data.empty()) { - // Crear archivo temporal - std::string temp_path = "/tmp/ccae_audio_" + std::to_string(std::hash{}(file_path)); + // Crear archivo temporal usando std::filesystem::temp_directory_path() + std::string temp_dir; +#ifdef _WIN32 + temp_dir = std::getenv("TEMP") ? std::getenv("TEMP") : "C:\\temp"; +#else + temp_dir = "/tmp"; +#endif + std::string temp_path = temp_dir + "/ccae_audio_" + std::to_string(std::hash{}(file_path)); std::ofstream temp_file(temp_path, std::ios::binary); if (!temp_file) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Cannot create temp file %s", temp_path.c_str()); @@ -37,7 +45,7 @@ namespace { } temp_file.write(reinterpret_cast(resource_data.data()), resource_data.size()); temp_file.close(); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Created temp audio file: %s (%zu bytes)", temp_path.c_str(), resource_data.size()); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Created temp audio file: %s (%u bytes)", temp_path.c_str(), static_cast(resource_data.size())); return temp_path; } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Using filesystem audio file: %s", file_path.c_str());