Пример #1
0
 public ReportOptionsDialog(ChannelList channelList, int subListIndex)
 {
   InitializeComponent();
   this.channelList = channelList;
   this.subListIndex = subListIndex;
   if (Properties.Settings.Default.PrintSortByName)
     this.rbSortByName.Checked = true;
   this.fontEdit1.EditValue = Properties.Settings.Default.PrintFontName;
   this.spinFontSize.Value = Properties.Settings.Default.PrintFontSize;
 }
Пример #2
0
 public virtual void AddChannel(ChannelList list, ChannelInfo channel)
 {
     if (list == null)
       {
     warnings.AppendFormat("No list found to add channel '{0}'\r\n", channel);
     return;
       }
       string warning = list.AddChannel(channel);
       if (warning != null)
     this.Warnings.AppendLine(warning);
 }
Пример #3
0
    private IList<ChannelInfo> Get2ndProgramNumber(ChannelList list)
    {
      var channels = list.GetChannelByNewProgNr(2);
      if (channels.Count == 1)
        return channels;

      var ch = list.Channels.OrderBy(c => c.NewProgramNr <= 0 ? 10000 : c.NewProgramNr).FirstOrDefault();
      if (ch == null)
        return null;
      channels = new List<ChannelInfo>();
      channels.Add(ch);
      return channels;
    }
Пример #4
0
    public ChannelListReport(ChannelList list, int subListIndex, bool orderByName, Font font)
    {
      this.subListIndex = subListIndex;
      this.orderByName = orderByName;

      InitializeComponent();
      this.DataSource = GenerateDataSource(list);

      this.txtHeading.Text = list.ShortCaption + (subListIndex <= 0 ? "" : " - Fav " + (char)('A' + subListIndex));
     
      this.txtHeading.Font = new Font(font.Name, font.Size+4, FontStyle.Bold);
      this.txtNumber.Font = font;
      this.txtChannelName.Font = font;
    }
Пример #5
0
    private List<ChannelList> GenerateDataSource(ChannelList list)
    {
      ChannelList sortedList = new ChannelList(list.SignalSource, list.Caption);
      foreach (var channel in list.Channels.OrderBy(this.SortCriteria))
      {
        int pos = channel.GetPosition(this.subListIndex);
        if (orderByName && (channel.Name == "" || channel.Name == "."))
          continue;
        if (pos >= 0)
          sortedList.Channels.Add(channel);
      }

      List<ChannelList> lists = new List<ChannelList>();
      lists.Add(sortedList);
      return lists;
    }
