1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\r
5 This library is free software; you can redistribute it and/or modify it under
\r
6 the terms of the GNU Lesser General Public License as published by the Free
\r
7 Software Foundation; either version 2.1 of the License, or (at your option)
\r
10 This library is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
\r
15 You should have received a copy of the GNU Lesser General Public License along
\r
16 with this library; if not, write to the Free Software Foundation, Inc.,
\r
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
\r
20 *******************************************************************************/
\r
22 //******************************************************************************
\r
24 //******************************************************************************
\r
26 #include "../../common/header/plugin.h"
\r
27 #include "../../common/header/plugin-extra.h"
\r
28 #include "../../common/library/library.h"
\r
29 #include <windows.h>
\r
32 //******************************************************************************
\r
34 //******************************************************************************
\r
38 TPI_SWITCHES * g_swInfo;
\r
39 const wxArrayString * g_asFiles;
\r
41 //******************************************************************************
\r
43 //******************************************************************************
\r
45 UINT __cdecl CallbackProc(void * user, UINT code, void* param)
\r
48 static TPI_PROCESSINFO piInfo;
\r
49 piInfo.eMessage = TPI_MESSAGE_STATUS;
\r
53 case eggevent::Start::CODE:
\r
54 piInfo.eStatus = TPI_STATUS_OPENARCHIVE;
\r
56 case eggevent::Extract::CODE:
\r
59 // TODO : アプリケーション側へ。
\r
60 eggevent::Extract * p = (eggevent::Extract *) param;
\r
61 wxString szFileName = WC2String(p->nameInArchive);
\r
62 if (g_asFiles->Count() != 0 && g_asFiles->Index(szFileName) == wxNOT_FOUND)
\r
64 return EGG_ERROR_SKIP;
\r
68 wcsncpy(p->fileName, (g_swInfo->fnDestinationDirectory.GetPathWithSep() + (g_swInfo->fStoreDirectoryPathes ? szFileName : wxFileName(szFileName).GetFullName())).wchar_str(), MAX_PATH - 1);
\r
69 return EGG_ERROR_SUCCESS;
\r
71 case eggevent::ActivityStart::CODE:
\r
72 piInfo.eStatus = TPI_STATUS_BEGINPROCESS;
\r
73 GetFileInformation(* (void **) user, & piInfo.fiInfo, ((eggevent::ActivityStart *) param)->index == 0);
\r
75 case eggevent::Progress::CODE:
\r
76 piInfo.eStatus = TPI_STATUS_INPROCESS;
\r
77 piInfo.nProcessedSize = ((eggevent::Progress *) param)->current * (piInfo.fiInfo.nUnpackedSize / 10000);
\r
79 case eggevent::ActivityFinish::CODE:
\r
80 piInfo.eStatus = TPI_STATUS_ENDPROCESS;
\r
82 case eggevent::Finish::CODE:
\r
83 piInfo.eStatus = TPI_STATUS_CLOSEARCHIVE;
\r
85 case eggevent::QueryPassword::CODE:
\r
88 // TODO : 個別ファイルに対する問い合わせの実装。
\r
89 piInfo.eMessage = TPI_MESSAGE_ASK;
\r
90 piInfo.eStatus = TPI_PARAM_PASSWORD;
\r
93 eggevent::QueryPassword * p = (eggevent::QueryPassword *) param;
\r
95 if (p->queryCount == 1)
\r
97 wcsncpy(p->password, g_swInfo->szPassword.wchar_str(), 1024 - 1);
\r
98 return EGG_ERROR_SUCCESS;
\r
101 // 2回目以降はコールバック関数に送信する。
\r
102 if (g_prProc == NULL || g_prProc(TPI_NOTIFY_COMMON, & piInfo) != TPI_CALLBACK_CONTINUE)
\r
104 return EGG_ERROR_CANCEL;
\r
107 // 既定のパスワードも変更しておく。
\r
108 g_swInfo->szPassword = piInfo.szParam;
\r
109 wcsncpy(p->password, piInfo.szParam.wchar_str(), 1024 - 1);
\r
110 return EGG_ERROR_SUCCESS;
\r
113 return EGG_ERROR_SUCCESS;
\r
117 if (g_prProc == NULL)
\r
119 return EGG_ERROR_SUCCESS;
\r
122 return g_prProc(TPI_NOTIFY_COMMON, & piInfo) != TPI_CALLBACK_CANCEL ? EGG_ERROR_SUCCESS : EGG_ERROR_CANCEL;
\r
125 //******************************************************************************
\r
126 // Inside Functions
\r
127 //******************************************************************************
\r
129 #define GetAPIAddress(name) GetProcAddress(g_hLib, "EGG_" name)
\r
131 int ErrorCodeConvert(int nErrorCode)
\r
133 switch (nErrorCode)
\r
135 case EGG_ERROR_FAIL: return TPI_ERROR_UNDEFINED;
\r
136 case EGG_ERROR_SUCCESS: return TPI_ERROR_SUCCESS;
\r
137 case EGG_ERROR_SKIP: return TPI_ERROR_D_SKIPPED;
\r
138 case EGG_ERROR_CANCEL: return TPI_ERROR_D_SKIPPED;
\r
139 case EGG_ERROR_IO: return TPI_ERROR_IO_MISC;
\r
140 case EGG_ERROR_TYPEMISMATCH:return TPI_ERROR_ARC_UNSUPPORTED;
\r
141 case EGG_ERROR_FILE: return TPI_ERROR_IO_MISC;
\r
142 case EGG_ERROR_FORMAT: return TPI_ERROR_IO_ARC_MISC;
\r
143 case EGG_ERROR_ALGORITHM: return TPI_ERROR_UNDEFINED;
\r
144 default: return TPI_ERROR_UNDEFINED;
\r
148 //******************************************************************************
\r
150 //******************************************************************************
\r
157 int __stdcall GetPluginInformation
\r
159 unsigned int _uInfoId,
\r
166 return TPI_ERROR_D_PARAMETER;
\r
170 case TPI_INFO_VERSION_MAJOR:
\r
171 case TPI_INFO_VERSION_MINOR:
\r
172 * (int *) _pPtr = 0;
\r
174 case TPI_INFO_VERSION_API:
\r
175 * (int *) _pPtr = 2;
\r
178 return TPI_ERROR_D_UNSUPPORTED;
\r
180 return TPI_ERROR_SUCCESS;
\r
183 int __stdcall GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)
\r
187 return TPI_ERROR_S_ENDOFDATA;
\r
190 _fiInfo->szTypeName = wxT("EGG/ALZ");
\r
191 _fiInfo->szSuffix = wxT("egg;alz");
\r
192 _fiInfo->szEngineName = wxT("UnEGG32.dll");
\r
193 _fiInfo->szTPIName = wxT("eggArc");
\r
194 _fiInfo->nTypeId = 0;
\r
195 _fiInfo->eSupportedCommand = TPI_COMMAND_EXTRACT;
\r
196 _fiInfo->fArchive = true;
\r
197 _fiInfo->fComment = true;
\r
198 _fiInfo->fSFX = true;
\r
199 _fiInfo->fSolid = true;
\r
200 _fiInfo->fEncryptPassword = true;
\r
201 _fiInfo->fMultiVolume = true;
\r
203 return TPI_ERROR_SUCCESS;
\r
206 int __stdcall LoadPlugin
\r
212 ::RemoveCwdFromSearchPath();
\r
213 g_hLib = ::LoadLibrary(L"UnEGG32.dll");
\r
214 if (g_hLib == NULL)
\r
216 ::FreeLibrary(g_hLib);
\r
217 return TPI_ERROR_U_LOAD_LIBRARY;
\r
220 return TPI_ERROR_SUCCESS;
\r
223 int __stdcall FreePlugin
\r
225 void * // _pReserved
\r
228 ::FreeLibrary(g_hLib);
\r
229 return TPI_ERROR_SUCCESS;
\r
232 int __stdcall CheckArchive
\r
234 const wxString & _szArcName,
\r
238 FARPROC fpProc = ::GetAPIAddress("IsValidArchive");
\r
239 if (fpProc == NULL)
\r
241 return TPI_ERROR_U_USE_LIBRARY;
\r
245 return ErrorCodeConvert(((UINT (__cdecl *)(const wchar_t *, egg_type *)) fpProc)(_szArcName.wchar_str(), & eType));
\r
248 int __stdcall OpenArchive
\r
250 const wxString & _szArcName,
\r
254 FARPROC fpProc = ::GetAPIAddress("CreateEgg");
\r
255 if (fpProc == NULL)
\r
257 return TPI_ERROR_U_USE_LIBRARY;
\r
259 int nErrorCode = ErrorCodeConvert(((UINT (__cdecl *)(void **, eggevent::Proc, void *)) fpProc)(_hArchive, CallbackProc, _hArchive));
\r
260 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
264 if (_hArchive == NULL)
\r
266 return TPI_ERROR_UNDEFINED;
\r
269 fpProc = ::GetAPIAddress("OpenArchive");
\r
270 return fpProc == NULL ? TPI_ERROR_U_USE_LIBRARY : ErrorCodeConvert(((UINT (__cdecl *)(void *, wchar_t *)) fpProc)(* _hArchive, _szArcName.wchar_str()));
\r
273 int __stdcall CloseArchive
\r
278 FARPROC fpProc = ::GetAPIAddress("CloseArchive");
\r
279 if (fpProc == NULL || _hArchive == NULL)
\r
281 return TPI_ERROR_U_USE_LIBRARY;
\r
283 int nErrorCode = ErrorCodeConvert(((UINT (__cdecl *)(void *)) fpProc)(_hArchive));
\r
284 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
289 fpProc = ::GetAPIAddress("DestroyEgg");
\r
290 return fpProc == NULL ? TPI_ERROR_U_USE_LIBRARY : ErrorCodeConvert(((UINT (__cdecl *)(void **)) fpProc)(& _hArchive));
\r
293 int __stdcall GetFileInformation
\r
296 TPI_FILEINFO * _fiInfo,
\r
300 static wxULongLong_t s_nFileId;
\r
301 static size_t s_nFileCount;
\r
302 static FARPROC fpProc;
\r
308 fpProc = ::GetAPIAddress("GetFileCount");
\r
309 if (fpProc == NULL)
\r
311 return TPI_ERROR_U_USE_LIBRARY;
\r
313 nErrorCode = ErrorCodeConvert(((UINT (__cdecl *)(void *, size_t *)) fpProc)(_hArchive, & s_nFileCount));
\r
314 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
319 fpProc = ::GetAPIAddress("GetFileHeader");
\r
320 if (fpProc == NULL)
\r
322 return TPI_ERROR_U_USE_LIBRARY;
\r
325 if (s_nFileId >= s_nFileCount)
\r
327 return TPI_ERROR_S_ENDOFDATA;
\r
330 EGGFileHeader fhInfo;
\r
331 nErrorCode = ErrorCodeConvert(((UINT (__cdecl *)(void *, size_t, EGGFileHeader *)) fpProc)(_hArchive, s_nFileId, & fhInfo));
\r
332 if (nErrorCode == TPI_ERROR_SUCCESS)
\r
334 _fiInfo->dwAttribute = fhInfo.attribute;
\r
335 if (fhInfo.encrypted)
\r
337 _fiInfo->dwAttribute |= TPI_ATTRIBUTE_ENCRYPTED;
\r
339 _fiInfo->dwCRC32 = fhInfo.crc;
\r
340 _fiInfo->nPackedSize = fhInfo.packedSize;
\r
341 _fiInfo->nUnpackedSize = fhInfo.unpackedSize;
\r
342 _fiInfo->tmModified = fhInfo.lastModified;
\r
343 _fiInfo->szComment = WC2String(fhInfo.comment);
\r
344 _fiInfo->szStoredName = WC2String(fhInfo.fileName);
\r
345 _fiInfo->szMethod = fhInfo.method == 2 ? wxT("ALZ") : fhInfo.method == 0 ? wxT("EGG") : wxT("unknown");
\r
346 _fiInfo->nFileId = s_nFileId++;
\r
347 _fiInfo->fnFileName = wxFileName(_fiInfo->szStoredName);
\r
353 int __stdcall GetArchiveInformation
\r
356 TPI_ARCHIVEINFO * _aiInfo
\r
359 GetFormatInformation(& _aiInfo->fiInfo, true);
\r
360 return TPI_ERROR_SUCCESS;
\r
363 int __stdcall Command
\r
365 wxULongLong_t _eCommand,
\r
366 TPI_SWITCHES * _swInfo,
\r
367 const wxString & _szArcName,
\r
368 const wxArrayString & _szFiles
\r
371 if (_eCommand != TPI_COMMAND_EXTRACT)
\r
373 return TPI_ERROR_U_USE_LIBRARY;
\r
378 int nErrorCode = OpenArchive(_szArcName, & hArc);
\r
379 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
384 // グローバル変数にポインタを保存。
\r
385 g_swInfo = _swInfo;
\r
386 g_asFiles = & _szFiles;
\r
388 FARPROC fpProc = ::GetAPIAddress("Extract");
\r
389 if (fpProc == NULL)
\r
391 return TPI_ERROR_U_USE_LIBRARY;
\r
393 nErrorCode = ErrorCodeConvert(((UINT (__cdecl *)(void *)) fpProc)(hArc));
\r
394 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
399 return CloseArchive(hArc);
\r
402 int __stdcall SetCallbackProc
\r
404 TPI_PROC _prArcProc
\r
408 if (_prArcProc == NULL)
\r
410 return TPI_ERROR_D_PARAMETER;
\r
412 g_prProc = * _prArcProc;
\r
414 return TPI_ERROR_SUCCESS;
\r