<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csutil/archive.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csutil/archive.h</h1><a href="archive_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> ZIP archive support for Crystal Space 3D library</span> <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru></span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00016"></a>00016 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00017"></a>00017 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00018"></a>00018 <span class="comment">*/</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#ifndef __CS_ARCHIVE_H__</span> <a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define __CS_ARCHIVE_H__</span> <a name="l00022"></a>00022 <span class="preprocessor"></span> <a name="l00027"></a>00027 <span class="preprocessor">#include "csextern.h"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="csstring_8h.html" title="String utility class.">csutil/csstring.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="parray_8h.html" title="Pointer Array.">csutil/parray.h</a>"</span> <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="csutil_2stringarray_8h.html" title="Array of strings.">csutil/stringarray.h</a>"</span> <a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="zip_8h.html" title="ZIP file format.">csutil/zip.h</a>"</span> <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="keyword">struct </span><a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a>; <a name="l00035"></a>00035 <a name="l00055"></a><a class="code" href="classcsArchive.html">00055</a> <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT <a class="code" href="classcsArchive.html" title="This class can be used to work with standard ZIP archives.">csArchive</a> <a name="l00056"></a>00056 { <a name="l00057"></a>00057 <span class="keyword">public</span>: <a name="l00058"></a><a class="code" href="classcsArchive.html#38dfd25c924ef1be36f131099021f661">00058</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> hdr_central[4]; <a name="l00059"></a><a class="code" href="classcsArchive.html#86d4a8bdb0835c08c77acc923cbe1627">00059</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> hdr_local[4]; <a name="l00060"></a><a class="code" href="classcsArchive.html#c19e9e5a0cfe053e7060787d33474e93">00060</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> hdr_endcentral[4]; <a name="l00061"></a><a class="code" href="classcsArchive.html#2e2975455aefb812999424f75c333e05">00061</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> hdr_extlocal[4]; <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keyword">private</span>: <a name="l00065"></a>00065 <span class="keyword">class </span>ArchiveEntry <a name="l00066"></a>00066 { <a name="l00067"></a>00067 <span class="keyword">public</span>: <a name="l00068"></a>00068 <span class="keywordtype">char</span> *filename; <a name="l00069"></a>00069 <a class="code" href="structZIP__central__directory__file__header.html">ZIP_central_directory_file_header</a> info; <a name="l00070"></a>00070 <span class="keywordtype">char</span> *buffer; <a name="l00071"></a>00071 <span class="keywordtype">size_t</span> buffer_pos; <a name="l00072"></a>00072 <span class="keywordtype">size_t</span> buffer_size; <a name="l00073"></a>00073 <span class="keywordtype">char</span> *extrafield, *comment; <a name="l00074"></a>00074 <span class="keywordtype">bool</span> faked; <a name="l00075"></a>00075 <a name="l00076"></a>00076 ArchiveEntry (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="structZIP__central__directory__file__header.html">ZIP_central_directory_file_header</a> &cdfh); <a name="l00077"></a>00077 ~ArchiveEntry (); <a name="l00078"></a>00078 <span class="keywordtype">bool</span> Append (<span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> size); <a name="l00079"></a>00079 <span class="keywordtype">bool</span> WriteLFH (FILE *file); <a name="l00080"></a>00080 <span class="keywordtype">bool</span> WriteCDFH (FILE *file); <a name="l00081"></a>00081 <span class="keywordtype">bool</span> ReadExtraField (FILE *file, <span class="keywordtype">size_t</span> extra_field_length); <a name="l00082"></a>00082 <span class="keywordtype">bool</span> ReadFileComment (FILE *file, <span class="keywordtype">size_t</span> file_comment_length); <a name="l00083"></a>00083 <span class="keywordtype">bool</span> WriteFile (FILE *file); <a name="l00084"></a>00084 <span class="keywordtype">void</span> FreeBuffer (); <a name="l00085"></a>00085 }; <a name="l00086"></a><a class="code" href="classcsArchive.html#2c805543fb866c6d58bbbcf19c1c94c8">00086</a> <span class="keyword">friend</span> <span class="keyword">class </span>ArchiveEntry; <a name="l00087"></a>00087 <a name="l00089"></a>00089 <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT ArchiveEntryVector <a name="l00090"></a>00090 : <span class="keyword">public</span> <a class="code" href="classcsPDelArray.html" title="An array of pointers.">csPDelArray</a><ArchiveEntry> <a name="l00091"></a>00091 { <a name="l00092"></a>00092 <span class="keyword">public</span>: <a name="l00093"></a>00093 ArchiveEntryVector () : <a class="code" href="classcsPDelArray.html" title="An array of pointers.">csPDelArray</a><ArchiveEntry> (256, 256) {} <a name="l00094"></a>00094 <span class="keyword">static</span> <span class="keywordtype">int</span> Compare (ArchiveEntry* <span class="keyword">const</span>& Item1, ArchiveEntry* <span class="keyword">const</span>& Item2) <a name="l00095"></a>00095 { <span class="keywordflow">return</span> strcmp (Item1->filename, Item2->filename); } <a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">int</span> CompareKey (ArchiveEntry* <span class="keyword">const</span>& Item, <span class="keywordtype">char</span> <span class="keyword">const</span>* <span class="keyword">const</span>& Key) <a name="l00097"></a>00097 { <span class="keywordflow">return</span> strcmp (Item->filename, Key); } <a name="l00098"></a>00098 }; <a name="l00099"></a>00099 <a name="l00100"></a>00100 ArchiveEntryVector dir; <span class="comment">// Archive directory: chain head (sorted)</span> <a name="l00101"></a>00101 <a class="code" href="classcsStringArray.html" title="An array of strings.">csStringArray</a> del; <span class="comment">// Files that should be deleted (sorted)</span> <a name="l00102"></a>00102 <a class="code" href="classcsArray.html" title="A templated array class.">csArray<ArchiveEntry*></a> lazy; <span class="comment">// Lazy operations (unsorted)</span> <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="keywordtype">char</span> *filename; <span class="comment">// Archive file name</span> <a name="l00105"></a>00105 FILE *file; <span class="comment">// Archive file pointer.</span> <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="keywordtype">size_t</span> comment_length; <span class="comment">// Archive comment length</span> <a name="l00108"></a>00108 <span class="keywordtype">char</span> *comment; <span class="comment">// Archive comment</span> <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="keywordtype">void</span> ReadDirectory (); <a name="l00111"></a>00111 <span class="keywordtype">bool</span> IsDeleted (<span class="keyword">const</span> <span class="keywordtype">char</span> *name) <span class="keyword">const</span>; <a name="l00112"></a>00112 <span class="keywordtype">void</span> UnpackTime (<a class="code" href="zip_8h.html#f687042e0e2c8c946cbf60f9e4242b50">ush</a> zdate, <a class="code" href="zip_8h.html#f687042e0e2c8c946cbf60f9e4242b50">ush</a> ztime, <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &rtime) <span class="keyword">const</span>; <a name="l00113"></a>00113 <span class="keywordtype">void</span> PackTime (<span class="keyword">const</span> <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &ztime, <a class="code" href="zip_8h.html#f687042e0e2c8c946cbf60f9e4242b50">ush</a> &rdate, <a class="code" href="zip_8h.html#f687042e0e2c8c946cbf60f9e4242b50">ush</a> &rtime) <span class="keyword">const</span>; <a name="l00114"></a>00114 <span class="keywordtype">bool</span> ReadArchiveComment (FILE *file, <span class="keywordtype">size_t</span> zipfile_comment_length); <a name="l00115"></a>00115 <span class="keywordtype">void</span> LoadECDR (<a class="code" href="structZIP__end__central__dir__record.html">ZIP_end_central_dir_record</a> &ecdr, <span class="keywordtype">char</span> *buff); <a name="l00116"></a>00116 <span class="keywordtype">bool</span> ReadCDFH (<a class="code" href="structZIP__central__directory__file__header.html">ZIP_central_directory_file_header</a> &cdfh, FILE *file); <a name="l00117"></a>00117 <span class="keywordtype">bool</span> ReadLFH (<a class="code" href="structZIP__local__file__header.html">ZIP_local_file_header</a> &lfh, FILE *file); <a name="l00118"></a>00118 <span class="keywordtype">bool</span> WriteECDR (<a class="code" href="structZIP__end__central__dir__record.html">ZIP_end_central_dir_record</a> &ecdr, FILE *file); <a name="l00119"></a>00119 <span class="keywordtype">bool</span> WriteZipArchive (); <a name="l00120"></a>00120 <span class="keywordtype">bool</span> WriteCentralDirectory (FILE *temp); <a name="l00121"></a>00121 <span class="keywordtype">void</span> UpdateDirectory (); <a name="l00122"></a>00122 <span class="keywordtype">void</span> ReadZipDirectory (FILE *infile); <a name="l00123"></a>00123 ArchiveEntry *InsertEntry (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a name="l00124"></a>00124 <a class="code" href="structZIP__central__directory__file__header.html">ZIP_central_directory_file_header</a> &cdfh); <a name="l00125"></a>00125 <span class="keywordtype">void</span> ReadZipEntries (FILE *infile); <a name="l00126"></a>00126 <span class="keywordtype">char</span> *ReadEntry (FILE *infile, ArchiveEntry *f); <a name="l00127"></a>00127 ArchiveEntry *CreateArchiveEntry (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a name="l00128"></a>00128 <span class="keywordtype">size_t</span> size = 0, <span class="keywordtype">bool</span> pack = <span class="keyword">true</span>); <a name="l00129"></a>00129 <span class="keywordtype">void</span> ResetArchiveEntry (ArchiveEntry *f, <span class="keywordtype">size_t</span> size, <span class="keywordtype">bool</span> pack); <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="keyword">public</span>: <a name="l00133"></a>00133 <a class="code" href="classcsArchive.html" title="This class can be used to work with standard ZIP archives.">csArchive</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *filename); <a name="l00135"></a>00135 ~<a class="code" href="classcsArchive.html" title="This class can be used to work with standard ZIP archives.">csArchive</a> (); <a name="l00136"></a>00136 <a name="l00138"></a>00138 <span class="keywordtype">void</span> Dir () <span class="keyword">const</span>; <a name="l00139"></a>00139 <a name="l00154"></a>00154 <span class="keywordtype">void</span> *NewFile (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">size_t</span> size = 0, <span class="keywordtype">bool</span> pack = <span class="keyword">true</span>); <a name="l00155"></a>00155 <a name="l00160"></a>00160 <span class="keywordtype">bool</span> DeleteFile (<span class="keyword">const</span> <span class="keywordtype">char</span> *name); <a name="l00161"></a>00161 <a name="l00166"></a>00166 <span class="keywordtype">bool</span> FileExists (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">size_t</span> *size = 0) <span class="keyword">const</span>; <a name="l00167"></a>00167 <a name="l00174"></a>00174 <span class="keywordtype">char</span> *Read (<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">size_t</span> *size = 0); <a name="l00175"></a>00175 <a name="l00182"></a>00182 <span class="keywordtype">bool</span> Write (<span class="keywordtype">void</span> *entry, <span class="keyword">const</span> <span class="keywordtype">char</span> *data, <span class="keywordtype">size_t</span> size); <a name="l00183"></a>00183 <a name="l00193"></a>00193 <span class="keywordtype">bool</span> Flush (); <a name="l00194"></a>00194 <a name="l00196"></a><a class="code" href="classcsArchive.html#dc740f22d9b922f4760018c4faed2519">00196</a> <span class="keywordtype">void</span> *GetFile (<span class="keywordtype">size_t</span> no) <a name="l00197"></a>00197 { <span class="keywordflow">return</span> (no < dir.GetSize ()) ? dir.Get (no) : 0; } <a name="l00198"></a>00198 <a name="l00200"></a>00200 <span class="keywordtype">void</span> *FindName (<span class="keyword">const</span> <span class="keywordtype">char</span> *name) <span class="keyword">const</span>; <a name="l00202"></a><a class="code" href="classcsArchive.html#c1c2868cc5058eb7ee5ea312b351623f">00202</a> <span class="keywordtype">char</span> *GetFileName (<span class="keywordtype">void</span> *entry)<span class="keyword"> const</span> <a name="l00203"></a>00203 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ((ArchiveEntry*)entry)->filename; } <a name="l00205"></a><a class="code" href="classcsArchive.html#a512dbd02901d6a9519b0a89564efa27">00205</a> <span class="keywordtype">size_t</span> GetFileSize (<span class="keywordtype">void</span> *entry)<span class="keyword"> const</span> <a name="l00206"></a>00206 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ((ArchiveEntry*)entry)->info.ucsize; } <a name="l00208"></a>00208 <span class="keywordtype">void</span> GetFileTime (<span class="keywordtype">void</span> *entry, <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &ztime) <span class="keyword">const</span>; <a name="l00210"></a>00210 <span class="keywordtype">void</span> SetFileTime (<span class="keywordtype">void</span> *entry, <span class="keyword">const</span> <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &ztime); <a name="l00211"></a>00211 <a name="l00213"></a><a class="code" href="classcsArchive.html#b56f2659ca38157b72977609968a2f23">00213</a> <span class="keywordtype">char</span> *GetName ()<span class="keyword"> const</span> <a name="l00214"></a>00214 <span class="keyword"> </span>{ <span class="keywordflow">return</span> filename; } <a name="l00216"></a><a class="code" href="classcsArchive.html#fd613fe7bb6cbd030ac75b2e2a8abc46">00216</a> <span class="keywordtype">char</span> *GetComment ()<span class="keyword"> const</span> <a name="l00217"></a>00217 <span class="keyword"> </span>{ <span class="keywordflow">return</span> comment; } <a name="l00218"></a>00218 }; <a name="l00219"></a>00219 <a name="l00220"></a><a class="code" href="classcsArchive.html#c61619ebe3f3c053b026dabbee37a727">00220</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcsArchive.html#c61619ebe3f3c053b026dabbee37a727" title="Query filetime from handle.">csArchive::GetFileTime</a> (<span class="keywordtype">void</span> *entry, <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &ztime)<span class="keyword"> const</span> <a name="l00221"></a>00221 <span class="keyword"></span>{ <a name="l00222"></a>00222 <span class="keywordflow">if</span> (entry) <a name="l00223"></a>00223 { <a name="l00224"></a>00224 UnpackTime (((<a class="code" href="classcsArchive.html#2c805543fb866c6d58bbbcf19c1c94c8">ArchiveEntry</a>*)entry)->info.last_mod_file_date, <a name="l00225"></a>00225 ((<a class="code" href="classcsArchive.html#2c805543fb866c6d58bbbcf19c1c94c8">ArchiveEntry</a>*)entry)->info.last_mod_file_time, <a name="l00226"></a>00226 ztime); <a name="l00227"></a>00227 } <a name="l00228"></a>00228 } <a name="l00229"></a>00229 <a name="l00230"></a><a class="code" href="classcsArchive.html#d05c5482c45327c84d232fedcb378699">00230</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcsArchive.html#d05c5482c45327c84d232fedcb378699" title="Set filetime for handle.">csArchive::SetFileTime</a> (<span class="keywordtype">void</span> *entry, <span class="keyword">const</span> <a class="code" href="structcsFileTime.html" title="File time structure - used to query and set the last-modification time of a file...">csFileTime</a> &ztime) <a name="l00231"></a>00231 { <a name="l00232"></a>00232 <span class="keywordflow">if</span> (entry) <a name="l00233"></a>00233 { <a name="l00234"></a>00234 PackTime (ztime, <a name="l00235"></a>00235 ((<a class="code" href="classcsArchive.html#2c805543fb866c6d58bbbcf19c1c94c8">ArchiveEntry</a>*)entry)->info.last_mod_file_date, <a name="l00236"></a>00236 ((<a class="code" href="classcsArchive.html#2c805543fb866c6d58bbbcf19c1c94c8">ArchiveEntry</a>*)entry)->info.last_mod_file_time); <a name="l00237"></a>00237 } <a name="l00238"></a>00238 } <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="preprocessor">#endif // __CS_ARCHIVE_H__</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>