OSDN Git Service

TPI内部でのパスのハードコーディングを撤廃。
[tpi/lychee.git] / src / plugin / cuiWrapper / cuiWrapper.cpp
index d17ee36..1ee4032 100644 (file)
 //    Includes\r
 //******************************************************************************\r
 \r
+#define MYUSE_LIBPATH 1\r
 #include "../../common/header/plugin.h"\r
 #include "../../common/header/plugin-extra.h"\r
 #include "../../common/library/library.h"\r
 #include "../../common/library/xmldoc.h"\r
 #include <wx/tokenzr.h>\r
 #include "cuiWrapper.h"\r
+#define min(a, b) ((a) < (b) ? (a) : (b))\r
 \r
 //******************************************************************************\r
 //    Global varients\r
@@ -83,7 +85,7 @@ int myExecute(const wxString & szCommandLine, wxString * szOutput, const wxStrin
        sa.bInheritHandle = TRUE;\r
        sa.nLength = sizeof(SECURITY_ATTRIBUTES);\r
        HANDLE hRead, hWrite;\r
-       if (! ::CreatePipe(& hRead, & hWrite, & sa, 0))\r
+       if (! ::CreatePipe(& hRead, & hWrite, & sa, 4096))\r
        {\r
                return TPI_ERROR_U_USE_LIBRARY;\r
        }\r
@@ -102,21 +104,25 @@ int myExecute(const wxString & szCommandLine, wxString * szOutput, const wxStrin
 \r
        if (szOutput != NULL)\r
        {\r
-               ::WaitForSingleObject(pi.hProcess, INFINITE);\r
-               DWORD dwSize = 0;\r
-               ::PeekNamedPipe(hRead, NULL, 0, NULL, & dwSize, NULL);\r
-               while (dwSize > 0)\r
+               bool bSignal;\r
+               do\r
                {\r
-                       char sz[32768];\r
-                       memset(sz, 0, sizeof(sz));\r
-                       ::ReadFile(hRead, & sz, sizeof(sz), & dwSize, NULL);\r
-                       * szOutput += wxString(sz);\r
-                       // UTF-8以外の文字コードだと、UTF82Stringを使うと書庫が開けなくなる。データの切り出しにも影響。\r
-//                     * szOutput += UTF82String(sz);\r
-//                     ::MessageBoxA(NULL, sz, NULL, 0);\r
-\r
+                       DWORD dwSize = 0;\r
+                       bSignal = ::WaitForSingleObject(pi.hProcess, 100) == WAIT_OBJECT_0;\r
                        ::PeekNamedPipe(hRead, NULL, 0, NULL, & dwSize, NULL);\r
+                       while (dwSize > 0)\r
+                       {\r
+                               char sz[4097];\r
+                               memset(sz, 0, sizeof(sz));\r
+                               ::ReadFile(hRead, & sz, sizeof(sz) - 1, & dwSize, NULL);\r
+                               * szOutput += wxString(sz);\r
+                               // UTF-8以外の文字コードだと、UTF82Stringを使うと書庫が開けなくなる。データの切り出しにも影響。\r
+//                             * szOutput += UTF82String(sz);\r
+//                             ::MessageBoxA(NULL, sz, NULL, 0);\r
+                               ::PeekNamedPipe(hRead, NULL, 0, NULL, & dwSize, NULL);\r
+                       }\r
                }\r
+               while (! bSignal);\r
        }\r
 \r
        ::CloseHandle(pi.hProcess);\r
@@ -177,6 +183,9 @@ int __stdcall GetPluginInformation
        case TPI_INFO_VERSION_API:\r
                * (int *) _pPtr = 2;\r
                break;\r
+       case TPI_INFO_HANDLE_ON_COMMAND:\r
+               * (int *) _pPtr = 0;\r
+               break;\r
        default:\r
                return TPI_ERROR_D_UNSUPPORTED;\r
        }\r
@@ -206,7 +215,7 @@ int __stdcall GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)
 \r
        MakeFormatInfo(xmlLibrary, wxT("cuiWrapper"), _fiInfo, s_nFileId++);\r
        wxString szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
-       if (myExecute(szExeFile, NULL, wxEmptyString, szExeFile.EndsWith(wxT(".exe"))) != TPI_ERROR_SUCCESS)\r
+       if (myExecute(szExeFile, NULL, wxEmptyString, szExeFile.MakeLower().EndsWith(wxT(".exe"))) != TPI_ERROR_SUCCESS)\r
        {\r
                _fiInfo->eSupportedCommand = 0;\r
        }\r
