OSDN Git Service

C++11のauto, nullptrを導入。
[tpi/lychee.git] / src / common / library / xmldoc.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id: library.cpp 371 2010-10-02 03:17:45Z sirakaba $\r
20 *******************************************************************************/\r
21 \r
22 //******************************************************************************\r
23 //    Includes\r
24 //******************************************************************************\r
25 \r
26 #include "xmldoc.h"\r
27 \r
28 //******************************************************************************\r
29 //    XML処理関数\r
30 //******************************************************************************\r
31 \r
32 bool myIsLib(wxXmlNode * n)\r
33 {\r
34         return (\r
35                 n->GetName() == wxT("library")\r
36                 && ! myGetAttributeBool(n, wxT("disable"))\r
37 #ifdef __WINDOWS__\r
38                 && ! myGetAttributeBool(n, wxT("disable-win"))\r
39 #else\r
40                 && ! myGetAttributeBool(n, wxT("disable-lin"))\r
41 #endif\r
42                 );\r
43 }\r
44 \r
45 wxXmlNode * myGetFirstLib(wxXmlDocument * xmlDoc, int nLibIndex)\r
46 {\r
47         if (! xmlDoc->IsOk())\r
48         {\r
49                 return nullptr;\r
50         }\r
51         wxXmlNode * n = xmlDoc->GetRoot()->GetChildren();\r
52         return (n == nullptr || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex);\r
53 }\r
54 \r
55 wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex)\r
56 {\r
57         n = n->GetNext();\r
58         return (n == nullptr || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex);\r
59 }\r
60 \r
61 wxULongLong_t myGetAttributeInt(wxXmlNode * n, const wxString & szValue, wxULongLong_t nDefaultValue, int nBase)\r
62 {\r
63         wxULongLong_t l;\r
64         n->GetAttribute(szValue, wxString::Format(wxString("%" wxLongLongFmtSpec "u"), nDefaultValue)).ToULongLong(& l, nBase);\r
65         return l;\r
66 }\r
67 \r
68 bool myGetAttributeBool(wxXmlNode * n, const wxString & szValue, bool bDefaultValue)\r
69 {\r
70         return myGetAttributeInt(n, szValue, bDefaultValue ? 1 : 0) != 0;\r
71 }\r
72 \r
73 #define CheckSupportedCommand(attr, value) if (n->HasAttribute(wxT(attr)) || n->HasAttribute(wxT(attr) wxT("-alt"))) _fiInfo->eSupportedCommand |= value\r
74 #define CheckSupportedSwitch(var,   value) value = szCmdLine.Find(wxT(var)) != wxNOT_FOUND\r
75 \r
76 void MakeFormatInfo(wxXmlNode * n, const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxULongLong_t nId)\r
77 {\r
78         _fiInfo->fArchive       = myGetAttributeBool(n, wxT("archive"), true);\r
79         _fiInfo->szTypeName     = n->GetAttribute(wxT("typename"), wxEmptyString);\r
80         _fiInfo->szSuffix       = n->GetAttribute(wxT("suffix"),   wxEmptyString);\r
81         _fiInfo->szEngineName   = n->GetAttribute(wxT("name"),     wxEmptyString);\r
82         _fiInfo->szTPIName      = szTPIName;\r
83         _fiInfo->nTypeId        = nId;\r
84 \r
85         // 対応コマンドを調査。\r
86         CheckSupportedCommand("create", TPI_COMMAND_CREATE);\r
87         CheckSupportedCommand("add",    TPI_COMMAND_ADD);\r
88         CheckSupportedCommand("extract",TPI_COMMAND_EXTRACT);\r
89         CheckSupportedCommand("delete", TPI_COMMAND_DELETE);\r
90         CheckSupportedCommand("update", TPI_COMMAND_UPDATE);\r
91         CheckSupportedCommand("test",   TPI_COMMAND_TEST);\r
92         CheckSupportedCommand("repair", TPI_COMMAND_REPAIR);\r
93         CheckSupportedCommand("move",   TPI_COMMAND_MOVE);\r
94         CheckSupportedCommand("sfx",    TPI_COMMAND_SFX);\r
95         CheckSupportedCommand("unsfx",  TPI_COMMAND_UNSFX);\r
96 \r
97         // 対応スイッチを調査。\r
98         wxString szCmdLine =\r
99                 n->HasAttribute(wxT("create"))      ? n->GetAttribute(wxT("create"),      wxEmptyString) :\r
100                 n->HasAttribute(wxT("create-alt"))  ? n->GetAttribute(wxT("create-alt"),  wxEmptyString) :\r
101                 n->HasAttribute(wxT("extract"))     ? n->GetAttribute(wxT("extract"),     wxEmptyString) :\r
102                 n->HasAttribute(wxT("extract-alt")) ? n->GetAttribute(wxT("extract-alt"), wxEmptyString) :\r
103                 (wxString) wxEmptyString;\r
104         CheckSupportedSwitch("96", _fiInfo->fComment);\r
105         CheckSupportedSwitch("a1", _fiInfo->fSFX);\r
106         CheckSupportedSwitch("a2", _fiInfo->fSolid);\r
107         CheckSupportedSwitch("a3", _fiInfo->fMMOptimize);\r
108         CheckSupportedSwitch("a4", _fiInfo->fEncryptHeader);\r
109         CheckSupportedSwitch("a5", _fiInfo->fEncryptPassword);\r
110         CheckSupportedSwitch("a6", _fiInfo->fEncryptKeyFile);\r
111         CheckSupportedSwitch("a7", _fiInfo->fMultiVolume);\r
112         CheckSupportedSwitch("a8", _fiInfo->fCompressHeader);\r
113 \r
114         _fiInfo->nCompressLevelMin  = myGetAttributeInt(n, wxT("level-min"));\r
115         _fiInfo->nCompressLevelMax  = myGetAttributeInt(n, wxT("level-max"));\r
116         _fiInfo->nRecoveryRecordMin = myGetAttributeInt(n, wxT("rr-min"));\r
117         _fiInfo->nRecoveryRecordMax = myGetAttributeInt(n, wxT("rr-max"));\r
118 }\r