OSDN Git Service

calLibraryのxml処理を共通化。
authorsirakaba <sirakaba@9df91469-1e22-0410-86e7-ea8537beb833>
Wed, 17 Nov 2010 14:38:49 +0000 (14:38 +0000)
committersirakaba <sirakaba@9df91469-1e22-0410-86e7-ea8537beb833>
Wed, 17 Nov 2010 14:38:49 +0000 (14:38 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/tpi/tpi@438 9df91469-1e22-0410-86e7-ea8537beb833

src/common/library/library.h
src/common/library/xmldoc.cpp
src/common/library/xmldoc.h
src/plugin/7zArc/7zArc.cpp
src/plugin/calLibrary/calLibrary.cpp
src/plugin/calLibrary/calLibrary.vcproj
src/plugin/cuiWrapper/cuiWrapper.cpp
src/plugin/cuiWrapper/cuiWrapper.vcproj

index c58f79b..74ede2b 100644 (file)
@@ -46,63 +46,3 @@ inline void RemoveCwdFromSearchPath(void)
        }\r
 #endif\r
 }\r
-\r
-#include <wx/xml/xml.h>\r
-#ifndef WXWIN_COMPATIBILITY_2_8\r
-#define GetAttribute GetPropVal\r
-#define HasAttribute HasProp\r
-#endif\r
-\r
-#define CheckSupportedCommand(attr, value) if (xmlLibrary->HasAttribute(wxT(attr)) || xmlLibrary->HasAttribute(wxT(attr) wxT("-alt"))) _fiInfo->eSupportedCommand |= value\r
-#define CheckSupportedSwitch(var,   value) value = szCmdLine.Find(wxT(var)) != wxNOT_FOUND\r
-\r
-inline short GetNumValue(wxXmlNode * node, const wxString & szValue)\r
-{\r
-       long l;\r
-       node->GetAttribute(szValue, wxT("0")).ToLong(& l);\r
-       return (short) l;\r
-}\r
-\r
-inline void MakeFormatInfo(const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxXmlNode * xmlLibrary, wxULongLong_t nId)\r
-{\r
-       _fiInfo->fArchive       = xmlLibrary->GetAttribute(wxT("archive"), wxT("1")) == wxT("1");\r
-       _fiInfo->szTypeName     = xmlLibrary->GetAttribute(wxT("typename"),wxEmptyString);\r
-       _fiInfo->szSuffix       = xmlLibrary->GetAttribute(wxT("suffix"),  wxEmptyString);\r
-       _fiInfo->szEngineName   = xmlLibrary->GetAttribute(wxT("name"),    wxEmptyString);\r
-       _fiInfo->szTPIName      = szTPIName;\r
-       _fiInfo->nTypeId        = nId;\r
-\r
-       // 対応コマンドを調査。\r
-       CheckSupportedCommand("create", TPI_COMMAND_CREATE);\r
-       CheckSupportedCommand("add",    TPI_COMMAND_ADD);\r
-       CheckSupportedCommand("extract",TPI_COMMAND_EXTRACT);\r
-       CheckSupportedCommand("delete", TPI_COMMAND_DELETE);\r
-       CheckSupportedCommand("update", TPI_COMMAND_UPDATE);\r
-       CheckSupportedCommand("test",   TPI_COMMAND_TEST);\r
-       CheckSupportedCommand("repair", TPI_COMMAND_REPAIR);\r
-       CheckSupportedCommand("move",   TPI_COMMAND_MOVE);\r
-       CheckSupportedCommand("sfx",    TPI_COMMAND_SFX);\r
-       CheckSupportedCommand("unsfx",  TPI_COMMAND_UNSFX);\r
-\r
-       // 対応スイッチを調査。\r
-       wxString szCmdLine =\r
-               xmlLibrary->HasAttribute(wxT("create"))      ? xmlLibrary->GetAttribute(wxT("create"),      wxEmptyString) :\r
-               xmlLibrary->HasAttribute(wxT("create-alt"))  ? xmlLibrary->GetAttribute(wxT("create-alt"),  wxEmptyString) :\r
-               xmlLibrary->HasAttribute(wxT("extract"))     ? xmlLibrary->GetAttribute(wxT("extract"),     wxEmptyString) :\r
-               xmlLibrary->HasAttribute(wxT("extract-alt")) ? xmlLibrary->GetAttribute(wxT("extract-alt"), wxEmptyString) :\r
-               (wxString) wxEmptyString;\r
-       CheckSupportedSwitch("96", _fiInfo->fComment);\r
-       CheckSupportedSwitch("a1", _fiInfo->fSFX);\r
-       CheckSupportedSwitch("a2", _fiInfo->fSolid);\r
-       CheckSupportedSwitch("a3", _fiInfo->fMMOptimize);\r
-       CheckSupportedSwitch("a4", _fiInfo->fEncryptHeader);\r
-       CheckSupportedSwitch("a5", _fiInfo->fEncryptPassword);\r
-       CheckSupportedSwitch("a6", _fiInfo->fEncryptKeyFile);\r
-       CheckSupportedSwitch("a7", _fiInfo->fMultiVolume);\r
-       CheckSupportedSwitch("a8", _fiInfo->fCompressHeader);\r
-\r
-       _fiInfo->nCompressLevelMin  = GetNumValue(xmlLibrary, wxT("level-min"));\r
-       _fiInfo->nCompressLevelMax  = GetNumValue(xmlLibrary, wxT("level-max"));\r
-       _fiInfo->nRecoveryRecordMin = GetNumValue(xmlLibrary, wxT("rr-min"));\r
-       _fiInfo->nRecoveryRecordMax = GetNumValue(xmlLibrary, wxT("rr-max"));\r
-}\r
index 13c67bd..b365a2a 100644 (file)
@@ -58,10 +58,10 @@ wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex)
        return (n == NULL || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex);\r
 }\r
 \r
