home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softwarová Záchrana 3
/
Softwarova-zachrana-3.bin
/
pserv.cpl
/
pserv-2.4.exe
/
source
/
TemplateDialog.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2005-01-05
|
6KB
|
182 lines
// TemplateDialog.cpp : implementation file
//
#include "stdafx.h"
#include "pserv2.h"
#include "TemplateDialog.h"
#include "cservice.h"
#include "PXmlReader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TemplateDialog dialog
CString FormattedString(LPCTSTR expression, ... );
TemplateDialog::TemplateDialog(CServiceList* pServiceList, CObList* pActions, CWnd* pParent /*=NULL*/)
: CDialog(TemplateDialog::IDD, pParent),
m_pServiceList( pServiceList ),
m_pActions( pActions )
{
//{{AFX_DATA_INIT(TemplateDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
TemplateDialog::~TemplateDialog()
{
DeleteActions();
}
void TemplateDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TemplateDialog)
DDX_Control(pDX, IDC_COMBO1, m_cbDefaultStartupMode);
DDX_Control(pDX, IDC_LIST1, m_ActionList);
//}}AFX_DATA_MAP
if( pDX->m_bSaveAndValidate )
{
}
else
{
#define CBMODE_DO_NOT_CHANGE 0
#define CBMODE_DISABLE 1
#define CBMODE_SET_MANUAL 2
#define CBMODE_SET_AUTOMATIC 3
m_cbDefaultStartupMode.AddString(_T("Do not change"));
m_cbDefaultStartupMode.AddString(_T("Disable"));
m_cbDefaultStartupMode.AddString(_T("Set to manual start"));
m_cbDefaultStartupMode.AddString(_T("Set to automatic start"));
m_cbDefaultStartupMode.SetCurSel(0);
if( !CheckActionsToPerform() )
{
AfxMessageBox(_T("No Actions to perform!"));
}
}
}
ServiceAction* TemplateDialog::findRequestedAction(LPCTSTR lpszName)
{
POSITION pos = m_pActions->GetHeadPosition();
while( pos )
{
ServiceAction* sa = (ServiceAction*)m_pActions->GetNext( pos );
if( lstrcmpi( sa->m_strServiceName, lpszName ) == 0 )
{
return sa;
}
}
return NULL;
}
void TemplateDialog::DeleteActions()
{
// delete existing actions
BOOL bDeleteCombo = IsWindow(m_ActionList);
int nDeleteIndex = 0;
while( m_ActionsToPerform.GetCount() )
{
ServiceAction* a = (ServiceAction*)m_ActionsToPerform.GetHead();
m_ActionsToPerform.RemoveHead();
if( bDeleteCombo )
m_ActionList.DeleteString(0);
delete a;
}
}
BOOL TemplateDialog::CheckActionsToPerform()
{
DeleteActions();
int nCurSel = m_cbDefaultStartupMode.GetCurSel();
CObArray* pServices = &(m_pServiceList->m_Entries);
int nElements = pServices->GetSize();
for( int nIndex = 0; nIndex < nElements; nIndex++ )
{
CService* pService = (CService*) pServices->GetAt(nIndex);
// find associated action
ServiceAction* sa = findRequestedAction(pService->m_strServiceName);
if( sa == NULL )
{
// no action found, check default apply default
if( (nCurSel == CBMODE_DISABLE) && (pService->m_dwStartType != SERVICE_DISABLED) )
{
sa = new ServiceAction( pService->m_strServiceName );
if( sa )
{
sa->m_dwActionToTake = SERVICE_DISABLED;
sa->m_pService = pService;
m_ActionsToPerform.AddTail( sa );
m_ActionList.AddString(FormattedString(_T("Disable %s"), (LPCTSTR)pService->m_strServiceName ) );
}
}
else if( (nCurSel == CBMODE_SET_MANUAL) && (pService->m_dwStartType != SERVICE_DEMAND_START) )
{
sa = new ServiceAction( pService->m_strServiceName );
if( sa )
{
sa->m_dwActionToTake = SERVICE_DEMAND_START;
sa->m_pService = pService;
m_ActionsToPerform.AddTail( sa );
m_ActionList.AddString(FormattedString(_T("Set %s to manual start"), (LPCTSTR)pService->m_strServiceName ) );
}
}
else if( (nCurSel == CBMODE_SET_AUTOMATIC) && (pService->m_dwStartType != SERVICE_AUTO_START) )
{
sa = new ServiceAction( pService->m_strServiceName );
if( sa )
{
sa->m_dwActionToTake = SERVICE_AUTO_START;
sa->m_pService = pService;
m_ActionsToPerform.AddTail( sa );
m_ActionList.AddString(FormattedString(_T("Set %s to manual start"), (LPCTSTR)pService->m_strServiceName ) );
}
}
}
else
{
if( (sa->m_dwActionToTake != SERVICE_NO_ACTION) && (sa->m_dwActionToTake != pService->m_dwStartType) )
{
ServiceAction* nsa = new ServiceAction( pService->m_strServiceName );
if( nsa )
{
nsa->m_dwActionToTake = sa->m_dwActionToTake;
nsa->m_pService = pService;
m_ActionsToPerform.AddTail( nsa );
m_ActionList.AddString(
FormattedString(_T("Set %s to %s start"),
(LPCTSTR)pService->m_strServiceName,
(LPCTSTR)CService::GetStartAsString(sa->m_dwActionToTake) ) );
}
}
}
}
return m_ActionsToPerform.GetCount() > 0;
}
BEGIN_MESSAGE_MAP(TemplateDialog, CDialog)
//{{AFX_MSG_MAP(TemplateDialog)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TemplateDialog message handlers
void TemplateDialog::OnSelchangeCombo1()
{
CheckActionsToPerform();
}