diff options
Diffstat (limited to 'Common')
-rw-r--r-- | Common/CmptData.cpp | 200 | ||||
-rw-r--r-- | Common/CmptData.h | 49 | ||||
-rw-r--r-- | Common/ComponentArray.cpp | 281 | ||||
-rw-r--r-- | Common/ComponentArray.h | 80 | ||||
-rw-r--r-- | Common/ComponentData.cpp | 407 | ||||
-rw-r--r-- | Common/ComponentData.h | 111 | ||||
-rw-r--r-- | Common/ComponentHolder.cpp | 386 | ||||
-rw-r--r-- | Common/ComponentHolder.h | 104 | ||||
-rw-r--r-- | Common/Defines.h | 32 | ||||
-rw-r--r-- | Common/NightSec.h | 591 | ||||
-rw-r--r-- | Common/NightSecApp.cpp | 138 | ||||
-rw-r--r-- | Common/NightSecApp.h | 41 | ||||
-rw-r--r-- | Common/OneInstance.h | 63 | ||||
-rw-r--r-- | Common/PropPageHolder.cpp | 317 | ||||
-rw-r--r-- | Common/PropPageHolder.h | 89 | ||||
-rw-r--r-- | Common/events.h | 6 | ||||
-rw-r--r-- | Common/interfaces.cpp | 4 | ||||
-rw-r--r-- | Common/interfaces.h | 14 | ||||
-rw-r--r-- | Common/types.h | 10 |
19 files changed, 2923 insertions, 0 deletions
diff --git a/Common/CmptData.cpp b/Common/CmptData.cpp new file mode 100644 index 0000000..2fd8878 --- /dev/null +++ b/Common/CmptData.cpp @@ -0,0 +1,200 @@ +// ShutdownData.cpp: implementation of the CPropertyBagImpl class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "CmptData.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CPropertyBag::CPropertyBag() +{ + m_pBag = NULL; +} + +CPropertyBag::~CPropertyBag() +{ + m_pBag = NULL; +} + +HRESULT CPropertyBag::Initialize(IUnknown * pUnk) +{ + if(pUnk == NULL) + { + if(m_pBag != NULL) + { + m_pBag->Release(); + m_pBag = NULL; + return S_OK; + } + else + return E_UNEXPECTED; + } + + HRESULT hr; + + hr = pUnk->QueryInterface(IID_IPropertyBag, (void**) &m_pBag); + + if(FAILED(hr)) + m_pBag = NULL; + + return hr; + +} + +HRESULT CPropertyBag::Initialize(int cUnks, IUnknown** ppUnks) +{ + HRESULT hr = S_FALSE; + + for (UINT i = 0; i < cUnks; i++) + { + hr = Initialize(ppUnks[i]); + + if(SUCCEEDED(hr)) + return hr; + } + + return hr; +} + +int CPropertyBag::GetInt(const string& sKeyName, int nDefault) const +{ + if(m_pBag == NULL) + return nDefault; + + CComVariant var; + + if(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL))) + { + if(var.vt == VT_I4) + { + return var.lVal; + } + else + return nDefault; + } + else + { + return nDefault; + } +} + +string CPropertyBag::GetString(const string& sKeyName, const string& sDefault) const +{ + USES_CONVERSION; + + if(m_pBag == NULL) + return sDefault; + + CComVariant var; + string sRet; + + if(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL))) + { + if(var.vt == VT_BSTR) + { + sRet = OLE2T(var.bstrVal); + return sRet; + } + else + return sDefault; + } + else { + return sDefault; + } + + +} + +HRESULT CPropertyBag::WriteInt(const string& sKeyName, int nValue) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + + var.vt = VT_I4; + var.lVal = nValue; + + return m_pBag->Write(CComBSTR(sKeyName), &var); + +} + +HRESULT CPropertyBag::WriteString(const string& sKeyName, const string& sValue) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + CComBSTR bsVal(sValue); + + var.vt = VT_BSTR; + var.bstrVal = bsVal; + + return m_pBag->Write(CComBSTR(sKeyName), &var); +} + + +HRESULT CPropertyBag::DeleteProperty(const string& sKeyName) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + + var.Clear(); + + return m_pBag->Write(CComBSTR(sKeyName), &var); +} + +UINT CPropertyBag::GetStringSet(const string& sFormat, string_array& asData) const +{ + UINT nCnt = 0; + string sVal; + string sKeyName; + + // Format Key Name + sKeyName.format(sFormat, nCnt++); + + // Add URLs to List Box + while((sVal = GetString(sKeyName, NS_NO_KEY)) != NS_NO_KEY) + { + asData.push_back(sVal); + + // Format Key Name + sKeyName.format(sFormat, nCnt++); + } + + return --nCnt; +} + +UINT CPropertyBag::WriteStringSet(const string& sFormat, const string_array& asData) +{ + UINT nCnt = 0; // Number of URLs from Registry + string sKeyName; + + string_array::const_iterator iter = asData.begin(); + for(; iter != asData.end(); iter++) + { + sKeyName.format(sFormat, nCnt++); + WriteString(sKeyName, *iter); + } + + UINT nRet = nCnt - 1; + sKeyName.format(sFormat, nCnt++); + CComVariant var; + + while(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL)) && + var.vt != VT_EMPTY && var.vt != VT_NULL) + { + // Format Registry Key + DeleteProperty(sKeyName); + sKeyName.format(sFormat, nCnt++); + var.Clear(); + } + + return nRet; + +} diff --git a/Common/CmptData.h b/Common/CmptData.h new file mode 100644 index 0000000..985de2d --- /dev/null +++ b/Common/CmptData.h @@ -0,0 +1,49 @@ +// ShutdownData.h: interface for the CShutdownData class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(PROPERTYBAGIMPL_H__6CC5C4C0_1F0A_11D2_B2D4_0020182B97FC__INCLUDED_) +#define PROPERTYBAGIMPL_H__6CC5C4C0_1F0A_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +#define NS_NO_KEY _T("No Key") +#define NS_BACKUP_REG_SOURCE _T("Source%.4d") +#define NS_BACKUP_REG_DEST _T("Destination") +#define NS_BACKUP_REG_ENGINE _T("Engine") +#define NS_IGNORE_REG_EXT _T("Ignore%.4d") +#define NS_ENCRYPT_REG_FILES _T("Path%.4d") +#define NS_ENCRYPT_REG_DISABLE _T("Disable") +#define NS_ENCRYPT_REG_READONLY _T("ReadOnly") + +class CPropertyBag +{ + +public: + CPropertyBag(); + virtual ~CPropertyBag(); + + HRESULT DeleteProperty(const string& sKeyName); + HRESULT WriteString(const string& sKeyName, const string& sValue); + HRESULT WriteInt(const string& sKeyName, int nValue); + string GetString(const string& sKeyName, const string& sDefault) const; + int GetInt(const string& sKeyName, int nDefault) const; + + // Chooses the first IPropertyBag it finds + HRESULT Initialize(int cUnks, IUnknown** ppUnks); + HRESULT Initialize(IUnknown* pUnk); + + bool IsInitialized() + { return m_pBag != NULL; }; + + UINT GetStringSet(const string& sFormat, string_array& asData) const; + UINT WriteStringSet(const string& sFormat, const string_array& asData); + +// Data +protected: + IPropertyBag* m_pBag; +}; + +#endif // !defined(AFX_PROPERTYBAGIMPL_H__6CC5C4C0_1F0A_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Common/ComponentArray.cpp b/Common/ComponentArray.cpp new file mode 100644 index 0000000..7bab44c --- /dev/null +++ b/Common/ComponentArray.cpp @@ -0,0 +1,281 @@ +// ComponentArray.cpp: implementation of the CComponentArray class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "ComponentArray.h" +#include "defines.h" + +#include <algorithm> +using std::find; + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CComponentArray::CComponentArray() { } + +CComponentArray::~CComponentArray() +{ + UnloadComponents(); +} + +////////////////////////////////////////////////////////////////// +// LoadComponents from Registry (Public Function) +// +// returns number of components. + +UINT CComponentArray::LoadComponents() +{ + // Can only load if empty + ASSERT(empty()); + + // Make sure List of Installed Components is Loaded + LoadInstalledComponents(); + + + // Open Key + CRegKey regKey; + if(regKey.Create(HKEY_CURRENT_USER, NS_REG_COMPONENTS) + != ERROR_SUCCESS) + + return 0; + + // Enumerate Subkeys which should contain Component ID's (GetIDFromKey) + DWORD dwCnt = 0; + DWORD dwLoadedCnt = 0; + string sKeyName; + while(!RegEnumKey(regKey.m_hKey, dwCnt, sKeyName.get_buffer(MAX_PATH), MAX_PATH)) + { + sKeyName.release_buffer(); + + dwCnt++; + + // Add the Component + if(SUCCEEDED(AddComponent(sKeyName))) + dwLoadedCnt++; // Increment Return Value + } + + // Check if there's anymore that are Installed + // But the user didn't have previously loaded (CheckOffInstalledComponent) + while(!m_asInstalledComponents.empty()) + { + // Add the Component + if(SUCCEEDED(AddComponent(m_asInstalledComponents[0]))) + dwLoadedCnt++; + } + + // Remove All NULL Spaces in array as we put each component + // at location requested by registry + iterator iter = begin(); + for(int nCnt = 0; nCnt < size(); nCnt++) + { + while((*this)[nCnt] == NULL) + erase(begin() + nCnt); + } + + if(empty()) + return 0; + + // Move DOS Components to End of Array + CComponentHolder* pComponent = NULL; + CComponentHolder* pLastComp = at(size() - 1); + for(nCnt = 0; nCnt < size() && pComponent != pLastComp; nCnt++) + { + pComponent = at(nCnt); + + if(pComponent->GetType() == COMPONENT_DOS) + { + erase(begin() + nCnt); + push_back(pComponent); + } + } + + // Return Number of Components + return (UINT)dwLoadedCnt; +} + +////////////////////////////////////////////////////////////////// +// Loads the component into memory and adds it to array at +// location requested. + +HRESULT CComponentArray::AddComponent(const string& sKeyName) +{ + CComponentHolder* pComponent; + HRESULT hr; + + + // Get the Component ID from a Registry KeyName + // eg: 'NightSecurity.ClearInetCache' would come from 'NightSecurity.ClearInetCache 2' + string sID = GetIDFromKey(sKeyName); + + + // Load and Initialize Component + pComponent = new CComponentHolder; + hr = pComponent->Initialize(sID, NS_REG_COMPONENTS + (_T("\\") + sKeyName)); + + + // If Failed then return NULL + if(SUCCEEDED(hr)) + { + + // Get the Component's Position + int nPos = pComponent->GetPos(); + + + // Add at nPos + // If nPos is already used insert before + if(nPos < size()) + { + + if(at(nPos) == NULL) + at(nPos) = pComponent; + else + insert(begin() + nPos, pComponent); + + } + else + { + resize(nPos + 1, NULL); + at(nPos) = pComponent; + } + + + } + + // Check it off from Installed List + CheckOffInstalledComponent(sID); + + + return hr; +} + + +///////////////////////////////////////////////////////// +// LoadInstalledComponents : Loads list of installed +// components for access later on +// +UINT CComponentArray::LoadInstalledComponents() +{ + + // Open Key + CRegKey regKey; + if(regKey.Create(HKEY_LOCAL_MACHINE, NS_REG_INSTALLEDCOMPONENTS) + != ERROR_SUCCESS) + + return 0; + + + + // Enumerate Subkeys which should be the IDs of Components + DWORD dwCnt = 0; + string sKeyName; + while(!RegEnumKey(regKey.m_hKey, dwCnt, sKeyName.get_buffer(MAX_PATH), MAX_PATH)) + { + + sKeyName.release_buffer(); + + // Add to List + m_asInstalledComponents.push_back(sKeyName); + + dwCnt++; + } + + + // Return Number of Components + return (UINT)dwCnt; + +} + +////////////////////////////////////////////////////////////////// +// Checks off the component from the Installed Components list +// Loaded with Installed Components + +bool CComponentArray::CheckOffInstalledComponent(const string& sID) +{ + int nFound = -1; + + string_array::iterator iter; + iter = find(m_asInstalledComponents.begin(), + m_asInstalledComponents.end(), sID); + + // If we found one then remove it + // Have to remove it outside of loop or we mess up the + // Array Index + if(iter != m_asInstalledComponents.end()) + { + m_asInstalledComponents.erase(iter); + return true; + } + + // Couldn't Find + return false; +} + + +////////////////////////////////////////////////////////////////// +// Remove the components from memory + +UINT CComponentArray::UnloadComponents() +{ + int nCnt = 0; + + while(!empty()) + { + nCnt++; + + // First let it do it's Clean Up + at(0)->Release(); + // Then Delete it + delete at(0); + // Then Remove it from Array + erase(begin()); + } + + // Return Number of Components + return nCnt; +} + + +////////////////////////////////////////////////////////////////// +// Takes a Component registry key and extracts the Program ID +// ID should come before space in Key +// eg: 'NightSecurity.ClearInetCache' would come from 'NightSecurity.ClearInetCache 2' + +string CComponentArray::GetIDFromKey(const string& sKeyName) +{ + // ID should come before space in Key + // eg: 'NightSecurity.ClearInetCache' would come from 'NightSecurity.ClearInetCache 2' + + string::size_type pos = sKeyName.find(_T(' ')); + + // return first part + // find return string::npos if fails (which also means end of string) + return sKeyName.substr(0, pos); + +} + + +////////////////////////////////////////////////////////////////// +// Saves each components data to the Registry + +HRESULT CComponentArray::SaveComponentData() +{ + HRESULT hrRet = S_OK; + + // Ask Each Component to Save it's own Data + iterator iter = begin(); + for(; iter != end(); iter++) + { + + // CComponentHolder checks to make sure that the + // Components are loaded, so we don't have to + // include error checking here. + HRESULT hr = (*iter)->GetData()->Save(); + if(FAILED(hr)) + hrRet = hr; + + } + + return hrRet; +} diff --git a/Common/ComponentArray.h b/Common/ComponentArray.h new file mode 100644 index 0000000..892faae --- /dev/null +++ b/Common/ComponentArray.h @@ -0,0 +1,80 @@ +////////////////////////////////////////////////////////////////// +// +// ComponentArray.h: interface for the CComponentArray class. +// +// Class that holds all the components for the application +// Need to call LoadComponents before you can use them +// +// Derived from a vector so you can access the components each +// as it's own CComponentHolder, but takes care of the Loading +// and Unloading itself. +// +// 'Installed Components' are components that haven't been used +// yet by a user, but have been installed on the system. +// The Loading code first loops through all the user's components +// and then sees if it's missing anything that's installed but +// hasn't been used yet. +// +// The reason for a distiction between a Program ID and a Registry +// Key is to support multiple instances of components in the future +// if needed. Each component would be inited from it's own Key. The +// keys could also be used as Stream ID's in a OLE Storage etc... +// +////////////////////////////////////////////////////////////////////// + +#if !defined(COMPONENTARRAY_H__ADB16FE6_1B31_11D2_B2D4_0020182B97FC__INCLUDED_) +#define COMPONENTARRAY_H__ADB16FE6_1B31_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +#include "..\Common\ComponentHolder.h" + +#include <mystring.h> +#include <vector> +using std::vector; + +// An Array of CComponentHolder's with inbuilt Loading and Unloading + +typedef vector<CComponentHolder*> ArrayComponents; +typedef vector<string> string_array; +class CComponentArray + : public ArrayComponents +{ +public: + CComponentArray(); + virtual ~CComponentArray(); + +public: + + // Load Components from Registry + UINT LoadComponents(); + + // Remove Components from Memory + UINT UnloadComponents(); + + // Save Comoponents Data to Registry + HRESULT SaveComponentData(); + +protected: + + ///////////////////////////////////////////////////////// + // List of All Installed Components + // Used to Compare with User's Current Components + string_array m_asInstalledComponents; + + // Load List of All Installed Components + UINT LoadInstalledComponents(); + + // Called when Loading a Component + bool CheckOffInstalledComponent(const string& sID); + HRESULT AddComponent(const string& sID); + + // Gets the Component ID from a Registry KeyName + // eg: 'NightSecurity.ClearInetCache' would come from 'NightSecurity.ClearInetCache 2' + string GetIDFromKey(const string& sKeyName); + +}; + +#endif // !defined(COMPONENTARRAY_H__ADB16FE6_1B31_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Common/ComponentData.cpp b/Common/ComponentData.cpp new file mode 100644 index 0000000..5b4d75d --- /dev/null +++ b/Common/ComponentData.cpp @@ -0,0 +1,407 @@ +// ComponentData.cpp : implementation file +// + +#include "stdafx.h" +#include "ComponentData.h" +#include "types.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#ifdef _DEBUG + +void DumpVariant(VARIANT& var) +{ + USES_CONVERSION; + + switch(var.vt) + { + case VT_NULL: + ATLTRACE(_T("VT_NULL")); + break; + case VT_EMPTY: + ATLTRACE(_T("VT_EMPTY")); + break; + case VT_UI1: + ATLTRACE(_T("VT_UI1: ")); + ATLTRACE(_T("%u"), (int)var.bVal); + break; + case VT_I2: + ATLTRACE(_T("VT_I2: ")); + ATLTRACE(_T("%d"), (int)var.bVal); + break; + case VT_I4: + ATLTRACE(_T("VT_I4: ")); + ATLTRACE(_T("%d"), (int)var.bVal); + break; + case VT_R4: + ATLTRACE(_T("VT_R4: ")); + ATLTRACE(_T("%f"), (double)var.bVal); + break; + case VT_R8: + ATLTRACE(_T("VT_R8: ")); + ATLTRACE(_T("%f"), (double)var.bVal); + break; + case VT_BOOL: + ATLTRACE(_T("VT_BOOL: ")); + ATLTRACE(_T("%s"), var.boolVal ? _T("true") : _T("false")); + break; + case VT_ERROR: + ATLTRACE(_T("VT_ERROR: ")); + ATLTRACE(_T("%d"), var.scode); + break; + case VT_CY: + ATLTRACE(_T("VT_CY: ")); + ATLTRACE(_T("%d"), var.cyVal); + break; + case VT_DATE: + ATLTRACE(_T("VT_DATE ")); + break; + case VT_BSTR: + ATLTRACE(_T("VT_BSTR: ")); + ATLTRACE(_T("%s"), OLE2T(var.bstrVal)); + break; + case VT_UNKNOWN: + ATLTRACE(_T("VT_UNKNOWN: ")); + break; + default: + ATLTRACE(_T("VT_ Other")); + break; + } +} + +#define TRACEVARIANT(var) DumpVariant(var) + +#else + +#define TRACEVARIANT(var) ((void)0) +#endif + + + +///////////////////////////////////////////////////////////////////////////// +// CComponentData + + +CComponentData::CComponentData() +{ +} + +CComponentData::~CComponentData() +{ +} + +///////////////////////////////////////////////////////////////////////////// +// CComponentData message handlers + +HRESULT CComponentData::Initialize(const string & sKey) +{ + // Need a registry key to read from + if(sKey.empty()) + return E_INVALIDARG; + + m_sKey = sKey; + + return S_OK; + +} + + +////////////////////////////////////////////////////////////////// +// Does the actual saving to the Registry + +HRESULT CComponentData::Save(string sKey /* = "" */) +{ + ATLTRACE(_T("DATA SAVE\n==========\n")); + + long lRet = 0; + CRegKey regKey; + + + // Set to Internal Key if sKey Is Empty + if(sKey.empty()) sKey = m_sKey; + + + // Try and open Our Key + if((lRet = regKey.Create(HKEY_CURRENT_USER, sKey)) != ERROR_SUCCESS) + return HRESULT_FROM_WIN32(lRet); + + + // Now do actual saving + // Only support number and String types for now + DWORD dwData = 0; + + string_variant_map::iterator iter = m_mapValues.begin(); + + for( ;iter != m_mapValues.end(); iter++) + { + ATLTRACE(_T("Saving: %s -- Value: "), iter->first.c_str()); + TRACEVARIANT(iter->second); + ATLTRACE(_T("\n")); + + switch(iter->second.vt) + { + // Number Types + case VT_UI1: + case VT_I2: + case VT_I4: + case VT_R4: + case VT_R8: + case VT_CY: + + lRet = regKey.SetValue(iter->second.lVal, iter->first); +// ASSERT(lRet == ERROR_SUCCESS); + break; + + // It's a String + case VT_BSTR: + + lRet = regKey.SetValue(string(iter->second.bstrVal), iter->first); +// ASSERT(lRet == ERROR_SUCCESS); + break; + + + // Delete the Key if NULL or Empty value + case VT_NULL: + case VT_EMPTY: + + lRet = regKey.DeleteValue(iter->first); +// ASSERT(lRet == ERROR_SUCCESS); + break; + + default: + break; + + + + } + + } + + return S_OK; + +} + +////////////////////////////////////////////////////////////////// +// Passes the caller a IUnknown to the the underlying IPropertyBag + +/*IUnknown* CComponentData::GetIUnknown(bool bAddRef) +{ + // If asked not to increment then Release + if(bAddRef) + this->AddRef(); + + + return GetUnknown(); +} +*/ + +////////////////////////////////////////////////////////////////// +// Reads actual Value from Registry + +HRESULT CComponentData::Read(const string & sValName, VARIANT& varVal) +{ + // First Lookup the Value in the current map + string_variant_map::iterator iter = m_mapValues.find(sValName); + if(iter != m_mapValues.end()) + return ::VariantCopy(&varVal, &(iter->second)); + + + + // Make sure we are initialized with a key + if(m_sKey == "") + return E_UNEXPECTED; + + // Open Key + CRegKey regDataKey; + if(regDataKey.Create(HKEY_CURRENT_USER, m_sKey) == ERROR_SUCCESS) + { + + // Get Size and Type of Registry Value + DWORD dwType = NULL; + DWORD dwSize; + if(::RegQueryValueEx(regDataKey.m_hKey, sValName, 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) + { + + + // We Only Support DWORD and String + switch(dwType) + { + + case REG_DWORD: + + // Get DWORD Value + DWORD dwData; + dwSize = sizeof(DWORD); + if(::RegQueryValueEx(regDataKey.m_hKey, sValName, 0, &dwType, (LPBYTE)&dwData, &dwSize) == ERROR_SUCCESS) + { + + // Make sure we have a clean variant + ::VariantClear(&varVal); + // Return a 4 byte Integer + varVal.vt = VT_I4; + varVal.lVal = dwData; + + + regDataKey.Close(); + return S_OK; + + } + break; + + + case REG_SZ: + + + // Get String Value + string sData; + if(::RegQueryValueEx(regDataKey.m_hKey, sValName, 0, &dwType, (LPBYTE)sData.get_buffer(dwSize), &dwSize) == ERROR_SUCCESS) + { + // Have to Release before we can AllocSysString + sData.release_buffer(); + + + // Make sure we have a clean variant + ::VariantClear(&varVal); + // Return a BSTR (Client responsible for cleanup) + varVal.vt = VT_BSTR; + varVal.bstrVal = _bstr_t(sData); + + regDataKey.Close(); + return S_OK; + + } + break; + } + + + } + + regDataKey.Close(); + return REGDB_E_KEYMISSING; + + } + + regDataKey.Close(); + return REGDB_E_READREGDB; + +} + +////////////////////////////////////////////////////////////////// +// Saves the value passed to Internal Map where it stays until +// saved by the function Save + +HRESULT CComponentData::Write(const string& sValName, const VARIANT & varVal) +{ + HRESULT hr; + CComVariant varCopy = varVal; + + // Check what we've got + // We only support DWORD and String + switch(varVal.vt) + { + + case VT_UI1: + case VT_I2: + case VT_I4: + case VT_R4: + case VT_R8: + case VT_CY: + + // First try and make a 4 byte integer out of it (DWORD) + hr = VariantChangeType(&varCopy, &varCopy, 0, VT_I4); + if(FAILED(hr)) + return hr; + + case VT_BSTR: + case VT_NULL: + case VT_EMPTY: + + // Add Item to Variant Map + m_mapValues.erase(sValName); + m_mapValues.insert(make_pair(sValName, varCopy)); + return S_OK; + break; + + + default: + + return E_INVALIDARG; + break; + + } + + return S_OK; + +} + + + +///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// IPropertyBag + +STDMETHODIMP CComponentData::Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog) +{ +// TRACE("CComponentData::XPropertyBag::Read\n"); + + // Pass calls + ATLTRACE(_T("Read: %s -- Value: "), (LPCTSTR)string(pszPropName)); + HRESULT hr = Read(string(pszPropName), *pVar); + TRACEVARIANT(*pVar); + ATLTRACE(_T("\n")); + return hr; +} + +STDMETHODIMP CComponentData::Write(LPCOLESTR pszPropName, VARIANT* pVar) +{ +// TRACE("CComponentData::XPropertyBag::Write\n"); + + // Pass calls + ATLTRACE(_T("Write: %s -- Value: "), (LPCTSTR)string(pszPropName)); + TRACEVARIANT(*pVar); + ATLTRACE(_T("\n")); + return Write(string(pszPropName), *pVar); + +} + + +////////////////////////////////////////////////////////////////// +// Host specific Functions (returns default if error or can't find) + +int CComponentData::GetInt(const string& sKey, int nDefault) +{ + CComVariant var; + + var.vt = VT_I4; + var.lVal = nDefault; + + if(FAILED(Read(sKey, var))) + return nDefault; + else + return var.lVal; +} + +////////////////////////////////////////////////////////////////// +// Host specific Function + +bool CComponentData::WriteInt(const string& sKey, int nValue) +{ + CComVariant var; + + var.vt = VT_I4; + var.lVal = nValue; + + return SUCCEEDED(Write(sKey, var)); + +} + +bool CComponentData::Delete(const string& sKey) +{ + CComVariant var; + var.vt = VT_NULL; + return SUCCEEDED(Write(sKey, var)); +} diff --git a/Common/ComponentData.h b/Common/ComponentData.h new file mode 100644 index 0000000..75dcdbb --- /dev/null +++ b/Common/ComponentData.h @@ -0,0 +1,111 @@ +////////////////////////////////////////////////////////////////// +// CComponentData +// +// Exposes the IPropertyBag interface for the components to store +// their data in. +// +// Also supports other host specific settings. +// +// Current implementation saves the data in the registry and only +// saves when requested to by host. +// +// Component can pass a Variant NULL to delete the specified +// property +// +// Only the following types are supported for now: +// VT_UI1 +// VT_I2 +// VT_I4 +// VT_R4 +// VT_R8 +// VT_CY +// VT_BSTR +////////////////////////////////////////////////////////////////// + + +#if !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_) +#define COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 +// ComponentData.h : header file +// + +#define DATA_KEY _T("Data") + +#include "../common/interfaces.h" +#include <map> +#include <utility> +using std::map; +using std::make_pair; + +#include <mystring.h> + +typedef map<string, CComVariant> string_variant_map; + +///////////////////////////////////////////////////////////////////////////// +// CComponentData command target +class ATL_NO_VTABLE CComponentData : + public CComObjectRootEx<CComMultiThreadModel>, + public IPropertyBag +{ + +// Attributes +public: + CComponentData(); + virtual ~CComponentData(); + + +public: + // Host specific functions + // Add String support later when needed. + bool WriteInt(const string& sKey, int nValue); + int GetInt(const string& sKey, int nDefault); + bool Delete(const string& sKey); + + // Can be used by Host and also called from the + // IPropertyBag Implementation below + HRESULT Write(const string& sValName, const VARIANT& varVal); + HRESULT Read(const string& sValName, VARIANT& varVal); + + // Initializes Key + HRESULT Initialize(const string& sKey); + + + // Saves All Setting to Registry Key + // If sKey = NULL then saves to key given in Initialize + HRESULT Save(string sKey = _T("")); + + + // Returns an IUnknown to IPropertyBag +// IUnknown* GetIUnknown(bool bAddRef = false); + + +protected: + + // Arrays of Settings to be written to Registry + // Supports Integers and Strings Only + string_variant_map m_mapValues; + + // Registry Key + string m_sKey; + +public: + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CComponentData) + COM_INTERFACE_ENTRY(IPropertyBag) +END_COM_MAP() + + // IPropertyBag Interface + STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog); + STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT* pVar); + +}; + +///////////////////////////////////////////////////////////////////////////// + + +#endif // !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Common/ComponentHolder.cpp b/Common/ComponentHolder.cpp new file mode 100644 index 0000000..474809b --- /dev/null +++ b/Common/ComponentHolder.cpp @@ -0,0 +1,386 @@ +// ComponentHolder.cpp: implementation of the CComponentHolder class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "ComponentHolder.h" + +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CComponentHolder::CComponentHolder() +{ + // Both pointers are null for an uninited object + m_pComponentDOS = NULL; + m_pComponentWin = NULL; +} + +CComponentHolder::~CComponentHolder() +{ + // Just in case owner forgot + Release(); +} + +////////////////////////////////////////////////////////////////// +// Returns the component type (DOS or Windows) + +UINT CComponentHolder::GetType() +{ + // Needs to be Initialzed + ASSERT(!(m_pComponentDOS == NULL && m_pComponentWin == NULL)); + + + // Return Type + if(m_pComponentWin != NULL) + return COMPONENT_WIN; + else + return COMPONENT_DOS; + +} + +////////////////////////////////////////////////////////////////// +// Returns a IUnknown to the current component + +IUnknown* CComponentHolder::GetUnknown() +{ + // Needs to be Initialzed + ASSERT(!(m_pComponentDOS == NULL && m_pComponentWin == NULL)); + + // When copying out a Pointer make sure to AddRef + if(m_pComponentWin != NULL) + { + m_pComponentWin->AddRef(); + return m_pComponentWin; + } + else + { + m_pComponentDOS->AddRef(); + return m_pComponentDOS; + } + +} + +////////////////////////////////////////////////////////////////// +// Accepts a String ID, converts it and then calls the real +// Initialize + +HRESULT CComponentHolder::Initialize(const string& sID, const string& sRegKey) +{ + ASSERT(!sRegKey.empty()); + + USES_CONVERSION; + HRESULT hr; + CLSID clsid; + + // Get the CLSID + hr = CLSIDFromString(T2OLE(sID), &clsid); + + if(FAILED(hr)) + return hr; + + // And then call the real version + return Initialize(clsid, sRegKey); + +} + +////////////////////////////////////////////////////////////////// +// Loads and Initializes the Component + +HRESULT CComponentHolder::Initialize(const CLSID & clsid, const string& sRegKey) +{ + ASSERT(!sRegKey.empty()); + USES_CONVERSION; + + // If we're already Initialized then Release all the + // and start again interfaces + if(IsInitialized()) + Release(); + + + // Intitialize the Data Component + m_Data.Initialize(sRegKey); + + + + // Get an IUnknown to the Component First + // Since we don't know what it supports + // (CComPtr) calls Release for this one + HRESULT hr; + CComPtr<IUnknown> pUnk; + hr = CoCreateInstance(clsid, NULL, /*CLSCTX_ALL*/CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER , IID_IUnknown, (void**) &pUnk); + + if(FAILED(hr)) + return hr; + + + // Check if it Supports IID_ISecureShutdownWin + hr = pUnk->QueryInterface(IID_ISecureShutdownWin, (void**) &m_pComponentWin); + if(FAILED(hr)) m_pComponentWin = NULL; + + + // Check if it Supports IID_ISecureShutdownDOS + hr = pUnk->QueryInterface(IID_ISecureShutdownDOS, (void**) &m_pComponentDOS); + if(FAILED(hr)) m_pComponentDOS = NULL; + + + // Did we catch something? + if(!IsInitialized()) + return hr; + + switch(GetType()) + { + case COMPONENT_WIN: + // Give the Component it's Data Pointer + hr = m_pComponentWin->SetData(m_Data.GetUnknown()); + if(FAILED(hr)) return hr; + break; + case COMPONENT_DOS: + // Give the Component it's Data Pointer + hr = m_pComponentDOS->SetData(m_Data.GetUnknown()); + if(FAILED(hr)) return hr; + break; + } + + // Get Name + m_sName = GetInfoStr(nsName, _T("(No Name)")); + + return S_OK; + +} + +////////////////////////////////////////////////////////////////// +// Helper Function + +bool CComponentHolder::IsInitialized() +{ + // Either one has to be initialized + return !((m_pComponentDOS == NULL) && (m_pComponentWin == NULL)); +} + +/*#ifndef NS_NO_PROPPAGE +////////////////////////////////////////////////////////////////// +// Returns a pointer to the Property page for current component +// or error if none + + +HRESULT CComponentHolder::GetPropPage(CPropPageHolder** pPropPage) +{ + // If we already have a Prop Page then just get pointer + if(m_PropPage.IsInitialized()) + { + *pPropPage = &m_PropPage; + return S_OK; + } + + + // Otherwise Create one + HRESULT hr; + + + // Get a IUnkown to the current Component + CComPtr<IUnknown> pUnk; // Releases Pointer + GetIUnknown(&pUnk); + + + // See if it likes us + hr = m_PropPage.Initialize(pUnk); + if(FAILED(hr)) return hr; + + + // Return Pointer + *pPropPage = &m_PropPage; + + + return S_OK; +} + + +bool CComponentHolder::HasPropPage() +{ + CPropPageHolder* pPropPage; + return SUCCEEDED(GetPropPage(&pPropPage)); +} + +#endif // NS_NO_PROPPAGE +*/ +////////////////////////////////////////////////////////////////// +// Completely removes the component from Memory + +HRESULT CComponentHolder::Release() +{ +/* + // Check if we've got PropPage + // If so then get rid of it + if(m_PropPage.IsInitialized()) + m_PropPage.Destroy(); +*/ + + // Save the Data to the DataObject + // m_Data.Save(); + + + // Only Update if Initialized + if(IsInitialized()){ + + switch(GetType()){ + + case COMPONENT_WIN: + + // Get Component to Release Data Pointer + m_pComponentWin->SetData(NULL); + + // Release Component + m_pComponentWin->Release(); + + break; + + case COMPONENT_DOS: + + // Get Component to Release Data Pointer + m_pComponentDOS->SetData(NULL); + + // Release Component + m_pComponentDOS->Release(); + + break; + + } + + // Set to NULL as a flag + m_pComponentWin = NULL; + m_pComponentDOS = NULL; + + m_sName = _T(""); + } + + return S_OK; +} + +////////////////////////////////////////////////////////////////// +// Invokes actual shutdown (Windows Components Only) + +HRESULT CComponentHolder::DoShutdown(DWORD dwMode, HWND hwndParent) +{ + // Needs to be Initialized First + ASSERT(!(m_pComponentDOS == NULL && m_pComponentWin == NULL)); + + + switch(GetType()){ + case COMPONENT_WIN: + + // Call Shutdown. Only Windows + return m_pComponentWin->DoShutdown((long)hwndParent, (long)dwMode); + + break; + + case COMPONENT_DOS: + + // Call Shutdown. DOS don't support + ASSERT(false); + return E_FAIL; + + break; + } + + return E_FAIL; + +} + +////////////////////////////////////////////////////////////////// +// Retrieves Text for Batch File (DOS Components Only) + +HRESULT CComponentHolder::GetBatchText(string& sBatchText) +{ + USES_CONVERSION; + BSTR bstrBatchText; + HRESULT hr; + + switch(GetType()) + { + case COMPONENT_WIN: + + // Not Supported in Windows + return E_FAIL; + + break; + + case COMPONENT_DOS: + + // Get Batch Text. + hr = m_pComponentDOS->GetBatchText(&bstrBatchText); + + // Transfer to CString + if(SUCCEEDED(hr)) + sBatchText = OLE2T(bstrBatchText); + + return hr; + + break; + + } + + return E_FAIL; + + +} + + +CComVariant CComponentHolder::GetInfo(NightSecInfo nsItem) +{ + USES_CONVERSION; + CComVariant vInfo; + vInfo.vt = VT_EMPTY; + HRESULT hr; + + switch(GetType()){ + + case COMPONENT_WIN: + hr = m_pComponentWin->get_Info(nsItem, &vInfo); + break; + case COMPONENT_DOS: + hr = m_pComponentDOS->get_Info(nsItem, &vInfo); + break; + + } + + if(FAILED(hr)) + vInfo.vt = VT_NULL; + + return vInfo; +} + +string CComponentHolder::GetInfoStr(NightSecInfo nsItem, const string& sDefault) +{ + USES_CONVERSION; + + // Get Name + CComVariant vInfo = GetInfo(nsItem); + + if(vInfo.vt == VT_BSTR) + return OLE2T(vInfo.bstrVal); + + return sDefault; + +} + +int CComponentHolder::GetInfoInt(NightSecInfo nsItem, int nDefault) +{ + // Get Name + CComVariant vInfo = GetInfo(nsItem); + + if(vInfo.vt == VT_NULL || vInfo.vt == VT_EMPTY) + return nDefault; + + if(SUCCEEDED(vInfo.ChangeType(VT_I4))) + return vInfo.lVal; + + return nDefault; + +} diff --git a/Common/ComponentHolder.h b/Common/ComponentHolder.h new file mode 100644 index 0000000..66b90e2 --- /dev/null +++ b/Common/ComponentHolder.h @@ -0,0 +1,104 @@ +////////////////////////////////////////////////////////////////// +// +// ComponentHolder.h: interface for the CComponentHolder class. +// +// Holds one componet (either DOS or Windows) +// +// Is Initialized when either DOS or Windows pointer is valid +// +// virtual functions make it possible to override the funtionality +// and create host based app specific components. +// See shutdown.exe program for example of this +// +////////////////////////////////////////////////////////////////////// + +#if !defined(COMPONENTHOLDER_H__FDBF1422_18AE_11D2_B2D4_0020182B97FC__INCLUDED_) +#define COMPONENTHOLDER_H__FDBF1422_18AE_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +#include "../common/defines.h" +#include "../common/interfaces.h" +#include "../common/ComponentData.h" + +#include <mystring.h> + +#define CComObjectMember CComObjectGlobal + +class CComponentHolder +{ + +public: + CComponentHolder(); + virtual ~CComponentHolder(); + + // Calls main component function for Windows Components + virtual HRESULT DoShutdown(DWORD dwMode, HWND hwndParent = NULL); + // Calls main component function for DOS Components + virtual HRESULT GetBatchText(string& sBatchText); + + + // Initialization + // Needs Registry Key to Initialize and Save the Component Data + virtual bool IsInitialized(); + virtual HRESULT Initialize(const CLSID& clsid, const string& sRegKey); + virtual HRESULT Initialize(const string& sID, const string& sRegKey); + + + virtual HRESULT Release(); + + // Returns type (DOS or Windows) + virtual UINT GetType(); + + // Get's a IUnknown to the Component + virtual IUnknown* GetUnknown(); + +protected: + ISecureShutdownDOS* m_pComponentDOS; + ISecureShutdownWin* m_pComponentWin; + + // Component ID +protected: + string m_sID; +public: + virtual const string& GetID() const { return m_sID; }; + + // Name +protected: + string m_sName; +public: + const string& GetName() const { return m_sName; }; + +/* +#ifndef NS_NO_PROPPAGE + // Component Property Page +protected: + CComObjectMember<CPropPageHolder> m_PropPage; +public: +// virtual HRESULT GetPropPage(CPropPageHolder** pPropPage); +// bool HasPropPage(); +#endif // NS_NO_PROPPAGE +*/ + + // Component's Data +protected: + CComObjectMember<CComponentData> m_Data; +public: + virtual CComponentData* GetData() { return &m_Data; }; + + + // Host specific Funtions for accessing component data +public: + int GetInfoInt(NightSecInfo nsItem, int nDefault); + string GetInfoStr(NightSecInfo nsItem, const string& sDefault); + CComVariant GetInfo(NightSecInfo nsItem); + virtual bool IsEnabled() { return m_Data.GetInt(ENABLED_KEY, false) ? true : false; }; + virtual bool Enable(bool bEnable) { return m_Data.WriteInt(ENABLED_KEY, bEnable); } ; + virtual int GetPos() { return m_Data.GetInt(POSITION_KEY, 1); } ; + virtual bool SetPos(int nPos) { return m_Data.WriteInt(POSITION_KEY, nPos); } ; + +}; + +#endif // !defined(COMPONENTHOLDER_H__FDBF1422_18AE_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Common/Defines.h b/Common/Defines.h new file mode 100644 index 0000000..b66b229 --- /dev/null +++ b/Common/Defines.h @@ -0,0 +1,32 @@ +#ifndef __DEFINES_H__980713 +#define __DEFINES_H__980713 + + +#define COMPONENT_WIN 1 +#define COMPONENT_DOS 2 + +#define WIZPAGE_MIDDLE 0 +#define WIZPAGE_FIRST 1 +#define WIZPAGE_LAST 2 + +#define NS_GROUP _T("Heavenly Helpers") +#define NS_MAIN _T("Night Security") +#define NS_COMPONENTS _T("Components") +#define NS_INSTALLEDCOMPONENTS _T("Installed Components") + +#define NS_HELP_FILE _T("nightsec.hlp") + +#define NS_REG_MAIN _T("Software\\Heavenly Helpers\\Night Security") +#define NS_REG_COMPONENTS _T("Software\\Heavenly Helpers\\Night Security\\Components") +#define NS_REG_INSTALLEDCOMPONENTS _T("Software\\Heavenly Helpers\\Night Security\\Installed Components") + +#define NIGHTSEC_CLEARALL 0x00000001 + +#define ENABLED_KEY _T("Enabled") +#define POSITION_KEY _T("Position") + +#define FORCE_SHUTDOWN_KEY _T("Force MSDOS") +#define IS_SETUP_KEY _T("Is Setup") +#define NO_LOG_KEY _T("No Log") + +#endif //__DEFINES_H__980713
\ No newline at end of file diff --git a/Common/NightSec.h b/Common/NightSec.h new file mode 100644 index 0000000..a3f8705 --- /dev/null +++ b/Common/NightSec.h @@ -0,0 +1,591 @@ +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + +/* File created by MIDL compiler version 3.01.75 */ +/* at Wed Apr 21 21:38:00 1999 + */ +/* Compiler settings for NightSec Worker.idl: + Oicf (OptLev=i2), W1, Zp8, env=Win32, ms_ext, c_ext + error checks: none +*/ +//@@MIDL_FILE_HEADING( ) +#include "rpc.h" +#include "rpcndr.h" +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __NightSec_Worker_h__ +#define __NightSec_Worker_h__ + +#ifdef __cplusplus +extern "C"{ +#endif + +/* Forward Declarations */ + +#ifndef __ISecureShutdownWin_FWD_DEFINED__ +#define __ISecureShutdownWin_FWD_DEFINED__ +typedef interface ISecureShutdownWin ISecureShutdownWin; +#endif /* __ISecureShutdownWin_FWD_DEFINED__ */ + + +#ifndef __ISecureShutdownDOS_FWD_DEFINED__ +#define __ISecureShutdownDOS_FWD_DEFINED__ +typedef interface ISecureShutdownDOS ISecureShutdownDOS; +#endif /* __ISecureShutdownDOS_FWD_DEFINED__ */ + + +#ifndef __EmptyRecycleBin_FWD_DEFINED__ +#define __EmptyRecycleBin_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class EmptyRecycleBin EmptyRecycleBin; +#else +typedef struct EmptyRecycleBin EmptyRecycleBin; +#endif /* __cplusplus */ + +#endif /* __EmptyRecycleBin_FWD_DEFINED__ */ + + +#ifndef __EmptyTempFolder_FWD_DEFINED__ +#define __EmptyTempFolder_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class EmptyTempFolder EmptyTempFolder; +#else +typedef struct EmptyTempFolder EmptyTempFolder; +#endif /* __cplusplus */ + +#endif /* __EmptyTempFolder_FWD_DEFINED__ */ + + +#ifndef __DeleteSwapFile_FWD_DEFINED__ +#define __DeleteSwapFile_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class DeleteSwapFile DeleteSwapFile; +#else +typedef struct DeleteSwapFile DeleteSwapFile; +#endif /* __cplusplus */ + +#endif /* __DeleteSwapFile_FWD_DEFINED__ */ + + +#ifndef __RunScanDisk_FWD_DEFINED__ +#define __RunScanDisk_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class RunScanDisk RunScanDisk; +#else +typedef struct RunScanDisk RunScanDisk; +#endif /* __cplusplus */ + +#endif /* __RunScanDisk_FWD_DEFINED__ */ + + +#ifndef __WipefreeSpace_FWD_DEFINED__ +#define __WipefreeSpace_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class WipefreeSpace WipefreeSpace; +#else +typedef struct WipefreeSpace WipefreeSpace; +#endif /* __cplusplus */ + +#endif /* __WipefreeSpace_FWD_DEFINED__ */ + + +#ifndef __WXPYShutdown_FWD_DEFINED__ +#define __WXPYShutdown_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class WXPYShutdown WXPYShutdown; +#else +typedef struct WXPYShutdown WXPYShutdown; +#endif /* __cplusplus */ + +#endif /* __WXPYShutdown_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" +#include "ocidl.h" + +void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t); +void __RPC_USER MIDL_user_free( void __RPC_FAR * ); + +/**************************************** + * Generated header for interface: __MIDL_itf_NightSec_Worker_0000 + * at Wed Apr 21 21:38:00 1999 + * using MIDL 3.01.75 + ****************************************/ +/* [local] */ + + +typedef /* [helpstring][uuid][v1_enum] */ +enum NightSecInfo + { nsName = 0, + nsCmdLine = nsName + 1, + nsHelpText = nsCmdLine + 1, + nsForceShow = nsHelpText + 1, + nsHideNormal = nsForceShow + 1, + nsCopyAble = nsHideNormal + 1, + nsHelpFile = nsCopyAble + 1, + nsHelpTopic = nsHelpFile + 1 + } NightSecInfo; + + + +extern RPC_IF_HANDLE __MIDL_itf_NightSec_Worker_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_NightSec_Worker_0000_v0_0_s_ifspec; + +#ifndef __ISecureShutdownWin_INTERFACE_DEFINED__ +#define __ISecureShutdownWin_INTERFACE_DEFINED__ + +/**************************************** + * Generated header for interface: ISecureShutdownWin + * at Wed Apr 21 21:38:00 1999 + * using MIDL 3.01.75 + ****************************************/ +/* [unique][helpstring][dual][uuid][object] */ + + + +EXTERN_C const IID IID_ISecureShutdownWin; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + interface DECLSPEC_UUID("34F11691-F275-11d2-A589-0020182B97FC") + ISecureShutdownWin : public IDispatch + { + public: + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE DoShutdown( + /* [in] */ long hParent, + /* [in] */ long lMode) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetData( + /* [in] */ IUnknown __RPC_FAR *pUnk) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_Info( + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal) = 0; + + }; + +#else /* C style interface */ + + typedef struct ISecureShutdownWinVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )( + ISecureShutdownWin __RPC_FAR * This); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( + ISecureShutdownWin __RPC_FAR * This); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfoCount )( + ISecureShutdownWin __RPC_FAR * This, + /* [out] */ UINT __RPC_FAR *pctinfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfo )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetIDsOfNames )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID __RPC_FAR *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Invoke )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams, + /* [out] */ VARIANT __RPC_FAR *pVarResult, + /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo, + /* [out] */ UINT __RPC_FAR *puArgErr); + + /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *DoShutdown )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ long hParent, + /* [in] */ long lMode); + + /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *SetData )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ IUnknown __RPC_FAR *pUnk); + + /* [helpstring][id][propget] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *get_Info )( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal); + + END_INTERFACE + } ISecureShutdownWinVtbl; + + interface ISecureShutdownWin + { + CONST_VTBL struct ISecureShutdownWinVtbl __RPC_FAR *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ISecureShutdownWin_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define ISecureShutdownWin_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define ISecureShutdownWin_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define ISecureShutdownWin_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define ISecureShutdownWin_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define ISecureShutdownWin_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define ISecureShutdownWin_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define ISecureShutdownWin_DoShutdown(This,hParent,lMode) \ + (This)->lpVtbl -> DoShutdown(This,hParent,lMode) + +#define ISecureShutdownWin_SetData(This,pUnk) \ + (This)->lpVtbl -> SetData(This,pUnk) + +#define ISecureShutdownWin_get_Info(This,nsItem,pvVal) \ + (This)->lpVtbl -> get_Info(This,nsItem,pvVal) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ISecureShutdownWin_DoShutdown_Proxy( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ long hParent, + /* [in] */ long lMode); + + +void __RPC_STUB ISecureShutdownWin_DoShutdown_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ISecureShutdownWin_SetData_Proxy( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ IUnknown __RPC_FAR *pUnk); + + +void __RPC_STUB ISecureShutdownWin_SetData_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE ISecureShutdownWin_get_Info_Proxy( + ISecureShutdownWin __RPC_FAR * This, + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal); + + +void __RPC_STUB ISecureShutdownWin_get_Info_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __ISecureShutdownWin_INTERFACE_DEFINED__ */ + + +#ifndef __ISecureShutdownDOS_INTERFACE_DEFINED__ +#define __ISecureShutdownDOS_INTERFACE_DEFINED__ + +/**************************************** + * Generated header for interface: ISecureShutdownDOS + * at Wed Apr 21 21:38:00 1999 + * using MIDL 3.01.75 + ****************************************/ +/* [unique][helpstring][dual][uuid][object] */ + + + +EXTERN_C const IID IID_ISecureShutdownDOS; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + interface DECLSPEC_UUID("34F11692-F275-11d2-A589-0020182B97FC") + ISecureShutdownDOS : public IDispatch + { + public: + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE GetBatchText( + /* [retval][out] */ BSTR __RPC_FAR *psText) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetData( + /* [in] */ IUnknown __RPC_FAR *pUnk) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_Info( + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal) = 0; + + }; + +#else /* C style interface */ + + typedef struct ISecureShutdownDOSVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )( + ISecureShutdownDOS __RPC_FAR * This); + + ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( + ISecureShutdownDOS __RPC_FAR * This); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfoCount )( + ISecureShutdownDOS __RPC_FAR * This, + /* [out] */ UINT __RPC_FAR *pctinfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfo )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo); + + HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetIDsOfNames )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID __RPC_FAR *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Invoke )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams, + /* [out] */ VARIANT __RPC_FAR *pVarResult, + /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo, + /* [out] */ UINT __RPC_FAR *puArgErr); + + /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetBatchText )( + ISecureShutdownDOS __RPC_FAR * This, + /* [retval][out] */ BSTR __RPC_FAR *psText); + + /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *SetData )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ IUnknown __RPC_FAR *pUnk); + + /* [helpstring][id][propget] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *get_Info )( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal); + + END_INTERFACE + } ISecureShutdownDOSVtbl; + + interface ISecureShutdownDOS + { + CONST_VTBL struct ISecureShutdownDOSVtbl __RPC_FAR *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ISecureShutdownDOS_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define ISecureShutdownDOS_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define ISecureShutdownDOS_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define ISecureShutdownDOS_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define ISecureShutdownDOS_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define ISecureShutdownDOS_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define ISecureShutdownDOS_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define ISecureShutdownDOS_GetBatchText(This,psText) \ + (This)->lpVtbl -> GetBatchText(This,psText) + +#define ISecureShutdownDOS_SetData(This,pUnk) \ + (This)->lpVtbl -> SetData(This,pUnk) + +#define ISecureShutdownDOS_get_Info(This,nsItem,pvVal) \ + (This)->lpVtbl -> get_Info(This,nsItem,pvVal) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ISecureShutdownDOS_GetBatchText_Proxy( + ISecureShutdownDOS __RPC_FAR * This, + /* [retval][out] */ BSTR __RPC_FAR *psText); + + +void __RPC_STUB ISecureShutdownDOS_GetBatchText_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ISecureShutdownDOS_SetData_Proxy( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ IUnknown __RPC_FAR *pUnk); + + +void __RPC_STUB ISecureShutdownDOS_SetData_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE ISecureShutdownDOS_get_Info_Proxy( + ISecureShutdownDOS __RPC_FAR * This, + /* [in] */ NightSecInfo nsItem, + /* [retval][out] */ VARIANT __RPC_FAR *pvVal); + + +void __RPC_STUB ISecureShutdownDOS_get_Info_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __ISecureShutdownDOS_INTERFACE_DEFINED__ */ + + + +#ifndef __NightSecComponents_LIBRARY_DEFINED__ +#define __NightSecComponents_LIBRARY_DEFINED__ + +/**************************************** + * Generated header for library: NightSecComponents + * at Wed Apr 21 21:38:00 1999 + * using MIDL 3.01.75 + ****************************************/ +/* [helpstring][version][uuid] */ + + + +EXTERN_C const IID LIBID_NightSecComponents; + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_EmptyRecycleBin; + +class DECLSPEC_UUID("34F11694-F275-11d2-A589-0020182B97FC") +EmptyRecycleBin; +#endif + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_EmptyTempFolder; + +class DECLSPEC_UUID("34F11695-F275-11d2-A589-0020182B97FC") +EmptyTempFolder; +#endif + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_DeleteSwapFile; + +class DECLSPEC_UUID("34F11696-F275-11d2-A589-0020182B97FC") +DeleteSwapFile; +#endif + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_RunScanDisk; + +class DECLSPEC_UUID("34F11697-F275-11d2-A589-0020182B97FC") +RunScanDisk; +#endif + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_WipefreeSpace; + +class DECLSPEC_UUID("34F11698-F275-11d2-A589-0020182B97FC") +WipefreeSpace; +#endif + +#ifdef __cplusplus +EXTERN_C const CLSID CLSID_WXPYShutdown; + +class DECLSPEC_UUID("34F11699-F275-11d2-A589-0020182B97FC") +WXPYShutdown; +#endif +#endif /* __NightSecComponents_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +unsigned long __RPC_USER BSTR_UserSize( unsigned long __RPC_FAR *, unsigned long , BSTR __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER BSTR_UserMarshal( unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, BSTR __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER BSTR_UserUnmarshal(unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, BSTR __RPC_FAR * ); +void __RPC_USER BSTR_UserFree( unsigned long __RPC_FAR *, BSTR __RPC_FAR * ); + +unsigned long __RPC_USER VARIANT_UserSize( unsigned long __RPC_FAR *, unsigned long , VARIANT __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER VARIANT_UserMarshal( unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, VARIANT __RPC_FAR * ); +unsigned char __RPC_FAR * __RPC_USER VARIANT_UserUnmarshal(unsigned long __RPC_FAR *, unsigned char __RPC_FAR *, VARIANT __RPC_FAR * ); +void __RPC_USER VARIANT_UserFree( unsigned long __RPC_FAR *, VARIANT __RPC_FAR * ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Common/NightSecApp.cpp b/Common/NightSecApp.cpp new file mode 100644 index 0000000..0fcec5e --- /dev/null +++ b/Common/NightSecApp.cpp @@ -0,0 +1,138 @@ +// NightSecApp.cpp: implementation of the CNightSecApp class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "NightSecApp.h" + +#include <regsvr.h> +#include <appmisc.h> +#include <path.h> +#include "../common/defines.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CComponentArray g_aComponents; + +#define NS_REGISTER_FAILED _T("Night Security was unable to register the %s component.\n\n%s\nIf Night Security doesn't seem to be working properly please reinstall.") +const DWORD dwTimeOut = 5000; // time for EXE to be idle before shutting down + +CNightSecApp::CNightSecApp(const string& sAppName, const string& sMtxName) + : m_sAppName(sAppName), m_oneInstance(sMtxName), + m_settings(HKEY_CURRENT_USER, NS_REG_MAIN) +{ + +} + +CNightSecApp::~CNightSecApp() +{ + +} + +bool CNightSecApp::InitInstance() +{ + LPCTSTR szCmdLine = GetCommandLine(); + + // If we've been asked to close then exit here + if(_tcsstr(szCmdLine, _T("close")) != NULL) + return false; + + // Load up all Components + if(!g_aComponents.LoadComponents()) + { + RegisterDlls(); + g_aComponents.LoadComponents(); + } + + return true; +} + +bool CNightSecApp::ExitInstance() +{ + g_aComponents.UnloadComponents(); + return false; +} + +HRESULT CNightSecApp::RegisterDlls(bool bUI /*= true*/) +{ + file_iterator iterFiles(GetProgramFolder(_Module.m_hInst), + _T("*.dll"), file_iterator::full_paths); + + file_iterator end; + + HRESULT hRet = S_OK; + + for( ; iterFiles != end; iterFiles++) + { + HRESULT hr = RegisterDLL(iterFiles->cFileName); + + if(SUCCEEDED(hr) || !bUI) + continue; + + string sError; + file_path fileDll(iterFiles->cFileName); + sError.format(NS_REGISTER_FAILED, (LPCTSTR)fileDll.file(), (LPCTSTR)FormatHR(hr)); + + MessageBox(NULL, sError, m_sAppName, MB_OK | MB_ICONEXCLAMATION); + } + + return hRet; +} + +// Passed to CreateThread to monitor the shutdown event +/*static DWORD WINAPI MonitorProc(void* pv) +{ + CNightSecApp* p = (CNightSecApp*)pv; + p->MonitorShutdown(); + return 0; +}*/ + +/*LONG CNightSecApp::Unlock() +{ + LONG l = CComModule::Unlock(); + if (l == 0) + { + bActivity = true; + SetEvent(hEventShutdown); // tell monitor that we transitioned to zero + } + return l; +} +*/ +//Monitors the shutdown event +/*void CNightSecApp::MonitorShutdown() +{ + while (1) + { + WaitForSingleObject(hEventShutdown, INFINITE); + DWORD dwWait=0; + do + { + bActivity = false; + dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut); + } while (dwWait == WAIT_OBJECT_0); + // timed out + if (!bActivity && m_nLockCnt == 0) // if no activity let's really bail + { +#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) + CoSuspendClassObjects(); + if (!bActivity && m_nLockCnt == 0) +#endif + break; + } + } + CloseHandle(hEventShutdown); + PostThreadMessage(dwThreadID, WM_QUIT, 0, 0); +} + +bool CNightSecApp::StartMonitor() +{ + hEventShutdown = CreateEvent(NULL, false, false, NULL); + if (hEventShutdown == NULL) + return false; + DWORD dwThreadID; + HANDLE h = CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID); + return (h != NULL); +} +*/
\ No newline at end of file diff --git a/Common/NightSecApp.h b/Common/NightSecApp.h new file mode 100644 index 0000000..80e9fae --- /dev/null +++ b/Common/NightSecApp.h @@ -0,0 +1,41 @@ +// NightSecApp.h: interface for the CNightSecApp class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_NIGHTSECAPP_H__19178A44_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_) +#define AFX_NIGHTSECAPP_H__19178A44_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include <mystring.h> +#include <RegSettings.h> +#include "../common/oneinstance.h" + +class CNightSecApp : public CComModule +{ +public: + CNightSecApp(const string& sAppName, const string& sMtxName = _T("")); + ~CNightSecApp(); + virtual bool InitInstance(); + virtual bool ExitInstance(); + HRESULT RegisterDlls(bool bUI = true); + + // From ATL +// LONG Unlock(); +// DWORD dwThreadID; +// HANDLE hEventShutdown; +// void MonitorShutdown(); +// bool StartMonitor(); + bool bActivity; + +protected: + const string m_sAppName; + COneInstance m_oneInstance; + +public: + CRegSettings m_settings; +}; + +#endif // !defined(AFX_NIGHTSECAPP_H__19178A44_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_) diff --git a/Common/OneInstance.h b/Common/OneInstance.h new file mode 100644 index 0000000..5eec36f --- /dev/null +++ b/Common/OneInstance.h @@ -0,0 +1,63 @@ +// OneInstance.h: interface for the COneInstance class. +// +////////////////////////////////////////////////////////////////////// + + +#if !defined(AFX_ONEINSTANCE_H__A3059F66_BFED_11D2_A501_0020182B97FC__INCLUDED_) +#define AFX_ONEINSTANCE_H__A3059F66_BFED_11D2_A501_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include <string> + +class COneInstance +{ +public: + + // Constructor + COneInstance(LPCSTR szID) + : sMtxName(szID) {}; + + // Activates a Window based on the following... + // szClass: Class name of Window (get from SPY) + // szTitle: Title bar of Window + bool FindAndActivate(LPCSTR szClass, LPCSTR szTitle) const + { + // Search for the Window + HWND hWnd = ::FindWindow(szClass, szTitle); + + // Check if we have any popups + HWND hChild = GetLastActivePopup(hWnd); + + bool bRet = SetForegroundWindow(hWnd) ? true : false; // bring main window to top + + if (hWnd != hChild) + SetForegroundWindow(hChild); // a pop-up window is active + // bring it to the top too + // do not run second instance + return bRet; + } + + // Checks if there is already a program loaded + // with the ID passed when creating COneInstance + bool IsAlreadyLoaded() const + { + if(sMtxName.empty()) + return false; + + // Use a Mutex and not a FindWindow because process could exist + // without a Window ( + ::CreateMutex(NULL, true, sMtxName.c_str()); + + // mutex will be automatically deleted when process ends + return (::GetLastError() == ERROR_ALREADY_EXISTS); + } + + +protected: + std::string sMtxName; +}; + +#endif // !defined(AFX_ONEINSTANCE_H__A3059F66_BFED_11D2_A501_0020182B97FC__INCLUDED_) diff --git a/Common/PropPageHolder.cpp b/Common/PropPageHolder.cpp new file mode 100644 index 0000000..cd14ff8 --- /dev/null +++ b/Common/PropPageHolder.cpp @@ -0,0 +1,317 @@ +// PropPageHolder.cpp : implementation file +// + +#include "stdafx.h" +#include "PropPageHolder.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CPropPageHolder + +CPropPageHolder::CPropPageHolder() +{ + m_pSite = NULL; + m_pPropPage = NULL; + m_bActivated = false; + memset(&m_PageInfo, 0, sizeof(PROPPAGEINFO)); +} + +/*CPropPageHolder::CPropPageHolder(IPropertyPage* pPage, IUnknown* pSite) +{ + m_pSite = NULL; + m_pPropPage = NULL; + m_bActivated = false; + memset(&m_PageInfo, 0, sizeof(PROPPAGEINFO)); + + // We were passed a IUnknown, so Initialize from there + Initialize(pPage, pSite); +} +*/ + +CPropPageHolder::~CPropPageHolder() +{ + // Just in case + if(m_pPropPage != NULL) + Destroy(); + + if(m_PageInfo.cb != 0) + { + CoTaskMemFree(m_PageInfo.pszDocString); + CoTaskMemFree(m_PageInfo.pszHelpFile); + CoTaskMemFree(m_PageInfo.pszTitle); + } +} + +///////////////////////////////////////////////////////////////////////////// +// CPropPageHolder message handlers + +////////////////////////////////////////////////////////////////// +// Loads Prop Page if it has one + +HRESULT CPropPageHolder::Initialize(IPropertyPage* pPage, IUnknown* pSite) +{ + // Can't Reinitialize + ASSERT(!m_pPropPage); + ASSERT(pSite); + ASSERT(pPage); + + // This is the Container site + // (Returned from IPropertyPageSite::GetPageContainer) + m_pSite = pSite; + + m_pPropPage = pPage; + pPage->AddRef(); + + // Get a IPropertyPageSite Pointer to ourselves + // for the new Proppage + IPropertyPageSite* pPageSite = NULL; + QueryInterface(IID_IPropertyPageSite, (void**)&pPageSite); + ASSERT(pPageSite); + + + // Set Page Site + HRESULT hr = m_pPropPage->SetPageSite(pPageSite); + + // Make sure to reset to null if failed + if(FAILED(hr)) + { + m_pPropPage->Release(); + m_pPropPage = NULL; + } + else + { + // Property page should have AddRef'ed, + // So release our pointer + Release(); + } + + return hr; + +} + +////////////////////////////////////////////////////////////////// +// Creates and shows PropPage + +HRESULT CPropPageHolder::Create(HWND hwndParent, const RECT& rect, bool bModalParent /*= true*/) +{ + // Need to Initialize First + ASSERT(m_pPropPage); + + + // If we're already activated then just + // move to new coordinates + if(m_bActivated) + return Move(rect); + + + HRESULT hr; + + + // Activate the Page + hr = m_pPropPage->Activate(hwndParent, &rect, true); + + + if(!FAILED(hr)) + { + m_bActivated = true; + + // Make sure it's visible + m_pPropPage->Show(SW_SHOW); + } + + + return hr; +} + +////////////////////////////////////////////////////////////////// +// Destroys and Releases PropPage + +HRESULT CPropPageHolder::Destroy() +{ + // Can't destroy NULL object + if(m_pPropPage == NULL) + return S_OK; + + + Close(); + + // Make it let go of our IPropertyPageSite Pointer + HRESULT hr = m_pPropPage->SetPageSite(NULL); + + + // Then release it + m_pPropPage->Release(); + + + m_pPropPage = NULL; + + return hr; +} + +HRESULT CPropPageHolder::Close() +{ + // Need to Initialize + // and create first + ASSERT(m_pPropPage); + + if(m_bActivated) + { + + m_bActivated = false; + + // Deactivate page + return m_pPropPage->Deactivate(); + + } + + // It went okay but didn't do anything so... + return S_FALSE; + +} + +////////////////////////////////////////////////////////////////// +// Calls IPropPage Show + +HRESULT CPropPageHolder::Show(UINT nCmdShow) +{ + // Need to Initialize + // and create first + ASSERT(m_pPropPage); + ASSERT(m_bActivated); + + return m_pPropPage->Show(nCmdShow); + +} + +////////////////////////////////////////////////////////////////// +// Calls IPropPage Move + +HRESULT CPropPageHolder::Move(const RECT& rect) +{ + // Need to Initialize + // and create first + ASSERT(m_pPropPage); + ASSERT(m_bActivated); + + return m_pPropPage->Move(&rect); + +} + +////////////////////////////////////////////////////////////////// +// PropPage is inited properly if pointer not null + +bool CPropPageHolder::IsInitialized() +{ + return !(m_pPropPage == NULL); +} + +////////////////////////////////////////////////////////////////// +// Calls IPropPage Apply (results in a call to OnStatusChanged +// in our IPropPageSite) + +HRESULT CPropPageHolder::Apply() +{ + // Need to Initialize First + ASSERT(m_pPropPage); + + return m_pPropPage->Apply(); +} + +////////////////////////////////////////////////////////////////// +// Is it Created? + +bool CPropPageHolder::IsActivated() + { return m_bActivated; } + + + +///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// PropertyPageSite + +STDMETHODIMP CPropPageHolder::OnStatusChange(DWORD dwFlags) +{ + TRACE("CPropPageHolder::XPropertyPageSite::OnStatusChange\n"); + + // We don't need to implement any of this + // as we use delayed saving + return S_OK; +} + +STDMETHODIMP CPropPageHolder::GetLocaleID(LCID* pLocaleID) +{ + TRACE("CPropPageHolder::XPropertyPageSite::GetLocaleID\n"); + + // Just give'm a default language + *pLocaleID = LOCALE_SYSTEM_DEFAULT; + return S_OK; +} + +STDMETHODIMP CPropPageHolder::GetPageContainer(IUnknown** ppUnk) +{ + TRACE("CPropPageHolder::XPropertyPageSite::GetPageContainer\n"); + + // If Error we need to set to NULL + // This takes care of that cuz NULL is the only error around + *ppUnk = m_pSite; + + if(!m_pSite) + return E_UNEXPECTED; + + m_pSite->AddRef(); + + // Sorry + return S_OK; +} + +STDMETHODIMP CPropPageHolder::TranslateAccelerator(LPMSG pMsg) +{ + TRACE("CPropPageHolder::XPropertyPageSite::TranslateAccelerator\n"); + + // Sorry + return E_NOTIMPL; +} + +string CPropPageHolder::GetTitle() +{ + USES_CONVERSION; + LoadInfo(); + + if(m_PageInfo.pszTitle) + return OLE2T(m_PageInfo.pszTitle); + + return _T(""); +} + +string CPropPageHolder::GetHelpFile() +{ + USES_CONVERSION; + LoadInfo(); + + if(m_PageInfo.pszHelpFile) + return OLE2T(m_PageInfo.pszHelpFile); + + return _T(""); +} + +DWORD CPropPageHolder::GetHelpContext() +{ + LoadInfo(); + return m_PageInfo.dwHelpContext; +} + + +HRESULT CPropPageHolder::LoadInfo() +{ + if(m_PageInfo.cb != 0) + return S_OK; + + ASSERT(m_pPropPage); + m_PageInfo.cb = sizeof(PROPPAGEINFO); + return m_pPropPage->GetPageInfo(&m_PageInfo); +} diff --git a/Common/PropPageHolder.h b/Common/PropPageHolder.h new file mode 100644 index 0000000..4fec7ee --- /dev/null +++ b/Common/PropPageHolder.h @@ -0,0 +1,89 @@ +////////////////////////////////////////////////////////////////// +// +// PropPageHolder.h : header file +// +// CPropPageHolder manages the components IPropertyPage Interface +// +// It also exposes a IPropertyPageSite Interface for the +// Component (not used for much though) +// +////////////////////////////////////////////////////////////////// + +#if !defined(AFX_PROPPAGEHOLDER_H__F0EC0A29_18D4_11D2_B2D4_0020182B97FC__INCLUDED_) +#define AFX_PROPPAGEHOLDER_H__F0EC0A29_18D4_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +///////////////////////////////////////////////////////////////////////////// +// CPropPageHolder command target + +class ATL_NO_VTABLE CPropPageHolder : + public CComObjectRootEx<CComSingleThreadModel>, + public IPropertyPageSite +{ + +// Attributes +public: + CPropPageHolder(); +// CPropPageHolder(IPropertyPage* pPage, IUnknown* pSite); + virtual ~CPropPageHolder(); + +// Operations +public: + HRESULT Close(); + + bool IsActivated(); // Is Proppage Created? + HRESULT Apply(); // Save Changes to Data Object + bool IsInitialized(); // Is Initialized? + + // Checks to see if it has a IPropPage + HRESULT Initialize(IPropertyPage* pUnk, IUnknown* pSite); + + // Activates and Shows the Page + // For best results start with WS_VISIBLE = false in + // dialog template (no flicker) + HRESULT Create(HWND hwndParent, const RECT& rect, bool bModalParent = true); + + // DeActivates Page and Releases IPropPage + HRESULT Destroy(); + + // Window Functions + HRESULT Show(UINT nCmdShow); + HRESULT Move(const RECT& rect); + +// Implementation +protected: + HRESULT LoadInfo(); + + // Is Created or not? + bool m_bActivated; + + IPropertyPage* m_pPropPage; + PROPPAGEINFO m_PageInfo; + IUnknown* m_pSite; // This is a pointer to the Page Container Site + // Returned from IPropertyPageSite::GetPageContainer + +public: + DWORD GetHelpContext(); + string GetHelpFile(); + string GetTitle(); + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CPropPageHolder) + COM_INTERFACE_ENTRY(IPropertyPageSite) +END_COM_MAP() + + // IPropertyBag + STDMETHOD(OnStatusChange)(DWORD dwFlags); + STDMETHOD(GetLocaleID)(LCID* pLocaleID); + STDMETHOD(GetPageContainer)(IUnknown** ppUnk); + STDMETHOD(TranslateAccelerator)(LPMSG pMsg); + +}; + +///////////////////////////////////////////////////////////////////////////// + +#endif // !defined(AFX_PROPPAGEHOLDER_H__F0EC0A29_18D4_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Common/events.h b/Common/events.h new file mode 100644 index 0000000..f736f9c --- /dev/null +++ b/Common/events.h @@ -0,0 +1,6 @@ +#ifndef __EVENTS_H__991107 +#define __EVENTS_H__991107 + +#import "../Shutdown/Shutdown.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids //"Import typelib" + +#endif //__EVENTS_H__991107
\ No newline at end of file diff --git a/Common/interfaces.cpp b/Common/interfaces.cpp new file mode 100644 index 0000000..b43b8b5 --- /dev/null +++ b/Common/interfaces.cpp @@ -0,0 +1,4 @@ + +#include "../interfaces/CmptIFaces_i.c" +#include "../interfaces/SiteIFaces_i.c" + diff --git a/Common/interfaces.h b/Common/interfaces.h new file mode 100644 index 0000000..9bf5667 --- /dev/null +++ b/Common/interfaces.h @@ -0,0 +1,14 @@ +#ifndef __INTERFACES_H__980711 +#define __INTERFACES_H__980711 + +#include "../interfaces/CmptIFaces.h" +#include "../interfaces/SiteIFaces.h" + +#include <comdef.h> + +_COM_SMARTPTR_TYPEDEF(INightSecError, __uuidof(INightSecError)); +_COM_SMARTPTR_TYPEDEF(INightSecErrorFix, __uuidof(INightSecErrorFix)); +_COM_SMARTPTR_TYPEDEF(INightSecErrorLog, __uuidof(INightSecErrorLog)); +_COM_SMARTPTR_TYPEDEF(INightSecSiteInfo, __uuidof(INightSecSiteInfo)); + +#endif //__INTERFACES_H__980711
\ No newline at end of file diff --git a/Common/types.h b/Common/types.h new file mode 100644 index 0000000..fa6a1b2 --- /dev/null +++ b/Common/types.h @@ -0,0 +1,10 @@ +// Extra types used in Night Security + +#include <mystring.h> + +#include <vector> +typedef std::vector<string> string_array; + +#include <set> +typedef std::set<string> string_set; + |