コード例 #1
0
        public virtual void OnBeforeAllTests()
        {
            // Cleanup directory and re-created
            Cleanup();

            // Attach to hardware
            using (m_Hardware)
                m_Hardware = HardwareManager.Open();
        }
コード例 #2
0
        /// <summary>
        /// Erstellt eine neue Zugriffsverwaltung.
        /// </summary>
        /// <param name="profileNames">Die Namen der zu verwendenden Geräteprofile.</param>
        public StandardFeedProvider(params string[] profileNames)
        {
            // Helper
            m_devices =
                (profileNames ?? Enumerable.Empty <string>())
                .Select(profileName => new StandardDevice(ProfileManager.FindProfile(profileName)))
                .ToArray();

            // Check configuration
            if (m_devices.Length != new HashSet <string>(m_devices.Select(profile => profile.Name), ProfileManager.ProfileNameComparer).Count)
            {
                throw new ArgumentException("invalid profile list", "profileNames");
            }

            // Start hardware access
            m_hardware = HardwareManager.Open();
        }
コード例 #3
0
        /// <summary>
        /// Führt den eigentliche Zugriff aus.
        /// </summary>
        private void Worker()
        {
            // Be fully safe
            try
            {
                // With hardware
                using (HardwareManager.Open())
                {
                    // Attach to group
                    PlugIn.LastSource.SelectGroup();

                    // Attach to device
                    Hardware device = PlugIn.LastSource.GetHardware();

                    // Create parser
                    m_Parser = TableParser.Create <GenericTable>(OnTable);

                    // Register raw stream
                    Guid consumerId = device.AddConsumer(m_Stream, m_Extended ? StreamTypes.ExtendedTable : StreamTypes.StandardTable, OnData);

                    // Start it
                    device.SetConsumerState(consumerId, true);

                    // Process
                    while (null != m_Worker)
                    {
                        Thread.Sleep(100);
                    }

                    // Stop all
                    device.SetConsumerState(consumerId, null);
                }
            }
            catch
            {
            }

            // Close the file
            using (BinaryWriter writer = m_TargetFile)
                m_TargetFile = null;

            // Did it
            Invoke(new Action(AdminSite.OperationDone));
        }
コード例 #4
0
        /// <summary>
        /// Führt die eigentliche Auswertung durch.
        /// </summary>
        private void Worker()
        {
            // Be safe
            try
            {
                // Prepare all displays
                foreach (GroupDisplay display in m_Displays.Values)
                {
                    display.Prepare();
                }

                // As long as necessary
                using (HardwareManager.Open())
                    while (null != m_Worker)
                    {
                        foreach (GroupDisplay display in m_Displays.Values)
                        {
                            // Process
                            display.ProcessNext();

                            // Done
                            if (null == m_Worker)
                            {
                                break;
                            }

                            // Relax a bit
                            Thread.Sleep(100);

                            // Done
                            if (null == m_Worker)
                            {
                                break;
                            }
                        }
                    }
            }
            catch
            {
            }

            // Report
            Invoke(new Action(AdminSite.OperationDone));
        }
