OCOverlay.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. #include "stdafx.h"
  15. #include "OCOverlay.h"
  16. #include "OCOverlayFactory.h"
  17. #include "RegistryUtil.h"
  18. #include "StringUtil.h"
  19. #include "UtilConstants.h"
  20. #include "RemotePathChecker.h"
  21. #include "resource.h"
  22. #include <algorithm>
  23. #include <iostream>
  24. #include <fstream>
  25. using namespace std;
  26. #pragma comment(lib, "shlwapi.lib")
  27. extern HINSTANCE instanceHandle;
  28. #define IDM_DISPLAY 0
  29. #define IDB_OK 101
  30. OCOverlay::OCOverlay(int state)
  31. : _referenceCount(1)
  32. , _state(state)
  33. {
  34. static RemotePathChecker s_remotePathChecker;
  35. _checker = &s_remotePathChecker;
  36. }
  37. OCOverlay::~OCOverlay(void)
  38. {
  39. }
  40. IFACEMETHODIMP_(ULONG) OCOverlay::AddRef()
  41. {
  42. return InterlockedIncrement(&_referenceCount);
  43. }
  44. IFACEMETHODIMP OCOverlay::QueryInterface(REFIID riid, void **ppv)
  45. {
  46. HRESULT hr = S_OK;
  47. if (IsEqualIID(IID_IUnknown, riid) || IsEqualIID(IID_IShellIconOverlayIdentifier, riid))
  48. {
  49. *ppv = static_cast<IShellIconOverlayIdentifier *>(this);
  50. }
  51. else
  52. {
  53. hr = E_NOINTERFACE;
  54. *ppv = NULL;
  55. }
  56. if (*ppv)
  57. {
  58. AddRef();
  59. }
  60. return hr;
  61. }
  62. IFACEMETHODIMP_(ULONG) OCOverlay::Release()
  63. {
  64. ULONG cRef = InterlockedDecrement(&_referenceCount);
  65. if (0 == cRef)
  66. {
  67. delete this;
  68. }
  69. return cRef;
  70. }
  71. IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
  72. {
  73. // this defines which handler has prededence, so
  74. // we order this in terms of likelyhood
  75. switch (_state) {
  76. case State_OK:
  77. *pPriority = 0;
  78. case State_OKShared:
  79. *pPriority = 1;
  80. case State_Warning:
  81. *pPriority = 2;
  82. case State_WarningShared:
  83. *pPriority = 3;
  84. case State_Sync:
  85. *pPriority = 4;
  86. case State_SyncShared:
  87. *pPriority = 5;
  88. case State_Error:
  89. *pPriority = 6;
  90. case State_ErrorShared:
  91. *pPriority = 7;
  92. default:
  93. *pPriority = 8;
  94. }
  95. return S_OK;
  96. }
  97. IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
  98. {
  99. auto watchedDirectories = _checker->WatchedDirectories();
  100. wstring wpath(pwszPath);
  101. wpath.append(L"\\");
  102. vector<wstring>::iterator it;
  103. bool watched = false;
  104. for (it = watchedDirectories.begin(); it != watchedDirectories.end(); ++it) {
  105. if (StringUtil::begins_with(wpath, *it)) {
  106. watched = true;
  107. }
  108. }
  109. if (!watched) {
  110. return MAKE_HRESULT(S_FALSE, 0, 0);
  111. }
  112. int state = 0;
  113. if (!_checker->IsMonitoredPath(pwszPath, &state)) {
  114. return MAKE_HRESULT(S_FALSE, 0, 0);
  115. }
  116. return MAKE_HRESULT(state == _state ? S_OK : S_FALSE, 0, 0);
  117. }
  118. IFACEMETHODIMP OCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
  119. {
  120. *pIndex = 0;
  121. *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
  122. *pIndex = _state;
  123. if (GetModuleFileName(instanceHandle, pwszIconFile, cchMax) == 0) {
  124. HRESULT hResult = HRESULT_FROM_WIN32(GetLastError());
  125. wcerr << L"IsOK? " << (hResult == S_OK) << L" with path " << pwszIconFile << L", index " << *pIndex << endl;
  126. return hResult;
  127. }
  128. return S_OK;
  129. }
  130. bool OCOverlay::_IsOverlaysEnabled()
  131. {
  132. //int enable;
  133. bool success = false;
  134. //if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_ENABLE_OVERLAY, &enable))
  135. //{
  136. // if(enable) {
  137. // success = true;
  138. // }
  139. //}
  140. return success;
  141. }