From 14a0bab123d6eef7046f53073359b011378326d4 Mon Sep 17 00:00:00 2001 From: Florian Kuepper Date: Sun, 26 Feb 2012 13:05:16 +0100 Subject: [PATCH] Added CreditsRessourcesDB --- Output/CreditsRessourcesDB.sqlite | Bin 0 -> 5120 bytes Vocaluxe/Base/CDataBase.cs | 271 ++++++++++++++++++++++++++++- Vocaluxe/Base/CSettings.cs | 2 + Vocaluxe/Screens/CScreenCredits.cs | 7 +- Vocaluxe/Vocaluxe.csproj | 1 + 5 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 Output/CreditsRessourcesDB.sqlite diff --git a/Output/CreditsRessourcesDB.sqlite b/Output/CreditsRessourcesDB.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..c9bc6a2d09d67eadd2b30edce1f4ff1d94b30c53 GIT binary patch literal 5120 zcmeHJ&uhXk6i$qrIM{7a#DkBW6noqLfK?4rR;%lx%+ttbrUieXt-5P>*meJ`hrupO zU2(K!2TwaRk3e4Db+?eSUCGnhrG>1!goX3WqRM!5x8VGuoyO z*j)y8-?E_Rm>t6z!Yv(w(Pv%LmgOC4GaZ_XjaZqjRE-YdebBJFjYFSWa7hYUsf6Du zzp%Xh3e?q{BqG_wX ziRD_%pGD$GVxSYr>YUGnE-P!VxS*BGIB4%%4#diH7xQS##acwc+ z3(2KSDWDX{jsgS|RQ#F$9U{Bz5LZl<0$Enz43ly(`bdQHpZe)%SscY(DUcxr)cj}Y Lu@zONKth3U+e)kK literal 0 HcmV?d00001 diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 84375cca..f2487000 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -17,14 +17,17 @@ namespace Vocaluxe.Base { private static string _HighscoreFilePath; private static string _CoverFilePath; + private static string _CreditsRessourcesFilePath; public static void Init() { _HighscoreFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileHighscoreDB); _CoverFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileCoverDB); + _CreditsRessourcesFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileCreditsRessourcesDB); InitHighscoreDB(); InitCoverDB(); + InitCreditsRessourcesDB(); } #region Highscores @@ -604,7 +607,7 @@ namespace Vocaluxe.Base 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);"; + "ImageID INTEGER NOT NULL, Data BLOB NOT NULL);"; command.ExecuteNonQuery(); command.Dispose(); @@ -613,6 +616,272 @@ namespace Vocaluxe.Base } #endregion Cover + #region CreditsRessources + public static bool GetCreditsRessource(string FileName, ref STexture tex, int MaxSize) + { + bool result = false; + + SQLiteConnection connection = new SQLiteConnection(); + connection.ConnectionString = "Data Source=" + _CoverFilePath; + SQLiteCommand command; + try + { + 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(); + 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.Close(); + reader.Dispose(); + } + command.Dispose(); + connection.Close(); + connection.Dispose(); + + return result; + } + + private static bool AddImageToCreditsDB(String ImagePath) + { + bool result = false; + STexture tex; + + if (File.Exists(ImagePath)) + { + + SQLiteConnection connection = new SQLiteConnection(); + connection.ConnectionString = "Data Source=" + _CoverFilePath; + SQLiteCommand command; + try + { + connection.Open(); + } + catch (Exception) + { + return false; + } + command = new SQLiteCommand(connection); + + SQLiteDataReader reader = null; + + if (reader != null) + reader.Close(); + + Bitmap origin; + try + { + origin = new Bitmap(ImagePath); + } + catch (Exception) + { + CLog.LogError("Error loading Texture: " + ImagePath); + tex = new STexture(-1); + + if (reader != null) + { + reader.Close(); + reader.Dispose(); + } + command.Dispose(); + connection.Close(); + connection.Dispose(); + + return false; + } + + int w = origin.Width; + int h = origin.Height; + + Bitmap bmp = new Bitmap(w, h); + Graphics g = Graphics.FromImage(bmp); + g.DrawImage(origin, new Rectangle(0, 0, w, h)); + g.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); + bmp.Dispose(); + + command.CommandText = "INSERT INTO Images (Path, width, height) " + + "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = ImagePath; + command.ExecuteNonQuery(); + + command.CommandText = "SELECT id FROM Images WHERE [Path] = @path"; + command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = ImagePath; + reader = null; + try + { + reader = command.ExecuteReader(); + } + catch (Exception) + { + throw; + } + + if (reader != null) + { + reader.Read(); + int id = reader.GetInt32(0); + reader.Close(); + command.CommandText = "INSERT INTO ImageData (ImageID, Data) " + + "VALUES ('" + id.ToString() + "', @data)"; + command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data; + command.ExecuteReader(); + result = true; + } + } + + return result; + } + + private static bool InitCreditsRessourcesDB() + { + SQLiteConnection connection = new SQLiteConnection(); + connection.ConnectionString = "Data Source=" + _CreditsRessourcesFilePath; + SQLiteCommand command; + + 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) + { + // update database + } + } + + 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 + { + connection.Open(); + } + 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, " + + "CoverID INTEGER NOT NULL, Data BLOB NOT NULL);"; + command.ExecuteNonQuery(); + + command.Dispose(); + connection.Close(); + connection.Dispose(); + } + #endregion CreditsRessources + private static byte[] GetBytes(SQLiteDataReader reader) { const int CHUNK_SIZE = 2 * 1024; diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 3fe7b0f6..f02430e4 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -36,6 +36,7 @@ namespace Vocaluxe.Base public const int iDatabaseHighscoreVersion = 1; public const int iDatabaseCoverVersion = 1; + public const int iDatabaseCreditsRessourcesVersion = 1; public static int iRenderW = 1280; @@ -55,6 +56,7 @@ namespace Vocaluxe.Base public static string sFileHighscoreDB = "HighscoreDB.sqlite"; public const string sFileCoverDB = "CoverDB.sqlite"; + public const string sFileCreditsRessourcesDB = "CreditsRessourcesDB.sqlite"; public const string sFilePerformanceLog = "Performance.log"; public const string sFileErrorLog = "Error.log"; public const string sFileBenchmarkLog = "Benchmark.log"; diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 76fd3ad2..097eb952 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -86,7 +86,12 @@ namespace Vocaluxe.Screens public override bool Draw() { - return base.Draw(); + base.Draw(); + + //Draw white background + CDraw.DrawColor(new SColorF(1, 1, 1, 1), new SRectF(0, 0, 1280, 720, 1)); + + return true; } } } diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index d10dac28..01576595 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -163,6 +163,7 @@ Form +