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.

3255 lines
109 KiB

  1. //****************************************************************************
  2. //* Author: Aaron Lee
  3. //* Purpose: Create .DDF and .INF files for specified files
  4. //******************************************************************************/
  5. /*
  6. ; ------------------------------------------------------------------------------------
  7. ; Format for this file
  8. ;
  9. ; position 1 = nts_x86 flag
  10. ; position 2 = ntw_x86 flag
  11. ; position 3 = win95 flag
  12. ; position 4 = win98 flag
  13. ; position 5 = nts_alpha flag
  14. ; position 6 = ntw_alpha flag
  15. ; position 7 = other_os flag
  16. ;
  17. ; position 8 = cabfilename
  18. ; position 9 = inf section
  19. ; position 10 = filename (wildcards okay)
  20. ;
  21. ; position 11= .INF rename to
  22. ; position 12= .DDF exclude from cab flag
  23. ; position 13= Do Not Produce Error if Empty
  24. ; position 14= Do Not include this file if the cab is empty!
  25. ; position 15= Slipstream file -- don't reference the 0 cab, reference the # specified in global Variable - g_iSlipStreamDiskID
  26. ; ------------------------------------------------------------------------------------
  27. 1,1,1,1,0,0,0,basic.cab,iis_product_files_sys,setupapi.dll,,1
  28. 1,1,1,1,0,0,0,basic.cab,iis_product_files_sys,cfgmgr32.dll
  29. 1,1,1,1,0,0,0,basic.cab,iis_product_files_sys,ocmanage.dll
  30. 1,1,1,1,0,0,0,basic.cab,iis_product_files_sys,sysocmgr.exe
  31. 1,1,1,1,0,0,0,basic.cab,iis_core_files_sys,inetsrv\mdutil.exe
  32. 1,1,1,1,0,0,0,basic.cab,iis_core_files_sys,inetsrv\iismap.dll
  33. 1,1,1,1,0,0,0,basic.cab,iis_core_files_inetsrv,inetsrv\iscomlog.dll
  34. ;nts_x86,
  35. ntw_x86,
  36. win95,
  37. win98,
  38. nts_alpha,
  39. ntw_alpha,
  40. other_os,
  41. cab filename,
  42. inf section,
  43. filename (wildcards okay),
  44. .INF rename to,
  45. .DDF exclude from cab,
  46. 1=don't show error if file not exist,
  47. 1=Do Not include this file if the cab is empty!,
  48. Owner
  49. */
  50. #include <direct.h>
  51. #include <tchar.h>
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <io.h>
  55. #include <string.h>
  56. #include <windows.h>
  57. #include <sys\types.h>
  58. #include <sys\stat.h>
  59. #include <iostream.h>
  60. #include <fstream.h>
  61. #include <winbase.h>
  62. #include "filefind.h"
  63. #include <iis64.h>
  64. // Defines
  65. #define delimiters ",\t\n"
  66. #define MAX_STRING 512
  67. #define MAX_ARRAY_SIZE 10000
  68. #define MAX_ARRAY_SMALL 1000
  69. #define ALL_FILES 0xff
  70. #define NTS_X86 "nts_x86"
  71. #define NTW_X86 "ntw_x86"
  72. #define WIN95 "win95"
  73. #define WIN98 "win98"
  74. #define NTS_ALPHA "nts_alpha"
  75. #define NTW_ALPHA "ntw_alpha"
  76. #define OTHER_OS "other_os"
  77. // Globals
  78. int g_iSlipStreamDiskID = 99; // default if none specified as input parameter
  79. int g_iGlobalReturnCode = TRUE;
  80. int g_bOutputFileDate = FALSE;
  81. int g_bOutputFileTime = FALSE;
  82. int g_bOutputFileDateTime = FALSE;
  83. int g_bDoFileCompare = FALSE;
  84. char g_szDoFileCompareData[_MAX_PATH];
  85. int g_bVersionCheck = FALSE;
  86. int g_bShowFileFormat = FALSE;
  87. int g_bOutputDetails = TRUE;
  88. int g_bChangeListOnly = FALSE;
  89. int g_bChangeListOnly2 = FALSE;
  90. int g_bCabbing_Flag = TRUE;
  91. int g_bDisplayToScreen = FALSE;
  92. char g_szModuleFilename[_MAX_FNAME];
  93. char g_szDDFOutput[_MAX_PATH];
  94. char g_szINFOutput[_MAX_PATH];
  95. char g_szLSTOutput[_MAX_PATH];
  96. char g_szCATOutput[_MAX_PATH];
  97. char g_szCNGOutput[_MAX_PATH];
  98. char g_szLOCOutput[_MAX_PATH];
  99. char g_szNOTExistOutput[_MAX_PATH];
  100. char g_szinput_filename_full[_MAX_PATH];
  101. char g_szinput_platform[10];
  102. char g_szCurrentDir[_MAX_PATH];
  103. char g_szFilenameTag[_MAX_FNAME] = "CAB";
  104. #define USENEW
  105. struct FileReadLine
  106. {
  107. int NTS_x86_flag;
  108. int NTW_x86_flag;
  109. int Win95_flag;
  110. int Win98_flag;
  111. int NTS_alpha_flag;
  112. int NTW_alpha_flag;
  113. int Other_os_flag;
  114. char CabFileName[50];
  115. char INF_Sections[100];
  116. char Filename_Full[_MAX_PATH];
  117. char Filename_Name[_MAX_FNAME];
  118. char Filename_Path[_MAX_PATH];
  119. char DDF_Renamed[_MAX_PATH];
  120. char INF_Rename_To[_MAX_FNAME];
  121. int DDF_Exclude_From_Cab_Flag;
  122. int Do_Not_Show_Error_Flag;
  123. int Do_Not_Include_file_if_cabEmpty_Flag;
  124. // invisible stuff
  125. long FileName_Size;
  126. int FileWasNotActuallyFoundToExist;
  127. int GetFromSlipStreamDisk;
  128. } Flat_GlobalArray_Main[MAX_ARRAY_SIZE];
  129. struct CabSizeInfoStruct
  130. {
  131. char CabFileName[50];
  132. int TotalFiles;
  133. long TotalFileSize;
  134. } Flat_GlobalArray_CabSizes[30];
  135. char Flat_GlobalArray_Err[MAX_ARRAY_SIZE][255];
  136. struct arrayrow
  137. {
  138. long total;
  139. long nextuse;
  140. } Flat_GlobalArrayIndex_Main, Flat_GlobalArrayIndex_Err, Flat_GlobalArrayIndex_CabSizes;
  141. char Flat_GlobalUniqueDirList[300][_MAX_PATH];
  142. int Flat_GlobalUniqueDirList_nextuse;
  143. int Flat_GlobalUniqueDirList_total;
  144. // used for files which should not be included in the cab.
  145. FileReadLine g_non_cablist_temp[MAX_ARRAY_SMALL];
  146. int g_non_cablist_temp_nextuse;
  147. int g_non_cablist_temp_total;
  148. // prototypes
  149. int __cdecl main(int ,char *argv[]);
  150. void ShowHelp(void);
  151. void ShowFormat(void);
  152. void MakeDirIfNeedTo(char []);
  153. int strltrim(LPSTR & thestring);
  154. int RemoveAllSpaces(LPSTR & thetempstring);
  155. int IsThisStringInHere(LPTSTR, char[]);
  156. void GetPath(char *input_filespec, char *path, char *fs);
  157. int DoesFileExist(char *input_filespec);
  158. void GetThisModuleName(void);
  159. char* __cdecl strtok2(char *,const char *);
  160. void Flat_ProcessFile(void);
  161. void Flat_GlobalArray_Fill(char[]);
  162. void Flat_GlobalArray_ChkDups(void);
  163. void Flat_GlobalArray_Prepend_UniqueString(void);
  164. void Flat_GlobalArray_Sort_Cols1(void);
  165. void Flat_GlobalArray_Sort_Cols1a(BOOL bDescendFlag);
  166. void Flat_GlobalArray_Sort_Cols2(BOOL bDescendFlag);
  167. int Flat_GlobalArray_Add(FileReadLine);
  168. void Flat_GlobalArray_Add_Err(char[]);
  169. int Flat_GlobalArray_EntryExists(FileReadLine);
  170. void Flat_GlobalArray_Print(void);
  171. void Flat_GlobalArray_Print_Err(void);
  172. int Flat_IsFileNameDup(int);
  173. void Flat_Create_Output_DDF(void);
  174. void Flat_Create_Output_INF(void);
  175. int Flat_Create_Output_ERR(void);
  176. int Flat_DoWeIncludeThisFileCheck(int processeduptill);
  177. void Global_TotalCabFileSize_Compute(void);
  178. void Global_TotalCabFileSize_Print(void);
  179. int ReturnDirLevelCount(char *DirectoryTree);
  180. void FillGlobalUniqueDirList();
  181. int GlobalUniqueDirChkIfAlreadyThere(char *TheStringToCheck);
  182. int GlobalUniqueDirReturnMyIndexMatch(char *TheStringToCheck);
  183. void PrintFileDateTime(char *Full_Filename);
  184. LPSTR StripWhitespaceA(LPSTR pszString);
  185. int iCompareTime(SYSTEMTIME *SystemTime1,SYSTEMTIME *SystemTime2);
  186. int CompareFiles(LPSTR lpFileName1,LPSTR lpFileName2);
  187. BOOL GetFileDate(LPTSTR lpFileName1,SYSTEMTIME *SystemTime1);
  188. //-------------------------------------------------------------------
  189. // purpose: main
  190. //-------------------------------------------------------------------
  191. int __cdecl main(int argc,char *argv[])
  192. {
  193. LPSTR pArg = NULL;
  194. int argno = 0;
  195. int nflags=0;
  196. char ini_filename_dir[_MAX_PATH];
  197. char ini_filename_only[_MAX_FNAME];
  198. char ini_filename_ext[_MAX_EXT];
  199. ini_filename_only[0]='\0';
  200. g_szinput_platform[0]='\0';
  201. GetThisModuleName();
  202. // Get current directory
  203. GetCurrentDirectory( _MAX_PATH, g_szCurrentDir);
  204. // process command line arguments
  205. for(argno=1; argno<argc; argno++)
  206. {
  207. if ( argv[argno][0] == '-' || argv[argno][0] == '/' )
  208. {
  209. nflags++;
  210. switch (argv[argno][1])
  211. {
  212. case '1':
  213. g_bOutputFileDate = TRUE;
  214. break;
  215. case '2':
  216. g_bOutputFileTime = TRUE;
  217. break;
  218. case '3':
  219. g_bOutputFileDateTime = TRUE;
  220. break;
  221. case '4':
  222. g_bDoFileCompare = TRUE;
  223. // Get the string for this flag
  224. pArg = CharNextA(argv[argno]);
  225. pArg = CharNextA(pArg);
  226. if (*pArg == ':')
  227. {
  228. char szTempString[MAX_PATH];
  229. LPSTR pCmdStart = NULL;
  230. pArg = CharNextA(pArg);
  231. // Check if it's quoted
  232. if (*pArg == '\"')
  233. {
  234. pArg = CharNextA(pArg);
  235. pCmdStart = pArg;
  236. while ((*pArg) && (*pArg != '\"')){pArg = CharNextA(pArg);}
  237. }
  238. else
  239. {
  240. pCmdStart = pArg;
  241. // while ((*pArg) && (*pArg != '/') && (*pArg != '-')){pArg = CharNextA(pArg);}
  242. while (*pArg){pArg = CharNextA(pArg);}
  243. }
  244. *pArg = '\0';
  245. lstrcpyA(g_szDoFileCompareData, StripWhitespaceA(pCmdStart));
  246. }
  247. break;
  248. case 'a':
  249. case 'A':
  250. g_bChangeListOnly = TRUE;
  251. break;
  252. case 'b':
  253. case 'B':
  254. g_bChangeListOnly2 = TRUE;
  255. break;
  256. case 'd':
  257. case 'D':
  258. g_bOutputDetails = FALSE;
  259. break;
  260. case 'f':
  261. case 'F':
  262. g_bShowFileFormat = TRUE;
  263. break;
  264. case 'n':
  265. case 'N':
  266. g_bCabbing_Flag = FALSE;
  267. break;
  268. case 'x':
  269. case 'X':
  270. g_bDisplayToScreen = TRUE;
  271. break;
  272. case 's':
  273. g_iSlipStreamDiskID = atoi(&argv[argno][2]);
  274. break;
  275. case 't':
  276. case 'T':
  277. strncpy (g_szFilenameTag, &argv[argno][2], sizeof(g_szFilenameTag));
  278. break;
  279. case 'v':
  280. case 'V':
  281. g_bVersionCheck = TRUE;
  282. break;
  283. case '?':
  284. goto exit_with_help;
  285. break;
  286. }
  287. } // if switch character found
  288. else
  289. {
  290. if ( *ini_filename_only == '\0' )
  291. {
  292. // if no arguments, then
  293. // get the ini_filename_dir and put it into
  294. strcpy(g_szinput_filename_full, argv[argno]);
  295. ini_filename_dir[0] = '\0';
  296. // split up this path
  297. _splitpath( g_szinput_filename_full, NULL, ini_filename_dir, ini_filename_only, ini_filename_ext);
  298. strcat(ini_filename_only, ini_filename_ext);
  299. // if we're missing dir, then get it.
  300. if (*ini_filename_dir == '\0')
  301. {
  302. // stick current dir into our variable
  303. strcpy(ini_filename_dir, g_szCurrentDir);
  304. strcpy(g_szinput_filename_full, g_szCurrentDir);
  305. strcat(g_szinput_filename_full, "\\");
  306. strcat(g_szinput_filename_full, ini_filename_only);
  307. }
  308. }
  309. else
  310. {
  311. // Additional filenames (or arguments without a "-" or "/" preceding)
  312. //goto exit_with_help;
  313. // should be the section to execute.
  314. strcpy(g_szinput_platform, argv[argno]);
  315. }
  316. } // non-switch char found
  317. } // for all arguments
  318. if (g_bShowFileFormat)
  319. {
  320. ShowFormat();
  321. goto exit_no_printf;
  322. }
  323. if (g_bVersionCheck)
  324. {
  325. printf("3\n\n");
  326. exit(3);
  327. return TRUE;
  328. }
  329. // check if filename was specified
  330. // check if section name was specified
  331. if ( *ini_filename_only == '\0')
  332. {
  333. printf("Too few arguments, argc=%d\n\n",argc);
  334. goto exit_with_help;
  335. }
  336. // Check if the file exists!
  337. if (FALSE == DoesFileExist(g_szinput_filename_full))
  338. {
  339. printf("INI file %s, does not exist!.\n", g_szinput_filename_full);
  340. goto exit_gracefully;
  341. }
  342. // check if all they want is to compare a file with another list of files
  343. // and check if the 2nd list of files has a date/time stamp which is more recent than file#1
  344. if (g_bDoFileCompare)
  345. {
  346. // check if filename was specified
  347. if (strcmp(g_szDoFileCompareData,"") == 0)
  348. {
  349. printf("-4 option missing file parameter!\n\n");
  350. goto exit_with_help;
  351. }
  352. // compare file#s date with the list of files in #2
  353. if (TRUE == CompareFiles(g_szinput_filename_full,g_szDoFileCompareData))
  354. {
  355. printf("1\n\n");
  356. goto exit_no_printf_1;
  357. }
  358. else
  359. {
  360. printf("0\n\n");
  361. goto exit_no_printf;
  362. }
  363. }
  364. // check if all they want is the date,time or date and time!!!
  365. if (g_bOutputFileDate || g_bOutputFileTime || g_bOutputFileDateTime)
  366. {
  367. // get the file's julian date and echo it out!
  368. PrintFileDateTime(g_szinput_filename_full);
  369. goto exit_no_printf;
  370. }
  371. // check if filename was specified
  372. // check if section name was specified
  373. if ( *ini_filename_only == '\0' || *g_szinput_platform == '\0')
  374. {
  375. printf("Too few arguments, argc=%d\n\n",argc);
  376. goto exit_with_help;
  377. }
  378. // Check if g_szinput_platform is one of the available options
  379. strcpy(g_szinput_platform, g_szinput_platform);
  380. if ( (_stricmp(g_szinput_platform, NTS_X86) != 0) &&
  381. (_stricmp(g_szinput_platform, NTW_X86) != 0) &&
  382. (_stricmp(g_szinput_platform, WIN95) != 0) &&
  383. (_stricmp(g_szinput_platform, WIN98) != 0) &&
  384. (_stricmp(g_szinput_platform, NTS_ALPHA) != 0) &&
  385. (_stricmp(g_szinput_platform, NTW_ALPHA) != 0) &&
  386. (_stricmp(g_szinput_platform, OTHER_OS) != 0))
  387. {
  388. printf("2nd parameter must be one of %s,%s,%s,%s,%s,%s or %s.\n", NTS_X86, NTW_X86, WIN95, WIN98, NTS_ALPHA, NTW_ALPHA, OTHER_OS);
  389. goto exit_gracefully;
  390. }
  391. // Fine, process the ini file.
  392. char stempstring[100];
  393. sprintf(stempstring, "Start %s.\n", g_szModuleFilename);
  394. printf(stempstring);
  395. printf("---------------------------------------------------\n");
  396. // We have at least g_szinput_platform and g_szinput_filename_full defined
  397. // run the function to do everything
  398. Flat_ProcessFile();
  399. exit_gracefully:
  400. printf("---------------------------------------------------\n");
  401. printf("Done.\n");
  402. if (g_iGlobalReturnCode == TRUE)
  403. {exit(0);}
  404. else
  405. {exit(1);}
  406. return g_iGlobalReturnCode;
  407. exit_with_help:
  408. ShowHelp();
  409. return FALSE;
  410. exit_no_printf:
  411. exit(0);
  412. return FALSE;
  413. exit_no_printf_1:
  414. exit(1);
  415. return TRUE;
  416. }
  417. int CompareFiles(LPSTR lpFileName1,LPSTR lpFileName2)
  418. {
  419. int iReturn = FALSE;
  420. int attr = 0;
  421. intptr_t hFile = 0;
  422. finddata datareturn;
  423. SYSTEMTIME SystemTime1;
  424. SYSTEMTIME SystemTime2;
  425. char filename_dir[_MAX_PATH];
  426. char filename_only[_MAX_FNAME];
  427. char TempString[_MAX_PATH];
  428. char *pDest = NULL;
  429. // file#1 should be a regular file
  430. // file#2 could be 1 file or a list of files.
  431. // regardless, take file#1's date and compare it with the dates of the files in list#2
  432. // if anyone of the files in list#2 is newer than file#1, return true!
  433. InitStringTable(STRING_TABLE_SIZE);
  434. // Get the date\time for file #1
  435. if (FALSE == GetFileDate(lpFileName1, &SystemTime1))
  436. {
  437. printf("CompareFiles: Failure to GetFileDate on %s\n",lpFileName1);
  438. goto CompareFiles_Exit;
  439. }
  440. pDest = lpFileName2;
  441. // Find end of the string
  442. while (*pDest){pDest = _tcsinc(pDest);}
  443. // If no trailing backslash then kool, copy on the *.*
  444. if (*(_tcsdec(lpFileName2, pDest)) == _T('\\'))
  445. {
  446. strcat(lpFileName2, "*.*");
  447. attr=ALL_FILES;
  448. }
  449. // get the path
  450. _splitpath(lpFileName2, NULL, filename_dir, filename_only, NULL);
  451. attr= 0;
  452. if (_stricmp(filename_only, "*") == 0)
  453. {attr=ALL_FILES;}
  454. if (_stricmp(filename_only, "*.*") == 0)
  455. {attr=ALL_FILES;}
  456. if (FindFirst(lpFileName2, attr, &hFile, &datareturn))
  457. {
  458. // check if it's a sub dir
  459. if (!(datareturn.attrib & _A_SUBDIR))
  460. {
  461. // Get the filename portion
  462. strcpy(TempString, filename_dir);
  463. strcat(TempString, datareturn.name);
  464. // compare the date with file#1's date
  465. if (FALSE == GetFileDate(TempString, &SystemTime2))
  466. {
  467. printf("CompareFiles: Failure to GetFileDate on %s\n",TempString);
  468. }
  469. else
  470. {
  471. // check if the filedate is bigger than file#1's date
  472. if (TRUE == iCompareTime(&SystemTime1,&SystemTime2))
  473. {
  474. iReturn = TRUE;
  475. goto CompareFiles_Exit;
  476. }
  477. }
  478. }
  479. while(FindNext(attr, hFile, &datareturn))
  480. {
  481. //printf("FindNext:%s\n",datareturn.name);
  482. // check if it's a sub dir
  483. if (!(datareturn.attrib & _A_SUBDIR))
  484. {
  485. // Get the filename portion
  486. strcpy(TempString, filename_dir);
  487. strcat(TempString, datareturn.name);
  488. // compare the date with file#1's date
  489. if (FALSE == GetFileDate(TempString, &SystemTime2))
  490. {
  491. printf("CompareFiles: Failure to GetFileDate on %s\n",TempString);
  492. }
  493. else
  494. {
  495. // check if the filedate is bigger than file#1's date
  496. if (TRUE == iCompareTime(&SystemTime1,&SystemTime2))
  497. {
  498. iReturn = TRUE;
  499. goto CompareFiles_Exit;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. CompareFiles_Exit:
  506. EndStringTable();
  507. return iReturn;
  508. }
  509. // if systemtime2 is larger than systemtime1 then return true!
  510. int iCompareTime(SYSTEMTIME *SystemTime1,SYSTEMTIME *SystemTime2)
  511. {
  512. int iReturn = FALSE;
  513. if (SystemTime2->wYear > SystemTime1->wYear){goto iCompareTime_Larger;}
  514. if (SystemTime2->wYear < SystemTime1->wYear){goto iCompareTime_Smaller;}
  515. if (SystemTime2->wMonth > SystemTime1->wMonth){goto iCompareTime_Larger;}
  516. if (SystemTime2->wMonth < SystemTime1->wMonth){goto iCompareTime_Smaller;}
  517. if (SystemTime2->wDay > SystemTime1->wDay){goto iCompareTime_Larger;}
  518. if (SystemTime2->wDay < SystemTime1->wDay){goto iCompareTime_Smaller;}
  519. if (SystemTime2->wHour > SystemTime1->wHour){goto iCompareTime_Larger;}
  520. if (SystemTime2->wHour < SystemTime1->wHour){goto iCompareTime_Smaller;}
  521. if (SystemTime2->wMinute > SystemTime1->wMinute){goto iCompareTime_Larger;}
  522. if (SystemTime2->wMinute < SystemTime1->wMinute){goto iCompareTime_Smaller;}
  523. if (SystemTime2->wSecond > SystemTime1->wSecond){goto iCompareTime_Larger;}
  524. if (SystemTime2->wSecond < SystemTime1->wSecond){goto iCompareTime_Smaller;}
  525. if (SystemTime2->wMilliseconds > SystemTime1->wMilliseconds){goto iCompareTime_Larger;}
  526. if (SystemTime2->wMilliseconds < SystemTime1->wMilliseconds){goto iCompareTime_Smaller;}
  527. // they are exactly the same
  528. iReturn = FALSE;
  529. return iReturn;
  530. iCompareTime_Larger:
  531. iReturn = TRUE;
  532. return iReturn;
  533. iCompareTime_Smaller:
  534. iReturn = FALSE;
  535. return iReturn;
  536. }
  537. BOOL GetFileDate(LPTSTR lpFileName1,SYSTEMTIME *SystemTime1)
  538. {
  539. HANDLE hFile1 = NULL;
  540. FILETIME fCreate,fAccess,fWrite;
  541. FILETIME LocalFileTime;
  542. if (!(hFile1=CreateFile(lpFileName1,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,0,0)))
  543. {
  544. return FALSE;
  545. }
  546. if (!GetFileTime(hFile1,&fCreate,&fAccess,&fWrite))
  547. {
  548. CloseHandle(hFile1);
  549. return FALSE;
  550. }
  551. if (!FileTimeToLocalFileTime(&fWrite,&LocalFileTime))
  552. {
  553. CloseHandle(hFile1);
  554. return FALSE;
  555. }
  556. if (!FileTimeToSystemTime(&LocalFileTime,SystemTime1))
  557. {
  558. CloseHandle(hFile1);
  559. return FALSE;
  560. }
  561. CloseHandle(hFile1);
  562. return TRUE;
  563. }
  564. void PrintFileDateTime(char *Full_Filename)
  565. {
  566. SYSTEMTIME SystemTime;
  567. char szDateandtime[50];
  568. // get the file's time stamp 17:31.
  569. // make it look like: 1731
  570. //
  571. // get the file's date 12/30/1999
  572. // make it look like 19991230
  573. // make it all look like 199912301731
  574. if (TRUE == GetFileDate(Full_Filename, &SystemTime))
  575. {
  576. //sprintf(szDateandtime,"[%02d/%02d/%02d %02d:%02d:%02d]\n",SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond);
  577. //printf(szDateandtime);
  578. if (g_bOutputFileDate)
  579. {
  580. sprintf(szDateandtime,"%02d%02d%02d\n",SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay);
  581. printf(szDateandtime);
  582. }
  583. if (g_bOutputFileTime)
  584. {
  585. sprintf(szDateandtime,"%02d%02d%02d\n",SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond);
  586. printf(szDateandtime);
  587. }
  588. if (g_bOutputFileDateTime)
  589. {
  590. sprintf(szDateandtime,"%02d%02d%02d%02d%02d%02d\n",
  591. SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay,
  592. SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond);
  593. printf(szDateandtime);
  594. }
  595. }
  596. return;
  597. }
  598. //-------------------------------------------------------------------
  599. // purpose:
  600. //-------------------------------------------------------------------
  601. void Flat_ProcessFile()
  602. {
  603. ifstream inputfile;
  604. char fileinputbuffer[1000];
  605. char stempstring[100];
  606. char * ptemp = NULL;
  607. Flat_GlobalArrayIndex_Main.total=0; Flat_GlobalArrayIndex_Main.nextuse=0;
  608. Flat_GlobalArrayIndex_Err.total=0; Flat_GlobalArrayIndex_Err.nextuse=0;
  609. // Get output file names
  610. strcpy(g_szDDFOutput, g_szModuleFilename);
  611. strcat(g_szDDFOutput, ".DDF");
  612. strcpy(g_szINFOutput, g_szModuleFilename);
  613. strcat(g_szINFOutput, ".INF");
  614. strcpy(g_szLSTOutput, g_szModuleFilename);
  615. strcat(g_szLSTOutput, ".LST");
  616. strcpy(g_szCATOutput, g_szModuleFilename);
  617. strcat(g_szCATOutput, ".CAT");
  618. strcpy(g_szCNGOutput, g_szModuleFilename);
  619. strcat(g_szCNGOutput, ".CNG");
  620. strcpy(g_szNOTExistOutput, g_szModuleFilename);
  621. strcat(g_szNOTExistOutput, ".NOT");
  622. strcpy(g_szLOCOutput, g_szModuleFilename);
  623. strcat(g_szLOCOutput, ".LOC");
  624. // don't delete these files if we're only doing the changelist file
  625. if (!g_bChangeListOnly)
  626. {
  627. DeleteFile(g_szCATOutput);
  628. DeleteFile(g_szNOTExistOutput);
  629. }
  630. // always delete this file
  631. DeleteFile(g_szCNGOutput);
  632. DeleteFile(g_szLOCOutput);
  633. // Read flat file and put into huge array
  634. inputfile.open(g_szinput_filename_full, ios::in);
  635. inputfile.getline(fileinputbuffer, sizeof(fileinputbuffer));
  636. do
  637. {
  638. // check for any comments, don't add these to the array.
  639. if (strchr(fileinputbuffer, ';') != NULL)
  640. {
  641. ptemp = strrchr(fileinputbuffer, ';');
  642. if (ptemp){*ptemp = '\0';}
  643. }
  644. if (*fileinputbuffer)
  645. {
  646. // Remove spaces
  647. char *p;
  648. p = fileinputbuffer;
  649. RemoveAllSpaces(p);
  650. // Take line, parse it and put it into our global file structure.
  651. // Do only for our platform!!!!
  652. Flat_GlobalArray_Fill(fileinputbuffer);
  653. }
  654. } while (inputfile.getline(fileinputbuffer, sizeof(fileinputbuffer)));
  655. inputfile.close();
  656. // OK, all entries should be in the global_main array
  657. // and all the "extra" entries should be in there too..
  658. // add a "IIS" to the font of any filename
  659. Flat_GlobalArray_Prepend_UniqueString();
  660. // 1. loop thru the global array and mark any filenames for duplicates..
  661. Flat_GlobalArray_Sort_Cols2(TRUE);
  662. Flat_GlobalArray_ChkDups();
  663. // 2. sort on #1 cab file, then on #2 section
  664. Flat_GlobalArray_Sort_Cols2(FALSE);
  665. if (g_bOutputDetails == TRUE) {Flat_GlobalArray_Print();}
  666. if (!g_bChangeListOnly)
  667. {
  668. //printf("\n\n sorted by cab and section...\n");
  669. // 3. loop thru the list and create .DDF file
  670. sprintf(stempstring, "Creating DDF file...%s\n",g_szDDFOutput);
  671. printf(stempstring);
  672. if (g_bCabbing_Flag) {Flat_Create_Output_DDF();}
  673. }
  674. // Sort on sections
  675. Flat_GlobalArray_Sort_Cols1a(FALSE);
  676. //printf("\n\n sorted by section...\n");
  677. if (g_bDisplayToScreen) Flat_GlobalArray_Print();
  678. // 4. loop thru the list and create .INF file
  679. if (g_bChangeListOnly)
  680. {
  681. sprintf(stempstring, "Creating CNG file only...%s\n",g_szINFOutput);
  682. printf(stempstring);
  683. }
  684. else
  685. {
  686. sprintf(stempstring, "Creating INF file...%s\n",g_szINFOutput);
  687. printf(stempstring);
  688. }
  689. Flat_Create_Output_INF();
  690. printf("\nTotals:\n");
  691. Global_TotalCabFileSize_Compute();
  692. Global_TotalCabFileSize_Print();
  693. printf("\nErrors/Warnings:\n");
  694. Flat_GlobalArray_Print_Err();
  695. Flat_Create_Output_ERR();
  696. return;
  697. }
  698. //-------------------------------------------------------------------
  699. // purpose:
  700. //-------------------------------------------------------------------
  701. void Flat_GlobalArray_Fill(char fileinputbuffer[])
  702. {
  703. char *token;
  704. int token_count;
  705. char thetempstring[MAX_STRING];
  706. char tempstring[255];
  707. char temperrorwords[255] = "";
  708. FileReadLine tempentry = {0,0,0,0,0,0,0,"","","","","","","",0,0,0,0,0,0};
  709. FileReadLine theentry = {0,0,0,0,0,0,0,"","","","","","","",0,0,0,0,0,0};
  710. strcpy(thetempstring, fileinputbuffer);
  711. // get the first token
  712. token = strtok2( thetempstring, delimiters );
  713. token_count = 0;
  714. // Add entry to Global Array, convert to all lowercase
  715. // parse out platforms
  716. if (token == NULL) {goto Exit_Flat_FillGlobalArray_Main;}
  717. strcpy(temperrorwords, "x86_NTS_flag");
  718. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  719. tempentry.NTS_x86_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError1;}
  720. strcpy(temperrorwords, "x86_NTW_flag");
  721. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  722. tempentry.NTW_x86_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError1;}
  723. strcpy(temperrorwords, "Win95_flag");
  724. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  725. tempentry.Win95_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError2;}
  726. strcpy(temperrorwords, "Win98_flag");
  727. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  728. tempentry.Win98_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError2;}
  729. strcpy(temperrorwords, "NTS_alpha_flag");
  730. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  731. tempentry.NTS_alpha_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError1;}
  732. strcpy(temperrorwords, "NTW_alpha_flag");
  733. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  734. tempentry.NTW_alpha_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError1;}
  735. strcpy(temperrorwords, "Other_os_flag");
  736. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  737. tempentry.Other_os_flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError1;}
  738. // do only for our specified platform!
  739. if ( (tempentry.NTS_x86_flag==0) && (_stricmp(g_szinput_platform,NTS_X86) == 0))
  740. {goto Exit_Flat_FillGlobalArray_Main;}
  741. if ( (tempentry.NTW_x86_flag==0) && (_stricmp(g_szinput_platform,NTW_X86) == 0))
  742. {goto Exit_Flat_FillGlobalArray_Main;}
  743. if ( (tempentry.Win95_flag==0) && (_stricmp(g_szinput_platform,WIN95) == 0))
  744. {goto Exit_Flat_FillGlobalArray_Main;}
  745. if ( (tempentry.Win98_flag==0) && (_stricmp(g_szinput_platform,WIN98) == 0))
  746. {goto Exit_Flat_FillGlobalArray_Main;}
  747. if ( (tempentry.NTS_alpha_flag==0) && (_stricmp(g_szinput_platform,NTS_ALPHA) == 0))
  748. {goto Exit_Flat_FillGlobalArray_Main;}
  749. if ( (tempentry.NTW_alpha_flag==0) && (_stricmp(g_szinput_platform,NTW_ALPHA) == 0))
  750. {goto Exit_Flat_FillGlobalArray_Main;}
  751. if ( (tempentry.Other_os_flag==0) && (_stricmp(g_szinput_platform,OTHER_OS) == 0))
  752. {goto Exit_Flat_FillGlobalArray_Main;}
  753. strcpy(temperrorwords, "Cabfilename");
  754. strcpy(tempentry.CabFileName, token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError2;}
  755. strcpy(temperrorwords, "INF_Sections");
  756. strcpy(tempentry.INF_Sections, token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto InputParseError2;}
  757. strcpy(temperrorwords, "Filename_Full");
  758. strcpy(tempentry.Filename_Full, token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  759. strcpy(temperrorwords, "INF_Rename_To");
  760. strcpy(tempentry.INF_Rename_To, token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  761. strcpy(temperrorwords, "DDF_Exclude_From_Cab_Flag");
  762. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  763. tempentry.DDF_Exclude_From_Cab_Flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  764. strcpy(temperrorwords, "Do_Not_Show_Error_Flag");
  765. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  766. tempentry.Do_Not_Show_Error_Flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  767. strcpy(temperrorwords, "Do_Not_Include_file_if_cabEmpty_Flag");
  768. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  769. tempentry.Do_Not_Include_file_if_cabEmpty_Flag = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  770. strcpy(temperrorwords, "GetFromSlipStreamDisk");
  771. if ( (_stricmp("1",(char *) token) != 0) && (_stricmp("0",(char *) token) != 0) && (_stricmp("", (char*) token)!=0) ) goto InputParseError;
  772. tempentry.GetFromSlipStreamDisk = atoi(token); token = strtok2( NULL, delimiters ); token_count++;if (token == NULL) {goto MoveToGlobals;}
  773. MoveToGlobals:
  774. if (!(tempentry.Filename_Full)) {goto Exit_Flat_FillGlobalArray_Main;}
  775. // Check for wildcards in position array in filename position #2
  776. int attr;
  777. char filename_dir[_MAX_PATH];
  778. char filename_only[_MAX_FNAME];
  779. // Get the filename portion
  780. _splitpath( tempentry.Filename_Full, NULL, filename_dir, filename_only, NULL);
  781. attr= 0;
  782. if (_stricmp(filename_only, "*.*") == 0)
  783. {attr=ALL_FILES;}
  784. // list thru the files
  785. intptr_t hFile;
  786. finddata datareturn;
  787. InitStringTable(STRING_TABLE_SIZE);
  788. if ( FindFirst(tempentry.Filename_Full, attr, &hFile, &datareturn) )
  789. {
  790. // check if it's a sub dir
  791. if (!( datareturn.attrib & _A_SUBDIR))
  792. {
  793. // ok we found one.
  794. // let's add it to our list of stuff to add
  795. theentry = tempentry;
  796. char tempstring1[255];
  797. strcpy(tempstring1, filename_dir);
  798. strcat(tempstring1, datareturn.name);
  799. strcpy(theentry.Filename_Full, tempstring1);
  800. strcpy(tempstring1, datareturn.name);
  801. strcpy(theentry.Filename_Name, tempstring1);
  802. strcpy(tempstring1, filename_dir);
  803. strcpy(theentry.Filename_Path, tempstring1);
  804. strcpy(tempstring1, datareturn.name);
  805. strcpy(theentry.DDF_Renamed, tempstring1);
  806. theentry.FileName_Size = datareturn.size;
  807. // now take this entry and try to add it to the global array!!!
  808. Flat_GlobalArray_Add(theentry);
  809. }
  810. while(FindNext(attr, hFile, &datareturn))
  811. {
  812. // check if it's a sub dir
  813. if (!(datareturn.attrib & _A_SUBDIR))
  814. {
  815. // ok we found one.
  816. // let's add it to our list of stuff to add
  817. theentry = tempentry;
  818. char tempstring1[255];
  819. strcpy(tempstring1, filename_dir);
  820. strcat(tempstring1, datareturn.name);
  821. strcpy(theentry.Filename_Full, tempstring1);
  822. strcpy(tempstring1, datareturn.name);
  823. strcpy(theentry.Filename_Name, tempstring1);
  824. strcpy(tempstring1, filename_dir);
  825. strcpy(theentry.Filename_Path, tempstring1);
  826. strcpy(tempstring1, datareturn.name);
  827. strcpy(theentry.DDF_Renamed, tempstring1);
  828. theentry.FileName_Size = datareturn.size;
  829. // now take this entry and try to add it to the global array!!!
  830. Flat_GlobalArray_Add(theentry);
  831. }
  832. }
  833. }
  834. else
  835. // we didn't find the specified file.
  836. {
  837. // If this is a file which doesn't get into a cab, then
  838. // let's add it to the .inf file section [SourceDisksFiles] later.
  839. if (tempentry.DDF_Exclude_From_Cab_Flag)
  840. {
  841. fstream f4;
  842. f4.open(g_szNOTExistOutput, ios::out | ios::app);
  843. char fullpath[_MAX_PATH];
  844. char * pmyfilename;
  845. char myPath[_MAX_PATH];
  846. pmyfilename = fullpath;
  847. // Resolve relative path to real path
  848. if (0 != GetFullPathName(tempentry.Filename_Full, _MAX_PATH, myPath, &pmyfilename))
  849. {
  850. // Take only the filename...
  851. // achg.htr=1,,1902
  852. strcpy(tempstring,pmyfilename);
  853. f4.write(tempstring, strlen(tempstring));
  854. if (tempentry.GetFromSlipStreamDisk == 0)
  855. {
  856. strcpy(tempstring,"=0,,50000");
  857. }
  858. else
  859. {
  860. sprintf(tempstring,"=%d,,50000",g_iSlipStreamDiskID);
  861. }
  862. f4.write(tempstring, strlen(tempstring));
  863. f4.write("\n", 1);
  864. // let's add it to our list of stuff to add
  865. theentry = tempentry;
  866. strcpy(theentry.Filename_Full, tempentry.Filename_Full);
  867. strcpy(theentry.Filename_Name, pmyfilename);
  868. _splitpath( tempentry.Filename_Full, NULL, theentry.Filename_Path, NULL, NULL);
  869. //strcpy(theentry.Filename_Path, myPath);
  870. strcpy(theentry.DDF_Renamed, pmyfilename);
  871. theentry.FileName_Size = 50000;
  872. printf(tempentry.Filename_Full);
  873. printf(". FileWasNotActuallyFoundToExist1.\n");
  874. theentry.FileWasNotActuallyFoundToExist = TRUE;
  875. // now take this entry and try to add it to the global array!!!
  876. Flat_GlobalArray_Add(theentry);
  877. }
  878. f4.close();
  879. }
  880. else
  881. {
  882. // check if we're not supposed to show errors!
  883. if (tempentry.Do_Not_Show_Error_Flag == 0)
  884. {
  885. // add it to the error list.
  886. sprintf(tempstring, "ERROR: file not found--> %s --> %s", tempentry.Filename_Full, fileinputbuffer);
  887. Flat_GlobalArray_Add_Err(tempstring);
  888. }
  889. }
  890. }
  891. EndStringTable();
  892. Exit_Flat_FillGlobalArray_Main:
  893. return;
  894. InputParseError:
  895. sprintf(tempstring, "INFUTIL ERROR: %s should be numeric and is not--> %s", temperrorwords, fileinputbuffer);
  896. Flat_GlobalArray_Add_Err(tempstring);
  897. return;
  898. InputParseError1:
  899. sprintf(tempstring, "INFUTIL ERROR: missing platform info--> %s", fileinputbuffer);
  900. Flat_GlobalArray_Add_Err(tempstring);
  901. return;
  902. InputParseError2:
  903. sprintf(tempstring, "INFUTIL ERROR: missing %s--> %s", temperrorwords, fileinputbuffer);
  904. Flat_GlobalArray_Add_Err(tempstring);
  905. return;
  906. }
  907. //-------------------------------------------------------------------
  908. // purpose:
  909. //-------------------------------------------------------------------
  910. int Flat_GlobalArray_Add(FileReadLine entrytoadd)
  911. {
  912. FileReadLine Temp = {0,0,0,0,0,0,0,"","","","","","","",0,0,0,0,0,0};
  913. // check if this value already exists in the globalarary
  914. if (Flat_GlobalArray_EntryExists(entrytoadd)) return FALSE;
  915. // blankout the array values if any.
  916. Flat_GlobalArray_Main[Flat_GlobalArrayIndex_Main.nextuse] = Temp;
  917. // move info into global array
  918. Flat_GlobalArray_Main[Flat_GlobalArrayIndex_Main.nextuse] = entrytoadd;
  919. // increment counter to array
  920. // increment next use space
  921. ++Flat_GlobalArrayIndex_Main.total;
  922. ++Flat_GlobalArrayIndex_Main.nextuse;
  923. return TRUE;
  924. }
  925. //-------------------------------------------------------------------
  926. // purpose:
  927. //-------------------------------------------------------------------
  928. int Flat_GlobalArray_EntryExists(FileReadLine theentry)
  929. {
  930. int matchcount;
  931. // loop thru the whole list
  932. for( int i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  933. {
  934. // check if entries are the same.
  935. matchcount=0;
  936. if (_strnicmp(Flat_GlobalArray_Main[i0].CabFileName, theentry.CabFileName, lstrlen(theentry.CabFileName) + 1) == 0 )
  937. {++matchcount;}
  938. if (_strnicmp(Flat_GlobalArray_Main[i0].INF_Sections, theentry.INF_Sections, lstrlen(theentry.INF_Sections) + 1) == 0 )
  939. {++matchcount;}
  940. if (_strnicmp(Flat_GlobalArray_Main[i0].Filename_Full, theentry.Filename_Full, lstrlen(theentry.Filename_Full) + 1) == 0 )
  941. {++matchcount;}
  942. if (_strnicmp(Flat_GlobalArray_Main[i0].Filename_Name, theentry.Filename_Name, lstrlen(theentry.Filename_Name) + 1) == 0 )
  943. {++matchcount;}
  944. if (matchcount == 4)
  945. {
  946. // we found a match!!! "WARNING: file already included"
  947. return TRUE;
  948. }
  949. }
  950. //. no matches... return FALSE.
  951. return FALSE;
  952. }
  953. //-------------------------------------------------------------------
  954. // purpose:
  955. //-------------------------------------------------------------------
  956. int IsThisStringInHere(LPTSTR lpTemp, char szStringToCheck[])
  957. {
  958. int bFlag = FALSE;
  959. // Lookup sections to see if they exists in ini file.
  960. if (*lpTemp != '\0')
  961. {
  962. // loop thru and process results
  963. bFlag = FALSE;
  964. while (*lpTemp)
  965. {
  966. // check if our section name is in there.
  967. if (_strnicmp(szStringToCheck, lpTemp, lstrlen(lpTemp) + 1) == 0 )
  968. {bFlag = TRUE;}
  969. lpTemp += (lstrlen(lpTemp) + 1);
  970. }
  971. // Check if our section was in there
  972. if (bFlag != TRUE)
  973. {return FALSE;}
  974. }
  975. return TRUE;
  976. }
  977. //-------------------------------------------------------------------
  978. // purpose:
  979. //-------------------------------------------------------------------
  980. int Flat_DDFDoesThisFileCabAlreadyExists(int processeduptill)
  981. {
  982. int i0;
  983. char CompareTo_cab[100];
  984. char CompareTo_fullfilename[100];
  985. strcpy(CompareTo_cab, Flat_GlobalArray_Main[processeduptill].CabFileName);
  986. strcpy(CompareTo_fullfilename, Flat_GlobalArray_Main[processeduptill].Filename_Full);
  987. for(i0=0;i0<processeduptill;i0++)
  988. {
  989. // check if global value has already been processed.
  990. // check if the cab is the same
  991. // check if the dir is the same
  992. // check if the filename is the same
  993. if (_stricmp(Flat_GlobalArray_Main[i0].CabFileName, CompareTo_cab) == 0)
  994. {
  995. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Full,CompareTo_fullfilename) == 0)
  996. {
  997. // if they both match, then shoot that means that we already printed this out.
  998. return TRUE;
  999. }
  1000. }
  1001. }
  1002. return FALSE;
  1003. }
  1004. //-------------------------------------------------------------------
  1005. // purpose:
  1006. //-------------------------------------------------------------------
  1007. void ShowHelp()
  1008. {
  1009. printf("InfUtil2 - prints out file date/time,\n");
  1010. printf(" or print out watch list from <input file> list,\n");
  1011. printf(" or creates .ddf and .inf files from <input file> list\n");
  1012. printf("----------------------------------------------------------------\n");
  1013. printf(" Usage:\n");
  1014. printf(" infutil2 /? /F [/1 /2 /3] [/4:<filename>] [/A /B] /D /N /S? /T??? /X <input file> <section name>\n\n");
  1015. printf(" Params:\n");
  1016. printf(" /? show this stuff\n");
  1017. printf(" /F show <input file> format help\n");
  1018. printf(" Flags for Date/Time use:\n");
  1019. printf(" /1 print out <input file>'s date as number\n");
  1020. printf(" /2 print out <input file>'s time as number\n");
  1021. printf(" /3 print out <input file>'s date and time as big number\n");
  1022. printf(" Flags for compare file list timestamp use:\n");
  1023. printf(" /4: compare dir in <filename> with <input file>'s timestamp. if dir has newer files, then set ERRORLEVEL=1\n");
  1024. printf(" Flags for change list use:\n");
  1025. printf(" /A produce a list of files to watch for changes (if files in list change then re-build cabs) from <input file> list\n");
  1026. printf(" /B produce a list of files to watch for changes (includes files which aren't in cabs) from <input file> list\n");
  1027. printf(" Flags for .ddf .inf use:\n");
  1028. printf(" /D don't show details\n");
  1029. printf(" /SslipstreamSourceDisksNames file id -- used for SP1 slipstream to point loose files to file specified in /S\n");
  1030. printf(" used in sync with <input file> change. look in .ddf file.\n");
  1031. printf(" /Ttag Appends tag_ to the beginning of all filenames\n");
  1032. printf(" /N Produce INF File which will not require .ddf file (meaning no cabs).(untested) \n");
  1033. printf(" /X Display output for debug\n");
  1034. printf(" <input file> is a file name.\n");
  1035. printf(" <section name> is either %s,%s,%s,%s,%s,%s,%s.\n", NTS_X86, NTW_X86, WIN95, WIN98, NTS_ALPHA, NTW_ALPHA, OTHER_OS);
  1036. printf("\n");
  1037. printf("Example:\n");
  1038. printf(" infutil2.exe /3 myfile.txt\n");
  1039. printf(" Will print out myfile.txt's date/time as yymmddhhmmss.\n");
  1040. printf(" infutil2.exe /Tcore inifile.ini %s\n", NTS_X86);
  1041. printf(" Will produce a infutil2.ddf,inf,cng files. the .ddf and .inf files will create cabs with files beginning with 'core_'\n");
  1042. printf(" infutil2.exe /C inifile.ini %s\n", NTS_X86);
  1043. printf(" Will only produce a infutil2.cng file with a list of files to watch for changes in.\n");
  1044. return;
  1045. }
  1046. void ShowFormat(void)
  1047. {
  1048. printf("Format for <input file>:\n");
  1049. printf(" position 1 = nts_x86 flag\n");
  1050. printf(" 2 = ntw_x86 flag\n");
  1051. printf(" 3 = win95 flag\n");
  1052. printf(" 4 = win98 flag\n");
  1053. printf(" 5 = nts_alpha flag\n");
  1054. printf(" 6 = ntw_alpha flag\n");
  1055. printf(" 7 = other_os flag\n");
  1056. printf(" 8 = cabfilename\n");
  1057. printf(" 9 = inf section\n");
  1058. printf(" 10 = filename (wildcards okay)\n");
  1059. printf(" 11 = .INF rename to\n");
  1060. printf(" 12 = .DDF exclude from cab flag\n");
  1061. printf(" 13 = Do Not Produce Error if Empty\n");
  1062. printf(" 14 = Do Not include this file if the cab is empty!\n");
  1063. printf("\n");
  1064. printf("Example of format for <input file>:\n");
  1065. printf(" 1,1,1,1,0,0,0,core.cab,core_files_sys,x86\\SysFile1.dll,,1,,\n");
  1066. printf(" 1,1,1,1,0,0,0,core.cab,core_files_sys,x86\\SysFile2.dll,,1,,\n");
  1067. printf(" 0,0,0,0,1,1,0,core.cab,core_files_sys,Alpha\\SysFile1.dll,,1,,\n");
  1068. printf(" 0,0,0,0,1,1,0,core.cab,core_files_sys,Alpha\\SysFile2.dll,,1,,\n");
  1069. printf(" 1,0,0,0,0,0,0,core.cab,product_files,x86\\ProdSrv.dll,,1,,\n");
  1070. printf(" 0,1,0,0,0,0,0,core.cab,product_files,x86\\ProdWks.dll,,1,,\n");
  1071. printf(" 0,0,1,1,0,0,0,core.cab,product_files,x86\\Prod95.dll,,1,,\n");
  1072. printf(" 0,0,0,0,1,0,0,core.cab,product_files,Alpha\\ProdSrvA.dll,,1,,\n");
  1073. printf(" 0,0,0,0,0,1,0,core.cab,product_files,Alpha\\ProdWksA.dll,,1,,\n");
  1074. printf(" 1,1,1,1,0,0,0,core.cab,product_files,x86\\Prodx86.dll,,1,,\n");
  1075. printf(" 0,0,0,0,1,1,0,core.cab,product_files,Alpha\\ProdAlph.dll,,1,,\n");
  1076. printf(" 1,1,1,1,0,0,0,core.cab,product_files2,x86\\Ext\\*.*,,,,\n");
  1077. printf(" 0,0,0,0,1,1,0,core.cab,product_files2,Alpha\\Ext\\*.*,,,,\n");
  1078. printf(" 1,1,1,1,1,1,0,core.cab,product_files2,16bit\\*.*,,,,\n");
  1079. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir1,content\\index.htm,,,,\n");
  1080. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir1,content\\readme.txt,,,,\n");
  1081. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir1,content\\default.htm,,,,\n");
  1082. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir2,content\\content1.htm,,,,\n");
  1083. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir2,content\\content2.htm,,,,\n");
  1084. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir2,content\\content3.htm,,,,\n");
  1085. printf(" 1,1,1,1,1,1,0,content.cab,content_files_dir2,content\\content4.htm,,,,\n");
  1086. printf(" 1,1,1,1,1,1,0,docs.cab,help_files_dir1,help\\*.*,,,,\n");
  1087. printf(" 1,1,1,1,1,1,0,docs.cab,help_files_dir2,help\\other\\*.*,,,,\n");
  1088. printf(" 1,1,1,1,1,1,0,docs.cab,help_files_dir3,help\\support\\*.txt,,,,\n");
  1089. printf(" 1,1,1,1,1,1,0,docs.cab,help_files_dir4,help\\other\\*.xls,,,,\n");
  1090. printf("\n");
  1091. printf("Example of use:\n");
  1092. printf(" infutil2.exe -Tcore -D abovefile.csv %s\n", NTS_X86);
  1093. printf(" Will produce .ddf,inf,err,cat,not and infutil2.cng files. Figure it out.\n");
  1094. return;
  1095. }
  1096. //-------------------------------------------------------------------
  1097. // purpose:
  1098. //-------------------------------------------------------------------
  1099. int DoesFileExist(char *input_filespec)
  1100. {
  1101. if (GetFileAttributes(input_filespec) == -1)
  1102. {
  1103. return(FALSE);
  1104. }
  1105. return (TRUE);
  1106. }
  1107. //-------------------------------------------------------------------
  1108. // purpose:
  1109. //-------------------------------------------------------------------
  1110. void GetPath(char * input_filespec, char * path, char * fs)
  1111. {
  1112. char filespec[100];
  1113. char * p;
  1114. struct _stat s;
  1115. strcpy(filespec, input_filespec);
  1116. /* if filespec is a directory, interpret it to mean dir\*.* */
  1117. if (_stat(filespec, &s) == 0 && s.st_mode & S_IFDIR)
  1118. {
  1119. /* root is special case */
  1120. if ( (*filespec == '\\' && *(filespec+1) == '\0') ||
  1121. (*(filespec+1) == ':' && *(filespec+2) == '\\' && *(filespec+3)=='\0'))
  1122. strcat(filespec, "*.*");
  1123. else
  1124. strcat(filespec, "\\*.*");
  1125. }
  1126. /* search string from end to beginning for back slash */
  1127. p=filespec+strlen(filespec)-1;
  1128. for(; p>filespec && *p != '\\' && *p != ':'; p--);
  1129. /* is it a drive or path */
  1130. if ( *p=='\\' || *p==':')
  1131. {
  1132. strncpy(path, filespec, DIFF(p-filespec)+1);
  1133. path[p-filespec+1]='\0';
  1134. strcpy(fs, p+1);
  1135. }
  1136. else /* no drive, path */
  1137. {
  1138. /* yep, no path */
  1139. path[0]='\0';
  1140. strcpy(fs, filespec);
  1141. }
  1142. } /* GetPath */
  1143. //-------------------------------------------------------------------
  1144. // purpose:
  1145. //-------------------------------------------------------------------
  1146. int strltrim(LPSTR & thestring)
  1147. {
  1148. char * p = NULL;
  1149. p = thestring;
  1150. // check for spaces to the right
  1151. if (*p ==' ')
  1152. {
  1153. while (*p == ' ')
  1154. {p += (lstrlen((char*) *p) + 1);}
  1155. thestring = p;
  1156. printf("%s testing..", p);
  1157. return TRUE;
  1158. }
  1159. return FALSE;
  1160. }
  1161. //-------------------------------------------------------------------
  1162. // purpose:
  1163. //-------------------------------------------------------------------
  1164. void MakeDirIfNeedTo(char thestring[])
  1165. {
  1166. char *p = NULL;
  1167. char tempstring[255];
  1168. // Check the string to see if there are any "\"'s in the string
  1169. // if there are then let's remove the filename and make the directory
  1170. if (strchr(thestring, '\\') != NULL)
  1171. {
  1172. strcpy(tempstring, thestring);
  1173. // remove the filename
  1174. p = strrchr(tempstring, '\\');
  1175. if(p){*p = '\0';}
  1176. // ok now we have the path
  1177. // let's create the directory
  1178. _mkdir(tempstring);
  1179. }
  1180. return;
  1181. }
  1182. //-------------------------------------------------------------------
  1183. // purpose:
  1184. //-------------------------------------------------------------------
  1185. void GetThisModuleName(void)
  1186. {
  1187. char szfilename_only[_MAX_FNAME];
  1188. char szPath[_MAX_PATH];
  1189. // Get the path
  1190. if (GetModuleFileName(NULL, szPath, _MAX_PATH))
  1191. {
  1192. // split up this path and take filename only
  1193. _splitpath( szPath, NULL, NULL, szfilename_only, NULL);
  1194. // set global variable with it
  1195. strcpy(g_szModuleFilename, szfilename_only);
  1196. }
  1197. return;
  1198. }
  1199. void Flat_GlobalArray_Prepend_UniqueString(void)
  1200. {
  1201. //char Filename_Full[_MAX_PATH];
  1202. //char Filename_Name[_MAX_FNAME];
  1203. //char Filename_Path[_MAX_PATH];
  1204. //char DDF_Renamed[_MAX_PATH];
  1205. //char INF_Rename_To[_MAX_FNAME];
  1206. char filename_only[_MAX_FNAME];
  1207. char filename_ext[_MAX_EXT];
  1208. char NewFilename[_MAX_FNAME];
  1209. int i0 =0;
  1210. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  1211. {
  1212. if (Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag == 0)
  1213. {
  1214. // Tack on the IIS Tag.
  1215. _splitpath( Flat_GlobalArray_Main[i0].Filename_Full, NULL, NULL, filename_only, filename_ext);
  1216. if (filename_ext)
  1217. {sprintf(NewFilename, "%s_%s%s", g_szFilenameTag, filename_only, filename_ext);}
  1218. else
  1219. {sprintf(NewFilename, "%s_%s", g_szFilenameTag, filename_only);}
  1220. // re-create the full name
  1221. //sprintf(Flat_GlobalArray_Main[i0].Filename_Full, "%s%s", Flat_GlobalArray_Main[i0].Filename_Path, NewFilename);
  1222. // re-create the filename only
  1223. //strcpy(Flat_GlobalArray_Main[i0].Filename_Name, NewFilename);
  1224. _splitpath( Flat_GlobalArray_Main[i0].DDF_Renamed, NULL, NULL, filename_only, filename_ext);
  1225. if (filename_ext)
  1226. {sprintf(NewFilename, "%s_%s%s", g_szFilenameTag, filename_only, filename_ext);}
  1227. else
  1228. {sprintf(NewFilename, "%s_%s", g_szFilenameTag, filename_only);}
  1229. // re-create the filename
  1230. strcpy(Flat_GlobalArray_Main[i0].DDF_Renamed, NewFilename);
  1231. /*
  1232. _splitpath( Flat_GlobalArray_Main[i0].INF_Rename_To, NULL, NULL, filename_only, filename_ext);
  1233. if (filename_only)
  1234. {
  1235. if (filename_ext)
  1236. {sprintf(NewFilename, "%s_%s%s", g_szFilenameTag, filename_only, filename_ext);}
  1237. else
  1238. {sprintf(NewFilename, "%s_%s", g_szFilenameTag, filename_only);}
  1239. // re-create the filename
  1240. strcpy(Flat_GlobalArray_Main[i0].INF_Rename_To, NewFilename);
  1241. }
  1242. */
  1243. }
  1244. }
  1245. }
  1246. //-------------------------------------------------------------------
  1247. // purpose: check for duplicate filenames
  1248. //-------------------------------------------------------------------
  1249. void Flat_GlobalArray_ChkDups(void)
  1250. {
  1251. int i0 =0;
  1252. int i1 =0;
  1253. int i3 = 0;
  1254. char filetemp[255];
  1255. char filetempwhole[255];
  1256. int theflag = FALSE;
  1257. char checkagainst[255];
  1258. int foundtheflag2 = FALSE;
  1259. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  1260. {
  1261. if (Flat_IsFileNameDup(i0))
  1262. {
  1263. printf (".");
  1264. i1 = 0;
  1265. // if the file exists outside a cab, then do not rename.
  1266. // only rename files which exist in the cab.
  1267. if (Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag == 0)
  1268. {
  1269. do
  1270. {
  1271. theflag = FALSE;
  1272. // Give it a new name.
  1273. // then check if the name already exists.
  1274. i1++;
  1275. if (g_bCabbing_Flag != TRUE)
  1276. {
  1277. #ifdef USENEW
  1278. if (i1 == 1)
  1279. {
  1280. // Count how many directory levels in There.
  1281. int iDirLevelCount = 0;
  1282. int z1 = 0;
  1283. iDirLevelCount = ReturnDirLevelCount(Flat_GlobalArray_Main[i0].Filename_Full);
  1284. strcpy(filetemp, Flat_GlobalArray_Main[i0].Filename_Path);
  1285. if (iDirLevelCount >=1)
  1286. {
  1287. for( z1 = 0; z1 < iDirLevelCount;z1++)
  1288. {strcat(filetemp, "..\\");}
  1289. }
  1290. /*
  1291. strcpy(filetemp, "");
  1292. if (iDirLevelCount >=1)
  1293. {
  1294. for( z1 = 0; z1 < iDirLevelCount;z1++)
  1295. {strcat(filetemp, "..\\");}
  1296. }
  1297. strcat(filetemp, Flat_GlobalArray_Main[i0].Filename_Path);
  1298. */
  1299. // add the filename
  1300. strcat(filetemp, Flat_GlobalArray_Main[i0].Filename_Name);
  1301. strcpy(filetempwhole,filetemp);
  1302. }
  1303. else
  1304. {
  1305. sprintf(filetemp, "%s_%s%d", g_szFilenameTag, Flat_GlobalArray_Main[i0].Filename_Full, i1);
  1306. strcpy(filetempwhole, Flat_GlobalArray_Main[i0].Filename_Path);
  1307. strcat(filetempwhole, filetemp);
  1308. }
  1309. #else
  1310. sprintf(filetemp, "%s_%s%d", g_szFilenameTag, Flat_GlobalArray_Main[i0].Filename_Name, i1);
  1311. strcpy(filetempwhole, Flat_GlobalArray_Main[i0].Filename_Path);
  1312. strcat(filetempwhole, filetemp);
  1313. #endif
  1314. }
  1315. else
  1316. {
  1317. sprintf(filetemp, "%s_%s%d", g_szFilenameTag, Flat_GlobalArray_Main[i0].Filename_Name, i1);
  1318. strcpy(filetempwhole, Flat_GlobalArray_Main[i0].Filename_Path);
  1319. strcat(filetempwhole, filetemp);
  1320. }
  1321. // check if the file exists..
  1322. // check if it already exists in our list...
  1323. strcpy(checkagainst, filetempwhole);
  1324. foundtheflag2= FALSE;
  1325. for (i3=0;i3<Flat_GlobalArrayIndex_Main.total;i3++)
  1326. {
  1327. if (i3 != i0)
  1328. {
  1329. if (_stricmp(Flat_GlobalArray_Main[i3].Filename_Name, filetemp) == 0)
  1330. {foundtheflag2= TRUE;}
  1331. else
  1332. {
  1333. if (_stricmp(Flat_GlobalArray_Main[i3].DDF_Renamed, filetemp) == 0)
  1334. {foundtheflag2= TRUE;}
  1335. }
  1336. }
  1337. }
  1338. if (foundtheflag2 == FALSE)
  1339. {
  1340. // check if it already exists in the filesystem...
  1341. int attr = 0;
  1342. intptr_t hFile = 0;
  1343. finddata datareturn;
  1344. InitStringTable(STRING_TABLE_SIZE);
  1345. if ( FindFirst(filetempwhole, attr, &hFile, &datareturn) )
  1346. {
  1347. // shoot that blows, it already exists
  1348. // do it again.
  1349. theflag = FALSE;
  1350. }
  1351. else
  1352. {
  1353. theflag = TRUE;
  1354. }
  1355. }
  1356. } while (theflag == FALSE);
  1357. // Add to the ddf renamedfile place
  1358. strcpy(Flat_GlobalArray_Main[i0].DDF_Renamed, filetemp);
  1359. }
  1360. }
  1361. }
  1362. printf ("\n");
  1363. return;
  1364. }
  1365. //-------------------------------------------------------------------
  1366. // purpose: check for duplicate filenames in filename column
  1367. //-------------------------------------------------------------------
  1368. int Flat_IsFileNameDup(int indextocheck)
  1369. {
  1370. int iReturn = FALSE;
  1371. int i0;
  1372. char checkagainst[255];
  1373. char checkagainst2[255];
  1374. // check for exact duplicate.
  1375. // if it is then we can't have any of these
  1376. // Return false, because we will remove this entry later
  1377. // it should return false, because the files are identical and do not need to be renamed.
  1378. strcpy(checkagainst, Flat_GlobalArray_Main[indextocheck].Filename_Full);
  1379. strcpy(checkagainst2, Flat_GlobalArray_Main[indextocheck].Filename_Name);
  1380. for (i0=0;i0<Flat_GlobalArrayIndex_Main.total;i0++)
  1381. //for (i0=0;i0<indextocheck;i0++)
  1382. {
  1383. iReturn = FALSE;
  1384. if (i0 != indextocheck)
  1385. {
  1386. /*
  1387. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, checkagainst2) == 0)
  1388. {
  1389. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, "global.asa") == 0)
  1390. {
  1391. printf(":");
  1392. printf(Flat_GlobalArray_Main[i0].Filename_Full);
  1393. printf("(");printf(Flat_GlobalArray_Main[i0].Filename_Name);printf(")");
  1394. printf("[");printf(Flat_GlobalArray_Main[i0].DDF_Renamed);printf("]");
  1395. printf(":");
  1396. printf(Flat_GlobalArray_Main[indextocheck].Filename_Full);
  1397. printf("(");printf(Flat_GlobalArray_Main[indextocheck].Filename_Name);printf(")");
  1398. printf("[");printf(Flat_GlobalArray_Main[indextocheck].DDF_Renamed);printf("]");
  1399. printf("\n");
  1400. }
  1401. }
  1402. */
  1403. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Full, checkagainst) == 0)
  1404. {
  1405. // We have a duplicate which we will ignore!
  1406. //printf(Flat_GlobalArray_Main[i0].Filename_Full);
  1407. //printf(". Duplicate.1.!!!!\n");
  1408. _stricmp(Flat_GlobalArray_Main[indextocheck].DDF_Renamed, Flat_GlobalArray_Main[i0].DDF_Renamed);
  1409. iReturn = FALSE;
  1410. goto Flat_IsFileNameDup_Exit;
  1411. }
  1412. else
  1413. {
  1414. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, checkagainst2) == 0)
  1415. {
  1416. // We have a duplicate, check if this one has already been renamed though.
  1417. if (_stricmp(Flat_GlobalArray_Main[i0].DDF_Renamed, checkagainst2) == 0)
  1418. {
  1419. //printf(". Duplicate.2.!!!!\n");
  1420. iReturn = TRUE;
  1421. goto Flat_IsFileNameDup_Exit;
  1422. }
  1423. else
  1424. {
  1425. // check if what we are renaming indextocheck to, is the same as DDF_Renamed...
  1426. if (_stricmp(Flat_GlobalArray_Main[i0].DDF_Renamed, Flat_GlobalArray_Main[indextocheck].DDF_Renamed) == 0)
  1427. {
  1428. //(". Duplicate.3.!!!!\n");
  1429. iReturn = TRUE;
  1430. goto Flat_IsFileNameDup_Exit;
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. // go on to the next one....
  1437. }
  1438. /*
  1439. // Check for filename duplicate only
  1440. strcpy(checkagainst, Flat_GlobalArray_Main[indextocheck].Filename_Name);
  1441. for (i0=0;i0<Flat_GlobalArrayIndex_Main.total;i0++)
  1442. {
  1443. if (i0 != indextocheck)
  1444. {
  1445. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, checkagainst) == 0)
  1446. {return TRUE;}
  1447. }
  1448. }
  1449. */
  1450. Flat_IsFileNameDup_Exit:
  1451. return iReturn;
  1452. }
  1453. //-------------------------------------------------------------------
  1454. // purpose: sort on CabFileName, then on Filename_Path
  1455. //-------------------------------------------------------------------
  1456. void Flat_GlobalArray_Sort_Cols2(BOOL bDescendFlag)
  1457. {
  1458. int offset, inorder;
  1459. int i;
  1460. int j;
  1461. int n;
  1462. int result;
  1463. int swapflag;
  1464. FileReadLine tempentry;
  1465. n = Flat_GlobalArrayIndex_Main.total;
  1466. offset=n;
  1467. do{
  1468. offset = (8 * offset) /11;
  1469. offset = (offset == 0) ? 1 : offset;
  1470. inorder = TRUE;
  1471. for (i=0,j=offset;i < (n - offset);i++,j++)
  1472. {
  1473. swapflag = FALSE;
  1474. result = _stricmp(Flat_GlobalArray_Main[i].CabFileName, Flat_GlobalArray_Main[j].CabFileName);
  1475. if (bDescendFlag)
  1476. {
  1477. if (result < 0)
  1478. {swapflag = TRUE;}
  1479. else
  1480. {
  1481. if (result == 0)
  1482. {
  1483. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Path, Flat_GlobalArray_Main[j].Filename_Path);
  1484. if (result < 0)
  1485. {swapflag = TRUE;}
  1486. else
  1487. {
  1488. if (result ==0)
  1489. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Name, Flat_GlobalArray_Main[j].Filename_Name);
  1490. if (result < 0)
  1491. {swapflag = TRUE;}
  1492. }
  1493. }
  1494. }
  1495. }
  1496. else
  1497. {
  1498. // check if larger
  1499. if (result > 0)
  1500. {swapflag = TRUE;}
  1501. else
  1502. {
  1503. if (result == 0)
  1504. {
  1505. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Path, Flat_GlobalArray_Main[j].Filename_Path);
  1506. // check if larger
  1507. if (result > 0)
  1508. {swapflag = TRUE;}
  1509. else
  1510. {
  1511. if (result ==0)
  1512. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Name, Flat_GlobalArray_Main[j].Filename_Name);
  1513. if (result > 0)
  1514. {swapflag = TRUE;}
  1515. }
  1516. }
  1517. }
  1518. }
  1519. if (swapflag == TRUE)
  1520. {
  1521. inorder = FALSE;
  1522. // do the swap
  1523. // move into temp
  1524. tempentry = Flat_GlobalArray_Main[i];
  1525. // move into original
  1526. Flat_GlobalArray_Main[i] = Flat_GlobalArray_Main[j];
  1527. // move temp into other
  1528. Flat_GlobalArray_Main[j] = tempentry;
  1529. }
  1530. }
  1531. } while (!(offset == 1 && inorder == TRUE));
  1532. return;
  1533. }
  1534. //-------------------------------------------------------------------
  1535. // purpose: sort on INF_Sections only
  1536. //-------------------------------------------------------------------
  1537. void Flat_GlobalArray_Sort_Cols1()
  1538. {
  1539. int offset, inorder;
  1540. int i;
  1541. int j;
  1542. int n;
  1543. int result;
  1544. FileReadLine tempentry;
  1545. n = Flat_GlobalArrayIndex_Main.total;
  1546. offset=n;
  1547. do{
  1548. offset = (8 * offset) /11;
  1549. offset = (offset == 0) ? 1 : offset;
  1550. inorder = TRUE;
  1551. for (i=0,j=offset;i < (n - offset);i++,j++)
  1552. {
  1553. result = _stricmp(Flat_GlobalArray_Main[i].INF_Sections, Flat_GlobalArray_Main[j].INF_Sections);
  1554. if (result > 0)
  1555. {
  1556. inorder = FALSE;
  1557. // do the swap
  1558. // move into temp
  1559. tempentry = Flat_GlobalArray_Main[i];
  1560. // move into original
  1561. Flat_GlobalArray_Main[i] = Flat_GlobalArray_Main[j];
  1562. // move temp into other
  1563. Flat_GlobalArray_Main[j] = tempentry;
  1564. }
  1565. }
  1566. } while (!(offset == 1 && inorder == TRUE));
  1567. return;
  1568. }
  1569. //-------------------------------------------------------------------
  1570. // purpose: sort on INF_Sections then on filename
  1571. //-------------------------------------------------------------------
  1572. void Flat_GlobalArray_Sort_Cols1a(BOOL bDescendFlag)
  1573. {
  1574. int offset, inorder;
  1575. int i;
  1576. int j;
  1577. int n;
  1578. int result;
  1579. int swapflag;
  1580. FileReadLine tempentry;
  1581. n = Flat_GlobalArrayIndex_Main.total;
  1582. offset=n;
  1583. do{
  1584. offset = (8 * offset) /11;
  1585. offset = (offset == 0) ? 1 : offset;
  1586. inorder = TRUE;
  1587. for (i=0,j=offset;i < (n - offset);i++,j++)
  1588. {
  1589. swapflag = FALSE;
  1590. result = _stricmp(Flat_GlobalArray_Main[i].INF_Sections, Flat_GlobalArray_Main[j].INF_Sections);
  1591. if (bDescendFlag)
  1592. {
  1593. if (result < 0)
  1594. {swapflag = TRUE;}
  1595. else
  1596. {
  1597. if (result == 0)
  1598. {
  1599. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Name, Flat_GlobalArray_Main[j].Filename_Name);
  1600. if (result < 0){swapflag = TRUE;}
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. // check if larger
  1607. if (result > 0)
  1608. {swapflag = TRUE;}
  1609. else
  1610. {
  1611. if (result == 0)
  1612. {
  1613. result = _stricmp(Flat_GlobalArray_Main[i].Filename_Name, Flat_GlobalArray_Main[j].Filename_Name);
  1614. // check if larger
  1615. if (result > 0){swapflag = TRUE;}
  1616. }
  1617. }
  1618. }
  1619. if (swapflag == TRUE)
  1620. {
  1621. inorder = FALSE;
  1622. // do the swap
  1623. // move into temp
  1624. tempentry = Flat_GlobalArray_Main[i];
  1625. // move into original
  1626. Flat_GlobalArray_Main[i] = Flat_GlobalArray_Main[j];
  1627. // move temp into other
  1628. Flat_GlobalArray_Main[j] = tempentry;
  1629. }
  1630. }
  1631. } while (!(offset == 1 && inorder == TRUE));
  1632. return;
  1633. }
  1634. //-------------------------------------------------------------------
  1635. // purpose:
  1636. //-------------------------------------------------------------------
  1637. void Flat_GlobalArray_Print(void)
  1638. {
  1639. int i0;
  1640. int total;
  1641. char bigtemp[20];
  1642. total = Flat_GlobalArrayIndex_Main.total;
  1643. for( i0 = 0; i0 < total;i0++)
  1644. {
  1645. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].NTS_x86_flag);
  1646. printf (bigtemp); printf(",");
  1647. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].NTW_x86_flag);
  1648. printf (bigtemp); printf(",");
  1649. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].Win95_flag);
  1650. printf (bigtemp); printf(",");
  1651. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].Win98_flag);
  1652. printf (bigtemp); printf(",");
  1653. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].NTS_alpha_flag);
  1654. printf (bigtemp); printf(",");
  1655. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].NTW_alpha_flag);
  1656. printf (bigtemp); printf(",");
  1657. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].Other_os_flag);
  1658. printf (bigtemp); printf(",");
  1659. printf(Flat_GlobalArray_Main[i0].CabFileName);
  1660. printf(",");
  1661. printf(Flat_GlobalArray_Main[i0].INF_Sections);
  1662. printf(",");
  1663. printf(Flat_GlobalArray_Main[i0].Filename_Full);
  1664. printf(",");
  1665. printf(Flat_GlobalArray_Main[i0].Filename_Name);
  1666. printf(",");
  1667. printf(Flat_GlobalArray_Main[i0].Filename_Path);
  1668. printf(",");
  1669. printf(Flat_GlobalArray_Main[i0].DDF_Renamed);
  1670. printf(",");
  1671. printf(Flat_GlobalArray_Main[i0].INF_Rename_To);
  1672. printf(",");
  1673. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag);
  1674. printf (bigtemp); printf(",");
  1675. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].Do_Not_Show_Error_Flag);
  1676. printf (bigtemp); printf(",");
  1677. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].Do_Not_Include_file_if_cabEmpty_Flag);
  1678. printf (bigtemp); printf(",");
  1679. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].GetFromSlipStreamDisk);
  1680. printf (bigtemp); printf(",");
  1681. sprintf(bigtemp, "%d", Flat_GlobalArray_Main[i0].FileName_Size);
  1682. printf (bigtemp);
  1683. printf ("\n");
  1684. }
  1685. return;
  1686. }
  1687. //-------------------------------------------------------------------
  1688. // purpose:
  1689. //-------------------------------------------------------------------
  1690. void Flat_Create_Output_INF(void)
  1691. {
  1692. int i0;
  1693. fstream f;
  1694. fstream f2;
  1695. fstream f3;
  1696. fstream f4;
  1697. fstream f5;
  1698. char last_section[255];
  1699. char this_section[255];
  1700. char tempstring[255];
  1701. char fullpath[_MAX_PATH];
  1702. int Changed_f4 = FALSE;
  1703. int Changed_f5 = FALSE;
  1704. if (!g_bChangeListOnly)
  1705. {
  1706. f.open(g_szINFOutput, ios::out);
  1707. f3.open(g_szCATOutput, ios::out);
  1708. }
  1709. f4.open(g_szCNGOutput, ios::out);
  1710. f5.open(g_szLOCOutput, ios::out);
  1711. if (g_bCabbing_Flag == TRUE)
  1712. {
  1713. // Produce .inf file for use with .ddf file
  1714. // for generating cabs!!!
  1715. // ----------------------------------------
  1716. // Produce the top half -- the sections
  1717. // bottom half -- producted by diamond using.ddf file
  1718. // ------------------------------------
  1719. strcpy(last_section, " ");
  1720. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  1721. {
  1722. Changed_f4 = FALSE;
  1723. Changed_f5 = FALSE;
  1724. strcpy(this_section, Flat_GlobalArray_Main[i0].INF_Sections);
  1725. // For each new section change.
  1726. if (_stricmp(this_section, last_section) != 0)
  1727. {
  1728. if (!g_bChangeListOnly)
  1729. {
  1730. // print out new section stuff
  1731. f.write("\n", 1);
  1732. sprintf(tempstring, "[%s]\n", this_section);
  1733. f.write (tempstring, strlen(tempstring));
  1734. }
  1735. strcpy(last_section, this_section);
  1736. }
  1737. if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE)
  1738. {
  1739. // write it out to the .cat file
  1740. // strcpy(tempstring,Flat_GlobalArray_Main[i0].Filename_Name);
  1741. // // take out trailing spaces.
  1742. // f3.write(tempstring, strlen(tempstring));
  1743. TCHAR * pmyfilename;
  1744. pmyfilename = fullpath;
  1745. TCHAR myPath[_MAX_PATH];
  1746. // Resolve relative path to real path
  1747. if (0 != GetFullPathName(Flat_GlobalArray_Main[i0].Filename_Full, _MAX_PATH, myPath, &pmyfilename))
  1748. {
  1749. if (!g_bChangeListOnly)
  1750. {
  1751. // should look like this
  1752. // <HASH>d:\mydir\myfile=d:\mydir\myfile
  1753. strcpy(tempstring,"<HASH>");
  1754. f3.write(tempstring, strlen(tempstring));
  1755. strcpy(tempstring,myPath);
  1756. f3.write(tempstring, strlen(tempstring));
  1757. strcpy(tempstring,"=");
  1758. f3.write(tempstring, strlen(tempstring));
  1759. strcpy(tempstring,myPath);
  1760. f3.write(tempstring, strlen(tempstring));
  1761. }
  1762. if (g_bChangeListOnly2)
  1763. {
  1764. // write out entry for change list.
  1765. strcpy(tempstring,myPath);
  1766. f4.write(tempstring, strlen(tempstring));
  1767. Changed_f4 = TRUE;
  1768. }
  1769. else if (Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag == 0)
  1770. {
  1771. // write out entry for change list
  1772. strcpy(tempstring,myPath);
  1773. f4.write(tempstring, strlen(tempstring));
  1774. Changed_f4 = TRUE;
  1775. }
  1776. if (Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag == 1)
  1777. {
  1778. // write out entry for localization (list of files in binaries dir outside of cab)
  1779. strcpy(tempstring,pmyfilename);
  1780. f5.write(tempstring, strlen(tempstring));
  1781. Changed_f5 = TRUE;
  1782. }
  1783. }
  1784. // Check if this file has the rename stuff set and additional info there,
  1785. // don't write the \n until past this part..
  1786. if (_stricmp(Flat_GlobalArray_Main[i0].INF_Rename_To,"") == 0)
  1787. {
  1788. // write out the filename!
  1789. // print out the filename
  1790. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, Flat_GlobalArray_Main[i0].DDF_Renamed) == 0)
  1791. {
  1792. strcpy(tempstring,Flat_GlobalArray_Main[i0].Filename_Name);
  1793. if (!g_bChangeListOnly)
  1794. {
  1795. f.write (tempstring, strlen(tempstring));
  1796. }
  1797. // append on overwrite all the time
  1798. // notice the two commas!
  1799. //f.write (",,4",3);
  1800. }
  1801. else
  1802. {
  1803. // rename to:
  1804. strcpy(tempstring, Flat_GlobalArray_Main[i0].Filename_Name);
  1805. if (!g_bChangeListOnly)
  1806. {
  1807. f.write (tempstring, strlen(tempstring));
  1808. }
  1809. // rename from:
  1810. strcpy(tempstring, Flat_GlobalArray_Main[i0].DDF_Renamed);
  1811. if (!g_bChangeListOnly)
  1812. {
  1813. f.write (",",1);
  1814. f.write (tempstring, strlen(tempstring));
  1815. // append on overwrite all the time
  1816. //f.write (",4",2);
  1817. }
  1818. }
  1819. }
  1820. else
  1821. {
  1822. // the rename flag was set and the filename is in there.
  1823. // format: rename to, rename from
  1824. if (!g_bChangeListOnly)
  1825. {
  1826. // rename to:
  1827. strcpy(tempstring, Flat_GlobalArray_Main[i0].INF_Rename_To);
  1828. f.write (tempstring, strlen(tempstring));
  1829. // rename from:
  1830. strcpy(tempstring, Flat_GlobalArray_Main[i0].DDF_Renamed);
  1831. f.write (",",1);
  1832. f.write (tempstring, strlen(tempstring));
  1833. // append on overwrite all the time
  1834. //f.write (",4",2);
  1835. }
  1836. }
  1837. }
  1838. // ok, now it's kool to write this part.
  1839. f.write("\n", 1);
  1840. f3.write("\n", 1);
  1841. if (Changed_f4)
  1842. {
  1843. f4.write("\n", 1);
  1844. }
  1845. if (Changed_f5)
  1846. {
  1847. f5.write("\n", 1);
  1848. }
  1849. }
  1850. if (!g_bChangeListOnly)
  1851. {
  1852. f.close();
  1853. f3.close();
  1854. }
  1855. f4.close();
  1856. f5.close();
  1857. }
  1858. else
  1859. {
  1860. // Produce .inf file for use without anything else!!!
  1861. // no need corresponding .ddf file for these!!!
  1862. // ----------------------------------------
  1863. // Produce the top half -- the sections
  1864. // ------------------------------------
  1865. strcpy(last_section, " ");
  1866. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  1867. {
  1868. strcpy(this_section, Flat_GlobalArray_Main[i0].INF_Sections);
  1869. // For each new section change.
  1870. if (_stricmp(this_section, last_section) != 0)
  1871. {
  1872. if (!g_bChangeListOnly)
  1873. {
  1874. // print out new section stuff
  1875. f.write("\n", 1);
  1876. sprintf(tempstring, "[%s]\n", this_section);
  1877. f.write (tempstring, strlen(tempstring));
  1878. }
  1879. strcpy(last_section, this_section);
  1880. }
  1881. #ifdef USENEW
  1882. if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE)
  1883. {
  1884. // Check if this file has the rename stuff set and additional info there,
  1885. // don't write the \n until past this part..
  1886. if (_stricmp(Flat_GlobalArray_Main[i0].INF_Rename_To,"") == 0)
  1887. {
  1888. // write out the filename!
  1889. // print out the filename
  1890. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, Flat_GlobalArray_Main[i0].DDF_Renamed) == 0)
  1891. {
  1892. if (!g_bChangeListOnly)
  1893. {
  1894. strcpy(tempstring,Flat_GlobalArray_Main[i0].Filename_Name);
  1895. f.write (tempstring, strlen(tempstring));
  1896. // append on overwrite all the time
  1897. // notice the two commas!
  1898. //f.write (",,4",3);
  1899. }
  1900. }
  1901. else
  1902. {
  1903. if (!g_bChangeListOnly)
  1904. {
  1905. // rename to:
  1906. strcpy(tempstring, Flat_GlobalArray_Main[i0].Filename_Name);
  1907. f.write (tempstring, strlen(tempstring));
  1908. // rename from:
  1909. strcpy(tempstring, Flat_GlobalArray_Main[i0].DDF_Renamed);
  1910. f.write (",",1);
  1911. f.write (tempstring, strlen(tempstring));
  1912. // append on overwrite all the time
  1913. //f.write (",4",2);
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. if (!g_bChangeListOnly)
  1920. {
  1921. // the rename flag was set and the filename is in there.
  1922. // format: rename to, rename from
  1923. // rename to:
  1924. strcpy(tempstring, Flat_GlobalArray_Main[i0].INF_Rename_To);
  1925. f.write (tempstring, strlen(tempstring));
  1926. // rename from:
  1927. strcpy(tempstring, Flat_GlobalArray_Main[i0].DDF_Renamed);
  1928. f.write (",",1);
  1929. f.write (tempstring, strlen(tempstring));
  1930. // append on overwrite all the time
  1931. //f.write (",4",2);
  1932. }
  1933. }
  1934. }
  1935. #else
  1936. if (!g_bChangeListOnly)
  1937. {
  1938. // write out the filename!
  1939. // like this: filename.txt, inetsrv\test\test\filename.txt
  1940. strcpy(tempstring,Flat_GlobalArray_Main[i0].Filename_Name);
  1941. f.write (tempstring, strlen(tempstring));
  1942. strcpy(tempstring, ",");
  1943. f.write(tempstring, strlen(tempstring));
  1944. strcpy(tempstring,Flat_GlobalArray_Main[i0].Filename_Full);
  1945. f.write (tempstring, strlen(tempstring));
  1946. }
  1947. #endif
  1948. if (!g_bChangeListOnly)
  1949. {
  1950. f.write("\n", 1);
  1951. }
  1952. }
  1953. // Produce the bottom half -- the sections
  1954. // ------------------------------------
  1955. // use f2 for some other batch processing.
  1956. if (!g_bChangeListOnly)
  1957. {
  1958. f2.open(g_szLSTOutput, ios::out);
  1959. //[SourceDisksNames]
  1960. //; file names and associated disks
  1961. //; diskid = description,tagfile,unused,subdir
  1962. //0="Setup Files","",0
  1963. f.write("\n\n", 2);
  1964. strcpy(tempstring, "[SourceDisksNames]\n");
  1965. f.write(tempstring, strlen(tempstring));
  1966. strcpy(tempstring, ";Filenames and asociated disks\n");
  1967. f.write(tempstring, strlen(tempstring));
  1968. strcpy(tempstring, ";diskid = description,tagfile,unused,subdir\n");
  1969. f.write(tempstring, strlen(tempstring));
  1970. #ifdef USENEW
  1971. FillGlobalUniqueDirList();
  1972. //0="Setup Files","",inetsrv
  1973. //1="Setup Files","",inetsrv\help
  1974. //2="Setup Files","",inetsrv\help\testing
  1975. int i9;
  1976. for( i9 = 0; i9 < Flat_GlobalUniqueDirList_total;i9++)
  1977. {
  1978. // REmove trailing slash character Flat_GlobalUniqueDirList[i9])
  1979. char tempdir[_MAX_PATH];
  1980. char *temppointer = NULL;
  1981. strcpy(tempdir, Flat_GlobalUniqueDirList[i9]);
  1982. temppointer = strrchr(tempdir, '\\');
  1983. if (temppointer) { (*temppointer) = '\0';}
  1984. sprintf(tempstring, "%d=\"Setup Files\",,,%s\n", i9, tempdir);
  1985. f.write(tempstring, strlen(tempstring));
  1986. }
  1987. #else
  1988. strcpy(tempstring, "0 = \"Setup Files\", \"\",0, \"\"\n");
  1989. f.write(tempstring, strlen(tempstring));
  1990. strcpy(tempstring, "\n\n");
  1991. f.write(tempstring, strlen(tempstring));
  1992. #endif
  1993. //[SourceDisksNames.x86]
  1994. //; file names and associated disks
  1995. //; diskid = description,tagfile,unused,subdir
  1996. //0="Setup Files","",0
  1997. f.write("\n\n", 2);
  1998. strcpy(tempstring, "[SourceDisksNames.x86]\n");
  1999. f.write(tempstring, strlen(tempstring));
  2000. strcpy(tempstring, ";Filenames and asociated disks\n");
  2001. f.write(tempstring, strlen(tempstring));
  2002. strcpy(tempstring, ";diskid = description,tagfile,unused,subdir\n");
  2003. f.write(tempstring, strlen(tempstring));
  2004. #ifdef USENEW
  2005. FillGlobalUniqueDirList();
  2006. //0="Setup Files","",inetsrv
  2007. //1="Setup Files","",inetsrv\help
  2008. //2="Setup Files","",inetsrv\help\testing
  2009. for(i9 = 0; i9 < Flat_GlobalUniqueDirList_total;i9++)
  2010. {
  2011. // REmove trailing slash character Flat_GlobalUniqueDirList[i9])
  2012. char tempdir[_MAX_PATH];
  2013. char *temppointer = NULL;
  2014. strcpy(tempdir, Flat_GlobalUniqueDirList[i9]);
  2015. temppointer = strrchr(tempdir, '\\');
  2016. if (temppointer) { (*temppointer) = '\0';}
  2017. sprintf(tempstring, "%d=\"Setup Files\",,,%s\n", i9, tempdir);
  2018. f.write(tempstring, strlen(tempstring));
  2019. }
  2020. #else
  2021. strcpy(tempstring, "0 = \"Setup Files\", \"\",0, \"\",\i386\n");
  2022. f.write(tempstring, strlen(tempstring));
  2023. strcpy(tempstring, "\n\n");
  2024. f.write(tempstring, strlen(tempstring));
  2025. #endif
  2026. //[SourceDisksNames.Alpha]
  2027. //; file names and associated disks
  2028. //; diskid = description,tagfile,unused,subdir
  2029. //0="Setup Files","",0
  2030. f.write("\n\n", 2);
  2031. strcpy(tempstring, "[SourceDisksNames.Alpha]\n");
  2032. f.write(tempstring, strlen(tempstring));
  2033. strcpy(tempstring, ";Filenames and asociated disks\n");
  2034. f.write(tempstring, strlen(tempstring));
  2035. strcpy(tempstring, ";diskid = description,tagfile,unused,subdir\n");
  2036. f.write(tempstring, strlen(tempstring));
  2037. #ifdef USENEW
  2038. FillGlobalUniqueDirList();
  2039. //0="Setup Files","",inetsrv
  2040. //1="Setup Files","",inetsrv\help
  2041. //2="Setup Files","",inetsrv\help\testing
  2042. for(i9 = 0; i9 < Flat_GlobalUniqueDirList_total;i9++)
  2043. {
  2044. // REmove trailing slash character Flat_GlobalUniqueDirList[i9])
  2045. char tempdir[_MAX_PATH];
  2046. char *temppointer = NULL;
  2047. strcpy(tempdir, Flat_GlobalUniqueDirList[i9]);
  2048. temppointer = strrchr(tempdir, '\\');
  2049. if (temppointer) { (*temppointer) = '\0';}
  2050. sprintf(tempstring, "%d=\"Setup Files\",,,%s\n", i9, tempdir);
  2051. f.write(tempstring, strlen(tempstring));
  2052. }
  2053. #else
  2054. strcpy(tempstring, "0 = \"Setup Files\", \"\",0, \"\",\Alpha\n");
  2055. f.write(tempstring, strlen(tempstring));
  2056. strcpy(tempstring, "\n\n");
  2057. f.write(tempstring, strlen(tempstring));
  2058. #endif
  2059. //; filename_on_source = diskid,subdir,size,checksum,spare,spare
  2060. //[SourceDisksFiles]
  2061. //_default.pif = 1,,1024,,,,,1,3
  2062. strcpy(tempstring, "; filename_on_source = diskid,subdir,size,checksum,spare,spare\n");
  2063. f.write(tempstring, strlen(tempstring));
  2064. strcpy(tempstring, "[SourceDisksFiles]\n");
  2065. f.write(tempstring, strlen(tempstring));
  2066. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  2067. {
  2068. // filename and directory
  2069. // filename.txt = 0,subdirectory
  2070. //sprintf(tempstring, "%s = 0\n", Flat_GlobalArray_Main[i0].Filename_Full);
  2071. #ifdef USENEW
  2072. if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE)
  2073. {
  2074. // Check if this file has the rename stuff set and additional info there,
  2075. // don't write the \n until past this part..
  2076. if (_stricmp(Flat_GlobalArray_Main[i0].INF_Rename_To,"") == 0)
  2077. {
  2078. // write out the filename!
  2079. // print out the filename
  2080. //[SourceDisksFiles]
  2081. //..\test1\cfw.pdb=2,,2
  2082. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, Flat_GlobalArray_Main[i0].DDF_Renamed) == 0)
  2083. {
  2084. int indexmatch = GlobalUniqueDirReturnMyIndexMatch(Flat_GlobalArray_Main[i0].Filename_Path);
  2085. sprintf(tempstring, "%s=%d", Flat_GlobalArray_Main[i0].Filename_Name, indexmatch);
  2086. f.write (tempstring, strlen(tempstring));
  2087. }
  2088. else
  2089. {
  2090. // rename from:
  2091. int indexmatch = GlobalUniqueDirReturnMyIndexMatch(Flat_GlobalArray_Main[i0].Filename_Path);
  2092. sprintf(tempstring, "%s=%d", Flat_GlobalArray_Main[i0].DDF_Renamed,indexmatch);
  2093. f.write (tempstring, strlen(tempstring));
  2094. }
  2095. }
  2096. else
  2097. {
  2098. // the rename flag was set and the filename is in there.
  2099. // rename from:
  2100. int indexmatch = GlobalUniqueDirReturnMyIndexMatch(Flat_GlobalArray_Main[i0].Filename_Path);
  2101. sprintf(tempstring, "%s=%d", Flat_GlobalArray_Main[i0].DDF_Renamed,indexmatch);
  2102. f.write (tempstring, strlen(tempstring));
  2103. }
  2104. }
  2105. f.write("\n", 1);
  2106. #else
  2107. sprintf(tempstring, "%s\n", Flat_GlobalArray_Main[i0].Filename_Full);
  2108. f.write(tempstring, strlen(tempstring));
  2109. #endif
  2110. //if (strcmp(Flat_GlobalArray_Main[i0].Filename_Path, "") == 0)
  2111. // {sprintf(tempstring, "%s;.\n", Flat_GlobalArray_Main[i0].Filename_Full);}
  2112. //else
  2113. // {sprintf(tempstring, "%s;%s\n", Flat_GlobalArray_Main[i0].Filename_Full, Flat_GlobalArray_Main[i0].Filename_Path);}
  2114. //sprintf(tempstring, "%s\\%s;%s\n", g_szCurrentDir,Flat_GlobalArray_Main[i0].Filename_Full,Flat_GlobalArray_Main[i0].Filename_Full);
  2115. sprintf(tempstring, "%s\\%s\n", g_szCurrentDir,Flat_GlobalArray_Main[i0].Filename_Full);
  2116. f2.write(tempstring, strlen(tempstring));
  2117. }
  2118. f2.close();
  2119. }
  2120. f.close();
  2121. }
  2122. return;
  2123. }
  2124. //-------------------------------------------------------------------
  2125. // purpose: ok, loop thru the array and create the ddf details...
  2126. //-------------------------------------------------------------------
  2127. void Flat_Create_Output_DDF(void)
  2128. {
  2129. fstream f;
  2130. char thefilename[255];
  2131. int i0;
  2132. int i1;
  2133. int i2;
  2134. int i3;
  2135. char last_cab[50];
  2136. char last_sourcedir[255];
  2137. char this_cab[50];
  2138. char this_sourcedir[255];
  2139. char tempstring[255];
  2140. // used for list of all cab's
  2141. char tempcablist[20][255];
  2142. int tempcablist_nextuse;
  2143. int tempcablist_total;
  2144. int found;
  2145. char temp_cab[50];
  2146. // loop thru all globalarray stuff and get all the cab filenames and stick into the tempcablist.
  2147. tempcablist_nextuse = 0;
  2148. tempcablist_total = 0;
  2149. for(i1=0;i1<Flat_GlobalArrayIndex_Main.total;i1++)
  2150. {
  2151. found=FALSE;
  2152. if (Flat_DoWeIncludeThisFileCheck(i1) == TRUE)
  2153. {
  2154. strcpy(temp_cab, Flat_GlobalArray_Main[i1].CabFileName);
  2155. // loop thru array to see if it's already there.
  2156. for(i2=0;i2<tempcablist_total;i2++)
  2157. {
  2158. if (_stricmp(tempcablist[i2], temp_cab) == 0)
  2159. {found=TRUE;}
  2160. }
  2161. if (found==FALSE)
  2162. {
  2163. // add it
  2164. strcpy(tempcablist[tempcablist_nextuse],temp_cab);
  2165. tempcablist_nextuse++;
  2166. tempcablist_total++;
  2167. }
  2168. }
  2169. }
  2170. // ok, create our little output file...
  2171. f.open(g_szDDFOutput, ios::out);
  2172. strcpy(last_cab, "0");
  2173. strcpy(last_sourcedir, "-");
  2174. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  2175. {
  2176. strcpy(this_cab, Flat_GlobalArray_Main[i0].CabFileName);
  2177. strcpy(this_sourcedir, Flat_GlobalArray_Main[i0].INF_Sections);
  2178. _splitpath( Flat_GlobalArray_Main[i0].Filename_Full, NULL, this_sourcedir, NULL, NULL);
  2179. if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE)
  2180. {
  2181. // For each Cab Type...
  2182. if (_stricmp(this_cab, last_cab) != 0)
  2183. {
  2184. // Check if it is the first time!
  2185. if (_stricmp(last_cab, "0") == 0)
  2186. {
  2187. strcpy(tempstring, "\n;***** LAYOUT SECTION (Generated) ***** \n");
  2188. f.write (tempstring, strlen(tempstring));
  2189. // print out all the cabinet names
  2190. // loop thru the list of cabinet names and print them out.
  2191. for(i2=0;i2<tempcablist_total;i2++)
  2192. {
  2193. sprintf(tempstring, " .Set CabinetName%d=%s\n", i2+1, tempcablist[i2]);
  2194. f.write (tempstring, strlen(tempstring));
  2195. }
  2196. f.write("\n", 1);
  2197. // Set Generate INF=on!!!!
  2198. strcpy(tempstring, ".Set GenerateInf=On\n");
  2199. f.write (tempstring, strlen(tempstring));
  2200. f.write("\n", 1);
  2201. // Do files which don't get included into the cab files..
  2202. strcpy(tempstring, ";*** Files not to include in Cab.\n");
  2203. f.write (tempstring, strlen(tempstring));
  2204. // Set source
  2205. // list files.
  2206. char last_filepath[255];
  2207. char this_filepath[255];
  2208. strcpy(g_non_cablist_temp[0].Filename_Name, "");
  2209. g_non_cablist_temp_nextuse = 0;
  2210. g_non_cablist_temp_total = 0;
  2211. int itexists;
  2212. for(i3=0;i3<Flat_GlobalArrayIndex_Main.total;i3++)
  2213. {
  2214. // check if this entry has the ddf_excludefromcab flag set.
  2215. if (Flat_GlobalArray_Main[i3].DDF_Exclude_From_Cab_Flag)
  2216. {
  2217. // add only if not already there...
  2218. itexists = FALSE;
  2219. for (int i6=0;i6<g_non_cablist_temp_total;i6++)
  2220. {
  2221. if (_stricmp(g_non_cablist_temp[i6].Filename_Name,Flat_GlobalArray_Main[i3].Filename_Name)==0)
  2222. {itexists = TRUE;}
  2223. }
  2224. if (itexists == FALSE)
  2225. {
  2226. // Add to our temporary array...
  2227. g_non_cablist_temp[g_non_cablist_temp_nextuse].NTS_x86_flag = Flat_GlobalArray_Main[i3].NTS_x86_flag;
  2228. g_non_cablist_temp[g_non_cablist_temp_nextuse].NTW_x86_flag = Flat_GlobalArray_Main[i3].NTW_x86_flag;
  2229. g_non_cablist_temp[g_non_cablist_temp_nextuse].Win95_flag = Flat_GlobalArray_Main[i3].Win95_flag;
  2230. g_non_cablist_temp[g_non_cablist_temp_nextuse].Win98_flag = Flat_GlobalArray_Main[i3].Win98_flag;
  2231. g_non_cablist_temp[g_non_cablist_temp_nextuse].NTS_alpha_flag = Flat_GlobalArray_Main[i3].NTS_alpha_flag;
  2232. g_non_cablist_temp[g_non_cablist_temp_nextuse].NTW_alpha_flag = Flat_GlobalArray_Main[i3].NTW_alpha_flag;
  2233. g_non_cablist_temp[g_non_cablist_temp_nextuse].Other_os_flag = Flat_GlobalArray_Main[i3].Other_os_flag;
  2234. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].CabFileName,Flat_GlobalArray_Main[i3].CabFileName);
  2235. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].INF_Sections,Flat_GlobalArray_Main[i3].INF_Sections);
  2236. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].Filename_Full,Flat_GlobalArray_Main[i3].Filename_Full);
  2237. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].Filename_Name,Flat_GlobalArray_Main[i3].Filename_Name);
  2238. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].Filename_Path,Flat_GlobalArray_Main[i3].Filename_Path);
  2239. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].DDF_Renamed,Flat_GlobalArray_Main[i3].DDF_Renamed);
  2240. strcpy(g_non_cablist_temp[g_non_cablist_temp_nextuse].INF_Rename_To,Flat_GlobalArray_Main[i3].INF_Rename_To);
  2241. g_non_cablist_temp[g_non_cablist_temp_nextuse].DDF_Exclude_From_Cab_Flag = Flat_GlobalArray_Main[i3].DDF_Exclude_From_Cab_Flag;
  2242. g_non_cablist_temp[g_non_cablist_temp_nextuse].Do_Not_Show_Error_Flag = Flat_GlobalArray_Main[i3].Do_Not_Show_Error_Flag;
  2243. g_non_cablist_temp[g_non_cablist_temp_nextuse].Do_Not_Include_file_if_cabEmpty_Flag = Flat_GlobalArray_Main[i3].Do_Not_Include_file_if_cabEmpty_Flag;
  2244. g_non_cablist_temp[g_non_cablist_temp_nextuse].FileName_Size = Flat_GlobalArray_Main[i3].FileName_Size;
  2245. g_non_cablist_temp[g_non_cablist_temp_nextuse].FileWasNotActuallyFoundToExist = Flat_GlobalArray_Main[i3].FileWasNotActuallyFoundToExist;
  2246. g_non_cablist_temp[g_non_cablist_temp_nextuse].GetFromSlipStreamDisk = Flat_GlobalArray_Main[i3].GetFromSlipStreamDisk;
  2247. /*
  2248. if (Flat_GlobalArray_Main[i3].FileWasNotActuallyFoundToExist)
  2249. {
  2250. printf(Flat_GlobalArray_Main[i3].Filename_Full);
  2251. printf(". HEY..\n");
  2252. }
  2253. */
  2254. g_non_cablist_temp_nextuse++;
  2255. g_non_cablist_temp_total++;
  2256. }
  2257. }
  2258. }
  2259. // sort the array
  2260. int offset, inorder, isort, jsort, niterate, resultsort; //, i0sort;
  2261. //FileReadLine tempentrysort[MAX_ARRAY_SMALL];
  2262. FileReadLine tempentrysort;
  2263. niterate = g_non_cablist_temp_total;
  2264. offset=niterate;
  2265. do{
  2266. offset = (8 * offset) /11;
  2267. offset = (offset == 0) ? 1 : offset;
  2268. inorder = TRUE;
  2269. for (isort=0,jsort=offset;isort < (niterate - offset);isort++,jsort++)
  2270. {
  2271. resultsort = _stricmp(g_non_cablist_temp[isort].Filename_Path, g_non_cablist_temp[jsort].Filename_Path);
  2272. if (resultsort > 0)
  2273. {
  2274. inorder = FALSE;
  2275. // do the swap
  2276. // move into temp
  2277. tempentrysort = g_non_cablist_temp[isort];
  2278. // move into original
  2279. g_non_cablist_temp[isort] = g_non_cablist_temp[jsort];
  2280. // move temp into other
  2281. g_non_cablist_temp[jsort] = tempentrysort;
  2282. /* weird to stuff..
  2283. // do the swap
  2284. // move into temp
  2285. for (i0sort=0;i0sort<MAX_ARRAY_SMALL;i0sort++)
  2286. {
  2287. tempentrysort[i0sort] = g_non_cablist_temp[isort];
  2288. //strcpy(tempentrysort[i0sort].thestring,(g_non_cablist_temp[isort].thecol[i0sort].thestring));
  2289. }
  2290. // move into original
  2291. for (i0sort=0;i0sort<MAX_ARRAY_SMALL;i0sort++)
  2292. {
  2293. // move into original
  2294. Flat_GlobalArray_Main[isort] = g_non_cablist_temp[jsort];
  2295. //strcpy( Flat_GlobalArray_Main[isort].thecol[i0sort].thestring, g_non_cablist_temp[jsort].thecol[i0sort].thestring);
  2296. }
  2297. // move temp into other
  2298. for (i0sort=0;i0sort<MAX_ARRAY_SMALL;i0sort++)
  2299. {
  2300. g_non_cablist_temp[jsort] = tempentrysort[i0sort];
  2301. //strcpy(g_non_cablist_temp[jsort].thecol[i0sort].thestring, tempentrysort[i0sort].thestring);
  2302. }
  2303. */
  2304. }
  2305. }
  2306. } while (!(offset == 1 && inorder == TRUE));
  2307. strcpy(tempstring, ".Set Compress=OFF\n");
  2308. f.write (tempstring, strlen(tempstring));
  2309. strcpy(tempstring, ".Set Cabinet=OFF\n");
  2310. f.write (tempstring, strlen(tempstring));
  2311. // loop thru our new array, and output stuff
  2312. strcpy(last_filepath,"0");
  2313. for (int i5=0;i5<g_non_cablist_temp_total;i5++)
  2314. {
  2315. strcpy(this_filepath, g_non_cablist_temp[i5].Filename_Path);
  2316. if (_stricmp(last_filepath, this_filepath) != 0)
  2317. {
  2318. // take the dir and write it out
  2319. f.write("\n", 1);
  2320. sprintf(tempstring, ".Set SourceDir=%s\n", this_filepath);
  2321. f.write (tempstring, strlen(tempstring));
  2322. strcpy(last_filepath, this_filepath);
  2323. }
  2324. if (g_non_cablist_temp[i5].FileWasNotActuallyFoundToExist)
  2325. {
  2326. printf(g_non_cablist_temp[i5].Filename_Full);
  2327. printf(". FileWasNotActuallyFoundToExist.skip write to ddf..\n");
  2328. g_iGlobalReturnCode = FALSE;
  2329. }
  2330. else
  2331. {
  2332. // print out the filename
  2333. if (_stricmp(g_non_cablist_temp[i5].Filename_Name, g_non_cablist_temp[i5].DDF_Renamed) == 0)
  2334. {strcpy(tempstring,g_non_cablist_temp[i5].Filename_Name);}
  2335. else
  2336. {
  2337. strcpy(tempstring,g_non_cablist_temp[i5].Filename_Name);
  2338. strcat(tempstring," ");
  2339. strcat(tempstring,g_non_cablist_temp[i5].DDF_Renamed);
  2340. }
  2341. f.write (tempstring, strlen(tempstring));
  2342. // files which are outside of the cab should have the unique flag set.
  2343. // of cource, because they are all in the same place!!
  2344. // check if this is one of those "special" files which
  2345. // come from a service pack.
  2346. if (g_non_cablist_temp[i5].GetFromSlipStreamDisk == 0)
  2347. {
  2348. strcpy(tempstring, "\t/unique=yes");
  2349. }
  2350. else
  2351. {
  2352. sprintf(tempstring,"\t/unique=yes /cab#=%d", g_iSlipStreamDiskID);
  2353. }
  2354. f.write (tempstring, strlen(tempstring));
  2355. f.write("\n", 1);
  2356. }
  2357. }
  2358. f.write("\n", 1);
  2359. // Files which do get included in the Cab
  2360. strcpy(tempstring, ";*** Files to include in Cabs.\n");
  2361. f.write (tempstring, strlen(tempstring));
  2362. f.write(";\n", 2);
  2363. sprintf(tempstring, "; Cab File = %s\n", this_cab);
  2364. f.write (tempstring, strlen(tempstring));
  2365. f.write(";\n", 2);
  2366. // Set cabinet on and compress on.
  2367. strcpy(tempstring, ".Set Cabinet=on\n");
  2368. f.write (tempstring, strlen(tempstring));
  2369. strcpy(tempstring, ".Set Compress=on\n");
  2370. f.write (tempstring, strlen(tempstring));
  2371. }
  2372. else
  2373. {
  2374. f.write("\n;\n", 3);
  2375. sprintf(tempstring, "; Cab File = %s\n", this_cab);
  2376. f.write (tempstring, strlen(tempstring));
  2377. f.write(";\n", 2);
  2378. // Write new stuff for every new cabinet
  2379. strcpy(tempstring, ".Set Cabinet=off\n");
  2380. f.write (tempstring, strlen(tempstring));
  2381. strcpy(tempstring, ".Set Cabinet=on\n");
  2382. f.write (tempstring, strlen(tempstring));
  2383. strcpy(tempstring, ".New Cabinet\n");
  2384. f.write (tempstring, strlen(tempstring));
  2385. }
  2386. strcpy(last_cab, this_cab);
  2387. }
  2388. // Copy over the filename
  2389. // don't copy over if the file should not be
  2390. // included in the the cab file.
  2391. //if (_stricmp(Flat_GlobalArray_Main[i0].thecol[COL_DDF_EXCLUDEFROMCAB].thestring,"true") != 0)
  2392. if (!(Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag))
  2393. {
  2394. // don't copy over if the same file, in the same directory for the same cab file
  2395. // exists already. this could happen if they want the same file in different
  2396. // sections....
  2397. if (Flat_DDFDoesThisFileCabAlreadyExists(i0) == FALSE)
  2398. {
  2399. //if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE) {
  2400. // For each new directory change
  2401. if (_stricmp(this_sourcedir, last_sourcedir) != 0)
  2402. {
  2403. // print out new section stuff
  2404. f.write("\n", 1);
  2405. sprintf(tempstring, ".Set SourceDir=%s\n", this_sourcedir);
  2406. f.write (tempstring, strlen(tempstring));
  2407. strcpy(last_sourcedir, this_sourcedir);
  2408. }
  2409. // write out the filename!
  2410. strcpy(thefilename, Flat_GlobalArray_Main[i0].Filename_Name);
  2411. if (_stricmp(Flat_GlobalArray_Main[i0].Filename_Name, Flat_GlobalArray_Main[i0].DDF_Renamed) == 0)
  2412. {
  2413. // Check for spaces
  2414. if (strchr(Flat_GlobalArray_Main[i0].Filename_Name, ' ') != NULL)
  2415. {
  2416. strcpy(thefilename, "\"");
  2417. strcat(thefilename,Flat_GlobalArray_Main[i0].Filename_Name);
  2418. strcat(thefilename, "\"");
  2419. }
  2420. else
  2421. {strcpy(thefilename,Flat_GlobalArray_Main[i0].Filename_Name);}
  2422. }
  2423. else
  2424. {
  2425. // Check for spaces
  2426. if (strchr(Flat_GlobalArray_Main[i0].Filename_Name, ' ') != NULL)
  2427. {
  2428. strcpy(thefilename, "\"");
  2429. strcat(thefilename,Flat_GlobalArray_Main[i0].Filename_Name);
  2430. strcat(thefilename, "\"");
  2431. }
  2432. else
  2433. {
  2434. strcpy(thefilename,Flat_GlobalArray_Main[i0].Filename_Name);
  2435. }
  2436. strcat(thefilename," ");
  2437. // check for spaces
  2438. if (strchr(Flat_GlobalArray_Main[i0].DDF_Renamed, ' ') != NULL)
  2439. {
  2440. strcpy(thefilename, "\"");
  2441. strcat(thefilename,Flat_GlobalArray_Main[i0].DDF_Renamed);
  2442. strcat(thefilename, "\"");
  2443. }
  2444. else
  2445. {
  2446. strcat(thefilename,Flat_GlobalArray_Main[i0].DDF_Renamed);
  2447. }
  2448. }
  2449. f.write (thefilename, strlen(thefilename));
  2450. // Check if this file has the unique flag set.
  2451. // don't write the \n until past this part..
  2452. /*if (_stricmp(Flat_GlobalArray_Main[i0].thecol[COL_DDF_UNIQUE].thestring,"true")) == 0)
  2453. {
  2454. strcpy(tempstring, "\t/unique=yes");
  2455. f.write (tempstring, strlen(tempstring));
  2456. }
  2457. */
  2458. // ok, now it's kool to write this part.
  2459. f.write ("\n", 1);
  2460. //}
  2461. }
  2462. }
  2463. }
  2464. }
  2465. f.close();
  2466. return;
  2467. }
  2468. //-------------------------------------------------------------------
  2469. // purpose:
  2470. //-------------------------------------------------------------------
  2471. int Flat_Create_Output_ERR(void)
  2472. {
  2473. int i0;
  2474. fstream f;
  2475. char filename_only[255];
  2476. char szPath[_MAX_PATH];
  2477. char tempstring[MAX_STRING];
  2478. // Get the path
  2479. GetModuleFileName(NULL, szPath, _MAX_PATH);
  2480. // split up this path
  2481. _splitpath( szPath, NULL, NULL, filename_only, NULL);
  2482. strcat(filename_only, ".ERR");
  2483. // if there are any errors to report...
  2484. if (Flat_GlobalArrayIndex_Err.total <= 0)
  2485. {return FALSE;}
  2486. // open the file
  2487. f.open(filename_only, ios::out);
  2488. // loop thru the errors and print out the errors
  2489. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Err.total;i0++)
  2490. {
  2491. strcpy(tempstring, (char*)Flat_GlobalArray_Err[i0]);
  2492. f.write (tempstring, strlen(tempstring));
  2493. f.write("\n", 1);
  2494. }
  2495. f.close();
  2496. return TRUE;
  2497. }
  2498. //-------------------------------------------------------------------
  2499. // purpose:
  2500. //-------------------------------------------------------------------
  2501. void Flat_GlobalArray_Add_Err(char theentry[])
  2502. {
  2503. g_iGlobalReturnCode = FALSE;
  2504. // lets add it
  2505. strcpy(Flat_GlobalArray_Err[Flat_GlobalArrayIndex_Err.nextuse], theentry);
  2506. // increment counter to array
  2507. // increment next use space
  2508. ++Flat_GlobalArrayIndex_Err.total;
  2509. ++Flat_GlobalArrayIndex_Err.nextuse;
  2510. return;
  2511. }
  2512. //-------------------------------------------------------------------
  2513. // purpose:
  2514. //-------------------------------------------------------------------
  2515. void Flat_GlobalArray_Print_Err(void)
  2516. {
  2517. int i0;
  2518. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Err.total;i0++)
  2519. {
  2520. printf (Flat_GlobalArray_Err[i0]);
  2521. printf ("\n");
  2522. }
  2523. return;
  2524. }
  2525. //-------------------------------------------------------------------
  2526. // purpose:
  2527. // the problem with regular strtok2 is that it will
  2528. // skip stuff like ",,," and ignore all the blanks in
  2529. // between to get to the next token. this strtok2 function
  2530. // was written to over come that. so that strtok2 works like
  2531. // you think it would.
  2532. //-------------------------------------------------------------------
  2533. char * __cdecl strtok2 (char * string,const char * control)
  2534. {
  2535. //unsigned char *str;
  2536. //const unsigned char *ctrl = control;
  2537. //unsigned char map[32];
  2538. char *str;
  2539. const char *ctrl = control;
  2540. char map[32];
  2541. int count;
  2542. static char *nextoken;
  2543. /* Clear control map */
  2544. for (count = 0; count < 32; count++)
  2545. map[count] = 0;
  2546. /* Set bits in delimiter table */
  2547. do
  2548. {
  2549. map[*ctrl >> 3] |= (1 << (*ctrl & 7));
  2550. } while (*ctrl++);
  2551. /* Initialize str. If string is NULL, set str to the saved
  2552. * pointer (i.e., continue breaking tokens out of the string
  2553. * from the last strtok2 call) */
  2554. if (string)
  2555. str = string;
  2556. else
  2557. str = nextoken;
  2558. /* Find beginning of token (skip over leading delimiters). Note that
  2559. * there is no token iff this loop sets str to point to the terminal
  2560. * null (*str == '\0') */
  2561. /*
  2562. while (
  2563. (map[*str >> 3] & (1 << (*str & 7) ) ) && *str
  2564. )
  2565. str++;
  2566. */
  2567. string = str;
  2568. /* Find the end of the token. If it is not the end of the string,
  2569. * put a null there. */
  2570. for ( ; *str ; str++ )
  2571. if ( map[*str >> 3] & (1 << (*str & 7)) ) {
  2572. *str++ = '\0';
  2573. break;
  2574. }
  2575. /* Update nextoken (or the corresponding field in the per-thread data
  2576. * structure */
  2577. nextoken = str;
  2578. /* Determine if a token has been found. */
  2579. if ( string == str )
  2580. return NULL;
  2581. else
  2582. return string;
  2583. }
  2584. int RemoveAllSpaces(LPSTR & thetempstring)
  2585. {
  2586. int iReturn = FALSE;
  2587. int j = 0;
  2588. char thevalue[1024];
  2589. char tempstring2[1024];
  2590. strcpy(tempstring2, thetempstring);
  2591. // strset(thevalue, '\0');
  2592. strcpy(thevalue, "");
  2593. for (int i=0;i < (int) strlen(tempstring2);i++)
  2594. {
  2595. if (tempstring2[i] == ' ')
  2596. {
  2597. iReturn = TRUE;
  2598. }
  2599. else
  2600. {
  2601. thevalue[j] = tempstring2[i];
  2602. thevalue[j+1] = '\0';
  2603. j++;
  2604. }
  2605. }
  2606. if (iReturn == TRUE) {strcpy(thetempstring, thevalue);}
  2607. return iReturn;
  2608. }
  2609. int Flat_DoWeIncludeThisFileCheck(int processeduptill)
  2610. {
  2611. //return TRUE;
  2612. int iReturn = FALSE;
  2613. int i0 = 0;
  2614. int TheCount = 0;
  2615. char CompareTo_cab[100];
  2616. if (Flat_GlobalArray_Main[processeduptill].Do_Not_Include_file_if_cabEmpty_Flag != 1) {return TRUE;}
  2617. // Grab the cabfilename
  2618. strcpy(CompareTo_cab, Flat_GlobalArray_Main[processeduptill].CabFileName);
  2619. for( i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  2620. {
  2621. if (i0 != processeduptill)
  2622. {
  2623. if (Flat_GlobalArray_Main[i0].Do_Not_Include_file_if_cabEmpty_Flag != 1)
  2624. {
  2625. if (_stricmp(Flat_GlobalArray_Main[i0].CabFileName, CompareTo_cab) == 0)
  2626. {
  2627. ++TheCount;
  2628. break;
  2629. }
  2630. }
  2631. }
  2632. }
  2633. if (TheCount > 0){iReturn = TRUE;}
  2634. return iReturn;
  2635. }
  2636. void Global_TotalCabFileSize_Compute(void)
  2637. {
  2638. char szTheCabFileName[50] = "";
  2639. int MyFileSize = 0;
  2640. int TheNextUse = 0;
  2641. int iTheFlag = FALSE;
  2642. int iIndexToUse = 0;
  2643. // Go thru the whole list and add everything up
  2644. for( int i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  2645. {
  2646. if (Flat_DoWeIncludeThisFileCheck(i0) == TRUE)
  2647. {
  2648. if (!(Flat_GlobalArray_Main[i0].DDF_Exclude_From_Cab_Flag))
  2649. {
  2650. iIndexToUse = Flat_GlobalArrayIndex_CabSizes.nextuse;
  2651. TheNextUse = 0;
  2652. // lets add it if not already there.
  2653. while (TheNextUse < Flat_GlobalArrayIndex_CabSizes.total)
  2654. {
  2655. if (_stricmp(Flat_GlobalArray_CabSizes[TheNextUse].CabFileName, Flat_GlobalArray_Main[i0].CabFileName) == 0)
  2656. {
  2657. iIndexToUse = TheNextUse;
  2658. iTheFlag = TRUE;
  2659. break;
  2660. }
  2661. TheNextUse++;
  2662. }
  2663. if (iTheFlag == TRUE)
  2664. {
  2665. // copy over the filename
  2666. strcpy(Flat_GlobalArray_CabSizes[iIndexToUse].CabFileName, Flat_GlobalArray_Main[i0].CabFileName);
  2667. // Get the size
  2668. Flat_GlobalArray_CabSizes[iIndexToUse].TotalFileSize = Flat_GlobalArray_CabSizes[iIndexToUse].TotalFileSize + Flat_GlobalArray_Main[i0].FileName_Size;
  2669. Flat_GlobalArray_CabSizes[iIndexToUse].TotalFiles++;
  2670. }
  2671. else
  2672. {
  2673. iIndexToUse = Flat_GlobalArrayIndex_CabSizes.nextuse;
  2674. // copy over the filename
  2675. strcpy(Flat_GlobalArray_CabSizes[iIndexToUse].CabFileName, Flat_GlobalArray_Main[i0].CabFileName);
  2676. // Get the size
  2677. Flat_GlobalArray_CabSizes[iIndexToUse].TotalFileSize = Flat_GlobalArray_CabSizes[iIndexToUse].TotalFileSize + Flat_GlobalArray_Main[i0].FileName_Size;
  2678. Flat_GlobalArray_CabSizes[iIndexToUse].TotalFiles++;
  2679. ++Flat_GlobalArrayIndex_CabSizes.total;
  2680. ++Flat_GlobalArrayIndex_CabSizes.nextuse;
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. void Global_TotalCabFileSize_Print(void)
  2687. {
  2688. int i0;
  2689. char stempstring[100];
  2690. for( i0 = 0; i0 < Flat_GlobalArrayIndex_CabSizes.total;i0++)
  2691. {
  2692. sprintf(stempstring, "%s: Filecount=%d, Size=%d\n",Flat_GlobalArray_CabSizes[i0].CabFileName, Flat_GlobalArray_CabSizes[i0].TotalFiles, Flat_GlobalArray_CabSizes[i0].TotalFileSize);
  2693. printf(stempstring);
  2694. }
  2695. printf("\n");
  2696. return;
  2697. }
  2698. // Returns the count of the "\" characters in the string
  2699. //
  2700. int ReturnDirLevelCount(char *DirectoryTree)
  2701. {
  2702. int TheCount = 0;
  2703. char szTemp[_MAX_PATH];
  2704. _tcscpy(szTemp, DirectoryTree);
  2705. char *p = szTemp;
  2706. while (*p)
  2707. {
  2708. if (*p == '\\')
  2709. {TheCount++;}
  2710. p = _tcsinc(p);
  2711. }
  2712. return TheCount;
  2713. }
  2714. void FillGlobalUniqueDirList()
  2715. {
  2716. // used to keep a list of unique directory names.
  2717. // loop thru the whole structure and pull out all the unique directory names.
  2718. for( int i0 = 0; i0 < Flat_GlobalArrayIndex_Main.total;i0++)
  2719. {
  2720. // check if entries are the same.
  2721. if (FALSE == GlobalUniqueDirChkIfAlreadyThere(Flat_GlobalArray_Main[i0].Filename_Path))
  2722. {
  2723. // Not there yet. so let's add it
  2724. strcpy(Flat_GlobalUniqueDirList[Flat_GlobalUniqueDirList_nextuse], Flat_GlobalArray_Main[i0].Filename_Path);
  2725. // increment counter to array
  2726. // increment next use space
  2727. ++Flat_GlobalUniqueDirList_total;
  2728. ++Flat_GlobalUniqueDirList_nextuse;
  2729. }
  2730. }
  2731. return;
  2732. }
  2733. int GlobalUniqueDirChkIfAlreadyThere(char *TheStringToCheck)
  2734. {
  2735. int iReturn = FALSE;
  2736. for( int i0 = 0; i0 < Flat_GlobalUniqueDirList_total;i0++)
  2737. {
  2738. if (_stricmp(Flat_GlobalUniqueDirList[i0], TheStringToCheck) == 0)
  2739. {
  2740. iReturn = TRUE;
  2741. goto isItAlreadyThere_Exit;
  2742. }
  2743. }
  2744. isItAlreadyThere_Exit:
  2745. return iReturn;
  2746. }
  2747. int GlobalUniqueDirReturnMyIndexMatch(char *TheStringToCheck)
  2748. {
  2749. int iReturn = 0;
  2750. for( int i0 = 0; i0 < Flat_GlobalUniqueDirList_total;i0++)
  2751. {
  2752. if (_stricmp(Flat_GlobalUniqueDirList[i0], TheStringToCheck) == 0)
  2753. {
  2754. iReturn = i0;
  2755. goto GlobalUniqueDirReturnMyIndexMatch_Exit;
  2756. }
  2757. }
  2758. GlobalUniqueDirReturnMyIndexMatch_Exit:
  2759. return iReturn;
  2760. }
  2761. //***************************************************************************
  2762. //* NAME: StripWhitespace *
  2763. //* SYNOPSIS: Strips spaces and tabs from both sides of given string. *
  2764. //***************************************************************************
  2765. LPSTR StripWhitespaceA( LPSTR pszString )
  2766. {
  2767. LPSTR pszTemp = NULL;
  2768. if ( pszString == NULL ) {
  2769. return NULL;
  2770. }
  2771. while ( *pszString == ' ' || *pszString == '\t' ) {
  2772. pszString += 1;
  2773. }
  2774. // Catch case where string consists entirely of whitespace or empty string.
  2775. if ( *pszString == '\0' ) {
  2776. return pszString;
  2777. }
  2778. pszTemp = pszString;
  2779. pszString += lstrlenA(pszString) - 1;
  2780. while ( *pszString == ' ' || *pszString == '\t' ) {
  2781. *pszString = '\0';
  2782. pszString -= 1;
  2783. }
  2784. return pszTemp;
  2785. }