138
138
FilePath IFileItem.FileName {
139
139
get { return FilePath; }
142
internal bool IsWildcard {
144
return Name.Contains("*");
149
/// Set to true if this ProjectFile was created at load time by
150
/// a ProjectFile containing wildcards. If true, this instance
151
/// should not be saved to a csproj file.
153
internal bool IsOriginatedFromWildcard
159
private const string RecursiveDirectoryWildcard = "**";
161
private string GetWildcardDirectoryName (string path)
163
int indexOfLast = path.LastIndexOfAny (new char[] {
164
Path.DirectorySeparatorChar,
165
Path.AltDirectorySeparatorChar });
173
return path.Substring (0, indexOfLast);
177
private string GetWildcardFileName (string path)
179
int indexOfLast = path.LastIndexOfAny (new char[] {
180
Path.DirectorySeparatorChar,
181
Path.AltDirectorySeparatorChar });
187
else if(indexOfLast == path.Length)
193
return path.Substring (indexOfLast + 1, path.Length - (indexOfLast + 1));
197
internal IEnumerable<string> ResolveWildcardFilePath ()
199
if (String.IsNullOrWhiteSpace(filename)) yield break;
201
string dir = GetWildcardDirectoryName (filename);
202
string file = GetWildcardFileName (filename);
204
if (String.IsNullOrEmpty (dir)) yield break;
205
if (String.IsNullOrEmpty (file)) yield break;
207
if (dir.EndsWith (RecursiveDirectoryWildcard))
209
dir = dir.Substring (0, dir.Length - RecursiveDirectoryWildcard.Length);
211
if (!Directory.Exists (dir))
213
yield break; // Invalid directory
216
List<string> directories = new List<string> ();
218
RecursiveAddChildDirectories (directories, dir);
220
foreach (var resolvedDir in directories)
222
foreach (var resolvedFile in Directory.GetFiles (resolvedDir, file))
224
yield return resolvedFile;
230
foreach (var resolvedFile in Directory.GetFiles (dir, file))
232
yield return resolvedFile;
237
private void RecursiveAddChildDirectories (List<string> directories, string directory)
239
directories.Add (directory);
241
foreach (var child in Directory.GetDirectories (directory))
243
RecursiveAddChildDirectories (directories, child);
247
internal IEnumerable<ProjectFile> ResolveWildcardItems ()
249
foreach (var resolvedFilePath in ResolveWildcardFilePath ())
251
ProjectFile projectFile = (ProjectFile) this.Clone ();
252
projectFile.Name = resolvedFilePath;
253
projectFile.IsOriginatedFromWildcard = true;
254
yield return projectFile;
143
259
/// The file should be treated as effectively having this relative path within the project. If the file is
144
260
/// a link or outside the project root, this will not be the same as the physical file.