summaryrefslogtreecommitdiff
path: root/CmdLine/CmdLineApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CmdLine/CmdLineApp.cpp')
-rw-r--r--CmdLine/CmdLineApp.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/CmdLine/CmdLineApp.cpp b/CmdLine/CmdLineApp.cpp
new file mode 100644
index 0000000..ff2b3ad
--- /dev/null
+++ b/CmdLine/CmdLineApp.cpp
@@ -0,0 +1,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;
+
+}