/// <summary> /// Terminate program if qtBuildPreset.xml not present /// </summary> public static void CheckIfPresetFilePresent() { if (!File.Exists(PROGRAM_DIR + "qtBuildPreset.xml")) { Errors.ErrorExit(ErrorCode.BUILD_PRESET_MISSING); } }
/// <summary> /// Opens configuration file in default text editor. /// </summary> public static void OpenConfigFile() { try { System.Diagnostics.Process.Start(PROGRAM_DIR + Configuration.CONFIG_FILE_NAME); } catch { Errors.ErrorExit(ErrorCode.CONFIG_OPEN_ERROR); } }
/// <summary> /// Generates defines.pri and includes.pri files (with data from YourProject.vcxproj) /// </summary> /// <param name="projData">Reference to project parser</param> /// <returns>success</returns> public static void GenerateDefinesAndInclude(ProjectFileParser projData) { Console.WriteLine("Generating defines.pri and includes.pri...\n"); // Write files try { File.WriteAllText(projData.projectPath + "Intermediate\\ProjectFiles\\defines.pri", projData.GetEngineDefines()); File.WriteAllText(projData.projectPath + "Intermediate\\ProjectFiles\\includes.pri", projData.GetEngineIncludes()); } catch { Errors.ErrorExit(ErrorCode.DEFINES_AND_INCLUDES_WRITE_FAILED); } }
/// <summary> /// Retrieve engine defines in QtCreator format /// </summary> /// <returns>Qt formatted defines list</returns> public string GetEngineDefines() { string defines = ""; try { defines = ExtractEngineDefines(); } catch { Errors.ErrorExit(ErrorCode.DEFINES_AND_INCLUDES_READ_FAILED); } return(ConvertDefinesToQtFormat(defines)); }
/// <summary> /// Extract project name from .uproject filename /// </summary> /// <param name="projectDir">Directory which contains sln and uproject file</param> /// <returns>Project Name</returns> public static string ExtractProjectName(string projectDir) { string projectName = ""; foreach (string file in Directory.GetFiles(projectDir)) { if (file.EndsWith(".uproject")) // uproject file found { projectName = file.Substring(file.LastIndexOf('\\') + 1).Replace(".uproject", ""); break; } } if (projectName == "") { Errors.ErrorExit(ErrorCode.UPROJECT_NOT_FOUND); } return(projectName); }
/// <summary> /// Retrieve engine path from project file /// </summary> /// <returns></returns> public string GetEnginePath() { var match = Regex.Match(projectFileContent, GetUnrealPathRegexPattern()); if (!match.Success || match.Groups["path"] == null) { Errors.ErrorExit(ErrorCode.ENGINE_PATH_NOT_FOUND_IN_PROJECT_FILE); } string path = match.Groups["path"].Value; if (!File.Exists(path + @"\Engine\Build\BatchFiles\build.bat")) { Errors.ErrorExit(ErrorCode.INVALID_ENGINE_PATH_FOUND); } path = path.Replace("\\", "/"); return(path); }
/// <summary> /// Loads content of the code project file into projectFileContent /// </summary> /// <param name="projectPath">Path to the project folder</param> /// <param name="projectName">Name of .uproject file</param> public ProjectFileParser(string projectPath, string projectName) { this.projectPath = projectPath; this.projectName = projectName; try { projectFileContent = LoadProjectFile(projectPath, projectName); uprojectFilePath = projectPath + projectName + ".uproject"; if (!File.Exists(uprojectFilePath)) { Errors.ErrorExit(ErrorCode.UPROJECT_NOT_FOUND); } } catch { Errors.ErrorExit(ErrorCode.CODE_PROJECT_FILE_READ_FAILED); } }
/// <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); } }
/// <summary> /// This method will generate and apply a modified qt.pro.user file, which contains build presets for UE4 /// </summary> /// <param name="projData">Reference to project parser</param> /// <returns>success</returns> public static void GenerateQtBuildPreset(ProjectFileParser projData) { // Helper variable which stores the retrieved Unreal Engine Version (currently not needed) //string UnrealVersion; // These variables are used to replace parts of the qtBuildPreset.xml file to match your project and Unreal Engine installation string UPROJ_FILE, UNREAL_PATH, PROJECT_DIR, PROJECT_NAME, QT_ENV_ID, QT_CONF_ID; QT_ENV_ID = Configuration.data.qtCreatorEnvironmentId; QT_CONF_ID = Configuration.data.qtCreatorUnrealConfigurationId; // Set project name PROJECT_NAME = projData.projectName; // Set project directory PROJECT_DIR = projData.projectPath; // Set project file path UPROJ_FILE = projData.uprojectFilePath; // set engine path UNREAL_PATH = projData.GetEnginePath(); // Load user file preset String qtBuildPreset = ""; try { qtBuildPreset = File.ReadAllText(FileActions.PROGRAM_DIR + "qtBuildPreset.xml"); } catch { Errors.ErrorExit(ErrorCode.BUILD_PRESET_READ_FAILED); } // Replace preset variables with actual values qtBuildPreset = qtBuildPreset.Replace("$PROJECT_NAME", PROJECT_NAME); qtBuildPreset = qtBuildPreset.Replace("$PROJECT_DIR", PROJECT_DIR); qtBuildPreset = qtBuildPreset.Replace("$UPROJ_FILE", UPROJ_FILE); qtBuildPreset = qtBuildPreset.Replace("$UNREAL_PATH", UNREAL_PATH); qtBuildPreset = qtBuildPreset.Replace("$QT_ENV_ID", QT_ENV_ID); qtBuildPreset = qtBuildPreset.Replace("$QT_CONF_ID", QT_CONF_ID); // remove -rocket for custom engine builds if (!projData.IsLauncherBuild()) { qtBuildPreset = qtBuildPreset.Replace("-rocket", ""); } // Write new user file try { File.WriteAllText(projData.projectPath + "Intermediate\\ProjectFiles\\" + projData.projectName + ".pro.user", qtBuildPreset); } catch { Errors.ErrorExit(ErrorCode.QT_PRO_USERFILE_WRITE_FAILED); } Console.WriteLine("User file written successfully."); }
/// <summary> /// Run a small wizard which is able to autodetect the Qt Creator ids /// </summary> public static void StartConfigWizard() { PrintHeader(); ConfigurationData newConfig = new ConfigurationData(); Console.WriteLine("It seems that you run this program for the first time as no configuration file was found.\n"); Console.WriteLine("This program now needs to detect your Qt environment id and the id of your Unreal Engine build kit.\n\n"); Console.WriteLine("When you now press enter, an empty project will be opened in QtCreator."); Console.WriteLine("The only thing you have to do is:\n\n 1. Select your Unreal Engine build kit when asked by QtCreator\n 2. Hit the configure project button\n 3. Close QtCreator.\n"); Console.WriteLine("Please make sure that QtCreator is not currently running, then press enter to proceed..."); Console.ReadLine(); File.WriteAllText(FileActions.PROGRAM_DIR + "temp.pro", ""); Process qtCreatorProcess = Process.Start(FileActions.PROGRAM_DIR + "temp.pro"); Console.WriteLine("QtCreator launched, waiting for user interaction..."); qtCreatorProcess.WaitForExit(); Console.WriteLine("QtCreator closed...\n"); PrintHeader(); if (!File.Exists(FileActions.PROGRAM_DIR + "temp.pro.user")) { Errors.ErrorExit(ErrorCode.QT_PRO_USERFILE_MISSING); } string userContent = ""; try { userContent = File.ReadAllText(FileActions.PROGRAM_DIR + "temp.pro.user"); } catch { Errors.ErrorExit(ErrorCode.QT_PRO_USERFILE_READ_FAILED); } try { File.Delete(FileActions.PROGRAM_DIR + "temp.pro.user"); File.Delete(FileActions.PROGRAM_DIR + "temp.pro"); } catch { Console.WriteLine("\nERROR: Error while deleting temporary pro file."); } const string middle_env_id_pattern = "\\{[0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12}\\}"; var envMatch = Regex.Match(userContent, "\\<variable\\>EnvironmentId\\</variable\\>[\\s]*\n[\\s]*\\<value type=\"QByteArray\"\\>(?<id>" + middle_env_id_pattern + ")"); if (envMatch.Success && Configuration.IsValidQtId(envMatch.Groups["id"].Value)) { newConfig.qtCreatorEnvironmentId = envMatch.Groups["id"].Value; } else { Errors.ErrorExit(ErrorCode.ENVIRONMENT_ID_NOT_FOUND); } var confMatch = Regex.Match(userContent, "key=\"ProjectExplorer.ProjectConfiguration.Id\"\\>(?<id>" + middle_env_id_pattern + ")"); if (confMatch.Success && Configuration.IsValidQtId(confMatch.Groups["id"].Value)) { newConfig.qtCreatorUnrealConfigurationId = confMatch.Groups["id"].Value; } else { Errors.ErrorExit(ErrorCode.CONFIGURATION_ID_NOT_FOUND); } if (!Configuration.WriteWizardConfig(newConfig)) { Errors.ErrorExit(ErrorCode.CONFIGURATION_WRITE_FAILED); } }