/// <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 void When_ReadingRepeatedly() { var configIni = new ConfigIni(); var textStringReaderA = new StringReader(";CommentA\n;CommentB"); var textStringReaderB = new StringReader(";CommentC\n;CommentD"); Assert.That(() => configIni.Read(textStringReaderA), Throws.Nothing); Assert.That(() => configIni.Read(textStringReaderB), Throws.Nothing); Assert.That(configIni.Sections, Has.Count.EqualTo(1)); Assert.That(configIni.Sections[0].Name, Is.Null); Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(1)); Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <CommentToken>()); var commentToken = configIni.Sections[0].Tokens[0] as CommentToken; Assert.That(commentToken.Lines, Has.Count.EqualTo(4)); }
public void When_Unmodified_DoesRetainEverything(string original) { var config = new ConfigIni(); config.Read(new StringReader(original)); var writer = new StringWriter(); config.Write(writer); Assert.That(writer.ToString(), Is.EqualTo(original)); }
public void When_ReaderHasMultipleEmptyLines() { var configIni = new ConfigIni(); var textStringReader = new StringReader("\n\n\n\n"); Assert.That(() => configIni.Read(textStringReader), Throws.Nothing); Assert.That(configIni.Sections, Has.Count.EqualTo(1)); Assert.That(configIni.Sections[0].Name, Is.Null); Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(1)); Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <WhitespaceToken>()); var whitespaceToken = configIni.Sections[0].Tokens[0] as WhitespaceToken; Assert.That(whitespaceToken.Lines, Has.Count.EqualTo(4)); }
public void When_ReadConfig_DefaultGame() { //Create a new config with a name for identification var config = new ConfigIni("DefaultGame"); //Load the configs contents from a file config.Read(File.OpenText(TestUtils.GetTestDataPath("MockProject/Config/DefaultGame.ini"))); //Evaluate the values and put them into a list. Should the property only have a single value, the list will have a single element. //Should the property not exist or should all its values have been deleted via config, the list will be empty. var values = new List <string>(); config.EvaluatePropertyValues("/Script/EngineSettings.GeneralProjectSettings", "ProjectID", values); Assert.That(values, Is.EquivalentTo(new[] { "3F9D696D4363312194B0ECB2671E899F" })); }
public void When_UnmodifiedFile_IsUnchanged(string file) { var filePath = TestUtils.GetTestDataPath(file); var reader = File.OpenText(filePath); var config = new ConfigIni(); config.Read(reader); reader.Close(); var fileContent = File.ReadAllText(filePath); var writer = new StringWriter(); config.Write(writer); var writerContent = writer.ToString(); Assert.That(writerContent, Is.EqualTo(fileContent)); }
public void When_ReaderHasMultipleValidLines() { var configIni = new ConfigIni(); string textString = String.Join("\n", new[] { ";Comment", "", "[Header]", "Key=Value" }); var textStringReader = new StringReader(textString); Assert.That(() => configIni.Read(textStringReader), Throws.Nothing); Assert.That(configIni.Sections, Has.Count.EqualTo(2)); Assert.That(configIni.Sections[0].Name, Is.Null); Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(2)); Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <CommentToken>()); Assert.That(configIni.Sections[0].Tokens[1], Is.TypeOf <WhitespaceToken>()); Assert.That(configIni.Sections[1].Tokens, Has.Count.EqualTo(1)); Assert.That(configIni.Sections[1].Tokens[0], Is.TypeOf <InstructionToken>()); }
private void LoadConfig() { if (File.Exists(ConfigIni.Path)) { KeepOldversion = ConfigIni.Read("KeepLastVersion", "Updater") == "1"; KeepInstaller = ConfigIni.Read("KeepInstaller", "Updater") == "1"; var lastpath = ConfigIni.Read("LastPath", "Updater"); if (!string.IsNullOrEmpty(lastpath)) { var bk = Path.GetFullPath(lastpath); if (Directory.Exists(bk)) { SelectedPath = bk; } return; } } if (TryGetCurrChromeExePath(out string path)) { SelectedPath = Path.GetDirectoryName(path); } }