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.

439 lines
12 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <time.h>
  6. #include "general.h"
  7. #define MAX_DISKS 40
  8. //
  9. // Macro for rounding up any number (x) to multiple of (n) which
  10. // must be a power of 2. For example, ROUNDUP( 2047, 512 ) would
  11. // yield result of 2048.
  12. //
  13. #define ROUNDUP2( x, n ) (((x) + ((n) - 1 )) & ~((n) - 1 ))
  14. FILE* logFile;
  15. int cdProduct;
  16. //HANDLE hActivateCopyThread, hCopyThreadIsAvailable;
  17. //CHAR chCopyThreadSource[ MAX_PATH ], chCopyThreadDestin[ MAX_PATH ];
  18. //CHAR chPreviousSource[ MAX_PATH ], chPreviousDestin[ MAX_PATH ];
  19. void MakeDbgName( LPCSTR pszSourceName, LPSTR pszTargetName );
  20. void DoFileCopy( LPSTR , LPSTR );
  21. //DWORD CopyThread( LPVOID lpvParam );
  22. void Msg ( const char * szFormat, ... ) {
  23. va_list vaArgs;
  24. va_start ( vaArgs, szFormat );
  25. vprintf ( szFormat, vaArgs );
  26. vfprintf ( logFile, szFormat, vaArgs );
  27. va_end ( vaArgs );
  28. }
  29. void Header(argv)
  30. char* argv[];
  31. {
  32. time_t t;
  33. Msg ("\n=========== MCPYFILE =============\n");
  34. Msg ("logfile : %s\n", argv[1] );
  35. Msg ("Input Layout: %s\n",argv[2]);
  36. Msg ("category : %s\n",argv[3]);
  37. Msg ("Compressed files: %s\n", argv[4]);
  38. Msg ("Uncompressed files : %s\n", argv[5]);
  39. Msg ("Hard drive: %s\n",argv[6]);
  40. Msg ("Copy d-DBG, x-FLOPPY, c-CDROM files: %s\n", argv[7] );
  41. time(&t);
  42. Msg ("Time: %s",ctime(&t));
  43. Msg ("==================================\n\n");
  44. }
  45. void Usage()
  46. {
  47. printf("PURPOSE: Copy files to hardrive or into disk1, disk2, ... dirs.\n");
  48. printf("\n");
  49. printf("PARAMETERS:\n");
  50. printf("\n");
  51. printf("[logFile] - Path to append a log of actions and errors.\n");
  52. printf("[InLayout] - Path of Layout which lists files to copy.\n");
  53. printf("[Category] - Specifies the category of files to copy.\n");
  54. printf("[files share] - location of Compressed files.\n" );
  55. printf("[files share] - location of Uncompressed files\n" );
  56. printf("[Harddrive] - Drive where files are stored.\n");
  57. printf("[copy dbg,floppy,or cd files] - use D for .dbg files or x for floppy files\n" );
  58. }
  59. int __cdecl main(argc,argv)
  60. int argc;
  61. char* argv[];
  62. {
  63. Entry ee;
  64. char sourcePath[MAX_PATH];
  65. char destinPath[MAX_PATH];
  66. int disks[MAX_DISKS];
  67. Entry *e;
  68. char *buf;
  69. int records,i;
  70. BOOL shouldCopy;
  71. BOOL bCompressedFile;
  72. BOOL bCopyDbgFiles;
  73. HANDLE hSource,hDestin, hThread;
  74. DWORD actualSize,bomSize, dwThreadID;
  75. WIN32_FIND_DATA fdSource, fdDestin;
  76. if ( argc != 8 ) {
  77. Usage();
  78. return(1);
  79. }
  80. if ((logFile=fopen(argv[1],"a"))==NULL) {
  81. printf("ERROR Couldn't open log file %s.\n",argv[1]);
  82. return(1);
  83. }
  84. // hActivateCopyThread = CreateEvent( NULL, FALSE, FALSE, NULL );
  85. // hCopyThreadIsAvailable = CreateEvent( NULL, FALSE, TRUE, NULL );
  86. // hThread = CreateThread( NULL, 0, CopyThread, NULL, 0, &dwThreadID );
  87. // CloseHandle( hThread );
  88. Header(argv);
  89. // Load all of the current entries in the layout file
  90. // provided to the program.
  91. //
  92. LoadFile(argv[2],&buf,&e,&records,"ALL");
  93. cdProduct = TRUE;
  94. bCopyDbgFiles = FALSE;
  95. if ( !_stricmp ( "ntflop", argv[3] ) || !_stricmp ( "lmflop", argv[3] ) ||
  96. _stricmp ( argv[7], "x" ) == 0 ) {
  97. cdProduct = FALSE;
  98. bCopyDbgFiles = FALSE;
  99. Msg ( "Making X86 Floppies...\n" );
  100. }
  101. else {
  102. Msg ( "Making CDs...\n" );
  103. bCopyDbgFiles = !_stricmp( argv[7], "d" );
  104. }
  105. Msg ( "bCopyDbgFiles = %d\n", bCopyDbgFiles );
  106. for (i=0;i<MAX_DISKS;i++) {
  107. disks[i]=0;
  108. }
  109. for (i=0;i<records;i++) {
  110. if (e[i].cdpath[strlen(e[i].cdpath)-1]=='\\') {
  111. e[i].cdpath[strlen(e[i].cdpath)-1]='\0';
  112. }
  113. if (e[i].path[strlen(e[i].path)-1]=='\\') {
  114. e[i].path[strlen(e[i].path)-1]='\0';
  115. }
  116. disks[e[i].disk]++;
  117. }
  118. for (i=0;i<records;i++) {
  119. ee=e[i];
  120. if (!_stricmp(ee.source,argv[3])) { // if category matches
  121. if ( cdProduct ) {
  122. // Making CD.
  123. //
  124. //
  125. // It's a compressed file IFF
  126. // the nocompress flag is NOT set (i.e. null) AND
  127. // we're NOT copying dbg-files.
  128. //
  129. bCompressedFile = !ee.nocompress[0] && !bCopyDbgFiles;
  130. }
  131. else {
  132. // Making x86 floppies.
  133. //
  134. // NOTE: in Layout.C, we go back to the convention of:
  135. //
  136. // "" == yes, compress this file
  137. // "x" == no don't compress this file
  138. //
  139. bCompressedFile = _stricmp(ee.nocompress, "x" );
  140. //Msg ( "%s, bCompressedFile = %d\n", ee.name, bCompressedFile );
  141. }
  142. //Msg ( "bCompressedFile = %d, %s\n", bCompressedFile, ee.name );
  143. if ( bCompressedFile ) {
  144. strcpy( sourcePath, argv[ 4 ] ); // use compressed path
  145. bomSize = ee.csize; // and compressed size
  146. }
  147. else {
  148. strcpy( sourcePath, argv[ 5 ] ); // uncompressed path
  149. bomSize = ee.size; // uncompressed size
  150. }
  151. strcat(sourcePath,ee.path);
  152. strcat(sourcePath,"\\");
  153. if ( bCompressedFile ) {
  154. convertName( ee.name, strchr( sourcePath, 0 ));
  155. }
  156. else if ( bCopyDbgFiles ) {
  157. MakeDbgName( ee.name, strchr( sourcePath, 0 ));
  158. }
  159. else {
  160. strcat( sourcePath, ee.name );
  161. }
  162. if ( cdProduct ) {
  163. strcpy(destinPath,argv[6]);
  164. if ( ! bCopyDbgFiles ) {
  165. strcat(destinPath,ee.cdpath);
  166. }
  167. }
  168. else {
  169. strcpy(destinPath,argv[6]);
  170. sprintf(&destinPath[strlen(destinPath)],"\\disk%d",ee.disk);
  171. }
  172. strcat(destinPath,"\\");
  173. if ( bCopyDbgFiles ) {
  174. MakeDbgName( ee.name, strchr( destinPath, 0 ));
  175. }
  176. else {
  177. if (ee.medianame[0]) {
  178. if ( bCompressedFile ) {
  179. convertName( ee.medianame, strchr( destinPath, 0 ));
  180. // For simplification in the BOM, we no longer
  181. // rename compressed files. I.E, any file that has
  182. // to be renamed, CANNOT be compressed.
  183. //
  184. Msg ( "ERROR: renaming compressed file not supported: %s\n",
  185. destinPath );
  186. }
  187. else {
  188. strcat( destinPath, ee.medianame );
  189. }
  190. }
  191. else {
  192. if ( bCompressedFile ) {
  193. convertName( ee.name, strchr( destinPath, 0 ));
  194. }
  195. else {
  196. strcat( destinPath, ee.name );
  197. }
  198. }
  199. }
  200. if (disks[ee.disk]>1) {
  201. hSource=FindFirstFile( sourcePath, &fdSource );
  202. if (hSource==INVALID_HANDLE_VALUE) {
  203. Msg ("ERROR Source: %s\n",sourcePath);
  204. }
  205. else {
  206. FindClose( hSource ); // close the source up.
  207. if ( !cdProduct ) {
  208. actualSize = ROUNDUP2( fdSource.nFileSizeLow,
  209. DMF_ALLOCATION_UNIT );
  210. }
  211. else {
  212. actualSize = ROUNDUP2( fdSource.nFileSizeLow,
  213. ALLOCATION_UNIT );
  214. }
  215. // Check the size of the file vs. the size in the
  216. // bom just for a verification of file sizes.
  217. // Don't do this for Dbg files, since these sizes are
  218. // never put in the layout.
  219. //
  220. if ( !bCopyDbgFiles && (bomSize < actualSize) ) {
  221. Msg ( "ERROR: disk#%d, %s Size of file: %d > BOM: %d Diff: %d\n",
  222. ee.disk,ee.name,
  223. actualSize,bomSize,actualSize-bomSize);
  224. }
  225. hDestin=FindFirstFile( destinPath, &fdDestin );
  226. if (hDestin==INVALID_HANDLE_VALUE) {
  227. // File doesn't exist, must copy it now.
  228. //
  229. // Msg ("New file %s\n", destinPath);
  230. DoFileCopy ( sourcePath, destinPath );
  231. }
  232. else {
  233. // File exists, but let's check the time stamp
  234. // to see if the source is newer.
  235. //
  236. FindClose( hDestin ); // close the destination
  237. if ( CompareFileTime(
  238. &fdSource.ftLastWriteTime,
  239. &fdDestin.ftLastWriteTime ) > 0 ) {
  240. // The source IS newer, copy the new file NOW.
  241. DoFileCopy ( sourcePath, destinPath );
  242. }
  243. }
  244. }
  245. }
  246. else {
  247. Msg ("WARNING Skipped Disk %d, File: %s\n",ee.disk,ee.name);
  248. }
  249. }
  250. }
  251. fclose(logFile);
  252. Header(argv);
  253. //WaitForSingleObject( hCopyThreadIsAvailable, INFINITE );
  254. }
  255. /**
  256. void DoThreadedCopy( LPSTR pszSource, LPSTR pszDestin ) {
  257. WaitForSingleObject( hCopyThreadIsAvailable, INFINITE );
  258. strcpy( chCopyThreadSource, pszSource );
  259. strcpy( chCopyThreadDestin, pszDestin );
  260. SetEvent( hActivateCopyThread );
  261. }
  262. ***/
  263. void DoFileCopy ( LPSTR chCopyThreadSource, LPSTR chCopyThreadDestin ) {
  264. BOOL bSuccess;
  265. UINT i, len;
  266. Msg ( "Copy: %s >>> %s\n", chCopyThreadSource, chCopyThreadDestin );
  267. bSuccess = CopyFile( chCopyThreadSource, chCopyThreadDestin, FALSE );
  268. if ( ! bSuccess ) {
  269. SetFileAttributes( chCopyThreadDestin, FILE_ATTRIBUTE_NORMAL );
  270. len = strlen( chCopyThreadDestin );
  271. for ( i = 2; i < len; i++ ) {
  272. if ( chCopyThreadDestin[ i ] == '\\' ) {
  273. chCopyThreadDestin[ i ] = '\0';
  274. CreateDirectory( chCopyThreadDestin, NULL );
  275. chCopyThreadDestin[ i ] = '\\';
  276. }
  277. }
  278. bSuccess = CopyFile( chCopyThreadSource, chCopyThreadDestin, FALSE );
  279. }
  280. if ( ! bSuccess ) {
  281. Msg ( "ERROR Source: %s\n"
  282. " Destin: %s\n"
  283. " GLE=%d\n",
  284. chCopyThreadSource,
  285. chCopyThreadDestin,
  286. GetLastError() );
  287. }
  288. }
  289. /****
  290. DWORD CopyThread( LPVOID lpvParam ) {
  291. BOOL bSuccess;
  292. UINT i, len;
  293. for(;;) {
  294. WaitForSingleObject( hActivateCopyThread, INFINITE );
  295. bSuccess = CopyFile( chCopyThreadSource, chCopyThreadDestin, FALSE );
  296. if ( ! bSuccess ) {
  297. SetFileAttributes( chCopyThreadDestin, FILE_ATTRIBUTE_NORMAL );
  298. len = strlen( chCopyThreadDestin );
  299. for ( i = 2; i < len; i++ ) {
  300. if ( chCopyThreadDestin[ i ] == '\\' ) {
  301. chCopyThreadDestin[ i ] = '\0';
  302. CreateDirectory( chCopyThreadDestin, NULL );
  303. chCopyThreadDestin[ i ] = '\\';
  304. }
  305. }
  306. bSuccess = CopyFile( chCopyThreadSource, chCopyThreadDestin, FALSE );
  307. }
  308. if ( ! bSuccess ) {
  309. Msg ( "ERROR Source: %s\n"
  310. " Destin: %s\n"
  311. " GLE=%d\n",
  312. chCopyThreadSource,
  313. chCopyThreadDestin,
  314. GetLastError() );
  315. }
  316. SetEvent( hCopyThreadIsAvailable );
  317. }
  318. return 0;
  319. }
  320. ***/
  321. void MakeDbgName( LPCSTR pszSourceName, LPSTR pszTargetName ) {
  322. //
  323. // Converts "filename.ext" into "ext\filename.dbg".
  324. //
  325. const char *p = strchr( pszSourceName, '.' );
  326. if ( p != NULL ) {
  327. strcpy( pszTargetName, p + 1 ); // old extension
  328. strcat( pszTargetName, "\\" ); // path separator
  329. strcat( pszTargetName, pszSourceName ); // base name
  330. strcpy( strchr( pszTargetName, '.' ), ".dbg" ); // new extension
  331. }
  332. else {
  333. strcpy( pszTargetName, pszSourceName );
  334. }
  335. }