diff --git a/.gitignore b/.gitignore index d0e92d4..9ac6d88 100755 --- a/.gitignore +++ b/.gitignore @@ -392,3 +392,6 @@ FodyWeavers.xsd sdl_app *.sln.iml + +images.zip +script.py \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index c9639af..5357ab1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -69,6 +69,15 @@ "ios": "cpp", "locale": "cpp", "queue": "cpp", - "stack": "cpp" + "stack": "cpp", + "codecvt": "cpp", + "map": "cpp", + "numeric": "cpp", + "regex": "cpp", + "fstream": "cpp", + "iostream": "cpp", + "numbers": "cpp", + "semaphore": "cpp", + "stop_token": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c7cd88..f6dcfa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) pkg_check_modules(GL REQUIRED gl) +pkg_check_modules(LIBZIP REQUIRED libzip) option(AUDIO "Audio support" OFF) @@ -56,6 +57,7 @@ endif() target_include_directories(sdl_app PRIVATE ${SDL2_INCLUDE_DIRS} ${GL_INCLUDE_DIRS} + ${LIBZIP_INCLUDE_DIRS} ) if(AUDIO) @@ -70,6 +72,7 @@ target_link_libraries(sdl_app ${SDL2_LIBRARIES} ${GL_LIBRARIES} Threads::Threads + ${LIBZIP_LIBRARIES} ) if(AUDIO) diff --git a/TextureManager.cpp b/TextureManager.cpp index 8a63e74..b2cd400 100755 --- a/TextureManager.cpp +++ b/TextureManager.cpp @@ -69,12 +69,13 @@ namespace ZL - TextureDataStruct CreateTextureDataFromBmp24(const std::string& fullFileName) + TextureDataStruct CreateTextureDataFromBmp24(const std::string& fullFileName, const std::string& ZIPFileName) { TextureDataStruct texData; - - std::vector fileArr = readFile(fullFileName); + std::vector fileArr; + if (!ZIPFileName.empty()) fileArr = readFileFromZIP(fullFileName, ZIPFileName); + else fileArr = readFile(fullFileName); size_t fileSize = fileArr.size(); @@ -117,12 +118,13 @@ namespace ZL return texData; } - TextureDataStruct CreateTextureDataFromBmp32(const std::string& fullFileName) + TextureDataStruct CreateTextureDataFromBmp32(const std::string& fullFileName, const std::string& ZIPFileName) { TextureDataStruct texData; - - std::vector fileArr = readFile(fullFileName); + std::vector fileArr; + if (!ZIPFileName.empty()) fileArr = readFileFromZIP(fullFileName, ZIPFileName); + else fileArr = readFile(fullFileName); size_t fileSize = fileArr.size(); diff --git a/TextureManager.h b/TextureManager.h index e46da1f..0d4e504 100755 --- a/TextureManager.h +++ b/TextureManager.h @@ -39,8 +39,8 @@ namespace ZL }; - TextureDataStruct CreateTextureDataFromBmp24(const std::string& fullFileName); - TextureDataStruct CreateTextureDataFromBmp32(const std::string& fullFileName); + TextureDataStruct CreateTextureDataFromBmp24(const std::string& fullFileName, const std::string& ZIPFileName=""); + TextureDataStruct CreateTextureDataFromBmp32(const std::string& fullFileName, const std::string& ZIPFileName=""); #ifdef PNG_ENABLED TextureDataStruct CreateTextureDataFromPng(const std::string& fullFileName); #endif diff --git a/Utils.cpp b/Utils.cpp index 5b80a8b..fdc3ba2 100755 --- a/Utils.cpp +++ b/Utils.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace ZL { @@ -40,6 +41,45 @@ namespace ZL return vec; } + std::vector readFileFromZIP(const std::string& filename, const std::string& zipfilename) { + const std::string zipPath = zipfilename; + int zipErr; + zip_t* archive = zip_open(zipPath.c_str(), ZIP_RDONLY, &zipErr); + if (!archive) { + throw std::runtime_error("Ошибка открытия ZIP: " + zipPath); + } + + std::string cleanFilename = filename; + if (cleanFilename.rfind("./", 0) == 0) { + cleanFilename = cleanFilename.substr(2); + } + + std::cout << "Ищем в ZIP: " << cleanFilename << std::endl; + + zip_file_t* zipFile = zip_fopen(archive, cleanFilename.c_str(), 0); + if (!zipFile) { + zip_close(archive); + throw std::runtime_error("Файл не найден в ZIP: " + cleanFilename); + } + + zip_stat_t fileStat; + if (zip_stat(archive, cleanFilename.c_str(), 0, &fileStat) != 0) { + zip_fclose(zipFile); + zip_close(archive); + throw std::runtime_error("Ошибка чтения ZIP-статистики."); + } + + std::vector fileData; + fileData.resize(fileStat.size); + + zip_fread(zipFile, fileData.data(), fileData.size()); + + zip_fclose(zipFile); + zip_close(archive); + + return fileData; + } + bool findString(const char* in, char* list) { size_t thisLength = strlen(in); diff --git a/Utils.h b/Utils.h index fb4eaed..89960a7 100755 --- a/Utils.h +++ b/Utils.h @@ -13,6 +13,8 @@ namespace ZL std::vector readFile(const std::string& filename); + std::vector readFileFromZIP(const std::string& filename, const std::string& zipfilename); + bool findString(const char* in, char* list); } \ No newline at end of file