-
Notifications
You must be signed in to change notification settings - Fork 9
/
WindowsSetupDlg.cpp
689 lines (637 loc) · 19.6 KB
/
WindowsSetupDlg.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// WindowsSetupDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ocs_deploy_tool.h"
#include "AgentSettings.h"
#include "WinAgentSettings.h"
#include "WindowsSetupDlg.h"
#include "FileVersion.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWindowsSetupDlg dialog
CWindowsSetupDlg::CWindowsSetupDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWindowsSetupDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWindowsSetupDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CWindowsSetupDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWindowsSetupDlg)
DDX_Control(pDX, IDC_LIST_FILES, m_ListFiles);
DDX_Control(pDX, IDC_LIST_PLUGINS, m_ListPlugins);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWindowsSetupDlg, CDialog)
//{{AFX_MSG_MAP(CWindowsSetupDlg)
ON_BN_CLICKED(ID_WIZNEXT, OnWiznext)
ON_BN_CLICKED(ID_WIZBACK, OnWizback)
ON_BN_CLICKED(IDC_BUTTON_EXE, OnButtonExe)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
ON_LBN_DBLCLK(IDC_LIST_FILES, OnDblclkListFiles)
ON_BN_CLICKED(IDC_BUTTON_CHANGE_DIRECTORY, OnButtonChangeDirectory)
ON_BN_CLICKED(IDC_CHECK_DEBUG, OnClickVerboseLog)
ON_BN_CLICKED(IDC_CHECK_NO_SERVICE, OnClickNoService)
ON_BN_CLICKED(IDC_CHECK_NO_SYSTRAY, OnClickNoSystray)
ON_BN_CLICKED(IDC_CHECK_LAUNCH_INVENTORY, OnClickLaunchInventory)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_ADD_PLUGIN, &CWindowsSetupDlg::OnBnClickedButtonAddPlugin)
ON_BN_CLICKED(IDC_BUTTON_REMOVE_PLUGIN, &CWindowsSetupDlg::OnBnClickedButtonRemovePlugin)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWindowsSetupDlg message handlers
BOOL CWindowsSetupDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
try
{
CString csMessage, csSection, csNumber;
BOOL bNoMoreValue;
int nIndex;
// Get tool version
CFileVersion fileVer;
CString csVersion;
// Get application path
if (GetModuleFileName( AfxGetInstanceHandle(), csVersion.GetBuffer( 4*_MAX_PATH+1), 4*_MAX_PATH) == 0)
{
csVersion.Empty();
}
else
{
csVersion.ReleaseBuffer();
// Open application file to get version from file
if (fileVer.Open( csVersion))
{
csVersion = fileVer.GetProductVersion();
csVersion.Remove( ' ');
csVersion.Replace( ',', '.');
fileVer.Close();
}
else
csVersion.Empty();
}
csMessage.FormatMessage( IDS_OCS_DEPLOY_TOOL, csVersion);
SetDlgItemText( IDC_STATUS, csMessage);
// Set Agent setup file
csMessage = AfxGetApp()->GetProfileString( AGENT_SECTION, OPTION_WIN_AGENT_SETUP_FILE, _T( ""));
SetDlgItemText( IDC_EDIT_EXE, csMessage);
// Set list of other files to copy
csSection.Format( _T("%s\\%s"), AGENT_SECTION, OPTION_WIN_AGENT_OTHER_FILES);
nIndex = 0;
bNoMoreValue = FALSE;
while (!bNoMoreValue)
{
csNumber.Format( _T( "%d"), nIndex);
csMessage = AfxGetApp()->GetProfileString( csSection, csNumber, _T( ""));
if (!csMessage.IsEmpty())
m_ListFiles.AddString( csMessage);
else
bNoMoreValue = TRUE;
nIndex ++;
}
// Set list of plugins to copy
csSection.Format( _T("%s\\%s"), AGENT_SECTION, WIN_AGENT_PLUGINS_FOLDER);
nIndex = 0;
bNoMoreValue = FALSE;
while (!bNoMoreValue)
{
csNumber.Format( _T( "%d"), nIndex);
csMessage = AfxGetApp()->GetProfileString( csSection, csNumber, _T( ""));
if (!csMessage.IsEmpty())
m_ListPlugins.AddString( csMessage);
else
bNoMoreValue = TRUE;
nIndex ++;
}
// Set OCS server address
csMessage = AfxGetApp()->GetProfileString( AGENT_SECTION, OPTION_SERVER_ADDRESS, DEFAULT_SERVER_ADDRESS);
SetDlgItemText( IDC_EDIT_SERVER_IP, csMessage);
// Set installer command line options
csMessage = AfxGetApp()->GetProfileString( AGENT_SECTION, OPTION_WIN_INSTALLER_OPTIONS, _T( ""));
SetDlgItemText( IDC_EDIT_OPTIONS, csMessage);
// Check /DEBUG to installer command line options
if (csMessage.Find( _T( "/DEBUG")) != -1)
// Option not already set
CheckDlgButton( IDC_CHECK_DEBUG, TRUE);
// Check /NO_SERVICE to installer command line options
if (csMessage.Find( _T( "/NO_SERVICE")) != -1)
// Option not already set
CheckDlgButton( IDC_CHECK_NO_SERVICE, TRUE);
// Check /NO_SYSTRAY to installer command line options
if (csMessage.Find( _T( "/NO_SYSTRAY")) != -1)
// Option not already set
CheckDlgButton( IDC_CHECK_LAUNCH_INVENTORY, TRUE);
// Check /NOW to installer command line options
if (csMessage.Find( _T( "/NOW")) != -1)
// Option not already set
CheckDlgButton( IDC_CHECK_LAUNCH_INVENTORY, TRUE);
// Set agent's installation directory
if (_tcscmp( m_pSettings->GetAgentSetupDirectory(), DEFAULT_WIN_AGENT_DIRECTORY) != 0)
{
// Not default setup folder selected, so enable checkbox
CheckDlgButton( IDC_BUTTON_CHANGE_DIRECTORY, TRUE);
GetDlgItem( IDC_EDIT_INSTALL)->EnableWindow( TRUE);
}
SetDlgItemText( IDC_EDIT_INSTALL, m_pSettings->GetAgentSetupDirectory());
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWindowsSetupDlg::OnWiznext()
{
// TODO: Add your control notification handler code here
try
{
if (!Save( TRUE))
return;
EndDialog( ID_WIZNEXT);
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return;
}
}
void CWindowsSetupDlg::OnWizback()
{
// TODO: Add your control notification handler code here
try
{
Save();
EndDialog( ID_WIZBACK);
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return;
}
}
void CWindowsSetupDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CWindowsSetupDlg::OnButtonExe()
{
// TODO: Add your control notification handler code here
LPITEMIDLIST pMyIdList = NULL;
LPMALLOC pIMalloc;
try
{
CFileDialog dlgOpenFile( TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T( "OCS Inventory NG Agent for Windows Setup|OCS-NG-Windows-Agent-Setup.exe|Executable files|*.exe||"));
TCHAR szInitialFolder[4*_MAX_PATH+1];
CString csMessage;
// Get User Desktop path
if (SHGetMalloc( &pIMalloc) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (SHGetSpecialFolderLocation( m_hWnd, CSIDL_DESKTOP, &pMyIdList) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (!SHGetPathFromIDList( pMyIdList, szInitialFolder))
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
pIMalloc->Free( pMyIdList);
return;
}
pIMalloc->Free( pMyIdList);
// Fill in the OPENFILENAME structure to support a template and hook.
dlgOpenFile.m_ofn.lpstrInitialDir = szInitialFolder;
if (!csMessage.LoadString( IDS_SELECT_AGENT_FILE))
AfxThrowMemoryException();
dlgOpenFile.m_ofn.lpstrTitle = csMessage.GetBuffer( csMessage.GetLength());
if (dlgOpenFile.DoModal() != IDOK)
return;
SetDlgItemText( IDC_EDIT_EXE, dlgOpenFile.GetPathName());
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
if (pMyIdList != NULL)
pIMalloc->Free( pMyIdList);
return;
}
}
void CWindowsSetupDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
LPITEMIDLIST pMyIdList = NULL;
LPMALLOC pIMalloc;
try
{
CFileDialog dlgOpenFile( TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T( "All files|*.*||"));
TCHAR szInitialFolder[4*_MAX_PATH+1];
CString csMessage;
// Get User Desktop path
if (SHGetMalloc( &pIMalloc) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (SHGetSpecialFolderLocation( m_hWnd, CSIDL_DESKTOP, &pMyIdList) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (!SHGetPathFromIDList( pMyIdList, szInitialFolder))
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
pIMalloc->Free( pMyIdList);
return;
}
pIMalloc->Free( pMyIdList);
pMyIdList = NULL;
// Fill in the OPENFILENAME structure to support a template and hook.
dlgOpenFile.m_ofn.lpstrInitialDir = szInitialFolder;
if (!csMessage.LoadString( IDS_SELECT_OTHER_FILE))
AfxThrowMemoryException();
dlgOpenFile.m_ofn.lpstrTitle = csMessage.GetBuffer( csMessage.GetLength());
if (dlgOpenFile.DoModal() != IDOK)
return;
m_ListFiles.AddString( dlgOpenFile.GetPathName());
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
if (pMyIdList != NULL)
pIMalloc->Free( pMyIdList);
return;
}
}
void CWindowsSetupDlg::OnButtonRemove()
{
// TODO: Add your control notification handler code here
try
{
int nCurSel;
if ((nCurSel = m_ListFiles.GetCurSel()) == LB_ERR )
// No item selected
return;
m_ListFiles.DeleteString( nCurSel);
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return;
}
}
void CWindowsSetupDlg::OnDblclkListFiles()
{
// TODO: Add your control notification handler code here
OnButtonRemove();
}
void CWindowsSetupDlg::OnClickVerboseLog()
{
// TODO: Add your control notification handler code here
CString csOptions;
int nIndex;
if (IsDlgButtonChecked( IDC_CHECK_DEBUG))
{
// Add /DEBUG to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if (csOptions.Find( _T( "/DEBUG")) == -1)
// Option not already set
csOptions.Append( _T( " /DEBUG=1"));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
else
{
// Remove /DEBUG to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if ((nIndex = csOptions.Find( _T( "/DEBUG=1"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/DEBUG=1")));
if ((nIndex = csOptions.Find( _T( "/DEBUG=2"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/DEBUG=2")));
if ((nIndex = csOptions.Find( _T( "/DEBUG"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/DEBUG")));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
}
void CWindowsSetupDlg::OnClickNoService()
{
// TODO: Add your control notification handler code here
CString csOptions;
int nIndex;
if (IsDlgButtonChecked( IDC_CHECK_NO_SERVICE))
{
// Add /NO_SERVICE to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if (csOptions.Find( _T( "/NO_SERVICE")) == -1)
// Option not already set
csOptions.Append( _T( " /NO_SERVICE"));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
else
{
// Remove /NO_SERVICE to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if ((nIndex = csOptions.Find( _T( "/NO_SERVICE"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/NO_SERVICE")));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
}
void CWindowsSetupDlg::OnClickNoSystray()
{
// TODO: Add your control notification handler code here
CString csOptions;
int nIndex;
if (IsDlgButtonChecked( IDC_CHECK_NO_SYSTRAY))
{
// Add /NO_SYSTRAY to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if (csOptions.Find( _T( "/NO_SYSTRAY")) == -1)
// Option not already set
csOptions.Append( _T( " /NO_SYSTRAY"));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
else
{
// Remove /NO_SYSTRAY to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if ((nIndex = csOptions.Find( _T( "/NO_SYSTRAY"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/NO_SYSTRAY")));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
}
void CWindowsSetupDlg::OnClickLaunchInventory()
{
// TODO: Add your control notification handler code here
CString csOptions;
int nIndex;
if (IsDlgButtonChecked( IDC_CHECK_LAUNCH_INVENTORY))
{
// Add /NOW to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if (csOptions.Find( _T( "/NOW")) == -1)
// Option not already set
csOptions.Append( _T( " /NOW"));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
else
{
// Remove /NOW to installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
if ((nIndex = csOptions.Find( _T( "/NOW"))) != -1)
// Option not already set
csOptions.Delete( nIndex, _tcslen( _T( "/NOW")));
SetDlgItemText( IDC_EDIT_OPTIONS, csOptions);
}
}
BOOL CWindowsSetupDlg::Save( BOOL bDisplayError)
{
int nIndex, nCount = 0;
CString csMessage, csSection, csNumber;
CStringList *pList;
// Get Agent setup file
if (GetDlgItemText( IDC_EDIT_EXE, csMessage) == 0)
{
// No data
bDisplayError && AfxMessageBox( IDS_ERROR_INVALID_VALUE, MB_ICONINFORMATION);
GetDlgItem( IDC_EDIT_EXE)->SetFocus();
return FALSE;
}
AfxGetApp()->WriteProfileString( AGENT_SECTION, OPTION_WIN_AGENT_SETUP_FILE, csMessage);
m_pSettings->SetAgentSetupFile( csMessage);
// Remove registry stored files, before saving new ones
RemoveOtherFilesFromRegistry();
// Get list of other files to copy
pList = m_pSettings->GetAgentOtherFiles();
csSection.Format( _T("%s\\%s"), AGENT_SECTION, OPTION_WIN_AGENT_OTHER_FILES);
if (((nCount = m_ListFiles.GetCount()) == LB_ERR) || (nCount == 0))
{
// No items in List => NO FILE TO COPY
pList->RemoveAll();
}
else
{
// Empty current list
pList->RemoveAll();
// Fill in file list with each file from listbox
for (nIndex = 0; nIndex < nCount; nIndex++)
{
m_ListFiles.GetText( nIndex, csMessage);
pList->AddTail( csMessage);
csNumber.Format( _T( "%d"), nIndex);
AfxGetApp()->WriteProfileString( csSection, csNumber, csMessage);
}
}
// Remove registry stored plugins, before saving new ones
RemovePluginsFilesFromRegistry();
// Get list of plugins to copy
pList = m_pSettings->GetPluginFiles();
csSection.Format( _T("%s\\%s"), AGENT_SECTION, WIN_AGENT_PLUGINS_FOLDER);
if (((nCount = m_ListPlugins.GetCount()) == LB_ERR) || (nCount == 0))
{
// No items in List => NO PLUGIN TO COPY
pList->RemoveAll();
}
else
{
// Empty current list
pList->RemoveAll();
// Fill in plugin list with each plugin from listbox
for (nIndex = 0; nIndex < nCount; nIndex++)
{
m_ListPlugins.GetText( nIndex, csMessage);
pList->AddTail( csMessage);
csNumber.Format( _T( "%d"), nIndex);
AfxGetApp()->WriteProfileString( csSection, csNumber, csMessage);
}
}
// Get OCS server address
if (GetDlgItemText( IDC_EDIT_SERVER_IP, csMessage) == 0)
{
// No data
bDisplayError && AfxMessageBox( IDS_ERROR_INVALID_VALUE, MB_ICONINFORMATION);
GetDlgItem( IDC_EDIT_SERVER_IP)->SetFocus();
return FALSE;
}
AfxGetApp()->WriteProfileString( AGENT_SECTION, OPTION_SERVER_ADDRESS, csMessage);
m_pSettings->SetServerAddress( csMessage);
// Get installer command line options
GetDlgItemText( IDC_EDIT_OPTIONS, csMessage);
AfxGetApp()->WriteProfileString( AGENT_SECTION, OPTION_WIN_INSTALLER_OPTIONS, csMessage);
m_pSettings->SetInstallerOptions( csMessage);
// Get agent's installation directory
if (GetDlgItemText( IDC_EDIT_INSTALL, csMessage) == 0)
{
// No data
bDisplayError && AfxMessageBox( IDS_ERROR_INVALID_VALUE, MB_ICONINFORMATION);
GetDlgItem( IDC_EDIT_INSTALL)->SetFocus();
return FALSE;
}
m_pSettings->SetAgentSetupDirectory( csMessage);
return TRUE;
}
void CWindowsSetupDlg::SetAgentSetting( CAgentSettings *pSettings)
{
m_pSettings = pSettings;
}
void CWindowsSetupDlg::OnButtonChangeDirectory()
{
// TODO: Add your control notification handler code here
try
{
if (IsDlgButtonChecked( IDC_BUTTON_CHANGE_DIRECTORY))
GetDlgItem( IDC_EDIT_INSTALL)->EnableWindow( TRUE);
else
{
GetDlgItem( IDC_EDIT_INSTALL)->EnableWindow( FALSE);
SetDlgItemText( IDC_EDIT_INSTALL, DEFAULT_WIN_AGENT_DIRECTORY);
}
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return;
}
}
BOOL CWindowsSetupDlg::RemoveOtherFilesFromRegistry()
{
HKEY hKey;
CString csKey, csValue;
DWORD dwErr, dwLength;
UINT uIndex = 0;
csKey.Format( _T( "SOFTWARE\\OCS_DEPLOY_TOOL\\%s\\%s"), AGENT_SECTION, OPTION_WIN_AGENT_OTHER_FILES);
if ((dwErr = RegOpenKeyEx( HKEY_CURRENT_USER, csKey, 0, KEY_READ|KEY_WRITE, &hKey)) != ERROR_SUCCESS)
return FALSE;
while (dwErr == ERROR_SUCCESS)
{
csValue.Format( _T( "%u"), uIndex);
// Check if value exists
dwErr = REG_SZ;
dwLength = 0;
if ((dwErr = RegQueryValueEx( hKey, csValue, NULL, &dwErr, NULL, &dwLength)) == ERROR_SUCCESS)
// Key exists, delete it
RegDeleteValue( hKey, csValue);
// Continue
uIndex ++;
}
RegCloseKey( hKey);
return TRUE;
}
void CWindowsSetupDlg::OnBnClickedButtonAddPlugin()
{
// TODO: Add your control notification handler code here
LPITEMIDLIST pMyIdList = NULL;
LPMALLOC pIMalloc;
try
{
CFileDialog dlgOpenFile( TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T( "All files|*.*||"));
TCHAR szInitialFolder[4*_MAX_PATH+1];
CString csMessage;
// Get User Desktop path
if (SHGetMalloc( &pIMalloc) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (SHGetSpecialFolderLocation( m_hWnd, CSIDL_DESKTOP, &pMyIdList) != NOERROR)
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
return;
}
if (!SHGetPathFromIDList( pMyIdList, szInitialFolder))
{
AfxMessageBox( IDS_ERROR_DISPLAY_FOLDER, MB_ICONSTOP);
pIMalloc->Free( pMyIdList);
return;
}
pIMalloc->Free( pMyIdList);
pMyIdList = NULL;
// Fill in the OPENFILENAME structure to support a template and hook.
dlgOpenFile.m_ofn.lpstrInitialDir = szInitialFolder;
if (!csMessage.LoadString( IDS_SELECT_PLUGIN_FILE))
AfxThrowMemoryException();
dlgOpenFile.m_ofn.lpstrTitle = csMessage.GetBuffer( csMessage.GetLength());
if (dlgOpenFile.DoModal() != IDOK)
return;
m_ListPlugins.AddString( dlgOpenFile.GetPathName());
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
if (pMyIdList != NULL)
pIMalloc->Free( pMyIdList);
return;
}
}
void CWindowsSetupDlg::OnBnClickedButtonRemovePlugin()
{
// TODO: Add your control notification handler code here
try
{
int nCurSel;
if ((nCurSel = m_ListPlugins.GetCurSel()) == LB_ERR )
// No item selected
return;
m_ListPlugins.DeleteString( nCurSel);
}
catch( CException *pEx)
{
pEx->ReportError( MB_OK|MB_ICONSTOP);
pEx->Delete();
return;
}
}
BOOL CWindowsSetupDlg::RemovePluginsFilesFromRegistry()
{
HKEY hKey;
CString csKey, csValue;
DWORD dwErr, dwLength;
UINT uIndex = 0;
csKey.Format( _T( "SOFTWARE\\OCS_DEPLOY_TOOL\\%s\\%s"), AGENT_SECTION, WIN_AGENT_PLUGINS_FOLDER);
if ((dwErr = RegOpenKeyEx( HKEY_CURRENT_USER, csKey, 0, KEY_READ|KEY_WRITE, &hKey)) != ERROR_SUCCESS)
return FALSE;
while (dwErr == ERROR_SUCCESS)
{
csValue.Format( _T( "%u"), uIndex);
// Check if value exists
dwErr = REG_SZ;
dwLength = 0;
if ((dwErr = RegQueryValueEx( hKey, csValue, NULL, &dwErr, NULL, &dwLength)) == ERROR_SUCCESS)
// Key exists, delete it
RegDeleteValue( hKey, csValue);
// Continue
uIndex ++;
}
RegCloseKey( hKey);
return TRUE;
}