MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / GetFilteredMask

Method GetFilteredMask

Libraries/unrar/scantree.cpp:129–207  ·  view source on GitHub ↗

For masks like dir1\dir2*\file.ext this function sets 'dir1' recursive mask and '*\dir2*\file.ext' filter. Masks without folder wildcards are returned as is.

Source from the content-addressed store, hash-verified

127// and '*\dir2*\file.ext' filter. Masks without folder wildcards are
128// returned as is.
129bool ScanTree::GetFilteredMask()
130{
131 // If we have some matching folders left for non-recursive folder wildcard
132 // mask, we return it here.
133 if (ExpandedFolderList.ItemsCount()>0 && ExpandedFolderList.GetString(CurMask,ASIZE(CurMask)))
134 return true;
135
136 FolderWildcards=false;
137 FilterList.Reset();
138 if (!FileMasks->GetString(CurMask,ASIZE(CurMask)))
139 return false;
140
141 // Check if folder wildcards present.
142 bool WildcardFound=false;
143 uint FolderWildcardCount=0;
144 uint SlashPos=0;
145 uint StartPos=0;
146#ifdef _WIN_ALL // Not treat the special NTFS \\?\d: path prefix as a wildcard.
147 if (CurMask[0]=='\\' && CurMask[1]=='\\' && CurMask[2]=='?' && CurMask[3]=='\\')
148 StartPos=4;
149#endif
150 for (uint I=StartPos;CurMask[I]!=0;I++)
151 {
152 if (CurMask[I]=='?' || CurMask[I]=='*')
153 WildcardFound=true;
154 if (IsPathDiv(CurMask[I]) || IsDriveDiv(CurMask[I]))
155 {
156 if (WildcardFound)
157 {
158 // Calculate a number of folder wildcards in current mask.
159 FolderWildcardCount++;
160 WildcardFound=false;
161 }
162 if (FolderWildcardCount==0)
163 SlashPos=I; // Slash position before first folder wildcard mask.
164 }
165 }
166 if (FolderWildcardCount==0)
167 return true;
168 FolderWildcards=true; // Global folder wildcards flag.
169
170 // If we have only one folder wildcard component and -r is missing or -r-
171 // is specified, prepare matching folders in non-recursive mode.
172 // We assume -r for masks like dir1*\dir2*\file*, because it is complicated
173 // to fast find them using OS file find API call.
174 if ((Recurse==RECURSE_NONE || Recurse==RECURSE_DISABLE) && FolderWildcardCount==1)
175 return ExpandFolderMask();
176
177 wchar Filter[NM];
178 // Convert path\dir*\ to *\dir filter to search for 'dir' in all 'path' subfolders.
179 wcsncpyz(Filter,L"*",ASIZE(Filter));
180 AddEndSlash(Filter,ASIZE(Filter));
181 // SlashPos might point or not point to path separator for masks like 'dir*', '\dir*' or 'd:dir*'
182 wchar *WildName=IsPathDiv(CurMask[SlashPos]) || IsDriveDiv(CurMask[SlashPos]) ? CurMask+SlashPos+1 : CurMask+SlashPos;
183 wcsncatz(Filter,WildName,ASIZE(Filter));
184
185 // Treat dir*\* or dir*\*.* as dir\, so empty 'dir' is also matched
186 // by such mask. Skipping empty dir with dir*\*.* confused some users.

Callers

nothing calls this directly

Calls 10

IsPathDivFunction · 0.85
IsDriveDivFunction · 0.85
wcsncpyzFunction · 0.85
AddEndSlashFunction · 0.85
wcsncatzFunction · 0.85
PointToNameFunction · 0.85
ItemsCountMethod · 0.80
GetStringMethod · 0.80
AddStringMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected