1
0

configIni.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. #include "./main.h"
  2. #include "./configIni.h"
  3. #include "./ifc_wasabihelper.h"
  4. #include "./ifc_omconfigcallback.h"
  5. #include <api/application/api_application.h>
  6. #include <shlwapi.h>
  7. #include <strsafe.h>
  8. #define BROWSER_SECTION L"OmBrowser"
  9. #define BROWSER_CLIENTID L"clientId"
  10. #define BROWSER_XPOS L"x"
  11. #define BROWSER_YPOS L"y"
  12. #define DEBUG_SECTION L"Debug"
  13. #define DEBUG_BROWSERPATH L"browserPath"
  14. #define DEBUG_FILTERCONTEXTMENU L"filterContextMenu"
  15. #define DEBUG_SHOWSCRIPTDEBUGGER L"showScriptDebugger"
  16. #define DEBUG_SHOWSCRIPTERROR L"showScriptErrors"
  17. #define TOOLBAR_SECTION L"Toolbar"
  18. #define TOOLBAR_BOTTOMDOCK L"bottomDock"
  19. #define TOOLBAR_AUTOHIDE L"autoHide"
  20. #define TOOLBAR_TABSTOP L"tabStop"
  21. #define TOOLBAR_FORCEADDRESSBAR L"addressbarForce"
  22. #define TOOLBAR_FANCYADDRESSBAR L"addressbarFancy"
  23. #define STATUSBAR_SECTION L"Statusbar"
  24. #define STATUSBAR_ENABLED L"enabled"
  25. #define BOOL2HRESULT(__result) ((FALSE != (__result)) ? S_OK : S_FALSE)
  26. OmConfigIni::OmConfigIni(LPCWSTR pszPath)
  27. : ref(1), configPath(NULL), lastCookie(0),
  28. pathValidated(FALSE)
  29. {
  30. InitializeCriticalSection(&lock);
  31. configPath = Plugin_CopyString(pszPath);
  32. }
  33. OmConfigIni::~OmConfigIni()
  34. {
  35. EnterCriticalSection(&lock);
  36. for(CallbackMap::iterator iter = callbackMap.begin(); iter != callbackMap.end(); iter++)
  37. {
  38. ifc_omconfigcallback *callback = iter->second;
  39. if (NULL != callback) callback->Release();
  40. }
  41. LeaveCriticalSection(&lock);
  42. Plugin_FreeString(configPath);
  43. DeleteCriticalSection(&lock);
  44. }
  45. static HRESULT OmConfigIni_MakeFileName(LPWSTR pszBuffer, INT cchBufferMax, LPCWSTR pszName)
  46. {
  47. if (NULL == pszBuffer)
  48. return E_POINTER;
  49. if (NULL == pszName || L'\0' == *pszName ||
  50. FAILED(StringCchCopy(pszBuffer, cchBufferMax, pszName)))
  51. {
  52. return E_INVALIDARG;
  53. }
  54. PathRemoveBlanks(pszBuffer);
  55. INT cchBuffer = lstrlen(pszBuffer);
  56. if (0 == cchBuffer)
  57. return E_INVALIDARG;
  58. if (FAILED(StringCchCopy(pszBuffer + cchBuffer, cchBufferMax - cchBuffer, L".ini")))
  59. return E_FAIL;
  60. return S_OK;
  61. }
  62. HRESULT OmConfigIni::CreateInstance(LPCWSTR pszName, OmConfigIni **instanceOut)
  63. {
  64. if (NULL == instanceOut) return E_POINTER;
  65. *instanceOut = NULL;
  66. WCHAR szFile[MAX_PATH] = {0};
  67. HRESULT hr = OmConfigIni_MakeFileName(szFile, ARRAYSIZE(szFile), pszName);
  68. if (FAILED(hr)) return hr;
  69. ifc_wasabihelper *wasabi = NULL;
  70. hr = Plugin_GetWasabiHelper(&wasabi);
  71. if (SUCCEEDED(hr) && wasabi != NULL)
  72. {
  73. api_application *app = NULL;
  74. hr = wasabi->GetApplicationApi(&app);
  75. if (SUCCEEDED(hr) && app != NULL)
  76. {
  77. WCHAR szBuffer[1024] = {0};
  78. LPCWSTR userPath = app->path_getUserSettingsPath();
  79. if (NULL == userPath || L'\0' == *userPath ||
  80. NULL == PathCombine(szBuffer, userPath, L"Plugins\\omBrowser") ||
  81. FALSE == PathAppend(szBuffer, szFile))
  82. {
  83. hr = E_UNEXPECTED;
  84. }
  85. else
  86. {
  87. *instanceOut = new OmConfigIni(szBuffer);
  88. if (NULL == *instanceOut) hr = E_OUTOFMEMORY;
  89. }
  90. app->Release();
  91. }
  92. wasabi->Release();
  93. }
  94. return hr;
  95. }
  96. size_t OmConfigIni::AddRef()
  97. {
  98. return InterlockedIncrement((LONG*)&ref);
  99. }
  100. size_t OmConfigIni::Release()
  101. {
  102. if (0 == ref)
  103. return ref;
  104. LONG r = InterlockedDecrement((LONG*)&ref);
  105. if (0 == r)
  106. delete(this);
  107. return r;
  108. }
  109. int OmConfigIni::QueryInterface(GUID interface_guid, void **object)
  110. {
  111. if (NULL == object) return E_POINTER;
  112. if (IsEqualIID(interface_guid, IFC_OmConfig))
  113. *object = static_cast<ifc_omconfig*>(this);
  114. else if (IsEqualIID(interface_guid, IFC_OmBrowserConfig))
  115. *object = static_cast<ifc_ombrowserconfig*>(this);
  116. else if (IsEqualIID(interface_guid, IFC_OmDebugConfig))
  117. *object = static_cast<ifc_omdebugconfig*>(this);
  118. else if (IsEqualIID(interface_guid, IFC_OmToolbarConfig))
  119. *object = static_cast<ifc_omtoolbarconfig*>(this);
  120. else if (IsEqualIID(interface_guid, IFC_OmStatusbarConfig))
  121. *object = static_cast<ifc_omstatusbarconfig*>(this);
  122. else
  123. {
  124. *object = NULL;
  125. return E_NOINTERFACE;
  126. }
  127. if (NULL == *object)
  128. return E_UNEXPECTED;
  129. AddRef();
  130. return S_OK;
  131. }
  132. HRESULT OmConfigIni::GetPath(LPWSTR pszBuffer, INT cchBufferMax)
  133. {
  134. if (NULL == pszBuffer) return E_POINTER;
  135. return StringCchCopy(pszBuffer, cchBufferMax, configPath);
  136. }
  137. DWORD OmConfigIni::ReadStr(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR lpDefault, LPWSTR lpReturnedString, DWORD nSize)
  138. {
  139. return GetPrivateProfileStringW(lpSectionName, lpKeyName, lpDefault, lpReturnedString, nSize, configPath);
  140. }
  141. UINT OmConfigIni::ReadInt(LPCWSTR lpSectionName, LPCWSTR lpKeyName, INT nDefault)
  142. {
  143. return GetPrivateProfileIntW(lpSectionName, lpKeyName, nDefault, configPath);
  144. }
  145. BOOL OmConfigIni::ReadBool(LPCWSTR lpSectionName, LPCWSTR lpKeyName, BOOL bDefault)
  146. {
  147. WCHAR szBuffer[32] = {0};
  148. INT cchLen = ReadStr(lpSectionName, lpKeyName, NULL, szBuffer, ARRAYSIZE(szBuffer));
  149. if (0 == cchLen) return bDefault;
  150. if (1 == cchLen)
  151. {
  152. switch(*szBuffer)
  153. {
  154. case L'0':
  155. case L'n':
  156. case L'f':
  157. return FALSE;
  158. case L'1':
  159. case L'y':
  160. case L't':
  161. return TRUE;
  162. }
  163. }
  164. else
  165. {
  166. if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"yes", -1, szBuffer, cchLen) ||
  167. CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"true", -1, szBuffer, cchLen))
  168. {
  169. return TRUE;
  170. }
  171. if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"no", -1, szBuffer, cchLen) ||
  172. CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"false", -1, szBuffer, cchLen))
  173. {
  174. return FALSE;
  175. }
  176. }
  177. INT v = 0;
  178. if (FALSE != StrToIntEx(szBuffer, STIF_SUPPORT_HEX, &v))
  179. return (0 != v);
  180. return bDefault;
  181. }
  182. HRESULT OmConfigIni::WriteStr(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR lpString)
  183. {
  184. if (NULL == configPath || L'\0' == *configPath)
  185. return E_UNEXPECTED;
  186. if (FALSE == pathValidated)
  187. {
  188. WCHAR szDirectory[MAX_PATH*2] = {0};
  189. if (SUCCEEDED(StringCchCopy(szDirectory, ARRAYSIZE(szDirectory), configPath)))
  190. {
  191. PathRemoveFileSpec(szDirectory);
  192. Plugin_EnsurePathExist(szDirectory);
  193. pathValidated = TRUE;
  194. }
  195. }
  196. if (0 != WritePrivateProfileStringW(lpSectionName, lpKeyName, lpString, configPath))
  197. return S_OK;
  198. DWORD errorCode = GetLastError();
  199. return HRESULT_FROM_WIN32(errorCode);
  200. }
  201. HRESULT OmConfigIni::WriteInt(LPCWSTR lpSectionName, LPCWSTR lpKeyName, INT nValue)
  202. {
  203. wchar_t szBuffer[32] = {0};
  204. HRESULT hr = StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), L"%d", nValue);
  205. if (FAILED(hr)) return hr;
  206. return WriteStr(lpSectionName, lpKeyName, szBuffer);
  207. }
  208. HRESULT OmConfigIni::WriteBool(LPCWSTR lpSectionName, LPCWSTR lpKeyName, BOOL bValue)
  209. {
  210. return WriteStr(lpSectionName, lpKeyName, (0 != bValue) ? L"yes" : L"no");
  211. }
  212. HRESULT OmConfigIni::GetClientId(LPWSTR pszBuffer, INT cchBufferMax)
  213. {
  214. if (NULL == pszBuffer) return E_POINTER;
  215. INT cchLen = ReadStr(BROWSER_SECTION, BROWSER_CLIENTID, NULL, pszBuffer, cchBufferMax);
  216. if (0 == cchLen) return S_FALSE;
  217. INT cchPrefix = lstrlen(L"WA-");
  218. if (cchLen <= cchPrefix ||
  219. CSTR_EQUAL != CompareString(CSTR_INVARIANT, NORM_IGNORECASE, pszBuffer, cchPrefix, L"WA-", cchPrefix))
  220. {
  221. pszBuffer[0] = L'\0';
  222. return E_INVALIDARG;
  223. }
  224. return S_OK;
  225. }
  226. HRESULT OmConfigIni::SetClientId(LPWSTR pszClientId)
  227. {
  228. EnterCriticalSection(&lock);
  229. WCHAR szBuffer[128] = {0};
  230. HRESULT hr = GetClientId(szBuffer, ARRAYSIZE(szBuffer));
  231. if (FAILED(hr) || CSTR_EQUAL != CompareString(CSTR_INVARIANT, NORM_IGNORECASE, pszClientId, -1, szBuffer, -1))
  232. {
  233. hr = WriteStr(BROWSER_SECTION, BROWSER_CLIENTID, pszClientId);
  234. if (SUCCEEDED(hr))
  235. {
  236. NotifyChange(&IFC_OmBrowserConfig, CFGID_BROWSER_CLIENTID, (ULONG_PTR)pszClientId);
  237. }
  238. }
  239. LeaveCriticalSection(&lock);
  240. return hr;
  241. }
  242. HRESULT OmConfigIni::GetMenuFilterEnabled(void)
  243. {
  244. BOOL result = ReadBool(DEBUG_SECTION, DEBUG_FILTERCONTEXTMENU, TRUE);
  245. return BOOL2HRESULT(result);
  246. }
  247. HRESULT OmConfigIni::GetScriptErrorEnabled(void)
  248. {
  249. BOOL result = ReadBool(DEBUG_SECTION, DEBUG_SHOWSCRIPTERROR, FALSE);
  250. return BOOL2HRESULT(result);
  251. }
  252. HRESULT OmConfigIni::GetScriptDebuggerEnabled(void)
  253. {
  254. BOOL result = ReadBool(DEBUG_SECTION, DEBUG_SHOWSCRIPTDEBUGGER, FALSE);
  255. return BOOL2HRESULT(result);
  256. }
  257. HRESULT OmConfigIni::GetBrowserPath(LPWSTR pszBuffer, INT cchBufferMax)
  258. {
  259. if (NULL == pszBuffer) return E_POINTER;
  260. INT cchLen = ReadStr(DEBUG_SECTION, DEBUG_BROWSERPATH, NULL, pszBuffer, cchBufferMax);
  261. if (0 == cchLen) return S_FALSE;
  262. if ((L'.' == pszBuffer[0] && L'\\' == pszBuffer[1]) ||
  263. (L'.' == pszBuffer[0] && L'.' == pszBuffer[1] && L'\\' == pszBuffer[2]))
  264. {
  265. WCHAR szTemp[2*MAX_PATH] = {0};
  266. StringCchCopy(szTemp, ARRAYSIZE(szTemp), configPath);
  267. PathRemoveFileSpec(szTemp);
  268. if (FALSE == PathAppend(szTemp, pszBuffer) ||
  269. FAILED(StringCchCopy(pszBuffer, cchBufferMax, szTemp)))
  270. {
  271. pszBuffer[0] = L'\0';
  272. return E_FAIL;
  273. }
  274. }
  275. return S_OK;
  276. }
  277. HRESULT OmConfigIni::EnableMenuFilter(BOOL fEnable)
  278. {
  279. EnterCriticalSection(&lock);
  280. HRESULT hr = GetMenuFilterEnabled();
  281. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  282. {
  283. hr = WriteBool(DEBUG_SECTION, DEBUG_FILTERCONTEXTMENU, fEnable);
  284. if (SUCCEEDED(hr))
  285. {
  286. NotifyChange(&IFC_OmDebugConfig, CFGID_DEBUG_FILTERMENU, (ULONG_PTR)fEnable);
  287. }
  288. }
  289. LeaveCriticalSection(&lock);
  290. return hr;
  291. }
  292. HRESULT OmConfigIni::EnableScriptError(BOOL fEnable)
  293. {
  294. HRESULT hr;
  295. EnterCriticalSection(&lock);
  296. hr = GetScriptErrorEnabled();
  297. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  298. {
  299. hr = WriteBool(DEBUG_SECTION, DEBUG_SHOWSCRIPTERROR, fEnable);
  300. if (SUCCEEDED(hr))
  301. {
  302. NotifyChange(&IFC_OmDebugConfig, CFGID_DEBUG_SCRIPTERROR, (ULONG_PTR)fEnable);
  303. }
  304. }
  305. LeaveCriticalSection(&lock);
  306. return hr;
  307. }
  308. HRESULT OmConfigIni::EnableScriptDebugger(BOOL fEnable)
  309. {
  310. EnterCriticalSection(&lock);
  311. HRESULT hr = GetScriptDebuggerEnabled();
  312. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  313. {
  314. hr = WriteBool(DEBUG_SECTION, DEBUG_SHOWSCRIPTDEBUGGER, fEnable);
  315. if (SUCCEEDED(hr))
  316. {
  317. NotifyChange(&IFC_OmDebugConfig, CFGID_DEBUG_SCRIPTDEBUGGER, (ULONG_PTR)fEnable);
  318. }
  319. }
  320. LeaveCriticalSection(&lock);
  321. return hr;
  322. }
  323. HRESULT OmConfigIni::SetBrowserPath(LPCWSTR pszPath)
  324. {
  325. EnterCriticalSection(&lock);
  326. WCHAR szBuffer[MAX_PATH * 2] = {0};
  327. HRESULT hr = GetBrowserPath(szBuffer, ARRAYSIZE(szBuffer));
  328. if (FAILED(hr) ||
  329. CSTR_EQUAL != CompareString(CSTR_INVARIANT, 0, szBuffer, -1, pszPath, -1))
  330. {
  331. hr = WriteString(DEBUG_SECTION, DEBUG_SHOWSCRIPTDEBUGGER, pszPath);
  332. if (SUCCEEDED(hr))
  333. {
  334. NotifyChange(&IFC_OmDebugConfig, CFGID_DEBUG_BROWSERPATH, (ULONG_PTR)pszPath);
  335. }
  336. }
  337. LeaveCriticalSection(&lock);
  338. return hr;
  339. }
  340. HRESULT OmConfigIni::Toolbar_GetBottomDockEnabled(void)
  341. {
  342. BOOL result = ReadBool(TOOLBAR_SECTION, TOOLBAR_BOTTOMDOCK, FALSE);
  343. return BOOL2HRESULT(result);
  344. }
  345. HRESULT OmConfigIni::Toolbar_GetAutoHideEnabled(void)
  346. {
  347. BOOL result = ReadBool(TOOLBAR_SECTION, TOOLBAR_AUTOHIDE, FALSE);
  348. return BOOL2HRESULT(result);
  349. }
  350. HRESULT OmConfigIni::Toolbar_GetTabStopEnabled(void)
  351. {
  352. BOOL result = ReadBool(TOOLBAR_SECTION, TOOLBAR_TABSTOP, FALSE);
  353. return BOOL2HRESULT(result);
  354. }
  355. HRESULT OmConfigIni::Toolbar_GetForceAddressbarEnabled(void)
  356. {
  357. BOOL result = ReadBool(TOOLBAR_SECTION, TOOLBAR_FORCEADDRESSBAR, FALSE);
  358. return BOOL2HRESULT(result);
  359. }
  360. HRESULT OmConfigIni::Toolbar_GetFancyAddressbarEnabled(void)
  361. {
  362. BOOL result = ReadBool(TOOLBAR_SECTION, TOOLBAR_FANCYADDRESSBAR, TRUE);
  363. return BOOL2HRESULT(result);
  364. }
  365. HRESULT OmConfigIni::Toolbar_EnableBottomDock(BOOL fEnable)
  366. {
  367. EnterCriticalSection(&lock);
  368. HRESULT hr = Toolbar_GetBottomDockEnabled();
  369. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  370. {
  371. hr = WriteBool(TOOLBAR_SECTION, TOOLBAR_BOTTOMDOCK, fEnable);
  372. if (SUCCEEDED(hr))
  373. {
  374. NotifyChange(&IFC_OmToolbarConfig, CFGID_TOOLBAR_BOTTOMDOCK, (ULONG_PTR)fEnable);
  375. }
  376. }
  377. LeaveCriticalSection(&lock);
  378. return hr;
  379. }
  380. HRESULT OmConfigIni::Toolbar_EnableAutoHide(BOOL fEnable)
  381. {
  382. EnterCriticalSection(&lock);
  383. HRESULT hr = Toolbar_GetAutoHideEnabled();
  384. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  385. {
  386. hr = WriteBool(TOOLBAR_SECTION, TOOLBAR_AUTOHIDE, fEnable);
  387. if (SUCCEEDED(hr))
  388. {
  389. NotifyChange(&IFC_OmToolbarConfig, CFGID_TOOLBAR_AUTOHIDE, (ULONG_PTR)fEnable);
  390. }
  391. }
  392. LeaveCriticalSection(&lock);
  393. return hr;
  394. }
  395. HRESULT OmConfigIni::Toolbar_EnableTabStop(BOOL fEnable)
  396. {
  397. EnterCriticalSection(&lock);
  398. HRESULT hr = Toolbar_GetTabStopEnabled();
  399. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  400. {
  401. hr = WriteBool(TOOLBAR_SECTION, TOOLBAR_TABSTOP, fEnable);
  402. if (SUCCEEDED(hr))
  403. {
  404. NotifyChange(&IFC_OmToolbarConfig, CFGID_TOOLBAR_TABSTOP, (ULONG_PTR)fEnable);
  405. }
  406. }
  407. LeaveCriticalSection(&lock);
  408. return hr;
  409. }
  410. HRESULT OmConfigIni::Toolbar_EnableForceAddressbar(BOOL fEnable)
  411. {
  412. EnterCriticalSection(&lock);
  413. HRESULT hr = Toolbar_GetForceAddressbarEnabled();
  414. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  415. {
  416. hr = WriteBool(TOOLBAR_SECTION, TOOLBAR_FORCEADDRESSBAR, fEnable);
  417. if (SUCCEEDED(hr))
  418. {
  419. NotifyChange(&IFC_OmToolbarConfig, CFGID_TOOLBAR_FORCEADDRESS, (ULONG_PTR)fEnable);
  420. }
  421. }
  422. LeaveCriticalSection(&lock);
  423. return hr;
  424. }
  425. HRESULT OmConfigIni::Toolbar_EnableFancyAddressbar(BOOL fEnable)
  426. {
  427. EnterCriticalSection(&lock);
  428. HRESULT hr = Toolbar_GetFancyAddressbarEnabled();
  429. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  430. {
  431. hr = WriteBool(TOOLBAR_SECTION, TOOLBAR_FANCYADDRESSBAR, fEnable);
  432. if (SUCCEEDED(hr))
  433. {
  434. NotifyChange(&IFC_OmToolbarConfig, CFGID_TOOLBAR_FANCYADDRESS, (ULONG_PTR)fEnable);
  435. }
  436. }
  437. LeaveCriticalSection(&lock);
  438. return hr;
  439. }
  440. HRESULT OmConfigIni::Statusbar_GetEnabled(void)
  441. {
  442. BOOL result = ReadBool(STATUSBAR_SECTION, STATUSBAR_ENABLED, FALSE);
  443. return BOOL2HRESULT(result);
  444. }
  445. HRESULT OmConfigIni::Statusbar_EnableStatusbar(BOOL fEnable)
  446. {
  447. EnterCriticalSection(&lock);
  448. HRESULT hr = Statusbar_GetEnabled();
  449. if (FAILED(hr) || ((S_OK == hr) != (FALSE != fEnable)))
  450. {
  451. hr = WriteBool(STATUSBAR_SECTION, STATUSBAR_ENABLED, fEnable);
  452. if (SUCCEEDED(hr))
  453. {
  454. NotifyChange(&IFC_OmStatusbarConfig, CFGID_STATUSBAR_ENABLED, (ULONG_PTR)fEnable);
  455. }
  456. }
  457. LeaveCriticalSection(&lock);
  458. return hr;
  459. }
  460. HRESULT OmConfigIni::RegisterCallback(ifc_omconfigcallback *callback, UINT *cookie)
  461. {
  462. if (NULL == cookie) return E_POINTER;
  463. *cookie = 0;
  464. if (NULL == callback)
  465. return E_INVALIDARG;
  466. EnterCriticalSection(&lock);
  467. *cookie = ++lastCookie;
  468. callbackMap.insert({ *cookie, callback });
  469. callback->AddRef();
  470. LeaveCriticalSection(&lock);
  471. return S_OK;
  472. }
  473. HRESULT OmConfigIni::UnregisterCallback(UINT cookie)
  474. {
  475. if (0 == cookie) return E_INVALIDARG;
  476. ifc_omconfigcallback *callback = NULL;
  477. EnterCriticalSection(&lock);
  478. for(CallbackMap::iterator iter = callbackMap.begin(); iter != callbackMap.end(); iter++)
  479. {
  480. if (cookie == iter->first)
  481. {
  482. callback = iter->second;
  483. callbackMap.erase(iter);
  484. break;
  485. }
  486. }
  487. LeaveCriticalSection(&lock);
  488. if (NULL != callback)
  489. {
  490. callback->Release();
  491. return S_OK;
  492. }
  493. return S_FALSE;
  494. }
  495. void OmConfigIni::NotifyChange(const GUID *configUid, UINT valueId, ULONG_PTR value)
  496. {
  497. EnterCriticalSection(&lock);
  498. for(CallbackMap::iterator iter = callbackMap.begin(); iter != callbackMap.end(); iter++)
  499. {
  500. ifc_omconfigcallback *callback = iter->second;
  501. callback->ValueChanged(configUid, valueId, value);
  502. }
  503. LeaveCriticalSection(&lock);
  504. }
  505. UINT OmConfigIni::GetX(void)
  506. {
  507. return ReadInt(BROWSER_SECTION, BROWSER_XPOS, -1);
  508. }
  509. UINT OmConfigIni::GetY(void)
  510. {
  511. return ReadInt(BROWSER_SECTION, BROWSER_YPOS, -1);
  512. }
  513. HRESULT OmConfigIni::SetX(UINT x)
  514. {
  515. return WriteInt(BROWSER_SECTION, BROWSER_XPOS, x);
  516. }
  517. HRESULT OmConfigIni::SetY(UINT y)
  518. {
  519. return WriteInt(BROWSER_SECTION, BROWSER_YPOS, y);
  520. }
  521. #define CBCLASS OmConfigIni
  522. START_MULTIPATCH
  523. START_PATCH(MPIID_OMCONFIG)
  524. M_CB(MPIID_OMCONFIG, ifc_omconfig, ADDREF, AddRef);
  525. M_CB(MPIID_OMCONFIG, ifc_omconfig, RELEASE, Release);
  526. M_CB(MPIID_OMCONFIG, ifc_omconfig, QUERYINTERFACE, QueryInterface);
  527. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_GETPATH, GetPath);
  528. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_READSTRING, ReadStr);
  529. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_READINT, ReadInt);
  530. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_READBOOL, ReadBool);
  531. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_WRITESTRING, WriteStr);
  532. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_WRITEINT, WriteInt);
  533. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_WRITEBOOL, WriteBool);
  534. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_REGISTERCALLBACK, RegisterCallback);
  535. M_CB(MPIID_OMCONFIG, ifc_omconfig, API_UNREGISTERCALLBACK, UnregisterCallback);
  536. NEXT_PATCH(MPIID_OMBROWSERCONFIG)
  537. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, ADDREF, AddRef);
  538. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, RELEASE, Release);
  539. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, QUERYINTERFACE, QueryInterface);
  540. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_GETCLIENTID, GetClientId);
  541. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_SETCLIENTID, SetClientId);
  542. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_GETX, GetX);
  543. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_SETX, SetX);
  544. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_GETY, GetY);
  545. M_CB(MPIID_OMBROWSERCONFIG, ifc_ombrowserconfig, API_SETY, SetY);
  546. NEXT_PATCH(MPIID_OMDEBUGCONFIG)
  547. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, ADDREF, AddRef);
  548. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, RELEASE, Release);
  549. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, QUERYINTERFACE, QueryInterface);
  550. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_GETMENUFILTERENABLED, GetMenuFilterEnabled);
  551. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_GETSCRIPTERRORENABLED, GetScriptErrorEnabled);
  552. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_GETSCRIPTDEBUGGERENABLED, GetScriptDebuggerEnabled);
  553. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_GETBROWSERPATH, GetBrowserPath);
  554. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_ENABLEMENUFILTER, EnableMenuFilter);
  555. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_ENABLESCRIPTERROR, EnableScriptError);
  556. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_ENABLESCRIPTDEBUGGER, EnableScriptDebugger);
  557. M_CB(MPIID_OMDEBUGCONFIG, ifc_omdebugconfig, API_SETBROWSERPATH, SetBrowserPath);
  558. NEXT_PATCH(MPIID_OMTOOLBARCONFIG)
  559. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, ADDREF, AddRef);
  560. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, RELEASE, Release);
  561. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, QUERYINTERFACE, QueryInterface);
  562. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_GETBOTTOMDOCKENABLED, Toolbar_GetBottomDockEnabled);
  563. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_ENABLEBOTTOMDOCK, Toolbar_EnableBottomDock);
  564. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_GETAUTOHIDEENABLED, Toolbar_GetAutoHideEnabled);
  565. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_ENABLEAUTOHIDE, Toolbar_EnableAutoHide);
  566. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_GETTABSTOPENABLED, Toolbar_GetTabStopEnabled);
  567. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_ENABLETABSTOP, Toolbar_EnableTabStop);
  568. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_GETFORCEADDRESSBARENABLED, Toolbar_GetForceAddressbarEnabled);
  569. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_ENABLEFORCEADDRESSBAR, Toolbar_EnableForceAddressbar);
  570. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_GETFANCYADDRESSBARENABLED, Toolbar_GetFancyAddressbarEnabled);
  571. M_CB(MPIID_OMTOOLBARCONFIG, ifc_omtoolbarconfig, API_ENABLEFANCYADDRESSBAR, Toolbar_EnableFancyAddressbar);
  572. NEXT_PATCH(MPIID_OMSTATUSBARCONFIG)
  573. M_CB(MPIID_OMSTATUSBARCONFIG, ifc_omstatusbarconfig, ADDREF, AddRef);
  574. M_CB(MPIID_OMSTATUSBARCONFIG, ifc_omstatusbarconfig, RELEASE, Release);
  575. M_CB(MPIID_OMSTATUSBARCONFIG, ifc_omstatusbarconfig, QUERYINTERFACE, QueryInterface);
  576. M_CB(MPIID_OMSTATUSBARCONFIG, ifc_omstatusbarconfig, API_GETENABLED, Statusbar_GetEnabled);
  577. M_CB(MPIID_OMSTATUSBARCONFIG, ifc_omstatusbarconfig, API_ENABLESTATUSBAR, Statusbar_EnableStatusbar);
  578. END_PATCH
  579. END_MULTIPATCH;
  580. #undef CBCLASS