OSDN Git Service

TPIHandleの各関数の返し値をboolにし、エラーコードをnErrorCodeに記録するよう変更。
[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: TPIHandle.cpp,v 1.5 2009/08/28 12:41:29 sirakaba Exp $\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)\r
47 {\r
48         this->nErrorCode = TPI_ERROR_SUCCESS;\r
49 }\r
50 \r
51 TPIHandle::~TPIHandle(void)\r
52 {\r
53         this->FreeLibrary();\r
54 }\r
55 \r
56 bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArcName, wxULongLong _llSubOption)\r
57 {\r
58         this->nErrorCode = TPI_ERROR_SUCCESS;\r
59         this->lib.Load(_szLibName);\r
60         if (! this->lib.IsLoaded())\r
61         {\r
62                 return false;\r
63         }\r
64 \r
65         if (_szArcName.IsEmpty())\r
66         {\r
67                 return true;\r
68         }\r
69 \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
73 }\r
74 \r
75 bool TPIHandle::FreeLibrary(void)\r
76 {\r
77         this->nErrorCode = TPI_ERROR_SUCCESS;\r
78         if (! this->lib.IsLoaded())\r
79         {\r
80                 return false;\r
81         }\r
82 \r
83         GetAPIAddress("FreePlugin", p);\r
84         this->nErrorCode = ((int (__stdcall *)(void *)) p)(NULL);\r
85 \r
86         this->lib.Unload();\r
87         return this->nErrorCode == TPI_ERROR_SUCCESS;\r
88 }\r
89 \r
90 bool TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong _llSubOption, void * _pPtr)\r
91 {\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
96 }\r
97 \r
98 bool TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)\r
99 {\r
100         this->nErrorCode = TPI_ERROR_SUCCESS;\r
101         if (! _fiInfo)\r
102         {\r
103                 return false;\r
104         }\r
105 \r
106         // Initialization.\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
125 \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
129 }\r
130 \r
131 bool TPIHandle::CheckArchive(const wxString & _szArcName, int * _nFileCount)\r
132 {\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
137 }\r
138 \r
139 bool TPIHandle::OpenArchive(const wxString & _szArcName)\r
140 {\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
145 }\r
146 \r
147 bool TPIHandle::CloseArchive(void)\r
148 {\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
153 }\r
154 \r
155 bool TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst)\r
156 {\r
157         this->nErrorCode = TPI_ERROR_SUCCESS;\r
158         if (! _fiInfo)\r
159         {\r
160                 return false;\r
161         }\r
162 \r
163         // Initialization.\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
178 \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
182 }\r
183 \r
184 bool TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo)\r
185 {\r
186         this->nErrorCode = TPI_ERROR_SUCCESS;\r
187         if (! _aiInfo)\r
188         {\r
189                 return false;\r
190         }\r
191 \r
192         // Initialization.\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
212         // FORMATINFO\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
231 \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
235 }\r
236 \r
237 bool TPIHandle::Command(unsigned int _uCommand, TPI_SWITCHES * _swInfo, const wxString & _szArcName, const wxArrayString & _szFiles)\r
238 {\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
243 }\r
244 \r
245 bool TPIHandle::SetCallbackProc(TPI_PROC _prProc)\r
246 {\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
251 }\r