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.

138 lines
4.1 KiB

  1. #include <windows.h>
  2. #include <regstr.h>
  3. #include "sdsutils.h"
  4. #define SETUP_INI "setup.ini"
  5. #define RENAMEFILES "RenameFiles"
  6. #define DELETEFILES "DeleteFiles"
  7. #define RECONVRENAMEFILES "PreConvRenameFiles"
  8. // REGSTR_PATH_SETUP = Software\Microsoft\Windows\CurrentVersion
  9. BOOL CheckGrpconvRegkey(LPSTR lpSubKey)
  10. {
  11. BOOL bRunGrpConv = FALSE;
  12. char szKey[MAX_PATH];
  13. char szFile[MAX_PATH];
  14. char szName[MAX_PATH];
  15. char szData[MAX_PATH];
  16. char *pTemp;
  17. char *pSep;
  18. HKEY hKey;
  19. HKEY hSubKey;
  20. DWORD dwKeyIndex = 0;
  21. DWORD dwFileIndex = 0;
  22. DWORD dwSize;
  23. DWORD dwNameSize;
  24. DWORD dwDataSize;
  25. DWORD dwAttrib;
  26. lstrcpy(szKey, REGSTR_PATH_SETUP);
  27. AddPath(szKey, lpSubKey);
  28. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  29. {
  30. while (!bRunGrpConv &&
  31. (RegEnumKey(hKey, dwKeyIndex, szKey, sizeof(szKey)) == ERROR_SUCCESS))
  32. {
  33. dwSize = sizeof(szFile);
  34. if ((RegOpenKeyEx(hKey, szKey, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) &&
  35. (ERROR_SUCCESS == RegQueryValueEx(hSubKey, NULL, NULL, NULL, (LPBYTE) szFile, &dwSize)))
  36. {
  37. // szFile contains now the path.
  38. pTemp = szFile + lstrlen(szFile);
  39. dwFileIndex = 0;
  40. dwNameSize = sizeof(szName);
  41. dwDataSize = sizeof(szData);
  42. while (!bRunGrpConv &&
  43. (RegEnumValue(hSubKey, dwFileIndex, szName, &dwNameSize, NULL, NULL,
  44. szData, &dwDataSize) == ERROR_SUCCESS) )
  45. {
  46. if (dwNameSize)
  47. {
  48. *pTemp = '\0';
  49. AddPath(szFile, szName);
  50. dwAttrib = GetFileAttributes(szFile);
  51. if (dwAttrib != (DWORD)-1)
  52. {
  53. // we have to check the data to see if this entry was processed
  54. pSep = ANSIStrChr(szData, ',');
  55. if (pSep)
  56. {
  57. *pSep = '\0';
  58. pSep++;
  59. bRunGrpConv = !(dwAttrib & (DWORD)AtoL(pSep));
  60. }
  61. else
  62. bRunGrpConv = TRUE;
  63. }
  64. }
  65. dwNameSize = sizeof(szName);
  66. dwDataSize = sizeof(szData);
  67. dwFileIndex++;
  68. }
  69. RegCloseKey(hSubKey);
  70. }
  71. dwKeyIndex++;
  72. }
  73. RegCloseKey(hKey);
  74. }
  75. return bRunGrpConv;
  76. }
  77. #if 0
  78. BOOL IsNT5orHigher()
  79. {
  80. OSVERSIONINFO verinfo;
  81. BOOL bRet = FALSE;
  82. verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  83. if (GetVersionEx(&verinfo))
  84. {
  85. if ((verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && (verinfo.dwMajorVersion >= 5))
  86. {
  87. bRet = TRUE;
  88. }
  89. }
  90. return bRet;
  91. }
  92. #endif
  93. BOOL NeedToRunGrpconv()
  94. {
  95. BOOL bRunGrpConv = FALSE;
  96. char szTemp[MAX_PATH];
  97. // check if grpconv -o needs to be run.
  98. // a) setup.ini in the windows directory exists
  99. // b) HKLM\Software\Microsoft\Windows\CurrentVersion\RenameFiles exist
  100. // c) HKLM\Software\Microsoft\Windows\CurrentVersion\DeleteFiles exist
  101. GetWindowsDirectory(szTemp, sizeof(szTemp));
  102. AddPath(szTemp, SETUP_INI);
  103. bRunGrpConv = (GetFileAttributes(szTemp) != (DWORD)-1);
  104. if (!bRunGrpConv)
  105. {
  106. // need check user profile directory
  107. if (ExpandEnvironmentStrings("%USERPROFILE%", szTemp, sizeof(szTemp)))
  108. {
  109. AddPath(szTemp, SETUP_INI);
  110. bRunGrpConv = (GetFileAttributes(szTemp) != (DWORD)-1);
  111. }
  112. }
  113. if (!bRunGrpConv)
  114. {
  115. bRunGrpConv = CheckGrpconvRegkey(RENAMEFILES);
  116. }
  117. if (!bRunGrpConv)
  118. {
  119. bRunGrpConv = CheckGrpconvRegkey(DELETEFILES);
  120. }
  121. if (!bRunGrpConv)
  122. {
  123. bRunGrpConv = CheckGrpconvRegkey(RECONVRENAMEFILES);
  124. }
  125. return bRunGrpConv;
  126. }