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.

214 lines
7.2 KiB

  1. // fxsinfsize.cpp : Defines the entry point for the console application.
  2. //
  3. #include <windows.h>
  4. #include <setupapi.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. void GetFileSizeAsString(LPCSTR FilePath,LPCSTR FileName,LPSTR FileSizeString);
  8. DWORD ParseCommandLine(int argc, char* argv[],LPSTR* lpstrInfFile,LPSTR* lpstrPathToBinaries);
  9. struct BinaryMapping
  10. {
  11. LPCSTR FileNameInInf;
  12. LPCSTR FileNameInDrop;
  13. };
  14. BinaryMapping FileNameList[] =
  15. {
  16. {"fxsadmin.msc", "\\fxsadmin.msc"},
  17. {"fxsadmin.dll", "\\fxsadmin.dll"},
  18. {"fxsrtmtd.dll", "\\fxsrtmtd.dll"},
  19. {"fxst30p.dll", "\\fxst30p.dll"},
  20. {"fxsapi.dll", "\\fxsapi.dll"},
  21. {"fxscfgwz.dll", "\\fxscfgwz.dll"},
  22. {"fxscom.dll", "\\fxscom.dll"},
  23. {"fxscomex.dll", "\\fxscomex.dll"},
  24. {"fxsclntR.dll", "\\fxsclntR.dll"},
  25. {"fxsclnt.exe", "\\fxsclnt.exe"},
  26. {"fxscount.h", "\\fxscount.h"},
  27. {"fxscover.exe", "\\fxscover.exe"},
  28. {"fxsdrv.dll", "\\fxsdrv.dll"},
  29. {"fxsevent.dll", "\\fxsevent.dll"},
  30. {"fxsext32.dll", "\\fxsext32.dll"},
  31. {"fxsmon.dll", "\\fxsmon.dll"},
  32. {"fxsperf.dll", "\\fxsperf.dll"},
  33. {"fxsperf.ini", "\\fxsperf.ini"},
  34. {"fxsres.dll", "\\fxsres.dll"},
  35. {"fxsroute.dll", "\\fxsroute.dll"},
  36. {"fxssend.exe", "\\fxssend.exe"},
  37. {"fxsst.dll", "\\fxsst.dll"},
  38. {"fxssvc.exe", "\\fxssvc.exe"},
  39. {"fxst30.dll", "\\fxst30.dll"},
  40. {"fxstiff.dll", "\\fxstiff.dll"},
  41. {"fxsui.dll", "\\fxsui.dll"},
  42. {"fxswzrd.dll", "\\fxswzrd.dll"},
  43. {"fxsxp32.dll", "\\fxsxp32.dll"},
  44. {"fxsext.ecf", "\\fxsext.ecf"},
  45. {"fxsclnt.msi", "\\fxsclnt.msi"},
  46. {"confdent.cov", "\\confdent.cov"},
  47. {"fyi.cov", "\\fyi.cov"},
  48. {"generic.cov", "\\generic.cov"},
  49. {"urgent.cov", "\\urgent.cov"},
  50. {"fxscl_s.hlp", "\\fxscl_s.hlp"},
  51. {"instmsia.exe", "\\instmsia.exe"},
  52. {"instmsiw.exe", "\\instmsiw.exe"},
  53. {"mfc42.dll", "\\mfc42.dll"},
  54. {"mfc42u.dll", "\\mfc42u.dll"},
  55. {"msvcp60.dll", "\\msvcp60.dll"},
  56. {"NT4_fxsdrv4.dll", "\\fxsdrv4.dll"},
  57. {"NT4_fxsapi.dll", "\\faxclients\\nt4\\fxsapi.dll"},
  58. {"W95_iconlib.dll", "\\faxclients\\win9x\\win95\\iconlib.dll"},
  59. {"W95_unidrv.dll", "\\faxclients\\win9x\\win95\\unidrv.hlp"},
  60. {"W95_unidrv.hlp", "\\faxclients\\win9x\\win95\\unidrv.hlp"},
  61. {"W98_iconlib.dll", "\\faxclients\\win9x\\win98\\iconlib.dll"},
  62. {"W98_unidrv.dll", "\\faxclients\\win9x\\win98\\unidrv.dll"},
  63. {"W98_unidrv.hlp", "\\faxclients\\win9x\\win98\\unidrv.dll"},
  64. {"W9X_fxsapi.dll", "\\faxclients\\win9x\\fxsapi.dll"},
  65. {"W9X_fxsclnt.exe", "\\faxclients\\win9x\\fxsclnt.exe"},
  66. {"W9X_fxsclntr.dll", "\\faxclients\\win9x\\fxsclntr.dll"},
  67. {"W9X_fxscover.exe", "\\faxclients\\win9x\\fxscover.exe"},
  68. {"W9X_fxsdrv16.drv", "\\faxclients\\win9x\\fxsdrv16.drv"},
  69. {"W9X_fxsdrv32.dll", "\\faxclients\\win9x\\fxsdrv32.dll"},
  70. {"W9X_fxsext32.dll", "\\faxclients\\win9x\\fxsext32.dll"},
  71. {"W9X_fxstiff.dll", "\\faxclients\\win9x\\fxstiff.dll"},
  72. {"W9X_fxssend.exe", "\\faxclients\\win9x\\fxssend.exe"},
  73. {"W9X_fxsxp32.dll", "\\faxclients\\win9x\\fxsxp32.dll"},
  74. {"W9X_fxswzrd.dll", "\\faxclients\\win9x\\fxswzrd.dll"},
  75. {"FXS_fxsclnt.chm", "\\faxclients\\win9x\\fxscldwn.chm"},
  76. {"FXS_fxscover.chm", "\\faxclients\\win9x\\fxscov_d.chm"},
  77. {"FXS_setup.exe", "\\faxclients\\fxssetup.exe"},
  78. {"FXS_strap.exe", "\\faxclients\\fxsstrap.exe"},
  79. {"FXS_setup.ini", "\\faxclients\\setup.ini"},
  80. {"FXS_msvcrt.dll", "\\faxclients\\fxsmsvcrt.dll"}
  81. };
  82. int cFileName = sizeof(FileNameList)/sizeof(FileNameList[0]);
  83. int __cdecl main(int argc, char* argv[])
  84. {
  85. LPSTR lpstrInfFile = NULL;
  86. LPSTR lpstrPathToBinaries = NULL;
  87. LPSTR lpstrLastComma = NULL;
  88. CHAR lpstrInputLine[MAX_PATH] = {0};
  89. CHAR lpstrFileSize[MAX_PATH] = {0};
  90. // parse command line parameters
  91. if (ParseCommandLine(argc,argv,&lpstrInfFile,&lpstrPathToBinaries)!=ERROR_SUCCESS)
  92. {
  93. printf("ERROR Running FXSINFSIZE.EXE\n\n");
  94. printf("Usage:\n");
  95. printf("fxsinfsize.exe /i:<inf file name> /p:<path to binaries>\n");
  96. printf("<inf file name> - full path to FXSOCM.INF being processed\n");
  97. printf("<path to binaries> - location of the drop in which the fax binaries are\n\n");
  98. printf("Example: fxsinfsize.exe /i fxsocm.inf /p %%_NTPOSTBLD%%\n");
  99. goto exit;
  100. }
  101. printf("Input INF file is: %s\n",lpstrInfFile);
  102. printf("Input path to binaries is: %s\n",lpstrPathToBinaries);
  103. printf("parsing %d files\n",cFileName);
  104. for (int iIndex=0; iIndex<cFileName; iIndex++)
  105. {
  106. GetPrivateProfileString("SourceDisksFiles",
  107. FileNameList[iIndex].FileNameInInf,
  108. "",
  109. lpstrInputLine,
  110. MAX_PATH,
  111. lpstrInfFile);
  112. if (strlen(lpstrInputLine)==0)
  113. {
  114. // lookup for this entry failed, let's loop for the next.
  115. printf("failed to lookup %s in %s\n",FileNameList[iIndex].FileNameInInf,lpstrInfFile);
  116. continue;
  117. }
  118. // get the file size as a string representation
  119. GetFileSizeAsString(lpstrPathToBinaries,FileNameList[iIndex].FileNameInDrop,lpstrFileSize);
  120. if (strlen(lpstrFileSize)==0)
  121. {
  122. // getting the file size failed.
  123. // we have to write something to the INF otherwise the
  124. // SetupAddInstallSectionToDiskSpaceList API fails
  125. // so, we fake a size.
  126. strncpy(lpstrFileSize,"100000",MAX_PATH);
  127. printf("failed to get size for %s\n",FileNameList[iIndex].FileNameInDrop);
  128. }
  129. // create the complete line.
  130. lpstrLastComma = strrchr(lpstrInputLine,',');
  131. if (lpstrLastComma==NULL)
  132. {
  133. printf("No comma in input string\n");
  134. continue;
  135. }
  136. *(++lpstrLastComma)=0;
  137. strncat(lpstrInputLine,lpstrFileSize,MAX_PATH-strlen(lpstrInputLine)-1);
  138. printf("writing to %s: %s\n",FileNameList[iIndex].FileNameInInf,lpstrInputLine);
  139. // write it back to the INF
  140. if (!WritePrivateProfileString( "SourceDisksFiles",
  141. FileNameList[iIndex].FileNameInInf,
  142. lpstrInputLine,
  143. lpstrInfFile))
  144. {
  145. // writing the updated string failed, loop for the next
  146. printf("WritePrivateProfileString %s failed, ec=%d\n",FileNameList[iIndex].FileNameInInf,GetLastError());
  147. }
  148. }
  149. exit:
  150. return 0;
  151. }
  152. void GetFileSizeAsString(LPCSTR FilePath,LPCSTR FileName,LPSTR FileSizeString)
  153. {
  154. WIN32_FILE_ATTRIBUTE_DATA FileAttributeData;
  155. CHAR szPathToFile[MAX_PATH] = {0};
  156. strncpy(szPathToFile,FilePath,MAX_PATH-1);
  157. strncat(szPathToFile,FileName,MAX_PATH-strlen(szPathToFile)-1);
  158. if (!GetFileAttributesEx(szPathToFile,GetFileExInfoStandard,&FileAttributeData))
  159. {
  160. printf("GetFileAttributesEx %s failed, ec=%d\n",szPathToFile,GetLastError());
  161. // fake some size so we get a count anyway.
  162. FileAttributeData.nFileSizeLow = 100000;
  163. }
  164. _itoa(FileAttributeData.nFileSizeLow,FileSizeString,10);
  165. }
  166. DWORD ParseCommandLine(int argc, char* argv[],LPSTR* lpstrInfFile,LPSTR* lpstrPathToBinaries)
  167. {
  168. if (argc!=3)
  169. {
  170. return ERROR_INVALID_PARAMETER;
  171. }
  172. for (int i = 1; i < argc; i++)
  173. {
  174. if ((_strnicmp("/i:",argv[i],3)==0) && (strlen(argv[i])>3))
  175. {
  176. (*lpstrInfFile) = argv[i]+3;
  177. if (strlen((*lpstrInfFile))==0)
  178. {
  179. return ERROR_INVALID_PARAMETER;
  180. }
  181. }
  182. else if ((!_strnicmp("/p:",argv[i],3)) && (strlen(argv[i])>3))
  183. {
  184. (*lpstrPathToBinaries) = argv[i]+3;
  185. if (strlen((*lpstrPathToBinaries))==0)
  186. {
  187. return ERROR_INVALID_PARAMETER;
  188. }
  189. }
  190. else
  191. {
  192. return ERROR_INVALID_PARAMETER;
  193. }
  194. }
  195. return ERROR_SUCCESS;
  196. }