From: sirakaba Date: Sat, 14 Nov 2009 04:16:28 +0000 (+0000) Subject: TPIHandleの各関数の返し値をboolにし、エラーコードをnErrorCodeに記録するよう変更。 X-Git-Tag: 0.01beta5~48 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=5baf4423316e75587386f43af2f458bb0540dfd2;p=tpi%2Flychee.git TPIHandleの各関数の返し値をboolにし、エラーコードをnErrorCodeに記録するよう変更。 git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/tpi/tpi@106 9df91469-1e22-0410-86e7-ea8537beb833 --- diff --git a/src/common/handle/TPIHandle.cpp b/src/common/handle/TPIHandle.cpp index 4c87347..26c9a3c 100644 --- a/src/common/handle/TPIHandle.cpp +++ b/src/common/handle/TPIHandle.cpp @@ -28,10 +28,26 @@ #include #include "TPIHandle.h" +#define GetAPIAddress(name, p) \ + if (! this->lib.HasSymbol(wxT(name))) \ + { \ + return false; \ + } \ + void * p = this->lib.GetSymbol(wxT(name)); \ + if (! p) \ + { \ + return false; \ + } + //****************************************************************************** // Class (TPIHandle) //****************************************************************************** +TPIHandle::TPIHandle(void) +{ + this->nErrorCode = TPI_ERROR_SUCCESS; +} + TPIHandle::~TPIHandle(void) { this->FreeLibrary(); @@ -39,6 +55,7 @@ TPIHandle::~TPIHandle(void) bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArcName, wxULongLong _llSubOption) { + this->nErrorCode = TPI_ERROR_SUCCESS; this->lib.Load(_szLibName); if (! this->lib.IsLoaded()) { @@ -50,66 +67,40 @@ bool TPIHandle::InitLibrary(const wxString & _szLibName, const wxString & _szArc return true; } - if (! this->lib.HasSymbol(wxT("LoadPlugin"))) - { - return false; - } - void * p = this->lib.GetSymbol(wxT("LoadPlugin")); - if (! p) - { - return false; - } - - return ((int (__stdcall *)(const wxString &, wxULongLong)) p)(_szArcName, _llSubOption) == TPI_ERROR_SUCCESS; + GetAPIAddress("LoadPlugin", p); + this->nErrorCode = ((int (__stdcall *)(const wxString &, wxULongLong)) p)(_szArcName, _llSubOption); + return this->nErrorCode == TPI_ERROR_SUCCESS; } bool TPIHandle::FreeLibrary(void) { + this->nErrorCode = TPI_ERROR_SUCCESS; if (! this->lib.IsLoaded()) { return false; } - if (! this->lib.HasSymbol(wxT("FreePlugin"))) - { - return false; - } - void * p = this->lib.GetSymbol(wxT("FreePlugin")); - if (! p) - { - return false; - } - ((int (__stdcall *)(void *)) p)(NULL); + GetAPIAddress("FreePlugin", p); + this->nErrorCode = ((int (__stdcall *)(void *)) p)(NULL); this->lib.Unload(); - return true; + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong _llSubOption, void * _pPtr) +bool TPIHandle::GetPluginInformation(unsigned int _uInfoId, wxULongLong _llSubOption, void * _pPtr) { - if (! this->lib.HasSymbol(wxT("GetPluginInformation"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("GetPluginInformation")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(unsigned int, wxULongLong, void *)) p)(_uInfoId, _llSubOption, _pPtr); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("GetPluginInformation", p); + this->nErrorCode = ((int (__stdcall *)(unsigned int, wxULongLong, void *)) p)(_uInfoId, _llSubOption, _pPtr); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst) +bool TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst) { - if (! this->lib.HasSymbol(wxT("GetFormatInformation")) || ! _fiInfo) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("GetFormatInformation")); - if (! p) + this->nErrorCode = TPI_ERROR_SUCCESS; + if (! _fiInfo) { - return -1; + return false; } // Initialization. @@ -132,64 +123,41 @@ int TPIHandle::GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst) _fiInfo->llTypeId = 0; _fiInfo->pCustomInfo = NULL; - return ((int (__stdcall *)(TPI_FORMATINFO *, bool)) p)(_fiInfo, _bFirst); + GetAPIAddress("GetFormatInformation", p); + this->nErrorCode = ((int (__stdcall *)(TPI_FORMATINFO *, bool)) p)(_fiInfo, _bFirst); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::CheckArchive(const wxString & _szArcName, int * _nFileCount) +bool TPIHandle::CheckArchive(const wxString & _szArcName, int * _nFileCount) { - if (! this->lib.HasSymbol(wxT("CheckArchive"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("CheckArchive")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(const wxString &, int *)) p)(_szArcName, _nFileCount); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("CheckArchive", p); + this->nErrorCode = ((int (__stdcall *)(const wxString &, int *)) p)(_szArcName, _nFileCount); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::OpenArchive(const wxString & _szArcName) +bool TPIHandle::OpenArchive(const wxString & _szArcName) { - if (! this->lib.HasSymbol(wxT("OpenArchive"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("OpenArchive")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(const wxString &, void * *)) p)(_szArcName, & this->archive); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("OpenArchive", p); + this->nErrorCode = ((int (__stdcall *)(const wxString &, void * *)) p)(_szArcName, & this->archive); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::CloseArchive(void) +bool TPIHandle::CloseArchive(void) { - if (! this->lib.HasSymbol(wxT("CloseArchive"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("CloseArchive")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(void *)) p)(this->archive); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("CloseArchive", p); + this->nErrorCode = ((int (__stdcall *)(void *)) p)(this->archive); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst) +bool TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst) { - if (! this->lib.HasSymbol(wxT("GetFileInformation")) || ! _fiInfo) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("GetFileInformation")); - if (! p) + this->nErrorCode = TPI_ERROR_SUCCESS; + if (! _fiInfo) { - return -1; + return false; } // Initialization. @@ -208,19 +176,17 @@ int TPIHandle::GetFileInformation(TPI_FILEINFO * _fiInfo, bool _bFirst) _fiInfo->llFileID = 0; _fiInfo->pCustomInfo = NULL; - return ((int (__stdcall *)(void *, TPI_FILEINFO *, bool)) p)(this->archive, _fiInfo, _bFirst); + GetAPIAddress("GetFileInformation", p); + this->nErrorCode = ((int (__stdcall *)(void *, TPI_FILEINFO *, bool)) p)(this->archive, _fiInfo, _bFirst); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo) +bool TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo) { - if (! this->lib.HasSymbol(wxT("GetArchiveInformation")) || ! _aiInfo) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("GetArchiveInformation")); - if (! p) + this->nErrorCode = TPI_ERROR_SUCCESS; + if (! _aiInfo) { - return -1; + return false; } // Initialization. @@ -263,35 +229,23 @@ int TPIHandle::GetArchiveInformation(TPI_ARCHIVEINFO * _aiInfo) _aiInfo->fiInfo.llTypeId = 0; _aiInfo->fiInfo.pCustomInfo = NULL; - return ((int (__stdcall *)(void *, TPI_ARCHIVEINFO *)) p)(this->archive, _aiInfo); + GetAPIAddress("GetArchiveInformation", p); + this->nErrorCode = ((int (__stdcall *)(void *, TPI_ARCHIVEINFO *)) p)(this->archive, _aiInfo); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::Command(unsigned int _uCommand, TPI_SWITCHES * _swInfo, const wxString & _szArcName, const wxArrayString & _szFiles) +bool TPIHandle::Command(unsigned int _uCommand, TPI_SWITCHES * _swInfo, const wxString & _szArcName, const wxArrayString & _szFiles) { - if (! this->lib.HasSymbol(wxT("Command"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("Command")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(unsigned int, TPI_SWITCHES *, const wxString &, const wxArrayString &)) p)(_uCommand, _swInfo, _szArcName, _szFiles); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("Command", p); + this->nErrorCode = ((int (__stdcall *)(unsigned int, TPI_SWITCHES *, const wxString &, const wxArrayString &)) p)(_uCommand, _swInfo, _szArcName, _szFiles); + return this->nErrorCode == TPI_ERROR_SUCCESS; } -int TPIHandle::SetCallbackProc(TPI_PROC _prProc) +bool TPIHandle::SetCallbackProc(TPI_PROC _prProc) { - if (! this->lib.HasSymbol(wxT("SetCallbackProc"))) - { - return -1; - } - void * p = this->lib.GetSymbol(wxT("SetCallbackProc")); - if (! p) - { - return -1; - } - - return ((int (__stdcall *)(TPI_PROC)) p)(_prProc); + this->nErrorCode = TPI_ERROR_SUCCESS; + GetAPIAddress("SetCallbackProc", p); + this->nErrorCode = ((int (__stdcall *)(TPI_PROC)) p)(_prProc); + return this->nErrorCode == TPI_ERROR_SUCCESS; } diff --git a/src/common/handle/TPIHandle.h b/src/common/handle/TPIHandle.h index a52910a..51892bb 100644 --- a/src/common/handle/TPIHandle.h +++ b/src/common/handle/TPIHandle.h @@ -32,21 +32,26 @@ class TPIHandle { public: + TPIHandle(void); ~TPIHandle(void); - int GetPluginInformation(unsigned int, wxULongLong, void *); - int GetFormatInformation(TPI_FORMATINFO *, bool); bool InitLibrary(const wxString &, const wxString &, wxULongLong); bool FreeLibrary(void); - int CheckArchive(const wxString &, int *); - int OpenArchive(const wxString &); - int CloseArchive(void); - int GetFileInformation(TPI_FILEINFO *, bool); - int GetArchiveInformation(TPI_ARCHIVEINFO *); + bool GetPluginInformation(unsigned int, wxULongLong, void *); + bool GetFormatInformation(TPI_FORMATINFO *, bool); - int Command(unsigned int, TPI_SWITCHES *, const wxString &, const wxArrayString &); + bool CheckArchive(const wxString &, int *); + bool OpenArchive(const wxString &); + bool CloseArchive(void); + bool GetFileInformation(TPI_FILEINFO *, bool); + bool GetArchiveInformation(TPI_ARCHIVEINFO *); + + bool Command(unsigned int, TPI_SWITCHES *, const wxString &, const wxArrayString &); + + bool SetCallbackProc(TPI_PROC); + + int nErrorCode; - int SetCallbackProc(TPI_PROC); private: wxDynamicLibrary lib; void * archive; diff --git a/src/frontend/dlg_make.cpp b/src/frontend/dlg_make.cpp index dc28094..4f73511 100644 --- a/src/frontend/dlg_make.cpp +++ b/src/frontend/dlg_make.cpp @@ -140,7 +140,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&) { // ‘Ήž‚·‚éŒ`Ž®–¼‚ðŽæ“¾B TPI_FORMATINFO fiInfo; - if (tpi.GetFormatInformation(& fiInfo, true) == TPI_ERROR_SUCCESS) + if (tpi.GetFormatInformation(& fiInfo, true)) { do { @@ -151,7 +151,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&) this->chType->Append(fiInfo.szTypeName); } } - while (tpi.GetFormatInformation(& fiInfo, false) == TPI_ERROR_SUCCESS); + while (tpi.GetFormatInformation(& fiInfo, false)); } tpi.FreeLibrary(); } diff --git a/src/frontend/frm_main.cpp b/src/frontend/frm_main.cpp index 3636ed9..639fadb 100644 --- a/src/frontend/frm_main.cpp +++ b/src/frontend/frm_main.cpp @@ -308,7 +308,7 @@ void MainFrame::OnArcCreate(wxCommandEvent& e) } // ƒR[ƒ‹ƒoƒbƒNŠÖ”‚ðÝ’èB - if (tpi.SetCallbackProc(TPICallbackProc) != TPI_ERROR_SUCCESS) + if (! tpi.SetCallbackProc(TPICallbackProc)) { ::ErrDlg(wxT("SetCallbackProc()!"), this); } @@ -317,13 +317,13 @@ void MainFrame::OnArcCreate(wxCommandEvent& e) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - int nErrorCode = this->ErrorCheck(tpi.Command(TPI_COMMAND_ADD, & swInfo, this->fnArchive.GetFullPath(), mkDlg.files)); - procDlg.Show(false); - tpi.FreeLibrary(); - if (nErrorCode != TPI_ERROR_SUCCESS) + if (! tpi.Command(TPI_COMMAND_ADD, & swInfo, this->fnArchive.GetFullPath(), mkDlg.files)) { + this->ErrorCheck(tpi.nErrorCode); return; } + procDlg.Show(false); + tpi.FreeLibrary(); if (mkDlg.cbOpenAfter->IsChecked()) { @@ -382,7 +382,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e) TPICallbackProc(TPI_NOTIFY_COMMON, & piInfo); // ƒR[ƒ‹ƒoƒbƒNŠÖ”‚ðÝ’èB - if (tpi.SetCallbackProc(TPICallbackProc) != TPI_ERROR_SUCCESS) + if (! tpi.SetCallbackProc(TPICallbackProc)) { ::ErrDlg(wxT("SetCallbackProc()!"), this); } @@ -391,7 +391,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e) this->fileinfo.Alloc(piInfo.fiInfo.llUnpackedSize.ToULong()); // ‘ŒÉ‚ðŠJ‚­B - if (tpi.OpenArchive(this->fnArchive.GetFullPath()) != TPI_ERROR_SUCCESS) + if (! tpi.OpenArchive(this->fnArchive.GetFullPath())) { procDlg.Show(false); tpi.FreeLibrary(); @@ -413,7 +413,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e) idArcRoot = this->tree_ctrl->AppendItem(idRoot, wxT("-----"), 0, 1); // ƒtƒ@ƒCƒ‹î•ñ‚ðƒ[ƒhB - if (tpi.GetFileInformation(& piInfo.fiInfo, true) == TPI_ERROR_SUCCESS) + if (tpi.GetFileInformation(& piInfo.fiInfo, true)) { piInfo.uStatus = 0x1001; do @@ -468,12 +468,12 @@ void MainFrame::OnArcOpen(wxCommandEvent& e) // î•ñ‚ð•Û‘¶‚µ‚ăJƒEƒ“ƒgƒAƒbƒvB this->fileinfo.Add(piInfo.fiInfo); } - while (tpi.GetFileInformation(& piInfo.fiInfo, false) == TPI_ERROR_SUCCESS); + while (tpi.GetFileInformation(& piInfo.fiInfo, false)); } // ‘ŒÉ‚̏î•ñ‚ðŽæ“¾B TPI_ARCHIVEINFO aiInfo; - if (tpi.GetArchiveInformation(& aiInfo) != TPI_ERROR_SUCCESS) + if (! tpi.GetArchiveInformation(& aiInfo)) { procDlg.Show(false); tpi.FreeLibrary(); @@ -482,7 +482,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e) } // ‘ŒÉ‚ð•Â‚¶‚éB - if (tpi.CloseArchive() != TPI_ERROR_SUCCESS) + if (! tpi.CloseArchive()) { ::ErrDlg(wxT("CloseArchive()!"), this); } @@ -565,7 +565,10 @@ void MainFrame::OnArcAdd(wxCommandEvent& e) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - this->ErrorCheck(this->tpi.Command(TPI_COMMAND_ADD, & swInfo, this->fnArchive.GetFullPath(), files)); + if (! this->tpi.Command(TPI_COMMAND_ADD, & swInfo, this->fnArchive.GetFullPath(), files)) + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); // ‘ŒÉ‚ðÄ“ǂݍž‚݁B @@ -593,7 +596,10 @@ void MainFrame::OnArcConvert(wxCommandEvent& e) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - this->ErrorCheck(this->tpi.Command(swInfo.fMakeSFX ? TPI_COMMAND_SFX : TPI_COMMAND_UNSFX, & swInfo, this->fnArchive.GetFullPath(), files)); + if (! this->tpi.Command(swInfo.fMakeSFX ? TPI_COMMAND_SFX : TPI_COMMAND_UNSFX, & swInfo, this->fnArchive.GetFullPath(), files)) + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); } @@ -676,7 +682,10 @@ void MainFrame::OnArcExtract(wxCommandEvent& e) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - int nErrorCode = this->ErrorCheck(this->tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->fnArchive.GetFullPath(), mkDlg.files)); + if(! this->tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->fnArchive.GetFullPath(), mkDlg.files)); + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); if (nMode == 0) @@ -702,7 +711,7 @@ void MainFrame::OnArcExtract(wxCommandEvent& e) { // ƒRƒ}ƒ“ƒh‚ðŽÀsB asFiles.Add(swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName(mkDlg.files[0]).GetFullName()); - if (nErrorCode == TPI_ERROR_SUCCESS) + if (tpi.nErrorCode == TPI_ERROR_SUCCESS) { ::wxExecute(ftFile->GetOpenCommand(wxT('"') + asFiles[0] + wxT('"')), wxEXEC_SYNC); } @@ -764,7 +773,10 @@ void MainFrame::OnArcDelete(wxCommandEvent& e) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - this->ErrorCheck(this->tpi.Command(TPI_COMMAND_DELETE, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))); + if (! this->tpi.Command(TPI_COMMAND_DELETE, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))) + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); // ‘ŒÉ‚ðÄ“ǂݍž‚Ý‚·‚éB @@ -777,10 +789,14 @@ void MainFrame::OnArcTest(wxCommandEvent&) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - if (this->ErrorCheck(this->tpi.Command(TPI_COMMAND_TEST, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))) == TPI_ERROR_SUCCESS) + if (this->tpi.Command(TPI_COMMAND_TEST, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))) { ::MsgDlg(wxT("This is a correct archive."), & procDlg, wxICON_INFORMATION); } + else + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); } @@ -790,7 +806,10 @@ void MainFrame::OnArcRepair(wxCommandEvent&) ProcessDialog procDlg; procDlg.InitDialog(); procDlg.Show(true); - this->ErrorCheck(this->tpi.Command(TPI_COMMAND_REPAIR, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))); + if (! this->tpi.Command(TPI_COMMAND_REPAIR, & swInfo, this->fnArchive.GetFullPath(), MakeTargetFileList(this, false))) + { + this->ErrorCheck(tpi.nErrorCode); + } procDlg.Show(false); } @@ -924,7 +943,7 @@ int MainFrame::LoadTPI(wxString szFileName) while (! szTPIName.IsEmpty()) { // ‘ΉžŠm”FB - if (! tpi.InitLibrary(szTPIName, szFileName, 0) || tpi.CheckArchive(szFileName, & nFileCount) != TPI_ERROR_SUCCESS || nFileCount < 0) + if (! tpi.InitLibrary(szTPIName, szFileName, 0) || ! tpi.CheckArchive(szFileName, & nFileCount) || nFileCount < 0) { tpi.FreeLibrary(); szTPIName = fs.FindNext();