// Override this method to save options.
        public override void Save()
        {
            /*=== update the global project options, then save ===*/

            List <OptionsElement> options    = ProjectOptions.Options;
            ProjectOptionsSet     optionsSet = OptionsManager.GetProjectOptions(project);

            foreach (OptionsElement oe in options)
            {
                optionsSet.GetNewConfiguration(oe.Configuration, oe.Platform).Options = new Options(oe.Options);
            }

            optionsSet.Save();
        }
Example #2
0
        // original path must be absolute
        public static string OriginalToGeneratedPath(Project project, string originalpath)
        {
            string projectpath = StringUtility.RLeft(project.FullName, "\\") + "\\";

            string pathstring = Paths.EvaluateRelativePath(projectpath, originalpath);

            if (Path.IsPathRooted(pathstring))
            {
                //cases: //
                //       /
                //       c:/

                if (pathstring.StartsWith("/"))
                {
                    pathstring = "_root" + pathstring;
                }
                else if (pathstring.StartsWith("//"))
                {
                    pathstring = "_net" + StringUtility.Right(pathstring, 1);
                }
                else
                {
                    //c:/
                    pathstring.Replace(":", "");
                    pathstring = "_win/" + pathstring;
                }
            }

            string relativepath = pathstring.Replace("..\\", "_\\");

            // 3. if it's a complete network path, I need to handle the root

            //TODO: get the generated directory from the project settings
            string generated = OptionsManager.GetProjectOptions(project).GetActiveConfiguration().Options.GeneratedDirectory.Value;

            if (generated == "")
            {
                generated = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options.GeneratedDirectory.Value;
            }

            generated = ResolveVisualStudioMacros(project, generated);

            generated = MakeValidPath(generated);

            //resolve the macros
            return(projectpath + generated + relativepath);
        }
        /*=== utility ===*/

        // Call this to initialize settings.
        public virtual void Initialize(Project p)
        {
            project        = p;
            gOptions       = new Options(OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options);
            ProjectOptions = new ProjectOptionsSet(project);

            /*=== add the existing options ===*/

            List <OptionsElement> options = OptionsManager.GetProjectOptions(p).Options;

            foreach (OptionsElement oe in options)
            {
                OptionsElement newOE = new OptionsElement();
                newOE.Configuration = oe.Configuration;
                newOE.Platform      = oe.Platform;
                newOE.Options       = new Options(oe.Options);

                ProjectOptions.AddConfiguration(newOE);
            }
        }
        /*=== construction ===*/

        public GlobalOptionsPropertyGrid() : base()
        {
            aOptions = new Options();
            gOptions = new Options(OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options);
        }
 // Override this method to save options.
 public override void Save()
 {
     OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options = new Options(gOptions);
     OptionsManager.GetGlobalOptions().Save();
 }
Example #6
0
        //TODO: need to add debug, nodebug catching
        void FinishedCompile(bool bErrored)
        {
            PrintDebugLine("Finished opC++ Build.");
            //handle post-build operations
            CurrentThread = null;

            EnableCompileButtons();

            PostEvent = "";

            if (bErrored)
            {
                return;
            }

            if (CurrentMode != null)
            {
                // if the command was from the toolbar, we can customize the post build event using settings
                if (!CurrentMode.bIntercepted)
                {
                    Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options;

                    if (CurrentMode.Action == CompileTypes.Build)
                    {
                        if (CurrentMode.Selection == SelectionTypes.Solution)
                        {
                            //TODO: grab the command
                            PostEvent = options.PostBuildSolution.Value;
                        }
                        else if (CurrentMode.Selection == SelectionTypes.Project)
                        {
                            //TODO: grab the command
                            PostEvent = options.PostBuildProject.Value;
                        }
                    }
                    else if (CurrentMode.Action == CompileTypes.Clean)
                    {
                        //TODO: grab the command
                        PostEvent = options.PostCleanSolution.Value;
                    }
                }
                else if (CurrentMode.Action == CompileTypes.Debug)
                {
                    PostEvent = "Debug.Start";
                }
                else if (CurrentMode.Action == CompileTypes.NoDebug)
                {
                    PostEvent = "Debug.StartWithoutDebugging";
                }
                else
                {
                    //setup the post-build event
                    if (CurrentMode.Action == CompileTypes.Build)
                    {
                        PostEvent = "Build.Build";
                    }
                    else if (CurrentMode.Action == CompileTypes.Rebuild)
                    {
                        PostEvent = "Build.Rebuild";
                    }
                    else if (CurrentMode.Action == CompileTypes.Clean)
                    {
                        PostEvent = "Build.Clean";
                    }

                    if (CurrentMode.Selection == SelectionTypes.Project)
                    {
                        PostEvent += "Selection";
                    }
                    else if (CurrentMode.Selection == SelectionTypes.ProjectOnly)
                    {
                        PostEvent += "OnlyProject";
                    }
                    else if (CurrentMode.Selection == SelectionTypes.Solution)
                    {
                        PostEvent += "Solution";
                    }
                }
            }

            if (PostEvent.Length != 0)
            {
                App().ExecuteCommand(PostEvent, "");
            }
        }
