Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: M A I N . C P P
  7. //
  8. // Contents: Tool for merging icons
  9. //
  10. // Author: jeffspr Nov-18-98
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.h"
  14. #pragma hdrstop
  15. #include "ncdebug.h"
  16. #include "icomerge.h"
  17. #include "tchar.h"
  18. //---[ Globals ]--------------------------------------------------------------
  19. BOOL g_fVerbose = FALSE;
  20. BOOL g_fDebugOnly = FALSE;
  21. WCHAR g_szInput1[MAX_PATH+1];
  22. WCHAR g_szInput2[MAX_PATH+1];
  23. WCHAR g_szOutput[MAX_PATH+1];
  24. //---[ Prototypes ]-----------------------------------------------------------
  25. BOOL WINAPI IcoMergeConsoleCrtlHandler(IN DWORD dwCtrlType);
  26. BOOL FParseCmdLine(INT argc, WCHAR* argv[]);
  27. void ShowUsage();
  28. //+---------------------------------------------------------------------------
  29. //
  30. // Function: wmain
  31. //
  32. // Purpose: Standard main
  33. //
  34. // Arguments:
  35. // argc [in] Count of args
  36. // argv [in] args
  37. //
  38. // Returns:
  39. //
  40. // Author: jeffspr 18 Nov 1998
  41. //
  42. // Notes:
  43. //
  44. EXTERN_C int __cdecl wmain(int argc, WCHAR* argv[])
  45. {
  46. HRESULT hr = S_OK;
  47. BOOL fVerbose = FALSE;
  48. LPICONRESOURCE pIR1 = NULL;
  49. LPICONRESOURCE pIR2 = NULL;
  50. InitializeDebugging();
  51. if (FParseCmdLine(argc, argv))
  52. {
  53. SetConsoleCtrlHandler(IcoMergeConsoleCrtlHandler, TRUE);
  54. if(g_fDebugOnly)
  55. {
  56. pIR1 = ReadIconFromICOFile(g_szInput1);
  57. if (pIR1)
  58. DebugPrintIconMasks(pIR1);
  59. }
  60. else
  61. {
  62. pIR1 = ReadIconFromICOFile(g_szInput1);
  63. if (pIR1)
  64. {
  65. if (g_fVerbose)
  66. {
  67. printf("Icon1:\n");
  68. DebugPrintIconMasks(pIR1);
  69. }
  70. }
  71. pIR2 = ReadIconFromICOFile(g_szInput2);
  72. if (pIR2)
  73. {
  74. if (g_fVerbose)
  75. {
  76. printf("Icon2:\n");
  77. DebugPrintIconMasks(pIR2);
  78. }
  79. }
  80. if (pIR1 && pIR2)
  81. {
  82. OverlayIcons(pIR1, pIR2);
  83. if (g_fVerbose)
  84. {
  85. DebugPrintIconMasks(pIR1);
  86. }
  87. WriteIconToICOFile(pIR1, g_szOutput);
  88. }
  89. else
  90. {
  91. printf("*** ERROR *** Not all icons were loaded. Can't generate overlay\n");
  92. }
  93. }
  94. }
  95. else
  96. {
  97. ShowUsage();
  98. }
  99. if (pIR1)
  100. free(pIR1);
  101. if (pIR2)
  102. free(pIR2);
  103. UnInitializeDebugging();
  104. return hr;
  105. }
  106. //+---------------------------------------------------------------------------
  107. //
  108. // Function: FParseCmdLine
  109. //
  110. // Purpose: Parse command line arguments
  111. //
  112. // Arguments:
  113. // argc [in] Count of args
  114. // argv [in] Args
  115. //
  116. // Returns:
  117. //
  118. // Author: jeffspr 18 Nov 1998
  119. //
  120. // Notes:
  121. //
  122. BOOL FParseCmdLine(IN int argc,
  123. IN WCHAR* argv[])
  124. {
  125. BOOL fReturn = FALSE;
  126. INT iParamLoop = 0;
  127. if (argc < 4)
  128. {
  129. if (argc == 3)
  130. {
  131. if ((argv[2][0] == '/') &&
  132. ((argv[2][1] == 'd') || (argv[2][1] == 'D')))
  133. {
  134. g_fDebugOnly = TRUE;
  135. lstrcpyW(g_szInput1, argv[1]);
  136. fReturn = TRUE;
  137. }
  138. else
  139. {
  140. ShowUsage();
  141. goto Exit;
  142. }
  143. }
  144. else
  145. {
  146. ShowUsage();
  147. goto Exit;
  148. }
  149. }
  150. else
  151. {
  152. lstrcpyW(g_szInput1, argv[1]);
  153. lstrcpyW(g_szInput2, argv[2]);
  154. lstrcpyW(g_szOutput, argv[3]);
  155. for (iParamLoop = 4; iParamLoop < argc; iParamLoop++)
  156. {
  157. if (argv[iParamLoop][0] == '/')
  158. {
  159. switch(argv[iParamLoop][1])
  160. {
  161. case '?':
  162. ShowUsage();
  163. goto Exit;
  164. case 'v':
  165. g_fVerbose = TRUE;
  166. break;
  167. default:
  168. AssertSz(FALSE, "Unknown parameter");
  169. ShowUsage();
  170. goto Exit;
  171. }
  172. }
  173. }
  174. fReturn = TRUE;
  175. }
  176. Exit:
  177. return fReturn;
  178. }
  179. #if 0
  180. BOOL FParseCmdLine(IN int argc,
  181. IN WCHAR* argv[])
  182. {
  183. AssertValidReadPtr(argv);
  184. BOOL fStatus=FALSE;
  185. CHAR ch;
  186. static const WCHAR c_szValidOptions[] = L"f:vVlLhH?";
  187. WCHAR szFileFullPath[MAX_PATH+1];
  188. PWSTR szFileComponent;
  189. while ((ch = getopt(argc, argv, (WCHAR*) c_szValidOptions)) != EOF)
  190. {
  191. switch (ch)
  192. {
  193. #if 0
  194. case 'f':
  195. int nChars;
  196. nChars = GetFullPathName(optarg, MAX_PATH,
  197. szFileFullPath, &szFileComponent);
  198. if (nChars)
  199. {
  200. pnaOptions->m_strAFileName = szFileFullPath;
  201. }
  202. fStatus = TRUE;
  203. break;
  204. #endif
  205. case 'v':
  206. case 'V':
  207. g_fVerbose = TRUE;
  208. break;
  209. default:
  210. case 'h':
  211. case 'H':
  212. case '?':
  213. case 0:
  214. fStatus = FALSE;
  215. break;
  216. }
  217. }
  218. return fStatus;
  219. }
  220. #endif
  221. //+---------------------------------------------------------------------------
  222. //
  223. // Function: ShowUsage
  224. //
  225. // Purpose: Show the cmd-line usage
  226. //
  227. // Arguments:
  228. // (none)
  229. //
  230. // Returns:
  231. //
  232. // Author: jeffspr 18 Nov 1998
  233. //
  234. // Notes:
  235. //
  236. void ShowUsage()
  237. {
  238. static const WCHAR c_szUsage[] =
  239. L"\n"
  240. L"icomerge <input_file1> <input_file2> <output_file> [/v]\n"
  241. L" or\n"
  242. L"icomerge /?\n"
  243. L"\n"
  244. L" input_file1 and input_file2 are icon files with transparency\n"
  245. L" output_file is the destination icon for the merged icons\n"
  246. L"\n"
  247. L" /?\t Displays this help\n";
  248. _tprintf(c_szUsage);
  249. }
  250. // ----------------------------------------------------------------------
  251. //
  252. // Function: IcoMergeConsoleCrtlHandler
  253. //
  254. // Purpose: Release resources on abnormal exit
  255. //
  256. // Arguments:
  257. // dwCtrlType [in] reason of abnormal exit
  258. //
  259. // Returns: FALSE --> so that netafx will be terminated
  260. //
  261. // Author: kumarp 15-April-98
  262. //
  263. // Notes:
  264. //
  265. BOOL WINAPI IcoMergeConsoleCrtlHandler(IN DWORD dwCtrlType)
  266. {
  267. return FALSE;
  268. }