Пример #6
0
        public void Save(string fileName, ChannelList list)
        {
            using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                foreach (var channel in list.Channels.OrderBy(c => c.NewProgramNr))
                {
                    if (channel.NewProgramNr == -1)
                    {
                        continue;
                    }

                    writer.Write(channel.NewProgramNr);
                    writer.Write(';');
                    writer.Write(channel.Name);
                    writer.WriteLine();
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Put the numbers in channel.FavIndex[i] in a sequential order, starting with 1
        /// </summary>
        /// <param name="channelList"></param>
        /// <param name="favCount">Number of favorite lists (i=0..favCount-1)</param>
        /// <returns>true if there were any changes</returns>
        public static bool SequentializeFavPos(ChannelList channelList, int favCount)
        {
            bool changed = false;

            for (int fav = 0; fav < favCount; fav++)
            {
                var list = channelList.Channels.Where(c => c.FavIndex[fav] >= 0).OrderBy(c => c.FavIndex[fav]).ToList();
                int i    = 1;
                foreach (var channel in list)
                {
                    if (channel.FavIndex[fav] != i)
                    {
                        channel.FavIndex[fav] = ++i;
                        changed = true;
                    }
                }
            }
            return(changed);
        }
Пример #8
0
    public string Load(string fileName, DataRoot root, ChannelList list)
    {
      if (list.ReadOnly)
        return "The current channel list is read-only";

      this.lineNumber = 0;
      this.dataRoot = root;
      this.channelList = list;
      this.warnings.Remove(0, this.warnings.Length);

      foreach (var channel in this.channelList.Channels)
        channel.NewProgramNr = -1;

      using (var stream = new StreamReader(fileName, Encoding.Default))
      {
        ReadChannelsFromStream(stream);
      }
      return this.warnings.ToString();
    }
Пример #9
0
        /// <summary>
        /// Put the numbers in channel.FavIndex[i] in a sequential order, starting with 1
        /// </summary>
        /// <param name="channelList"></param>
        /// <param name="favCount">Number of favorite lists (i=0..favCount-1)</param>
        /// <returns>true if there were any changes</returns>
        public static bool SequentializeFavPos(ChannelList channelList, int favCount)
        {
            bool changed = false;

            for (int fav = 0; fav < favCount; fav++)
            {
                var list = channelList.Channels.Where(c => c.GetPosition(fav + 1) >= 0).OrderBy(c => c.GetPosition(fav + 1)).ToList();
                int i    = 1;
                foreach (var channel in list)
                {
                    if (channel.GetPosition(fav + 1) != i)
                    {
                        channel.SetPosition(fav + 1, ++i);
                        changed = true;
                    }
                }
            }
            return(changed);
        }
Пример #10
0
        public string Load(string fileName, DataRoot root, ChannelList list)
        {
            if (list.ReadOnly)
            {
                return("The current channel list is read-only");
            }

            this.lineNumber  = 0;
            this.dataRoot    = root;
            this.channelList = list;
            this.warnings.Remove(0, this.warnings.Length);

            foreach (var channel in this.channelList.Channels)
            {
                channel.NewProgramNr = -1;
            }

            using (var stream = new StreamReader(fileName, Encoding.Default))
            {
                ReadChannelsFromStream(stream);
            }
            return(this.warnings.ToString());
        }
Пример #11
0
        private void ShowChannelList(ChannelList channelList)
        {
            if (this.currentChannelList != null)
            this.SaveInputGridLayout(this.currentChannelList.SignalSource);
              if (channelList != null)
              {
            this.LoadInputGridLayout(channelList);
            this.gridRight.DataSource = channelList.Channels;
            this.gridLeft.DataSource = channelList.Channels;

            SignalSource src = 0;
            if ((this.currentTvSerializer.Features.ChannelNameEdit & ChannelNameEditMode.Analog) != 0)
              src |= SignalSource.Analog;
            if ((this.currentTvSerializer.Features.ChannelNameEdit & ChannelNameEditMode.Digital) != 0)
              src |= SignalSource.Digital;
            this.colName.OptionsColumn.AllowEdit = this.colOutName.OptionsColumn.AllowEdit = (channelList.SignalSource & src) != 0;
              }
              else
              {
            this.gridRight.DataSource = null;
            this.gridLeft.DataSource = null;
              }
              this.currentChannelList = channelList;
              this.editor.ChannelList = channelList;

              if (gviewRight.IsValidRowHandle(0))
            this.SelectFocusedRow(this.gviewRight, 0);

              if (gviewLeft.IsValidRowHandle(0))
            this.SelectFocusedRow(this.gviewLeft, 0);

              bool allowEdit = channelList != null && !channelList.ReadOnly;
              this.gviewLeft.OptionsBehavior.Editable = allowEdit;
              this.gviewRight.OptionsBehavior.Editable = allowEdit;

              this.UpdateInsertSlotTextBox();
              this.UpdateMenu();
        }
Пример #12
0
        private void WriteChannels(ChannelList list, byte[] fileContent, FileStream stream)
        {
            foreach (var channel in list.Channels)
              {
            channel.UpdateRawData();
            channel.OldProgramNr = channel.NewProgramNr;
              }

              stream.Write(fileContent, 0, fileContent.Length);
        }
Пример #13
0
        private void ReadDvbsChannels(ZipFile zip, string filename, ChannelList channels, out byte[] fileContent, int entrySize)
        {
            fileContent = ReadFileContent(zip, filename);
              if (fileContent == null)
            return;

              this.DataRoot.AddChannelList(channels);
              int count = fileContent.Length/entrySize;
              DataMapping mapping = dvbsMappings.GetMapping(entrySize);
              channels.MaxChannelNameLength = mapping.Settings.GetInt("lenName") / 2;
              mapping.SetDataPtr(fileContent, 0);
              for (int slotIndex = 0; slotIndex < count; slotIndex++)
              {
            SatChannel ci = new SatChannel(slotIndex, channels.SignalSource, mapping, this.DataRoot, c.SortedFavorites, this.serviceProviderNames);
            if (ci.InUse)
              this.DataRoot.AddChannel(channels, ci);

            mapping.BaseOffset += entrySize;
              }
        }
Пример #14
0
        private void ReadAnalogChannels(ZipFile zip, string fileName, ChannelList list, out byte[] data, Dictionary<int,decimal> freq)
        {
            data = null;
              int entrySize = c.avbtChannelLength;
              if (entrySize == 0)
            return;

              data = ReadFileContent(zip, fileName);
              if (data == null)
            return;

              this.DataRoot.AddChannelList(list);
              var rawChannel = analogMappings.GetMapping(entrySize);
              list.MaxChannelNameLength = rawChannel.Settings.GetInt("lenName")/2;
              rawChannel.SetDataPtr(data, 0);
              int count = data.Length / entrySize;

              for (int slotIndex = 0; slotIndex < count; slotIndex++)
              {
            MapAnalogChannel(rawChannel, slotIndex, list, freq.TryGet(slotIndex));
            rawChannel.BaseOffset += entrySize;
              }
        }
Пример #15
0
 public void Save(string fileName, ChannelList list)
 {
   using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
   {
     foreach (var channel in list.Channels.OrderBy(c => c.NewProgramNr))
     {
       if (channel.NewProgramNr == -1) continue;
       
       writer.Write(channel.NewProgramNr);
       writer.Write(';');
       writer.Write(channel.Name);
       writer.WriteLine();
     }
   }
 }
Пример #16
0
    private void ReadDigitalChannels(SQLiteCommand cmd, string table, SignalSource signalSource, ChannelList tvChannels, ChannelList radioChannels)
    {
      string[] fieldNames = { "channel_handle", "channel_number", "channel_label", "frequency", "list_bits",
                            "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())
        {
          ChannelInfo channel = new DbChannel(signalSource, r, fields, this.DataRoot, this.channelInfoByUid);
          if (!channel.IsDeleted)
          {
            var channelList = (channel.SignalSource & SignalSource.Radio) != 0 ? radioChannels : tvChannels;
            this.DataRoot.AddChannel(channelList, channel);
          }
        }
      }
    }
Пример #17
0
 /// <summary>
 /// Put the numbers in channel.FavIndex[i] in a sequential order, starting with 1
 /// </summary>
 /// <param name="channelList"></param>
 /// <param name="favCount">Number of favorite lists (i=0..favCount-1)</param>
 public static void SequentializeFavPos(ChannelList channelList, int favCount)
 {     
   for (int fav = 0; fav < favCount; fav++)
   {
     var list = channelList.Channels.Where(c => c.FavIndex[fav] >= 0).OrderBy(c => c.FavIndex[fav]).ToList();
     int i = 0;
     foreach (var channel in list)
       channel.FavIndex[fav] = ++i;
   }
 }
Пример #18
0
 public virtual void AddChannelList(ChannelList list)
 {
     this.channelLists.Add(list);
 }
Пример #19
0
 private void WriteChannels(SQLiteCommand cmd, string table, ChannelList channelList, bool analog=false)
 {
   string sql = "update " + table + " set channel_number=@nr ";
   if (!analog)
     sql += ", channel_order=@nr";
   sql += ", list_bits=@Bits where channel_handle=@id";
   cmd.CommandText = sql;
   cmd.Parameters.Add(new SQLiteParameter("@id", DbType.Int32));
   cmd.Parameters.Add(new SQLiteParameter("@nr", DbType.Int32));
   cmd.Parameters.Add(new SQLiteParameter("@Bits", DbType.Int32));
   cmd.Prepare();
   foreach (ChannelInfo channelInfo in channelList.Channels)
   {
     var channel = channelInfo as DbChannel;
     if (channel == null) // ignore reference list proxy channels
       continue;
     channel.UpdateRawData();
     cmd.Parameters["@id"].Value = channel.RecordIndex;
     cmd.Parameters["@nr"].Value = channel.NewProgramNr;
     cmd.Parameters["@Bits"].Value = channel.Bits;
     cmd.ExecuteNonQuery();
   }
 }
Пример #20
0
        private bool GetGridColumnVisibility(GridColumn col, ChannelList list)
        {
            var filter = list.VisibleColumnFieldNames;
              if (filter != null && !filter.Contains(col.FieldName))
            return false;

              var source = list.SignalSource;
              if (col == this.colChannelOrTransponder) return (source & SignalSource.Sat) == 0;
              if (col == this.colShortName) return (source & SignalSource.Digital) != 0;
              if (col == this.colEncrypted) return (source & SignalSource.Digital) != 0;
              if (col == this.colServiceId) return (source & SignalSource.Digital) != 0;
              if (col == this.colVideoPid) return (source & SignalSource.Digital) != 0;
              if (col == this.colAudioPid) return (source & SignalSource.Digital) != 0;
              if (col == this.colServiceType) return (source & SignalSource.Digital) != 0;
              if (col == this.colServiceTypeName) return (source & SignalSource.Digital) != 0;
              if (col == this.colEncrypted) return (source & SignalSource.Digital) != 0;
              if (col == this.colTransportStreamId) return (source & SignalSource.Digital) != 0;
              if (col == this.colNetworkName) return (source & SignalSource.Digital) != 0;
              if (col == this.colNetworkOperator) return (source & SignalSource.Digital) != 0;
              if (col == this.colProvider) return (source & SignalSource.Digital) != 0;
              if (col == this.colSatellite) return (source & SignalSource.Sat) != 0;
              if (col == this.colNetworkId) return (source & SignalSource.Digital) != 0;
              if (col == this.colSymbolRate) return (source & SignalSource.Sat) != 0;
              if (col == this.colIndex) return col.Visible;
              if (col == this.colUid) return col.Visible;
              if (col == this.colDebug) return colDebug.Visible;
              if (col == this.colSignalSource) return col.Visible;
              if (col == this.colLogicalIndex) return colLogicalIndex.Visible;
              if (col == this.colPolarity) return false;

              return true;
        }
Пример #21
0
        private void ReadChannelList(ref int off, int size, int table, ChannelList channels)
        {
            int recordSize = svlMapping.Settings.GetInt("RecordSize");
              if (size % recordSize != 0)
            throw new FileLoadException(ERR_badFileFormat);
              int channelCount = size/recordSize;
              if (channelCount == 0)
            return;

              var broadcastDataOffset = svlMapping.Settings.GetInt("BroadcastSystemData");
              var nameLength = svlMapping.Settings.GetInt("NameLength");
              var source = channels.SignalSource & (SignalSource.MaskAnalogDigital | SignalSource.MaskAntennaCableSat);
              for (int i = 0; i < channelCount; i++)
              {
            svlMapping.SetDataPtr(svlFileContent, off);
            dvbMapping.SetDataPtr(svlFileContent, off + broadcastDataOffset);
            var ci = ReadChannel(source, i, nameLength);
            if (ci != null)
              this.DataRoot.AddChannel(channels, ci);
            off += recordSize;
              }
        }
Пример #22
0
        /// <summary>
        /// Applies the ordering of a reference list to the TV list
        /// </summary>
        /// <param name="refDataRoot">object representing the whole reference list file</param>
        /// <param name="refList">the particular ChannelList to take the order from</param>
        /// <param name="refListPosIndex">the sublist index in the reference list that should be applied (0=main channel number, 1=fav1, ...)</param>
        /// <param name="tvList">the particular ChannelList to apply the order to</param>
        /// <param name="tvListPosIndex">the sublist index in the target list that should be changed (-1=main and all favs, 0=main channel number, 1=fav1, ...)</param>
        /// <param name="addProxyChannels">if true, a placeholder channel will be created in the tvList if there is no matching TV channel for a reference channel</param>
        /// <param name="positionOffset">can be used to shift the Pr# of the reference list so avoid conflicts with already assigned Pr# in the TV list</param>
        /// <param name="chanFilter">a function which is called for each channel in the reference list (with 2nd parameter=true) and TV list (2nd parameter=false) to determine if the channel is part of the reordering
        /// This is used to filter for analog/digital, radio/TV, antenna/cable/sat/ip
        /// </param>
        /// <param name="overwrite">controls whether Pr# will be reassigned to the reference channel when they are already in-use in the TV list</param>
        /// <param name="consecutive">when true, consecutive numbers will be used instead of the Pr# in the reference list when applying the order</param>
        public void ApplyReferenceList(DataRoot refDataRoot, ChannelList refList, int refListPosIndex, ChannelList tvList, int tvListPosIndex, bool addProxyChannels = true, int positionOffset = 0, Func <ChannelInfo, bool, bool> chanFilter = null, bool overwrite = true, bool consecutive = false)
        {
            // create Hashtable for exact channel lookup
            // the UID of a TV channel list contains a source-indicator (Analog, Cable, Sat), which may be undefined in the reference list)
            var onidTsidSid  = new Dictionary <long, List <ChannelInfo> >();
            var chansByNewNr = new Dictionary <int, List <ChannelInfo> >();

            foreach (var channel in tvList.Channels)
            {
                var key = DvbKey(channel.OriginalNetworkId, channel.TransportStreamId, channel.ServiceId);
                if (key == 0)
                {
                    continue;
                }
                var list = onidTsidSid.TryGet(key);
                if (list == null)
                {
                    list = new List <ChannelInfo>();
                    onidTsidSid.Add(key, list);
                }
                list.Add(channel);
            }

            var incNr       = 1 + positionOffset;
            var refPos      = refListPosIndex < 0 || !refDataRoot.SortedFavorites ? 0 : refListPosIndex;
            var refChannels = refList.Channels.OrderBy(ch => ch.GetOldPosition(refPos)).ToList();
            var newPos      = Math.Max(0, tvListPosIndex);

            foreach (var refChannel in refChannels)
            {
                if (!(chanFilter?.Invoke(refChannel, true) ?? true))
                {
                    continue;
                }

                var tvChannel = FindChannel(tvList, newPos, refChannel, onidTsidSid);

                if (tvChannel != null)
                {
                    if (!(chanFilter?.Invoke(tvChannel, false) ?? true))
                    {
                        continue;
                    }

                    var newNr = consecutive ? incNr++ : refChannel.GetOldPosition(refPos) + positionOffset;

                    // handle conflicts when the number is already in-use
                    if (chansByNewNr.TryGetValue(newNr, out var curChans))
                    {
                        if (!overwrite)
                        {
                            continue;
                        }
                        foreach (var chan in curChans)
                        {
                            chan.SetPosition(newPos, -1);
                        }
                    }
                    else
                    {
                        curChans            = new List <ChannelInfo>();
                        chansByNewNr[newNr] = curChans;
                    }
                    curChans.Add(tvChannel);

                    tvChannel.SetPosition(newPos, newNr);
                    if (refDataRoot.CanSkip && this.DataRoot.CanSkip)
                    {
                        tvChannel.Skip = refChannel.Skip;
                    }
                    if (refDataRoot.CanLock && this.DataRoot.CanLock)
                    {
                        tvChannel.Lock = refChannel.Lock;
                    }
                    if (refDataRoot.CanHide && this.DataRoot.CanHide)
                    {
                        tvChannel.Hidden = refChannel.Hidden;
                    }

                    //tvChannel.IsDeleted = refChannel.IsDeleted;
                    if ((tvChannel.SignalSource & SignalSource.Analog) != 0 && !string.IsNullOrEmpty(refChannel.Name))
                    {
                        tvChannel.Name           = refChannel.Name;
                        tvChannel.IsNameModified = true;
                    }

                    if (tvListPosIndex == -1)
                    {
                        ApplyFavorites(refDataRoot, refChannel, tvChannel);
                    }
                }
                else if (addProxyChannels)
                {
                    tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name);
                    tvList.AddChannel(tvChannel);
                }
            }
        }
Пример #23
0
 public virtual void AddChannelList(ChannelList list)
 {
     this.channelLists.Add(list);
     this.loader.Features.MixedSourceFavorites |= list.IsMixedSourceFavoritesList;
 }
Пример #24
0
        private ChannelInfo FindChannel(ChannelList tvList, int subListIndex, ChannelInfo refChannel, Dictionary <long, List <ChannelInfo> > onidTsidSid)
        {
            List <ChannelInfo> candidates;

            // try to find matching channels based on UID or ONID+TSID+SID+Transponder
            var channels = refChannel.Uid == "0-0-0" ? new List <ChannelInfo>() : tvList.GetChannelByUid(refChannel.Uid).ToList();

            if (channels.Count == 0)
            {
                var key = DvbKey(refChannel.OriginalNetworkId, refChannel.TransportStreamId, refChannel.ServiceId);
                if (key != 0 && onidTsidSid.TryGetValue(key, out candidates))
                {
                    channels = candidates;
                }

                // narrow the list down further when a transponder is also provided (i.e. the same channel can be received on multiple DVB-T frequencies)
                if (channels.Count > 1 && !string.IsNullOrEmpty(refChannel.ChannelOrTransponder))
                {
                    candidates = channels.Where(ch => ch.ChannelOrTransponder == refChannel.ChannelOrTransponder).ToList();
                    if (candidates.Count > 0)
                    {
                        channels = candidates;
                    }
                }
            }
            var channel = channels.FirstOrDefault(c => c.GetPosition(subListIndex) == -1);

            if (channel != null)
            {
                return(channel);
            }


            // try to find matching channels by name
            channels = tvList.GetChannelByName(refChannel.Name).Where(c => c.GetPosition(subListIndex) == -1).ToList();

            // if the reference list has information about a service type (tv/radio/data), then only consider channels matching it (or lacking service type information)
            var serviceType = refChannel.SignalSource & SignalSource.MaskTvRadioData;

            if (serviceType != 0)
            {
                channels = channels.Where(ch =>
                {
                    var m = ch.SignalSource & SignalSource.MaskTvRadioData;
                    return(m == 0 || m == serviceType);
                }).ToList();
            }

            if (channels.Count == 0)
            {
                return(null);
            }

            if (channels.Count > 1)
            {
                // exact upper/lowercase matching (often there are channels like "DISCOVERY" and "Discovery")
                candidates = channels.Where(c => c.Name == refChannel.Name).ToList();
                if (candidates.Count > 0)
                {
                    channels = candidates;
                }
            }
            if (channels.Count > 1)
            {
                // prefer unencrypted channels
                candidates = channels.Where(c => c.Encrypted.HasValue && c.Encrypted.Value == false).ToList();
                if (candidates.Count > 0)
                {
                    channels = candidates;
                }
            }
            return(channels[0]);
        }
Пример #25
0
        /// <summary>
        /// Applies the ordering of a reference list to the TV list
        /// </summary>
        /// <param name="refDataRoot">object representing the whole reference list file</param>
        /// <param name="refList">the particular ChannelList to take the order from</param>
        /// <param name="tvList">the particular ChannelList to apply the order to</param>
        /// <param name="addProxyChannels">if true, a placeholder channel will be created in the tvList if there is no matching TV channel for a reference channel</param>
        /// <param name="positionOffset">can be used to shift the Pr# of the reference list so avoid conflicts with already assigned Pr# in the TV list</param>
        /// <param name="chanFilter">a function which is called for each channel in the reference list (with 2nd parameter=true) and TV list (2nd parameter=false) to determine if the channel is part of the reordering
        /// This is used to filter for analog/digital, radio/TV, antenna/cable/sat/ip
        /// </param>
        /// <param name="overwrite">controls whether Pr# will be reassigned to the reference channel when they are already in-use in the TV list</param>
        /// <param name="consecutive">when true, consecutive numbers will be used instead of the Pr# in the reference list when applying the order</param>
        public void ApplyReferenceList(DataRoot refDataRoot, ChannelList refList, ChannelList tvList, bool addProxyChannels = true, int positionOffset = 0, Func <ChannelInfo, bool, bool> chanFilter = null, bool overwrite = true, bool consecutive = false)
        {
            // create Hashtable for exact channel lookup
            // the UID of a TV channel list contains a source-indicator (Analog, Cable, Sat), which may be undefined in the reference list)
            var onidTsidSid = new Dictionary <long, List <ChannelInfo> >();

            foreach (var channel in tvList.Channels)
            {
                var key  = DvbKey(channel.OriginalNetworkId, channel.TransportStreamId, channel.ServiceId);
                var list = onidTsidSid.TryGet(key);
                if (list == null)
                {
                    list = new List <ChannelInfo>();
                    onidTsidSid.Add(key, list);
                }
                list.Add(channel);
            }

            var incNr = 1 + positionOffset;

            foreach (var refChannel in refList.Channels.OrderBy(ch => ch.OldProgramNr))
            {
                if (!(chanFilter?.Invoke(refChannel, true) ?? true))
                {
                    continue;
                }

                var tvChannels = tvList.GetChannelByUid(refChannel.Uid);

                // try to find matching channels based on ONID+TSID+SID
                if (tvChannels.Count == 0)
                {
                    var key = DvbKey(refChannel.OriginalNetworkId, refChannel.TransportStreamId, refChannel.ServiceId);
                    List <ChannelInfo> candidates;
                    if (key != 0 && onidTsidSid.TryGetValue(key, out candidates))
                    {
                        tvChannels = candidates;

                        // narrow the list down further when a transponder is also provided (i.e. the same TV channel can be received on multiple DVB-T frequencies)
                        if (tvChannels.Count > 1 && !string.IsNullOrEmpty(refChannel.ChannelOrTransponder))
                        {
                            candidates = tvChannels.Where(ch => ch.ChannelOrTransponder == refChannel.ChannelOrTransponder).ToList();
                            if (candidates.Count > 0)
                            {
                                tvChannels = candidates;
                            }
                        }
                    }
                }

                // try to find matching channels by name
                if (tvChannels.Count == 0 && !string.IsNullOrWhiteSpace(refChannel.Name))
                {
                    tvChannels = tvList.GetChannelByName(refChannel.Name).ToList();
                }

                // get the first unassigned channel from the candidates (e.g. when matching by non-unique names), or fall back to the first matching channel (e.g. by unique ID)
                ChannelInfo tvChannel = tvChannels.FirstOrDefault(c => c.GetPosition(0) == -1);
                if (tvChannel == null && tvChannels.Count > 0)
                {
                    tvChannel = tvChannels[0];
                }

                if (tvChannel != null)
                {
                    if (!(chanFilter?.Invoke(tvChannel, false) ?? true))
                    {
                        continue;
                    }

                    var newNr = consecutive ? incNr++ : refChannel.OldProgramNr + positionOffset;

                    // handle conflicts when the number is already in-use
                    var curChans = tvList.GetChannelByNewProgNr(newNr);
                    if (!overwrite && curChans.Any())
                    {
                        continue;
                    }
                    foreach (var chan in curChans)
                    {
                        chan.NewProgramNr = -1;
                    }

                    tvChannel.SetPosition(0, newNr);
                    tvChannel.Skip      = refChannel.Skip;
                    tvChannel.Lock      = refChannel.Lock;
                    tvChannel.Hidden    = refChannel.Hidden;
                    tvChannel.IsDeleted = refChannel.IsDeleted;
                    if ((tvChannel.SignalSource & SignalSource.Analog) != 0 && !string.IsNullOrEmpty(refChannel.Name))
                    {
                        tvChannel.Name           = refChannel.Name;
                        tvChannel.IsNameModified = true;
                    }

                    ApplyFavorites(refDataRoot, refChannel, tvChannel);
                }
                else if (addProxyChannels)
                {
                    tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name);
                    tvList.AddChannel(tvChannel);
                }
            }
        }
