[xiph-commits] r16706 - trunk/oggdsf/src/lib/helper/common
cristianadam at svn.xiph.org
cristianadam at svn.xiph.org
Sun Nov 15 14:37:37 PST 2009
Author: cristianadam
Date: 2009-11-15 14:37:37 -0800 (Sun, 15 Nov 2009)
New Revision: 16706
Added:
trunk/oggdsf/src/lib/helper/common/xmlsettings.h
Modified:
trunk/oggdsf/src/lib/helper/common/Log.h
trunk/oggdsf/src/lib/helper/common/util.h
Log:
used msxml instead of pugixml, the latter doesn't work on windows mobile.
Modified: trunk/oggdsf/src/lib/helper/common/Log.h
===================================================================
--- trunk/oggdsf/src/lib/helper/common/Log.h 2009-11-15 22:35:31 UTC (rev 16705)
+++ trunk/oggdsf/src/lib/helper/common/Log.h 2009-11-15 22:37:37 UTC (rev 16706)
@@ -115,7 +115,7 @@
template <typename T>
LogLevel& LogT<T>::ReportingLevel()
{
- static LogLevel reportingLevel = logDEBUG4;
+ static LogLevel reportingLevel = logNONE;
return reportingLevel;
}
Modified: trunk/oggdsf/src/lib/helper/common/util.h
===================================================================
--- trunk/oggdsf/src/lib/helper/common/util.h 2009-11-15 22:35:31 UTC (rev 16705)
+++ trunk/oggdsf/src/lib/helper/common/util.h 2009-11-15 22:37:37 UTC (rev 16706)
@@ -1,3 +1,34 @@
+//===========================================================================
+//Copyright (C) 2009 Cristian Adam
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Cristian Adam nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+
#ifndef UTIL_H
#define UTIL_H
@@ -2,17 +33,14 @@
#include <shlobj.h>
-#include <fstream>
-#include "pugixml/pugixml.hpp"
+#include "common/XmlSettings.h"
namespace util
{
- inline void ConfigureLog(HANDLE hModule)
+ inline std::wstring GetModuleName(HANDLE hModule)
{
- using namespace std;
- using namespace pugi;
-
- // Obtain the module name
- wstring moduleFileName;
+ std::wstring moduleFileName;
moduleFileName.resize(MAX_PATH);
- int chars = ::GetModuleFileName(static_cast<HMODULE>(hModule), &*moduleFileName.begin(), moduleFileName.size());
+ int chars = ::GetModuleFileName(static_cast<HMODULE>(hModule),
+ &*moduleFileName.begin(), moduleFileName.size());
+
moduleFileName.resize(chars);
@@ -22,43 +50,71 @@
size_t lastBackslash = moduleFileName.rfind(L'\\') + 1;
size_t lastDot = moduleFileName.rfind(L'.');
- wstring moduleName = moduleFileName.substr(lastBackslash, lastDot - lastBackslash);
+ return moduleFileName.substr(lastBackslash, lastDot - lastBackslash);
+ }
- // Obtain the user data configuration directory
- wstring configLocation;
+ inline std::wstring GetConfigurationPath()
+ {
+ std::wstring configLocation;
configLocation.resize(MAX_PATH);
+
::SHGetSpecialFolderPath(0, &*configLocation.begin(), CSIDL_APPDATA, false);
+
configLocation.resize(wcslen(configLocation.c_str()));
+ configLocation += L"\\Xiph.Org\\Ogg Codecs";
- configLocation += L"\\Xiph.org\\oggcodecs";
+ return configLocation;
+ }
- // Open the settings xml and read the log configuration
- wstring xmlFileName = configLocation;
- xmlFileName += L"\\settings.xml";
+ struct ComInitializer
+ {
+ ComInitializer()
+ {
+ ::CoInitializeEx(0, COINIT_APARTMENTTHREADED);
+ }
+ ~ComInitializer()
+ {
+ ::CoUninitialize();
+ }
+ };
- ifstream xmlConfigStream;
- xmlConfigStream.open(xmlFileName.c_str());
+ inline HMODULE& GetHModule()
+ {
+ static HMODULE module = 0;
+ return module;
+ }
- xml_document doc;
- doc.load(xmlConfigStream);
+ inline void ConfigureLogSettings()
+ {
+ std::wstring moduleName = util::GetModuleName(util::GetHModule());
+ std::wstring configurationPath = util::GetConfigurationPath();
- stringstream queryString;
- queryString << "/Configuration/Module[@Name=\"" << CW2A(moduleName.c_str()) << "\"]/Log";
+ std::wstring xmlConfigurationFile = configurationPath;
+ xmlConfigurationFile+= L"\\settings.xml";
- xpath_query query(queryString.str().c_str());
+ std::wstring levelString;
- wstring levelString = CA2W(doc.select_single_node(query).node().attribute("Level").value());
- Log::ReportingLevel() = Log::FromString(levelString);
+ XmlSettings settings;
+ if (settings.Load(xmlConfigurationFile, moduleName))
+ {
+ levelString = settings.GetAttributeValue(L"Log", L"Level");
+ }
- if (Log::ReportingLevel() != logNONE)
+ if (!levelString.empty())
{
- wstring logFileName = configLocation;
- logFileName += L"\\";
- logFileName += moduleName + L".log";
-
- Log::Stream(logFileName);
+ Log::ReportingLevel() = Log::FromString(levelString);
+
+ if (Log::ReportingLevel() != logNONE)
+ {
+ std::wstring logFileName = configurationPath;
+ logFileName += L"\\";
+ logFileName += moduleName + L".log";
+
+ Log::Stream(logFileName);
+ }
}
}
+
}
#endif // UTIL_H
\ No newline at end of file
Added: trunk/oggdsf/src/lib/helper/common/xmlsettings.h
===================================================================
--- trunk/oggdsf/src/lib/helper/common/xmlsettings.h (rev 0)
+++ trunk/oggdsf/src/lib/helper/common/xmlsettings.h 2009-11-15 22:37:37 UTC (rev 16706)
@@ -0,0 +1,115 @@
+//===========================================================================
+//Copyright (C) 2009 Cristian Adam
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Cristian Adam nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+
+#ifndef XMLSETTINGS_H
+#define XMLSETTINGS_H
+
+#include <MsXml.h>
+#include <string>
+
+class XmlSettings
+{
+ CComPtr<IXMLDOMDocument> m_xmlDoc;
+ std::wstring m_moduleName;
+
+public:
+
+ XmlSettings()
+ {
+ m_xmlDoc.CoCreateInstance(CLSID_DOMDocument);
+ }
+
+ virtual ~XmlSettings()
+ {
+ }
+
+ bool Load(const std::wstring& xmlFileName, const std::wstring& moduleName)
+ {
+ using std::wstringstream;
+ using std::wstring;
+
+ m_moduleName = moduleName;
+
+ if (!m_xmlDoc)
+ {
+ return false;
+ }
+
+ VARIANT_BOOL isSuccessful = VARIANT_FALSE;
+ HRESULT hr = m_xmlDoc->load(CComVariant(xmlFileName.c_str()), &isSuccessful);
+
+ return SUCCEEDED(hr) && isSuccessful == VARIANT_TRUE;
+ }
+
+ std::wstring GetAttributeValue(const std::wstring& keyName, const std::wstring& attributeName)
+ {
+ std::wstring result;
+
+ std::wstringstream queryString;
+ queryString << L"/Configuration/Module[@Name=\"" << m_moduleName << L"\"]/" << keyName;
+
+ CComPtr<IXMLDOMNode> node;
+ HRESULT hr = m_xmlDoc->selectSingleNode(CComBSTR(queryString.str().c_str()), &node);
+ if (FAILED(hr) || !node)
+ {
+ return result;
+ }
+
+ CComPtr<IXMLDOMNamedNodeMap> attributesMap;
+ hr = node->get_attributes(&attributesMap);
+
+ if (FAILED(hr))
+ {
+ return result;
+ }
+
+ CComPtr<IXMLDOMNode> levelAttribute;
+ hr = attributesMap->getNamedItem(CComBSTR(attributeName.c_str()), &levelAttribute);
+
+ if (FAILED(hr))
+ {
+ return result;
+ }
+
+ CComVariant levelValue;
+ hr = levelAttribute->get_nodeValue(&levelValue);
+
+ if (FAILED(hr))
+ {
+ return result;
+ }
+
+ result = static_cast<wchar_t*>(CComBSTR(levelValue.bstrVal));
+ return result;
+ }
+};
+
+#endif // XMLSETTINGS_H
More information about the commits
mailing list