PageRenderTime 42ms CodeModel.GetById 33ms app.highlight 6ms RepoModel.GetById 1ms 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
  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
  9#include <shlwapi.h>
 10
 11
 12STDMETHODIMP CShellExtOverlay::GetOverlayInfo(
 13    LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
 14{
 15    TDEBUG_TRACE("CShellExtOverlay::GetOverlayInfo: myTortoiseClass = " << myTortoiseClass);
 16    // icons are determined by TortoiseOverlays shim
 17    *pIndex = 0;
 18    *pdwFlags = 0;
 19    *pwszIconFile = 0;
 20    return S_OK;
 21}
 22
 23
 24STDMETHODIMP CShellExtOverlay::GetPriority(int *pPriority)
 25{
 26    *pPriority = 1;
 27    return S_OK;
 28}
 29
 30
 31STDMETHODIMP CShellExtOverlay::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)
 32{
 33    ThgCriticalSection cs(CShellExt::GetCriticalSection());
 34
 35    std::string cval;
 36    if (GetRegistryConfig("EnableOverlays", cval) != 0 && cval == "0")
 37        return S_FALSE;
 38
 39    // This overlay handler processes all filenames in lowercase, so that a path
 40    // "C:\FOO\BAR\Baz.TXT" will be considered equal to "C:\foo\bar\baz.txt"
 41    // (note that mercurial preserves the case of filenames in .hg/dirstate)
 42
 43    std::wstring lowerpath(pwszPath);
 44    ::CharLowerW(const_cast<wchar_t*>(lowerpath.c_str()));
 45
 46    std::string path = WideToMultibyte(lowerpath.c_str());
 47
 48    if (GetRegistryConfig("LocalDisksOnly", cval) != 0 && cval != "0"
 49            && PathIsNetworkPath(path.c_str()))
 50        return S_FALSE;
 51
 52    char filterStatus = 0;
 53    if (myTortoiseClass == 'A')
 54       filterStatus = 'A';
 55
 56    char status = 0;
 57    if (!HgQueryDirstate(myTortoiseClass, path, filterStatus, status))
 58        return S_FALSE;
 59
 60    if (status == myTortoiseClass)
 61        return S_OK;
 62
 63    return S_FALSE;
 64}
 65
 66
 67CShellExtOverlay::CShellExtOverlay(char tortoiseClass) :
 68    myTortoiseClass(tortoiseClass)
 69{
 70    m_cRef = 0L;
 71    CShellExt::IncDllRef();
 72}
 73
 74
 75CShellExtOverlay::~CShellExtOverlay()
 76{
 77    CShellExt::DecDllRef();
 78}
 79
 80
 81STDMETHODIMP_(ULONG) CShellExtOverlay::AddRef()
 82{
 83    ThgCriticalSection cs(CShellExt::GetCriticalSection());
 84    return ++m_cRef;
 85}
 86
 87
 88STDMETHODIMP_(ULONG) CShellExtOverlay::Release()
 89{
 90    ThgCriticalSection cs(CShellExt::GetCriticalSection());
 91    if(--m_cRef)
 92        return m_cRef;
 93    delete this;
 94    return 0L;
 95}
 96
 97
 98STDMETHODIMP CShellExtOverlay::QueryInterface(REFIID riid, LPVOID FAR* ppv)
 99{    
100    if (ppv == 0)
101        return E_POINTER;
102
103    *ppv = NULL;
104
105    if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier) 
106        || IsEqualIID(riid, IID_IUnknown) )
107    {
108        *ppv = (IShellIconOverlayIdentifier*) this;
109    }
110    
111    if (*ppv)
112    {
113        AddRef();
114        return S_OK;
115    }
116
117    return E_NOINTERFACE;
118}