annotate system/file_impl.h @ 45:53a311ea8289

Patched an old patch of mine (OGG koe files handling)... It's a bit less ugly, and it works with tremor!
author thib
date Wed, 25 Mar 2009 17:32:52 +0000
parents 223b71206888
children 5f548e5957a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28
223b71206888 Initial import
thib
parents:
diff changeset
29
223b71206888 Initial import
thib
parents:
diff changeset
30 #ifndef __FILE_IMPL_H__
223b71206888 Initial import
thib
parents:
diff changeset
31 #define __FILE_IMPL_H__
223b71206888 Initial import
thib
parents:
diff changeset
32
223b71206888 Initial import
thib
parents:
diff changeset
33 #include<vector>
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 struct ARCFILE_ATOM {
223b71206888 Initial import
thib
parents:
diff changeset
36 char* filename;
223b71206888 Initial import
thib
parents:
diff changeset
37 char* filename_lower;
223b71206888 Initial import
thib
parents:
diff changeset
38 off_t offset;
223b71206888 Initial import
thib
parents:
diff changeset
39 int arcsize;
223b71206888 Initial import
thib
parents:
diff changeset
40 int filesize;
223b71206888 Initial import
thib
parents:
diff changeset
41 int private_data;
223b71206888 Initial import
thib
parents:
diff changeset
42 bool operator <(const ARCFILE_ATOM& to) const {
223b71206888 Initial import
thib
parents:
diff changeset
43 return strcmp(filename_lower, to.filename_lower) < 0;
223b71206888 Initial import
thib
parents:
diff changeset
44 }
223b71206888 Initial import
thib
parents:
diff changeset
45 bool operator <(char* const to) const {
223b71206888 Initial import
thib
parents:
diff changeset
46 return strcmp(filename_lower, to) < 0;
223b71206888 Initial import
thib
parents:
diff changeset
47 }
223b71206888 Initial import
thib
parents:
diff changeset
48 };
223b71206888 Initial import
thib
parents:
diff changeset
49
223b71206888 Initial import
thib
parents:
diff changeset
50 class ARCFILE {
223b71206888 Initial import
thib
parents:
diff changeset
51 protected:
223b71206888 Initial import
thib
parents:
diff changeset
52 char* arcname;
223b71206888 Initial import
thib
parents:
diff changeset
53 char* filenames_orig;
223b71206888 Initial import
thib
parents:
diff changeset
54 int list_point;
223b71206888 Initial import
thib
parents:
diff changeset
55 std::vector<ARCFILE_ATOM> arc_atom;
223b71206888 Initial import
thib
parents:
diff changeset
56 typedef std::vector<ARCFILE_ATOM>::iterator iterator;
223b71206888 Initial import
thib
parents:
diff changeset
57 ARCFILE* next; /* FILESEARCH の一つの型が複数の ARCFILE を持つとき、リストをつくる */
223b71206888 Initial import
thib
parents:
diff changeset
58 /* arcname に指定されたファイル/ディレクトリの内容チェック */
223b71206888 Initial import
thib
parents:
diff changeset
59 virtual int CheckFileDeal(void);
223b71206888 Initial import
thib
parents:
diff changeset
60 virtual void ListupFiles(int fname_len);
223b71206888 Initial import
thib
parents:
diff changeset
61 virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM&);
223b71206888 Initial import
thib
parents:
diff changeset
62 iterator SearchName(const char* f, const char* ext=0);
223b71206888 Initial import
thib
parents:
diff changeset
63 public:
223b71206888 Initial import
thib
parents:
diff changeset
64 ARCFILE(char* fname);
223b71206888 Initial import
thib
parents:
diff changeset
65 void SetNext(ARCFILE* _next) { next = _next;}
223b71206888 Initial import
thib
parents:
diff changeset
66 ARCFILE* Next(void) { return next; }
223b71206888 Initial import
thib
parents:
diff changeset
67 void Init(void);
223b71206888 Initial import
thib
parents:
diff changeset
68 virtual ~ARCFILE();
223b71206888 Initial import
thib
parents:
diff changeset
69 /* ファイル検索 */
223b71206888 Initial import
thib
parents:
diff changeset
70 class ARCINFO* Find(const char* fname, const char* ext);
223b71206888 Initial import
thib
parents:
diff changeset
71 /* ファイルリストの出力 */
223b71206888 Initial import
thib
parents:
diff changeset
72 int Deal(void) { Init(); return arc_atom.size(); }
223b71206888 Initial import
thib
parents:
diff changeset
73 void ListFiles(FILE* out);
223b71206888 Initial import
thib
parents:
diff changeset
74 void InitList(void);
223b71206888 Initial import
thib
parents:
diff changeset
75 char* ListItem(void);
223b71206888 Initial import
thib
parents:
diff changeset
76 };
223b71206888 Initial import
thib
parents:
diff changeset
77
223b71206888 Initial import
thib
parents:
diff changeset
78 class SCN2kFILE : public ARCFILE {
223b71206888 Initial import
thib
parents:
diff changeset
79 protected:
223b71206888 Initial import
thib
parents:
diff changeset
80 virtual int CheckFileDeal(void);
223b71206888 Initial import
thib
parents:
diff changeset
81 virtual void ListupFiles(int fname_len);
223b71206888 Initial import
thib
parents:
diff changeset
82 virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom);
223b71206888 Initial import
thib
parents:
diff changeset
83 public:
223b71206888 Initial import
thib
parents:
diff changeset
84 SCN2kFILE(char* fname) : ARCFILE(fname) {}
223b71206888 Initial import
thib
parents:
diff changeset
85 virtual ~SCN2kFILE() {}
223b71206888 Initial import
thib
parents:
diff changeset
86 };
223b71206888 Initial import
thib
parents:
diff changeset
87
223b71206888 Initial import
thib
parents:
diff changeset
88 class CattleyaFILE : public ARCFILE {
223b71206888 Initial import
thib
parents:
diff changeset
89 bool is_compress;
223b71206888 Initial import
thib
parents:
diff changeset
90 /* header の Huffman 木構築用 */
223b71206888 Initial import
thib
parents:
diff changeset
91 char* bitbuf;
223b71206888 Initial import
thib
parents:
diff changeset
92 char* bitbuf_end;
223b71206888 Initial import
thib
parents:
diff changeset
93 int ltree[0x400];
223b71206888 Initial import
thib
parents:
diff changeset
94 int rtree[0x400];
223b71206888 Initial import
thib
parents:
diff changeset
95 int treecnt;
223b71206888 Initial import
thib
parents:
diff changeset
96 int bitcnt;
223b71206888 Initial import
thib
parents:
diff changeset
97 int GetBit(void);
223b71206888 Initial import
thib
parents:
diff changeset
98 int GetCh(void);
223b71206888 Initial import
thib
parents:
diff changeset
99 void SetBuf(char* buf, int len);
223b71206888 Initial import
thib
parents:
diff changeset
100 int MakeTree(void);
223b71206888 Initial import
thib
parents:
diff changeset
101 int Decode(int seed);
223b71206888 Initial import
thib
parents:
diff changeset
102
223b71206888 Initial import
thib
parents:
diff changeset
103 protected:
223b71206888 Initial import
thib
parents:
diff changeset
104 virtual int CheckFileDeal(void);
223b71206888 Initial import
thib
parents:
diff changeset
105 virtual void ListupFiles(int fname_len);
223b71206888 Initial import
thib
parents:
diff changeset
106 virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom);
223b71206888 Initial import
thib
parents:
diff changeset
107 public:
223b71206888 Initial import
thib
parents:
diff changeset
108 CattleyaFILE(char* fname) : ARCFILE(fname) {is_compress = false;}
223b71206888 Initial import
thib
parents:
diff changeset
109 virtual ~CattleyaFILE() {}
223b71206888 Initial import
thib
parents:
diff changeset
110 };
223b71206888 Initial import
thib
parents:
diff changeset
111
223b71206888 Initial import
thib
parents:
diff changeset
112 class NULFILE : public ARCFILE {
223b71206888 Initial import
thib
parents:
diff changeset
113 protected:
223b71206888 Initial import
thib
parents:
diff changeset
114 virtual int CheckFileDeal(void);
223b71206888 Initial import
thib
parents:
diff changeset
115 virtual void ListupFiles(int fname_len);
223b71206888 Initial import
thib
parents:
diff changeset
116 virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom);
223b71206888 Initial import
thib
parents:
diff changeset
117 public:
223b71206888 Initial import
thib
parents:
diff changeset
118 NULFILE() : ARCFILE("") {}
223b71206888 Initial import
thib
parents:
diff changeset
119 virtual ~NULFILE() {}
223b71206888 Initial import
thib
parents:
diff changeset
120 };
223b71206888 Initial import
thib
parents:
diff changeset
121 class DIRFILE : public ARCFILE {
223b71206888 Initial import
thib
parents:
diff changeset
122 protected:
223b71206888 Initial import
thib
parents:
diff changeset
123 virtual int CheckFileDeal(void);
223b71206888 Initial import
thib
parents:
diff changeset
124 virtual void ListupFiles(int fname_len);
223b71206888 Initial import
thib
parents:
diff changeset
125 virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom);
223b71206888 Initial import
thib
parents:
diff changeset
126 public:
223b71206888 Initial import
thib
parents:
diff changeset
127 DIRFILE(char* fname) : ARCFILE(fname) {}
223b71206888 Initial import
thib
parents:
diff changeset
128 virtual ~DIRFILE() {}
223b71206888 Initial import
thib
parents:
diff changeset
129 FILE* Open(const char* fname); /* FILE* を開く */
223b71206888 Initial import
thib
parents:
diff changeset
130 char* SearchFile(const char* dirname); /* ファイル検索 */
223b71206888 Initial import
thib
parents:
diff changeset
131 };
223b71206888 Initial import
thib
parents:
diff changeset
132 class ARCINFO_AVG32 : public ARCINFO {
223b71206888 Initial import
thib
parents:
diff changeset
133 ARCINFO_AVG32(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) {
223b71206888 Initial import
thib
parents:
diff changeset
134 }
223b71206888 Initial import
thib
parents:
diff changeset
135 virtual bool ExecExtract(void);
223b71206888 Initial import
thib
parents:
diff changeset
136 friend class ARCFILE;
223b71206888 Initial import
thib
parents:
diff changeset
137 };
223b71206888 Initial import
thib
parents:
diff changeset
138 class ARCINFO2k : public ARCINFO {
223b71206888 Initial import
thib
parents:
diff changeset
139 static char decode_seed[256];
223b71206888 Initial import
thib
parents:
diff changeset
140 static char decode_seed2[16];
223b71206888 Initial import
thib
parents:
diff changeset
141 protected:
223b71206888 Initial import
thib
parents:
diff changeset
142 ARCINFO2k(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name,atom) {
223b71206888 Initial import
thib
parents:
diff changeset
143 }
223b71206888 Initial import
thib
parents:
diff changeset
144 virtual bool ExecExtract(void);
223b71206888 Initial import
thib
parents:
diff changeset
145 friend class SCN2kFILE;
223b71206888 Initial import
thib
parents:
diff changeset
146 };
223b71206888 Initial import
thib
parents:
diff changeset
147
223b71206888 Initial import
thib
parents:
diff changeset
148 class ARCINFOZ : public ARCINFO {
223b71206888 Initial import
thib
parents:
diff changeset
149 protected:
223b71206888 Initial import
thib
parents:
diff changeset
150 ARCINFOZ(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) {
223b71206888 Initial import
thib
parents:
diff changeset
151 }
223b71206888 Initial import
thib
parents:
diff changeset
152 virtual bool ExecExtract(void);
223b71206888 Initial import
thib
parents:
diff changeset
153 friend class DaemonBaneFILE;
223b71206888 Initial import
thib
parents:
diff changeset
154 friend class CattleyaFILE;
223b71206888 Initial import
thib
parents:
diff changeset
155 };
223b71206888 Initial import
thib
parents:
diff changeset
156
223b71206888 Initial import
thib
parents:
diff changeset
157 #endif /* __FILE_IMPL_H__ */