Пример #26
0
        private void ReadChannel(string line)
        {
            var parts = CsvFile.Parse(line, ',');

            if (parts.Count < 5)
            {
                return;
            }
            int programNr;

            if (!int.TryParse(parts[1], out programNr))
            {
                return;
            }
            string uid = parts[3];

            if (uid.StartsWith("S")) // remove satellite orbital position from UID ... not all TV models provide this information
            {
                uid = "S" + uid.Substring(uid.IndexOf('-'));
            }
            SignalSource signalSource = GetSignalSource(ref programNr, uid, parts);

            if (signalSource == 0)
            {
                return;
            }

            string      name        = parts[4];
            ChannelList channelList = this.GetInitiallyClearedChannelList(signalSource);

            if (channelList == null)
            {
                return;
            }

            IEnumerable <ChannelInfo> channels = FindChannels(channelList, name, uid);
            var channel = channels == null ? null : channels.FirstOrDefault(c => c.NewProgramNr == -1);

            if (channel != null)
            {
                if (!this.addChannels)
                {
                    channel.NewProgramNr = programNr;
                    if ((channel.SignalSource & SignalSource.Analog) != 0)
                    {
                        channel.Name           = name;
                        channel.IsNameModified = true;
                    }
                    if (parts.Count >= 7)
                    {
                        ApplyFlags(channel, parts[6]);
                    }
                }
            }
            else if (parts.Count >= 6) // create proxy channel when using the new ref-list format
            {
                channel = new ChannelInfo(signalSource, uid, programNr, name);
                if (addChannels)
                {
                    channel.NewProgramNr = -1;
                    channel.OldProgramNr = programNr;
                }
                channelList.AddChannel(channel);
            }
        }
