zipObject.cpp

Engine/source/core/util/zip/zipObject.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(ZipObject , "@brief Provides access <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "A <a href="/coding/class/classzipobject/">ZipObject</a> add, delete and extract files that are within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive. You may also " "read and write directly <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the files within the archive by obtaining <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classstreamobject/">StreamObject</a> " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the file." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive)
DefineEngineMethod(ZipObject , addFile , bool , (const char *filename, const char *pathInZip, bool replace) , (true) , "@brief Add <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive\n\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param pathInZip The path and name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be given <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param replace If <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> already exists within the zip archive at the same location as this " "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> file, this parameter indicates <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it should be replaced. By default, it will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">replaced.\n</a>" " @return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip archive." )
DefineEngineMethod(ZipObject , closeArchive , void , () , "@brief Close an already opened zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@see openArchive()" )
DefineEngineMethod(ZipObject , closeFile , void , (SimObject *stream) , "@brief Close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@param stream The <a href="/coding/class/classstreamobject/">StreamObject</a> of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@see openFileForRead()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openFileForWrite()" )
DefineEngineMethod(ZipObject , deleteFile , bool , (const char *pathInZip) , "@brief Deleted the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> from the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive\n\n</a>" "@param pathInZip The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be deleted from the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return True of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deleted.\n</a>" "@note Files that have been deleted from the archive will still show up with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "getFileEntryCount() until you close the archive. If you need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> have the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> date with only valid files within the archive, you could close and then " "open the archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see getFileEntryCount()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see closeArchive()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see openArchive()" )
DefineEngineMethod(ZipObject , extractFile , bool , (const char *pathInZip, const char *filename) , "@brief Extact <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> from the zip archive and save it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">location.\n\n</a>" "@param pathInZip The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be extracted within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param filename The path and name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> give the extracted <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully extracted." )
DefineEngineMethod(ZipObject , getFileEntry , String , (S32 index) , "@brief Get information on the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "This methods provides five different pieces of information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file:\n</a>" "<ul><li>filename - The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive</li>" "<li>uncompressed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a></li>" "<li>compressed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a></li>" "<li>compression method</li>" "<li>CRC32</li></ul>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "Use getFileEntryCount() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> obtain the total number of files within the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param index The index of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive. Use getFileEntryCount() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine the number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n</a>" "@return A tab delimited list of information on the requested file, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> could not be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">found.\n</a>" " @see getFileEntryCount()" )
DefineEngineMethod(ZipObject , getFileEntryCount , S32 , () , "@brief Get the number of files within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "Use getFileEntry() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> retrive information on each <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@return The number of files within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@note The returned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> will include any files that have been deleted from " "the archive using deleteFile(). To clear out all deleted files, you could " "close and then open the archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see getFileEntry()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see closeArchive()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see openArchive()" )
DefineEngineMethod(ZipObject , openArchive , bool , (const char *filename, const char *accessMode) , ("read") , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">manipulation.\n\n</a>" "Once <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive is opened use the various <a href="/coding/class/classzipobject/">ZipObject</a> methods <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " "working with the files within the archive. Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the archive when " "you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n\n</a>" "@param filename The path and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name of the zip archive <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">open.\n</a>" "@param accessMode One of read, write or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">readwrite\n</a>" " @return True is the archive was successfully <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">opened.\n</a>" " @note If you wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> make any changes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the archive, be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open it " "with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> write or readwrite access <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mode.\n</a>" " @see closeArchive()" )
DefineEngineMethod(ZipObject , openFileForRead , SimObject * , (const char *filename) , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading.\n\n</a>" "Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> when you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return A standard <a href="/coding/class/classstreamobject/">StreamObject</a> is returned <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@note You must first open the zip archive before working with files within <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@see closeFile()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openArchive()" )
DefineEngineMethod(ZipObject , openFileForWrite , SimObject * , (const char *filename) , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> writing <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to.\n\n</a>" "Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> when you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return A standard <a href="/coding/class/classstreamobject/">StreamObject</a> is returned <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@note You must first open the zip archive before working with files within <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@see closeFile()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openArchive()" )

Detailed Description

Public Variables

const struct @72 gModeMap []
Zip::ZipArchive::AccessMode mode 
const char * strMode 

Public Functions

ConsoleDocClass(ZipObject , "@brief Provides access <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "A <a href="/coding/class/classzipobject/">ZipObject</a> add, delete and extract files that are within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive. You may also " "read and write directly <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the files within the archive by obtaining <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classstreamobject/">StreamObject</a> " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the file." " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive)

DefineEngineMethod(ZipObject , addFile , bool , (const char *filename, const char *pathInZip, bool replace) , (true) , "@brief Add <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive\n\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> add <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param pathInZip The path and name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be given <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param replace If <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> already exists within the zip archive at the same location as this " "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> file, this parameter indicates <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it should be replaced. By default, it will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">replaced.\n</a>" " @return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the zip archive." )

DefineEngineMethod(ZipObject , closeArchive , void , () , "@brief Close an already opened zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@see openArchive()" )

DefineEngineMethod(ZipObject , closeFile , void , (SimObject *stream) , "@brief Close <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@param stream The <a href="/coding/class/classstreamobject/">StreamObject</a> of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously opened <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@see openFileForRead()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openFileForWrite()" )

DefineEngineMethod(ZipObject , deleteFile , bool , (const char *pathInZip) , "@brief Deleted the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> from the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive\n\n</a>" "@param pathInZip The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be deleted from the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return True of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deleted.\n</a>" "@note Files that have been deleted from the archive will still show up with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "getFileEntryCount() until you close the archive. If you need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> have the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> date with only valid files within the archive, you could close and then " "open the archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see getFileEntryCount()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see closeArchive()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see openArchive()" )

DefineEngineMethod(ZipObject , extractFile , bool , (const char *pathInZip, const char *filename) , "@brief Extact <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> from the zip archive and save it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">location.\n\n</a>" "@param pathInZip The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be extracted within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param filename The path and name <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> give the extracted <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> was successfully extracted." )

DefineEngineMethod(ZipObject , getFileEntry , String , (S32 index) , "@brief Get information on the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "This methods provides five different pieces of information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the requested <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file:\n</a>" "<ul><li>filename - The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive</li>" "<li>uncompressed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a></li>" "<li>compressed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1ab7d671599a7b25ca99a487fa341bc33a">size</a></li>" "<li>compression method</li>" "<li>CRC32</li></ul>\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "Use getFileEntryCount() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> obtain the total number of files within the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@param index The index of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive. Use getFileEntryCount() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine the number of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n</a>" "@return A tab delimited list of information on the requested file, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> could not be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">found.\n</a>" " @see getFileEntryCount()" )

DefineEngineMethod(ZipObject , getFileEntryCount , S32 , () , "@brief Get the number of files within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "Use getFileEntry() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> retrive information on each <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n\n</a>" "@return The number of files within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@note The returned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> will include any files that have been deleted from " "the archive using deleteFile(). To clear out all deleted files, you could " "close and then open the archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again.\n</a>" " @see getFileEntry()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see closeArchive()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @see openArchive()" )

DefineEngineMethod(ZipObject , openArchive , bool , (const char *filename, const char *accessMode) , ("read") , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">manipulation.\n\n</a>" "Once <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> zip archive is opened use the various <a href="/coding/class/classzipobject/">ZipObject</a> methods <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> " "working with the files within the archive. Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the archive when " "you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n\n</a>" "@param filename The path and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name of the zip archive <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">open.\n</a>" "@param accessMode One of read, write or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">readwrite\n</a>" " @return True is the archive was successfully <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">opened.\n</a>" " @note If you wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> make any changes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the archive, be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open it " "with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> write or readwrite access <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mode.\n</a>" " @see closeArchive()" )

DefineEngineMethod(ZipObject , openFileForRead , SimObject * , (const char *filename) , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reading.\n\n</a>" "Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> when you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return A standard <a href="/coding/class/classstreamobject/">StreamObject</a> is returned <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@note You must first open the zip archive before working with files within <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@see closeFile()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openArchive()" )

DefineEngineMethod(ZipObject , openFileForWrite , SimObject * , (const char *filename) , "@brief Open <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> within the zip archive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> writing <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to.\n\n</a>" "Be sure <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> close the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> when you are done with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@param filename The path and name of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> open within the zip <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">archive.\n</a>" "@return A standard <a href="/coding/class/classstreamobject/">StreamObject</a> is returned <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> working with the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@note You must first open the zip archive before working with files within <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "@see closeFile()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@see openArchive()" )

IMPLEMENT_CONOBJECT(ZipObject )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "core/util/zip/zipObject.h"
 25#include "core/util/safeDelete.h"
 26#include "console/engineAPI.h"
 27
 28//-----------------------------------------------------------------------------
 29// Constructor/Destructor
 30//-----------------------------------------------------------------------------
 31
 32ZipObject::ZipObject()
 33{
 34   mZipArchive = NULL;
 35}
 36
 37ZipObject::~ZipObject()
 38{
 39   closeArchive();
 40}
 41
 42IMPLEMENT_CONOBJECT(ZipObject);
 43
 44ConsoleDocClass( ZipObject,
 45   "@brief Provides access to a zip file.\n\n"
 46
 47   "A ZipObject add, delete and extract files that are within a zip archive.  You may also "
 48   "read and write directly to the files within the archive by obtaining a StreamObject "
 49   "for the file."
 50
 51   "@tsexample\n"
 52   "// Open a zip archive, creating it if it doesn't exist\n"
 53   "%archive = new ZipObject();\n"
 54   "%archive.openArchive(\"testArchive.zip\", Write);\n\n"
 55   "// Add a file to the archive with the given name\n"
 56   "%archive.addFile(\"./water.png\", \"water.png\");\n\n"
 57   "// Close the archive to save the changes\n"
 58   "%archive.closeArchive();\n"
 59   "@endtsexample\n\n"
 60
 61   "@note Behind the scenes all of the work is being done with the ZipArchive and StreamObject classes.\n"
 62
 63   "@see StreamObject when using methods such as openFileForRead() and openFileForWrite()\n\n"
 64
 65   "@ingroup FileSystem\n"
 66);
 67
 68
 69//-----------------------------------------------------------------------------
 70// Protected Methods
 71//-----------------------------------------------------------------------------
 72
 73StreamObject *ZipObject::createStreamObject(Stream *stream)
 74{
 75   for(S32 i = 0;i < mStreamPool.size();++i)
 76   {
 77      StreamObject *so = mStreamPool[i];
 78
 79      if(so == NULL)
 80      {
 81         // Reuse any free locations in the pool
 82         so = new StreamObject(stream);
 83         so->registerObject();
 84         mStreamPool[i] = so;
 85         return so;
 86      }
 87      
 88      if(so->getStream() == NULL)
 89      {
 90         // Existing unused stream, update it and return it
 91         so->setStream(stream);
 92         return so;
 93      }
 94   }
 95
 96   // No free object found, create a new one
 97   StreamObject *so = new StreamObject(stream);
 98   so->registerObject();
 99   mStreamPool.push_back(so);
100
101   return so;
102}
103
104//-----------------------------------------------------------------------------
105// Public Methods
106//-----------------------------------------------------------------------------
107
108bool ZipObject::openArchive(const char *filename, Zip::ZipArchive::AccessMode mode /* = Read */)
109{
110   closeArchive();
111
112   mZipArchive = new Zip::ZipArchive;
113   if(mZipArchive->openArchive(filename, mode))
114      return true;
115
116   SAFE_DELETE(mZipArchive);
117   return false;
118}
119
120void ZipObject::closeArchive()
121{
122   if(mZipArchive == NULL)
123      return;
124
125   for(S32 i = 0;i < mStreamPool.size();++i)
126   {
127      StreamObject *so = mStreamPool[i];
128      if(so && so->getStream() != NULL)
129         closeFile(so);
130      
131      SAFE_DELETE_OBJECT(mStreamPool[i]);
132   }
133   mStreamPool.clear();
134
135   mZipArchive->closeArchive();
136   SAFE_DELETE(mZipArchive);
137}
138
139//-----------------------------------------------------------------------------
140
141StreamObject * ZipObject::openFileForRead(const char *filename)
142{
143   if(mZipArchive == NULL)
144      return NULL;
145
146   Stream * stream = mZipArchive->openFile(filename, Zip::ZipArchive::Read);
147   if(stream != NULL)
148      return createStreamObject(stream);
149
150   return NULL;
151}
152
153StreamObject * ZipObject::openFileForWrite(const char *filename)
154{
155   if(mZipArchive == NULL)
156      return NULL;
157
158   Stream * stream = mZipArchive->openFile(filename, Zip::ZipArchive::Write);
159   if(stream != NULL)
160      return createStreamObject(stream);
161
162   return NULL;
163}
164
165void ZipObject::closeFile(StreamObject *stream)
166{
167   if(mZipArchive == NULL)
168      return;
169
170#ifdef TORQUE_DEBUG
171   bool found = false;
172   for(S32 i = 0;i < mStreamPool.size();++i)
173   {
174      StreamObject *so = mStreamPool[i];
175      if(so && so == stream)
176      {
177         found = true;
178         break;
179      }
180   }
181
182   AssertFatal(found, "ZipObject::closeFile() - Attempting to close stream not opened by this ZipObject");
183#endif
184
185   mZipArchive->closeFile(stream->getStream());
186   stream->setStream(NULL);
187}
188
189//-----------------------------------------------------------------------------
190
191bool ZipObject::addFile(const char *filename, const char *pathInZip, bool replace /* = true */)
192{
193   return mZipArchive->addFile(filename, pathInZip, replace);
194}
195
196bool ZipObject::extractFile(const char *pathInZip, const char *filename)
197{
198   return mZipArchive->extractFile(pathInZip, filename);
199}
200
201bool ZipObject::deleteFile(const char *filename)
202{
203   return mZipArchive->deleteFile(filename);
204}
205
206//-----------------------------------------------------------------------------
207
208S32 ZipObject::getFileEntryCount()
209{
210   return mZipArchive ? mZipArchive->numEntries() : 0;
211}
212
213String ZipObject::getFileEntry(S32 idx)
214{
215   if(mZipArchive == NULL)
216      return "";
217
218   const Zip::CentralDir &dir = (*mZipArchive)[idx];
219   char buffer[1024];
220   S32 chars = dSprintf(buffer, sizeof(buffer), "%s\t%d\t%d\t%d\t%08x",
221            dir.mFilename.c_str(), dir.mUncompressedSize, dir.mCompressedSize,
222            dir.mCompressMethod, dir.mCRC32);
223   if (chars < sizeof(buffer))
224      buffer[chars] = 0;
225
226   return String(buffer);
227}
228
229//-----------------------------------------------------------------------------
230// Console Methods
231//-----------------------------------------------------------------------------
232
233static const struct
234{
235   const char *strMode;
236   Zip::ZipArchive::AccessMode mode;
237} gModeMap[]=
238{
239   { "read", Zip::ZipArchive::Read },
240   { "write", Zip::ZipArchive::Write },
241   { "readwrite", Zip::ZipArchive::ReadWrite },
242   { NULL, (Zip::ZipArchive::AccessMode)0 }
243};
244
245//-----------------------------------------------------------------------------
246
247DefineEngineMethod(ZipObject, openArchive, bool, ( const char* filename, const char* accessMode ), ( "read" ),
248   "@brief Open a zip archive for manipulation.\n\n"
249
250   "Once a zip archive is opened use the various ZipObject methods for "
251   "working with the files within the archive.  Be sure to close the archive when "
252   "you are done with it.\n\n"
253
254   "@param filename The path and file name of the zip archive to open.\n"
255   "@param accessMode One of read, write or readwrite\n"
256
257   "@return True is the archive was successfully opened.\n"
258   
259   "@note If you wish to make any changes to the archive, be sure to open it "
260   "with a write or readwrite access mode.\n"
261
262   "@see closeArchive()")
263{
264   Zip::ZipArchive::AccessMode mode = Zip::ZipArchive::Read;
265
266   for(S32 i = 0;gModeMap[i].strMode;++i)
267   {
268      if(dStricmp(gModeMap[i].strMode, accessMode) == 0)
269      {
270         mode = gModeMap[i].mode;
271         break;
272      }
273   }
274
275   char buf[512];
276   Con::expandScriptFilename(buf, sizeof(buf), filename);
277
278   return object->openArchive(buf, mode);
279}
280
281DefineEngineMethod(ZipObject, closeArchive, void, (),,
282   "@brief Close an already opened zip archive.\n\n"
283   "@see openArchive()")
284{
285   object->closeArchive();
286}
287
288//-----------------------------------------------------------------------------
289
290DefineEngineMethod(ZipObject, openFileForRead, SimObject*, ( const char* filename ),,
291   "@brief Open a file within the zip archive for reading.\n\n"
292
293   "Be sure to close the file when you are done with it.\n"
294
295   "@param filename The path and name of the file to open within the zip archive.\n"
296
297   "@return A standard StreamObject is returned for working with the file.\n"
298   "@note You must first open the zip archive before working with files within it.\n"
299
300   "@see closeFile()\n"
301   "@see openArchive()")
302{
303   StreamObject *stream = object->openFileForRead(filename);
304   return stream;
305}
306
307DefineEngineMethod(ZipObject, openFileForWrite, SimObject*, ( const char* filename ),,
308   "@brief Open a file within the zip archive for writing to.\n\n"
309   
310   "Be sure to close the file when you are done with it.\n"
311
312   "@param filename The path and name of the file to open within the zip archive.\n"
313
314   "@return A standard StreamObject is returned for working with the file.\n"
315   "@note You must first open the zip archive before working with files within it.\n"
316
317   "@see closeFile()\n"
318   "@see openArchive()")
319{
320   StreamObject *stream = object->openFileForWrite(filename);
321   return stream;
322}
323
324DefineEngineMethod(ZipObject, closeFile, void, ( SimObject* stream ),,
325   "@brief Close a previously opened file within the zip archive.\n\n"
326   "@param stream The StreamObject of a previously opened file within the zip archive.\n"
327   "@see openFileForRead()\n"
328   "@see openFileForWrite()")
329{
330   StreamObject *so = dynamic_cast<StreamObject *>(stream);
331   if(so == NULL)
332   {
333      Con::errorf("ZipObject::closeFile - Invalid stream specified");
334      return;
335   }
336
337   object->closeFile(so);
338}
339
340//-----------------------------------------------------------------------------
341
342DefineEngineMethod(ZipObject, addFile, bool, ( const char* filename, const char* pathInZip, bool replace ), ( true ),
343   "@brief Add a file to the zip archive\n\n"
344   
345   "@param filename The path and name of the file to add to the zip archive.\n"
346   "@param pathInZip The path and name to be given to the file within the zip archive.\n"
347   "@param replace If a file already exists within the zip archive at the same location as this "
348   "new file, this parameter indicates if it should be replaced.  By default, it will be replaced.\n"
349   "@return True if the file was successfully added to the zip archive.")
350{
351   // Left this line commented out as it was useful when i had a problem
352   //  with the zip's i was creating. [2/21/2007 justind]
353   // [tom, 2/21/2007] To is now a warnf() for better visual separation in the console
354  // Con::errorf("zipAdd: %s", argv[2]);
355   //Con::warnf("    To: %s", argv[3]);
356
357   return object->addFile(filename, pathInZip, replace);
358}
359
360DefineEngineMethod(ZipObject, extractFile, bool, ( const char* pathInZip, const char* filename ),,
361   "@brief Extact a file from the zip archive and save it to the requested location.\n\n"
362   "@param pathInZip The path and name of the file to be extracted within the zip archive.\n"
363   "@param filename The path and name to give the extracted file.\n\n"
364   "@return True if the file was successfully extracted.")
365{
366   return object->extractFile(pathInZip, filename);
367}
368
369DefineEngineMethod(ZipObject, deleteFile, bool, ( const char* pathInZip ),,
370   "@brief Deleted the given file from the zip archive\n\n"
371   "@param pathInZip The path and name of the file to be deleted from the zip archive.\n"
372   "@return True of the file was successfully deleted.\n"
373
374   "@note Files that have been deleted from the archive will still show up with a "
375   "getFileEntryCount() until you close the archive.  If you need to have the file "
376   "count up to date with only valid files within the archive, you could close and then "
377   "open the archive again.\n"
378
379   "@see getFileEntryCount()\n"
380   "@see closeArchive()\n"
381   "@see openArchive()")
382{
383   return object->deleteFile(pathInZip);
384}
385
386//-----------------------------------------------------------------------------
387
388DefineEngineMethod(ZipObject, getFileEntryCount, S32, (),,
389   "@brief Get the number of files within the zip archive.\n\n"
390
391   "Use getFileEntry() to retrive information on each file within the archive.\n\n"
392
393   "@return The number of files within the zip archive.\n"
394
395   "@note The returned count will include any files that have been deleted from "
396   "the archive using deleteFile().  To clear out all deleted files, you could "
397   "close and then open the archive again.\n"
398
399   "@see getFileEntry()\n"
400   "@see closeArchive()\n"
401   "@see openArchive()")
402{
403   return object->getFileEntryCount();
404}
405
406DefineEngineMethod(ZipObject, getFileEntry, String, ( S32 index ),,
407   "@brief Get information on the requested file within the zip archive.\n\n"
408
409   "This methods provides five different pieces of information for the requested file:\n"
410   "<ul><li>filename - The path and name of the file within the zip archive</li>"
411   "<li>uncompressed size</li>"
412   "<li>compressed size</li>"
413   "<li>compression method</li>"
414   "<li>CRC32</li></ul>\n"
415
416   "Use getFileEntryCount() to obtain the total number of files within the archive.\n"
417
418   "@param index The index of the file within the zip archive.  Use getFileEntryCount() to determine the number of files.\n"
419   "@return A tab delimited list of information on the requested file, or an empty string if the file could not be found.\n"
420
421   "@see getFileEntryCount()")
422{
423   return object->getFileEntry(index);
424}
425