From: <an...@us...> - 2007-02-15 03:40:08
|
Revision: 119 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=119&view=rev Author: and-81 Date: 2007-02-14 19:39:19 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/MCEReplacement/Forms/SetupForm.cs trunk/plugins/MCEReplacement/MCEReplacement.cs trunk/plugins/TV3ExtChannelChanger/ExternalChannelConfig.cs trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.cs trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.designer.cs trunk/plugins/TV3ExtChannelChanger/Forms/PluginSetup.cs trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.Designer.cs trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.cs trunk/plugins/TV3ExtChannelChanger/TV3ExtChannelChanger.cs trunk/plugins/TV3MceBlaster/Forms/PluginSetup.Designer.cs trunk/plugins/TV3MceBlaster/Forms/StbSetup.Designer.cs trunk/plugins/TV3MceBlaster/TV3MceBlaster.cs Modified: trunk/plugins/MCEReplacement/Forms/SetupForm.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/SetupForm.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/MCEReplacement/Forms/SetupForm.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -45,7 +45,7 @@ private void SetupForm_Load(object sender, EventArgs e) { - labelVersion.Text = MCEReplacement.Version; + labelVersion.Text = MCEReplacement.PluginVersion; checkBoxLogVerbose.Checked = MCEReplacement.LogVerbose; checkBoxRequiresFocus.Checked = MCEReplacement.RequireFocus; Modified: trunk/plugins/MCEReplacement/MCEReplacement.cs =================================================================== --- trunk/plugins/MCEReplacement/MCEReplacement.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/MCEReplacement/MCEReplacement.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -26,7 +26,7 @@ #region Constants - public const string Version = "MCE Replacement Plugin 1.0.2.0 for MediaPortal + SVN"; + public const string PluginVersion = "MCE Replacement Plugin 1.0.2.0 for MediaPortal + SVN"; public const int MessageModeCommand = 0x0018; @@ -262,7 +262,7 @@ public void Start() { - Log.Info("MCEReplacement: Starting ({0})", Version); + Log.Info("MCEReplacement: Starting ({0})", PluginVersion); Log.Debug("MCEReplacement: Platform is {0}", (IntPtr.Size == 4 ? "32-bit" : "64-bit")); @@ -1311,55 +1311,91 @@ return ProcessSerialCommand(commands); } - static bool BlastIR(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) + #endregion Private Methods + + #region Public Methods + + /// <summary> + /// Loads the default remote button input handler + /// </summary> + public static void LoadDefaultMapping() { - FileStream file = null; + _defaultInputHandler = new InputHandler("MCE Replacement"); - try + if (!_defaultInputHandler.IsLoaded) + Log.Error("MCEReplacement: Error loading default mapping file"); + } + + /// <summary> + /// Loads multi-mappings for input handling + /// </summary> + public static void LoadMultiMappings() + { + FileStream file = new FileStream(MultiMappingFile, FileMode.Open, FileAccess.Read, FileShare.Read); + + XmlDocument doc = new XmlDocument(); + doc.Load(file); + + XmlNodeList mappings = doc.DocumentElement.SelectNodes("map"); + + _multiInputHandlers = new List<InputHandler>(mappings.Count); + _multiMaps = new string[mappings.Count]; + + string map; + for (int index = 0; index < mappings.Count; index++) { - file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + map = mappings.Item(index).Attributes["name"].Value; - if (file.Length == 0) - { - Log.Error("MCEReplacement: IR file \"{0}\" has no data, possible IR learn failure", fileName); - file.Close(); - return false; - } + _multiMaps[index] = map; + _multiInputHandlers.Add(new InputHandler(map)); - if (!MceIrApi.CheckFile(file.SafeFileHandle)) - { - Log.Error("MCEReplacement: Bad IR file \"{0}\"", fileName); - file.Close(); - return false; - } + if (!_multiInputHandlers[index].IsLoaded) + Log.Error("MCEReplacement: Error loading default mapping file for {0}", map); + } - MceIrApi.SelectBlaster(port); - MceIrApi.SetBlasterSpeed(speed); - MceIrApi.SetBlasterType(BlastType); + file.Close(); + } - if (MceIrApi.PlaybackFromFile(file.SafeFileHandle)) - { - if (LogVerbose) - Log.Info("MCEReplacement: Blast successful"); + /// <summary> + /// Call this when entering standby to ensure that the MceIrApi is informed. + /// </summary> + public static void OnSuspend() + { + if (!InConfiguration && EventMapperEnabled) + MapEvent(MappedEvent.MappingEvent.PC_Suspend); - file.Close(); - return true; - } - } - catch (Exception ex) + if (MceIrApi.InUse) { - Log.Error("MCEReplacement: BlastIR() {0}", ex.Message); + if (LogVerbose) + Log.Info("MCEReplacement: Suspending MceIrApi"); + + MceIrApi.Suspend(); } + } - Log.Error("MCEReplacement: Failed to blast IR file \"{0}\"", fileName); + /// <summary> + /// Call this when leaving standby to ensure the MceIrApi is informed. + /// </summary> + public static void OnResume() + { + if (MceIrApi.InUse) + { + if (LogVerbose) + Log.Info("MCEReplacement: Resuming MceIrApi"); - if (file != null) - file.Close(); + MceIrApi.Resume(); + } - return false; + if (!InConfiguration && EventMapperEnabled) + MapEvent(MappedEvent.MappingEvent.PC_Resume); } - static bool ProcessMacro(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) + /// <summary> + /// Process the supplied Macro file. + /// </summary> + /// <param name="fileName">Macro file to process.</param> + /// <returns>Sucess.</returns> + public static bool ProcessMacro(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { FileStream file = null; @@ -1395,7 +1431,7 @@ { if (LogVerbose) Log.Debug("MCEReplacement: Pause {0}", commandProperty); - + int sleep = int.Parse(commandProperty); Thread.Sleep(sleep); break; @@ -1551,83 +1587,59 @@ return true; } - #endregion Private Methods - - #region Public Methods - /// <summary> - /// Loads the default remote button input handler + /// Blast an IR command. /// </summary> - public static void LoadDefaultMapping() + /// <param name="fileName">File to blast.</param> + /// <param name="port">Port to blast to.</param> + /// <param name="speed">Speed to blast at.</param> + /// <returns>Success.</returns> + public static bool BlastIR(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { - _defaultInputHandler = new InputHandler("MCE Replacement"); + FileStream file = null; - if (!_defaultInputHandler.IsLoaded) - Log.Error("MCEReplacement: Error loading default mapping file"); - } + try + { + file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - /// <summary> - /// Loads multi-mappings for input handling - /// </summary> - public static void LoadMultiMappings() - { - FileStream file = new FileStream(MultiMappingFile, FileMode.Open, FileAccess.Read, FileShare.Read); + if (file.Length == 0) + { + Log.Error("MCEReplacement: IR file \"{0}\" has no data, possible IR learn failure", fileName); + file.Close(); + return false; + } - XmlDocument doc = new XmlDocument(); - doc.Load(file); + if (!MceIrApi.CheckFile(file.SafeFileHandle)) + { + Log.Error("MCEReplacement: Bad IR file \"{0}\"", fileName); + file.Close(); + return false; + } - XmlNodeList mappings = doc.DocumentElement.SelectNodes("map"); + MceIrApi.SelectBlaster(port); + MceIrApi.SetBlasterSpeed(speed); + MceIrApi.SetBlasterType(BlastType); - _multiInputHandlers = new List<InputHandler>(mappings.Count); - _multiMaps = new string[mappings.Count]; + if (MceIrApi.PlaybackFromFile(file.SafeFileHandle)) + { + if (LogVerbose) + Log.Info("MCEReplacement: Blast successful"); - string map; - for (int index = 0; index < mappings.Count; index++) - { - map = mappings.Item(index).Attributes["name"].Value; - - _multiMaps[index] = map; - _multiInputHandlers.Add(new InputHandler(map)); - - if (!_multiInputHandlers[index].IsLoaded) - Log.Error("MCEReplacement: Error loading default mapping file for {0}", map); + file.Close(); + return true; + } } - - file.Close(); - } - - /// <summary> - /// Call this when entering standby to ensure that the MceIrApi is informed. - /// </summary> - public static void OnSuspend() - { - if (!InConfiguration && EventMapperEnabled) - MapEvent(MappedEvent.MappingEvent.PC_Suspend); - - if (MceIrApi.InUse) + catch (Exception ex) { - if (LogVerbose) - Log.Info("MCEReplacement: Suspending MceIrApi"); - - MceIrApi.Suspend(); + Log.Error("MCEReplacement: BlastIR() {0}", ex.Message); } - } - /// <summary> - /// Call this when leaving standby to ensure the MceIrApi is informed. - /// </summary> - public static void OnResume() - { - if (MceIrApi.InUse) - { - if (LogVerbose) - Log.Info("MCEReplacement: Resuming MceIrApi"); + Log.Error("MCEReplacement: Failed to blast IR file \"{0}\"", fileName); - MceIrApi.Resume(); - } + if (file != null) + file.Close(); - if (!InConfiguration && EventMapperEnabled) - MapEvent(MappedEvent.MappingEvent.PC_Resume); + return false; } /// <summary> @@ -2066,20 +2078,22 @@ } /// <summary> - /// Learn an IR code and put it in a file + /// Learn an IR Command and put it in a file /// </summary> - /// <param name="blastCommand">File to learn</param> - /// <returns>bool value shows success</returns> - public static bool LearnIRCommand(string blastCommand) + /// <param name="fileName">File to place learned IR command in.</param> + /// <returns>Success.</returns> + public static bool LearnIRCommand(string fileName) { - string fileName = AppDataFolder + blastCommand + IRExtension; + string filePath = AppDataFolder + fileName + IRExtension; FileStream file = null; bool status = false; try { - file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read); + file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); status = MceIrApi.RecordToFile(file.SafeFileHandle, LearnTimeout); + if (file.Length == 0) + status = false; } catch (Exception ex) { Modified: trunk/plugins/TV3ExtChannelChanger/ExternalChannelConfig.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/ExternalChannelConfig.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/ExternalChannelConfig.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -16,6 +16,8 @@ string _fileName; + int _cardID = -1; + int _pauseTime = 250; bool _sendSelect = false; bool _doubleChannelSelect = false; @@ -37,6 +39,12 @@ get { return _fileName; } } + public int CardId + { + get { return _cardID; } + set { _cardID = value; } + } + public int PauseTime { get { return _pauseTime; } @@ -93,10 +101,12 @@ #region Constructor - public ExternalChannelConfig(string fileName) + public ExternalChannelConfig(int cardId, string fileName) { _fileName = fileName; + _cardID = cardId; + if (!File.Exists(_fileName)) { for (int i = 0; i < 10; i++) Modified: trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -19,7 +19,6 @@ #region Variables - TabPage[] _tvCardTabs; StbSetup[] _tvCardStbSetups; #endregion Variables @@ -35,31 +34,30 @@ private void ExternalChannels_Load(object sender, EventArgs e) { - int cards = TV3ExtChannelChanger.ExternalChannelConfigs.Length; - string cardName; - string cardNumber; + IList cards = TvDatabase.Card.ListAll(); - _tvCardTabs = new TabPage[cards]; - _tvCardStbSetups = new StbSetup[cards]; + _tvCardStbSetups = new StbSetup[cards.Count]; comboBoxCopyFrom.Items.Clear(); - for (int index = 0; index < cards; index++) + TabPage tempPage; + int index = 0; + + foreach (TvDatabase.Card card in cards) { - cardNumber = (index + 1).ToString(); - cardName = "TV Card " + cardNumber; + comboBoxCopyFrom.Items.Add(card.IdCard); - comboBoxCopyFrom.Items.Add(cardName); - - _tvCardStbSetups[index] = new StbSetup(index); - _tvCardStbSetups[index].Name = "StbSetup" + cardNumber; + _tvCardStbSetups[index] = new StbSetup(card.IdCard); + _tvCardStbSetups[index].Name = string.Format("StbSetup{0}", index); _tvCardStbSetups[index].Dock = DockStyle.Fill; _tvCardStbSetups[index].TabIndex = 0; - _tvCardTabs[index] = new TabPage(cardName); - _tvCardTabs[index].Controls.Add(_tvCardStbSetups[index]); + tempPage = new TabPage(string.Format("TV Card {0}", index + 1)); + tempPage.Controls.Add(_tvCardStbSetups[index]); - this.tabControlTVCards.TabPages.Add(_tvCardTabs[index]); + this.tabControlTVCards.TabPages.Add(tempPage); + + index++; } comboBoxCopyFrom.SelectedIndex = 0; @@ -104,11 +102,11 @@ private void buttonOK_Click(object sender, EventArgs e) { foreach (StbSetup setup in _tvCardStbSetups) + { setup.Save(); + TV3ExtChannelChanger.GetExternalChannelConfig(setup.CardId).SaveExternalChannelConfig(); + } - foreach (ExternalChannelConfig config in TV3ExtChannelChanger.ExternalChannelConfigs) - config.SaveExternalChannelConfig(); - this.DialogResult = DialogResult.OK; this.Close(); } @@ -267,7 +265,7 @@ private void buttonCopyFrom_Click(object sender, EventArgs e) { - _tvCardStbSetups[tabControlTVCards.SelectedIndex].SetToCard(comboBoxCopyFrom.SelectedIndex); + _tvCardStbSetups[tabControlTVCards.SelectedIndex].SetToCard((int)comboBoxCopyFrom.SelectedItem); } private void buttonCancel_Click(object sender, EventArgs e) Modified: trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.designer.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.designer.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.designer.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -48,7 +48,7 @@ // buttonOK // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOK.Location = new System.Drawing.Point(400, 352); + this.buttonOK.Location = new System.Drawing.Point(400, 360); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(56, 24); this.buttonOK.TabIndex = 5; @@ -62,7 +62,7 @@ | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxQuickSetup.Controls.Add(this.buttonQuickSet); this.groupBoxQuickSetup.Controls.Add(this.comboBoxQuickSetup); - this.groupBoxQuickSetup.Location = new System.Drawing.Point(8, 296); + this.groupBoxQuickSetup.Location = new System.Drawing.Point(8, 304); this.groupBoxQuickSetup.Name = "groupBoxQuickSetup"; this.groupBoxQuickSetup.Size = new System.Drawing.Size(288, 48); this.groupBoxQuickSetup.TabIndex = 1; @@ -97,7 +97,7 @@ this.groupBoxTest.Controls.Add(this.labelCh); this.groupBoxTest.Controls.Add(this.buttonTest); this.groupBoxTest.Controls.Add(this.numericUpDownTest); - this.groupBoxTest.Location = new System.Drawing.Point(304, 296); + this.groupBoxTest.Location = new System.Drawing.Point(304, 304); this.groupBoxTest.Name = "groupBoxTest"; this.groupBoxTest.Size = new System.Drawing.Size(216, 48); this.groupBoxTest.TabIndex = 2; @@ -144,7 +144,7 @@ // buttonCopyFrom // this.buttonCopyFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCopyFrom.Location = new System.Drawing.Point(8, 352); + this.buttonCopyFrom.Location = new System.Drawing.Point(8, 360); this.buttonCopyFrom.Name = "buttonCopyFrom"; this.buttonCopyFrom.Size = new System.Drawing.Size(144, 21); this.buttonCopyFrom.TabIndex = 3; @@ -157,7 +157,7 @@ this.comboBoxCopyFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.comboBoxCopyFrom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxCopyFrom.FormattingEnabled = true; - this.comboBoxCopyFrom.Location = new System.Drawing.Point(160, 352); + this.comboBoxCopyFrom.Location = new System.Drawing.Point(160, 360); this.comboBoxCopyFrom.Name = "comboBoxCopyFrom"; this.comboBoxCopyFrom.Size = new System.Drawing.Size(120, 21); this.comboBoxCopyFrom.TabIndex = 4; @@ -170,14 +170,14 @@ this.tabControlTVCards.Location = new System.Drawing.Point(8, 8); this.tabControlTVCards.Name = "tabControlTVCards"; this.tabControlTVCards.SelectedIndex = 0; - this.tabControlTVCards.Size = new System.Drawing.Size(512, 280); + this.tabControlTVCards.Size = new System.Drawing.Size(512, 288); this.tabControlTVCards.TabIndex = 0; // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(464, 352); + this.buttonCancel.Location = new System.Drawing.Point(464, 360); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(56, 24); this.buttonCancel.TabIndex = 6; @@ -191,7 +191,7 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(528, 383); + this.ClientSize = new System.Drawing.Size(528, 391); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.tabControlTVCards); this.Controls.Add(this.comboBoxCopyFrom); @@ -200,6 +200,7 @@ this.Controls.Add(this.groupBoxQuickSetup); this.Controls.Add(this.buttonOK); this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(536, 418); this.Name = "ExternalChannels"; this.ShowIcon = false; this.ShowInTaskbar = false; Modified: trunk/plugins/TV3ExtChannelChanger/Forms/PluginSetup.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/Forms/PluginSetup.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/Forms/PluginSetup.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -56,8 +56,7 @@ { Log.Info("TV3ExtChannelChanger: Configuration activated"); - if (TV3ExtChannelChanger.ExternalChannelConfigs == null) - TV3ExtChannelChanger.LoadExternalConfigs(); + TV3ExtChannelChanger.LoadExternalConfigs(); base.OnSectionActivated(); } @@ -66,8 +65,15 @@ private void buttonSTB_Click(object sender, EventArgs e) { - ExternalChannels externalChannels = new ExternalChannels(); - externalChannels.ShowDialog(this); + if (TvDatabase.Card.ListAll().Count == 0) + { + MessageBox.Show(this, "There are no capture cards installed in the TV server", "No TV Cards", MessageBoxButtons.OK, MessageBoxIcon.Stop); + } + else + { + ExternalChannels externalChannels = new ExternalChannels(); + externalChannels.ShowDialog(this); + } } } Modified: trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.Designer.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.Designer.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.Designer.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -46,6 +46,7 @@ this.listViewExternalCommands = new System.Windows.Forms.ListView(); this.columnHeaderExternal = new System.Windows.Forms.ColumnHeader(); this.columnHeaderCommand = new System.Windows.Forms.ColumnHeader(); + this.labelCardName = new System.Windows.Forms.Label(); this.groupBoxOptions.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRepeatDelay)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPauseTime)).BeginInit(); @@ -68,7 +69,7 @@ this.groupBoxOptions.Controls.Add(this.checkBoxDoubleSelect); this.groupBoxOptions.Controls.Add(this.labelMS); this.groupBoxOptions.Controls.Add(this.checkBoxSendSelect); - this.groupBoxOptions.Location = new System.Drawing.Point(296, 8); + this.groupBoxOptions.Location = new System.Drawing.Point(296, 16); this.groupBoxOptions.Name = "groupBoxOptions"; this.groupBoxOptions.Size = new System.Drawing.Size(200, 240); this.groupBoxOptions.TabIndex = 1; @@ -221,7 +222,7 @@ this.groupBoxCommands.Controls.Add(this.buttonSet); this.groupBoxCommands.Controls.Add(this.comboBoxCommands); this.groupBoxCommands.Controls.Add(this.listViewExternalCommands); - this.groupBoxCommands.Location = new System.Drawing.Point(8, 8); + this.groupBoxCommands.Location = new System.Drawing.Point(8, 16); this.groupBoxCommands.Name = "groupBoxCommands"; this.groupBoxCommands.Size = new System.Drawing.Size(280, 240); this.groupBoxCommands.TabIndex = 0; @@ -280,14 +281,27 @@ this.columnHeaderCommand.Text = "Command"; this.columnHeaderCommand.Width = 170; // + // labelCardName + // + this.labelCardName.Dock = System.Windows.Forms.DockStyle.Top; + this.labelCardName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.labelCardName.Location = new System.Drawing.Point(0, 0); + this.labelCardName.Name = "labelCardName"; + this.labelCardName.Size = new System.Drawing.Size(504, 16); + this.labelCardName.TabIndex = 2; + this.labelCardName.Text = "Unknown TV Card"; + this.labelCardName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // StbSetup // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.labelCardName); this.Controls.Add(this.groupBoxOptions); this.Controls.Add(this.groupBoxCommands); + this.MinimumSize = new System.Drawing.Size(504, 262); this.Name = "StbSetup"; - this.Size = new System.Drawing.Size(504, 254); + this.Size = new System.Drawing.Size(504, 262); this.groupBoxOptions.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRepeatDelay)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPauseTime)).EndInit(); @@ -317,5 +331,6 @@ private System.Windows.Forms.ListView listViewExternalCommands; private System.Windows.Forms.ColumnHeader columnHeaderExternal; private System.Windows.Forms.ColumnHeader columnHeaderCommand; + private System.Windows.Forms.Label labelCardName; } } Modified: trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -16,8 +16,27 @@ public partial class StbSetup : UserControl { + #region Constants + + const string parameterInfo = +@"%1 = Current channel number digit (-1 for Select/Pre-Change) +%2 = Full channel number string"; + + #endregion Constants + + #region Variables + + int _cardId; + + #endregion Variables + #region Properties + public int CardId + { + get { return _cardId; } + } + public int PauseTime { get { return Decimal.ToInt32(numericUpDownPauseTime.Value); } @@ -74,25 +93,25 @@ #endregion Properties - #region Variables - - const string parameterInfo = -@"%1 = Current channel number digit (-1 for Select/Pre-Change) -%2 = Full channel number string -%3 = Blaster port (0 = Both, 1 = Port 1, 2 = Port 2)"; - - int _card; - - #endregion Variables - #region Constructor - public StbSetup(int card) + public StbSetup(int cardId) { InitializeComponent(); - _card = card; + _cardId = cardId; + foreach (TvDatabase.Card card in TvDatabase.Card.ListAll()) + { + if (card.IdCard == _cardId) + { + labelCardName.Text = card.Name; + if (!card.Enabled) + labelCardName.Text += " (Disabled)"; + break; + } + } + // Setup commands combo box comboBoxCommands.Items.Add("Run Program"); comboBoxCommands.Items.Add("Serial Command"); @@ -121,17 +140,20 @@ item = new ListViewItem(subItems); listViewExternalCommands.Items.Add(item); - SetToCard(_card); + SetToCard(_cardId); } #endregion Constructor #region Public Methods - public void SetToCard(int card) + public void SetToCard(int cardId) { - ExternalChannelConfig config = TV3ExtChannelChanger.ExternalChannelConfigs[card]; + ExternalChannelConfig config = TV3ExtChannelChanger.GetExternalChannelConfig(cardId); + if (config == null) + return; + // Setup command list. for (int i = 0; i < 10; i++) listViewExternalCommands.Items[i].SubItems[1].Text = config.Digits[i]; @@ -158,10 +180,12 @@ numericUpDownRepeatDelay.Value = new Decimal(config.RepeatPauseTime); } - public void SetToConfig(int card) + public void SetToConfig(int cardId) { - ExternalChannelConfig config = TV3ExtChannelChanger.ExternalChannelConfigs[card]; + ExternalChannelConfig config = TV3ExtChannelChanger.GetExternalChannelConfig(cardId); + config.CardId = cardId; + config.PauseTime = Decimal.ToInt32(numericUpDownPauseTime.Value); config.SendSelect = checkBoxSendSelect.Checked; config.DoubleChannelSelect = checkBoxDoubleSelect.Checked; @@ -247,7 +271,7 @@ public void Save() { - SetToConfig(_card); + SetToConfig(_cardId); } #endregion Public Methods Modified: trunk/plugins/TV3ExtChannelChanger/TV3ExtChannelChanger.cs =================================================================== --- trunk/plugins/TV3ExtChannelChanger/TV3ExtChannelChanger.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3ExtChannelChanger/TV3ExtChannelChanger.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -24,9 +24,7 @@ #region Constants - public static readonly string AppDataFolder = - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + - "\\MediaPortal TV Server\\"; + public const string PluginVersion = "TV3 Ext Channel Changer Plugin 1.0.2.0"; public const string STBFolder = "STB\\"; @@ -35,6 +33,10 @@ public const string KeyCommandPrefix = "Keys: "; public const string MessageCommandPrefix = "Message: "; + public static readonly string AppDataFolder = + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + + "\\MediaPortal TV Server\\"; + #endregion Constants #region Variables @@ -85,11 +87,6 @@ set { _logVerbose = value; } } - public static ExternalChannelConfig[] ExternalChannelConfigs - { - get { return _externalChannelConfigs; } - } - #endregion Properties #region Plugin methods @@ -97,8 +94,10 @@ [CLSCompliant(false)] public void Start(IController controller) { - Log.Info("TV3ExtChannelChanger: Version {0}", Version); + Log.Info("TV3ExtChannelChanger: Version {0}", PluginVersion); + Log.Debug("TV3ExtChannelChanger: Platform is {0}", (IntPtr.Size == 4 ? "32-bit" : "64-bit")); + TvBusinessLayer layer = new TvBusinessLayer(); LogVerbose = Convert.ToBoolean(layer.GetSetting("TV3ExtChannelChangerLogVerbose", "False").Value); @@ -118,12 +117,7 @@ [CLSCompliant(false)] public SetupTv.SectionSettings Setup { - get - { - LoadExternalConfigs(); - - return new SetupTv.Sections.PluginSetup(); - } + get { return new SetupTv.Sections.PluginSetup(); } } #endregion Plugin methods @@ -147,13 +141,13 @@ } } - static bool ProcessExternalChannel(string externalChannel, int card) + static bool ProcessExternalChannel(string externalChannel, int cardId) { bool returnCode = true; try { - ExternalChannelConfig config = ExternalChannelConfigs[card - 1]; + ExternalChannelConfig config = GetExternalChannelConfig(cardId); // Clean up the "externalChannel" string into "channel". StringBuilder channel = new StringBuilder(); @@ -362,18 +356,38 @@ /// </summary> public static void LoadExternalConfigs() { - int cardCount = TvDatabase.Card.ListAll().Count; + IList cards = TvDatabase.Card.ListAll(); - if (cardCount == 0) - cardCount = 1; + if (cards.Count == 0) + return; - _externalChannelConfigs = new ExternalChannelConfig[cardCount]; + _externalChannelConfigs = new ExternalChannelConfig[cards.Count]; - for (int index = 0; index < cardCount; index++) - ExternalChannelConfigs[index] = new ExternalChannelConfig(AppDataFolder + "ExternalChannelConfig" + (index + 1).ToString() + ".xml"); + int index = 0; + foreach (TvDatabase.Card card in cards) + { + _externalChannelConfigs[index++] = new ExternalChannelConfig(card.IdCard, string.Format("{0}ExternalChannelConfig{1}.xml", AppDataFolder, card.IdCard)); + } } /// <summary> + /// Given a card ID returns the configuration for that card. + /// </summary> + /// <param name="cardId">ID of card to retreive configuration for.</param> + /// <returns>Card configuration, null if it doesn't exist.</returns> + public static ExternalChannelConfig GetExternalChannelConfig(int cardId) + { + if (_externalChannelConfigs == null) + return null; + + foreach (ExternalChannelConfig config in _externalChannelConfigs) + if (config.CardId == cardId) + return config; + + return null; + } + + /// <summary> /// Splits a Run command into it's component parts. /// </summary> /// <param name="runCommand">The command to be split</param> Modified: trunk/plugins/TV3MceBlaster/Forms/PluginSetup.Designer.cs =================================================================== --- trunk/plugins/TV3MceBlaster/Forms/PluginSetup.Designer.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3MceBlaster/Forms/PluginSetup.Designer.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -1,5 +1,6 @@ namespace SetupTv.Sections { + partial class PluginSetup { /// <summary> Modified: trunk/plugins/TV3MceBlaster/Forms/StbSetup.Designer.cs =================================================================== --- trunk/plugins/TV3MceBlaster/Forms/StbSetup.Designer.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3MceBlaster/Forms/StbSetup.Designer.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -343,7 +343,7 @@ this.Controls.Add(this.labelCardName); this.Controls.Add(this.groupBoxOptions); this.Controls.Add(this.groupBoxCommands); - this.MinimumSize = new System.Drawing.Size(504, 310); + this.MinimumSize = new System.Drawing.Size(504, 318); this.Name = "StbSetup"; this.Size = new System.Drawing.Size(504, 318); this.groupBoxOptions.ResumeLayout(false); Modified: trunk/plugins/TV3MceBlaster/TV3MceBlaster.cs =================================================================== --- trunk/plugins/TV3MceBlaster/TV3MceBlaster.cs 2007-02-14 14:00:52 UTC (rev 118) +++ trunk/plugins/TV3MceBlaster/TV3MceBlaster.cs 2007-02-15 03:39:19 UTC (rev 119) @@ -24,8 +24,10 @@ #region Constants - public const int LearnTimeout = 4000; // Milliseconds + public const string PluginVersion = "TV3 MCE Blaster Plugin 1.0.2.0"; + public const int LearnIRTimeout = 4000; // Milliseconds + public const string IRFolder = "IR\\"; public const string MacroFolder = "MACRO\\"; public const string STBFolder = "STB\\"; @@ -118,7 +120,7 @@ [CLSCompliant(false)] public void Start(IController controller) { - Log.Info("TV3MceBlaster: Version {0}", Version); + Log.Info("TV3MceBlaster: Version {0}", PluginVersion); Log.Debug("TV3MceBlaster: Platform is {0}", (IntPtr.Size == 4 ? "32-bit" : "64-bit")); @@ -337,55 +339,52 @@ return ProcessSerialCommand(commands); } - static bool BlastIR(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) - { - FileStream file = null; + #endregion Private Methods - try - { - file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + #region Public Methods - if (file.Length == 0) - { - Log.Error("TV3MceBlaster: IR file \"{0}\" has no data, possible IR learn failure", fileName); - file.Close(); - return false; - } + /// <summary> + /// Load external channel configurations. + /// </summary> + public static void LoadExternalConfigs() + { + IList cards = TvDatabase.Card.ListAll(); - if (!MceIrApi.CheckFile(file.SafeFileHandle)) - { - Log.Error("TV3MceBlaster: Bad IR file \"{0}\"", fileName); - file.Close(); - return false; - } + if (cards.Count == 0) + return; - MceIrApi.SelectBlaster(port); - MceIrApi.SetBlasterSpeed(speed); - MceIrApi.SetBlasterType(BlastType); + _externalChannelConfigs = new ExternalChannelConfig[cards.Count]; - if (MceIrApi.PlaybackFromFile(file.SafeFileHandle)) - { - if (LogVerbose) - Log.Info("TV3MceBlaster: Blast successful"); - - file.Close(); - return true; - } - } - catch (Exception ex) + int index = 0; + foreach (TvDatabase.Card card in cards) { - Log.Error("TV3MceBlaster: BlastIR() {0}", ex.Message); + _externalChannelConfigs[index++] = new ExternalChannelConfig(card.IdCard, string.Format("{0}ExternalChannelConfig{1}.xml", AppDataFolder, card.IdCard)); } + } - Log.Error("TV3MceBlaster: Failed to blast IR file \"{0}\"", fileName); + /// <summary> + /// Given a card ID returns the configuration for that card. + /// </summary> + /// <param name="cardId">ID of card to retreive configuration for.</param> + /// <returns>Card configuration, null if it doesn't exist.</returns> + public static ExternalChannelConfig GetExternalChannelConfig(int cardId) + { + if (_externalChannelConfigs == null) + return null; - if (file != null) - file.Close(); + foreach (ExternalChannelConfig config in _externalChannelConfigs) + if (config.CardId == cardId) + return config; - return false; + return null; } - static bool ProcessMacro(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) + /// <summary> + /// Process the supplied Macro file. + /// </summary> + /// <param name="fileName">Macro file to process.</param> + /// <returns>Sucess.</returns> + public static bool ProcessMacro(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { FileStream file = null; @@ -525,44 +524,59 @@ return true; } - #endregion Private Methods - - #region Public Methods - /// <summary> - /// Load external channel configurations. + /// Blast an IR command. /// </summary> - public static void LoadExternalConfigs() + /// <param name="fileName">File to blast.</param> + /// <param name="port">Port to blast to.</param> + /// <param name="speed">Speed to blast at.</param> + /// <returns>Success.</returns> + public static bool BlastIR(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { - IList cards = TvDatabase.Card.ListAll(); + FileStream file = null; - if (cards.Count == 0) - return; + try + { + file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); - _externalChannelConfigs = new ExternalChannelConfig[cards.Count]; + if (file.Length == 0) + { + Log.Error("TV3MceBlaster: IR file \"{0}\" has no data, possible IR learn failure", fileName); + file.Close(); + return false; + } - int index = 0; - foreach (TvDatabase.Card card in cards) + if (!MceIrApi.CheckFile(file.SafeFileHandle)) + { + Log.Error("TV3MceBlaster: Bad IR file \"{0}\"", fileName); + file.Close(); + return false; + } + + MceIrApi.SelectBlaster(port); + MceIrApi.SetBlasterSpeed(speed); + MceIrApi.SetBlasterType(BlastType); + + if (MceIrApi.PlaybackFromFile(file.SafeFileHandle)) + { + if (LogVerbose) + Log.Info("TV3MceBlaster: Blast successful"); + + file.Close(); + return true; + } + } + catch (Exception ex) { - _externalChannelConfigs[index++] = new ExternalChannelConfig(card.IdCard, string.Format("{0}ExternalChannelConfig{1}.xml", AppDataFolder, card.IdCard)); + Log.Error("TV3MceBlaster: BlastIR() {0}", ex.Message); } - } - /// <summary> - /// Given a card ID returns the configuration for that card. - /// </summary> - /// <param name="cardId">ID of card to retreive configuration for.</param> - /// <returns>Card configuration, null if it doesn't exist.</returns> - public static ExternalChannelConfig GetExternalChannelConfig(int cardId) - { - if (_externalChannelConfigs == null) - return null; + Log.Error("TV3MceBlaster: Failed to blast IR file \"{0}\"", fileName); - foreach (ExternalChannelConfig config in _externalChannelConfigs) - if (config.CardId == cardId) - return config; + if (file != null) + file.Close(); - return null; + return false; } /// <summary> @@ -938,20 +952,22 @@ } /// <summary> - /// Learn an IR code and put it in a file + /// Learn an IR Command and put it in a file /// </summary> - /// <param name="blastCommand">File to learn</param> - /// <returns>bool value shows success</returns> - public static bool LearnIRCommand(string blastCommand) + /// <param name="fileName">File to place learned IR command in.</param> + /// <returns>Success.</returns> + public static bool LearnIRCommand(string fileName) { - string fileName = AppDataFolder + blastCommand + IRExtension; + string filePath = AppDataFolder + fileName + IRExtension; FileStream file = null; bool status = false; try { - file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read); - status = MceIrApi.RecordToFile(file.SafeFileHandle, LearnTimeout); + file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); + status = MceIrApi.RecordToFile(file.SafeFileHandle, LearnIRTimeout); + if (file.Length == 0) + status = false; } catch (Exception ex) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |