Author: ankit
Date: 2006-11-29 07:35:10 -0500 (Wed, 29 Nov 2006)
New Revision: 68662

Modified:
   trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
   trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
   trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
Log:
* SlnFileFormat.cs: Add basic write/save support.
* MSBuildFileFormat.cs (WriteFile): OutputPath should be relative.
(ParseProject): Rename to ..
(LoadProject): .. this. Set default name of the project.
Create new config only if it doesn't already exist.     
(HandleRename): Change the name of the project file when the project is
renamed.


Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog       2006-11-29 
12:30:13 UTC (rev 68661)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog       2006-11-29 
12:35:10 UTC (rev 68662)
@@ -1,3 +1,13 @@
+2006-11-29  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * SlnFileFormat.cs: Add basic write/save support.
+       * MSBuildFileFormat.cs (WriteFile): OutputPath should be relative.
+       (ParseProject): Rename to ..
+       (LoadProject): .. this. Set default name of the project.
+       Create new config only if it doesn't already exist.     
+       (HandleRename): Change the name of the project file when the project is
+       renamed.
+
 2006-11-20  Ankit Jain  <[EMAIL PROTECTED]>
 
        * MsPrjHelper.cs (MapPath): Make "internal static". Change "\" to "/" 
only

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs    
2006-11-29 12:30:13 UTC (rev 68661)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs    
2006-11-29 12:35:10 UTC (rev 68662)
@@ -154,7 +154,8 @@
 
                                EnsureChildValue (configNode, "OutputType", ns, 
config.CompileTarget);
                                EnsureChildValue (configNode, "AssemblyName", 
ns, config.OutputAssembly);
-                               EnsureChildValue (configNode, "OutputPath", ns, 
config.OutputDirectory);
+                               EnsureChildValue (configNode, "OutputPath", ns, 
+                                       
Runtime.FileUtilityService.AbsoluteToRelativePath (project.BaseDirectory, 
config.OutputDirectory));
                                EnsureChildValue (configNode, "DebugSymbols", 
ns, config.DebugMode);
 
                                if (project.LanguageName == "VBNet") {
@@ -215,10 +216,10 @@
                                return null;
 
                        try {
-                               monitor.BeginTask (string.Format 
(GettextCatalog.GetString ("Loading project: {0}"), fileName), 1);
-                               project = ParseProject (fileName, monitor);
+                               monitor.BeginTask (GettextCatalog.GetString 
("Loading project: {0}", fileName), 1);
+                               project = LoadProject (fileName, monitor);
                        } catch (Exception ex) {
-                               monitor.ReportError (string.Format 
(GettextCatalog.GetString ("Could not load project: {0}"), fileName), ex);
+                               monitor.ReportError (GettextCatalog.GetString 
("Could not load project: {0}", fileName), ex);
                                throw;
                        } finally {
                                monitor.EndTask ();
@@ -228,7 +229,7 @@
                }
 
                //FIXME: Use monitor to report warnings/errors
-               DotNetProject ParseProject (string fname, IProgressMonitor 
monitor)
+               DotNetProject LoadProject (string fname, IProgressMonitor 
monitor)
                {
                        FileStream fs = new FileStream (fname, FileMode.Open, 
FileAccess.Read);
                        XmlDocument doc = new XmlDocument ();
@@ -249,6 +250,8 @@
                        //Create the project
                        DotNetProject project = new DotNetProject (lang);
                        project.FileName = fname;
+                       //Default project name
+                       project.Name = Path.GetFileNameWithoutExtension (fname);
                        project.FileFormat = new MSBuildFileFormat (lang);
                        project.ClrVersion = ClrVersion.Net_2_0;
 
@@ -276,7 +279,7 @@
                        }
 
                        if (guid != null)
-                               project.ExtendedProperties ["guid"] = guid;
+                               project.ExtendedProperties ["guid"] = guid.Trim 
(new char [] {'{', '}'});
 
                        //ReadItemGroups : References, Source files etc
                        ReadItemGroups (doc, project, globalConfig, basePath);
@@ -294,11 +297,16 @@
                                        String.IsNullOrEmpty (dic 
["CONFIGURATION"]))
                                        continue;
 