-long myGetAttributeInt(wxXmlNode * n, const wxString & szValue, long nDefaultValue)\r
+wxULongLong_t myGetAttributeInt(wxXmlNode * n, const wxString & szValue, wxULongLong_t nDefaultValue, int nBase)\r
 {\r
-       long l;\r
-       n->GetAttribute(szValue, wxString::Format(wxT("%d"), nDefaultValue)).ToLong(& l, 16);\r
+       wxULongLong_t l;\r
+       n->GetAttribute(szValue, wxString::Format(wxString("%" wxLongLongFmtSpec "u"), nDefaultValue)).ToULongLong(& l, nBase);\r
        return l;\r
 }\r
 \r
index 9354f78..95f4d67 100644 (file)
@@ -39,7 +39,7 @@ bool myIsLib(wxXmlNode * n);
 wxXmlNode * myGetFirstLib(wxXmlDocument * xmlDoc, int nLibIndex = 0);\r
 wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex = 0);\r
 \r
-long myGetAttributeInt( wxXmlNode * n, const wxString & szValue, long nDefaultValue = 0);\r
+wxULongLong_t myGetAttributeInt( wxXmlNode * n, const wxString & szValue, wxULongLong_t nDefaultValue = 0, int nBase = 10);\r
 bool myGetAttributeBool(wxXmlNode * n, const wxString & szValue, bool bDefaultValue = false);\r
 void MakeFormatInfo(wxXmlNode * n, const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxULongLong_t nId);\r
 \r
