Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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