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

Method ExpandFolderMask

Libraries/unrar/scantree.cpp:78–123  ·  view source on GitHub ↗

For masks like dir1\dir2*\*.ext in non-recursive mode.

Source from the content-addressed store, hash-verified

76
77// For masks like dir1\dir2*\*.ext in non-recursive mode.
78bool ScanTree::ExpandFolderMask()
79{
80 bool WildcardFound=false;
81 uint SlashPos=0;
82 for (int I=0;CurMask[I]!=0;I++)
83 {
84 if (CurMask[I]=='?' || CurMask[I]=='*')
85 WildcardFound=true;
86 if (WildcardFound && IsPathDiv(CurMask[I]))
87 {
88 // First path separator position after folder wildcard mask.
89 // In case of dir1\dir2*\dir3\name.ext mask it may point not to file
90 // name, so we cannot use PointToName() here.
91 SlashPos=I;
92 break;
93 }
94 }
95
96 wchar Mask[NM];
97 wcsncpyz(Mask,CurMask,ASIZE(Mask));
98 Mask[SlashPos]=0;
99
100 // Prepare the list of all folders matching the wildcard mask.
101 ExpandedFolderList.Reset();
102 FindFile Find;
103 Find.SetMask(Mask);
104 FindData FD;
105 while (Find.Next(&FD))
106 if (FD.IsDir)
107 {
108 wcsncatz(FD.Name,CurMask+SlashPos,ASIZE(FD.Name));
109
110 // Treat dir*\* or dir*\*.* as dir, so empty 'dir' is also matched
111 // by such mask. Skipping empty dir with dir*\*.* confused some users.
112 wchar *LastMask=PointToName(FD.Name);
113 if (wcscmp(LastMask,L"*")==0 || wcscmp(LastMask,L"*.*")==0)
114 RemoveNameFromPath(FD.Name);
115
116 ExpandedFolderList.AddString(FD.Name);
117 }
118 if (ExpandedFolderList.ItemsCount()==0)
119 return false;
120 // Return the first matching folder name now.
121 ExpandedFolderList.GetString(CurMask,ASIZE(CurMask));
122 return true;
123}
124
125
126// For masks like dir1\dir2*\file.ext this function sets 'dir1' recursive mask

Callers

nothing calls this directly

Calls 11

IsPathDivFunction · 0.85
wcsncpyzFunction · 0.85
wcsncatzFunction · 0.85
PointToNameFunction · 0.85
RemoveNameFromPathFunction · 0.85
SetMaskMethod · 0.80
NextMethod · 0.80
AddStringMethod · 0.80
ItemsCountMethod · 0.80
GetStringMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected