~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/prj2make-sharp-lib/SlnFileFormat.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// SlnFileFormat.cs
3
 
//
4
 
// Author:
5
 
//   Ankit Jain <jankit@novell.com>
6
 
//
7
 
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8
 
//
9
 
// Permission is hereby granted, free of charge, to any person obtaining
10
 
// a copy of this software and associated documentation files (the
11
 
// "Software"), to deal in the Software without restriction, including
12
 
// without limitation the rights to use, copy, modify, merge, publish,
13
 
// distribute, sublicense, and/or sell copies of the Software, and to
14
 
// permit persons to whom the Software is furnished to do so, subject to
15
 
// the following conditions:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
// 
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
//
28
 
 
29
 
using System;
30
 
using System.Collections;
31
 
using System.Collections.Generic;
32
 
using System.Collections.Specialized;
33
 
using System.Globalization;
34
 
using System.IO;
35
 
using System.Text;
36
 
using System.Text.RegularExpressions;
37
 
using System.Xml;
38
 
 
39
 
using MonoDevelop.Projects;
40
 
using MonoDevelop.Projects.Serialization;
41
 
using MonoDevelop.Core;
42
 
using MonoDevelop.Core.ProgressMonitoring;
43
 
using MonoDevelop.Ide.Gui;
44
 
 
45
 
namespace MonoDevelop.Prj2Make
46
 
