1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\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
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
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
19 $Id: library.cpp 371 2010-10-02 03:17:45Z sirakaba $
\r
20 *******************************************************************************/
\r
22 //******************************************************************************
\r
24 //******************************************************************************
\r
28 //******************************************************************************
\r
30 //******************************************************************************
\r
32 bool myIsLib(wxXmlNode * n)
\r
35 n->GetName() == wxT("library")
\r
36 && ! myGetAttributeBool(n, wxT("disable"))
\r
38 && ! myGetAttributeBool(n, wxT("disable-win"))
\r
40 && ! myGetAttributeBool(n, wxT("disable-lin"))
\r
45 wxXmlNode * myGetFirstLib(wxXmlDocument * xmlDoc, int nLibIndex)
\r
47 if (! xmlDoc->IsOk())
\r
51 wxXmlNode * n = xmlDoc->GetRoot()->GetChildren();
\r
52 return (n == NULL || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex);
\r
55 wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex)
\r
58 return (n == NULL || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex);
\r
61 long myGetAttributeInt(wxXmlNode * n, const wxString & szValue, long nDefaultValue)
\r
64 n->GetAttribute(szValue, wxString::Format(wxT("%d"), nDefaultValue)).ToLong(& l, 16);
\r
68 bool myGetAttributeBool(wxXmlNode * n, const wxString & szValue, bool bDefaultValue)
\r
70 return myGetAttributeInt(n, szValue, bDefaultValue ? 1 : 0) != 0;
\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
76 void MakeFormatInfo(wxXmlNode * n, const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxULongLong_t nId)
\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
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
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
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