Esempio n. 1
0
        public Project(Solution sol, SolutionProject sp)
        {
            solutionProject = sp;

            solution = sol;

            cmdSave = new Crow.Command(new Action(() => Save()))
            {
                Caption = "Save", Icon = new SvgPicture("#Crow.Coding.icons.save.svg"), CanExecute = true
            };
            cmdOpen = new Crow.Command(new Action(() => Load()))
            {
                Caption = "Open", Icon = new SvgPicture("#Crow.Coding.icons.open.svg"), CanExecute = false
            };
            cmdCompile = new Crow.Command(new Action(() => Compile()))
            {
                Caption = "Compile",
                Icon    = "#Crow.Coding.icons.compile.svg"
            };
            cmdSetAsStartProj = new Crow.Command(new Action(() => setAsStartupProject()))
            {
                Caption = "Set as Startup Project"
            };
            cmdNewFile = new Crow.Command(new Action(() => AddNewFile()))
            {
                Caption = "Add New File", Icon = new SvgPicture("#Crow.Coding.icons.blank-file.svg"), CanExecute = true
            };

            Commands = new List <Crow.Command> (new Crow.Command[] { cmdOpen, cmdSave, cmdSetAsStartProj, cmdCompile, cmdNewFile });

            Load();
        }
Esempio n. 2
0
        /// <summary>
        /// Loads visual studio .sln solution
        /// </summary>
        /// <exception cref="System.IO.FileNotFoundException">The file specified in path was not found.</exception>
        static public Solution LoadSolution(string path)
        {
            Solution s = new Solution();

            s.path = path;

            String slnTxt = File.ReadAllText(path);

            //
            //  Extra line feed is used by Visual studio, cmake does not generate extra line feed.
            //
            s.slnVer = Double.Parse(Regex.Match(slnTxt, "[\r\n]?Microsoft Visual Studio Solution File, Format Version ([0-9.]+)", RegexOptions.Multiline).Groups[1].Value, CultureInfo.InvariantCulture);

            int vsNumber = Int32.Parse(Regex.Match(slnTxt, "^\\# Visual Studio (Express )?([0-9]+)", RegexOptions.Multiline).Groups[2].Value);

            if (vsNumber > 2000)
            {
                s.fileFormatVersion = vsNumber;
            }
            else
            {
                s.fileFormatVersion = vsNumber - 14 + 2015;         // Visual Studio 14 => vs2015, formula might not be applicable for future vs versions.
            }
            foreach (String line in new String[] { "VisualStudioVersion", "MinimumVisualStudioVersion" })
            {
                var    m = Regex.Match(slnTxt, "^" + line + " = ([0-9.]+)", RegexOptions.Multiline);
                String v = null;
                if (m.Success)
                {
                    v = m.Groups[1].Value;
                }

                s.GetType().GetField(line).SetValue(s, v);
            }

            Regex reProjects = new Regex(
                "Project\\(\"(?<ProjectHostGuid>{[A-F0-9-]+})\"\\) = \"(?<ProjectName>.*?)\", \"(?<RelativePath>.*?)\", \"(?<ProjectGuid>{[A-F0-9-]+})\"[\r\n]*(?<dependencies>.*?)EndProject[\r\n]+",
                RegexOptions.Singleline);


            reProjects.Replace(slnTxt, new MatchEvaluator(m =>
            {
                SolutionProject p = new SolutionProject();

                foreach (String g in reProjects.GetGroupNames())
                {
                    if (g == "0")       //"0" - RegEx special kind of group
                    {
                        continue;
                    }

                    //
                    // ProjectHostGuid, ProjectName, RelativePath, ProjectGuid fields/properties are set here.
                    //
                    String v = m.Groups[g].ToString();
                    if (g != "dependencies")
                    {
                        FieldInfo fi = p.GetType().GetField(g);
                        if (fi != null)
                        {
                            fi.SetValue(p, v);
                        }
                        else
                        {
                            p.GetType().GetProperty(g).SetValue(p, v);
                        }
                        continue;
                    }

                    if (v == "")        // No dependencies set
                    {
                        continue;
                    }

                    String depsv = new Regex("ProjectSection\\(ProjectDependencies\\)[^\r\n]*?[\r\n]+" + "(.*?)" + "EndProjectSection", RegexOptions.Singleline).Match(v).Groups[1].Value;

                    //
                    // key is always equal to it's value.
                    // http://stackoverflow.com/questions/5629981/question-about-visual-studio-sln-file-format
                    //
                    var ProjectDependencies = new Regex("\\s*?({[A-F0-9-]+}) = ({[A-F0-9-]+})[\r\n]+", RegexOptions.Multiline).Matches(depsv).Cast <Match>().Select(x => x.Groups[1].Value).ToList();
                }     //foreach
                s.Projects.Add(new Project(s, p));
                return("");
            }
                                                          )
                               );

            new Regex("GlobalSection\\(SolutionConfigurationPlatforms\\).*?[\r\n]+(.*?)EndGlobalSection[\r\n]+", RegexOptions.Singleline).Replace(slnTxt, new MatchEvaluator(m2 =>
            {
                s.configurations = new Regex("\\s*(.*)\\s+=").Matches(m2.Groups[1].ToString()).Cast <Match>().Select(x => x.Groups[1].Value).ToList();
                return("");
            }
                                                                                                                                                                             ));

            Console.WriteLine("******** CONFIG ***************");

            new Regex("GlobalSection\\(ProjectConfigurationPlatforms\\).*?[\r\n]+(.*?)EndGlobalSection[\r\n]+", RegexOptions.Singleline).Replace(slnTxt, new MatchEvaluator(m2 =>
            {
                foreach (Match m3 in new Regex("\\s*({[A-F0-9-]+})\\.(.*?)\\.(.*?)\\s+=\\s+(.*?)[\r\n]+").Matches(m2.Groups[1].ToString()))
                {
                    String guid           = m3.Groups[1].Value;
                    String solutionConfig = m3.Groups[2].Value;
                    String action         = m3.Groups[3].Value;
                    String projectConfig  = m3.Groups[4].Value;

                    Project p = s.Projects.Where(x => x.ProjectGuid == guid).FirstOrDefault();
                    if (p == null)
                    {
                        continue;
                    }

                    Console.WriteLine("{0},{1},{2},{3}", guid, solutionConfig, action, projectConfig);

                    int iConfigIndex = s.configurations.IndexOf(solutionConfig);
                    if (iConfigIndex == -1)
                    {
                        continue;
                    }

//	                while (p.slnConfigurations.Count < s.configurations.Count)
//	                {
//	                    p.slnConfigurations.Add(null);
//	                    p.slnBuildProject.Add(false);
//	                }
//
//	                if (action == "ActiveCfg")
//	                {
//	                    p.slnConfigurations[iConfigIndex] = projectConfig;
//	                }
//	                else
//	                {
//	                    if (action.StartsWith("Build"))
//	                    {
//	                        p.slnBuildProject[iConfigIndex] = true;
//	                    }
//	                    else
//	                    {
//	                        if (action.StartsWith("Deploy"))
//	                        {
//	                            if (p.slnDeployProject == null) p.slnDeployProject = new List<bool?>();
//
//	                            while (p.slnDeployProject.Count < s.configurations.Count)
//	                                p.slnDeployProject.Add(null);
//
//	                            p.slnDeployProject[iConfigIndex] = true;
//	                        }
//	                    }
//	                } //if-esle
                }
                return("");
            }
                                                                                                                                                                            ));

            //
            // Initializes parent-child relationship.
            //
            new Regex("GlobalSection\\(NestedProjects\\).*?[\r\n]+(.*?)EndGlobalSection[\r\n]+", RegexOptions.Singleline).Replace(slnTxt, new MatchEvaluator(m4 =>
            {
                String v = m4.Groups[1].Value;
                new Regex("\\s*?({[A-F0-9-]+}) = ({[A-F0-9-]+})[\r\n]+", RegexOptions.Multiline).Replace(v, new MatchEvaluator(m5 =>
                {
                    String[] args  = m5.Groups.Cast <System.Text.RegularExpressions.Group>().Skip(1).Select(x => x.Value).ToArray();
                    Project child  = s.Projects.Where(x => args[0] == x.ProjectGuid).FirstOrDefault();
                    Project parent = s.Projects.Where(x => args[1] == x.ProjectGuid).FirstOrDefault();
                    parent.dependantProjects.Add(child);
                    child.ParentProject = parent;
                    return("");
                }));
                return("");
            }
                                                                                                                                                             ));

            s.UserConfig = new Configuration(s.path + ".user");
            s.ReloadStyling();
            s.ReloadDefaultTemplates();
            s.updateToolboxItems();
            return(s);
        }     //LoadSolution