OSDN Git Service

db087a8bf9816bb432726585c08a9eac6119ada0
[tpi/lychee.git] / src / common / handle / TPIHandle.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \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
8   any later version.\r
9 \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
13   for more details.\r
14 \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
18 \r
19   $Id$\r
20 *******************************************************************************/\r
21 \r
22 //******************************************************************************\r
23 //    Includes\r
24 //******************************************************************************\r
25 \r
26 #define wxUSE_DYNLIB_CLASS 1\r
27 #include "../header/plugin.h"\r
28 #include <wx/dynlib.h>\r
29 #include "TPIHandle.h"\r
30 \r
31 #define GetAPIAddress(name, p) \\r
32         if (! this->lib.HasSymbol(wxT(name))) \\r
33         { \\r
34                 return false; \\r
35         } \\r
36         void * p = this->lib.GetSymbol(wxT(name)); \\r
37         if (! p) \\r
38         { \\r
39                 return false; \\r
40         }\r
41 \r
42 //******************************************************************************\r
43 //    Class (TPIHandle)\r
44 //******************************************************************************\r
45 \r
46 TPIHandle::TPIHandle(void) : nErrorCode(TPI_ERROR_SUCCESS), bHandleOnCommand(1), archive(NULL)\r
47 {\r
48 }\r
49 \r
50 TPIHandle::~TPIHandle(void)\r
51 {\r
52         this->FreeLibrary();\r
53 }\r
54 \r
55 bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArcName, TPI_PROC _prProc, wxULongLong_t _llTypeId)\r
56 {\r
57         this->nErrorCode = TPI_ERROR_SUCCESS;\r
58         if (! this->lib.Load(_szLibName))\r
59         {\r
60                 return false;\r
61         }\r
62 \r
63         GetAPIAddress("LoadPlugin", p);\r
64         int nErrorCode = ((int (__stdcall *)(const wxString &, TPI_PROC, wxULongLong_t)) p)(_szArcName, _prProc, _llTypeId);\r
65         if (! this->GetPluginInformation(TPI_INFO_HANDLE_ON_COMMAND, 0, & this->bHandleOnCommand))\r
66         {\r
67                 this->bHandleOnCommand = 1;\r
68         }\r
69         this->nErrorCode = nErrorCode;\r
70         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
71 }\r
72 \r
73 bool TPIHandle::FreeLibrary(void)\r
74 {\r
75         this->nErrorCode = TPI_ERROR_SUCCESS;\r
76         if (! this->lib.IsLoaded())\r
77         {\r
78                 return false;\r
79         }\r
80 \r
81         GetAPIAddress("FreePlugin", p);\r
82         this->nErrorCode = ((int (__stdcall *)(void *)) p)(NULL);\r
83 \r
84         this->lib.Unload();\r
85         this->archive = NULL;\r
86         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
87 }\r
88 \r
89 bool TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong_t _llSubOption, void * _pPtr)\r
90 {\r
91         this->nErrorCode = TPI_ERROR_SUCCESS;\r
92         GetAPIAddress("GetPluginInformation", p);\r
93         this->nErrorCode = ((int (__stdcall *)(unsigned int, wxULongLong_t, void *)) p)(_uInfoId, _llSubOption, _pPtr);\r
94         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
95 }\r
96 \r
97 bool TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)\r
98 {\r
99         this->nErrorCode = TPI_ERROR_SUCCESS;\r
100         if (! _fiInfo)\r
101         {\r
102                 return false;\r
103         }\r
104 \r
105         // Initialization.\r
106         _fiInfo->fArchive           = false;\r
107         _fiInfo->fComment           = false;\r
108         _fiInfo->fCompressHeader    = false;\r
109         _fiInfo->fEncryptKeyFile    = false;\r
110         _fiInfo->fEncryptPassword   = false;\r
111         _fiInfo->fEncryptHeader     = false;\r
112         _fiInfo->fMMOptimize        = false;\r
113         _fiInfo->fMultiVolume       = false;\r
114         _fiInfo->fSolid             = false;\r
115         _fiInfo->nCompressLevelMin  = 0;\r
116         _fiInfo->nCompressLevelMax  = 0;\r
117         _fiInfo->nRecoveryRecordMin = 0;\r
118         _fiInfo->nRecoveryRecordMax = 0;\r
119         _fiInfo->szTypeName.Empty();\r
120         _fiInfo->szSuffix.Empty();\r
121         _fiInfo->szEngineName.Empty();\r
122         _fiInfo->szTPIName.Empty();\r
123         _fiInfo->eSupportedCommand = 0;\r
124         _fiInfo->nTypeId           = 0;\r
125         _fiInfo->pCustomInfo    = NULL;\r
126 \r
127         GetAPIAddress("GetFormatInformation", p);\r
128         this->nErrorCode = ((int (__stdcall *)(TPI_FORMATINFO *, bool)) p)(_fiInfo, _bFirst);\r
129         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
130 }\r
131 \r
132 bool TPIHandle::OpenArchive(const wxString & _szArcName, wxULongLong_t * _llFileCount)\r
133 {\r
134         this->nErrorCode = TPI_ERROR_SUCCESS;\r
135         GetAPIAddress("OpenArchive", p);\r
136         this->nErrorCode = ((int (__stdcall *)(const wxString &, void * *, wxULongLong_t *)) p)(_szArcName, & this->archive, _llFileCount);\r
137         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
138 }\r
139 \r
140 bool TPIHandle::CloseArchive(void)\r
141 {\r
142         if (this->archive == NULL)\r
143         {\r
144                 return false;\r
145         }\r
146         this->nErrorCode = TPI_ERROR_SUCCESS;\r
147         GetAPIAddress("CloseArchive", p);\r
148         this->nErrorCode = ((int (__stdcall *)(void *)) p)(this->archive);\r
149         this->archive = NULL;\r
150         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
151 }\r
152 \r
153 bool TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst)\r
154 {\r
155         this->nErrorCode = TPI_ERROR_SUCCESS;\r
156         if (! _fiInfo)\r
157         {\r
158                 return false;\r
159         }\r
160 \r
161         // Initialization.\r
162         _fiInfo->eDanger        = 0;\r
163         _fiInfo->eOSType        = 0;\r
164         _fiInfo->wCompressRatio = 0;\r
165         _fiInfo->wPermission    = 0644;\r
166         _fiInfo->dwAttribute    = 0;\r
167         _fiInfo->dwCRC32        = 0;\r
168         _fiInfo->tmAccess       = 0;\r
169         _fiInfo->tmCreate       = 0;\r
170         _fiInfo->tmModify       = 0;\r
171         _fiInfo->nPackedSize    = 0;\r
172         _fiInfo->nUnpackedSize  = 0;\r
173         _fiInfo->fnFileName.Clear();\r
174         _fiInfo->szStoredName.Empty();\r
175         _fiInfo->szMethod.Empty();\r
176         _fiInfo->szComment.Empty();\r
177         _fiInfo->szUser.Empty();\r
178         _fiInfo->szGroup.Empty();\r
179         _fiInfo->nFileId        = 0;\r
180         _fiInfo->pCustomInfo    = NULL;\r
181 \r
182         GetAPIAddress("GetFileInformation", p);\r
183         this->nErrorCode = ((int (__stdcall *)(void *, TPI_FILEINFO *, bool)) p)(this->archive, _fiInfo, _bFirst);\r
184         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
185 }\r
186 \r
187 bool TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo)\r
188 {\r
189         this->nErrorCode = TPI_ERROR_SUCCESS;\r
190         if (! _aiInfo)\r
191         {\r
192                 return false;\r
193         }\r
194 \r
195         // Initialization.\r
196         _aiInfo->fSFX           = false;\r
197         _aiInfo->fSolid                 = false;\r
198         _aiInfo->fMMOptimize    = false;\r
199         _aiInfo->fEncryptData   = false;\r
200         _aiInfo->fEncryptHeader = false;\r
201         _aiInfo->fCompressHeader= false;\r
202         _aiInfo->nCompressLevel = 0;\r
203         _aiInfo->nRecoveryRecord= 0;\r
204         _aiInfo->tmAccess       = 0;\r
205         _aiInfo->tmCreate       = 0;\r
206         _aiInfo->tmModify       = 0;\r
207         _aiInfo->eOSType        = 0;\r
208         _aiInfo->nFileSize      = 0;\r
209         _aiInfo->nPackedSize    = 0;\r
210         _aiInfo->nReadSize      = 0;\r
211         _aiInfo->nUnpackedSize  = 0;\r
212         _aiInfo->nSplitSize     = 0;\r
213         _aiInfo->fnArchive.Clear();\r
214         _aiInfo->szComment.Empty();\r
215         _aiInfo->wCompressRatio = 0;\r
216         _aiInfo->pCustomInfo    = NULL;\r
217         // FORMATINFO\r
218         _aiInfo->fiInfo.fComment           = false;\r
219         _aiInfo->fiInfo.fCompressHeader    = false;\r
220         _aiInfo->fiInfo.fEncryptKeyFile    = false;\r
221         _aiInfo->fiInfo.fEncryptPassword   = false;\r
222         _aiInfo->fiInfo.fEncryptHeader     = false;\r
223         _aiInfo->fiInfo.fMMOptimize        = false;\r
224         _aiInfo->fiInfo.fMultiVolume       = false;\r
225         _aiInfo->fiInfo.fSolid             = false;\r
226         _aiInfo->fiInfo.nCompressLevelMin  = 0;\r
227         _aiInfo->fiInfo.nCompressLevelMax  = 0;\r
228         _aiInfo->fiInfo.nRecoveryRecordMin = 0;\r
229         _aiInfo->fiInfo.nRecoveryRecordMax = 0;\r
230         _aiInfo->fiInfo.szTypeName.Empty();\r
231         _aiInfo->fiInfo.szSuffix.Empty();\r
232         _aiInfo->fiInfo.szEngineName.Empty();\r
233         _aiInfo->fiInfo.szTPIName.Empty();\r
234         _aiInfo->fiInfo.eSupportedCommand = 0;\r
235         _aiInfo->fiInfo.nTypeId           = 0;\r
236         _aiInfo->fiInfo.pCustomInfo    = NULL;\r
237 \r
238         GetAPIAddress("GetArchiveInformation", p);\r
239         this->nErrorCode = ((int (__stdcall *)(void *, TPI_ARCHIVEINFO *)) p)(this->archive, _aiInfo);\r
240         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
241 }\r
242 \r
243 bool TPIHandle::Command(wxULongLong_t _eCommand, TPI_SWITCHES * _swInfo, const wxArrayString & _szFiles)\r
244 {\r
245         this->nErrorCode = TPI_ERROR_SUCCESS;\r
246         GetAPIAddress("Command", p);\r
247         this->nErrorCode = ((int (__stdcall *)(wxULongLong_t, TPI_SWITCHES *, void *, const wxArrayString &)) p)(_eCommand, _swInfo, this->archive, _szFiles);\r
248         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
249 }\r