Пример #27
0
        private void MapAnalogChannel(DataMapping rawChannel, int slotIndex, ChannelList list, decimal freq)
        {
            bool isCable = (list.SignalSource & SignalSource.Cable) != 0;
              AnalogChannel ci = new AnalogChannel(slotIndex, isCable, rawChannel, freq, c.SortedFavorites);
              if (!ci.InUse)
            return;

              this.DataRoot.AddChannel(list, ci);
        }
Пример #28
0
    private ChannelList ReadChannels(SQLiteCommand cmd, string dbPath, Dictionary<long, string> providers, bool digital)
    {
      var signalSource = DetectSignalSource(cmd, digital);
      var sat = (signalSource & SignalSource.Sat) == 0 ? null : this.DetectSatellite(cmd);

      string name = Path.GetFileName(dbPath);
      ChannelList channelList = new ChannelList(signalSource, name);
      string table = digital ? "SRV_DVB" : "SRV_ANL";
      List<string> fieldNames = new List<string> { 
                            "chType", "chNum", "freq", // CHNL
                            "SRV.srvId", "major", "progNum", "cast(srvName as blob)", "srvType", "hidden", "scrambled", "lockMode", "numSel", // SRV
                            };
      if (digital)
        fieldNames.AddRange(new[] {"onid", "tsid", "vidPid", "provId", "cast(shrtSrvName as blob)", "lcn"}); // SRV_DVB

      var sql = this.BuildQuery(table, fieldNames);
      var fields = this.GetFieldMap(fieldNames);

      cmd.CommandText = sql;
      using (var r = cmd.ExecuteReader())
      {
        while (r.Read())
        {
          var tp = this.transponderByFreq?.TryGet(r.GetInt32(2));
          var channel = new DbChannel(r, fields, this.DataRoot, providers, sat, tp);
          if (!channel.IsDeleted)
          {
            this.DataRoot.AddChannel(channelList, channel);
            this.channelById.Add(channel.RecordIndex, channel);
          }
        }
      }

      this.DataRoot.AddChannelList(channelList);
      return channelList;
    }