{
47
 
        internal class SlnFileFormat
48
 
        {
49
 
                static string folderTypeGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}";
50
 
 
51
 
                static SlnFileFormat ()
52
 
                {
53
 
                        IdeApp.Initialized += delegate (object sender, EventArgs args) {
54
 
                                IdeApp.ProjectOperations.AddingEntryToCombine += new AddEntryEventHandler (HandleAddEntry);
55
 
                        };
56
 
                }
57
 
 
58
 
                public string GetValidFormatName (object obj, string fileName)
59
 
                {
60
 
                        return Path.ChangeExtension (fileName, ".sln");
61
 
                }
62
 
                
63
 
                public bool CanReadFile (string file)
64
 
                {
65
 
                        if (String.Compare (Path.GetExtension (file), ".sln", true) != 0)
66
 
                                return false;
67
 
                        string tmp;
68
 
                        string version = GetSlnFileVersion (file, out tmp);
69
 
                        return version == "9.00" || version == "10.00";
70
 
                }
71
 
                
72
 
                public bool CanWriteFile (object obj)
73
 
                {
74
 
                        return obj is Combine;
75
 
                }
76
 
                
77
 
                public System.Collections.Specialized.StringCollection GetExportFiles (object obj)
78
 
                {
79
 
                        Combine c = obj as Combine;
80
 
                        if (c != null && !c.IsRoot && c.ParentCombine.FileFormat is MSBuildFileFormat)
81
 
                                // Solution folder
82
 
                                return new System.Collections.Specialized.StringCollection ();
83
 
 
84
 
                        return null;
85
 
                }
86
 
                
87
 
                public void WriteFile (string file, object obj, IProgressMonitor monitor)
88
 
                {
89
 
                        Combine c = obj as Combine;
90
 
                        if (c == null)
91
 
                                return;
92
 
 
93
 
                        if (!c.IsRoot && c.ParentCombine.FileFormat is MSBuildFileFormat)
94
 
                                // Ignore a non-root combine if its parent is a msbuild solution
95
 
                                // Eg. if parent is a mds, then this should get emitted as the
96
 
                                // top level solution
97
 
                                return;
98
 
 
99
 
                        string tmpfilename = String.Empty;
100
 
                        try {
101
 
                                monitor.BeginTask (GettextCatalog.GetString ("Saving solution: {0}", file), 1);
102
 
                                try {
103
 
                                        if (File.Exists (file))
104
 
                                                tmpfilename = Path.GetTempFileName ();
105
 
                                } catch (IOException) {
106
 
                                }
107
 
 
108
 
                                if (tmpfilename == String.Empty) {
109
 
                                        WriteFileInternal (file, c, monitor);
110
 
                                } else {
111
 
                                        WriteFileInternal (tmpfilename, c, monitor);
112
 
                                        File.Delete (file);
113
 
                                        File.Move (tmpfilename, file);
114
 
                                }
115
 
                        } catch (Exception ex) {
116
 
                                monitor.ReportError (GettextCatalog.GetString ("Could not save solution: {0}", file), ex);
117
 
                                LoggingService.LogError (GettextCatalog.GetString ("Could not save solution: {0}", file), ex);
118
 
 
119
 
                                if (!String.IsNullOrEmpty (tmpfilename))
120
 
                                        File.Delete (tmpfilename);
121
 
                                throw;
122
 
                        } finally {
123
 
                                monitor.EndTask ();
124
 
                        }
125
 
                }
126
 
 
127
 
                void WriteFileInternal (string file, Combine c, IProgressMonitor monitor)
128
 
                {
129
 
                        using (StreamWriter sw = new StreamWriter (file, false, Encoding.UTF8)) {
130
 
                                sw.NewLine = "\r\n";
131
 
 
132
 
                                SlnData slnData = GetSlnData (c);
133
 
                                if (slnData == null) {
134
 
                                        // If a non-msbuild project is being converted by just
135
 
                                        // changing the fileformat, then create the SlnData for it
136
 
                                        slnData = new SlnData ();
137
 
                                        c.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
138
 
                                }
139
 
 
140
 
                                sw.WriteLine ();
141
 
                                //Write Header
142
 
                                sw.WriteLine ("Microsoft Visual Studio Solution File, Format Version " + slnData.VersionString);
143
 
                                sw.WriteLine (slnData.HeaderComment);
144
 
 
145
 
                                //Write the projects
146
 
                                monitor.BeginTask (GettextCatalog.GetString ("Saving projects"), 1);
147
 
                                WriteProjects (c, c.BaseDirectory, sw, monitor);
148
 
                                monitor.EndTask ();
149
 
 
150
 
                                //Write the lines for unknownProjects
151
 
                                foreach (string l in slnData.UnknownProjects)
152
 
                                        sw.WriteLine (l);
153
 
 
154
 
                                //Write the Globals
155
 
                                sw.WriteLine ("Global");
156
 
 
157
 
                                //Write SolutionConfigurationPlatforms
158
 
                                //FIXME: SolutionConfigurations?
159
 
                                sw.WriteLine ("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
160
 
 
161
 
                                foreach (CombineConfiguration config in c.Configurations)
162
 
                                        sw.WriteLine ("\t\t{0} = {0}", config.Name);
163
 
 
164
 
                                sw.WriteLine ("\tEndGlobalSection");
165
 
 
166
 
                                //Write ProjectConfigurationPlatforms
167
 
                                sw.WriteLine ("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
168
 
 
169
 
                                List<string> list = new List<string> ();
170
 
                                WriteProjectConfigurations (c, list, 0, null);
171
 
 
172
 
                                list.Sort (StringComparer.Create (CultureInfo.InvariantCulture, true));
173
 
                                foreach (string s in list)
174
 
                                        sw.WriteLine (s);
175
 
 
176
 
                                //Write lines for projects we couldn't load
177
 
                                if (slnData.SectionExtras.ContainsKey ("ProjectConfigurationPlatforms")) {
178
 
                                        foreach (string s in slnData.SectionExtras ["ProjectConfigurationPlatforms"])
179
 
                                                sw.WriteLine ("\t\t{0}", s);
180
 
                                }
181
 
 
182
 
                                sw.WriteLine ("\tEndGlobalSection");
183
 
 
184
 
                                //Write Nested Projects
185
 
                                sw.WriteLine ("\tGlobalSection(NestedProjects) = preSolution");
186
 
                                WriteNestedProjects (c, c, sw);
187
 
                                sw.WriteLine ("\tEndGlobalSection");
188
 
 
189
 
                                //Write 'others'
190
 
                                if (slnData.GlobalExtra != null) {
191
 
                                        foreach (string s in slnData.GlobalExtra)
192
 
                                                sw.WriteLine (s);
193
 
                                }
194
 
                                
195
 
                                sw.WriteLine ("EndGlobal");
196
 
                        }
197
 
                }
198
 
 
199
 
                void WriteProjects (Combine combine, string baseDirectory, StreamWriter writer, IProgressMonitor monitor)
200
 
                {
201
 
                        monitor.BeginStepTask (GettextCatalog.GetString ("Saving projects"), combine.Entries.Count, 1); 
202
 
                        foreach (CombineEntry ce in combine.Entries) {
203
 
                                Combine c = ce as Combine;
204
 
 
205
 
                                List<string> l = null;
206
 
                                if (c == null) {
207
 
                                        //Project
208
 
                                        DotNetProject project = ce as DotNetProject;
209
 
                                        if (project == null) {
210
 
                                                monitor.ReportWarning (GettextCatalog.GetString (
211
 
                                                        "Error saving project ({0}) : Only DotNetProjects can be part of a MSBuild solution. Ignoring.", ce.Name));
212
 
                                                monitor.Step (1);
213
 
                                                continue;
214
 
                                        }
215
 
 
216
 
                                        if (!MSBuildFileFormat.LanguageTypeGuids.ContainsKey (project.LanguageName)) {
217
 
                                                // FIXME: Should not happen, temp
218
 
                                                monitor.ReportWarning (GettextCatalog.GetString ("Saving for project {0} not supported. Ignoring.",
219
 
                                                        ce.FileName));
220
 
                                                monitor.Step (1);
221
 
                                                continue;
222
 
                                        }
223
 
 
224
 
                                        IFileFormat ff = project.FileFormat;
225
 
                                        if (! (ff is MSBuildFileFormat)) {
226
 
                                                // Convert to a msbuild file format
227
 
                                                project.FileFormat = new MSBuildFileFormat ();
228
 
                                                project.FileName = project.FileFormat.GetValidFormatName (project, project.FileName);
229
 
                                        }
230
 
 
231
 
                                        project.Save (monitor);
232
 
 
233
 
                                        MSBuildData msbData = Utils.GetMSBuildData (project);
234
 
                                        if (msbData == null)
235
 
                                                //This should not happen as project.Save would've added this
236
 
                                                throw new Exception (String.Format (
237
 
                                                        "INTERNAL ERROR: Project named '{0}', filename = {1}, does not have a 'data' object.", 
238
 
                                                        project.Name, project.FileName));
239
 
 
240
 
                                        l = msbData.Extra;
241
 
 
242
 
                                        writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""",
243
 
                                                MSBuildFileFormat.LanguageTypeGuids [project.LanguageName],
244
 
                                                project.Name, 
245
 
                                                FileService.NormalizeRelativePath (FileService.AbsoluteToRelativePath (
246
 
                                                        baseDirectory, project.FileName)).Replace ('/', '\\'),
247
 
                                                msbData.Guid);
248
 
                                } else {
249
 
                                        //Solution
250
 
                                        SlnData slnData = GetSlnData (c);
251
 
                                        if (slnData == null) {
252
 
                                                // Solution folder
253
 
                                                slnData = new SlnData ();
254
 
                                                c.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
255
 
                                                SlnData data = GetSlnData (combine);
256
 
                                                if (data != null) {
257
 
                                                        slnData.VersionString = data.VersionString;
258
 
                                                        slnData.HeaderComment = data.HeaderComment;
259
 
                                                }
260
 
                                        }
261
 
 
262
 
                                        l = slnData.Extra;
263
 
                                        
264
 
                                        writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""",
265
 
                                                folderTypeGuid,
266
 
                                                ce.Name, 
267
 
                                                ce.Name,
268
 
                                                slnData.Guid);
269
 
                                }
270
 
 
271
 
                                if (l != null) {
272
 
                                        foreach (string s in l)
273
 
                                                writer.WriteLine (s);
274
 
                                }
275
 
 
276
 
                                writer.WriteLine ("EndProject");
277
 
                                if (c != null)
278
 
                                        WriteProjects (c, baseDirectory, writer, monitor);
279
 
                                monitor.Step (1);
280
 
                        }
281
 
                        monitor.EndTask ();
282
 
                }
283
 
 
284
 
                void WriteProjectConfigurations (Combine c, List<string> list, int ind, string config)
285
 
                {
286
 
                        foreach (CombineConfiguration cc in c.Configurations) {
287
 
                                string rootConfigName = config ?? cc.Name;
288
 
                                if (cc.Name != rootConfigName)
289
 
                                        continue;
290
 
 
291
 
                                foreach (CombineConfigurationEntry cce in cc.Entries) {
292
 
                                        DotNetProject p = cce.Entry as DotNetProject;
293
 
                                        if (p == null) {
294
 
                                                Combine combine = cce.Entry as Combine;
295
 
                                                if (combine == null)
296
 
                                                        continue;
297
 
 
298
 
                                                //FIXME: Bug in md :/ Workaround, setting the config name explicitly
299
 
                                                //Solution folder's cce.ConfigurationName doesn't get set
300
 
                                                if (String.IsNullOrEmpty (cce.ConfigurationName)) {
301
 
                                                        if (combine.GetConfiguration (rootConfigName) != null)
302
 
                                                                cce.ConfigurationName = rootConfigName;
303
 
                                                }
304
 
 
305
 
                                                if (cce.ConfigurationName != rootConfigName) {
306
 
                                                        //Sln folder's config must match the root,
307
 
                                                        //so that its the same throughout the tree
308
 
                                                        //this ensures that _all_ the projects are
309
 
                                                        //relative to rootconfigname
310
 
                                                        //FIXME: Could be either:
311
 
                                                        //      1. Invalid setting
312
 
                                                        //      2. New imported project, which doesn't yet have
313
 
                                                        //         a config named rootConfigName
314
 
                                                        LoggingService.LogDebug ("Known Problem: Invalid setting. Ignoring.");
315
 
                                                        continue;
316
 
                                                }
317
 
 
318
 
                                                WriteProjectConfigurations (combine, list, ind + 1, cc.Name);
319
 
 
320
 
                                                continue;
321
 
                                        }
322
 
 
323
 
                                        /* Project */
324
 
 
325
 
                                        MSBuildData data = Utils.GetMSBuildData (p);
326
 
                                        list.Add (String.Format (
327
 
                                                "\t\t{0}.{1}.ActiveCfg = {2}", data.Guid, cc.Name, cce.ConfigurationName));
328
 
 
329
 
                                        if (cce.Build)
330
 
                                                list.Add (String.Format (
331
 
                                                        "\t\t{0}.{1}.Build.0 = {2}", data.Guid, cc.Name, cce.ConfigurationName));
332
 
                                }
333
 
                        }
334
 
                }
335
 
 
336
 
                void WriteNestedProjects (Combine combine, Combine root, StreamWriter writer)
337
 
                {
338
 
                        foreach (CombineEntry ce in combine.Entries) {
339
 
                                Combine c = ce as Combine;
340
 
                                if (c == null || c.ParentCombine == null)
341
 
                                        continue;
342
 
 
343
 
                                WriteNestedProjects (c, root, writer);
344
 
                        }
345
 
 
346
 
                        SlnData data = GetSlnData (combine);
347
 
                        if (data == null)
348
 
                                throw new Exception (String.Format (
349
 
                                        "INTERNAL ERROR: Solution named '{0}', filename = {1}, does not have a 'data' object.", 
350
 
                                        combine.Name, combine.FileName));
351
 
 
352
 
                        string containerGuid = data.Guid;
353
 
                        foreach (CombineEntry ce in combine.Entries) {
354
 
                                if (ce.ParentCombine == root)
355
 
                                        continue;
356
 
 
357
 
                                string containeeGuid = null;
358
 
                                if (ce is Combine) {
359
 
                                        SlnData slnData = GetSlnData (ce);
360
 
                                        containeeGuid = slnData.Guid;
361
 
                                } else {
362
 
                                        MSBuildData msbData = Utils.GetMSBuildData (ce);
363
 
                                        containeeGuid = msbData.Guid;
364
 
                                }
365
 
 
366
 
                                writer.WriteLine (@"{0}{1} = {2}", "\t\t", containeeGuid, containerGuid);
367
 
                        }
368
 
                }
369
 
 
370
 
                //Reader
371
 
                public object ReadFile (string fileName, IProgressMonitor monitor)
372
 
                {
373
 
                        Combine combine = null;
374
 
                        if (fileName == null || monitor == null)
375
 
                                return null;
376
 
 
377
 
                        try {
378
 
                                monitor.BeginTask (string.Format (GettextCatalog.GetString ("Loading solution: {0}"), fileName), 1);
379
 
                                combine = LoadSolution (fileName, monitor);
380
 
                                SetHandlers (combine, true);
381
 
                        } catch (Exception ex) {
382
 
                                monitor.ReportError (GettextCatalog.GetString ("Could not load solution: {0}", fileName), ex);
383
 
                                throw;
384
 
                        } finally {
385
 
                                monitor.EndTask ();
386
 
                        }
387
 
 
388
 
                        return combine;
389
 
                }
390
 
 
391
 
                //ExtendedProperties
392
 
                //      Per config
393
 
                //              Platform : Eg. Any CPU
394
 
                //              SolutionConfigurationPlatforms
395
 
                //
396
 
                Combine LoadSolution (string fileName, IProgressMonitor monitor)
397
 
                {
398
 
                        string headerComment;
399
 
                        string version = GetSlnFileVersion (fileName, out headerComment);
400
 
                        if (version != "9.00" && version != "10.00")
401
 
                                throw new UnknownProjectVersionException (fileName, version);
402
 
 
403
 
                        ListDictionary globals = null;
404
 
                        Combine combine = null;
405
 
                        SlnData data = null;
406
 
                        List<Section> projectSections = null;
407
 
                        List<string> lines = null;
408
 
 
409
 
                        monitor.BeginTask (GettextCatalog.GetString ("Loading solution: {0}", fileName), 1);
410
 
                        //Parse the .sln file
411
 
                        using (StreamReader reader = new StreamReader(fileName)) {
412
 
                                combine = new Combine ();
413
 
                                combine.Name = Path.GetFileNameWithoutExtension (fileName);
414
 
                                combine.FileName = fileName;
415
 
                                combine.Version = "0.1"; //FIXME:
416
 
                                combine.FileFormat = new MSBuildFileFormat ();
417
 
                                data = new SlnData ();
418
 
                                combine.ExtendedProperties [typeof (SlnFileFormat)] = data;
419
 
                                data.VersionString = version;
420
 
                                data.HeaderComment = headerComment;
421
 
 
422
 
                                string s = null;
423
 
                                projectSections = new List<Section> ();
424
 
                                lines = new List<string> ();
425
 
                                globals = new ListDictionary ();
426
 
                                //Parse
427
 
                                while (reader.Peek () >= 0) {
428
 
                                        s = GetNextLine (reader, lines).Trim ();
429
 
 
430
 
                                        if (String.Compare (s, "Global", true) == 0) {
431
 
                                                ParseGlobal (reader, lines, globals);
432
 
                                                continue;
433
 
                                        }
434
 
 
435
 
                                        if (s.StartsWith ("Project")) {
436
 
                                                Section sec = new Section ();
437
 
                                                projectSections.Add (sec);
438
 
 
439
 
                                                sec.Start = lines.Count - 1;
440
 
 
441
 
                                                int e = ReadUntil ("EndProject", reader, lines);
442
 
                                                sec.Count = (e < 0) ? 1 : (e - sec.Start + 1);
443
 
 
444
 
                                                continue;
445
 
                                        }
446
 
                                }
447
 
                        }
448
 
 
449
 
                        monitor.BeginTask("Loading projects ..", projectSections.Count + 1);
450
 
                        Dictionary<string, CombineEntry> entries = new Dictionary<string, CombineEntry> ();
451
 
                        foreach (Section sec in projectSections) {
452
 
                                monitor.Step (1);
453
 
                                Match match = ProjectRegex.Match (lines [sec.Start]);
454
 
                                if (!match.Success) {
455
 
                                        LoggingService.LogDebug (GettextCatalog.GetString (
456
 
                                                "Invalid Project definition on line number #{0} in file '{1}'. Ignoring.",
457
 
                                                sec.Start + 1,
458
 
                                                fileName));
459
 
 
460
 
                                        continue;
461
 
                                }
462
 
 
463
 
                                try {
464
 
                                        // Valid guid?
465
 
                                        new Guid (match.Groups [1].Value);
466
 
                                } catch (FormatException) {
467
 
                                        //Use default guid as projectGuid
468
 
                                        LoggingService.LogDebug (GettextCatalog.GetString (
469
 
                                                "Invalid Project type guid '{0}' on line #{1}. Ignoring.",
470
 
                                                match.Groups [1].Value,
471
 
                                                sec.Start + 1));
472
 
                                        continue;
473
 
                                }
474
 
 
475
 
                                string projTypeGuid = match.Groups [1].Value.ToUpper ();
476
 
                                string projectName = match.Groups [2].Value;
477
 
                                string projectPath = match.Groups [3].Value;
478
 
                                string projectGuid = match.Groups [4].Value;
479
 
 
480
 
                                if (projTypeGuid == folderTypeGuid) {
481
 
                                        //Solution folder
482
 
                                        SolutionFolder folder = new SolutionFolder ();
483
 
                                        folder.Name = projectName;
484
 
                                        folder.FileName = projectPath;
485
 
                                        folder.Version = "0.1"; //FIXME:
486
 
                                        folder.FileFormat = new MSBuildFileFormat ();
487
 
 
488
 
                                        SlnData slnData = new SlnData (projectGuid);
489
 
                                        folder.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
490
 
                                        slnData.VersionString = data.VersionString;
491
 
                                        slnData.HeaderComment = data.HeaderComment;
492
 
 
493
 
                                        slnData.Extra = lines.GetRange (sec.Start + 1, sec.Count - 2);
494
 
 
495
 
                                        entries [projectGuid] = folder;
496
 
                                        
497
 
                                        continue;
498
 
                                }
499
 
 
500
 
                                if (!MSBuildFileFormat.LanguageTypeGuids.ContainsValue (projTypeGuid)) {
501
 
                                        LoggingService.LogWarning (GettextCatalog.GetString (
502
 
                                                "Unknown project type guid '{0}' on line #{1}. Ignoring.",
503
 
                                                projTypeGuid,
504
 
                                                sec.Start + 1));
505
 
                                        monitor.ReportWarning (GettextCatalog.GetString (
506
 
                                                "{0}({1}): Unsupported or unrecognized project : '{2}'. See logs.", 
507
 
                                                fileName, sec.Start + 1, projectPath));
508
 
                                        continue;
509
 
                                }
510
 
 
511
 
                                if (projectPath.StartsWith("http://")) {
512
 
                                        monitor.ReportWarning (GettextCatalog.GetString (
513
 
                                                "{0}({1}): Projects with non-local source (http://...) not supported. '{2}'.",
514
 
                                                fileName, sec.Start + 1, projectPath));
515
 
                                        data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
516
 
                                        continue;
517
 
                                }
518
 
 
519
 
                                DotNetProject project = null;
520
 
                                string path = SlnMaker.MapPath (Path.GetDirectoryName (fileName), projectPath);
521
 
                                if (String.IsNullOrEmpty (path)) {
522
 
                                        monitor.ReportWarning (GettextCatalog.GetString (
523
 
                                                "Invalid project path found in {0} : {1}", fileName, projectPath));
524
 
                                        LoggingService.LogWarning (GettextCatalog.GetString (
525
 
                                                "Invalid project path found in {0} : {1}", fileName, projectPath));
526
 
 
527
 
                                        continue;
528
 
                                }
529
 
 
530
 
                                projectPath = Path.GetFullPath (path);
531
 
                                try {
532
 
                                        project = Services.ProjectService.ReadCombineEntry (projectPath, monitor) as DotNetProject;
533
 
                                        if (project == null) {
534
 
                                                LoggingService.LogError ("Internal Error: Didn't get the expected DotNetProject for {0} project.",
535
 
                                                        projectPath);
536
 
                                                continue;
537
 
                                        }
538
 
 
539
 
                                        MSBuildData msdata = Utils.GetMSBuildData (project);
540
 
                                        entries [projectGuid] = project;
541
 
                                        data.ProjectsByGuid [msdata.Guid] = project;
542
 
 
543
 
                                        msdata.Extra = lines.GetRange (sec.Start + 1, sec.Count - 2);
544
 
                                } catch (Exception e) {
545
 
                                        LoggingService.LogError (GettextCatalog.GetString (
546
 
                                                                "Error while trying to load the project {0}. Exception : {1}",
547
 
                                                                projectPath, e.ToString ()));
548
 
                                        monitor.ReportWarning (GettextCatalog.GetString (
549
 
                                                "Error while trying to load the project {0}. Exception : {1}", projectPath, e.Message));
550
 
 
551
 
                                        if (project == null)
552
 
                                                data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
553
 
                                }
554
 
                        }
555
 
                        monitor.EndTask ();
556
 
 
557
 
                        if (globals != null && globals.Contains ("NestedProjects")) {
558
 
                                LoadNestedProjects (globals ["NestedProjects"] as Section, lines, entries, monitor);
559
 
                                globals.Remove ("NestedProjects");
560
 
                        }
561
 
 
562
 
                        //Add top level folders and projects to the main combine
563
 
                        foreach (CombineEntry ce in entries.Values) {
564
 
                                if (ce.ParentCombine == null)
565
 
                                        combine.Entries.Add (ce);
566
 
                        }
567
 
 
568
 
                        //Resolve project references
569
 
                        List<ProjectReference> toRemove = new List<ProjectReference> ();
570
 
                        List<ProjectReference> toAdd = new List<ProjectReference> ();
571
 
                        foreach (Project p in combine.GetAllProjects ()) {
572
 
                                toRemove.Clear ();
573
 
                                toAdd.Clear ();
574
 
                                MSBuildData msbuildData = Utils.GetMSBuildData (p);
575
 
                                if (msbuildData == null)
576
 
                                        continue;
577
 
 
578
 
                                foreach (ProjectReference pref in p.ProjectReferences) {
579
 
                                        if (pref.ReferenceType != ReferenceType.Project)
580
 
                                                continue;
581
 
 
582
 
                                        Project rp = combine.FindProject (pref.Reference);
583
 
                                        if (rp != null)
584
 
                                                continue;
585
 
 
586
 
                                        //Unresolved
587
 
                                        XmlElement elem = msbuildData.ProjectReferenceElements [pref];
588
 
                                        if (elem == null)
589
 
                                                //Should not happen
590
 
                                                continue;
591
 
 
592
 
                                        if (elem ["Project"] == null)
593
 
                                                continue;
594
 
 
595
 
                                        string guid = elem ["Project"].InnerText.Trim ();
596
 
                                        if (!data.ProjectsByGuid.ContainsKey (guid))
597
 
                                                continue;
598
 
 
599
 
                                        toRemove.Add (pref);
600
 
                                        rp = data.ProjectsByGuid [guid];
601
 
                                        ProjectReference newRef = new ProjectReference (ReferenceType.Project, rp.Name);
602
 
                                        toAdd.Add (newRef);
603
 
 
604
 
                                        XmlElement clonedElement = (XmlElement) elem.Clone ();
605
 
                                        elem.ParentNode.InsertAfter (clonedElement, elem);
606
 
                                        msbuildData.ProjectReferenceElements [newRef] = clonedElement;
607
 
                                }
608
 
 
609
 
                                foreach (ProjectReference pref in toRemove) {
610
 
                                        p.ProjectReferences.Remove (pref);
611
 
                                        msbuildData.ProjectReferenceElements.Remove (pref);
612
 
                                }
613
 
 
614
 
                                foreach (ProjectReference pref in toAdd)
615
 
                                        p.ProjectReferences.Add (pref);
616
 
                        }
617
 
 
618
 
                        //FIXME: This can be just SolutionConfiguration also!
619
 
                        if (globals != null) {
620
 
                                if (globals.Contains ("SolutionConfigurationPlatforms")) {
621
 
                                        LoadSolutionConfigurations (globals ["SolutionConfigurationPlatforms"] as Section, lines,
622
 
                                                combine, monitor);
623
 
                                        globals.Remove ("SolutionConfigurationPlatforms");
624
 
                                }
625
 
 
626
 
                                if (globals.Contains ("ProjectConfigurationPlatforms")) {
627
 
                                        LoadProjectConfigurationMappings (globals ["ProjectConfigurationPlatforms"] as Section, lines,
628
 
                                                combine, monitor);
629
 
                                        globals.Remove ("ProjectConfigurationPlatforms");
630
 
                                }
631
 
                        }
632
 
 
633
 
                        //Save the global sections that we dont use
634
 
                        List<string> globalLines = new List<string> ();
635
 
                        foreach (Section sec in globals.Values)
636
 
                                globalLines.InsertRange (globalLines.Count, lines.GetRange (sec.Start, sec.Count));
637
 
 
638
 
                        data.GlobalExtra = globalLines;
639
 
                        monitor.EndTask ();
640
 
                        return combine;
641
 
                }
642
 
 
643
 
                void ParseGlobal (StreamReader reader, List<string> lines, ListDictionary dict)
644
 
                {
645
 
                        //Process GlobalSection-s
646
 
                        while (reader.Peek () >= 0) {
647
 
                                string s = GetNextLine (reader, lines).Trim ();
648
 
                                if (s.Length == 0)
649
 
                                        //Skip blank lines
650
 
                                        continue;
651
 
 
652
 
                                Match m = GlobalSectionRegex.Match (s);
653
 
                                if (!m.Success) {
654
 
                                        if (String.Compare (s, "EndGlobal", true) == 0)
655
 
                                                return;
656
 
 
657
 
                                        continue;
658
 
                                }
659
 
 
660
 
                                Section sec = new Section (m.Groups [1].Value, m.Groups [2].Value, lines.Count - 1, 1);
661
 
                                dict [sec.Key] = sec;
662
 
 
663
 
                                sec.Count = ReadUntil ("EndGlobalSection", reader, lines) - sec.Start + 1;
664
 
                                //FIXME: sec.Count == -1 : No EndGlobalSection found, ignore entry?
665
 
                        }
666
 
                }
667
 
 
668
 
                void LoadProjectConfigurationMappings (Section sec, List<string> lines, Combine sln, IProgressMonitor monitor)
669
 
                {
670
 
                        if (sec == null || String.Compare (sec.Val, "postSolution", true) != 0)
671
 
                                return;
672
 
 
673
 
                        List<CombineConfigurationEntry> noBuildList = new List<CombineConfigurationEntry> ();
674
 
                        Dictionary<string, CombineConfigurationEntry> cache = new Dictionary<string, CombineConfigurationEntry> ();
675
 
                        Dictionary<string, string> ignoredProjects = new Dictionary<string, string> ();
676
 
                        SlnData slnData = GetSlnData (sln);
677
 
                        
678
 
                        List<string> extras = new List<string> ();
679
 
 
680
 
                        for (int i = 0; i < sec.Count - 2; i ++) {
681
 
                                int lineNum = i + sec.Start + 1;
682
 
                                string s = lines [lineNum].Trim ();
683
 
                                extras.Add (s);
684
 
                                
685
 
                                //Format:
686
 
                                // {projectGuid}.SolutionConfigName|SolutionPlatform.ActiveCfg = ProjConfigName|ProjPlatform
687
 
                                // {projectGuid}.SolutionConfigName|SolutionPlatform.Build.0 = ProjConfigName|ProjPlatform
688
 
 
689
 
                                string [] parts = s.Split (new char [] {'='}, 2);
690
 
                                if (parts.Length < 2) {
691
 
                                        LoggingService.LogDebug ("{0} ({1}) : Invalid format. Ignoring", sln.FileName, lineNum + 1);
692
 
                                        continue;
693
 
                                }
694
 
 
695
 
                                string action;
696
 
                                string projConfig = parts [1].Trim ();
697
 
 
698
 
                                string left = parts [0].Trim ();
699
 
                                if (left.EndsWith (".ActiveCfg")) {
700
 
                                        action = "ActiveCfg";
701
 
                                        left = left.Substring (0, left.Length - 10);
702
 
                                } else if (left.EndsWith (".Build.0")) {
703
 
                                        action = "Build.0";
704
 
                                        left = left.Substring (0, left.Length - 8);
705
 
                                } else { 
706
 
                                        LoggingService.LogWarning (GettextCatalog.GetString ("{0} ({1}) : Unknown action. Only ActiveCfg & Build.0 supported.",
707
 
                                                sln.FileName, lineNum + 1));
708
 
                                        continue;
709
 
                                }
710
 
 
711
 
                                string [] t = left.Split (new char [] {'.'}, 2);
712
 
                                if (t.Length < 2) {
713
 
                                        LoggingService.LogDebug ("{0} ({1}) : Invalid format of the left side. Ignoring",
714
 
                                                sln.FileName, lineNum + 1);
715
 
                                        continue;
716
 
                                }
717
 
 
718
 
                                string projGuid = t [0];
719
 
                                string slnConfig = t [1];
720
 
 
721
 
                                if (!slnData.ProjectsByGuid.ContainsKey (projGuid)) {
722
 
                                        if (ignoredProjects.ContainsKey (projGuid))
723
 
                                                // already warned
724
 
                                                continue;
725
 
 
726
 
                                        LoggingService.LogWarning (GettextCatalog.GetString ("{0} ({1}) : Project with guid = '{2}' not found or not loaded. Ignoring", 
727
 
                                                sln.FileName, lineNum + 1, projGuid));
728
 
                                        ignoredProjects [projGuid] = projGuid;
729
 
                                        continue;
730
 
                                }
731
 
 
732
 
                                DotNetProject project = slnData.ProjectsByGuid [projGuid];
733
 
 
734
 
                                string key = projGuid + "." + slnConfig;
735
 
                                CombineConfigurationEntry combineConfigEntry = null;
736
 
                                if (cache.ContainsKey (key)) {
737
 
                                        combineConfigEntry = cache [key];
738
 
                                } else {
739
 
                                        combineConfigEntry = GetConfigEntryForProject (sln, slnConfig, project);
740
 
                                        cache [key] = combineConfigEntry;
741
 
                                }
742
 
 
743
 
                                /* If both ActiveCfg & Build.0 entries are missing
744
 
                                 * for a project, then default values :
745
 
                                 *      ActiveCfg : same as the solution config
746
 
                                 *      Build : true
747
 
                                 *
748
 
                                 * ELSE
749
 
                                 * if Build (true/false) for the project will 
750
 
                                 * will depend on presence/absence of Build.0 entry
751
 
                                 */
752
 
                                if (String.Compare (action, "ActiveCfg", false) == 0) {
753
 
                                        combineConfigEntry.ConfigurationName = projConfig;
754
 
                                        noBuildList.Add (combineConfigEntry);
755
 
                                } else if (String.Compare (action, "Build.0", false) == 0) {
756
 
                                        noBuildList.Remove (combineConfigEntry);
757
 
                                }
758
 
 
759
 
                                extras.RemoveAt (extras.Count - 1);
760
 
                        }
761
 
 
762
 
                        slnData.SectionExtras ["ProjectConfigurationPlatforms"] = extras;
763
 
 
764
 
                        foreach (CombineConfigurationEntry e in noBuildList) {
765
 
                                //Mark (build=false) of all projects for which 
766
 
                                //ActiveCfg was found but no Build.0
767
 
                                e.Build = false;
768
 
                        }
769
 
                }
770
 
 
771
 
                /* Finds a CombineConfigurationEntry corresponding to the @configName for a project (@projectName) 
772
 
                 * in @combine */
773
 
                CombineConfigurationEntry GetConfigEntryForProject (Combine combine, string configName, Project project)
774
 
                {
775
 
                        if (project.ParentCombine == null)
776
 
                                throw new Exception (String.Format (
777
 
                                        "INTERNAL ERROR: project {0} is not part of any combine", project.Name));
778
 
 
779
 
                        CombineConfigurationEntry ret = GetConfigEntry (project, configName);
780
 
 
781
 
                        //Ensure the corresponding entries exist all the way
782
 
                        //upto the RootCombine
783
 
                        Combine parent = project.ParentCombine;
784
 
                        while (!parent.IsRoot && parent.ParentCombine != null) {
785
 
                                CombineConfigurationEntry p = GetConfigEntry (parent, configName);
786
 
                                if (p.ConfigurationName != configName)
787
 
                                        p.ConfigurationName = configName;
788
 
                                parent = parent.ParentCombine;
789
 
                        }
790
 
 
791
 
                        return ret;
792
 
                }
793
 
 
794
 
                /* Gets the CombineConfigurationEntry corresponding to the @entry in its parentCombine's 
795
 
                 * CombineConfiguration. Creates the required bits if not present */
796
 
                CombineConfigurationEntry GetConfigEntry (CombineEntry entry, string configName)
797
 
                {
798
 
                        Combine parent = entry.ParentCombine;
799
 
                        CombineConfiguration combineConfig = parent.GetConfiguration (configName) as CombineConfiguration;
800
 
                        if (combineConfig == null) {
801
 
                                combineConfig = (CombineConfiguration) parent.CreateConfiguration (configName);
802
 
                                parent.Configurations.Add (combineConfig);
803
 
                        }
804
 
 
805
 
                        foreach (CombineConfigurationEntry cce in combineConfig.Entries) {
806
 
                                if (cce.Entry == entry)
807
 
                                        return cce;
808
 
                        }
809
 
 
810
 
                        return combineConfig.AddEntry (entry);
811
 
                }
812
 
 
813
 
                void LoadSolutionConfigurations (Section sec, List<string> lines, Combine combine, IProgressMonitor monitor)
814
 
                {
815
 
                        if (sec == null || String.Compare (sec.Val, "preSolution", true) != 0)
816
 
                                return;
817
 
 
818
 
                        for (int i = 0; i < sec.Count - 2; i ++) {
819
 
                                //FIXME: expects both key and val to be on the same line
820
 
                                int lineNum = i + sec.Start + 1;
821
 
                                string s = lines [lineNum].Trim ();
822
 
                                if (s.Length == 0)
823
 
                                        //Skip blank lines
824
 
                                        continue;
825
 
 
826
 
                                KeyValuePair<string, string> pair = SplitKeyValue (s);
827
 
 
828
 
                                if (pair.Key.IndexOf ('|') < 0) {
829
 
                                        //Config must of the form ConfigName|Platform
830
 
                                        LoggingService.LogError (GettextCatalog.GetString ("{0} ({1}) : Invalid config name '{2}'", combine.FileName, lineNum + 1, pair.Key));
831
 
                                        continue;
832
 
                                }
833
 
                                
834
 
                                CombineConfiguration config = (CombineConfiguration) 
835
 
                                        combine.GetConfiguration (pair.Key);
836
 
                                
837
 
                                if (config == null) {
838
 
                                        config = (CombineConfiguration) 
839
 
                                                combine.CreateConfiguration (pair.Key);
840
 
                                        combine.Configurations.Add (config);
841
 
                                }
842
 
                        }
843
 
                }
844
 
 
845
 
                void LoadNestedProjects (Section sec, List<string> lines,
846
 
                        Dictionary<string, CombineEntry> entries, IProgressMonitor monitor)
847
 
                {
848
 
                        if (sec == null || String.Compare (sec.Val, "preSolution", true) != 0)
849
 
                                return;
850
 
 
851
 
                        for (int i = 0; i < sec.Count - 2; i ++) {
852
 
                                KeyValuePair<string, string> pair = SplitKeyValue (lines [i + sec.Start + 1].Trim ());
853
 
 
854
 
                                if (!entries.ContainsKey (pair.Value)) {
855
 
                                        //Container not found
856
 
                                        LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Value));
857
 
                                        continue;
858
 
                                }
859
 
 
860
 
                                if (!entries.ContainsKey (pair.Key)) {
861
 
                                        //Containee not found
862
 
                                        LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Key));
863
 
                                        continue;
864
 
                                }
865
 
 
866
 
                                Combine folder = entries [pair.Value] as Combine;
867
 
                                if (folder == null)
868
 
                                        continue;
869
 
 
870
 
                                folder.Entries.Add (entries [pair.Key]);
871
 
                        }
872
 
                }
873
 
 
874
 
                string GetNextLine (StreamReader reader, List<string> list)
875
 
                {
876
 
                        if (reader.Peek () < 0)
877
 
                                return null;
878
 
 
879
 
                        string ret = reader.ReadLine ();
880
 
                        list.Add (ret);
881
 
                        return ret;
882
 
                }
883
 
 
884
 
                int ReadUntil (string end, StreamReader reader, List<string> lines)
885
 
                {
886
 
                        int ret = -1;
887
 
                        while (reader.Peek () >= 0) {
888
 
                                string s = GetNextLine (reader, lines);
889
 
 
890
 
                                if (String.Compare (s.Trim (), end, true) == 0)
891
 
                                        return (lines.Count - 1);
892
 
                        }
893
 
 
894
 
                        return ret;
895
 
                }
896
 
 
897
 
 
898
 
                KeyValuePair<string, string> SplitKeyValue (string s)
899
 
                {
900
 
                        string [] pair = s.Split (new char [] {'='}, 2);
901
 
                        string key = pair [0].Trim ();
902
 
                        string val = String.Empty;
903
 
                        if (pair.Length == 2)
904
 
                                val = pair [1].Trim ();
905
 
 
906
 
                        return new KeyValuePair<string, string> (key, val);
907
 
                }
908
 
 
909
 
                // Utility function to determine the sln file version
910
 
                string GetSlnFileVersion(string strInSlnFile, out string headerComment)
911
 
                {
912
 
                        string strVersion = null;
913
 
                        string strInput = null;
914
 
                        headerComment = null;
915
 
                        Match match;
916
 
                        StreamReader reader = new StreamReader(strInSlnFile);
917
 
                        
918
 
                        strInput = reader.ReadLine();
919
 
                        if (strInput == null)
920
 
                                return null;
921
 
 
922
 
                        match = SlnVersionRegex.Match(strInput);
923
 
                        if (!match.Success) {
924
 
                                strInput = reader.ReadLine();
925
 
                                if (strInput == null)
926
 
                                        return null;
927
 
                                match = SlnVersionRegex.Match (strInput);
928
 
                        }
929
 
 
930
 
                        if (match.Success)
931
 
                        {
932
 
                                strVersion = match.Groups[1].Value;
933
 
                                headerComment = reader.ReadLine ();
934
 
                        }
935
 
                        
936
 
                        // Close the stream
937
 
                        reader.Close();
938
 
 
939
 
                        return strVersion;
940
 
                }
941
 
 
942
 
                static SlnData GetSlnData (CombineEntry entry)
943
 
                {
944
 
                        if (entry.ExtendedProperties.Contains (typeof (SlnFileFormat)))
945
 
                                return entry.ExtendedProperties [typeof (SlnFileFormat)] as SlnData;
946
 
                        return null;
947
 
                }
