Artifact 2cd48208f91bb9692f85711d45fb4c0d0306bf43
1 //--- K.I.LIB ---
2 // kl_carc.cpp : handling "common archivers' dll"
3
4 #include "stdafx.h"
5 #include "kilibext.h"
6
7
8 //------------------------ load/unload 制御 ----------------------//
9
10
11 kiArcDLLRaw::kiArcDLLRaw( const char* dllname )
12 : m_DllPath( dllname ), not_loaded_yet( true )
13 {
14 ki_memzero( m_Proc, ISARC_FUNCTION_END*sizeof(FARPROC) );
15 f_VSb = NULL;
16 }
17
18 kiArcDLLRaw::~kiArcDLLRaw()
19 {
20 unload();
21 }
22
23 bool kiArcDLLRaw::load()
24 {
25 not_loaded_yet = false;
26
27 m_hDLL = kiSUtil::loadLibrary( m_DllPath );
28 if( !m_hDLL )
29 return false;
30
31 // DLLの名前部分を切り出し
32 char str[MAX_PATH], *p;
33 const char *x, *y, *z;
34 for( x=y=m_DllPath; *x!='\0'; x=kiStr::next(x) )
35 if( *x=='\\' || *x=='/' )
36 y = x + 1;
37 for( p=str, z=y; (*z!='.' && *z!='3' && *z!='\0'); p++, z++ )
38 *p = *z;
39 *p = '\0';
40
41 // コマンド送りAPIを取得。ccで始まるAPI名かも?
42 f_Cmd = ::GetProcAddress( m_hDLL, str );
43 if( f_Cmd )
44 m_DllNameBody = str;
45 else
46 {
47 f_Cmd = ::GetProcAddress( m_hDLL, "ccCommand" );
48 if( f_Cmd )
49 m_DllNameBody = "cc";
50 else
51 {
52 if( str[0]=='7' && (f_Cmd=::GetProcAddress(m_hDLL,"SevenZip")) )
53 m_DllNameBody = "SevenZip";
54 else
55 return false;
56 }
57 }
58
59 return true;
60 }
61
62 void kiArcDLLRaw::unload()
63 {
64 if( !not_loaded_yet && m_hDLL )
65 {
66 ki_memzero( m_Proc, ISARC_FUNCTION_END*sizeof(FARPROC) );
67 ::FreeLibrary( m_hDLL );
68 not_loaded_yet = true;
69 }
70 }
71
72 bool kiArcDLLRaw::isAlive()
73 {
74 if( not_loaded_yet )
75 load();
76
77 return (m_hDLL != NULL);
78 }
79
80 FARPROC kiArcDLLRaw::getProc( const char* procname )
81 {
82 kiStr funcName = (const char*)m_DllNameBody;
83 funcName += procname;
84 return ::GetProcAddress( m_hDLL, funcName );
85 }
86
87 //----------------------------- APIのラッパ群 --------------------------//
88
89
90 int kiArcDLLRaw::command( const HWND wnd, LPCSTR cmd, LPSTR buf, const DWORD siz )
91 {
92 if( not_loaded_yet )
93 if( !load() )
94 return ERROR_NOT_SUPPORT;
95
96 // コマンド関数は必ずロードされている
97
98 typedef int (WINAPI * CARC_CMD)(const HWND,const char*,char*,const DWORD);
99 return ((CARC_CMD)f_Cmd)( wnd, cmd, buf, siz );
100 }
101
102 WORD kiArcDLLRaw::getVer()
103 {
104 if( not_loaded_yet )
105 if( !load() )
106 return 0;
107
108 if( !f_Ver )
109 f_Ver = getProc( "GetVersion" );
110
111 typedef WORD (WINAPI * CARC_VER)(void);
112 return f_Ver ? ((CARC_VER)f_Ver)() : 0;
113 }
114
115 WORD kiArcDLLRaw::getVerSub()
116 {
117 if( not_loaded_yet )
118 if( !load() )
119 return 0;
120
121 if( !f_VSb )
122 f_VSb = getProc( "GetSubVersion" );
123
124 typedef WORD (WINAPI * CARC_VER)(void);
125 return f_VSb ? ((CARC_VER)f_VSb)() : 0;
126 }
127
128 BOOL kiArcDLLRaw::check( LPCSTR filename, const int mode )
129 {
130 if( not_loaded_yet )
131 if( !load() )
132 return FALSE;
133
134 if( !f_Chk )
135 f_Chk = getProc( "CheckArchive" );
136
137 typedef BOOL (WINAPI * CARC_CHK)(const char*,const int);
138 return f_Chk ? ((CARC_CHK)f_Chk)( filename, mode ) : FALSE;
139 }
140
141 int kiArcDLLRaw::getArcType( LPCSTR filename )
142 {
143 if( not_loaded_yet )
144 if( !load() )
145 return FALSE;
146
147 if( !f_Gat )
148 f_Gat = getProc( "GetArchiveType" );
149
150 typedef BOOL (WINAPI * CARC_GAT)(const char*);
151 return f_Gat ? ((CARC_GAT)f_Gat)( filename ) : 0;
152 }
153
154 HARC kiArcDLLRaw::openArc( const HWND wnd, LPCSTR arcname, const DWORD flag )
155 {
156 if( not_loaded_yet )
157 if( !load() )
158 return NULL;
159
160 if( !f_Opn )
161 f_Opn = getProc( "OpenArchive" );
162
163 typedef HARC (WINAPI * CARC_OPN)(const HWND,LPCSTR,const DWORD);
164 return f_Opn ? ((CARC_OPN)f_Opn)( wnd, arcname, flag ) : NULL;
165 }
166
167 void kiArcDLLRaw::closeArc( HARC arc )
168 {
169 if( not_loaded_yet )
170 if( !load() )
171 return;
172
173 if( !f_Cls )
174 f_Cls = getProc( "CloseArchive" );
175
176 typedef int (WINAPI * CARC_CLS)(HARC);
177 if( f_Cls )
178 ((CARC_CLS)f_Cls)( arc );
179 }
180
181 int kiArcDLLRaw::findfirst( HARC arc, LPCSTR wildname, INDIVIDUALINFO* inf )
182 {
183 if( not_loaded_yet )
184 if( !load() )
185 return ERROR_NOT_SUPPORT;
186
187 if( !f_Ffs )
188 f_Ffs = getProc( "FindFirst" );
189
190 typedef int (WINAPI * CARC_FFS)(HARC,LPCSTR,INDIVIDUALINFO FAR *);
191 return f_Ffs ? ((CARC_FFS)f_Ffs)( arc, wildname, inf ) : ERROR_NOT_SUPPORT;
192 }
193
194 int kiArcDLLRaw::findnext( HARC arc, INDIVIDUALINFO* inf )
195 {
196 if( not_loaded_yet )
197 if( !load() )
198 return ERROR_NOT_SUPPORT;
199
200 if( !f_Fnx )
201 f_Fnx = getProc( "FindNext" );
202
203 typedef int (WINAPI * CARC_FNX)(HARC,INDIVIDUALINFO FAR *);
204 return f_Fnx ? ((CARC_FNX)f_Fnx)( arc, inf ) : ERROR_NOT_SUPPORT;
205 }
206
207 int kiArcDLLRaw::getAttr( HARC arc )
208 {
209 if( not_loaded_yet )
210 if( !load() )
211 return ERROR_NOT_SUPPORT;
212
213 if( !f_GAr )
214 f_GAr = getProc( "GetAttribute" );
215
216 typedef int (WINAPI * CARC_GAR)(HARC);
217 return f_GAr ? ((CARC_GAR)f_GAr)( arc ) : 0;
218 }
219
220 BOOL kiArcDLLRaw::setOwner( HWND wnd )
221 {
222 if( not_loaded_yet )
223 if( !load() )
224 return ERROR_NOT_SUPPORT;
225
226 if( !f_SOw )
227 f_SOw = getProc( "SetOwnerWindow" );
228
229 typedef BOOL (WINAPI * CARC_SOW)(HWND);
230 return f_SOw ? ((CARC_SOW)f_SOw)( wnd ) : FALSE;
231 }
232
233 BOOL kiArcDLLRaw::clearOwner()
234 {
235 if( not_loaded_yet )
236 if( !load() )
237 return ERROR_NOT_SUPPORT;
238
239 if( !f_COw )
240 f_COw = getProc( "ClearOwnerWindow" );
241
242 typedef BOOL (WINAPI * CARC_COW)();
243 return f_COw ? ((CARC_COW)f_COw)() : FALSE;
244 }
245