From d36333d7785ef573033d3a180e83bc5941e63b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20Uslu?= Date: Tue, 15 Jan 2013 18:07:00 +0200 Subject: [PATCH] Renamed ConfigManager as SettingsManager. Renamed Config.cs as SettingsReader.cs. Initial work done for https://github.com/raistlinthewiz/voxeliq/issues/45. --- assets/config.ini | 4 ---- src/Engine/Common/Logging/FileTarget.cs | 10 +++++----- src/Engine/Core/Config/EngineConfig.cs | 1 + src/game/Program.cs | 3 --- src/game/Settings/Readers/AudioSettings.cs | 2 +- src/game/Settings/Readers/GraphicsSettings.cs | 2 +- src/game/Settings/Readers/LogSettings.cs | 13 ++----------- .../{ConfigManager.cs => SettingsManager.cs} | 4 ++-- src/game/Settings/{Config.cs => SettingsReader.cs} | 8 ++++---- src/game/VoxeliqGame.Windows.XNA.csproj | 4 ++-- 10 files changed, 18 insertions(+), 33 deletions(-) rename src/game/Settings/{ConfigManager.cs => SettingsManager.cs} (96%) rename src/game/Settings/{Config.cs => SettingsReader.cs} (86%) diff --git a/assets/config.ini b/assets/config.ini index ebd19c6..a30a111 100644 --- a/assets/config.ini +++ b/assets/config.ini @@ -16,10 +16,6 @@ Enabled = false; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; General logging settings -[Logging] -Root=logs - ; Settings for console logger [ConsoleLog] Enabled=true diff --git a/src/Engine/Common/Logging/FileTarget.cs b/src/Engine/Common/Logging/FileTarget.cs index 20c5619..bd4af36 100644 --- a/src/Engine/Common/Logging/FileTarget.cs +++ b/src/Engine/Common/Logging/FileTarget.cs @@ -15,6 +15,8 @@ namespace VoxeliqEngine.Common.Logging /// public class FileTarget : LogTarget, IDisposable { + private const string LogRoot = "logs"; + private readonly string _fileName; // log-file's filename. private readonly string _filePath; // log-file's full path. private FileStream _fileStream; // filestream pointing to logfile. @@ -30,16 +32,14 @@ public class FileTarget : LogTarget, IDisposable /// Reset log file on application startup? public FileTarget(string fileName, Logger.Level minLevel, Logger.Level maxLevel, bool includeTimeStamps, bool reset = false) { - var logRoot = "logs"; - this.MinimumLevel = minLevel; this.MaximumLevel = maxLevel; this.IncludeTimeStamps = includeTimeStamps; this._fileName = fileName; - this._filePath = string.Format("{0}/{1}", logRoot, _fileName); // construct the full path using LoggingRoot defined in config.ini + this._filePath = string.Format("{0}/{1}", LogRoot, _fileName); // construct the full path using LoggingRoot defined in config.ini - if (!Directory.Exists(logRoot)) // create logging directory if it does not exist yet. - Directory.CreateDirectory(logRoot); + if (!Directory.Exists(LogRoot)) // create logging directory if it does not exist yet. + Directory.CreateDirectory(LogRoot); this._fileStream = new FileStream(_filePath, reset ? FileMode.Create : FileMode.Append, FileAccess.Write, FileShare.Read); // init the file stream. this._logStream = new StreamWriter(this._fileStream) { AutoFlush = true }; // init the stream writer. diff --git a/src/Engine/Core/Config/EngineConfig.cs b/src/Engine/Core/Config/EngineConfig.cs index b13ef3b..f7c2812 100644 --- a/src/Engine/Core/Config/EngineConfig.cs +++ b/src/Engine/Core/Config/EngineConfig.cs @@ -51,6 +51,7 @@ public EngineConfig() /// internal bool Validate() { + // valide all the subconfigurations. if (!this.Chunk.Validate()) return false; diff --git a/src/game/Program.cs b/src/game/Program.cs index 568ac8b..18eed2b 100644 --- a/src/game/Program.cs +++ b/src/game/Program.cs @@ -39,9 +39,6 @@ private static void Main(string[] args) InitLoggers(); // init logging facility. - // print version information. - var frameworkVersion = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Game)).GetName().Version; - Logger.Info("voxeliq v{0} warming-up..", Assembly.GetAssembly(typeof (Player)).GetName().Version); Logger.Info(string.Format("Using framework {0} over {1}.", VersionInfo.GameFramework, VersionInfo.GraphicsApi)); diff --git a/src/game/Settings/Readers/AudioSettings.cs b/src/game/Settings/Readers/AudioSettings.cs index 29d2bd4..9da50f8 100644 --- a/src/game/Settings/Readers/AudioSettings.cs +++ b/src/game/Settings/Readers/AudioSettings.cs @@ -7,7 +7,7 @@ namespace VoxeliqGame.Settings.Readers { - public sealed class AudioSettings : Config + public sealed class AudioSettings : SettingsReader { /// /// Is audio enabled? diff --git a/src/game/Settings/Readers/GraphicsSettings.cs b/src/game/Settings/Readers/GraphicsSettings.cs index 377914e..59d995a 100644 --- a/src/game/Settings/Readers/GraphicsSettings.cs +++ b/src/game/Settings/Readers/GraphicsSettings.cs @@ -7,7 +7,7 @@ namespace VoxeliqGame.Settings.Readers { - public sealed class GraphicsSettings : Config + public sealed class GraphicsSettings : SettingsReader { /// /// Sets the screen width. diff --git a/src/game/Settings/Readers/LogSettings.cs b/src/game/Settings/Readers/LogSettings.cs index 5a86a0e..78a6ac8 100644 --- a/src/game/Settings/Readers/LogSettings.cs +++ b/src/game/Settings/Readers/LogSettings.cs @@ -12,17 +12,8 @@ namespace VoxeliqGame.Settings.Readers /// /// Holds configuration info for log manager. /// - public sealed class LogSettings : Config + public sealed class LogSettings : SettingsReader { - /// - /// Gets or sets the logging root. - /// - public string LoggingRoot - { - get { return this.GetString("Root", @"logs"); } - set { this.Set("Root", value); } - } - /// /// Available log target configs. /// @@ -53,7 +44,7 @@ private LogSettings() : /// /// Holds configuration of a log target. /// - public class LogTargetConfig : Config + public class LogTargetConfig : SettingsReader { /// /// Is enabled? diff --git a/src/game/Settings/ConfigManager.cs b/src/game/Settings/SettingsManager.cs similarity index 96% rename from src/game/Settings/ConfigManager.cs rename to src/game/Settings/SettingsManager.cs index e8d47fb..da5f8ca 100644 --- a/src/game/Settings/ConfigManager.cs +++ b/src/game/Settings/SettingsManager.cs @@ -12,14 +12,14 @@ namespace VoxeliqGame.Settings { - public sealed class ConfigManager + public sealed class SettingsManager { private static readonly Logger Logger = LogManager.CreateLogger(); private static readonly IniConfigSource Parser; // the ini parser. private static readonly string ConfigFile; private static bool _fileExists = false; // does the ini file exists? - static ConfigManager() + static SettingsManager() { try { diff --git a/src/game/Settings/Config.cs b/src/game/Settings/SettingsReader.cs similarity index 86% rename from src/game/Settings/Config.cs rename to src/game/Settings/SettingsReader.cs index d41a704..a47bc64 100644 --- a/src/game/Settings/Config.cs +++ b/src/game/Settings/SettingsReader.cs @@ -9,18 +9,18 @@ namespace VoxeliqGame.Settings { - public class Config + public class SettingsReader { private readonly IConfig _section; - public Config(string sectionName) + public SettingsReader(string sectionName) { - this._section = ConfigManager.Section(sectionName) ?? ConfigManager.AddSection(sectionName); + this._section = SettingsManager.Section(sectionName) ?? SettingsManager.AddSection(sectionName); } public void Save() { - ConfigManager.Save(); + SettingsManager.Save(); } protected bool GetBoolean(string key, bool defaultValue) { return this._section.GetBoolean(key, defaultValue); } diff --git a/src/game/VoxeliqGame.Windows.XNA.csproj b/src/game/VoxeliqGame.Windows.XNA.csproj index 9cebf5c..f8cf917 100644 --- a/src/game/VoxeliqGame.Windows.XNA.csproj +++ b/src/game/VoxeliqGame.Windows.XNA.csproj @@ -119,8 +119,8 @@ - - + +