Zip Reader Function Library
Zip Reader Function Library
#pragma once
#include "Engine/Texture2D.h"
#include "DDSLoader.h"
#include "TaskGraphInterfaces.h"
#include "Developer/ImageWrapper/Public/ImageWrapper.h"
#include "zlib.h"
#include "ZipReaderFunctionLibrary.generated.h"
bool resize;
FString filename;
IImageWrapperPtr ImageWrapper;
int32 x, y;
int32 uncompress();
private:
int32 bytesRemaining;
public:
int32 TotalPrimesToFind;
//Done?
bool IsFinished() const
{
return bytesRemaining == 0 && x >= width && y >= height;
}
//Constructor / Destructor
FZipReaderWorker(FString Filename, void* CompressedBuffer, void** OutMipData,
int32 CompressedSize, int32 UncompressedSize, int32* OutWidth, int32* OutHeight,
IImageWrapperPtr ImgWrapper, bool Resize);
virtual ~FZipReaderWorker();
/** Shuts down the thread. Static so it can easily be called from outside the
thread context */
void Shutdown();
bool IsThreadFinished();
};
struct CompressedChunkInfo
{
// Default constructor, zero initializing all members.
CompressedChunkInfo()
{
UncompressedSize = 0;
CompressedSize = 0;
CompressedOffset = 0;
}
struct CachedTextureInfo
{
CachedTextureInfo()
{
PageNumber = 0;
Width = 0;
Height = 0;
TmpMipData = NULL;
Texture = NULL;
}
int32 PageNumber;
void* TmpMipData;
int32 Width;
int32 Height;
TWeakObjectPtr<UTexture2D> Texture;
};
struct ZipFile
{
// Default constructor, zero initializing all members.
ZipFile()
{
CompressedData = NULL;
RequestId = -1;
IsCompressedReadComplete = false;
MainPagesLoaded = 0;
SecondaryPagesLoaded = 0;
FileSize = 0;
}
// Size of zip.
int32 FileSize;
// A list of pages requested from this zip that haven't been dispatched for
load.
TArray<int32> PendingPageRequests;
// A list of page requests with jobs that have been started already.
TArray<int32> ActivePageRequests;
typedef struct {
#pragma pack(push,1) // Supposedly, this is supported on GCC as of certain
versions, definitely 4.0 and greater. *Important for porting - make sure that
something equivalent is done for your compiler, otherwise archives will fail to
load due to wrong offsets in reading/seeking.
uint32 signature;
uint16 versionNeededToExtract; // unsupported
uint16 generalPurposeBitFlag; // unsupported
uint16 compressionMethod;
uint16 lastModFileTime;
uint16 lastModFileDate;
uint32 crc32;
uint32 compressedSize;
uint32 uncompressedSize;
uint16 fileNameLength;
uint16 extraFieldLength; // unsupported
#pragma pack(pop)
} JZLocalFileHeader;
typedef struct {
#pragma pack(push,1)
uint32 signature;
uint16 versionMadeBy; // unsupported
uint16 versionNeededToExtract; // unsupported
uint16 generalPurposeBitFlag; // unsupported
uint16 compressionMethod;
uint16 lastModFileTime;
uint16 lastModFileDate;
uint32 crc32;
uint32 compressedSize;
uint32 uncompressedSize;
uint16 fileNameLength;
uint16 extraFieldLength; // unsupported
uint16 fileCommentLength; // unsupported
uint16 diskNumberStart; // unsupported
uint16 internalFileAttributes; // unsupported
uint32 externalFileAttributes; // unsupported
uint32 relativeOffsetOflocalHeader;
#pragma pack(pop)
} JZGlobalFileHeader;
typedef struct {
#pragma pack(push,1)
uint16 compressionMethod;
uint16 lastModFileTime;
uint16 lastModFileDate;
uint32 crc32;
uint32 compressedSize;
uint32 uncompressedSize;
uint32 offset;
#pragma pack(pop)
} JZFileHeader;
typedef struct {
#pragma pack(push,1)
uint32 signature; // 0x06054b50
uint16 diskNumber; // unsupported
uint16 centralDirectoryDiskNumber; // unsupported
uint16 numEntriesThisDisk; // unsupported
uint16 numEntries;
uint32 centralDirectorySize;
uint32 centralDirectoryOffset;
uint16 zipCommentLength;
#pragma pack(pop)
// Followed by .ZIP file comment (variable size)
} JZEndRecord;
UCLASS()
class ZIPREADER_API UZipReaderFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
//
private:
// Read local ZIP file header. Silent on errors so optimistic reading possible.
int jzReadLocalFileHeader(IFileHandle *zip, JZFileHeader *header, char *filename,
int len);
// Read local ZIP file header. Silent on errors so optimistic reading possible.
int jzReadLocalFileHeaderFromMemory(void* zipData, JZFileHeader *header, char
*filename, int len, int32 currentOffset);