From: <an...@us...> - 2007-03-09 03:23:19
|
Revision: 168 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=168&view=rev Author: and-81 Date: 2007-03-08 19:23:17 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/ComSkipLauncher/ComSkipLauncher.cs trunk/plugins/ComSkipLauncher/ComSkipLauncher.csproj Modified: trunk/plugins/ComSkipLauncher/ComSkipLauncher.cs =================================================================== --- trunk/plugins/ComSkipLauncher/ComSkipLauncher.cs 2007-03-08 05:17:49 UTC (rev 167) +++ trunk/plugins/ComSkipLauncher/ComSkipLauncher.cs 2007-03-09 03:23:17 UTC (rev 168) @@ -5,19 +5,28 @@ using System.Text; using System.Windows.Forms; +using MediaPortal.Configuration; using MediaPortal.GUI.Library; using MediaPortal.TV.Database; using MediaPortal.TV.Recording; +using MediaPortal.Util; namespace MediaPortal.Plugins { - public class ComSkipLauncher : ISetupForm + public class ComSkipLauncher : IPlugin, ISetupForm { + #region Constants + + public static readonly string MPConfigFile = Config.GetFolder(Config.Dir.Config) + "\\MediaPortal.xml"; + + #endregion Constants + #region Members - string _comSkipPath = "C:\\ComSkip\\ComSkip.exe"; + string _program; + string _parameters; #endregion Members @@ -25,11 +34,15 @@ public void Start() { + Log.Info("ComSkipLauncher: Start"); + LoadSettings(); Recorder.OnTvRecordingEnded += new MediaPortal.TV.Recording.Recorder.OnTvRecordingHandler(Recorder_OnTvRecordingEnded); } public void Stop() { + Log.Info("ComSkipLauncher: Stop"); + Recorder.OnTvRecordingEnded -= new MediaPortal.TV.Recording.Recorder.OnTvRecordingHandler(Recorder_OnTvRecordingEnded); } @@ -47,7 +60,16 @@ public void ShowPlugin() { - // TODO: Configuration + LoadSettings(); + + ExternalProgram externalProgram = new ExternalProgram(_program, _parameters); + if (externalProgram.ShowDialog() == DialogResult.OK) + { + _program = externalProgram.Program; + _parameters = externalProgram.Parameters; + + SaveSettings(); + } } public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) @@ -62,25 +84,108 @@ void Recorder_OnTvRecordingEnded(string recordingFilename, TVRecording recording, TVProgram program) { - Process comskip = new Process(); - comskip.StartInfo = new ProcessStartInfo(); - comskip.StartInfo.Arguments = string.Format("--playnice --zpcut {0}", recordingFilename); - comskip.StartInfo.CreateNoWindow = true; - comskip.StartInfo.FileName = _comSkipPath; - //comskip.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - comskip.StartInfo.WorkingDirectory = Path.GetDirectoryName(recordingFilename); + Log.Debug("ComSkipLauncher: Recorder_OnTvRecordingEnded {0}", recordingFilename); - comskip.Start(); + try + { + string fileName = String.Empty; + List<TVRecorded> recorded = new List<TVRecorded>(); + TVDatabase.GetRecordedTV(ref recorded); + foreach (TVRecorded rec in recorded) + { + if (rec.Title == recording.Title && rec.StartTime == recording.StartTime) + { + fileName = rec.FileName; + break; + } + } - comskip.WaitForExit(); + if (String.IsNullOrEmpty(fileName)) + { + Log.Warn("ComSkipLauncher: Couldn't process recording titled {0}, no filename found.", recording.Title); + return; + } + + string parameters = ProcessParameters(_parameters, fileName); + + Log.Info( + "ComSkipLauncher: Recording ended ({0}), launching program ({1} {2}) ...", + fileName, + _program, + parameters + ); + + Process comskip = new Process(); + comskip.StartInfo = new ProcessStartInfo(); + comskip.StartInfo.Arguments = parameters; + comskip.StartInfo.FileName = _program; + comskip.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + comskip.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName); + + comskip.Start(); + } + catch (Exception ex) + { + Log.Error("ComSkipLauncher: {0}", ex.Message); + } } void LoadSettings() { + try + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(MPConfigFile)) + { + _program = xmlreader.GetValueAsString("ComSkipLauncher", "Program", "C:\\ComSkip\\ComSkip.exe"); + _parameters = xmlreader.GetValueAsString("ComSkipLauncher", "Parameters", "--playnice --zpcut \"{0}\""); + } + } + catch (Exception ex) + { + Log.Error("ComSkipLauncher: {0}", ex.Message); + } + } + void SaveSettings() + { + try + { + using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(MPConfigFile)) + { + xmlwriter.SetValue("ComSkipLauncher", "Program", _program); + xmlwriter.SetValue("ComSkipLauncher", "Parameters", _parameters); + } + } + catch (Exception ex) + { + Log.Error("ComSkipLauncher: {0}", ex.Message); + } } + internal static string ProcessParameters(string input, string fileName) + { + string output = String.Empty; + try + { + output = string.Format( + input, // Format + fileName, // {0} = Recorded filename (includes path) + Path.GetFileName(fileName), // {1} = Recorded filename (w/o path) + Path.GetFileNameWithoutExtension(fileName), // {2} = Recorded filename (w/o path or extension) + Path.GetDirectoryName(fileName), // {3} = Recorded file path + DateTime.Now.ToShortDateString(), // {4} = Current date + DateTime.Now.ToShortTimeString() // {5} = Current time + ); + } + catch (Exception ex) + { + Log.Error("ComSkipLauncher: {0}", ex.Message); + } + + return output; + } + #endregion Implementation } Modified: trunk/plugins/ComSkipLauncher/ComSkipLauncher.csproj =================================================================== --- trunk/plugins/ComSkipLauncher/ComSkipLauncher.csproj 2007-03-08 05:17:49 UTC (rev 167) +++ trunk/plugins/ComSkipLauncher/ComSkipLauncher.csproj 2007-03-09 03:23:17 UTC (rev 168) @@ -43,6 +43,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> <Reference Include="TVCapture, Version=1.0.2623.6917, Culture=neutral, processorArchitecture=x86"> @@ -50,11 +51,28 @@ <HintPath>..\..\MediaPortal\xbmc\bin\Release\TVCapture.dll</HintPath> <Private>False</Private> </Reference> + <Reference Include="Utils, Version=1.0.2622.31921, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.dll</HintPath> + <Private>False</Private> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="ComSkipLauncher.cs" /> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="ExternalProgram.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="ExternalProgram.Designer.cs"> + <DependentUpon>ExternalProgram.cs</DependentUpon> + </Compile> </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="ExternalProgram.resx"> + <DependentUpon>ExternalProgram.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |