Skip to content

Commit

Permalink
fixed handling of program numbers for deleted channels:
Browse files Browse the repository at this point in the history
- after loading a list it is now ensures that if IsDeleted => OldProgramNr =-1 and for fixing bad files: if OldProgramNr == -1 => IsDeleted = true
- while saving a list, if NewProgramNr == -1, the channel will be set to IsDeleted=true and temporarily gets a sequential NewProgramNr assigned, so that no "-1" or duplicate numbers end up in the file. Afterwards for deleted channels the NewProgramNr will be set back to -1.
- GlobalClone files now set IsDeleted and IsDisabled if a channel was removed
  • Loading branch information
PredatH0r committed Nov 30, 2017
1 parent eb8d8a9 commit 6379920
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 32 deletions.
18 changes: 9 additions & 9 deletions source/ChanSort.Api/Controller/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ public void AutoNumberingForUnassignedChannels(UnsortedChannelMode mode)
if (appChannel.NewProgramNr == -1)
{
if (mode == UnsortedChannelMode.MarkDeleted)
continue;
appChannel.Hidden = true;
appChannel.Skip = true;
appChannel.IsDeleted = true;
else
{
appChannel.Hidden = true;
appChannel.Skip = true;
}
}

int progNr = GetNewPogramNr(appChannel, ref maxProgNr);
Expand All @@ -381,15 +384,15 @@ private string ChanSortCriteria(ChannelInfo channel)
{
// explicitly sorted
if (channel.GetPosition(this.SubListIndex) != -1)
return channel.GetPosition(this.SubListIndex).ToString("d4");
return channel.GetPosition(this.SubListIndex).ToString("d5");

// eventually hide unsorted channels
if (this.unsortedChannelMode == UnsortedChannelMode.MarkDeleted)
return "Z";

// eventually append in old order
if (this.unsortedChannelMode == UnsortedChannelMode.AppendInOrder)
return "B" + channel.OldProgramNr.ToString("d4");
return "B" + channel.OldProgramNr.ToString("d5");

// sort alphabetically, with "." and "" on the bottom
if (channel.Name == ".")
Expand All @@ -409,10 +412,7 @@ private int GetNewPogramNr(ChannelInfo appChannel, ref int maxPrNr)
if (prNr > maxPrNr)
maxPrNr = prNr;
if (prNr == -1)
{
if (appChannel.OldProgramNr != -1 && this.unsortedChannelMode != UnsortedChannelMode.MarkDeleted)
prNr = ++maxPrNr;
}
prNr = ++maxPrNr;
return prNr;
}

Expand Down
4 changes: 4 additions & 0 deletions source/ChanSort.Api/Controller/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public virtual string GetFileInformation()
int deleted = 0;
int hidden = 0;
int skipped = 0;
int locked = 0;
foreach (var channel in list.Channels)
{
if (channel.IsDeleted)
Expand All @@ -73,10 +74,13 @@ public virtual string GetFileInformation()
++hidden;
if (channel.Skip)
++skipped;
if (channel.Lock)
++locked;
}
sb.Append("number of deleted channels: ").AppendLine(deleted.ToString());
sb.Append("number of hidden channels: ").AppendLine(hidden.ToString());
sb.Append("number of skipped channels: ").AppendLine(skipped.ToString());
sb.Append("number of locked channels: ").AppendLine(locked.ToString());
sb.AppendLine();
}
return sb.ToString();
Expand Down
24 changes: 23 additions & 1 deletion source/ChanSort.Api/Model/DataRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,29 @@ public void ApplyCurrentProgramNumbers()
foreach (var channel in list.Channels)
{
for (int i=0; i<=c; i++)
channel.SetPosition(i, channel.GetOldPosition(i));
channel.SetPosition(i, channel.IsDeleted ? -1 : channel.GetOldPosition(i));
}
}
}
#endregion

