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.

326 lines
14 KiB

  1. //***************************************************************************
  2. //* Copyright (c) Microsoft Corporation 1995. All rights reserved. *
  3. //***************************************************************************
  4. //* *
  5. //* WEXTRACT.H - Self-extracting/Self-installing stub. *
  6. //* *
  7. //***************************************************************************
  8. #ifndef _WEXTRACT_H_
  9. #define _WEXTRACT_H_
  10. //***************************************************************************
  11. //* INCLUDE FILES *
  12. //***************************************************************************
  13. #include <shlobj.h>
  14. #include <shellapi.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <fcntl.h>
  18. #include <io.h>
  19. #include <sys\stat.h>
  20. #include "fdi.h"
  21. #include "resource.h"
  22. #include <cpldebug.h>
  23. #include <res.h>
  24. #include <sdsutils.h>
  25. //***************************************************************************
  26. //* DEFINES *
  27. //***************************************************************************
  28. #define SMALL_BUF_LEN 80
  29. #define STRING_BUF_LEN 512
  30. #define MAX_STRING STRING_BUF_LEN
  31. #define MSG_MAX STRING_BUF_LEN
  32. #define FILETABLESIZE 40
  33. #define SHFREE_ORDINAL 195 // Required for BrowseForDir
  34. #define _OSVER_WIN9X 0
  35. #define _OSVER_WINNT3X 1
  36. #define _OSVER_WINNT40 2
  37. #define _OSVER_WINNT50 3
  38. // If the following #define is turned on, the directory where the app.
  39. // (wextract app.) is running from is passed as command line to the
  40. // exe that it will then launch after decompression (self extracting).
  41. // This is useful, say, if we are trying to use modified runonce app. that
  42. // Mark was working on. Else, if we are trying to run a custom app. say
  43. // or even an INF (using rundll32, this code does not work). For now,
  44. // I am disabling this so that our Service Pack code can use this.
  45. //
  46. // #define ISVINSTALL // If defined, WExtract will pass
  47. // the directory it was run from
  48. // to the installation program. This
  49. // is to support the ISV Installer
  50. // which requires this path to find
  51. // the CABs.
  52. #define CMD_CHAR1 '/'
  53. #define CMD_CHAR2 '-'
  54. #define EOL '\0'
  55. #define TEMPPREFIX "IXP"
  56. #define TEMP_TEMPLATE "IXP%03d.TMP"
  57. // define quiet modes
  58. #define QUIETMODE_ALL 0x0001
  59. #define QUIETMODE_USER 0x0002
  60. // disk checking methods
  61. #define CHK_REQDSK_NONE 0x0000
  62. #define CHK_REQDSK_EXTRACT 0x0001
  63. #define CHK_REQDSK_INST 0x0002
  64. // Disk check Message type
  65. #define MSG_REQDSK_NONE 0x0000
  66. #define MSG_REQDSK_ERROR 0x0001
  67. #define MSG_REQDSK_WARN 0x0002
  68. #define MSG_REQDSK_RETRYCANCEL 0x0004
  69. // alternative download & extract dir name
  70. #define DIR_MSDOWNLD "msdownld.tmp"
  71. #define KBYTES 1000
  72. #define ADVPACKDLL "advpack.dll"
  73. //***************************************************************************
  74. //* TYPE DEFINITIONS *
  75. //***************************************************************************
  76. // Filename List: We keep track of all files that we have created by keeping
  77. // their names in a list and when the program is complete we use this list
  78. // to delete files if necessary
  79. typedef struct _FNAME {
  80. LPTSTR pszFilename;
  81. struct _FNAME *pNextName;
  82. } FNAME, *PFNAME;
  83. // Current Cabinet Information
  84. typedef struct _CABINET {
  85. TCHAR achCabPath[MAX_PATH]; // Cabinet file path
  86. TCHAR achCabFilename[MAX_PATH]; // Cabinet file name.ext
  87. TCHAR achDiskName[MAX_PATH]; // User readable disk label
  88. USHORT setID;
  89. USHORT iCabinet;
  90. } CABINET, *PCABINET;
  91. // Master State Information for File Extraction
  92. typedef struct _SESSION {
  93. VOID *lpCabinet; // Pointer to cabinet in mem
  94. UINT cbCabSize;
  95. ERF erf;
  96. TCHAR achTitle[128];
  97. UINT wCluster;
  98. BOOL fCanceled; // User hit Cancel button
  99. BOOL fOverwrite; // Overwrite Files
  100. PFNAME pExtractedFiles; // List of Files Extracted
  101. TCHAR achDestDir[MAX_PATH]; // Dest Dir
  102. TCHAR achCabPath[MAX_PATH]; // Current Path to cabs
  103. BOOL fAllCabinets;
  104. BOOL fContinuationCabinet;
  105. UINT cFiles;
  106. UINT cbTotal;
  107. UINT cbAdjustedTotal;
  108. UINT cbWritten;
  109. LPCSTR cszOverwriteFile;
  110. //** fNextCabCalled allows us to figure out which of the acab[] entries
  111. // to use if we are processing all file in a cabinet set (i.e., if
  112. // fAllCabinet is TRUE). If fdintNEXT_CABINET has never been called,
  113. // then acab[1] has the information for the next cabinet. But if
  114. // it has been called, then fdintCABINET_INFO will have been called
  115. // at least twice (once for the first cabinet, and once at least for
  116. // a continuation cabinet), and so acab[0] is the cabinet we need to
  117. // pass to a subsequent FDICopy() call.
  118. BOOL fNextCabCalled; // TRUE => GetNextCabinet called
  119. CABINET acab[2]; // Last two fdintCABINET_INFO data sets
  120. DWORD dwReboot;
  121. UINT uExtractOnly;
  122. UINT uExtractOpt;
  123. DWORD cbPackInstSize;
  124. } SESSION, *PSESSION;
  125. // Memory File: We have to imitate a file with the cabinet attached to
  126. // this executable by using the following MEMFILE structure.
  127. typedef struct _MEMFILE {
  128. void *start;
  129. long current;
  130. long length;
  131. } MEMFILE, *PMEMFILE;
  132. // File Table: In order to support both Win32 File Handles and Memory Files
  133. // (see above) we maintain our own file table. So FDI file handles are
  134. // indexes into a table of these structures.
  135. typedef enum { NORMAL_FILE, MEMORY_FILE } FILETYPE;
  136. typedef struct _FAKEFILE {
  137. BOOL avail;
  138. FILETYPE ftype;
  139. MEMFILE mfile; // State for memory file
  140. HANDLE hf; // Handle for disk file
  141. } FAKEFILE, *PFAKEFILE;
  142. // Required for BrowseForDir()
  143. typedef WINSHELLAPI HRESULT (WINAPI *SHGETSPECIALFOLDERLOCATION)(HWND, int, LPITEMIDLIST *);
  144. typedef WINSHELLAPI LPITEMIDLIST (WINAPI *SHBROWSEFORFOLDER)(LPBROWSEINFO);
  145. typedef WINSHELLAPI void (WINAPI *SHFREE)(LPVOID);
  146. typedef WINSHELLAPI BOOL (WINAPI *SHGETPATHFROMIDLIST)( LPCITEMIDLIST, LPTSTR );
  147. typedef struct _MyFile {
  148. LPSTR szFilename;
  149. ULONG ulSize;
  150. struct _MyFile *Next;
  151. } MYFILE, *PMYFILE;
  152. // define the cmdline flags
  153. #define CMDL_CREATETEMP 0x00000001
  154. #define CMDL_USERBLANKCMD 0x00000002
  155. #define CMDL_USERREBOOT 0x00000004
  156. #define CMDL_NOEXTRACT 0x00000008
  157. #define CMDL_NOGRPCONV 0x00000010
  158. #define CMDL_NOVERCHECK 0x00000020
  159. #define CMDL_DELAYREBOOT 0x00000040
  160. #define CMDL_DELAYPOSTCMD 0x00000080
  161. typedef struct _CMDLINE {
  162. BOOL fCreateTemp;
  163. BOOL fUserBlankCmd;
  164. BOOL fUserReboot;
  165. BOOL fNoExtracting;
  166. BOOL fNoGrpConv;
  167. BOOL fNoVersionCheck;
  168. WORD wQuietMode;
  169. TCHAR szRunonceDelDir[MAX_PATH];
  170. TCHAR szUserTempDir[MAX_PATH];
  171. TCHAR szUserCmd[MAX_PATH];
  172. DWORD dwFlags;
  173. } CMDLINE_DATA, *PCMDLINE_DATA;
  174. typedef HRESULT (WINAPI *DOINFINSTALL)( ADVPACKARGS * );
  175. typedef BOOL (*pfuncPROCESS_UPDATED_FILE)( DWORD, DWORD, PCSTR, PCSTR );
  176. //***************************************************************************
  177. //* MACRO DEFINITIONS *
  178. //***************************************************************************
  179. #define MsgBox( hWnd, nMsgID, uIcon, uButtons ) \
  180. MsgBox2Param( hWnd, nMsgID, NULL, NULL, uIcon, uButtons )
  181. #define MsgBox1Param( hWnd, nMsgID, szParam, uIcon, uButtons ) \
  182. MsgBox2Param( hWnd, nMsgID, szParam, NULL, uIcon, uButtons )
  183. #define ErrorMsg( hWnd, nMsgID ) \
  184. MsgBox2Param( hWnd, nMsgID, NULL, NULL, MB_ICONERROR, MB_OK )
  185. #define ErrorMsg1Param( hWnd, nMsgID, szParam ) \
  186. MsgBox2Param( hWnd, nMsgID, szParam, NULL, MB_ICONERROR, MB_OK )
  187. #define ErrorMsg2Param( hWnd, nMsgID, szParam1, szParam2 ) \
  188. MsgBox2Param( hWnd, nMsgID, szParam1, szParam2, MB_ICONERROR, MB_OK )
  189. //***************************************************************************
  190. //* GLOBAL CONSTANTS *
  191. //***************************************************************************
  192. static TCHAR achWndClass[] = "WEXTRACT"; // Window Class Name
  193. static TCHAR achMemCab[] = "*MEMCAB";
  194. static TCHAR achSETUPDLL[] = "rundll32.exe %s,InstallHinfSection %s 128 %s";
  195. static TCHAR achShell32Lib[] = "SHELL32.DLL";
  196. static TCHAR achSHGetSpecialFolderLocation[] = "SHGetSpecialFolderLocation";
  197. static TCHAR achSHBrowseForFolder[] = "SHBrowseForFolder";
  198. static TCHAR achSHGetPathFromIDList[] = "SHGetPathFromIDList";
  199. // BUGBUG: mg: These should eventually become customizable from CABPACK.
  200. static char szSectionName[] = "DefaultInstall";
  201. // default INF install section name
  202. static TCHAR achDefaultSection[] = "DefaultInstall";
  203. static char szDOINFINSTALL[] = "DoInfInstall";
  204. extern BOOL g_bConvertRunOnce;
  205. //***************************************************************************
  206. //* FUNCTION PROTOTYPES *
  207. //***************************************************************************
  208. BOOL Init( HINSTANCE, LPCTSTR, INT );
  209. BOOL DoMain( );
  210. VOID CleanUp( VOID );
  211. VOID NEAR PASCAL MEditSubClassWnd( HWND, FARPROC );
  212. LRESULT CALLBACK MEditSubProc( HWND, UINT, WPARAM, LPARAM );
  213. INT_PTR CALLBACK WaitDlgProc( HWND, UINT, WPARAM, LPARAM );
  214. INT_PTR CALLBACK LicenseDlgProc( HWND, UINT, WPARAM, LPARAM );
  215. INT_PTR CALLBACK TempDirDlgProc( HWND, UINT, WPARAM, LPARAM );
  216. INT_PTR CALLBACK OverwriteDlgProc( HWND, UINT, WPARAM, LPARAM );
  217. INT_PTR CALLBACK ExtractDlgProc( HWND, UINT, WPARAM, LPARAM );
  218. VOID WaitForObject( HANDLE );
  219. BOOL CheckOSVersion( PTARGETVERINFO );
  220. BOOL DisplayLicense( VOID );
  221. BOOL ExtractFiles( VOID );
  222. BOOL RunInstallCommand( VOID );
  223. VOID FinishMessage( VOID );
  224. BOOL BrowseForDir( HWND, LPCTSTR, LPTSTR );
  225. BOOL CenterWindow( HWND, HWND );
  226. INT CALLBACK MsgBox2Param( HWND, UINT, LPCSTR, LPCSTR, UINT, UINT );
  227. DWORD GetResource( LPCSTR, VOID *, DWORD );
  228. LPSTR LoadSz( UINT, LPSTR, UINT );
  229. BOOL CatDirAndFile( LPTSTR, int, LPCTSTR, LPCTSTR );
  230. BOOL FileExists( LPCTSTR );
  231. BOOL CheckOverwrite( LPCTSTR );
  232. BOOL AddFile( LPCTSTR );
  233. HANDLE Win32Open( LPCTSTR, int, int );
  234. INT_PTR FAR DIAMONDAPI openfunc( char FAR *, int, int );
  235. UINT FAR DIAMONDAPI readfunc( INT_PTR, void FAR *, UINT );
  236. UINT FAR DIAMONDAPI writefunc( INT_PTR, void FAR *, UINT );
  237. int FAR DIAMONDAPI closefunc( INT_PTR );
  238. long FAR DIAMONDAPI seekfunc( INT_PTR, long, int );
  239. BOOL AdjustFileTime( INT_PTR, USHORT, USHORT );
  240. DWORD Attr32FromAttrFAT( WORD );
  241. FNALLOC( allocfunc );
  242. FNFREE( freefunc );
  243. FNFDINOTIFY( doGetNextCab );
  244. FNFDINOTIFY( fdiNotifyExtract );
  245. int UpdateCabinetInfo( PFDINOTIFICATION );
  246. BOOL VerifyCabinet( HGLOBAL );
  247. BOOL ExtractThread( VOID );
  248. BOOL GetCabinet( VOID );
  249. BOOL GetFileList( VOID );
  250. BOOL GetUsersPermission( VOID );
  251. VOID DeleteExtractedFiles( VOID );
  252. BOOL GetTempDirectory( VOID );
  253. BOOL IsGoodTempDir( LPCTSTR );
  254. BOOL IsEnoughSpace( LPCTSTR, UINT, UINT );
  255. BOOL RunApps( LPSTR lpCommand, STARTUPINFO *lpsti );
  256. BOOL ParseCmdLine( LPCTSTR lpszCmdLineOrg );
  257. BOOL AnalyzeCmd( LPTSTR szOrigiCommand, LPTSTR *lplpCommand, BOOL *pfInfCmd );
  258. void DisplayHelp();
  259. void CleanRegRunOnce();
  260. void AddRegRunOnce();
  261. void ConvertRegRunOnce();
  262. void MyRestartDialog( DWORD dwRebootMode );
  263. void DeleteMyDir( LPSTR lpDir );
  264. void AddPath(LPSTR szPath, LPCSTR szName );
  265. BOOL IsRootPath(LPCSTR pPath);
  266. INT_PTR CALLBACK WarningDlgProc(HWND hwnd, UINT msg,WPARAM wParam, LPARAM lParam);
  267. BOOL IsNTAdmin();
  268. DWORD NeedRebootInit(WORD wOSVer);
  269. BOOL NeedReboot(DWORD dwRebootCheck, WORD wOSVer);
  270. BOOL IfNotExistCreateDir( LPTSTR szDir );
  271. BOOL IsWindowsDrive( LPTSTR szPath );
  272. BOOL DiskSpaceErrMsg( UINT msgType, ULONG ulExtractNeeded, DWORD dwInstNeeded, LPTSTR lpDrv );
  273. BOOL CheckWinDir();
  274. DWORD MyGetLastError();
  275. void savAppExitCode( DWORD dwAppRet );
  276. DWORD CheckReboot( VOID );
  277. BOOL TravelUpdatedFiles( pfuncPROCESS_UPDATED_FILE );
  278. BOOL ProcessUpdatedFile_Size( DWORD, DWORD, PCSTR, PCSTR );
  279. BOOL ProcessUpdatedFile_Write( DWORD, DWORD, PCSTR, PCSTR );
  280. VOID MakeDirectory ( LPCTSTR );
  281. INT_PTR MyDialogBox( HANDLE, LPCTSTR, HWND, DLGPROC, LPARAM, INT_PTR );
  282. BOOL CheckFileVersion( PTARGETVERINFO ptargetVers, LPSTR, int, int* );
  283. BOOL GetFileTobeChecked( LPSTR szPath, int iSize, LPCSTR szNameStr );
  284. UINT GetMsgboxFlag( DWORD dwFlag );
  285. int CompareVersion( DWORD, DWORD, DWORD, DWORD );
  286. void ExpandCmdParams( PCSTR pszInParam, PSTR pszOutParam );
  287. HINSTANCE MyLoadLibrary( LPTSTR lpFile );
  288. #endif // _WEXTRACT_H_