About
The ZipFile class provides means to work with ZIP archives. ZIP files can be created, modified and extracted.
- Note
- To create ZIP archives with the MAXON API see Archives Manual.
Allocation/Deallocation
ZipFile objects are created with the usual tools, see Entity Creation and Destruction Manual (Classic).
Opening and Closing
Filename
Metadata
Compression Level
CRC
Extracting an Entire Archive
if (zf == nullptr)
if (!zf->ExtractToDirectory(fnZip, fnDest))
Definition: ge_autoptr.h:37
Manages file and path names.
Definition: c4d_file.h:94
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())
return OK
Definition: apibase.h:2747
@ DIRECTORY
Folder selection dialog.
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
Current File
Internally the ZipFile class has a pointer to the "current" file inside of the archive. The following functions provide means to change the current file pointer to another file or directory.
UInt32 fileSizeUncompressed = 0;
if (!zf->GoToFirstFile())
return PrintMsgAndCloseZipFile(zf, "Error: No files in ZIP archive.");
do
{
{
sceneFound = true;
break;
}
} while (zf->GoToNextFile());
if (!sceneFound || fileSizeUncompressed == 0)
return PrintMsgAndCloseZipFile(zf, "Error: No C4D scene found in archive.");
Definition: c4d_string.h:39
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::UInt32 UInt32
Definition: ge_sys_math.h:61
#define ZIP_FLAG_DIRECTORY
Directory flag.
Definition: lib_zipfile.h:21
Definition: lib_zipfile.h:73
UInt32 lFlags
Flags: ZIP_FLAG.
Definition: lib_zipfile.h:76
UInt32 lUncompressedSize
Uncompressed size.
Definition: lib_zipfile.h:81
The current file can be extracted from a ZIP archive:
if (zf == nullptr)
if (!zf->Open(fnZip, true))
if (!zf->GoToFirstFile())
{
zf->Close();
}
do
{
zf->ExtractCurrentFile(fnDest);
} while (zf->GoToNextFile());
zf->Close();
Bool ShowInFinder(const Filename &fn, Bool open)
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
Comprehensive information can be retrieved for the current file:
Similar to "normal" files (e.g. BaseFile) the current file can be opened for reading:
if (!zf->OpenCurrentFile())
return PrintMsgAndCloseZipFile(zf, "Error: Failed to open current file in archive.");
return PrintMsgAndCloseZipFile(zf, "Error: Failed to open allocate buffer.");
const Int32 maxChunkSize = 0x1000;
Char*
const bufferEnd =
buffer.GetPointer() + fileSizeUncompressed;
while (!zf->EndOfCurrentFile())
{
if (chunkSize <= 0)
break;
const Int32 numBytesRead = zf->ReadCurrentFile(bufferCurrentPos, chunkSize);
if (numBytesRead < 0)
break;
bufferCurrentPos += numBytesRead;
}
if (!zf->EndOfCurrentFile() || (bufferCurrentPos != bufferEnd))
{
return PrintMsgAndCloseZipFile(zf, "Error: Something went wrong, while reading file from archive.");
}
zf->CloseCurrentFile();
zf->Close();
const char ** buffer
Definition: abstract.h:327
#define NewMemClear(T, cnt)
Definition: defaultallocator.h:204
maxon::Char Char
Definition: ge_sys_math.h:56
maxon::Int32 Int32
Definition: ge_sys_math.h:60
X ClampValue(X value, X lowerLimit, X upperLimit)
Clips a value against a lower and upper limit. The new value is returned.
Definition: apibasemath.h:230
#define iferr_ignore(...)
Definition: resultbase.h:1486
Add to an ZIP File
if (zf == nullptr)
{
}
zf->Close();
String GetFileString() const
#define ZIP_APPEND_CREATE
Creates a new ZIP file.
Definition: lib_zipfile.h:132
Further Reading