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.

1976 lines
64 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: jpn.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * FEMGRATE, JPN speciific functions
  7. *
  8. \***************************************************************************/
  9. #include "femgrate.h"
  10. #include <tchar.h>
  11. BOOL FixSpecificFolder(HINF hInf)
  12. {
  13. BOOL bRet = FALSE;
  14. INFCONTEXT InfContext;
  15. UINT LineCount,LineNo;
  16. LPCTSTR szSectionName = TEXT("Folder.SpecificObjectToRename");
  17. LPCTSTR RegName;
  18. LPCTSTR NT4Name;
  19. LPCTSTR NT5Name;
  20. LPCTSTR MoveIt;
  21. TCHAR szUSFRegKey[MAX_PATH];
  22. TCHAR szNTUSF[MAX_PATH];
  23. TCHAR szExpNT4USF[MAX_PATH];
  24. TCHAR szExpNT5USF[MAX_PATH];
  25. DWORD dwSize, dwType;
  26. LONG lResult;
  27. UINT uiCount;
  28. HKEY hKey;
  29. if(hInf == INVALID_HANDLE_VALUE) {
  30. DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] Open femgrate.inf failed !\n")));
  31. return FALSE;
  32. }
  33. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  34. if((LONG)LineCount <= 0) {
  35. DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] line count == 0 !\n")));
  36. goto err1;
  37. }
  38. for(LineNo=0; LineNo<LineCount; LineNo++) {
  39. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  40. && (RegName = pSetupGetField(&InfContext,1))
  41. && (NT4Name = pSetupGetField(&InfContext,2))
  42. && (NT5Name = pSetupGetField(&InfContext,3))) {
  43. DebugMsg((DM_VERBOSE,TEXT("FixSpecificFolder: RegName = %s !\n"),RegName));
  44. DebugMsg((DM_VERBOSE,TEXT("FixSpecificFolder: NT4Name = %s !\n"),NT4Name));
  45. DebugMsg((DM_VERBOSE,TEXT("FixSpecificFolder: NT5Name = %s !\n"),NT5Name));
  46. //
  47. // Query for the user's current "Folder" location.
  48. //
  49. DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] FixUserFolder, [%d] !\n"),LineNo));
  50. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  51. USER_SHELL_FOLDER,
  52. 0,
  53. KEY_READ,
  54. &hKey);
  55. if (lResult != ERROR_SUCCESS) {
  56. DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] , Open User Shell Folders failed!\n")));
  57. continue;
  58. }
  59. lstrcpy(szUSFRegKey,RegName);
  60. dwSize = sizeof(szNTUSF);
  61. lResult = RegQueryValueEx (hKey,
  62. szUSFRegKey,
  63. NULL,
  64. &dwType,
  65. (LPBYTE) szNTUSF,
  66. &dwSize);
  67. DebugMsg((DM_VERBOSE,TEXT("FixSpecificFolder: Current Value (%s) = %s !\n"),szUSFRegKey,szNTUSF));
  68. if (lResult != ERROR_SUCCESS) {
  69. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] Query User Shell Folders failed!\n")));
  70. RegCloseKey (hKey);
  71. continue;
  72. }
  73. ExpandEnvironmentStrings (szNTUSF, szExpNT4USF, MAX_PATH);
  74. ExpandEnvironmentStrings (szNTUSF, szExpNT5USF, MAX_PATH);
  75. ConcatenatePaths(szExpNT4USF,NT4Name,MAX_PATH);
  76. ConcatenatePaths(szExpNT5USF,NT5Name,MAX_PATH);
  77. lResult = GetFileAttributes(szExpNT4USF);
  78. if (lResult == 0xFFFFFFFF) {
  79. //
  80. // Directory does not exist.
  81. //
  82. DebugMsg((DM_VERBOSE, TEXT("[FixSpecificFolder] - File is not existed [%s] !\n"),szExpNT4USF));
  83. } else if ((lResult & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
  84. //
  85. // this isn't a directory
  86. //
  87. DebugMsg((DM_VERBOSE, TEXT("[FixSpecificFolder] This is a directory [%s] !\n"),szExpNT4USF));
  88. } else if (MoveFile(szExpNT4USF, szExpNT5USF)) {
  89. DebugMsg((DM_VERBOSE, TEXT("[FixSpecificFolder] Move %s to %s OK !\n"),szExpNT4USF, szExpNT5USF));
  90. }
  91. else {
  92. DebugMsg((DM_VERBOSE, TEXT("[FixSpecificFolder] Failed to change folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF));
  93. }
  94. RegCloseKey (hKey);
  95. }
  96. }
  97. bRet = TRUE;
  98. err1:
  99. return bRet;
  100. }
  101. BOOL FixUserFolders(HINF hInf)
  102. {
  103. BOOL bRet = FALSE;
  104. INFCONTEXT InfContext;
  105. UINT LineCount,LineNo;
  106. LPCTSTR szSectionName = TEXT("Folder.ObjectToRename");
  107. LPCTSTR RegName;
  108. LPCTSTR NT4Name;
  109. LPCTSTR NT5Name;
  110. LPCTSTR MoveIt;
  111. TCHAR szUSFRegKey[MAX_PATH];
  112. TCHAR szNT4USF[MAX_PATH];
  113. TCHAR szExpNT4USF[MAX_PATH];
  114. TCHAR szExpNT5USF[MAX_PATH];
  115. DWORD dwSize, dwType;
  116. LONG lResult;
  117. UINT uiCount;
  118. HKEY hKey;
  119. if(hInf == INVALID_HANDLE_VALUE) {
  120. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] Open femgrate.inf failed !\n")));
  121. return FALSE;
  122. }
  123. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  124. if((LONG)LineCount <= 0) {
  125. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] line count == 0 !\n")));
  126. goto err1;
  127. }
  128. for(LineNo=0; LineNo<LineCount; LineNo++) {
  129. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  130. && (RegName = pSetupGetField(&InfContext,1))
  131. && (NT4Name = pSetupGetField(&InfContext,2))
  132. && (NT5Name = pSetupGetField(&InfContext,3))
  133. && (MoveIt = pSetupGetField(&InfContext,4))) {
  134. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: RegName = %s !\n"),RegName));
  135. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: NT4Name = %s !\n"),NT4Name));
  136. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: NT5Name = %s !\n"),NT5Name));
  137. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: MoveIt = %s !\n"),MoveIt));
  138. //
  139. // Query for the user's current "Folder" location.
  140. //
  141. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] FixUserFolder, [%d] !\n"),LineNo));
  142. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  143. USER_SHELL_FOLDER,
  144. 0,
  145. KEY_READ | KEY_WRITE,
  146. &hKey);
  147. if (lResult != ERROR_SUCCESS) {
  148. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] , Open User Shell Folders failed!\n")));
  149. continue;
  150. }
  151. lstrcpy(szUSFRegKey,RegName);
  152. dwSize = sizeof(szNT4USF);
  153. lResult = RegQueryValueEx (hKey,
  154. szUSFRegKey,
  155. NULL,
  156. &dwType,
  157. (LPBYTE) szNT4USF,
  158. &dwSize);
  159. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Current Value (%s) = %s !\n"),szUSFRegKey,szNT4USF));
  160. if (lResult != ERROR_SUCCESS) {
  161. DebugMsg((DM_VERBOSE,TEXT("[FixUserFolders] Query User Shell Folders failed!\n")));
  162. RegCloseKey (hKey);
  163. continue;
  164. }
  165. if (lstrcmpi(NT4Name, szNT4USF) != 0) {
  166. DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] NT4Name <> szFolder :\n%s\n"),szExpNT4USF));
  167. RegCloseKey (hKey);
  168. continue;
  169. }
  170. //
  171. // MoveIt == 1, we want move it to new folder
  172. // else, we just update registry
  173. //
  174. if (lstrcmp(MoveIt,TEXT("1")) == 0) {
  175. ExpandEnvironmentStrings (NT4Name, szExpNT4USF, MAX_PATH);
  176. ExpandEnvironmentStrings (NT5Name, szExpNT5USF, MAX_PATH);
  177. if (CopyProfileDirectory (szExpNT4USF, szExpNT5USF, CPD_IGNOREHIVE)) {
  178. DebugMsg((DM_VERBOSE, TEXT("Fix Folder: Successfully changed folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF));
  179. if (Delnode (szExpNT4USF)) {
  180. DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Successfully remove folder:\n%s\n"),szExpNT4USF));
  181. }
  182. else {
  183. DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Failed remove folder:\n%s\n"),szExpNT4USF));
  184. }
  185. }
  186. else {
  187. DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Failed to change folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF));
  188. }
  189. }
  190. //
  191. // Set CSIDL_PERSONAL to point to this directory.
  192. //
  193. lResult = RegSetValueEx (hKey, szUSFRegKey, 0, REG_EXPAND_SZ,
  194. (LPBYTE) NT5Name, (lstrlen(NT5Name) + 1) * sizeof(TCHAR));
  195. if (lResult != ERROR_SUCCESS) {
  196. DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Set Registry faile, %s,%s\n"),szUSFRegKey,NT5Name));
  197. }
  198. RegCloseKey (hKey);
  199. }
  200. }
  201. bRet = TRUE;
  202. err1:
  203. return bRet;
  204. }
  205. BOOL FixFoldersInSetup(HINF hInf,BOOL bCommonGroup)
  206. {
  207. BOOL bRet = FALSE;
  208. INFCONTEXT InfContext;
  209. UINT LineCount,LineNo;
  210. LPCTSTR szSectionName = TEXT("Folder.ObjectToRenameInSetup");
  211. LPCTSTR RegName;
  212. LPCTSTR NT4Name;
  213. LPCTSTR NT5Name;
  214. TCHAR szUSFRegKey[MAX_PATH];
  215. TCHAR szNT5USF[MAX_PATH];
  216. TCHAR szNT4USF[MAX_PATH];
  217. TCHAR szExpNT4USF[MAX_PATH];
  218. TCHAR szExpNT5USF[MAX_PATH];
  219. DWORD dwSize, dwType;
  220. LONG lResult;
  221. HKEY hKey;
  222. if(hInf == INVALID_HANDLE_VALUE) {
  223. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] Open femgrate.inf failed !\n")));
  224. return FALSE;
  225. }
  226. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  227. if((LONG)LineCount <= 0) {
  228. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] line count == 0 !\n")));
  229. goto err1;
  230. }
  231. for(LineNo=0; LineNo<LineCount; LineNo++) {
  232. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  233. && (RegName = pSetupGetField(&InfContext,1))
  234. && (NT4Name = pSetupGetField(&InfContext,2))
  235. && (NT5Name = pSetupGetField(&InfContext,3))) {
  236. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] Line# [%d] !\n"),LineNo));
  237. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] RegName = %s !\n"),RegName));
  238. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] NT4Name = %s !\n"),NT4Name));
  239. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] NT5Name = %s !\n"),NT5Name));
  240. //
  241. // Query for the user's current "Folder" location.
  242. //
  243. lResult = RegOpenKeyEx ((bCommonGroup ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER),
  244. USER_SHELL_FOLDER, 0, KEY_READ | KEY_WRITE, &hKey);
  245. if (lResult != ERROR_SUCCESS) {
  246. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] FixSpecialFolder, Open User Shell Folders failed!\n")));
  247. continue;
  248. }
  249. if (bCommonGroup) {
  250. lstrcpy (szUSFRegKey,TEXT("Common "));
  251. lstrcat (szUSFRegKey,RegName);
  252. } else {
  253. lstrcpy (szUSFRegKey,RegName);
  254. }
  255. dwSize = sizeof(szNT5USF);
  256. lResult = RegQueryValueEx (hKey,
  257. szUSFRegKey,
  258. NULL,
  259. &dwType,
  260. (LPBYTE) szNT5USF,
  261. &dwSize);
  262. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] Current Registry Value (%s) = %s !\n"),szUSFRegKey,szNT5USF));
  263. if (lResult != ERROR_SUCCESS) {
  264. DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] Query User Shell Folders failed!\n")));
  265. RegCloseKey(hKey);
  266. continue;
  267. }
  268. if (_tcsstr(szNT5USF,NT4Name)) {
  269. //
  270. // it means the value is still in SB
  271. //
  272. lstrcpy(szNT4USF,szNT5USF);
  273. if (ReplaceString(szNT4USF,NT4Name,NT5Name,szNT5USF)) {
  274. ExpandEnvironmentStrings (szNT4USF, szExpNT4USF, MAX_PATH);
  275. ExpandEnvironmentStrings (szNT5USF, szExpNT5USF, MAX_PATH);
  276. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] szExpNT4USF = %s\n"),szExpNT4USF));
  277. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] case 1 szExpNT5USF = %s\n"),szExpNT5USF));
  278. } else {
  279. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] case 1 The replace string got error \n")));
  280. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] %s\n %s\n %s\n%s\n"),szNT5USF,NT5Name,NT4Name,szNT4USF));
  281. }
  282. lResult = RegSetValueEx (hKey,
  283. szUSFRegKey,
  284. 0,
  285. REG_SZ,
  286. (LPBYTE) szNT5USF,
  287. (lstrlen(szNT5USF)+1)*sizeof(TCHAR));
  288. if (lResult == ERROR_SUCCESS) {
  289. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] set registry value %s = %s \n"),szUSFRegKey,szNT5USF));
  290. } else {
  291. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] failed set registry value %s = %s \n"),szUSFRegKey,szNT5USF));
  292. }
  293. } else {
  294. //
  295. // it means the value has been changed to DB
  296. //
  297. if (ReplaceString(szNT5USF,NT5Name,NT4Name,szNT4USF)) {
  298. ExpandEnvironmentStrings (szNT4USF, szExpNT4USF, MAX_PATH);
  299. ExpandEnvironmentStrings (szNT5USF, szExpNT5USF, MAX_PATH);
  300. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] case 2 szExpNT4USF = %s\n"),szExpNT4USF));
  301. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] case 2 szExpNT5USF = %s\n"),szExpNT5USF));
  302. } else {
  303. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] The replace string got error \n")));
  304. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] %s\n %s\n %s\n%s\n"),szNT5USF,NT5Name,NT4Name,szNT4USF));
  305. }
  306. }
  307. //
  308. // here is a bug in build before 2072 that the ACLS of "all users" has no read access to "everyone"
  309. //
  310. // The new created directory will inherit this attributes, and it caused access denied.
  311. //
  312. // so we apply old directory's ACL to new one
  313. //
  314. // this is compatibile with US version
  315. //
  316. if (bCommonGroup) {
  317. if (CreateSecurityDirectory(szExpNT4USF, szExpNT5USF)) {
  318. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] CreateSecurityDirectory %s %s OK \n"),szExpNT4USF, szExpNT5USF));
  319. } else {
  320. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] CreateSecurityDirectory %s %s Failed \n"),szExpNT4USF, szExpNT5USF));
  321. }
  322. }
  323. if (CopyProfileDirectory (szExpNT4USF, szExpNT5USF, CPD_IGNOREHIVE)) {
  324. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] Successfully copied folder\nFrom:%s\nTo :%s\n"),szExpNT4USF,szExpNT5USF));
  325. if (Delnode (szExpNT4USF)) {
  326. DebugMsg((DM_VERBOSE, TEXT("[FixFoldersInSetup] Successfully removed folder:%s\n"),szExpNT4USF));
  327. }
  328. else {
  329. DebugMsg((DM_VERBOSE, TEXT("Fix Folder: Failed remove folder:\n%s\n"),szExpNT4USF));
  330. }
  331. }
  332. else {
  333. DebugMsg((DM_VERBOSE, TEXT("Fix Folder: Failed to change folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF));
  334. }
  335. RegCloseKey (hKey);
  336. }
  337. }
  338. bRet = TRUE;
  339. err1:
  340. return bRet;
  341. }
  342. BOOL FixCommon(HINF hInf)
  343. {
  344. TCHAR szCommon[MAX_PATH];
  345. TCHAR szProgramFolderPath[MAX_PATH];
  346. TCHAR szExpProgramFolderPath[MAX_PATH];
  347. BOOL bRet = FALSE;
  348. HANDLE hFile;
  349. DWORD RequiredSize;
  350. WIN32_FIND_DATA fd;
  351. UINT nCommon, nFileName;
  352. LPTSTR lpTag, lpEnd, lpEnd2;
  353. //
  354. // Loop through all the program groups in the All Users profile
  355. // and remove the " (Common)" tag.
  356. //
  357. if(hInf == INVALID_HANDLE_VALUE) {
  358. DebugMsg((DM_VERBOSE,TEXT("[FixCommon] Open femgrate.inf failed !\n")));
  359. return FALSE;
  360. }
  361. if (! SetupGetLineText(NULL,
  362. hInf,
  363. TEXT("Misc"),
  364. TEXT("Common"),
  365. szCommon,
  366. sizeof(szCommon),
  367. &RequiredSize)) {
  368. goto err1;
  369. }
  370. nCommon = lstrlen(szCommon);
  371. GetProgramsDirectory(TRUE,szProgramFolderPath);
  372. ExpandEnvironmentStrings (szProgramFolderPath, szExpProgramFolderPath, MAX_PATH);
  373. lstrcpy(szProgramFolderPath,szExpProgramFolderPath);
  374. //
  375. // From here, szProgramFolderPath used for Folder name without "Common"
  376. //
  377. lpEnd = CheckSlash (szExpProgramFolderPath);
  378. lpEnd2 = CheckSlash (szProgramFolderPath);
  379. lstrcpy (lpEnd, c_szStarDotStar);
  380. hFile = FindFirstFile (szExpProgramFolderPath, &fd);
  381. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] Find %s\n"),szExpProgramFolderPath));
  382. if (hFile != INVALID_HANDLE_VALUE) {
  383. do {
  384. if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  385. nFileName = lstrlen (fd.cFileName);
  386. DebugMsg((DM_VERBOSE, TEXT("Find %s\n"),fd.cFileName));
  387. if (nFileName > nCommon) {
  388. lpTag = fd.cFileName + nFileName - nCommon;
  389. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] lpTag=%s szCommon=%s\n"),lpTag, szCommon));
  390. if (!lstrcmpi(lpTag, szCommon)) {
  391. lstrcpy (lpEnd, fd.cFileName);
  392. *lpTag = TEXT('\0');
  393. lstrcpy (lpEnd2, fd.cFileName);
  394. if (CopyProfileDirectory (szExpProgramFolderPath, szProgramFolderPath, CPD_IGNOREHIVE)) {
  395. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully changed group name:\n")));
  396. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath));
  397. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath));
  398. if (Delnode (szExpProgramFolderPath)) {
  399. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully remove folder:\n%s\n"),szExpProgramFolderPath));
  400. }
  401. else {
  402. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed remove folder:\n%s\n"),szExpProgramFolderPath));
  403. }
  404. } else {
  405. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed to change group name with error %d.\n"), GetLastError()));
  406. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath));
  407. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath));
  408. }
  409. }
  410. }
  411. }
  412. } while (FindNextFile(hFile, &fd));
  413. FindClose (hFile);
  414. }
  415. bRet = TRUE;
  416. err1:
  417. return bRet;
  418. }
  419. BOOL RenameLink(
  420. BOOL bCommonGroup,
  421. LPCTSTR ObjSrcName,
  422. LPCTSTR ObjDstName,
  423. LPCTSTR ObjPath)
  424. {
  425. TCHAR szSrcPath[MAX_PATH];
  426. TCHAR szDstPath[MAX_PATH];
  427. LONG lResult;
  428. BOOL bRet=FALSE;
  429. DebugMsg((DM_VERBOSE,TEXT("[RenameLink] \nOld = %s\nNew = %s\nPath = %s\n"),ObjSrcName,ObjDstName,ObjPath));
  430. if (!GetProgramsDirectory(bCommonGroup,szSrcPath))
  431. return bRet;
  432. if ( !GetProgramsDirectory(bCommonGroup,szDstPath))
  433. return bRet;
  434. if (ObjPath && *ObjPath) {
  435. ConcatenatePaths(szSrcPath,ObjPath,MAX_PATH);
  436. ConcatenatePaths(szDstPath,ObjPath,MAX_PATH);
  437. }
  438. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  439. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  440. lstrcat(szSrcPath,TEXT(".lnk"));
  441. lstrcat(szDstPath,TEXT(".lnk"));
  442. lResult = GetFileAttributes(szSrcPath);
  443. if (lResult == 0xFFFFFFFF) {
  444. //
  445. // Directory does not exist.
  446. //
  447. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] File is not existed [%s] !\n"),szSrcPath));
  448. goto err1;
  449. }
  450. if (lResult & FILE_ATTRIBUTE_DIRECTORY) {
  451. //
  452. // this is a directory, but we want a file.
  453. //
  454. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] This is a directory [%s] !\n"),szSrcPath));
  455. goto err1;
  456. }
  457. //
  458. // if destination file existed, it's not good !
  459. //
  460. lResult = GetFileAttributes(szDstPath);
  461. if (lResult == 0xFFFFFFFF) {
  462. if (MoveFile (szSrcPath, szDstPath)) {
  463. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Successfully changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  464. }
  465. else {
  466. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Failed to change link name with error %d.\n%s\n%s\n"), GetLastError(),szSrcPath,szDstPath));
  467. goto err1;
  468. }
  469. }
  470. else {
  471. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Destination file existed, maybe we don't want to overwrite ,%s\n"),szDstPath));
  472. goto err1;
  473. }
  474. bRet = TRUE;
  475. err1:
  476. return bRet;
  477. }
  478. BOOL RenameFolder(
  479. BOOL bCommonGroup,
  480. LPCTSTR ObjSrcName,
  481. LPCTSTR ObjDstName)
  482. {
  483. TCHAR szSrcPath[MAX_PATH];
  484. TCHAR szDstPath[MAX_PATH];
  485. LONG lResult;
  486. BOOL bRet=FALSE;
  487. DebugMsg((DM_VERBOSE,TEXT("[RenameFolder]\nOld = %s\nNew = %s\n"),ObjSrcName,ObjDstName));
  488. GetProgramsDirectory(bCommonGroup,szSrcPath);
  489. GetProgramsDirectory(bCommonGroup,szDstPath);
  490. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  491. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  492. lResult = GetFileAttributes(szSrcPath);
  493. if (lResult == 0xFFFFFFFF) {
  494. //
  495. // Directory does not exist.
  496. //
  497. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Directory is not existed [%s] !\n"),szSrcPath));
  498. goto err1;
  499. }
  500. if (!(lResult & FILE_ATTRIBUTE_DIRECTORY)) {
  501. //
  502. // this is not a directory.
  503. //
  504. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] This is not a directory [%s] !\n"),szSrcPath));
  505. goto err1;
  506. }
  507. if (CopyProfileDirectory (szSrcPath, szDstPath, CPD_IGNOREHIVE)) {
  508. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Successfully changed folder name:\n%s\n%s"),szSrcPath,szDstPath));
  509. if (! Delnode(szSrcPath)) {
  510. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) failed !"), szSrcPath));
  511. } else {
  512. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) successfully !"), szSrcPath));
  513. }
  514. }
  515. else {
  516. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Convert Folder: Failed to change group name with error %d\n.%s\n%s\n"), GetLastError(),szSrcPath,szDstPath));
  517. goto err1;
  518. }
  519. bRet = TRUE;
  520. err1:
  521. return bRet;
  522. }
  523. BOOL RenameProgramFolderOrLink(HINF hInf,BOOL bCommon)
  524. {
  525. BOOL bRet = FALSE;
  526. INFCONTEXT InfContext;
  527. UINT LineCount,LineNo;
  528. LPCTSTR szSectionName = TEXT("StartMenu.ObjectToRename");
  529. LPCTSTR ObjectType;
  530. LPCTSTR ObjectSrcName;
  531. LPCTSTR ObjectDstName;
  532. LPCTSTR ObjectPath;
  533. LPCTSTR GroupAttribute;
  534. BOOL CommonGroup;
  535. BOOL IsMenuItem;
  536. if(hInf == INVALID_HANDLE_VALUE) {
  537. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Open femgrate.inf failed !\n")));
  538. return FALSE;
  539. }
  540. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  541. if((LONG)LineCount <= 0) {
  542. goto err1;
  543. }
  544. for(LineNo=0; LineNo<LineCount; LineNo++) {
  545. if(SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  546. && (ObjectType = pSetupGetField(&InfContext,1))
  547. && (ObjectSrcName = pSetupGetField(&InfContext,2))
  548. && (ObjectDstName = pSetupGetField(&InfContext,3))
  549. && (GroupAttribute = pSetupGetField(&InfContext,5))) {
  550. ObjectPath = pSetupGetField(&InfContext,4);
  551. IsMenuItem = A2I(ObjectType);
  552. CommonGroup = A2I(GroupAttribute);
  553. if ((bCommon && (CommonGroup == 0)) ||
  554. (!bCommon && (CommonGroup == 1))) {
  555. // DebugMsg((DM_VERBOSE,TEXT("Eject this line(%d) .....................................\n"),LineNo));
  556. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  557. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  558. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  559. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  560. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  561. continue;
  562. }
  563. if (IsMenuItem) {
  564. // DebugMsg((DM_VERBOSE,TEXT("RenameLink (%d).....................................\n"),LineNo));
  565. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  566. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  567. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  568. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  569. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  570. RenameLink(bCommon,ObjectSrcName,ObjectDstName,ObjectPath);
  571. }
  572. else {
  573. // DebugMsg((DM_VERBOSE,TEXT("RenameFolder (%d) .....................................\n"),LineNo));
  574. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  575. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  576. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  577. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  578. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  579. RenameFolder(bCommon,ObjectSrcName,ObjectDstName);
  580. }
  581. }
  582. }
  583. bRet = TRUE;
  584. err1:
  585. return bRet;
  586. }
  587. //
  588. // Fix Sound scheme that originally is SB katana
  589. //
  590. BOOL MapSBtoDBKana(HINF hInf,LPCTSTR lpszSectionName,LPTSTR lpszSoundName)
  591. {
  592. LPCTSTR szSBKana,szDBKana;
  593. LONG LineCount,LineNo;
  594. DWORD dwSize,dwType;
  595. INFCONTEXT InfContext;
  596. if(hInf == INVALID_HANDLE_VALUE) {
  597. DebugMsg((DM_VERBOSE,TEXT("[MapSBtoDBKana] Open femgrate.inf failed !\n")));
  598. return FALSE;
  599. }
  600. LineCount = (UINT)SetupGetLineCount(hInf,lpszSectionName);
  601. if((LONG)LineCount <= 0) {
  602. DebugMsg((DM_VERBOSE,TEXT("[MapSBtoDBKana] line count == 0 !\n")));
  603. return FALSE;
  604. }
  605. for(LineNo=0; LineNo<LineCount; LineNo++) {
  606. if (SetupGetLineByIndex(hInf,lpszSectionName,LineNo,&InfContext)
  607. && (szSBKana = pSetupGetField(&InfContext,1))) {
  608. if (lstrcmpi(szSBKana,lpszSoundName) == 0) {
  609. if (szDBKana = pSetupGetField(&InfContext,2)) {
  610. lstrcpy(lpszSoundName,szDBKana);
  611. return TRUE;
  612. }
  613. else {
  614. //
  615. // inf error, no second data
  616. //
  617. return FALSE;
  618. }
  619. }
  620. }
  621. }
  622. return FALSE;
  623. }
  624. BOOL NameSubstitution(HINF hInf,LPTSTR lpszOrgName,LPTSTR lpszDir,LPTSTR lpszSection)
  625. {
  626. TCHAR szExpDir[MAX_PATH];
  627. LPTSTR lpszAnchor;
  628. TCHAR szOnlyName[MAX_PATH];
  629. if (_tcsstr(lpszOrgName,TEXT("\\"))) {
  630. if (ExpandEnvironmentStrings(lpszDir,szExpDir,MAX_PATH) == 0) {
  631. return FALSE;
  632. }
  633. _tcsupr(lpszOrgName);
  634. _tcsupr(szExpDir);
  635. lpszAnchor = _tcsstr(lpszOrgName,szExpDir);
  636. if ((lpszAnchor == NULL ) || (lpszAnchor != lpszOrgName)) {
  637. return FALSE;
  638. }
  639. lstrcpy(szOnlyName,lpszAnchor+lstrlen(szExpDir));
  640. DebugMsg((DM_VERBOSE,TEXT("We want to find %s !\n"),szOnlyName));
  641. if (MapSBtoDBKana(hInf,lpszSection,szOnlyName)) {
  642. lstrcpy(lpszAnchor+lstrlen(szExpDir),szOnlyName);
  643. return TRUE;
  644. }
  645. }
  646. else {
  647. if (MapSBtoDBKana(hInf,lpszSection,lpszOrgName)) {
  648. return TRUE;
  649. }
  650. }
  651. return FALSE;
  652. }
  653. BOOL EnumSoundSchemeApps(HKEY hKey,HINF hInf)
  654. {
  655. HKEY hSubKey;
  656. DWORD dwIndex;
  657. DWORD dwKeyNameSize;
  658. TCHAR szKeyName[MAX_PATH];
  659. DWORD dwSoundValue;
  660. TCHAR szSoundValue[MAX_PATH];
  661. LONG lResult;
  662. dwKeyNameSize = sizeof(szKeyName);
  663. for (dwIndex = 0;
  664. RegEnumKey(hKey, dwIndex, szKeyName, dwKeyNameSize) == ERROR_SUCCESS;
  665. dwIndex++) {
  666. lResult = RegOpenKey(hKey,
  667. szKeyName,
  668. &hSubKey);
  669. if (lResult == ERROR_SUCCESS) {
  670. EnumSoundSchemeApps(hSubKey,hInf);
  671. RegCloseKey(hSubKey);
  672. }
  673. }
  674. //
  675. // no sub-key, then just get the value
  676. //
  677. if (dwIndex == 0) {
  678. dwSoundValue = sizeof(szSoundValue);
  679. lResult = RegQueryValue(hKey,
  680. NULL,
  681. szSoundValue,
  682. &dwSoundValue);
  683. if (lResult == ERROR_SUCCESS) {
  684. if (szSoundValue[0]) {
  685. if (NameSubstitution(hInf,szSoundValue,TEXT("%SystemRoot%\\Media\\"),TEXT("Sound.Files"))) {
  686. RegSetValue(hKey,
  687. NULL,
  688. REG_SZ,
  689. szSoundValue,
  690. (lstrlen(szSoundValue)+1)*sizeof(TCHAR));
  691. }
  692. }
  693. }
  694. }
  695. return TRUE;
  696. }
  697. BOOL FixSoundRegValue(HINF hInf)
  698. {
  699. LONG lResult;
  700. BOOL bRet=FALSE;
  701. HKEY hKey;
  702. if(hInf == INVALID_HANDLE_VALUE) {
  703. DebugMsg((DM_VERBOSE,TEXT("[FixSoundRegValue] Open femgrate.inf failed !\n")));
  704. goto Err0;
  705. }
  706. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  707. REGSTR_PATH_APPS,
  708. 0,
  709. KEY_ALL_ACCESS,
  710. &hKey);
  711. if (lResult != ERROR_SUCCESS) {
  712. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  713. goto Err0;
  714. }
  715. EnumSoundSchemeApps(hKey,hInf);
  716. if (! DoInstallationFromSection(hInf, TEXT("Sound.Reg.Update"))) {
  717. DebugMsg((DM_VERBOSE,TEXT("[FixSoundRegValue] DoInstallationFromSection failed !\n")));
  718. goto Err1;
  719. }
  720. bRet = TRUE;
  721. Err1:
  722. RegCloseKey(hKey);
  723. Err0:
  724. return bRet;
  725. }
  726. //
  727. // Search the registry and find SB value then replace with DB value
  728. //
  729. BOOL FixSBKanaRegValue(HINF hInf)
  730. {
  731. LPCTSTR szRegRoot,szRegPath;
  732. LPCTSTR szRegSBVal,szRegDBVal;
  733. LPCTSTR szRegSBData,szRegDBData;
  734. LONG LineCount,LineNo;
  735. DWORD dwSize,dwType;
  736. INFCONTEXT InfContext;
  737. HKEY hKey,hKeyRoot;
  738. BOOL bOK;
  739. TCHAR szRegCurData[MAX_PATH];
  740. LONG lResult;
  741. LPCTSTR lpszSectionName = TEXT("Reg.UpdateIfExsit");
  742. if(hInf == INVALID_HANDLE_VALUE) {
  743. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Open femgrate.inf failed !\n")));
  744. return FALSE;
  745. }
  746. LineCount = (UINT)SetupGetLineCount(hInf,lpszSectionName);
  747. if((LONG)LineCount <= 0) {
  748. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] line count == 0 !\n")));
  749. return FALSE;
  750. }
  751. for(LineNo=0; LineNo<LineCount; LineNo++) {
  752. if (SetupGetLineByIndex(hInf,lpszSectionName,LineNo,&InfContext)
  753. && (szRegRoot = pSetupGetField(&InfContext,1))
  754. && (szRegPath = pSetupGetField(&InfContext,2))
  755. && (szRegSBData = pSetupGetField(&InfContext,4))
  756. && (szRegDBData = pSetupGetField(&InfContext,6))) {
  757. szRegSBVal = pSetupGetField(&InfContext,3);
  758. szRegDBVal = pSetupGetField(&InfContext,5);
  759. if (!LookUpStringInTable(InfRegSpecTohKey,szRegRoot,(PUINT)&hKeyRoot)) {
  760. continue;
  761. }
  762. lResult = RegOpenKeyEx( hKeyRoot,
  763. szRegPath,
  764. 0,
  765. KEY_READ | KEY_WRITE,
  766. &hKey);
  767. if (lResult != ERROR_SUCCESS) {
  768. continue;
  769. }
  770. dwSize = sizeof(szRegCurData);
  771. lResult = RegQueryValueEx (hKey,
  772. szRegSBVal,
  773. NULL,
  774. &dwType,
  775. (LPBYTE) szRegCurData,
  776. &dwSize);
  777. if (lResult != ERROR_SUCCESS) {
  778. goto Err1;
  779. }
  780. if ((dwType != REG_SZ) && (dwType != REG_EXPAND_SZ)) {
  781. goto Err1;
  782. }
  783. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] szRegPath = %s, old data = %s, SB data = %s!\n"),szRegPath,szRegCurData,szRegSBData));
  784. if (lstrcmp(szRegCurData,szRegSBData ) == 0) {
  785. #if 1
  786. lResult = RegSetValueEx (hKey,
  787. szRegSBVal,
  788. 0,
  789. dwType,
  790. (LPBYTE) szRegDBData,
  791. (lstrlen(szRegDBData)+1) * sizeof (TCHAR));
  792. #endif
  793. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Set reg value %s,%s,%s!\n"),szRegPath,szRegSBVal,szRegDBData));
  794. if (lResult != ERROR_SUCCESS) {
  795. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Set reg value error %s,%s == 0 !\n"),szRegSBVal,szRegDBData));
  796. }
  797. } else {
  798. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] szRegPath = %s, old data = %s, SB data = %s , comparing result is different !\n"),szRegPath,szRegCurData,szRegSBData));
  799. }
  800. Err1:
  801. RegCloseKey(hKey);
  802. }
  803. }
  804. return TRUE;
  805. }
  806. //
  807. // Fix Patterns
  808. //
  809. BOOL FixPatterns(HINF hInf)
  810. {
  811. LONG lResult;
  812. BOOL bRet=FALSE;
  813. HKEY hKey;
  814. LONG LineNo,LineCount;
  815. LPCTSTR pszOldValName;
  816. LPCTSTR pszNewValName;
  817. LPCTSTR szSectionName = TEXT("Patterns");
  818. INFCONTEXT InfContext;
  819. if(hInf == INVALID_HANDLE_VALUE) {
  820. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Open femgrate.inf failed !\n")));
  821. goto Err0;
  822. }
  823. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  824. TEXT("Control Panel\\Patterns"),
  825. 0,
  826. KEY_ALL_ACCESS,
  827. &hKey);
  828. if (lResult != ERROR_SUCCESS) {
  829. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Open Control Panel\\Patterns failed !\n")));
  830. goto Err0;
  831. }
  832. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  833. if((LONG)LineCount <= 0) {
  834. goto Err1;
  835. }
  836. for(LineNo=0; LineNo<LineCount; LineNo++) {
  837. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  838. && (pszOldValName = pSetupGetField(&InfContext,1))
  839. && (pszNewValName = pSetupGetField(&InfContext,2))) {
  840. if (RegReplaceIfExisting(hKey,pszOldValName,pszNewValName)) {
  841. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Replace pattern %s with %s OK !\n"),pszOldValName,pszNewValName));
  842. } else {
  843. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Replace pattern %s with %s Failed !\n"),pszOldValName,pszNewValName));
  844. }
  845. }
  846. }
  847. bRet = TRUE;
  848. Err1:
  849. RegCloseKey(hKey);
  850. Err0:
  851. return bRet;
  852. }
  853. //
  854. // FixCurrentWallPaperInDeskTop
  855. //
  856. BOOL FixCurrentWallPaperInDeskTop(HINF hInf)
  857. {
  858. HKEY hKey;
  859. LONG lResult;
  860. DWORD dwType,dwSize;
  861. TCHAR szData[MAX_PATH];
  862. BOOL bRet = FALSE;
  863. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  864. TEXT("Control Panel\\Desktop"),
  865. 0,
  866. KEY_READ | KEY_WRITE,
  867. &hKey);
  868. if (lResult != ERROR_SUCCESS) {
  869. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] , Open Control Panel\\Desktop failed!\n")));
  870. goto Err0;
  871. }
  872. dwSize = sizeof(szData);
  873. lResult = RegQueryValueEx (hKey,
  874. TEXT("Wallpaper"),
  875. NULL,
  876. &dwType,
  877. (LPBYTE) szData,
  878. &dwSize);
  879. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop: Current WallPaperValue is %s !\n"),szData));
  880. if (lResult != ERROR_SUCCESS) {
  881. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] Query Current WallPaperValue failed!\n")));
  882. goto Err1;
  883. }
  884. if (NameSubstitution(hInf,szData,TEXT("%systemroot%\\"),TEXT("WallPaper.Reg"))) {
  885. lResult = RegSetValueEx(hKey,
  886. TEXT("Wallpaper"),
  887. 0,
  888. REG_SZ,
  889. (LPBYTE) szData,
  890. (lstrlen(szData) + 1) * sizeof(TCHAR));
  891. if (lResult != ERROR_SUCCESS) {
  892. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] RegSetValue WallPaperValue failed!\n")));
  893. goto Err1;
  894. }
  895. }
  896. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] Current WallPaper has been changed to %s!\n"),szData));
  897. bRet = TRUE;
  898. Err1:
  899. RegCloseKey(hKey);
  900. Err0:
  901. return bRet;
  902. }
  903. //
  904. // FixAppearanceScheme
  905. //
  906. BOOL FixAppearanceScheme(HINF hInf)
  907. {
  908. HKEY hAppearanceKey,hSchemeKey;
  909. LONG lResult;
  910. LPCTSTR szSectionName = TEXT("Apperance Scheme");
  911. TCHAR szCurrentScheme[MAX_PATH];
  912. LPCTSTR NT4SchemeName;
  913. LPCTSTR NT5SchemeName;
  914. LONG LineCount,LineNo;
  915. DWORD dwSize,dwType;
  916. INFCONTEXT InfContext;
  917. BOOL bRet = FALSE;
  918. if(hInf == INVALID_HANDLE_VALUE) {
  919. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open femgrate.inf failed !\n")));
  920. goto Err0;
  921. }
  922. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  923. REGSTR_PATH_APPEARANCE,
  924. 0,
  925. KEY_ALL_ACCESS,
  926. &hAppearanceKey);
  927. if (lResult != ERROR_SUCCESS) {
  928. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  929. goto Err0;
  930. }
  931. //
  932. // Now query for the programs directory
  933. //
  934. dwSize = MAX_PATH * sizeof(TCHAR);
  935. szCurrentScheme[0] = TEXT('\0');
  936. lResult = RegQueryValueEx (hAppearanceKey,
  937. TEXT("Current"),
  938. NULL,
  939. &dwType,
  940. (LPBYTE) szCurrentScheme,
  941. &dwSize);
  942. if (lResult != ERROR_SUCCESS) {
  943. //
  944. // this case is fine
  945. //
  946. szCurrentScheme[0] = TEXT('\0');
  947. }
  948. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  949. REGSTR_PATH_LOOKSCHEMES,
  950. 0,
  951. KEY_ALL_ACCESS,
  952. &hSchemeKey);
  953. if (lResult != ERROR_SUCCESS) {
  954. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  955. goto Err1;
  956. }
  957. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  958. if((LONG)LineCount <= 0) {
  959. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] line count == 0 !\n")));
  960. goto Err2;
  961. }
  962. for(LineNo=0; LineNo<LineCount; LineNo++) {
  963. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  964. && (NT4SchemeName = pSetupGetField(&InfContext,1))) {
  965. if (szCurrentScheme[0] != '\0') {
  966. if (lstrcmp(szCurrentScheme,NT4SchemeName) == 0) {
  967. if (NT5SchemeName = pSetupGetField(&InfContext,2)) {
  968. lResult = RegSetValueEx(hAppearanceKey,
  969. TEXT("Current"),
  970. 0,
  971. REG_SZ,
  972. (LPBYTE) NT5SchemeName,
  973. (lstrlen(NT5SchemeName)+1)*sizeof(TCHAR));
  974. if (lResult != ERROR_SUCCESS) {
  975. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Set Appearance current scheme fail ! \n")));
  976. }
  977. }
  978. else {
  979. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] NT5's scheme missed!\n")));
  980. }
  981. }
  982. }
  983. lResult = RegDeleteValue(hSchemeKey,
  984. NT4SchemeName);
  985. if (lResult != ERROR_SUCCESS) {
  986. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] ----------------------- Delete scheme [%d], %s failed !\n"),LineNo,NT4SchemeName));
  987. } else {
  988. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] ----------------------- Delete scheme [%d], %s OK !\n"),LineNo,NT4SchemeName));
  989. }
  990. }
  991. }
  992. bRet = TRUE;
  993. Err2:
  994. RegCloseKey(hSchemeKey);
  995. Err1:
  996. RegCloseKey(hAppearanceKey);
  997. Err0:
  998. return bRet;
  999. }
  1000. //
  1001. //ntbug#113976,#113007
  1002. //
  1003. // SB section in win.ini and entpack.ini
  1004. //
  1005. // replace SB section name with DB section name
  1006. //
  1007. BOOL FixSBIniSectionWithDBIniSection(HINF hInf)
  1008. {
  1009. LONG lResult;
  1010. LPCTSTR szSectionName = TEXT("INISectionRename");
  1011. LONG LineCount,LineNo;
  1012. DWORD dwSize,dwType;
  1013. INFCONTEXT InfContext;
  1014. LPCTSTR pszIniFile,pszSBName,pszDBName;
  1015. BOOL bRet = FALSE;
  1016. if(hInf == INVALID_HANDLE_VALUE) {
  1017. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] Open femgrate.inf failed !\n")));
  1018. goto Err0;
  1019. }
  1020. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1021. if((LONG)LineCount <= 0) {
  1022. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] line count == 0 !\n")));
  1023. goto Err0;
  1024. }
  1025. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1026. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext) &&
  1027. (pszIniFile = pSetupGetField(&InfContext,1)) &&
  1028. (pszSBName = pSetupGetField(&InfContext,2)) &&
  1029. (pszDBName = pSetupGetField(&InfContext,3))) {
  1030. if (INIFile_ChangeSectionName (pszIniFile,pszSBName,pszDBName)) {
  1031. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] INIFile_ChangeSectionName %s,%s,%s OK !\n"),
  1032. pszIniFile,pszSBName,pszDBName));
  1033. } else {
  1034. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] INIFile_ChangeSectionName %s,%s,%s Failed !\n"),
  1035. pszIniFile,pszSBName,pszDBName));
  1036. }
  1037. }
  1038. }
  1039. bRet = TRUE;
  1040. Err0:
  1041. return bRet;
  1042. }
  1043. BOOL FixSBIniKeyWithDBIniKey(HINF hInf)
  1044. {
  1045. LONG lResult;
  1046. LPCTSTR szSectionName = TEXT("INIKeyRename");
  1047. LONG LineCount,LineNo;
  1048. DWORD dwSize,dwType;
  1049. INFCONTEXT InfContext;
  1050. LPCTSTR pszIniFile,pszSection,pszSBName,pszDBName;
  1051. BOOL bRet = FALSE;
  1052. if(hInf == INVALID_HANDLE_VALUE) {
  1053. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] Open femgrate.inf failed !\n")));
  1054. goto Err0;
  1055. }
  1056. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1057. if((LONG)LineCount <= 0) {
  1058. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] line count == 0 !\n")));
  1059. goto Err0;
  1060. }
  1061. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1062. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext) &&
  1063. (pszIniFile = pSetupGetField(&InfContext,1)) &&
  1064. (pszSection = pSetupGetField(&InfContext,2)) &&
  1065. (pszSBName = pSetupGetField(&InfContext,3)) &&
  1066. (pszDBName = pSetupGetField(&InfContext,4))) {
  1067. if (INIFile_ChangeKeyName (pszIniFile,pszSection,pszSBName,pszDBName)) {
  1068. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] INIFile_ChangeSectionName %s,%s,%s OK !\n"),
  1069. pszIniFile,pszSBName,pszDBName));
  1070. } else {
  1071. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] INIFile_ChangeSectionName %s,%s,%s Failed !\n"),
  1072. pszIniFile,pszSBName,pszDBName));
  1073. }
  1074. }
  1075. }
  1076. bRet = TRUE;
  1077. Err0:
  1078. return bRet;
  1079. }
  1080. //
  1081. // this is a dup of RenameLink, should unify them later
  1082. //
  1083. BOOL RenameGenericLink(
  1084. LPCTSTR FolderName,
  1085. LPCTSTR ObjSrcName,
  1086. LPCTSTR ObjDstName)
  1087. {
  1088. TCHAR szSrcPath[MAX_PATH];
  1089. TCHAR szDstPath[MAX_PATH];
  1090. LONG lResult;
  1091. BOOL bRet=FALSE;
  1092. DebugMsg((DM_VERBOSE,TEXT("[RenameGenericLink] Folder = %s\n \nOld = %s\nSrc = %s\n"),FolderName,ObjSrcName,ObjDstName));
  1093. GetGenericUserFolderDirectory(FolderName,szSrcPath);
  1094. GetGenericUserFolderDirectory(FolderName,szDstPath);
  1095. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  1096. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  1097. lResult = GetFileAttributes(szSrcPath);
  1098. if (lResult == 0xFFFFFFFF) {
  1099. //
  1100. // Directory does not exist.
  1101. //
  1102. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] File is not existed [%s] !\n"),szSrcPath));
  1103. goto err1;
  1104. }
  1105. if (lResult & FILE_ATTRIBUTE_DIRECTORY) {
  1106. //
  1107. // this is a directory, but we want a file.
  1108. //
  1109. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] This is a directory [%s] !\n"),szSrcPath));
  1110. goto err1;
  1111. }
  1112. if (RenameFile(szSrcPath, szDstPath))
  1113. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Successfully changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  1114. else {
  1115. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Failed changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  1116. goto err1;
  1117. }
  1118. bRet = TRUE;
  1119. err1:
  1120. return bRet;
  1121. }
  1122. BOOL FixGenericLink(HINF hInf)
  1123. {
  1124. BOOL bRet = FALSE;
  1125. INFCONTEXT InfContext;
  1126. UINT LineCount,LineNo;
  1127. LPCTSTR szSectionName = TEXT("Generic.LinkToRename");
  1128. LPCTSTR FolderName;
  1129. LPCTSTR NT4Name;
  1130. LPCTSTR NT5Name;
  1131. LPCTSTR MoveIt;
  1132. TCHAR szUSFRegKey[MAX_PATH];
  1133. TCHAR szNTUSF[MAX_PATH];
  1134. TCHAR szExpNT4USF[MAX_PATH];
  1135. TCHAR szExpNT5USF[MAX_PATH];
  1136. DWORD dwSize, dwType;
  1137. LONG lResult;
  1138. UINT uiCount;
  1139. HKEY hKey;
  1140. if(hInf == INVALID_HANDLE_VALUE) {
  1141. DebugMsg((DM_VERBOSE,TEXT("[FixGenericLink] Open femgrate.inf failed !\n")));
  1142. return FALSE;
  1143. }
  1144. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1145. if((LONG)LineCount <= 0) {
  1146. DebugMsg((DM_VERBOSE,TEXT("[FixGenericLink] line count == 0 !\n")));
  1147. goto err1;
  1148. }
  1149. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1150. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  1151. && (FolderName = pSetupGetField(&InfContext,1))
  1152. && (NT4Name = pSetupGetField(&InfContext,2))
  1153. && (NT5Name = pSetupGetField(&InfContext,3))) {
  1154. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: RegName = %s !\n"),FolderName));
  1155. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: NT4Name = %s !\n"),NT4Name));
  1156. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: NT5Name = %s !\n"),NT5Name));
  1157. RenameGenericLink(FolderName,NT4Name,NT5Name);
  1158. }
  1159. }
  1160. bRet = TRUE;
  1161. err1:
  1162. return bRet;
  1163. }
  1164. BOOL FixPathInProfileLink(HINF hInf)
  1165. {
  1166. BOOL bRet = FALSE;
  1167. INFCONTEXT InfContext;
  1168. UINT LineCount,LineNo;
  1169. LPCTSTR szSectionName = TEXT("RenamePathInProfileLink");
  1170. LPCTSTR FolderName;
  1171. LPCTSTR LinkFileName;
  1172. LPCTSTR NT4SubStr;
  1173. LPCTSTR NT5SubStr;
  1174. LPCTSTR MoveIt;
  1175. TCHAR szSrcPath[MAX_PATH];
  1176. TCHAR szNTUSF[MAX_PATH];
  1177. TCHAR szExpNT4USF[MAX_PATH];
  1178. TCHAR szExpNT5USF[MAX_PATH];
  1179. DWORD dwSize, dwType;
  1180. LONG lResult;
  1181. UINT uiCount;
  1182. HKEY hKey;
  1183. if(hInf == INVALID_HANDLE_VALUE) {
  1184. DebugMsg((DM_VERBOSE,TEXT("[FixPathInProfileLink] Open femgrate.inf failed !\n")));
  1185. return FALSE;
  1186. }
  1187. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1188. if((LONG)LineCount <= 0) {
  1189. DebugMsg((DM_VERBOSE,TEXT("[FixPathInProfileLink] line count == 0 !\n")));
  1190. goto err1;
  1191. }
  1192. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1193. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  1194. && (FolderName = pSetupGetField(&InfContext,1))
  1195. && (LinkFileName = pSetupGetField(&InfContext,2))
  1196. && (NT4SubStr = pSetupGetField(&InfContext,3))
  1197. && (NT5SubStr = pSetupGetField(&InfContext,4))) {
  1198. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FolderName = %s !\n") ,FolderName));
  1199. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: LinkFileName = %s !\n"),LinkFileName));
  1200. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: NT4SubStr = %s !\n") ,NT4SubStr));
  1201. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: NT5SubStr = %s !\n") ,NT5SubStr));
  1202. if ( !GetGenericUserFolderDirectory(FolderName,szSrcPath))
  1203. goto err1;
  1204. ConcatenatePaths(szSrcPath,LinkFileName,MAX_PATH);
  1205. if (SUCCEEDED (FixPathInLink(szSrcPath,NT4SubStr,NT5SubStr))) {
  1206. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FixPathInLink OK ! %s,%s,%s!\n") ,szSrcPath,NT4SubStr,NT5SubStr));
  1207. } else {
  1208. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FixPathInLink Failed !%s,%s,%s!\n") ,szSrcPath,NT4SubStr,NT5SubStr));
  1209. }
  1210. }
  1211. }
  1212. bRet = TRUE;
  1213. err1:
  1214. return bRet;
  1215. }
  1216. BOOL FixGenericDirectory(HINF hInf)
  1217. {
  1218. BOOL bRet = FALSE;
  1219. INFCONTEXT InfContext;
  1220. UINT LineCount,LineNo;
  1221. LPCTSTR SectionName = TEXT("DirectoryToRename");
  1222. LPCTSTR SrcName;
  1223. LPCTSTR DstName;
  1224. TCHAR ExpSrcName[MAX_PATH];
  1225. TCHAR ExpDstName[MAX_PATH];
  1226. DWORD dwSize, dwType;
  1227. LONG lResult;
  1228. if(hInf == INVALID_HANDLE_VALUE) {
  1229. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Open femgrate.inf failed !\n")));
  1230. return FALSE;
  1231. }
  1232. LineCount = (UINT)SetupGetLineCount(hInf,SectionName);
  1233. if((LONG)LineCount <= 0) {
  1234. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] line count == 0 !\n")));
  1235. goto err1;
  1236. }
  1237. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1238. if (SetupGetLineByIndex(hInf,SectionName,LineNo,&InfContext)
  1239. && (SrcName = pSetupGetField(&InfContext,1))
  1240. && (DstName = pSetupGetField(&InfContext,2))) {
  1241. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Line# [%d] !\n"),LineNo));
  1242. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] SrcName = %s !\n"),SrcName));
  1243. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DstName = %s !\n"),DstName));
  1244. ExpandEnvironmentStrings (SrcName, ExpSrcName, MAX_PATH);
  1245. ExpandEnvironmentStrings (DstName, ExpDstName, MAX_PATH);
  1246. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpSrcName = %s\n"),ExpSrcName));
  1247. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpDstName = %s\n"),ExpDstName));
  1248. if (! IsDirExisting(ExpSrcName)) {
  1249. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpSrcName doesn't exist, do nothing ! %s\n"),ExpSrcName));
  1250. continue;
  1251. }
  1252. if (RenameDirectory(ExpSrcName,ExpDstName)) {
  1253. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] Rename %s to %s OK !\n"),ExpSrcName,ExpDstName));
  1254. } else {
  1255. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] Rename %s to %s FAIL!\n"),ExpSrcName,ExpDstName));
  1256. }
  1257. }
  1258. }
  1259. bRet = TRUE;
  1260. err1:
  1261. return bRet;
  1262. }
  1263. BOOL FixPartialFileName(HINF hInf)
  1264. {
  1265. BOOL bRet = FALSE;
  1266. INFCONTEXT InfContext;
  1267. UINT LineCount,LineNo;
  1268. LPCTSTR SectionName = TEXT("Generic.PartialRename");
  1269. LPCTSTR DirName;
  1270. LPCTSTR SrcName;
  1271. LPCTSTR DstName;
  1272. LPCTSTR ExtName;
  1273. TCHAR SrcPathName[MAX_PATH];
  1274. TCHAR CurPathName[MAX_PATH];
  1275. TCHAR DstPathName[MAX_PATH];
  1276. DWORD dwSize, dwType;
  1277. LONG lResult;
  1278. HANDLE hFile;
  1279. WIN32_FIND_DATA fd;
  1280. LPTSTR SrcDirEnd;
  1281. LPTSTR DstDirEnd;
  1282. LPTSTR CurDirEnd;
  1283. if(hInf == INVALID_HANDLE_VALUE) {
  1284. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Open femgrate.inf failed !\n")));
  1285. return FALSE;
  1286. }
  1287. LineCount = (UINT)SetupGetLineCount(hInf,SectionName);
  1288. if((LONG)LineCount <= 0) {
  1289. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] line count == 0 !\n")));
  1290. goto err1;
  1291. }
  1292. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1293. if (SetupGetLineByIndex(hInf,SectionName,LineNo,&InfContext)
  1294. && (DirName = pSetupGetField(&InfContext,1))
  1295. && (SrcName = pSetupGetField(&InfContext,2))
  1296. && (DstName = pSetupGetField(&InfContext,3))) {
  1297. ExtName = pSetupGetField(&InfContext,4);
  1298. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Line# [%d] !\n"),LineNo));
  1299. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DirName = %s !\n"),DirName));
  1300. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] SrcName = %s !\n"),SrcName));
  1301. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DstName = %s !\n"),DstName));
  1302. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] ExtName = %s !\n"),ExtName));
  1303. ExpandEnvironmentStrings (DirName, SrcPathName, MAX_PATH);
  1304. ExpandEnvironmentStrings (DirName, CurPathName, MAX_PATH);
  1305. ExpandEnvironmentStrings (DirName, DstPathName, MAX_PATH);
  1306. SrcDirEnd = CheckSlash (SrcPathName);
  1307. DstDirEnd = CheckSlash (DstPathName);
  1308. CurDirEnd = CheckSlash (CurPathName);
  1309. lstrcat(SrcPathName,SrcName);
  1310. lstrcat(SrcPathName,TEXT("*"));
  1311. lstrcat(SrcPathName,ExtName);
  1312. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Source = %s !\n"),SrcPathName));
  1313. hFile = FindFirstFile (SrcPathName, &fd);
  1314. if (hFile != INVALID_HANDLE_VALUE) {
  1315. do {
  1316. LPCTSTR ExtraPtr = fd.cFileName+lstrlen(SrcName);
  1317. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] fd.cFileName = %s !\n"),fd.cFileName));
  1318. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] ExtraPtr = %s !\n"),ExtraPtr));
  1319. lstrcat(DstDirEnd,DstName);
  1320. lstrcat(DstDirEnd,ExtraPtr);
  1321. lstrcat(CurDirEnd,fd.cFileName);
  1322. DebugMsg((DM_VERBOSE, TEXT("%s %s\n"),SrcPathName,DstPathName));
  1323. RenameFile(CurPathName,DstPathName);
  1324. } while (FindNextFile(hFile, &fd));
  1325. FindClose (hFile);
  1326. }
  1327. }
  1328. }
  1329. bRet = TRUE;
  1330. err1:
  1331. return bRet;
  1332. }
  1333. BOOL RenameSBKANAFiles(
  1334. HINF hInf)
  1335. /*
  1336. [WallPaper.Files]
  1337. BMP files
  1338. [Sound.Files]
  1339. Sound Files
  1340. */
  1341. {
  1342. BOOL bResult;
  1343. TCHAR WinDir[MAX_PATH];
  1344. TCHAR Directory[MAX_PATH];
  1345. GetWindowsDirectory(WinDir,sizeof(WinDir));
  1346. bResult = RenameSectionFiles(hInf,
  1347. TEXT("WallPaper.Files"),
  1348. WinDir,
  1349. WinDir);
  1350. DebugMsg((DM_VERBOSE, TEXT("[RenameAllFiles] Rename [WallPaper.Files] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1351. lstrcpy(Directory,WinDir);
  1352. ConcatenatePaths(Directory,TEXT("Media"),MAX_PATH);
  1353. bResult = RenameSectionFiles(hInf,
  1354. TEXT("Sound.Files"),
  1355. Directory,
  1356. Directory);
  1357. DebugMsg((DM_VERBOSE, TEXT("[RenameAllFiles] Rename [Sound.Files] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1358. return TRUE;
  1359. }
  1360. BOOL RenameSBKANARegSZ(
  1361. HINF hInf)
  1362. /*
  1363. [WallPaper.Files]
  1364. BMP files
  1365. [Sound.Files]
  1366. Sound Files
  1367. */
  1368. {
  1369. BOOL bResult;
  1370. TCHAR WinDir[MAX_PATH];
  1371. TCHAR Directory[MAX_PATH];
  1372. bResult = RenameSectionRegSZ(hInf,
  1373. TEXT("Cursor_Scheme_Reg"),
  1374. HKEY_CURRENT_USER,
  1375. TEXT("Control Panel\\Cursors\\Schemes"));
  1376. DebugMsg((DM_VERBOSE, TEXT("[RenameSBKANARegSZ] Rename [Cursor_Scheme_Reg] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1377. return TRUE;
  1378. }
  1379. int WINAPI WinMainJPN(
  1380. int nCmd,
  1381. HINF hMigrateInf)
  1382. {
  1383. const UINT nLocale = LOCALE_JPN;
  1384. switch(nCmd) {
  1385. case FUNC_PatchInSetup:
  1386. if (IsInSetupUpgradeMode() == FALSE) {
  1387. DebugMsg((DM_VERBOSE,TEXT("This is NOT upgrade \n")));
  1388. break;
  1389. }
  1390. DebugMsg((DM_VERBOSE,TEXT("..................This is upgrade \n")));
  1391. if (FixFoldersInSetup(hMigrateInf,TRUE)) {
  1392. if (FixCommon(hMigrateInf)) {
  1393. if (RenameProgramFolderOrLink(hMigrateInf,TRUE)) {
  1394. DebugMsg((DM_VERBOSE,TEXT("All Users, RenameProgramFolderOrLink() ok ! \n")));
  1395. }
  1396. else {
  1397. DebugMsg((DM_VERBOSE,TEXT("All Users, RenameProgramFolderOrLink() failed ! \n")));
  1398. }
  1399. }
  1400. else {
  1401. DebugMsg((DM_VERBOSE,TEXT("All Users, FixCommon() failed ! \n")));
  1402. }
  1403. }
  1404. else {
  1405. DebugMsg((DM_VERBOSE,TEXT("All Users, FixFoldersInSetup() failed ! \n")));
  1406. }
  1407. if (FixFoldersInSetup(hMigrateInf,FALSE)) {
  1408. if (RenameProgramFolderOrLink(hMigrateInf,FALSE)) {
  1409. DebugMsg((DM_VERBOSE,TEXT("Default User, RenameProgramFolderOrLink() ok ! \n")));
  1410. }
  1411. else {
  1412. DebugMsg((DM_VERBOSE,TEXT("Default User, RenameProgramFolderOrLink() failed ! \n")));
  1413. }
  1414. }
  1415. else {
  1416. DebugMsg((DM_VERBOSE,TEXT("Default User, FixFoldersInSetup() failed ! \n")));
  1417. }
  1418. if (RenameSBKANAFiles(hMigrateInf)) {
  1419. DebugMsg((DM_VERBOSE,TEXT("Fix Sound Settings OK ! \n")));
  1420. }
  1421. else {
  1422. DebugMsg((DM_VERBOSE,TEXT("Fix Sound Settings failed ! \n")));
  1423. }
  1424. if (FixSoundRegValue(hMigrateInf)) {
  1425. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue OK ! \n")));
  1426. }
  1427. else {
  1428. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue failed ! \n")));
  1429. }
  1430. if (FixTimeZone(nLocale)) {
  1431. DebugMsg((DM_VERBOSE,TEXT("FixTimeZone OK ! \n")));
  1432. }
  1433. else {
  1434. DebugMsg((DM_VERBOSE,TEXT("FixTimeZone failed ! \n")));
  1435. }
  1436. if (FixSBKanaRegValue(hMigrateInf)) {
  1437. DebugMsg((DM_VERBOSE,TEXT("FixSBKanaRegValue OK ! \n")));
  1438. } else {
  1439. DebugMsg((DM_VERBOSE,TEXT("FixSBKanaRegValue Failed ! \n")));
  1440. }
  1441. //
  1442. // FixSBIniSectionWithDBIniSection first and then FixSBIniKeyWithDBIniKey
  1443. //
  1444. if (FixSBIniSectionWithDBIniSection(hMigrateInf)) {
  1445. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection OK ! \n")));
  1446. } else {
  1447. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection failed ! \n")));
  1448. }
  1449. if (FixSBIniKeyWithDBIniKey(hMigrateInf)) {
  1450. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection OK ! \n")));
  1451. } else {
  1452. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection failed ! \n")));
  1453. }
  1454. if (FixGenericDirectory(hMigrateInf)) {
  1455. DebugMsg((DM_VERBOSE,TEXT("FixGenericDirectory OK ! \n")));
  1456. } else {
  1457. DebugMsg((DM_VERBOSE,TEXT("FixGenericDirectory failed ! \n")));
  1458. }
  1459. if (FixGenericLink(hMigrateInf)) {
  1460. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1461. } else {
  1462. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1463. }
  1464. if (FixPartialFileName(hMigrateInf)) {
  1465. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1466. } else {
  1467. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1468. }
  1469. if (RenameSBKANARegSZ(hMigrateInf)) {
  1470. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ OK ! \n")));
  1471. } else {
  1472. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ failed ! \n")));
  1473. }
  1474. break;
  1475. case FUNC_PatchInLogon:
  1476. if (FixUserFolders(hMigrateInf)) {
  1477. if (RenameProgramFolderOrLink(hMigrateInf,FALSE)) {
  1478. DebugMsg((DM_VERBOSE,TEXT("Current User, RenameProgramFolderOrLink() ok ! \n")));
  1479. }
  1480. else {
  1481. DebugMsg((DM_VERBOSE,TEXT("Current User, RenameProgramFolderOrLink() failed ! \n")));
  1482. }
  1483. }
  1484. else {
  1485. DebugMsg((DM_VERBOSE,TEXT("Current User, FixFoldersInSetup() failed ! \n")));
  1486. }
  1487. if (FixSpecificFolder(hMigrateInf)) {
  1488. DebugMsg((DM_VERBOSE,TEXT("Current User, FixSpecificFolder() ok ! \n")));
  1489. } else {
  1490. DebugMsg((DM_VERBOSE,TEXT("Current User, FixSpecificFolder() failed ! \n")));
  1491. }
  1492. if (FixAppearanceScheme(hMigrateInf)) {
  1493. DebugMsg((DM_VERBOSE,TEXT("FixAppearanceScheme OK ! \n")));
  1494. } else {
  1495. DebugMsg((DM_VERBOSE,TEXT("FixAppearanceScheme Failed ! \n")));
  1496. }
  1497. if (FixSchemeProblem(TRUE,hMigrateInf)) {
  1498. DebugMsg((DM_VERBOSE,TEXT("FixSchemeProblem OK ! \n")));
  1499. }
  1500. else {
  1501. DebugMsg((DM_VERBOSE,TEXT("FixSchemeProblem Fail ! \n")));
  1502. }
  1503. if (FixSoundRegValue(hMigrateInf)) {
  1504. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue OK ! \n")));
  1505. }
  1506. else {
  1507. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue failed ! \n")));
  1508. }
  1509. if (FixPatterns(hMigrateInf)) {
  1510. DebugMsg((DM_VERBOSE,TEXT("FixPatterns OK ! \n")));
  1511. }
  1512. else {
  1513. DebugMsg((DM_VERBOSE,TEXT("FixPatterns failed ! \n")));
  1514. }
  1515. if (FixCurrentWallPaperInDeskTop(hMigrateInf)) {
  1516. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop OK ! \n")));
  1517. }
  1518. else {
  1519. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop failed ! \n")));
  1520. }
  1521. if (FixGenericLink(hMigrateInf)) {
  1522. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1523. } else {
  1524. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1525. }
  1526. if (FixPartialFileName(hMigrateInf)) {
  1527. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1528. } else {
  1529. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1530. }
  1531. if (FixPathInProfileLink(hMigrateInf)) {
  1532. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink OK ! \n")));
  1533. } else {
  1534. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink failed ! \n")));
  1535. }
  1536. if (RenameSBKANARegSZ(hMigrateInf)) {
  1537. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ OK ! \n")));
  1538. } else {
  1539. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ failed ! \n")));
  1540. }
  1541. if (RenameRegValueName(hMigrateInf,TRUE)) {
  1542. DebugMsg((DM_VERBOSE,TEXT("RenameRegValueName OK ! \n")));
  1543. } else {
  1544. DebugMsg((DM_VERBOSE,TEXT("RenameRegValueName failed ! \n")));
  1545. }
  1546. break;
  1547. case FUNC_PatchPreload:
  1548. if (PatchPreloadKeyboard(FALSE)) {
  1549. DebugMsg((DM_VERBOSE,TEXT("PatchPreloadKeyboard OK ! \n")));
  1550. } else {
  1551. DebugMsg((DM_VERBOSE,TEXT("PatchPreloadKeyboard Failed ! \n")));
  1552. }
  1553. break;
  1554. case FUNC_PatchTest:
  1555. break;
  1556. default:
  1557. DebugMsg((DM_VERBOSE,TEXT("No such function\n")));
  1558. }
  1559. return (0);
  1560. }