@@ -260,7 +269,7 @@ int __stdcall LoadPlugin
                        {\r
                                // .tar.XXXなど二重判定への対応。\r
 //                             if (asExt[i].IsSameAs(fnArchive.GetExt(), false))\r
-                               if (fnArchive.GetFullName().EndsWith(wxT('.') + asExt[i]))\r
+                               if (fnArchive.GetFullName().MakeLower().EndsWith(wxT('.') + asExt[i].MakeLower()))\r
                                {\r
                                        // ライブラリをロード。\r
                                        g_LibInfo.szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
@@ -292,7 +301,9 @@ int __stdcall OpenArchive
 )\r
 {\r
        wxString szOutput;\r
-       if (myExecute(g_LibInfo.szExeFile + wxT(" ") + MakeCommandLineSend(g_LibInfo.node.GetAttribute(wxT("list"), wxEmptyString), _szArcName), & szOutput, wxEmptyString, g_LibInfo.szExeFile.EndsWith(wxT(".exe"))) != TPI_ERROR_SUCCESS)\r
+       TPI_SWITCHES swInfo;\r
+       swInfo.szArcName = _szArcName;\r
+       if (myExecute(g_LibInfo.szExeFile + wxT(" ") + MakeCommandLineSend(g_LibInfo.node.GetAttribute(wxT("list"), wxEmptyString), & swInfo), & szOutput, wxEmptyString, g_LibInfo.szExeFile.MakeLower().EndsWith(wxT(".exe"))) != TPI_ERROR_SUCCESS)\r
        {\r
                return TPI_ERROR_U_USE_LIBRARY;\r
        }\r
@@ -303,7 +314,16 @@ int __stdcall OpenArchive
        {\r
                * _nFileCount = as->GetCount();\r
        }\r
-       return as->IsEmpty() ? TPI_ERROR_UNDEFINED : TPI_ERROR_SUCCESS;\r
+\r
+       wxString szStartLine = g_LibInfo.node.GetAttribute(wxT("list-line-s"), wxEmptyString);\r
+       if ((! szStartLine.IsEmpty() && as->Index(szStartLine) == wxNOT_FOUND) || as->IsEmpty())\r
+       {\r
+               // 書庫が読み込めなかった?\r
+               delete as;\r
+               return TPI_ERROR_ARC_UNSUPPORTED;\r
+       }\r
+\r
+       return TPI_ERROR_SUCCESS;\r
 }\r
 \r
 int __stdcall CloseArchive\r
@@ -342,13 +362,8 @@ int __stdcall GetFileInformation
                wxString szStartLine = g_LibInfo.node.GetAttribute(wxT("list-line-s"), wxEmptyString);\r
                if (! szStartLine.IsEmpty())\r
                {\r
-                       // 開始行の次の行にセット。\r
+                       // 開始行の次の行にセット。エラーはOpenArchiveでチェック済み。\r
                        s_nCurrentLine = asOutput.Index(szStartLine) + 1;\r
-                       if (s_nCurrentLine == wxNOT_FOUND + 1)\r
-                       {\r
-                               // 書庫が読み込めなかった?\r
-                               return TPI_ERROR_ARC_UNSUPPORTED;\r
-                       }\r
                }\r
 \r
                // 初期設定。\r
@@ -410,7 +425,7 @@ int __stdcall Command
 (\r
        wxULongLong_t _eCommand,\r
        TPI_SWITCHES * _swInfo,\r
-       const wxString & _szArcName,\r
+       void *,// _hArchive,\r
        const wxArrayString & _szFiles\r
 )\r
 {\r
@@ -451,11 +466,11 @@ int __stdcall Command
        // コマンドライン・レスポンスファイル作成。\r
        wxString\r
                szResponceFileName = MakeResponceFile(_szFiles, myGetAttributeBool(& g_LibInfo.node, wxT("quote-resp"), true)),\r
-               szCommandLineSend  = MakeCommandLineSend(szCommandLine, _szArcName, _swInfo, _szFiles, szResponceFileName);\r
+               szCommandLineSend  = MakeCommandLineSend(szCommandLine, _swInfo, _szFiles, szResponceFileName);\r
 \r
        // コマンドライン実行。\r
        wxString szOutput;\r
-       int nErrorCode = myExecute(g_LibInfo.szExeFile + wxT(" ") + szCommandLineSend, & szOutput, _swInfo->fnDestinationDirectory.GetFullPath(), g_LibInfo.szExeFile.EndsWith(wxT(".exe")));\r
+       int nErrorCode = myExecute(g_LibInfo.szExeFile + wxT(" ") + szCommandLineSend, & szOutput, _swInfo->fnDestinationDirectory.GetFullPath(), g_LibInfo.szExeFile.MakeLower().EndsWith(wxT(".exe")));\r
 \r
        // レスポンスファイル削除。\r
        ::wxRemoveFile(szResponceFileName);\r