Пример #29
0
        private void ReadDvbctChannels(ZipFile zip, string fileName, ChannelList list, out byte[] data, Dictionary<int, decimal> frequency)
        {
            data = null;
              int entrySize = c.dvbtChannelLength;
              if (entrySize == 0)
            return;

              data = ReadFileContent(zip, fileName);
              if (data == null)
            return;

              this.DataRoot.AddChannelList(list);
              var source = list.SignalSource;
              DataMapping rawChannel = dvbctMappings.GetMapping(entrySize);
              list.MaxChannelNameLength = rawChannel.Settings.GetInt("lenName") / 2;
              rawChannel.SetDataPtr(data, 0);
              int count = data.Length / entrySize;
              for (int slotIndex = 0; slotIndex < count; slotIndex++)
              {
            DigitalChannel ci = new DigitalChannel(slotIndex, source, rawChannel, frequency, c.SortedFavorites, this.serviceProviderNames);
            if (ci.InUse && !ci.IsDeleted && ci.OldProgramNr > 0)
              this.DataRoot.AddChannel(list, ci);

            rawChannel.BaseOffset += entrySize;
              }
        }
Пример #30
0
 private void SaveChannelList(ChannelList channelList, string dbPath)
 {
   using (var conn = new SQLiteConnection("Data Source=" + dbPath))
   {
     conn.Open();
     using (var cmdUpdateSrv = PrepareUpdateCommand(conn))
     using (var cmdDeleteSrv = PrepareDeleteCommand(conn, (channelList.SignalSource & SignalSource.Digital) != 0))
     using (var cmdInsertFav = PrepareInsertFavCommand(conn))
     using (var cmdUpdateFav = PrepareUpdateFavCommand(conn))
     using (var cmdDeleteFav = PrepareDeleteFavCommand(conn))
     {
       using (var trans = conn.BeginTransaction())
       {
         Editor.SequentializeFavPos(channelList, 5);
         this.WriteChannels(cmdUpdateSrv, cmdDeleteSrv, cmdInsertFav, cmdUpdateFav, cmdDeleteFav, channelList);
         trans.Commit();
       }
       this.RepairCorruptedDatabaseImage(cmdUpdateSrv);
     }
   }
 }