-                               DotNetProjectConfiguration config = 
(DotNetProjectConfiguration) globalConfig.Clone ();
-                               config.Name = dic ["CONFIGURATION"];
+                               DotNetProjectConfiguration config = 
+                                       (DotNetProjectConfiguration) 
project.GetConfiguration (dic ["CONFIGURATION"]);
 
+                               if (config == null) {
+                                       config = (DotNetProjectConfiguration) 
globalConfig.Clone ();
+                                       config.Name = dic ["CONFIGURATION"];
+                                       project.Configurations.Add (config);
+                               }
+
                                ReadConfig (iter.Current, config, 
project.LanguageName, basePath, ref tmp);
-                               project.Configurations.Add (config);
 
                                project.ExtendedProperties [config] = 
iter.Current.UnderlyingObject;
                        }
@@ -322,9 +330,22 @@
                        //project.ConfigurationAdded += new 
ConfigurationEventHandler (HandleConfigurationAdded);
                        project.ConfigurationRemoved += new 
ConfigurationEventHandler (HandleConfigurationRemoved);
 
+                       project.NameChanged += new 
CombineEntryRenamedEventHandler (HandleRename);
+
                        return project;
                }
 
+               static void HandleRename (object sender, 
CombineEntryRenamedEventArgs e)
+               {
+                       string oldfname = e.CombineEntry.FileName;
+                       string extn = Path.GetExtension (oldfname);
+                       string dir = Path.GetDirectoryName (oldfname);
+                       string newfname = Path.Combine (dir, e.NewName + extn);
+
+                       File.Move (oldfname, newfname);
+                       e.CombineEntry.FileName = newfname;
+               }
+
                //Event handlers
                static void HandleConfigurationRemoved (object sender, 
ConfigurationEventArgs e)
                {
@@ -546,7 +567,8 @@
                                        case "Reference":
                                                string hintPath = String.Empty;
                                                string fullname = 
Runtime.SystemAssemblyService.GetAssemblyFullName (include);
-                                               if ((fullname != null && 
Runtime.SystemAssemblyService.FindInstalledAssembly (fullname) != null) ||
+                                               if ((fullname != null && 
+                                                       
Runtime.SystemAssemblyService.FindInstalledAssembly (fullname) != null) ||
                                                        !ReadAsString (node, 
"HintPath", ref hintPath, false)) {
 
                                                        //If the assembly is 
from a package file
@@ -560,8 +582,7 @@
                                                project.ExtendedProperties [pr] 
= node;
                                                break;
                                        case "ProjectReference":
-                                               //Not using @include currently, 
instead using the Name
-                                               //string projGuid = 
GetChildValue (node, "Project");
+                                               //Not using @Include currently, 
instead using the Name
                                                string projGuid = null;
                                                string projName = null;
 

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs        
2006-11-29 12:30:13 UTC (rev 68661)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs        
2006-11-29 12:35:10 UTC (rev 68662)
@@ -31,6 +31,7 @@
 using System.Collections.Generic;
 using System.Collections.Specialized;
 using System.IO;
+using System.Text;
 using System.Text.RegularExpressions;
 using System.Xml;
 using MonoDevelop.Projects;
@@ -41,7 +42,8 @@
 {
        internal class SlnFileFormat: IFileFormat
        {
-               static Guid folderGuid = new Guid 
("2150E333-8FDC-42A3-9474-1A3956D46DE8");
+               static Guid folderTypeGuid = new Guid 
("2150E333-8FDC-42A3-9474-1A3956D46DE8");
+               static Guid projectTypeGuid = new Guid 
("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC");
 
                public string Name {
                        get { return "Visual Studio .NET 2005 Solution"; }
@@ -64,9 +66,98 @@
                
                public void WriteFile (string file, object obj, 
IProgressMonitor monitor)
                {
-                       //FIXME:
+                       Combine c = (Combine) obj;
+                       if (c.ParentCombine != null)
+                               //Not the top most solution
+                               return;
+
+                       using (StreamWriter sw = new StreamWriter (file, false, 
Encoding.UTF8)) {
+                               //Write Header
+                               sw.WriteLine ("Microsoft Visual Studio Solution 
File, Format Version 9.00");
+
+                               //Write the projects
+                               WriteProjects (c, sw);
+
+                               //Write the Globals
+                               sw.WriteLine ("Global");
+
+                               //Write SolutionConfigurationPlatforms
+                               //FIXME: SolutionConfigurations?
+                               sw.WriteLine 
("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
+
+                               foreach (CombineConfiguration config in 
c.Configurations) {
+                                       string s = (string) 
config.ExtendedProperties ["SolutionConfigurationPlatforms"];
+                                       if (String.IsNullOrEmpty (s))
+                                               //FIXME: Platforms
+                                               sw.WriteLine ("\t\t{0}|{1} = 
{0}|{1}", config.Name, "Any CPU");
+                                       else
+                                               sw.WriteLine ("\t\t{0}", s);
+                               }
+
+                               sw.WriteLine ("\tEndGlobalSection");
+
+                               //Write Nested Projects
+                               sw.WriteLine ("\tGlobalSection(NestedProjects) 
= preSolution");
+                               WriteNestedProjects (c, sw);
+                               sw.WriteLine ("\tEndGlobalSection");
+
+                               //FIXME: ProjectConfigurationPlatforms
+                               //FIXME:  .ActiveCfg
+
+                               //Write 'others'
+                               List<string> others = c.ExtendedProperties 
["global_extras"] as List<string>;
+                               if (others != null) {
+                                       foreach (string s in others)
+                                               sw.WriteLine (s);
+                               }
+                               
+                               sw.WriteLine ("EndGlobal");
+                       }
                }
-               
+
+               void WriteProjects (Combine combine, StreamWriter writer)
+               {
+                       foreach (CombineEntry ce in combine.Entries) {
+                               Combine c = ce as Combine;
+
+                               writer.WriteLine (@"Project(""{{{0}}}"") = 
""{1}"", ""{2}"", ""{{{3}}}""",
+                                       (c != null) ? folderTypeGuid.ToString 
().ToUpper () : projectTypeGuid.ToString ().ToUpper (),
+                                       ce.Name, 
+                                       (c != null) ? ce.Name : 
ce.RelativeFileName, 
+                                       //FIXME: "guid" is avail only incase of 
msbuild projects.. 
+                                       (string) ce.ExtendedProperties 
["guid"]);
+
+                               List<string> l = ce.ExtendedProperties 
["extra"] as List<string>;
+                               if (l != null) {
+                                       foreach (string s in l)
+                                               writer.WriteLine (s);
+                               }
+
+                               writer.WriteLine ("EndProject");
+                               if (c != null)
+                                       WriteProjects (c, writer);
+                       }
+               }
+
+               void WriteNestedProjects (Combine combine, StreamWriter writer)
+               {
+                       foreach (CombineEntry ce in combine.Entries) {
+                               Combine c = ce as Combine;
+                               if (c == null || c.ParentCombine == null)
+                                       continue;
+
+                               WriteNestedProjects (c, writer);
+                       }
+
+                       string guid = (string) combine.ExtendedProperties 
["guid"];
+                       Combine root = combine.RootCombine;
+                       foreach (CombineEntry ce in combine.Entries) {
+                               if (ce.ParentCombine != root)
+                                       writer.WriteLine (@"{0}{{{1}}} = 
{{{2}}}", "\t\t", (string) ce.ExtendedProperties ["guid"], guid);
+                       }
+               }
+
+               //Reader
                public object ReadFile (string fileName, IProgressMonitor 
monitor)
                {
                        Combine combine = null;
@@ -75,203 +166,336 @@
                        
                        try {
                                monitor.BeginTask (string.Format 
(GettextCatalog.GetString ("Loading solution: {0}"), fileName), 1);
-                               combine = ParseSln (fileName, monitor);
+                               combine = LoadSolution (fileName, monitor);
+                               SetHandlers (combine);
                        } catch (Exception ex) {
                                monitor.ReportError (string.Format 
(GettextCatalog.GetString ("Could not load solution: {0}"), fileName), ex);
                                throw;
                        } finally {
                                monitor.EndTask ();
                        }
-                       
+
                        return combine;
                }
 
-               //FIXME: Move to seperate class
-               Combine ParseSln (string fileName, IProgressMonitor monitor)
+               static void SetHandlers (Combine combine)
                {
+                       foreach (CombineEntry ce in combine.Entries) {
+                               Combine c = ce as Combine;
+                               if (c == null)
+                                       continue;
+
+                               SetHandlers (c);
+                       }
+                         
+                       combine.EntryModified += new CombineEntryEventHandler 
(HandleCombineEntryModified);
+                       combine.EntryAdded += new CombineEntryEventHandler 
(HandleCombineEntryAdded);
+               }
+
+               static void HandleCombineEntryModified (object sender, 
CombineEntryEventArgs e)
+               {
+                       Combine c = (Combine) sender;
+               }
+
+               static void HandleCombineEntryAdded (object sender, 
CombineEntryEventArgs e)
+               {
+                       Combine newCombine = e.CombineEntry as Combine;
+                       if (newCombine == null)
+                               return;
+
+                       //FIXME: Remove the empty mds created for this solution 
folder
+                       //File.Delete (newCombine.FileName);
+
+                       newCombine.FileFormat = new SlnFileFormat ();
+                       newCombine.ExtendedProperties ["guid"] = Guid.NewGuid 
().ToString ().ToUpper ();
+
+                       //This is set to ensure that the solution folder's 
BaseDirectory
+                       //(which is derived from .FileName) matches that of the 
root
+                       //combine
+                       newCombine.FileName = newCombine.RootCombine.FileName;
+
+                       SetHandlers (newCombine);
+               }
+
+               //ExtendedProperties
+               //      Toplevel solution:
+               //              global_extras : List<string> containing 
GlobalSections
+               //                              not used by this addin
+               //      
+               //      Per project/folder:
+               //              guid
+               //              extra : List<string> containing "extra" strings,
+               //                      not used by this addin
+               //
+               //      Per config
+               //              Platform : Eg. Any CPU
+               //              SolutionConfigurationPlatforms
+               //
+               Combine LoadSolution (string fileName, IProgressMonitor monitor)
+               {
                        //string version = GetSlnFileVersion (fileName);
                        //if (version != "9.00")
                        //      throw new UnknownProjectVersionException 
(fileName, version);
 
-                       StreamReader reader = new StreamReader(fileName);
+                       ListDictionary globals = null;
+                       Combine combine = null;
+                       List<Section> projectSections = null;
+                       List<string> lines = null;
+
+                       //Parse the .sln file
+                       using (StreamReader reader = new 
StreamReader(fileName)) {
+                               combine = new Combine ();
+                               combine.Name = Path.GetFileNameWithoutExtension 
(fileName);
+                               combine.FileName = fileName;
+                               combine.FileFormat = new SlnFileFormat ();
+
+                               string s = null;
+                               projectSections = new List<Section> ();
+                               lines = new List<string> ();
+                               globals = new ListDictionary ();
+                               //Parse
+                               while (!reader.EndOfStream) {
+                                       s = GetNextLine (reader, lines).Trim ();
+
+                                       if (String.Compare (s, "Global", true) 
== 0) {
+                                               ParseGlobal (reader, lines, 
globals);
+                                               continue;
+                                       }
+
+                                       if (s.StartsWith ("Project")) {
+                                               Section sec = new Section ();
+                                               projectSections.Add (sec);
+
+                                               sec.Start = lines.Count - 1;
+
+                                               int e = ReadUntil 
("EndProject", reader, lines);
+                                               sec.Count = (e < 0) ? 1 : (e - 
sec.Start + 1);
+
+                                               continue;
+                                       }
+                               }
+                       }
+
+                       Dictionary<string, CombineEntry> entries = new 
Dictionary<string, CombineEntry> ();
                        Regex regex = new Regex(@"Project\(""(\{.*\})""\) = 
""(.*)"", ""(.*)"", ""(\{.*\})""");
-    
-                       Combine combine = new Combine ();
-                       combine.FileName = fileName;
-                       combine.FileFormat = new SlnFileFormat ();
+                       foreach (Section sec in projectSections) {
+                               Match match = regex.Match (lines [sec.Start]);
+                               if (!match.Success) {
+                                       Runtime.LoggingService.DebugFormat 
(GettextCatalog.GetString (
+                                               "Invalid Project definition on 
line number #{0} in file '{1}'. Ignoring.",
+                                               sec.Start + 1,
+                                               fileName));
 
-                       Dictionary<string, DotNetProject> projects = new 
Dictionary<string, DotNetProject> ();
-                       Dictionary<string, Combine> folders = null;
-                       string s;
-                       while (true)
-                       {
-                               s = reader.ReadLine();
-                               if (s.StartsWith("Global"))
-                                       break;
-
-                               Match match = regex.Match(s);
-                               if (!match.Success)
                                        continue;
+                               }
 
-                               Guid projectTypeGuid = new Guid (match.Groups 
[1].Value);
+                               Guid projTypeGuid = 
SlnFileFormat.projectTypeGuid;
+                               try {
+                                       projTypeGuid = new Guid (match.Groups 
[1].Value);
+                               } catch (FormatException) {
+                                       //Use default guid as projectGuid
+                                       Runtime.LoggingService.Debug 
(GettextCatalog.GetString (
+                                               "Invalid Project type guid 
'{0}' on line #{1}. Trying to read as a Project.",
+                                               match.Groups [1].Value,
+                                               sec.Start + 1));
+                               }
+
                                string projectName = match.Groups[2].Value;
-                               string projPath = match.Groups[3].Value;
+                               string projectPath = match.Groups[3].Value;
                                string projectGuid = match.Groups[4].Value;
 
-                               if (projectTypeGuid == folderGuid) {
+                               if (projTypeGuid == folderTypeGuid) {
                                        //Solution folder
                                        Combine folder = new Combine ();
                                        folder.Name = projectName;
-                                       folder.FileName = projPath;
+                                       folder.FileName = projectPath;
                                        folder.FileFormat = new SlnFileFormat 
();
 
-                                       folder.ExtendedProperties ["guid"] = 
projectGuid;
-                                       folder.ExtendedProperties ["folder"] = 
true;
+                                       folder.ExtendedProperties ["guid"] = 
projectGuid.Trim (new char [] {'{', '}'});
+                                       folder.ExtendedProperties ["extra"] = 
lines.GetRange (sec.Start + 1, sec.Count - 2);
 
-                                       if (folders == null)
-                                               folders = new 
Dictionary<string, Combine> ();
-                                       folders [projectGuid] = folder;
-
+                                       entries [projectGuid] = folder;
+                                       
                                        continue;
                                }
 
-                               if (!projPath.StartsWith("http://";) &&
-                                       (projPath.EndsWith (".csproj") || 
projPath.EndsWith (".vbproj")))
+                               if (projTypeGuid != projectTypeGuid)
+                                       Runtime.LoggingService.Debug 
(GettextCatalog.GetString (
+                                               "Unknown project type guid 
'{0}' on line #{1}. Trying to read as a project.",
+                                               projTypeGuid,
+                                               sec.Start + 1));
+
+                               if (!projectPath.StartsWith("http://";) &&
+                                       (projectPath.EndsWith (".csproj") || 
projectPath.EndsWith (".vbproj")))
                                {
-                                       projPath = MapPath 
(Path.GetDirectoryName (fileName), projPath);
+                                       projectPath = Path.GetFullPath (MapPath 
(Path.GetDirectoryName (fileName), projectPath));
                                        try {
-                                               DotNetProject project = 
Services.ProjectService.ReadFile (projPath, monitor) as DotNetProject;
+                                               DotNetProject project = 
Services.ProjectService.ReadFile (projectPath, monitor) as DotNetProject;
                                                project.Name = projectName;
-                                               projects [projectGuid] = 
project;
+                                               entries [projectGuid] = project;
+                                               project.ExtendedProperties 
["extra"] = 
+                                                       lines.GetRange 
(sec.Start + 1, sec.Count - 2);
                                        } catch {
-                                               //FIXME: monitor.ReportWarning 
-                                               Console.WriteLine ("Failed to 
load project file '{0}'", projPath);
-                                               continue;
+                                               //
                                        }
+                                       continue;
                                }
-    
+                               //FIXME: Non .csproj/.vbproj projects not 
supported (yet)
+                               monitor.ReportWarning (GettextCatalog.GetString 
(
+                                       "{0}({1}): Unsupported or unrecognized 
project type for this solution. See logs.", fileName, sec.Start + 1));
                        }
 
-                       //FIXME: Project can have ProjectDependencies
+                       if (globals != null && globals.Contains 
("NestedProjects")) {
+                               LoadNestedProjects (globals ["NestedProjects"] 
as Section, lines, entries, monitor);
+                               globals.Remove ("NestedProjects");
+                       }
 
-                       if (String.Compare (s.Trim (), "Global", true) == 0) {
-                               ListDictionary dict = ParseGlobal (reader);
+                       //Add top level folders and projects to the main combine
+                       foreach (CombineEntry ce in entries.Values) {
+                               if (ce.ParentCombine == null)
+                                       combine.Entries.Add (ce);
+                       }
 
-                               if (dict.Contains ("NestedProjects") && folders 
!= null)
-                                       //"NestedProjects" section was found 
and 
-                                       //folders are defined
-                                       LoadNestedProjects (dict 
["NestedProjects"] as List<string>,
-                                               folders, projects);
+                       //FIXME: This can be just SolutionConfiguration also!
+                       if (globals != null && globals.Contains 
("SolutionConfigurationPlatforms")) {
+                               LoadConfigurations (globals 
["SolutionConfigurationPlatforms"] as Section, lines,
+                                       combine, monitor);
+                               globals.Remove 
("SolutionConfigurationPlatforms");
+                       }
 
-                               //Add the folders to the main combine
-                               if (folders != null)
-                                       foreach (Combine f in folders.Values)
-                                               combine.Entries.Add (f);
+                       //Save the global sections that we dont use
+                       List<string> globalLines = new List<string> ();
+                       foreach (Section sec in globals.Values)
+                               globalLines.InsertRange (globalLines.Count, 
lines.GetRange (sec.Start, sec.Count));
 
-                               //Add the projects to the main combine
-                               foreach (DotNetProject p in projects.Values)
-                                       combine.Entries.Add (p);
-
-                               //FIXME: This can be just SolutionConfiguration 
also!
-                               if (dict.Contains 
("SolutionConfigurationPlatforms"))
-                                       LoadConfigurations (dict 
["SolutionConfigurationPlatforms"] as List<string>,
-                                               combine);
-                       }
-
+                       combine.ExtendedProperties ["global_extras"] = 
globalLines;
                        return combine;
                }
 
-               ListDictionary ParseGlobal (StreamReader reader)
+               void ParseGlobal (StreamReader reader, List<string> lines, 
ListDictionary dict)
                {
                        Regex regex = new Regex 
(@"GlobalSection\s*\(([^)]*)\)\s*=\s*(\w*)");
-                       ListDictionary dict = new ListDictionary ();
 
                        //Process GlobalSection-s
                        while (!reader.EndOfStream) {
-                               List<string> list = new List<string> ();
+                               string s = GetNextLine (reader, lines).Trim ();
+                               if (s.Length == 0)
+                                       //Skip blank lines
+                                       continue;
 
-                               string s = reader.ReadLine ().Trim ();
+                               Match m = regex.Match (s);
+                               if (!m.Success) {
+                                       if (String.Compare (s, "EndGlobal", 
true) == 0)
+                                               return;
 
-                               Match m = regex.Match (s);
-                               if (!m.Success)
                                        continue;
+                               }
 
-                               string key = m.Groups [1].Value;
-                               string val = m.Groups [2].Value;
+                               Section sec = new Section (m.Groups [1].Value, 
m.Groups [2].Value, lines.Count - 1, 1);
+                               dict [sec.Key] = sec;
 
-                               dict [key] = list;
-
-                               //First entry in the list is the val 
'preSolution' like below
-                               //GlobalSection(SolutionConfigurationPlatforms) 
= preSolution
-                               list.Add (val);
-
-                               while (!reader.EndOfStream) {
-                                       s = reader.ReadLine ().Trim ();
-                                       if (String.Compare (s, 
"EndGlobalSection", true) == 0)
-                                               break;
-                                       if (s.Length == 0)
-                                               continue;
-
-                                       //Not splitting the key/value here
-                                       list.Add (s);
-                               }
+                               sec.Count = ReadUntil ("EndGlobalSection", 
reader, lines) - sec.Start + 1;
+                               //FIXME: sec.Count == -1 : No EndGlobalSection 
found, ignore entry?
                        }
-
-                       return dict;
                }
 
-               void LoadConfigurations (List<string> list, Combine combine)
+               void LoadConfigurations (Section sec, List<string> lines, 
Combine combine, IProgressMonitor monitor)
                {
-                       if (list == null || list.Count <= 1 ||
-                               String.Compare (list [0], "preSolution", true) 
!= 0) 
+                       if (sec == null || String.Compare (sec.Val, 
"preSolution", true) != 0)
                                return;
 
-                       for (int i = 1; i < list.Count; i ++) {
+                       for (int i = 0; i < sec.Count - 2; i ++) {
                                //FIXME: expects both key and val to be on the 
same line
-                               KeyValuePair<string, string> pair = 
SplitKeyValue (list [i]);
+                               string s = lines [i + sec.Start + 1].Trim ();
+                               if (s.Length == 0)
+                                       //Skip blank lines
+                                       continue;
 
+                               KeyValuePair<string, string> pair = 
SplitKeyValue (s);
+
                                //key : Debug|Any CPU
                                string [] key_parts = pair.Key.Split (new char 
[] {'|'}, 2);
                                if (key_parts.Length == 0)
                                        continue;
-
+                               
                                CombineConfiguration config = 
(CombineConfiguration) 
-                                       combine.CreateConfiguration (key_parts 
[0]);
+                                       combine.GetConfiguration (key_parts 
[0]);
                                
+                               if (config == null) {
+                                       config = (CombineConfiguration) 
+                                               combine.CreateConfiguration 
(key_parts [0]);
+                                       combine.Configurations.Add (config);
+                               }
+                               
+                               if (key_parts.Length > 1) {
+                                       if (String.Compare (key_parts [1], "Any 
CPU", true) != 0)
+                                               Runtime.LoggingService.Debug 
(GettextCatalog.GetString (
+                                                       "Platform specific 
configurations not supported. Only (default) 'Any CPU' supported."));
+
+                                       config.ExtendedProperties.Add 
("Platform", key_parts [1]);
+                               }
+
                                //Add all the projects to the configurations
                                foreach (CombineEntry entry in combine.Entries)
                                        config.AddEntry (entry);
+
+                               config.ExtendedProperties.Add 
("SolutionConfigurationPlatforms", s);
                        }
                }
 
-               void LoadNestedProjects (List<string> list, 
-                       Dictionary<string, Combine> folders, Dictionary<string, 
DotNetProject> projects)
+               void LoadNestedProjects (Section sec, List<string> lines,
+                       Dictionary<string, CombineEntry> entries, 
IProgressMonitor monitor)
                {
-                       if (list == null || list.Count <= 1 ||
-                               String.Compare (list [0], "preSolution", true) 
!= 0) 
+                       if (sec == null || String.Compare (sec.Val, 
"preSolution", true) != 0)
                                return;
 
-                       for (int i = 1; i < list.Count; i ++) {
-                               KeyValuePair<string, string> pair = 
SplitKeyValue (list [i]);
-                               if (!folders.ContainsKey (pair.Value))
-                                       //Folder not found
-                                       //FIXME: Warning? 
+                       for (int i = 0; i < sec.Count; i ++) {
+                               KeyValuePair<string, string> pair = 
SplitKeyValue (lines [i + sec.Start + 1].Trim ());
+
+                               if (!entries.ContainsKey (pair.Value)) {
+                                       //Container not found
+                                       Runtime.LoggingService.Debug ("Project 
with guid '{0}' not found.", pair.Value);
                                        continue;
-                               if (!projects.ContainsKey (pair.Key))
-                                       //Project not found
-                                       //FIXME: Warning?
+                               }
+
+                               if (!entries.ContainsKey (pair.Key)) {
+                                       //Containee not found
+                                       Runtime.LoggingService.Debug ("Project 
with guid '{0}' not found.", pair.Key);
                                        continue;
+                               }
 
-                               Combine folder = folders [pair.Value];
-                               DotNetProject proj = projects [pair.Key];
+                               Combine folder = entries [pair.Value] as 
Combine;
+                               if (folder == null)
+                                       continue;
 
-                               folder.Entries.Add (proj);
-                               
-                               //Remove the project from the dictionary
-                               projects.Remove (pair.Key);
+                               folder.Entries.Add (entries [pair.Key]);
                        }
                }
 
+               string GetNextLine (StreamReader reader, List<string> list)
+               {
+                       if (reader.EndOfStream)
+                               return null;
+
+                       string ret = reader.ReadLine ();
+                       list.Add (ret);
+                       return ret;
+               }
+
+               int ReadUntil (string end, StreamReader reader, List<string> 
lines)
+               {
+                       int ret = -1;
+                       while (!reader.EndOfStream) {
+                               string s = GetNextLine (reader, lines);
+
+                               if (String.Compare (s.Trim (), end, true) == 0)
+                                       return (lines.Count - 1);
+                       }
+
+                       return ret;
+               }
+
+
                KeyValuePair<string, string> SplitKeyValue (string s)
                {
                        string [] pair = s.Split (new char [] {'='}, 2);
@@ -306,8 +530,6 @@
                        return strVersion;
                }
 
-               //FIXME: Move this somewhere else?
-               //is there an existing method for this?
                internal static string MapPath (string basePath, string relPath)
                {
                        if (relPath == null || relPath.Length == 0)
@@ -356,6 +578,25 @@
                                return path;
                }
 
+               class Section {
+                       public string Key;
+                       public string Val;
 
+                       public int Start = -1; //Line number
+                       public int Count = 0;
+
+                       public Section ()
+                       {
+                       }
+
+                       public Section (string Key, string Val, int Start, int 
Count)
+                       {
+                               this.Key = Key;
+                               this.Val = Val;
+                               this.Start = Start;
+                               this.Count = Count;
+                       }
+               }
+
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to