#region SetPrNrForDeletedChannels()
public void SetPrNrForDeletedChannels()
{
// make sure that deleted channels have OldProgramNr = -1
foreach (var list in this.ChannelLists)
{
if (list.IsMixedSourceFavoritesList)
continue;
foreach (var chan in list.Channels)
{
if (chan.IsDeleted)
{
chan.NewProgramNr = -1;
chan.OldProgramNr = -1;
}
else if (chan.OldProgramNr == -1) // old versions of ChanSort saved -1 and without setting IsDeleted
chan.IsDeleted = true;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions source/ChanSort.Loader.GlobalClone/GcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal class GcChannel : ChannelInfo
{
internal int Index;
internal XmlNode XmlNode;
internal bool IsDisabled;

#region ctor()
internal GcChannel(SignalSource source, int index, XmlNode node)
Expand Down
16 changes: 13 additions & 3 deletions source/ChanSort.Loader.GlobalClone/GcSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void ReadChannelList(XmlNode node, bool analog)
#endregion

#region ParseChannelInfoNode()
private void ParseChannelInfoNodes(XmlNode itemNode, ChannelInfo ch, bool onlyNames = false)
private void ParseChannelInfoNodes(XmlNode itemNode, GcChannel ch, bool onlyNames = false)
{
bool hasHexName = false;
int mapType = 0;
Expand All @@ -230,7 +230,9 @@ private void ParseChannelInfoNodes(XmlNode itemNode, ChannelInfo ch, bool onlyNa
{
// common to ATV and DTV
case "prNum":
ch.OldProgramNr = int.Parse(info.InnerText) & 0x3FFF;
ch.OldProgramNr = int.Parse(info.InnerText);
if (ch.OldProgramNr != -1) // older versions of ChanSort accidentally saved -1 instead of IsDeleted=1
ch.OldProgramNr &= 0x3FFF;
break;
case "vchName":
// In old file format versions, this field contains binary data stuffed into UTF8 envelopes. that data is correct
Expand Down Expand Up @@ -292,6 +294,9 @@ private void ParseChannelInfoNodes(XmlNode itemNode, ChannelInfo ch, bool onlyNa
// ?
break;
case "isDisabled":
ch.IsDisabled = int.Parse(info.InnerText) != 0;
break;
case "isDeleted":
ch.IsDeleted = int.Parse(info.InnerText) != 0;
break;
case "usSatelliteHandle":
Expand Down Expand Up @@ -366,6 +371,7 @@ public override void Save(string tvOutputFile)
{
foreach (var list in this.DataRoot.ChannelLists)
{

foreach (var channel in list.Channels)
{
var ch = channel as GcChannel;
Expand Down Expand Up @@ -411,6 +417,8 @@ public override void Save(string tvOutputFile)
// ?
break;
case "isDisabled":
node.InnerText = ch.IsDeleted || ch.IsDisabled ? "1" : "0";
break;
case "isDeleted":
node.InnerText = ch.IsDeleted ? "1" : "0";
break;
Expand Down Expand Up @@ -475,11 +483,13 @@ private void ChangeEncoding()
{
foreach (var list in this.DataRoot.ChannelLists)
{
if (list.IsMixedSourceFavoritesList)
continue;
foreach (var channel in list.Channels)
{
var gcChannel = channel as GcChannel;
if (gcChannel != null)
this.ParseChannelInfoNodes(gcChannel.XmlNode, channel, true);
this.ParseChannelInfoNodes(gcChannel.XmlNode, gcChannel, true);
}
}
}
Expand Down
44 changes: 26 additions & 18 deletions source/ChanSort/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,11 @@ private bool LoadTvDataFile(ISerializerPlugin plugin, string tvDataFile)
if (!this.PromptSaveAndContinue())
return false;

serializer.DataRoot.SetPrNrForDeletedChannels();
this.SetFileName(tvDataFile);
this.currentPlugin = plugin;
this.currentTvSerializer = serializer;
this.DataRoot = this.currentTvSerializer.DataRoot;
this.DataRoot = serializer.DataRoot;
this.AddFileToMruList(this.currentTvFile);
this.UpdateMruMenu();

Expand Down Expand Up @@ -769,32 +770,37 @@ private bool PromptHandlingOfUnsortedChannels()
{
foreach (var channel in list.Channels)
{
if (channel.NewProgramNr < 0 && channel.OldProgramNr >= 0)
if (channel.NewProgramNr < 0 && !channel.IsDeleted)
{
hasUnsorted = true;
break;
}
}
}
if (!hasUnsorted)
return true;

var msg = Resources.MainForm_PromptHandlingOfUnsortedChannels_Question;
DialogResult res;
using (var dlg = new ActionBoxDialog(msg))
UnsortedChannelMode mode = UnsortedChannelMode.MarkDeleted;

if (hasUnsorted)
{
dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Append, DialogResult.Yes, dlg.FullList);
if (this.currentTvSerializer.Features.CanDeleteChannels)
dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Delete, DialogResult.No, dlg.Delete);
dlg.AddAction(Resources.MainForm_Cancel, DialogResult.Cancel, dlg.Cancel);
res = dlg.ShowDialog(this);
}
var msg = Resources.MainForm_PromptHandlingOfUnsortedChannels_Question;
DialogResult res;
using (var dlg = new ActionBoxDialog(msg))
{
dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Append, DialogResult.Yes, dlg.FullList);
if (this.currentTvSerializer.Features.CanDeleteChannels)
dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Delete, DialogResult.No, dlg.Delete);
dlg.AddAction(Resources.MainForm_Cancel, DialogResult.Cancel, dlg.Cancel);
res = dlg.ShowDialog(this);
}

if (res == DialogResult.Cancel)
return false;
if (res == DialogResult.Cancel)
return false;
if (res == DialogResult.Yes)
mode = UnsortedChannelMode.AppendInOrder;
}

this.Editor.AutoNumberingForUnassignedChannels(
res == DialogResult.Yes ? UnsortedChannelMode.AppendInOrder : UnsortedChannelMode.MarkDeleted);
// ensure unsorted and deleted channels have a valid program number
this.Editor.AutoNumberingForUnassignedChannels(mode);
return true;
}

Expand Down Expand Up @@ -903,6 +909,8 @@ private void SaveTvDataFile()
{
foreach (var chan in list.Channels)
{
if (chan.IsDeleted) // during the saving process, deleted channels temporarily got a NewProgramNr assigned
chan.NewProgramNr = -1;
chan.OldProgramNr = chan.NewProgramNr;
chan.OldFavIndex.Clear();
chan.OldFavIndex.AddRange(chan.FavIndex);
Expand Down Expand Up @@ -1774,7 +1782,7 @@ private void ExportExcelList()
{
foreach (var channel in list.Channels.OrderBy(c => c.NewProgramNr))
{
if (channel.IsDeleted || channel.OldProgramNr == -1)
if (channel.IsDeleted || channel.NewProgramNr == -1)
continue;
sb.Append(list.ShortCaption).Append(sep);
sb.Append(channel.NewProgramNr).Append(sep);
Expand Down
5 changes: 4 additions & 1 deletion source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
ChanSort Change Log
===================
2017-11-30
- fixed: deleting channels and selecting to "Remove unsorted channels"
when saving could produce problems loading the list on the TV.
i.e. LG GlobalClone.TLL

2017-11-13
- Samsung .zip: fixed loading/saving of favorites A-E


2017-10-29
- Show popup with download link for MS Visual C++ 2010 x86 Redist
(this package is needed to open lists with a SQLite file format)
Expand Down

0 comments on commit 6379920

Please sign in to comment.