Пример #31
0
        private void SaveChannels(ZipFile zip, string fileName, ChannelList channels, byte[] fileContent)
        {
            if (fileContent == null)
            return;
              zip.Delete(fileName);

              string tempFilePath = Path.GetTempFileName();
              using (var stream = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
              {
            this.WriteChannels(channels, fileContent, stream);
              }

              zip.Add(tempFilePath, fileName);
        }
Пример #32
0
    private void WriteChannels(SQLiteCommand cmdUpdateSrv, SQLiteCommand cmdDeleteSrv, SQLiteCommand cmdInsertFav, SQLiteCommand cmdUpdateFav, SQLiteCommand cmdDeleteFav, 
      ChannelList channelList, bool analog = false)
    {

      foreach (ChannelInfo channelInfo in channelList.Channels)
      {
        var channel = channelInfo as DbChannel;
        if (channel == null) // ignore reference list proxy channels
          continue;
        
        if (channel.NewProgramNr < 0)
        {
          // delete channel from all tables that have a reference to srvId
          cmdDeleteSrv.Parameters["@id"].Value = channel.RecordIndex;
          cmdDeleteSrv.ExecuteNonQuery();
          continue;
        }

        // update channel record
        cmdUpdateSrv.Parameters["@id"].Value = channel.RecordIndex;
        cmdUpdateSrv.Parameters["@nr"].Value = channel.NewProgramNr;
        cmdUpdateSrv.Parameters["@lock"].Value = channel.Lock;
        cmdUpdateSrv.Parameters["@hidden"].Value = channel.Hidden;
        cmdUpdateSrv.Parameters["@numsel"].Value = !channel.Skip;
        cmdUpdateSrv.Parameters["@srvname"].Value = channel.Name == null ? (object)DBNull.Value : Encoding.BigEndianUnicode.GetBytes(channel.Name);
        cmdUpdateSrv.ExecuteNonQuery();

        // update favorites
        for (int i=0, mask=1; i<5; i++, mask <<= 1)
        {
          int oldPos = channel.OriginalFavIndex[i];
          int newPos = ((int)channel.Favorites & mask) != 0 ? channel.FavIndex[i] : -1;

          if (newPos >= 0)
          {
            var c = oldPos < 0 ? cmdInsertFav : cmdUpdateFav;
            c.Parameters["@id"].Value = channel.RecordIndex;
            c.Parameters["@fav"].Value = i + 1;
            c.Parameters["@pos"].Value = newPos - 1;
            c.ExecuteNonQuery();
          }      
          else
          {
            cmdDeleteFav.Parameters["@id"].Value = channel.RecordIndex;
            cmdDeleteFav.Parameters["@fav"].Value = i + 1;
            cmdDeleteFav.ExecuteNonQuery();
          }

          channel.OriginalFavIndex[i] = channel.FavIndex[i] = newPos;
        }
        channel.OriginalFavs = channel.Favorites;
      }
    }
Пример #33
0
        private void LoadInputGridLayout(ChannelList list)
        {
            string newLayout;
              var newSource = list.SignalSource;
              if ((newSource & SignalSource.Analog) != 0)
            newLayout = Settings.Default.InputGridLayoutAnalog;
              else if ((newSource & SignalSource.DvbS) != 0)
            newLayout = Settings.Default.InputGridLayoutDvbS;
              else
            newLayout = Settings.Default.InputGridLayoutDvbCT;
              if (!string.IsNullOrEmpty(newLayout))
            this.SetGridLayout(this.gviewRight, newLayout);

              foreach (GridColumn col in this.gviewRight.Columns)
            col.Visible = GetGridColumnVisibility(col, list);

              this.ClearRightFilter();
        }
Пример #34
0
        private void ShowChannelList(ChannelList channelList)
        {
            if (this.CurrentChannelList != null)
            this.SaveInputGridLayout(this.CurrentChannelList.SignalSource);

              this.CurrentChannelList = channelList;
              this.Editor.ChannelList = channelList;

              if (channelList != null)
              {
            this.LoadInputGridLayout();
            this.gridRight.DataSource = channelList.Channels;
            this.gridLeft.DataSource = channelList.Channels;

            SignalSource src = 0;
            if ((this.currentTvSerializer.Features.ChannelNameEdit & ChannelNameEditMode.Analog) != 0)
              src |= SignalSource.Analog;
            if ((this.currentTvSerializer.Features.ChannelNameEdit & ChannelNameEditMode.Digital) != 0)
              src |= SignalSource.Digital;
            this.colName.OptionsColumn.AllowEdit = this.colOutName.OptionsColumn.AllowEdit = (channelList.SignalSource & src) != 0;

            if (this.DataRoot.MixedSourceFavorites)
            {
              if (channelList.IsMixedSourceFavoritesList)
              {
            this.tabSubList.SelectedTabPageIndex = 1;
            this.pageProgNr.PageVisible = false;
            this.grpSubList.Visible = true;
              }
              else
              {
            this.grpSubList.Visible = false;
            this.pageProgNr.PageVisible = true;
            this.tabSubList.SelectedTabPageIndex = 0;
              }
            }
            else
            {
              this.pageProgNr.PageVisible = true;
              this.grpSubList.Visible = DataRoot.SortedFavorites;
            }

            //this.tabSubList.TabPages[0].PageVisible = !channelList.IsMixedSourceFavoritesList;
            //this.pageProgNr.Enabled = this.pageProgNr.Visible;
              }
              else
              {
            this.gridRight.DataSource = null;
            this.gridLeft.DataSource = null;
            this.grpSubList.Visible = false;
              }

              if (gviewRight.IsValidRowHandle(0))
            this.SelectFocusedRow(this.gviewRight, 0);

              if (gviewLeft.IsValidRowHandle(0))
            this.SelectFocusedRow(this.gviewLeft, 0);

              UpdateGridReadOnly();

              this.UpdateInsertSlotTextBox();
              this.UpdateMenu();

              this.mnuFavList.Enabled = this.grpSubList.Visible;
              if (!this.grpSubList.Visible)
            this.tabSubList.SelectedTabPageIndex = 0;
        }
Пример #35
0
        private void FillChannelListCombo()
        {
            this.tabChannelList.TabPages.Clear();

              var itemList = new List<BarItem>();
              foreach(BarItemLink link in this.mnuInputSource.ItemLinks)
            itemList.Add(link.Item);
              foreach (BarItem item in itemList)
              {
            this.barManager1.Items.Remove(item);
            item.Dispose();
              }
              this.mnuInputSource.ClearLinks();

              XtraTabPage firstNonEmpty = null;
              int i = 0;
              foreach (var list in this.dataRoot.ChannelLists)
              {
            if (list.Channels.Count == 0)
              continue;
            var tab = this.tabChannelList.TabPages.Add(list.Caption);
            tab.Tag = list;
            if (firstNonEmpty == null && list.Count > 0)
              firstNonEmpty = tab;
            var item = new BarButtonItem(this.barManager1, list.Caption);
            item.ItemShortcut = new BarShortcut((Keys) ((int)(Keys.Alt | Keys.D1) + i));
            item.Tag = i;
            item.ItemClick += this.miInputSource_ItemClick;
            this.mnuInputSource.AddItem(item);
            ++i;
              }

              if (tabChannelList.TabPages.Count > 0)
              {
            if (firstNonEmpty == null)
              firstNonEmpty = tabChannelList.TabPages[0];
            if (firstNonEmpty == this.tabChannelList.SelectedTabPage)
              this.ShowChannelList((ChannelList)firstNonEmpty.Tag);
            else
              this.tabChannelList.SelectedTabPage = firstNonEmpty;
              }
              else
              {
            this.tabChannelList.TabPages.Add(this.pageEmpty);
            this.currentChannelList = null;
              }
        }
Пример #36
0
 public virtual void AddChannelList(ChannelList list)
 {
     this.channelLists.Add(list);
 }
Пример #37
0
        private void LoadFiles(ISerializerPlugin plugin, string tvDataFile)
        {
            bool dataUpdated = false;
              try
              {
            if (DetectCommonFileCorruptions(tvDataFile))
              return;

            if (!this.LoadTvDataFile(plugin, tvDataFile))
              return;

            dataUpdated = true;
            this.gviewRight.BeginDataUpdate();
            this.gviewLeft.BeginDataUpdate();

            this.editor = new Editor();
            this.editor.DataRoot = this.dataRoot;

            this.currentChannelList = null;
            this.editor.ChannelList = null;
            this.gridRight.DataSource = null;
            this.gridLeft.DataSource = null;
            this.FillChannelListCombo();

            //this.SetControlsEnabled(!this.dataRoot.IsEmpty);
            this.UpdateFavoritesEditor(this.dataRoot.SupportedFavorites);

            if (this.dataRoot.Warnings.Length > 0 && this.miShowWarningsAfterLoad.Checked)
              this.BeginInvoke((Action)this.ShowFileInformation);

            this.BeginInvoke((Action)this.InitInitialChannelOrder);
              }
              catch (Exception ex)
              {
            if (!(ex is IOException))
              throw;
            string name = plugin != null ? plugin.PluginName : "Loader";
            XtraMessageBox.Show(this, name + "\n\n" + ex.Message, Resources.MainForm_LoadFiles_IOException,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.currentPlugin = null;
            this.currentTvFile = null;
            this.currentTvSerializer = null;
            this.Text = this.title;
              }
              finally
              {
            if (dataUpdated)
            {
              this.gviewRight.EndDataUpdate();
              this.gviewLeft.EndDataUpdate();
            }
              }
        }
Пример #38
0
    private IEnumerable<ChannelInfo> FindChannels(ChannelList channelList, string name, string uid)
    {
      // if there's only a single channel with the given name, use it regardless of UID (allows for a changed freq/tranpsonder)
      IList<ChannelInfo> list = channelList.GetChannelByName(name).ToList();
      if (list.Count == 1)
        return list;

      string[] uidParts;
      if (uid.StartsWith("C") && (uidParts = uid.Split('-')).Length <= 4)
      {
        // older CSV files didn't use the Transponder as part of the UID, which is necessary
        // to distinguish between DVB-T channels with identical (onid,tsid,sid), which may be received 
        // from multiple regional transmitters on different transponders
        int onid = int.Parse(uidParts[1]);
        int tsid = int.Parse(uidParts[2]);
        int sid = int.Parse(uidParts[3]);
        return channelList.Channels.Where(c => 
          c.OriginalNetworkId == onid && 
          c.TransportStreamId == tsid &&
          c.ServiceId == sid
          ).ToList();
      }

      var byUidList = channelList.GetChannelByUid(uid);
      return byUidList;
    }
Пример #39
0
        private void WriteChannels(SQLiteCommand cmd, ChannelList channelList)
        {
            cmd.CommandText = "update SVL set major_channel=@progNr, profile1index=@fav1, profile2index=@fav2, profile3index=@fav3, profile4index=@fav4, child_lock=@lock, skip=@skip where rowid=@rowid";
              cmd.Parameters.Clear();
              cmd.Parameters.Add(new SQLiteParameter("@rowid", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@progNr", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@fav1", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@fav2", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@fav3", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@fav4", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@lock", DbType.Int32));
              cmd.Parameters.Add(new SQLiteParameter("@skip", DbType.Int32));
              cmd.Prepare();
              foreach (ChannelInfo channelInfo in channelList.Channels)
              {
            var channel = channelInfo as DbChannel;
            if (channel == null) // skip reference list proxy channels
              continue;
            if (channel.NewProgramNr < 0 || channel.OldProgramNr < 0)
              continue;
            cmd.Parameters["@rowid"].Value = channel.RecordIndex;
            cmd.Parameters["@progNr"].Value = channel.NewProgramNr;
            for (int fav = 0; fav < 4; fav++)
              cmd.Parameters["@fav" + (fav + 1)].Value = Math.Max(0, channel.FavIndex[fav]);
            cmd.Parameters["@lock"].Value = channel.Lock;
            cmd.Parameters["@skip"].Value = channel.Skip;
            cmd.ExecuteNonQuery();
              }

              // delete unassigned channels
              cmd.CommandText = "delete from SVL where rowid=@rowid";
              cmd.Parameters.Clear();
              cmd.Parameters.Add(new SQLiteParameter("@rowid", DbType.Int32));
              foreach (ChannelInfo channel in channelList.Channels)
              {
            if (channel.NewProgramNr == -1 && channel.OldProgramNr >= 0)
            {
              cmd.Parameters["@rowid"].Value = channel.RecordIndex;
              cmd.ExecuteNonQuery();
            }
              }
        }
Пример #40
0
        private void WriteChannels(SQLiteCommand cmdUpdateSrv, SQLiteCommand cmdDeleteSrv, SQLiteCommand cmdInsertFav, SQLiteCommand cmdUpdateFav, SQLiteCommand cmdDeleteFav, 
      ChannelList channelList, bool analog = false)
        {
            foreach (ChannelInfo channelInfo in channelList.Channels)
              {
            var channel = channelInfo as DbChannel;
            if (channel == null) // ignore reference list proxy channels
              continue;
            channel.UpdateRawData();
            if (channel.NewProgramNr < 0)
            {
              cmdDeleteSrv.Parameters["@id"].Value = channel.RecordIndex;
              cmdDeleteSrv.ExecuteNonQuery();
            }
            else
            {
              cmdUpdateSrv.Parameters["@id"].Value = channel.RecordIndex;
              cmdUpdateSrv.Parameters["@nr"].Value = channel.NewProgramNr;
              cmdUpdateSrv.Parameters["@lock"].Value = channel.Lock;
              cmdUpdateSrv.Parameters["@hidden"].Value = channel.Hidden;
              cmdUpdateSrv.Parameters["@numsel"].Value = !channel.Skip;
              cmdUpdateSrv.Parameters["@srvname"].Value = channel.Name == null ? null : Encoding.BigEndianUnicode.GetBytes(channel.Name);
              cmdUpdateSrv.ExecuteNonQuery();
            }

            for (int i=0, mask=1; i<5; i++, mask <<= 1)
            {
            #if INDIVIDUALLY_SORTED_FAVS
              int oldPos;
              if (!channel.OriginalFavIndex.TryGetValue(i, out oldPos))
            oldPos = -1;
              int newPos = channel.FavIndex[i];
              if (newPos == oldPos)
            continue;
            #else
              int oldPos = ((int)channel.OriginalFavs & mask) != 0 ? channel.OldProgramNr : -1;
              int newPos = ((int)channel.Favorites & mask) != 0 ? channel.NewProgramNr : -1;
            #endif
              if (newPos > 0)
              {
            var c = oldPos < 0 ? cmdInsertFav : cmdUpdateFav;
            c.Parameters["@id"].Value = channel.RecordIndex;
            c.Parameters["@fav"].Value = i + 1;
            c.Parameters["@pos"].Value = newPos;
            c.ExecuteNonQuery();
              }
              else
              {
            cmdDeleteFav.Parameters["@id"].Value = channel.RecordIndex;
            cmdDeleteFav.Parameters["@fav"].Value = i + 1;
            cmdDeleteFav.ExecuteNonQuery();
              }
            }
            channel.OriginalFavs = channel.Favorites;
              }
        }