diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-17 01:18:13 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-17 18:27:00 +0300 |
commit | 2c8f037e166b559d03a8540d14a0536f1c395116 (patch) | |
tree | ff22c69cc67f3b6a23ccb8703eec4332dcd932c3 | |
parent | f8dcd06e9c1f0c080f323d8be14c2dfc3c33869e (diff) |
[Core] Code cleanup
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFile.cs | 31 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs | 99 |
2 files changed, 32 insertions, 98 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFile.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFile.cs index cb13bb719e..f1af02ae84 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFile.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFile.cs @@ -7,6 +7,7 @@ using System.IO; using System.Collections; using MonoDevelop.Core; using MonoDevelop.Projects.Text; +using System.Text.RegularExpressions; namespace MonoDevelop.Projects.Formats.MSBuild { @@ -36,6 +37,36 @@ namespace MonoDevelop.Projects.Formats.MSBuild } /// <summary> + /// Gets the sln format version of the provided solution file + /// </summary> + /// <returns>The file version.</returns> + /// <param name="file">File.</param> + public static string GetFileVersion (string file) + { + string strVersion = null; + using (var reader = new StreamReader (file)) { + var strInput = reader.ReadLine(); + if (strInput == null) + return null; + + var match = slnVersionRegex.Match (strInput); + if (!match.Success) { + strInput = reader.ReadLine(); + if (strInput == null) + return null; + match = slnVersionRegex.Match (strInput); + if (!match.Success) + return null; + } + + strVersion = match.Groups[1].Value; + return strVersion; + } + } + + static Regex slnVersionRegex = new Regex (@"Microsoft Visual Studio Solution File, Format Version (\d?\d.\d\d)"); + + /// <summary> /// The directory to be used as base for converting absolute paths to relative /// </summary> public FilePath BaseDirectory { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs index fd85ff5b51..6249e8c2c6 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs @@ -59,8 +59,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild public bool CanReadFile (string file, MSBuildFileFormat format) { if (String.Compare (Path.GetExtension (file), ".sln", StringComparison.OrdinalIgnoreCase) == 0) { - string tmp; - string version = GetSlnFileVersion (file, out tmp); + string version = SlnFile.GetFileVersion (file); return format.SupportsSlnVersion (version); } return false; @@ -71,11 +70,6 @@ namespace MonoDevelop.Projects.Formats.MSBuild return obj is Solution; } - public List<string> GetItemFiles (object obj) - { - return null; - } - public Task WriteFile (string file, object obj, bool saveProjects, ProgressMonitor monitor) { return Task.Run (delegate { @@ -934,96 +928,5 @@ namespace MonoDevelop.Projects.Formats.MSBuild folder.Items.Add (item); } } - - string GetNextLine (StreamReader reader, List<string> list) - { - if (reader.Peek () < 0) - 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.Peek () >= 0) { - string s = GetNextLine (reader, lines); - - if (String.Compare (s.Trim (), end, true) == 0) - return (lines.Count - 1); - } - - return ret; - } - - - // Utility function to determine the sln file version - string GetSlnFileVersion(string strInSlnFile, out string headerComment) - { - string strVersion = null; - string strInput = null; - headerComment = null; - Match match; - StreamReader reader = new StreamReader(strInSlnFile); - - strInput = reader.ReadLine(); - if (strInput == null) - return null; - - match = SlnVersionRegex.Match(strInput); - if (!match.Success) { - strInput = reader.ReadLine(); - if (strInput == null) - return null; - match = SlnVersionRegex.Match (strInput); - } - - if (match.Success) - { - strVersion = match.Groups[1].Value; - headerComment = reader.ReadLine (); - } - - // Close the stream - reader.Close(); - - return strVersion; - } - - static Regex slnVersionRegex = null; - internal static Regex SlnVersionRegex { - get { - if (slnVersionRegex == null) - slnVersionRegex = new Regex (@"Microsoft Visual Studio Solution File, Format Version (\d?\d.\d\d)"); - return slnVersionRegex; - } - } - - public string Name { - get { return "MSBuild"; } - } - - } - - 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; - } } } |