~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
                FilePath IFileItem.FileName {
139
139
                        get { return FilePath; }
140
140
                }
141
 
                
 
141
 
 
142
                internal bool IsWildcard {
 
143
                        get {
 
144
                                return Name.Contains("*");
 
145
                        }
 
146
                }
 
147
 
 
148
                /// <summary>
 
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.
 
152
                /// </summary>
 
153
                internal bool IsOriginatedFromWildcard
 
154
                {
 
155
                        get;
 
156
                        private set;
 
157
                }
 
158
 
 
159
                private const string RecursiveDirectoryWildcard = "**";
 
160
 
 
161
                private string GetWildcardDirectoryName (string path)
 
162
                {
 
163
                        int indexOfLast = path.LastIndexOfAny (new char[] {
 
164
                                Path.DirectorySeparatorChar, 
 
165
                                Path.AltDirectorySeparatorChar });
 
166
 
 
167
                        if (indexOfLast < 0) 
 
168
                        {
 
169
                                return String.Empty;
 
170
                        }
 
171
                        else
 
172
                        {
 
173
                                return path.Substring (0, indexOfLast);
 
174
                        }
 
175
                }
 
176
 
 
177
                private string GetWildcardFileName (string path)
 
178
                {
 
179
                        int indexOfLast = path.LastIndexOfAny (new char[] {
 
180
                                Path.DirectorySeparatorChar, 
 
181
                                Path.AltDirectorySeparatorChar });
 
182
                        
 
183
                        if (indexOfLast < 0) 
 
184
                        {
 
185
                                return path;
 
186
                        }
 
187
                        else if(indexOfLast == path.Length)
 
188
                        {
 
189
                                return String.Empty;
 
190
                        }
 
191
                        else
 
192
                        {
 
193
                                return path.Substring (indexOfLast + 1, path.Length - (indexOfLast + 1));
 
194
                        }
 
195
                }
 
196
 
 
197
                internal IEnumerable<string> ResolveWildcardFilePath ()
 
198
                {
 
199
                        if (String.IsNullOrWhiteSpace(filename)) yield break;
 
200
 
 
201
                        string dir = GetWildcardDirectoryName (filename);
 
202
                        string file = GetWildcardFileName (filename);
 
203
 
 
204
                        if (String.IsNullOrEmpty (dir)) yield break;
 
205
                        if (String.IsNullOrEmpty (file)) yield break;
 
206
 
 
207
                        if (dir.EndsWith (RecursiveDirectoryWildcard))
 
208
                        {
 
209
                                dir = dir.Substring (0, dir.Length - RecursiveDirectoryWildcard.Length);
 
210
 
 
211
                                if (!Directory.Exists (dir))
 
212
                                {
 
213
                                        yield break; // Invalid directory
 
214
                                }
 
215
 
 
216
                                List<string> directories = new List<string> ();
 
217
 
 
218
                                RecursiveAddChildDirectories (directories, dir);
 
219
 
 
220
                                foreach (var resolvedDir in directories)
 
221
                                {
 
222
                                        foreach (var resolvedFile in Directory.GetFiles (resolvedDir, file))
 
223
                                        {
 
224
                                                yield return resolvedFile;
 
225
                                        }
 
226
                                }
 
227
                        }
 
228
                        else
 
229
                        {
 
230
                                foreach (var resolvedFile in Directory.GetFiles (dir, file))
 
231
                                {
 
232
                                        yield return resolvedFile;
 
233
                                }
 
234
                        }
 
235
                }
 
236
 
 
237
                private void RecursiveAddChildDirectories (List<string> directories, string directory)
 
238
                {
 
239
                        directories.Add (directory);
 
240
 
 
241
                        foreach (var child in Directory.GetDirectories (directory))
 
242
                        {
 
243
                                RecursiveAddChildDirectories (directories, child);
 
244
                        }
 
245
                }
 
246
 
 
247
                internal IEnumerable<ProjectFile> ResolveWildcardItems ()
 
248
                {
 
249
                        foreach (var resolvedFilePath in ResolveWildcardFilePath ())
 
250
                        {
 
251
                                ProjectFile projectFile = (ProjectFile) this.Clone ();
 
252
                                projectFile.Name = resolvedFilePath;
 
253
                                projectFile.IsOriginatedFromWildcard = true;
 
254
                                yield return projectFile;
 
255
                        }
 
256
                }
 
257
 
142
258
                /// <summary>
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.
156
272
                        }
157
273
                }
158
274
 
 
275
 
159
276
                Project project;
160
277
                public Project Project {
161
278
                        get { return project; }