Example #7
0
        void StartCompile(CompileMode mode)
        {
            // a compile is running already
            if (IsCompiling())
            {
                //TODO: should halt compiling really
                return;
                //CurrentThread.Stop();
            }

            if (mode.bIntercepted)
            {
                Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options;

                bool bExtendCommands = options.ExtendCommands.Value;

                if (!bExtendCommands)
                {
                    return;
                }
            }

            if (IsVSCompiling())
            {
                //cancel it
                App().ExecuteCommand("Build.Cancel", "");
            }

            // activate the output pane...
            GetOutputPane().Clear();
            ActivateOutputPane();

            // ok, lets attempt to start compiling now.

            CurrentThread = null;
            PostEvent     = "";

            // no solution loaded
            DTE2     app      = App();
            Solution solution = app.Solution;

            if (solution == null)
            {
                return;
            }

            // first save all the open files - this is a global setting
            SaveOpenFiles();

            List <Project> Projects;

            // find the selections we need (projects)
            if (mode.Selection == SelectionTypes.Solution)
            {
                Projects = ProjectUtility.GetSolutionProjects();
            }
            else if (mode.Selection == SelectionTypes.Project)
            {
                Projects = ProjectUtility.GetActiveProjects();
            }
            else            // if (mode.Selection == SelectionTypes.ProjectOnly)
            {
                Projects = ProjectUtility.GetActiveProjectOnly();
            }


            //
            // Mode Arguments
            //
            // clean : send it -clean
            // rebuild : send it -force
            // build : none...
            string ModeArguments = "";

            if (mode.Action == CompileTypes.Rebuild)
            {
                ModeArguments += "-force";
            }
            else if (mode.Action == CompileTypes.Clean)
            {
                ModeArguments += "-clean";
            }
            //else if Debug || NoDebug || Build ... no additional needed

            //TODO: need the global options path
            string GlobalArguments = "-dependencies \"" + Paths.GetGlobalOptionsFilename() + "\"";

            //no projects to compile
            if (Projects.Count == 0)
            {
                return;
            }

            List <CommandSetting> CommandSettings = new List <CommandSetting>();

            int numprojects = Projects.Count;

            for (int ip = 0; ip < numprojects; ip++)
            {
                Project project = Projects[ip];

                string ActiveConfiguration = ProjectUtility.ProjectActiveConfiguration(project);

                List <VCFile> ohfiles = ProjectUtility.GetOhFiles(project);

                // does it contain active oh files? if not skip it.
                ProjectUtility.FilterActiveFiles(ref ohfiles, ActiveConfiguration);
                if (ohfiles.Count == 0)
                {
                    continue;
                }

                // are the project settings set to enable opcpp?
                bool bProjectEnabled = true;
                if (!bProjectEnabled)
                {
                    continue;
                }

                //3. do we have .doh files in the project?
                List <VCFile> dohfiles = ProjectUtility.GetDohFiles(project);
                ProjectUtility.FilterActiveFiles(ref dohfiles, ActiveConfiguration);
                //              if (dohfiles.Count == 0)
                //                  continue;

                //fetch the project doh files from the global/project doh settings
                List <string> ProjectDohFiles = new List <string>();
                //              if(ProjectDohFiles.Count + dohfiles.Count == 0)
                //              {
                //                  //print a message "Project has oh files but no dialect was found or specified"
                //                  continue;
                //              }

                //now build the settings
                CommandSetting setting = new CommandSetting();

                setting.Project    = project;
                setting.WorkingDir = StringUtility.RLeft(project.FileName, "\\");

                //build the oh files list from the arguments
                //build the doh files list from the arguments
                string ohfilestring = "";
                for (int i = 0; i < ohfiles.Count; i++)
                {
                    VCFile file = ohfiles[i];

                    ohfilestring += '"';
                    ohfilestring += file.FullPath;
                    ohfilestring += '"';

                    if (i + 1 < ohfiles.Count)
                    {
                        ohfilestring += ',';
                    }
                }

                string dohfilestring = "";
                for (int i = 0; i < dohfiles.Count; i++)
                {
                    VCFile file = dohfiles[i];
                    dohfilestring += '"';
                    dohfilestring += file.FullPath;
                    dohfilestring += '"';

                    if (i + 1 < dohfiles.Count)
                    {
                        dohfilestring += ',';
                    }
                }

                for (int i = 0; i < ProjectDohFiles.Count; i++)
                {
                    dohfilestring += '"';
                    dohfilestring += ProjectDohFiles[i];
                    dohfilestring += '"';

                    if (i + 1 < ProjectDohFiles.Count)
                    {
                        dohfilestring += ',';
                    }
                }

                string FileArguments = "";

                if (ohfilestring.Length > 0)
                {
                    FileArguments += " -oh " + ohfilestring;
                }

                if (dohfilestring.Length > 0)
                {
                    FileArguments += " -doh " + dohfilestring;
                }

                // fetch the global + overloaded project arguments
                CommandLineInfo info = OptionsManager.GetCommandLineInfo(project);
                setting.ExePath = info.ExecutablePath;

                FileArguments += " -dependencies \"" + Paths.GetProjectOptionsFilename(project) + "\"";

                if (setting.ExePath == "")
                {
                    LogCompile("Error: opCpp exe path is undefined, please define in global and/or project settings");
                    return;
                }

                string ProjectArguments = info.Arguments;

                string MacroArguments = FileArguments + " " + ProjectArguments + " " + ModeArguments + " " + GlobalArguments;

                if (opBeta.IsBeta)
                {
                    MacroArguments += " -beta";
                }

                setting.Arguments = Paths.ResolveVisualStudioMacros(project, MacroArguments);

                //verify the macros worked...
                Regex findmacros = new Regex("$\\(*.\\)");
                Match result     = findmacros.Match(setting.Arguments);
                if (result.Success)
                {
                    string foundstring = setting.Arguments.Substring(result.Index, result.Length);
                    LogCompile("Error: bad macro found in settings - " + foundstring);
                    return;
                }

                CommandSettings.Add(setting);
            }

            //no commands to execute
            if (CommandSettings.Count == 0)
            {
//              CurrentMode = null;
//              FinishedCompile(false);
                return;
            }

            //execute commands
            CurrentMode = mode;

            CurrentThread            = new opCppThread(CommandSettings);
            CurrentThread.OnReadLine = LogCompile;
            CurrentThread.OnEnd      = FinishedCompile;
            CurrentThread.Start();
        }
