#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/config.h>\r
-#include <wx/stdpaths.h>\r
-#include <wx/xml/xml.h>\r
#include <wx/tokenzr.h>\r
#include "cuiWrapper.h"\r
\r
} g_LibInfo;\r
\r
TPI_PROC g_prProc;\r
-wxString g_szCurrentArchive;\r
-wxArrayString g_asOutput;\r
\r
//******************************************************************************\r
// Inside Functions\r
//******************************************************************************\r
\r
-int myExecute(wxString szCommandLine, wxString * szOutput, wxString szCwd)\r
+int myExecute(const wxString & szCommandLine, wxString * szOutput, const wxString & szCwd, bool fWine)\r
{\r
#ifdef __LINUX__\r
wxString sz = ::wxGetCwd();\r
::wxSetWorkingDirectory(szCwd);\r
- FILE * fp = popen(szCommandLine.ToUTF8(), "r");\r
+ FILE * fp = popen(fWine ? (wxT("wine ") + szCommandLine).ToUTF8() : szCommandLine.ToUTF8(), "r");\r
::wxSetWorkingDirectory(sz);\r
if (fp == NULL)\r
{\r
{\r
memset(sz, 0, sizeof(sz));\r
::ReadFile(hRead, & sz, sizeof(sz), & dwSize, NULL);\r
- * szOutput += UTF82String(sz);\r
+ * szOutput += wxString(sz);\r
+ // UTF-8以外の文字コードだと、UTF82Stringを使うと書庫が開けなくなる。データの切り出しにも影響。\r
+// * szOutput += UTF82String(sz);\r
// ::MessageBoxA(NULL, sz, NULL, 0);\r
}\r
else if (::WaitForSingleObject(pi.hProcess, 0) == WAIT_OBJECT_0)\r
#endif\r
}\r
\r
-PosInfo MakePosInfo(wxString szPrefix)\r
+PosInfo MakePosInfo(const wxString & szPrefix)\r
{\r
PosInfo pi;\r
- g_LibInfo.node.GetAttribute(wxT("list-") + szPrefix + wxT("-s"), wxEmptyString).ToULongLong(& pi.nStart);\r
- g_LibInfo.node.GetAttribute(wxT("list-") + szPrefix + wxT("-c"), wxEmptyString).ToULongLong(& pi.nCount);\r
- g_LibInfo.node.GetAttribute(wxT("list-") + szPrefix + wxT("-l"), wxT("0")).ToULongLong(& pi.nLine);\r
+ pi.nStart = myGetAttributeInt(& g_LibInfo.node, wxT("list-") + szPrefix + wxT("-s"));\r
+ pi.nCount = myGetAttributeInt(& g_LibInfo.node, wxT("list-") + szPrefix + wxT("-c"));\r
+ pi.nLine = myGetAttributeInt(& g_LibInfo.node, wxT("list-") + szPrefix + wxT("-l"));\r
return pi;\r
}\r
\r
-wxULongLong_t GetSize(PosInfo & pi, wxULongLong_t nCurrent, wxArrayString & as)\r
+wxULongLong_t GetSize(const PosInfo & pi, wxULongLong_t nCurrent, const wxArrayString & as)\r
{\r
if (pi.nStart == 0 && pi.nCount == 0)\r
{\r
return 0;\r
}\r
\r
- wxULongLong_t nTemp, nPos = nCurrent + pi.nLine;\r
+ wxULongLong_t nTemp = 0, nPos = nCurrent + pi.nLine;\r
wxString sz = pi.nCount == 0 ? as[nPos].Mid(pi.nStart) : as[nPos].Mid(pi.nStart, pi.nCount);\r
sz.ToULongLong(& nTemp);\r
return nTemp;\r
int __stdcall GetFormatInformation(TPI_FORMATINFO * _fiInfo, bool _bFirst)\r
{\r
static wxULongLong_t s_nFileId;\r
- wxStandardPaths p;\r
- wxXmlDocument config(wxPathOnly(p.GetExecutablePath()) + wxT("/lib/cuiWrapper.xml"));\r
- // 一気に先頭のライブラリの情報を取得。\r
- wxXmlNode * xmlLibrary = config.GetRoot()->GetChildren();\r
-\r
+ static wxXmlDocument xmlDoc(myMakeXMLName(wxT("cuiWrapper")));\r
+ static wxXmlNode * xmlLibrary;\r
if (_bFirst)\r
{\r
// xml解析開始。\r
s_nFileId = 0;\r
+ xmlLibrary = myGetFirstLib(& xmlDoc);\r
}\r
else\r
{\r
- for (wxULongLong_t i = 0; i < s_nFileId && xmlLibrary != NULL; i++)\r
- {\r
- xmlLibrary = xmlLibrary->GetNext();\r
- }\r
+ xmlLibrary = myGetNextLib(xmlLibrary);\r
}\r
-\r
- if (xmlLibrary == NULL || xmlLibrary->GetName() != wxT("library"))\r
+ if (xmlLibrary == NULL)\r
{\r
// データの終端に達した場合。\r
return TPI_ERROR_S_ENDOFDATA;\r
}\r
\r
- MakeFormatInfo(wxT("cuiWrapper"), _fiInfo, xmlLibrary, s_nFileId++);\r
- if (myExecute(xmlLibrary->GetAttribute(wxT("name"), wxEmptyString), NULL, wxEmptyString) != TPI_ERROR_SUCCESS)\r
+ MakeFormatInfo(xmlLibrary, wxT("cuiWrapper"), _fiInfo, s_nFileId++);\r
+ wxString szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
+ if (myExecute(szExeFile, NULL, wxEmptyString, szExeFile.Find(wxT('.')) != wxNOT_FOUND && szExeFile.AfterLast(wxT('.')) == wxT("exe")) != TPI_ERROR_SUCCESS)\r
{\r
_fiInfo->eSupportedCommand = 0;\r
}\r
-\r
return TPI_ERROR_SUCCESS;\r
}\r
\r
int __stdcall LoadPlugin\r
(\r
const wxString & _szArcName,\r
- wxULongLong_t _llTypeId\r
+ wxULongLong_t _nTypeId\r
)\r
{\r
// xml解析開始。\r
- wxStandardPaths p;\r
- wxXmlDocument config(wxPathOnly(p.GetExecutablePath()) + wxT("/lib/cuiWrapper.xml"));\r
- if (! config.IsOk())\r
- {\r
- return TPI_ERROR_UNDEFINED;\r
- }\r
- // 一気に先頭のライブラリの情報を取得。\r
- wxXmlNode * xmlLibrary = config.GetRoot()->GetChildren();\r
+ wxXmlDocument xmlDoc(myMakeXMLName(wxT("cuiWrapper")));\r
+ wxXmlNode * xmlLibrary;\r
\r
// 対象が存在するならば対応するライブラリを調査、\r
// 対象が存在しないならば指示されたライブラリをロード。\r
if (! ::wxFileExists(_szArcName))\r
{\r
- // 適当な位置まで移動。\r
- for (g_LibInfo.nLibIndex = 0; g_LibInfo.nLibIndex < _llTypeId && xmlLibrary != NULL; g_LibInfo.nLibIndex++)\r
- {\r
- xmlLibrary = xmlLibrary->GetNext();\r
- }\r
- if (xmlLibrary == NULL || xmlLibrary->GetName() != wxT("library"))\r
+ xmlLibrary = myGetFirstLib(& xmlDoc, _nTypeId);\r
+ if (xmlLibrary == NULL)\r
{\r
// xml文法エラー。\r
return TPI_ERROR_UNDEFINED;\r
g_LibInfo.szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
g_LibInfo.szExeFileAlt = xmlLibrary->GetAttribute(wxT("name-alt"), wxEmptyString);\r
g_LibInfo.node = * xmlLibrary;\r
-\r
+ g_LibInfo.nLibIndex = _nTypeId;\r
return TPI_ERROR_SUCCESS;\r
}\r
\r
// 無限ループに陥らないよう上限を設定。\r
+ xmlLibrary = myGetFirstLib(& xmlDoc);\r
for (g_LibInfo.nLibIndex = 0; g_LibInfo.nLibIndex < 300 && xmlLibrary != NULL; g_LibInfo.nLibIndex++)\r
{\r
- // ライブラリをロード。\r
- g_LibInfo.szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
- g_LibInfo.szExeFileAlt = xmlLibrary->GetAttribute(wxT("name-alt"), wxEmptyString);\r
- g_LibInfo.node = * xmlLibrary;\r
-\r
// 書庫に対応しているかチェック。\r
- if (CheckArchive(_szArcName, NULL) == TPI_ERROR_SUCCESS)\r
+ wxFileName fnArchive(_szArcName);\r
+ wxArrayString asExt = ::wxStringTokenize(xmlLibrary->GetAttribute(wxT("suffix"), wxEmptyString), wxT(";"));\r
+ if (xmlLibrary->HasAttribute(wxT("list")))\r
{\r
- // 対応していれば処理を終了。\r
- return TPI_ERROR_SUCCESS;\r
+ for (size_t i = 0; i < asExt.GetCount(); i++)\r
+ {\r
+ // .tar.XXXなど二重判定への対応。\r
+// if (asExt[i].IsSameAs(fnArchive.GetExt(), false))\r
+ if (fnArchive.GetFullName().EndsWith(wxT('.') + asExt[i]))\r
+ {\r
+ // ライブラリをロード。\r
+ g_LibInfo.szExeFile = xmlLibrary->GetAttribute(wxT("name"), wxEmptyString);\r
+ g_LibInfo.szExeFileAlt = xmlLibrary->GetAttribute(wxT("name-alt"), wxEmptyString);\r
+ g_LibInfo.node = * xmlLibrary;\r
+ g_LibInfo.nLibIndex = _nTypeId;\r
+ return TPI_ERROR_SUCCESS;\r
+ }\r
+ }\r
}\r
-\r
- xmlLibrary = xmlLibrary->GetNext();\r
+ xmlLibrary = myGetNextLib(xmlLibrary);\r
}\r
-\r
return TPI_ERROR_U_LOAD_LIBRARY;\r
}\r
\r
return TPI_ERROR_SUCCESS;\r
}\r
\r
-int __stdcall CheckArchive\r
-(\r
- const wxString & _szArcName,\r
- wxULongLong_t * _llFileCount\r
-)\r
-{\r
- wxFileName fnArchive(_szArcName);\r
- wxArrayString asExt = ::wxStringTokenize(g_LibInfo.node.GetAttribute(wxT("suffix"), wxEmptyString), wxT(";"));\r
- if (! g_LibInfo.node.HasAttribute(wxT("list")))\r
- {\r
- return TPI_ERROR_ARC_UNSUPPORTED;\r
- }\r
-\r
- for (size_t i = 0; i < asExt.GetCount(); i++)\r
- {\r
- // .tar.XXXなど二重判定への対応。\r
-// if (asExt[i].IsSameAs(fnArchive.GetExt(), false))\r
- if (fnArchive.GetFullName().EndsWith(wxT('.') + asExt[i]))\r
- {\r
- // 開いて確認。先行してデータを取得しておく。\r
- int nErrorCode = OpenArchive(_szArcName, NULL);\r
-\r
- // 対応。\r
- if (_llFileCount != NULL)\r
- {\r
- // ファイル数は多めに取っておく。\r
- * _llFileCount = g_asOutput.GetCount();\r
- }\r
- return nErrorCode;\r
- }\r
- }\r
-\r
- return TPI_ERROR_ARC_UNSUPPORTED;\r
-}\r
-\r
int __stdcall OpenArchive\r
(\r
const wxString & _szArcName,\r
- void * * _hArchive\r
+ void * * _hArchive,\r
+ wxULongLong_t * _nFileCount\r
)\r
{\r
- if (g_szCurrentArchive != _szArcName)\r
+ wxString szOutput;\r
+ if (myExecute(g_LibInfo.szExeFile + wxT(" ") + MakeCommandLineSend(g_LibInfo.node.GetAttribute(wxT("list"), wxEmptyString), _szArcName), & szOutput, wxEmptyString, g_LibInfo.szExeFile.Find(wxT('.')) != wxNOT_FOUND && g_LibInfo.szExeFile.AfterLast(wxT('.')) == wxT("exe")) != TPI_ERROR_SUCCESS)\r
{\r
- wxString szOutput;\r
- wxArrayString as;\r
- if (myExecute(g_LibInfo.szExeFile + wxT(" ") + MakeCommandLineSend(g_LibInfo.node.GetAttribute(wxT("list"), wxEmptyString), _szArcName, NULL, as, wxEmptyString), & szOutput, wxEmptyString) != TPI_ERROR_SUCCESS)\r
- {\r
- return TPI_ERROR_U_USE_LIBRARY;\r
- }\r
- g_szCurrentArchive = _szArcName;\r
- g_asOutput = ::wxStringTokenize(szOutput, wxT("\r\n"));\r
- g_asOutput.Shrink();\r
+ return TPI_ERROR_U_USE_LIBRARY;\r
}\r
- if (_hArchive != NULL)\r
+ wxArrayString * as = new wxArrayString(::wxStringTokenize(szOutput, wxT("\r\n")));\r
+ * _hArchive = (void *) as;\r
+ as->Shrink();\r
+ if (_nFileCount != NULL)\r
{\r
- * _hArchive = & g_asOutput;\r
+ * _nFileCount = as->GetCount();\r
}\r
- return g_asOutput.IsEmpty() ? TPI_ERROR_UNDEFINED : TPI_ERROR_SUCCESS;\r
+ return as->IsEmpty() ? TPI_ERROR_UNDEFINED : TPI_ERROR_SUCCESS;\r
}\r
\r
int __stdcall CloseArchive\r
void * _hArchive\r
)\r
{\r
- ((wxArrayString *) _hArchive)->Clear();\r
+ wxArrayString * as = (wxArrayString *) _hArchive;\r
+ as->Clear();\r
+ delete as;\r
return TPI_ERROR_SUCCESS;\r
}\r
\r
}\r
\r
// 初期設定。\r
- g_LibInfo.node.GetAttribute(wxT("list-line-c"), wxT("1")).ToULongLong(& nProcessPerLine);\r
+ nProcessPerLine = myGetAttributeInt(& g_LibInfo.node, wxT("list-line-c"), 1);\r
szEndLine = g_LibInfo.node.GetAttribute(wxT("list-line-e"), szStartLine);\r
szDateFormat = g_LibInfo.node.GetAttribute(wxT("list-date-f"), wxDefaultDateTimeFormat);\r
piFName = MakePosInfo(wxT("fname"));\r
// ファイル名を取得。\r
_fiInfo->szStoredName = piFName.nCount == 0 ? asOutput[s_nCurrentLine + piFName.nLine].Mid(piFName.nStart) : asOutput[s_nCurrentLine + piFName.nLine].Mid(piFName.nStart, piFName.nCount);\r
_fiInfo->szStoredName.Trim();\r
- _fiInfo->fnFileName = wxFileName::wxFileName(_fiInfo->szStoredName);\r
+ _fiInfo->fnFileName = wxFileName(_fiInfo->szStoredName, wxPATH_DOS);\r
\r
// サイズ取得。\r
_fiInfo->nPackedSize = GetSize(piPSize, s_nCurrentLine, asOutput);\r
)\r
{\r
// 形式に関する情報を取得。\r
- MakeFormatInfo(wxT("cuiWrapper"), & _aiInfo->fiInfo, & g_LibInfo.node, 0);\r
+ MakeFormatInfo(& g_LibInfo.node, wxT("cuiWrapper"), & _aiInfo->fiInfo, 0);\r
return TPI_ERROR_SUCCESS;\r
}\r
\r
\r
// コマンドライン・レスポンスファイル作成。\r
wxString\r
- szResponceFileName = MakeResponceFile(_szFiles, g_LibInfo.node.GetAttribute(wxT("quote-resp"), wxT("1")) == wxT("1")),\r
+ szResponceFileName = MakeResponceFile(_szFiles, myGetAttributeBool(& g_LibInfo.node, wxT("quote-resp"), true)),\r
szCommandLineSend = MakeCommandLineSend(szCommandLine, _szArcName, _swInfo, _szFiles, szResponceFileName);\r
\r
// コマンドライン実行。\r
wxString szOutput;\r
- int nErrorCode = myExecute(g_LibInfo.szExeFile + wxT(" ") + szCommandLineSend, & szOutput, _swInfo->fnDestinationDirectory.GetFullPath());\r
+ int nErrorCode = myExecute(g_LibInfo.szExeFile + wxT(" ") + szCommandLineSend, & szOutput, _swInfo->fnDestinationDirectory.GetFullPath(), g_LibInfo.szExeFile.Find(wxT('.')) != wxNOT_FOUND && g_LibInfo.szExeFile.AfterLast(wxT('.')) == wxT("exe"));\r
\r
// レスポンスファイル削除。\r
::wxRemoveFile(szResponceFileName);\r