diff --git a/CheckingRules.ruleset b/CheckingRules.ruleset new file mode 100644 index 00000000..de4b78c7 --- /dev/null +++ b/CheckingRules.ruleset @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Vocaluxe.sln b/Vocaluxe.sln index 3714a400..f7c3f8c7 100644 --- a/Vocaluxe.sln +++ b/Vocaluxe.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2012 for Windows Desktop +# Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vocaluxe", "Vocaluxe\Vocaluxe.csproj", "{2A1E0F2D-5392-4BB7-B0A1-A9DFA13E79FF}" ProjectSection(ProjectDependencies) = postProject {6F3E1874-F28A-40E9-AFBD-31934D593679} = {6F3E1874-F28A-40E9-AFBD-31934D593679} diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 7137d260..aa88b3ab 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -133,7 +133,7 @@ namespace Vocaluxe.Base { get { - if (_CurrentPlaylistElement.Artist != "" && _CurrentPlaylistElement.Title != "") + if (_CurrentPlaylistElement.Artist.Length > 0 && _CurrentPlaylistElement.Title.Length > 0) return _CurrentPlaylistElement.Artist + " - " + _CurrentPlaylistElement.Title; else return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath); diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 03f86f73..8458ae16 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -287,276 +287,278 @@ namespace Vocaluxe.Base XmlWriter writer = null; try { - 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) + using (writer = XmlWriter.Create(CSettings.sFileConfig, _settings)) { - //Write "old" song-folders to config. - writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); - for (int i = 0; i < SongFolderOld.Count; i++) + 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.Length > 0 && MicConfig[p - 1].InputName.Length > 0 && 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; + if (writer != null) + writer.Close(); return false; } - writer = null; return true; } @@ -731,7 +733,7 @@ namespace Vocaluxe.Base //Only found a parameter case 1: - if (!Regex.IsMatch(parts[0], @"\s") && parts[0] != string.Empty) + if (!Regex.IsMatch(parts[0], @"\s") && parts[0].Length > 0) { //Add parameter _Params.Add(parts[0]); @@ -744,7 +746,7 @@ namespace Vocaluxe.Base //Found parameter and value case 2: - if (!Regex.IsMatch(parts[0], @"\s") && parts[0] != string.Empty) + if (!Regex.IsMatch(parts[0], @"\s") && parts[0].Length > 0) { //Add parameter _Params.Add(parts[0]); @@ -856,7 +858,7 @@ namespace Vocaluxe.Base return false; } } - if (Path.GetFileName(value) == string.Empty) + if (Path.GetFileName(value).Length == 0) { return false; } @@ -876,7 +878,7 @@ namespace Vocaluxe.Base { for (int j = 0; j < CSettings.MaxNumPlayer; j++) { - if (Players[j] != string.Empty) + if (Players[j].Length > 0) { if (Path.GetFileName(CProfiles.Profiles[i].ProfileFile) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON) { diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index dc402c45..493d9ed5 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -171,7 +171,7 @@ namespace Vocaluxe.Base xmlReader.GetValue("//root/Info/Name", ref coverTheme.Name, String.Empty); xmlReader.GetValue("//root/Info/Folder", ref coverTheme.Folder, String.Empty); - if (coverTheme.Folder != String.Empty && coverTheme.Name != String.Empty) + if (coverTheme.Folder.Length > 0 && coverTheme.Name.Length > 0) { coverTheme.File = file; @@ -190,7 +190,7 @@ namespace Vocaluxe.Base coverTheme = CoverTheme(coverThemeName); - if (coverTheme.Name != String.Empty) + if (coverTheme.Name.Length > 0) { CXMLReader xmlReader = CXMLReader.OpenFile((Path.Combine(CSettings.sFolderCover, coverTheme.File))); diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 622038ab..6c8ff5f3 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -68,57 +68,54 @@ namespace Vocaluxe.Base player.ShortSong = (ShortSong == 1); player.Difficulty = (EGameDifficulty)Diff; - SQLiteConnection connection = new SQLiteConnection(); - SQLiteCommand command; - - connection.ConnectionString = "Data Source=" + FilePath; - - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return -1; + connection.ConnectionString = "Data Source=" + FilePath; + + try + { + connection.Open(); + } + catch (Exception) + { + return -1; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + int DataBaseSongID = GetDataBaseSongID(Artist, Title, NumPlayed, command); + int result = AddScore(player, command, DataBaseSongID); + return result; + } } - command = new SQLiteCommand(connection); - - int DataBaseSongID = GetDataBaseSongID(Artist, Title, NumPlayed, command); - int result = AddScore(player, command, DataBaseSongID); - - command.Dispose(); - connection.Close(); - connection.Dispose(); - - return result; } public static int AddScore(SPlayer player) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _HighscoreFilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return -1; - } + connection.ConnectionString = "Data Source=" + _HighscoreFilePath; - command = new SQLiteCommand(connection); + try + { + connection.Open(); + } + catch (Exception) + { + return -1; + } - int DataBaseSongID = GetDataBaseSongID(player, command); - int result = AddScore(player, command, DataBaseSongID); + using (SQLiteCommand command = new SQLiteCommand(connection)) + { - connection.Close(); - connection.Dispose(); + int DataBaseSongID = GetDataBaseSongID(player, command); + int result = AddScore(player, command, DataBaseSongID); - return result; + return result; + } + } } private static int AddScore(SPlayer player, SQLiteCommand command, int DataBaseSongID) @@ -159,7 +156,6 @@ namespace Vocaluxe.Base } catch (Exception) { - ; } if (reader != null && reader.HasRows) @@ -169,8 +165,10 @@ namespace Vocaluxe.Base } if (reader != null) - reader.Close(); - + { + reader.Dispose(); + reader = null; + } command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty) " + "VALUES (@SongID, @PlayerName, @Score, @LineNr, @Date, @Medley, @Duet, @ShortSong, @Difficulty)"; @@ -188,15 +186,7 @@ namespace Vocaluxe.Base //Read last insert line command.CommandText = "SELECT id FROM Scores ORDER BY id DESC LIMIT 0, 1"; - reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + reader = command.ExecuteReader(); if (reader != null && reader.HasRows) { @@ -204,8 +194,6 @@ namespace Vocaluxe.Base { lastInsertID = reader.GetInt32(0); } - - reader.Close(); reader.Dispose(); } } @@ -215,81 +203,70 @@ namespace Vocaluxe.Base public static void LoadScore(ref List Score, SPlayer player) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _HighscoreFilePath; - SQLiteCommand command; - - Score = new List(); - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return; - } + connection.ConnectionString = "Data Source=" + _HighscoreFilePath; - command = new SQLiteCommand(connection); + Score = new List(); - int Medley = 0; - if (player.Medley) - Medley = 1; - - int Duet = 0; - if (player.Duet) - Duet = 1; - - int ShortSong = 0; - if (player.ShortSong) - ShortSong = 1; - - int DataBaseSongID = GetDataBaseSongID(player, command); - if (DataBaseSongID >= 0) - { - command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " + - "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " + - "ORDER BY [Score] DESC"; - command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; - command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; - command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; - command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = ShortSong; - - SQLiteDataReader reader = null; try { - reader = command.ExecuteReader(); + connection.Open(); } catch (Exception) { - throw; + return; } - if (reader != null && reader.HasRows) + using (SQLiteCommand command = new SQLiteCommand(connection)) { - while (reader.Read()) - { - SScores score = new SScores(); - score.Name = reader.GetString(0); - score.Score = reader.GetInt32(1); - score.Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"); - score.Difficulty = (EGameDifficulty)reader.GetInt32(3); - score.LineNr = reader.GetInt32(4); - score.ID = reader.GetInt32(5); - Score.Add(score); + int Medley = 0; + if (player.Medley) + Medley = 1; + + int Duet = 0; + if (player.Duet) + Duet = 1; + + int ShortSong = 0; + if (player.ShortSong) + ShortSong = 1; + + int DataBaseSongID = GetDataBaseSongID(player, command); + if (DataBaseSongID >= 0) + { + command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " + + "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " + + "ORDER BY [Score] DESC"; + command.Parameters.Add("@SongID", System.Data.DbType.Int32, 0).Value = DataBaseSongID; + command.Parameters.Add("@Medley", System.Data.DbType.Int32, 0).Value = Medley; + command.Parameters.Add("@Duet", System.Data.DbType.Int32, 0).Value = Duet; + command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = ShortSong; + + SQLiteDataReader reader = command.ExecuteReader(); + if (reader != null && reader.HasRows) + { + while (reader.Read()) + { + SScores score = new SScores(); + score.Name = reader.GetString(0); + score.Score = reader.GetInt32(1); + score.Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"); + score.Difficulty = (EGameDifficulty)reader.GetInt32(3); + score.LineNr = reader.GetInt32(4); + score.ID = reader.GetInt32(5); + + Score.Add(score); + } + reader.Dispose(); + } + } - reader.Close(); - reader.Dispose(); + } - } - - - command.Dispose(); - connection.Close(); - connection.Dispose(); } private static int GetDataBaseSongID(SPlayer player, SQLiteCommand command) @@ -304,26 +281,25 @@ namespace Vocaluxe.Base private static int GetDataBaseSongID(string Artist, string Title, string FilePath, int DefNumPlayed) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; + using (SQLiteConnection connection = new SQLiteConnection()) + { + connection.ConnectionString = "Data Source=" + FilePath; - try - { - connection.Open(); - } - catch (Exception) - { - return -1; + try + { + connection.Open(); + } + catch (Exception) + { + return -1; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + return GetDataBaseSongID(Artist, Title, DefNumPlayed, command); + } } - command = new SQLiteCommand(connection); - int id = GetDataBaseSongID(Artist, Title, DefNumPlayed, command); - command.Dispose(); - connection.Close(); - connection.Dispose(); - - return id; } private static int GetDataBaseSongID(string Artist, string Title, int DefNumPlayed, SQLiteCommand command) @@ -332,21 +308,12 @@ namespace Vocaluxe.Base command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = Title; command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = Artist; - SQLiteDataReader reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + SQLiteDataReader reader = command.ExecuteReader(); if (reader != null && reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); - reader.Close(); reader.Dispose(); return id; } @@ -366,31 +333,19 @@ namespace Vocaluxe.Base command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = Title; command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = Artist; - reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + reader = command.ExecuteReader(); if (reader != null) { reader.Read(); int id = reader.GetInt32(0); - reader.Close(); reader.Dispose(); return id; } } if (reader != null) - { - reader.Close(); reader.Dispose(); - } return -1; } @@ -401,56 +356,47 @@ namespace Vocaluxe.Base Title = String.Empty; NumPlayed = 0; - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return false; - } + connection.ConnectionString = "Data Source=" + FilePath; - command = new SQLiteCommand(connection); - command.CommandText = "SELECT Artist, Title, NumPlayed FROM Songs WHERE [id] = @id"; - command.Parameters.Add("@id", System.Data.DbType.String, 0).Value = SongID; + try + { + connection.Open(); + } + catch (Exception) + { + return false; + } - SQLiteDataReader reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - return false; - } + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + command.CommandText = "SELECT Artist, Title, NumPlayed FROM Songs WHERE [id] = @id"; + command.Parameters.Add("@id", System.Data.DbType.String, 0).Value = SongID; - if (reader != null && reader.HasRows) - { - reader.Read(); - Artist = reader.GetString(0); - Title = reader.GetString(1); - NumPlayed = reader.GetInt32(2); - reader.Close(); - reader.Dispose(); + SQLiteDataReader reader = null; + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + return false; + } - command.Dispose(); - connection.Close(); - connection.Dispose(); - return true; + if (reader != null && reader.HasRows) + { + reader.Read(); + Artist = reader.GetString(0); + Title = reader.GetString(1); + NumPlayed = reader.GetInt32(2); + reader.Dispose(); + return true; + } + if (reader != null) + reader.Dispose(); + } } - else - { - if (reader != null) - reader.Close(); - } - - command.Dispose(); - connection.Close(); - connection.Dispose(); return false; } @@ -481,76 +427,77 @@ namespace Vocaluxe.Base private static void CreateHighscoreDB(string FilePath) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); + connection.ConnectionString = "Data Source=" + FilePath; + + try + { + connection.Open(); + } + catch (Exception) + { + return; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, @Value)"; + command.Parameters.Add("@Value",DbType.Int32).Value = CSettings.iDatabaseHighscoreVersion; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Songs ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "Artist TEXT NOT NULL, Title TEXT NOT NULL, NumPlayed INTEGER);"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Scores ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "SongID INTEGER NOT NULL, PlayerName TEXT NOT NULL, Score INTEGER NOT NULL, LineNr INTEGER NOT NULL, Date BIGINT NOT NULL, " + + "Medley INTEGER NOT NULL, Duet INTEGER NOT NULL, ShortSong INTEGER NOT NULL, Difficulty INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + } } - catch (Exception) - { - return; - } - - command = new SQLiteCommand(connection); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, " + CSettings.iDatabaseHighscoreVersion.ToString() + ")"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Songs ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "Artist TEXT NOT NULL, Title TEXT NOT NULL, NumPlayed INTEGER);"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Scores ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "SongID INTEGER NOT NULL, PlayerName TEXT NOT NULL, Score INTEGER NOT NULL, LineNr INTEGER NOT NULL, Date BIGINT NOT NULL, " + - "Medley INTEGER NOT NULL, Duet INTEGER NOT NULL, ShortSong INTEGER NOT NULL, Difficulty INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.Dispose(); - connection.Close(); - connection.Dispose(); } private static void CreateHighscoreDBV1(string FilePath) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); + connection.ConnectionString = "Data Source=" + FilePath; + + try + { + connection.Open(); + } + catch (Exception) + { + return; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, 1 )"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Songs ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "Artist TEXT NOT NULL, Title TEXT NOT NULL, NumPlayed INTEGER);"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Scores ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "SongID INTEGER NOT NULL, PlayerName TEXT NOT NULL, Score INTEGER NOT NULL, LineNr INTEGER NOT NULL, Date BIGINT NOT NULL, " + + "Medley INTEGER NOT NULL, Duet INTEGER NOT NULL, Difficulty INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + } } - catch (Exception) - { - return; - } - - command = new SQLiteCommand(connection); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, 1 )"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Songs ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "Artist TEXT NOT NULL, Title TEXT NOT NULL, NumPlayed INTEGER);"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Scores ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "SongID INTEGER NOT NULL, PlayerName TEXT NOT NULL, Score INTEGER NOT NULL, LineNr INTEGER NOT NULL, Date BIGINT NOT NULL, " + - "Medley INTEGER NOT NULL, Duet INTEGER NOT NULL, Difficulty INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.Dispose(); - connection.Close(); - connection.Dispose(); } /// @@ -560,110 +507,102 @@ namespace Vocaluxe.Base /// private static bool CreateOrConvert(string FilePath) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return false; - } + connection.ConnectionString = "Data Source=" + FilePath; - SQLiteDataReader reader = null; - command = new SQLiteCommand(connection); - - command.CommandText = "PRAGMA user_version"; - reader = command.ExecuteReader(); - reader.Read(); - - int version = reader.GetInt32(0); - - reader.Close(); - reader.Dispose(); - - //Check if old scores table exists - command.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='US_Scores';"; - reader = command.ExecuteReader(); - reader.Read(); - bool scoresTableExists = reader.HasRows; - - reader.Close(); - reader.Dispose(); - - command.CommandText = "SELECT Value FROM Version"; - reader = null; - - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - ; - } - - if (reader == null) - { - // create new database/tables - if (version == 1) //Check for USDX 1.1 DB + try { - CreateHighscoreDBV1(FilePath); - ConvertFrom110(FilePath); - UpdateDatabase(1, connection); + connection.Open(); } - else if (version == 0 && scoresTableExists) //Check for USDX 1.01 or CMD Mod DB + catch (Exception) { - CreateHighscoreDBV1(FilePath); - ConvertFrom101(FilePath); - UpdateDatabase(1, connection); + return false; } - else - CreateHighscoreDB(FilePath); - } - else if (reader.FieldCount == 0) - { - // create new database/tables - if (version == 1) //Check for USDX 1.1 DB + + SQLiteDataReader reader = null; + using (SQLiteCommand command = new SQLiteCommand(connection)) { - CreateHighscoreDBV1(FilePath); - ConvertFrom110(FilePath); - UpdateDatabase(1, connection); - } - else if (version == 0 && scoresTableExists) //Check for USDX 1.01 or CMD Mod DB - { - CreateHighscoreDBV1(FilePath); - ConvertFrom101(FilePath); - UpdateDatabase(1, connection); - } - else - CreateHighscoreDB(FilePath); - } - else - { - reader.Read(); - int CurrentVersion = reader.GetInt32(0); - if (CurrentVersion < CSettings.iDatabaseHighscoreVersion) - { - // update database - UpdateDatabase(CurrentVersion, connection); + + command.CommandText = "PRAGMA user_version"; + reader = command.ExecuteReader(); + reader.Read(); + + int version = reader.GetInt32(0); + + reader.Dispose(); + + //Check if old scores table exists + command.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='US_Scores';"; + reader = command.ExecuteReader(); + reader.Read(); + bool scoresTableExists = reader.HasRows; + + reader.Dispose(); + + command.CommandText = "SELECT Value FROM Version"; + reader = null; + + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + } + + if (reader == null) + { + // create new database/tables + if (version == 1) //Check for USDX 1.1 DB + { + CreateHighscoreDBV1(FilePath); + ConvertFrom110(FilePath); + UpdateDatabase(1, connection); + } + else if (version == 0 && scoresTableExists) //Check for USDX 1.01 or CMD Mod DB + { + CreateHighscoreDBV1(FilePath); + ConvertFrom101(FilePath); + UpdateDatabase(1, connection); + } + else + CreateHighscoreDB(FilePath); + } + else if (reader.FieldCount == 0) + { + // create new database/tables + if (version == 1) //Check for USDX 1.1 DB + { + CreateHighscoreDBV1(FilePath); + ConvertFrom110(FilePath); + UpdateDatabase(1, connection); + } + else if (version == 0 && scoresTableExists) //Check for USDX 1.01 or CMD Mod DB + { + CreateHighscoreDBV1(FilePath); + ConvertFrom101(FilePath); + UpdateDatabase(1, connection); + } + else + CreateHighscoreDB(FilePath); + } + else + { + reader.Read(); + int CurrentVersion = reader.GetInt32(0); + if (CurrentVersion < CSettings.iDatabaseHighscoreVersion) + { + // update database + UpdateDatabase(CurrentVersion, connection); + } + } + + if (reader != null) + reader.Dispose(); } } - if (reader != null) - { - reader.Close(); - reader.Dispose(); - } - - command.Dispose(); - - connection.Close(); - connection.Dispose(); - return true; } @@ -674,129 +613,123 @@ namespace Vocaluxe.Base /// True if succeeded private static bool ConvertFrom110(string FilePath) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return false; - } + connection.ConnectionString = "Data Source=" + FilePath; - command = new SQLiteCommand(connection); - - //The USDX database has no column for LineNr, Medley and Duet so just fill 0 in there - command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; - command.ExecuteNonQuery(); - - command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; - command.ExecuteNonQuery(); - - List scores = new List(); - List songs = new List(); - - SQLiteDataReader reader = null; - command.CommandText = "SELECT id, PlayerName, Date FROM Scores"; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } - - if (reader != null && reader.HasRows) - { - while (reader.Read()) + try { - SData data = new SData(); - data.id = reader.GetInt32(0); - data.str1 = reader.GetString(1); - Int64 ticks = 0; + connection.Open(); + } + catch (Exception) + { + return false; + } + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + //The USDX database has no column for LineNr, Medley and Duet so just fill 0 in there + command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; + command.ExecuteNonQuery(); + + List scores = new List(); + List songs = new List(); + + SQLiteDataReader reader = null; + command.CommandText = "SELECT id, PlayerName, Date FROM Scores"; try { - ticks = reader.GetInt64(2); + reader = command.ExecuteReader(); + } + catch (Exception) + { + throw; } - catch { } - data.ticks = UnixTimeToTicks((int)ticks); + if (reader != null && reader.HasRows) + { + while (reader.Read()) + { + SData data = new SData(); + data.id = reader.GetInt32(0); + data.str1 = reader.GetString(1); + Int64 ticks = 0; + + try + { + ticks = reader.GetInt64(2); + } + catch { } + + data.ticks = UnixTimeToTicks((int)ticks); + + scores.Add(data); + } + reader.Close(); + } + + command.CommandText = "SELECT id, Artist, Title FROM Songs"; + + reader = command.ExecuteReader(); + + if (reader != null && reader.HasRows) + { + while (reader.Read()) + { + SData data = new SData(); + data.id = reader.GetInt32(0); + data.str1 = reader.GetString(1); + data.str2 = reader.GetString(2); + songs.Add(data); + } + } + + if(reader != null) + reader.Dispose(); + + SQLiteTransaction _Transaction = connection.BeginTransaction(); + // update Title and Artist strings + foreach (SData data in songs) + { + command.CommandText = "UPDATE Songs SET [Artist] = @artist, [Title] = @title WHERE [ID] = @id"; + command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = data.str2; + command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = data.str1; + command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; + command.ExecuteNonQuery(); + } + + // update player names + foreach (SData data in scores) + { + command.CommandText = "UPDATE Scores SET [PlayerName] = @player, [Date] = @date WHERE [id] = @id"; + command.Parameters.Add("@player", System.Data.DbType.String, 0).Value = data.str1; + command.Parameters.Add("@date", System.Data.DbType.Int64, 0).Value = data.ticks; + command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; + command.ExecuteNonQuery(); + } + _Transaction.Commit(); + + //Delete old tables after conversion + command.CommandText = "DROP TABLE US_Scores;"; + command.ExecuteNonQuery(); + + command.CommandText = "DROP TABLE US_Songs;"; + command.ExecuteNonQuery(); + + command.CommandText = "DROP TABLE us_statistics_info;"; + command.ExecuteNonQuery(); + + //This versioning is not used in Vocaluxe so reset it to 0 + command.CommandText = "PRAGMA user_version = 0"; + command.ExecuteNonQuery(); - scores.Add(data); } - reader.Close(); } - command.CommandText = "SELECT id, Artist, Title FROM Songs"; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } - - if (reader != null && reader.HasRows) - { - while (reader.Read()) - { - SData data = new SData(); - data.id = reader.GetInt32(0); - data.str1 = reader.GetString(1); - data.str2 = reader.GetString(2); - songs.Add(data); - } - reader.Close(); - } - - reader.Dispose(); - - SQLiteTransaction _Transaction = connection.BeginTransaction(); - // update Title and Artist strings - foreach (SData data in songs) - { - command.CommandText = "UPDATE Songs SET [Artist] = @artist, [Title] = @title WHERE [ID] = @id"; - command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = data.str2; - command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = data.str1; - command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; - command.ExecuteNonQuery(); - } - - // update player names - foreach (SData data in scores) - { - command.CommandText = "UPDATE Scores SET [PlayerName] = @player, [Date] = @date WHERE [id] = @id"; - command.Parameters.Add("@player", System.Data.DbType.String, 0).Value = data.str1; - command.Parameters.Add("@date", System.Data.DbType.Int64, 0).Value = data.ticks; - command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; - command.ExecuteNonQuery(); - } - _Transaction.Commit(); - - //Delete old tables after conversion - command.CommandText = "DROP TABLE US_Scores;"; - command.ExecuteNonQuery(); - - command.CommandText = "DROP TABLE US_Songs;"; - command.ExecuteNonQuery(); - - command.CommandText = "DROP TABLE us_statistics_info;"; - command.ExecuteNonQuery(); - - //This versioning is not used in Vocaluxe so reset it to 0 - command.CommandText = "PRAGMA user_version = 0"; - command.ExecuteNonQuery(); - - command.Dispose(); - connection.Close(); - connection.Dispose(); - return true; } @@ -807,184 +740,178 @@ namespace Vocaluxe.Base /// True if succeeded private static bool ConvertFrom101(string FilePath) { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + FilePath; - SQLiteCommand command; - SQLiteDataReader reader = null; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); - } - catch (Exception) - { - return false; - } + connection.ConnectionString = "Data Source=" + FilePath; - command = new SQLiteCommand(connection); - - command.CommandText = "PRAGMA table_info(US_Scores);"; - reader = command.ExecuteReader(); - - - bool dateExists = false; - - //Check for column Date - while (reader.Read()) - { - for (int i = 0; i < reader.FieldCount; i++) + try { - if (reader.GetName(i) == "name") + connection.Open(); + } + catch (Exception) + { + return false; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + command.CommandText = "PRAGMA table_info(US_Scores);"; + bool dateExists = false; + using (SQLiteDataReader reader = command.ExecuteReader()) { - if (reader.GetString(i) == "Date") - dateExists = true; - break; + //Check for column Date + while (reader.Read()) + { + for (int i = 0; i < reader.FieldCount; i++) + { + if (reader.GetName(i) == "name") + { + if (reader.GetString(i) == "Date") + dateExists = true; + break; + } + } + } + } - } - } + //This is a USDX 1.01 DB + if (!dateExists) + command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', '0', '0', '0', Difficulty from US_Scores"; + else // This is a CMD 1.01 DB + command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; + command.ExecuteNonQuery(); - reader.Close(); + command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; + command.ExecuteNonQuery(); - //This is a USDX 1.01 DB - if (!dateExists) - command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', '0', '0', '0', Difficulty from US_Scores"; - else // This is a CMD 1.01 DB - command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, Difficulty) SELECT SongID, Player, Score, '0', Date, '0', '0', Difficulty from US_Scores"; - command.ExecuteNonQuery(); + // convert from CP1252 to UTF8 + List scores = new List(); + List songs = new List(); - command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; - command.ExecuteNonQuery(); + Sqlite3.sqlite3 OldDB; + int res = Sqlite3.sqlite3_open(FilePath, out OldDB); - // convert from CP1252 to UTF8 - List scores = new List(); - List songs = new List(); - - Sqlite3.sqlite3 OldDB; - int res = Sqlite3.sqlite3_open(FilePath, out OldDB); - - if (res != Sqlite3.SQLITE_OK) - { - CLog.LogError("Error opening Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); - } - else - { - Sqlite3.Vdbe Stmt = new Sqlite3.Vdbe(); - res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, Artist, Title FROM Songs", -1, ref Stmt, 0); - - if (res != Sqlite3.SQLITE_OK) - { - CLog.LogError("Error query Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); - } - else - { - //Sqlite3.sqlite3_step(Stmt); - - Encoding UTF8 = Encoding.UTF8; - Encoding CP1252 = Encoding.GetEncoding(1252); - - while (Sqlite3.sqlite3_step(Stmt) == Sqlite3.SQLITE_ROW) + if (res != Sqlite3.SQLITE_OK) { - SData data = new SData(); - - data.id = Sqlite3.sqlite3_column_int(Stmt, 0); - - byte[] bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 1); - if (bytes != null) - data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); - else - data.str1 = "Someone"; - - bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 2); - if (bytes != null) - data.str2 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); - else - data.str2 = "Someone"; - - songs.Add(data); + CLog.LogError("Error opening Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); } - Sqlite3.sqlite3_finalize(Stmt); - } - - Stmt = new Sqlite3.Vdbe(); - - if (!dateExists) - res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, PlayerName FROM Scores", -1, ref Stmt, 0); - else - res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, PlayerName, Date FROM Scores", -1, ref Stmt, 0); - - if (res != Sqlite3.SQLITE_OK) - { - CLog.LogError("Error query Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); - } - else - { - //Sqlite3.sqlite3_step(Stmt); - - Encoding UTF8 = Encoding.UTF8; - Encoding CP1252 = Encoding.GetEncoding(1252); - - while (Sqlite3.sqlite3_step(Stmt) == Sqlite3.SQLITE_ROW) + else { - SData data = new SData(); + Sqlite3.Vdbe Stmt = new Sqlite3.Vdbe(); + res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, Artist, Title FROM Songs", -1, ref Stmt, 0); - data.id = Sqlite3.sqlite3_column_int(Stmt, 0); - - byte[] bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 1); - if (bytes != null) - data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); + if (res != Sqlite3.SQLITE_OK) + { + CLog.LogError("Error query Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); + } else - data.str1 = "Someone"; + { + //Sqlite3.sqlite3_step(Stmt); - if (dateExists) - data.ticks = UnixTimeToTicks(Sqlite3.sqlite3_column_int(Stmt, 2)); + Encoding UTF8 = Encoding.UTF8; + Encoding CP1252 = Encoding.GetEncoding(1252); - scores.Add(data); + while (Sqlite3.sqlite3_step(Stmt) == Sqlite3.SQLITE_ROW) + { + SData data = new SData(); + + data.id = Sqlite3.sqlite3_column_int(Stmt, 0); + + byte[] bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 1); + if (bytes != null) + data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); + else + data.str1 = "Someone"; + + bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 2); + if (bytes != null) + data.str2 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); + else + data.str2 = "Someone"; + + songs.Add(data); + } + Sqlite3.sqlite3_finalize(Stmt); + } + + Stmt = new Sqlite3.Vdbe(); + + if (!dateExists) + res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, PlayerName FROM Scores", -1, ref Stmt, 0); + else + res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT id, PlayerName, Date FROM Scores", -1, ref Stmt, 0); + + if (res != Sqlite3.SQLITE_OK) + { + CLog.LogError("Error query Database: " + FilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")"); + } + else + { + //Sqlite3.sqlite3_step(Stmt); + + Encoding UTF8 = Encoding.UTF8; + Encoding CP1252 = Encoding.GetEncoding(1252); + + while (Sqlite3.sqlite3_step(Stmt) == Sqlite3.SQLITE_ROW) + { + SData data = new SData(); + + data.id = Sqlite3.sqlite3_column_int(Stmt, 0); + + byte[] bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 1); + if (bytes != null) + data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes)); + else + data.str1 = "Someone"; + + if (dateExists) + data.ticks = UnixTimeToTicks(Sqlite3.sqlite3_column_int(Stmt, 2)); + + scores.Add(data); + } + Sqlite3.sqlite3_finalize(Stmt); + } } - Sqlite3.sqlite3_finalize(Stmt); + Sqlite3.sqlite3_close(OldDB); + + SQLiteTransaction _Transaction = connection.BeginTransaction(); + + // update Title and Artist strings + foreach (SData data in songs) + { + command.CommandText = "UPDATE Songs SET [Artist] = @artist, [Title] = @title WHERE [ID] = @id"; + command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = data.str2; + command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = data.str1; + command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; + command.ExecuteNonQuery(); + } + + // update player names + foreach (SData data in scores) + { + if (!dateExists) + command.CommandText = "UPDATE Scores SET [PlayerName] = @player WHERE [id] = @id"; + else + { + command.CommandText = "UPDATE Scores SET [PlayerName] = @player, [Date] = @date WHERE [id] = @id"; + command.Parameters.Add("@date", System.Data.DbType.Int64, 0).Value = data.ticks; + } + command.Parameters.Add("@player", System.Data.DbType.String, 0).Value = data.str1; + command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; + command.ExecuteNonQuery(); + } + _Transaction.Commit(); + + //Delete old tables after conversion + command.CommandText = "DROP TABLE US_Scores;"; + command.ExecuteNonQuery(); + + command.CommandText = "DROP TABLE US_Songs;"; + command.ExecuteNonQuery(); } } - Sqlite3.sqlite3_close(OldDB); - - SQLiteTransaction _Transaction = connection.BeginTransaction(); - - // update Title and Artist strings - foreach (SData data in songs) - { - command.CommandText = "UPDATE Songs SET [Artist] = @artist, [Title] = @title WHERE [ID] = @id"; - command.Parameters.Add("@title", System.Data.DbType.String, 0).Value = data.str2; - command.Parameters.Add("@artist", System.Data.DbType.String, 0).Value = data.str1; - command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; - command.ExecuteNonQuery(); - } - - // update player names - foreach (SData data in scores) - { - if (!dateExists) - command.CommandText = "UPDATE Scores SET [PlayerName] = @player WHERE [id] = @id"; - else - { - command.CommandText = "UPDATE Scores SET [PlayerName] = @player, [Date] = @date WHERE [id] = @id"; - command.Parameters.Add("@date", System.Data.DbType.Int64, 0).Value = data.ticks; - } - command.Parameters.Add("@player", System.Data.DbType.String, 0).Value = data.str1; - command.Parameters.Add("@id", System.Data.DbType.Int32, 0).Value = data.id; - command.ExecuteNonQuery(); - } - _Transaction.Commit(); - - //Delete old tables after conversion - command.CommandText = "DROP TABLE US_Scores;"; - command.ExecuteNonQuery(); - - command.CommandText = "DROP TABLE US_Songs;"; - command.ExecuteNonQuery(); - - reader.Dispose(); - command.Dispose(); - connection.Close(); - connection.Dispose(); return true; } @@ -1001,19 +928,19 @@ namespace Vocaluxe.Base private static bool ConvertV1toV2(SQLiteConnection connection) { - SQLiteCommand command; - command = new SQLiteCommand(connection); + using (SQLiteCommand command = new SQLiteCommand(connection)) + { - command.CommandText = "ALTER TABLE Scores ADD ShortSong INTEGER"; - command.ExecuteNonQuery(); - command.CommandText = "UPDATE Scores SET [ShortSong] = @ShortSong"; - command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = 0; - command.ExecuteNonQuery(); - command.CommandText = "UPDATE Version SET [Value] = @version"; - command.Parameters.Add("@version", System.Data.DbType.Int32, 0).Value = 2; - command.ExecuteNonQuery(); - command.Dispose(); + command.CommandText = "ALTER TABLE Scores ADD ShortSong INTEGER"; + command.ExecuteNonQuery(); + command.CommandText = "UPDATE Scores SET [ShortSong] = @ShortSong"; + command.Parameters.Add("@ShortSong", System.Data.DbType.Int32, 0).Value = 0; + command.ExecuteNonQuery(); + command.CommandText = "UPDATE Version SET [Value] = @version"; + command.Parameters.Add("@version", System.Data.DbType.Int32, 0).Value = 2; + command.ExecuteNonQuery(); + } return true; } @@ -1021,65 +948,61 @@ namespace Vocaluxe.Base private static bool ImportData(string SourceDBPath, string DestinationDBPath) { #region open db - SQLiteConnection connSource = new SQLiteConnection(); - connSource.ConnectionString = "Data Source=" + SourceDBPath; + using (SQLiteConnection connSource = new SQLiteConnection()) + { + connSource.ConnectionString = "Data Source=" + SourceDBPath; - try - { - connSource.Open(); - } - catch (Exception e) - { - CLog.LogError("Error on import high score data. Can't open source database \"" + SourceDBPath + "\" (" + e.Message + ")"); - return false; - } + try + { + connSource.Open(); + } + catch (Exception e) + { + CLog.LogError("Error on import high score data. Can't open source database \"" + SourceDBPath + "\" (" + e.Message + ")"); + return false; + } #endregion open db - SQLiteCommand cmdSource = new SQLiteCommand(connSource); - SQLiteDataReader rSource; - - #region import table scores - cmdSource.CommandText = "SELECT SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty FROM Scores"; - rSource = cmdSource.ExecuteReader(); - if (rSource == null) - { - cmdSource.Dispose(); - connSource.Close(); - return false; - } - - if (rSource.FieldCount == 0) - { - rSource.Close(); - cmdSource.Dispose(); - connSource.Close(); - return true; - } - - while (rSource.Read()) - { - int songid = rSource.GetInt32(0); - string player = rSource.GetString(1); - int score = rSource.GetInt32(2); - int linenr = rSource.GetInt32(3); - long date = rSource.GetInt64(4); - int medley = rSource.GetInt32(5); - int duet = rSource.GetInt32(6); - int shortsong = rSource.GetInt32(7); - int diff = rSource.GetInt32(8); - - string artist, title; - int numplayed; - if (GetDataBaseSongInfos(songid, out artist, out title, out numplayed, SourceDBPath)) + using (SQLiteCommand cmdSource = new SQLiteCommand(connSource)) { - AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath); + SQLiteDataReader rSource; + + #region import table scores + cmdSource.CommandText = "SELECT SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty FROM Scores"; + rSource = cmdSource.ExecuteReader(); + if (rSource == null) + return false; + + if (rSource.FieldCount == 0) + { + rSource.Close(); + return true; + } + + while (rSource.Read()) + { + int songid = rSource.GetInt32(0); + string player = rSource.GetString(1); + int score = rSource.GetInt32(2); + int linenr = rSource.GetInt32(3); + long date = rSource.GetInt64(4); + int medley = rSource.GetInt32(5); + int duet = rSource.GetInt32(6); + int shortsong = rSource.GetInt32(7); + int diff = rSource.GetInt32(8); + + string artist, title; + int numplayed; + if (GetDataBaseSongInfos(songid, out artist, out title, out numplayed, SourceDBPath)) + { + AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath); + } + } + #endregion import table scores + + rSource.Close(); } } - #endregion import table scores - - rSource.Close(); - cmdSource.Dispose(); - connSource.Close(); return true; } @@ -1103,138 +1026,111 @@ namespace Vocaluxe.Base _ConnectionCover.Open(); } - SQLiteCommand command; - command = new SQLiteCommand(_ConnectionCover); - - command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path"; - command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; - - SQLiteDataReader reader = null; - try + using (SQLiteCommand command = new SQLiteCommand(_ConnectionCover)) { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } - if (reader != null && reader.HasRows) - { - reader.Read(); - int id = reader.GetInt32(0); - int w = reader.GetInt32(1); - int h = reader.GetInt32(2); - reader.Close(); - - command.CommandText = "SELECT Data FROM CoverData WHERE CoverID = " + id.ToString(); - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } - - if (reader.HasRows) - { - result = true; - reader.Read(); - byte[] data = GetBytes(reader); - tex = CDraw.QuequeTexture(w, h, ref data); - } - } - else - { - if (reader != null) - reader.Close(); - - if (_TransactionCover == null) - { - _TransactionCover = _ConnectionCover.BeginTransaction(); - } - - Bitmap origin; - try - { - origin = new Bitmap(CoverPath); - } - catch (Exception) - { - CLog.LogError("Error loading Texture: " + CoverPath); - tex = new STexture(-1); - - if (reader != null) - { - reader.Close(); - reader.Dispose(); - } - command.Dispose(); - - return false; - } - - int w = MaxSize; - int h = MaxSize; - - if (origin.Width >= origin.Height && origin.Width > w) - h = (int)Math.Round((float)w / origin.Width * origin.Height); - else if (origin.Height > origin.Width && origin.Height > h) - w = (int)Math.Round((float)h / origin.Height * origin.Width); - - 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(); - - byte[] data = new byte[w * h * 4]; - - 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(); - - tex = CDraw.QuequeTexture(w, h, ref data); - - command.CommandText = "INSERT INTO Cover (Path, width, height) " + - "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; + command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path"; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; - command.ExecuteNonQuery(); - command.CommandText = "SELECT id FROM Cover WHERE [Path] = @path"; - command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; - reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + SQLiteDataReader reader = command.ExecuteReader(); - if (reader != null) + if (reader != null && reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); + int w = reader.GetInt32(1); + int h = reader.GetInt32(2); reader.Close(); - command.CommandText = "INSERT INTO CoverData (CoverID, Data) " + - "VALUES ('" + id.ToString() + "', @data)"; - command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; - command.ExecuteReader(); - result = true; - } - } - if (reader != null) - { - reader.Close(); - reader.Dispose(); + command.CommandText = "SELECT Data FROM CoverData WHERE CoverID = @id"; + command.Parameters.Add("@id",DbType.Int32).Value=id; + reader = command.ExecuteReader(); + + if (reader.HasRows) + { + result = true; + reader.Read(); + byte[] data = GetBytes(reader); + tex = CDraw.QuequeTexture(w, h, ref data); + } + } + else + { + if (reader != null) + reader.Close(); + + if (_TransactionCover == null) + { + _TransactionCover = _ConnectionCover.BeginTransaction(); + } + + Bitmap origin; + try + { + origin = new Bitmap(CoverPath); + } + catch (Exception) + { + CLog.LogError("Error loading Texture: " + CoverPath); + return false; + } + + int w = MaxSize; + int h = MaxSize; + byte[] data; + + try + { + if (origin.Width >= origin.Height && origin.Width > w) + h = (int)Math.Round((float)w / origin.Width * origin.Height); + else if (origin.Height > origin.Width && origin.Height > h) + w = (int)Math.Round((float)h / origin.Height * origin.Width); + + using (Bitmap bmp = new Bitmap(w, h)) + { + using (Graphics g = Graphics.FromImage(bmp)) + { + g.DrawImage(origin, new Rectangle(0, 0, w, h)); + } + + data = new byte[w * h * 4]; + 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); + } + } + finally + { + origin.Dispose(); + } + + tex = CDraw.QuequeTexture(w, h, ref data); + + command.CommandText = "INSERT INTO Cover (Path, width, height) VALUES (@path, @w, @h)"; + command.Parameters.Add("@w", DbType.Int32).Value = w; + command.Parameters.Add("@h", DbType.Int32).Value = h; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; + command.ExecuteNonQuery(); + + command.CommandText = "SELECT id FROM Cover WHERE [Path] = @path"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; + reader = command.ExecuteReader(); + + if (reader != null) + { + reader.Read(); + int id = reader.GetInt32(0); + command.CommandText = "INSERT INTO CoverData (CoverID, Data) VALUES (@id, @data)"; + command.Parameters.Add("@id", DbType.Int32).Value = id; + command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; + command.ExecuteReader(); + result = true; + } + } + + if (reader != null) + reader.Dispose(); } - command.Dispose(); return result; } @@ -1256,107 +1152,101 @@ namespace Vocaluxe.Base if (_ConnectionCover != null) { _ConnectionCover.Close(); + _ConnectionCover.Dispose(); _ConnectionCover = null; } } private static bool InitCoverDB() { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CoverFilePath; - SQLiteCommand command; + using (SQLiteConnection connection = new SQLiteConnection()) + { + connection.ConnectionString = "Data Source=" + _CoverFilePath; - try - { - connection.Open(); - } - catch (Exception) - { - return false; - } - - command = new SQLiteCommand(connection); - command.CommandText = "SELECT Value FROM Version"; - - SQLiteDataReader reader = null; - - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - ; - } - - if (reader == null) - { - // create new database/tables - CreateCoverDB(); - } - else if (reader.FieldCount == 0) - { - // create new database/tables - CreateCoverDB(); - } - else - { - reader.Read(); - - if (reader.GetInt32(0) < CSettings.iDatabaseHighscoreVersion) + try { - // update database + connection.Open(); + } + catch (Exception) + { + return false; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + command.CommandText = "SELECT Value FROM Version"; + + SQLiteDataReader reader = null; + + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + } + + if (reader == null) + { + // create new database/tables + CreateCoverDB(); + } + else if (reader.FieldCount == 0) + { + // create new database/tables + CreateCoverDB(); + } + else + { + reader.Read(); + + if (reader.GetInt32(0) < CSettings.iDatabaseHighscoreVersion) + { + // update database + } + } + if (reader != null) + reader.Dispose(); } } - - if (reader != null) - { - reader.Close(); - reader.Dispose(); - } - - command.Dispose(); - - connection.Close(); - connection.Dispose(); - return true; } private static void CreateCoverDB() { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CoverFilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); + connection.ConnectionString = "Data Source=" + _CoverFilePath; + + try + { + connection.Open(); + } + catch (Exception) + { + return; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, @Value)"; + command.Parameters.Add("@Value", DbType.Int32).Value = CSettings.iDatabaseCoverVersion; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Cover ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "Path TEXT NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS CoverData ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "CoverID INTEGER NOT NULL, Data BLOB NOT NULL);"; + command.ExecuteNonQuery(); + + } } - catch (Exception) - { - return; - } - - command = new SQLiteCommand(connection); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, " + CSettings.iDatabaseCoverVersion.ToString() + ")"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Cover ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "Path TEXT NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS CoverData ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "CoverID INTEGER NOT NULL, Data BLOB NOT NULL);"; - command.ExecuteNonQuery(); - - command.Dispose(); - connection.Close(); - connection.Dispose(); } #endregion Cover @@ -1365,68 +1255,58 @@ namespace Vocaluxe.Base { bool result = false; - 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); - - command.CommandText = "SELECT id, width, height FROM Images WHERE [Path] = @path"; - command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = FileName; - - SQLiteDataReader reader = null; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } - - if (reader != null && reader.HasRows) - { - reader.Read(); - int id = reader.GetInt32(0); - int w = reader.GetInt32(1); - int h = reader.GetInt32(2); - reader.Close(); - - command.CommandText = "SELECT Data FROM ImageData WHERE ImageID = " + id.ToString(); + connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; try { - reader = command.ExecuteReader(); + connection.Open(); } catch (Exception) { - throw; + return false; } - - if (reader.HasRows) + using (SQLiteCommand command = new SQLiteCommand(connection)) { - result = true; - reader.Read(); - byte[] data = GetBytes(reader); - tex = CDraw.AddTexture(w, h, ref data); + + command.CommandText = "SELECT id, width, height FROM Images WHERE [Path] = @path"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = FileName; + + SQLiteDataReader reader = command.ExecuteReader(); + + if (reader != null && reader.HasRows) + { + reader.Read(); + int id = reader.GetInt32(0); + int w = reader.GetInt32(1); + int h = reader.GetInt32(2); + reader.Close(); + + command.CommandText = "SELECT Data FROM ImageData WHERE ImageID = @id"; + command.Parameters.Add("@id",DbType.Int32).Value=id; + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + throw; + } + + if (reader.HasRows) + { + result = true; + reader.Read(); + byte[] data = GetBytes(reader); + tex = CDraw.AddTexture(w, h, ref data); + } + } + + if (reader != null) + reader.Dispose(); } } - if (reader != null) - { - reader.Close(); - reader.Dispose(); - } - command.Dispose(); - connection.Close(); - connection.Dispose(); - return result; } @@ -1461,53 +1341,50 @@ namespace Vocaluxe.Base catch (Exception) { CLog.LogError("Error loading Texture: " + ImagePath); - tex = new STexture(-1); - - connection.Close(); - return false; } - int w = origin.Width; int h = origin.Height; + byte[] data; + + try + { + using (Bitmap bmp = new Bitmap(w, h)) + { + using (Graphics g = Graphics.FromImage(bmp)) + { + g.DrawImage(origin, new Rectangle(0, 0, w, h)); + } + tex = CDraw.AddTexture(bmp); + data = new byte[w * h * 4]; - 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]; + 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); + } + } + finally + { + origin.Dispose(); + } - 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(); - - command.CommandText = "INSERT INTO Images (Path, width, height) " + - "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; + command.CommandText = "INSERT INTO Images (Path, width, height) VALUES (@path, @w, @h)"; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = Path.GetFileName(ImagePath); + command.Parameters.Add("@w", System.Data.DbType.Int32, 0).Value = w; + command.Parameters.Add("@h", System.Data.DbType.Int32, 0).Value = h; 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; - } + SQLiteDataReader reader = command.ExecuteReader(); if (reader != null) { reader.Read(); int id = reader.GetInt32(0); reader.Close(); - command.CommandText = "INSERT INTO ImageData (ImageID, Data) " + - "VALUES ('" + id.ToString() + "', @data)"; + command.CommandText = "INSERT INTO ImageData (ImageID, Data) VALUES (@id, @data)"; + command.Parameters.Add("@id", System.Data.DbType.Int32, 20).Value = id; command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; command.ExecuteReader(); result = true; @@ -1521,101 +1398,95 @@ namespace Vocaluxe.Base private static bool InitCreditsRessourcesDB() { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; - SQLiteCommand command; + using (SQLiteConnection connection = new SQLiteConnection()) + { + connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; - try - { - connection.Open(); - } - catch (Exception) - { - return false; - } - - command = new SQLiteCommand(connection); - command.CommandText = "SELECT Value FROM Version"; - - SQLiteDataReader reader = null; - - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - ; - } - - if (reader == null) - { - // Log error - CLog.LogError("Can't find Credits-DB!"); - } - else if (reader.FieldCount == 0) - { - // Log error - CLog.LogError("Can't find Credits-DB! Field-Count = 0"); - } - else - { - reader.Read(); - - if (reader.GetInt32(0) < CSettings.iDatabaseHighscoreVersion) + try { - // update database + connection.Open(); + } + catch (Exception) + { + return false; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + command.CommandText = "SELECT Value FROM Version"; + + SQLiteDataReader reader = null; + + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + } + + if (reader == null) + { + // Log error + CLog.LogError("Can't find Credits-DB!"); + } + else if (reader.FieldCount == 0) + { + // Log error + CLog.LogError("Can't find Credits-DB! Field-Count = 0"); + } + else + { + reader.Read(); + + if (reader.GetInt32(0) < CSettings.iDatabaseHighscoreVersion) + { + // update database + } + } + + if (reader != null) + reader.Dispose(); } } - - if (reader != null) - { - reader.Close(); - reader.Dispose(); - } - - command.Dispose(); - - connection.Close(); - connection.Dispose(); - return true; } private static void CreateCreditsRessourcesDB() { - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; - SQLiteCommand command; - - try + using (SQLiteConnection connection = new SQLiteConnection()) { - connection.Open(); + connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; + + try + { + connection.Open(); + } + catch (Exception) + { + return; + } + + using (SQLiteCommand command = new SQLiteCommand(connection)) + { + + command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, @Value)"; + command.Parameters.Add("@Value", DbType.Int32).Value = CSettings.iDatabaseCreditsRessourcesVersion; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS Images ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "Path TEXT NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL);"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS ImageData ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + + "ImageID INTEGER NOT NULL, Data BLOB NOT NULL);"; + command.ExecuteNonQuery(); + + } } - catch (Exception) - { - return; - } - - command = new SQLiteCommand(connection); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Version ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Value INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "INSERT INTO Version (id, Value) VALUES(NULL, " + CSettings.iDatabaseCreditsRessourcesVersion.ToString() + ")"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS Images ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "Path TEXT NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL);"; - command.ExecuteNonQuery(); - - command.CommandText = "CREATE TABLE IF NOT EXISTS ImageData ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " + - "ImageID INTEGER NOT NULL, Data BLOB NOT NULL);"; - command.ExecuteNonQuery(); - - command.Dispose(); - connection.Close(); - connection.Dispose(); } #endregion CreditsRessources diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 06967894..3b2e9d17 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -73,7 +73,9 @@ namespace Vocaluxe.Base public static bool Unload() { - return _Draw.Unload(); + bool result = _Draw.Unload(); + _Draw = null; + return result; } public static int GetScreenWidth() @@ -166,20 +168,22 @@ namespace Vocaluxe.Base if (!System.IO.File.Exists(TexturePath)) return new STexture(-1); - Bitmap origin = new Bitmap(TexturePath); - int w = MaxSize; - int h = MaxSize; + using (Bitmap origin = new Bitmap(TexturePath)) + { + int w = MaxSize; + int h = MaxSize; - if (origin.Width >= origin.Height && origin.Width > w) - h = (int)Math.Round((float)w / origin.Width * origin.Height); - else if (origin.Height > origin.Width && origin.Height > h) - w = (int)Math.Round((float)h / origin.Height * origin.Width); + if (origin.Width >= origin.Height && origin.Width > w) + h = (int)Math.Round((float)w / origin.Width * origin.Height); + else if (origin.Height > origin.Width && origin.Height > h) + w = (int)Math.Round((float)h / origin.Height * origin.Width); - Bitmap bmp = new Bitmap(origin, w, h); - STexture tex = _Draw.AddTexture(bmp); - bmp.Dispose(); - origin.Dispose(); - return tex; + using (Bitmap bmp = new Bitmap(origin, w, h)) + { + STexture tex = _Draw.AddTexture(bmp); + return tex; + } + } } public static STexture AddTexture(int W, int H, IntPtr Data) diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index c190e0d2..3361f00c 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -36,66 +36,76 @@ namespace Vocaluxe.Base float factor = GetFactor(chr, flags); CFonts.Height = SIZEh * factor; - Bitmap bmp = new Bitmap(10, 10); - System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); + Font fo; + Size sizeB; + SizeF size; + System.Drawing.Graphics g; + using (Bitmap bmp = new Bitmap(10, 10)) + { + g = System.Drawing.Graphics.FromImage(bmp); - Font fo = CFonts.GetFont(); - Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + fo = CFonts.GetFont(); + sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - SizeF size = g.MeasureString(chr.ToString(), fo); - - g.Dispose(); - bmp.Dispose(); + size = g.MeasureString(chr.ToString(), fo); - bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height); - g = System.Drawing.Graphics.FromImage(bmp); - g.Clear(System.Drawing.Color.Transparent); + g.Dispose(); + } - g.SmoothingMode = SmoothingMode.AntiAlias; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; - CFonts.Height = SIZEh; - fo = CFonts.GetFont(); + using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height)) + { + g = System.Drawing.Graphics.FromImage(bmp); + g.Clear(System.Drawing.Color.Transparent); - PointF point = new PointF( - outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f, - (sizeB.Height - size.Height - (size.Height + SIZEh/4f) * (1f - factor)) / 2f); + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; + CFonts.Height = SIZEh; + fo = CFonts.GetFont(); - GraphicsPath path = new GraphicsPath(); - path.AddString( - chr.ToString(), - fo.FontFamily, - (int)fo.Style, - SIZEh, - point, - new StringFormat()); + PointF point = new PointF( + outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f, + (sizeB.Height - size.Height - (size.Height + SIZEh / 4f) * (1f - factor)) / 2f); - Pen pen = new Pen( - Color.FromArgb( - (int)CFonts.OutlineColor.A * 255, - (int)CFonts.OutlineColor.R * 255, - (int)CFonts.OutlineColor.G * 255, - (int)CFonts.OutlineColor.B * 255), - SIZEh * outline); + using (GraphicsPath path = new GraphicsPath()) + { + path.AddString( + chr.ToString(), + fo.FontFamily, + (int)fo.Style, + SIZEh, + point, + new StringFormat()); - pen.LineJoin = LineJoin.Round; - g.DrawPath(pen, path); - g.FillPath(Brushes.White, path); + using (Pen pen = new Pen( + Color.FromArgb( + (int)CFonts.OutlineColor.A * 255, + (int)CFonts.OutlineColor.R * 255, + (int)CFonts.OutlineColor.G * 255, + (int)CFonts.OutlineColor.B * 255), + SIZEh * outline)) + { - /* - g.DrawString( - chr.ToString(), - fo, - Brushes.White, - point); - * */ + pen.LineJoin = LineJoin.Round; + g.DrawPath(pen, path); + g.FillPath(Brushes.White, path); + } + } - Texture = CDraw.AddTexture(bmp); - //bmp.Save("test.png", ImageFormat.Png); - Chr = chr; - width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width/factor / bmp.Width); + /* + g.DrawString( + chr.ToString(), + fo, + Brushes.White, + point); + * */ - bmp.Dispose(); + Texture = CDraw.AddTexture(bmp); + //bmp.Save("test.png", ImageFormat.Png); + Chr = chr; + width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width / factor / bmp.Width); + + } g.Dispose(); fo.Dispose(); } @@ -114,23 +124,31 @@ namespace Vocaluxe.Base CFonts.Style = EStyle.Normal; CFonts.Height = SIZEh; - Bitmap bmp = new Bitmap(10, 10); - System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); + float h_style, h_normal; + using (Bitmap bmp = new Bitmap(10, 10)) + { + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) + { - Font fo = CFonts.GetFont(); - Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - //SizeF size = g.MeasureString(chr.ToString(), fo); - float h_normal = sizeB.Height; + Font fo = CFonts.GetFont(); + Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + //SizeF size = g.MeasureString(chr.ToString(), fo); + h_normal = sizeB.Height; + } + CFonts.Style = style; - CFonts.Style = style; - bmp = new Bitmap(10, 10); - g = System.Drawing.Graphics.FromImage(bmp); + } + using (Bitmap bmp = new Bitmap(10, 10)) + { + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) + { - fo = CFonts.GetFont(); - sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - //size = g.MeasureString(chr.ToString(), fo); - float h_style = sizeB.Height; - g.Dispose(); + Font fo = CFonts.GetFont(); + Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + //size = g.MeasureString(chr.ToString(), fo); + h_style = sizeB.Height; + } + } return h_normal / h_style; } } @@ -415,7 +433,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (Text == String.Empty) + if (Text.Length == 0) return; Height = h; @@ -452,7 +470,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (Text == String.Empty) + if (Text.Length == 0) return; Height = h; @@ -489,7 +507,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (Text == String.Empty) + if (Text.Length == 0) return; Height = h; @@ -955,7 +973,7 @@ namespace Vocaluxe.Base private static int GetFontIndex(string ThemeName, string FontName) { - if (ThemeName == String.Empty || FontName == String.Empty) + if (ThemeName.Length == 0 || FontName.Length == 0) return -1; for (int i = 0; i < _Fonts.Count; i++) @@ -969,7 +987,7 @@ namespace Vocaluxe.Base private static int GetFontIndexParty(int PartyModeID, string FontName) { - if (PartyModeID == -1 || FontName == String.Empty) + if (PartyModeID == -1 || FontName.Length == 0) return -1; for (int i = 0; i < _Fonts.Count; i++) diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 2ceb98d3..0d24defd 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -871,7 +871,7 @@ namespace Vocaluxe.Base { _Cursor.UnloadTextures(); - if (CTheme.Cursor.color != string.Empty) + if (CTheme.Cursor.color.Length > 0) { SColorF color; color = CTheme.GetColor(CTheme.Cursor.color, -1); diff --git a/Vocaluxe/Base/CInput.cs b/Vocaluxe/Base/CInput.cs index e6465d31..d8aae95e 100644 --- a/Vocaluxe/Base/CInput.cs +++ b/Vocaluxe/Base/CInput.cs @@ -22,6 +22,7 @@ namespace Vocaluxe.Base public static void Close() { _Input.Close(); + _Input = null; } public static bool Connect() diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 3ade852f..4c393ddb 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -351,28 +351,30 @@ namespace Vocaluxe.Base Params.IncludeDebugInformation = true; #endif - CodeDomProvider CDP = CodeDomProvider.CreateProvider("CSharp"); - CompilerResults CompileResult = null; + using (CodeDomProvider CDP = CodeDomProvider.CreateProvider("CSharp")) + { + CompilerResults CompileResult = null; - try - { - CompileResult = CDP.CompileAssemblyFromFile(Params, files); - } - catch (Exception e) - { - CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.Message); - return null; - } - - if (CompileResult.Errors.Count > 0) - { - for (int i = 0; i < CompileResult.Errors.Count; i++) + try { - CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + CompileResult.Errors[i].ErrorText); - } - return null; + CompileResult = CDP.CompileAssemblyFromFile(Params, files); + } + catch (Exception e) + { + CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.Message); + return null; + } + + if (CompileResult.Errors.Count > 0) + { + for (int i = 0; i < CompileResult.Errors.Count; i++) + { + CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + CompileResult.Errors[i].ErrorText); + } + return null; + } + return CompileResult.CompiledAssembly; } - return CompileResult.CompiledAssembly; } private static CMenuParty GetPartyScreenInstance(Assembly Assembly, string ScreenName, string XmlPath) diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index 70569215..5ef193db 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -105,7 +105,7 @@ namespace Vocaluxe.Base { if (PlaylistID < 0 || PlaylistID >= _Playlists.Count) return; - if (_Playlists[PlaylistID].PlaylistFile != String.Empty) + if (_Playlists[PlaylistID].PlaylistFile.Length > 0) { try { @@ -233,46 +233,47 @@ namespace Vocaluxe.Base try { - sr = new StreamReader(file, Encoding.Default, true); - - int pos = -1; - string line; - while((line = sr.ReadLine()) != null) + using (sr = new StreamReader(file, Encoding.Default, true)) { - pos = line.IndexOf(":"); - if (pos > 0) + + int pos = -1; + string line; + while ((line = sr.ReadLine()) != null) { - //Name or comment - if (line[0] == '#') + pos = line.IndexOf(":"); + if (pos > 0) { - string Identifier = line.Substring(1, pos - 1).Trim(); - string Value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - if (Identifier.ToUpper() == "NAME") + //Name or comment + if (line[0] == '#') { - pl.PlaylistName = Value; - } - } - //Song - else - { - string Artist = line.Substring(0, pos - 1).Trim(); - string Title = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - bool found = false; - for (int s = 0; s < AllSongs.Length; s++) - { - if (AllSongs[s].Artist == Artist && AllSongs[s].Title == Title) + string Identifier = line.Substring(1, pos - 1).Trim(); + string Value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); + if (Identifier.ToUpper() == "NAME") { - pl.AddSong(AllSongs[s].ID); - found = true; - break; + pl.PlaylistName = Value; } } - if (!found) - CLog.LogError("Can't find song '" + Title + "' from '" + Artist + "' in playlist file: " + file); + //Song + else + { + string Artist = line.Substring(0, pos - 1).Trim(); + string Title = line.Substring(pos + 1, line.Length - pos - 1).Trim(); + bool found = false; + for (int s = 0; s < AllSongs.Length; s++) + { + if (AllSongs[s].Artist == Artist && AllSongs[s].Title == Title) + { + pl.AddSong(AllSongs[s].ID); + found = true; + break; + } + } + if (!found) + CLog.LogError("Can't find song '" + Title + "' from '" + Artist + "' in playlist file: " + file); + } } } } - sr.Close(); File.Delete(file); } catch diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 686f5c4a..9fc9da0f 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -59,8 +59,8 @@ namespace Vocaluxe.Base profile.Avatar = new SAvatar(-1); profile.GuestProfile = EOffOn.TR_CONFIG_OFF; profile.Active = EOffOn.TR_CONFIG_ON; - - if (FileName != String.Empty) + + if (FileName.Length > 0) profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName); else profile.ProfileFile = String.Empty; @@ -253,7 +253,7 @@ namespace Vocaluxe.Base { if (ProfileID < 0 || ProfileID >= _Profiles.Count) return; - if (_Profiles[ProfileID].ProfileFile != String.Empty) + if (_Profiles[ProfileID].ProfileFile.Length > 0) { try { @@ -293,7 +293,7 @@ namespace Vocaluxe.Base if (ProfileID < 0 || ProfileID >= _Profiles.Count) return; - if (_Profiles[ProfileID].ProfileFile == String.Empty) + if (_Profiles[ProfileID].ProfileFile.Length == 0) { string filename = string.Empty; foreach (char chr in _Profiles[ProfileID].PlayerName) @@ -302,7 +302,7 @@ namespace Vocaluxe.Base filename += chr.ToString(); } - if (filename == String.Empty) + if (filename.Length == 0) filename = "1"; int i = 0; @@ -330,29 +330,30 @@ namespace Vocaluxe.Base CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile + ": " + e.Message); return; } - - if (writer == null) + try { - CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile); - return; + + writer.WriteStartDocument(); + writer.WriteStartElement("root"); + + writer.WriteStartElement("Info"); + writer.WriteElementString("PlayerName", _Profiles[ProfileID].PlayerName); + writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), _Profiles[ProfileID].Difficulty)); + writer.WriteElementString("Avatar", _Profiles[ProfileID].Avatar.FileName); + writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].GuestProfile)); + writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].Active)); + writer.WriteEndElement(); + + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); + + writer.Flush(); + } + finally + { + writer.Close(); + writer = null; } - - writer.WriteStartDocument(); - writer.WriteStartElement("root"); - - writer.WriteStartElement("Info"); - writer.WriteElementString("PlayerName", _Profiles[ProfileID].PlayerName); - writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), _Profiles[ProfileID].Difficulty)); - writer.WriteElementString("Avatar", _Profiles[ProfileID].Avatar.FileName); - writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].GuestProfile)); - writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].Active)); - writer.WriteEndElement(); - - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); - - writer.Flush(); - writer.Close(); } private static void LoadProfile(string FileName) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 79133616..c13bd022 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -145,7 +145,7 @@ namespace Vocaluxe.Base { string sVersion = sProgramName; - if (sProgramCodeName != String.Empty) + if (sProgramCodeName.Length > 0) sVersion += " \"" + sProgramCodeName + "\""; return sVersion += " " + GetVersionText(); diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 75241ded..4a3751c5 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -64,7 +64,7 @@ namespace Vocaluxe.Base get { return _SearchFilter; } set { - if (value != String.Empty) + if (value.Length > 0) { _Sort(_SongSorting, EOffOn.TR_CONFIG_OFF, _IgnoreArticles, value, false, _ShowDuetSongs); } @@ -409,14 +409,14 @@ namespace Vocaluxe.Base _FilteredSongs.Clear(); string[] searchStrings = null; - if (_SearchFilter != String.Empty) + if (_SearchFilter.Length > 0) searchStrings = _SearchFilter.ToUpper().Split(new char[] { ' ' }); foreach (CSong song in _Songs) { if (!song.IsDuet || _ShowDuetSongs) { - if (_SearchFilter == String.Empty) + if (_SearchFilter.Length == 0) _FilteredSongs.Add(song); else if (searchStrings != null) { @@ -480,7 +480,7 @@ namespace Vocaluxe.Base FieldInfo field = null; bool isString = false; List SortList = new List(); - if (fieldName == String.Empty) + if (fieldName.Length == 0) _FilteredSongs.ForEach((song) => SortList.Add(new SongPointer(song.ID, ""))); { field = Type.GetType("Vocaluxe.Menu.SongMenu.CSong,VocaluxeLib").GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); @@ -657,7 +657,7 @@ namespace Vocaluxe.Base for (int i = 0; i < _SongsSortList.Length; i++) { string Year = _SongsSortList[i].SortString; - if (Year != "") + if (Year.Length > 0) { Year = Year.Substring(0, 3); _SongsSortList[i].SortString = Year + "0 - " + Year + "9"; diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 14747225..2f902c67 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -165,7 +165,7 @@ namespace Vocaluxe.Base break; } - if (file == String.Empty) + if (file.Length == 0) return -1; int stream = CSound.Load(file); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index cbd80aab..225a5256 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -313,40 +313,41 @@ namespace Vocaluxe.Base private static void SaveTheme(int ThemeIndex) { #region ThemeMainFile - XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[ThemeIndex].Path, _Themes[ThemeIndex].FileName), _settings); - writer.WriteStartDocument(); - writer.WriteStartElement("root"); + using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[ThemeIndex].Path, _Themes[ThemeIndex].FileName), _settings)) + { + writer.WriteStartDocument(); + writer.WriteStartElement("root"); - // ThemeSystemVersion - writer.WriteElementString("ThemeSystemVersion", ThemeSystemVersion.ToString()); + // ThemeSystemVersion + writer.WriteElementString("ThemeSystemVersion", ThemeSystemVersion.ToString()); - #region Info - writer.WriteStartElement("Info"); + #region Info + writer.WriteStartElement("Info"); - writer.WriteElementString("Name", _Themes[ThemeIndex].Name); - writer.WriteElementString("Author", _Themes[ThemeIndex].Author); - writer.WriteElementString("SkinFolder", _Themes[ThemeIndex].SkinFolder); - writer.WriteElementString("ThemeVersionMajor", _Themes[ThemeIndex].ThemeVersionMajor.ToString()); - writer.WriteElementString("ThemeVersionMinor", _Themes[ThemeIndex].ThemeVersionMinor.ToString()); + writer.WriteElementString("Name", _Themes[ThemeIndex].Name); + writer.WriteElementString("Author", _Themes[ThemeIndex].Author); + writer.WriteElementString("SkinFolder", _Themes[ThemeIndex].SkinFolder); + writer.WriteElementString("ThemeVersionMajor", _Themes[ThemeIndex].ThemeVersionMajor.ToString()); + writer.WriteElementString("ThemeVersionMinor", _Themes[ThemeIndex].ThemeVersionMinor.ToString()); - writer.WriteEndElement(); - #endregion Info + writer.WriteEndElement(); + #endregion Info - // Cursor - if (_Themes[ThemeIndex].PartyModeID == -1) - SaveCursor(writer); + // Cursor + if (_Themes[ThemeIndex].PartyModeID == -1) + SaveCursor(writer); - // save fonts - if (_Themes[ThemeIndex].PartyModeID == -1) - CFonts.SaveThemeFonts(_Themes[ThemeIndex].Name, writer); + // save fonts + if (_Themes[ThemeIndex].PartyModeID == -1) + CFonts.SaveThemeFonts(_Themes[ThemeIndex].Name, writer); - // End of File - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); + // End of File + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); - writer.Flush(); - writer.Close(); + writer.Flush(); + } #endregion ThemeMainFile } @@ -354,53 +355,54 @@ namespace Vocaluxe.Base { for (int SkinIndex = 0; SkinIndex < _Skins.Count; SkinIndex++) { - XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[SkinIndex].Path, _Skins[SkinIndex].FileName), _settings); - writer.WriteStartDocument(); - writer.WriteStartElement("root"); - - // ThemeSystemVersion - writer.WriteElementString("SkinSystemVersion", SkinSystemVersion.ToString()); - - #region Info - writer.WriteStartElement("Info"); - - writer.WriteElementString("Name", _Skins[SkinIndex].Name); - writer.WriteElementString("Author", _Skins[SkinIndex].Author); - writer.WriteElementString("SkinVersionMajor", _Skins[SkinIndex].SkinVersionMajor.ToString()); - writer.WriteElementString("SkinVersionMinor", _Skins[SkinIndex].SkinVersionMinor.ToString()); - - writer.WriteEndElement(); - #endregion Info - - // save colors - SaveColors(writer, SkinIndex); - - #region Skins - writer.WriteStartElement("Skins"); - - foreach (SkinElement element in _Skins[SkinIndex].SkinList.Values) + using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[SkinIndex].Path, _Skins[SkinIndex].FileName), _settings)) { - writer.WriteElementString(element.Name, element.Value); + writer.WriteStartDocument(); + writer.WriteStartElement("root"); + + // ThemeSystemVersion + writer.WriteElementString("SkinSystemVersion", SkinSystemVersion.ToString()); + + #region Info + writer.WriteStartElement("Info"); + + writer.WriteElementString("Name", _Skins[SkinIndex].Name); + writer.WriteElementString("Author", _Skins[SkinIndex].Author); + writer.WriteElementString("SkinVersionMajor", _Skins[SkinIndex].SkinVersionMajor.ToString()); + writer.WriteElementString("SkinVersionMinor", _Skins[SkinIndex].SkinVersionMinor.ToString()); + + writer.WriteEndElement(); + #endregion Info + + // save colors + SaveColors(writer, SkinIndex); + + #region Skins + writer.WriteStartElement("Skins"); + + foreach (SkinElement element in _Skins[SkinIndex].SkinList.Values) + { + writer.WriteElementString(element.Name, element.Value); + } + writer.WriteEndElement(); + #endregion Skins + + #region Videos + writer.WriteStartElement("Videos"); + + foreach (SkinElement element in _Skins[SkinIndex].VideoList) + { + writer.WriteElementString(element.Name, element.Value); + } + writer.WriteEndElement(); + #endregion Videos + + // End of File + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); + + writer.Flush(); } - writer.WriteEndElement(); - #endregion Skins - - #region Videos - writer.WriteStartElement("Videos"); - - foreach (SkinElement element in _Skins[SkinIndex].VideoList) - { - writer.WriteElementString(element.Name, element.Value); - } - writer.WriteEndElement(); - #endregion Videos - - // End of File - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); - - writer.Flush(); - writer.Close(); } } @@ -439,7 +441,7 @@ namespace Vocaluxe.Base if (version == ThemeSystemVersion) { xmlReader.GetValue("//root/Info/Name", ref theme.Name, String.Empty); - if (theme.Name != String.Empty) + if (theme.Name.Length > 0) { xmlReader.GetValue("//root/Info/Author", ref theme.Author, String.Empty); xmlReader.GetValue("//root/Info/SkinFolder", ref theme.SkinFolder, String.Empty); @@ -514,7 +516,7 @@ namespace Vocaluxe.Base if (version == SkinSystemVersion) { xmlReader.GetValue("//root/Info/Name", ref skin.Name, String.Empty); - if (skin.Name != String.Empty) + if (skin.Name.Length > 0) { xmlReader.GetValue("//root/Info/Author", ref skin.Author, String.Empty); xmlReader.TryGetIntValue("//root/Info/SkinVersionMajor", ref skin.SkinVersionMajor); @@ -866,7 +868,7 @@ namespace Vocaluxe.Base writer.WriteElementString("W", Cursor.w.ToString("#0.000")); writer.WriteElementString("H", Cursor.h.ToString("#0.000")); - if (Cursor.color != String.Empty) + if (Cursor.color.Length > 0) { writer.WriteElementString("Color", Cursor.color); } diff --git a/Vocaluxe/GlobalSuppressions.cs b/Vocaluxe/GlobalSuppressions.cs new file mode 100644 index 00000000..0b83f3ab --- /dev/null +++ b/Vocaluxe/GlobalSuppressions.cs @@ -0,0 +1,14 @@ +// Diese Datei wird von der Codeanalyse zur Wartung der SuppressMessage- +// Attribute verwendet, die auf dieses Projekt angewendet werden. +// Unterdrückungen auf Projektebene haben entweder kein Ziel oder +// erhalten ein spezifisches Ziel mit Namespace-, Typ-, Memberbereich usw. +// +// Wenn Sie dieser Datei eine Unterdrückung hinzufügen möchten, klicken Sie mit der +// rechten Maustaste auf die Meldung in der Fehlerliste, zeigen Sie auf +// "Meldung(en) unterdrücken", und klicken Sie auf "In Projektunterdrückungsdatei". +// Sie müssen dieser Datei nicht manuell Unterdrückungen hinzufügen. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom", Scope = "member", Target = "Vocaluxe.MainProgram.#AssemblyResolver(System.Object,System.ResolveEventArgs)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Objekte verwerfen, bevor Bereich verloren geht", Scope = "member", Target = "Vocaluxe.Lib.Draw.CDrawWinForm.#ColorizeBitmap(System.Drawing.Bitmap,Vocaluxe.Menu.SColorF)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Objekte verwerfen, bevor Bereich verloren geht", Scope = "member", Target = "Vocaluxe.Lib.Draw.CDrawWinForm.#CopyScreen(Vocaluxe.Menu.STexture&)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Objekte verwerfen, bevor Bereich verloren geht", Scope = "member", Target = "Vocaluxe.Base.CGlyph.#.ctor(System.Char,System.Single)")] diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index d7aa03e6..ae483f01 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -493,13 +493,14 @@ namespace Vocaluxe.Lib.Draw //This creates a new white texture and adds it to the texture pool //This texture is used for the DrawRect method - Bitmap blankMap = new Bitmap(1, 1); - Graphics g = Graphics.FromImage(blankMap); - g.Clear(Color.White); - g.Dispose(); - _BlankTexture = AddTexture(blankMap); + using (Bitmap blankMap = new Bitmap(1, 1)) + { + Graphics g = Graphics.FromImage(blankMap); + g.Clear(Color.White); + g.Dispose(); + _BlankTexture = AddTexture(blankMap); - blankMap.Dispose(); + } return true; } else @@ -560,7 +561,7 @@ namespace Vocaluxe.Lib.Draw } } //Apply fullscreen mode - if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) + if (CSettings.bFullScreen != _fullscreen) { if (!_fullscreen) EnterFullScreen(); @@ -575,10 +576,9 @@ namespace Vocaluxe.Lib.Draw //Calculate the FPS Rate and restart the timer after a frame CTime.CalculateFPS(); CTime.Restart(); - } - else - this.Close(); + } } + this.Close(); } /// @@ -881,8 +881,15 @@ namespace Vocaluxe.Lib.Draw CLog.LogError("Error loading Texture: " + TexturePath); return new STexture(-1); } - STexture s = AddTexture(bmp, TexturePath); - bmp.Dispose(); + STexture s; + try + { + s = AddTexture(bmp, TexturePath); + } + finally + { + bmp.Dispose(); + } return s; } CLog.LogError("Can't find File: " + TexturePath); diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 51cc0c4f..7edd16c7 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -246,9 +246,8 @@ namespace Vocaluxe.Lib.Draw CTime.CalculateFPS(); CTime.Restart(); } - else - this.Close(); } + this.Close(); } public bool Unload() @@ -396,8 +395,10 @@ namespace Vocaluxe.Lib.Draw if (!found) { - Bitmap bmp = new Bitmap(TexturePath); - return AddTexture(bmp); + using (Bitmap bmp = new Bitmap(TexturePath)) + { + return AddTexture(bmp); + } } } @@ -433,11 +434,13 @@ namespace Vocaluxe.Lib.Draw public STexture AddTexture(int W, int H, ref byte[] Data) { - Bitmap bmp = new Bitmap(W, H); - BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - Marshal.Copy(Data, 0, bmp_data.Scan0, Data.Length); - bmp.UnlockBits(bmp_data); - return AddTexture(bmp); + using (Bitmap bmp = new Bitmap(W, H)) + { + BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + Marshal.Copy(Data, 0, bmp_data.Scan0, Data.Length); + bmp.UnlockBits(bmp_data); + return AddTexture(bmp); + } } public bool UpdateTexture(ref STexture Texture, IntPtr Data) @@ -525,23 +528,25 @@ namespace Vocaluxe.Lib.Draw { Bitmap newBitmap = new Bitmap(original.Width, original.Height); - Graphics g = Graphics.FromImage(newBitmap); + using (Graphics g = Graphics.FromImage(newBitmap)) + { - ColorMatrix cm = new ColorMatrix(); - cm.Matrix33 = color.A; - cm.Matrix00 = color.R; - cm.Matrix11 = color.G; - cm.Matrix22 = color.B; - cm.Matrix44 = 1; + ColorMatrix cm = new ColorMatrix(); + cm.Matrix33 = color.A; + cm.Matrix00 = color.R; + cm.Matrix11 = color.G; + cm.Matrix22 = color.B; + cm.Matrix44 = 1; - ImageAttributes ia = new ImageAttributes(); - ia.SetColorMatrix(cm); + using (ImageAttributes ia = new ImageAttributes()) + { + ia.SetColorMatrix(cm); - g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), - 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia); + g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), + 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia); - ia.Dispose(); - g.Dispose(); + } + } return newBitmap; } diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 06a09e95..8300f10b 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -500,9 +500,8 @@ namespace Vocaluxe.Lib.Draw CTime.CalculateFPS(); CTime.Restart(); } - else - this.Close(); } + this.Close(); } public bool Unload() @@ -617,17 +616,18 @@ namespace Vocaluxe.Lib.Draw int width = GetScreenWidth(); int height = GetScreenHeight(); - Bitmap screen = new Bitmap(width, height); + using (Bitmap screen = new Bitmap(width, height)) + { - BitmapData bmp_data = screen.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + BitmapData bmp_data = screen.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - GL.ReadPixels(0, 0, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0); - screen.UnlockBits(bmp_data); + GL.ReadPixels(0, 0, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0); + screen.UnlockBits(bmp_data); - screen.RotateFlip(RotateFlipType.RotateNoneFlipY); - screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); - screen.Dispose(); + screen.RotateFlip(RotateFlipType.RotateNoneFlipY); + screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); + } } public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) @@ -799,27 +799,28 @@ namespace Vocaluxe.Lib.Draw texture.w2 = (float)MathHelper.NextPowerOfTwo(w); texture.h2 = (float)MathHelper.NextPowerOfTwo(h); - Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); - Graphics g = Graphics.FromImage(bmp2); - g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; - g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; - g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); - g.Dispose(); + using (Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2)) + { + Graphics g = Graphics.FromImage(bmp2); + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); + g.Dispose(); - texture.width_ratio = 1f; - texture.height_ratio = 1f; + texture.width_ratio = 1f; + texture.height_ratio = 1f; - BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.w2, (int)texture.h2, 0, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.w2, (int)texture.h2, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, bmp_data.Width, bmp_data.Height, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, bmp_data.Width, bmp_data.Height, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0); - bmp2.UnlockBits(bmp_data); - bmp2.Dispose(); + bmp2.UnlockBits(bmp_data); + } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); diff --git a/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs b/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs index 4992a38d..8bb4c866 100644 --- a/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs +++ b/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs @@ -674,8 +674,11 @@ namespace Vocaluxe.Lib.Input.WiiMote protected virtual void Dispose(bool disposing) { - if(disposing) - Disconnect(); + if (disposing) + { + Disconnect(); + _ReadDone.Close(); + } } #endregion } diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index 38cca523..4ee9bdd1 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -43,7 +43,7 @@ namespace Vocaluxe.Lib.Playlist public void SavePlaylist() { - if (PlaylistFile == string.Empty) + if (PlaylistFile.Length == 0) { string filename = string.Empty; foreach (char chr in PlaylistName) @@ -52,7 +52,7 @@ namespace Vocaluxe.Lib.Playlist filename += chr.ToString(); } - if (filename == String.Empty) + if (filename.Length == 0) filename = "1"; int i = 0; @@ -85,37 +85,43 @@ namespace Vocaluxe.Lib.Playlist return; } - writer.WriteStartDocument(); - writer.WriteStartElement("root"); - - writer.WriteStartElement("Info"); - writer.WriteElementString("PlaylistName", PlaylistName); - writer.WriteEndElement(); - - writer.WriteStartElement("Songs"); - for (int i = 0; i < Songs.Count; i++) + try { - CSong song = CSongs.GetSong(Songs[i].SongID); - if (song != null) + writer.WriteStartDocument(); + writer.WriteStartElement("root"); + + writer.WriteStartElement("Info"); + writer.WriteElementString("PlaylistName", PlaylistName); + writer.WriteEndElement(); + + writer.WriteStartElement("Songs"); + for (int i = 0; i < Songs.Count; i++) { - writer.WriteStartElement("Song" + (i + 1).ToString()); - writer.WriteElementString("Artist", song.Artist); - writer.WriteElementString("Title", song.Title); - writer.WriteElementString("GameMode", Enum.GetName(typeof(EGameMode), Songs[i].GameMode)); - writer.WriteEndElement(); - } - else - { - CLog.LogError("Playlist.SavePlaylist(): Can't find Song. This should never happen!"); + CSong song = CSongs.GetSong(Songs[i].SongID); + if (song != null) + { + writer.WriteStartElement("Song" + (i + 1).ToString()); + writer.WriteElementString("Artist", song.Artist); + writer.WriteElementString("Title", song.Title); + writer.WriteElementString("GameMode", Enum.GetName(typeof(EGameMode), Songs[i].GameMode)); + writer.WriteEndElement(); + } + else + { + CLog.LogError("Playlist.SavePlaylist(): Can't find Song. This should never happen!"); + } } + writer.WriteEndElement(); + + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); + + writer.Flush(); + } + finally + { + writer.Close(); } - writer.WriteEndElement(); - - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); - - writer.Flush(); - writer.Close(); } private void LoadPlaylist() diff --git a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs index c8abe845..a16e9409 100644 --- a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs +++ b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs @@ -36,26 +36,27 @@ namespace Vocaluxe.Lib.Sound int id = 0; foreach (DeviceInformation dev in devices) { - DirectSoundCapture ds = new DirectSoundCapture(dev.DriverGuid); + using (DirectSoundCapture ds = new DirectSoundCapture(dev.DriverGuid)) + { - SRecordDevice device = new SRecordDevice(); - device.Driver = dev.DriverGuid.ToString(); - device.ID = id; - device.Name = dev.Description; - device.Inputs = new List(); + SRecordDevice device = new SRecordDevice(); + device.Driver = dev.DriverGuid.ToString(); + device.ID = id; + device.Name = dev.Description; + device.Inputs = new List(); - SInput inp = new SInput(); - inp.Name = "Default"; - inp.Channels = ds.Capabilities.Channels; + SInput inp = new SInput(); + inp.Name = "Default"; + inp.Channels = ds.Capabilities.Channels; - if (inp.Channels > 2) - inp.Channels = 2; //more are not supported in vocaluxe + if (inp.Channels > 2) + inp.Channels = 2; //more are not supported in vocaluxe - device.Inputs.Add(inp); - _Devices.Add(device); + device.Inputs.Add(inp); + _Devices.Add(device); - id++; - ds.Dispose(); + id++; + } } _DeviceConfig = _Devices.ToArray(); @@ -68,11 +69,7 @@ namespace Vocaluxe.Lib.Sound { if (_initialized) { - foreach (SoundCardSource source in _Sources) - { - source.Stop(); - source.Dispose(); - } + Stop(); _initialized = false; } //System.IO.File.WriteAllBytes("test0.raw", _Buffer[0].Buffer); @@ -131,7 +128,10 @@ namespace Vocaluxe.Lib.Sound foreach (SoundCardSource source in _Sources) { source.Stop(); + source.Dispose(); } + _Sources.Clear(); + return true; } public void AnalyzeBuffer(int Player) diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 3dc53446..9b1a333c 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -164,7 +164,7 @@ namespace Vocaluxe.Lib.Webcam return false; //No MonikerString found, try first webcam - if (Config.MonikerString == String.Empty) + if (Config.MonikerString.Length == 0) _Webcam = new VideoCaptureDevice(_WebcamDevices[0].MonikerString); else //Found MonikerString _Webcam = new VideoCaptureDevice(Config.MonikerString); diff --git a/Vocaluxe/Properties/AssemblyInfo.cs b/Vocaluxe/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..dfc9df0d --- /dev/null +++ b/Vocaluxe/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("Vocaluxe.Properties")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Vocaluxe.Properties")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("da631594-f891-4994-9869-c37e626e44f9")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 2ca30655..1767dd95 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -597,7 +597,7 @@ namespace Vocaluxe.Screens for (int i = 0; i < CSettings.MaxNumPlayer; i++) { //Update texture and name - if (CConfig.Players[i] != String.Empty) + if (CConfig.Players[i].Length > 0) { Statics[htStatics(StaticPlayerAvatar[i])].Texture = CProfiles.Profiles[CGame.Player[i].ProfileID].Avatar.Texture; Texts[htTexts(TextPlayer[i])].Text = CProfiles.Profiles[CGame.Player[i].ProfileID].PlayerName; @@ -692,7 +692,7 @@ namespace Vocaluxe.Screens Statics[htStatics("StaticPlayer" + i)].Visible = true; Statics[htStatics("StaticPlayerAvatar" + i)].Visible = true; Texts[htTexts("TextPlayer" + i)].Visible = true; - if (Texts[htTexts("TextPlayer" + i)].Text == string.Empty) + if (Texts[htTexts("TextPlayer" + i)].Text.Length == 0) { Texts[htTexts("TextPlayer" + i)].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + i.ToString(); } diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 29ef67a8..51ea197d 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -622,7 +622,7 @@ namespace Vocaluxe.Screens CDraw.RemoveTexture(ref _CurrentVideoTexture); - if (song.VideoFileName != String.Empty) + if (song.VideoFileName.Length > 0) { _CurrentVideo = CVideo.VdLoad(Path.Combine(song.Folder, song.VideoFileName)); CVideo.VdSkip(_CurrentVideo, song.Start, song.VideoGap); @@ -630,7 +630,7 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); - if (song.BackgroundFileName != String.Empty) + if (song.BackgroundFileName.Length > 0) _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileName)); SingNotes[htSingNotes(SingBars)].Reset(); diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 6ee33631..ecbfdad2 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -1105,13 +1105,13 @@ namespace Vocaluxe.Screens SongID = CSongs.VisibleSongs[SongIndex].ID; } - if (NewFilterString == String.Empty && _sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) + if (NewFilterString.Length == 0 && _sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) { CSongs.Category = -1; refresh = true; } - if (NewFilterString != String.Empty && CSongs.Category != 0) + if (NewFilterString.Length > 0 && CSongs.Category != 0) { CSongs.Category = 0; refresh = true; diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index f0e6b365..062512ba 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -63,6 +63,7 @@ prompt 4 Off + ..\CheckingRules.ruleset x64 @@ -193,6 +194,7 @@ + Form diff --git a/VocaluxeLib/GlobalSuppressions.cs b/VocaluxeLib/GlobalSuppressions.cs new file mode 100644 index 00000000..c04a0e50 --- /dev/null +++ b/VocaluxeLib/GlobalSuppressions.cs @@ -0,0 +1,12 @@ +// Diese Datei wird von der Codeanalyse zur Wartung der SuppressMessage- +// Attribute verwendet, die auf dieses Projekt angewendet werden. +// Unterdrückungen auf Projektebene haben entweder kein Ziel oder +// erhalten ein spezifisches Ziel mit Namespace-, Typ-, Memberbereich usw. +// +// Wenn Sie dieser Datei eine Unterdrückung hinzufügen möchten, klicken Sie mit der +// rechten Maustaste auf die Meldung in der Fehlerliste, zeigen Sie auf +// "Meldung(en) unterdrücken", und klicken Sie auf "In Projektunterdrückungsdatei". +// Sie müssen dieser Datei nicht manuell Unterdrückungen hinzufügen. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "Vocaluxe.Menu.CHelper.TryParse(System.String,System.Single@)", Scope = "member", Target = "Vocaluxe.Menu.SongMenu.CSong.#ReadHeader(System.String)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Int32.TryParse(System.String,System.Int32@)", Scope = "member", Target = "Vocaluxe.Menu.SongMenu.CSong.#ReadNotes(System.String,System.Boolean)")] diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 7d0f06d7..41a7fbe9 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -104,7 +104,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Background color for type \"Color\" from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -127,13 +127,13 @@ namespace Vocaluxe.Menu public void Resume() { - if (_Theme.Type == EBackgroundTypes.Video && _Theme.VideoName != String.Empty && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) + if (_Theme.Type == EBackgroundTypes.Video && _Theme.VideoName.Length > 0 && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) CBase.Theme.SkinVideoResume(_Theme.VideoName, _PartyModeID); } public void Pause() { - if (_Theme.VideoName != String.Empty) + if (_Theme.VideoName.Length > 0) CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID); } @@ -153,7 +153,7 @@ namespace Vocaluxe.Menu ok = DrawVideo(); } - if (_Theme.TextureName != String.Empty && + if (_Theme.TextureName.Length > 0 && (_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) ok = DrawTexture(); @@ -171,7 +171,7 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index f8b99d40..bf41eeea 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -227,7 +227,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -241,7 +241,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) { writer.WriteElementString("SColor", _Theme.SColorName); } @@ -370,10 +370,10 @@ namespace Vocaluxe.Menu { Text.LoadTextures(); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) SColor = CBase.Theme.GetColor(_Theme.SColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CEqualizer.cs b/VocaluxeLib/Menu/CEqualizer.cs index 7e68a6c4..0cfe3d52 100644 --- a/VocaluxeLib/Menu/CEqualizer.cs +++ b/VocaluxeLib/Menu/CEqualizer.cs @@ -165,7 +165,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Equalizer color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -178,7 +178,7 @@ namespace Vocaluxe.Menu } writer.WriteComment(": Equalizer color for maximal volume from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("MaxColor", _Theme.ColorName); } @@ -273,10 +273,10 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.MaxColorName != String.Empty) + if (_Theme.MaxColorName.Length > 0) MaxColor = CBase.Theme.GetColor(_Theme.MaxColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CHelper.cs b/VocaluxeLib/Menu/CHelper.cs index 67d8a75e..f59c4fd6 100644 --- a/VocaluxeLib/Menu/CHelper.cs +++ b/VocaluxeLib/Menu/CHelper.cs @@ -73,8 +73,9 @@ namespace Vocaluxe.Menu return 0; } int result = 0; - int.TryParse(value, out result); - return result; + if(int.TryParse(value, out result)) + return result; + return 0; } public static void SetRect(RectangleF Bounds, ref RectangleF Rect, float RectAspect, EAspect Aspect) diff --git a/VocaluxeLib/Menu/CLyric.cs b/VocaluxeLib/Menu/CLyric.cs index 4034b312..33767112 100644 --- a/VocaluxeLib/Menu/CLyric.cs +++ b/VocaluxeLib/Menu/CLyric.cs @@ -164,7 +164,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Lyric text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -178,7 +178,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Highlighted lyric color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) { writer.WriteElementString("SColor", _Theme.SColorName); } @@ -547,10 +547,10 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) ColorProcessed = CBase.Theme.GetColor(_Theme.SColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 977674c5..c2e03576 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -409,7 +409,7 @@ namespace Vocaluxe.Menu public virtual void SaveTheme() { - if (_ThemePath == String.Empty) + if (_ThemePath.Length == 0) return; XmlWriterSettings settings = new XmlWriterSettings(); @@ -418,98 +418,99 @@ namespace Vocaluxe.Menu settings.ConformanceLevel = ConformanceLevel.Document; string file = Path.Combine(_ThemePath, _ThemeName + ".xml"); - XmlWriter writer = XmlWriter.Create(file, settings); - - writer.WriteStartDocument(); - writer.WriteStartElement("root"); - - writer.WriteStartElement(_ThemeName); - - // Screen Version - writer.WriteElementString("ScreenVersion", _ScreenVersion.ToString()); - - // Backgrounds - for (int i = 0; i < _Backgrounds.Count; i++) - _Backgrounds[i].SaveTheme(writer); - - // Statics - for (int i = 0; i < _Statics.Count; i++) - _Statics[i].SaveTheme(writer); - - // Texts - for (int i = 0; i < _Texts.Count; i++) + using (XmlWriter writer = XmlWriter.Create(file, settings)) { - _Texts[i].SaveTheme(writer); + + writer.WriteStartDocument(); + writer.WriteStartElement("root"); + + writer.WriteStartElement(_ThemeName); + + // Screen Version + writer.WriteElementString("ScreenVersion", _ScreenVersion.ToString()); + + // Backgrounds + for (int i = 0; i < _Backgrounds.Count; i++) + _Backgrounds[i].SaveTheme(writer); + + // Statics + for (int i = 0; i < _Statics.Count; i++) + _Statics[i].SaveTheme(writer); + + // Texts + for (int i = 0; i < _Texts.Count; i++) + { + _Texts[i].SaveTheme(writer); + } + + // Buttons + for (int i = 0; i < _Buttons.Count; i++) + { + _Buttons[i].SaveTheme(writer); + } + + // SelectSlides + for (int i = 0; i < _SelectSlides.Count; i++) + { + _SelectSlides[i].SaveTheme(writer); + } + + // SongMenus + for (int i = 0; i < _SongMenus.Count; i++) + { + _SongMenus[i].SaveTheme(writer); + } + + // Lyrics + for (int i = 0; i < _Lyrics.Count; i++) + { + _Lyrics[i].SaveTheme(writer); + } + + // SingBars + for (int i = 0; i < _SingNotes.Count; i++) + { + _SingNotes[i].SaveTheme(writer); + } + + // NameSelections + for (int i = 0; i < _NameSelections.Count; i++) + { + _NameSelections[i].SaveTheme(writer); + } + + //Equalizers + for (int i = 0; i < _Equalizers.Count; i++) + { + _Equalizers[i].SaveTheme(writer); + } + + //Playlists + for (int i = 0; i < _Playlists.Count; i++) + { + _Playlists[i].SaveTheme(writer); + } + + //ParticleEffects + for (int i = 0; i < _ParticleEffects.Count; i++) + { + _ParticleEffects[i].SaveTheme(writer); + } + + //ScreenSettings + for (int i = 0; i < _ScreenSettings.Count; i++) + { + _ScreenSettings[i].SaveTheme(writer); + } + + writer.WriteEndElement(); + + // End of File + writer.WriteEndElement(); //end of root + writer.WriteEndDocument(); + + writer.Flush(); } - - // Buttons - for (int i = 0; i < _Buttons.Count; i++) - { - _Buttons[i].SaveTheme(writer); - } - - // SelectSlides - for (int i = 0; i < _SelectSlides.Count; i++) - { - _SelectSlides[i].SaveTheme(writer); - } - - // SongMenus - for (int i = 0; i < _SongMenus.Count; i++) - { - _SongMenus[i].SaveTheme(writer); - } - - // Lyrics - for (int i = 0; i < _Lyrics.Count; i++) - { - _Lyrics[i].SaveTheme(writer); - } - - // SingBars - for (int i = 0; i < _SingNotes.Count; i++) - { - _SingNotes[i].SaveTheme(writer); - } - - // NameSelections - for (int i = 0; i < _NameSelections.Count; i++) - { - _NameSelections[i].SaveTheme(writer); - } - - //Equalizers - for (int i = 0; i < _Equalizers.Count; i++) - { - _Equalizers[i].SaveTheme(writer); - } - - //Playlists - for (int i = 0; i < _Playlists.Count; i++) - { - _Playlists[i].SaveTheme(writer); - } - - //ParticleEffects - for (int i = 0; i < _ParticleEffects.Count; i++) - { - _ParticleEffects[i].SaveTheme(writer); - } - - //ScreenSettings - for (int i = 0; i < _ScreenSettings.Count; i++) - { - _ScreenSettings[i].SaveTheme(writer); - } - - writer.WriteEndElement(); - - // End of File - writer.WriteEndElement(); //end of root - writer.WriteEndDocument(); - - writer.Flush(); - writer.Close(); } public virtual void ReloadTextures() @@ -649,7 +650,7 @@ namespace Vocaluxe.Menu public virtual void ReloadTheme(string XmlPath) { - if (_ThemePath == String.Empty) + if (_ThemePath.Length == 0) return; UnloadTextures(); diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index f8ec3b75..8e6eadcf 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -182,7 +182,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorEmptyTileName != String.Empty) + if (_Theme.ColorEmptyTileName.Length > 0) { writer.WriteElementString("ColorEmptyTile", _Theme.ColorEmptyTileName); } @@ -215,7 +215,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Text font name"); writer.WriteElementString("Font", _Theme.NameFont); writer.WriteComment(": Text color from ColorScheme (high priority)"); - if (_Theme.NameColorName != String.Empty) + if (_Theme.NameColorName.Length > 0) { writer.WriteElementString("Color", _Theme.NameColorName); } @@ -474,10 +474,10 @@ namespace Vocaluxe.Menu _TextureEmptyTile = CBase.Theme.GetSkinTexture(_Theme.TextureEmptyTileName, _PartyModeID); _TextureTileSelected = CBase.Theme.GetSkinTexture(_Theme.TextureTileSelectedName, _PartyModeID); - if (_Theme.ColorEmptyTileName != String.Empty) + if (_Theme.ColorEmptyTileName.Length > 0) ColorEmptyTile = CBase.Theme.GetColor(_Theme.ColorEmptyTileName, _PartyModeID); - if (_Theme.NameColorName != String.Empty) + if (_Theme.NameColorName.Length > 0) _Theme.NameColor = CBase.Theme.GetColor(_Theme.NameColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CObjectInteractions.cs b/VocaluxeLib/Menu/CObjectInteractions.cs index 525a00e3..631e12b7 100644 --- a/VocaluxeLib/Menu/CObjectInteractions.cs +++ b/VocaluxeLib/Menu/CObjectInteractions.cs @@ -42,7 +42,7 @@ namespace Vocaluxe.Menu Init(); } - protected virtual void Init() + protected void Init() { _Interactions = new List(); _Selection = 0; diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index 19227f0f..e321f755 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -287,7 +287,7 @@ namespace Vocaluxe.Menu public void Draw() { - if (_TextureName != String.Empty) + if (_TextureName.Length > 0) CBase.Drawing.DrawTexture(CBase.Theme.GetSkinTexture(_TextureName, _PartyModeID), _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); else CBase.Drawing.DrawTexture(_Texture, _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); @@ -428,7 +428,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": ParticleEffect color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -544,7 +544,7 @@ namespace Vocaluxe.Menu h = 0; CParticle star; - if (_Theme.TextureName != String.Empty) + if (_Theme.TextureName.Length > 0) { star = new CParticle(_PartyModeID, _Theme.TextureName, Color, CBase.Game.GetRandom(w) + Rect.X - size / 4f, @@ -611,9 +611,9 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if(_Theme.TextureName != String.Empty) + if(_Theme.TextureName.Length > 0) Texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index 2102a64b..3df074d6 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -360,7 +360,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorBackgroundName != String.Empty) + if (_Theme.ColorBackgroundName.Length > 0) { writer.WriteElementString("ColorBackground", _Theme.ColorBackgroundName); } @@ -374,7 +374,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected paylist-entry color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SColorBackgroundName != String.Empty) + if (_Theme.SColorBackgroundName.Length > 0) { writer.WriteElementString("SColorBackground", _Theme.SColorBackgroundName); } @@ -467,10 +467,10 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorBackgroundName != String.Empty) + if (_Theme.ColorBackgroundName.Length > 0) BackgroundColor = CBase.Theme.GetColor(_Theme.ColorBackgroundName, _PartyModeID); - if (_Theme.SColorBackgroundName != String.Empty) + if (_Theme.SColorBackgroundName.Length > 0) BackgroundSColor = CBase.Theme.GetColor(_Theme.SColorBackgroundName, _PartyModeID); _Theme.Text1.LoadTextures(); diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 687f0a6b..e2d2df00 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -413,7 +413,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -427,7 +427,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) { writer.WriteElementString("SColor", _Theme.SColorName); } @@ -441,7 +441,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Highlighted SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or
, , , (lower priority)"); - if (_Theme.HColorName != String.Empty) + if (_Theme.HColorName.Length > 0) { writer.WriteElementString("HColor", _Theme.HColorName); } @@ -455,7 +455,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ArrowColorName != String.Empty) + if (_Theme.ArrowColorName.Length > 0) { writer.WriteElementString("ArrowColor", _Theme.ArrowColorName); } @@ -469,7 +469,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SArrowColorName != String.Empty) + if (_Theme.SArrowColorName.Length > 0) { writer.WriteElementString("ArrowSColor", _Theme.SArrowColorName); } @@ -483,7 +483,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.TextColorName != String.Empty) + if (_Theme.TextColorName.Length > 0) { writer.WriteElementString("TextColor", _Theme.TextColorName); } @@ -497,7 +497,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.STextColorName != String.Empty) + if (_Theme.STextColorName.Length > 0) { writer.WriteElementString("TextSColor", _Theme.STextColorName); } @@ -817,25 +817,25 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) SColor = CBase.Theme.GetColor(_Theme.SColorName, _PartyModeID); - if (_Theme.HColorName != String.Empty) + if (_Theme.HColorName.Length > 0) HColor = CBase.Theme.GetColor(_Theme.HColorName, _PartyModeID); - if (_Theme.ArrowColorName != String.Empty) + if (_Theme.ArrowColorName.Length > 0) ColorArrow = CBase.Theme.GetColor(_Theme.ArrowColorName, _PartyModeID); - if (_Theme.SArrowColorName != String.Empty) + if (_Theme.SArrowColorName.Length > 0) SColorArrow = CBase.Theme.GetColor(_Theme.SArrowColorName, _PartyModeID); - if (_Theme.TextColorName != String.Empty) + if (_Theme.TextColorName.Length > 0) TextColor = CBase.Theme.GetColor(_Theme.TextColorName, _PartyModeID); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) STextColor = CBase.Theme.GetColor(_Theme.STextColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index cb8b4aa8..cbd1f0cc 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -186,7 +186,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , ,
(lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -286,7 +286,7 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index d0e64f9f..4e5f1e0a 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -576,7 +576,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -590,7 +590,7 @@ namespace Vocaluxe.Menu writer.WriteComment(": Selected Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) { writer.WriteElementString("SColor", _Theme.SColorName); } @@ -849,10 +849,10 @@ namespace Vocaluxe.Menu public void LoadTextures() { - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SColorName != String.Empty) + if (_Theme.SColorName.Length > 0) SColor = CBase.Theme.GetColor(_Theme.SColorName, _PartyModeID); } @@ -879,7 +879,7 @@ namespace Vocaluxe.Menu private void UpdateTextPosition() { - if (_Text == String.Empty) + if (_Text.Length == 0) return; CBase.Fonts.SetFont(Fon); diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index 9dc01b08..66c4ab17 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -330,7 +330,7 @@ namespace Vocaluxe.Menu.SongMenu this.FileName = Path.GetFileName(FilePath); EHeaderFlags HeaderFlags = new EHeaderFlags(); - StreamReader sr; + StreamReader sr = null; try { @@ -362,6 +362,8 @@ namespace Vocaluxe.Menu.SongMenu { case "ENCODING": this.Encoding = CEncoding.GetEncoding(Value); + sr.Dispose(); + sr = null; sr = new StreamReader(FilePath, this.Encoding); Identifier = String.Empty; @@ -369,9 +371,9 @@ namespace Vocaluxe.Menu.SongMenu while (!sr.EndOfStream) { line = sr.ReadLine(); - if (line.Length == 0) + if (line.Length == 0) continue; - if(!line[0].ToString().Equals("#")) break; + if (!line[0].ToString().Equals("#")) break; pos = line.IndexOf(":"); @@ -384,39 +386,39 @@ namespace Vocaluxe.Menu.SongMenu } break; case "TITLE": - if (Value != String.Empty) + if (Value.Length > 0) { this.Title = Value; HeaderFlags |= EHeaderFlags.Title; } break; case "ARTIST": - if (Value != String.Empty) + if (Value.Length > 0) { this.Artist = Value; HeaderFlags |= EHeaderFlags.Artist; } break; case "TITLE-ON-SORTING": - if (Value != String.Empty) + if (Value.Length > 0) { this.TitleSorting = Value; } break; case "ARTIST-ON-SORTING": - if (Value != String.Empty) + if (Value.Length > 0) { this.ArtistSorting = Value; } break; case "P1": - if (Value != String.Empty) + if (Value.Length > 0) { this.DuetPart1 = Value; } break; case "P2": - if (Value != String.Empty) + if (Value.Length > 0) { this.DuetPart2 = Value; } @@ -586,19 +588,21 @@ namespace Vocaluxe.Menu.SongMenu } catch (Exception e) { + if (sr != null) + sr.Dispose(); CBase.Log.LogError("Error reading txt header in file \"" + FilePath + "\": " + e.Message); return false; } - + sr.Dispose(); CheckFiles(); //Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag. - if (this.ArtistSorting == String.Empty) + if (this.ArtistSorting.Length == 0) { this.ArtistSorting = this.Artist; } - if (this.TitleSorting == String.Empty) + if (this.TitleSorting.Length == 0) { this.TitleSorting = this.Title; } @@ -634,7 +638,7 @@ namespace Vocaluxe.Menu.SongMenu int Player = 0; int FileLineNo = 0; - StreamReader sr; + StreamReader sr = null; try { @@ -776,8 +780,11 @@ namespace Vocaluxe.Menu.SongMenu catch (Exception e) { CBase.Log.LogError("Error loading song. Line No.: " + FileLineNo.ToString() + ". An unhandled exception occured (" + e.Message + "): " + FilePath); + if(sr != null) + sr.Dispose(); return false; } + sr.Dispose(); FindRefrain(); FindShortEnd(); _NotesLoaded = true; @@ -805,7 +812,7 @@ namespace Vocaluxe.Menu.SongMenu { if (_CoverSmallLoaded) return; - if (this.CoverFileName != String.Empty) + if (this.CoverFileName.Length > 0) { if (!CBase.DataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize())) _CoverTextureSmall = CBase.Cover.GetNoCover(); @@ -818,7 +825,7 @@ namespace Vocaluxe.Menu.SongMenu private void CheckFiles() { - if(this.CoverFileName == String.Empty){ + if(this.CoverFileName.Length == 0){ List files = CHelper.ListFiles(this.Folder, "*.jpg", false); files.AddRange(CHelper.ListFiles(this.Folder, "*.png", false)); foreach(String file in files) @@ -830,7 +837,7 @@ namespace Vocaluxe.Menu.SongMenu } } - if (this.BackgroundFileName == String.Empty) + if (this.BackgroundFileName.Length == 0) { List files = CHelper.ListFiles(this.Folder, "*.jpg", false); files.AddRange(CHelper.ListFiles(this.Folder, "*.png", false)); @@ -847,12 +854,12 @@ namespace Vocaluxe.Menu.SongMenu private void CheckDuet() { - if (DuetPart1 == String.Empty) + if (DuetPart1.Length == 0) { DuetPart1 = "Part 1"; CBase.Log.LogError("Warning: Can't find #P1-tag for duets in \"" + this.Artist + " - " + this.Title + "\"."); } - if (DuetPart2 == String.Empty) + if (DuetPart2.Length == 0) { DuetPart2 = "Part 2"; CBase.Log.LogError("Warning: Can't find #P2-tag for duets in \"" + this.Artist + " - " + this.Title + "\"."); @@ -889,7 +896,7 @@ namespace Vocaluxe.Menu.SongMenu { for (int j = i + 1; j < lines.LineCount; j++) { - if (sentences[i] == sentences[j] && sentences[i] != String.Empty) + if (sentences[i] == sentences[j] && sentences[i].Length > 0) { Series tempSeries = new Series(); tempSeries.start = i; @@ -903,7 +910,7 @@ namespace Vocaluxe.Menu.SongMenu for (int k = 1; k <= max; k++) { - if (sentences[i + k] == sentences[j + k] && sentences[i + k] != String.Empty) + if (sentences[i + k] == sentences[j + k] && sentences[i + k].Length > 0) tempSeries.end = i + k; else break; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 3c8290bf..bfb77487 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -350,7 +350,7 @@ namespace Vocaluxe.Menu.SongMenu writer.WriteComment(": Tile color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) { writer.WriteElementString("Color", _Theme.ColorName); } @@ -578,7 +578,7 @@ namespace Vocaluxe.Menu.SongMenu { Init(); - if (_Theme.ColorName != String.Empty) + if (_Theme.ColorName.Length > 0) _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } @@ -652,7 +652,7 @@ namespace Vocaluxe.Menu.SongMenu _streams.Add(_stream); _actsongstream = _stream; - if (CBase.Songs.GetVisibleSong(_actsong).VideoFileName != String.Empty && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) + if (CBase.Songs.GetVisibleSong(_actsong).VideoFileName.Length > 0 && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) { _video = CBase.Video.Load(Path.Combine(CBase.Songs.GetVisibleSong(_actsong).Folder, CBase.Songs.GetVisibleSong(_actsong).VideoFileName)); if (_video == -1) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 89a26d3c..be18331d 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -144,7 +144,7 @@ namespace Vocaluxe.Menu.SongMenu _MedleyTagIcon.Visible = false; } - if (CBase.Songs.GetNumVisibleSongs() == 0 && CBase.Songs.GetSearchFilter() != String.Empty) + if (CBase.Songs.GetNumVisibleSongs() == 0 && CBase.Songs.GetSearchFilter().Length > 0) { _CoverBig.Texture = _CoverBigTexture; _Artist.Text = String.Empty; diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 7a97fb5d..44f557a2 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -46,6 +46,7 @@ prompt 4 Off + ..\CheckingRules.ruleset
AnyCPU @@ -110,6 +111,7 @@ +