diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs
index 7a68bc66..532a4ed6 100644
--- a/Vocaluxe/Base/CConfig.cs
+++ b/Vocaluxe/Base/CConfig.cs
@@ -35,7 +35,15 @@ namespace Vocaluxe.Base
{
static class CConfig
{
- private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
+ ///
+ /// Uniform settings for writing XML files. ALWAYS use this!
+ ///
+ public static readonly XmlWriterSettings XMLSettings = new XmlWriterSettings
+ {
+ Indent = true,
+ Encoding = Encoding.UTF8,
+ ConformanceLevel = ConformanceLevel.Document
+ };
// Debug
public static EDebugLevel DebugLevel = EDebugLevel.TR_CONFIG_OFF;
@@ -142,10 +150,6 @@ namespace Vocaluxe.Base
public static void Init()
{
- _Settings.Indent = true;
- _Settings.Encoding = Encoding.UTF8;
- _Settings.ConformanceLevel = ConformanceLevel.Document;
-
SongFolder.Add(Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderSongs));
#if INSTALLER
@@ -304,7 +308,7 @@ namespace Vocaluxe.Base
XmlWriter writer = null;
try
{
- writer = XmlWriter.Create(Path.Combine(CSettings.DataPath, CSettings.FileConfig));
+ writer = XmlWriter.Create(Path.Combine(CSettings.DataPath, CSettings.FileConfig), XMLSettings);
writer.WriteStartDocument();
writer.WriteStartElement("root");
diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs
index 7dd65963..ebadc6fd 100644
--- a/Vocaluxe/Base/CMain.cs
+++ b/Vocaluxe/Base/CMain.cs
@@ -21,6 +21,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
+using System.Xml;
using Vocaluxe.Base.Fonts;
using VocaluxeLib;
using VocaluxeLib.Game;
@@ -141,6 +142,11 @@ namespace Vocaluxe.Base
{
return CConfig.GetMaxNumMics();
}
+
+ public XmlWriterSettings GetXMLSettings()
+ {
+ return CConfig.XMLSettings;
+ }
}
class CBsettings : ISettings
diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs
index 7f08c8e9..2133e6c6 100644
--- a/Vocaluxe/Base/CTheme.cs
+++ b/Vocaluxe/Base/CTheme.cs
@@ -107,7 +107,6 @@ namespace Vocaluxe.Base
private const int _SkinSystemVersion = 3;
#region Vars
- private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
private static readonly List _Themes = new List();
public static string[] ThemeNames
{
@@ -148,10 +147,6 @@ namespace Vocaluxe.Base
#region Theme and Skin loading and writing
public static void InitTheme()
{
- _Settings.Indent = true;
- _Settings.Encoding = Encoding.UTF8;
- _Settings.ConformanceLevel = ConformanceLevel.Document;
-
_ListThemes();
ListSkins();
@@ -291,7 +286,7 @@ namespace Vocaluxe.Base
private static void _SaveTheme(int themeIndex)
{
#region ThemeMainFile
- using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].FileName), _Settings))
+ using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].FileName), CConfig.XMLSettings))
{
writer.WriteStartDocument();
writer.WriteStartElement("root");
@@ -333,7 +328,7 @@ namespace Vocaluxe.Base
{
for (int skinIndex = 0; skinIndex < _Skins.Count; skinIndex++)
{
- using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[skinIndex].Path, _Skins[skinIndex].FileName), _Settings))
+ using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[skinIndex].Path, _Skins[skinIndex].FileName), CConfig.XMLSettings))
{
writer.WriteStartDocument();
writer.WriteStartElement("root");
diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs
index 1ea3e611..13c154e4 100644
--- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs
+++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs
@@ -31,33 +31,22 @@ namespace Vocaluxe.Lib.Playlist
{
public class CPlaylistFile
{
- private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
-
public string PlaylistName;
public string PlaylistFile;
public List Songs = new List();
public CPlaylistFile()
{
- _Init();
PlaylistName = string.Empty;
PlaylistFile = string.Empty;
}
public CPlaylistFile(string file)
{
- _Init();
PlaylistFile = file;
_LoadPlaylist();
}
- private void _Init()
- {
- _Settings.Indent = true;
- _Settings.Encoding = Encoding.UTF8;
- _Settings.ConformanceLevel = ConformanceLevel.Document;
- }
-
public void SavePlaylist()
{
if (PlaylistFile == "")
@@ -88,7 +77,7 @@ namespace Vocaluxe.Lib.Playlist
XmlWriter writer;
try
{
- writer = XmlWriter.Create(PlaylistFile, _Settings);
+ writer = XmlWriter.Create(PlaylistFile, CConfig.XMLSettings);
}
catch (Exception e)
{
@@ -147,7 +136,7 @@ namespace Vocaluxe.Lib.Playlist
Songs = new List();
List songs = xmlReader.GetValues("Songs");
- EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL;
+ var gm = EGameMode.TR_GAMEMODE_NORMAL;
foreach (string song in songs)
{
@@ -157,7 +146,7 @@ namespace Vocaluxe.Lib.Playlist
xmlReader.GetValue("//root/Songs/" + song + "/Title", out title, String.Empty);
xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm);
- CPlaylistSong playlistSong = new CPlaylistSong {SongID = -1};
+ var playlistSong = new CPlaylistSong {SongID = -1};
foreach (CSong curSong in CSongs.AllSongs)
{
@@ -182,14 +171,14 @@ namespace Vocaluxe.Lib.Playlist
public void AddSong(int songID)
{
- CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = CSongs.GetSong(songID).IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL};
+ var song = new CPlaylistSong {SongID = songID, GameMode = CSongs.GetSong(songID).IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL};
Songs.Add(song);
}
public void AddSong(int songID, EGameMode gm)
{
- CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = gm};
+ var song = new CPlaylistSong {SongID = songID, GameMode = gm};
Songs.Add(song);
}
@@ -216,7 +205,7 @@ namespace Vocaluxe.Lib.Playlist
if (sourceNr < 0 || destNr < 0 || sourceNr == destNr || sourceNr > Songs.Count - 1 || destNr > Songs.Count - 1)
return;
- CPlaylistSong ps = new CPlaylistSong(Songs[sourceNr]);
+ var ps = new CPlaylistSong(Songs[sourceNr]);
Songs.RemoveAt(sourceNr);
Songs.Insert(destNr, ps);
}
@@ -226,7 +215,7 @@ namespace Vocaluxe.Lib.Playlist
if (destNr < 0 || destNr > Songs.Count - 1)
return;
- CPlaylistSong ps = new CPlaylistSong(songID, gm);
+ var ps = new CPlaylistSong(songID, gm);
Songs.Insert(destNr, ps);
}
}
diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs
index fc9871a8..b8389d92 100644
--- a/VocaluxeLib/IBasic.cs
+++ b/VocaluxeLib/IBasic.cs
@@ -21,6 +21,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
+using System.Xml;
using VocaluxeLib.Draw;
using VocaluxeLib.Game;
using VocaluxeLib.Menu;
@@ -54,6 +55,11 @@ namespace VocaluxeLib
bool IsMicConfigured(int playerNr);
int GetMaxNumMics();
+
+ ///
+ /// Get the uniform settings for writing XML files. ALWAYS use this!
+ ///
+ XmlWriterSettings GetXMLSettings();
}
public interface ISettings
diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs
index 4a3021b9..4c42bf0a 100644
--- a/VocaluxeLib/Menu/CMenu.cs
+++ b/VocaluxeLib/Menu/CMenu.cs
@@ -151,7 +151,7 @@ namespace VocaluxeLib.Menu
{
foreach (string elName in elements)
{
- T element = (T)Activator.CreateInstance(typeof(T), _PartyModeID);
+ var element = (T)Activator.CreateInstance(typeof(T), _PartyModeID);
if (element.LoadTheme("//root/" + ThemeName, elName, xmlReader, skinIndex))
addElementHandler(element, elName);
else
@@ -198,10 +198,8 @@ namespace VocaluxeLib.Menu
if (_ThemePath == "")
return;
- XmlWriterSettings settings = new XmlWriterSettings {Indent = true, Encoding = Encoding.UTF8, ConformanceLevel = ConformanceLevel.Document};
-
string file = Path.Combine(_ThemePath, ThemeName + ".xml");
- using (XmlWriter writer = XmlWriter.Create(file, settings))
+ using (XmlWriter writer = XmlWriter.Create(file, CBase.Config.GetXMLSettings()))
{
writer.WriteStartDocument();
writer.WriteStartElement("root");
@@ -770,7 +768,7 @@ namespace VocaluxeLib.Menu
if (_Interactions.Count <= 0)
return;
- List items = new List();
+ var items = new List();
for (int i = 0; i < _Interactions.Count; i++)
{
@@ -779,7 +777,7 @@ namespace VocaluxeLib.Menu
_Interactions[i].Type != EType.NameSelection && _Interactions[i].Type != EType.Text && _Interactions[i].Type != EType.SongMenu &&
_Interactions[i].Type != EType.Equalizer && _Interactions[i].Type != EType.Playlist && _Interactions[i].Type != EType.ParticleEffect))
continue;
- SZSort zs = new SZSort {ID = i, Z = _GetZValue(i)};
+ var zs = new SZSort {ID = i, Z = _GetZValue(i)};
items.Add(zs);
}
@@ -1105,10 +1103,10 @@ namespace VocaluxeLib.Menu
///
private bool _NextInteraction(SKeyEvent key)
{
- SKeyEvent[] directions = new SKeyEvent[4];
- float[] distances = new float[4];
- int[] stages = new int[4];
- int[] elements = new int[4];
+ var directions = new SKeyEvent[4];
+ var distances = new float[4];
+ var stages = new int[4];
+ var elements = new int[4];
for (int i = 0; i < 4; i++)
directions[i] = new SKeyEvent();
@@ -1248,11 +1246,11 @@ namespace VocaluxeLib.Menu
private float _GetDistanceDirect(SKeyEvent key, SRectF actualRect, SRectF targetRect)
{
- PointF source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f);
- PointF dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f);
+ var source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f);
+ var dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f);
- PointF vector = new PointF(dest.X - source.X, dest.Y - source.Y);
- float distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y);
+ var vector = new PointF(dest.X - source.X, dest.Y - source.Y);
+ var distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y);
bool inDirection = false;
switch (key.Key)
{
@@ -1281,11 +1279,11 @@ namespace VocaluxeLib.Menu
private float _GetDistance180(SKeyEvent key, SRectF actualRect, SRectF targetRect)
{
- PointF source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f);
- PointF dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f);
+ var source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f);
+ var dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f);
- PointF vector = new PointF(dest.X - source.X, dest.Y - source.Y);
- float distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y);
+ var vector = new PointF(dest.X - source.X, dest.Y - source.Y);
+ var distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y);
bool inDirection = false;
switch (key.Key)
{
@@ -1584,7 +1582,7 @@ namespace VocaluxeLib.Menu
private SRectF _GetRect(CInteraction interaction)
{
- SRectF result = new SRectF();
+ var result = new SRectF();
switch (interaction.Type)
{
case EType.Button:
@@ -1808,7 +1806,7 @@ namespace VocaluxeLib.Menu
private void _LoadThemeBasics(CXMLReader xmlReader, int skinIndex)
{
// Backgrounds
- CBackground background = new CBackground(_PartyModeID);
+ var background = new CBackground(_PartyModeID);
int i = 1;
while (background.LoadTheme("//root/" + ThemeName, "Background" + i, xmlReader, skinIndex))
{
@@ -1818,7 +1816,7 @@ namespace VocaluxeLib.Menu
}
// Statics
- CStatic stat = new CStatic(_PartyModeID);
+ var stat = new CStatic(_PartyModeID);
i = 1;
while (stat.LoadTheme("//root/" + ThemeName, "Static" + i, xmlReader, skinIndex))
{
@@ -1828,7 +1826,7 @@ namespace VocaluxeLib.Menu
}
// Texts
- CText text = new CText(_PartyModeID);
+ var text = new CText(_PartyModeID);
i = 1;
while (text.LoadTheme("//root/" + ThemeName, "Text" + i, xmlReader, skinIndex))
{
@@ -1838,7 +1836,7 @@ namespace VocaluxeLib.Menu
}
// ParticleEffects
- CParticleEffect partef = new CParticleEffect(_PartyModeID);
+ var partef = new CParticleEffect(_PartyModeID);
i = 1;
while (partef.LoadTheme("//root/" + ThemeName, "ParticleEffect" + i, xmlReader, skinIndex))
{
diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs
index 11c9b840..e823b323 100644
--- a/VocaluxeLib/Profile/CProfile.cs
+++ b/VocaluxeLib/Profile/CProfile.cs
@@ -26,13 +26,6 @@ namespace VocaluxeLib.Profile
{
public class CProfile
{
- private static readonly XmlWriterSettings _Settings = new XmlWriterSettings
- {
- Indent = true,
- Encoding = Encoding.UTF8,
- ConformanceLevel = ConformanceLevel.Document
- };
-
public int ID;
public string PlayerName;
@@ -107,7 +100,7 @@ namespace VocaluxeLib.Profile
public void SaveProfile()
{
if (String.IsNullOrEmpty(FilePath))
- FilePath = Path.Combine(CBase.Settings.GetDataPath(),CBase.Settings.GetFolderProfiles());
+ FilePath = Path.Combine(CBase.Settings.GetDataPath(), CBase.Settings.GetFolderProfiles());
if (FileName == String.Empty)
{
string filename = string.Empty;
@@ -139,7 +132,7 @@ namespace VocaluxeLib.Profile
XmlWriter writer;
try
{
- writer = XmlWriter.Create(Path.Combine(FilePath, FileName), _Settings);
+ writer = XmlWriter.Create(Path.Combine(FilePath, FileName), CBase.Config.GetXMLSettings());
}
catch (Exception e)
{