Browse Source

Added Solution file format validation

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@31 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 22 years ago
parent
commit
ec715753ea
  1. 14
      src/Main/Base/Project/Src/Commands/DebugCommands.cs
  2. 29
      src/Main/Base/Project/Src/Project/Solution/Solution.cs

14
src/Main/Base/Project/Src/Commands/DebugCommands.cs

@ -16,9 +16,10 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
public override void Run() public override void Run()
{ {
Debug.Assert(ProjectService.OpenSolution != null); Debug.Assert(ProjectService.OpenSolution != null);
if (ProjectService.OpenSolution.IsDirty) { // if (ProjectService.OpenSolution.IsDirty) {
ProjectService.OpenSolution.Build(); // new
} // }
new Build().Run();
IProject startupProject = ProjectService.OpenSolution.StartupProject; IProject startupProject = ProjectService.OpenSolution.StartupProject;
if (startupProject != null) { if (startupProject != null) {
startupProject.Start(true); startupProject.Start(true);
@ -31,9 +32,10 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
{ {
Debug.Assert(ProjectService.OpenSolution != null); Debug.Assert(ProjectService.OpenSolution != null);
if (ProjectService.OpenSolution.IsDirty) { // if (ProjectService.OpenSolution.IsDirty) {
ProjectService.OpenSolution.Build(); // ProjectService.OpenSolution.Build();
} // }
new Build().Run();
IProject startupProject = ProjectService.OpenSolution.StartupProject; IProject startupProject = ProjectService.OpenSolution.StartupProject;
if (startupProject != null) { if (startupProject != null) {
startupProject.Start(true); startupProject.Start(true);

29
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -336,22 +336,40 @@ namespace ICSharpCode.SharpDevelop.Project
} }
static Regex versionPattern = new Regex("Microsoft Visual Studio Solution File, Format Version\\s+(?<Version>.*)", RegexOptions.Compiled);
static Regex projectLinePattern = new Regex("Project\\(\"(?<ProjectGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled); static Regex projectLinePattern = new Regex("Project\\(\"(?<ProjectGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled);
static Regex globalSectionPattern = new Regex("\\s*GlobalSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled); static Regex globalSectionPattern = new Regex("\\s*GlobalSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled);
static void SetupSolution(Solution newSolution, string fileName) static bool SetupSolution(Solution newSolution, string fileName)
{ {
string solutionDirectory = Path.GetDirectoryName(fileName); string solutionDirectory = Path.GetDirectoryName(fileName);
ProjectSection nestedProjectsSection = null; ProjectSection nestedProjectsSection = null;
using (StreamReader sr = File.OpenText(fileName)) { using (StreamReader sr = File.OpenText(fileName)) {
string line = sr.ReadLine();
Console.WriteLine("line '{0}'", line);
Match match = versionPattern.Match(line);
if (!match.Success) {
MessageService.ShowError(fileName + " is not a valid solution file.");
return false;
}
switch (match.Result("${Version}")) {
case "9.00":
break;
default:
MessageService.ShowError("Can't read Microsoft Solution file format " + match.Result("${Version}") + ". Use Visual Studio.NET to convert it to a newer version.");
return false;
}
while (true) { while (true) {
string line = sr.ReadLine(); line = sr.ReadLine();
if (line == null) { if (line == null) {
break; break;
} }
Match match = projectLinePattern.Match(line); match = projectLinePattern.Match(line);
if (match.Success) { if (match.Success) {
string projectGuid = match.Result("${ProjectGuid}"); string projectGuid = match.Result("${ProjectGuid}");
string title = match.Result("${Title}"); string title = match.Result("${Title}");
@ -404,6 +422,7 @@ namespace ICSharpCode.SharpDevelop.Project
folder.AddFolder(newSolution.guidDictionary[from]); folder.AddFolder(newSolution.guidDictionary[from]);
} }
} }
return true;
} }
public static Solution Load(string fileName) public static Solution Load(string fileName)
@ -417,7 +436,9 @@ namespace ICSharpCode.SharpDevelop.Project
ICSharpCode.SharpDevelop.Project.Converter.CombineToSolution.ConvertSolution(newSolution, fileName); ICSharpCode.SharpDevelop.Project.Converter.CombineToSolution.ConvertSolution(newSolution, fileName);
} else { } else {
newSolution.fileName = fileName; newSolution.fileName = fileName;
SetupSolution(newSolution, fileName); if (!SetupSolution(newSolution, fileName)) {
return null;
}
} }
return newSolution; return newSolution;
} }

Loading…
Cancel
Save