diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index ecd3d5c1..03f86f73 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -284,270 +284,279 @@ namespace Vocaluxe.Base public static bool SaveConfig() { - XmlWriter writer = XmlWriter.Create(CSettings.sFileConfig, _settings); - writer.WriteStartDocument(); - writer.WriteStartElement("root"); - - #region Info - writer.WriteStartElement("Info"); - - writer.WriteElementString("Version", CSettings.GetFullVersionText()); - writer.WriteElementString("Time", System.DateTime.Now.ToString()); - writer.WriteElementString("Platform", System.Environment.OSVersion.Platform.ToString()); - writer.WriteElementString("OSVersion", System.Environment.OSVersion.ToString()); - writer.WriteElementString("ProcessorCount", System.Environment.ProcessorCount.ToString()); - - writer.WriteElementString("Screens", Screen.AllScreens.Length.ToString()); - writer.WriteElementString("PrimaryScreenResolution", Screen.PrimaryScreen.Bounds.Size.ToString()); - - writer.WriteElementString("Directory", System.Environment.CurrentDirectory.ToString()); - - writer.WriteEndElement(); - #endregion Info - - #region Debug - writer.WriteStartElement("Debug"); - - writer.WriteComment("DebugLevel: " + CHelper.ListStrings(Enum.GetNames(typeof(EDebugLevel)))); - writer.WriteElementString("DebugLevel", Enum.GetName(typeof(EDebugLevel), DebugLevel)); - - writer.WriteEndElement(); - #endregion Debug - - #region Graphics - writer.WriteStartElement("Graphics"); - - writer.WriteComment("Renderer: " + CHelper.ListStrings(Enum.GetNames(typeof(ERenderer)))); - writer.WriteElementString("Renderer", Enum.GetName(typeof(ERenderer), Renderer)); - - writer.WriteComment("TextureQuality: " + CHelper.ListStrings(Enum.GetNames(typeof(ETextureQuality)))); - writer.WriteElementString("TextureQuality", Enum.GetName(typeof(ETextureQuality), TextureQuality)); - - writer.WriteComment("CoverSize (pixels): 32, 64, 128, 256, 512, 1024 (default: 128)"); - writer.WriteElementString("CoverSize", CoverSize.ToString()); - - writer.WriteComment("Screen width and height (pixels)"); - writer.WriteElementString("ScreenW", ScreenW.ToString()); - writer.WriteElementString("ScreenH", ScreenH.ToString()); - - writer.WriteComment("AAMode: " + CHelper.ListStrings(Enum.GetNames(typeof(EAntiAliasingModes)))); - writer.WriteElementString("AAMode", Enum.GetName(typeof(EAntiAliasingModes), AAMode)); - - writer.WriteComment("Colors: " + CHelper.ListStrings(Enum.GetNames(typeof(EColorDeep)))); - writer.WriteElementString("Colors", Enum.GetName(typeof(EColorDeep), Colors)); - - writer.WriteComment("MaxFPS should be between 1..200"); - writer.WriteElementString("MaxFPS", MaxFPS.ToString("#")); - - writer.WriteComment("VSync: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("VSync", Enum.GetName(typeof(EOffOn), VSync)); - - writer.WriteComment("FullScreen: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("FullScreen", Enum.GetName(typeof(EOffOn), FullScreen)); - - writer.WriteComment("FadeTime should be between 0..3 Seconds"); - writer.WriteElementString("FadeTime", FadeTime.ToString("#0.00")); - - writer.WriteEndElement(); - #endregion Graphics - - #region Theme - writer.WriteStartElement("Theme"); - - writer.WriteComment("Theme name"); - writer.WriteElementString("Name", Theme); - - writer.WriteComment("Skin name"); - writer.WriteElementString("Skin", Skin); - - writer.WriteComment("Name of cover-theme"); - writer.WriteElementString("Cover", CoverTheme); - - writer.WriteComment("Draw note-lines:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("DrawNoteLines", Enum.GetName(typeof(EOffOn), DrawNoteLines)); - - writer.WriteComment("Draw tone-helper:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("DrawToneHelper", Enum.GetName(typeof(EOffOn), DrawToneHelper)); - - writer.WriteComment("Look of timer:" + CHelper.ListStrings(Enum.GetNames(typeof(ETimerLook)))); - writer.WriteElementString("TimerLook", Enum.GetName(typeof(ETimerLook), TimerLook)); - - writer.WriteComment("Information about players on SingScreen:" + CHelper.ListStrings(Enum.GetNames(typeof(EPlayerInfo)))); - writer.WriteElementString("PlayerInfo", Enum.GetName(typeof(EPlayerInfo), PlayerInfo)); - - writer.WriteComment("Fade player-information with lyrics and notebars:" + CHelper.ListStrings(Enum.GetNames(typeof(EFadePlayerInfo)))); - writer.WriteElementString("FadePlayerInfo", Enum.GetName(typeof(EFadePlayerInfo), FadePlayerInfo)); - - writer.WriteComment("Cover Loading:" + CHelper.ListStrings(Enum.GetNames(typeof(ECoverLoading)))); - writer.WriteElementString("CoverLoading", Enum.GetName(typeof(ECoverLoading), CoverLoading)); - - writer.WriteComment("Lyric Style:" + CHelper.ListStrings(Enum.GetNames(typeof(ELyricStyle)))); - writer.WriteElementString("LyricStyle", Enum.GetName(typeof(ELyricStyle), LyricStyle)); - - writer.WriteEndElement(); - #endregion Theme - - #region Sound - writer.WriteStartElement("Sound"); - - writer.WriteComment("PlayBackLib: " + CHelper.ListStrings(Enum.GetNames(typeof(EPlaybackLib)))); - writer.WriteElementString("PlayBackLib", Enum.GetName(typeof(EPlaybackLib), PlayBackLib)); - - writer.WriteComment("RecordLib: " + CHelper.ListStrings(Enum.GetNames(typeof(ERecordLib)))); - writer.WriteElementString("RecordLib", Enum.GetName(typeof(ERecordLib), RecordLib)); - - writer.WriteComment("AudioBufferSize: " + CHelper.ListStrings(Enum.GetNames(typeof(EBufferSize)))); - writer.WriteElementString("AudioBufferSize", Enum.GetName(typeof(EBufferSize), AudioBufferSize)); - - writer.WriteComment("AudioLatency from -500 to 500 ms"); - writer.WriteElementString("AudioLatency", AudioLatency.ToString()); - - writer.WriteComment("Background Music"); - writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic)); - - writer.WriteComment("Background Music Volume from 0 to 100"); - writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString()); - - writer.WriteComment("Background Music Source"); - writer.WriteElementString("BackgroundMusicSource", Enum.GetName(typeof(EBackgroundMusicSource), BackgroundMusicSource)); - - writer.WriteComment("Preview Volume from 0 to 100"); - writer.WriteElementString("PreviewMusicVolume", PreviewMusicVolume.ToString()); - - writer.WriteComment("Game Volume from 0 to 100"); - writer.WriteElementString("GameMusicVolume", GameMusicVolume.ToString()); - - writer.WriteEndElement(); - #endregion Sound - - #region Game - writer.WriteStartElement("Game"); - - writer.WriteComment("Game-Language:"); - writer.WriteElementString("Language", Language); - - // SongFolder - // Check, if program was started with songfolder-parameters - if (SongFolderOld.Count > 0) + XmlWriter writer = null; + try { - //Write "old" song-folders to config. - writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); - for (int i = 0; i < SongFolderOld.Count; i++) + writer = XmlWriter.Create(CSettings.sFileConfig, _settings); + writer.WriteStartDocument(); + writer.WriteStartElement("root"); + + #region Info + writer.WriteStartElement("Info"); + + writer.WriteElementString("Version", CSettings.GetFullVersionText()); + writer.WriteElementString("Time", System.DateTime.Now.ToString()); + writer.WriteElementString("Platform", System.Environment.OSVersion.Platform.ToString()); + writer.WriteElementString("OSVersion", System.Environment.OSVersion.ToString()); + writer.WriteElementString("ProcessorCount", System.Environment.ProcessorCount.ToString()); + + writer.WriteElementString("Screens", Screen.AllScreens.Length.ToString()); + writer.WriteElementString("PrimaryScreenResolution", Screen.PrimaryScreen.Bounds.Size.ToString()); + + writer.WriteElementString("Directory", System.Environment.CurrentDirectory.ToString()); + + writer.WriteEndElement(); + #endregion Info + + #region Debug + writer.WriteStartElement("Debug"); + + writer.WriteComment("DebugLevel: " + CHelper.ListStrings(Enum.GetNames(typeof(EDebugLevel)))); + writer.WriteElementString("DebugLevel", Enum.GetName(typeof(EDebugLevel), DebugLevel)); + + writer.WriteEndElement(); + #endregion Debug + + #region Graphics + writer.WriteStartElement("Graphics"); + + writer.WriteComment("Renderer: " + CHelper.ListStrings(Enum.GetNames(typeof(ERenderer)))); + writer.WriteElementString("Renderer", Enum.GetName(typeof(ERenderer), Renderer)); + + writer.WriteComment("TextureQuality: " + CHelper.ListStrings(Enum.GetNames(typeof(ETextureQuality)))); + writer.WriteElementString("TextureQuality", Enum.GetName(typeof(ETextureQuality), TextureQuality)); + + writer.WriteComment("CoverSize (pixels): 32, 64, 128, 256, 512, 1024 (default: 128)"); + writer.WriteElementString("CoverSize", CoverSize.ToString()); + + writer.WriteComment("Screen width and height (pixels)"); + writer.WriteElementString("ScreenW", ScreenW.ToString()); + writer.WriteElementString("ScreenH", ScreenH.ToString()); + + writer.WriteComment("AAMode: " + CHelper.ListStrings(Enum.GetNames(typeof(EAntiAliasingModes)))); + writer.WriteElementString("AAMode", Enum.GetName(typeof(EAntiAliasingModes), AAMode)); + + writer.WriteComment("Colors: " + CHelper.ListStrings(Enum.GetNames(typeof(EColorDeep)))); + writer.WriteElementString("Colors", Enum.GetName(typeof(EColorDeep), Colors)); + + writer.WriteComment("MaxFPS should be between 1..200"); + writer.WriteElementString("MaxFPS", MaxFPS.ToString("#")); + + writer.WriteComment("VSync: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("VSync", Enum.GetName(typeof(EOffOn), VSync)); + + writer.WriteComment("FullScreen: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("FullScreen", Enum.GetName(typeof(EOffOn), FullScreen)); + + writer.WriteComment("FadeTime should be between 0..3 Seconds"); + writer.WriteElementString("FadeTime", FadeTime.ToString("#0.00")); + + writer.WriteEndElement(); + #endregion Graphics + + #region Theme + writer.WriteStartElement("Theme"); + + writer.WriteComment("Theme name"); + writer.WriteElementString("Name", Theme); + + writer.WriteComment("Skin name"); + writer.WriteElementString("Skin", Skin); + + writer.WriteComment("Name of cover-theme"); + writer.WriteElementString("Cover", CoverTheme); + + writer.WriteComment("Draw note-lines:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("DrawNoteLines", Enum.GetName(typeof(EOffOn), DrawNoteLines)); + + writer.WriteComment("Draw tone-helper:" + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("DrawToneHelper", Enum.GetName(typeof(EOffOn), DrawToneHelper)); + + writer.WriteComment("Look of timer:" + CHelper.ListStrings(Enum.GetNames(typeof(ETimerLook)))); + writer.WriteElementString("TimerLook", Enum.GetName(typeof(ETimerLook), TimerLook)); + + writer.WriteComment("Information about players on SingScreen:" + CHelper.ListStrings(Enum.GetNames(typeof(EPlayerInfo)))); + writer.WriteElementString("PlayerInfo", Enum.GetName(typeof(EPlayerInfo), PlayerInfo)); + + writer.WriteComment("Fade player-information with lyrics and notebars:" + CHelper.ListStrings(Enum.GetNames(typeof(EFadePlayerInfo)))); + writer.WriteElementString("FadePlayerInfo", Enum.GetName(typeof(EFadePlayerInfo), FadePlayerInfo)); + + writer.WriteComment("Cover Loading:" + CHelper.ListStrings(Enum.GetNames(typeof(ECoverLoading)))); + writer.WriteElementString("CoverLoading", Enum.GetName(typeof(ECoverLoading), CoverLoading)); + + writer.WriteComment("Lyric Style:" + CHelper.ListStrings(Enum.GetNames(typeof(ELyricStyle)))); + writer.WriteElementString("LyricStyle", Enum.GetName(typeof(ELyricStyle), LyricStyle)); + + writer.WriteEndElement(); + #endregion Theme + + #region Sound + writer.WriteStartElement("Sound"); + + writer.WriteComment("PlayBackLib: " + CHelper.ListStrings(Enum.GetNames(typeof(EPlaybackLib)))); + writer.WriteElementString("PlayBackLib", Enum.GetName(typeof(EPlaybackLib), PlayBackLib)); + + writer.WriteComment("RecordLib: " + CHelper.ListStrings(Enum.GetNames(typeof(ERecordLib)))); + writer.WriteElementString("RecordLib", Enum.GetName(typeof(ERecordLib), RecordLib)); + + writer.WriteComment("AudioBufferSize: " + CHelper.ListStrings(Enum.GetNames(typeof(EBufferSize)))); + writer.WriteElementString("AudioBufferSize", Enum.GetName(typeof(EBufferSize), AudioBufferSize)); + + writer.WriteComment("AudioLatency from -500 to 500 ms"); + writer.WriteElementString("AudioLatency", AudioLatency.ToString()); + + writer.WriteComment("Background Music"); + writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic)); + + writer.WriteComment("Background Music Volume from 0 to 100"); + writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString()); + + writer.WriteComment("Background Music Source"); + writer.WriteElementString("BackgroundMusicSource", Enum.GetName(typeof(EBackgroundMusicSource), BackgroundMusicSource)); + + writer.WriteComment("Preview Volume from 0 to 100"); + writer.WriteElementString("PreviewMusicVolume", PreviewMusicVolume.ToString()); + + writer.WriteComment("Game Volume from 0 to 100"); + writer.WriteElementString("GameMusicVolume", GameMusicVolume.ToString()); + + writer.WriteEndElement(); + #endregion Sound + + #region Game + writer.WriteStartElement("Game"); + + writer.WriteComment("Game-Language:"); + writer.WriteElementString("Language", Language); + + // SongFolder + // Check, if program was started with songfolder-parameters + if (SongFolderOld.Count > 0) { - writer.WriteElementString("SongFolder" + (i + 1).ToString(), SongFolderOld[i]); + //Write "old" song-folders to config. + writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); + for (int i = 0; i < SongFolderOld.Count; i++) + { + writer.WriteElementString("SongFolder" + (i + 1).ToString(), SongFolderOld[i]); + } } - } - else - { - //Write "normal" song-folders to config. - writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); - for (int i = 0; i < SongFolder.Count; i++) + else { - writer.WriteElementString("SongFolder" + (i + 1).ToString(), SongFolder[i]); + //Write "normal" song-folders to config. + writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); + for (int i = 0; i < SongFolder.Count; i++) + { + writer.WriteElementString("SongFolder" + (i + 1).ToString(), SongFolder[i]); + } } - } - writer.WriteComment("SongMenu: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongMenu)))); - writer.WriteElementString("SongMenu", Enum.GetName(typeof(ESongMenu), SongMenu)); + writer.WriteComment("SongMenu: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongMenu)))); + writer.WriteElementString("SongMenu", Enum.GetName(typeof(ESongMenu), SongMenu)); - writer.WriteComment("SongSorting: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongSorting)))); - writer.WriteElementString("SongSorting", Enum.GetName(typeof(ESongSorting), SongSorting)); + writer.WriteComment("SongSorting: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongSorting)))); + writer.WriteElementString("SongSorting", Enum.GetName(typeof(ESongSorting), SongSorting)); - writer.WriteComment("Ignore articles on song-sorting: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("IgnoreArticles", Enum.GetName(typeof(EOffOn), IgnoreArticles)); + writer.WriteComment("Ignore articles on song-sorting: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("IgnoreArticles", Enum.GetName(typeof(EOffOn), IgnoreArticles)); - writer.WriteComment("ScoreAnimationTime: Values >= 1 or 0 for no animation. Time is in seconds."); - writer.WriteElementString("ScoreAnimationTime", ScoreAnimationTime.ToString()); + writer.WriteComment("ScoreAnimationTime: Values >= 1 or 0 for no animation. Time is in seconds."); + writer.WriteElementString("ScoreAnimationTime", ScoreAnimationTime.ToString()); - writer.WriteComment("TimerMode: " + CHelper.ListStrings(Enum.GetNames(typeof(ETimerMode)))); - writer.WriteElementString("TimerMode", Enum.GetName(typeof(ETimerMode), TimerMode)); + writer.WriteComment("TimerMode: " + CHelper.ListStrings(Enum.GetNames(typeof(ETimerMode)))); + writer.WriteElementString("TimerMode", Enum.GetName(typeof(ETimerMode), TimerMode)); - writer.WriteComment("NumPlayer: 1.." + CSettings.MaxNumPlayer.ToString()); - writer.WriteElementString("NumPlayer", NumPlayer.ToString()); + writer.WriteComment("NumPlayer: 1.." + CSettings.MaxNumPlayer.ToString()); + writer.WriteElementString("NumPlayer", NumPlayer.ToString()); - writer.WriteComment("Order songs in tabs: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("Tabs", Enum.GetName(typeof(EOffOn), Tabs)); + writer.WriteComment("Order songs in tabs: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("Tabs", Enum.GetName(typeof(EOffOn), Tabs)); - writer.WriteComment("Lyrics also on Top of screen: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("LyricsOnTop", Enum.GetName(typeof(EOffOn), LyricsOnTop)); + writer.WriteComment("Lyrics also on Top of screen: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("LyricsOnTop", Enum.GetName(typeof(EOffOn), LyricsOnTop)); - writer.WriteComment("MinLineBreakTime: Value >= 0 in s. Minimum time the text is shown before it is to be sung"); - writer.WriteElementString("MinLineBreakTime", MinLineBreakTime.ToString()); + writer.WriteComment("MinLineBreakTime: Value >= 0 in s. Minimum time the text is shown before it is to be sung"); + writer.WriteElementString("MinLineBreakTime", MinLineBreakTime.ToString()); - writer.WriteComment("Default profile for players 1..." + CSettings.MaxNumPlayer.ToString() + ":"); - writer.WriteStartElement("Players"); - for (int i = 1; i <= CSettings.MaxNumPlayer; i++) - { - writer.WriteElementString("Player" + i.ToString(), Path.GetFileName(Players[i - 1])); - } - writer.WriteEndElement(); - - writer.WriteEndElement(); - #endregion Game - - #region Video - writer.WriteStartElement("Video"); - - writer.WriteComment("VideoDecoder: " + CHelper.ListStrings(Enum.GetNames(typeof(EVideoDecoder)))); - writer.WriteElementString("VideoDecoder", Enum.GetName(typeof(EVideoDecoder), VideoDecoder)); - - writer.WriteComment("VideoBackgrounds: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("VideoBackgrounds", Enum.GetName(typeof(EOffOn), VideoBackgrounds)); - - writer.WriteComment("VideoPreview: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("VideoPreview", Enum.GetName(typeof(EOffOn), VideoPreview)); - - writer.WriteComment("Show Videos while singing: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("VideosInSongs", Enum.GetName(typeof(EOffOn), VideosInSongs)); - - writer.WriteComment("Show backgroundmusic videos as background: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("VideosToBackground", Enum.GetName(typeof(EOffOn), VideosToBackground)); - - writer.WriteComment("WebcamLib: " + CHelper.ListStrings(Enum.GetNames(typeof(EWebcamLib)))); - writer.WriteElementString("WebcamLib", Enum.GetName(typeof(EWebcamLib), WebcamLib)); - - writer.WriteStartElement("WebcamConfig"); - - writer.WriteElementString("MonikerString", WebcamConfig.MonikerString); - writer.WriteElementString("Framerate", WebcamConfig.Framerate.ToString()); - writer.WriteElementString("Width", WebcamConfig.Width.ToString()); - writer.WriteElementString("Height", WebcamConfig.Height.ToString()); - - writer.WriteEndElement(); - - writer.WriteEndElement(); - #endregion Video - - #region Record - writer.WriteStartElement("Record"); - - for (int p = 1; p <= CSettings.MaxNumPlayer; p++) - { - if (MicConfig[p - 1].DeviceName != String.Empty && MicConfig[p - 1].InputName != String.Empty && MicConfig[p - 1].Channel > 0) + writer.WriteComment("Default profile for players 1..." + CSettings.MaxNumPlayer.ToString() + ":"); + writer.WriteStartElement("Players"); + for (int i = 1; i <= CSettings.MaxNumPlayer; i++) { - writer.WriteStartElement("MicConfig" + p.ToString()); - - writer.WriteElementString("DeviceName", MicConfig[p - 1].DeviceName); - writer.WriteElementString("DeviceDriver", MicConfig[p - 1].DeviceDriver); - writer.WriteElementString("InputName", MicConfig[p - 1].InputName); - writer.WriteElementString("Channel", MicConfig[p - 1].Channel.ToString()); - - writer.WriteEndElement(); + writer.WriteElementString("Player" + i.ToString(), Path.GetFileName(Players[i - 1])); } + writer.WriteEndElement(); + + writer.WriteEndElement(); + #endregion Game + + #region Video + writer.WriteStartElement("Video"); + + writer.WriteComment("VideoDecoder: " + CHelper.ListStrings(Enum.GetNames(typeof(EVideoDecoder)))); + writer.WriteElementString("VideoDecoder", Enum.GetName(typeof(EVideoDecoder), VideoDecoder)); + + writer.WriteComment("VideoBackgrounds: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("VideoBackgrounds", Enum.GetName(typeof(EOffOn), VideoBackgrounds)); + + writer.WriteComment("VideoPreview: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("VideoPreview", Enum.GetName(typeof(EOffOn), VideoPreview)); + + writer.WriteComment("Show Videos while singing: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("VideosInSongs", Enum.GetName(typeof(EOffOn), VideosInSongs)); + + writer.WriteComment("Show backgroundmusic videos as background: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); + writer.WriteElementString("VideosToBackground", Enum.GetName(typeof(EOffOn), VideosToBackground)); + + writer.WriteComment("WebcamLib: " + CHelper.ListStrings(Enum.GetNames(typeof(EWebcamLib)))); + writer.WriteElementString("WebcamLib", Enum.GetName(typeof(EWebcamLib), WebcamLib)); + + writer.WriteStartElement("WebcamConfig"); + + writer.WriteElementString("MonikerString", WebcamConfig.MonikerString); + writer.WriteElementString("Framerate", WebcamConfig.Framerate.ToString()); + writer.WriteElementString("Width", WebcamConfig.Width.ToString()); + writer.WriteElementString("Height", WebcamConfig.Height.ToString()); + + writer.WriteEndElement(); + + writer.WriteEndElement(); + #endregion Video + + #region Record + writer.WriteStartElement("Record"); + + for (int p = 1; p <= CSettings.MaxNumPlayer; p++) + { + if (MicConfig[p - 1].DeviceName != String.Empty && MicConfig[p - 1].InputName != String.Empty && MicConfig[p - 1].Channel > 0) + { + writer.WriteStartElement("MicConfig" + p.ToString()); + + writer.WriteElementString("DeviceName", MicConfig[p - 1].DeviceName); + writer.WriteElementString("DeviceDriver", MicConfig[p - 1].DeviceDriver); + writer.WriteElementString("InputName", MicConfig[p - 1].InputName); + writer.WriteElementString("Channel", MicConfig[p - 1].Channel.ToString()); + + writer.WriteEndElement(); + } + } + + writer.WriteComment("Mic delay in ms. 0, 20, 40, 60 ... 500"); + writer.WriteElementString("MicDelay", MicDelay.ToString()); + + writer.WriteEndElement(); + #endregion Record + + // End of File + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); + writer.Flush(); + writer.Close(); } - - writer.WriteComment("Mic delay in ms. 0, 20, 40, 60 ... 500"); - writer.WriteElementString("MicDelay", MicDelay.ToString()); - - writer.WriteEndElement(); - #endregion Record - - // End of File - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); - - writer.Flush(); - writer.Close(); + catch (Exception) + { + writer = null; + return false; + } + writer = null; return true; } diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 0019008e..622038ab 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -1439,90 +1439,80 @@ namespace Vocaluxe.Base if (File.Exists(ImagePath)) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; - SQLiteCommand command; - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return false; - } - command = new SQLiteCommand(connection); - - SQLiteDataReader reader = null; - - if (reader != null) - reader.Close(); - - Bitmap origin; - try - { - origin = new Bitmap(ImagePath); - } - catch (Exception) - { - CLog.LogError("Error loading Texture: " + ImagePath); - tex = new STexture(-1); - - if (reader != null) + connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; + try { - reader.Close(); - reader.Dispose(); + connection.Open(); } - command.Dispose(); - connection.Close(); - connection.Dispose(); + catch (Exception) + { + return false; + } + using (SQLiteCommand command = new SQLiteCommand(connection)) + { - return false; - } + Bitmap origin; + try + { + origin = new Bitmap(ImagePath); + } + catch (Exception) + { + CLog.LogError("Error loading Texture: " + ImagePath); + tex = new STexture(-1); - int w = origin.Width; - int h = origin.Height; + connection.Close(); - Bitmap bmp = new Bitmap(w, h); - Graphics g = Graphics.FromImage(bmp); - g.DrawImage(origin, new Rectangle(0, 0, w, h)); - g.Dispose(); - if (origin != null) - origin.Dispose(); - tex = CDraw.AddTexture(bmp); - byte[] data = new byte[w * h * 4]; + return false; + } - BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - Marshal.Copy(bmp_data.Scan0, data, 0, w * h * 4); - bmp.UnlockBits(bmp_data); - bmp.Dispose(); + int w = origin.Width; + int h = origin.Height; - command.CommandText = "INSERT INTO Images (Path, width, height) " + - "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; - command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = Path.GetFileName(ImagePath); - command.ExecuteNonQuery(); + Bitmap bmp = new Bitmap(w, h); + Graphics g = Graphics.FromImage(bmp); + g.DrawImage(origin, new Rectangle(0, 0, w, h)); + g.Dispose(); + origin.Dispose(); + tex = CDraw.AddTexture(bmp); + byte[] data = new byte[w * h * 4]; - command.CommandText = "SELECT id FROM Images WHERE [Path] = @path"; - command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = Path.GetFileName(ImagePath); - reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + Marshal.Copy(bmp_data.Scan0, data, 0, w * h * 4); + bmp.UnlockBits(bmp_data); + bmp.Dispose(); - if (reader != null) - { - reader.Read(); - int id = reader.GetInt32(0); - reader.Close(); - command.CommandText = "INSERT INTO ImageData (ImageID, Data) " + - "VALUES ('" + id.ToString() + "', @data)"; - command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; - command.ExecuteReader(); - result = true; + command.CommandText = "INSERT INTO Images (Path, width, height) " + + "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = Path.GetFileName(ImagePath); + command.ExecuteNonQuery(); + + command.CommandText = "SELECT id FROM Images WHERE [Path] = @path"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = Path.GetFileName(ImagePath); + SQLiteDataReader reader = null; + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + throw; + } + + if (reader != null) + { + reader.Read(); + int id = reader.GetInt32(0); + reader.Close(); + command.CommandText = "INSERT INTO ImageData (ImageID, Data) " + + "VALUES ('" + id.ToString() + "', @data)"; + command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; + command.ExecuteReader(); + result = true; + } + } } } diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index dbdc14f9..c190e0d2 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -135,11 +135,11 @@ namespace Vocaluxe.Base } } - class CFont + class CFont:IDisposable { private List _Glyphs; private Hashtable _htGlyphs; - private PrivateFontCollection fonts; + private PrivateFontCollection fonts = null; private FontFamily family; private float SIZEh; @@ -268,6 +268,16 @@ namespace Vocaluxe.Base } _Glyphs.Clear(); } + + public void Dispose() + { + if (fonts != null) + { + fonts.Dispose(); + fonts = null; + } + GC.SuppressFinalize(this); + } } struct SFont diff --git a/Vocaluxe/Base/CLog.cs b/Vocaluxe/Base/CLog.cs index ab2e1695..18d30681 100644 --- a/Vocaluxe/Base/CLog.cs +++ b/Vocaluxe/Base/CLog.cs @@ -6,11 +6,11 @@ using System.Text; namespace Vocaluxe.Base { - class Log + class Log:IDisposable { private string _LogFileName; private string _LogName; - private StreamWriter _LogFile; + private StreamWriter _LogFile = null; public Log(string FileName, string LogName) { @@ -56,6 +56,16 @@ namespace Vocaluxe.Base _LogFile.WriteLine("----------------------------------------"); _LogFile.WriteLine(); } + + public void Dispose() + { + if (_LogFile != null) + { + _LogFile.Dispose(); + _LogFile = null; + } + GC.SuppressFinalize(this); + } } static class CLog diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index ef7e5aa0..a77459f6 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -605,23 +605,11 @@ namespace Vocaluxe.Base public CSong GetVisibleSong(int VisibleIndex) { - if (VisibleIndex >= CSongs.NumVisibleSongs) - return null; - - CSong song = CSongs.VisibleSongs[VisibleIndex]; - //Flamefire: Why copy the song-instance??? Cover and stuff will be loaded twice! - //And for unknown reason causes no-big-cover bug if covers are not loaded on startup - return song; - //if (song == null) - // return null; - - //return new CSong(song); + return CSongs.GetVisibleSongByIndex(VisibleIndex); } public CSong GetSongByID(int SongID) { - //Flamefire: Why copy? - //return new CSong(CSongs.GetSong(SongID)); return CSongs.GetSong(SongID); } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 16b288c1..75241ded 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -381,6 +381,23 @@ namespace Vocaluxe.Base get { return _Categories.ToArray(); } } + public static CSong GetVisibleSongByIndex(int index) + { + if (index < 0) + return null; + + foreach (SongPointer sp in _SongsSortList) + { + if (sp.Visible) + { + if (index == 0) + return _Songs[sp.SongID]; + index--; + } + } + return null; + } + private static void _FilterSongs(String SearchFilter, bool ShowDuetSongs) { if (_Init && _SearchFilter == SearchFilter && _ShowDuetSongs == ShowDuetSongs) diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index d77c10ad..14747225 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -300,7 +300,7 @@ namespace Vocaluxe.Base #endregion Record } - class CBuffer + class CBuffer : IDisposable { private const double _BaseToneFreq = 65.4064; private const int _NumHalfTones = 47; @@ -315,7 +315,7 @@ namespace Vocaluxe.Base private double _MaxVolume = 0.0; private bool _NewSamples; - private MemoryStream _Stream; // full buffer + private MemoryStream _Stream = null; // full buffer public CBuffer() { @@ -554,6 +554,16 @@ namespace Vocaluxe.Base return 1 - AccumDist / _AnalysisBuffer.Length; } + + public void Dispose() + { + if (_Stream != null) + { + _Stream.Dispose(); + _Stream = null; + } + GC.SuppressFinalize(this); + } } class CSyncTimer diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index a69065ae..1b38a8b8 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using Vocaluxe.Base; using Vocaluxe.Menu; diff --git a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs index cd717e3a..e9df11f7 100644 --- a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs +++ b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs @@ -11,9 +11,9 @@ using Vocaluxe.Menu; namespace Vocaluxe.Lib.Input.WiiMote { - class CWiiMote : IInput + class CWiiMote : IInput, IDisposable { - WiiMoteLib _WiiMote; + WiiMoteLib _WiiMote = null; private List _KeysPool; private List _CurrentKeysPool; @@ -324,5 +324,15 @@ namespace Vocaluxe.Lib.Input.WiiMote _MousePool.Clear(); } } + + public void Dispose() + { + if (_WiiMote != null) + { + _WiiMote.Dispose(); + _WiiMote = null; + } + GC.SuppressFinalize(this); + } } } diff --git a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs index 0b3fbc90..ed486447 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs @@ -104,7 +104,7 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct TAc_decoder { //Pointer on the Acinerella instance - public IntPtr pAcInstance; + private IntPtr pAcInstance; //Contains the type of the decoder. public TAc_decoder_type dec_type; diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 9df8a799..f0e6b365 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -229,6 +229,7 @@ Form +