index 447eea7..755c32b 100644 (file)
@@ -748,7 +748,7 @@ int __stdcall OpenArchive
        for (g_LibInfo.nLibIndex = 0; g_LibInfo.nLibIndex < 300 && xmlLibrary != NULL; g_LibInfo.nLibIndex++)\r
        {\r
                // ライブラリをロード。\r
-               const GUID guid = {0x23170F69, 0x40C1, 0x278A, {0x10, 0x00, 0x00, 0x01, 0x10, myGetAttributeInt(xmlLibrary, wxT("name")), 0x00, 0x00}};\r
+               const GUID guid = {0x23170F69, 0x40C1, 0x278A, {0x10, 0x00, 0x00, 0x01, 0x10, myGetAttributeInt(xmlLibrary, wxT("name"), 0, 16), 0x00, 0x00}};\r
                if (((unsigned int (__stdcall *)(const GUID *, const GUID *, void * *)) g_LibInfo.fpProc)(& guid, & IID_IInArchive, (void **) & hArc) != S_OK)\r
                {\r
                        xmlLibrary = myGetNextLib(xmlLibrary);\r
@@ -930,7 +930,7 @@ int __stdcall Command
 \r
                // エンジンを読み込み。\r
                IOutArchive * hArc;\r
-               const GUID guid = {0x23170F69, 0x40C1, 0x278A, {0x10, 0x00, 0x00, 0x01, 0x10, myGetAttributeInt(& g_LibInfo.node, wxT("name")), 0x00, 0x00}};\r
+               const GUID guid = {0x23170F69, 0x40C1, 0x278A, {0x10, 0x00, 0x00, 0x01, 0x10, myGetAttributeInt(& g_LibInfo.node, wxT("name"), 0, 16), 0x00, 0x00}};\r
                if (((unsigned int (__stdcall *)(const GUID *, const GUID *, void **)) g_LibInfo.fpProc)(& guid, & IID_IOutArchive, (void **) & hArc) != S_OK)\r
                {\r
                        return TPI_ERROR_ARC_UNSUPPORTED;\r
index db91e72..20eaa89 100644 (file)
@@ -26,6 +26,7 @@
 #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/dynlib.h>\r
 #include <wx/config.h>\r
 #include <wx/stdpaths.h>\r
@@ -600,62 +601,45 @@ int __stdcall GetPluginInformation
 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/calLibrary.xml"));\r
-       // 一気に先頭のライブラリの情報を取得。\r
-       wxXmlNode * xmlLibrary = config.GetRoot()->GetChildren();\r
-\r
+       static wxXmlDocument xmlDoc(myMakeXMLName(wxT("calLibrary")));\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("calLibrary"), _fiInfo, xmlLibrary, s_nFileId++);\r
-\r
+       MakeFormatInfo(xmlLibrary, wxT("calLibrary"), _fiInfo, s_nFileId++);\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/calLibrary.xml"));\r
-       if (! config.IsOk())\r
-       {\r
-               return TPI_ERROR_UNDEFINED;\r
-       }\r
-       // 一気に先頭のライブラリの情報を取得。\r
-       wxXmlNode * xmlLibrary = config.GetRoot()->GetChildren();\r
+       wxXmlDocument xmlDoc(myMakeXMLName(wxT("calLibrary")));\r
+       wxXmlNode * xmlLibrary;\r
 \r
        // 対象が存在するならば対応するライブラリを調査、\r
        // 対象が存在しないならば指示されたライブラリをロード。\r
        ::RemoveCwdFromSearchPath();\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
@@ -668,35 +652,36 @@ int __stdcall LoadPlugin
                        return TPI_ERROR_U_LOAD_LIBRARY;\r
                }\r
                g_LibInfo.szPrefix = xmlLibrary->GetAttribute(wxT("prefix"), wxEmptyString);\r
-               g_LibInfo.fUnicode = xmlLibrary->GetAttribute(wxT("unicode"), wxT("0")) == wxT("1");\r
+               g_LibInfo.fUnicode = myGetAttributeBool(xmlLibrary, wxT("unicode"));\r
                g_LibInfo.node = * xmlLibrary;\r
+               g_LibInfo.nLibIndex = _nTypeId;\r
 \r
                // 代替ライブラリもロード。ロードできなくてもエラーにはしない。\r
                g_LibInfoAlt.szPrefix = xmlLibrary->GetAttribute(wxT("prefix-alt"), wxEmptyString);\r
-               g_LibInfoAlt.fUnicode = xmlLibrary->GetAttribute(wxT("unicode-alt"), wxT("0")) == wxT("1");\r
+               g_LibInfoAlt.fUnicode = myGetAttributeBool(xmlLibrary, wxT("unicode-alt"));\r
                g_LibInfoAlt.hLib = ::LoadLibrary(xmlLibrary->GetAttribute(wxT("name-alt"), wxEmptyString).wchar_str());\r
-\r
                return TPI_ERROR_SUCCESS;\r
        }\r
 \r
        // 無限ループに陥らないよう上限を設定。\r
