All Projects → rickyah → Ini Parser

rickyah / Ini Parser

Licence: mit
Read/Write an INI file the easy way!

Projects that are alternatives of or similar to Ini Parser

parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (-86.63%)
Mutual labels:  config, configuration, configuration-management, ini
libconfini
Yet another INI parser
Stars: ✭ 106 (-83.51%)
Mutual labels:  config, configuration, configuration-management, ini
config-parser
A slim, fully managed C# library for reading/writing .ini, .conf, .cfg etc configuration files.
Stars: ✭ 67 (-89.58%)
Mutual labels:  config, mono, configuration, ini
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+42.3%)
Mutual labels:  config, configuration-management, config-management, configuration
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+18.04%)
Mutual labels:  cli, config, configuration
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (-65.01%)
Mutual labels:  config, config-management, ini
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-96.89%)
Mutual labels:  config, configuration, configuration-management
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-94.87%)
Mutual labels:  config, configuration, configuration-management
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (-30.02%)
Mutual labels:  config, configuration-management, configuration
apollo.net
Apollo配置中心.Net客户端
Stars: ✭ 449 (-30.17%)
Mutual labels:  config-management, configuration, configuration-management
dotfiles
My personal app/env configs and dotfiles.
Stars: ✭ 27 (-95.8%)
Mutual labels:  config, configuration, configuration-management
Config
PHP library for simple configuration management
Stars: ✭ 39 (-93.93%)
Mutual labels:  config, config-management, ini
Centraldogma
Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2
Stars: ✭ 378 (-41.21%)
Mutual labels:  config, configuration-management, configuration
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-74.34%)
Mutual labels:  config, configuration-management, configuration
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (-88.8%)
Mutual labels:  config, configuration-management, ini
Gcfg
read INI-style configuration files into Go structs; supports user-defined types and subsections
Stars: ✭ 146 (-77.29%)
Mutual labels:  config, ini, configuration
Config
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Pandrino and other Ruby projects.
Stars: ✭ 1,821 (+183.2%)
Mutual labels:  config, configuration-management, configuration
Config
A lightweight yet powerful config package for Go projects
Stars: ✭ 126 (-80.4%)
Mutual labels:  config, config-management, configuration
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+188.49%)
Mutual labels:  config, configuration-management, configuration
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-96.89%)
Mutual labels:  config, configuration, configuration-management

INI File Parser

A .NET, Mono and Unity3d compatible(*) library for reading/writing INI data from IO streams, file streams, and strings written in C#.

Also implements merging operations, both for complete ini files, sections, or even just a subset of the keys contained by the files.

(*) This library is 100% .NET code and does not have any dependencies on Windows API calls in order to be portable.

Build Status

Get the latest version: https://github.com/rickyah/ini-parser/releases/latest Install it with NuGet: https://www.nuget.org/packages/ini-parser/

Version 2.0

Since the INI format isn't really a "standard", version 2 introduces a simpler way to customize INI parsing:

  • Pass a configuration object to an IniParser, specifying the behaviour of the parser. A default implementation is used if none is provided.

  • Derive from IniDataParser and override the fine-grained parsing methods.

Installation

The library is published to NuGet and can be installed on the command-line from the directory containing your solution.

> nuget install ini-parser

Or, from the Package Manager Console in Visual Studio

PM> Install-Package ini-parser

If you are using Visual Studio, you can download the NuGet Package Manager extension that will allow adding the NuGet dependency for your project.

If you use MonoDevelop / Xamarin Studio, you can install the MonoDevelop NuGet AddIn to also be able to add this library as dependency from the IDE.

Getting Started

All code examples expect the following using clauses:

using IniParser;
using IniParser.Model;

INI data is stored in nested dictionaries, so accessing the value associated to a key in a section is straightforward. Load the data using one of the provided methods.

var parser = new FileIniDataParser();
IniData data = parser.ReadFile("Configuration.ini");

Retrieve the value for a key inside of a named section. Values are always retrieved as strings.

string useFullScreenStr = data["UI"]["fullscreen"];
// useFullScreenStr contains "true"
bool useFullScreen = bool.Parse(useFullScreenStr);

Modify the value in the dictionary, not the value retrieved, and save to a new file or overwrite.

data["UI"]["fullscreen"] = "true";
parser.WriteFile("Configuration.ini", data);

Head to the wiki for more usage examples, or check out the code of the example project

Merging ini files

Merging ini files is a one-method operation:

   var parser = new IniParser.Parser.IniDataParser();

   IniData config = parser.Parse(File.ReadAllText("global_config.ini"));
   IniData user_config = parser.Parse(File.ReadAllText("user_config.ini"));
   config.Merge(user_config);

   // config now contains that data from both ini files, and the values of
   // the keys and sections are overwritten with the values of the keys and
   // sections that also existed in the user config file

Keep in mind that you can merge individual sections if you like:

config["user_settings"].Merge(user_config["user_settings"]);

Comments

The library allows modifying the comments from an ini file. However note than writing the file back to disk, the comments will be rearranged so comments are written before the element they refer to.

To query, add or remove comments, access the property Comments available both in SectionData and KeyData models.

var listOfCommentsForSection = config.["user_settings"].Comments;
var listOfCommentsForKey = config["user_settings"].GetKeyData("resolution").Comments;

Unity3D

You can easily use this library in your Unity3D projects. Just drop either the code or the DLL inside your project's Assets folder and you're ready to go!

ini-parser is actually being used in ProjectPrefs a free add-on available in the Unity Assets Store that allows you to set custom preferences for your project. I'm not affiliated with this project: Kudos to Garrafote for making this add-on.

Contributing

Do you have an idea to improve this library, or did you happen to run into a bug? Please share your idea or the bug you found in the issues page, or even better: feel free to fork and contribute to this project with a Pull Request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].