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.

1978 lines
66 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. szExpProgramFolderPath[0] = 0;
  354. //
  355. // Loop through all the program groups in the All Users profile
  356. // and remove the " (Common)" tag.
  357. //
  358. if(hInf == INVALID_HANDLE_VALUE) {
  359. DebugMsg((DM_VERBOSE,TEXT("[FixCommon] Open femgrate.inf failed !\n")));
  360. return FALSE;
  361. }
  362. if (! SetupGetLineText(NULL,
  363. hInf,
  364. TEXT("Misc"),
  365. TEXT("Common"),
  366. szCommon,
  367. sizeof(szCommon),
  368. &RequiredSize)) {
  369. goto err1;
  370. }
  371. nCommon = lstrlen(szCommon);
  372. GetProgramsDirectory(TRUE,szProgramFolderPath);
  373. ExpandEnvironmentStrings (szProgramFolderPath, szExpProgramFolderPath, MAX_PATH);
  374. lstrcpy(szProgramFolderPath,szExpProgramFolderPath);
  375. //
  376. // From here, szProgramFolderPath used for Folder name without "Common"
  377. //
  378. lpEnd = CheckSlash (szExpProgramFolderPath);
  379. lpEnd2 = CheckSlash (szProgramFolderPath);
  380. lstrcpy (lpEnd, c_szStarDotStar);
  381. hFile = FindFirstFile (szExpProgramFolderPath, &fd);
  382. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] Find %s\n"),szExpProgramFolderPath));
  383. if (hFile != INVALID_HANDLE_VALUE) {
  384. do {
  385. if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  386. nFileName = lstrlen (fd.cFileName);
  387. DebugMsg((DM_VERBOSE, TEXT("Find %s\n"),fd.cFileName));
  388. if (nFileName > nCommon) {
  389. lpTag = fd.cFileName + nFileName - nCommon;
  390. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] lpTag=%s szCommon=%s\n"),lpTag, szCommon));
  391. if (!lstrcmpi(lpTag, szCommon)) {
  392. lstrcpy (lpEnd, fd.cFileName);
  393. *lpTag = TEXT('\0');
  394. lstrcpy (lpEnd2, fd.cFileName);
  395. if (CopyProfileDirectory (szExpProgramFolderPath, szProgramFolderPath, CPD_IGNOREHIVE)) {
  396. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully changed group name:\n")));
  397. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath));
  398. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath));
  399. if (Delnode (szExpProgramFolderPath)) {
  400. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully remove folder:\n%s\n"),szExpProgramFolderPath));
  401. }
  402. else {
  403. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed remove folder:\n%s\n"),szExpProgramFolderPath));
  404. }
  405. } else {
  406. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed to change group name with error %d.\n"), GetLastError()));
  407. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath));
  408. DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath));
  409. }
  410. }
  411. }
  412. }
  413. } while (FindNextFile(hFile, &fd));
  414. FindClose (hFile);
  415. }
  416. bRet = TRUE;
  417. err1:
  418. return bRet;
  419. }
  420. BOOL RenameLink(
  421. BOOL bCommonGroup,
  422. LPCTSTR ObjSrcName,
  423. LPCTSTR ObjDstName,
  424. LPCTSTR ObjPath)
  425. {
  426. TCHAR szSrcPath[MAX_PATH];
  427. TCHAR szDstPath[MAX_PATH];
  428. LONG lResult;
  429. BOOL bRet=FALSE;
  430. DebugMsg((DM_VERBOSE,TEXT("[RenameLink] \nOld = %s\nNew = %s\nPath = %s\n"),ObjSrcName,ObjDstName,ObjPath));
  431. if (!GetProgramsDirectory(bCommonGroup,szSrcPath))
  432. return bRet;
  433. if ( !GetProgramsDirectory(bCommonGroup,szDstPath))
  434. return bRet;
  435. if (ObjPath && *ObjPath) {
  436. ConcatenatePaths(szSrcPath,ObjPath,MAX_PATH);
  437. ConcatenatePaths(szDstPath,ObjPath,MAX_PATH);
  438. }
  439. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  440. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  441. lstrcat(szSrcPath,TEXT(".lnk"));
  442. lstrcat(szDstPath,TEXT(".lnk"));
  443. lResult = GetFileAttributes(szSrcPath);
  444. if (lResult == 0xFFFFFFFF) {
  445. //
  446. // Directory does not exist.
  447. //
  448. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] File is not existed [%s] !\n"),szSrcPath));
  449. goto err1;
  450. }
  451. if (lResult & FILE_ATTRIBUTE_DIRECTORY) {
  452. //
  453. // this is a directory, but we want a file.
  454. //
  455. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] This is a directory [%s] !\n"),szSrcPath));
  456. goto err1;
  457. }
  458. //
  459. // if destination file existed, it's not good !
  460. //
  461. lResult = GetFileAttributes(szDstPath);
  462. if (lResult == 0xFFFFFFFF) {
  463. if (MoveFile (szSrcPath, szDstPath)) {
  464. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Successfully changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  465. }
  466. else {
  467. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Failed to change link name with error %d.\n%s\n%s\n"), GetLastError(),szSrcPath,szDstPath));
  468. goto err1;
  469. }
  470. }
  471. else {
  472. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Destination file existed, maybe we don't want to overwrite ,%s\n"),szDstPath));
  473. goto err1;
  474. }
  475. bRet = TRUE;
  476. err1:
  477. return bRet;
  478. }
  479. BOOL RenameFolder(
  480. BOOL bCommonGroup,
  481. LPCTSTR ObjSrcName,
  482. LPCTSTR ObjDstName)
  483. {
  484. TCHAR szSrcPath[MAX_PATH];
  485. TCHAR szDstPath[MAX_PATH];
  486. LONG lResult;
  487. BOOL bRet=FALSE;
  488. DebugMsg((DM_VERBOSE,TEXT("[RenameFolder]\nOld = %s\nNew = %s\n"),ObjSrcName,ObjDstName));
  489. GetProgramsDirectory(bCommonGroup,szSrcPath);
  490. GetProgramsDirectory(bCommonGroup,szDstPath);
  491. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  492. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  493. lResult = GetFileAttributes(szSrcPath);
  494. if (lResult == 0xFFFFFFFF) {
  495. //
  496. // Directory does not exist.
  497. //
  498. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Directory is not existed [%s] !\n"),szSrcPath));
  499. goto err1;
  500. }
  501. if (!(lResult & FILE_ATTRIBUTE_DIRECTORY)) {
  502. //
  503. // this is not a directory.
  504. //
  505. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] This is not a directory [%s] !\n"),szSrcPath));
  506. goto err1;
  507. }
  508. if (CopyProfileDirectory (szSrcPath, szDstPath, CPD_IGNOREHIVE)) {
  509. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Successfully changed folder name:\n%s\n%s"),szSrcPath,szDstPath));
  510. if (! Delnode(szSrcPath)) {
  511. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) failed !"), szSrcPath));
  512. } else {
  513. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) successfully !"), szSrcPath));
  514. }
  515. }
  516. else {
  517. DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Convert Folder: Failed to change group name with error %d\n.%s\n%s\n"), GetLastError(),szSrcPath,szDstPath));
  518. goto err1;
  519. }
  520. bRet = TRUE;
  521. err1:
  522. return bRet;
  523. }
  524. BOOL RenameProgramFolderOrLink(HINF hInf,BOOL bCommon)
  525. {
  526. BOOL bRet = FALSE;
  527. INFCONTEXT InfContext;
  528. UINT LineCount,LineNo;
  529. LPCTSTR szSectionName = TEXT("StartMenu.ObjectToRename");
  530. LPCTSTR ObjectType;
  531. LPCTSTR ObjectSrcName;
  532. LPCTSTR ObjectDstName;
  533. LPCTSTR ObjectPath;
  534. LPCTSTR GroupAttribute;
  535. BOOL CommonGroup;
  536. BOOL IsMenuItem;
  537. if(hInf == INVALID_HANDLE_VALUE) {
  538. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Open femgrate.inf failed !\n")));
  539. return FALSE;
  540. }
  541. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  542. if((LONG)LineCount <= 0) {
  543. goto err1;
  544. }
  545. for(LineNo=0; LineNo<LineCount; LineNo++) {
  546. if(SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  547. && (ObjectType = pSetupGetField(&InfContext,1))
  548. && (ObjectSrcName = pSetupGetField(&InfContext,2))
  549. && (ObjectDstName = pSetupGetField(&InfContext,3))
  550. && (GroupAttribute = pSetupGetField(&InfContext,5))) {
  551. ObjectPath = pSetupGetField(&InfContext,4);
  552. IsMenuItem = A2I(ObjectType);
  553. CommonGroup = A2I(GroupAttribute);
  554. if ((bCommon && (CommonGroup == 0)) ||
  555. (!bCommon && (CommonGroup == 1))) {
  556. // DebugMsg((DM_VERBOSE,TEXT("Eject this line(%d) .....................................\n"),LineNo));
  557. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  558. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  559. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  560. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  561. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  562. continue;
  563. }
  564. if (IsMenuItem) {
  565. // DebugMsg((DM_VERBOSE,TEXT("RenameLink (%d).....................................\n"),LineNo));
  566. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  567. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  568. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  569. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  570. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  571. RenameLink(bCommon,ObjectSrcName,ObjectDstName,ObjectPath);
  572. }
  573. else {
  574. // DebugMsg((DM_VERBOSE,TEXT("RenameFolder (%d) .....................................\n"),LineNo));
  575. // DebugMsg((DM_VERBOSE,TEXT("ObjectType = %s\n"),ObjectType));
  576. // DebugMsg((DM_VERBOSE,TEXT("ObjectSrcName = %s\n"),ObjectSrcName));
  577. // DebugMsg((DM_VERBOSE,TEXT("ObjectDstName = %s\n"),ObjectDstName));
  578. // DebugMsg((DM_VERBOSE,TEXT("GroupAttribute= %s\n"),GroupAttribute));
  579. // DebugMsg((DM_VERBOSE,TEXT("bCommon = %d\n"),bCommon));
  580. RenameFolder(bCommon,ObjectSrcName,ObjectDstName);
  581. }
  582. }
  583. }
  584. bRet = TRUE;
  585. err1:
  586. return bRet;
  587. }
  588. //
  589. // Fix Sound scheme that originally is SB katana
  590. //
  591. BOOL MapSBtoDBKana(HINF hInf,LPCTSTR lpszSectionName,LPTSTR lpszSoundName)
  592. {
  593. LPCTSTR szSBKana,szDBKana;
  594. LONG LineCount,LineNo;
  595. DWORD dwSize,dwType;
  596. INFCONTEXT InfContext;
  597. if(hInf == INVALID_HANDLE_VALUE) {
  598. DebugMsg((DM_VERBOSE,TEXT("[MapSBtoDBKana] Open femgrate.inf failed !\n")));
  599. return FALSE;
  600. }
  601. LineCount = (UINT)SetupGetLineCount(hInf,lpszSectionName);
  602. if((LONG)LineCount <= 0) {
  603. DebugMsg((DM_VERBOSE,TEXT("[MapSBtoDBKana] line count == 0 !\n")));
  604. return FALSE;
  605. }
  606. for(LineNo=0; LineNo<LineCount; LineNo++) {
  607. if (SetupGetLineByIndex(hInf,lpszSectionName,LineNo,&InfContext)
  608. && (szSBKana = pSetupGetField(&InfContext,1))) {
  609. if (lstrcmpi(szSBKana,lpszSoundName) == 0) {
  610. if (szDBKana = pSetupGetField(&InfContext,2)) {
  611. lstrcpy(lpszSoundName,szDBKana);
  612. return TRUE;
  613. }
  614. else {
  615. //
  616. // inf error, no second data
  617. //
  618. return FALSE;
  619. }
  620. }
  621. }
  622. }
  623. return FALSE;
  624. }
  625. BOOL NameSubstitution(HINF hInf,LPTSTR lpszOrgName,LPTSTR lpszDir,LPTSTR lpszSection)
  626. {
  627. TCHAR szExpDir[MAX_PATH];
  628. LPTSTR lpszAnchor;
  629. TCHAR szOnlyName[MAX_PATH];
  630. if (_tcsstr(lpszOrgName,TEXT("\\"))) {
  631. if (ExpandEnvironmentStrings(lpszDir,szExpDir,MAX_PATH) == 0) {
  632. return FALSE;
  633. }
  634. _tcsupr(lpszOrgName);
  635. _tcsupr(szExpDir);
  636. lpszAnchor = _tcsstr(lpszOrgName,szExpDir);
  637. if ((lpszAnchor == NULL ) || (lpszAnchor != lpszOrgName)) {
  638. return FALSE;
  639. }
  640. lstrcpy(szOnlyName,lpszAnchor+lstrlen(szExpDir));
  641. DebugMsg((DM_VERBOSE,TEXT("We want to find %s !\n"),szOnlyName));
  642. if (MapSBtoDBKana(hInf,lpszSection,szOnlyName)) {
  643. lstrcpy(lpszAnchor+lstrlen(szExpDir),szOnlyName);
  644. return TRUE;
  645. }
  646. }
  647. else {
  648. if (MapSBtoDBKana(hInf,lpszSection,lpszOrgName)) {
  649. return TRUE;
  650. }
  651. }
  652. return FALSE;
  653. }
  654. BOOL EnumSoundSchemeApps(HKEY hKey,HINF hInf)
  655. {
  656. HKEY hSubKey;
  657. DWORD dwIndex;
  658. DWORD dwKeyNameSize;
  659. TCHAR szKeyName[MAX_PATH];
  660. DWORD dwSoundValue;
  661. TCHAR szSoundValue[MAX_PATH];
  662. LONG lResult;
  663. dwKeyNameSize = sizeof(szKeyName)/sizeof(szKeyName[0]);
  664. for (dwIndex = 0;
  665. RegEnumKey(hKey, dwIndex, szKeyName, dwKeyNameSize) == ERROR_SUCCESS;
  666. dwIndex++) {
  667. lResult = RegOpenKey(hKey,
  668. szKeyName,
  669. &hSubKey);
  670. if (lResult == ERROR_SUCCESS) {
  671. EnumSoundSchemeApps(hSubKey,hInf);
  672. RegCloseKey(hSubKey);
  673. }
  674. }
  675. //
  676. // no sub-key, then just get the value
  677. //
  678. if (dwIndex == 0) {
  679. dwSoundValue = sizeof(szSoundValue);
  680. lResult = RegQueryValue(hKey,
  681. NULL,
  682. szSoundValue,
  683. &dwSoundValue);
  684. if (lResult == ERROR_SUCCESS) {
  685. if (szSoundValue[0]) {
  686. if (NameSubstitution(hInf,szSoundValue,TEXT("%SystemRoot%\\Media\\"),TEXT("Sound.Files"))) {
  687. RegSetValue(hKey,
  688. NULL,
  689. REG_SZ,
  690. szSoundValue,
  691. (lstrlen(szSoundValue)+1)*sizeof(TCHAR));
  692. }
  693. }
  694. }
  695. }
  696. return TRUE;
  697. }
  698. BOOL FixSoundRegValue(HINF hInf)
  699. {
  700. LONG lResult;
  701. BOOL bRet=FALSE;
  702. HKEY hKey;
  703. if(hInf == INVALID_HANDLE_VALUE) {
  704. DebugMsg((DM_VERBOSE,TEXT("[FixSoundRegValue] Open femgrate.inf failed !\n")));
  705. goto Err0;
  706. }
  707. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  708. REGSTR_PATH_APPS,
  709. 0,
  710. KEY_ALL_ACCESS,
  711. &hKey);
  712. if (lResult != ERROR_SUCCESS) {
  713. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  714. goto Err0;
  715. }
  716. EnumSoundSchemeApps(hKey,hInf);
  717. if (! DoInstallationFromSection(hInf, TEXT("Sound.Reg.Update"))) {
  718. DebugMsg((DM_VERBOSE,TEXT("[FixSoundRegValue] DoInstallationFromSection failed !\n")));
  719. goto Err1;
  720. }
  721. bRet = TRUE;
  722. Err1:
  723. RegCloseKey(hKey);
  724. Err0:
  725. return bRet;
  726. }
  727. //
  728. // Search the registry and find SB value then replace with DB value
  729. //
  730. BOOL FixSBKanaRegValue(HINF hInf)
  731. {
  732. LPCTSTR szRegRoot,szRegPath;
  733. LPCTSTR szRegSBVal,szRegDBVal;
  734. LPCTSTR szRegSBData,szRegDBData;
  735. LONG LineCount,LineNo;
  736. DWORD dwSize,dwType;
  737. INFCONTEXT InfContext;
  738. HKEY hKey,hKeyRoot;
  739. BOOL bOK;
  740. TCHAR szRegCurData[MAX_PATH];
  741. LONG lResult;
  742. LPCTSTR lpszSectionName = TEXT("Reg.UpdateIfExsit");
  743. if(hInf == INVALID_HANDLE_VALUE) {
  744. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Open femgrate.inf failed !\n")));
  745. return FALSE;
  746. }
  747. LineCount = (UINT)SetupGetLineCount(hInf,lpszSectionName);
  748. if((LONG)LineCount <= 0) {
  749. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] line count == 0 !\n")));
  750. return FALSE;
  751. }
  752. for(LineNo=0; LineNo<LineCount; LineNo++) {
  753. if (SetupGetLineByIndex(hInf,lpszSectionName,LineNo,&InfContext)
  754. && (szRegRoot = pSetupGetField(&InfContext,1))
  755. && (szRegPath = pSetupGetField(&InfContext,2))
  756. && (szRegSBData = pSetupGetField(&InfContext,4))
  757. && (szRegDBData = pSetupGetField(&InfContext,6))) {
  758. szRegSBVal = pSetupGetField(&InfContext,3);
  759. szRegDBVal = pSetupGetField(&InfContext,5);
  760. if (!LookUpStringInTable(InfRegSpecTohKey,szRegRoot,(PUINT)&hKeyRoot)) {
  761. continue;
  762. }
  763. lResult = RegOpenKeyEx( hKeyRoot,
  764. szRegPath,
  765. 0,
  766. KEY_READ | KEY_WRITE,
  767. &hKey);
  768. if (lResult != ERROR_SUCCESS) {
  769. continue;
  770. }
  771. dwSize = sizeof(szRegCurData);
  772. lResult = RegQueryValueEx (hKey,
  773. szRegSBVal,
  774. NULL,
  775. &dwType,
  776. (LPBYTE) szRegCurData,
  777. &dwSize);
  778. if (lResult != ERROR_SUCCESS) {
  779. goto Err1;
  780. }
  781. if ((dwType != REG_SZ) && (dwType != REG_EXPAND_SZ)) {
  782. goto Err1;
  783. }
  784. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] szRegPath = %s, old data = %s, SB data = %s!\n"),szRegPath,szRegCurData,szRegSBData));
  785. if (lstrcmp(szRegCurData,szRegSBData ) == 0) {
  786. #if 1
  787. lResult = RegSetValueEx (hKey,
  788. szRegSBVal,
  789. 0,
  790. dwType,
  791. (LPBYTE) szRegDBData,
  792. (lstrlen(szRegDBData)+1) * sizeof (TCHAR));
  793. #endif
  794. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Set reg value %s,%s,%s!\n"),szRegPath,szRegSBVal,szRegDBData));
  795. if (lResult != ERROR_SUCCESS) {
  796. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] Set reg value error %s,%s == 0 !\n"),szRegSBVal,szRegDBData));
  797. }
  798. } else {
  799. DebugMsg((DM_VERBOSE,TEXT("[FixSBKanaRegValue] szRegPath = %s, old data = %s, SB data = %s , comparing result is different !\n"),szRegPath,szRegCurData,szRegSBData));
  800. }
  801. Err1:
  802. RegCloseKey(hKey);
  803. }
  804. }
  805. return TRUE;
  806. }
  807. //
  808. // Fix Patterns
  809. //
  810. BOOL FixPatterns(HINF hInf)
  811. {
  812. LONG lResult;
  813. BOOL bRet=FALSE;
  814. HKEY hKey;
  815. LONG LineNo,LineCount;
  816. LPCTSTR pszOldValName;
  817. LPCTSTR pszNewValName;
  818. LPCTSTR szSectionName = TEXT("Patterns");
  819. INFCONTEXT InfContext;
  820. if(hInf == INVALID_HANDLE_VALUE) {
  821. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Open femgrate.inf failed !\n")));
  822. goto Err0;
  823. }
  824. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  825. TEXT("Control Panel\\Patterns"),
  826. 0,
  827. KEY_ALL_ACCESS,
  828. &hKey);
  829. if (lResult != ERROR_SUCCESS) {
  830. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Open Control Panel\\Patterns failed !\n")));
  831. goto Err0;
  832. }
  833. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  834. if((LONG)LineCount <= 0) {
  835. goto Err1;
  836. }
  837. for(LineNo=0; LineNo<LineCount; LineNo++) {
  838. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  839. && (pszOldValName = pSetupGetField(&InfContext,1))
  840. && (pszNewValName = pSetupGetField(&InfContext,2))) {
  841. if (RegReplaceIfExisting(hKey,pszOldValName,pszNewValName)) {
  842. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Replace pattern %s with %s OK !\n"),pszOldValName,pszNewValName));
  843. } else {
  844. DebugMsg((DM_VERBOSE,TEXT("[FixPatterns] Replace pattern %s with %s Failed !\n"),pszOldValName,pszNewValName));
  845. }
  846. }
  847. }
  848. bRet = TRUE;
  849. Err1:
  850. RegCloseKey(hKey);
  851. Err0:
  852. return bRet;
  853. }
  854. //
  855. // FixCurrentWallPaperInDeskTop
  856. //
  857. BOOL FixCurrentWallPaperInDeskTop(HINF hInf)
  858. {
  859. HKEY hKey;
  860. LONG lResult;
  861. DWORD dwType,dwSize;
  862. TCHAR szData[MAX_PATH];
  863. BOOL bRet = FALSE;
  864. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  865. TEXT("Control Panel\\Desktop"),
  866. 0,
  867. KEY_READ | KEY_WRITE,
  868. &hKey);
  869. if (lResult != ERROR_SUCCESS) {
  870. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] , Open Control Panel\\Desktop failed!\n")));
  871. goto Err0;
  872. }
  873. dwSize = sizeof(szData);
  874. lResult = RegQueryValueEx (hKey,
  875. TEXT("Wallpaper"),
  876. NULL,
  877. &dwType,
  878. (LPBYTE) szData,
  879. &dwSize);
  880. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop: Current WallPaperValue is %s !\n"),szData));
  881. if (lResult != ERROR_SUCCESS) {
  882. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] Query Current WallPaperValue failed!\n")));
  883. goto Err1;
  884. }
  885. if (NameSubstitution(hInf,szData,TEXT("%systemroot%\\"),TEXT("WallPaper.Reg"))) {
  886. lResult = RegSetValueEx(hKey,
  887. TEXT("Wallpaper"),
  888. 0,
  889. REG_SZ,
  890. (LPBYTE) szData,
  891. (lstrlen(szData) + 1) * sizeof(TCHAR));
  892. if (lResult != ERROR_SUCCESS) {
  893. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] RegSetValue WallPaperValue failed!\n")));
  894. goto Err1;
  895. }
  896. }
  897. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentWallPaperInDeskTop] Current WallPaper has been changed to %s!\n"),szData));
  898. bRet = TRUE;
  899. Err1:
  900. RegCloseKey(hKey);
  901. Err0:
  902. return bRet;
  903. }
  904. //
  905. // FixAppearanceScheme
  906. //
  907. BOOL FixAppearanceScheme(HINF hInf)
  908. {
  909. HKEY hAppearanceKey,hSchemeKey;
  910. LONG lResult;
  911. LPCTSTR szSectionName = TEXT("Apperance Scheme");
  912. TCHAR szCurrentScheme[MAX_PATH];
  913. LPCTSTR NT4SchemeName;
  914. LPCTSTR NT5SchemeName;
  915. LONG LineCount,LineNo;
  916. DWORD dwSize,dwType;
  917. INFCONTEXT InfContext;
  918. BOOL bRet = FALSE;
  919. if(hInf == INVALID_HANDLE_VALUE) {
  920. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open femgrate.inf failed !\n")));
  921. goto Err0;
  922. }
  923. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  924. REGSTR_PATH_APPEARANCE,
  925. 0,
  926. KEY_ALL_ACCESS,
  927. &hAppearanceKey);
  928. if (lResult != ERROR_SUCCESS) {
  929. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  930. goto Err0;
  931. }
  932. //
  933. // Now query for the programs directory
  934. //
  935. dwSize = MAX_PATH * sizeof(TCHAR);
  936. szCurrentScheme[0] = TEXT('\0');
  937. lResult = RegQueryValueEx (hAppearanceKey,
  938. TEXT("Current"),
  939. NULL,
  940. &dwType,
  941. (LPBYTE) szCurrentScheme,
  942. &dwSize);
  943. if (lResult != ERROR_SUCCESS) {
  944. //
  945. // this case is fine
  946. //
  947. szCurrentScheme[0] = TEXT('\0');
  948. }
  949. lResult = RegOpenKeyEx (HKEY_CURRENT_USER,
  950. REGSTR_PATH_LOOKSCHEMES,
  951. 0,
  952. KEY_ALL_ACCESS,
  953. &hSchemeKey);
  954. if (lResult != ERROR_SUCCESS) {
  955. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Open REGSTR_PATH_APPEARANCE failed !\n")));
  956. goto Err1;
  957. }
  958. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  959. if((LONG)LineCount <= 0) {
  960. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] line count == 0 !\n")));
  961. goto Err2;
  962. }
  963. for(LineNo=0; LineNo<LineCount; LineNo++) {
  964. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  965. && (NT4SchemeName = pSetupGetField(&InfContext,1))) {
  966. if (szCurrentScheme[0] != '\0') {
  967. if (lstrcmp(szCurrentScheme,NT4SchemeName) == 0) {
  968. if (NT5SchemeName = pSetupGetField(&InfContext,2)) {
  969. lResult = RegSetValueEx(hAppearanceKey,
  970. TEXT("Current"),
  971. 0,
  972. REG_SZ,
  973. (LPBYTE) NT5SchemeName,
  974. (lstrlen(NT5SchemeName)+1)*sizeof(TCHAR));
  975. if (lResult != ERROR_SUCCESS) {
  976. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] Set Appearance current scheme fail ! \n")));
  977. }
  978. }
  979. else {
  980. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] NT5's scheme missed!\n")));
  981. }
  982. }
  983. }
  984. lResult = RegDeleteValue(hSchemeKey,
  985. NT4SchemeName);
  986. if (lResult != ERROR_SUCCESS) {
  987. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] ----------------------- Delete scheme [%d], %s failed !\n"),LineNo,NT4SchemeName));
  988. } else {
  989. DebugMsg((DM_VERBOSE,TEXT("[FixAppearanceScheme] ----------------------- Delete scheme [%d], %s OK !\n"),LineNo,NT4SchemeName));
  990. }
  991. }
  992. }
  993. bRet = TRUE;
  994. Err2:
  995. RegCloseKey(hSchemeKey);
  996. Err1:
  997. RegCloseKey(hAppearanceKey);
  998. Err0:
  999. return bRet;
  1000. }
  1001. //
  1002. //ntbug#113976,#113007
  1003. //
  1004. // SB section in win.ini and entpack.ini
  1005. //
  1006. // replace SB section name with DB section name
  1007. //
  1008. BOOL FixSBIniSectionWithDBIniSection(HINF hInf)
  1009. {
  1010. LONG lResult;
  1011. LPCTSTR szSectionName = TEXT("INISectionRename");
  1012. LONG LineCount,LineNo;
  1013. DWORD dwSize,dwType;
  1014. INFCONTEXT InfContext;
  1015. LPCTSTR pszIniFile,pszSBName,pszDBName;
  1016. BOOL bRet = FALSE;
  1017. if(hInf == INVALID_HANDLE_VALUE) {
  1018. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] Open femgrate.inf failed !\n")));
  1019. goto Err0;
  1020. }
  1021. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1022. if((LONG)LineCount <= 0) {
  1023. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] line count == 0 !\n")));
  1024. goto Err0;
  1025. }
  1026. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1027. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext) &&
  1028. (pszIniFile = pSetupGetField(&InfContext,1)) &&
  1029. (pszSBName = pSetupGetField(&InfContext,2)) &&
  1030. (pszDBName = pSetupGetField(&InfContext,3))) {
  1031. if (INIFile_ChangeSectionName (pszIniFile,pszSBName,pszDBName)) {
  1032. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] INIFile_ChangeSectionName %s,%s,%s OK !\n"),
  1033. pszIniFile,pszSBName,pszDBName));
  1034. } else {
  1035. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniSectionWithDBIniSection] INIFile_ChangeSectionName %s,%s,%s Failed !\n"),
  1036. pszIniFile,pszSBName,pszDBName));
  1037. }
  1038. }
  1039. }
  1040. bRet = TRUE;
  1041. Err0:
  1042. return bRet;
  1043. }
  1044. BOOL FixSBIniKeyWithDBIniKey(HINF hInf)
  1045. {
  1046. LONG lResult;
  1047. LPCTSTR szSectionName = TEXT("INIKeyRename");
  1048. LONG LineCount,LineNo;
  1049. DWORD dwSize,dwType;
  1050. INFCONTEXT InfContext;
  1051. LPCTSTR pszIniFile,pszSection,pszSBName,pszDBName;
  1052. BOOL bRet = FALSE;
  1053. if(hInf == INVALID_HANDLE_VALUE) {
  1054. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] Open femgrate.inf failed !\n")));
  1055. goto Err0;
  1056. }
  1057. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1058. if((LONG)LineCount <= 0) {
  1059. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] line count == 0 !\n")));
  1060. goto Err0;
  1061. }
  1062. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1063. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext) &&
  1064. (pszIniFile = pSetupGetField(&InfContext,1)) &&
  1065. (pszSection = pSetupGetField(&InfContext,2)) &&
  1066. (pszSBName = pSetupGetField(&InfContext,3)) &&
  1067. (pszDBName = pSetupGetField(&InfContext,4))) {
  1068. if (INIFile_ChangeKeyName (pszIniFile,pszSection,pszSBName,pszDBName)) {
  1069. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] INIFile_ChangeSectionName %s,%s,%s OK !\n"),
  1070. pszIniFile,pszSBName,pszDBName));
  1071. } else {
  1072. DebugMsg((DM_VERBOSE,TEXT("[FixSBIniKeyWithDBIniKey] INIFile_ChangeSectionName %s,%s,%s Failed !\n"),
  1073. pszIniFile,pszSBName,pszDBName));
  1074. }
  1075. }
  1076. }
  1077. bRet = TRUE;
  1078. Err0:
  1079. return bRet;
  1080. }
  1081. //
  1082. // this is a dup of RenameLink, should unify them later
  1083. //
  1084. BOOL RenameGenericLink(
  1085. LPCTSTR FolderName,
  1086. LPCTSTR ObjSrcName,
  1087. LPCTSTR ObjDstName)
  1088. {
  1089. TCHAR szSrcPath[MAX_PATH];
  1090. TCHAR szDstPath[MAX_PATH];
  1091. LONG lResult;
  1092. BOOL bRet=FALSE;
  1093. DebugMsg((DM_VERBOSE,TEXT("[RenameGenericLink] Folder = %s\n \nOld = %s\nSrc = %s\n"),FolderName,ObjSrcName,ObjDstName));
  1094. GetGenericUserFolderDirectory(FolderName,szSrcPath);
  1095. GetGenericUserFolderDirectory(FolderName,szDstPath);
  1096. ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH);
  1097. ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH);
  1098. lResult = GetFileAttributes(szSrcPath);
  1099. if (lResult == 0xFFFFFFFF) {
  1100. //
  1101. // Directory does not exist.
  1102. //
  1103. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] File is not existed [%s] !\n"),szSrcPath));
  1104. goto err1;
  1105. }
  1106. if (lResult & FILE_ATTRIBUTE_DIRECTORY) {
  1107. //
  1108. // this is a directory, but we want a file.
  1109. //
  1110. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] This is a directory [%s] !\n"),szSrcPath));
  1111. goto err1;
  1112. }
  1113. if (RenameFile(szSrcPath, szDstPath))
  1114. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Successfully changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  1115. else {
  1116. DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Failed changed link name:\n%s\n%s\n"),szSrcPath,szDstPath));
  1117. goto err1;
  1118. }
  1119. bRet = TRUE;
  1120. err1:
  1121. return bRet;
  1122. }
  1123. BOOL FixGenericLink(HINF hInf)
  1124. {
  1125. BOOL bRet = FALSE;
  1126. INFCONTEXT InfContext;
  1127. UINT LineCount,LineNo;
  1128. LPCTSTR szSectionName = TEXT("Generic.LinkToRename");
  1129. LPCTSTR FolderName;
  1130. LPCTSTR NT4Name;
  1131. LPCTSTR NT5Name;
  1132. LPCTSTR MoveIt;
  1133. TCHAR szUSFRegKey[MAX_PATH];
  1134. TCHAR szNTUSF[MAX_PATH];
  1135. TCHAR szExpNT4USF[MAX_PATH];
  1136. TCHAR szExpNT5USF[MAX_PATH];
  1137. DWORD dwSize, dwType;
  1138. LONG lResult;
  1139. UINT uiCount;
  1140. HKEY hKey;
  1141. if(hInf == INVALID_HANDLE_VALUE) {
  1142. DebugMsg((DM_VERBOSE,TEXT("[FixGenericLink] Open femgrate.inf failed !\n")));
  1143. return FALSE;
  1144. }
  1145. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1146. if((LONG)LineCount <= 0) {
  1147. DebugMsg((DM_VERBOSE,TEXT("[FixGenericLink] line count == 0 !\n")));
  1148. goto err1;
  1149. }
  1150. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1151. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  1152. && (FolderName = pSetupGetField(&InfContext,1))
  1153. && (NT4Name = pSetupGetField(&InfContext,2))
  1154. && (NT5Name = pSetupGetField(&InfContext,3))) {
  1155. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: RegName = %s !\n"),FolderName));
  1156. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: NT4Name = %s !\n"),NT4Name));
  1157. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink: NT5Name = %s !\n"),NT5Name));
  1158. RenameGenericLink(FolderName,NT4Name,NT5Name);
  1159. }
  1160. }
  1161. bRet = TRUE;
  1162. err1:
  1163. return bRet;
  1164. }
  1165. BOOL FixPathInProfileLink(HINF hInf)
  1166. {
  1167. BOOL bRet = FALSE;
  1168. INFCONTEXT InfContext;
  1169. UINT LineCount,LineNo;
  1170. LPCTSTR szSectionName = TEXT("RenamePathInProfileLink");
  1171. LPCTSTR FolderName;
  1172. LPCTSTR LinkFileName;
  1173. LPCTSTR NT4SubStr;
  1174. LPCTSTR NT5SubStr;
  1175. LPCTSTR MoveIt;
  1176. TCHAR szSrcPath[MAX_PATH];
  1177. TCHAR szNTUSF[MAX_PATH];
  1178. TCHAR szExpNT4USF[MAX_PATH];
  1179. TCHAR szExpNT5USF[MAX_PATH];
  1180. DWORD dwSize, dwType;
  1181. LONG lResult;
  1182. UINT uiCount;
  1183. HKEY hKey;
  1184. if(hInf == INVALID_HANDLE_VALUE) {
  1185. DebugMsg((DM_VERBOSE,TEXT("[FixPathInProfileLink] Open femgrate.inf failed !\n")));
  1186. return FALSE;
  1187. }
  1188. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  1189. if((LONG)LineCount <= 0) {
  1190. DebugMsg((DM_VERBOSE,TEXT("[FixPathInProfileLink] line count == 0 !\n")));
  1191. goto err1;
  1192. }
  1193. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1194. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  1195. && (FolderName = pSetupGetField(&InfContext,1))
  1196. && (LinkFileName = pSetupGetField(&InfContext,2))
  1197. && (NT4SubStr = pSetupGetField(&InfContext,3))
  1198. && (NT5SubStr = pSetupGetField(&InfContext,4))) {
  1199. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FolderName = %s !\n") ,FolderName));
  1200. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: LinkFileName = %s !\n"),LinkFileName));
  1201. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: NT4SubStr = %s !\n") ,NT4SubStr));
  1202. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: NT5SubStr = %s !\n") ,NT5SubStr));
  1203. if ( !GetGenericUserFolderDirectory(FolderName,szSrcPath))
  1204. goto err1;
  1205. ConcatenatePaths(szSrcPath,LinkFileName,MAX_PATH);
  1206. if (SUCCEEDED (FixPathInLink(szSrcPath,NT4SubStr,NT5SubStr))) {
  1207. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FixPathInLink OK ! %s,%s,%s!\n") ,szSrcPath,NT4SubStr,NT5SubStr));
  1208. } else {
  1209. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink: FixPathInLink Failed !%s,%s,%s!\n") ,szSrcPath,NT4SubStr,NT5SubStr));
  1210. }
  1211. }
  1212. }
  1213. bRet = TRUE;
  1214. err1:
  1215. return bRet;
  1216. }
  1217. BOOL FixGenericDirectory(HINF hInf)
  1218. {
  1219. BOOL bRet = FALSE;
  1220. INFCONTEXT InfContext;
  1221. UINT LineCount,LineNo;
  1222. LPCTSTR SectionName = TEXT("DirectoryToRename");
  1223. LPCTSTR SrcName;
  1224. LPCTSTR DstName;
  1225. TCHAR ExpSrcName[MAX_PATH];
  1226. TCHAR ExpDstName[MAX_PATH];
  1227. DWORD dwSize, dwType;
  1228. LONG lResult;
  1229. if(hInf == INVALID_HANDLE_VALUE) {
  1230. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Open femgrate.inf failed !\n")));
  1231. return FALSE;
  1232. }
  1233. LineCount = (UINT)SetupGetLineCount(hInf,SectionName);
  1234. if((LONG)LineCount <= 0) {
  1235. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] line count == 0 !\n")));
  1236. goto err1;
  1237. }
  1238. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1239. if (SetupGetLineByIndex(hInf,SectionName,LineNo,&InfContext)
  1240. && (SrcName = pSetupGetField(&InfContext,1))
  1241. && (DstName = pSetupGetField(&InfContext,2))) {
  1242. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Line# [%d] !\n"),LineNo));
  1243. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] SrcName = %s !\n"),SrcName));
  1244. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DstName = %s !\n"),DstName));
  1245. ExpandEnvironmentStrings (SrcName, ExpSrcName, MAX_PATH);
  1246. ExpandEnvironmentStrings (DstName, ExpDstName, MAX_PATH);
  1247. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpSrcName = %s\n"),ExpSrcName));
  1248. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpDstName = %s\n"),ExpDstName));
  1249. if (! IsDirExisting(ExpSrcName)) {
  1250. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] szExpSrcName doesn't exist, do nothing ! %s\n"),ExpSrcName));
  1251. continue;
  1252. }
  1253. if (RenameDirectory(ExpSrcName,ExpDstName)) {
  1254. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] Rename %s to %s OK !\n"),ExpSrcName,ExpDstName));
  1255. } else {
  1256. DebugMsg((DM_VERBOSE, TEXT("[FixGenericDirectory] Rename %s to %s FAIL!\n"),ExpSrcName,ExpDstName));
  1257. }
  1258. }
  1259. }
  1260. bRet = TRUE;
  1261. err1:
  1262. return bRet;
  1263. }
  1264. BOOL FixPartialFileName(HINF hInf)
  1265. {
  1266. BOOL bRet = FALSE;
  1267. INFCONTEXT InfContext;
  1268. UINT LineCount,LineNo;
  1269. LPCTSTR SectionName = TEXT("Generic.PartialRename");
  1270. LPCTSTR DirName;
  1271. LPCTSTR SrcName;
  1272. LPCTSTR DstName;
  1273. LPCTSTR ExtName;
  1274. TCHAR SrcPathName[MAX_PATH];
  1275. TCHAR CurPathName[MAX_PATH];
  1276. TCHAR DstPathName[MAX_PATH];
  1277. DWORD dwSize, dwType;
  1278. LONG lResult;
  1279. HANDLE hFile;
  1280. WIN32_FIND_DATA fd;
  1281. LPTSTR SrcDirEnd;
  1282. LPTSTR DstDirEnd;
  1283. LPTSTR CurDirEnd;
  1284. if(hInf == INVALID_HANDLE_VALUE) {
  1285. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Open femgrate.inf failed !\n")));
  1286. return FALSE;
  1287. }
  1288. LineCount = (UINT)SetupGetLineCount(hInf,SectionName);
  1289. if((LONG)LineCount <= 0) {
  1290. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] line count == 0 !\n")));
  1291. goto err1;
  1292. }
  1293. for(LineNo=0; LineNo<LineCount; LineNo++) {
  1294. if (SetupGetLineByIndex(hInf,SectionName,LineNo,&InfContext)
  1295. && (DirName = pSetupGetField(&InfContext,1))
  1296. && (SrcName = pSetupGetField(&InfContext,2))
  1297. && (DstName = pSetupGetField(&InfContext,3))) {
  1298. ExtName = pSetupGetField(&InfContext,4);
  1299. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Line# [%d] !\n"),LineNo));
  1300. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DirName = %s !\n"),DirName));
  1301. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] SrcName = %s !\n"),SrcName));
  1302. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] DstName = %s !\n"),DstName));
  1303. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] ExtName = %s !\n"),ExtName));
  1304. ExpandEnvironmentStrings (DirName, SrcPathName, MAX_PATH);
  1305. ExpandEnvironmentStrings (DirName, CurPathName, MAX_PATH);
  1306. ExpandEnvironmentStrings (DirName, DstPathName, MAX_PATH);
  1307. SrcDirEnd = CheckSlash (SrcPathName);
  1308. DstDirEnd = CheckSlash (DstPathName);
  1309. CurDirEnd = CheckSlash (CurPathName);
  1310. lstrcat(SrcPathName,SrcName);
  1311. lstrcat(SrcPathName,TEXT("*"));
  1312. lstrcat(SrcPathName,ExtName);
  1313. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] Source = %s !\n"),SrcPathName));
  1314. hFile = FindFirstFile (SrcPathName, &fd);
  1315. if (hFile != INVALID_HANDLE_VALUE) {
  1316. do {
  1317. LPCTSTR ExtraPtr = fd.cFileName+lstrlen(SrcName);
  1318. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] fd.cFileName = %s !\n"),fd.cFileName));
  1319. DebugMsg((DM_VERBOSE,TEXT("[FixGenericDirectory] ExtraPtr = %s !\n"),ExtraPtr));
  1320. lstrcat(DstDirEnd,DstName);
  1321. lstrcat(DstDirEnd,ExtraPtr);
  1322. lstrcat(CurDirEnd,fd.cFileName);
  1323. DebugMsg((DM_VERBOSE, TEXT("%s %s\n"),SrcPathName,DstPathName));
  1324. RenameFile(CurPathName,DstPathName);
  1325. } while (FindNextFile(hFile, &fd));
  1326. FindClose (hFile);
  1327. }
  1328. }
  1329. }
  1330. bRet = TRUE;
  1331. err1:
  1332. return bRet;
  1333. }
  1334. BOOL RenameSBKANAFiles(
  1335. HINF hInf)
  1336. /*
  1337. [WallPaper.Files]
  1338. BMP files
  1339. [Sound.Files]
  1340. Sound Files
  1341. */
  1342. {
  1343. BOOL bResult;
  1344. TCHAR WinDir[MAX_PATH];
  1345. TCHAR Directory[MAX_PATH];
  1346. GetWindowsDirectory(WinDir,sizeof(WinDir)/sizeof(WinDir[0]));
  1347. bResult = RenameSectionFiles(hInf,
  1348. TEXT("WallPaper.Files"),
  1349. WinDir,
  1350. WinDir);
  1351. DebugMsg((DM_VERBOSE, TEXT("[RenameAllFiles] Rename [WallPaper.Files] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1352. lstrcpy(Directory,WinDir);
  1353. ConcatenatePaths(Directory,TEXT("Media"),MAX_PATH);
  1354. bResult = RenameSectionFiles(hInf,
  1355. TEXT("Sound.Files"),
  1356. Directory,
  1357. Directory);
  1358. DebugMsg((DM_VERBOSE, TEXT("[RenameAllFiles] Rename [Sound.Files] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1359. return TRUE;
  1360. }
  1361. BOOL RenameSBKANARegSZ(
  1362. HINF hInf)
  1363. /*
  1364. [WallPaper.Files]
  1365. BMP files
  1366. [Sound.Files]
  1367. Sound Files
  1368. */
  1369. {
  1370. BOOL bResult;
  1371. TCHAR WinDir[MAX_PATH];
  1372. TCHAR Directory[MAX_PATH];
  1373. bResult = RenameSectionRegSZ(hInf,
  1374. TEXT("Cursor_Scheme_Reg"),
  1375. HKEY_CURRENT_USER,
  1376. TEXT("Control Panel\\Cursors\\Schemes"));
  1377. DebugMsg((DM_VERBOSE, TEXT("[RenameSBKANARegSZ] Rename [Cursor_Scheme_Reg] %s !\n"),bResult ? TEXT("OK") : TEXT("FAIL")));
  1378. return TRUE;
  1379. }
  1380. int WINAPI WinMainJPN(
  1381. int nCmd,
  1382. HINF hMigrateInf)
  1383. {
  1384. const UINT nLocale = LOCALE_JPN;
  1385. switch(nCmd) {
  1386. case FUNC_PatchInSetup:
  1387. if (IsInSetupUpgradeMode() == FALSE) {
  1388. DebugMsg((DM_VERBOSE,TEXT("This is NOT upgrade \n")));
  1389. break;
  1390. }
  1391. DebugMsg((DM_VERBOSE,TEXT("..................This is upgrade \n")));
  1392. if (FixFoldersInSetup(hMigrateInf,TRUE)) {
  1393. if (FixCommon(hMigrateInf)) {
  1394. if (RenameProgramFolderOrLink(hMigrateInf,TRUE)) {
  1395. DebugMsg((DM_VERBOSE,TEXT("All Users, RenameProgramFolderOrLink() ok ! \n")));
  1396. }
  1397. else {
  1398. DebugMsg((DM_VERBOSE,TEXT("All Users, RenameProgramFolderOrLink() failed ! \n")));
  1399. }
  1400. }
  1401. else {
  1402. DebugMsg((DM_VERBOSE,TEXT("All Users, FixCommon() failed ! \n")));
  1403. }
  1404. }
  1405. else {
  1406. DebugMsg((DM_VERBOSE,TEXT("All Users, FixFoldersInSetup() failed ! \n")));
  1407. }
  1408. if (FixFoldersInSetup(hMigrateInf,FALSE)) {
  1409. if (RenameProgramFolderOrLink(hMigrateInf,FALSE)) {
  1410. DebugMsg((DM_VERBOSE,TEXT("Default User, RenameProgramFolderOrLink() ok ! \n")));
  1411. }
  1412. else {
  1413. DebugMsg((DM_VERBOSE,TEXT("Default User, RenameProgramFolderOrLink() failed ! \n")));
  1414. }
  1415. }
  1416. else {
  1417. DebugMsg((DM_VERBOSE,TEXT("Default User, FixFoldersInSetup() failed ! \n")));
  1418. }
  1419. if (RenameSBKANAFiles(hMigrateInf)) {
  1420. DebugMsg((DM_VERBOSE,TEXT("Fix Sound Settings OK ! \n")));
  1421. }
  1422. else {
  1423. DebugMsg((DM_VERBOSE,TEXT("Fix Sound Settings failed ! \n")));
  1424. }
  1425. if (FixSoundRegValue(hMigrateInf)) {
  1426. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue OK ! \n")));
  1427. }
  1428. else {
  1429. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue failed ! \n")));
  1430. }
  1431. if (FixTimeZone(nLocale)) {
  1432. DebugMsg((DM_VERBOSE,TEXT("FixTimeZone OK ! \n")));
  1433. }
  1434. else {
  1435. DebugMsg((DM_VERBOSE,TEXT("FixTimeZone failed ! \n")));
  1436. }
  1437. if (FixSBKanaRegValue(hMigrateInf)) {
  1438. DebugMsg((DM_VERBOSE,TEXT("FixSBKanaRegValue OK ! \n")));
  1439. } else {
  1440. DebugMsg((DM_VERBOSE,TEXT("FixSBKanaRegValue Failed ! \n")));
  1441. }
  1442. //
  1443. // FixSBIniSectionWithDBIniSection first and then FixSBIniKeyWithDBIniKey
  1444. //
  1445. if (FixSBIniSectionWithDBIniSection(hMigrateInf)) {
  1446. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection OK ! \n")));
  1447. } else {
  1448. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection failed ! \n")));
  1449. }
  1450. if (FixSBIniKeyWithDBIniKey(hMigrateInf)) {
  1451. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection OK ! \n")));
  1452. } else {
  1453. DebugMsg((DM_VERBOSE,TEXT("FixSBSectionWithDBSection failed ! \n")));
  1454. }
  1455. if (FixGenericDirectory(hMigrateInf)) {
  1456. DebugMsg((DM_VERBOSE,TEXT("FixGenericDirectory OK ! \n")));
  1457. } else {
  1458. DebugMsg((DM_VERBOSE,TEXT("FixGenericDirectory failed ! \n")));
  1459. }
  1460. if (FixGenericLink(hMigrateInf)) {
  1461. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1462. } else {
  1463. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1464. }
  1465. if (FixPartialFileName(hMigrateInf)) {
  1466. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1467. } else {
  1468. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1469. }
  1470. if (RenameSBKANARegSZ(hMigrateInf)) {
  1471. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ OK ! \n")));
  1472. } else {
  1473. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ failed ! \n")));
  1474. }
  1475. break;
  1476. case FUNC_PatchInLogon:
  1477. if (FixUserFolders(hMigrateInf)) {
  1478. if (RenameProgramFolderOrLink(hMigrateInf,FALSE)) {
  1479. DebugMsg((DM_VERBOSE,TEXT("Current User, RenameProgramFolderOrLink() ok ! \n")));
  1480. }
  1481. else {
  1482. DebugMsg((DM_VERBOSE,TEXT("Current User, RenameProgramFolderOrLink() failed ! \n")));
  1483. }
  1484. }
  1485. else {
  1486. DebugMsg((DM_VERBOSE,TEXT("Current User, FixFoldersInSetup() failed ! \n")));
  1487. }
  1488. if (FixSpecificFolder(hMigrateInf)) {
  1489. DebugMsg((DM_VERBOSE,TEXT("Current User, FixSpecificFolder() ok ! \n")));
  1490. } else {
  1491. DebugMsg((DM_VERBOSE,TEXT("Current User, FixSpecificFolder() failed ! \n")));
  1492. }
  1493. if (FixAppearanceScheme(hMigrateInf)) {
  1494. DebugMsg((DM_VERBOSE,TEXT("FixAppearanceScheme OK ! \n")));
  1495. } else {
  1496. DebugMsg((DM_VERBOSE,TEXT("FixAppearanceScheme Failed ! \n")));
  1497. }
  1498. if (FixSchemeProblem(TRUE,hMigrateInf)) {
  1499. DebugMsg((DM_VERBOSE,TEXT("FixSchemeProblem OK ! \n")));
  1500. }
  1501. else {
  1502. DebugMsg((DM_VERBOSE,TEXT("FixSchemeProblem Fail ! \n")));
  1503. }
  1504. if (FixSoundRegValue(hMigrateInf)) {
  1505. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue OK ! \n")));
  1506. }
  1507. else {
  1508. DebugMsg((DM_VERBOSE,TEXT("FixSoundRegValue failed ! \n")));
  1509. }
  1510. if (FixPatterns(hMigrateInf)) {
  1511. DebugMsg((DM_VERBOSE,TEXT("FixPatterns OK ! \n")));
  1512. }
  1513. else {
  1514. DebugMsg((DM_VERBOSE,TEXT("FixPatterns failed ! \n")));
  1515. }
  1516. if (FixCurrentWallPaperInDeskTop(hMigrateInf)) {
  1517. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop OK ! \n")));
  1518. }
  1519. else {
  1520. DebugMsg((DM_VERBOSE,TEXT("FixCurrentWallPaperInDeskTop failed ! \n")));
  1521. }
  1522. if (FixGenericLink(hMigrateInf)) {
  1523. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1524. } else {
  1525. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1526. }
  1527. if (FixPartialFileName(hMigrateInf)) {
  1528. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink OK ! \n")));
  1529. } else {
  1530. DebugMsg((DM_VERBOSE,TEXT("FixGenericLink failed ! \n")));
  1531. }
  1532. if (FixPathInProfileLink(hMigrateInf)) {
  1533. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink OK ! \n")));
  1534. } else {
  1535. DebugMsg((DM_VERBOSE,TEXT("FixPathInProfileLink failed ! \n")));
  1536. }
  1537. if (RenameSBKANARegSZ(hMigrateInf)) {
  1538. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ OK ! \n")));
  1539. } else {
  1540. DebugMsg((DM_VERBOSE,TEXT("RenameSBKANARegSZ failed ! \n")));
  1541. }
  1542. if (RenameRegValueName(hMigrateInf,TRUE)) {
  1543. DebugMsg((DM_VERBOSE,TEXT("RenameRegValueName OK ! \n")));
  1544. } else {
  1545. DebugMsg((DM_VERBOSE,TEXT("RenameRegValueName failed ! \n")));
  1546. }
  1547. break;
  1548. case FUNC_PatchPreload:
  1549. if (PatchPreloadKeyboard(FALSE)) {
  1550. DebugMsg((DM_VERBOSE,TEXT("PatchPreloadKeyboard OK ! \n")));
  1551. } else {
  1552. DebugMsg((DM_VERBOSE,TEXT("PatchPreloadKeyboard Failed ! \n")));
  1553. }
  1554. break;
  1555. case FUNC_PatchTest:
  1556. break;
  1557. default:
  1558. DebugMsg((DM_VERBOSE,TEXT("No such function\n")));
  1559. }
  1560. return (0);
  1561. }