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 #define wxUSE_DYNLIB_CLASS 1
\r
27 #include "../header/plugin.h"
\r
28 #include <wx/dynlib.h>
\r
29 #include "TPIHandle.h"
\r
31 #define GetAPIAddress(name, p) \
\r
32 if (! this->lib.HasSymbol(wxT(name))) \
\r
36 void * p = this->lib.GetSymbol(wxT(name)); \
\r
42 //******************************************************************************
\r
43 // Class (TPIHandle)
\r
44 //******************************************************************************
\r
46 TPIHandle::TPIHandle(void) : nErrorCode(TPI_ERROR_SUCCESS), bHandleOnCommand(1), archive(NULL)
\r
50 TPIHandle::~TPIHandle(void)
\r
52 this->FreeLibrary();
\r
55 bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArcName, TPI_PROC _prProc, wxULongLong_t _llTypeId)
\r
57 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
58 if (! this->lib.Load(_szLibName))
\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
67 this->bHandleOnCommand = 1;
\r
69 this->nErrorCode = nErrorCode;
\r
70 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
73 bool TPIHandle::FreeLibrary(void)
\r
75 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
76 if (! this->lib.IsLoaded())
\r
81 GetAPIAddress("FreePlugin", p);
\r
82 this->nErrorCode = ((int (__stdcall *)(void *)) p)(NULL);
\r
85 this->archive = NULL;
\r
86 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
89 bool TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong_t _llSubOption, void * _pPtr)
\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
97 bool TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)
\r
99 this->nErrorCode = TPI_ERROR_SUCCESS;
\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
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
132 bool TPIHandle::OpenArchive(const wxString & _szArcName, wxULongLong_t * _llFileCount)
\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
140 bool TPIHandle::CloseArchive(void)
\r
142 if (this->archive == NULL)
\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
153 bool TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst)
\r
155 this->nErrorCode = TPI_ERROR_SUCCESS;
\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
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
187 bool TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo)
\r
189 this->nErrorCode = TPI_ERROR_SUCCESS;
\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
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
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
243 bool TPIHandle::Command(wxULongLong_t _eCommand, TPI_SWITCHES * _swInfo, const wxArrayString & _szFiles)
\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