2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
34 using System.ComponentModel;
35 using System.Diagnostics;
38 using System.Windows.Forms;
39 using LibCECTray.Properties;
40 using LibCECTray.settings;
43 namespace LibCECTray.controller.applications
45 partial class ConfigureApplication : Form
47 public ConfigureApplication(ApplicationController controller) :
50 _controller = controller;
51 tbFilename.Text = controller.ApplicationFilename;
52 tbWorkingDir.Text = controller.ApplicationWorkingDirectory;
53 tbUiName.Text = controller.UiName;
54 tbProcessName.Text = controller.ProcessName;
56 Text = string.Format(Resources.configure_application, controller.UiName);
58 if (!_controller.CanConfigureProcess)
60 tbFilename.Enabled = false;
61 tbWorkingDir.Enabled = false;
62 tbUiName.Enabled = false;
63 tbProcessName.Enabled = false;
64 bFindFile.Enabled = false;
68 public override sealed string Text
70 get { return base.Text; }
71 set { base.Text = value; }
74 public ConfigureApplication(CECSettings settings, CECController controller)
76 _cecController = controller;
78 InitializeComponent();
80 // take the icon of the main window
81 ComponentResourceManager resources = new ComponentResourceManager(typeof(CECTray));
82 Icon = resources.GetObject("$this.Icon") as Icon;
84 Text = Resources.add_new_application;
87 private void BFindFileClick(object sender, EventArgs e)
89 OpenFileDialog dialog = new OpenFileDialog
91 Title = Resources.select_exe_file,
92 InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
93 Filter = Resources.exe_file_filter,
97 if (dialog.ShowDialog() != DialogResult.OK) return;
99 var fileName = dialog.SafeFileName;
100 if (fileName != null && File.Exists(dialog.FileName))
102 var versionInfo = FileVersionInfo.GetVersionInfo(dialog.FileName);
103 var path = dialog.FileName.Substring(0, dialog.FileName.Length - fileName.Length);
104 if (path.EndsWith("\\"))
105 path = path.Substring(0, path.Length - 1);
107 tbFilename.Text = fileName;
108 tbWorkingDir.Text = path;
109 tbUiName.Text = versionInfo.FileDescription;
110 tbProcessName.Text = fileName;
111 Text = string.Format(Resources.configure_application, versionInfo.FileDescription);
115 tbFilename.Text = string.Empty;
116 tbWorkingDir.Text = string.Empty;
117 tbUiName.Text = string.Empty;
118 tbProcessName.Text = string.Empty;
119 Text = Resources.add_new_application;
123 private void BOkClick(object sender, EventArgs e)
125 if (_controller != null)
127 _controller.ApplicationFilename = tbFilename.Text;
128 _controller.ApplicationWorkingDirectory = tbWorkingDir.Text;
129 _controller.UiName = tbUiName.Text;
130 _controller.ProcessName = tbProcessName.Text;
131 _controller.Settings.Persist();
133 else if (_cecController != null)
135 ApplicationController newController = new ApplicationController(_cecController, tbUiName.Text, tbProcessName.Text, tbFilename.Text, tbWorkingDir.Text);
136 if (_cecController.RegisterApplication(newController))
137 newController.Settings.Persist();
142 private void BCancelClick(object sender, EventArgs e)
148 private readonly ApplicationController _controller;
149 private readonly CECController _cecController;
150 private readonly CECSettings _settings;