From 7da58b4b3f683af6ab72d4ee9d94e9ca1a216f66 Mon Sep 17 00:00:00 2001 From: RiJo Date: Fri, 19 Dec 2014 11:21:58 +0100 Subject: [PATCH] Derive IniFile from Dictionary --- MediaOrganizer/IniFile.cs | 27 ++++++++------------------- MediaOrganizer/MediaOrganizer.cs | 6 +++--- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/MediaOrganizer/IniFile.cs b/MediaOrganizer/IniFile.cs index c5fdf53..1919952 100644 --- a/MediaOrganizer/IniFile.cs +++ b/MediaOrganizer/IniFile.cs @@ -1,5 +1,5 @@ // -// IniFile.cs: Data structure used to save/load ini files. +// IniFile.cs: Data structure used to save/load an ini file. // // Copyright (C) 2014 Rikard Johansson // @@ -17,6 +17,7 @@ // using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -25,25 +26,13 @@ namespace ExifOrganizer.Organizer { - public class IniFile + public class IniFile : Dictionary { - private Dictionary values = new Dictionary(); - public IniFile() + : base() { } - public string this[string key] - { - get { return values[key]; } - set { values[key] = value; } - } - - public bool Contains(string key) - { - return values.ContainsKey(key); - } - public bool TryLoad(string filename) { try @@ -64,7 +53,7 @@ public void Load(string filename) if (!File.Exists(filename)) throw new FileNotFoundException(filename); - values.Clear(); + Clear(); foreach (string line in File.ReadAllLines(filename)) { @@ -79,7 +68,7 @@ public void Load(string filename) string key = keyValue[0].Trim(); string value = keyValue[1].Trim(); - values[key] = value; + Add(key, value); } } @@ -102,9 +91,9 @@ public void Save(string filename) throw new ArgumentNullException("filename"); List lines = new List(); - foreach (string key in values.Keys) + foreach (KeyValuePair kvp in this) { - string line = String.Format("{0}: {1}", key, values[key]); + string line = String.Format("{0}: {1}", kvp.Key, kvp.Value); lines.Add(line); } diff --git a/MediaOrganizer/MediaOrganizer.cs b/MediaOrganizer/MediaOrganizer.cs index a782440..9a11565 100644 --- a/MediaOrganizer/MediaOrganizer.cs +++ b/MediaOrganizer/MediaOrganizer.cs @@ -154,11 +154,11 @@ public void LoadConfig() { IniFile iniFile = new IniFile(); iniFile.TryLoad(iniFilePath); - if (iniFile.Contains("sourcePath")) + if (iniFile.ContainsKey("sourcePath")) sourcePath = iniFile["sourcePath"]; - if (iniFile.Contains("destinationPath")) + if (iniFile.ContainsKey("destinationPath")) destinationPath = iniFile["destinationPath"]; - if (iniFile.Contains("recursive")) + if (iniFile.ContainsKey("recursive")) Recursive = iniFile["recursive"] == "1"; }