948
 
 
949
 
                // Event handlers
950
 
                public static void HandleAddEntry (object s, AddEntryEventArgs args)
951
 
                {
952
 
                        if (GetSlnData (args.Combine) == null)
953
 
                                return;
954
 
 
955
 
                        IFileFormat msformat = new MSBuildFileFormat ();
956
 
 
957
 
                        if (!msformat.CanReadFile (args.FileName)) {
958
 
                                if (!IdeApp.Services.MessageService.AskQuestion (GettextCatalog.GetString (
959
 
                                        "The project file {0} must be converted to msbuild format to be added " +
960
 
                                        "to a msbuild solution. Convert?", args.FileName), "Conversion required")) {
961
 
                                        args.Cancel = true;
962
 
                                        return;
963
 
                                }
964
 
                        } else {
965
 
                                // vs2005 solution/project
966
 
                                return;
967
 
                        }
968
 
 
969
 
                        IProgressMonitor monitor = new NullProgressMonitor ();
970
 
                        IFileFormat slnff = new VS2003SlnFileFormat ();
971
 
                        IFileFormat prjff = new VS2003ProjectFileFormat ();
972
 
 
973
 
                        if (slnff.CanReadFile (args.FileName)) {
974
 
                                // VS2003 solution
975
 
                                Combine c = VS2003SlnFileFormat.ImportSlnAsMSBuild (args.FileName);
976
 
                                c.Save (monitor);
977
 
 
978
 
                                args.FileName = c.FileName;
979
 
                        } else if (prjff.CanReadFile (args.FileName)) {
980
 
                                // VS2003 project
981
 
 
982
 
                                DotNetProject proj = VS2003ProjectFileFormat.ImportCsprojAsMSBuild (args.FileName);
983
 
                                args.FileName = proj.FileName;
984
 
                        } else {
985
 
                                CombineEntry ce = Services.ProjectService.ReadCombineEntry (args.FileName, monitor);
986
 
                                ConvertToMSBuild (ce);
987
 
                                args.FileName = ce.FileName;
988
 
                                ce.Save (monitor);
989
 
                        }
990
 
                }
