blob: ff2b3adb150d8fc80b753155f09faacc0e2078f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// CmdLineApp.cpp: implementation of the CCmdLineApp class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CmdLineApp.h"
#include "CmdLineDlg.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCmdLineApp::CCmdLineApp()
: CNightSecApp(_T("Secure Shutdown"))
{ }
CCmdLineApp::~CCmdLineApp()
{ }
bool CCmdLineApp::InitInstance()
{
if(!CNightSecApp::InitInstance())
return false;
// Get Parameters
bool bParams = false;
bool bShowHelp = true;
LPSTR szChar;
int nIndex = -1;
// Loop through command line arguments
for (int i = 1; i < __argc; i++)
{
szChar = __targv[i];
_tcslwr(szChar);
// Check if it's a param
// Note we can use - as a param because we don't
// accept file names (otherwise - can be in file name)
if (szChar[0] == '/' || szChar[0] == '-')
{
// Accepts multiple arguments in one param
// eg: -rti
// First skip over first token then go through
// other chars one by one
for(szChar++; szChar[0] != '\0'; szChar++)
{
// Check if we have a match
if((nIndex = FindParam(szChar[0])) > -1)
{
// If so then call it
g_aComponents[nIndex]->DoShutdown(NULL);
// Set flag so we don't show dialog later on
bShowHelp = false;
}
}
}
}
// Return if no dialog
if(!bShowHelp)
return false;
// Otherwise...
CCmdLineDlg dlg;
dlg.DoModal();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return false;
}
//////////////////////////////////////////////////////////////////
// Checks Component Array for any components with Param passed
UINT CCmdLineApp::FindParam(TCHAR chParam)
{
string sTemp;
// Loop through'm all
for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
{
// Only Windows Components can be called from cmd line
if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN)
{
// Check for match
sTemp = g_aComponents[nCnt]->GetInfoStr(nsCmdLine, _T(""));
sTemp.make_lower();
if(!sTemp.empty() && sTemp[0] == chParam)
return nCnt;
}
}
return -1;
}
|