コード例 #5
0
        /// <summary>
        /// Führt die eintreffenden Aufträge aus.
        /// </summary>
        private void WorkerThread(object reset)
        {
            // Always use the configured language
            UserProfile.ApplyLanguage();

            // Use hardware manager
            using (HardwareManager.Open())
            {
                // Device to use
                Hardware device;

                // Try to attach profile
                try
                {
                    // Open it
                    device = HardwareManager.OpenHardware(Profile);

                    // Should reset
                    if ((bool)reset)
                    {
                        device.ResetWakeupDevice();
                    }

                    // Report success
                    ActionDone(null, null);
                }
                catch (Exception e)
                {
                    // Report error
                    ActionDone(e, null);

                    // Did it
                    return;
                }

                // Loop
                for (var lastIdle = DateTime.UtcNow; m_Running;)
                {
                    // Wait for new item to process
                    m_Trigger.WaitOne();

                    // Load operation
                    var operation = m_Operation;

                    // Clear
                    m_Operation = null;

                    // Process
                    if (m_Running)
                    {
                        if (operation != null)
                        {
                            try
                            {
                                // Process
                                var result = operation(device);

                                // See if there is at least one active source with a program guide running
                                var withGuide = Streams.Values.FirstOrDefault(stream => stream.IsProgamGuideActive.GetValueOrDefault(false));

                                // Check for service parser operation
                                if (m_ServiceParser == null)
                                {
                                    // Can be activated it at least one source with active program guide
                                    if (withGuide != null)
                                    {
                                        try
                                        {
                                            // Create
                                            m_ServiceParser = new ServiceParser(Profile, withGuide.Manager.Source);
                                        }
                                        catch
                                        {
                                            // Ignore any error
                                            m_ServiceParser = null;
                                        }
                                    }
                                }
                                else
                                {
                                    // Only allowed if there is at least one source with active program guide
                                    if (withGuide == null)
                                    {
                                        DisableServiceParser();
                                    }
                                }

                                // Done
                                if (!ReferenceEquals(result, DelayedOperationTag))
                                {
                                    ActionDone(null, result);
                                }
                            }
                            catch (Exception e)
                            {
                                // Report
                                ActionDone(e, null);
                            }
                        }
                    }

                    // See if idle processing should be started
                    if (m_Running)
                    {
                        if ((DateTime.UtcNow - lastIdle).TotalSeconds >= 5)
                        {
                            // Run
                            OnIdle(device);

                            // Reset
                            lastIdle = DateTime.UtcNow;
                        }
                    }
                }

                // Reset EPG flag
                EPGProgress = null;

                // Clear EPG list to preserve memory
                m_EPGItems.Clear();

                // Reset PSI scan flag
                using (var scanner = m_Scanner)
                {
                    // Forget all
                    m_ScanProgress = -1;
                    m_Scanner      = null;
                }

                // Just be safe
                try
                {
                    // Final cleanup
                    RemoveAll();
                }
                catch
                {
                    // Ignore any error
                }
            }
        }
コード例 #6
0
 public virtual void StartupTests()
 {
     // Allocate hardware
     using (m_Hardware)
         m_Hardware = HardwareManager.Open();
 }
コード例 #7
0
        /// <summary>
        /// Der Anwender hat eine neue Quelle ausgewählt.
        /// </summary>
        /// <param name="sender">Wird ignoriert.</param>
        /// <param name="e">Wird ignoriert.</param>
        private void selSource_SelectionChangeCommitted(object sender, EventArgs e)
        {
            // Reset color
            lstStreams.BackColor = m_Background;
            txSignal.BackColor   = m_Signal;
            txSignal.Text        = null;

            // Stop all activities
            CloseStreams();

            // Clear list
            lstStreams.Items.Clear();

            // Attach to selection
            SourceItem source = (SourceItem)selSource.SelectedItem;

            // Nothing to do
            if (null == source)
            {
                return;
            }

            // Remember
            PlugIn.LastSource = source.Source;

            // Be as safe as possible
            try
            {
                // Make sure that hardware is controlled
                if (m_HardwareManager == null)
                {
                    m_HardwareManager = HardwareManager.Open();
                }

                // Select the source
                source.Source.SelectGroup();

                // Get the stream information
                var info = source.Source.GetSourceInformationAsync().CancelAfter(5000).Result;
                if (info == null)
                {
                    return;
                }

                // Attach to the hardware
                Hardware device = source.Source.GetHardware();

                // Silent decrypt
                if (info.IsEncrypted)
                {
                    try
                    {
                        // Process
                        device.Decrypt(source.Source.Source);

                        // Did it
                        lstStreams.BackColor = Color.Green;
                    }
                    catch
                    {
                        // Failed
                        lstStreams.BackColor = Color.Red;
                    }
                }

                // Video
                if (info.VideoType == VideoTypes.MPEG2)
                {
                    m_Streams.Add(new StreamItem(device, info.VideoStream, StreamTypes.Video, "SDTV", false));
                }
                else if (info.VideoType == VideoTypes.H264)
                {
                    m_Streams.Add(new StreamItem(device, info.VideoStream, StreamTypes.Video, "HDTV", true));
                }

                // Audio
                foreach (AudioInformation audio in info.AudioTracks)
                {
                    m_Streams.Add(new StreamItem(device, audio.AudioStream, StreamTypes.Audio, string.Format("{0} {1}", audio.AudioType, audio.Language)));
                }

                // DVB subtitles
                foreach (SubtitleInformation sub in info.Subtitles)
                {
                    m_Streams.Add(new StreamItem(device, sub.SubtitleStream, StreamTypes.SubTitle, string.Format("{0} {1}", sub.SubtitleType, sub.Language)));
                }

                // Videotext
                if (0 != info.TextStream)
                {
                    m_Streams.Add(new StreamItem(device, info.TextStream, StreamTypes.VideoText, "TTX"));
                }
            }
            catch (Exception ex)
            {
                // Report
                MessageBox.Show(this, ex.Message, string.Format(Properties.Resources.Exception_Source_Title, source));
            }

            // Add to list
            lstStreams.Items.AddRange(m_Streams.ToArray());

            // Set column widths
            foreach (ColumnHeader column in lstStreams.Columns)
            {
                // First width
                column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);

                // Remember
                int width1 = column.Width;

                // Second width
                column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);

                // Remember
                int width2 = column.Width;

                // Reset
                column.AutoResize(ColumnHeaderAutoResizeStyle.None);

                // Set width
                column.Width = Math.Max(width1, width2);
            }
        }
