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.

276 lines
7.3 KiB

  1. #include <windows.h>
  2. #include "RegEdit.h"
  3. #ifndef DBCS
  4. #define AnsiNext(x) ((x)+1)
  5. #endif
  6. #define NUMACTIONS (ID_LASTACTIONRADIO-ID_FIRSTACTIONRADIO+1)
  7. #define EDITSPERACTION (ID_LASTEDIT-ID_FIRSTACTIONEDIT+1)
  8. #define OFFSET_COMMAND 0
  9. #define OFFSET_FIRSTDDE 1
  10. #define OFFSET_DDEEXEC 1
  11. #define OFFSET_DDEIFEXEC 2
  12. #define OFFSET_DDEAPP 3
  13. #define OFFSET_DDETOPIC 4
  14. #define BLOCKLEN 100
  15. char szNull[] = "";
  16. static char szShell[] = "shell";
  17. static char szCommand[] = "command";
  18. static char szDDEExec[] = "ddeexec";
  19. static char szDDEIfExec[] = "ddeexec\\ifexec";
  20. static char szDDEApplication[] = "ddeexec\\application";
  21. static char szDDETopic[] = "ddeexec\\topic";
  22. static char *ppCommands[] = {
  23. szCommand, szDDEExec, szDDEIfExec, szDDEApplication, szDDETopic
  24. } ;
  25. static char szOpen[] = "open";
  26. static char szPrint[] = "print";
  27. static char *ppActionIds[] = {
  28. szOpen, szPrint
  29. } ;
  30. static char szSystem[] = "System";
  31. char cUsesDDE[NUMACTIONS];
  32. HANDLE *pLocalVals = NULL;
  33. WORD NEAR PASCAL CreateId(HANDLE hId)
  34. {
  35. HKEY hKeyNew;
  36. PSTR pId, pTemp;
  37. WORD wErrMsg = IDS_INVALIDID;
  38. pId = LocalLock(hId);
  39. if(!*pId || *pId=='.')
  40. goto Error1;
  41. for(pTemp=pId; *pTemp; ++pTemp)
  42. /* this excludes '\\' and all other chars except 33-127 */
  43. if(*pTemp=='\\' || *pTemp<=' ')
  44. goto Error1;
  45. wErrMsg = IDS_EXISTS;
  46. if(RegOpenKey(HKEY_CLASSES_ROOT, pId, &hKeyNew) == ERROR_SUCCESS)
  47. goto Error2;
  48. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(HKEY_CLASSES_ROOT, pId, &hKeyNew)))
  49. goto Error1;
  50. wErrMsg = NULL;
  51. Error2:
  52. RegCloseKey(hKeyNew);
  53. Error1:
  54. LocalUnlock(hId);
  55. return(wErrMsg);
  56. }
  57. WORD NEAR PASCAL MyGetClassName(HANDLE hId, HANDLE *hName)
  58. {
  59. WORD wErrMsg;
  60. wErrMsg = GetErrMsg((WORD)MyQueryValue(HKEY_CLASSES_ROOT, LocalLock(hId),
  61. hName));
  62. LocalUnlock(hId);
  63. return(wErrMsg);
  64. }
  65. WORD NEAR PASCAL DeleteClassId(HANDLE hId)
  66. {
  67. WORD wErrMsg;
  68. wErrMsg = GetErrMsg((WORD)RegDeleteKey(HKEY_CLASSES_ROOT, LocalLock(hId)));
  69. LocalUnlock(hId);
  70. return(wErrMsg);
  71. }
  72. WORD NEAR PASCAL MergeData(HWND hWndName, HANDLE hId)
  73. {
  74. HANDLE hName;
  75. HANDLE *phTemp;
  76. WORD wErrMsg = IDS_OUTOFMEMORY;
  77. HKEY hKeyId, hKeyShell, hKeyAction;
  78. int i, j;
  79. if(!(hName=GetEditString(hWndName)))
  80. goto Error2;
  81. if(wErrMsg=GetErrMsg((WORD)RegOpenKey(HKEY_CLASSES_ROOT, LocalLock(hId),
  82. &hKeyId)))
  83. goto Error3;
  84. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(hKeyId, szShell, &hKeyShell)))
  85. goto Error4;
  86. if(wErrMsg=GetErrMsg((WORD)RegSetValue(hKeyId, szNull, (DWORD)REG_SZ,
  87. LocalLock(hName), 0L)))
  88. goto Error5;
  89. for(i=0, phTemp=pLocalVals; i<NUMACTIONS; ++i) {
  90. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(hKeyShell, ppActionIds[i],
  91. &hKeyAction)))
  92. goto Error5;
  93. for(j=0; j<EDITSPERACTION; ++j, ++phTemp) {
  94. if(*phTemp && (j<OFFSET_FIRSTDDE || cUsesDDE[i])) {
  95. PSTR pTemp;
  96. pTemp = LocalLock(*phTemp);
  97. if((j==OFFSET_DDETOPIC && !lstrcmpi(pTemp, szSystem)) ||
  98. (j==OFFSET_DDEAPP && !lstrcmpi(pTemp,
  99. GetAppName(*(phTemp+OFFSET_COMMAND-OFFSET_DDEAPP)))))
  100. RegDeleteKey(hKeyAction, ppCommands[j]);
  101. else
  102. wErrMsg = GetErrMsg((WORD)RegSetValue(hKeyAction, ppCommands[j],
  103. (DWORD)REG_SZ, pTemp, 0L));
  104. LocalUnlock(*phTemp);
  105. if(wErrMsg)
  106. goto Error5;
  107. } else {
  108. RegDeleteKey(hKeyAction, ppCommands[j]);
  109. }
  110. }
  111. RegCloseKey(hKeyAction);
  112. }
  113. wErrMsg = NULL;
  114. Error5:
  115. LocalUnlock(hName);
  116. RegCloseKey(hKeyShell);
  117. Error4:
  118. RegCloseKey(hKeyId);
  119. Error3:
  120. LocalUnlock(hId);
  121. LocalFree(hName);
  122. Error2:
  123. return(wErrMsg);
  124. }
  125. WORD NEAR PASCAL ResetClassList(HWND hWndIdList, HWND hWndNameList)
  126. {
  127. HANDLE hClassId, hClassName;
  128. HKEY hKeyClasses;
  129. int i;
  130. WORD wErrMsg;
  131. /* Reset the name list */
  132. SendMessage(hWndIdList, LB_RESETCONTENT, 0, 0L);
  133. SendMessage(hWndNameList, LB_RESETCONTENT, 0, 0L);
  134. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(HKEY_CLASSES_ROOT, szNull,
  135. &hKeyClasses)))
  136. goto Error1;
  137. for(i=0; MyEnumKey(hKeyClasses, i, &hClassId)==ERROR_SUCCESS && !wErrMsg;
  138. ++i) {
  139. int nId;
  140. PSTR pClassId;
  141. pClassId = LocalLock(hClassId);
  142. if(*pClassId=='.' || (wErrMsg=MyGetClassName(hClassId, &hClassName)))
  143. goto Error2;
  144. wErrMsg = IDS_OUTOFMEMORY;
  145. if((nId=(int)SendMessage(hWndNameList, LB_ADDSTRING, 0,
  146. (DWORD)((LPSTR)LocalLock(hClassName))))==LB_ERR
  147. || SendMessage(hWndIdList, LB_INSERTSTRING, nId,
  148. (DWORD)((LPSTR)pClassId))==LB_ERR)
  149. goto Error3;
  150. wErrMsg = NULL;
  151. Error3:
  152. LocalUnlock(hClassName);
  153. LocalFree(hClassName);
  154. Error2:
  155. LocalUnlock(hClassId);
  156. LocalFree(hClassId);
  157. }
  158. SendMessage(hWndNameList, LB_SETTOPINDEX, 0, 0L);
  159. SendMessage(hWndNameList, LB_SETCURSEL, 0, 0L);
  160. RegCloseKey(hKeyClasses);
  161. Error1:
  162. return(wErrMsg);
  163. }
  164. WORD NEAR PASCAL GetLocalCopies(HWND hWndName, HANDLE hId)
  165. {
  166. HKEY hKeyId, hKeyShell, hSubKey;
  167. HANDLE hName, *phTemp;
  168. WORD wErrMsg = IDS_OUTOFMEMORY;
  169. int i, j;
  170. if(!pLocalVals) {
  171. HANDLE hLocalVals;
  172. if(!(hLocalVals=LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
  173. NUMACTIONS*EDITSPERACTION*sizeof(HANDLE)))
  174. || !(pLocalVals=(HANDLE *)LocalLock(hLocalVals)))
  175. goto Error1;
  176. }
  177. for(i=0, phTemp=pLocalVals; i<NUMACTIONS; ++i) {
  178. cUsesDDE[i] = 0;
  179. for(j=0; j<EDITSPERACTION; ++j, ++phTemp) {
  180. if(*phTemp) {
  181. LocalFree(*phTemp);
  182. *phTemp = NULL;
  183. }
  184. }
  185. }
  186. SendMessage(hWndName, WM_SETTEXT, 0, (DWORD)((LPSTR)szNull));
  187. if(!hId)
  188. return(NULL);
  189. if(wErrMsg=GetErrMsg((WORD)RegOpenKey(HKEY_CLASSES_ROOT, LocalLock(hId),
  190. &hKeyId)))
  191. goto Error3;
  192. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(hKeyId, szShell, &hKeyShell)))
  193. goto Error4;
  194. if(wErrMsg=GetErrMsg((WORD)MyQueryValue(hKeyId, szNull, &hName)))
  195. goto Error5;
  196. SendMessage(hWndName, WM_SETTEXT, 0, (DWORD)((LPSTR)LocalLock(hName)));
  197. LocalUnlock(hName);
  198. LocalFree(hName);
  199. for(i=0, phTemp=pLocalVals; i<NUMACTIONS; ++i) {
  200. if(wErrMsg=GetErrMsg((WORD)RegCreateKey(hKeyShell, ppActionIds[i],
  201. &hSubKey)))
  202. goto Error5;
  203. for(j=0; j<EDITSPERACTION; ++j, ++phTemp) {
  204. if((wErrMsg=(WORD)MyQueryValue(hSubKey, ppCommands[j], phTemp))
  205. !=(WORD)ERROR_BADKEY && (wErrMsg=GetErrMsg(wErrMsg)))
  206. goto Error5;
  207. if(j>=OFFSET_FIRSTDDE) {
  208. if(*phTemp)
  209. cUsesDDE[i] = 1;
  210. else if(j == OFFSET_DDETOPIC) {
  211. *phTemp = StringToLocalHandle(szSystem, LMEM_MOVEABLE);
  212. } else if(j == OFFSET_DDEAPP) {
  213. HANDLE hTemp;
  214. if(hTemp = *(phTemp-(OFFSET_DDEAPP+OFFSET_COMMAND)))
  215. *phTemp = StringToLocalHandle(GetAppName(hTemp),
  216. LMEM_MOVEABLE);
  217. }
  218. }
  219. }
  220. RegCloseKey(hSubKey);
  221. }
  222. wErrMsg = NULL;
  223. Error5:
  224. RegCloseKey(hKeyShell);
  225. Error4:
  226. RegCloseKey(hKeyId);
  227. Error3:
  228. LocalUnlock(hId);
  229. Error1:
  230. return(wErrMsg);
  231. }