| 1 | /* file.h : KANON ã®å§çž®ãã¡ã€ã«ã»PDT ãã¡ã€ã«ïŒç»åãã¡ã€ã«ïŒã®å±éã® |
|---|
| 2 | * ããã®ã¯ã©ã¹ |
|---|
| 3 | * class FileSearcher : ãã¡ã€ã«ã®ç®¡çãè¡ã |
|---|
| 4 | * class ARCINFO : æžåº«ãã¡ã€ã«ã®äžã®ïŒã€ã®ãã¡ã€ã«ãæ±ãã¯ã©ã¹ |
|---|
| 5 | * class PDTCONV : PDT ãã¡ã€ã«ã®å±éãè¡ãã |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | /* |
|---|
| 9 | * |
|---|
| 10 | * Copyright (C) 2000- Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp> |
|---|
| 11 | * |
|---|
| 12 | * This program is free software; you can redistribute it and/or modify |
|---|
| 13 | * it under the terms of the GNU General Public License as published by |
|---|
| 14 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 15 | * (at your option) any later version. |
|---|
| 16 | * |
|---|
| 17 | * This program is distributed in the hope that it will be useful, |
|---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 20 | * GNU General Public License for more details. |
|---|
| 21 | * |
|---|
| 22 | * You should have received a copy of the GNU General Public License along |
|---|
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #ifndef __KANON_FILE_H__ |
|---|
| 29 | #define __KANON_FILE_H__ |
|---|
| 30 | |
|---|
| 31 | #ifndef DIR_SPLIT |
|---|
| 32 | #define DIR_SPLIT '/' /* UNIX */ |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | // read 'KANON' compressed file |
|---|
| 36 | |
|---|
| 37 | #include <stdio.h> |
|---|
| 38 | #include <stdlib.h> |
|---|
| 39 | #include <string.h> |
|---|
| 40 | #include <sys/types.h> |
|---|
| 41 | |
|---|
| 42 | #ifdef HAVE_CONFIG_H |
|---|
| 43 | # include "config.h" |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | #if defined(__sparc) || defined(sparc) |
|---|
| 47 | # if !defined(WORDS_BIGENDIAN) |
|---|
| 48 | # define WORDS_BIGENDIAN 1 |
|---|
| 49 | # endif |
|---|
| 50 | #endif |
|---|
| 51 | |
|---|
| 52 | #define INT_SIZE 4 |
|---|
| 53 | |
|---|
| 54 | static int read_little_endian_int(const char* buf) { |
|---|
| 55 | const unsigned char *p = (const unsigned char *) buf; |
|---|
| 56 | return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | static int read_little_endian_short(const char* buf) { |
|---|
| 60 | const unsigned char *p = (const unsigned char *) buf; |
|---|
| 61 | return (p[1] << 8) | p[0]; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | static int write_little_endian_int(char* buf, int number) { |
|---|
| 65 | int c = read_little_endian_int(buf); |
|---|
| 66 | unsigned char *p = (unsigned char *) buf; |
|---|
| 67 | unsigned int unum = (unsigned int) number; |
|---|
| 68 | p[0] = unum & 255; |
|---|
| 69 | unum >>= 8; |
|---|
| 70 | p[1] = unum & 255; |
|---|
| 71 | unum >>= 8; |
|---|
| 72 | p[2] = unum & 255; |
|---|
| 73 | unum >>= 8; |
|---|
| 74 | p[3] = unum & 255; |
|---|
| 75 | return c; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | static int write_little_endian_short(char* buf, int number) { |
|---|
| 79 | int c = read_little_endian_short(buf); |
|---|
| 80 | unsigned char *p = (unsigned char *) buf; |
|---|
| 81 | unsigned int unum = (unsigned int) number; |
|---|
| 82 | p[0] = unum & 255; |
|---|
| 83 | unum >>= 8; |
|---|
| 84 | p[1] = unum & 255; |
|---|
| 85 | return c; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | /********************************************* |
|---|
| 90 | ** FileSearcher: |
|---|
| 91 | ** æžåº«ãã¡ã€ã«ïŒãã£ã¬ã¯ããªãå«ãã |
|---|
| 92 | ** å
šãã¡ã€ã«ã®ç®¡çãè¡ãã |
|---|
| 93 | ** |
|---|
| 94 | ** æåã«ãèšå®ãã¡ã€ã«ãããã¡ã€ã«ã®çš®é¡ããšã« |
|---|
| 95 | ** å®éã«å
¥ã£ãŠãããã£ã¬ã¯ããªãæžåº«ãèšå®ãã |
|---|
| 96 | ** |
|---|
| 97 | ** 以éã¯Find() ã¡ãœããã§å®éã®ãã¡ã€ã«ã®å
容ãåŸã |
|---|
| 98 | ** |
|---|
| 99 | */ |
|---|
| 100 | |
|---|
| 101 | /* ARCFILE ãš DIRFILE ã¯ãã¡ã€ã«çš®é¡ããšã®æ
å ± */ |
|---|
| 102 | class ARCFILE; |
|---|
| 103 | class DIRFILE; |
|---|
| 104 | class SCN2kFILE; |
|---|
| 105 | /* ARCINFO ã¯ãã¡ã€ã«ãèªã¿èŸŒãããã«å¿
èŠ */ |
|---|
| 106 | class ARCINFO; |
|---|
| 107 | class ARCFILE_ATOM; |
|---|
| 108 | |
|---|
| 109 | class KeyHolder { |
|---|
| 110 | public: |
|---|
| 111 | static KeyHolder* GetInstance(void); |
|---|
| 112 | static void Quit(void); |
|---|
| 113 | |
|---|
| 114 | void SetKey(char[16]); |
|---|
| 115 | void SetKey2(char[33]); |
|---|
| 116 | void GuessKey(char*); |
|---|
| 117 | |
|---|
| 118 | private: |
|---|
| 119 | KeyHolder(){} |
|---|
| 120 | ~KeyHolder(){} |
|---|
| 121 | |
|---|
| 122 | public: |
|---|
| 123 | const char* GetKey(void); |
|---|
| 124 | |
|---|
| 125 | private: |
|---|
| 126 | char key[16]; |
|---|
| 127 | static KeyHolder* _singleton; |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | class FileSearcher { |
|---|
| 131 | public: |
|---|
| 132 | #define TYPEMAX 14 |
|---|
| 133 | enum FILETYPE { |
|---|
| 134 | /* äžå¿ã0 - 15 ãŸã§ reserved */ |
|---|
| 135 | ALL = 1, /* dat/ 以äžã®ãã¡ã€ã«(ããã©ã«ãã®æ€çŽ¢å
) */ |
|---|
| 136 | ROOT= 2, /* ã²ãŒã ã®ã€ã³ã¹ããŒã«ãã£ã¬ã¯ã㪠*/ |
|---|
| 137 | PDT = 3, /* default: PDT/ */ |
|---|
| 138 | SCN = 4, /* default: DAT/SEEN.TXT */ |
|---|
| 139 | ANM = 5, /* default: DAT/ALLANM.ANL */ |
|---|
| 140 | ARD = 6, /* default: DAT/ALLARD.ARD */ |
|---|
| 141 | CUR = 7, /* default: DAT/ALLCUR.CUR */ |
|---|
| 142 | MID = 8, /* default: ALL */ |
|---|
| 143 | WAV = 9, /* default: ALL */ |
|---|
| 144 | KOE = 10, /* default: KOE/ */ |
|---|
| 145 | BGM = 11, /* default: BGM */ |
|---|
| 146 | MOV = 12, /* default : MOV */ |
|---|
| 147 | GAN = 13 /* default : MOV */ |
|---|
| 148 | }; |
|---|
| 149 | enum ARCTYPE {ATYPE_DIR, ATYPE_ARC, ATYPE_SCN2k}; |
|---|
| 150 | |
|---|
| 151 | public: |
|---|
| 152 | static FileSearcher* GetInstance(void); |
|---|
| 153 | static void Quit(void); |
|---|
| 154 | |
|---|
| 155 | /* åãã«ã²ãŒã ã®ããŒã¿ããããã£ã¬ã¯ããªãèšå®ããå¿
èŠããã */ |
|---|
| 156 | int InitRoot(char* root); |
|---|
| 157 | /* ãã¡ã€ã«ã®åããšã®æ
å ±ãã»ãããã */ |
|---|
| 158 | void SetFileInformation(FILETYPE type, ARCTYPE is_arc, |
|---|
| 159 | char* filename); |
|---|
| 160 | /* è€æ°ã®ãã¡ã€ã«ãäžã€ã®åã«é¢é£ã¥ãã */ |
|---|
| 161 | void AppendFileInformation(FILETYPE type, ARCTYPE is_arc, |
|---|
| 162 | char* filename); |
|---|
| 163 | ARCFILE* MakeARCFILE(ARCTYPE tp, const char* filename); |
|---|
| 164 | /* fname ã§æå®ãããååã®ãã¡ã€ã«ãæ€çŽ¢ */ |
|---|
| 165 | class ARCINFO* Find(FILETYPE type, const char* fname, const char* ext=0); |
|---|
| 166 | /* ããçš®é¡ã®ãã¡ã€ã«ããã¹ãŠãªã¹ãã¢ãã |
|---|
| 167 | ** æ«å°Ÿã¯ NULL pointer |
|---|
| 168 | */ |
|---|
| 169 | char** ListAll(FILETYPE type); |
|---|
| 170 | |
|---|
| 171 | private: |
|---|
| 172 | FileSearcher(void); |
|---|
| 173 | ~FileSearcher(); |
|---|
| 174 | |
|---|
| 175 | private: |
|---|
| 176 | /* InitRoot() ã®æç¹ã§åæåããã倿° */ |
|---|
| 177 | DIRFILE* root_dir; |
|---|
| 178 | DIRFILE* dat_dir; |
|---|
| 179 | ARCFILE* searcher[TYPEMAX]; |
|---|
| 180 | /* ãã¡ã€ã«ã®ååšäœçœ®ã® information */ |
|---|
| 181 | ARCTYPE is_archived[TYPEMAX]; |
|---|
| 182 | const char* filenames[TYPEMAX]; |
|---|
| 183 | /* ããã©ã«ãã® information */ |
|---|
| 184 | static ARCTYPE default_is_archived[TYPEMAX]; |
|---|
| 185 | static const char* default_dirnames[TYPEMAX]; |
|---|
| 186 | static FileSearcher *_singleton; |
|---|
| 187 | }; |
|---|
| 188 | |
|---|
| 189 | class ARCINFO { |
|---|
| 190 | protected: |
|---|
| 191 | /* ãã¡ã€ã«ãã®ãã®ã®æ
å ± */ |
|---|
| 192 | ARCFILE_ATOM& info; |
|---|
| 193 | char* arcfile; |
|---|
| 194 | /* mmap ããŠããå Žåããã®æ
å ± */ |
|---|
| 195 | bool use_mmap; |
|---|
| 196 | char* mmapped_memory; |
|---|
| 197 | int fd; |
|---|
| 198 | /* ãã¡ã€ã«å
容ã®å
¥ã£ãŠãããããã¡ */ |
|---|
| 199 | const char* data; |
|---|
| 200 | |
|---|
| 201 | protected: |
|---|
| 202 | ARCINFO(const char* arcfile, ARCFILE_ATOM& from); // only from ARCFILE |
|---|
| 203 | friend class ARCFILE; |
|---|
| 204 | friend class DIRFILE; |
|---|
| 205 | |
|---|
| 206 | virtual bool ExecExtract(void); |
|---|
| 207 | public: |
|---|
| 208 | /* dest ã¯256byte çšåºŠã®äœè£ãããããš */ |
|---|
| 209 | static void Extract(char*& dest, char*& src, char* destend, char* srcend); |
|---|
| 210 | static void Extract2k(char*& dest, char*& src, char* destend, char* srcend); |
|---|
| 211 | virtual ~ARCINFO(); |
|---|
| 212 | /* å¿
èŠãªã Read åã«åŒã¶ããšã§åŠçãåå²ã§ãã */ |
|---|
| 213 | int Size(void) const; |
|---|
| 214 | char* CopyRead(void); /* Read() ããŠå
容ã®ã³ããŒãè¿ã */ |
|---|
| 215 | const char* Read(void); |
|---|
| 216 | /* ãã¡ã€ã«ã regular file ã®å Žåããã¡ã€ã«åãåž°ã */ |
|---|
| 217 | /* ããã§ãªããªã 0 ãåž°ã */ |
|---|
| 218 | const char* Path(void) const; |
|---|
| 219 | FILE* OpenFile(int* length=0) const; /* äºææ§ã®ããïŒraw file ã®å Žåããã¡ã€ã«ãéã */ |
|---|
| 220 | }; |
|---|
| 221 | |
|---|
| 222 | class GRPCONV { |
|---|
| 223 | public: |
|---|
| 224 | int width; |
|---|
| 225 | int height; |
|---|
| 226 | bool is_mask; |
|---|
| 227 | |
|---|
| 228 | const char* filename; |
|---|
| 229 | const char* data; |
|---|
| 230 | int datalen; |
|---|
| 231 | |
|---|
| 232 | int Width(void) { return width;} |
|---|
| 233 | int Height(void) { return height;} |
|---|
| 234 | bool IsMask(void) { return is_mask;} |
|---|
| 235 | |
|---|
| 236 | GRPCONV(void); |
|---|
| 237 | virtual ~GRPCONV(); |
|---|
| 238 | void Init(const char* fname, const char* data, int dlen, int width, int height, bool is_mask); |
|---|
| 239 | |
|---|
| 240 | virtual bool Read(char* image) = 0; |
|---|
| 241 | static GRPCONV* AssignConverter(const char* inbuf, int inlen, const char* fname); |
|---|
| 242 | static GRPCONV* AssignConverter(ARCINFO* info) { |
|---|
| 243 | const char* dat = info->Read(); |
|---|
| 244 | if (dat == 0) return 0; |
|---|
| 245 | return AssignConverter(dat, info->Size(), info->Path()); //FIXME: Is it really okay? |
|---|
| 246 | } |
|---|
| 247 | void CopyRGBA(char* image, const char* from); |
|---|
| 248 | void CopyRGB(char* image, const char* from); |
|---|
| 249 | void CopyRGBA_rev(char* image, const char* from); |
|---|
| 250 | void CopyRGB_rev(char* image, const char* from); |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | #endif // !defined(__KANON_FILE_H__) |
|---|