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.

236 lines
6.9 KiB

  1. /*++
  2. awdvstub.c
  3. Copyright (c) 1997 Microsoft Corporation
  4. This program is a stub AWD viewer... it will first convert an awd file named
  5. on the command line to a tiff file in the temp directory, then it will launch
  6. the tiff viewer on that file.
  7. Also, when used with the '/c' switch, it's an AWD converter. Two programs in one!
  8. Author:
  9. Brian Dewey (t-briand) 1997-7-15
  10. --*/
  11. #include <windows.h>
  12. #include <commctrl.h>
  13. #include <commdlg.h>
  14. #include <shellapi.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <tchar.h>
  18. #include "awdlib.h" // Gives access to the AWD routines.
  19. #include "tifflib.h" // TIFF routines.
  20. #include "tifflibp.h" // I need access to the private TIFF definitions.
  21. #include "faxutil.h" // not sure why I need this...
  22. #include "viewrend.h" // win95 viewer library.
  23. #include "resource.h" // resource constants
  24. // ------------------------------------------------------------
  25. // Prototypes
  26. void Useage(HINSTANCE hInst);
  27. void PopupError(UINT uID, HINSTANCE hModule);
  28. // ------------------------------------------------------------
  29. // WinMain
  30. int
  31. WINAPI
  32. WinMain(
  33. HINSTANCE hInstance,
  34. HINSTANCE hPrevInstance,
  35. LPSTR lpCmdLine,
  36. int nCmdShow
  37. )
  38. {
  39. LPWSTR *argv;
  40. DWORD argc;
  41. UINT uiCurrentArg; // Used for iterating through arguments.
  42. UINT uiNumFiles=0; // This is the number of files we've gotten
  43. // from the command line.
  44. WCHAR szTempPath[MAX_PATH]; // Holds the temporary path.
  45. WCHAR szTempFile[MAX_PATH]; // Holds the temporary file name.
  46. WCHAR szAwdFile[MAX_PATH]; // Holds the name of the AWD file we're viewing or converting.
  47. int iStrLen;
  48. BOOL bConvert = FALSE; // TRUE if we're to do a permanent conversion.
  49. // If FALSE, we do a conversion to a temporary file &
  50. // launch the viewer.
  51. BOOL bTempProvided = FALSE;// If TRUE, then the user provided the destination file.
  52. UINT uiHackPosition = 0; // Oh, this is part of some awful code below...
  53. argv = CommandLineToArgvW( GetCommandLine(), &argc );
  54. if(NULL == argv)
  55. {
  56. return 1;
  57. }
  58. if(argc < 2)
  59. {
  60. Useage(hInstance);
  61. return 1;
  62. }
  63. for(uiCurrentArg = 1; uiCurrentArg < argc; uiCurrentArg++)
  64. {
  65. if((argv[uiCurrentArg][0] == L'-') ||
  66. (argv[uiCurrentArg][0] == L'/'))
  67. {
  68. switch(argv[uiCurrentArg][1])
  69. {
  70. // We're doing a switch based on the character after the
  71. // command-argument specifier ('-' or '/'). Put additional
  72. // arguments here as needed.
  73. case L'c':
  74. case L'C':
  75. if (argc<3)
  76. {
  77. Useage(hInstance);
  78. return 1;
  79. }
  80. bConvert = TRUE; // We're meant to do a permanent conversion.
  81. break;
  82. default:
  83. // Should an invalid parameter be an error?
  84. Useage(hInstance);
  85. return 1;
  86. } // Switch
  87. } else
  88. {
  89. switch(uiNumFiles) {
  90. case 0:
  91. // If we haven't encountered any files before, then
  92. // this is the name of the AWD file.
  93. wcscpy(szAwdFile, argv[uiCurrentArg]);
  94. break;
  95. case 1:
  96. // Now, we're reading the name of the TIF file for permanent conversion.
  97. bTempProvided = TRUE;
  98. wcscpy(szTempFile, argv[uiCurrentArg]);
  99. break;
  100. default:
  101. // Too many parameters!
  102. Useage(hInstance);
  103. return 1;
  104. }
  105. uiNumFiles++;
  106. }
  107. } // For
  108. if(!bTempProvided) {
  109. if(!bConvert) {
  110. // If the user didn't give a temp file name, we provide one.
  111. if(!GetTempPath(MAX_PATH, szTempPath)) {
  112. PopupError(IDS_NOTEMPPATH, hInstance);
  113. return 1; // Failed to get the path.
  114. }
  115. GetTempFileName(
  116. szTempPath, // put the file in this directory.
  117. TEXT("avs"), // prefix -- "awd viewer stub"
  118. 0, // Generate a unique name.
  119. szTempFile // Will hold the new name
  120. );
  121. DeleteFile(szTempFile); // Get rid of that file name.
  122. // (created when obtained.)
  123. } else {
  124. // The user requested permanent conversion, but didn't
  125. // supply a name. In this case, change the extention of
  126. // the file to TIF instead of generating a temp file name.
  127. wcscpy(szTempFile, szAwdFile);
  128. }
  129. // Make sure the file has the TIF extension.
  130. iStrLen = wcslen(szTempFile);
  131. szTempFile[iStrLen-3] = L't';
  132. szTempFile[iStrLen-2] = L'i';
  133. szTempFile[iStrLen-1] = L'f';
  134. } // if(bTempProvided)...
  135. if(ConvertAWDToTiff(szAwdFile, szTempFile))
  136. {
  137. SHELLEXECUTEINFO sei = {0};
  138. if(bConvert)
  139. {
  140. return 0; // We're done!
  141. }
  142. // now we have to tiff in szTempFile.
  143. // let's run ShellExecute on it to open it.
  144. // and wait for the viewer to close.
  145. sei.cbSize = sizeof (SHELLEXECUTEINFO);
  146. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  147. sei.lpVerb = TEXT("open");
  148. sei.lpFile = szTempFile;
  149. sei.lpParameters = NULL;
  150. sei.lpDirectory = TEXT(".");
  151. sei.nShow = SW_MAXIMIZE;
  152. if(!ShellExecuteEx(&sei))
  153. {
  154. PopupError(IDS_NOVIEW, hInstance);
  155. }
  156. WaitForSingleObject(sei.hProcess, INFINITE);
  157. // When we get here, the viewer has terminated.
  158. DeleteFile(szTempFile); // Erase our tracks.
  159. }
  160. else
  161. {
  162. PopupError(IDS_ERRCONV, hInstance);
  163. }
  164. return 0;
  165. }
  166. // Useage
  167. //
  168. // Displays command useage.
  169. //
  170. // Parameters:
  171. // hInst Current module instance.
  172. //
  173. // Returns:
  174. // Nothing.
  175. //
  176. // Author:
  177. // Brian Dewey (t-briand) 1997-8-7
  178. void
  179. Useage(HINSTANCE hInst)
  180. {
  181. PopupError(IDS_USEAGE, hInst);
  182. }
  183. // PopupError
  184. //
  185. // Displays a message box with an error message.
  186. //
  187. // Parameters:
  188. // uID String resource ID
  189. // hModule Module instance.
  190. //
  191. // Returns:
  192. // Nothing.
  193. //
  194. // Author:
  195. // Brian Dewey (t-briand) 1997-8-19
  196. void
  197. PopupError(UINT uID, HINSTANCE hModule)
  198. {
  199. TCHAR szTitle[512], szMsg[512];
  200. if(!LoadString(hModule,
  201. IDS_TITLE,
  202. szTitle,
  203. sizeof(szTitle)/sizeof(TCHAR)))
  204. {
  205. return;
  206. }
  207. if(!LoadString(hModule,
  208. uID,
  209. szMsg,
  210. sizeof(szMsg)/sizeof(TCHAR)))
  211. {
  212. return;
  213. }
  214. AlignedMessageBox(NULL, szMsg, szTitle, MB_OK | MB_ICONSTOP);
  215. }