Merge remote-tracking branch 'voc/release-0.1' into release-0.1

This commit is contained in:
Florian Kuepper committed 2012-02-28 08:41:34 +01:00
commit 09faac15ed
8 files changed
+221 -72

No files matched your search

Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<dllmap os="linux" dll="PortAudio.dll" target="libportaudio.so.2"/>
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
+202 -30
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
@@ -7,15 +8,23 @@ using System.IO;
using System.Text;
using System.Data.SQLite;
using Community.CsharpSqlite;
using Vocaluxe.Lib.Draw;
using Vocaluxe.Lib.Song;
using System.Data;
namespace Vocaluxe.Base
{
static class CDataBase
{
struct SData
{
public int id;
public long ticks;
public string str1;
public string str2;
}
private static string _HighscoreFilePath;
private static string _CoverFilePath;
private static string _CreditsRessourcesFilePath;
@@ -417,6 +426,79 @@ namespace Vocaluxe.Base
command.CommandText = "INSERT INTO Songs SELECT ID, Artist, Title, TimesPlayed from US_Songs";
command.ExecuteNonQuery();
List<SData> scores = new List<SData>();
List<SData> songs = new List<SData>();
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())
{
SData data = new SData();
data.id = reader.GetInt32(0);
data.str1 = reader.GetString(1);
data.ticks = UnixTimeToTicks((int)reader.GetInt64(2));
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();
// 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();
}
//Delete old tables after conversion
command.CommandText = "DROP TABLE US_Scores;";
command.ExecuteNonQuery();
@@ -462,19 +544,24 @@ namespace Vocaluxe.Base
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++)
while (reader.Read())
{
if (reader.GetName(i) == "Date")
for (int i = 0; i < reader.FieldCount; i++)
{
dateExists = true;
break;
if (reader.GetName(i) == "name")
{
if (reader.GetString(i) == "Date")
dateExists = true;
break;
}
}
}
reader.Close();
@@ -488,31 +575,112 @@ namespace Vocaluxe.Base
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");
// convert from CP1252 to UTF8
List<SData> scores = new List<SData>();
List<SData> songs = new List<SData>();
/* 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";
Sqlite3.sqlite3 OldDB;
int res = Sqlite3.sqlite3_open(_HighscoreFilePath, out OldDB);
//Create a DataTable containing the results
//DataTable results = new DataTable();
//SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
//adapter.Fill(results);
if (res != Sqlite3.SQLITE_OK)
{
CLog.LogError("Error opening Database: " + _HighscoreFilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")");
}
else
{
Sqlite3.Vdbe Stmt = new Sqlite3.Vdbe();
res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT ID, Artist, Title FROM US_Songs", -1, ref Stmt, 0);
//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();
if (res != Sqlite3.SQLITE_OK)
{
CLog.LogError("Error query Database: " + _HighscoreFilePath + " (" + Sqlite3.sqlite3_errmsg(OldDB) + ")");
}
else
{
Sqlite3.sqlite3_step(Stmt);
// command.CommandText = "UPDATE Songs SET Artist ='" + artist + "', Title = '" + title + "'WHERE ID = " + id;
// command.ExecuteNonQuery();
//}
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);
data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes));
bytes = Sqlite3.sqlite3_column_rawbytes(Stmt, 2);
data.str2 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes));
songs.Add(data);
}
Sqlite3.sqlite3_finalize(Stmt);
}
Stmt = new Sqlite3.Vdbe();
if (!dateExists)
res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT rowid, Player FROM US_Scores", -1, ref Stmt, 0);
else
res = Sqlite3.sqlite3_prepare_v2(OldDB, "SELECT rowid, Player, Date FROM US_Scores", -1, ref Stmt, 0);
if (res != Sqlite3.SQLITE_OK)
{
CLog.LogError("Error query Database: " + _HighscoreFilePath + " (" + 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);
data.str1 = UTF8.GetString(Encoding.Convert(CP1252, UTF8, bytes));
if (dateExists)
data.ticks = UnixTimeToTicks(Sqlite3.sqlite3_column_int(Stmt, 2));
scores.Add(data);
}
Sqlite3.sqlite3_finalize(Stmt);
}
}
Sqlite3.sqlite3_close(OldDB);
// 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();
}
//Delete old tables after conversion
command.CommandText = "DROP TABLE US_Scores;";
@@ -520,9 +688,6 @@ namespace Vocaluxe.Base
command.CommandText = "DROP TABLE US_Songs;";
command.ExecuteNonQuery();
//results.Dispose();
//adapter.Dispose();
reader.Dispose();
command.Dispose();
@@ -1070,5 +1235,12 @@ namespace Vocaluxe.Base
return stream.ToArray();
}
}
private static long UnixTimeToTicks(int UnixTime)
{
DateTime t70 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
t70 = t70.AddSeconds(UnixTime);
return t70.Ticks;
}
}
}
+8 -29
View File
@@ -105,16 +105,7 @@ typedef ac_package_data* lp_ac_package_data;
void init_info(lp_ac_file_info info)
{
info->title[0] = 0;
info->author[0] = 0;
info->copyright[0] = 0;
info->comment[0] = 0;
info->album[0] = 0;
info->year = -1;
info->track = -1;
info->genre[0] = 0;
info->duration = -1;
info->bitrate = -1;
}
int av_initialized = 0;
@@ -361,20 +352,7 @@ int CALL_CONVT ac_open(
//Retrieve stream information
AVFormatContext *ctx = ((lp_ac_data)pacInstance)->pFormatCtx;
if(avformat_find_stream_info(ctx, NULL) >= 0) {
/*
strcpy(pacInstance->info.title, ctx->title);
strcpy(pacInstance->info.author, ctx->author);
strcpy(pacInstance->info.copyright, ctx->copyright);
strcpy(pacInstance->info.comment, ctx->comment);
strcpy(pacInstance->info.album, ctx->album);
strcpy(pacInstance->info.genre, ctx->genre);
pacInstance->info.year = ctx->year;
pacInstance->info.track = ctx->track;
pacInstance->info.bitrate = ctx->bit_rate;
*/
if(avformat_find_stream_info(ctx, NULL) >= 0) {
pacInstance->info.duration = ctx->duration * 1000 / AV_TIME_BASE;
} else {
return -1;
@@ -658,16 +636,17 @@ double ac_sync_video(lp_ac_package pPackage, lp_ac_decoder pDec, AVFrame *src_fr
}
int ac_decode_video_package(lp_ac_package pPackage, lp_ac_video_decoder pDecoder, lp_ac_decoder pDec) {
int finished;
double pts;
if (((lp_ac_package_data)pPackage)->ffpackage.size <= 0)
return 0;
int finished = 0;
double pts = 0;
avcodec_decode_video2(
pDecoder->pCodecCtx, pDecoder->pFrame, &finished,
&(((lp_ac_package_data)pPackage)->ffpackage));
&(((lp_ac_package_data)pPackage)->ffpackage));
if (finished) {
pts=0;
if(((lp_ac_package_data)pPackage)->ffpackage.dts == AV_NOPTS_VALUE &&
*(uint64_t*)pDecoder->pFrame->opaque != AV_NOPTS_VALUE ){
pts = *(uint64_t*)pDecoder->pFrame->opaque;
@@ -68,21 +68,8 @@ typedef enum _ac_output_format ac_output_format;
/*Contains information about the whole file/stream that has been opened. Default values are ""
for strings and -1 for integer values.*/
struct _ac_file_info {
/*Information about the file*/
char title[512];
char author[512];
char copyright[512];
char comment[512];
char album[512];
int year;
int track;
char genre[32];
/*Length of the file*/
int64_t duration;
/*Bitrate*/
int bitrate;
};
typedef struct _ac_file_info ac_file_info;
+4
View File
@@ -58,6 +58,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Bass.Net.dll</HintPath>
</Reference>
<Reference Include="Community.CsharpSqlite, Version=3.7.7.1, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Community.CsharpSqlite.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.5.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\NAudio.dll</HintPath>