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.

328 lines
15 KiB

  1. //***************************************************************************
  2. //* Copyright (c) Microsoft Corporation 1995. All rights reserved. *
  3. //***************************************************************************
  4. //* *
  5. //* ADVPACK.H - Self-extracting/Self-installing stub. *
  6. //* *
  7. //***************************************************************************
  8. // Check out different levels of quiet mode.
  9. #ifndef _ADVPACK_H_
  10. #define _ADVPACK_H_
  11. //***************************************************************************
  12. //* INCLUDE FILES *
  13. //***************************************************************************
  14. #include <shlobj.h>
  15. #include <shellapi.h>
  16. #include "res.h"
  17. #include "advpub.h"
  18. #include "sdsutils.h"
  19. //***************************************************************************
  20. //* DEFINES *
  21. //***************************************************************************
  22. #define ADVPACK_VERSION 205 // Format: MajorVer*100+MinorVer
  23. #define BIG_STRING 512
  24. #define BUF_1K 1024
  25. #define MAX_INFLINE 256
  26. #define SHFREE_ORDINAL 195 // Required for BrowseForDir
  27. #define _OSVER_WIN95 0
  28. #define _OSVER_WINNT3X 1
  29. #define _OSVER_WINNT40 2
  30. #define _OSVER_WINNT50 3
  31. #define _OSVER_WINNT51 4
  32. //#define MAXERRORCHECK
  33. // define quiet modes
  34. #define QUIETMODE_ALL 0x0001
  35. #define QUIETMODE_SHOWMSG 0x0002
  36. // Flags specified in advanced INF file
  37. #define FLAG_VALUE 0x0001 // Bit 0
  38. #define FLAG_FAIL 0x0002 // Bit 1
  39. #define FLAG_QUIET 0x0004 // Bit 2
  40. #define FLAG_NOSTRIP 0x0008 // Bit 3
  41. #define FLAG_NODIRCHECK 0x0010 // Bit 4
  42. #define FLAG_FAIL_NOT 0x0020 // Bit 5
  43. #define FLAG_STRIPAFTER_FIRST 0x0040
  44. #define DEFAULT_FLAGS FLAG_VALUE
  45. // Flags specifying how to set the LDID
  46. #define LDID_SFN 0x0001 // Bit 0
  47. #define LDID_OEM_CHARS 0x0002 // Bit 1
  48. #define LDID_SFN_NT_ALSO 0x0004 // Bit 2
  49. // Setup engine types
  50. #define ENGINE_SETUPAPI 0
  51. #define ENGINE_SETUPX 1
  52. // CoreInstall() flags
  53. #define COREINSTALL_PROMPT 0x0001 // Bit 0
  54. #define COREINSTALL_GRPCONV 0x0002 // Bit 1
  55. #define COREINSTALL_SMARTREBOOT 0x0004 // Bit 2
  56. #define COREINSTALL_BKINSTALL 0x0008
  57. #define COREINSTALL_ROLLBACK 0x0010
  58. #define COREINSTALL_REBOOTCHECKONINSTALL 0x0020
  59. #define COREINSTALL_ROLLBKDOALL 0x0040
  60. #define COREINSTALL_DELAYREGISTEROCX 0x0080
  61. #define COREINSTALL_SETUPAPI 0x0100
  62. #define COREINSTALL_DELAYREBOOT 0x0200
  63. #define COREINSTALL_DELAYPOSTCMD 0x0400
  64. // Cleanup bitfield
  65. #define CLEN_REMVINF 0x0001
  66. // registeries for store save/restore info
  67. //
  68. #define REGKEY_SAVERESTORE "Software\\Microsoft\\Advanced INF Setup"
  69. #define REGSUBK_REGBK "RegBackup"
  70. #define REGSUBK_CATALOGS "Catalogs"
  71. #define REGVAL_BKDIR "BackupPath"
  72. #define REGVAL_BKSIZE "BackupFileSize"
  73. #define REGVAL_BKFILE "BackupFileName"
  74. #define REGVAL_BKINSTCAB "InstallCabFile"
  75. #define REGVAL_BKINSTINF "InstallINFFile"
  76. #define REGVAL_BKINSTSEC "InstallINFSection"
  77. #define REGVAL_BKREGDATA "BackupRegistry"
  78. #define REGVAL_BKMODVER "ComponentVersion"
  79. #define DEF_BACKUPPATH "Uninstall Information" // default fullpath: PROGRAMFILES\backup information\<module>
  80. // registeries for system pathes
  81. #define REGVAL_SM_ACCESSORIES "SM_AccessoriesName"
  82. #define REGVAL_PF_ACCESSORIES "PF_AccessoriesName"
  83. #define REGVAL_PROGRAMFILESPATH "ProgramFilesPath"
  84. #define REGVAL_PROGRAMFILES "ProgramFilesDir"
  85. //***************************************************************************
  86. //* TYPE DEFINITIONS *
  87. //***************************************************************************
  88. // Required for BrowseForDir()
  89. typedef WINSHELLAPI HRESULT (WINAPI *SHGETSPECIALFOLDERLOCATION)(HWND, int, LPITEMIDLIST *);
  90. typedef WINSHELLAPI LPITEMIDLIST (WINAPI *SHBROWSEFORFOLDER)(LPBROWSEINFO);
  91. typedef WINSHELLAPI void (WINAPI *SHFREE)(LPVOID);
  92. typedef WINSHELLAPI BOOL (WINAPI *SHGETPATHFROMIDLIST)( LPCITEMIDLIST, LPSTR );
  93. // Args passed to directory dialog
  94. typedef struct _DIRDLGPARMS {
  95. LPSTR lpszPromptText;
  96. LPSTR lpszDefault;
  97. LPSTR lpszDestDir;
  98. ULONG cbDestDirSize;
  99. DWORD dwInstNeedSize;
  100. } DIRDLGPARMS, *PDIRDLGPARMS;
  101. // list of INF Install Section key names
  102. typedef struct _INFOPT {
  103. PCSTR pszInfKey;
  104. } INFOPT, *PINFOPT;
  105. // OCX data struct
  106. typedef struct _REGOCXData {
  107. PSTR pszOCX;
  108. PSTR pszSwitch;
  109. PSTR pszParam;
  110. } REGOCXDATA, *PREGOCXDATA;
  111. typedef UINT (WINAPI *MYFILEQUEUECALLBACK)( PVOID Context,UINT Notification,UINT_PTR parm1,UINT_PTR parm2 );
  112. typedef struct tagVERHEAD {
  113. WORD wTotLen;
  114. WORD wValLen;
  115. WORD wType; /* always 0 */
  116. WCHAR szKey[(sizeof("VS_VERSION_INFO")+3)&~03];
  117. VS_FIXEDFILEINFO vsf;
  118. } VERHEAD ;
  119. //***************************************************************************
  120. //* MACRO DEFINITIONS *
  121. //***************************************************************************
  122. #define MsgBox( hWnd, nMsgID, uIcon, uButtons ) \
  123. MsgBox2Param( hWnd, nMsgID, NULL, NULL, uIcon, uButtons )
  124. #define MsgBox1Param( hWnd, nMsgID, szParam, uIcon, uButtons ) \
  125. MsgBox2Param( hWnd, nMsgID, szParam, NULL, uIcon, uButtons )
  126. #define ErrorMsg( hWnd, nMsgID ) \
  127. MsgBox2Param( hWnd, nMsgID, NULL, NULL, MB_ICONERROR, MB_OK )
  128. #define ErrorMsg1Param( hWnd, nMsgID, szParam ) \
  129. MsgBox2Param( hWnd, nMsgID, szParam, NULL, MB_ICONERROR, MB_OK )
  130. #define ErrorMsg2Param( hWnd, nMsgID, szParam1, szParam2 ) \
  131. MsgBox2Param( hWnd, nMsgID, szParam1, szParam2, MB_ICONERROR, MB_OK )
  132. #define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
  133. #define SIZEOF(x) (sizeof(x))
  134. //***************************************************************************
  135. //* string defines *
  136. //***************************************************************************
  137. #define szNT4XDelayUntilReboot "System\\CurrentControlSet\\Control\\Session Manager"
  138. #define szNT4XPendingValue "PendingFileRenameOperations"
  139. #define szNT3XDelayUntilReboot "System\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations"
  140. // install OCX
  141. #define achREGSVREXE " /RegServer"
  142. #define achUNREGSVREXE " /UnRegServer"
  143. #define achREGSVRDLL "DllRegisterServer"
  144. #define achUNREGSVRDLL "DllUnregisterServer"
  145. #define achIEXREG "IExpressRegOCX%d"
  146. #define achRUNDLL "rundll32.exe advpack.dll,RegisterOCX %s,%s,%s"
  147. #define RUNONCEEX "RunOnceEx"
  148. #define RUNONCEEXDATA "%s|%s"
  149. #define RUNONCE_IERNONCE "rundll32.exe %s,RunOnceExProcess"
  150. #define W95INF32DLL "W95INF32.DLL"
  151. #define SETUPAPIDLL "SETUPAPI.DLL"
  152. // INF Install section keys
  153. #define ADVINF_DELDIRS "DelDirs"
  154. #define ADVINF_CLEANUP "Cleanup"
  155. #define ADVINF_MODNAME "ComponentName"
  156. #define ADVINF_ADDREG "AddReg"
  157. #define ADVINF_DELREG "DelReg"
  158. #define ADVINF_BKREG "BackupReg"
  159. #define ADVINF_COPYFILE "CopyFiles"
  160. #define ADVINF_DELFILE "DelFiles"
  161. #define ADVINF_PREROLBK "PreRollBack"
  162. #define ADVINF_POSTROLBK "PostRollBack"
  163. #define ADVINF_BACKUPPATH "BackupPath"
  164. #define ADVINF_CHKADMIN "CheckAdminRights"
  165. #define ADVINF_PERUSER "PerUserInstall"
  166. #define ADVINF_PU_DSP "DisplayName"
  167. #define ADVINF_PU_GUID "GUID"
  168. #define ADVINF_PU_VER "Version"
  169. #define ADVINF_PU_LANG "Locale"
  170. #define ADVINF_PU_ISINST "IsInstalled"
  171. #define ADVINF_PU_STUB "StubPath"
  172. #define ADVINF_PU_CID "ComponentID"
  173. #define ADVINF_PU_ROLLBK "RollbackUninstall"
  174. #define ADVINF_FLAGS "AdvOptions"
  175. #define ADVINF_MODVER "ComponentVersion"
  176. #define ADVINF_UPDINFENG "UpdateINFEngine"
  177. #define ADVINF_NOBACKPLATF "NoBackupPlatform"
  178. #define ADVINF_CATALOG_NAME "CatalogName"
  179. //***************************************************************************
  180. //* FUNCTION PROTOTYPES *
  181. //***************************************************************************
  182. // EXPORTED FUNCTIONS
  183. BOOL WINAPI DllMain( HINSTANCE, DWORD, LPVOID );
  184. HRESULT WINAPI DoInfInstall( ADVPACKARGS * );
  185. DWORD WINAPI GetInfInstallSectionName( LPCSTR, LPSTR, DWORD );
  186. INT WINAPI RegisterOCX( HWND, HINSTANCE, PSTR, INT );
  187. // INTERNAL FUNCTIONS
  188. HRESULT CommonInstallInit( PCSTR, PCSTR, PSTR, DWORD, PCSTR, BOOL, DWORD );
  189. VOID CommonInstallCleanup( VOID );
  190. HRESULT CoreInstall( PCSTR, PCSTR, PCSTR, DWORD, DWORD, PCSTR );
  191. HRESULT RunCommands( PCSTR, PCSTR, PCSTR, DWORD, BOOL );
  192. DWORD GetTranslatedInt( PCSTR pszInfFilename, PCSTR pszTranslateSection,
  193. PCSTR pszTranslateKey, DWORD dwDefault );
  194. HRESULT GetTranslatedString( PCSTR, PCSTR, PCSTR, PSTR, DWORD, PDWORD );
  195. HRESULT GetTranslatedLine( PCSTR, PCSTR, DWORD, PSTR*, PDWORD );
  196. DWORD GetTranslatedSection(PCSTR c_pszInfFilename, PCSTR c_pszTranslateSection,
  197. PSTR pszBuffer, DWORD dwBufSize );
  198. BOOL MyNTReboot( VOID );
  199. PSTR GetStringField( PSTR*, PCSTR, CHAR, BOOL );
  200. BOOL IsSeparator( CHAR, PCSTR );
  201. PSTR StripWhitespace( PSTR );
  202. PSTR StripQuotes( PSTR );
  203. BOOL IsGoodAdvancedInfVersion( PCSTR );
  204. BOOL SelectSetupEngine( PCSTR, PCSTR, DWORD );
  205. INT BeginPrompt( PCSTR, PCSTR, PSTR, DWORD );
  206. VOID EndPrompt( PCSTR, PCSTR );
  207. BOOL MyGetPrivateProfileString( PCSTR, PCSTR, PCSTR, PSTR, DWORD );
  208. BOOL LoadSetupLib( PCSTR, PCSTR, BOOL, DWORD );
  209. VOID UnloadSetupLib( VOID );
  210. BOOL CheckOSVersion( VOID );
  211. INT MsgBox2Param( HWND, UINT, LPCSTR, LPCSTR, UINT, UINT );
  212. LPSTR LoadSz( UINT, LPSTR, UINT );
  213. BOOL UserDirPrompt( LPSTR, LPSTR, LPSTR, ULONG, DWORD );
  214. INT_PTR CALLBACK DirDlgProc( HWND, UINT, WPARAM, LPARAM );
  215. BOOL BrowseForDir( HWND, LPCSTR, LPSTR );
  216. BOOL CenterWindow( HWND, HWND );
  217. BOOL IsGoodDir( LPCSTR );
  218. HRESULT CtlSetLddPath( UINT, LPSTR, DWORD );
  219. HRESULT GenInstall(LPSTR, LPSTR, LPSTR);
  220. BOOL GetValueFromRegistry( LPSTR, UINT, LPSTR, LPSTR, LPSTR );
  221. HRESULT SetLDIDs( PCSTR, PCSTR, DWORD, PCSTR );
  222. HRESULT GetDestinationDir( PCSTR, PCSTR, DWORD, DWORD, PSTR, DWORD );
  223. BOOL DirExists( LPSTR );
  224. DWORD ParseDestinationLine( PSTR, PSTR, PSTR *, PDWORD, PDWORD, PDWORD, PDWORD );
  225. BOOL ParseCustomLine( PSTR, PSTR *, PSTR *, PSTR *, PSTR *, PSTR *, BOOL, BOOL );
  226. BOOL RegisterOCXs( LPSTR, LPSTR, BOOL, BOOL, DWORD);
  227. BOOL InstallOCX( PREGOCXDATA, BOOL, BOOL, int );
  228. DWORD FormStrWithoutPlaceHolders( LPCSTR, LPSTR, DWORD, LPCSTR );
  229. DWORD IsMyKeyExists( LPCSTR, LPCSTR, LPSTR, UINT, LPCSTR );
  230. DWORD GetWininitSize();
  231. DWORD GetRegValueSize(LPCSTR lpcszRegKey, LPCSTR lpcszValue);
  232. DWORD GetNumberOfValues(LPCSTR lpcszRegKey);
  233. DWORD InternalNeedRebootInit(WORD wOSVer);
  234. BOOL InternalNeedReboot(DWORD dwRebootCheck, WORD wOSVer);
  235. BOOL IsEnoughInstSpace( LPSTR szPath, DWORD cbInstNeedSize, LPDWORD pdwPadSize );
  236. LONG My_atol( LPSTR );
  237. INT My_atoi( LPSTR );
  238. BOOL IsFullPath( PCSTR );
  239. //BOOL GetUNCroot( LPSTR, LPSTR );
  240. DWORD MyFileSize( PCSTR );
  241. HRESULT CreateFullPath( PCSTR, BOOL );
  242. HRESULT LaunchAndWait( LPSTR, LPSTR, HANDLE *, DWORD, DWORD );
  243. DWORD RO_GetPrivateProfileSection( LPCSTR lpSec, LPSTR lpBuf, DWORD dwSize, LPCSTR lpFile);
  244. HINSTANCE MyLoadLibrary( LPSTR lpFile );
  245. BOOL GetThisModulePath( LPSTR lpPath, int size );
  246. BOOL UpdateHelpDlls( LPCSTR *ppszDlls, INT numDlls, LPSTR pszPath, LPSTR pszMsg, DWORD dwFlag);
  247. void DoCleanup( LPCSTR szInfFilename, LPCSTR szInstallSection );
  248. void DelDirs( LPCSTR szInfFilename, LPCSTR szInstallSection );
  249. void MyRemoveDirectory( LPSTR szFolder );
  250. PSTR FindFileExt( PSTR pszFile );
  251. BOOL GetFullInfNameAndSrcDir( PCSTR pszInfFilename, PSTR pszFilename, PSTR pszSrcDir );
  252. HRESULT ProcessFileSections( PCSTR pszSection, PCSTR pszSrcDir, MYFILEQUEUECALLBACK pMyFileQueueCallback );
  253. HRESULT SaveRestoreInfo( PCSTR pszInf, PCSTR pszSection, PCSTR pszSrcDir, PCSTR pszCatalogs, DWORD dwFlags );
  254. //HRESULT ExtractFiles(LPCSTR pszCabName, LPCSTR pszExpandDir, DWORD dwFlags,
  255. // LPCSTR pszFileList, LPVOID lpReserved, DWORD dwReserved);
  256. //BOOL GetParentDir( LPSTR szFolder );
  257. PSTR GetNextToken(PSTR *ppszData, CHAR chDeLim);
  258. HRESULT RegRestoreAllEx( HKEY hkBckupKey );
  259. HRESULT ProcessAllRegSec( HWND hw, PCSTR pszTitle, PCSTR pszInf, PCSTR pszSection, HKEY hKey, HKEY hCUKey, DWORD dwFlags, BOOL *lpbOneReg );
  260. HRESULT ProcessAllFiles( HWND hw, PCSTR pszSection, PCSTR pszSrcDir, PCSTR pszBackupPath,
  261. PCSTR pszBaseName, PCSTR pszCatalogs, PCSTR pszModule, DWORD dwFlags );
  262. BOOL AddEnvInPath( PSTR pszOldPath, PSTR pszNew );
  263. BOOL GetProgramFilesDir( LPSTR pszPrgfDir, int iSize );
  264. void SetSysPathsInReg();
  265. HRESULT ProcessPerUserSec( PCSTR pcszInf, PCSTR pcszSec );
  266. HRESULT DirSafe(LPCSTR pszDir);
  267. BOOL GetUniHiveKeyName( HKEY hKey, LPSTR pszRegHiveKey, DWORD dwSize, LPCSTR pszBackupPath );
  268. void SetPathForRegHiveUse( LPSTR pszPath, DWORD * adwAttr, int iLevels, BOOL bSave );
  269. HRESULT RunCommandsSections( PCSTR pcszInf, PCSTR pcszSection, PCSTR c_pszKey, PCSTR c_pszSourceDir, DWORD dwFlags, BOOL bNeedReboot );
  270. void GetNextRunOnceExSubKey( HKEY hKey, PSTR pszSubKey, int *piSubKeyNum );
  271. void GetNextRunOnceValName( HKEY hKey, PCSTR pszFormat, PSTR pszValName, int line );
  272. BOOL UseRunOnceEx();
  273. BOOL RemoveBackupBaseOnVer( LPCSTR pszInf, LPCSTR pszSection );
  274. LPSTR GetStringFieldNoQuote( PSTR *ppszString, PCSTR c_pszSeparators, BOOL bStripWhiteSpace);
  275. BOOL GetFieldString(LPSTR lpszLine, int iField, LPSTR lpszField, int cbSize);
  276. BOOL InitializeSetupAPI();
  277. HRESULT RunPatchingCommands(PCSTR c_pszInfFilename, PCSTR szInstallSection, PCSTR c_pszSourceDir);
  278. #endif // _ADVPACK_H_