/// <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); } }
/// <summary> /// Load data from configuration file /// Atm the function only loads 2 values (because there are only two settings), but it could easily be extended to detect more settings. /// </summary> /// <returns>True if valid configuration was read and stored in data field</returns> public static bool LoadConfiguration() { data = new ConfigurationData(); if (!File.Exists(FileActions.PROGRAM_DIR + CONFIG_FILE_NAME)) { return false; } string[] config = File.ReadAllLines(FileActions.PROGRAM_DIR + CONFIG_FILE_NAME); string line = ""; for (int i = 0; i < config.Length; ++i) { line = config[i]; // ignore comments if (line.Contains("\'")) line = line.Remove(line.IndexOf('\'')); line = line.Trim(); string[] key_val_pair = line.Split('='); // skip line if no key value pair was found if (line == "" || key_val_pair.Length != 2) continue; key_val_pair[0] = key_val_pair[0].Trim(); key_val_pair[1] = key_val_pair[1].Trim(); switch (key_val_pair[0]) { case "qt_environment_id": data.qtCreatorEnvironmentId = key_val_pair[1]; if (!Regex.Match(data.qtCreatorEnvironmentId, ENV_ID_PATTERN).Success) { Console.WriteLine("CONFIG ERROR: Invalid QtCreator environment ID set."); return false; } break; case "unreal_project_configuration_id": data.qtCreatorUnrealConfigurationId = key_val_pair[1]; if (!Regex.Match(data.qtCreatorUnrealConfigurationId, ENV_ID_PATTERN).Success) { Console.WriteLine("CONFIG ERROR: Invalid QtCreator configuration ID set."); return false; } break; default: Console.WriteLine("CONFIG ERROR: Configuration parse error.\n"); return false; } } if (data.qtCreatorEnvironmentId == "" || data.qtCreatorUnrealConfigurationId == "") return false; return true; }
/// <summary> /// Writes the initial configuration file /// </summary> /// <param name="data">Data to write</param> /// <returns>True if successful</returns> public static bool WriteWizardConfig(ConfigurationData data) { string file = ""; file += "[General]\r\n\r\n"; file += "' These values can be found in a .pro.user file of a project on this computer which uses (exclusively) your Unreal Engine build kit.\r\n"; file += "qt_environment_id = " + data.qtCreatorEnvironmentId + "\r\n"; file += "unreal_project_configuration_id = " + data.qtCreatorUnrealConfigurationId + "\r\n\r\n"; try { File.WriteAllText(FileActions.PROGRAM_DIR + CONFIG_FILE_NAME, file); } catch { return false; } return true; }