1
0

serviceEditor.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "main.h"
  2. #include "./service.h"
  3. #include <strsafe.h>
  4. static HRESULT Editor_SetStr(LPWSTR *ppTarget, LPCWSTR pValue, BOOL fUtf8, BOOL fCompare, LCID locale, UINT compareFlags)
  5. {
  6. if (NULL == pValue)
  7. {
  8. if (NULL != *ppTarget)
  9. {
  10. Plugin_FreeString(*ppTarget);
  11. *ppTarget = NULL;
  12. return S_OK;
  13. }
  14. return S_FALSE;
  15. }
  16. LPWSTR v = NULL;
  17. if (FALSE == fUtf8)
  18. {
  19. if (NULL != *ppTarget)
  20. {
  21. if (FALSE != fCompare && CSTR_EQUAL == CompareString(locale, compareFlags, *ppTarget, -1, pValue, -1))
  22. return S_FALSE;
  23. }
  24. v = Plugin_CopyString(pValue);
  25. if (NULL == v) return E_OUTOFMEMORY;
  26. }
  27. else
  28. {
  29. v = Plugin_MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pValue, -1);
  30. if (NULL == v) return E_OUTOFMEMORY;
  31. if (NULL != *ppTarget)
  32. {
  33. if (FALSE != fCompare && CSTR_EQUAL == CompareString(locale, compareFlags, *ppTarget, -1, v, -1))
  34. {
  35. Plugin_FreeString(v);
  36. return S_FALSE;
  37. }
  38. }
  39. }
  40. Plugin_FreeString(*ppTarget);
  41. *ppTarget = v;
  42. return S_OK;
  43. }
  44. HRESULT OmService::SetName(LPCWSTR pszName, BOOL utf8)
  45. {
  46. EnterCriticalSection(&lock);
  47. HRESULT hr = Editor_SetStr(&name, pszName, utf8, TRUE, LOCALE_USER_DEFAULT, 0);
  48. LeaveCriticalSection(&lock);
  49. if (S_OK == hr) modified.Mark(modifiedName);
  50. return hr;
  51. }
  52. HRESULT OmService::SetUrl(LPCWSTR pszUrl, BOOL utf8)
  53. {
  54. EnterCriticalSection(&lock);
  55. HRESULT hr = Editor_SetStr(&url, pszUrl, utf8, TRUE, CSTR_INVARIANT, 0);
  56. LeaveCriticalSection(&lock);
  57. if (S_OK == hr) modified.Mark(modifiedUrl);
  58. return hr;
  59. }
  60. HRESULT OmService::SetIcon(LPCWSTR pszPath, BOOL utf8)
  61. {
  62. EnterCriticalSection(&lock);
  63. HRESULT hr = Editor_SetStr(&icon, pszPath, utf8, TRUE, CSTR_INVARIANT, 0);
  64. LeaveCriticalSection(&lock);
  65. if (S_OK == hr) modified.Mark(modifiedIcon);
  66. return hr;
  67. }
  68. HRESULT OmService::SetRating(UINT nRating)
  69. {
  70. HRESULT hr;
  71. EnterCriticalSection(&lock);
  72. if (rating == nRating)
  73. {
  74. hr = S_FALSE;
  75. }
  76. else
  77. {
  78. rating = nRating;
  79. hr = S_OK;
  80. }
  81. LeaveCriticalSection(&lock);
  82. if (S_OK == hr)
  83. modified.Mark(modifiedRating);
  84. return hr;
  85. }
  86. HRESULT OmService::SetVersion(UINT nVersion)
  87. {
  88. HRESULT hr;
  89. EnterCriticalSection(&lock);
  90. if (version == nVersion)
  91. hr = S_FALSE;
  92. else
  93. {
  94. version = nVersion;
  95. hr = S_OK;
  96. }
  97. LeaveCriticalSection(&lock);
  98. if (S_OK == hr)
  99. modified.Mark(modifiedVersion);
  100. return hr;
  101. }
  102. HRESULT OmService::SetGeneration(UINT nGeneration)
  103. {
  104. HRESULT hr;
  105. EnterCriticalSection(&lock);
  106. if (generation == nGeneration)
  107. hr = S_FALSE;
  108. else
  109. {
  110. generation = nGeneration;
  111. hr = S_OK;
  112. }
  113. LeaveCriticalSection(&lock);
  114. if (S_OK == hr)
  115. modified.Mark(modifiedGeneration);
  116. return hr;
  117. }
  118. HRESULT OmService::SetFlags(UINT nFlags, UINT nMask)
  119. {
  120. HRESULT hr;
  121. EnterCriticalSection(&lock);
  122. UINT newFlags = (flags & ~nMask) | (nFlags & nMask);
  123. if (flags == newFlags)
  124. hr = S_FALSE;
  125. else
  126. {
  127. flags = newFlags;
  128. hr = S_OK;
  129. }
  130. LeaveCriticalSection(&lock);
  131. if (S_OK == hr)
  132. modified.Mark(modifiedFlags);
  133. return hr;
  134. }
  135. HRESULT OmService::SetDescription(LPCWSTR pszDescription, BOOL utf8)
  136. {
  137. EnterCriticalSection(&lock);
  138. HRESULT hr = Editor_SetStr(&description, pszDescription, utf8, TRUE, LOCALE_USER_DEFAULT, 0);
  139. LeaveCriticalSection(&lock);
  140. if (S_OK == hr) modified.Mark(modifiedDescription);
  141. return hr;
  142. }
  143. HRESULT OmService::SetAuthorFirst(LPCWSTR pszName, BOOL utf8)
  144. {
  145. EnterCriticalSection(&lock);
  146. HRESULT hr = Editor_SetStr(&authorFirst, pszName, utf8, TRUE, LOCALE_USER_DEFAULT, 0);
  147. LeaveCriticalSection(&lock);
  148. if (S_OK == hr) modified.Mark(modifiedAuthorFirst);
  149. return hr;
  150. }
  151. HRESULT OmService::SetAuthorLast(LPCWSTR pszName, BOOL utf8)
  152. {
  153. EnterCriticalSection(&lock);
  154. HRESULT hr = Editor_SetStr(&authorLast, pszName, utf8, TRUE, LOCALE_USER_DEFAULT, 0);
  155. LeaveCriticalSection(&lock);
  156. if (S_OK == hr) modified.Mark(modifiedAuthorLast);
  157. return hr;
  158. }
  159. HRESULT OmService::SetUpdated(LPCWSTR pszDate, BOOL utf8)
  160. {
  161. EnterCriticalSection(&lock);
  162. HRESULT hr = Editor_SetStr(&updated, pszDate, utf8, TRUE, CSTR_INVARIANT, 0);
  163. LeaveCriticalSection(&lock);
  164. if (S_OK == hr) modified.Mark(modifiedUpdated);
  165. return hr;
  166. }
  167. HRESULT OmService::SetPublished(LPCWSTR pszDate, BOOL utf8)
  168. {
  169. EnterCriticalSection(&lock);
  170. HRESULT hr = Editor_SetStr(&published, pszDate, utf8, TRUE, CSTR_INVARIANT, 0);
  171. LeaveCriticalSection(&lock);
  172. if (S_OK == hr) modified.Mark(modifiedPublished);
  173. return hr;
  174. }
  175. HRESULT OmService::SetThumbnail(LPCWSTR pszPath, BOOL utf8)
  176. {
  177. EnterCriticalSection(&lock);
  178. HRESULT hr = Editor_SetStr(&thumbnail, pszPath, utf8, TRUE, CSTR_INVARIANT, 0);
  179. LeaveCriticalSection(&lock);
  180. if (S_OK == hr) modified.Mark(modifiedThumbnail);
  181. return hr;
  182. }
  183. HRESULT OmService::SetScreenshot(LPCWSTR pszPath, BOOL utf8)
  184. {
  185. EnterCriticalSection(&lock);
  186. HRESULT hr = Editor_SetStr(&screenshot, pszPath, utf8, TRUE, CSTR_INVARIANT, 0);
  187. LeaveCriticalSection(&lock);
  188. if (S_OK == hr) modified.Mark(modifiedScreenshot);
  189. return hr;
  190. }
  191. HRESULT OmService::SetModified(UINT nFlags, UINT nMask)
  192. {
  193. modified.Set(nFlags, nMask);
  194. return S_OK;
  195. }
  196. HRESULT OmService::GetModified(UINT *pFlags)
  197. {
  198. if (NULL == pFlags) return E_POINTER;
  199. *pFlags = modified.Get();
  200. return S_OK;
  201. }
  202. HRESULT OmService::BeginUpdate()
  203. {
  204. modified.BeginUpdate();
  205. return S_OK;
  206. }
  207. HRESULT OmService::EndUpdate()
  208. {
  209. modified.EndUpdate();
  210. return S_OK;
  211. }