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.

156 lines
5.1 KiB

  1. //
  2. // PROGRAMS.CPP
  3. //
  4. #include "precomp.h"
  5. static BOOL importProgramsHelper(LPCTSTR pcszInsFile, LPCTSTR pcszWorkDir, BOOL fImport);
  6. BOOL WINAPI ImportProgramsA(LPCSTR pcszInsFile, LPCSTR pcszWorkDir, BOOL fImport)
  7. {
  8. USES_CONVERSION;
  9. return importProgramsHelper(A2CT(pcszInsFile), A2CT(pcszWorkDir), fImport);
  10. }
  11. BOOL WINAPI ImportProgramsW(LPCWSTR pcwszInsFile, LPCWSTR pcwszWorkDir, BOOL fImport)
  12. {
  13. USES_CONVERSION;
  14. return importProgramsHelper(W2CT(pcwszInsFile), W2CT(pcwszWorkDir), fImport);
  15. }
  16. void ExportProgram(HKEY hkClientKey, HANDLE hFile, LPCTSTR pcszProgramType)
  17. {
  18. HKEY hk;
  19. TCHAR szKey[MAX_PATH];
  20. PathCombine(szKey, RK_CLIENT, pcszProgramType);
  21. if (SHOpenKey(hkClientKey, pcszProgramType, KEY_READ, &hk) == ERROR_SUCCESS)
  22. ExportRegValue2Inf(hk, NULL, TEXT("HKLM"), szKey, hFile);
  23. }
  24. void ExportHTMLEditor(HANDLE hFile, BOOL fHKLM)
  25. {
  26. HKEY hk;
  27. DWORD dwIndex, dwSize;
  28. TCHAR szSubKey[MAX_PATH];
  29. if (fHKLM)
  30. {
  31. if (SHOpenKeyHKLM(RK_HTMLEDIT, KEY_DEFAULT_ACCESS, &hk) != ERROR_SUCCESS)
  32. return;
  33. }
  34. else
  35. {
  36. if (SHOpenKeyHKCU(RK_HTMLEDIT, KEY_DEFAULT_ACCESS, &hk) != ERROR_SUCCESS)
  37. return;
  38. }
  39. // this value is needed for the edit button and menu item in IE
  40. ExportRegValue2Inf(hk, TEXT("Description"), fHKLM ? TEXT("HKLM") : TEXT("HKCU"), RK_HTMLEDIT, hFile);
  41. dwIndex = 0;
  42. dwSize = ARRAYSIZE(szSubKey);
  43. while (RegEnumKeyEx(hk, dwIndex, szSubKey, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
  44. {
  45. HKEY hkSub;
  46. TCHAR szKey[MAX_PATH];
  47. PathCombine(szKey, RK_HTMLEDIT, szSubKey);
  48. if (SHOpenKey(hk, szSubKey, KEY_DEFAULT_ACCESS, &hkSub) == ERROR_SUCCESS)
  49. ExportRegTree2Inf(hkSub, fHKLM ? TEXT("HKLM") : TEXT("HKCU"), szKey, hFile, TRUE);
  50. dwSize = ARRAYSIZE(szSubKey);
  51. dwIndex++;
  52. }
  53. }
  54. static BOOL importProgramsHelper(LPCTSTR pcszInsFile, LPCTSTR pcszWorkDir, BOOL fImport)
  55. {
  56. HANDLE hFile;
  57. TCHAR szProgramsFile[MAX_PATH];
  58. // clear out extreginf entry
  59. WritePrivateProfileString(EXTREGINF, IK_PROGRAMS, NULL, pcszInsFile);
  60. WritePrivateProfileString(IS_EXTREGINF_HKLM, IK_PROGRAMS, NULL, pcszInsFile);
  61. WritePrivateProfileString(IS_EXTREGINF_HKCU, IK_PROGRAMS, NULL, pcszInsFile);
  62. // clear any old inf out of working dir
  63. PathCombine(szProgramsFile, pcszWorkDir, TEXT("programs.inf"));
  64. DeleteFile(szProgramsFile);
  65. if (!fImport)
  66. return TRUE;
  67. if ((hFile = CreateNewFile(szProgramsFile)) != INVALID_HANDLE_VALUE)
  68. {
  69. TCHAR szBuf[MAX_PATH];
  70. HKEY hkPrograms;
  71. WriteStringToFile(hFile, (LPCVOID) PROGRAMS_INF_ADD, StrLen(PROGRAMS_INF_ADD));
  72. // do HKLM stuff first
  73. // export all defaults except for HTML editor which is in a different place
  74. if (SHOpenKeyHKLM(RK_CLIENT, KEY_READ, &hkPrograms) == ERROR_SUCCESS)
  75. {
  76. ExportProgram(hkPrograms, hFile, TEXT("Calendar"));
  77. ExportProgram(hkPrograms, hFile, TEXT("Contacts"));
  78. ExportProgram(hkPrograms, hFile, TEXT("Internet Call"));
  79. ExportProgram(hkPrograms, hFile, TEXT("Mail"));
  80. ExportProgram(hkPrograms, hFile, TEXT("News"));
  81. RegCloseKey(hkPrograms);
  82. }
  83. // need to look in both HKCU AND HKLM for html editor info
  84. ExportHTMLEditor(hFile, TRUE);
  85. // need to export mailto: protocol stuff in HKCR
  86. if (SHOpenKeyHKCR(TEXT("mailto"), KEY_READ, &hkPrograms) == ERROR_SUCCESS)
  87. {
  88. ExportRegTree2Inf(hkPrograms, TEXT("HKCR"), TEXT("mailto"), hFile, TRUE);
  89. RegCloseKey(hkPrograms);
  90. }
  91. // now do HKCU stuff
  92. WriteStringToFile(hFile, INF_IEAKADDREG_HKCU, StrLen(INF_IEAKADDREG_HKCU));
  93. // whether or not to check if IE is default browser value
  94. if (SHOpenKeyHKCU(RK_IE_MAIN, KEY_READ, &hkPrograms) == ERROR_SUCCESS)
  95. {
  96. ExportRegValue2Inf(hkPrograms, TEXT("Check_Associations"), TEXT("HKCU"), RK_IE_MAIN,
  97. hFile);
  98. RegCloseKey(hkPrograms);
  99. }
  100. ExportHTMLEditor(hFile, FALSE);
  101. CloseHandle(hFile);
  102. wnsprintf(szBuf, ARRAYSIZE(szBuf), TEXT("*,%s,DefaultInstall"), PathFindFileName(szProgramsFile));
  103. WritePrivateProfileString(EXTREGINF, IK_PROGRAMS, szBuf, pcszInsFile);
  104. if (!InsIsSectionEmpty(IS_IEAKADDREG_HKLM, szProgramsFile))
  105. {
  106. wnsprintf(szBuf, ARRAYSIZE(szBuf), TEXT("*,%s,IEAKInstall.HKLM"), PathFindFileName(szProgramsFile));
  107. WritePrivateProfileString(IS_EXTREGINF_HKLM, IK_PROGRAMS, szBuf, pcszInsFile);
  108. }
  109. if (!InsIsSectionEmpty(IS_IEAKADDREG_HKCU, szProgramsFile))
  110. {
  111. wnsprintf(szBuf, ARRAYSIZE(szBuf), TEXT("*,%s,IEAKInstall.HKCU"), PathFindFileName(szProgramsFile));
  112. WritePrivateProfileString(IS_EXTREGINF_HKCU, IK_PROGRAMS, szBuf, pcszInsFile);
  113. }
  114. return TRUE;
  115. }
  116. return FALSE;
  117. }