Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pk3.h
Go to the documentation of this file.
1 /*
2  * Copyright 2002-2003 LibPK3, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in
12  * the documentation and/or other materials provided with the
13  * distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE LIBPK3 PROJECT
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE LIBPK3 PROJECT OR CONTRIBUTORS
20  * BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27  * DAMAGE.
28  *
29  * The views and conclusions contained in the software and
30  * documentation are those of the authors and should not be
31  * interpreted as representing official policies, either expressed or
32  * implied, of the LibPK3 Project or Viktor Liehr alias picard.
33  *
34  * $Id: pk3.h 12643 2010-02-25 14:26:53Z dan_w $
35  *
36  */
37 
38 #ifndef __PK3__H__
39 #define __PK3__H__
40 
41 #include <stdio.h>
42 #include <string.h>
43 #include <zlib.h>
44 
45 #define PK3LENGTH 512
46 
47 class CPK3
48 {
49 private:
50  struct TZipDirHeader;
51  struct TZipDirFileHeader;
52  struct TZipLocalHeader;
53 
54  FILE *f;
55  char pk3filename[PK3LENGTH];
56  char *m_pDirData; //Raw data buffer.
57  int m_nEntries; //Number of entries.
58 
59 //Pointers to the dir entries in pDirData.
60  const TZipDirFileHeader **m_papDir;
61  void GetFilename( int i, char *pszDest ) const;
62  int GetFileLen( int i ) const;
63  bool ReadFile( int i, void *pBuf );
64 
65 public: CPK3() : m_nEntries( 0 ) {}
66  CPK3( FILE *n_f );
67  CPK3( const char *filename );
68  ~CPK3() {}
69 
70  bool CheckPK3( FILE *f );
71  bool Open( const char *filename );
72  bool ExtractFile( const char *lp_name );
73  bool ExtractFile( const char *lp_name, const char *new_filename );
74  char * ExtractFile( int index, int *file_size );
75  char * ExtractFile( const char *lpname, int *file_size );
76  int FileExists( const char *lpname ); //Checks if a file exists and returns index or -1 if not found
77  bool Close( void );
78 
79  void PrintFileContent();
80 };
81 
82 #endif
83