Use always the same xml writer settings

This commit is contained in:
Flamefire committed 2013-10-18 23:40:23 +02:00
1 parent 3b82d5c13c
commit 3a8acecd5c
7 files changed
+54 -63

No files matched your search

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