diff options
Diffstat (limited to 'Shutdown')
33 files changed, 2920 insertions, 0 deletions
diff --git a/Shutdown/BatchFileCmpt.cpp b/Shutdown/BatchFileCmpt.cpp new file mode 100644 index 0000000..c2823b0 --- /dev/null +++ b/Shutdown/BatchFileCmpt.cpp @@ -0,0 +1,251 @@ +// BatchFileCmpt.cpp: implementation of the CBatchFileCmpt class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "BatchFileCmpt.h" + +#include "..\Common\Defines.h" +#include "resource.h" +#include <appmisc.h> + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CBatchFileCmpt::CBatchFileCmpt() +{ + m_sName = _T("Finalize Shutdown"); + m_bBatchFile = false; +} + +CBatchFileCmpt::~CBatchFileCmpt() +{ + if(m_bBatchFile) + CallBatchFile(); +} + +////////////////////////////////////////////////////////////////// +// Calls the two helper functions below to create the batchfile +// and then run it + +HRESULT CBatchFileCmpt::DoShutdown(DWORD dwMode, HWND hWndParent) +{ + // Create the batch file + HRESULT hr = MakeBatchFile(); + + if(g_site.m_log.HasErrors()) + g_site.m_log.WaitLog(); + + // Calls the batch file from destructor + m_bBatchFile = SUCCEEDED(hr) && (hr != S_FALSE) && + (!g_site.m_dlgItems.IsCancelled()); + + return hr; +} + +////////////////////////////////////////////////////////////////// +// Creates (or modifies) the Batchfile DosMode.bat in Program Folder + +HRESULT CBatchFileCmpt::MakeBatchFile() +{ + // Get Batch File Name + string sFileName; + + sFileName.load_string(IDS_BATCHFILENAME); + sFileName = GetProgramFolder(_Module.m_hInst) + sFileName; + + // Get DOS Component Strings + string sMainBatch, sTemp; + + sTemp.load_string(IDS_STARTSECTION); + sMainBatch += sTemp; + + HRESULT hr = S_OK; + int nDOSComponents = 0; + + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + if(g_aComponents[nCnt]->GetType() == COMPONENT_DOS) + { + if(g_aComponents[nCnt]->IsEnabled()) + { + sTemp.resize(0); + hr = g_aComponents[nCnt]->GetBatchText(sTemp); + + if(SUCCEEDED(hr)) + { + sMainBatch += sTemp + "\r\n"; + nDOSComponents++; + } + + } + + } + + } + + // If there's no DOS Components then don't do a shutdown + if(!nDOSComponents) + if(!_Module.m_settings.GetInt(FORCE_SHUTDOWN_KEY, false) ? true : false) + return S_FALSE; + + sTemp.load_string(IDS_ENDSECTION); + sMainBatch += sTemp; + + // Get any additions to the batch file; + string sPreText; + string sPostText; + hr = GetCurBatchFile(sFileName, sPreText, sPostText); + + if(FAILED(hr)) + return hr; + + HANDLE fileMSModeBatch; + + // Open the File for Writing + // This time we truncate the file + // if it isn't already there then create it + if((fileMSModeBatch = CreateFile(sFileName, GENERIC_WRITE, + /*0*/FILE_SHARE_READ, NULL, OPEN_ALWAYS | TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, + NULL)) == INVALID_HANDLE_VALUE) + return ReportLastError(_T("Couldn't write to the the batch file\n\n")); + + // Write All the differnet sections to the file + DWORD dwWritten = 0; + WriteFile(fileMSModeBatch, sPreText, sPreText.size(), &dwWritten, NULL); + WriteFile(fileMSModeBatch, sMainBatch, sMainBatch.size(), &dwWritten, NULL); + WriteFile(fileMSModeBatch, sPostText, sPostText.size(), &dwWritten, NULL); + + CloseHandle(fileMSModeBatch); + + return (nDOSComponents > 0) ? S_OK : S_FALSE; +} + +HRESULT CBatchFileCmpt::GetCurBatchFile(const string& sFileName, string& sPreText, string& sPostText) +{ + + // Now read in the file + HANDLE fileMSModeBatch; + + // Open the file + // if it isn't already there then create it + if((fileMSModeBatch = CreateFile(sFileName, GENERIC_READ, + 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, + NULL)) == INVALID_HANDLE_VALUE) + return ReportLastError(_T("Couldn't open the batch file\n\n")); + + // Load all our tags and search text + string sStartSearchText; sStartSearchText.load_string(IDS_STARTSEARHTEXT); + string sEndSearchText; sEndSearchText.load_string(IDS_ENDSEARCHTEXT); + string sOriginal; + + string::size_type nStartPos = string::npos; + string::size_type nEndPos = string::npos; + + // Only continue reading if there's something + if(GetFileSize(fileMSModeBatch, NULL)) + { + // Read Entire file in + DWORD dwToRead = 1024; + DWORD dwRead = 1024; + + do + { + dwToRead += dwToRead; + dwRead += dwRead; + + SetFilePointer(fileMSModeBatch, 0, NULL, FILE_BEGIN); + if(!ReadFile(fileMSModeBatch, sOriginal.get_buffer(dwToRead), dwToRead, &dwRead, NULL)) + { + HRESULT hr = ReportLastError(_T("Couldn't read from the batch file\n\n")); + CloseHandle(fileMSModeBatch); + return hr; + } + + sOriginal.release_buffer(); + sOriginal.resize(dwRead); + } + while(dwRead == dwToRead); + + + // Get the beginning of the insert + nStartPos = sOriginal.find(sStartSearchText); + // Get the beginning of the line + if(nStartPos != string::npos) + nStartPos = sOriginal.rfind(_T("\r\n"), nStartPos); + + // We found the beginning of the line skip the \r\n + if(nStartPos != string::npos) + nStartPos += 2; + // Otherwise just start from the top of the file + else + nStartPos = 0; + + // Get the Prefix Text + sPreText = sOriginal.substr(0, nStartPos); + + + + // Get the End of the Insert + nEndPos = sOriginal.find(sEndSearchText, nStartPos); + + // Try to find the next line + if(nEndPos != string::npos) + nEndPos = sOriginal.find(_T("\r\n"), nEndPos); + // Skip over that carriage return + if(nEndPos != string::npos) + nEndPos += 2; + + // If we found anything then retrieve Suffix Text + if(nEndPos != string::npos) + sPostText = sOriginal.substr(nEndPos, string::npos); + } + + // Now that we've read everything in close the file + CloseHandle(fileMSModeBatch); + + return S_OK; +} + +/////////////////////////////////////////////////////////////// +// Runs the Batchfile Created + +HRESULT CBatchFileCmpt::CallBatchFile() +{ + string sFileName; + + // Only go into DOS Mode if Windows 9x + // The different PIFs take care of that + if(::GetPlatform() == VER_PLATFORM_WIN32_NT) + sFileName.load_string(IDS_BATCHFILEPIF_NT); + else + sFileName.load_string(IDS_BATCHFILEPIF); + + + // Make Batchfile Name + string sTemp; + string sFileDir = GetProgramFolder(_Module.m_hInst); + + sFileName = sFileDir + sFileName; + +#ifndef _DEBUG + + // Run the batchfile (PIF) + if(ShellExecute(NULL, _T("open"), sFileName, NULL, sFileDir, SW_SHOWNORMAL) <= (HINSTANCE)32) + ::MessageBox(NULL, _T("Couldn't start MS-DOS mode batch file."), _T("Secure Shutdown"), MB_ICONSTOP); + +#endif // _DEBUG + + return S_OK; +} + + + +HRESULT CBatchFileCmpt::ReportLastError(string sMessage) +{ + HRESULT hr = HRESULT_FROM_WIN32(::GetLastError()); + sMessage += FormatHR(hr); + MessageBox(NULL, sMessage, _T("Secure Shutdown"), MB_ICONSTOP | MB_OK); + return hr; +} diff --git a/Shutdown/BatchFileCmpt.h b/Shutdown/BatchFileCmpt.h new file mode 100644 index 0000000..745f5fd --- /dev/null +++ b/Shutdown/BatchFileCmpt.h @@ -0,0 +1,58 @@ +////////////////////////////////////////////////////////////////// +// +// BatchFileCmpt.h: interface for the CBatchFileCmpt class. +// +// CBatchFileCmpt is a Host Implemented component only for this +// program it derives from CComponentHolder so it can fit +// into the main program array of components and then overrides +// most of the funtions. +// +// It's DoShutdown function creates the batchfile for all the DOS +// Components +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_BATCHFILECMPT_H__2DCE7A04_2D47_11D2_B2D4_0020182B97FC__INCLUDED_) +#define AFX_BATCHFILECMPT_H__2DCE7A04_2D47_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +#include "..\common\ComponentHolder.h" + +class CBatchFileCmpt + : public CComponentHolder +{ +public: + CBatchFileCmpt(); + virtual ~CBatchFileCmpt(); + + // Override + virtual HRESULT DoShutdown(DWORD dwMode, HWND hWndParent = NULL); + +protected: + HRESULT ReportLastError(string sMessage); + // Helper Functions + HRESULT MakeBatchFile(); + HRESULT GetCurBatchFile(const string& sFileName, string& sPreText, string& sPostText); + HRESULT CallBatchFile(); + + + bool m_bBatchFile; + + +public: + // Override these fellows to prevent problems + virtual bool IsEnabled() { return true; }; + virtual bool Enable(bool bEnable) { return bEnable; } ; + virtual int GetPos() { return 20; } ; + virtual bool SetPos(int nPos) { return false; } ; + virtual HRESULT GetBatchText(string& sBatchText) { return E_NOTIMPL; }; + virtual IUnknown* GetUnknown() { return NULL; }; + virtual UINT GetType() { return COMPONENT_WIN; }; + + +}; + +#endif // !defined(AFX_BATCHFILECMPT_H__2DCE7A04_2D47_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Shutdown/ItemDlg.cpp b/Shutdown/ItemDlg.cpp new file mode 100644 index 0000000..04c6264 --- /dev/null +++ b/Shutdown/ItemDlg.cpp @@ -0,0 +1,195 @@ +// ItemDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ItemDlg.h" + + + +///////////////////////////////////////////////////////////////////////////// +// CItemDlg dialog + + +CItemDlg::CItemDlg() + : CDialogImplEx(IDD), CPersistPosWindow<CItemDlg>(_T("Item")) +{ + m_hIcon = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDR_MAINFRAME)); + m_bCancel = false; +} + + +///////////////////////////////////////////////////////////////////////////// +// CItemDlg message handlers + +////////////////////////////////////////////////////////////////// +// Since we can't really cancel the current component +// Set flag and wait till there's a chance to close + +LRESULT CItemDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + g_site.Fire_Cancel(); + m_bCancel = true; + + // Give a visual indication that request has been handled + SetDlgItemText(IDCANCEL, _T("Cancelling...")); + ::EnableWindow(GetDlgItem(IDCANCEL), FALSE); + + return 0; +} + +LRESULT CItemDlg::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + OnCancel(0, 0, NULL, bHandled); + return 0; +} + +////////////////////////////////////////////////////////////////// +// InitDialog (what more can I say) + +LRESULT CItemDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Set the icon for this dialog. + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + + // Create the small icon image list. + m_ImageListSmall.Create(IDB_CHECKS, + 16, + 0, // list won't grow + RGB(255, 0, 255)); + + // Set Mask color for Image Lists + m_ImageListSmall.SetBkColor(CLR_NONE); + + m_ctlItems = GetDlgItem(IDC_ITEMS); + + // Associate the image lists with the list view control. + m_ctlItems.SetImageList(m_ImageListSmall, LVSIL_SMALL); + + + + // We need at least one bogus column since we're using + // report view + + LV_COLUMN lvC; // list view column structure + + // Now initialize the columns you will need. + // Initialize the LV_COLUMN structure. + // The mask specifies that the fmt, width, pszText, and subitem members + // of the structure are valid. + lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvC.fmt = LVCFMT_LEFT; // left-align column + lvC.cx = 200; // width of column in pixels + lvC.iSubItem = 0; + lvC.pszText = "Item"; + + if (m_ctlItems.InsertColumn(0, &lvC) == -1) + return true; + + + // Fill List Control + // Get Names of Windows Components + // string_array was passed in Create + // Loop through Items and get the names for Dialog box + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + + // If it's a Windows Component + if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN) + + // If it's currently active + if(g_aComponents[nCnt]->IsEnabled()) + + // Add it's name + m_ctlItems.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, + nCnt, g_aComponents[nCnt]->GetName(), 0, 0, 0, nCnt); + + } + + // Try and hide the control as best we can + m_ctlItems.SetBkColor(::GetSysColor(COLOR_3DFACE)); + m_ctlItems.SetTextBkColor(::GetSysColor(COLOR_3DFACE)); + + + // Make sure the column (although hidden from dlg template) + // is the width of control + + RECT rect; + m_ctlItems.GetClientRect(&rect); + m_ctlItems.SetColumnWidth(0, rect.right); + + + // See if we can get the Window Position + if(!LoadPosition(_Module.m_settings)) + { + // Move the Window to 50, 50 + GetWindowRect(&rect); + MoveWindow(50, 50, rect.right - rect.left, rect.bottom - rect.top); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +LRESULT CItemDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + SavePosition(_Module.m_settings); + return 0; +} + +////////////////////////////////////////////////////////////////// +// Gives the item a pointer image and scrolls it into view + +bool CItemDlg::SetCurrentItem(int nItem) +{ + // Setup Structures + LV_ITEM lv; + + lv.mask = LVIF_IMAGE; + lv.iSubItem = 0; + lv.iItem = nItem; + lv.iImage = 1; + + + // Scroll to item + m_ctlItems.EnsureVisible(nItem, false); + + // Give the item the right image + return m_ctlItems.SetItem(&lv) ? true : false; +} + +////////////////////////////////////////////////////////////////// +// Gives the item a tick or cross image depending on bState + +bool CItemDlg::CheckOffItem(int nItem, bool bState /*= true*/) +{ + // Setup Structures + LV_ITEM lv; + + lv.mask = LVIF_IMAGE; + lv.iSubItem = 0; + lv.iItem = nItem; + lv.iImage = bState ? 2 : 3; // Image 2 is tick, 3 is cross + + // Set right image for item + return m_ctlItems.SetItem(&lv) ? true : false; + +} + +LRESULT CItemDlg::OnSetFocusItems(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + CancelItemSelection(); + return 0; +} + + +void CItemDlg::CancelItemSelection() +{ + // Deselect All + for(int nCnt = 0; nCnt < m_ctlItems.GetItemCount(); nCnt ++) + // Set right state for item + ListView_SetItemState(m_ctlItems, nCnt, 0, (UINT)-1); + + GotoDlgCtrl(GetDlgItem(IDCANCEL)); +} diff --git a/Shutdown/ItemDlg.h b/Shutdown/ItemDlg.h new file mode 100644 index 0000000..f3abab1 --- /dev/null +++ b/Shutdown/ItemDlg.h @@ -0,0 +1,81 @@ +////////////////////////////////////////////////////////////////// +// +// ItemDlg.h : header file +// +// Dialog for Shutdown. Handles different pix and strings etc.. +// +////////////////////////////////////////////////////////////////// + + +#if !defined(AFX_ITEMDLG_H__39C297A3_2DCF_11D2_B2D4_0020182B97FC__INCLUDED_) +#define AFX_ITEMDLG_H__39C297A3_2DCF_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 + +#include <atlwin.h> +#include <atlctrls.h> +#include "resource.h" + +#include "PersistPosWindow.h" + +///////////////////////////////////////////////////////////////////////////// +// CItemDlg dialog + +class CItemDlg + : public CDialogImplEx, +// : public CDialogImpl<CItemDlg> + public CPersistPosWindow<CItemDlg> + +{ +// Construction +public: + CItemDlg(); // standard constructor + ~CItemDlg() + { if(IsWindow()) DestroyWindow(); } + + // Used to tick off an item + // if bState is false means failed + bool CheckOffItem(int nItem, bool bState = true); + + // Give item a pointer next to it + bool SetCurrentItem(int nItem); + + // Has Cancel Button been pressed + bool IsCancelled() + { return m_bCancel; }; + +// Dialog Data + enum { IDD = IDD_ITEMDLG }; + CListViewCtrl m_ctlItems; + + +// Implementation +protected: + void CancelItemSelection(); + bool m_bCancel; + CImageList m_ImageListSmall; + HICON m_hIcon; + + +BEGIN_MSG_MAP(CNormalPage) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) + NOTIFY_HANDLER(IDC_ITEMS, NM_SETFOCUS, OnSetFocusItems) + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) + MESSAGE_HANDLER(WM_CLOSE, OnClose) +END_MSG_MAP() + + // Generated message map functions + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnSetFocusItems(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Developer Studio will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_ITEMDLG_H__39C297A3_2DCF_11D2_B2D4_0020182B97FC__INCLUDED_) diff --git a/Shutdown/LogDlg.cpp b/Shutdown/LogDlg.cpp new file mode 100644 index 0000000..3d94bc9 --- /dev/null +++ b/Shutdown/LogDlg.cpp @@ -0,0 +1,502 @@ +// LogDlg.cpp : Implementation of CShutdownApp and DLL registration. + +#include "stdafx.h" +#include "LogDlg.h" + +#include <algorithm> +using std::replace; + +_COM_SMARTPTR_TYPEDEF(INightSecErrorFix, __uuidof(INightSecErrorFix)); + +#include <appmisc.h> +#include <shlobj.h> + +#define IMAGE_OKAY 0 +#define IMAGE_ERROR 1 + +///////////////////////////////////////////////////////////////////////////// +// +LRESULT CLogDlg::OnHide(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // We use this event to keep the program open + // when the user is looking at the log + if(m_hEvent) + SetEvent(m_hEvent); + + ShowWindow(SW_HIDE); + return 0; +} + +LRESULT CLogDlg::OnSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // I think this is good enough. ie: saving on the desktop. + if(IDYES == MessageBox(_T("The log will be saved on your desktop. Continue?"), _T("Save Log"), MB_YESNO | MB_ICONQUESTION)) + SaveLog(); + + return 0; +} + +LRESULT CLogDlg::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + OnHide(0, 0, NULL, bHandled); + return 0; +} + +/*LRESULT CLogDlg::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + return 0; +} +*/ +////////////////////////////////////////////////////////////////// +// InitDialog (what more can I say) + +LRESULT CLogDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + m_hIcon = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDI_ERR)); + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // Create the small icon image list. + m_ImageListSmall.Create(IDB_ERRORS, + 16, + 0, // list won't grow + RGB(255, 0, 255)); + + // Set Mask color for Image Lists + m_ImageListSmall.SetBkColor(CLR_NONE); + + m_ctlErrors = GetDlgItem(IDC_ERROR_LOG); + + // Associate the image lists with the list view control. + m_ctlErrors.SetImageList(m_ImageListSmall, LVSIL_SMALL); + + // This sets the sizing of the dialog + SetMin(IDC_MINSIZE); + SetControlSizing(ID_SAVE, SD_HORZ | SD_MOVING); + SetControlSizing(ID_HIDE, SD_HORZ | SD_MOVING); + SetControlSizing(IDC_ERROR_LOG, SD_HORZ | SD_VERT | SD_SIZING); + + // We need at least one bogus column since we're using + // report view + LV_COLUMN lvC; // list view column structure + + // Now initialize the columns you will need. + // Initialize the LV_COLUMN structure. + // The mask specifies that the fmt, width, pszText, and subitem members + // of the structure are valid. + lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvC.fmt = LVCFMT_LEFT; // left-align column + lvC.cx = 200; // width of column in pixels + lvC.iSubItem = 0; + lvC.pszText = _T("Errors"); + + if (m_ctlErrors.InsertColumn(0, &lvC) == -1) + return true; + + // Make sure the column is the width of control + RECT rect; + m_ctlErrors.GetClientRect(&rect); + m_ctlErrors.SetColumnWidth(0, rect.right); + + // Move Window to previous position + if(!LoadPosition(_Module.m_settings)) + // If fails then Center it on the desktop + CenterWindow(GetDesktopWindow()); + + // This event gets set when we're hidden + m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +LRESULT CLogDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Clear All Items (which also releases the COM Objects) + while(m_ctlErrors.GetItemCount()) + RemoveItem(0); + + // Just in case set the event + if(m_hEvent) + SetEvent(m_hEvent); + + // Put window position in registry for next time + SavePosition(_Module.m_settings); + + return 0; +} + +////////////////////////////////////////////////////////////////// +// Gives the item a tick or cross image depending on bState + +bool CLogDlg::AddItem(INightSecError* pError) +{ + USES_CONVERSION; + + if(!pError) + return false; + + // Get the Description of the Error + BSTR bsTemp; + HRESULT hr = pError->get_Description(&bsTemp); + + if(FAILED(hr)) + return false; + + // Clean up any new lines + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\n', L' '); + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\r', L' '); + + // Make sure object stays around + pError->AddRef(); + + // Create or Show the Log Window + ShowLog(); + + // Setup Structures + LV_ITEM lv; + lv.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM; + lv.iSubItem = 0; + lv.iItem = m_ctlErrors.GetItemCount(); + lv.iImage = 1; + lv.lParam = (LPARAM)pError; + lv.pszText = OLE2T(bsTemp); + + // Set right image for item + return m_ctlErrors.InsertItem(&lv) ? true : false; +} + +void CLogDlg::ShowLog() +{ + // If not created then Create + if(!IsWindow()) + Create(m_hWndParent, NULL); + + // Make sure it's Visible + if(!IsWindowVisible()) + ShowWindow(SW_SHOW); + + // Make sure event is not signalled so we don't just close by self + ResetEvent(m_hEvent); +} + +void CLogDlg::WaitLog() +{ + // Prompt the user + UINT nRet = MessageBoxTimeout(g_site.m_log, _T("There were errors during Secure Shutdown. \n\nWould you like to pause a moment before continuing?"), _T("Secure Shutdown"), MB_YESNO | MB_ICONQUESTION, 10000, 5000); + + if(nRet == IDYES) + { + // Display the Log Window + ShowLog(); + + // Wait for the Event + if(m_hEvent) + WaitForAndIdle(1, &m_hEvent, INFINITE); + } + + // If we time out then save the log on the desktop + else if(nRet == IDTIMEOUT) + if(!_Module.m_settings.GetInt(NO_LOG_KEY, false)) + SaveLog(); +} + +HRESULT CLogDlg::SaveLog(/*const string& sFile*/) +{ + string sFile; + LPITEMIDLIST pidl; + HRESULT hr; + + // Get Desktop PIDL + hr = SHGetSpecialFolderLocation(*this, CSIDL_DESKTOPDIRECTORY, &pidl); + + if(FAILED(hr)) + return 0; + + // Get the Folder from That + if(!SHGetPathFromIDList(pidl, sFile.get_buffer(MAX_PATH))) + return 0; + + sFile.release_buffer(); + + // This is the file name + // LIMITATION: Can't be changed + sFile += _T("\\Secure Shutdown Log.txt"); + + // Open the File + HANDLE hFile = NULL; + if((hFile = CreateFile(sFile, GENERIC_WRITE, FILE_SHARE_READ, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, + NULL)) == INVALID_HANDLE_VALUE) + return HRESULT_FROM_WIN32(::GetLastError()); + + int nPos = -1; + DWORD dwWritten; + + // Always use ANSI here + // LIMITATION: Only errors up to 1K in length + char* szText = new char[1024]; + + // Write Header + char* szTemp = "SECURE SHUTDOWN ERROR LOG\r\n\r\n"; + WriteFile(hFile, szTemp, strlen(szTemp), &dwWritten, NULL); + + LVITEMA lvi; + memset(&lvi, 0, sizeof(LVITEMA)); + + while((nPos = m_ctlErrors.GetNextItem(nPos, 0)) != -1) + { + // We need all this crazy code here to make sure + // We get ANSI text in UNICODE Builds. + lvi.mask = LVIF_TEXT | LVIF_IMAGE; + lvi.iItem = nPos; + lvi.iSubItem = 0; + lvi.cchTextMax = 1024; + lvi.pszText = szText; + lvi.iImage = 0; + + ::SendMessageA(m_ctlErrors, LVM_GETITEMA, 0, (LPARAM)&lvi); + + // Only write errors (No Fixed) + if(lvi.iImage != IMAGE_OKAY) + { + // Write it to the file + WriteFile(hFile, szText, strlen(szText), &dwWritten, NULL); + WriteFile(hFile, "\r\n", 2, &dwWritten, NULL); + } + } + + // Close the File + CloseHandle(hFile); + + return S_OK; +} + +bool CLogDlg::HasErrors() +{ + if(!IsWindow()) + return false; + + // If we're created then we've got errors + int nPos = -1; + LV_ITEM lv; + while((nPos = m_ctlErrors.GetNextItem(nPos, LVNI_ALL)) != -1) + { + lv.mask = LVIF_IMAGE; + lv.iItem = nPos; + lv.iSubItem = 0; + m_ctlErrors.GetItem(&lv); + + if(lv.iImage == IMAGE_ERROR) + return true; + } + + return false; +} + +LRESULT CLogDlg::OnListRClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // First of all get the mouse incase we move (unlikely) + POINT ptMouse; + ::GetCursorPos(&ptMouse); + + LVHITTESTINFO lvHit; + lvHit.pt = ptMouse; + lvHit.flags = LVHT_ONITEM; + + m_ctlErrors.ScreenToClient(&lvHit.pt); + int nIndex = m_ctlErrors.HitTest(&lvHit); + + // If we didn't click on an item then... + if(nIndex == -1) + { + // ...Deselect All + for(int nCnt = 0; nCnt < m_ctlErrors.GetItemCount(); nCnt ++) + // Set right state for item + ListView_SetItemState(m_ctlErrors, nCnt, 0, (UINT)-1); + + return 0; + } + + // Focus on Current Item + ListView_SetItemState(m_ctlErrors, nIndex, LVIS_SELECTED | LVIS_FOCUSED, + LVIS_STATEIMAGEMASK); + + // Load the Menu + HMENU hMenu = ::LoadMenu(_Module.m_hInstResource, MAKEINTRESOURCE(IDR_ERROR_MENU)); + if (!hMenu) return 0; + + HMENU hSubMenu = GetSubMenu(hMenu, 0); + if (!hSubMenu) + { + DestroyMenu(hMenu); + return 0; + } + + // Get a COM Pointer to the current Error + INightSecErrorFixPtr pFix = (INightSecError*)m_ctlErrors.GetItemData(nIndex); + + if(pFix) + { + // Check if Fixable + BOOL bFixable = FALSE; + if(SUCCEEDED(pFix->get_Fixable(&bFixable)) && bFixable) + ::EnableMenuItem(hSubMenu, ID_ERROR_FIX, MF_BYCOMMAND | MF_ENABLED); + + // Check if Retryable + BOOL bRetryable = FALSE; + if(SUCCEEDED(pFix->get_Retryable(&bRetryable)) && bRetryable) + ::EnableMenuItem(hSubMenu, ID_ERROR_RETRY, MF_BYCOMMAND | MF_ENABLED); + } + + // Make the default (same as double-click) Retry + SetMenuDefaultItem(hSubMenu, ID_ERROR_RETRY, FALSE); + + // Show the Menu + ::TrackPopupMenu(hSubMenu, 0, ptMouse.x, ptMouse.y, 0, m_hWnd, NULL); + ::PostMessage(m_hWnd, WM_USER, 0, 0); + return 0; +} + +LRESULT CLogDlg::OnErrorFix(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // Fix all selected items + int nPos = -1; + while((nPos = m_ctlErrors.GetNextItem(nPos, LVIS_SELECTED)) != -1) + FixItem(nPos); + + return 0; +} + +LRESULT CLogDlg::OnErrorRetry(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // Retry all selected Items + int nPos = -1; + while((nPos = m_ctlErrors.GetNextItem(nPos, LVIS_SELECTED)) != -1) + RetryItem(nPos); + + return 0; +} + +LRESULT CLogDlg::OnErrorDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // Delete all selected items + int nPos = -1; + while((nPos = m_ctlErrors.GetNextItem(nPos, LVIS_SELECTED)) != -1) + RemoveItem(nPos); + + return 0; +} + +HRESULT CLogDlg::FixItem(int nIndex) +{ + USES_CONVERSION; + + // Extract COM Pointer from ListCtrl + INightSecErrorFixPtr pFix = (INightSecError*)m_ctlErrors.GetItemData(nIndex); + + if(pFix == NULL) + return 0; + + // Check if actually fixable + BOOL bFixable = FALSE; + if(FAILED(pFix->get_Fixable(&bFixable)) || !bFixable) + return 0; + + // Fix it + HCURSOR hOldCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT)); + + HRESULT hr = pFix->Fix(); + + ::SetCursor(hOldCursor); + + INightSecErrorPtr pError = pFix; + + if(pError == NULL) + return 0; + + // Get New Error Messages + BSTR bsTemp; + pError->get_Description(&bsTemp); + + // Clean up newlines + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\n', L' '); + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\r', L' '); + + // Set Image and Text + LV_ITEM lv; + lv.mask = LVIF_IMAGE | LVIF_TEXT; + lv.iSubItem = 0; + lv.iItem = nIndex; + lv.pszText = OLE2T(bsTemp); + lv.iImage = SUCCEEDED(hr) ? 0 : 1; + + // Set right image and text for item + m_ctlErrors.SetItem(&lv); + + return hr; +} + +HRESULT CLogDlg::RetryItem(int nIndex) +{ + USES_CONVERSION; + + // Extract COM Pointer from List Ctrl + INightSecErrorFixPtr pFix = (INightSecError*)m_ctlErrors.GetItemData(nIndex); + + if(pFix == NULL) + return 0; + + // Check if we can actually Retry + BOOL bRetryable = FALSE; + if(FAILED(pFix->get_Retryable(&bRetryable)) || !bRetryable) + return 0; + + // Retry it + HCURSOR hOldCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT)); + + HRESULT hr = pFix->Retry(); + + ::SetCursor(hOldCursor); + + INightSecErrorPtr pError = pFix; + + if(pError == NULL) + return 0; + + // Get new Error Messages + BSTR bsTemp; + pError->get_Description(&bsTemp); + + // Clean up newlines + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\n', L' '); + replace(bsTemp, bsTemp + SysStringLen(bsTemp), L'\r', L' '); + + // Set Image and Text + LV_ITEM lv; + lv.mask = LVIF_IMAGE | LVIF_TEXT; + lv.iSubItem = 0; + lv.iItem = nIndex; + lv.pszText = OLE2T(bsTemp); + lv.iImage = SUCCEEDED(hr) ? IMAGE_OKAY : IMAGE_ERROR; + + // Set right image and text for item + m_ctlErrors.SetItem(&lv); + + return hr; +} + +bool CLogDlg::RemoveItem(int nIndex) +{ + // Release COM Ptr + INightSecError* pError = (INightSecError*)m_ctlErrors.GetItemData(nIndex); + if(pError) pError->Release(); + + // Remove it + return m_ctlErrors.DeleteItem(nIndex) ? true : false; +} + +void CLogDlg::Init(HWND hWndParent) +{ + m_hWndParent = hWndParent; +} diff --git a/Shutdown/LogDlg.h b/Shutdown/LogDlg.h new file mode 100644 index 0000000..ac174b4 --- /dev/null +++ b/Shutdown/LogDlg.h @@ -0,0 +1,102 @@ +// LogDlg.h: Definition of the CLogDlg class +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_LOGDLG_H__F3AF1F46_93A1_11D3_BFC3_0020182B97FC__INCLUDED_) +#define AFX_LOGDLG_H__F3AF1F46_93A1_11D3_BFC3_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "resource.h" // main symbols +#include <atlwin.h> +#include <atlctrls.h> +#include <contexthelp.h> + +#include "SizingDialog.h" +#include "PersistPosWindow.h" + +///////////////////////////////////////////////////////////////////////////// +// CLogDlg + +class CLogDlg + : public CDialogImplEx, +// : public CDialogImpl<CLogDlg>, + public CSizingDialog<CLogDlg>, + public CPersistPosWindow<CLogDlg>, + public CContextHelp<CLogDlg> +{ +public: + CLogDlg() : CDialogImplEx(IDD), CPersistPosWindow<CLogDlg>(_T("Log")) + { + m_hWndParent = NULL; + m_hEvent = NULL; + m_hIcon = NULL; + } + + ~CLogDlg() + { + if(IsWindow()) + DestroyWindow(); + + if(m_hEvent) + CloseHandle(m_hEvent); + } + +// Dialog Data +protected: + enum { IDD = IDD_LOG }; + CListViewCtrl m_ctlErrors; + CImageList m_ImageListSmall; + HWND m_hWndParent; + HICON m_hIcon; + HANDLE m_hEvent; + +public: +BEGIN_MSG_MAP(CLogDlg) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) + MESSAGE_HANDLER(WM_CLOSE, OnClose) +// MESSAGE_HANDLER(WM_TIMER, OnTimer) + NOTIFY_HANDLER(IDC_ERROR_LOG, NM_RCLICK, OnListRClick) + COMMAND_HANDLER(ID_HIDE, BN_CLICKED, OnHide) + COMMAND_HANDLER(ID_SAVE, BN_CLICKED, OnSave) + COMMAND_ID_HANDLER(ID_ERROR_FIX, OnErrorFix) + COMMAND_ID_HANDLER(ID_ERROR_RETRY, OnErrorRetry) + COMMAND_ID_HANDLER(ID_ERROR_DELETE, OnErrorDelete) + CHAIN_MSG_MAP(CSizingDialog<CLogDlg>) + CHAIN_MSG_MAP(CContextHelp<CLogDlg>) +END_MSG_MAP() + +BEGIN_HELP_MAP("nightsec.hlp") + HELP_ID(IDC_ERROR_LOG, 5003) + HELP_ID(ID_HIDE, 5002) + HELP_ID(ID_SAVE, 5001) +END_HELP_MAP + + // Generated message map functions + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); +// LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnListRClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); + LRESULT OnHide(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnErrorFix(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnErrorRetry(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnErrorDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + +public: + void Init(HWND hWndParent); + bool RemoveItem(int nIndex); + HRESULT FixItem(int nIndex); + HRESULT RetryItem(int nIndex); + bool AddItem(INightSecError* pError); + bool HasErrors(); + void ShowLog(); + HRESULT SaveLog(/*const string& sFile*/); + void WaitLog(); +}; + +#endif // !defined(AFX_LOGDLG_H__F3AF1F46_93A1_11D3_BFC3_0020182B97FC__INCLUDED_) diff --git a/Shutdown/LogDlg.rgs b/Shutdown/LogDlg.rgs new file mode 100644 index 0000000..5c5c83b --- /dev/null +++ b/Shutdown/LogDlg.rgs @@ -0,0 +1,21 @@ +HKCR
+{
+ Shutdown.LogDlg.1 = s 'LogDlg Class'
+ {
+ CLSID = s '{F3AF1F45-93A1-11D3-BFC3-0020182B97FC}'
+ }
+ Shutdown.LogDlg = s 'LogDlg Class'
+ {
+ CLSID = s '{F3AF1F45-93A1-11D3-BFC3-0020182B97FC}'
+ }
+ NoRemove CLSID
+ {
+ ForceRemove {F3AF1F45-93A1-11D3-BFC3-0020182B97FC} = s 'LogDlg Class'
+ {
+ ProgID = s 'Shutdown.LogDlg.1'
+ VersionIndependentProgID = s 'Shutdown.LogDlg'
+ val AppID = s '{936DD342-8FF9-11D3-BFBD-0020182B97FC}'
+ LocalServer32 = s '%Module%'
+ }
+ }
+}
diff --git a/Shutdown/PersistPosWindow.cpp b/Shutdown/PersistPosWindow.cpp new file mode 100644 index 0000000..131a236 --- /dev/null +++ b/Shutdown/PersistPosWindow.cpp @@ -0,0 +1,11 @@ +// PersistPosWindow.cpp: implementation of the CPersistPosWindow class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "PersistPosWindow.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + diff --git a/Shutdown/PersistPosWindow.h b/Shutdown/PersistPosWindow.h new file mode 100644 index 0000000..74aff51 --- /dev/null +++ b/Shutdown/PersistPosWindow.h @@ -0,0 +1,112 @@ +// PersistPosWindow.h: interface for the CPersistPosWindow class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_PERSISTPOSWINDOW_H__7D209B81_ED68_11D3_8378_0020182B97FC__INCLUDED_) +#define AFX_PERSISTPOSWINDOW_H__7D209B81_ED68_11D3_8378_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include <RegSettings.h> + +template<class T> +class CPersistPosWindow +{ +public: + CPersistPosWindow(LPCTSTR szPrefix) + { m_szPrefix = szPrefix; }; + + bool LoadPosition(CRegSettings& settings); + bool SavePosition(CRegSettings& settings); + +protected: + LPCTSTR m_szPrefix; // Prefix for Registry Entries +}; + +template <class T> +bool CPersistPosWindow<T>::LoadPosition(CRegSettings& settings) +{ + // Pointer to the Window Class + T* pThis = (T*)this; + + // Init WINDOWPLACEMENT Structure + WINDOWPLACEMENT wp; + wp.length = sizeof(WINDOWPLACEMENT); + wp.flags = 0; + wp.showCmd = SW_SHOWNA; + // Not worrying about these for now + // Probably okay + wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0; + wp.ptMinPosition.x = wp.ptMinPosition.y = 0; + + + // This prefix is used before each Registry Entry + string sPrefix(m_szPrefix); + + // Load the Window Position from the registry + wp.rcNormalPosition.top = settings.GetInt(sPrefix + _T("_top"), -1); + wp.rcNormalPosition.left = settings.GetInt(sPrefix + _T("_left"), -1); + wp.rcNormalPosition.bottom = settings.GetInt(sPrefix + _T("_bottom"), -1); + wp.rcNormalPosition.right = settings.GetInt(sPrefix + _T("_right"), -1); + + // Make sure each of them got a value from the Registry + // If not don't proceed + if(wp.rcNormalPosition.top != -1 && + wp.rcNormalPosition.left != -1 && + wp.rcNormalPosition.bottom != -1 && + wp.rcNormalPosition.right != -1) + { + + // Check if on screen or not + WINDOWPLACEMENT wpScreen; + wpScreen.length = sizeof(WINDOWPLACEMENT); + wpScreen.flags = 0; + + GetWindowPlacement(GetDesktopWindow(), &wpScreen); + + // See if Desktop Window and our Window Intersect + // If not don't proceed + RECT rcTemp; + if(IntersectRect(&rcTemp, &wpScreen.rcNormalPosition, + &wp.rcNormalPosition)) + { + + // Move and Size the actual Window + SetWindowPlacement(*pThis, &wp); + return true; + + } + } + + return false; +} + +template <class T> +bool CPersistPosWindow<T>::SavePosition(CRegSettings& settings) +{ + // Pointer to our Window Class + T* pThis = (T*)this; + + WINDOWPLACEMENT wp; + wp.length = sizeof(WINDOWPLACEMENT); + wp.flags = 0; + + // Get the Current Placement + GetWindowPlacement(*pThis, &wp); + + // This goes in front of each Registry Entry + string sPrefix(m_szPrefix); + + // Write to the registry + settings.WriteInt(sPrefix + _T("_top"), wp.rcNormalPosition.top); + settings.WriteInt(sPrefix + _T("_left"), wp.rcNormalPosition.left); + settings.WriteInt(sPrefix + _T("_bottom"), wp.rcNormalPosition.bottom); + settings.WriteInt(sPrefix + _T("_right"), wp.rcNormalPosition.right); + + return true; +} + + +#endif // !defined(AFX_PERSISTPOSWINDOW_H__7D209B81_ED68_11D3_8378_0020182B97FC__INCLUDED_) diff --git a/Shutdown/Shutdown.cpp b/Shutdown/Shutdown.cpp new file mode 100644 index 0000000..e06992f --- /dev/null +++ b/Shutdown/Shutdown.cpp @@ -0,0 +1,118 @@ +// Shutdown.cpp : Implementation of WinMain + + +// Note: Proxy/Stub Information +// To build a separate proxy/stub DLL, +// run nmake -f Shutdownps.mk in the project directory. + +#include "stdafx.h" +#include "resource.h" +#include <initguid.h> +#include "Shutdown.h" + +#include "Shutdown_i.c" + +#include "../common/Interfaces.cpp" + +CShutdownApp _Module; +CComObjectGlobal<CShutdownSite> g_site; + +/* +BEGIN_OBJECT_MAP(ObjectMap) +END_OBJECT_MAP() +*/ + +const DWORD dwPause = 1000; // time to wait for threads to finish up + +LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2) +{ + while (p1 != NULL && *p1 != NULL) + { + LPCTSTR p = p2; + while (p != NULL && *p != NULL) + { + if (*p1 == *p) + return CharNext(p1); + p = CharNext(p); + } + p1 = CharNext(p1); + } + return NULL; +} + +///////////////////////////////////////////////////////////////////////////// +// +extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, + HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) +{ + lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT + +#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) + HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); +#else + HRESULT hRes = CoInitialize(NULL); +#endif + _ASSERTE(SUCCEEDED(hRes)); + _Module.Init(NULL/*ObjectMap*/, hInstance, &LIBID_SHUTDOWNLib); +// _Module.dwThreadID = GetCurrentThreadId(); + TCHAR szTokens[] = _T("-/"); + + int nRet = 0; + BOOL bRun = TRUE; + LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); + while (lpszToken != NULL) + { + if (lstrcmpi(lpszToken, _T("UnregServer"))==0) + { +// _Module.UpdateRegistryFromResource(IDR_Shutdown, FALSE); +// nRet = _Module.UnregisterServer(TRUE); + bRun = FALSE; + break; + } + if (lstrcmpi(lpszToken, _T("RegServer"))==0) + { + _Module.RegisterDlls(); + +// _Module.UpdateRegistryFromResource(IDR_Shutdown, TRUE); +// nRet = _Module.RegisterServer(TRUE); + bRun = FALSE; + break; + } + lpszToken = FindOneOf(lpszToken, szTokens); + } + + if (bRun) + { +// _Module.StartMonitor(); +#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) +// hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, +// REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); +// _ASSERTE(SUCCEEDED(hRes)); +// hRes = CoResumeClassObjects(); +#else +// hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, +// REGCLS_MULTIPLEUSE); +#endif +// _ASSERTE(SUCCEEDED(hRes)); + + if(_Module.InitInstance()) + { + + MSG msg; + while (GetMessage(&msg, 0, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + +// _Module.RevokeClassObjects(); +// Sleep(dwPause); //wait for any threads to finish + } + + _Module.ExitInstance(); + } + + _Module.Term(); + CoUninitialize(); + return nRet; +} diff --git a/Shutdown/Shutdown.dsp b/Shutdown/Shutdown.dsp new file mode 100644 index 0000000..e324fb2 --- /dev/null +++ b/Shutdown/Shutdown.dsp @@ -0,0 +1,455 @@ +# Microsoft Developer Studio Project File - Name="Shutdown" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=Shutdown - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Shutdown.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Shutdown.mak" CFG="Shutdown - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Shutdown - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE "Shutdown - Win32 Unicode Debug" (based on "Win32 (x86) Application") +!MESSAGE "Shutdown - Win32 Release MinSize" (based on "Win32 (x86) Application") +!MESSAGE "Shutdown - Win32 Release MinDependency" (based on "Win32 (x86) Application") +!MESSAGE "Shutdown - Win32 Unicode Release MinSize" (based on "Win32 (x86) Application") +!MESSAGE "Shutdown - Win32 Unicode Release MinDependency" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Shutdown - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib /nologo /subsystem:windows /debug /machine:I386 /out:"../Debug/Shutdown.exe" /pdbtype:sept +# Begin Custom Build - Performing registration +OutDir=.\Debug +TargetPath=\Projects\NightSec\Debug\Shutdown.exe +InputPath=\Projects\NightSec\Debug\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + +# End Custom Build + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "DebugU" +# PROP BASE Intermediate_Dir "DebugU" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "DebugU" +# PROP Intermediate_Dir "DebugU" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /out:"../Debug/Shutdown.exe" /pdbtype:sept +# Begin Custom Build - Performing registration +OutDir=.\DebugU +TargetPath=\Projects\NightSec\Debug\Shutdown.exe +InputPath=\Projects\NightSec\Debug\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + if "%OS%"=="" goto NOTNT + if not "%OS%"=="Windows_NT" goto NOTNT + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + goto end + :NOTNT + echo Warning : Cannot register Unicode EXE on Windows 95 + :end + +# End Custom Build + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Release MinSize" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseMinSize" +# PROP BASE Intermediate_Dir "ReleaseMinSize" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseMinSize" +# PROP Intermediate_Dir "ReleaseMinSize" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_ATL_DLL" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_ATL_DLL" /Yu"stdafx.h" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comctl32.lib /nologo /subsystem:windows /machine:I386 /out:"../Release/Shutdown.exe" /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none +# Begin Custom Build - Performing registration +OutDir=.\ReleaseMinSize +TargetPath=\Projects\NightSec\Release\Shutdown.exe +InputPath=\Projects\NightSec\Release\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + +# End Custom Build + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Release MinDependency" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseMinDependency" +# PROP BASE Intermediate_Dir "ReleaseMinDependency" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseMinDependency" +# PROP Intermediate_Dir "ReleaseMinDependency" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib /nologo /subsystem:windows /machine:I386 /out:"../Release/Shutdown.exe" +# Begin Custom Build - Performing registration +OutDir=.\ReleaseMinDependency +TargetPath=\Projects\NightSec\Release\Shutdown.exe +InputPath=\Projects\NightSec\Release\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + +# End Custom Build + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Release MinSize" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseUMinSize" +# PROP BASE Intermediate_Dir "ReleaseUMinSize" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseUMinSize" +# PROP Intermediate_Dir "ReleaseUMinSize" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_ATL_DLL" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_ATL_DLL" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"../Release/Shutdown.exe" +# Begin Custom Build - Performing registration +OutDir=.\ReleaseUMinSize +TargetPath=\Projects\NightSec\Release\Shutdown.exe +InputPath=\Projects\NightSec\Release\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + if "%OS%"=="" goto NOTNT + if not "%OS%"=="Windows_NT" goto NOTNT + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + goto end + :NOTNT + echo Warning : Cannot register Unicode EXE on Windows 95 + :end + +# End Custom Build + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Release MinDependency" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseUMinDependency" +# PROP BASE Intermediate_Dir "ReleaseUMinDependency" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseUMinDependency" +# PROP Intermediate_Dir "ReleaseUMinDependency" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# Begin Custom Build - Performing registration +OutDir=.\ReleaseUMinDependency +TargetPath=.\ReleaseUMinDependency\Shutdown.exe +InputPath=.\ReleaseUMinDependency\Shutdown.exe +SOURCE="$(InputPath)" + +"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + if "%OS%"=="" goto NOTNT + if not "%OS%"=="Windows_NT" goto NOTNT + "$(TargetPath)" /RegServer + echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg" + echo Server registration done! + goto end + :NOTNT + echo Warning : Cannot register Unicode EXE on Windows 95 + :end + +# End Custom Build + +!ENDIF + +# Begin Target + +# Name "Shutdown - Win32 Debug" +# Name "Shutdown - Win32 Unicode Debug" +# Name "Shutdown - Win32 Release MinSize" +# Name "Shutdown - Win32 Release MinDependency" +# Name "Shutdown - Win32 Unicode Release MinSize" +# Name "Shutdown - Win32 Unicode Release MinDependency" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\Include\src\appmisc.cpp +# End Source File +# Begin Source File + +SOURCE=.\BatchFileCmpt.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ComponentArray.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ComponentData.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ComponentHolder.cpp +# End Source File +# Begin Source File + +SOURCE=.\ItemDlg.cpp +# End Source File +# Begin Source File + +SOURCE=.\LogDlg.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\NightSecApp.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Include\src\path.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Include\src\RegSvr.cpp +# End Source File +# Begin Source File + +SOURCE=.\Shutdown.cpp +# End Source File +# Begin Source File + +SOURCE=.\Shutdown.idl + +!IF "$(CFG)" == "Shutdown - Win32 Debug" + +# ADD MTL /tlb "Shutdown.tlb" + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Debug" + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Release MinSize" + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Release MinDependency" + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Release MinSize" + +!ELSEIF "$(CFG)" == "Shutdown - Win32 Unicode Release MinDependency" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\Shutdown.rc +# End Source File +# Begin Source File + +SOURCE=.\ShutdownApp.cpp +# End Source File +# Begin Source File + +SOURCE=.\ShutdownSite.cpp +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"stdafx.h" +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\Include\appmisc.h +# End Source File +# Begin Source File + +SOURCE=.\BatchFileCmpt.h +# End Source File +# Begin Source File + +SOURCE=.\ItemDlg.h +# End Source File +# Begin Source File + +SOURCE=.\LogDlg.h +# End Source File +# Begin Source File + +SOURCE=..\..\Include\path.h +# End Source File +# Begin Source File + +SOURCE=.\PersistPosWindow.h +# End Source File +# Begin Source File + +SOURCE=.\Resource.h +# End Source File +# Begin Source File + +SOURCE=.\ShutdownApp.h +# End Source File +# Begin Source File + +SOURCE=.\ShutdownCP.h +# End Source File +# Begin Source File + +SOURCE=.\ShutdownSite.h +# End Source File +# Begin Source File + +SOURCE=.\SizingDialog.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\res\bitmap1.bmp +# End Source File +# Begin Source File + +SOURCE=.\res\checks1.bmp +# End Source File +# Begin Source File + +SOURCE=.\res\icon1.ico +# End Source File +# Begin Source File + +SOURCE=.\LogDlg.rgs +# End Source File +# Begin Source File + +SOURCE=.\res\LogDlg.rgs +# End Source File +# Begin Source File + +SOURCE=".\res\Night Security Shutdown.ico" +# End Source File +# Begin Source File + +SOURCE=".\res\Night Security Stub.ico" +# End Source File +# Begin Source File + +SOURCE=.\Shutdown.rgs +# End Source File +# End Group +# End Target +# End Project diff --git a/Shutdown/Shutdown.h b/Shutdown/Shutdown.h new file mode 100644 index 0000000..c2964c7 --- /dev/null +++ b/Shutdown/Shutdown.h @@ -0,0 +1,57 @@ +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + +/* File created by MIDL compiler version 5.01.0164 */ +/* at Wed Nov 03 10:32:26 1999 + */ +/* Compiler settings for E:\Projects\NightSec\Shutdown\Shutdown.idl: + Oicf (OptLev=i2), W1, Zp8, env=Win32, ms_ext, c_ext + error checks: allocation ref bounds_check enum stub_data +*/ +//@@MIDL_FILE_HEADING( ) + + +/* verify that the <rpcndr.h> version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 440 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __Shutdown_h__ +#define __Shutdown_h__ + +#ifdef __cplusplus +extern "C"{ +#endif + +/* Forward Declarations */ + +/* 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 * ); + + +#ifndef __SHUTDOWNLib_LIBRARY_DEFINED__ +#define __SHUTDOWNLib_LIBRARY_DEFINED__ + +/* library SHUTDOWNLib */ +/* [helpstring][version][uuid] */ + + +EXTERN_C const IID LIBID_SHUTDOWNLib; +#endif /* __SHUTDOWNLib_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Shutdown/Shutdown.idl b/Shutdown/Shutdown.idl new file mode 100644 index 0000000..273ac87 --- /dev/null +++ b/Shutdown/Shutdown.idl @@ -0,0 +1,38 @@ +// Shutdown.idl : IDL source for Shutdown.dll +// + +// This file will be processed by the MIDL tool to +// produce the type library (Shutdown.tlb) and marshalling code. + +import "oaidl.idl"; +import "ocidl.idl"; + + [ + uuid(409C4B06-9310-11d3-BFC1-0020182B97FC), + helpstring("Buddy Events") + ] + dispinterface DShutdownEvents + { + properties: + methods: + [id(1)] HRESULT Cancel(); + }; + +[ + uuid(409C4B07-9310-11d3-BFC1-0020182B97FC), + version(2.5), + helpstring("Night Security Shutdown 2.5") +] +library NightSecShutdown +{ + importlib("stdole32.tlb"); + importlib("stdole2.tlb"); + + [ + uuid(409C4B08-9310-11d3-BFC1-0020182B97FC) + ] + coclass Shutdown + { + [default, source] dispinterface DShutdownEvents; + }; +}; diff --git a/Shutdown/Shutdown.rc b/Shutdown/Shutdown.rc new file mode 100644 index 0000000..8b65ba7 --- /dev/null +++ b/Shutdown/Shutdown.rc @@ -0,0 +1,236 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "1 TYPELIB ""Shutdown.tlb""\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 2,5,0,1 + PRODUCTVERSION 2,5,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "Part of the Night Security Program\0" + VALUE "CompanyName", "The Family (Thailand)\0" + VALUE "FileDescription", "Night Security (Shutdown Module)\0" + VALUE "FileVersion", "2, 5, 0, 1\0" + VALUE "InternalName", "Night Security Shutdown\0" + VALUE "LegalCopyright", "Copyright (C) 1998 - 1999, The Family (Thailand)\0" + VALUE "LegalTrademarks", "\0" + VALUE "OLESelfRegister", "\0" + VALUE "OriginalFilename", "Shutdown.exe\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "Night Security 2.5\0" + VALUE "ProductVersion", "2, 5, 0, 1\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + + +///////////////////////////////////////////////////////////////////////////// +// +// REGISTRY +// + +IDR_Shutdown REGISTRY MOVEABLE PURE "Shutdown.rgs" + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_CHECKS BITMAP DISCARDABLE "res\\bitmap1.bmp" +IDB_ERRORS BITMAP DISCARDABLE "res\\checks1.bmp" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_ITEMDLG DIALOG DISCARDABLE 0, 0, 169, 119 +STYLE DS_MODALFRAME | DS_SETFOREGROUND | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Secure Shutdown" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Cancel",IDCANCEL,117,98,45,14 + CONTROL "List1",IDC_ITEMS,"SysListView32",LVS_REPORT | + LVS_SINGLESEL | LVS_NOLABELWRAP | LVS_NOCOLUMNHEADER | + LVS_NOSORTHEADER,32,7,130,83 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,6,92,156,1 + ICON IDR_NIGHTSEC,IDC_STATIC,6,7,20,20 +END + +IDD_LOG DIALOGEX 0, 0, 330, 158 +STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +EXSTYLE WS_EX_CONTEXTHELP +CAPTION "Secure Shutdown Errors" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Hide",ID_HIDE,281,6,42,14 + CONTROL "List1",IDC_ERROR_LOG,"SysListView32",LVS_REPORT | + LVS_AUTOARRANGE | LVS_NOSORTHEADER | WS_TABSTOP,7,26,316, + 125,WS_EX_CLIENTEDGE + LTEXT "There were errors during the Shutdown process.", + IDC_STATIC,7,6,160,18 + CONTROL "",IDC_MINSIZE,"Static",SS_GRAYRECT | NOT WS_VISIBLE,0,0, + 272,119 + PUSHBUTTON "Save",ID_SAVE,234,6,42,14 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDR_MAINFRAME ICON DISCARDABLE "res\\Night Security Shutdown.ico" +IDR_NIGHTSEC ICON DISCARDABLE "res\\Night Security Stub.ico" +IDI_ERR ICON DISCARDABLE "res\\icon1.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_ITEMDLG, DIALOG + BEGIN + LEFTMARGIN, 6 + RIGHTMARGIN, 162 + TOPMARGIN, 7 + BOTTOMMARGIN, 112 + END + + IDD_LOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 323 + TOPMARGIN, 6 + BOTTOMMARGIN, 151 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDR_ERROR_MENU MENU DISCARDABLE +BEGIN + POPUP "Error" + BEGIN + MENUITEM "Retry", ID_ERROR_RETRY, GRAYED + MENUITEM "Fix", ID_ERROR_FIX, GRAYED + MENUITEM "Clear", ID_ERROR_DELETE + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_PROJNAME "Shutdown" + IDS_LOGDLG_DESC "LogDlg Class" + IDS_ABOUTBOX "&About Night Security Shutdown..." + IDS_BATCHFILENAME "DOSmode.bat" + IDS_STARTSECTION "REM *** START *** (Night Security Additions Start Here)\r\nREM DO NOT REMOVE OR MODIFY THE ABOVE LINE\r\nREM ADDITIONS WILL GO TO THE BOTTOM OF THIS BATCH FILE IF NOT FOUND\r\n\r\n" + IDS_BATCHFILEPIF "DOSmode.pif" + IDS_ENDSECTION "\r\n\r\nREM DO NOT REMOVE OR MODIFY THE LINE BELOW\r\nREM ANYTHING BELOW START WILL BE REMOVED IF NOT FOUND\r\nREM *** END *** (Night Security Additions End Here)\r\n" + IDS_STARTSEARHTEXT "*** START ***" + IDS_ENDSEARCHTEXT "*** END ***" + IDS_BATCHFILEPIF_NT "DOSmode.bat" +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// +1 TYPELIB "Shutdown.tlb" + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Shutdown/Shutdown.rgs b/Shutdown/Shutdown.rgs new file mode 100644 index 0000000..e8cf570 --- /dev/null +++ b/Shutdown/Shutdown.rgs @@ -0,0 +1,11 @@ +HKCR
+{
+ NoRemove AppID
+ {
+ {936DD342-8FF9-11D3-BFBD-0020182B97FC} = s 'Shutdown'
+ 'Shutdown.EXE'
+ {
+ val AppID = s {936DD342-8FF9-11D3-BFBD-0020182B97FC}
+ }
+ }
+}
diff --git a/Shutdown/ShutdownApp.cpp b/Shutdown/ShutdownApp.cpp new file mode 100644 index 0000000..714fe55 --- /dev/null +++ b/Shutdown/ShutdownApp.cpp @@ -0,0 +1,128 @@ +// ShutdownApp.cpp: implementation of the CShutdownApp class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "ShutdownApp.h" + +#include <mystring.h> + +#include "batchfilecmpt.h" +#include <appmisc.h> +#include "itemdlg.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CShutdownApp::CShutdownApp() + : CNightSecApp(_T("Secure Shutdown"), _T("NightSecurity.SecureShutdown.{2ED9B360-F6EF-11d2-A5A1-0020182B97FC}")) +{ } + +CShutdownApp::~CShutdownApp() +{ } + +bool CShutdownApp::InitInstance() +{ + // If more than one instance bail out early + if(m_oneInstance.IsAlreadyLoaded()) + { + m_oneInstance.FindAndActivate(_T("#32770"), _T("Secure Shutdown")); + return false; + } + + if(!CNightSecApp::InitInstance()) + return false; + + // If the checklist hasn't been run all the way through yet + // then... + if(!m_settings.GetInt(IS_SETUP_KEY, 0)) + { + // Ask if they'd like to fill it out + if(::MessageBox(NULL, _T("You haven't filled out the Night Security checklist yet. Would you like to do that now?."), _T("Secure Shutdown"), MB_ICONQUESTION | MB_YESNO) == IDYES) + { + // Start the Checklist Program + if(ShellExecute(NULL, _T("open"), string(GetProgramFolder(_Module.m_hInst) + _T("Checklist.exe")), NULL, "", SW_SHOWNORMAL) <= (HINSTANCE)32) + ::MessageBox(NULL, _T("Couldn't start Night Security Checklist. Make sure it's installed properly."), _T("Secure Shutdown"), MB_ICONSTOP); + + return false; + } + + // Only ask'm once. If they answer 'no' then don't bother'm + // again + m_settings.WriteInt(IS_SETUP_KEY, 1); + + } + + g_site.SetSite(); + + // Do the actual shutdown + DoShutdown(NULL); + + // If any components changed data + g_aComponents.SaveComponentData(); + + g_site.ClearSite(); + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return false; +} + +HRESULT CShutdownApp::DoShutdown(HWND hwndParent, long lOptions) +{ + // ... Add Entry for Batchfile Creation Components (host based) + // into array + g_aComponents.push_back(new CBatchFileCmpt); + + // Create Progress Dialog + g_site.m_dlgItems.Create(NULL); + + g_site.m_log.Init(g_site.m_dlgItems); + + // Now comes the real stuff + HRESULT hr = S_OK; + MSG msg; + + int nCurPos = 0; + + // Call Do Shutdown for All Windows Components + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + // If it's a Windows Component + if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN) + { + // If it's currently active + if(g_aComponents[nCnt]->IsEnabled()) + { + // Make Entry Active + g_site.m_dlgItems.SetCurrentItem(nCurPos); + + PEEK_ALL_MESSAGES(msg); + + // Call Shutdown + hr = g_aComponents[nCnt]->DoShutdown(lOptions, g_site.m_dlgItems); + + // Was Component Cancelled? + // All nicely behaved components return E_ABORT + // on cancel + if(hr == E_ABORT) + return E_ABORT; + + // Check it off + // (Check it with a false if failed) + g_site.m_dlgItems.CheckOffItem(nCurPos, SUCCEEDED(hr)); + + PEEK_ALL_MESSAGES(msg); + + // Is Dialog Cancelled? + if(g_site.m_dlgItems.IsCancelled()) + return E_ABORT; + + nCurPos++; + } + } + } + + return S_OK; +}
\ No newline at end of file diff --git a/Shutdown/ShutdownApp.h b/Shutdown/ShutdownApp.h new file mode 100644 index 0000000..65dbdac --- /dev/null +++ b/Shutdown/ShutdownApp.h @@ -0,0 +1,25 @@ +// ShutdownApp.h: interface for the CShutdownApp class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_ShutdownApp_H__19178A46_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_) +#define AFX_ShutdownApp_H__19178A46_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "..\common\NightSecApp.h" + +class CShutdownApp : public CNightSecApp +{ +public: + CShutdownApp(); + virtual ~CShutdownApp(); + + virtual bool InitInstance(); + HRESULT DoShutdown(HWND hwndParent, long lOptions = 0); + +}; + +#endif // !defined(AFX_ShutdownApp_H__19178A46_7FDB_11D3_BF9E_0020182B97FC__INCLUDED_) diff --git a/Shutdown/ShutdownCP.h b/Shutdown/ShutdownCP.h new file mode 100644 index 0000000..cbccd51 --- /dev/null +++ b/Shutdown/ShutdownCP.h @@ -0,0 +1,36 @@ +#ifndef _SITEIFACESCP_H_ +#define _SITEIFACESCP_H_ + +#include "../common/events.h" + +template <class T> +class CProxyDShutdownEvents : public IConnectionPointImpl<T, &DIID_DShutdownEvents, CComDynamicUnkArray> +{ + //Warning this class may be recreated by the wizard. +public: + HRESULT Fire_Cancel() + { + CComVariant varResult; + T* pT = static_cast<T*>(this); + int nConnectionIndex; + int nConnections = m_vec.GetSize(); + + for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) + { + pT->Lock(); + CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex); + pT->Unlock(); + IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p); + if (pDispatch != NULL) + { + VariantClear(&varResult); + DISPPARAMS disp = { NULL, NULL, 0, 0 }; + pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); + } + } + + return varResult.scode; + } +}; + +#endif
\ No newline at end of file diff --git a/Shutdown/ShutdownSite.cpp b/Shutdown/ShutdownSite.cpp new file mode 100644 index 0000000..45dcdd9 --- /dev/null +++ b/Shutdown/ShutdownSite.cpp @@ -0,0 +1,78 @@ +// ShutdownSite.cpp: implementation of the CShutdownSite class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "ShutdownSite.h" + +_COM_SMARTPTR_TYPEDEF(INightSecErrorFix, __uuidof(INightSecErrorFix)); + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CShutdownSite::CShutdownSite() +{ + +} + +CShutdownSite::~CShutdownSite() +{ + +} + +void CShutdownSite::SetSite() +{ + IUnknown* pUnk = NULL; + IObjectWithSitePtr pWithSite; + + IUnknown* pUnkMe = GetUnknown(); + + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + if(SUCCEEDED(pUnk = g_aComponents[nCnt]->GetUnknown()) && pUnk != NULL) + { + pWithSite = pUnk; + if(pWithSite != NULL) + pWithSite->SetSite(pUnkMe); + + pUnk->Release(); + } + } + +} + +void CShutdownSite::ClearSite() +{ + IUnknown* pUnk = NULL; + IObjectWithSitePtr pWithSite; + + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + if(SUCCEEDED(pUnk = g_aComponents[nCnt]->GetUnknown()) && pUnk != NULL) + { + pWithSite = pUnk; + if(pWithSite != NULL) + pWithSite->SetSite(NULL); + + pUnk->Release(); + } + } +} + + +STDMETHODIMP CShutdownSite::AddError(/*[in]*/ IUnknown* pUnk) +{ + INightSecErrorPtr pErr = pUnk; + + if(pErr) + return m_log.AddItem(pErr) ? S_OK : E_FAIL; + + return E_NOINTERFACE; +} + +STDMETHODIMP CShutdownSite::HasErrors(/*[out, retval]*/ BOOL* pbRet) +{ + *pbRet = m_log.HasErrors() ? TRUE : FALSE; + return S_OK; +} diff --git a/Shutdown/ShutdownSite.h b/Shutdown/ShutdownSite.h new file mode 100644 index 0000000..599ebb2 --- /dev/null +++ b/Shutdown/ShutdownSite.h @@ -0,0 +1,64 @@ +// ShutdownSite.h: interface for the CShutdownSite class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_SHUTDOWNSITE_H__F3AF1F43_93A1_11D3_BFC3_0020182B97FC__INCLUDED_) +#define AFX_SHUTDOWNSITE_H__F3AF1F43_93A1_11D3_BFC3_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "shutdown.h" +#include "../common/interfaces.h" + +#include "logdlg.h" +#include "ItemDlg.h" +#include "ShutdownCP.h" + +class ATL_NO_VTABLE CShutdownSite : + public CComObjectRootEx<CComMultiThreadModel>, + public IDispatchImpl<INightSecSiteInfo, &IID_INightSecSiteInfo, &LIBID_SHUTDOWNLib>, + public INightSecErrorLog, + public CProxyDShutdownEvents<CShutdownSite>, + public IConnectionPointContainerImpl<CShutdownSite> +{ +public: + CShutdownSite(); + virtual ~CShutdownSite(); + + void SetSite(); + void ClearSite(); + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CShutdownSite) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(INightSecSiteInfo) + COM_INTERFACE_ENTRY(INightSecErrorLog) + COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer) +END_COM_MAP() + +BEGIN_CONNECTION_POINT_MAP(CShutdownSite) + CONNECTION_POINT_ENTRY(DIID_DShutdownEvents) +END_CONNECTION_POINT_MAP() + + +// INightSecSiteInfo + STDMETHOD(get_Info)(/*[in]*/ NightSecSiteInfo nsItem, /*[out, retval]*/ VARIANT* pvVal) + { + ::VariantClear(pvVal); + return S_FALSE; + } + +// INightSecErrorLog + STDMETHOD(AddError)(/*[in]*/ IUnknown* pUnk); + STDMETHOD(HasErrors)(/*[out, retval]*/ BOOL* pbRet); + +// Data +public: + CLogDlg m_log; + CItemDlg m_dlgItems; +}; + +#endif // !defined(AFX_SHUTDOWNSITE_H__F3AF1F43_93A1_11D3_BFC3_0020182B97FC__INCLUDED_) diff --git a/Shutdown/Shutdownps.def b/Shutdown/Shutdownps.def new file mode 100644 index 0000000..ee41a99 --- /dev/null +++ b/Shutdown/Shutdownps.def @@ -0,0 +1,11 @@ +
+LIBRARY "ShutdownPS"
+
+DESCRIPTION 'Proxy/Stub DLL'
+
+EXPORTS
+ DllGetClassObject @1 PRIVATE
+ DllCanUnloadNow @2 PRIVATE
+ GetProxyDllInfo @3 PRIVATE
+ DllRegisterServer @4 PRIVATE
+ DllUnregisterServer @5 PRIVATE
diff --git a/Shutdown/Shutdownps.mk b/Shutdown/Shutdownps.mk new file mode 100644 index 0000000..caf5e22 --- /dev/null +++ b/Shutdown/Shutdownps.mk @@ -0,0 +1,16 @@ + +Shutdownps.dll: dlldata.obj Shutdown_p.obj Shutdown_i.obj + link /dll /out:Shutdownps.dll /def:Shutdownps.def /entry:DllMain dlldata.obj Shutdown_p.obj Shutdown_i.obj \ + kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib oleaut32.lib uuid.lib \ + +.c.obj: + cl /c /Ox /DWIN32 /D_WIN32_WINNT=0x0400 /DREGISTER_PROXY_DLL \ + $< + +clean: + @del Shutdownps.dll + @del Shutdownps.lib + @del Shutdownps.exp + @del dlldata.obj + @del Shutdown_p.obj + @del Shutdown_i.obj diff --git a/Shutdown/SizingDialog.cpp b/Shutdown/SizingDialog.cpp new file mode 100644 index 0000000..f45e303 --- /dev/null +++ b/Shutdown/SizingDialog.cpp @@ -0,0 +1,20 @@ +// SizingDialog.cpp: implementation of the CSizingDialog class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "SizingDialog.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CSizingDialog::CSizingDialog() +{ + +} + +CSizingDialog::~CSizingDialog() +{ + +} diff --git a/Shutdown/SizingDialog.h b/Shutdown/SizingDialog.h new file mode 100644 index 0000000..d6e351a --- /dev/null +++ b/Shutdown/SizingDialog.h @@ -0,0 +1,171 @@ +// SizingDialog.h: interface for the CSizingDialog class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_SIZINGDIALOG_H__5C154C94_9FEF_11D3_82D8_0020182B97FC__INCLUDED_) +#define AFX_SIZINGDIALOG_H__5C154C94_9FEF_11D3_82D8_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +//#define SD_TOP 0x00000001 +#define SD_HORZ 0x00000002 +//#define SD_LEFT 0x00000010 +#define SD_VERT 0x00000020 +#define SD_MOVING 0x00010000 +#define SD_SIZING 0x00020000 + +#define RECT_WIPE(rc) (rc.left = rc.top = rc.right = rc.bottom = 0) +#define IS_RECT_EMPTY(rc) ((rc.left == 0) && (rc.top == 0) && (rc.right == 0) && (rc.bottom == 0)) +#define POINT_WIPE(pt) (pt.x = pt.y = 0) +#define IS_POINT_EMPTY(pt) ((pt.x == 0) && (pt.y == 0)) + +template<class T> +class CSizingDialog +{ +public: + CSizingDialog() + { POINT_WIPE(m_ptMin); } + + bool SetMin(UINT nID); + bool SetMin(LPPOINT pt); + + bool SetControlSizing(UINT nID, DWORD dwLocation); + +BEGIN_MSG_MAP(CSizingDialog<T>) + MESSAGE_HANDLER(WM_SIZE, OnSize) + MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo) +END_MSG_MAP() + +protected: +// LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + + struct POS_DATA + { + DWORD dwLocation; + UINT nID; + RECT rcOffsets; + }; + + typedef vector<POS_DATA> pos_array; + pos_array m_aPositions; + POINT m_ptMin; +}; + +template <class T> +bool CSizingDialog<T>::SetMin(LPPOINT pt) +{ + m_ptMin.x = pt.x; + m_ptMin.y = pt.y; + return true; +} +template <class T> +bool CSizingDialog<T>::SetControlSizing(UINT nID, DWORD dwLocation) +{ + T* pThis = (T*)this; + ASSERT(dwLocation); + ASSERT(pThis->GetDlgItem(nID)); + + POS_DATA ps; + ps.dwLocation = dwLocation; + ps.nID = nID; + + RECT rcDlg; + if(!pThis->GetClientRect(&rcDlg)) + return false; + + RECT rcCtl; + if(!::GetWindowRect(pThis->GetDlgItem(nID), &rcCtl)) + return false; + + if(!pThis->ScreenToClient(&rcCtl)) + return false; + + ps.rcOffsets.left = rcCtl.left - rcDlg.left; + ps.rcOffsets.top = rcCtl.top - rcDlg.top; + ps.rcOffsets.right = rcDlg.right - rcCtl.right; + ps.rcOffsets.bottom = rcDlg.bottom - rcCtl.bottom; + + m_aPositions.push_back(ps); + + return true; +} + +template <class T> +bool CSizingDialog<T>::SetMin(UINT nID) +{ + T* pThis = (T*)this; + + ASSERT(pThis->GetDlgItem(nID)); + RECT rcCtl; + if(!::GetWindowRect(pThis->GetDlgItem(nID), &rcCtl)) + return false; + + RECT rcDlg; + if(!pThis->GetWindowRect(&rcDlg)) + return false; + + m_ptMin.x = rcCtl.right - rcDlg.left; + m_ptMin.y = rcCtl.bottom - rcDlg.top; + + return true; +} + + +template <class T> +LRESULT CSizingDialog<T>::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if(IS_POINT_EMPTY(m_ptMin)) + return 0; + + LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam; // address of structure + lpmmi->ptMinTrackSize = m_ptMin; + return 0; +} + +template <class T> +LRESULT CSizingDialog<T>::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + T* pThis = (T*)this; + UINT nWidth = LOWORD(lParam); // width of client area + UINT nHeight = HIWORD(lParam); // height of client area + + for(pos_array::iterator iter = m_aPositions.begin(); iter != m_aPositions.end(); iter++) + { + RECT rc; + if(!::GetWindowRect(pThis->GetDlgItem(iter->nID), &rc)) + continue; + if(!pThis->ScreenToClient(&rc)) + continue; + + if(iter->dwLocation & SD_MOVING) + { + ::SetWindowPos(pThis->GetDlgItem(iter->nID), NULL, + (iter->dwLocation & SD_HORZ) ? + nWidth - iter->rcOffsets.right - rc.right + rc.left : + rc.left, + (iter->dwLocation & SD_VERT) ? + nHeight - iter->rcOffsets.bottom - rc.bottom + rc.top : + rc.top, + 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_DEFERERASE); + } + else if(iter->dwLocation & SD_SIZING) + { + ::SetWindowPos(pThis->GetDlgItem(iter->nID), NULL, 0, 0, + (iter->dwLocation & SD_HORZ) ? + nWidth - iter->rcOffsets.right - rc.left : + rc.right - rc.left, + (iter->dwLocation & SD_VERT) ? + nHeight - iter->rcOffsets.bottom - rc.top : + rc.bottom - rc.top, + SWP_NOMOVE | SWP_NOZORDER | SWP_DEFERERASE); + } + } + + return 0; +} + +#endif // !defined(AFX_SIZINGDIALOG_H__5C154C94_9FEF_11D3_82D8_0020182B97FC__INCLUDED_) diff --git a/Shutdown/StdAfx.cpp b/Shutdown/StdAfx.cpp new file mode 100644 index 0000000..a5eea17 --- /dev/null +++ b/Shutdown/StdAfx.cpp @@ -0,0 +1,12 @@ +// stdafx.cpp : source file that includes just the standard includes +// stdafx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +#ifdef _ATL_STATIC_REGISTRY +#include <statreg.h> +#include <statreg.cpp> +#endif + +#include <atlimpl.cpp> diff --git a/Shutdown/StdAfx.h b/Shutdown/StdAfx.h new file mode 100644 index 0000000..0bf2b0a --- /dev/null +++ b/Shutdown/StdAfx.h @@ -0,0 +1,48 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#if !defined(AFX_STDAFX_H__936DD344_8FF9_11D3_BFBD_0020182B97FC__INCLUDED_) +#define AFX_STDAFX_H__936DD344_8FF9_11D3_BFBD_0020182B97FC__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define STRICT + +// Windows 95 Compatible +#undef WINVER +#define WINVER 0x0400 +#undef _WIN32_WINNT + +// Don't want our program dependant on some browser! +#undef _WIN32_IE +#define _WIN32_IE 0x0000 + +#define _ATL_APARTMENT_THREADED + +#include <comdef.h> +#include <atlbase.h> +//You may derive a class from CComModule and use it if you want to override +//something, but do not change the name of _Module +#include "../common/types.h" + +#include "shutdownapp.h" + +extern CShutdownApp _Module; +#include <atlcom.h> +#include <atlwin.h> +#include <atlextra.h> + +#include "../common/componentarray.h" +extern CComponentArray g_aComponents; + +#include "ShutdownSite.h" +extern CComObjectGlobal<CShutdownSite> g_site; + + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__936DD344_8FF9_11D3_BFBD_0020182B97FC__INCLUDED) diff --git a/Shutdown/res/LogDlg.rgs b/Shutdown/res/LogDlg.rgs new file mode 100644 index 0000000..5c5c83b --- /dev/null +++ b/Shutdown/res/LogDlg.rgs @@ -0,0 +1,21 @@ +HKCR
+{
+ Shutdown.LogDlg.1 = s 'LogDlg Class'
+ {
+ CLSID = s '{F3AF1F45-93A1-11D3-BFC3-0020182B97FC}'
+ }
+ Shutdown.LogDlg = s 'LogDlg Class'
+ {
+ CLSID = s '{F3AF1F45-93A1-11D3-BFC3-0020182B97FC}'
+ }
+ NoRemove CLSID
+ {
+ ForceRemove {F3AF1F45-93A1-11D3-BFC3-0020182B97FC} = s 'LogDlg Class'
+ {
+ ProgID = s 'Shutdown.LogDlg.1'
+ VersionIndependentProgID = s 'Shutdown.LogDlg'
+ val AppID = s '{936DD342-8FF9-11D3-BFBD-0020182B97FC}'
+ LocalServer32 = s '%Module%'
+ }
+ }
+}
diff --git a/Shutdown/res/Night Security Shutdown.ico b/Shutdown/res/Night Security Shutdown.ico Binary files differnew file mode 100644 index 0000000..e7451cd --- /dev/null +++ b/Shutdown/res/Night Security Shutdown.ico diff --git a/Shutdown/res/Night Security Stub.ico b/Shutdown/res/Night Security Stub.ico Binary files differnew file mode 100644 index 0000000..2b50f8a --- /dev/null +++ b/Shutdown/res/Night Security Stub.ico diff --git a/Shutdown/res/bitmap1.bmp b/Shutdown/res/bitmap1.bmp Binary files differnew file mode 100644 index 0000000..82879b3 --- /dev/null +++ b/Shutdown/res/bitmap1.bmp diff --git a/Shutdown/res/checks1.bmp b/Shutdown/res/checks1.bmp Binary files differnew file mode 100644 index 0000000..edf808d --- /dev/null +++ b/Shutdown/res/checks1.bmp diff --git a/Shutdown/res/icon1.ico b/Shutdown/res/icon1.ico Binary files differnew file mode 100644 index 0000000..3fad43c --- /dev/null +++ b/Shutdown/res/icon1.ico diff --git a/Shutdown/resource.h b/Shutdown/resource.h new file mode 100644 index 0000000..75fde58 --- /dev/null +++ b/Shutdown/resource.h @@ -0,0 +1,42 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Shutdown.rc +// +#define IDS_PROJNAME 100 +#define IDR_Shutdown 100 +#define IDS_LOGDLG_DESC 101 +#define IDS_ABOUTBOX 102 +#define IDS_BATCHFILENAME 103 +#define IDS_STARTSECTION 104 +#define IDS_BATCHFILEPIF 105 +#define IDS_ENDSECTION 106 +#define IDS_STARTSEARHTEXT 107 +#define IDS_ENDSEARCHTEXT 108 +#define IDS_BATCHFILEPIF_NT 109 +#define IDR_MAINFRAME 128 +#define IDR_NIGHTSEC 130 +#define IDB_CHECKS 131 +#define IDD_ITEMDLG 131 +#define IDB_ERRORS 132 +#define IDD_LOG 201 +#define ID_HIDE 201 +#define IDR_ERROR_MENU 201 +#define IDC_ERROR_LOG 202 +#define IDI_ERR 202 +#define IDC_MINSIZE 203 +#define ID_SAVE 204 +#define IDC_ITEMS 1004 +#define ID_ERROR_DELETE 32769 +#define ID_ERROR_FIX 32771 +#define ID_ERROR_RETRY 32772 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 203 +#define _APS_NEXT_COMMAND_VALUE 32773 +#define _APS_NEXT_CONTROL_VALUE 204 +#define _APS_NEXT_SYMED_VALUE 111 +#endif +#endif |