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
19 $Id: TPIHandle.cpp,v 1.5 2009/08/28 12:41:29 sirakaba Exp $
\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)
\r
48 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
51 TPIHandle::~TPIHandle(void)
\r
53 this->FreeLibrary();
\r
56 bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArcName, wxULongLong _llSubOption)
\r
58 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
59 this->lib.Load(_szLibName);
\r
60 if (! this->lib.IsLoaded())
\r
65 if (_szArcName.IsEmpty())
\r
70 GetAPIAddress("LoadPlugin", p);
\r
71 this->nErrorCode = ((int (__stdcall *)(const wxString &, wxULongLong)) p)(_szArcName, _llSubOption);
\r
72 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
75 bool TPIHandle::FreeLibrary(void)
\r
77 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
78 if (! this->lib.IsLoaded())
\r
83 GetAPIAddress("FreePlugin", p);
\r
84 this->nErrorCode = ((int (__stdcall *)(void *)) p)(NULL);
\r
87 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
90 bool TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong _llSubOption, void * _pPtr)
\r
92 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
93 GetAPIAddress("GetPluginInformation", p);
\r
94 this->nErrorCode = ((int (__stdcall *)(unsigned int, wxULongLong, void *)) p)(_uInfoId, _llSubOption, _pPtr);
\r
95 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
98 bool TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)
\r
100 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
107 _fiInfo->fComment = false;
\r
108 _fiInfo->fEncryptKeyFile = false;
\r
109 _fiInfo->fEncryptPassword = false;
\r
110 _fiInfo->fEncryptHeader = false;
\r
111 _fiInfo->fMMOptimize = false;
\r
112 _fiInfo->fMultiVolume = false;
\r
113 _fiInfo->fSolid = false;
\r
114 _fiInfo->sCompressLevelMin = 0;
\r
115 _fiInfo->sCompressLevelMax = 0;
\r
116 _fiInfo->sRecoveryRecordMin = 0;
\r
117 _fiInfo->sRecoveryRecordMax = 0;
\r
118 _fiInfo->szTypeName = wxEmptyString;
\r
119 _fiInfo->szSuffix = wxEmptyString;
\r
120 _fiInfo->szEngineName = wxEmptyString;
\r
121 _fiInfo->szTPIName = wxEmptyString;
\r
122 _fiInfo->llSupportedCommand = 0;
\r
123 _fiInfo->llTypeId = 0;
\r
124 _fiInfo->pCustomInfo = NULL;
\r
126 GetAPIAddress("GetFormatInformation", p);
\r
127 this->nErrorCode = ((int (__stdcall *)(TPI_FORMATINFO *, bool)) p)(_fiInfo, _bFirst);
\r
128 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
131 bool TPIHandle::CheckArchive(const wxString & _szArcName, int * _nFileCount)
\r
133 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
134 GetAPIAddress("CheckArchive", p);
\r
135 this->nErrorCode = ((int (__stdcall *)(const wxString &, int *)) p)(_szArcName, _nFileCount);
\r
136 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
139 bool TPIHandle::OpenArchive(const wxString & _szArcName)
\r
141 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
142 GetAPIAddress("OpenArchive", p);
\r
143 this->nErrorCode = ((int (__stdcall *)(const wxString &, void * *)) p)(_szArcName, & this->archive);
\r
144 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
147 bool TPIHandle::CloseArchive(void)
\r
149 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
150 GetAPIAddress("CloseArchive", p);
\r
151 this->nErrorCode = ((int (__stdcall *)(void *)) p)(this->archive);
\r
152 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
155 bool TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst)
\r
157 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
164 _fiInfo->dwAttribute = 0;
\r
165 _fiInfo->dwCRC32 = 0;
\r
166 _fiInfo->tmAccess = 0;
\r
167 _fiInfo->tmCreate = 0;
\r
168 _fiInfo->tmModified = 0;
\r
169 _fiInfo->uDanger = 0;
\r
170 _fiInfo->uOSType = 0;
\r
171 _fiInfo->llPackedSize = 0;
\r
172 _fiInfo->llUnpackedSize = 0;
\r
173 _fiInfo->szStoredName = wxEmptyString;
\r
174 _fiInfo->szMethod = wxEmptyString;
\r
175 _fiInfo->wCompressRatio = 0;
\r
176 _fiInfo->llFileID = 0;
\r
177 _fiInfo->pCustomInfo = NULL;
\r
179 GetAPIAddress("GetFileInformation", p);
\r
180 this->nErrorCode = ((int (__stdcall *)(void *, TPI_FILEINFO *, bool)) p)(this->archive, _fiInfo, _bFirst);
\r
181 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
184 bool TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo)
\r
186 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
193 _aiInfo->fSolid = false;
\r
194 _aiInfo->fMMOptimize = false;
\r
195 _aiInfo->fEncryptData = false;
\r
196 _aiInfo->fEncryptHeader = false;
\r
197 _aiInfo->sCompressLevel = 0;
\r
198 _aiInfo->sRecoveryRecord= 0;
\r
199 _aiInfo->tmAccess = 0;
\r
200 _aiInfo->tmCreate = 0;
\r
201 _aiInfo->tmModified = 0;
\r
202 _aiInfo->nSFXType = 0;
\r
203 _aiInfo->uOSType = 0;
\r
204 _aiInfo->llFileSize = 0;
\r
205 _aiInfo->llPackedSize = 0;
\r
206 _aiInfo->llReadSize = 0;
\r
207 _aiInfo->llUnpackedSize = 0;
\r
208 _aiInfo->llSplitSize = 0;
\r
209 _aiInfo->szComment = wxEmptyString;
\r
210 _aiInfo->wCompressRatio = 0;
\r
211 _aiInfo->pCustomInfo = NULL;
\r
213 _aiInfo->fiInfo.fComment = false;
\r
214 _aiInfo->fiInfo.fEncryptKeyFile = false;
\r
215 _aiInfo->fiInfo.fEncryptPassword = false;
\r
216 _aiInfo->fiInfo.fEncryptHeader = false;
\r
217 _aiInfo->fiInfo.fMMOptimize = false;
\r
218 _aiInfo->fiInfo.fMultiVolume = false;
\r
219 _aiInfo->fiInfo.fSolid = false;
\r
220 _aiInfo->fiInfo.sCompressLevelMin = 0;
\r
221 _aiInfo->fiInfo.sCompressLevelMax = 0;
\r
222 _aiInfo->fiInfo.sRecoveryRecordMin = 0;
\r
223 _aiInfo->fiInfo.sRecoveryRecordMax = 0;
\r
224 _aiInfo->fiInfo.szTypeName = wxEmptyString;
\r
225 _aiInfo->fiInfo.szSuffix = wxEmptyString;
\r
226 _aiInfo->fiInfo.szEngineName = wxEmptyString;
\r
227 _aiInfo->fiInfo.szTPIName = wxEmptyString;
\r
228 _aiInfo->fiInfo.llSupportedCommand = 0;
\r
229 _aiInfo->fiInfo.llTypeId = 0;
\r
230 _aiInfo->fiInfo.pCustomInfo = NULL;
\r
232 GetAPIAddress("GetArchiveInformation", p);
\r
233 this->nErrorCode = ((int (__stdcall *)(void *, TPI_ARCHIVEINFO *)) p)(this->archive, _aiInfo);
\r
234 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
237 bool TPIHandle::Command(unsigned int _uCommand, TPI_SWITCHES * _swInfo, const wxString & _szArcName, const wxArrayString & _szFiles)
\r
239 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
240 GetAPIAddress("Command", p);
\r
241 this->nErrorCode = ((int (__stdcall *)(unsigned int, TPI_SWITCHES *, const wxString &, const wxArrayString &)) p)(_uCommand, _swInfo, _szArcName, _szFiles);
\r
242 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r
245 bool TPIHandle::SetCallbackProc(TPI_PROC _prProc)
\r
247 this->nErrorCode = TPI_ERROR_SUCCESS;
\r
248 GetAPIAddress("SetCallbackProc", p);
\r
249 this->nErrorCode = ((int (__stdcall *)(TPI_PROC)) p)(_prProc);
\r
250 return this->nErrorCode == TPI_ERROR_SUCCESS;
\r