/*
* SWbemQueryPropertiesLoader.h
* Copyright (c) 2012 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
#pragma once
#include <sol/Exception.h>
#include <sol/wmi/SWbemQueryProperties.h>
namespace SOL {
class SWbemQueryPropertiesLoader: public Object {
public:
SWbemQueryPropertiesLoader()
{
}
public:
bool load(__out SWbemQueryProperties& properties,
__in_opt const TCHAR* propertiesFile=NULL)
{
bool rc = false;
TCHAR filePath[1024];
memset(filePath, (TCHAR)0, SizeOf(filePath));
const TCHAR* DEFAULT_PROPERTIES_FILE_NAME = _T("Query.properties");
if (propertiesFile == NULL) {
TCHAR module[_MAX_PATH];
memset(module, (TCHAR)0, SizeOf(module));
GetModuleFileName(NULL, module, _MAX_PATH);
TCHAR* dot = strrchr(module, '.');
if (dot) {
*dot = '\0'; //NULL terminated hered
}
_stprintf(filePath, _T("%s.%s"), module, DEFAULT_PROPERTIES_FILE_NAME);
if (GetFileAttributes(filePath) == 0xffffffff) {
_bstr_t bstring = filePath;
throw Exception(E_INVALIDARG, "File not found:\"%s\" %s", (const char*)bstring, __FUNCTION__);
}
} else {
_stprintf(filePath, _T("%s"), propertiesFile);
}
if (GetFileAttributes(filePath) == 0xffffffff) {
_bstr_t bstring = filePath;
throw Exception(E_INVALIDARG, "Filenot found:\"%s\" %s", (const char*)bstring, __FUNCTION__);
} else {
rc = properties.load(filePath);
}
return rc;
}
};
}
|