OSDN Git Service

外部のコールバック関数が指定されていないとき、処理が中断してしまうバグを修正。
authorsirakaba <sirakaba@9df91469-1e22-0410-86e7-ea8537beb833>
Sat, 3 Oct 2009 07:09:47 +0000 (07:09 +0000)
committersirakaba <sirakaba@9df91469-1e22-0410-86e7-ea8537beb833>
Sat, 3 Oct 2009 07:09:47 +0000 (07:09 +0000)
グローバル変数を整理。

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/tpi/tpi@14 9df91469-1e22-0410-86e7-ea8537beb833

src/plugin/spiLibrary/spiLibrary.cpp

index 68c0116..ce6cd0f 100644 (file)
 \r
 HMODULE g_hLib;\r
 TPI_PROC g_prProc;\r
-unsigned int g_uFileCount;\r
-unsigned int g_uFilePointer;\r
-wxString g_szAppPath;\r
 \r
 //******************************************************************************\r
 //    Entry\r
 //******************************************************************************\r
 \r
 #ifdef __LINUX__\r
-void __attribute__((constructor)) Attach(void)\r
-{\r
-       wxStandardPaths p;\r
-       g_szAppPath = wxPathOnly(p.GetExecutablePath());\r
-}\r
-\r
 void __attribute__((destructor)) Detach(void)\r
 {\r
        ::FreeLibrary(g_hLib);\r
@@ -68,12 +59,6 @@ BOOL __stdcall DllMain(HMODULE, DWORD fdwReason, void *)
 {\r
        switch (fdwReason)\r
        {\r
-       case DLL_PROCESS_ATTACH:\r
-       {\r
-               wxStandardPaths p;\r
-               g_szAppPath = ::wxPathOnly(p.GetExecutablePath());\r
-               break;\r
-       }\r
        case DLL_PROCESS_DETACH:\r
                ::FreeLibrary(g_hLib);\r
                break;\r
@@ -99,12 +84,7 @@ int __stdcall CallbackProc(int _nNow, int _nMax, long _lData)
        piInfo.fiInfo.fnFileName = * (wxFileName *) _lData;\r
 \r
        // \83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\82É\91\97\90M\81B\r
-       if (g_prProc == NULL)\r
-       {\r
-               return TRUE;\r
-       }\r
-\r
-       return g_prProc(TPI_NOTIFY_COMMON, & piInfo) == TPI_CALLBACK_CANCEL;\r
+       return g_prProc != NULL && g_prProc(TPI_NOTIFY_COMMON, & piInfo) == TPI_CALLBACK_CANCEL;\r
 }\r
 \r
 //******************************************************************************\r
@@ -168,13 +148,14 @@ int __stdcall LoadPlugin
        wxULongLong\r
 )\r
 {\r
-       wxDir fs(g_szAppPath + wxT("/lib/"));\r
-       wxString szSPIName = wxEmptyString;\r
+       wxStandardPaths p;\r
+       wxString szSPIPath = wxPathOnly(p.GetExecutablePath()) + wxT("/lib/"), szSPIName = wxEmptyString;\r
+       wxDir fs(szSPIPath);\r
        bool b = fs.GetFirst(& szSPIName, wxT("*.spi"));\r
        while (b)\r
        {\r
                // SPI\82ð\83\8d\81[\83h\81B\r
-               wxString szLibName = g_szAppPath + wxT("/lib/") + szSPIName;\r
+               wxString szLibName = szSPIPath + szSPIName;\r
                g_hLib = ::LoadLibraryA(szLibName.char_str());\r
                if (g_hLib == NULL)\r
                {\r
@@ -286,9 +267,6 @@ int __stdcall OpenArchive
                return nReturnCode;\r
        }\r
 \r
-       g_uFilePointer = 0;\r
-       g_uFileCount = (unsigned int) (::LocalSize(* _hArchive) / sizeof(fileInfo));\r
-\r
        return * _hArchive == NULL ? TPI_ERROR_IO_ARC_OPEN : nReturnCode;\r
 }\r
 \r
@@ -307,21 +285,24 @@ int __stdcall GetFileInformation
        bool _bFirst\r
 )\r
 {\r
+       static unsigned int uFileCount, uFilePointer;\r
+\r
        if (_bFirst)\r
        {\r
-               g_uFilePointer = 0;\r
+               uFilePointer = 0;\r
+               uFileCount = (unsigned int) (::LocalSize(_hArchive) / sizeof(fileInfo));\r
        }\r
 \r
-       if (g_uFilePointer > g_uFileCount)\r
+       if (uFilePointer > uFileCount)\r
        {\r
                return TPI_ERROR_UNDEFINED;\r
        }\r
 \r
-       fileInfo pfiInfo = ((fileInfo *) ::LocalLock(_hArchive))[g_uFilePointer];\r
+       fileInfo pfiInfo = ((fileInfo *) ::LocalLock(_hArchive))[uFilePointer];\r
        if (pfiInfo.method[0] == 0)\r
        {\r
                // \92\9a\94J\82È\83v\83\89\83O\83C\83\93\82Ì\82½\82ß\82Ì\90\94\8d\87\82í\82¹ (^^;\r
-               g_uFileCount = g_uFilePointer;\r
+               uFileCount = uFilePointer;\r
                return TPI_ERROR_UNDEFINED;\r
        }\r
 \r
@@ -330,9 +311,8 @@ int __stdcall GetFileInformation
        _fiInfo->llPackedSize   = pfiInfo.compsize;\r
        _fiInfo->llUnpackedSize = pfiInfo.filesize;\r
        _fiInfo->wCompressRatio = pfiInfo.compsize >= pfiInfo.filesize ? 1000 : (WORD) (1000 * pfiInfo.compsize / pfiInfo.filesize);\r
-       _fiInfo->llFileID       = g_uFilePointer++;\r
+       _fiInfo->llFileID       = uFilePointer++;\r
        _fiInfo->tmModified     = pfiInfo.timestamp;\r
-       _fiInfo->pCustomInfo    = NULL;\r
        _fiInfo->szStoredName   = MB2String(pfiInfo.path) + MB2String(pfiInfo.filename);\r
        _fiInfo->fnFileName     = wxFileName::FileName(_fiInfo->szStoredName);\r
        _fiInfo->szMethod       = MB2String((char *) pfiInfo.method);\r