|
// Copyright (C) 2011 Fog Creek Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
#include "THgShell_h.h"
#include "TortoiseUtils.h"
#include "StringUtils.h"
#include "QueryDirstate.h"
#include "RegistryConfig.h"
#include "TortoiseHgOverlay.h"
CComAutoCriticalSection CTortoiseHgOverlay::m_cs;
STDMETHODIMP CTortoiseHgOverlay::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax,
int *pIndex, DWORD *pdwFlags)
{
ATLTRACE("CShellExtOverlay::GetOverlayInfo: myTortoiseClass = '%c'\n", m_chTortoiseClass);
// icons are determined by TortoiseOverlays shim
*pIndex = 0;
*pdwFlags = 0;
*pwszIconFile = 0;
return S_OK;
}
STDMETHODIMP CTortoiseHgOverlay::GetPriority(int *pPriority)
{
*pPriority = 1;
return S_OK;
}
STDMETHODIMP CTortoiseHgOverlay::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)
{
CComCritSecLock<CComAutoCriticalSection> lock(m_cs);
CString strCval;
if (GetRegistryConfig("EnableOverlays", strCval) != 0 && strCval == "0")
return S_FALSE;
// This overlay handler processes all filenames in lowercase, so that a path
// "C:\FOO\BAR\Baz.TXT" will be considered equal to "C:\foo\bar\baz.txt"
// (note that mercurial preserves the case of filenames in .hg/dirstate)
CString strPath = CString(pwszPath).MakeLower();
if (GetRegistryConfig("LocalDisksOnly", strCval) != 0 && strCval != "0")
{
if (::PathIsNetworkPath(strPath)) return S_FALSE;
if (strPath.GetLength() > 2 && strPath[1] == ':')
{
CString strDrive = "C:\\";
strDrive.SetAt(0, strPath[0]);
if (::GetDriveType(strDrive) == DRIVE_REMOTE) return S_FALSE;
}
}
char chFilterStatus = 0;
if (m_chTortoiseClass == 'A') chFilterStatus = 'A';
char chStatus = 0;
if (!HgQueryDirstate(m_chTortoiseClass, strPath, chFilterStatus, chStatus))
{
return S_FALSE;
}
return (chStatus == m_chTortoiseClass) ? S_OK : S_FALSE;
}
CTortoiseHgOverlay::CTortoiseHgOverlay(char chClass) :
m_chTortoiseClass(chClass)
{
}
CTortoiseHgNormal::CTortoiseHgNormal() :
CTortoiseHgOverlay('C')
{
}
CTortoiseHgAdded::CTortoiseHgAdded() :
CTortoiseHgOverlay('A')
{
}
CTortoiseHgModified::CTortoiseHgModified() :
CTortoiseHgOverlay('M')
{
}
CTortoiseHgUnversioned::CTortoiseHgUnversioned() :
CTortoiseHgOverlay('?')
{
}
|
Loading...