This class contains all methods related to console input and output
コード例 #1
0
        /// <summary>
        /// Generates the Qt project file
        /// </summary>
        /// <param name="projData">Reference to project parser</param>
        /// <returns>success</returns>
        public static void GenerateProFile(ProjectFileParser projData)
        {
            /* These lists will store all source and header files
             * which are found in the source directory of your project */
            List <string> SourceFilePaths;
            List <string> HeaderFilePaths;

            ConsoleActions.PrintHeader();

            Console.WriteLine("Generating .pro file...");
            SourceFilePaths = new List <string>();
            HeaderFilePaths = new List <string>();

            string sourcePath = projData.projectPath + "Source";

            if (!Directory.Exists(sourcePath))
            {
                Errors.ErrorExit(ErrorCode.SOURCE_PATH_NOT_FOUND);
            }

            FileActions.ScanDirectoryForFiles(SourceFilePaths, HeaderFilePaths, sourcePath, projData.projectName);

            // Add some useful configuration options and include all UE defines
            string qtProFile = "TEMPLATE = app\n" +
                               "CONFIG += console\n" +
                               "CONFIG -= app_bundle\n" +
                               "CONFIG -= qt\n" +
                               "CONFIG += c++11\n" +
                               " \n" +
                               "# All the defines of your project will go in this file\n" +
                               "# You can put this file on your repository, but you will need to remake it once you upgrade the engine.\n" +
                               "include(defines.pri)\n" +
                               " \n" +
                               "# Qt Creator will automatically add headers and source files if you add them via Qt Creator.\n" +
                               "HEADERS += ";

            // Add all found header files
            foreach (string headerFile in HeaderFilePaths)
            {
                qtProFile += headerFile + " \\\n\t";
            }

            qtProFile += "\nSOURCES += ";

            // Add all found source files
            foreach (string sourceFile in SourceFilePaths)
            {
                qtProFile += sourceFile + " \\\n\t";
            }

            // Add UE includes
            qtProFile = qtProFile + "\n# All your generated includes will go in this file\n" +
                        "# You can not put this on the repository as this contains hard coded paths\n" +
                        "# and is dependent on your windows install and engine version\n" +
                        "include(includes.pri)";

            // Add additional files to project
            List <string> distFiles = new List <string>();

            // build.cs
            if (File.Exists(sourcePath + "\\" + projData.projectName + "\\" + projData.projectName + ".Build.cs"))
            {
                distFiles.Add("../../Source/" + projData.projectName + "/" + projData.projectName + ".Build.cs");
            }

            // target.cs files
            string[] files = Directory.GetFiles(projData.projectPath + "\\Source\\");
            foreach (string file in files)
            {
                if (file.EndsWith(".Target.cs"))
                {
                    distFiles.Add("../../Source/" + Path.GetFileName(file));
                }
            }

            if (distFiles.Count > 0)
            {
                qtProFile += "\n\nDISTFILES += ";
                foreach (string distFile in distFiles)
                {
                    qtProFile += distFile + " \\\n\t";
                }
            }

            try
            {
                File.WriteAllText(projData.projectPath + "Intermediate\\ProjectFiles\\" + projData.projectName + ".pro", qtProFile);
            }
            catch
            {
                Errors.ErrorExit(ErrorCode.PROJECT_FILE_WRITE_FAILED);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // program cannot run without qtBuildPreset.xml
            FileActions.CheckIfPresetFilePresent();

            ConsoleActions.DisplayFirstRunDisclaimer();

            string projectDir  = "";
            string projectName = "";

            if (!Configuration.HasConfigurationFile())
            {
                ConsoleActions.StartConfigWizard();
                ConsoleActions.PrintHeader();
                Console.WriteLine("Configuration file written successfully.\n");
                Console.WriteLine("From now on you have two options to create project files:\n");
                Console.WriteLine("1. Run the tool from anywhere and enter the path to the project folder manually");
                Console.WriteLine("2. Run it from the command-line inside the project folder. (tool will detect everything from the working directory)");
                Console.WriteLine("\n\nIf you prefer the second option, I recommend adding the uProGen folder\nto the PATH variable.");
                Console.WriteLine("\n\n\t-Press Enter to quit...");
                Console.ReadLine();
                return;
            }
            else if (!Configuration.LoadConfiguration())
            {
                ConsoleActions.PrintHeader();
                Console.WriteLine("Invalid configuration found.\nThe configuration file will now open so you can fix the values.\nYou can also delete the file and rerun the tool (this will reinvoke the wizard).");
                Console.ReadLine();
                FileActions.OpenConfigFile();
                Environment.Exit(0);
            }

            // search working directory for project files
            projectDir  = FileActions.LookForProjectInWD();
            projectDir += "\\";

            if (projectDir == "\\") // working directory isn't a project directory
            {
                ConsoleActions.PrintHeader();

                projectDir = ConsoleActions.InputProjectPath();
                Console.WriteLine();
            }

            projectName = FileActions.ExtractProjectName(projectDir);

            ProjectFileParser projectParser = new VCX_Parser(projectDir, projectName);

            Generator.GenerateProFile(projectParser);

            Generator.GenerateDefinesAndInclude(projectParser);

            Generator.GenerateQtBuildPreset(projectParser);

            Console.WriteLine("\nQt Project generation successful.\n");
            Console.WriteLine("Do you want to open your project now (y/n)?");
            string answer = Console.ReadLine();

            if (answer.ToLower() == "y" || answer.ToLower() == "yes")
            {
                // opens your newly generated project (if .pro is associated with QtCreator)
                Process.Start(projectDir + "\\Intermediate\\ProjectFiles\\" + projectName + ".pro");
            }
        }