Skip to content

Commit

Permalink
- fixed "DevExpress.Data.UboundColumnDataTypeValidator+InvalidTypeExc…
Browse files Browse the repository at this point in the history
…eption" error

- added support for latest "amdb\*.db" format, which no longer contains the "ca_type" column
  • Loading branch information
PredatH0r committed Apr 20, 2024
1 parent c609b9b commit 78e53e7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 53 deletions.
120 changes: 69 additions & 51 deletions source/ChanSort.Loader.VisionEdge4K/VisionEdge4KDbSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class VisionEdge4KSerializer : SerializerBase

private readonly Dictionary<int, ChannelList> channels = new();
private readonly ChannelList favs = new(SignalSource.All, "Fav") { IsMixedSourceFavoritesList = true };
private bool hasCaType;


#region ctor()
Expand Down Expand Up @@ -143,66 +144,81 @@ private void ReadChannels(SqliteCommand cmd)
int ixP = 0;
int ixST = 12;

cmd.CommandText = @"
this.hasCaType = false;
cmd.CommandText = "select * from program_table limit 0";
using (var r = cmd.ExecuteReader())
{
for (int i = 0; i < r.FieldCount; i++)
{
hasCaType |= r.GetName(i) == "ca_type";
if (hasCaType)
break;
}
}

cmd.CommandText = $@"
select
p.id, p.disp_order, p.name, p.service_id, p.vid_pid, p.pcr_pid, p.vid_type, p.tv_type, p.ca_type, p.lock, p.skip, p.hide,
p.id, p.disp_order, p.name, p.service_id, p.vid_pid, p.pcr_pid, p.vid_type, p.tv_type, {(hasCaType ? "p.ca_type" : "0 ca_type")}, p.lock, p.skip, p.hide,
st.sat_id, st.on_id, st.ts_id, st.freq, st.pol, st.sym_rate
from program_table p
left outer join satellite_transponder_table st on p.tp_type=0 and st.id=p.tp_id
order by p.tv_type,p.disp_order";

