| 1 | /* |
|---|
| 2 | * Copyright (c) 2004 Kazunori "jagarl" Ueno |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * Redistribution and use in source and binary forms, with or without |
|---|
| 6 | * modification, are permitted provided that the following conditions |
|---|
| 7 | * are met: |
|---|
| 8 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | * notice, this list of conditions and the following disclaimer. |
|---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | * documentation and/or other materials provided with the distribution. |
|---|
| 13 | * 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | * derived from this software without specific prior written permission. |
|---|
| 15 | * |
|---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | #ifndef __FILE_IMPL_H__ |
|---|
| 31 | #define __FILE_IMPL_H__ |
|---|
| 32 | |
|---|
| 33 | #include <vector> |
|---|
| 34 | |
|---|
| 35 | struct ARCFILE_ATOM { |
|---|
| 36 | char* filename; |
|---|
| 37 | char* filename_lower; |
|---|
| 38 | off_t offset; |
|---|
| 39 | int arcsize; |
|---|
| 40 | int filesize; |
|---|
| 41 | int private_data; |
|---|
| 42 | bool operator <(const ARCFILE_ATOM& to) const { |
|---|
| 43 | return strcmp(filename_lower, to.filename_lower) < 0; |
|---|
| 44 | } |
|---|
| 45 | bool operator <(char* const to) const { |
|---|
| 46 | return strcmp(filename_lower, to) < 0; |
|---|
| 47 | } |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | class ARCFILE { |
|---|
| 51 | protected: |
|---|
| 52 | char* arcname; |
|---|
| 53 | char* filenames_orig; |
|---|
| 54 | int list_point; |
|---|
| 55 | std::vector<ARCFILE_ATOM> arc_atom; |
|---|
| 56 | typedef std::vector<ARCFILE_ATOM>::iterator iterator; |
|---|
| 57 | ARCFILE* next; /* FILESEARCH ã®äžã€ã®åãè€æ°ã® ARCFILE ãæã€ãšãããªã¹ããã€ãã */ |
|---|
| 58 | /* arcname ã«æå®ããããã¡ã€ã«ïŒãã£ã¬ã¯ããªã®å
容ãã§ã㯠*/ |
|---|
| 59 | virtual int CheckFileDeal(void); |
|---|
| 60 | virtual void ListupFiles(int fname_len); |
|---|
| 61 | virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM&); |
|---|
| 62 | iterator SearchName(const char* f, const char* ext=0); |
|---|
| 63 | public: |
|---|
| 64 | ARCFILE(const char* fname); |
|---|
| 65 | void SetNext(ARCFILE* _next) { delete next; next = _next;} |
|---|
| 66 | ARCFILE* Next(void) { return next; } |
|---|
| 67 | void Init(void); |
|---|
| 68 | virtual ~ARCFILE(); |
|---|
| 69 | /* ãã¡ã€ã«æ€çŽ¢ */ |
|---|
| 70 | class ARCINFO* Find(const char* fname, const char* ext); |
|---|
| 71 | /* ãã¡ã€ã«ãªã¹ãã®åºå */ |
|---|
| 72 | int Deal(void) { Init(); return arc_atom.size(); } |
|---|
| 73 | void ListFiles(FILE* out); |
|---|
| 74 | void InitList(void); |
|---|
| 75 | char* ListItem(void); |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | class SCN2kFILE : public ARCFILE { |
|---|
| 79 | protected: |
|---|
| 80 | virtual int CheckFileDeal(void); |
|---|
| 81 | virtual void ListupFiles(int fname_len); |
|---|
| 82 | virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); |
|---|
| 83 | public: |
|---|
| 84 | SCN2kFILE(char* fname) : ARCFILE(fname) {} |
|---|
| 85 | virtual ~SCN2kFILE() {} |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | class CattleyaFILE : public ARCFILE { |
|---|
| 89 | private: |
|---|
| 90 | bool is_compress; |
|---|
| 91 | /* header ã® Huffman æšæ§ç¯çš */ |
|---|
| 92 | char* bitbuf; |
|---|
| 93 | char* bitbuf_end; |
|---|
| 94 | int ltree[0x400]; |
|---|
| 95 | int rtree[0x400]; |
|---|
| 96 | int treecnt; |
|---|
| 97 | int bitcnt; |
|---|
| 98 | int GetBit(void); |
|---|
| 99 | int GetCh(void); |
|---|
| 100 | void SetBuf(char* buf, int len); |
|---|
| 101 | int MakeTree(void); |
|---|
| 102 | int Decode(int seed); |
|---|
| 103 | |
|---|
| 104 | protected: |
|---|
| 105 | virtual int CheckFileDeal(void); |
|---|
| 106 | virtual void ListupFiles(int fname_len); |
|---|
| 107 | virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); |
|---|
| 108 | |
|---|
| 109 | public: |
|---|
| 110 | CattleyaFILE(char* fname) : ARCFILE(fname) {is_compress = false;} |
|---|
| 111 | virtual ~CattleyaFILE() {} |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | class NULFILE : public ARCFILE { |
|---|
| 115 | protected: |
|---|
| 116 | virtual int CheckFileDeal(void); |
|---|
| 117 | virtual void ListupFiles(int fname_len); |
|---|
| 118 | virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); |
|---|
| 119 | public: |
|---|
| 120 | NULFILE() : ARCFILE("") {} |
|---|
| 121 | virtual ~NULFILE() {} |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | class DIRFILE : public ARCFILE { |
|---|
| 125 | protected: |
|---|
| 126 | virtual int CheckFileDeal(void); |
|---|
| 127 | virtual void ListupFiles(int fname_len); |
|---|
| 128 | virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); |
|---|
| 129 | public: |
|---|
| 130 | DIRFILE(char* fname) : ARCFILE(fname) {} |
|---|
| 131 | virtual ~DIRFILE() {} |
|---|
| 132 | FILE* Open(const char* fname); /* FILE* ãéã */ |
|---|
| 133 | char* SearchFile(const char* dirname); /* ãã¡ã€ã«æ€çŽ¢ */ |
|---|
| 134 | }; |
|---|
| 135 | |
|---|
| 136 | class ARCINFO_AVG32 : public ARCINFO { |
|---|
| 137 | protected: |
|---|
| 138 | ARCINFO_AVG32(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { |
|---|
| 139 | } |
|---|
| 140 | virtual bool ExecExtract(void); |
|---|
| 141 | friend class ARCFILE; |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | class ARCINFO2k : public ARCINFO { |
|---|
| 145 | private: |
|---|
| 146 | static char decode_seed[256]; |
|---|
| 147 | static char decode_seed2[16]; |
|---|
| 148 | protected: |
|---|
| 149 | ARCINFO2k(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name,atom) { |
|---|
| 150 | } |
|---|
| 151 | virtual bool ExecExtract(void); |
|---|
| 152 | friend class SCN2kFILE; |
|---|
| 153 | }; |
|---|
| 154 | |
|---|
| 155 | class ARCINFOZ : public ARCINFO { |
|---|
| 156 | protected: |
|---|
| 157 | ARCINFOZ(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { |
|---|
| 158 | } |
|---|
| 159 | virtual bool ExecExtract(void); |
|---|
| 160 | friend class DaemonBaneFILE; |
|---|
| 161 | friend class CattleyaFILE; |
|---|
| 162 | }; |
|---|
| 163 | |
|---|
| 164 | #endif /* __FILE_IMPL_H__ */ |
|---|