PageRenderTime 36ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/win32/shellext/CShellExtOverlay.cpp

https://bitbucket.org/tortoisehg/hgtk/
C++ | 118 lines | 84 code | 30 blank | 4 comment | 20 complexity | 138a8f76dcfbbcfaf902d1d40fca0832 MD5 | raw file
Possible License(s): GPL-2.0
  1. #include "stdafx.h"
  2. #include "ShellExt.h"
  3. #include "TortoiseUtils.h"
  4. #include "StringUtils.h"
  5. #include "QueryDirstate.h"
  6. #include "RegistryConfig.h"
  7. #include "CShellExtOverlay.h"
  8. #include <shlwapi.h>
  9. STDMETHODIMP CShellExtOverlay::GetOverlayInfo(
  10. LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
  11. {
  12. TDEBUG_TRACE("CShellExtOverlay::GetOverlayInfo: myTortoiseClass = " << myTortoiseClass);
  13. // icons are determined by TortoiseOverlays shim
  14. *pIndex = 0;
  15. *pdwFlags = 0;
  16. *pwszIconFile = 0;
  17. return S_OK;
  18. }
  19. STDMETHODIMP CShellExtOverlay::GetPriority(int *pPriority)
  20. {
  21. *pPriority = 1;
  22. return S_OK;
  23. }
  24. STDMETHODIMP CShellExtOverlay::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)
  25. {
  26. ThgCriticalSection cs(CShellExt::GetCriticalSection());
  27. std::string cval;
  28. if (GetRegistryConfig("EnableOverlays", cval) != 0 && cval == "0")
  29. return S_FALSE;
  30. // This overlay handler processes all filenames in lowercase, so that a path
  31. // "C:\FOO\BAR\Baz.TXT" will be considered equal to "C:\foo\bar\baz.txt"
  32. // (note that mercurial preserves the case of filenames in .hg/dirstate)
  33. std::wstring lowerpath(pwszPath);
  34. ::CharLowerW(const_cast<wchar_t*>(lowerpath.c_str()));
  35. std::string path = WideToMultibyte(lowerpath.c_str());
  36. if (GetRegistryConfig("LocalDisksOnly", cval) != 0 && cval != "0"
  37. && PathIsNetworkPath(path.c_str()))
  38. return S_FALSE;
  39. char filterStatus = 0;
  40. if (myTortoiseClass == 'A')
  41. filterStatus = 'A';
  42. char status = 0;
  43. if (!HgQueryDirstate(myTortoiseClass, path, filterStatus, status))
  44. return S_FALSE;
  45. if (status == myTortoiseClass)
  46. return S_OK;
  47. return S_FALSE;
  48. }
  49. CShellExtOverlay::CShellExtOverlay(char tortoiseClass) :
  50. myTortoiseClass(tortoiseClass)
  51. {
  52. m_cRef = 0L;
  53. CShellExt::IncDllRef();
  54. }
  55. CShellExtOverlay::~CShellExtOverlay()
  56. {
  57. CShellExt::DecDllRef();
  58. }
  59. STDMETHODIMP_(ULONG) CShellExtOverlay::AddRef()
  60. {
  61. ThgCriticalSection cs(CShellExt::GetCriticalSection());
  62. return ++m_cRef;
  63. }
  64. STDMETHODIMP_(ULONG) CShellExtOverlay::Release()
  65. {
  66. ThgCriticalSection cs(CShellExt::GetCriticalSection());
  67. if(--m_cRef)
  68. return m_cRef;
  69. delete this;
  70. return 0L;
  71. }
  72. STDMETHODIMP CShellExtOverlay::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  73. {
  74. if (ppv == 0)
  75. return E_POINTER;
  76. *ppv = NULL;
  77. if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier)
  78. || IsEqualIID(riid, IID_IUnknown) )
  79. {
  80. *ppv = (IShellIconOverlayIdentifier*) this;
  81. }
  82. if (*ppv)
  83. {
  84. AddRef();
  85. return S_OK;
  86. }
  87. return E_NOINTERFACE;
  88. }