mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-03-21 19:21:30 +01:00
- allow Pr#0 for analog channels
- added loader for Toshiba *.db files (saving not yet implemented)
This commit is contained in:
93
ChanSort.Loader.DbFile/ChanSort.Loader.DbFile.csproj
Normal file
93
ChanSort.Loader.DbFile/ChanSort.Loader.DbFile.csproj
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F6F02792-07F1-48D5-9AF3-F945CA5E3931}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ChanSort.Loader.DbFile</RootNamespace>
|
||||
<AssemblyName>ChanSort.Loader.DbFile</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SQLite.Designer">
|
||||
<HintPath>..\DLL\SQLite.Designer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>..\DLL\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="DbSerializer.cs" />
|
||||
<Compile Include="DbSerializerPlugin.cs" />
|
||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ChanSort.Api\ChanSort.Api.csproj">
|
||||
<Project>{DCCFFA08-472B-4D17-BB90-8F513FC01392}</Project>
|
||||
<Name>ChanSort.Api</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
276
ChanSort.Loader.DbFile/DbSerializer.cs
Normal file
276
ChanSort.Loader.DbFile/DbSerializer.cs
Normal file
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SQLite;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using ChanSort.Api;
|
||||
|
||||
namespace ChanSort.Loader.DbFile
|
||||
{
|
||||
class DbSerializer : SerializerBase
|
||||
{
|
||||
private const int BITS_InUse = 0x10000;
|
||||
private readonly ChannelList atvChannels = new ChannelList(SignalSource.AnalogCT | SignalSource.TvAndRadio, "Analog");
|
||||
private readonly ChannelList dtvChannels = new ChannelList(SignalSource.DvbCT | SignalSource.TvAndRadio, "DVB-C/T");
|
||||
private readonly ChannelList satChannels = new ChannelList(SignalSource.DvbS | SignalSource.TvAndRadio, "Satellite");
|
||||
|
||||
#region ctor()
|
||||
public DbSerializer(string inputFile) : base(inputFile)
|
||||
{
|
||||
this.Features.ChannelNameEdit = true;
|
||||
|
||||
this.DataRoot.AddChannelList(this.atvChannels);
|
||||
this.DataRoot.AddChannelList(this.dtvChannels);
|
||||
this.DataRoot.AddChannelList(this.satChannels);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DisplayName
|
||||
public override string DisplayName { get { return "Toshiba *.db Loader"; } }
|
||||
#endregion
|
||||
|
||||
|
||||
#region Load()
|
||||
public override void Load()
|
||||
{
|
||||
string sysDataConnString = "Data Source=" + Path.GetDirectoryName(Path.GetDirectoryName(this.FileName)) +
|
||||
"\\dvb_type001\\dvbSysData.db";
|
||||
using (var sysDataConn = new SQLiteConnection(sysDataConnString))
|
||||
{
|
||||
sysDataConn.Open();
|
||||
using (var cmd = sysDataConn.CreateCommand())
|
||||
{
|
||||
this.ReadSatellites(cmd);
|
||||
this.ReadTransponders(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
string channelConnString = "Data Source=" + this.FileName;
|
||||
using (var channelConn = new SQLiteConnection(channelConnString))
|
||||
{
|
||||
channelConn.Open();
|
||||
using (var cmd = channelConn.CreateCommand())
|
||||
{
|
||||
this.ReadAnalogChannels(cmd);
|
||||
this.ReadDtvChannels(cmd);
|
||||
this.ReadSatChannels(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadSatellites()
|
||||
private void ReadSatellites(SQLiteCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "select distinct satellite_id, satellite_name, orbital_position, west_east_flag from satellite";
|
||||
using (var r = cmd.ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
{
|
||||
Satellite sat = new Satellite(r.GetInt32(0));
|
||||
int pos = r.GetInt32(2);
|
||||
sat.OrbitalPosition = string.Format("{0}.{1}{2}", pos / 10, pos % 10, r.GetInt32(3) == 1 ? "E" : "W");
|
||||
sat.Name = r.GetString(1) + " " + sat.OrbitalPosition;
|
||||
this.DataRoot.AddSatellite(sat);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadTransponders()
|
||||
private void ReadTransponders(SQLiteCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "select satellite_id, frequency, polarization, symbol_rate, transponder_number from satellite";
|
||||
using (var r = cmd.ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
{
|
||||
int satId = r.GetInt32(0);
|
||||
int freq = r.GetInt32(1);
|
||||
int id = satId * 1000000 + freq / 1000;
|
||||
if (this.DataRoot.Transponder.TryGet(id) != null)
|
||||
continue;
|
||||
Transponder tp = new Transponder(id);
|
||||
tp.FrequencyInMhz = (decimal)freq / 1000;
|
||||
tp.Number = r.GetInt32(4);
|
||||
tp.Polarity = r.GetInt32(2) == 0 ? 'H' : 'V';
|
||||
tp.Satellite = this.DataRoot.Satellites.TryGet(satId);
|
||||
tp.SymbolRate = r.GetInt32(3) / 1000;
|
||||
this.DataRoot.AddTransponder(tp.Satellite, tp);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region ReadAnalogChannels()
|
||||
private void ReadAnalogChannels(SQLiteCommand cmd)
|
||||
{
|
||||
string[] fieldNames = {"channel_handle", "channel_number", "list_bits", "channel_label", "frequency"};
|
||||
var sql = this.GetQuery("EuroATVChanList", fieldNames);
|
||||
var fields = this.GetFieldMap(fieldNames);
|
||||
|
||||
cmd.CommandText = sql;
|
||||
using (var r = cmd.ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
ReadAnalogChannel(r, fields);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadAnalogChannel(SQLiteDataReader r, IDictionary<string, int> field)
|
||||
{
|
||||
var bits = r.GetInt32(field["list_bits"]);
|
||||
if ((bits & BITS_InUse) == 0)
|
||||
return;
|
||||
|
||||
ChannelInfo channel = new ChannelInfo(SignalSource.Analog|SignalSource.Tv,
|
||||
r.GetInt32(field["channel_handle"]),
|
||||
r.GetInt32(field["channel_number"]),
|
||||
r.GetString(field["channel_label"]));
|
||||
|
||||
channel.FreqInMhz = (decimal) r.GetInt32(field["frequency"])/1000000;
|
||||
|
||||
this.DataRoot.AddChannel(this.atvChannels, channel);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadDtvChannels()
|
||||
private void ReadDtvChannels(SQLiteCommand cmd)
|
||||
{
|
||||
this.ReadDigitalChannels(cmd, "EuroDTVChanList", SignalSource.DvbCT, this.dtvChannels);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadSatChannels()
|
||||
private void ReadSatChannels(SQLiteCommand cmd)
|
||||
{
|
||||
this.ReadDigitalChannels(cmd, "EuroSATChanList", SignalSource.DvbS, this.satChannels);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadDigitalChannels()
|
||||
private void ReadDigitalChannels(SQLiteCommand cmd, string table, SignalSource signalSource, ChannelList channels)
|
||||
{
|
||||
string[] fieldNames = { "channel_handle", "channel_number", "list_bits", "channel_label", "frequency",
|
||||
"dvb_service_type", "onid", "tsid", "sid", "sat_id", "channel_order" };
|
||||
var sql = this.GetQuery(table, fieldNames);
|
||||
var fields = this.GetFieldMap(fieldNames);
|
||||
|
||||
cmd.CommandText = sql;
|
||||
using (var r = cmd.ExecuteReader())
|
||||
{
|
||||
while (r.Read())
|
||||
ReadDigitalChannel(r, fields, signalSource, channels);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadDigitalChannel()
|
||||
private void ReadDigitalChannel(SQLiteDataReader r, IDictionary<string, int> field, SignalSource signalSource, ChannelList channels)
|
||||
{
|
||||
var bits = r.GetInt32(field["list_bits"]);
|
||||
if ((bits & BITS_InUse) == 0)
|
||||
return;
|
||||
|
||||
var name = r.GetString(field["channel_label"]);
|
||||
string longName, shortName;
|
||||
this.GetChannelNames(name, out longName, out shortName);
|
||||
|
||||
ChannelInfo channel = new ChannelInfo(signalSource,
|
||||
r.GetInt32(field["channel_handle"]),
|
||||
r.GetInt32(field["channel_number"]),
|
||||
longName);
|
||||
channel.ShortName = shortName;
|
||||
channel.RecordOrder = r.GetInt32(field["channel_order"]);
|
||||
channel.FreqInMhz = (decimal)r.GetInt32(field["frequency"]) / 1000;
|
||||
int serviceType = r.GetInt32(field["dvb_service_type"]);
|
||||
if (serviceType == 1 || serviceType == 25)
|
||||
channel.SignalSource |= SignalSource.Tv;
|
||||
else if (serviceType == 2)
|
||||
channel.SignalSource |= SignalSource.Radio;
|
||||
channel.ServiceType = serviceType;
|
||||
channel.OriginalNetworkId = r.GetInt32(field["onid"]);
|
||||
channel.TransportStreamId = r.GetInt32(field["tsid"]);
|
||||
channel.ServiceId = r.GetInt32(field["sid"]);
|
||||
|
||||
if ((signalSource & SignalSource.Sat) != 0)
|
||||
{
|
||||
int satId = r.GetInt32(field["sat_id"]);
|
||||
var sat = this.DataRoot.Satellites.TryGet(satId);
|
||||
if (sat != null)
|
||||
{
|
||||
channel.Satellite = sat.Name;
|
||||
channel.SatPosition = sat.OrbitalPosition;
|
||||
int tpId = satId*1000000 + (int) channel.FreqInMhz;
|
||||
var tp = this.DataRoot.Transponder.TryGet(tpId);
|
||||
if (tp != null)
|
||||
{
|
||||
channel.SymbolRate = tp.SymbolRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.DataRoot.AddChannel(channels, channel);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetQuery()
|
||||
private string GetQuery(string table, string[] fieldNames)
|
||||
{
|
||||
string sql = "select ";
|
||||
for (int i = 0; i < fieldNames.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
sql += ",";
|
||||
sql += fieldNames[i];
|
||||
}
|
||||
sql += " from " + table;
|
||||
return sql;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetFieldMap()
|
||||
private IDictionary<string, int> GetFieldMap(string[] fieldNames)
|
||||
{
|
||||
Dictionary<string, int> field = new Dictionary<string, int>();
|
||||
for (int i = 0; i < fieldNames.Length; i++)
|
||||
field[fieldNames[i]] = i;
|
||||
return field;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetChannelNames()
|
||||
private void GetChannelNames(string name, out string longName, out string shortName)
|
||||
{
|
||||
StringBuilder sbLong = new StringBuilder();
|
||||
StringBuilder sbShort = new StringBuilder();
|
||||
|
||||
bool inShort = false;
|
||||
foreach (char c in name)
|
||||
{
|
||||
if (c == 0x86)
|
||||
inShort = true;
|
||||
else if (c == 0x87)
|
||||
inShort = false;
|
||||
if (c >= 0x80 && c <= 0x9F)
|
||||
continue;
|
||||
|
||||
if (inShort)
|
||||
sbShort.Append(c);
|
||||
sbLong.Append(c);
|
||||
}
|
||||
|
||||
longName = sbLong.ToString();
|
||||
shortName = sbShort.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public override void Save(string tvOutputFile, string csvOutputFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
15
ChanSort.Loader.DbFile/DbSerializerPlugin.cs
Normal file
15
ChanSort.Loader.DbFile/DbSerializerPlugin.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using ChanSort.Api;
|
||||
|
||||
namespace ChanSort.Loader.DbFile
|
||||
{
|
||||
public class DbSerializerPlugin : ISerializerPlugin
|
||||
{
|
||||
public string PluginName { get { return "Toshiba chmgt.db"; } }
|
||||
public string FileFilter { get { return "chmgt.db"; } }
|
||||
|
||||
public SerializerBase CreateSerializer(string inputFile)
|
||||
{
|
||||
return new DbSerializer(inputFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
ChanSort.Loader.DbFile/Properties/AssemblyInfo.cs
Normal file
36
ChanSort.Loader.DbFile/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ChanSort.Loader.DbFile")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ChanSort.Loader.DbFile")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("172c8359-67a7-4728-8463-255a972aefc0")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user