diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 6fa62860..2674a093 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -10,6 +10,7 @@ using System.Data.SQLite; using Vocaluxe.Lib.Draw; using Vocaluxe.Lib.Song; +using System.Data; namespace Vocaluxe.Base { @@ -308,6 +309,31 @@ namespace Vocaluxe.Base reader.Dispose(); } + 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(); + + //Check for USDX 1.1 DB + if (version == 1) + ConvertFrom110(); + //Check for USDX 1.01 or CMD Mod DB + else if (version == 0 && scoresTableExists) + ConvertFrom101(); + command.Dispose(); connection.Close(); @@ -362,6 +388,149 @@ namespace Vocaluxe.Base } */ } + + /// + /// Converts a USDX 1.1 database into the Vocaluxe format + /// + /// True if succeeded + private static bool ConvertFrom110() + { + SQLiteConnection connection = new SQLiteConnection(); + connection.ConnectionString = "Data Source=" + _HighscoreFilePath; + SQLiteCommand command; + + try + { + connection.Open(); + } + catch (Exception) + { + return false; + } + + 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(); + + //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; + } + + /// + /// Converts a USDX 1.01 or CMD 1.01 database to Vocaluxe format + /// + /// True if succeeded + private static bool ConvertFrom101() + { + SQLiteConnection connection = new SQLiteConnection(); + connection.ConnectionString = "Data Source=" + _HighscoreFilePath; + SQLiteCommand command; + SQLiteDataReader reader = null; + + try + { + connection.Open(); + } + catch (Exception) + { + return false; + } + + command = new SQLiteCommand(connection); + + command.CommandText = "PRAGMA table_info(US_Scores);"; + reader = command.ExecuteReader(); + reader.Read(); + + bool dateExists = false; + + //Check for column Date + for (int i = 0; i < reader.FieldCount; i++) + { + if (reader.GetName(i) == "Date") + { + dateExists = true; + break; + } + } + + reader.Close(); + + //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(); + + command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs"; + command.ExecuteNonQuery(); + + CLog.LogError("The database has been converted but all non ASCII characters got lost in this process"); + + /* Unfortunately all SQLite Wrappers do convert data to UTF8 when interacting with the database, so converting cant be done in .Net, + * we might have to write a library in C++ which can convert data or just write a simple program to which converts the tables. + */ + + //Now loop through all tables and convert from CP1252 to UTF8 + //command.CommandText = "SELECT ID, Artist, Title from US_Songs"; + + //Create a DataTable containing the results + //DataTable results = new DataTable(); + //SQLiteDataAdapter adapter = new SQLiteDataAdapter(command); + //adapter.Fill(results); + + //foreach (DataRow row in results.Rows) + //{ + // //FIXME: Convert Latin1(CP1252) to UTF8 + // int id = Convert.ToInt32(row.ItemArray[0].ToString()); + // string artist = row.ItemArray[1].ToString(); + // //artist = Encoding.Unicode.GetString(Encoding.Convert(Encoding.GetEncoding(1252), Encoding.Unicode, Encoding.GetEncoding(1252).GetBytes(row.ItemArray[1].ToString()))); + // string title = row.ItemArray[2].ToString(); + + // command.CommandText = "UPDATE Songs SET Artist ='" + artist + "', Title = '" + title + "'WHERE ID = " + id; + // command.ExecuteNonQuery(); + //} + + //Delete old tables after conversion + command.CommandText = "DROP TABLE US_Scores;"; + command.ExecuteNonQuery(); + + command.CommandText = "DROP TABLE US_Songs;"; + command.ExecuteNonQuery(); + + //results.Dispose(); + //adapter.Dispose(); + + reader.Dispose(); + command.Dispose(); + connection.Close(); + connection.Dispose(); + + return true; + } #endregion Highscores #region Cover diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index f02430e4..05658607 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -48,6 +48,7 @@ namespace Vocaluxe.Base public static bool bFullScreen = false; public const string sIcon = "Vocaluxe.ico"; + public const string sLogo = "Logo.png"; public const string FallbackLanguage = "English"; public static string sBassRegistration = "Registration.xml"; public static string sFileConfig = "Config.xml"; @@ -64,6 +65,7 @@ namespace Vocaluxe.Base public const string sSoundT440 = "440Hz.mp3"; public const string sFolderCover = "Cover"; + public const string sFolderGraphics = "Graphics"; public const string sFolderFonts = "Fonts"; public const string sFolderThemes = "Themes"; public const string sFolderSkins = "Skins"; diff --git a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs index 06a8597b..2b7b1ac3 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs @@ -38,22 +38,7 @@ namespace Vocaluxe.Lib.Video.Acinerella [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct TAc_file_info { - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] - public string title; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] - public string author; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] - public string copyright; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] - public string comment; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] - public string album; - public Int32 year; - public Int32 track; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] - public string genre; public Int64 duration; - public Int32 bitrate; } // TAc_instance represents an Acinerella instance. Each instance can open and @@ -180,7 +165,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // Initializes an Acinerella instance. //function ac_init(): PAc_instance; cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_init", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern IntPtr _ac_init(); + private static extern IntPtr _ac_init(); public static IntPtr ac_init() { @@ -193,7 +178,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // Frees an Acinerella instance. //procedure ac_free(inst: PAc_instance); cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_free", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern void _ac_free(IntPtr PAc_instance); + private static extern void _ac_free(IntPtr PAc_instance); public static void ac_free(IntPtr PAc_instance) { @@ -221,7 +206,7 @@ namespace Vocaluxe.Lib.Video.Acinerella proberesult: PAc_proberesult): integer; cdecl; external ac_dll; */ [DllImport(AcDll, EntryPoint = "ac_open", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_open( + private static extern Int32 _ac_open( IntPtr PAc_instance, IntPtr sender, TAc_openclose_callback open_proc, @@ -250,7 +235,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // Closes an opened media file. //procedure ac_close(inst: PAc_instance);cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_close", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern void _ac_close(IntPtr PAc_instance); + private static extern void _ac_close(IntPtr PAc_instance); public static void ac_close(IntPtr PAc_instance) { @@ -264,7 +249,7 @@ namespace Vocaluxe.Lib.Video.Acinerella //procedure ac_get_stream_info( //inst: PAc_instance; nb: integer; pinfo: PAc_stream_info); cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_get_stream_info", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern void _ac_get_stream_info( + private static extern void _ac_get_stream_info( IntPtr PAc_instance, Int32 nb, out TAc_stream_info Info @@ -300,7 +285,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // could be found. //function ac_create_decoder(pacInstance: PAc_instance; nb: integer): PAc_decoder; cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_create_decoder", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern IntPtr _ac_create_decoder(IntPtr PAc_instance, Int32 nb); + private static extern IntPtr _ac_create_decoder(IntPtr PAc_instance, Int32 nb); public static IntPtr ac_create_decoder(IntPtr PAc_instance, Int32 nb) { @@ -313,7 +298,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // Frees an created decoder. //procedure ac_free_decoder(pDecoder: PAc_decoder); cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_free_decoder", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern void _ac_free_decoder(IntPtr PAc_decoder); + private static extern void _ac_free_decoder(IntPtr PAc_decoder); public static void ac_free_decoder(IntPtr PAc_decoder) { @@ -327,7 +312,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // "buffer" property of the decoder. //function ac_decode_package(pPackage: PAc_package; pDecoder: PAc_decoder): integer; cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_decode_package", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_decode_package(IntPtr PAc_package, IntPtr PAc_decoder); + private static extern Int32 _ac_decode_package(IntPtr PAc_package, IntPtr PAc_decoder); public static Int32 ac_decode_package(IntPtr PAc_package, IntPtr PAc_decoder) { @@ -338,7 +323,7 @@ namespace Vocaluxe.Lib.Video.Acinerella } [DllImport(AcDll, EntryPoint = "ac_get_audio_frame", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_get_audio_frame(IntPtr PAcInstance, IntPtr PAc_decoder); + private static extern Int32 _ac_get_audio_frame(IntPtr PAcInstance, IntPtr PAc_decoder); public static Int32 ac_get_audio_frame(IntPtr PAcInstance, IntPtr PAc_decoder) { @@ -349,7 +334,7 @@ namespace Vocaluxe.Lib.Video.Acinerella } [DllImport(AcDll, EntryPoint = "ac_get_frame", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_get_frame(IntPtr PAcInstance, IntPtr PAc_decoder); + private static extern Int32 _ac_get_frame(IntPtr PAcInstance, IntPtr PAc_decoder); public static Int32 ac_get_frame(IntPtr PAcInstance, IntPtr PAc_decoder) @@ -360,7 +345,7 @@ namespace Vocaluxe.Lib.Video.Acinerella } } [DllImport(AcDll, EntryPoint = "ac_skip_frames", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_skip_frames(IntPtr PAcInstance, IntPtr PAc_decoder, Int32 num); + private static extern Int32 _ac_skip_frames(IntPtr PAcInstance, IntPtr PAc_decoder, Int32 num); public static Int32 ac_skip_frames(IntPtr PAcInstance, IntPtr PAc_decoder, Int32 num) { @@ -376,7 +361,7 @@ namespace Vocaluxe.Lib.Video.Acinerella // The target_pos paremeter is in milliseconds. Returns 1 if the functions succeded.} //function ac_seek(pDecoder: PAc_decoder; dir: integer; target_pos: int64): integer; cdecl; external ac_dll; [DllImport(AcDll, EntryPoint = "ac_seek", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] - public static extern Int32 _ac_seek(IntPtr PAc_decoder, Int32 dir, Int64 target_pos); + private static extern Int32 _ac_seek(IntPtr PAc_decoder, Int32 dir, Int64 target_pos); public static Int32 ac_seek(IntPtr PAc_decoder, Int32 dir, Int64 target_pos) { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index 3dac356e..e6031786 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -580,7 +580,6 @@ namespace Vocaluxe.Lib.Video return; int FrameFinished = 0; - bool error = false; if (DropFrame && !_BeforeLoop) { try @@ -604,7 +603,6 @@ namespace Vocaluxe.Lib.Video } catch (Exception) { - error = true; CLog.LogError("Error AcGetFrame " + _FileName); } @@ -649,8 +647,7 @@ namespace Vocaluxe.Lib.Video } else { - if (!error) // just a quick and dirty workaround for the mkv seek bug in ffmpeg - _NoMoreFrames = true; + _NoMoreFrames = true; } return; } diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index f7fb9602..e14caf14 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -173,7 +173,7 @@ namespace Vocaluxe { public SplashScreen() { - string path = Path.Combine(Environment.CurrentDirectory, Path.Combine("Graphics", "logo.png")); + string path = Path.Combine(Environment.CurrentDirectory, Path.Combine(CSettings.sFolderGraphics, CSettings.sLogo)); if (File.Exists(path)) { try