コード例 #8
0
        /// <summary>
        /// Sucht eine Konfiguration der Teildatenströme, die eine Aufzeichnung aller Quellen
        /// eventuell mit Reduktion des Aufzeichnungsumfangs erlaubt.
        /// </summary>
        /// <param name="disableOrder">Die Liste der Aspekte, die ausgeblendet werden dürfen.</param>
        /// <returns>Die Anzahl der Quellen, die verwendet werden können.</returns>
        public int Optimize(params StreamDisableSelector[] disableOrder)
        {
            // No souces
            if (m_Sources.Count < 1)
            {
                return(m_Sources.Count);
            }

            // Total stream count
            int available;

            // No limit
            using (HardwareManager.Open())
            {
                // Attach to the device
                Hardware device = m_Sources[0].Source.GetHardware();

                // No limit at all
                if (!device.HasConsumerRestriction)
                {
                    return(m_Sources.Count);
                }

                // Get all the active streams
                ushort[] activeStreams = device.GetActiveStreams();

                // Ask for it
                available = device.Restrictions.ConsumerLimit.Value - activeStreams.Length;

                // None at all
                if (available < 1)
                {
                    return(0);
                }

                // Stream managers in use
                List <SourceStreamsManager> managers = new List <SourceStreamsManager>();
                try
                {
                    // Create one by one
                    for (int i = 0; i < m_Sources.Count; ++i)
                    {
                        // Attach
                        SelectionInfo info = m_Sources[i];

                        // Create new manager
                        SourceStreamsManager manager = info.Source.Open(info.OriginalStreams);

                        // Remember for cleanupo
                        managers.Add(manager);

                        // See if source is available
                        if (!manager.CreateStream(null))
                        {
                            // Fake entry - will not be used
                            info.CurrentStreams = info.OriginalStreams.Clone();
                            info.ConsumerCount  = 0;
                        }
                        else
                        {
                            // Remember all we found
                            info.CurrentStreams = manager.ActiveSelection;
                            info.ConsumerCount  = manager.ConsumerCount;
                        }
                    }

                    // Whoo - can open it all as requested
                    return(m_Sources.Count);
                }
                catch (OutOfConsumersException)
                {
                }
                finally
                {
                    // Terminate all
                    foreach (SourceStreamsManager manager in managers)
                    {
                        manager.Dispose();
                    }
                }

                // First try to make sure that each source can be opened in stand-alone mode
                foreach (SelectionInfo info in m_Sources)
                {
                    info.Optimize(disableOrder, Report);
                }

                // Now simulate starting all - will try to get most out of the first one and so on
                for (int ixStream = 0; ixStream < m_Sources.Count; ixStream++)
                {
                    // Attach to the item
                    SelectionInfo current = m_Sources[ixStream];

                    // See how many additional streams will be needed
                    int needed = current.ConsumerCount.Value - available;

                    // Try to free some
                    for (int ixDisable = 0; (needed > 0) && (ixDisable < disableOrder.Length);)
                    {
                        // Load the next option
                        StreamDisableSelector disable = disableOrder[ixDisable++];

                        // Apply self
                        current.ApplyDisable(disable, StreamDisableMode.Self, ref needed, Report);

                        // Apply higher priorized
                        for (int ixHigher = ixStream; (needed > 0) && (ixHigher-- > 0);)
                        {
                            m_Sources[ixHigher].ApplyDisable(disable, StreamDisableMode.Higher, ref needed, Report);
                        }
                    }

                    // Should not be startet - we find no way to provide a proper subset of streams
                    if (needed > 0)
                    {
                        return(ixStream);
                    }

                    // Back to what is left
                    available = -needed;
                }

                // Not possible
                return(m_Sources.Count);
            }
        }