991
 
 
992
 
                internal static void SetHandlers (Combine combine, bool setEntries)
993
 
                {
994
 
                        if (setEntries) {
995
 
                                foreach (CombineEntry ce in combine.Entries) {
996
 
                                        Combine c = ce as Combine;
997
 
                                        if (c == null)
998
 
                                                continue;
999
 
 
1000
 
                                        SetHandlers (c, setEntries);
1001
 
                                }
1002
 
                        }
1003
 
 
1004
 
                        combine.EntryAdded += HandleCombineEntryAdded;
1005
 
                }
1006
 
 
1007
 
                static void HandleCombineEntryAdded (object sender, CombineEntryEventArgs e)
1008
 
                {
1009
 
                        try {
1010
 
                                // ReadFile for Sln/MSBuildFileFormat set the handlers
1011
 
                                ConvertToMSBuild (e.CombineEntry);
1012
 
 
1013
 
                                Combine rootSln = e.CombineEntry.RootCombine;
1014
 
                                SlnData rootSlnData = GetSlnData (rootSln);
1015
 
                                SlnData slnData = GetSlnData (e.CombineEntry);
1016
 
                                if (slnData != null) {
1017
 
                                        foreach (KeyValuePair<string, DotNetProject> pair in slnData.ProjectsByGuid)
1018
 
                                                rootSlnData.ProjectsByGuid [pair.Key] = pair.Value;
1019
 
                                } else {
1020
 
                                        //Add guid for the new project
1021
 
                                        MSBuildData msdata = Utils.GetMSBuildData (e.CombineEntry);
1022
 
                                        DotNetProject project = e.CombineEntry as DotNetProject;
1023
 
                                        if (project != null && msdata != null)
1024
 
                                                //msbuild project
1025
 
                                                rootSlnData.ProjectsByGuid [msdata.Guid] = project;
1026
 
                                }
1027
 
 
1028
 
                                //FIXME: Can't call this now as we don't extend Combine :/
1029
 
                                //rootSln.NotifyModified ();
1030
 
                                //Need some other solution, for now, hack -
1031
 
                                rootSln.FileName = rootSln.FileName;
1032
 
                        } catch (Exception ex) {
1033
 
                                LoggingService.LogDebug ("HandleCombineEntryAdded : {0}", ex);
1034
 
                        }
1035
 
                }
