Leaked source code of windows server 2003
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.

349 lines
9.7 KiB

  1. // scrmap1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ISAdmin.h"
  5. #include "scrmap1.h"
  6. #include "scripmap.h"
  7. #include "addscrip.h"
  8. #include "editscri.h"
  9. #include "delscrip.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // ScrMap1 property page
  16. IMPLEMENT_DYNCREATE(ScrMap1, CGenPage)
  17. ScrMap1::ScrMap1() : CGenPage(ScrMap1::IDD)
  18. {
  19. //{{AFX_DATA_INIT(ScrMap1)
  20. // NOTE: the ClassWizard will add member initialization here
  21. //}}AFX_DATA_INIT
  22. m_rkScriptKey = NULL;
  23. m_pseScriptMapList = NULL;
  24. }
  25. ScrMap1::~ScrMap1()
  26. {
  27. if (m_rkScriptKey != NULL)
  28. delete(m_rkScriptKey);
  29. DeleteScriptList();
  30. }
  31. void ScrMap1::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CGenPage::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(ScrMap1)
  35. DDX_Control(pDX, IDC_SCRIPTMAPLISTBOX, m_lboxScriptMap);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(ScrMap1, CGenPage)
  39. //{{AFX_MSG_MAP(ScrMap1)
  40. ON_BN_CLICKED(IDC_SCRIPTMAPADDBUTTON, OnScriptmapaddbutton)
  41. ON_BN_CLICKED(IDC_SCRIPTMAPEDITBUTTON, OnScriptmapeditbutton)
  42. ON_BN_CLICKED(IDC_SCRIPTMAPREMOVEBUTTON, OnScriptmapremovebutton)
  43. ON_LBN_DBLCLK(IDC_SCRIPTMAPLISTBOX, OnDblclkScriptmaplistbox)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // ScrMap1 message handlers
  48. BOOL ScrMap1::OnInitDialog()
  49. {
  50. CGenPage::OnInitDialog();
  51. CString strNextValueName, strNextValue;
  52. BOOL bAllocationError = FALSE;
  53. CRegValueIter *rviScriptKeys;
  54. DWORD err, ulRegType;
  55. m_ulScriptIndex = 0;
  56. BOOL bReadError = FALSE;
  57. int iTabSpacing = 58;
  58. m_lboxScriptMap.SetTabStops(iTabSpacing);
  59. m_bScriptEntriesExist = FALSE;
  60. m_rkScriptKey = new CRegKey(*m_rkMainKey,_T("Script Map"),REGISTRY_ACCESS_RIGHTS);
  61. // Anything under this key should be a mime mapping.
  62. // No way to verify that, but non-string entries are invalid
  63. // so ignore them.
  64. if (m_rkScriptKey != NULL) {
  65. if (*m_rkScriptKey != NULL) {
  66. if (rviScriptKeys = new CRegValueIter(*m_rkScriptKey)) {
  67. while ((err = rviScriptKeys->Next(&strNextValueName, &ulRegType)) == ERROR_SUCCESS) {
  68. if (ulRegType == REG_SZ) {
  69. if (m_rkScriptKey->QueryValue(strNextValueName, strNextValue) == 0) {
  70. if (!AddScriptEntry(strNextValueName, strNextValue, TRUE))
  71. bAllocationError = TRUE;
  72. }
  73. else {
  74. bReadError = TRUE;
  75. }
  76. }
  77. }
  78. delete (rviScriptKeys);
  79. }
  80. m_bScriptEntriesExist = TRUE;
  81. }
  82. }
  83. if (!m_bScriptEntriesExist) { //Can't open registry key
  84. CString strNoScriptEntriesMsg;
  85. strNoScriptEntriesMsg.LoadString(IDS_SCRIPTNOSCRIPTENTRIESMSG);
  86. AfxMessageBox(strNoScriptEntriesMsg);
  87. }
  88. if (bAllocationError) { //Error adding one or more entries
  89. CString strAllocFailMsg;
  90. strAllocFailMsg.LoadString(IDS_SCRIPTENTRIESALLOCFAILMSG);
  91. AfxMessageBox(strAllocFailMsg);
  92. }
  93. if (bReadError) { //Error reading one or more entries
  94. CString strReadErrorMsg;
  95. strReadErrorMsg.LoadString(IDS_SCRIPTREADERRORMSG);
  96. AfxMessageBox(strReadErrorMsg);
  97. }
  98. // TODO: Add extra initialization here
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. // EXCEPTION: OCX Property Pages should return FALSE
  101. }
  102. void ScrMap1::OnScriptmapaddbutton()
  103. {
  104. // TODO: Add your control notification handler code here
  105. if (m_bScriptEntriesExist) {
  106. CAddScript addscriptGetInfo(this);
  107. if (addscriptGetInfo.DoModal() == IDOK) {
  108. if (AddScriptEntry(addscriptGetInfo.GetFileExtension(), addscriptGetInfo.GetScriptMap(),FALSE)) {
  109. m_bIsDirty = TRUE;
  110. SetModified(TRUE);
  111. }
  112. else {
  113. CString strAllocFailMsg;
  114. strAllocFailMsg.LoadString(IDS_SCRIPTENTRYALLOCFAILMSG);
  115. AfxMessageBox(strAllocFailMsg);
  116. }
  117. }
  118. }
  119. else {
  120. CString strNoScriptEntriesMsg;
  121. strNoScriptEntriesMsg.LoadString(IDS_SCRIPTNOSCRIPTENTRIESMSG);
  122. AfxMessageBox(strNoScriptEntriesMsg);
  123. }
  124. }
  125. void ScrMap1::OnScriptmapeditbutton()
  126. {
  127. // TODO: Add your control notification handler code here
  128. if (m_bScriptEntriesExist) {
  129. int iCurSel;
  130. PSCRIPT_ENTRY pseEditEntry;
  131. if ((iCurSel = m_lboxScriptMap.GetCurSel()) != LB_ERR) {
  132. for (pseEditEntry = m_pseScriptMapList;(pseEditEntry != NULL) &&
  133. (m_lboxScriptMap.GetItemData(iCurSel) != pseEditEntry->iListIndex);
  134. pseEditEntry = pseEditEntry->NextPtr)
  135. ;
  136. ASSERT (pseEditEntry != NULL);
  137. CEditScript editscriptGetInfo(this,
  138. pseEditEntry->scriptData->GetFileExtension(),
  139. pseEditEntry->scriptData->GetScriptMap());
  140. if (editscriptGetInfo.DoModal() == IDOK) {
  141. if (EditScriptMapping(iCurSel,
  142. pseEditEntry,
  143. editscriptGetInfo.GetFileExtension(),
  144. editscriptGetInfo.GetScriptMap())) {
  145. m_bIsDirty = TRUE;
  146. SetModified(TRUE);
  147. }
  148. else {
  149. CString strEditErrorMsg;
  150. strEditErrorMsg.LoadString(IDS_SCRIPTEDITERRORMSG);
  151. AfxMessageBox(strEditErrorMsg);
  152. }
  153. }
  154. }
  155. else {
  156. CString strNoHighlightMsg;
  157. strNoHighlightMsg.LoadString(IDS_NOHIGHLIGHTMSG);
  158. AfxMessageBox(strNoHighlightMsg);
  159. }
  160. }
  161. else {
  162. CString strNoScriptEntriesMsg;
  163. strNoScriptEntriesMsg.LoadString(IDS_SCRIPTNOSCRIPTENTRIESMSG);
  164. AfxMessageBox(strNoScriptEntriesMsg);
  165. }
  166. }
  167. void ScrMap1::OnScriptmapremovebutton()
  168. {
  169. // TODO: Add your control notification handler code here
  170. if (m_bScriptEntriesExist) {
  171. int iCurSel;
  172. CDelScript delscriptGetInfo(this);
  173. if ((iCurSel = m_lboxScriptMap.GetCurSel()) != LB_ERR) {
  174. if (delscriptGetInfo.DoModal() == IDOK) {
  175. DeleteScriptMapping(iCurSel);
  176. m_bIsDirty = TRUE;
  177. SetModified(TRUE);
  178. }
  179. }
  180. else {
  181. CString strNoHighlightMsg;
  182. strNoHighlightMsg.LoadString(IDS_NOHIGHLIGHTMSG);
  183. AfxMessageBox(strNoHighlightMsg);
  184. }
  185. }
  186. else {
  187. CString strNoScriptEntriesMsg;
  188. strNoScriptEntriesMsg.LoadString(IDS_SCRIPTNOSCRIPTENTRIESMSG);
  189. AfxMessageBox(strNoScriptEntriesMsg);
  190. }
  191. }
  192. void ScrMap1::OnDblclkScriptmaplistbox()
  193. {
  194. // TODO: Add your control notification handler code here
  195. OnScriptmapeditbutton();
  196. }
  197. ////////////////////////////////////////////////////////////////////////
  198. // Other Functions
  199. void ScrMap1::SaveInfo()
  200. {
  201. PSCRIPT_ENTRY pseSaveEntry;
  202. CString strTempValue;
  203. if (m_bIsDirty) {
  204. for (pseSaveEntry = m_pseScriptMapList;(pseSaveEntry != NULL); pseSaveEntry = pseSaveEntry->NextPtr) {
  205. if (pseSaveEntry->DeleteCurrent) {
  206. m_rkScriptKey->DeleteValue(pseSaveEntry->scriptData->GetPrevFileExtension());
  207. pseSaveEntry->DeleteCurrent = FALSE;
  208. }
  209. if (pseSaveEntry->WriteNew) {
  210. strTempValue = pseSaveEntry->scriptData->GetScriptMap();
  211. m_rkScriptKey->SetValue(pseSaveEntry->scriptData->GetFileExtension(), strTempValue);
  212. pseSaveEntry->scriptData->SetPrevFileExtension();
  213. pseSaveEntry->WriteNew = FALSE;
  214. }
  215. }
  216. }
  217. CGenPage::SaveInfo();
  218. }
  219. BOOL ScrMap1::AddScriptEntry(LPCTSTR pchFileExtension, LPCTSTR pchScriptMap, BOOL bExistingEntry)
  220. {
  221. PSCRIPT_ENTRY pseNewEntry;
  222. int iCurSel;
  223. BOOL bretcode = FALSE;
  224. if ((pseNewEntry = new SCRIPT_ENTRY) != NULL) {
  225. if ((pseNewEntry->scriptData = new CScriptMap(pchFileExtension, pchScriptMap, bExistingEntry)) != NULL) {
  226. iCurSel = m_lboxScriptMap.AddString(pseNewEntry->scriptData->GetDisplayString());
  227. if ((iCurSel != LB_ERR) && (iCurSel != LB_ERRSPACE)) {
  228. pseNewEntry->DeleteCurrent = FALSE;
  229. pseNewEntry->WriteNew = TRUE;
  230. m_lboxScriptMap.SetItemData(iCurSel,m_ulScriptIndex);
  231. m_lboxScriptMap.SetCurSel(iCurSel);
  232. pseNewEntry->iListIndex = m_ulScriptIndex++;
  233. pseNewEntry->NextPtr = m_pseScriptMapList;
  234. m_pseScriptMapList = pseNewEntry;
  235. bretcode = TRUE;
  236. }
  237. else {
  238. delete (pseNewEntry->scriptData);
  239. delete (pseNewEntry);
  240. }
  241. }
  242. else
  243. delete (pseNewEntry);
  244. }
  245. return (bretcode);
  246. }
  247. void ScrMap1::DeleteScriptList()
  248. {
  249. PSCRIPT_ENTRY pseCurEntry;
  250. while (m_pseScriptMapList != NULL) {
  251. delete (m_pseScriptMapList->scriptData);
  252. pseCurEntry = m_pseScriptMapList;
  253. m_pseScriptMapList = m_pseScriptMapList->NextPtr;
  254. delete (pseCurEntry);
  255. }
  256. }
  257. void ScrMap1::DeleteScriptMapping(int iCurSel)
  258. {
  259. PSCRIPT_ENTRY pseDelEntry;
  260. for (pseDelEntry = m_pseScriptMapList;(pseDelEntry != NULL) &&
  261. (m_lboxScriptMap.GetItemData(iCurSel) != pseDelEntry->iListIndex);
  262. pseDelEntry = pseDelEntry->NextPtr)
  263. ;
  264. ASSERT (pseDelEntry != NULL);
  265. if (pseDelEntry->scriptData->PrevScriptMapExists())
  266. pseDelEntry->DeleteCurrent = TRUE;
  267. pseDelEntry->WriteNew = FALSE;
  268. m_lboxScriptMap.DeleteString(iCurSel);
  269. }
  270. BOOL ScrMap1::EditScriptMapping(int iCurSel,
  271. PSCRIPT_ENTRY pseEditEntry,
  272. LPCTSTR pchFileExtension,
  273. LPCTSTR pchScriptMap)
  274. {
  275. BOOL bretcode = FALSE;
  276. pseEditEntry->scriptData->SetFileExtension(pchFileExtension);
  277. pseEditEntry->scriptData->SetScriptMap(pchScriptMap);
  278. m_lboxScriptMap.DeleteString(iCurSel); // Delete first so memory is freed
  279. iCurSel = m_lboxScriptMap.AddString(pseEditEntry->scriptData->GetDisplayString());
  280. // There error case on this is incredibly rare, so don't bother saving and restoring the above fields
  281. // Just don't set flags so registry is not updated.
  282. if ((iCurSel != LB_ERR) && (iCurSel != LB_ERRSPACE)) {
  283. m_lboxScriptMap.SetItemData(iCurSel,pseEditEntry->iListIndex);
  284. if (pseEditEntry->scriptData->PrevScriptMapExists())
  285. pseEditEntry->DeleteCurrent = TRUE;
  286. pseEditEntry->WriteNew = TRUE;
  287. bretcode = TRUE;
  288. }
  289. return (bretcode);
  290. }