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.

286 lines
7.1 KiB

  1. /*
  2. Modifications:
  3. 01.10.94 Joe Holman Added DISK_TO_START_NUMBERING_AT because
  4. we now have 2 bootdisks, thus we to start
  5. making floppies on disk # 3.
  6. 01.11.94 Joe Holman Change value back to 2.
  7. 05.05.94 Joe Holman Change # to 1.
  8. 06.14.94 Joe Holman Change # to 2 for German Media.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <windows.h>
  14. #include <time.h>
  15. #include "general.h"
  16. FILE* logFile;
  17. char* product;
  18. int useCdPath;
  19. void Header(argv)
  20. char* argv[];
  21. {
  22. time_t t;
  23. PRINT1("\n=========== LAYOUT =============\n")
  24. PRINT2("Input BOM: %s\n",argv[2])
  25. PRINT2("Output Layout: %s\n",argv[3])
  26. PRINT2("Product: %s\n",argv[4])
  27. PRINT2("Floppy Size: %s\n",argv[5])
  28. time(&t); PRINT2("Time: %s",ctime(&t))
  29. PRINT1("================================\n\n");
  30. }
  31. void Usage()
  32. {
  33. printf("PURPOSE: Assigns files to disks and generates a layout file.\n");
  34. printf("\n");
  35. printf("PARAMETERS:\n");
  36. printf("\n");
  37. printf("[LogFile] - Path to append a log of actions and errors.\n");
  38. printf("[InBom] - Path of BOM for which a layout is to be made.\n");
  39. printf("[OutLayout] - Path of new layout.\n");
  40. printf("[Product] - Product to lay out.\n");
  41. printf(" NTFLOP = Windows NT on floppy\n");
  42. printf(" LMFLOP = Lan Manager on floppy\n");
  43. printf(" NTCD = Windows NT on CD\n");
  44. printf(" LMCD = Lan Manager on CD\n");
  45. printf(" SDK = Software Development Kit\n");
  46. printf("[FloppySize] - Size in bytes of the second disk.\n\n");
  47. }
  48. int __cdecl PrioritySizeNameCompare(const void*,const void*);
  49. int Same(e1,e2)
  50. Entry* e1;
  51. Entry* e2;
  52. {
  53. char *p1, *p2;
  54. if (useCdPath)
  55. {
  56. p1=e1->cdpath;
  57. p2=e2->cdpath;
  58. }
  59. else
  60. {
  61. p1="x";
  62. p2=p1;
  63. }
  64. return( (!_stricmp(e1->name,e2->name)) &&
  65. (!_stricmp(e1->path,e2->path)) &&
  66. (!_stricmp(e1->source,e2->source)) &&
  67. (!_stricmp(p1,p2)));
  68. }
  69. void LayoutAssignDisks(e,diskSize,records)
  70. Entry* e;
  71. int diskSize;
  72. int records;
  73. {
  74. int disk;
  75. int freeSpace, i, itemSize, totalUnassigned;
  76. int lastUnassignedPriority;
  77. //
  78. // For the CD-ROM case, all files go on disk 1.
  79. //
  80. if(useCdPath) {
  81. for(i=0; i<records; i++) {
  82. e[i].disk = 1;
  83. }
  84. return;
  85. }
  86. //
  87. // Start out with all files not assigned to any disk.
  88. //
  89. totalUnassigned = records;
  90. for(i=0; i<records; i++) {
  91. //
  92. // Note files that are hard-coded to a particular disk.
  93. //
  94. if(e[i].disk > 0) {
  95. totalUnassigned--;
  96. }
  97. }
  98. //
  99. // The way the infs and [Source Media Descriptions] sections
  100. // are written, there MUST be a disk 1. So start with disk 1.
  101. // Disk 1 will actually be disk 4 because of the boot floppies,
  102. // but that's not important here.
  103. //
  104. disk = 1;
  105. do {
  106. //
  107. // Disk is initially empty.
  108. //
  109. freeSpace = diskSize;
  110. //
  111. // Look for files that are hardcoded to the current disk.
  112. // Reduce the amount of free space available on the current disk
  113. // accordingly.
  114. //
  115. for(i=0; i<records; i++) {
  116. if((e[i].disk == disk) && (!i || !Same(&e[i],&e[i-1]))) {
  117. freeSpace -= _stricmp(e[i].nocompress,"x") ? e[i].csize : e[i].size;
  118. }
  119. }
  120. lastUnassignedPriority = 1000;
  121. for(i=0; i<records; i++) {
  122. //
  123. // If the current file is unassigned, attempt to assign it
  124. // to a disk.
  125. //
  126. if(e[i].disk == 0) {
  127. //
  128. // If this is the same file as the preceeding entry,
  129. // we're done with this file.
  130. //
  131. if(i && Same(&e[i],&e[i-1])) {
  132. e[i].disk = e[i-1].disk;
  133. } else {
  134. itemSize = _stricmp(e[i].nocompress,"x") ? e[i].csize : e[i].size;
  135. //
  136. // If there is enough space on the current disk for this file,
  137. // assign the file to the current disk and adjust the amount of
  138. // free space remaining accordingly.
  139. //
  140. if(freeSpace >= itemSize) {
  141. if((e[i].priority <= lastUnassignedPriority)
  142. || ((e[i].priority == 999) && (lastUnassignedPriority>9)))
  143. {
  144. e[i].disk = disk;
  145. freeSpace -= itemSize;
  146. }
  147. } else if(itemSize >= diskSize) {
  148. PRINT2("ERROR File %s is too big for any disk. Assigned to disk 999.\n",e[i].name)
  149. e[i].disk = 999;
  150. } else if(lastUnassignedPriority == 1000) {
  151. lastUnassignedPriority = e[i].priority;
  152. }
  153. }
  154. //
  155. // If we successfully assigned this file to a disk,
  156. // note that fact here.
  157. //
  158. if(e[i].disk) {
  159. totalUnassigned--;
  160. }
  161. }
  162. }
  163. PRINT3("INFO Disk: %2.d Free Space: %7.d\n",disk,freeSpace)
  164. //
  165. // Move to next disk.
  166. //
  167. disk++;
  168. } while(totalUnassigned);
  169. }
  170. __cdecl main(argc,argv)
  171. int argc;
  172. char* argv[];
  173. {
  174. FILE *outLayout;
  175. Entry *e;
  176. int records,i;
  177. char *buf;
  178. if (argc!=6) { Usage(); return(1); }
  179. if ((logFile=fopen(argv[1],"a"))==NULL)
  180. {
  181. printf("ERROR Couldn't open log file %s\n",argv[1]);
  182. return(1);
  183. }
  184. Header(argv);
  185. LoadFile(argv[2],&buf,&e,&records,argv[4]);
  186. if (MyOpenFile(&outLayout,argv[3],"wb")) return(1);
  187. if (!_stricmp(argv[4],"ntflop") || !_stricmp(argv[4],"lmflop"))
  188. useCdPath=0;
  189. else
  190. useCdPath=1;
  191. //
  192. // munge the compress flag depending on the product type.
  193. // if we are laying out floppies, then files are always
  194. // compressed unless a special flag is set in the bom.
  195. //
  196. if(!useCdPath) {
  197. for (i=0;i<records;i++) {
  198. if(_strnicmp(e[i].nocompress,"xfloppy",7)) {
  199. //
  200. // not xfloppy; not uncompressed.
  201. //
  202. e[i].nocompress = "";
  203. } else {
  204. e[i].nocompress = "x";
  205. }
  206. }
  207. }
  208. qsort(e,records,sizeof(Entry),PrioritySizeNameCompare);
  209. LayoutAssignDisks(e,atoi(argv[5]),records);
  210. i=0; while ((fputc(buf[i++],outLayout))!='\n');
  211. for (i=0;i<records;i++)
  212. EntryPrint(&e[i],outLayout);
  213. fclose(outLayout);
  214. fclose(logFile);
  215. free(e);
  216. return(0);
  217. }
  218. int __cdecl PrioritySizeNameCompare(const void *v1, const void *v2)
  219. {
  220. int result;
  221. Entry *e1 = (Entry *)v1;
  222. Entry *e2 = (Entry *)v2;
  223. if (e1->priority!=e2->priority)
  224. return(e1->priority-e2->priority);
  225. if (e1->size!=e2->size)
  226. return(e2->size-e1->size);
  227. if (result=_stricmp(e1->name,e2->name))
  228. return(result);
  229. if (useCdPath)
  230. return(_stricmp(e1->cdpath,e2->cdpath));
  231. else
  232. return(0); // always the same for floppies
  233. }