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.

915 lines
31 KiB

  1. /////7/////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // FApplicationManager.cpp
  4. //
  5. // Copyright (C) 1998, 1999 Microsoft Corporation. All rights reserved.
  6. //
  7. // Abstract :
  8. //
  9. // This is the class factory for the Windows Game Manager
  10. //
  11. // History :
  12. //
  13. // 05/06/1999 luish Created
  14. // 4/09/2000 RichGr LoadDebugRuntime Registry setting delegates calls to Debug dll.
  15. //
  16. //////////////////////////////////////////////////////////////////////////////////////////////
  17. #include <objbase.h>
  18. #include <verinfo.h>
  19. #include <string.h>
  20. #include <tchar.h>
  21. #include "FApplicationManager.h"
  22. #include "ApplicationManager.h"
  23. #include "RegistryKey.h"
  24. #include "Win32API.h"
  25. #include "AppManDebug.h"
  26. #include "Global.h"
  27. #include "StructIdentifiers.h"
  28. #include "ExceptionHandler.h"
  29. #ifdef DBG_MODULE
  30. #undef DBG_MODULE
  31. #endif
  32. #define DBG_MODULE DBG_FAPPMAN
  33. HANDLE g_hModule;
  34. LONG g_lDLLReferenceCount = 0;
  35. HINSTANCE g_hDebugDLL;
  36. LPFNGETCLASSOBJECT g_pfnDllGetClassObject = NULL;
  37. BOOL g_bUseDebugRuntime = FALSE;
  38. #ifndef DX_FINAL_RELEASE
  39. // Handy variable when debugging.
  40. #ifdef _DEBUG
  41. BOOL g_bThisIsDebugBuild = TRUE;
  42. #else
  43. BOOL g_bThisIsDebugBuild = FALSE;
  44. #endif
  45. #define APPMAN_RETAIL_FILENAME _T("AppMan.dll")
  46. #define APPMAN_DEBUG_FILENAME _T("AppManD.dll")
  47. #endif // DX_FINAL_RELEASE
  48. //////////////////////////////////////////////////////////////////////////////////////////////
  49. //
  50. //////////////////////////////////////////////////////////////////////////////////////////////
  51. STDAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID /*lpReserved*/)
  52. {
  53. FUNCTION(" ::DllMain()");
  54. HRESULT hResult = S_OK;
  55. ////////////////////////////////////////////////////////////////////////////////////////////
  56. try
  57. {
  58. TCHAR szFileAndPath[MAX_PATH] = {0};
  59. DWORD dwLen = 0;
  60. TCHAR *pszFile = NULL;
  61. HKEY hKey = 0;
  62. //
  63. // Save the module handle. This is used to extract resources
  64. //
  65. g_hModule = hModule;
  66. #ifndef _DEBUG
  67. if (dwReason == DLL_PROCESS_ATTACH)
  68. {
  69. //
  70. // Retail code
  71. //
  72. // Make sure we are in APPMAN_RETAIL_FILENAME - we don't want to recursively LoadLibrary(APPMAN_DEBUG_FILENAME)
  73. // if someone renamed the dlls or the dlls built incorrectly.
  74. //
  75. g_bUseDebugRuntime = FALSE;
  76. dwLen = GetModuleFileName((HMODULE) hModule, &szFileAndPath[0], sizeof(szFileAndPath));
  77. if (0 < dwLen)
  78. {
  79. //
  80. // Find the position of the last '\'. This precedes the filename.
  81. //
  82. pszFile = _tcsrchr(szFileAndPath, _T('\\'));
  83. if (NULL != pszFile)
  84. {
  85. pszFile += 1;
  86. //
  87. // Is module name valid? Exit with error if not.
  88. //
  89. if (0 == _tcsnicmp(APPMAN_RETAIL_FILENAME, pszFile, MAX_PATH))
  90. {
  91. if ((!RegOpenKey(HKEY_LOCAL_MACHINE, REGPATH_APPMAN, &hKey))&&(hKey))
  92. {
  93. DWORD type = 0;
  94. DWORD dwLoadDebugRuntime;
  95. DWORD cb = sizeof(dwLoadDebugRuntime);
  96. if (!RegQueryValueEx(hKey, _T("LoadDebugRuntime"), NULL, &type, (CONST LPBYTE)&dwLoadDebugRuntime, &cb))
  97. {
  98. if (dwLoadDebugRuntime)
  99. {
  100. g_hDebugDLL = LoadLibrary(APPMAN_DEBUG_FILENAME);
  101. if (NULL != g_hDebugDLL)
  102. {
  103. g_pfnDllGetClassObject = (LPFNGETCLASSOBJECT)GetProcAddress(g_hDebugDLL, "DllGetClassObject");
  104. if (NULL != g_pfnDllGetClassObject)
  105. {
  106. g_bUseDebugRuntime = TRUE;
  107. }
  108. else
  109. {
  110. FreeLibrary(g_hDebugDLL);
  111. g_hDebugDLL = NULL;
  112. }
  113. }
  114. }
  115. }
  116. //
  117. // Close the registry key
  118. //
  119. RegCloseKey(hKey);
  120. }
  121. }
  122. }
  123. }
  124. //
  125. // Time bomb this
  126. //
  127. #ifndef DX_FINAL_RELEASE
  128. #pragma message("BETA EXPIRATION TIME BOMB! Remove for final build!")
  129. if (FALSE == g_bUseDebugRuntime)
  130. {
  131. SYSTEMTIME sSystemTime;
  132. GetSystemTime(&sSystemTime);
  133. if ((sSystemTime.wYear > DX_EXPIRE_YEAR)||((sSystemTime.wYear == DX_EXPIRE_YEAR)&&(MAKELONG(sSystemTime.wDay, sSystemTime.wMonth) > MAKELONG(DX_EXPIRE_DAY, DX_EXPIRE_MONTH))))
  134. {
  135. MessageBox(0, DX_EXPIRE_TEXT, TEXT("Microsoft Application Manager"), MB_OK);
  136. }
  137. }
  138. #endif // DX_FINAL_RELEASE
  139. }
  140. else if (dwReason == DLL_PROCESS_DETACH && g_bUseDebugRuntime)
  141. {
  142. FreeLibrary(g_hDebugDLL);
  143. g_hDebugDLL = NULL;
  144. }
  145. #else // preprocessor #else...
  146. if (dwReason == DLL_PROCESS_ATTACH)
  147. {
  148. //
  149. // Debug code - AppManD.dll.
  150. // If we are debug, then spew a string at level 1
  151. //
  152. #ifndef DX_FINAL_RELEASE
  153. #pragma message("BETA EXPIRATION TIME BOMB! Remove for final build!")
  154. SYSTEMTIME sSystemTime;
  155. GetSystemTime(&sSystemTime);
  156. if ((sSystemTime.wYear > DX_EXPIRE_YEAR)||((sSystemTime.wYear == DX_EXPIRE_YEAR)&&(MAKELONG(sSystemTime.wDay, sSystemTime.wMonth) > MAKELONG(DX_EXPIRE_DAY, DX_EXPIRE_MONTH))))
  157. {
  158. MessageBox(0, DX_EXPIRE_TEXT, TEXT("Microsoft Application Manager"), MB_OK);
  159. }
  160. #endif // DX_FINAL_RELEASE
  161. }
  162. #endif
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////////////
  165. catch(CAppManExceptionHandler * pException)
  166. {
  167. hResult = pException->GetResultCode();
  168. delete pException;
  169. }
  170. catch(...)
  171. {
  172. hResult = E_UNEXPECTED;
  173. }
  174. ///////////////////////////////////////////////////////////////////////////////////////
  175. return TRUE;
  176. }
  177. //////////////////////////////////////////////////////////////////////////////////////////////
  178. //
  179. //////////////////////////////////////////////////////////////////////////////////////////////
  180. STDAPI DllGetClassObject(REFCLSID ClassIDReference, REFIID RefIID, void ** lppVoidObject)
  181. {
  182. FUNCTION(" ::DllGetClassObject ()");
  183. HRESULT hResult = S_OK;
  184. ////////////////////////////////////////////////////////////////////////////////////////////
  185. try
  186. {
  187. LPCLASSFACTORY pClassFactory;
  188. *lppVoidObject = NULL;
  189. #ifndef _DEBUG
  190. //
  191. // 4/09/2000(RichGr): We want to delegate this call to the debug version if we've been asked to
  192. // and everything's valid.
  193. //
  194. if (g_bUseDebugRuntime)
  195. {
  196. hResult = g_pfnDllGetClassObject(ClassIDReference, RefIID, lppVoidObject);
  197. return hResult;
  198. }
  199. #endif
  200. //
  201. // Make sure the ppVoidObject is not null
  202. //
  203. if (NULL == lppVoidObject)
  204. {
  205. return E_INVALIDARG;
  206. }
  207. *lppVoidObject = NULL;
  208. //
  209. // Check to make sure that the proper CLSID is being specified
  210. //
  211. if (ClassIDReference != CLSID_ApplicationManager)
  212. {
  213. return CLASS_E_CLASSNOTAVAILABLE;
  214. }
  215. //
  216. // Create the class factory
  217. //
  218. pClassFactory = (LPCLASSFACTORY) new CFApplicationManager;
  219. if (NULL == pClassFactory)
  220. {
  221. return E_OUTOFMEMORY;
  222. }
  223. //
  224. // Get the requested interface
  225. //
  226. hResult = pClassFactory->QueryInterface(RefIID, lppVoidObject);
  227. pClassFactory->Release();
  228. }
  229. ///////////////////////////////////////////////////////////////////////////////////////
  230. catch(CAppManExceptionHandler * pException)
  231. {
  232. hResult = pException->GetResultCode();
  233. delete pException;
  234. }
  235. catch(...)
  236. {
  237. hResult = E_UNEXPECTED;
  238. }
  239. ///////////////////////////////////////////////////////////////////////////////////////
  240. return hResult;
  241. }
  242. //////////////////////////////////////////////////////////////////////////////////////////////
  243. //
  244. //////////////////////////////////////////////////////////////////////////////////////////////
  245. STDAPI DllCanUnloadNow(void)
  246. {
  247. FUNCTION(" ::DllCanUnloadNow ()");
  248. if (g_lDLLReferenceCount)
  249. {
  250. return S_FALSE;
  251. }
  252. return S_OK;
  253. }
  254. //////////////////////////////////////////////////////////////////////////////////////////////
  255. //
  256. //////////////////////////////////////////////////////////////////////////////////////////////
  257. STDAPI DllRegisterServer(void)
  258. {
  259. FUNCTION(" ::DllRegisterServer ()");
  260. HRESULT hResult = S_OK;
  261. ///////////////////////////////////////////////////////////////////////////////////////
  262. try
  263. {
  264. CRegistryKey oRegistryKey;
  265. APPLICATION_MANAGER_RECORD sApplicationManagerRecord;
  266. DWORD dwDisposition, dwDWORD;
  267. CHAR szString[MAX_PATH_CHARCOUNT];
  268. CHAR szDLLFileName[MAX_PATH_CHARCOUNT];
  269. //
  270. // Get the current windows directory
  271. //
  272. GetModuleFileNameA((HMODULE) g_hModule, szDLLFileName, MAX_PATH_CHARCOUNT);
  273. //
  274. // Register [HKEY_CLASSES_ROOT\CLSID\{79FF4730-235C-11d3-A76C-00C04F8F8B94}]
  275. //
  276. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  277. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  278. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) "Application Manager", sizeof("Application Manager") + 1);
  279. wsprintfA(szString, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  280. oRegistryKey.SetValue("AppID", REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  281. //
  282. // Register [HKEY_CLASSES_ROOT\CLSID\{79FF4730-235C-11d3-A76C-00C04F8F8B94}\InProcServer32]
  283. //
  284. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\InprocServer32", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  285. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  286. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szDLLFileName, MAX_PATH_CHARCOUNT);
  287. oRegistryKey.SetValue("ThreadingModel", REG_SZ, (LPBYTE) "Apartment", sizeof("Apartment") + 1);
  288. //
  289. // Now add icon for the disk cleaner
  290. //
  291. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\DefaultIcon", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  292. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  293. wsprintfA(szString,szDLLFileName);
  294. strcat(szString,", 0");
  295. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, sizeof(szString));
  296. //
  297. // Register [HKEY_CLASSES_ROOT\CLSID\{79FF4730-235C-11d3-A76C-00C04F8F8B94}\ProgID]
  298. //
  299. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\ProgID", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  300. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  301. wsprintfA(szString, "ApplicationManager.%d", GetAppManVersion());
  302. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  303. //
  304. // Register [HKEY_CLASSES_ROOT\CLSID\{79FF4730-235C-11d3-A76C-00C04F8F8B94}\VersionIndependentProgID]
  305. //
  306. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\VersionIndependentProgID", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  307. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  308. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) "ApplicationManager", sizeof("ApplicationManager") + 1);
  309. //
  310. // Register [HKEY_CLASSES_ROOT\ApplicationManager]
  311. //
  312. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, "ApplicationManager", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  313. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) "Application Manager", sizeof("Application Manager") + 1);
  314. //
  315. // Register [HKEY_CLASSES_ROOT\ApplicationManager\CLSID]
  316. //
  317. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CLSID", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  318. wsprintfA(szString, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  319. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  320. //
  321. // Register [HKEY_CLASSES_ROOT\ApplicationManager\CurVer]
  322. //
  323. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CurVer", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  324. wsprintfA(szString, "ApplicationManager.%d", GetAppManVersion());
  325. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  326. //
  327. // Register [HKEY_CLASSES_ROOT\ApplicationManager.%d]
  328. //
  329. wsprintfA(szString, "ApplicationManager.%d", GetAppManVersion());
  330. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  331. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) "Application Manager", sizeof("Application Manager") + 1);
  332. //
  333. // Register [HKEY_CLASSES_ROOT\ApplicationManager.%d\CLSID]
  334. //
  335. wsprintfA(szString, "ApplicationManager.%d\\CLSID", GetAppManVersion());
  336. oRegistryKey.CreateKey(HKEY_CLASSES_ROOT, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  337. wsprintfA(szString, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  338. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  339. //
  340. // Register [HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Explorer/VolumeCaches/Delete Game Manager Files]
  341. //
  342. wsprintfA(szString, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Delete Game Manager Files");
  343. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, szString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, FALSE, NULL);
  344. wsprintfA(szString, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  345. oRegistryKey.SetValue(NULL, REG_SZ, (LPBYTE) szString, MAX_PATH_CHARCOUNT);
  346. DWORD dwDiskCleanerDayThreshold = DISKCLEANER_DAY_THRESHOLD;
  347. oRegistryKey.SetValue("DiskCleanerDayThreshold", REG_DWORD, (unsigned char *)&dwDiskCleanerDayThreshold, sizeof(DWORD));
  348. //
  349. // Open the root key if possible
  350. //
  351. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan"))
  352. {
  353. oRegistryKey.OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan", KEY_ALL_ACCESS);
  354. //
  355. // Make sure the AppMan version is the right version
  356. //
  357. if (S_OK == oRegistryKey.CheckForExistingValue("AppManVersion"))
  358. {
  359. DWORD dwDataLen, dwDataValue, dwDataType;
  360. dwDataLen = sizeof(dwDataValue);
  361. oRegistryKey.GetValue("AppManVersion", &dwDataType, (BYTE *) &dwDataValue, &dwDataLen);
  362. if (REG_VERSION > dwDataValue)
  363. {
  364. oRegistryKey.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan");
  365. }
  366. }
  367. }
  368. //
  369. // Create the application manager registry keys
  370. //
  371. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  372. //
  373. // Initialize the AppMan\Version value
  374. //
  375. dwDWORD = REG_VERSION;
  376. oRegistryKey.SetValue("AppManVersion", REG_DWORD, (const BYTE *) &dwDWORD, sizeof(dwDWORD));
  377. //
  378. // Initialize wait event extra wait vars
  379. //
  380. dwDWORD = 0;
  381. oRegistryKey.SetValue("WaitEntryEventExtraTime", REG_DWORD, (const BYTE *) &dwDWORD, sizeof(dwDWORD));
  382. dwDWORD = 0;
  383. oRegistryKey.SetValue("WaitLeaveEventExtraTime", REG_DWORD, (const BYTE *) &dwDWORD, sizeof(dwDWORD));
  384. //
  385. // Initialize the AppMan\DefaultCacheSize
  386. //
  387. dwDWORD = DEFAULT_PERCENT_CACHE_SIZE;
  388. oRegistryKey.SetValue("DefaultPercentCacheSize", REG_DWORD, (const BYTE *) &dwDWORD, sizeof(dwDWORD));
  389. //
  390. // Insert the original APPLICATION_MANAGER_RECORD
  391. //
  392. sApplicationManagerRecord.dwSize = sizeof(APPLICATION_MANAGER_RECORD);
  393. sApplicationManagerRecord.dwStructId = APPLICATION_MANAGER_STRUCT;
  394. if (FAILED(CoCreateGuid(&sApplicationManagerRecord.sSystemGuid)))
  395. {
  396. THROW(E_UNEXPECTED);
  397. }
  398. sApplicationManagerRecord.dwAdvancedMode = FALSE;
  399. oRegistryKey.SetValue("Vector000", REG_BINARY, (LPBYTE) &sApplicationManagerRecord, sizeof(APPLICATION_MANAGER_RECORD));
  400. //
  401. // Create the AppMan\Devices key.
  402. //
  403. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\Devices", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  404. //
  405. // Create the AppMan\Applications key
  406. //
  407. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\Applications", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  408. //
  409. // Create the AppMan\Associations key
  410. //
  411. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\Associations", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  412. //
  413. // Create the AppMan\TempAllocation key
  414. //
  415. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\TempSpaceAllocation", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  416. //
  417. // Create the AppMan\Cleanup key
  418. //
  419. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\Cleanup", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  420. //
  421. // Create the AppMan\Lock key
  422. //
  423. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\Lock", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  424. //
  425. // Create the AppMan\Lock key
  426. //
  427. oRegistryKey.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppMan\\WaitEvent", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, TRUE, &dwDisposition);
  428. oRegistryKey.CloseKey();
  429. }
  430. ///////////////////////////////////////////////////////////////////////////////////////
  431. catch(CAppManExceptionHandler * pException)
  432. {
  433. hResult = pException->GetResultCode();
  434. delete pException;
  435. }
  436. catch(...)
  437. {
  438. hResult = E_UNEXPECTED;
  439. }
  440. ///////////////////////////////////////////////////////////////////////////////////////
  441. return hResult;
  442. return S_OK;
  443. }
  444. //////////////////////////////////////////////////////////////////////////////////////////////
  445. //
  446. // TODO : Replace literal .1 with actual version number
  447. //
  448. //////////////////////////////////////////////////////////////////////////////////////////////
  449. STDAPI DllUnregisterServer(void)
  450. {
  451. FUNCTION(" ::DllUnregisterServer ()");
  452. HRESULT hResult = S_OK;
  453. ///////////////////////////////////////////////////////////////////////////////////////
  454. try
  455. {
  456. CRegistryKey oRegistryKey;
  457. CHAR szString[MAX_PATH_CHARCOUNT];
  458. //
  459. // Delete the registry keys
  460. //
  461. wsprintfA(szString, "ApplicationManager.%d\\CLSID", GetAppManVersion());
  462. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  463. {
  464. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  465. }
  466. wsprintfA(szString, "ApplicationManager.%d", GetAppManVersion());
  467. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  468. {
  469. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  470. }
  471. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CurVer"))
  472. {
  473. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CurVer");
  474. }
  475. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CLSID"))
  476. {
  477. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, "ApplicationManager\\CLSID");
  478. }
  479. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, "ApplicationManager"))
  480. {
  481. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, "ApplicationManager");
  482. }
  483. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\VersionIndependentProgID", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  484. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  485. {
  486. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  487. }
  488. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\ProgID", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  489. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  490. {
  491. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  492. }
  493. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\InprocServer32", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  494. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  495. {
  496. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  497. }
  498. wsprintfA(szString, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", CLSID_ApplicationManager.Data1, CLSID_ApplicationManager.Data2, CLSID_ApplicationManager.Data3, CLSID_ApplicationManager.Data4[0], CLSID_ApplicationManager.Data4[1], CLSID_ApplicationManager.Data4[2], CLSID_ApplicationManager.Data4[3], CLSID_ApplicationManager.Data4[4], CLSID_ApplicationManager.Data4[5], CLSID_ApplicationManager.Data4[6], CLSID_ApplicationManager.Data4[7]);
  499. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_CLASSES_ROOT, szString))
  500. {
  501. oRegistryKey.DeleteKey(HKEY_CLASSES_ROOT, szString);
  502. }
  503. wsprintfA(szString, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Delete Game Manager Files");
  504. if (S_OK == oRegistryKey.CheckForExistingKey(HKEY_LOCAL_MACHINE, szString))
  505. {
  506. oRegistryKey.DeleteKey(HKEY_LOCAL_MACHINE, szString);
  507. }
  508. //
  509. // Close oRegistryKey
  510. //
  511. oRegistryKey.CloseKey();
  512. }
  513. ///////////////////////////////////////////////////////////////////////////////////////
  514. catch(CAppManExceptionHandler * pException)
  515. {
  516. hResult = pException->GetResultCode();
  517. delete pException;
  518. }
  519. catch(...)
  520. {
  521. hResult = E_UNEXPECTED;
  522. }
  523. ///////////////////////////////////////////////////////////////////////////////////////
  524. return hResult;
  525. }
  526. //////////////////////////////////////////////////////////////////////////////////////////////
  527. //
  528. //////////////////////////////////////////////////////////////////////////////////////////////
  529. CFApplicationManager::CFApplicationManager(void)
  530. {
  531. FUNCTION("CFApplicationManager::CFApplicationManager (void)");
  532. m_lReferenceCount = 1;
  533. }
  534. //////////////////////////////////////////////////////////////////////////////////////////////
  535. //
  536. //////////////////////////////////////////////////////////////////////////////////////////////
  537. CFApplicationManager::~CFApplicationManager(void)
  538. {
  539. FUNCTION("CFApplicationManager::~CFApplicationManager (void)");
  540. }
  541. //////////////////////////////////////////////////////////////////////////////////////////////
  542. //
  543. //////////////////////////////////////////////////////////////////////////////////////////////
  544. STDMETHODIMP CFApplicationManager::QueryInterface(REFIID RefIID, void ** lppVoidObject)
  545. {
  546. FUNCTION("CFApplicationManager::QueryInterface ()");
  547. HRESULT hResult = S_OK;
  548. ///////////////////////////////////////////////////////////////////////////////////////
  549. try
  550. {
  551. //
  552. // Check to make sure that &RefIID is not null
  553. //
  554. if (NULL == &RefIID)
  555. {
  556. return E_UNEXPECTED;
  557. }
  558. //
  559. // Check to make sure that ppVoidObject is not null
  560. //
  561. if (NULL == lppVoidObject)
  562. {
  563. return E_INVALIDARG;
  564. }
  565. *lppVoidObject = NULL;
  566. //
  567. // Check for known interfaces
  568. //
  569. if (RefIID == IID_IUnknown)
  570. {
  571. *lppVoidObject = (LPVOID) this;
  572. AddRef();
  573. hResult = S_OK;
  574. }
  575. else
  576. {
  577. if (RefIID == IID_IClassFactory)
  578. {
  579. *lppVoidObject = (LPVOID) this;
  580. AddRef();
  581. hResult = S_OK;
  582. }
  583. else
  584. {
  585. hResult = E_NOINTERFACE;
  586. }
  587. }
  588. }
  589. ///////////////////////////////////////////////////////////////////////////////////////
  590. catch(CAppManExceptionHandler * pException)
  591. {
  592. hResult = pException->GetResultCode();
  593. delete pException;
  594. }
  595. catch(...)
  596. {
  597. hResult = E_UNEXPECTED;
  598. }
  599. ///////////////////////////////////////////////////////////////////////////////////////
  600. return hResult;
  601. }
  602. //////////////////////////////////////////////////////////////////////////////////////////////
  603. //
  604. //////////////////////////////////////////////////////////////////////////////////////////////
  605. ULONG STDMETHODCALLTYPE CFApplicationManager::AddRef(void)
  606. {
  607. FUNCTION("CFApplicationManager::AddRef ()");
  608. return InterlockedIncrement(&m_lReferenceCount);
  609. }
  610. //////////////////////////////////////////////////////////////////////////////////////////////
  611. //
  612. //////////////////////////////////////////////////////////////////////////////////////////////
  613. ULONG STDMETHODCALLTYPE CFApplicationManager::Release(void)
  614. {
  615. FUNCTION("CFApplicationManager::Release ()");
  616. DWORD dwReferenceCount;
  617. dwReferenceCount = InterlockedDecrement(&m_lReferenceCount);
  618. if (0 == dwReferenceCount)
  619. {
  620. delete this;
  621. }
  622. return dwReferenceCount;
  623. }
  624. //////////////////////////////////////////////////////////////////////////////////////////////
  625. //
  626. //////////////////////////////////////////////////////////////////////////////////////////////
  627. STDMETHODIMP CFApplicationManager::CreateInstance(IUnknown * lpoParent, REFIID RefIID, LPVOID * lppVoidObject)
  628. {
  629. FUNCTION("CFApplicationManager::CreateInstance ()");
  630. HRESULT hResult = S_OK;
  631. ///////////////////////////////////////////////////////////////////////////////////////
  632. try
  633. {
  634. CApplicationManagerRoot * lpoApplicationManagerRoot;
  635. IUnknown * lpoUnknownObject;
  636. //
  637. // Make sure no one is trying to aggregrate this interface
  638. //
  639. if (NULL != lpoParent)
  640. {
  641. return CLASS_E_NOAGGREGATION;
  642. }
  643. //
  644. // Check that parameters are valid
  645. //
  646. if (NULL == lppVoidObject)
  647. {
  648. return E_INVALIDARG;
  649. }
  650. //
  651. // Ok, let's create a new CWindowsGameManager instance.
  652. //
  653. lpoApplicationManagerRoot = new CApplicationManagerRoot;
  654. if (NULL == lpoApplicationManagerRoot)
  655. {
  656. return E_OUTOFMEMORY;
  657. }
  658. else if (lpoApplicationManagerRoot->m_bInsufficientAccessToRun)
  659. {
  660. return E_ACCESSDENIED;
  661. }
  662. //
  663. // Cast the CWindowsGameManager object to an IUnknown
  664. //
  665. lpoUnknownObject = (IUnknown *) lpoApplicationManagerRoot;
  666. //
  667. // Get an interface pointer for RefIID
  668. //
  669. hResult = lpoUnknownObject->QueryInterface(RefIID, lppVoidObject);
  670. lpoUnknownObject->Release();
  671. }
  672. ///////////////////////////////////////////////////////////////////////////////////////
  673. catch(CAppManExceptionHandler * pException)
  674. {
  675. hResult = pException->GetResultCode();
  676. delete pException;
  677. }
  678. catch(...)
  679. {
  680. hResult = E_UNEXPECTED;
  681. }
  682. ///////////////////////////////////////////////////////////////////////////////////////
  683. return hResult;
  684. }
  685. //////////////////////////////////////////////////////////////////////////////////////////////
  686. //
  687. //////////////////////////////////////////////////////////////////////////////////////////////
  688. STDMETHODIMP CFApplicationManager::LockServer(BOOL fLock)
  689. {
  690. FUNCTION("CFApplicationManager::LockServer ()");
  691. if (TRUE == fLock)
  692. {
  693. InterlockedIncrement(&g_lDLLReferenceCount);
  694. }
  695. else
  696. {
  697. InterlockedDecrement(&g_lDLLReferenceCount);
  698. }
  699. return S_OK;
  700. }
  701. //////////////////////////////////////////////////////////////////////////////////////////////