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.

305 lines
9.9 KiB

  1. /****************************************************************************\
  2. SRCPATH.C / Factory Mode (FACTORY.EXE)
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 2001
  5. All rights reserved
  6. Source file for Factory that contains the reset source path state
  7. functions.
  8. 05/2001 - Jason Cohen (JCOHEN)
  9. Added this new source file for factory for configuring the source path
  10. in the registry.
  11. \****************************************************************************/
  12. //
  13. // Include File(s):
  14. //
  15. #include "factoryp.h"
  16. //
  17. // Internal Define(s):
  18. //
  19. #define FILE_DOSNET_INF _T("dosnet.inf")
  20. #define DIR_I386 _T("i386")
  21. #define DIR_IA64 _T("ia64")
  22. #define INI_SEC_DIRS _T("Directories")
  23. #define INI_KEY_DIR _T("d%d")
  24. #define NUM_FIRST_SOURCE_DX 1
  25. //
  26. // Internal Function Prototypes:
  27. //
  28. static BOOL MoveSourceFiles(LPTSTR lpszSrc, LPTSTR lpszDst, LPTSTR lpszInfFile, BOOL bCheckOnly);
  29. //
  30. // External Function(s):
  31. //
  32. BOOL ResetSource(LPSTATEDATA lpStateData)
  33. {
  34. BOOL bRet = TRUE;
  35. LPTSTR lpszSourcePath;
  36. if ( lpszSourcePath = IniGetExpand(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_RESETSOURCE, NULL) )
  37. {
  38. TCHAR szPath[MAX_PATH] = NULLSTR,
  39. szSrcPath[MAX_PATH];
  40. LPTSTR lpszDirName = NULL,
  41. lpszCabs = GET_FLAG(g_dwFactoryFlags, FLAG_IA64_MODE) ? DIR_IA64 : DIR_I386,
  42. lpszEnd;
  43. //
  44. // The source path needs to point to the folder that has the i386 directory in it,
  45. // so lets do some checking and make sure they knew this when they specified the key.
  46. //
  47. // First make sure there is no trailing backslash (even if it is the root folder).
  48. //
  49. if ( _T('\\') == *(lpszEnd = CharPrev(lpszSourcePath, lpszSourcePath + lstrlen(lpszSourcePath))) )
  50. {
  51. *lpszEnd = NULLCHR;
  52. }
  53. // Now get the full path and a pointer to the last folder name.
  54. //
  55. GetFullPathName(lpszSourcePath, AS(szPath), szPath, &lpszDirName);
  56. if ( szPath[0] && lpszDirName )
  57. {
  58. // See if the directory name is i386/ia64.
  59. //
  60. lpszEnd = szPath + lstrlen(szPath);
  61. if ( lstrcmpi(lpszDirName, lpszCabs) == 0 )
  62. {
  63. // Double check that there actually isn't an i386\i386 / ia64\ia64 folder.
  64. //
  65. AddPathN(szPath, lpszCabs, AS(szPath));
  66. if ( !DirectoryExists(szPath) )
  67. {
  68. // Remove the i386/ia64 because they should not have specified it.
  69. //
  70. *CharPrev(szPath, lpszDirName) = NULLCHR;
  71. }
  72. else
  73. {
  74. // The i386\i386 / ia64\ia64 folder really does exist, so put the path
  75. // back the way it was and use it.
  76. //
  77. *lpszEnd = NULLCHR;
  78. }
  79. }
  80. else if ( DirectoryExists(szPath) )
  81. {
  82. // Lets double check that they didn't put the i386/ia64 files in a folder
  83. // with another name.
  84. //
  85. AddPathN(szPath, FILE_DOSNET_INF, AS(szPath));
  86. if ( FileExists(szPath) )
  87. {
  88. // Well this is kind of bad. We can either log an error warning them that
  89. // this really won't work, or we could automatically rename the folder. The
  90. // only possible problem would be on ia64 if they didn't also have the i386 folder.
  91. // But maybe that isn't really that big of a deal, so I think that I might just rename
  92. // the folder.
  93. //
  94. *lpszEnd = NULLCHR;
  95. lstrcpyn(szSrcPath, szPath, AS(szSrcPath));
  96. lstrcpyn(lpszDirName, lpszCabs, AS(szPath) - (int) (lpszDirName - szPath));
  97. // ISSUE-2002/02/26-acosma,robertko - There is no check for success here and this code is really confusing!
  98. // Where are we moving to?
  99. //
  100. MoveFile(szSrcPath, szPath);
  101. }
  102. else
  103. {
  104. // If the source doesn't exist there, then maybe they haven't copied it yet. So we
  105. // will just have to assume that they know what they are doing and put the path back
  106. // the way we got it.
  107. //
  108. *lpszEnd = NULLCHR;
  109. }
  110. }
  111. }
  112. //
  113. // Now set the path in the registry.
  114. //
  115. bRet = UpdateSourcePath(szPath[0] ? szPath : lpszSourcePath);
  116. // Don't need this guy anymore.
  117. //
  118. FREE(lpszSourcePath);
  119. //
  120. // Now see if we have the sources in the root of the drive, which is where we put
  121. // them on a default config set install.
  122. //
  123. // We can check to see if we need to move the sources from the root if we have a
  124. // full path (that is more than just the root) so we know what drive to check the
  125. // root of (which must be a fixed drive).
  126. //
  127. lstrcpyn(szSrcPath, szPath, 4);
  128. if ( ( lstrlen(szPath) > 3 ) &&
  129. ( _T(':') == szPath[1] ) &&
  130. ( GetDriveType(szSrcPath) == DRIVE_FIXED ) )
  131. {
  132. TCHAR szDosNetInf[MAX_PATH];
  133. // Now use that source and the i386/ia64 folder to find the dos net inf
  134. // file.
  135. //
  136. lstrcpyn(szDosNetInf, szSrcPath, AS(szDosNetInf));
  137. AddPathN(szDosNetInf, lpszCabs, AS(szDosNetInf));
  138. AddPathN(szDosNetInf, FILE_DOSNET_INF, AS(szDosNetInf));
  139. //
  140. // If it is all good, go ahead and move the sources.
  141. //
  142. if ( !MoveSourceFiles(szSrcPath, szPath, szDosNetInf, FALSE) )
  143. {
  144. // We should log an error here, but we can do it for the
  145. // next release.
  146. //
  147. // ISSUE-2002/02/25-acosma,robertko - Should we really set this to false to fail the state if something
  148. // went wrong during the copy? Or we just go on like nothing ever happened?
  149. //
  150. //bRet = FALSE;
  151. }
  152. }
  153. }
  154. return bRet;
  155. }
  156. BOOL DisplayResetSource(LPSTATEDATA lpStateData)
  157. {
  158. return IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_RESETSOURCE, NULL);
  159. }
  160. //
  161. // Internal Function(s):
  162. //
  163. static BOOL MoveSourceFiles(LPTSTR lpszSrc, LPTSTR lpszDst, LPTSTR lpszInfFile, BOOL bCheckOnly)
  164. {
  165. TCHAR szInf[MAX_PATH],
  166. szSrc[MAX_PATH],
  167. szDst[MAX_PATH];
  168. LPTSTR lpszEndSrc,
  169. lpszEndDst;
  170. DWORD dwLoop = NUM_FIRST_SOURCE_DX;
  171. BOOL bRet = FALSE,
  172. bMore;
  173. TCHAR szDirKey[32],
  174. szDir[MAX_PATH];
  175. // We have to have the dos net file.
  176. //
  177. if ( !FileExists(lpszInfFile) )
  178. {
  179. return FALSE;
  180. }
  181. // Make our local copies of the inf, source, and destination buffers.
  182. //
  183. lstrcpyn(szInf, lpszInfFile, AS(szInf));
  184. lstrcpyn(szSrc, lpszSrc, AS(szSrc));
  185. lstrcpyn(szDst, lpszDst, AS(szDst));
  186. lpszEndSrc = szSrc + lstrlen(szSrc);
  187. lpszEndDst = szDst + lstrlen(szDst);
  188. // Loop through all the directories listed in the dos net file.
  189. //
  190. do
  191. {
  192. // Create the key we want to look for in the inf file.
  193. //
  194. if ( FAILED ( StringCchPrintf ( szDirKey, AS ( szDirKey ), INI_KEY_DIR, dwLoop++) ) )
  195. {
  196. FacLogFileStr(3, _T("StringCchPrintf failed %s %d" ), szDirKey, dwLoop );
  197. }
  198. // Now see if that key exists.
  199. //
  200. szDir[0] = NULLCHR;
  201. if ( bMore = ( GetPrivateProfileString(INI_SEC_DIRS, szDirKey, NULLSTR, szDir, AS(szDir), szInf) && szDir[0] ) )
  202. {
  203. // If we copy at least one folder, then return TRUE by default.
  204. //
  205. bRet = TRUE;
  206. // We may need to reset our root destination and source paths.
  207. //
  208. *lpszEndSrc = NULLCHR;
  209. *lpszEndDst = NULLCHR;
  210. // Now setup the destination and source paths.
  211. //
  212. AddPathN(szSrc, szDir, AS(szSrc));
  213. AddPathN(szDst, szDir, AS(szDst));
  214. // Move the directory (or see if it can be moved), if it fails we
  215. // should error and bail.
  216. //
  217. if ( bCheckOnly )
  218. {
  219. // If we are just checking, then make sure the destination
  220. // directory doesn't already exist.
  221. //
  222. bRet = bMore = ( DirectoryExists(szSrc) && !DirectoryExists(szDst) );
  223. }
  224. else
  225. {
  226. // If parent directory does not exists then we must create it, otherwise the MoveFile will fail
  227. //
  228. if ( !DirectoryExists(lpszDst) )
  229. {
  230. CreatePath(lpszDst);
  231. }
  232. // If the move failed, stop.
  233. //
  234. bRet = bMore = MoveFile(szSrc, szDst);
  235. // We might have moved the inf file.
  236. //
  237. if ( bRet )
  238. {
  239. int iLen = lstrlen(szSrc);
  240. if ( CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, szSrc, iLen, szInf, iLen) == CSTR_EQUAL )
  241. {
  242. TCHAR szInfName[MAX_PATH];
  243. lstrcpyn(szInfName, szInf + iLen, AS(szInfName));
  244. lstrcpyn(szInf, szDst, AS(szInf));
  245. AddPathN(szInf, szInfName, AS(szInf));
  246. }
  247. }
  248. }
  249. }
  250. }
  251. while ( bMore );
  252. // Return if it is okay to copy (if check only is set) or if there was an error.
  253. //
  254. return bRet;
  255. }