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.

871 lines
24 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: regtip.cpp
  4. //
  5. // Contents: Reister/Unregister TIP functionality.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "private.h"
  9. #include "regtip.h"
  10. //
  11. // misc def in Cicero
  12. //
  13. const TCHAR c_szCTFTIPKey[] = TEXT("SOFTWARE\\Microsoft\\CTF\\TIP\\");
  14. const TCHAR c_szCTFTIPKeyWow6432[] = TEXT("Software\\Wow6432Node\\Microsoft\\CTF\\TIP");
  15. const TCHAR c_szEnable[] = TEXT("Enable");
  16. const WCHAR c_szEnableW[] = L"Enable";
  17. const TCHAR c_szLanguageProfileKey[] = TEXT("LanguageProfile\\");
  18. const WCHAR c_szDescriptionW[] = L"Description";
  19. const WCHAR c_szIconFileW[] = L"IconFile";
  20. const TCHAR c_szIconIndex[] = TEXT("IconIndex");
  21. const TCHAR c_szItem[] = TEXT("Item\\"); // Item to category mapping
  22. const TCHAR c_szCategoryKey[] = TEXT("Category\\");
  23. const WCHAR c_wszDescription[] = L"Description";
  24. const TCHAR c_szCategory[] = TEXT("Category\\"); // Category to item mapping
  25. const WCHAR c_szMUIDescriptionW[] = L"Display Description";
  26. typedef enum
  27. {
  28. CAT_FORWARD = 0x0,
  29. CAT_BACKWARD = 0x1
  30. } OURCATDIRECTION;
  31. //
  32. // registry access functions
  33. //
  34. /* S E T R E G V A L U E */
  35. /*-----------------------------------------------------------------------------
  36. -----------------------------------------------------------------------------*/
  37. static BOOL SetRegValue(HKEY hKey, const WCHAR *szName, WCHAR *szValue)
  38. {
  39. LONG ec;
  40. ec = RegSetValueExW(hKey, szName, 0, REG_SZ, (BYTE *)szValue, (lstrlenW(szValue)+1) * sizeof(WCHAR));
  41. return (ec == ERROR_SUCCESS);
  42. }
  43. /* S E T R E G V A L U E */
  44. /*-----------------------------------------------------------------------------
  45. -----------------------------------------------------------------------------*/
  46. static BOOL SetRegValue(HKEY hKey, const CHAR *szName, DWORD dwValue)
  47. {
  48. LONG ec;
  49. ec = RegSetValueExA( hKey, szName, 0, REG_DWORD, (BYTE *)&dwValue, sizeof(DWORD) );
  50. return (ec == ERROR_SUCCESS);
  51. }
  52. /* D E L E T E R E G K E Y */
  53. /*-----------------------------------------------------------------------------
  54. -----------------------------------------------------------------------------*/
  55. static LONG DeleteRegKey( HKEY hKey, const CHAR *szKey )
  56. {
  57. HKEY hKeySub;
  58. LONG ec = RegOpenKeyEx( hKey, szKey, 0, KEY_READ | KEY_WRITE, &hKeySub );
  59. if (ec != ERROR_SUCCESS) {
  60. return ec;
  61. }
  62. FILETIME time;
  63. DWORD dwSize = 256;
  64. TCHAR szBuffer[256];
  65. while (RegEnumKeyEx( hKeySub, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time) == ERROR_SUCCESS) {
  66. ec = DeleteRegKey( hKeySub, szBuffer );
  67. if (ec != ERROR_SUCCESS) {
  68. return ec;
  69. }
  70. dwSize = 256;
  71. }
  72. RegCloseKey( hKeySub );
  73. return RegDeleteKey( hKey, szKey );
  74. }
  75. /* D E L E T E R E G V A L U E */
  76. /*-----------------------------------------------------------------------------
  77. -----------------------------------------------------------------------------*/
  78. static LONG DeleteRegValue( HKEY hKey, const WCHAR *szName )
  79. {
  80. LONG ec;
  81. ec = RegDeleteValueW( hKey, szName );
  82. return (ec == ERROR_SUCCESS);
  83. }
  84. //
  85. // Input processor profile functions
  86. //
  87. /* O U R R E G I S T E R */
  88. /*-----------------------------------------------------------------------------
  89. private version of CInputProcessorProfiles::Register()
  90. (Cicero interface function)
  91. -----------------------------------------------------------------------------*/
  92. static HRESULT OurRegister(REFCLSID rclsid)
  93. {
  94. // --- CInputProcessorProfiles::Register() ---
  95. // CMyRegKey key;
  96. // TCHAR szKey[256];
  97. //
  98. // lstrcpy(szKey, c_szCTFTIPKey);
  99. // CLSIDToStringA(rclsid, szKey + lstrlen(szKey));
  100. //
  101. // if (key.Create(HKEY_LOCAL_MACHINE, szKey) != S_OK)
  102. // return E_FAIL;
  103. //
  104. // key.SetValueW(L"1", c_szEnableW);
  105. //
  106. // return S_OK;
  107. HKEY hKey;
  108. CHAR szKey[ 256 ];
  109. LONG ec;
  110. lstrcpy(szKey, c_szCTFTIPKey);
  111. CLSIDToStringA(rclsid, szKey + lstrlen(szKey));
  112. ec = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  113. if (ec != ERROR_SUCCESS)
  114. return E_FAIL;
  115. SetRegValue(hKey, c_szEnableW, L"1");
  116. RegCloseKey(hKey);
  117. return S_OK;
  118. }
  119. /* O U R A D D L A N G U A G E P R O F I L E */
  120. /*-----------------------------------------------------------------------------
  121. private version of CInputProcessorProfiles::AddLanguageProfile()
  122. (Cicero interface function)
  123. -----------------------------------------------------------------------------*/
  124. static HRESULT OurAddLanguageProfile( REFCLSID rclsid,
  125. LANGID langid,
  126. REFGUID guidProfile,
  127. const WCHAR *pchProfile,
  128. ULONG cch,
  129. const WCHAR *pchFile,
  130. ULONG cchFile,
  131. ULONG uIconIndex)
  132. {
  133. // --- CInputProcessorProfiles::AddLanguageProfile() ---
  134. // CMyRegKey keyTmp;
  135. // CMyRegKey key;
  136. // char szTmp[256];
  137. //
  138. // if (!pchProfile)
  139. // return E_INVALIDARG;
  140. //
  141. // lstrcpy(szTmp, c_szCTFTIPKey);
  142. // CLSIDToStringA(rclsid, szTmp + lstrlen(szTmp));
  143. // lstrcat(szTmp, "\\");
  144. // lstrcat(szTmp, c_szLanguageProfileKey);
  145. // wsprintf(szTmp + lstrlen(szTmp), "0x%08x", langid);
  146. //
  147. // if (keyTmp.Create(HKEY_LOCAL_MACHINE, szTmp) != S_OK)
  148. // return E_FAIL;
  149. //
  150. // CLSIDToStringA(guidProfile, szTmp);
  151. // if (key.Create(keyTmp, szTmp) != S_OK)
  152. // return E_FAIL;
  153. //
  154. // key.SetValueW(WCHtoWSZ(pchProfile, cch), c_szDescriptionW);
  155. //
  156. // if (pchFile)
  157. // {
  158. // key.SetValueW(WCHtoWSZ(pchFile, cchFile), c_szIconFileW);
  159. // key.SetValue(uIconIndex, c_szIconIndex);
  160. // }
  161. //
  162. // CAssemblyList::InvalidCache();
  163. // return S_OK;
  164. HKEY hKey;
  165. HKEY hKeyTmp;
  166. LONG ec;
  167. CHAR szTmp[256];
  168. WCHAR szProfile[256];
  169. if (!pchProfile)
  170. return E_INVALIDARG;
  171. lstrcpy(szTmp, c_szCTFTIPKey);
  172. CLSIDToStringA(rclsid, szTmp + lstrlen(szTmp));
  173. lstrcat(szTmp, "\\" );
  174. lstrcat(szTmp, c_szLanguageProfileKey);
  175. wsprintf(szTmp + lstrlen(szTmp), "0x%08x", langid);
  176. ec = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szTmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyTmp, NULL);
  177. if (ec != ERROR_SUCCESS)
  178. return E_FAIL;
  179. CLSIDToStringA(guidProfile, szTmp);
  180. ec = RegCreateKeyEx(hKeyTmp, szTmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  181. RegCloseKey(hKeyTmp);
  182. if (ec != ERROR_SUCCESS)
  183. return E_FAIL;
  184. lstrcpynW(szProfile, pchProfile, cch+1);
  185. szProfile[cch] = L'\0';
  186. SetRegValue(hKey, c_szDescriptionW, szProfile);
  187. if (pchFile)
  188. {
  189. WCHAR szFile[ MAX_PATH ];
  190. lstrcpynW(szFile, pchFile, cchFile+1);
  191. szFile[cchFile] = L'\0';
  192. SetRegValue(hKey, c_szIconFileW, szFile);
  193. SetRegValue(hKey, c_szIconIndex, uIconIndex);
  194. }
  195. RegCloseKey( hKey );
  196. return S_OK;
  197. }
  198. //+---------------------------------------------------------------------------
  199. //
  200. // NumToWDec
  201. //
  202. //----------------------------------------------------------------------------
  203. static void NumToWDec(DWORD dw, WCHAR *psz)
  204. {
  205. DWORD dwIndex = 1000000000;
  206. BOOL fNum = FALSE;
  207. while (dwIndex)
  208. {
  209. BYTE b = (BYTE)(dw / dwIndex);
  210. if (b)
  211. fNum = TRUE;
  212. if (fNum)
  213. {
  214. *psz = (WCHAR)(L'0' + b);
  215. psz++;
  216. }
  217. dw %= dwIndex;
  218. dwIndex /= 10;
  219. }
  220. if (!fNum)
  221. {
  222. *psz = L'0';
  223. psz++;
  224. }
  225. *psz = L'\0';
  226. return;
  227. }
  228. //+---------------------------------------------------------------------------
  229. //
  230. // OurSetLanguageProfileDisplayName
  231. //
  232. //----------------------------------------------------------------------------
  233. static HRESULT OurSetLanguageProfileDisplayName(REFCLSID rclsid,
  234. LANGID langid,
  235. REFGUID guidProfile,
  236. const WCHAR *pchFile,
  237. ULONG cchFile,
  238. ULONG uResId)
  239. {
  240. HKEY hKeyTmp;
  241. HKEY hKey;
  242. LONG ec;
  243. CHAR szTmp[MAX_PATH];
  244. WCHAR wszTmp[MAX_PATH];
  245. WCHAR wszResId[MAX_PATH];
  246. WCHAR szFile[MAX_PATH];
  247. if (!pchFile)
  248. return E_INVALIDARG;
  249. lstrcpy(szTmp, c_szCTFTIPKey);
  250. CLSIDToStringA(rclsid, szTmp + lstrlen(szTmp));
  251. lstrcat(szTmp, "\\");
  252. lstrcat(szTmp, c_szLanguageProfileKey);
  253. wsprintf(szTmp + lstrlen(szTmp), "0x%08x", langid);
  254. ec = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szTmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyTmp, NULL);
  255. if (ec != ERROR_SUCCESS)
  256. return E_FAIL;
  257. CLSIDToStringA(guidProfile, szTmp);
  258. ec = RegCreateKeyEx(hKeyTmp, szTmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  259. RegCloseKey(hKeyTmp);
  260. if (ec != ERROR_SUCCESS)
  261. return E_FAIL;
  262. //
  263. // make "@[filename],-ResId" string
  264. //
  265. lstrcpyW(wszTmp, L"@");
  266. // WCHtoWSZ(pchFile, cchFile)
  267. lstrcpynW(szFile, pchFile, cchFile+1);
  268. szFile[cchFile] = L'\0';
  269. lstrcatW(wszTmp, szFile);
  270. lstrcatW(wszTmp, L",-");
  271. NumToWDec(uResId, wszResId);
  272. lstrcatW(wszTmp, wszResId);
  273. SetRegValue(hKey, c_szMUIDescriptionW, wszTmp);
  274. RegCloseKey(hKey);
  275. return S_OK;
  276. }
  277. //
  278. // Category manager functions
  279. //
  280. /* O U R G E T C A T K E Y */
  281. /*-----------------------------------------------------------------------------
  282. private version of GetCatKey()
  283. (Cicero internal function)
  284. -----------------------------------------------------------------------------*/
  285. static inline void OurGetCatKey( REFCLSID rclsid, REFGUID rcatid, LPSTR pszKey, LPCSTR pszItem )
  286. {
  287. // --- GetCatKey() ---
  288. // lstrcpy(pszKey, c_szCTFTIPKey);
  289. // CLSIDToStringA(rclsid, pszKey + lstrlen(pszKey));
  290. // lstrcat(pszKey, "\\");
  291. // lstrcat(pszKey, c_szCategoryKey);
  292. // lstrcat(pszKey, pszItem);
  293. // CLSIDToStringA(rcatid, pszKey + lstrlen(pszKey));
  294. lstrcpy(pszKey, c_szCTFTIPKey);
  295. CLSIDToStringA(rclsid, pszKey + lstrlen(pszKey));
  296. lstrcat(pszKey, "\\");
  297. lstrcat(pszKey, c_szCategoryKey);
  298. lstrcat(pszKey, pszItem);
  299. CLSIDToStringA(rcatid, pszKey + lstrlen(pszKey));
  300. }
  301. /* O U R R E G I S T E R G U I D D E S C R I P T I O N */
  302. /*-----------------------------------------------------------------------------
  303. private version of RegisterGUIDDescription()
  304. (Cicero library function & interface function)
  305. -----------------------------------------------------------------------------*/
  306. static HRESULT OurRegisterGUIDDescription( REFCLSID rclsid, REFGUID rcatid, WCHAR *pszDesc )
  307. {
  308. // --- RegisterGUIDDescription() ---
  309. // ITfCategoryMgr *pcat;
  310. // HRESULT hr;
  311. //
  312. // if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  313. // NULL,
  314. // CLSCTX_INPROC_SERVER,
  315. // IID_ITfCategoryMgr,
  316. // (void**)&pcat)))
  317. // {
  318. // hr = pcat->RegisterGUIDDescription(rclsid, rcatid, pszDesc, wcslen(pszDesc));
  319. // pcat->Release();
  320. // }
  321. //
  322. // return hr;
  323. // --- CCategoryMgr::RegisterGUIDDescription() ---
  324. // return s_RegisterGUIDDescription(rclsid, rguid, WCHtoWSZ(pchDesc, cch));
  325. // --- CCategoryMgr::s_RegisterGUIDDescription() ---
  326. // TCHAR szKey[256];
  327. // CMyRegKey key;
  328. //
  329. // GetCatKey(rclsid, rguid, szKey, c_szItem);
  330. //
  331. // if (key.Create(HKEY_LOCAL_MACHINE, szKey) != S_OK)
  332. // return E_FAIL;
  333. //
  334. // key.SetValueW(pszDesc, c_wszDescription);
  335. //
  336. // return S_OK;
  337. CHAR szKey[ 256 ];
  338. HKEY hKey;
  339. LONG ec;
  340. OurGetCatKey( rclsid, rcatid, szKey, c_szItem );
  341. ec = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  342. if (ec != ERROR_SUCCESS)
  343. return E_FAIL;
  344. SetRegValue(hKey, c_wszDescription, pszDesc);
  345. RegCloseKey(hKey);
  346. return S_OK;
  347. }
  348. /* O U R I N T E R N A L R E G I S T E R C A T E G O R Y */
  349. /*-----------------------------------------------------------------------------
  350. private version of CCategoryMgr::_InternalRegisterCategory()
  351. (Cicero interface function)
  352. -----------------------------------------------------------------------------*/
  353. static HRESULT OurInternalRegisterCategory( REFCLSID rclsid, REFGUID rcatid, REFGUID rguid, OURCATDIRECTION catdir )
  354. {
  355. // --- CCategoryMgr::_InternalRegisterCategory() ---
  356. // TCHAR szKey[256];
  357. // CONST TCHAR *pszForward = (catdir == CAT_FORWARD) ? c_szCategory : c_szItem;
  358. // CMyRegKey key;
  359. // CMyRegKey keySub;
  360. //
  361. // GetCatKey(rclsid, rcatid, szKey, pszForward);
  362. //
  363. // if (key.Create(HKEY_LOCAL_MACHINE, szKey) != S_OK)
  364. // return E_FAIL;
  365. //
  366. // //
  367. // // we add this guid and save it.
  368. // //
  369. // char szValue[CLSID_STRLEN + 1];
  370. // CLSIDToStringA(rguid, szValue);
  371. // keySub.Create(key, szValue);
  372. // _FlushGuidArrayCache(rguid, catdir);
  373. //
  374. // return S_OK;
  375. TCHAR szKey[256];
  376. CONST TCHAR *pszForward = (catdir == CAT_FORWARD) ? c_szCategory : c_szItem;
  377. HKEY hKey;
  378. HKEY hKeySub;
  379. LONG ec;
  380. OurGetCatKey(rclsid, rcatid, szKey, pszForward);
  381. ec = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  382. if (ec != ERROR_SUCCESS)
  383. return E_FAIL;
  384. char szValue[CLSID_STRLEN + 1];
  385. CLSIDToStringA(rguid, szValue);
  386. RegCreateKeyEx( hKey, szValue, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeySub, NULL);
  387. RegCloseKey( hKey );
  388. RegCloseKey( hKeySub );
  389. return S_OK;
  390. }
  391. /* O U R I N T E R N A L U N R E G I S T E R C A T E G O R Y */
  392. /*-----------------------------------------------------------------------------
  393. private version of CCategoryMgr::_InternalUnregisterCategory()
  394. (Cicero interface function)
  395. -----------------------------------------------------------------------------*/
  396. static HRESULT OurInternalUnregisterCategory( REFCLSID rclsid, REFGUID rcatid, REFGUID rguid, OURCATDIRECTION catdir )
  397. {
  398. // --- CCategoryMgr::_InternalUnregisterCategory ---
  399. // TCHAR szKey[256];
  400. // CONST TCHAR *pszForward = (catdir == CAT_FORWARD) ? c_szCategory : c_szItem;
  401. // CMyRegKey key;
  402. //
  403. // GetCatKey(rclsid, rcatid, szKey, pszForward);
  404. //
  405. // if (key.Open(HKEY_LOCAL_MACHINE, szKey) != S_OK)
  406. // return E_FAIL;
  407. //
  408. // DWORD dwIndex = 0;
  409. // DWORD dwCnt;
  410. // char szValue[CLSID_STRLEN + 1];
  411. // dwCnt = sizeof(szValue);
  412. //
  413. // CLSIDToStringA(rguid, szValue);
  414. // key.RecurseDeleteKey(szValue);
  415. // _FlushGuidArrayCache(rguid, catdir);
  416. //
  417. // return S_OK;
  418. CHAR szKey[256];
  419. CONST TCHAR *pszForward = (catdir == CAT_FORWARD) ? c_szCategory : c_szItem;
  420. HKEY hKey;
  421. LONG ec;
  422. OurGetCatKey(rclsid, rcatid, szKey, pszForward);
  423. ec = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szKey, 0, KEY_ALL_ACCESS, &hKey );
  424. if (ec != ERROR_SUCCESS) {
  425. return E_FAIL;
  426. }
  427. DWORD dwCnt;
  428. char szValue[CLSID_STRLEN + 1];
  429. dwCnt = sizeof(szValue);
  430. CLSIDToStringA( rguid, szValue );
  431. DeleteRegKey( hKey, szValue );
  432. // _FlushGuidArrayCache(rguid, catdir);
  433. // ^ NOTE: KOJIW: We cannot clear Cicero internal cache from TIP side...
  434. RegCloseKey( hKey );
  435. return S_OK;
  436. }
  437. /* O U R R E G I S T E R T I P */
  438. /*-----------------------------------------------------------------------------
  439. private version of RegisterTIP()
  440. (Cicero library function)
  441. -----------------------------------------------------------------------------*/
  442. BOOL OurRegisterTIP(LPSTR szFilePath, REFCLSID rclsid, WCHAR *pwszDesc, const REGTIPLANGPROFILE *plp)
  443. {
  444. // --- RegisterTIP() ---
  445. // ITfInputProcessorProfiles *pReg = NULL;
  446. // HRESULT hr;
  447. //
  448. // // register ourselves with the ActiveIMM
  449. // hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL,
  450. // CLSCTX_INPROC_SERVER,
  451. // IID_ITfInputProcessorProfiles, (void**)&pReg);
  452. // if (FAILED(hr))
  453. // goto Exit;
  454. //
  455. // hr = pReg->Register(rclsid);
  456. //
  457. // if (FAILED(hr))
  458. // goto Exit;
  459. //
  460. // while (plp->langid)
  461. // {
  462. // WCHAR wszFilePath[MAX_PATH];
  463. // WCHAR *pv = &wszFilePath[0];
  464. //
  465. // wszFilePath[0] = L'\0';
  466. //
  467. // if (wcslen(plp->szIconFile))
  468. // {
  469. // char szFilePath[MAX_PATH];
  470. // WCHAR *pvCur;
  471. //
  472. // GetModuleFileName(hInst, szFilePath, ARRAYSIZE(szFilePath));
  473. // wcscpy(wszFilePath, AtoW(szFilePath));
  474. //
  475. // pv = pvCur = &wszFilePath[0];
  476. // while (*pvCur)
  477. // {
  478. // if (*pvCur == L'\\')
  479. // pv = pvCur + 1;
  480. // pvCur++;
  481. // }
  482. // *pv = L'\0';
  483. //
  484. // }
  485. // wcscpy(pv, plp->szIconFile);
  486. //
  487. // pReg->AddLanguageProfile(rclsid,
  488. // plp->langid,
  489. // *plp->pguidProfile,
  490. // plp->szProfile,
  491. // wcslen(plp->szProfile),
  492. // wszFilePath,
  493. // wcslen(wszFilePath),
  494. // plp->uIconIndex);
  495. // plp++;
  496. // }
  497. //
  498. // RegisterGUIDDescription(rclsid, rclsid, pwszDesc);
  499. //Exit:
  500. // SafeRelease(pReg);
  501. // return SUCCEEDED(hr);
  502. HRESULT hr;
  503. hr = OurRegister(rclsid);
  504. if (FAILED(hr))
  505. goto Exit;
  506. while (plp->langid)
  507. {
  508. WCHAR wszFilePath[MAX_PATH];
  509. WCHAR *pv = &wszFilePath[0];
  510. wszFilePath[0] = L'\0';
  511. if (wcslen(plp->szIconFile))
  512. {
  513. WCHAR *pvCur;
  514. MultiByteToWideChar(CP_ACP, 0, szFilePath, -1, wszFilePath, MAX_PATH);
  515. pv = pvCur = &wszFilePath[0];
  516. while (*pvCur)
  517. {
  518. if (*pvCur == L'\\')
  519. pv = pvCur + 1;
  520. pvCur++;
  521. }
  522. *pv = L'\0';
  523. }
  524. lstrcpyW(pv, plp->szIconFile);
  525. OurAddLanguageProfile(rclsid,
  526. plp->langid,
  527. *plp->pguidProfile,
  528. plp->szProfile,
  529. lstrlenW(plp->szProfile),
  530. wszFilePath,
  531. lstrlenW(wszFilePath),
  532. plp->uIconIndex);
  533. if (plp->uDisplayDescResIndex)
  534. {
  535. OurSetLanguageProfileDisplayName(rclsid,
  536. plp->langid,
  537. *plp->pguidProfile,
  538. wszFilePath,
  539. wcslen(wszFilePath),
  540. plp->uDisplayDescResIndex);
  541. }
  542. plp++;
  543. }
  544. OurRegisterGUIDDescription( rclsid, rclsid, pwszDesc );
  545. Exit:
  546. return SUCCEEDED(hr);
  547. }
  548. /* O U R R E G I S T E R C A T E G O R Y */
  549. /*-----------------------------------------------------------------------------
  550. private versio of RegisterCategory()
  551. (Cicero library function)
  552. -----------------------------------------------------------------------------*/
  553. HRESULT OurRegisterCategory( REFCLSID rclsid, REFGUID rcatid, REFGUID rguid )
  554. {
  555. // --- RegisterCategory() ---
  556. // ITfCategoryMgr *pcat;
  557. // HRESULT hr;
  558. //
  559. // if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  560. // NULL,
  561. // CLSCTX_INPROC_SERVER,
  562. // IID_ITfCategoryMgr,
  563. // (void**)&pcat)))
  564. // {
  565. // hr = pcat->RegisterCategory(rclsid, rcatid, rguid);
  566. // pcat->Release();
  567. // }
  568. //
  569. // return hr;
  570. // --- CCategoryMgr::RegisterCategory() ---
  571. // return s_RegisterCategory(rclsid, rcatid, rguid);
  572. // --- CCategoryMgr::s_RegisterGUIDDescription() ---
  573. // HRESULT hr;
  574. //
  575. // //
  576. // // create forward link from category to guids.
  577. // //
  578. // if (FAILED(hr = _InternalRegisterCategory(rclsid, rcatid, rguid, CAT_FORWARD)))
  579. // return hr;
  580. //
  581. // //
  582. // // create backward link from guid to categories.
  583. // //
  584. // if (FAILED(hr = _InternalRegisterCategory(rclsid, rguid, rcatid, CAT_BACKWARD)))
  585. // {
  586. // _InternalUnregisterCategory(rclsid, rcatid, rguid, CAT_FORWARD);
  587. // return hr;
  588. // }
  589. //
  590. // return S_OK;
  591. HRESULT hr;
  592. if (FAILED(hr = OurInternalRegisterCategory(rclsid, rcatid, rguid, CAT_FORWARD))) {
  593. return hr;
  594. }
  595. if (FAILED(hr = OurInternalRegisterCategory(rclsid, rguid, rcatid, CAT_BACKWARD))) {
  596. OurInternalUnregisterCategory(rclsid, rcatid, rguid, CAT_FORWARD);
  597. return hr;
  598. }
  599. return S_OK;
  600. }
  601. /* O U R U N R E G I S T E R C A T E G O R Y */
  602. /*-----------------------------------------------------------------------------
  603. private version of UnregisterCategory()
  604. (Cicero library function)
  605. -----------------------------------------------------------------------------*/
  606. HRESULT OurUnregisterCategory( REFCLSID rclsid, REFGUID rcatid, REFGUID rguid )
  607. {
  608. // --- UnregisterCategory() ---
  609. // ITfCategoryMgr *pcat;
  610. // HRESULT hr;
  611. //
  612. // if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  613. // NULL,
  614. // CLSCTX_INPROC_SERVER,
  615. // IID_ITfCategoryMgr,
  616. // (void**)&pcat)))
  617. // {
  618. // hr = pcat->UnregisterCategory(rclsid, rcatid, rguid);
  619. // pcat->Release();
  620. // }
  621. //
  622. // return hr;
  623. // --- CCategoryMgr::UnregisterCategory() ---
  624. // return s_UnregisterCategory(rclsid, rcatid, rguid);
  625. // --- CCategoryMgr::s_UnregisterCategory() ---
  626. // HRESULT hr;
  627. //
  628. // //
  629. // // remove forward link from category to guids.
  630. // //
  631. // if (FAILED(hr = _InternalUnregisterCategory(rclsid, rcatid, rguid, CAT_FORWARD)))
  632. // return hr;
  633. //
  634. // //
  635. // // remove backward link from guid to categories.
  636. // //
  637. // if (FAILED(hr = _InternalUnregisterCategory(rclsid, rguid, rcatid, CAT_BACKWARD)))
  638. // {
  639. // _InternalRegisterCategory(rclsid, rcatid, rguid, CAT_FORWARD);
  640. // return hr;
  641. // }
  642. //
  643. // return S_OK;
  644. HRESULT hr;
  645. if (FAILED(hr = OurInternalUnregisterCategory(rclsid, rcatid, rguid, CAT_FORWARD))) {
  646. return hr;
  647. }
  648. if (FAILED(hr = OurInternalUnregisterCategory(rclsid, rguid, rcatid, CAT_BACKWARD))) {
  649. OurInternalRegisterCategory(rclsid, rcatid, rguid, CAT_FORWARD);
  650. return hr;
  651. }
  652. return S_OK;
  653. }
  654. /* O U R R E G I S T E R C A T E G O R I E S */
  655. /*-----------------------------------------------------------------------------
  656. private version of RegisterCategories()
  657. (Cicero library function)
  658. -----------------------------------------------------------------------------*/
  659. HRESULT OurRegisterCategories( REFCLSID rclsid, const REGISTERCAT *pregcat )
  660. {
  661. // --- RegisterCategories() ---
  662. // while (pregcat->pcatid)
  663. // {
  664. // if (FAILED(RegisterCategory(rclsid, *pregcat->pcatid, *pregcat->pguid)))
  665. // return E_FAIL;
  666. // pregcat++;
  667. // }
  668. // return S_OK;
  669. while (pregcat->pcatid) {
  670. if (FAILED(OurRegisterCategory(rclsid, *pregcat->pcatid, *pregcat->pguid))) {
  671. return E_FAIL;
  672. }
  673. pregcat++;
  674. }
  675. return S_OK;
  676. }
  677. //+---------------------------------------------------------------------------
  678. //
  679. // InitProfileRegKeyStr
  680. //
  681. //----------------------------------------------------------------------------
  682. static BOOL InitProfileRegKeyStr(char *psz, REFCLSID rclsid, LANGID langid, REFGUID guidProfile)
  683. {
  684. lstrcpy(psz, c_szCTFTIPKey);
  685. CLSIDToStringA(rclsid, psz + lstrlen(psz));
  686. lstrcat(psz, "\\");
  687. lstrcat(psz, c_szLanguageProfileKey);
  688. wsprintf(psz + lstrlen(psz), "0x%08x", langid);
  689. lstrcat(psz, "\\");
  690. CLSIDToStringA(guidProfile, psz + lstrlen(psz));
  691. return TRUE;
  692. }
  693. HRESULT OurEnableLanguageProfileByDefault(REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL fEnable)
  694. {
  695. HKEY hKey;
  696. char szTmp[256];
  697. LONG ec;
  698. if (!InitProfileRegKeyStr(szTmp, rclsid, langid, guidProfile))
  699. return E_FAIL;
  700. ec = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szTmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
  701. if (ec != ERROR_SUCCESS)
  702. return E_FAIL;
  703. SetRegValue(hKey, c_szEnable, (DWORD)(fEnable ? 1 : 0));
  704. RegCloseKey(hKey);
  705. return S_OK;
  706. }