public static ConfigHierarchyLevelRange AnyFrom(ConfigHierarchyLevel from) { var range = new ConfigHierarchyLevelRange(from, from); range.m_HasTo = false; return(range); }
/// <summary> /// Load config from filesystem /// </summary> protected virtual ConfigIni LoadConfig(string platform, string category, ConfigHierarchyLevel level) { var filePath = GetConfigFilePath(platform, category, level); if (filePath == null) { return(null); } StreamReader reader; try { reader = File.OpenText(filePath); } catch (DirectoryNotFoundException) { return(null); } catch (FileNotFoundException) { return(null); } var config = new ConfigIni(Path.GetFileName(filePath)); config.Read(reader); reader.Close(); return(config); }
public static ConfigHierarchyLevelRange AnyTo(ConfigHierarchyLevel to) { var range = new ConfigHierarchyLevelRange(to, to); range.m_HasFrom = false; return(range); }
public void AnyTo(ConfigHierarchyLevel level) { var range = ConfigHierarchyLevelRange.AnyTo(level); Assert.That(range.IncludesAnything, Is.True); Assert.That(range.HasTo, Is.True); Assert.That(range.To, Is.EqualTo(level)); Assert.That(range.HasFrom, Is.False); }
public void When_CachingConfig(string platform, string category, ConfigHierarchyLevel level) { var hierarchy = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\"); var dummyConfig = new ConfigIni(); hierarchy.Exposed_CacheConfig(platform, category, level, dummyConfig); var gotConfig = hierarchy.Exposed_GetCachedConfig(platform, category, level); Assert.That(gotConfig, Is.SameAs(dummyConfig)); }
public void When_OrderIsFlipped(ConfigHierarchyLevel from, ConfigHierarchyLevel to) { var range = new ConfigHierarchyLevelRange(from, to); Assert.That(range.From, Is.EqualTo(to)); Assert.That(range.To, Is.EqualTo(from)); Assert.That(range.IncludesAnything, Is.True); Assert.That(range.HasTo, Is.True); Assert.That(range.HasFrom, Is.True); }
public void When_IsSingleLevel(ConfigHierarchyLevel level) { var range = new ConfigHierarchyLevelRange(level, level); Assert.That(range.From, Is.EqualTo(level)); Assert.That(range.To, Is.EqualTo(range.From)); Assert.That(range.IncludesAnything, Is.True); Assert.That(range.HasTo, Is.True); Assert.That(range.HasFrom, Is.True); }
/// <summary> /// Constructs the file path that would lead to the requested config file /// </summary> public virtual string GetConfigFilePath(string platform, string category, ConfigHierarchyLevel level) { switch (level) { case ConfigHierarchyLevel.Base: return(Path.Combine(Environment.CurrentDirectory, EnginePath, ConfigDirName, $"{BaseConfigFilePrefix}.ini")); case ConfigHierarchyLevel.BaseCategory: return(Path.Combine(Environment.CurrentDirectory, EnginePath, ConfigDirName, $"{BaseConfigFilePrefix}{category}.ini")); case ConfigHierarchyLevel.BasePlatformCategory: if (platform == DefaultPlatform) { return(null); } else { if (CheckEngineHasPlatformExtension(platform)) { //Return new config path return(Path.Combine(GenerateEnginePlatformExtensionConfigDirPath(platform), $"{platform}{category}.ini")); } else { //Return legacy config path return(Path.Combine(Environment.CurrentDirectory, EnginePath, ConfigDirName, platform, $"{platform}{category}.ini")); } } case ConfigHierarchyLevel.ProjectCategory: return(Path.Combine(Environment.CurrentDirectory, ProjectPath, ConfigDirName, $"{DefaultConfigFilePrefix}{category}.ini")); case ConfigHierarchyLevel.ProjectPlatformCategory: if (platform == DefaultPlatform) { return(null); } else { if (CheckProjectHasPlatformExtension(platform)) { //Return new config path return(Path.Combine(GenerateProjectPlatformExtensionConfigDirPath(platform), $"{platform}{category}.ini")); } else { //Return legacy config path return(Path.Combine(Environment.CurrentDirectory, ProjectPath, ConfigDirName, platform, $"{platform}{category}.ini")); } } default: throw new InvalidEnumArgumentException(nameof(level), (int)level, typeof(ConfigHierarchyLevel)); } }
public void When_CalledWithValidLevel(string platform, string category, ConfigHierarchyLevel level) { var hierarchy = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\") { }; var path = hierarchy.GetConfigFilePath(platform, category, level); Assert.That(path, Is.Not.Null); Assert.That(path, Is.Not.Empty); }
public bool Includes(ConfigHierarchyLevel level) { if (!IncludesAnything) { return(false); } if (HasFrom && level < From) { return(false); } if (HasTo && level > To) { return(false); } return(true); }
public ConfigHierarchyLevelRange(ConfigHierarchyLevel from, ConfigHierarchyLevel to) { m_IncludesAnything = true; m_HasFrom = true; m_HasTo = true; if (from <= to) { From = from; To = to; } else { To = from; From = to; } }
public override ConfigIni GetConfig(string platform, string category, ConfigHierarchyLevel level) { ConfigIni config = null; if (!IsConfigCached(platform, category, level)) { config = LoadConfig(platform, category, level); CacheConfig(platform, category, level, config); } else { config = GetCachedConfig(platform, category, level); } return(config); }
public void When_CalledWithoutPlatform_RelaysToDefaultPlatform() { int spyCount = 0; string latestRequestedPlatform = null; string latestRequestedCategory = null; ConfigHierarchyLevel latestRequestedLevel = (ConfigHierarchyLevel)(-1); Dictionary <ConfigHierarchyLevel, ConfigIni> expectedConfigs = new Dictionary <ConfigHierarchyLevel, ConfigIni>(); expectedConfigs[ConfigHierarchyLevel.Base] = new ConfigIni("Base.ini"); expectedConfigs[ConfigHierarchyLevel.BaseCategory] = new ConfigIni("BaseMyCategory.ini"); expectedConfigs[ConfigHierarchyLevel.BasePlatformCategory] = new ConfigIni("DefaultMyCategory.ini"); var hierarchy = new MockConfigHierarchy() { OnSpyGetConfig = (platform, category, level) => { spyCount++; Assert.That(level, Is.GreaterThan(latestRequestedLevel)); Assert.That(category, Is.EqualTo("MyCategory")); Assert.That(platform, Is.EqualTo("Default")); latestRequestedPlatform = platform; latestRequestedCategory = category; latestRequestedLevel = level; ConfigIni config; if (expectedConfigs.TryGetValue(level, out config)) { return(config); } return(null); } }; var configs = new List <ConfigIni>(); hierarchy.GetConfigs("MyCategory", configs); Assert.That(spyCount, Is.GreaterThanOrEqualTo(1)); Assert.That(configs, Is.EquivalentTo(expectedConfigs.Values)); Assert.That(latestRequestedLevel, Is.EqualTo(ConfigHierarchyLevel.ProjectPlatformCategory)); Assert.That(latestRequestedCategory, Is.EqualTo("MyCategory")); Assert.That(latestRequestedPlatform, Is.EqualTo("Default")); }
protected virtual bool IsConfigCached(string platform, string category, ConfigHierarchyLevel level) { return(m_ConfigCache.ContainsKey(new ConfigKey(platform, category, level))); }
public ConfigKey(string platform, string category, ConfigHierarchyLevel level) { Platform = platform; Category = category; Level = level; }
protected virtual void CacheConfig(string platform, string category, ConfigHierarchyLevel level, ConfigIni config) { var key = new ConfigKey(platform, category, level); m_ConfigCache[key] = config; }
protected virtual ConfigIni GetCachedConfig(string platform, string category, ConfigHierarchyLevel level) { ConfigIni result; if (m_ConfigCache.TryGetValue(new ConfigKey(platform, category, level), out result)) { return(result); } return(null); }
public string When_LegacyAndPlatformExtensionConfigFilesExist(string projectPath, string enginePath, string platform, string category, ConfigHierarchyLevel level) { var hierarchy = new MockFileConfigHierarchy(projectPath, enginePath) { }; string path = hierarchy.GetConfigFilePath(platform, category, level); return(path); }
public ConfigIni Exposed_LoadConfig(string platform, string category, ConfigHierarchyLevel level) { return(LoadConfig(platform, category, level)); }
public void When_Negative(ConfigHierarchyLevel from, ConfigHierarchyLevel to, ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.FromTo(from, to).Includes(test), Is.False); }
public void All(ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.All().Includes(test), Is.True); }
public void When_Negative(ConfigHierarchyLevel level, ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.Exact(level).Includes(test), Is.False); }
/// <summary> /// Returns the default config of the given <see cref="category"/> and the given <see cref="level"/>, if available. /// Returns null otherwise. /// <seealso cref="GetConfig(string,string,UE4Config.Hierarchy.ConfigHierarchyLevel)"/> /// </summary> public ConfigIni GetConfig(string category, ConfigHierarchyLevel level) { return(GetConfig(DefaultPlatform, category, level)); }
public void When_Positive(ConfigHierarchyLevel to, ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.AnyTo(to).Includes(test), Is.True); }
public void When_Positive(ConfigHierarchyLevel from, ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.AnyFrom(from).Includes(test), Is.True); }
public static ConfigHierarchyLevelRange Exact(ConfigHierarchyLevel level) { return(new ConfigHierarchyLevelRange(level, level)); }
public void Exposed_CacheConfig(string platform, string category, ConfigHierarchyLevel level, ConfigIni config) { CacheConfig(platform, category, level, config); }
/// <summary> /// Returns the platform config of the given <see cref="category"/> and the given <see cref="level"/>, if available. /// Returns null otherwise. /// </summary> public abstract ConfigIni GetConfig(string platform, string category, ConfigHierarchyLevel level);
public void None(ConfigHierarchyLevel test) { Assert.That(ConfigHierarchyLevelRange.None().Includes(test), Is.False); }
public static ConfigHierarchyLevelRange FromTo(ConfigHierarchyLevel from, ConfigHierarchyLevel to) { return(new ConfigHierarchyLevelRange(from, to)); }