using var r = cmd.ExecuteReader();
while (r.Read())
using (var r = cmd.ExecuteReader())
{
var handle = r.GetInt32(ixP + 0);
var oldProgNr = r.GetInt32(ixP + 1);
var name = r.GetString(ixP + 2);
ChannelInfo channel = new ChannelInfo(0, handle, oldProgNr, name);
channel.ServiceId = r.GetInt32(ixP + 3) & 0x7FFF;
channel.VideoPid = r.GetInt32(ixP + 4);
channel.PcrPid = r.GetInt32(ixP + 5);
var vidType = r.GetInt32(ixP + 6);
var tvType = r.GetInt32(ixP + 7);
if (tvType == 0)
{
channel.ServiceType = vidType;
channel.ServiceTypeName = "TV";
channel.SignalSource |= SignalSource.Tv;
}
else
{
channel.ServiceType = 0;
channel.ServiceTypeName = "Radio/Data";
channel.SignalSource |= SignalSource.Radio | SignalSource.Data;
}
channel.Encrypted = r.GetInt32(ixP + 8) != 0;
channel.Lock = r.GetBoolean(ixP + 9);
channel.Skip = r.GetBoolean(ixP + 10);
channel.Hidden = r.GetBoolean(ixP + 11);

// DVB-S
int satId = 0;
if (!r.IsDBNull(ixST + 0))
while (r.Read())
{
satId = r.GetInt32(ixST + 0);
var sat = this.DataRoot.Satellites.TryGet(satId);
channel.Satellite = sat?.Name;
channel.SatPosition = sat?.OrbitalPosition;
channel.OriginalNetworkId = r.GetInt32(ixST + 1) & 0x7FFF;
channel.TransportStreamId = r.GetInt32(ixST + 2) & 0x7FFF;
channel.FreqInMhz = r.GetInt32(ixST + 3);
if (channel.FreqInMhz > 20000) // DVB-S is in MHz already, DVB-C/T in kHz
channel.FreqInMhz /= 1000;
channel.Polarity = r.GetInt32(ixST + 4) == 0 ? 'H' : 'V';
channel.SymbolRate = r.GetInt32(ixST + 5);
}
var handle = r.GetInt32(ixP + 0);
var oldProgNr = r.GetInt32(ixP + 1);
var name = r.GetString(ixP + 2);
ChannelInfo channel = new ChannelInfo(0, handle, oldProgNr, name);
channel.ServiceId = r.GetInt32(ixP + 3) & 0x7FFF;
channel.VideoPid = r.GetInt32(ixP + 4);
channel.PcrPid = r.GetInt32(ixP + 5);
var vidType = r.GetInt32(ixP + 6);
var tvType = r.GetInt32(ixP + 7);
if (tvType == 0)
{
channel.ServiceType = vidType;
channel.ServiceTypeName = "TV";
channel.SignalSource |= SignalSource.Tv;
}
else
{
channel.ServiceType = 0;
channel.ServiceTypeName = "Radio/Data";
channel.SignalSource |= SignalSource.Radio | SignalSource.Data;
}

var list = this.channels.TryGet(satId);
if (list != null)
{
channel.OldProgramNr = list.Channels.Count + 1;
this.DataRoot.AddChannel(list, channel);
this.DataRoot.AddChannel(this.favs, channel);
channel.Encrypted = r.GetInt32(ixP + 8) != 0;
channel.Lock = r.GetBoolean(ixP + 9);
channel.Skip = r.GetBoolean(ixP + 10);
channel.Hidden = r.GetBoolean(ixP + 11);

// DVB-S
int satId = 0;
if (!r.IsDBNull(ixST + 0))
{
satId = r.GetInt32(ixST + 0);
var sat = this.DataRoot.Satellites.TryGet(satId);
channel.Satellite = sat?.Name;
channel.SatPosition = sat?.OrbitalPosition;
channel.OriginalNetworkId = r.GetInt32(ixST + 1) & 0x7FFF;
channel.TransportStreamId = r.GetInt32(ixST + 2) & 0x7FFF;
channel.FreqInMhz = r.GetInt32(ixST + 3);
if (channel.FreqInMhz > 20000) // DVB-S is in MHz already, DVB-C/T in kHz
channel.FreqInMhz /= 1000;
channel.Polarity = r.GetInt32(ixST + 4) == 0 ? 'H' : 'V';
channel.SymbolRate = r.GetInt32(ixST + 5);
}

var list = this.channels.TryGet(satId);
if (list != null)
{
channel.OldProgramNr = list.Channels.Count + 1;
this.DataRoot.AddChannel(list, channel);
this.DataRoot.AddChannel(this.favs, channel);
}
}
}
}
Expand Down Expand Up @@ -255,6 +271,8 @@ private void AdjustColumns()
list.VisibleColumnFieldNames.Remove(nameof(ChannelInfo.AudioPid));
list.VisibleColumnFieldNames.Remove(nameof(ChannelInfo.ShortName));
list.VisibleColumnFieldNames.Remove(nameof(ChannelInfo.Provider));
if (!this.hasCaType)
list.VisibleColumnFieldNames.Remove(nameof(ChannelInfo.Encrypted));
}
}
#endregion
Expand Down
8 changes: 6 additions & 2 deletions source/ChanSort/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraReports.Design;
using DevExpress.XtraTab;

namespace ChanSort.Ui
Expand Down Expand Up @@ -1621,6 +1620,8 @@ private void ShowGridColumns(XGridView gview)
{
if (!field.StartsWith("+"))
continue;
if (gview.Columns[field.Substring(1)] != null) // ignore "+" for existing columns
continue;
var col = gview.Columns[field];
if (col != null)
continue;
Expand Down Expand Up @@ -2455,7 +2456,10 @@ private void gview_CustomUnboundColumnData(object sender, CustomColumnDataEventA
{
var pi = e.Row.GetType().GetProperty(field.Substring(1));
if (pi != null && pi.CanRead)
e.Value = pi.GetValue(e.Row);
{
var value = pi.GetValue(e.Row);
e.Value = value?.ToString(); // for the custom "+"-fields the UnboundDataType is set to string
}
}
}
else
Expand Down
4 changes: 4 additions & 0 deletions source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ChanSort Change Log
===================

2024-04-20
- fixed "DevExpress.Data.UboundColumnDataTypeValidator+InvalidTypeException" error
- added support for latest "amdb\*.db" format, which no longer contains the "ca_type" column

2024-02-25
- fixed support for Dijitsu channel lists with missing atv\_cmdb\_2.bin file
- experimental support for Metz channel\_list.xml lists
Expand Down

0 comments on commit 78e53e7

Please sign in to comment.