1036
 
 
1037
 
                internal static void ConvertToMSBuild (CombineEntry ce)
1038
 
                {
1039
 
                        MSBuildFileFormat msformat = new MSBuildFileFormat ();
1040
 
                        if (!msformat.CanReadFile (ce.FileName)) {
1041
 
                                // Convert
1042
 
                                ce.FileFormat = msformat;
1043
 
                                ce.FileName = msformat.GetValidFormatName (ce, ce.FileName);
1044
 
 
1045
 
                                // Save will create the required SlnData, MSBuildData
1046
 
                                // objects, create the new guids for the projects _and_ the
1047
 
                                // solution folders
1048
 
                                ce.Save (new NullProgressMonitor ());
1049
 
                                // Writing out again might be required to fix
1050
 
                                // project references which have changed (filenames
1051
 
                                // changed due to the conversion)
1052
 
                        }
1053
 
                }
1054
 
 
1055
 
                // static regexes
1056
 
                static Regex projectRegex = null;
1057
 
                internal static Regex ProjectRegex {
1058
 
                        get {
1059
 
                                if (projectRegex == null)
1060
 
                                        projectRegex = new Regex(@"Project\(""(\{[^}]*\})""\) = ""(.*)"", ""(.*)"", ""(\{[^{]*\})""");
1061
 
                                return projectRegex;
1062
 
                        }
1063
 
                }
