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 >
C/C++ Source or Header  |  2005-01-05  |  6KB  |  182 lines

  1. // TemplateDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "pserv2.h"
  6. #include "TemplateDialog.h"
  7. #include "cservice.h"
  8. #include "PXmlReader.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // TemplateDialog dialog
  18. CString FormattedString(LPCTSTR expression, ... );
  19.  
  20. TemplateDialog::TemplateDialog(CServiceList* pServiceList, CObList* pActions, CWnd* pParent /*=NULL*/)
  21.     :   CDialog(TemplateDialog::IDD, pParent),
  22.         m_pServiceList( pServiceList ),
  23.         m_pActions( pActions )
  24. {
  25.     //{{AFX_DATA_INIT(TemplateDialog)
  26.         // NOTE: the ClassWizard will add member initialization here
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30. TemplateDialog::~TemplateDialog()
  31. {
  32.     DeleteActions();
  33. }
  34.  
  35.  
  36. void TemplateDialog::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(TemplateDialog)
  40.     DDX_Control(pDX, IDC_COMBO1, m_cbDefaultStartupMode);
  41.     DDX_Control(pDX, IDC_LIST1, m_ActionList);
  42.     //}}AFX_DATA_MAP
  43.     if( pDX->m_bSaveAndValidate )
  44.     {
  45.     }
  46.     else
  47.     {
  48.  
  49. #define CBMODE_DO_NOT_CHANGE 0
  50. #define CBMODE_DISABLE 1
  51. #define CBMODE_SET_MANUAL 2
  52. #define CBMODE_SET_AUTOMATIC 3
  53.  
  54.         m_cbDefaultStartupMode.AddString(_T("Do not change"));
  55.         m_cbDefaultStartupMode.AddString(_T("Disable"));
  56.         m_cbDefaultStartupMode.AddString(_T("Set to manual start"));
  57.         m_cbDefaultStartupMode.AddString(_T("Set to automatic start"));
  58.         m_cbDefaultStartupMode.SetCurSel(0);
  59.         
  60.         if( !CheckActionsToPerform() )
  61.         {
  62.             AfxMessageBox(_T("No Actions to perform!"));
  63.         }
  64.     }
  65. }
  66.  
  67. ServiceAction* TemplateDialog::findRequestedAction(LPCTSTR lpszName)
  68. {
  69.     POSITION pos = m_pActions->GetHeadPosition();
  70.     while( pos )
  71.     {
  72.         ServiceAction* sa = (ServiceAction*)m_pActions->GetNext( pos );
  73.         if( lstrcmpi( sa->m_strServiceName, lpszName ) == 0 )
  74.         {
  75.             return sa;
  76.         }
  77.     }
  78.     return NULL;
  79. }
  80.  
  81. void TemplateDialog::DeleteActions()
  82. {
  83.     // delete existing actions
  84.     BOOL bDeleteCombo = IsWindow(m_ActionList);
  85.  
  86.     int nDeleteIndex = 0;
  87.     while( m_ActionsToPerform.GetCount() )
  88.     {
  89.         ServiceAction* a = (ServiceAction*)m_ActionsToPerform.GetHead();
  90.         m_ActionsToPerform.RemoveHead();
  91.         if( bDeleteCombo )
  92.             m_ActionList.DeleteString(0);
  93.         delete a;
  94.     }
  95. }
  96.  
  97. BOOL TemplateDialog::CheckActionsToPerform()
  98. {
  99.     DeleteActions();    
  100.  
  101.     int nCurSel = m_cbDefaultStartupMode.GetCurSel();
  102.  
  103.     CObArray* pServices = &(m_pServiceList->m_Entries);
  104.     int nElements = pServices->GetSize();
  105.     for( int nIndex = 0; nIndex < nElements; nIndex++ )
  106.     {
  107.         CService* pService = (CService*) pServices->GetAt(nIndex);
  108.  
  109.         // find associated action
  110.         ServiceAction* sa = findRequestedAction(pService->m_strServiceName);
  111.         if( sa == NULL )
  112.         {
  113.             // no action found, check default apply default
  114.             if( (nCurSel == CBMODE_DISABLE) && (pService->m_dwStartType != SERVICE_DISABLED) )
  115.             {
  116.                 sa = new ServiceAction( pService->m_strServiceName );
  117.                 if( sa )
  118.                 {
  119.                     sa->m_dwActionToTake = SERVICE_DISABLED;
  120.                     sa->m_pService = pService;
  121.                     m_ActionsToPerform.AddTail( sa );
  122.                     m_ActionList.AddString(FormattedString(_T("Disable %s"), (LPCTSTR)pService->m_strServiceName ) );
  123.                 }
  124.             }
  125.             else if( (nCurSel == CBMODE_SET_MANUAL) && (pService->m_dwStartType != SERVICE_DEMAND_START) )
  126.             {
  127.                 sa = new ServiceAction( pService->m_strServiceName );
  128.                 if( sa )
  129.                 {
  130.                     sa->m_dwActionToTake = SERVICE_DEMAND_START;
  131.                     sa->m_pService = pService;
  132.                     m_ActionsToPerform.AddTail( sa );
  133.                     m_ActionList.AddString(FormattedString(_T("Set %s to manual start"), (LPCTSTR)pService->m_strServiceName ) );
  134.                 }
  135.             }
  136.             else if( (nCurSel == CBMODE_SET_AUTOMATIC) && (pService->m_dwStartType != SERVICE_AUTO_START) )
  137.             {
  138.                 sa = new ServiceAction( pService->m_strServiceName );
  139.                 if( sa )
  140.                 {
  141.                     sa->m_dwActionToTake = SERVICE_AUTO_START;
  142.                     sa->m_pService = pService;
  143.                     m_ActionsToPerform.AddTail( sa );
  144.                     m_ActionList.AddString(FormattedString(_T("Set %s to manual start"), (LPCTSTR)pService->m_strServiceName ) );
  145.                 }
  146.             }
  147.         }
  148.         else
  149.         {
  150.             if( (sa->m_dwActionToTake != SERVICE_NO_ACTION) && (sa->m_dwActionToTake != pService->m_dwStartType) )
  151.             {
  152.                 ServiceAction* nsa = new ServiceAction( pService->m_strServiceName );
  153.                 if( nsa )
  154.                 {
  155.                     nsa->m_dwActionToTake = sa->m_dwActionToTake;
  156.                     nsa->m_pService = pService;
  157.                     m_ActionsToPerform.AddTail( nsa );
  158.                     m_ActionList.AddString(
  159.                         FormattedString(_T("Set %s to %s start"), 
  160.                             (LPCTSTR)pService->m_strServiceName, 
  161.                             (LPCTSTR)CService::GetStartAsString(sa->m_dwActionToTake) ) );
  162.                 }
  163.             }
  164.         }
  165.     }
  166.     return m_ActionsToPerform.GetCount() > 0;
  167. }
  168.  
  169. BEGIN_MESSAGE_MAP(TemplateDialog, CDialog)
  170.     //{{AFX_MSG_MAP(TemplateDialog)
  171.     ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  172.     //}}AFX_MSG_MAP
  173. END_MESSAGE_MAP()
  174.  
  175. /////////////////////////////////////////////////////////////////////////////
  176. // TemplateDialog message handlers
  177.  
  178. void TemplateDialog::OnSelchangeCombo1() 
  179. {
  180.     CheckActionsToPerform();
  181. }
  182.