コード例 #9
0
        /// <summary>
        /// Analysiert die aktuelle Konfiguration des Suchlaufs auf Basis
        /// der DVB <i>Network Information Table (NIT)</i> Informationen.
        /// </summary>
        private void AnalyserThread()
        {
            // Be safe
            try
            {
                // Configure language
                UserProfile.ApplyLanguage();

                // Uses hardware manager
                using (HardwareManager.Open())
                {
                    // Attach to the hardware itself
                    Hardware device = HardwareManager.OpenHardware(Profile);

                    // Reset counters
                    TotalLocations  = m_Locations.Count;
                    CurrentLocation = 0;

                    // Last inversion used
                    SpectrumInversions lastInversion = SpectrumInversions.On;

                    // Process all transponders
                    foreach (GroupLocation location in m_Locations)
                    {
                        // Update counter
                        ++CurrentLocation;

                        // Reset
                        CurrentLocationGroupsPending = 0;
                        CurrentLocationGroup         = 0;

                        // Check caller
                        if (!LocationStart(location))
                        {
                            return;
                        }

                        // Groups found on this location
                        Dictionary <SourceGroup, bool> found = new Dictionary <SourceGroup, bool>();

                        // Groups with valid network information - only those are considered
                        List <SourceGroup> nitAvailable = new List <SourceGroup>();

                        // Load counter
                        CurrentLocationGroupsPending = location.Groups.Count;

                        // Process all groups
                        foreach (SourceGroup group in location.Groups)
                        {
                            // Get the expected type
                            Type groupType = group.GetType();

                            // Clone the group
                            SourceGroup newGroup = SourceGroup.FromString <SourceGroup>(group.ToString());

                            // Count up
                            --CurrentLocationGroupsPending;
                            ++CurrentLocationGroup;

                            // See if this is already processed
                            if (null != found.Keys.FirstOrDefault(p => p.CompareTo(newGroup, true)))
                            {
                                continue;
                            }

                            // Check for external termination
                            if (null == m_Worker)
                            {
                                return;
                            }

                            // Not supported
                            if (!Profile.SupportsGroup(newGroup) || !device.CanHandle(newGroup))
                            {
                                // Remember
                                m_UnhandledGroups.Add(newGroup);

                                // Next
                                continue;
                            }

                            // Check caller
                            if (!GroupStart(location, newGroup))
                            {
                                return;
                            }

                            // Attach to the group
                            if (null != SelectGroup(device, location, newGroup, ref lastInversion))
                            {
                                // See if we are a cable group
                                CableGroup cableGroup = newGroup as CableGroup;

                                // Attach to the NIT
                                var nit = device.GetLocationInformation(15000);
                                if (null != nit)
                                {
                                    // Remember
                                    nitAvailable.Add(newGroup);

                                    // Process
                                    foreach (SourceGroup other in nit.Groups)
                                    {
                                        if (other.GetType() == groupType)
                                        {
                                            // See if this is a cable group
                                            CableGroup otherCable = other as CableGroup;

                                            // Update inversion
                                            if (null != otherCable)
                                            {
                                                // Other must be cable, too
                                                if (null == cableGroup)
                                                {
                                                    continue;
                                                }

                                                // Use same parameters
                                                otherCable.SpectrumInversion = cableGroup.SpectrumInversion;
                                                otherCable.Bandwidth         = cableGroup.Bandwidth;
                                            }

                                            // Report
                                            if (ScannerTraceSwitch.Level >= TraceLevel.Info)
                                            {
                                                Trace.WriteLine(string.Format(Properties.Resources.Trace_Scanner_NIT, other), ScannerTraceSwitch.DisplayName);
                                            }

                                            // Mark it
                                            found[other] = true;
                                        }
                                    }
                                }
                            }

                            // Check caller
                            if (!GroupDone(location, newGroup))
                            {
                                return;
                            }
                        }

                        // Create a brand new scan location
                        ScanLocation scan = location.ToScanLocation();

                        // Try to update
                        foreach (SourceGroup group in nitAvailable)
                        {
                            // Try to find the full qualified name
                            SourceGroup nitGroup = found.Keys.FirstOrDefault(p => p.CompareTo(group, true));

                            // Update
                            if (null == nitGroup)
                            {
                                scan.Groups.Add(group);
                            }
                            else
                            {
                                scan.Groups.Add(nitGroup);
                            }
                        }

                        // Just remember
                        m_AnalyseResult[location] = scan;

                        // Check caller
                        if (!LocationDone(location))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Remember
                m_ThreadException = e;
            }
        }
コード例 #10
0
        /// <summary>
        /// Führt den eigentlichen Sendersuchlauf aus.
        /// </summary>
        private void ScannerThread()
        {
            // Be safe
            try
            {
                // Configure language
                UserProfile.ApplyLanguage();

                // Uses hardware manager
                using (HardwareManager.Open())
                {
                    // Attach to the hardware itself
                    var device = HardwareManager.OpenHardware(Profile);

                    // Tell it that we only do a scan
                    device.PrepareSourceScan();

                    // Start loading location result list
                    foreach (var location in m_Locations)
                    {
                        m_ScanResults.Add(location.Clone());
                    }

                    // Reset counters
                    TotalLocations = m_Locations.Count;

                    // Last successfull inversion
                    var lastInversion = SpectrumInversions.On;

                    // Process all transponders
                    for (CurrentLocation = 0; CurrentLocation < m_Locations.Count;)
                    {
                        // Get new and old
                        var location    = m_Locations[CurrentLocation];
                        var newLocation = m_ScanResults[CurrentLocation];

                        // Count
                        ++CurrentLocation;

                        // Reset
                        CurrentLocationGroupsPending = 0;
                        CurrentLocationGroup         = 0;

                        // Check caller
                        if (!LocationStart(location))
                        {
                            return;
                        }

                        // Allow NIT scan on...
                        var enableNIT = new List <SourceGroup>();
                        var foundInfo = new List <SourceGroup>();

                        // Startup and load the groups from the configuration
                        foreach (SourceGroup group in location.Groups)
                        {
                            enableNIT.Add(group);
                        }

                        // All we have to process
                        var process = new List <SourceGroup>(enableNIT);

                        // Allowed group type
                        var groupType = (process.Count > 0) ? process[0].GetType() : null;

                        // All we did so far
                        var done = new HashSet <SourceGroup>();

                        // Process all groups
                        while (process.Count > 0)
                        {
                            // Take the first one
                            var group = process[0];

                            // Remove it
                            process.RemoveAt(0);

                            // Reset counter
                            CurrentLocationGroupsPending = process.Count;

                            // Count what we did
                            ++CurrentLocationGroup;

                            // Already done
                            if (done.Contains(group))
                            {
                                continue;
                            }

                            // Found group information on equivalent group
                            if (foundInfo.FirstOrDefault(g => g.CompareTo(group, true)) != null)
                            {
                                continue;
                            }

                            // Mark as done
                            done.Add(group);

                            // Check for external termination
                            if (m_Worker == null)
                            {
                                return;
                            }

                            // Not supported
                            if (!Profile.SupportsGroup(group) || !device.CanHandle(group))
                            {
                                // Remember
                                m_UnhandledGroups.Add(group);

                                // Next
                                continue;
                            }

                            // Read the configuration
                            var filter = Profile.GetFilter(group);

                            // See if this should be skiped
                            if (filter != null)
                            {
                                if (filter.ExcludeFromScan)
                                {
                                    // Remember
                                    m_GroupsExcluded.Add(group);

                                    // Next
                                    continue;
                                }
                            }

                            // Check caller
                            if (!GroupStart(location, group))
                            {
                                return;
                            }

                            // See if we should process the NIT
                            var checkNIT = enableNIT.Contains(group);

                            // See if we should process
                            if (checkNIT || group.IsComplete)
                            {
                                // Clone the group - may change
                                group = SourceGroup.FromString <SourceGroup>(group.ToString());

                                // Attach to the group
                                var info = SelectGroup(device, location, group, ref lastInversion);

                                // Mark as done again - group may be updated for DVB-C and if unchanged this is simply a no-operation
                                done.Add(group);

                                // Read the configuration again - actually for DVB-C it may change
                                filter = Profile.GetFilter(group);

                                // See if this should be skiped
                                if (filter != null)
                                {
                                    if (filter.ExcludeFromScan)
                                    {
                                        // Remember
                                        m_GroupsExcluded.Add(group);

                                        // Next
                                        continue;
                                    }
                                }

                                // Remember that we found a group information - transponder is not dead
                                if (info != null)
                                {
                                    foundInfo.Add(group);
                                }

                                // See if NIT update is allowed
                                if (checkNIT)
                                {
                                    if (info != null)
                                    {
                                        // See if we are a cable group
                                        var cableGroup = group as CableGroup;

                                        // Try load
                                        var nit = device.GetLocationInformation(15000);
                                        if (nit != null)
                                        {
                                            foreach (SourceGroup other in nit.Groups)
                                            {
                                                if (other.GetType() == groupType)
                                                {
                                                    // See if this is a cable group
                                                    var otherCable = other as CableGroup;

                                                    // Disable NIT scan on the group as is
                                                    enableNIT.RemoveAll(g => g.CompareTo(other, true));
                                                    process.RemoveAll(g => g.CompareTo(other, true));

                                                    // Set inversion
                                                    if (otherCable != null)
                                                    {
                                                        if (cableGroup != null)
                                                        {
                                                            // Use same parameters
                                                            otherCable.SpectrumInversion = cableGroup.SpectrumInversion;
                                                            otherCable.Bandwidth         = cableGroup.Bandwidth;

                                                            // Disable NIT scan on the group which may be DVB-C corrected
                                                            enableNIT.RemoveAll(g => g.CompareTo(otherCable, true));
                                                            process.RemoveAll(g => g.CompareTo(otherCable, true));
                                                        }
                                                    }

                                                    // Report
                                                    if (ScannerTraceSwitch.Level >= TraceLevel.Info)
                                                    {
                                                        Trace.WriteLine(string.Format(Properties.Resources.Trace_Scanner_NIT, other), ScannerTraceSwitch.DisplayName);
                                                    }

                                                    // Add for processing
                                                    process.Insert(0, other);
                                                }
                                            }
                                        }
                                    }
                                }

                                // Reset counter - may be updated if a new NIT was processed
                                CurrentLocationGroupsPending = process.Count;

                                // Skip if a legacy template group
                                if (group.IsComplete)
                                {
                                    // Merge
                                    newLocation.Groups.Add(group);

                                    // Process this group
                                    if (info == null)
                                    {
                                        m_Protocol.Add(new ProtocolRecord {
                                            Mode = ProtocolRecordMode.EmptyGroup, Location = location, Group = group
                                        });
                                    }
                                    else
                                    {
                                        foreach (var source in info.Sources)
                                        {
                                            // Only stations
                                            var station = source as Station;
                                            if (station == null)
                                            {
                                                continue;
                                            }

                                            // Attach to the filter
                                            var modifiers = Profile.GetFilter(source);
                                            if (modifiers != null)
                                            {
                                                if (modifiers.ExcludeFromScan)
                                                {
                                                    continue;
                                                }
                                                else
                                                {
                                                    modifiers.ApplyTo(station);
                                                }
                                            }

                                            // Remember
                                            group.Sources.Add(station);

                                            // Get the count
                                            int foundOfType;
                                            if (!SourcesFound.TryGetValue(station.SourceType, out foundOfType))
                                            {
                                                foundOfType = 0;
                                            }

                                            // Update
                                            SourcesFound[station.SourceType] = ++foundOfType;

                                            // Ask user
                                            if (!StationFound(location, group, station))
                                            {
                                                return;
                                            }
                                        }
                                    }
                                }
                            }

                            // Check caller
                            if (!GroupDone(location, group))
                            {
                                return;
                            }
                        }

                        // Check caller
                        if (!LocationDone(location))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Remember
                m_ThreadException = e;
            }
        }
コード例 #11
0
        static void Main(string[] args)
        {
            // Be safe
            try
            {
                // Check settings
                var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                if (!version.Equals(Properties.Settings.Default.Version))
                {
                    // Upgrade
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.Version = version;
                    Properties.Settings.Default.Save();
                }

                // Prepare
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Force priority
                Process.GetCurrentProcess().PriorityClass = Properties.Settings.Default.Priority;

                // Check start mode
                string startMode = ((null == args) || (args.Length < 1)) ? null : args[0];

                // Apply language
                UserProfile.ApplyLanguage();

                // See how we should work
                if (Equals(startMode, "/Reset"))
                {
                    // Ask user
                    if (DialogResult.Yes != MessageBox.Show(Properties.Resources.ResetSettings, Properties.Resources.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
                    {
                        return;
                    }

                    // Process
                    Properties.Settings.Default.Reset();
                    Properties.Settings.Default.Save();
                }
                if (Equals(startMode, "/LearnRC"))
                {
                    // Run RC configuration
                    RCSettings.Edit(RCSettings.ConfigurationFile).Dispose();
                }
                else
                {
                    // Check OSD mode
                    if (Properties.Settings.Default.ManualOSDLegacyMode)
                    {
                        OverlayWindow.UseLegacyOverlay = Properties.Settings.Default.OSDLegacyMode;
                    }

                    // Form to start
                    ViewerMain form = null;

                    // Test parameter
                    if (!string.IsNullOrEmpty(startMode))
                    {
                        if (Equals(startMode, "/VCR"))
                        {
                            // Create in VCR LIVE / CURRENT mode
                            form = new ViewerMain(StartupModes.RemoteVCR);
                        }
                        else if (startMode.ToLower().StartsWith("dvbnet://"))
                        {
                            // Start with the server part
                            startMode = startMode.Substring(9);

                            // See if this is a regular start using the URL protocol
                            bool startedByProtocol = !startMode.StartsWith("*");

                            // Must be the control center
                            if (startedByProtocol)
                            {
                                // Prepare for special decoding
                                byte[] tmp = new byte[startMode.Length];

                                // Copy by byte
                                for (int i = tmp.Length; i-- > 0;)
                                {
                                    tmp[i] = (byte)startMode[i];
                                }

                                // Retrieve
                                startMode = Encoding.UTF8.GetString(tmp);
                            }
                            else
                            {
                                // Just cut off the control character
                                startMode = startMode.Substring(1);
                            }

                            // Just correct for URL stuff
                            startMode = Uri.UnescapeDataString(startMode.Replace('+', ' '));

                            // See if this is a file replay
                            int file = startMode.ToLower().IndexOf("/play=");
                            if (file < 0)
                            {
                                // Create in VCR CURRENT mode
                                form = new ViewerMain(StartupModes.WatchOrTimeshift, startMode);
                            }
                            else
                            {
                                // Get server and file name
                                string server = startMode.Substring(0, file);
                                string path   = startMode.Substring(file + 6);

                                // Replay
                                form = new ViewerMain(StartupModes.PlayRemoteFile, path, server);
                            }
                        }
                        else if (startMode.StartsWith("/VCR="))
                        {
                            // Create in VCR REPLY mode
                            form = new ViewerMain(StartupModes.PlayRemoteFile, startMode.Substring(5), null);
                        }
                        else if (startMode.StartsWith("/TCP="))
                        {
                            // Create in STREAMING SLAVE mode
                            form = new ViewerMain(StartupModes.ConnectTCP, startMode.Substring(5));
                        }
                        else if (startMode.StartsWith("/FILE="))
                        {
                            // Create in LOCAL REPLAY mode
                            form = new ViewerMain(StartupModes.PlayLocalFile, startMode.Substring(6));
                        }
                    }

                    // Local mode
                    if (form != null)
                    {
                        // Run the application
                        Application.Run(form);
                    }
                    else
                    {
                        // Ask for the profile
                        var profile = UserProfile.Profile;
                        if (profile != null)
                        {
                            using (HardwareManager.Open())
                                Application.Run(new ViewerMain(profile));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Report as is
                MessageBox.Show(e.ToString());

                // Terminate
                Environment.Exit(1);
            }

            // If we are running as the users shell log off
            using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Winlogon"))
                if (key != null)
                {
                    try
                    {
                        // Load shell
                        var shell = key.GetValue("Shell") as string;
                        if (shell != null)
                        {
                            // Remove quotes
                            if (shell.Length >= 2)
                            {
                                if (shell.StartsWith("\""))
                                {
                                    if (shell.EndsWith("\""))
                                    {
                                        shell = shell.Substring(1, shell.Length - 2).Replace("\"\"", "\"");
                                    }
                                }
                            }

                            // Clip
                            shell = shell.Trim();

                            // See what's left
                            if (!string.IsNullOrEmpty(shell))
                            {
                                // Attach to file
                                var file1 = new FileInfo(shell);
                                var file2 = new FileInfo(Application.ExecutablePath);

                                // Check
                                if (string.Equals(file1.FullName, file2.FullName, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    ExitWindowsEx(0x10, 0);
                                }
                            }
                        }
                    }
                    catch
                    {
                        // Ignore any error
                    }
                }
        }