-       for (g_LibInfo.nLibIndex = 0; g_LibInfo.nLibIndex < 300 && xmlLibrary != NULL && xmlLibrary->GetName() == wxT("library"); g_LibInfo.nLibIndex++)\r
+       xmlLibrary = myGetFirstLib(& xmlDoc);\r
+       for (g_LibInfo.nLibIndex = 0; g_LibInfo.nLibIndex < 300 && xmlLibrary != NULL; g_LibInfo.nLibIndex++)\r
        {\r
                // ライブラリをロード。\r
                g_LibInfo.hLib = ::LoadLibrary(xmlLibrary->GetAttribute(wxT("name"), wxEmptyString).wchar_str());\r
                if (g_LibInfo.hLib == NULL)\r
                {\r
-                       xmlLibrary = xmlLibrary->GetNext();\r
+                       xmlLibrary = myGetNextLib(xmlLibrary);\r
                        continue;\r
                }\r
                g_LibInfo.szPrefix = xmlLibrary->GetAttribute(wxT("prefix"), wxEmptyString);\r
-               g_LibInfo.fUnicode = xmlLibrary->GetAttribute(wxT("unicode"), wxT("0")) == wxT("1");\r
+               g_LibInfo.fUnicode = myGetAttributeBool(xmlLibrary, wxT("unicode"));\r
+               g_LibInfo.node = * xmlLibrary;\r
 \r
                // 代替ライブラリもロード。ロードできなくてもエラーにはしない。\r
                g_LibInfoAlt.szPrefix = xmlLibrary->GetAttribute(wxT("prefix-alt"), wxEmptyString);\r
-               g_LibInfoAlt.fUnicode = xmlLibrary->GetAttribute(wxT("unicode-alt"), wxT("0")) == wxT("1");\r
+               g_LibInfoAlt.fUnicode = myGetAttributeBool(xmlLibrary, wxT("unicode-alt"));\r
                g_LibInfoAlt.hLib = ::LoadLibrary(xmlLibrary->GetAttribute(wxT("name-alt"), wxEmptyString).wchar_str());\r
-               g_LibInfo.node = * xmlLibrary;\r
 \r
                // Unicodeモードに設定。\r
                FARPROC fpProc = ::GetAPIAddress("SetUnicodeMode", false);\r
@@ -713,11 +698,10 @@ int __stdcall LoadPlugin
                {\r
                        return TPI_ERROR_SUCCESS;\r
                }\r
-\r
                ::FreeLibrary(g_LibInfo.hLib);\r
-               xmlLibrary = xmlLibrary->GetNext();\r
+               ::FreeLibrary(g_LibInfoAlt.hLib);\r
+               xmlLibrary = myGetNextLib(xmlLibrary);\r
        }\r
-\r
        return TPI_ERROR_U_LOAD_LIBRARY;\r
 }\r
 \r
@@ -996,7 +980,7 @@ int __stdcall GetArchiveInformation
        _aiInfo->fSFX = fpProc != NULL && ((int (__stdcall *)(void *)) fpProc)(_hArchive) > 0;\r
 \r
        // 形式に関する情報を取得。\r
-       MakeFormatInfo(wxT("calLibrary"), & _aiInfo->fiInfo, & g_LibInfo.node, 0);\r
+       MakeFormatInfo(& g_LibInfo.node, wxT("calLibrary"), & _aiInfo->fiInfo, 0);\r
 \r
        return TPI_ERROR_SUCCESS;\r
 }\r
@@ -1049,8 +1033,8 @@ int __stdcall Command
        // コマンドライン・レスポンスファイル作成。\r
        wxString\r
                szResponceFileName = g_LibInfo.fRunning ?\r
-                       MakeResponceFile(_szFiles, g_LibInfo.node.GetAttribute(   wxT("quote-resp"), wxT("1")) == wxT("1"), g_LibInfo.fUnicode) :\r
-                       MakeResponceFile(_szFiles, g_LibInfoAlt.node.GetAttribute(wxT("quote-resp"), wxT("1")) == wxT("1"), g_LibInfoAlt.fUnicode),\r
+                       MakeResponceFile(_szFiles, myGetAttributeBool(& g_LibInfo.node,    wxT("quote-resp"), true), g_LibInfo.fUnicode) :\r
+                       MakeResponceFile(_szFiles, myGetAttributeBool(& g_LibInfoAlt.node, wxT("quote-resp"), true), g_LibInfoAlt.fUnicode),\r
                szCommandLineSend  = MakeCommandLineSend(szCommandLine, _szArcName, _swInfo, _szFiles, szResponceFileName);\r
 \r
        // コマンドライン実行。\r
index aa4596a..0361d50 100644 (file)
                                />\r
                        </FileConfiguration>\r
                </File>\r
+               <File\r
+                       RelativePath="..\..\common\library\xmldoc.cpp"\r
+                       >\r
+               </File>\r
        </Files>\r
        <Globals>\r
        </Globals>\r
index 5288704..675864b 100644 (file)
@@ -138,9 +138,9 @@ int myExecute(const wxString & szCommandLine, wxString * szOutput, const wxStrin
 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
@@ -354,7 +354,7 @@ int __stdcall GetFileInformation
                }\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
@@ -452,7 +452,7 @@ int __stdcall Command
 \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
index 6a6843e..e321e5b 100644 (file)
                                />\r
                        </FileConfiguration>\r
                </File>\r
+               <File\r
+                       RelativePath="..\..\common\library\xmldoc.cpp"\r
+                       >\r
+               </File>\r
        </Files>\r
        <Globals>\r
        </Globals>\r