Example #8
0
        /*=== utility ===*/

        public override void Running()
        {
            bool bErrored = false;

            foreach (opCpp2005.CommandSetting command in Commands)
            {
                try
                {
                    Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options;

                    // Print out the project that's currently compiling.
                    if (!command.Arguments.Contains("-clean"))
                    {
                        string configuration = ProjectUtility.GetActiveConfiguration(command.Project);
                        string platform      = ProjectUtility.GetActivePlatform(command.Project);
                        string message       = "------ opC++ Build started: Project: " + command.Project.Name + ", Configuration: " + configuration + " " + platform + " ------";

                        OnReadLine(message);
                    }

                    if (options.OutputCommandline.Value)                    //TODO: hook into global options
                    {
                        string argstring = command.Arguments.Replace("-beta", "");

                        OnReadLine("---------------------------------------------");
                        OnReadLine("Working Directory = " + command.WorkingDir);
                        OnReadLine("Path = " + command.ExePath);
                        OnReadLine("Arguments = " + argstring);
                        OnReadLine("::::::::::::::::::::::::::::::::::::::::::::;");
                    }

                    //create a new process
                    process = new System.Diagnostics.Process();

                    process.StartInfo.WorkingDirectory = command.WorkingDir;

                    //this path is from the registry
                    //NOTE: this should be integrated with the installer
                    process.StartInfo.FileName  = command.ExePath;
                    process.StartInfo.Arguments = command.Arguments;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.ErrorDialog            = false;
                    //process.EnableRaisingEvents = true;

                    //process.
                    process.OutputDataReceived += new DataReceivedEventHandler(a_OutputDataReceived);

                    process.Start();

                    //begin async output reading
                    process.BeginOutputReadLine();

//                  while(!process.HasExited)
//                  {
//                      string value;
//                      while( (value = process.StandardOutput.ReadLine()) != null )
//                          OnReadLine(value);
//                  }

                    //while (!process.HasExited) ;

                    //wait only 10 seconds (temporary?)
                    process.WaitForExit(1000 * 10);

                    //the second call makes sure the async output is all finished before proceeding.
                    process.WaitForExit();

                    if (process.HasExited)
                    {
                        //success
                    }
                    else
                    {
                        bErrored = true;

                        //check status...this should be temporary!
                        OnReadLine("Error: opC++ may not have finished in 10 seconds.");
                        break;
                    }

                    if (process.ExitCode != 0)
                    {
                        bErrored = true;
                        break;
                    }
                }
                catch (Exception e)
                {
                    OnReadLine("exception: " + e.Message + "\nStack Trace: " + e.StackTrace);
                    bErrored = true;
                    break;
                }
            }

            OnEnd(bErrored);
        }