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
47 //
\8d\
\91¢
\91Ì
\82ð
\8f\89\8aú
\89»
\81B
\r
48 static TPI_PROCESSINFO piInfo;
\r
49 piInfo.uMessage = TPI_MESSAGE_STATUS;
\r
53 case eggevent::Start::CODE:
\r
54 piInfo.uStatus = TPI_STATUS_OPENARCHIVE;
\r
56 case eggevent::Extract::CODE:
\r
58 //
\93W
\8aJ
\82·
\82é
\82©
\82Ç
\82¤
\82©
\94»
\92f
\81B
\r
59 // TODO :
\83A
\83v
\83\8a\83P
\81[
\83V
\83\87\83\93\91¤
\82Ö
\81B
\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
67 //
\93W
\8aJ
\82·
\82é
\81B
\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.uStatus = TPI_STATUS_BEGINPROCESS;
\r
73 GetFileInformation(* (void **) user, & piInfo.fiInfo, ((eggevent::ActivityStart *) param)->index == 0);
\r
75 case eggevent::Progress::CODE:
\r
76 piInfo.uStatus = TPI_STATUS_INPROCESS;
\r
77 piInfo.llProcessedSize = ((eggevent::Progress *) param)->current * (piInfo.fiInfo.llUnpackedSize.ToULong() / 10000);
\r
79 case eggevent::ActivityFinish::CODE:
\r
80 piInfo.uStatus = TPI_STATUS_ENDPROCESS;
\r
82 case eggevent::Finish::CODE:
\r
83 piInfo.uStatus = TPI_STATUS_CLOSEARCHIVE;
\r
85 case eggevent::QueryPassword::CODE:
\r
87 //
\83p
\83X
\83\8f\81[
\83h
\96â
\82¢
\8d\87\82í
\82¹
\81B
\r
88 // TODO :
\8cÂ
\95Ê
\83t
\83@
\83C
\83\8b\82É
\91Î
\82·
\82é
\96â
\82¢
\8d\87\82í
\82¹
\82Ì
\8eÀ
\91\95\81B
\r
89 piInfo.uMessage = TPI_MESSAGE_ASK;
\r
90 piInfo.uStatus = TPI_PARAM_PASSWORD;
\r
92 //
\83R
\81[
\83\8b\83o
\83b
\83N
\8aÖ
\90\94\82É
\91\97\90M
\81B
\r
93 eggevent::QueryPassword * p = (eggevent::QueryPassword *) param;
\r
94 //
\8f\89\89ñ
\82Í
\8aù
\92è
\82Ì
\83p
\83X
\83\8f\81[
\83h
\82ð
\8e\8e\82·
\81B
\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
\89ñ
\96Ú
\88È
\8d~
\82Í
\83R
\81[
\83\8b\83o
\83b
\83N
\8aÖ
\90\94\82É
\91\97\90M
\82·
\82é
\81B
\r
102 if (g_prProc == NULL || g_prProc(TPI_NOTIFY_COMMON, & piInfo) != TPI_CALLBACK_CONTINUE)
\r
104 return EGG_ERROR_CANCEL;
\r
107 //
\8aù
\92è
\82Ì
\83p
\83X
\83\8f\81[
\83h
\82à
\95Ï
\8dX
\82µ
\82Ä
\82¨
\82
\81B
\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
116 //
\83R
\81[
\83\8b\83o
\83b
\83N
\8aÖ
\90\94\82É
\91\97\90M
\81B
\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 nErrorCodeConvert(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("UnEGG.dll");
\r
193 _fiInfo->szTPIName = wxT("eggArc");
\r
194 _fiInfo->llTypeId = 0;
\r
195 _fiInfo->llSupportedCommand = 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
208 const wxString & _szArcName,
\r
212 g_hLib = ::LoadLibrary(L"UnEGG.dll");
\r
213 if (g_hLib == NULL || CheckArchive(_szArcName, NULL) != TPI_ERROR_SUCCESS)
\r
215 ::FreeLibrary(g_hLib);
\r
216 return TPI_ERROR_U_LOAD_LIBRARY;
\r
219 return TPI_ERROR_SUCCESS;
\r
222 int __stdcall FreePlugin
\r
224 void * // _pReserved
\r
227 ::FreeLibrary(g_hLib);
\r
228 return TPI_ERROR_SUCCESS;
\r
231 int __stdcall CheckArchive
\r
233 const wxString & _szArcName,
\r
237 FARPROC fpProc = ::GetAPIAddress("IsValidArchive");
\r
238 if (fpProc == NULL)
\r
240 return TPI_ERROR_U_USE_LIBRARY;
\r
243 if (_nFileCount != NULL)
\r
249 return nErrorCodeConvert(((UINT (__cdecl *)(const wchar_t *, egg_type *)) fpProc)(_szArcName.wchar_str(), & eType));
\r
252 int __stdcall OpenArchive
\r
254 const wxString & _szArcName,
\r
258 FARPROC fpProc = ::GetAPIAddress("CreateEgg");
\r
259 if (fpProc == NULL)
\r
261 return TPI_ERROR_U_USE_LIBRARY;
\r
263 int nErrorCode = nErrorCodeConvert(((UINT (__cdecl *)(void **, eggevent::Proc, void *)) fpProc)(_hArchive, CallbackProc, _hArchive));
\r
264 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
268 if (_hArchive == NULL)
\r
270 return TPI_ERROR_UNDEFINED;
\r
273 fpProc = ::GetAPIAddress("OpenArchive");
\r
274 return fpProc == NULL ? TPI_ERROR_U_USE_LIBRARY : nErrorCodeConvert(((UINT (__cdecl *)(void *, wchar_t *)) fpProc)(* _hArchive, _szArcName.wchar_str()));
\r
277 int __stdcall CloseArchive
\r
282 FARPROC fpProc = ::GetAPIAddress("CloseArchive");
\r
283 if (fpProc == NULL || _hArchive == NULL)
\r
285 return TPI_ERROR_U_USE_LIBRARY;
\r
287 int nErrorCode = nErrorCodeConvert(((UINT (__cdecl *)(void *)) fpProc)(_hArchive));
\r
288 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
293 fpProc = ::GetAPIAddress("DestroyEgg");
\r
294 return fpProc == NULL ? TPI_ERROR_U_USE_LIBRARY : nErrorCodeConvert(((UINT (__cdecl *)(void **)) fpProc)(& _hArchive));
\r
297 int __stdcall GetFileInformation
\r
300 TPI_FILEINFO * _fiInfo,
\r
304 static unsigned int s_uFileID, s_uFileCount;
\r
305 static FARPROC fpProc;
\r
311 fpProc = ::GetAPIAddress("GetFileCount");
\r
312 if (fpProc == NULL)
\r
314 return TPI_ERROR_U_USE_LIBRARY;
\r
316 nErrorCode = nErrorCodeConvert(((UINT (__cdecl *)(void *, size_t *)) fpProc)(_hArchive, & s_uFileCount));
\r
317 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
322 fpProc = ::GetAPIAddress("GetFileHeader");
\r
323 if (fpProc == NULL)
\r
325 return TPI_ERROR_U_USE_LIBRARY;
\r
328 if (s_uFileID >= s_uFileCount)
\r
330 return TPI_ERROR_S_ENDOFDATA;
\r
333 EGGFileHeader fhInfo;
\r
334 nErrorCode = nErrorCodeConvert(((UINT (__cdecl *)(void *, size_t, EGGFileHeader *)) fpProc)(_hArchive, s_uFileID, & fhInfo));
\r
335 if (nErrorCode == TPI_ERROR_SUCCESS)
\r
337 _fiInfo->dwAttribute = fhInfo.attribute;
\r
338 _fiInfo->dwCRC32 = fhInfo.crc;
\r
339 _fiInfo->llPackedSize = fhInfo.packedSize;
\r
340 _fiInfo->llUnpackedSize = fhInfo.unpackedSize;
\r
341 _fiInfo->tmModified = fhInfo.lastModified;
\r
342 _fiInfo->szStoredName = WC2String(fhInfo.fileName);
\r
343 _fiInfo->szMethod = fhInfo.method == 2 ? wxT("ALZ") : fhInfo.method == 0 ? wxT("EGG") : wxT("unknown");
\r
344 _fiInfo->llFileID = s_uFileID++;
\r
345 _fiInfo->fnFileName = wxFileName(_fiInfo->szStoredName);
\r
351 int __stdcall GetArchiveInformation
\r
354 TPI_ARCHIVEINFO * _aiInfo
\r
357 GetFormatInformation(& _aiInfo->fiInfo, true);
\r
358 return TPI_ERROR_SUCCESS;
\r
361 int __stdcall Command
\r
363 unsigned int _uCommand,
\r
364 TPI_SWITCHES * _swInfo,
\r
365 const wxString & _szArcName,
\r
366 const wxArrayString & _szFiles
\r
369 if (_uCommand != TPI_COMMAND_EXTRACT)
\r
371 return TPI_ERROR_U_USE_LIBRARY;
\r
374 //
\8aJ
\82«
\82È
\82¨
\82·
\81B
\r
376 int nErrorCode = OpenArchive(_szArcName, & hArc);
\r
377 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
382 //
\83O
\83\8d\81[
\83o
\83\8b\95Ï
\90\94\82É
\83|
\83C
\83\93\83^
\82ð
\95Û
\91¶
\81B
\r
383 g_swInfo = _swInfo;
\r
384 g_asFiles = & _szFiles;
\r
386 FARPROC fpProc = ::GetAPIAddress("Extract");
\r
387 if (fpProc == NULL)
\r
389 return TPI_ERROR_U_USE_LIBRARY;
\r
391 nErrorCode = nErrorCodeConvert(((UINT (__cdecl *)(void *)) fpProc)(hArc));
\r
392 if (nErrorCode != TPI_ERROR_SUCCESS)
\r
397 return CloseArchive(hArc);
\r
400 int __stdcall SetCallbackProc
\r
402 TPI_PROC _prArcProc
\r
405 //
\83|
\83C
\83\93\83^
\82ð
\95Û
\91¶
\81B
\r
406 if (_prArcProc == NULL)
\r
408 return TPI_ERROR_D_PARAMETER;
\r
410 g_prProc = * _prArcProc;
\r
412 return TPI_ERROR_SUCCESS;
\r