Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

757 lines
21 KiB

  1. // AdvDlg.cpp : implementation file
  2. //
  3. // NOTE: This files makes the assumption that there are a reasonable number of published.
  4. // If there are thousands, or hundreds of thousands of them - it will be slow because it
  5. // rescans the metabase after changes. Then again, this whole product is intended for
  6. // sites that are MUCH smaller than that.
  7. #include "stdafx.h"
  8. #include "AdvDlg.h"
  9. #include "pwsDoc.h"
  10. #include "PWSChart.h"
  11. #include "PwsForm.h"
  12. #include <mddef.h>
  13. #include "EdDir.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #define COL_ALIAS 0
  20. #define COL_DIRECTORY 1
  21. #define COL_ERROR 2
  22. // a global reference to the form view - for ease of access
  23. extern CPwsForm* g_p_FormView;
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CAdvancedDlg dialog
  26. //-----------------------------------------------------------------
  27. CAdvancedDlg::CAdvancedDlg(CWnd* pParent /*=NULL*/)
  28. : CDialog(CAdvancedDlg::IDD, pParent),
  29. m_fApplyingGlobals( FALSE )
  30. {
  31. //{{AFX_DATA_INIT(CAdvancedDlg)
  32. m_sz_defaultdoc = _T("");
  33. m_f_browsingallowed = FALSE;
  34. m_f_enabledefault = FALSE;
  35. //}}AFX_DATA_INIT
  36. }
  37. //-----------------------------------------------------------------
  38. void CAdvancedDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAdvancedDlg)
  42. DDX_Control(pDX, IDC_STATIC_DEFAULT, m_cstatic_default);
  43. DDX_Control(pDX, IDC_DEFAULT_DOC, m_cedit_default);
  44. DDX_Control(pDX, IDC_CHANGE, m_cbutton_change);
  45. DDX_Control(pDX, IDC_LIST, m_clistctrl_list);
  46. DDX_Control(pDX, IDC_REMOVE, m_cbutton_remove);
  47. DDX_Text(pDX, IDC_DEFAULT_DOC, m_sz_defaultdoc);
  48. DDX_Check(pDX, IDC_BROWSING_ALLOWED, m_f_browsingallowed);
  49. DDX_Check(pDX, IDC_ENABLEDEFAULT, m_f_enabledefault);
  50. //}}AFX_DATA_MAP
  51. }
  52. //-----------------------------------------------------------------
  53. BEGIN_MESSAGE_MAP(CAdvancedDlg, CDialog)
  54. //{{AFX_MSG_MAP(CAdvancedDlg)
  55. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  56. ON_BN_CLICKED(IDC_ADD, OnAdd)
  57. ON_BN_CLICKED(IDC_CHANGE, OnChange)
  58. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  59. ON_BN_CLICKED(IDC_ENABLEDEFAULT, OnEnabledefault)
  60. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  61. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  62. ON_BN_CLICKED(IDC_BROWSING_ALLOWED, OnBrowsingAllowed)
  63. ON_EN_KILLFOCUS(IDC_DEFAULT_DOC, OnKillfocusDefaultDoc)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. //-----------------------------------------------------------------
  67. BOOL CAdvancedDlg::FInitList()
  68. {
  69. CString sz;
  70. int i;
  71. // setup the alias field
  72. sz.LoadString( IDS_ALIAS );
  73. i = m_clistctrl_list.InsertColumn( COL_ALIAS, sz, LVCFMT_LEFT, 95 );
  74. // setup the directory field
  75. sz.LoadString( IDS_DIRECTORY );
  76. i = m_clistctrl_list.InsertColumn( COL_DIRECTORY, sz, LVCFMT_LEFT, 225);
  77. // setup the match criteria column
  78. sz.LoadString( IDS_ERROR );
  79. i = m_clistctrl_list.InsertColumn( COL_ERROR, sz, LVCFMT_LEFT, 95 );
  80. // prepare the list's image list
  81. if ( m_imageList.Create( IDB_LIST_IMAGES, 17, 3, 0x00FF00FF ) )
  82. // set the image list into the list control
  83. m_clistctrl_list.SetImageList( &m_imageList, LVSIL_SMALL );
  84. return TRUE;
  85. }
  86. //-----------------------------------------------------------------
  87. BOOL CAdvancedDlg::FInitGlobalParameters()
  88. {
  89. CHAR buff[MAX_PATH];
  90. DWORD dword;
  91. m_fApplyingGlobals = TRUE;
  92. // prep the mb objcet
  93. CWrapMetaBase mb;
  94. if ( !FInitMetabaseWrapper(NULL) )
  95. return FALSE;
  96. if ( !mb.FInit() ) {
  97. FCloseMetabaseWrapper();
  98. return FALSE;
  99. }
  100. // open the root directory object
  101. if ( !mb.Open(SZ_MB_DIRGLOBALS_OBJECT) )
  102. {
  103. AfxMessageBox( IDS_MetaError );
  104. FCloseMetabaseWrapper();
  105. return (DWORD)-1;
  106. }
  107. // Get the parameters from the metabase and put them into the dialog
  108. if ( mb.GetDword( "", MD_DIRECTORY_BROWSING, IIS_MD_UT_FILE, &dword ) )
  109. {
  110. m_f_browsingallowed = (dword & MD_DIRBROW_ENABLED) > 0;
  111. m_f_enabledefault = (dword & MD_DIRBROW_LOADDEFAULT) > 0;
  112. }
  113. else
  114. {
  115. m_f_browsingallowed = FALSE;
  116. m_f_enabledefault = FALSE;
  117. }
  118. // get the default document string
  119. dword = MAX_PATH;
  120. if ( mb.GetString( "", MD_DEFAULT_LOAD_FILE, IIS_MD_UT_FILE, buff, &dword ) )
  121. m_sz_defaultdoc = buff;
  122. m_szSaved = m_sz_defaultdoc;
  123. // update the data
  124. UpdateData( FALSE );
  125. // enable or disable the default document string as appropriate
  126. OnEnabledefault();
  127. // close the metabase object
  128. mb.Close();
  129. FCloseMetabaseWrapper();
  130. m_fApplyingGlobals = FALSE;
  131. return TRUE;
  132. }
  133. //-----------------------------------------------------------------
  134. BOOL CAdvancedDlg::FillList()
  135. {
  136. CHAR buff[MAX_PATH];
  137. DWORD cbpath;
  138. CVirtDir* pDir;
  139. // prep the mb objcet
  140. CWrapMetaBase mb;
  141. if ( !FInitMetabaseWrapper(NULL) )
  142. return FALSE;
  143. if ( !mb.FInit() ) {
  144. FCloseMetabaseWrapper();
  145. return FALSE;
  146. }
  147. // open the root directory object
  148. if ( !mb.Open(SZ_MB_ROOTDIR_OBJECT) )
  149. {
  150. AfxMessageBox( IDS_MetaError );
  151. FCloseMetabaseWrapper();
  152. return (DWORD)-1;
  153. }
  154. // create the root <home> directory object
  155. pDir = new CVirtDir( TRUE ); // true means this is the root
  156. pDir->m_szAlias.LoadString( IDS_HOME_DIRECTORY );
  157. pDir->m_szMetaAlias.Empty();
  158. // get the directory path
  159. cbpath = MAX_PATH;
  160. mb.GetString( "", MD_VR_PATH, IIS_MD_UT_FILE, buff, &cbpath);
  161. pDir->m_szPath = buff;
  162. // add the item to the list
  163. AddToDisplayList( pDir );
  164. // enumerate the directories, adding each to the list
  165. DWORD index = 0;
  166. while ( mb.EnumObjects("", buff, index) )
  167. {
  168. // create the new directory object
  169. pDir = new CVirtDir();
  170. // set the alias
  171. pDir->m_szAlias = buff;
  172. pDir->m_szMetaAlias = buff;
  173. // get the directory path
  174. cbpath = MAX_PATH;
  175. if ( !mb.GetString( buff, MD_VR_PATH, IIS_MD_UT_FILE, buff, &cbpath) )
  176. break;
  177. pDir->m_szPath = buff;
  178. // add the item to the list
  179. AddToDisplayList( pDir );
  180. // advance the index
  181. index++;
  182. }
  183. // close the metabase object
  184. mb.Close();
  185. FCloseMetabaseWrapper();
  186. return TRUE;
  187. }
  188. //-----------------------------------------------------------------
  189. void CAdvancedDlg::AddToDisplayList( CVirtDir* pDir )
  190. {
  191. CString szErr;
  192. DWORD i = m_clistctrl_list.GetSelectedCount();
  193. // add the item to the end of the list - with the alias text
  194. i = m_clistctrl_list.InsertItem( i, pDir->m_szAlias, 0 );
  195. // fill in the directory in the list
  196. m_clistctrl_list.SetItemText( i, COL_DIRECTORY, pDir->m_szPath );
  197. // fill in the error string
  198. pDir->GetErrorStr( szErr );
  199. m_clistctrl_list.SetItemText( i, COL_ERROR, szErr );
  200. // attach the object itself to the list as private data.
  201. m_clistctrl_list.SetItemData( i, (DWORD)pDir );
  202. }
  203. //-----------------------------------------------------------------
  204. void CAdvancedDlg::EnableDependantButtons()
  205. {
  206. CVirtDir* pDir;
  207. // the whole purpose of this routine is to gray or activate
  208. // the edit and delete buttons depending on whether or not anything
  209. // is selected. So start by getting the selection count
  210. UINT cItemsSel = m_clistctrl_list.GetSelectedCount();
  211. // get index of the selected list item
  212. int iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  213. // get the pDir from the list
  214. pDir = (CVirtDir*)m_clistctrl_list.GetItemData( iList );
  215. ASSERT( pDir );
  216. if ( cItemsSel > 0 )
  217. {
  218. // there are items selected
  219. m_cbutton_change.EnableWindow( TRUE );
  220. m_cbutton_remove.EnableWindow( !pDir->m_fIsRoot ); // cannot remove the root
  221. }
  222. else
  223. {
  224. // nope. Nothing selected
  225. m_cbutton_change.EnableWindow( FALSE );
  226. m_cbutton_remove.EnableWindow( FALSE );
  227. }
  228. }
  229. /////////////////////////////////////////////////////////////////////////////
  230. // CAdvancedDlg message handlers
  231. //---------------------------------------------------------------------------
  232. BOOL CAdvancedDlg::OnInitDialog()
  233. {
  234. //DebugBreak();
  235. // call the parental oninitdialog
  236. BOOL f = CDialog::OnInitDialog();
  237. // initialize the global parameters
  238. FInitGlobalParameters();
  239. // initialize the list
  240. FInitList();
  241. FillList();
  242. EnableDependantButtons();
  243. // exchange the data
  244. UpdateData( FALSE );
  245. // return the answer
  246. return f;
  247. }
  248. //---------------------------------------------------------------------------
  249. void CAdvancedDlg::RefreshGlobals()
  250. {
  251. UpdateData( TRUE );
  252. FInitGlobalParameters();
  253. UpdateData( FALSE );
  254. }
  255. //---------------------------------------------------------------------------
  256. void CAdvancedDlg::RefreshList()
  257. {
  258. // first, delete all the virdir objects referenced by the list
  259. EmptyOutList();
  260. // re-fill the list
  261. FillList();
  262. }
  263. //---------------------------------------------------------------------------
  264. void CAdvancedDlg::OnRefresh()
  265. {
  266. m_fApplyingGlobals = TRUE;
  267. RefreshGlobals();
  268. m_fApplyingGlobals = FALSE;
  269. RefreshList();
  270. }
  271. //---------------------------------------------------------------------------
  272. void CAdvancedDlg::EmptyOutList()
  273. {
  274. CVirtDir* pVDir;
  275. // get the number of elements in the list
  276. DWORD cItems = m_clistctrl_list.GetItemCount();
  277. for ( DWORD iItem = 0; iItem < cItems; iItem++ )
  278. {
  279. // get the virt dir pointer
  280. pVDir = (CVirtDir*)m_clistctrl_list.GetItemData( iItem );
  281. // delete the vit dir
  282. if ( pVDir )
  283. delete pVDir;
  284. }
  285. // empty the list itself
  286. m_clistctrl_list.DeleteAllItems();
  287. }
  288. //---------------------------------------------------------------------------
  289. void CAdvancedDlg::OnCancel()
  290. {
  291. // clean up the list
  292. EmptyOutList();
  293. ShowWindow(SW_HIDE);
  294. }
  295. //---------------------------------------------------------------------------
  296. void CAdvancedDlg::OnKillfocusDefaultDoc()
  297. {
  298. UpdateData( TRUE );
  299. // apply it to the metabase right-away
  300. if ( !m_fApplyingGlobals )
  301. {
  302. m_fApplyingGlobals = TRUE;
  303. // apply it to the metabase right-away
  304. ApplyGlobalParameters();
  305. RefreshGlobals();
  306. if ( g_p_FormView )
  307. g_p_FormView->UpdateDirInfo();
  308. m_fApplyingGlobals = FALSE;
  309. }
  310. }
  311. //---------------------------------------------------------------------------
  312. void CAdvancedDlg::OnBrowsingAllowed()
  313. {
  314. UpdateData( TRUE );
  315. // apply it to the metabase right-away
  316. if ( !m_fApplyingGlobals )
  317. {
  318. m_fApplyingGlobals = TRUE;
  319. // apply it to the metabase right-away
  320. ApplyGlobalParameters();
  321. RefreshGlobals();
  322. if ( g_p_FormView )
  323. g_p_FormView->UpdateDirInfo();
  324. m_fApplyingGlobals = FALSE;
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. void CAdvancedDlg::OnEnabledefault()
  329. {
  330. UpdateData( TRUE );
  331. // enable or disable the default document string as appropriate
  332. if ( m_f_enabledefault )
  333. {
  334. m_sz_defaultdoc = m_szSaved;
  335. // enable things
  336. m_cedit_default.EnableWindow( TRUE );
  337. m_cstatic_default.EnableWindow( TRUE );
  338. }
  339. else
  340. {
  341. m_szSaved = m_sz_defaultdoc;
  342. m_sz_defaultdoc.Empty();
  343. // disable things
  344. m_cedit_default.EnableWindow( FALSE );
  345. m_cstatic_default.EnableWindow( FALSE );
  346. }
  347. UpdateData( FALSE );
  348. if ( !m_fApplyingGlobals )
  349. {
  350. m_fApplyingGlobals = TRUE;
  351. // apply it to the metabase right-away
  352. ApplyGlobalParameters();
  353. RefreshGlobals();
  354. if ( g_p_FormView )
  355. g_p_FormView->UpdateDirInfo();
  356. m_fApplyingGlobals = FALSE;
  357. }
  358. }
  359. //---------------------------------------------------------------------------
  360. void CAdvancedDlg::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  361. {
  362. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  363. *pResult = 0;
  364. // enable the correct items
  365. EnableDependantButtons();
  366. }
  367. //---------------------------------------------------------------------------
  368. void CAdvancedDlg::OnAdd()
  369. {
  370. // create the new directory object
  371. CVirtDir* pDir = new CVirtDir();
  372. // give the new directory some defaults
  373. pDir->m_szPath.Empty();
  374. pDir->m_szAlias.Empty();
  375. pDir->m_szMetaAlias.Empty();
  376. // Edit the rule. If it fails, remove it from the list
  377. if ( pDir->Edit() )
  378. {
  379. // save the item to the metabase
  380. pDir->FSaveToMetabase();
  381. // refresh the list
  382. RefreshList();
  383. }
  384. // in all cases, delete the pDir object. If it was saved to the metabase,
  385. // it was picked up again during the refresh
  386. delete pDir;
  387. }
  388. //---------------------------------------------------------------------------
  389. void CAdvancedDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  390. {
  391. *pResult = 0;
  392. // if something in the list was double clicked, edit it
  393. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  394. OnChange();
  395. }
  396. //---------------------------------------------------------------------------
  397. void CAdvancedDlg::OnChange()
  398. {
  399. CVirtDir* pDir;
  400. int iList;
  401. CString szErr;
  402. // there had better be one selected
  403. if ( m_clistctrl_list.GetSelectedCount() != 1 )
  404. return;
  405. // get index of the selected list item
  406. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  407. ASSERT( iList >= 0 );
  408. // get the pDir from the list
  409. pDir = (CVirtDir*)m_clistctrl_list.GetItemData( iList );
  410. // edit the pDir, update it if successful, delete if not
  411. if ( pDir->Edit() )
  412. {
  413. // save the item to the metabase
  414. pDir->FSaveToMetabase();
  415. // refresh the list
  416. RefreshList();
  417. }
  418. }
  419. //---------------------------------------------------------------------------
  420. void CAdvancedDlg::OnRemove()
  421. {
  422. int iList;
  423. CVirtDir* pDir;
  424. // there had better be one selected
  425. if ( m_clistctrl_list.GetSelectedCount() != 1 )
  426. return;
  427. // ask the user to confirm this decision
  428. if ( AfxMessageBox(IDS_CONFIRM_REMOVE, MB_OKCANCEL) != IDOK )
  429. return;
  430. // get index of the selected list item
  431. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  432. ASSERT( iList >= 0 );
  433. // get the pDir from the list
  434. pDir = (CVirtDir*)m_clistctrl_list.GetItemData( iList );
  435. // remove the item from the metabase
  436. pDir->FRemoveFromMetabase();
  437. // refresh the list
  438. RefreshList();
  439. }
  440. //---------------------------------------------------------------------------
  441. void CAdvancedDlg::ApplyGlobalParameters()
  442. {
  443. DWORD dword;
  444. BOOL f;
  445. // prep the mb objcet
  446. CWrapMetaBase mb;
  447. if ( !FInitMetabaseWrapper(NULL) )
  448. return;
  449. if ( !mb.FInit() ) {
  450. FCloseMetabaseWrapper();
  451. return;
  452. }
  453. // open the root directory object
  454. if ( !mb.Open(SZ_MB_DIRGLOBALS_OBJECT, METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE) )
  455. {
  456. DWORD err = GetLastError();
  457. CString sz;
  458. sz.LoadString( IDS_MetaError );
  459. sz.Format( "%s\nError = %d", sz, err );
  460. AfxMessageBox( sz );
  461. FCloseMetabaseWrapper();
  462. return;
  463. }
  464. // to prepare the browsing flag for saving - we must get the current value
  465. if ( mb.GetDword( "", MD_DIRECTORY_BROWSING, IIS_MD_UT_FILE, &dword ) )
  466. {
  467. // start by setting or clearing the browsing allowed flag
  468. if ( m_f_browsingallowed )
  469. dword |= MD_DIRBROW_ENABLED; // set the flag
  470. else
  471. dword &= ~MD_DIRBROW_ENABLED; // clear the flag
  472. // next, set or clear the enable default flag
  473. if ( m_f_enabledefault )
  474. dword |= MD_DIRBROW_LOADDEFAULT; // set the flag
  475. else
  476. dword &= ~MD_DIRBROW_LOADDEFAULT; // clear the flag
  477. // save the browsing flag
  478. f = mb.SetDword( "", MD_DIRECTORY_BROWSING, IIS_MD_UT_FILE, dword );
  479. }
  480. // save the default string
  481. if ( m_f_enabledefault )
  482. f = mb.SetString( "", MD_DEFAULT_LOAD_FILE, IIS_MD_UT_FILE, (LPCSTR)m_sz_defaultdoc );
  483. // close the metabase object
  484. mb.Close();
  485. FCloseMetabaseWrapper();
  486. return;
  487. }
  488. /////////////////////////////////////////////////////////////////////////////
  489. // CVirtDir object - for maintaining the list
  490. //---------------------------------------------------------------------------
  491. CVirtDir::CVirtDir(BOOL bRoot) :
  492. m_fIsRoot(bRoot)
  493. {}
  494. //---------------------------------------------------------------------------
  495. BOOL CVirtDir::FInitAsNew()
  496. {
  497. return TRUE;
  498. }
  499. //---------------------------------------------------------------------------
  500. void CVirtDir::GetErrorStr( CString &sz )
  501. {
  502. // see if the specified path is valid
  503. if ( GetFileAttributes(m_szPath) == 0xFFFFFFFF )
  504. sz.LoadString( IDS_ERR_PATH_INVALID );
  505. else
  506. sz.Empty();
  507. }
  508. //---------------------------------------------------------------------------
  509. BOOL CVirtDir::Edit()
  510. {
  511. CEditDirectory dlg;
  512. dlg.pDir = this;
  513. dlg.m_sz_alias = m_szAlias;
  514. dlg.m_sz_path = m_szPath;
  515. if ( dlg.DoModal() == IDOK )
  516. {
  517. m_szAlias = dlg.m_sz_alias;
  518. m_szPath = dlg.m_sz_path;
  519. return TRUE;
  520. }
  521. return FALSE;
  522. }
  523. //---------------------------------------------------------------------------
  524. BOOL CVirtDir::FSaveToMetabase()
  525. {
  526. BOOL fSuccess = TRUE;
  527. CString sz;
  528. DWORD err;
  529. // if the alias name has changed, we must first remove the original object
  530. // from the metabase, then re-add it with the new name
  531. if ( !m_fIsRoot && (m_szAlias != m_szMetaAlias) )
  532. {
  533. fSuccess = FRemoveFromMetabase( FALSE ); // false to not save the metabase
  534. m_szMetaAlias.Empty();
  535. if ( !fSuccess ) return FALSE;
  536. }
  537. // prep the metabase
  538. CWrapMetaBase mb;
  539. if ( !FInitMetabaseWrapper(NULL) )
  540. return FALSE;
  541. if ( !mb.FInit() ) {
  542. FCloseMetabaseWrapper();
  543. return FALSE;
  544. }
  545. // the first thing we do is open the metabase with WRITE permissions
  546. // open the metabase object
  547. if ( !mb.Open(SZ_MB_ROOTDIR_OBJECT, METADATA_PERMISSION_WRITE) )
  548. {
  549. err = GetLastError();
  550. sz.LoadString( IDS_MetaError );
  551. sz.Format( "%s\nError = %d", sz, err );
  552. AfxMessageBox( sz );
  553. FCloseMetabaseWrapper();
  554. return FALSE;
  555. }
  556. // if the object is new, then there is nothing in the metaAlias string.
  557. // in that case we should start by creating a new object in the metabase
  558. if ( !m_fIsRoot && m_szMetaAlias.IsEmpty() )
  559. {
  560. fSuccess = mb.AddObject( m_szAlias );
  561. m_szMetaAlias = m_szAlias;
  562. }
  563. // now we can save the directory data - but only if the object is there
  564. if ( fSuccess ) // test the object existence
  565. {
  566. fSuccess = mb.SetString( m_szMetaAlias, MD_VR_PATH, IIS_MD_UT_FILE, m_szPath );
  567. }
  568. // save the metabase
  569. mb.Save();
  570. // close the object
  571. mb.Close();
  572. FCloseMetabaseWrapper();
  573. // if there was an error - say something intelligent
  574. if ( !fSuccess )
  575. {
  576. err = GetLastError();
  577. sz.LoadString( IDS_MetaError );
  578. sz.Format( "%s\nError = %d", sz, err );
  579. AfxMessageBox( sz );
  580. }
  581. // return the answer
  582. return fSuccess;
  583. }
  584. //---------------------------------------------------------------------------
  585. BOOL CVirtDir::FRemoveFromMetabase( BOOL fSaveMB )
  586. {
  587. BOOL fSuccess = TRUE;
  588. CString sz;
  589. DWORD err;
  590. // Never remove a root object.
  591. if ( m_szMetaAlias.IsEmpty() )
  592. return fSuccess;
  593. // prep the metabase
  594. CWrapMetaBase mb;
  595. if ( !FInitMetabaseWrapper(NULL) )
  596. return FALSE;
  597. if ( !mb.FInit() ) {
  598. FCloseMetabaseWrapper();
  599. return FALSE;
  600. }
  601. // the first thing we do is open the metabase with WRITE permissions
  602. // open the metabase object
  603. if ( !mb.Open(SZ_MB_ROOTDIR_OBJECT, METADATA_PERMISSION_WRITE) )
  604. {
  605. err = GetLastError();
  606. sz.LoadString( IDS_MetaError );
  607. sz.Format( "%s\nError = %d", sz, err );
  608. AfxMessageBox( sz );
  609. FCloseMetabaseWrapper();
  610. return FALSE;
  611. }
  612. // delete the item
  613. fSuccess = mb.DeleteObject( m_szMetaAlias );
  614. // save the metabase - if requested
  615. if ( fSaveMB )
  616. mb.Save();
  617. //
  618. // close the metawrapper
  619. //
  620. mb.Close();
  621. FCloseMetabaseWrapper();
  622. // if there was an error - say something intelligent
  623. if ( !fSuccess )
  624. {
  625. err = GetLastError();
  626. sz.LoadString( IDS_MetaError );
  627. sz.Format( "%s\nError = %d", sz, err );
  628. AfxMessageBox( sz );
  629. }
  630. // return the answer
  631. return fSuccess;
  632. }