Чтение bmp из zip файла
This commit is contained in:
parent
4e9275fa88
commit
a8689e8b58
3
.gitignore
vendored
3
.gitignore
vendored
@ -392,3 +392,6 @@ FodyWeavers.xsd
|
||||
sdl_app
|
||||
|
||||
*.sln.iml
|
||||
|
||||
images.zip
|
||||
script.py
|
||||
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
|
||||
@ -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<char> fileArr = readFile(fullFileName);
|
||||
std::vector<char> 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<char> fileArr = readFile(fullFileName);
|
||||
std::vector<char> fileArr;
|
||||
if (!ZIPFileName.empty()) fileArr = readFileFromZIP(fullFileName, ZIPFileName);
|
||||
else fileArr = readFile(fullFileName);
|
||||
|
||||
size_t fileSize = fileArr.size();
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
40
Utils.cpp
40
Utils.cpp
@ -5,6 +5,7 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <zip.h>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
@ -40,6 +41,45 @@ namespace ZL
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<char> 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<char> 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user