Kiln » TortoiseHg » TortoiseHg
Clone URL:  
TortoiseHgOverlay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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('?') { }