1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2019, 2021-2024 - TortoiseGit
4 // Copyright (C) 2003-2011, 2017 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #define ADMINDIRTIMEOUT 10000
25 #define DRIVETYPETIMEOUT 300000 // 5 min
27 #define DEFAULTWIN11MENUTOPENTRIES MENUSYNC|MENUCOMMIT|MENUSWITCH|MENUREVERT|MENUCONFLICTEDITOR|MENUDIFF|MENUPULL|MENUPUSH|MENUREPOBROWSE|MENULOG|MENUBLAME|MENUCLONE|MENUMERGE|MENUSTASHSAVE|MENUSETTINGS
28 #define DEFAULTMENUTOPENTRIES MENUSYNC|MENUCREATEREPOS|MENUCLONE|MENUCOMMIT
29 #define DEFAULTMENUEXTENTRIES MENUSVNIGNORE|MENUSTASHAPPLY|MENUSUBSYNC
31 using Locker
= CComCritSecLock
<CComCriticalSection
>;
35 /** state known to be false (the constant does not evaulate to false) */
37 /** state known to be true */
39 /** state could be true or false */
44 * \ingroup TortoiseShell
45 * Helper class which caches access to the registry. Also provides helper methods
46 * for checks against the settings stored in the registry.
56 dllFull
,// same as dll except it uses commandline git tool with all status modes supported
62 bool RefreshIfNeeded();
64 CacheType
GetCacheType();
66 unsigned __int64
GetMenuLayout();
67 unsigned __int64
GetMenuLayout11();
68 unsigned __int64
GetMenuExt();
69 unsigned __int64
GetMenuMask();
71 bool IsProcessElevated();
72 BOOL
IsOnlyNonElevated();
75 BOOL
IsFolderOverlay();
76 BOOL
IsSimpleContext();
77 BOOL
HasShellMenuAccelerators();
78 BOOL
IsUnversionedAsModified();
79 BOOL
IsRecurseSubmodules();
80 BOOL
ShowUnversionedOverlay();
81 BOOL
ShowIgnoredOverlay();
82 BOOL
ShowExcludedAsNormal();
83 BOOL
HideMenusForUnversionedItems();
92 BOOL
IsContextPathAllowed(const std::wstring
& path
);
93 BOOL
IsPathAllowed(LPCWSTR path
);
95 BOOL
HasGITAdminDir(LPCWSTR path
, BOOL bIsDir
, CString
* ProjectTopDir
= nullptr);
98 void ExcludeContextValid();
103 /// node in the lookup tree
108 /// default (path spec did not end a '?').
109 /// if this is not set, the default for all
110 /// sub-paths is !included.
111 /// This is a temporary setting an be invalid
112 /// after @ref PostProcessData
113 bool recursive
= false;
115 /// this is an "include" specification
116 Tristate included
= Tristate::Unknown
;
118 /// if @ref recursive is not set, this is
119 /// the parent path status being passed down
120 /// combined with the information of other
121 /// entries for the same @ref path.
122 Tristate subPathIncluded
= Tristate::Unknown
;
124 /// do entries for sub-paths exist?
125 bool hasSubFolderEntries
= false;
128 /// For efficient folding, it is imperative that
129 /// "recursive" entries are first
130 bool operator<(const SEntry
& rhs
) const
132 int diff
= _wcsicmp(path
.c_str(), rhs
.path
.c_str());
133 return (diff
< 0) || ((diff
== 0) && recursive
&& !rhs
.recursive
);
136 friend bool operator<(const SEntry
& rhs
, const std::pair
<LPCWSTR
, size_t>& lhs
);
137 friend bool operator<(const std::pair
<LPCWSTR
, size_t>& lhs
, const SEntry
& rhs
);
141 /// lookup by path (all entries sorted by path)
142 using TData
= std::vector
<SEntry
>;
145 /// registry keys plus cached last content
146 CRegStdString excludelist
;
147 std::wstring excludeliststr
;
149 CRegStdString includelist
;
150 std::wstring includeliststr
;
152 /// construct \ref data content
153 void AddEntry(const std::wstring
& s
, bool include
);
154 void AddEntries(const std::wstring
& s
, bool include
);
156 /// for all paths, have at least one entry in data
157 void PostProcessData();
159 /// lookup. default result is "unknown".
160 /// We must look for *every* parent path because of situations like:
161 /// excluded: C:, C:\some\deep\path
163 /// lookup for C:\some\deeper\path
164 Tristate
IsPathAllowed(LPCWSTR path
, TData::const_iterator begin
, TData::const_iterator end
) const;
170 /// notify of (potential) registry settings
174 Tristate
IsPathAllowed(LPCWSTR path
) const;
177 friend bool operator< (const CPathFilter::SEntry
& rhs
, const std::pair
<LPCWSTR
, size_t>& lhs
);
178 friend bool operator< (const std::pair
<LPCWSTR
, size_t>& lhs
, const CPathFilter::SEntry
& rhs
);
182 BOOL bHasAdminDir
= false;
183 std::wstring sProjectRoot
;
184 ULONGLONG timeout
= ADMINDIRTIMEOUT
;
188 CRegStdDWORD cachetype
;
189 CRegStdDWORD blockstatus
;
191 CRegStdDWORD onlynonelevated
;
192 CRegStdDWORD showrecursive
;
193 CRegStdDWORD folderoverlay
;
194 CRegStdDWORD driveremote
;
195 CRegStdDWORD drivefixed
;
196 CRegStdDWORD drivecdrom
;
197 CRegStdDWORD driveremove
;
198 CRegStdDWORD drivefloppy
;
199 CRegStdDWORD driveram
;
200 CRegStdDWORD driveunknown
;
201 CRegStdQWORD menuLayout11
;
202 CRegStdDWORD menulayoutlow
; /* Fist level mask */
203 CRegStdDWORD menulayouthigh
;
204 CRegStdDWORD shellmenuaccelerators
;
205 CRegStdDWORD menuextlow
; /* ext menu mask */
206 CRegStdDWORD menuexthigh
;
207 CRegStdDWORD simplecontext
;
208 CRegStdDWORD menumasklow_lm
;
209 CRegStdDWORD menumaskhigh_lm
;
210 CRegStdDWORD menumasklow_cu
;
211 CRegStdDWORD menumaskhigh_cu
;
212 CRegStdDWORD unversionedasmodified
;
213 CRegStdDWORD recursesubmodules
;
214 CRegStdDWORD showunversionedoverlay
;
215 CRegStdDWORD showignoredoverlay
;
216 CRegStdDWORD excludedasnormal
;
217 CRegStdDWORD hidemenusforunversioneditems
;
219 CPathFilter pathFilter
;
221 ULONGLONG drivetypeticker
= 0;
222 ULONGLONG menumaskticker
= 0;
223 UINT drivetypecache
[27];
224 wchar_t drivetypepathcache
[MAX_PATH
]{}; // MAX_PATH ok.
225 std::map
<std::wstring
, AdminDir_s
> admindircache
;
226 CRegStdString nocontextpaths
;
227 std::wstring excludecontextstr
;
228 std::vector
<std::wstring
> excontextvector
;
229 CComAutoCriticalSection m_critSec
;
230 HANDLE m_registryChangeEvent
= nullptr;
231 HKEY m_hNotifyRegKey
= nullptr;
232 bool isElevated
= false;
235 inline bool operator<(const ShellCache::CPathFilter::SEntry
& lhs
, const std::pair
<LPCWSTR
, size_t>& rhs
)
237 return _wcsnicmp(lhs
.path
.c_str(), rhs
.first
, rhs
.second
) < 0;
240 inline bool operator<(const std::pair
<LPCWSTR
, size_t>& lhs
, const ShellCache::CPathFilter::SEntry
& rhs
)
242 return _wcsnicmp(lhs
.first
, rhs
.path
.c_str(), lhs
.second
) < 0;