1064
 
 
1065
 
                static Regex globalSectionRegex = null;
1066
 
                static Regex GlobalSectionRegex {
1067
 
                        get {
1068
 
                                if (globalSectionRegex == null)
1069
 
                                        globalSectionRegex = new Regex (@"GlobalSection\s*\(([^)]*)\)\s*=\s*(\w*)"); 
1070
 
                                return globalSectionRegex;
1071
 
                        }
1072
 
                }
1073
 
 
1074
 
                static Regex slnVersionRegex = null;
1075
 
                internal static Regex SlnVersionRegex {
1076
 
                        get {
1077
 
                                if (slnVersionRegex == null)
1078
 
                                        slnVersionRegex = new Regex (@"Microsoft Visual Studio Solution File, Format Version (\d?\d.\d\d)");
1079
 
                                return slnVersionRegex;
1080
 
                        }
1081
 
                }
1082
 
 
1083
 
        }
1084
 
 
1085
 
        class Section {
1086
 
                public string Key;
1087
 
                public string Val;
1088
 
 
1089
 
                public int Start = -1; //Line number
1090
 
                public int Count = 0;
1091
 
 
1092
 
                public Section ()
1093
 
                {
1094
 
                }
1095
 
 
1096
 
                public Section (string Key, string Val, int Start, int Count)
1097
 
                {
1098
 
                        this.Key = Key;
1099
 
                        this.Val = Val;
1100
 
                        this.Start = Start;
1101
 
                        this.Count = Count;
1102
 
                }
1103
 
        }
1104
 
 
1105
 
        class SolutionFolder : Combine {
1106
 
                public override bool NeedsReload {
1107
 
                        get { return false; }
1108
 
                }
1109
 
        }
1110
 
 
1111
 
}