/// <summary> /// Reads a config hierarchy (or retrieve it from the cache) /// </summary> /// <param name="Type">The type of hierarchy to read</param> /// <param name="ProjectDir">The project directory to read the hierarchy for</param> /// <param name="Platform">Which platform to read platform-specific config files for</param> /// <param name="GeneratedConfigDir">Base directory for generated configs</param> /// <returns>The requested config hierarchy</returns> public static ConfigHierarchy ReadHierarchy(ConfigHierarchyType Type, DirectoryReference ProjectDir, UnrealTargetPlatform Platform, DirectoryReference GeneratedConfigDir = null) { // Get the key to use for the cache. It cannot be null, so we use the engine directory if a project directory is not given. ConfigHierarchyKey Key = new ConfigHierarchyKey(Type, ProjectDir, Platform); // Try to get the cached hierarchy with this key ConfigHierarchy Hierarchy; if (!HierarchyKeyToHierarchy.TryGetValue(Key, out Hierarchy)) { List <ConfigFile> Files = new List <ConfigFile>(); foreach (FileReference IniFileName in ConfigHierarchy.EnumerateConfigFileLocations(Type, ProjectDir, Platform)) { ConfigFile File; if (TryReadFile(IniFileName, out File)) { Files.Add(File); } } // If we haven't been given a generated project dir, but we do have a project then the generated configs // should go into ProjectDir/Saved if (GeneratedConfigDir == null && ProjectDir != null) { GeneratedConfigDir = DirectoryReference.Combine(ProjectDir, "Saved"); } if (GeneratedConfigDir != null) { // We know where the generated version of this config file lives, so we can read it back in // and include any user settings from there in our hierarchy string BaseIniName = Enum.GetName(typeof(ConfigHierarchyType), Type); string PlatformName = ConfigHierarchy.GetIniPlatformName(Platform); FileReference DestinationIniFilename = FileReference.Combine(GeneratedConfigDir, "Config", PlatformName, BaseIniName + ".ini"); ConfigFile File; if (TryReadFile(DestinationIniFilename, out File)) { Files.Add(File); } } // Handle command line overrides string[] CmdLine = Environment.GetCommandLineArgs(); string IniConfigArgPrefix = "-ini:" + Enum.GetName(typeof(ConfigHierarchyType), Type) + ":"; foreach (string CmdLineArg in CmdLine) { if (CmdLineArg.StartsWith(IniConfigArgPrefix)) { ConfigFile OverrideFile = new ConfigFile(CmdLineArg.Substring(IniConfigArgPrefix.Length)); Files.Add(OverrideFile); } } Hierarchy = new ConfigHierarchy(Files); HierarchyKeyToHierarchy.Add(Key, Hierarchy); } return(Hierarchy); }