From 3a2c74069fe0e7da8b8dc577c5c9ccfba9e69cf0 Mon Sep 17 00:00:00 2001 From: sirakaba Date: Wed, 17 Nov 2010 14:00:07 +0000 Subject: [PATCH] =?utf8?q?=E5=85=B1=E9=80=9A=E3=81=AExml=E5=87=A6=E7=90=86?= =?utf8?q?=E9=96=A2=E6=95=B0=E7=BE=A4=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/tpi/tpi@437 9df91469-1e22-0410-86e7-ea8537beb833 --- src/common/library/xmldoc.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++ src/common/library/xmldoc.h | 50 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 src/common/library/xmldoc.cpp create mode 100644 src/common/library/xmldoc.h diff --git a/src/common/library/xmldoc.cpp b/src/common/library/xmldoc.cpp new file mode 100644 index 0000000..13c67bd --- /dev/null +++ b/src/common/library/xmldoc.cpp @@ -0,0 +1,118 @@ +/******************************************************************************* + TPI - flexible but useless plug-in framework. + Copyright (C) 2002-2009 Silky + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + $Id: library.cpp 371 2010-10-02 03:17:45Z sirakaba $ +*******************************************************************************/ + +//****************************************************************************** +// Includes +//****************************************************************************** + +#include "xmldoc.h" + +//****************************************************************************** +// XML処理関数 +//****************************************************************************** + +bool myIsLib(wxXmlNode * n) +{ + return ( + n->GetName() == wxT("library") + && ! myGetAttributeBool(n, wxT("disable")) +#ifdef __WINDOWS__ + && ! myGetAttributeBool(n, wxT("disable-win")) +#else + && ! myGetAttributeBool(n, wxT("disable-lin")) +#endif + ); +} + +wxXmlNode * myGetFirstLib(wxXmlDocument * xmlDoc, int nLibIndex) +{ + if (! xmlDoc->IsOk()) + { + return NULL; + } + wxXmlNode * n = xmlDoc->GetRoot()->GetChildren(); + return (n == NULL || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex); +} + +wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex) +{ + n = n->GetNext(); + return (n == NULL || myIsLib(n)) ? (nLibIndex <= 0 ? n : myGetNextLib(n, nLibIndex - 1)) : myGetNextLib(n, nLibIndex); +} + +long myGetAttributeInt(wxXmlNode * n, const wxString & szValue, long nDefaultValue) +{ + long l; + n->GetAttribute(szValue, wxString::Format(wxT("%d"), nDefaultValue)).ToLong(& l, 16); + return l; +} + +bool myGetAttributeBool(wxXmlNode * n, const wxString & szValue, bool bDefaultValue) +{ + return myGetAttributeInt(n, szValue, bDefaultValue ? 1 : 0) != 0; +} + +#define CheckSupportedCommand(attr, value) if (n->HasAttribute(wxT(attr)) || n->HasAttribute(wxT(attr) wxT("-alt"))) _fiInfo->eSupportedCommand |= value +#define CheckSupportedSwitch(var, value) value = szCmdLine.Find(wxT(var)) != wxNOT_FOUND + +void MakeFormatInfo(wxXmlNode * n, const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxULongLong_t nId) +{ + _fiInfo->fArchive = myGetAttributeBool(n, wxT("archive"), true); + _fiInfo->szTypeName = n->GetAttribute(wxT("typename"), wxEmptyString); + _fiInfo->szSuffix = n->GetAttribute(wxT("suffix"), wxEmptyString); + _fiInfo->szEngineName = n->GetAttribute(wxT("name"), wxEmptyString); + _fiInfo->szTPIName = szTPIName; + _fiInfo->nTypeId = nId; + + // 対応コマンドを調査。 + CheckSupportedCommand("create", TPI_COMMAND_CREATE); + CheckSupportedCommand("add", TPI_COMMAND_ADD); + CheckSupportedCommand("extract",TPI_COMMAND_EXTRACT); + CheckSupportedCommand("delete", TPI_COMMAND_DELETE); + CheckSupportedCommand("update", TPI_COMMAND_UPDATE); + CheckSupportedCommand("test", TPI_COMMAND_TEST); + CheckSupportedCommand("repair", TPI_COMMAND_REPAIR); + CheckSupportedCommand("move", TPI_COMMAND_MOVE); + CheckSupportedCommand("sfx", TPI_COMMAND_SFX); + CheckSupportedCommand("unsfx", TPI_COMMAND_UNSFX); + + // 対応スイッチを調査。 + wxString szCmdLine = + n->HasAttribute(wxT("create")) ? n->GetAttribute(wxT("create"), wxEmptyString) : + n->HasAttribute(wxT("create-alt")) ? n->GetAttribute(wxT("create-alt"), wxEmptyString) : + n->HasAttribute(wxT("extract")) ? n->GetAttribute(wxT("extract"), wxEmptyString) : + n->HasAttribute(wxT("extract-alt")) ? n->GetAttribute(wxT("extract-alt"), wxEmptyString) : + (wxString) wxEmptyString; + CheckSupportedSwitch("96", _fiInfo->fComment); + CheckSupportedSwitch("a1", _fiInfo->fSFX); + CheckSupportedSwitch("a2", _fiInfo->fSolid); + CheckSupportedSwitch("a3", _fiInfo->fMMOptimize); + CheckSupportedSwitch("a4", _fiInfo->fEncryptHeader); + CheckSupportedSwitch("a5", _fiInfo->fEncryptPassword); + CheckSupportedSwitch("a6", _fiInfo->fEncryptKeyFile); + CheckSupportedSwitch("a7", _fiInfo->fMultiVolume); + CheckSupportedSwitch("a8", _fiInfo->fCompressHeader); + + _fiInfo->nCompressLevelMin = myGetAttributeInt(n, wxT("level-min")); + _fiInfo->nCompressLevelMax = myGetAttributeInt(n, wxT("level-max")); + _fiInfo->nRecoveryRecordMin = myGetAttributeInt(n, wxT("rr-min")); + _fiInfo->nRecoveryRecordMax = myGetAttributeInt(n, wxT("rr-max")); +} diff --git a/src/common/library/xmldoc.h b/src/common/library/xmldoc.h new file mode 100644 index 0000000..9354f78 --- /dev/null +++ b/src/common/library/xmldoc.h @@ -0,0 +1,50 @@ +/******************************************************************************* + TPI - flexible but useless plug-in framework. + Copyright (C) 2002-2009 Silky + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + $Id: library.h 398 2010-10-30 11:07:43Z sirakaba $ +*******************************************************************************/ + +//****************************************************************************** +// Includes +//****************************************************************************** + +#include "../header/plugin.h" +#include +#include +#ifndef WXWIN_COMPATIBILITY_2_8 +#define GetAttribute GetPropVal +#define HasAttribute HasProp +#endif + +//****************************************************************************** +// XMLˆ—ŠÖ” +//****************************************************************************** + +bool myIsLib(wxXmlNode * n); +wxXmlNode * myGetFirstLib(wxXmlDocument * xmlDoc, int nLibIndex = 0); +wxXmlNode * myGetNextLib(wxXmlNode * n, int nLibIndex = 0); + +long myGetAttributeInt( wxXmlNode * n, const wxString & szValue, long nDefaultValue = 0); +bool myGetAttributeBool(wxXmlNode * n, const wxString & szValue, bool bDefaultValue = false); +void MakeFormatInfo(wxXmlNode * n, const wxString & szTPIName, TPI_FORMATINFO * _fiInfo, wxULongLong_t nId); + +wxString inline myMakeXMLName(const wxString & szFile) +{ + wxStandardPaths p; + return wxPathOnly(p.GetExecutablePath()) + wxT("/lib/") + szFile + wxT(".xml"); +} -- 2.11.0