// SCMTool.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "SCMTool.h"
#include "SCMToolDlg.h"
#include "allpages.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSCMToolApp
BEGIN_MESSAGE_MAP(CSCMToolApp, CWinApp)
//{{AFX_MSG_MAP(CSCMToolApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSCMToolApp construction
CSCMToolApp::CSCMToolApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSCMToolApp object
CSCMToolApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSCMToolApp initialization
BOOL CSCMToolApp::InitInstance()
{
AfxEnableControlContainer();
CString Header=_T("NSCM - version ");
Header+=IDS_VERSION;
CAllPages allpages(Header);
MyAllPages = &allpages;
//check if there's new SCMTool.exe version
CString date1=_T(""),date2=_T(""),Buf=_T(""),ver=_T("");
CString exefile = _T("\\SCMTool.exe");
CFile::GetStatus(LPCTSTR(CAllPages::GetCurMFCDir() + exefile), LocalSCMTool);
CString dir = _T("\\ver.txt");
TCHAR* pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
ver = Buf.GetAt(0);
if(ver == '5')
CFile::GetStatus(LPCTSTR(_T("\\\\Ntserv5\\p4util\\NSCM\\SCMTool.exe")), GlobalSCMTool);
else if(ver == '6')
CFile::GetStatus(LPCTSTR(_T("\\\\Ntserv5\\p4util6\\NSCM\\SCMTool.exe")), GlobalSCMTool);
CTime local = LocalSCMTool.m_mtime;
int day = local.GetDay();
int month = local.GetMonth();
int year = local.GetYear();
if((month<10)&&(day<10)) date1.Format(_T("%d0%d0%d"),year,month,day);
else if(month<10) date1.Format(_T("%d0%d%d"),year,month,day);
else if(day<10) date1.Format(_T("%d%d0%d"),year,month,day);
else if((month>=10)&&(day>=10)) date1.Format(_T("%d%d%d"),year,month,day);
CTime current = GlobalSCMTool.m_mtime;
day = current.GetDay();
month = current.GetMonth();
year = current.GetYear();
if((month<10)&&(day<10)) date2.Format(_T("%d0%d0%d"),year,month,day);
else if(month<10) date2.Format(_T("%d0%d%d"),year,month,day);
else if(day<10) date2.Format(_T("%d%d0%d"),year,month,day);
else if((month>=10)&&(day>=10)) date2.Format(_T("%d%d%d"),year,month,day);
if (date1 < date2)
{
if(AfxMessageBox(_T("You have old SCMTool version \nWould you like to update it? "), MB_YESNO) == IDYES)
{
//setup new SCMTool.exe version
ShellExecute(NULL, _T("open"), _T("\\\\Ntserv5\\p4util\\setupNSCM.exe"),_T( "" ),_T( "" ), SW_SHOWNORMAL);
return FALSE;
}
}
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//get main application window
allpages.DoModal();
CString Command=_T("");
Command += CAllPages::Cmd() + _T(" /c del /q ") + CAllPages::GetCurDir() + _T("\\TempTxt ");
CSCMToolApp::RunProcess(Command,1,NULL,NULL);
return FALSE;
}
HANDLE CSCMToolApp::RunProcess(CString CmdLine,int HideFlag ,TCHAR *Env,TCHAR *CurrDir)
{
//run specified command
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL k;
memset(&si, 0, sizeof(STARTUPINFO));
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = CmdLine.GetBuffer(0);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = 0;
CmdLine.ReleaseBuffer(); //release buffer
if (HideFlag)
{ //do not show Dos window
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
}
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
//run process
k = CreateProcess(NULL, CmdLine.GetBuffer(0),NULL,NULL,FALSE,CREATE_NEW_CONSOLE | HIGH_PRIORITY_CLASS ,Env , CurrDir, &si, &pi);
if (!k)
{ //did not succeed run process
AfxMessageBox(_T("CANNOT RUN APPLICATION: ") + CmdLine);
pi.hProcess = NULL;
}
//return process handle
return pi.hProcess;
}
DWORD CSCMToolApp::Waiting(CString cmd,int HideFlag ,TCHAR *Env,TCHAR *CurrDir)
{ //run cmd & waits untill it finished.
HANDLE hProcess;
DWORD st;
hProcess = RunProcess(cmd,HideFlag,Env,CurrDir);
CWaitCursor cursor;
Sleep(50);
do
{
GetExitCodeProcess(hProcess,&st);
Sleep(50);
}
while (st == STILL_ACTIVE);
return (st);
}
CAllPages * CSCMToolApp::GetPropertySheet()
{
return (MyAllPages);
}