Esempio n. 1
0
 public static void ReadFromConfigFile()
 {
     Ares.Settings.Settings settings = Ares.Settings.Settings.Instance;
     try
     {
         using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "aresplugin.xml")))
         {
             settings.RecentFiles.AddFile(new Settings.RecentFiles.ProjectEntry(reader.GetValue("Files", "ProjectFile"), ""));
             settings.SoundDirectory  = reader.GetValue("Directories", "SoundsDirectory");
             settings.MusicDirectory  = reader.GetValue("Directories", "MusicDirectory");
             settings.UdpPort         = reader.GetValueAsInt("Network", "UDPPort", 8009);
             settings.TcpPort         = reader.GetValueAsInt("Network", "TCPPort", 11112);
             settings.IPAddress       = reader.GetValue("Network", "IPAddress");
             settings.GlobalVolume    = reader.GetValueAsInt("Volume", "Global", 100);
             settings.MusicVolume     = reader.GetValueAsInt("Volume", "Music", 100);
             settings.SoundVolume     = reader.GetValueAsInt("Volume", "Sounds", 100);
             settings.LocalPlayerPath = reader.GetValue("Files", "LocalPlayerPath");
         }
     }
     catch (Exception)
     {
     }
 }
Esempio n. 2
0
        public SetupForm()
        {
            InitializeComponent();
            labelDefaultPort.Text = String.Format("(Default: {0})", WifiRemote.DEFAULT_PORT);

            // load port from settings
            using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                originalPort = reader.GetValue(WifiRemote.PLUGIN_NAME, "port");
                checkBoxDisableBonjour.Checked = reader.GetValueAsBool(WifiRemote.PLUGIN_NAME, "disableBonjour", false);
                textBoxName.Text = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "serviceName", WifiRemote.GetServiceName());
                checkBoxShowConnectionMessage.Checked = reader.GetValueAsBool(WifiRemote.PLUGIN_NAME, "showNotifications", false);

                txtUsername.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "username", ""));
                txtPassword.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "password", ""));
                txtPasscode.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "passcode", ""));

                cbAuthMethod.SelectedIndex = reader.GetValueAsInt(WifiRemote.PLUGIN_NAME, "auth", 0);
                numericUpDownAutologin.Value = reader.GetValueAsInt(WifiRemote.PLUGIN_NAME, "autologinTimeout", 0);

                resetPort();

                // Read plugin ids and convert them to int
                String[] savedPluginStrings = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "savedPlugins", "").Split('|');
                savedPlugins = new Dictionary<int, string>();

                for (int j = 0; j + 1 < savedPluginStrings.Length; j = j + 2)
                {
                    // Add plugin id and name
                    int i;
                    if (int.TryParse(savedPluginStrings[j], out i))
                    {
                        savedPlugins.Add(i, savedPluginStrings[j + 1]);
                    }
                }

                // Read ignored plugins
                // Ignored by default:
                //     -1:
                //      0: home
                //   3005: GUITopbar
                // 730716: fanart handler
                String[] ignoredPluginsString = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "ignoredPlugins", "-1|0|3005|730716").Split('|');
                ignoredPluginsList = new List<int>();

                foreach (String pluginId in ignoredPluginsString)
                {
                    int i;
                    if (int.TryParse(pluginId, out i))
                    {
                        ignoredPluginsList.Add(i);
                    }
                }

            }

            // Test if Bonjour is installed
            try
            {
                Version bonjourVersion = ZeroconfService.NetService.DaemonVersion;
                buttonDownloadBonjour.Enabled = false;
                checkBoxDisableBonjour.Enabled = false;
                buttonDownloadBonjour.Text = "Bonjour already installed";
            }
            catch
            {
                if (Is64Bit() || Is32BitProcessOn64BitProcessor())
                {
                    // 64 bit windows
                    is64bit = true;
                    buttonDownloadBonjour.Enabled = true;
                    checkBoxDisableBonjour.Enabled = true;
                    buttonDownloadBonjour.Text = "Download and install Bonjour (64 bit)";
                }
                else
                {
                    // 32 bit windows
                    is64bit = false;
                    buttonDownloadBonjour.Enabled = true;
                    checkBoxDisableBonjour.Enabled = true;
                    buttonDownloadBonjour.Text = "Download and install Bonjour (32 bit)";
                }
            }

            // Setup plugins list
            availablePlugins = new ArrayList();
            plugins = new ArrayList();
            pluginIcons = new ImageList();
            pluginIcons.ImageSize = new Size(20, 20);

            EnumerateWindowPlugins();
            LoadPlugins();
            LoadSettings();

            // Add saved plugins to list for ordering
            foreach (var aSavedPlugin in savedPlugins)
            {
                // Find saved plugin with this window id
                var query = from ItemTag p in plugins
                            where p.WindowId == aSavedPlugin.Key
                            select p;

                // Add the first found plugin to the list
                foreach (ItemTag plugin in query)
                {
                    if (plugin.IsEnabled)
                    {
                        pluginsDataSource.Add(new WindowPlugin(aSavedPlugin.Value,
                                                               aSavedPlugin.Key,
                                                               (plugin.ActiveImage != null)
                                                                    ? ImageHelper.imageToByteArray(plugin.ActiveImage, System.Drawing.Imaging.ImageFormat.Png)
                                                                    : ImageHelper.imageToByteArray(Properties.Resources.NoPluginImage, System.Drawing.Imaging.ImageFormat.Png),
                                                               !ignoredPluginsList.Contains(aSavedPlugin.Key)));
                    }
                    break;
                }
            }

            // Add rest of the plugins to the list
            foreach (ItemTag plugin in plugins)
            {
                if (!savedPlugins.ContainsKey(plugin.WindowId))
                {
                    addPluginToList(plugin);
                }
            }

            dataGridViewPluginList.AutoGenerateColumns = false;
            dataGridViewPluginList.AutoSize = true;
            dataGridViewPluginList.DataSource = pluginsDataSource;
            dataGridViewPluginList.CurrentCellDirtyStateChanged += new EventHandler(dataGridViewPluginList_CurrentCellDirtyStateChanged);

            DataGridViewCheckBoxColumn displayColumn = new DataGridViewCheckBoxColumn();
            displayColumn.ReadOnly = false;
            displayColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
            displayColumn.DataPropertyName = "DisplayPlugin";
            displayColumn.Name = "";
            dataGridViewPluginList.Columns.Add(displayColumn);

            DataGridViewImageColumn iconColumn = new DataGridViewImageColumn(false);
            iconColumn.ReadOnly = true;
            iconColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;
            iconColumn.Width = 20;
            iconColumn.DataPropertyName = "Icon";
            iconColumn.Name = "";
            dataGridViewPluginList.Columns.Add(iconColumn);

            DataGridViewColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.ReadOnly = false;
            nameColumn.MinimumWidth = 200;
            nameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            nameColumn.DataPropertyName = "Name";
            nameColumn.Name = "Plugin";
            dataGridViewPluginList.Columns.Add(nameColumn);
        }
Esempio n. 3
0
        public SetupForm()
        {
            InitializeComponent();
            labelDefaultPort.Text = String.Format("(Default: {0})", WifiRemote.DEFAULT_PORT);

            // load port from settings
            using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                originalPort = reader.GetValue(WifiRemote.PLUGIN_NAME, "port");
                checkBoxDisableBonjour.Checked = reader.GetValueAsBool(WifiRemote.PLUGIN_NAME, "disableBonjour", false);
                textBoxName.Text = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "serviceName", WifiRemote.GetServiceName());
                checkBoxShowConnectionMessage.Checked = reader.GetValueAsBool(WifiRemote.PLUGIN_NAME, "showNotifications", false);

                txtUsername.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "username", ""));
                txtPassword.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "password", ""));
                txtPasscode.Text = WifiRemote.DecryptString(reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "passcode", ""));

                cbAuthMethod.SelectedIndex   = reader.GetValueAsInt(WifiRemote.PLUGIN_NAME, "auth", 0);
                numericUpDownAutologin.Value = reader.GetValueAsInt(WifiRemote.PLUGIN_NAME, "autologinTimeout", 0);



                resetPort();

                // Read plugin ids and convert them to int
                String[] savedPluginStrings = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "savedPlugins", "").Split('|');
                savedPlugins = new Dictionary <int, string>();

                for (int j = 0; j + 1 < savedPluginStrings.Length; j = j + 2)
                {
                    // Add plugin id and name
                    int i;
                    if (int.TryParse(savedPluginStrings[j], out i))
                    {
                        try
                        {
                            savedPlugins.Add(i, savedPluginStrings[j + 1]);
                        }
                        catch (Exception e)
                        {
                            WifiRemote.LogMessage("Adding saved plugin from config failed: " + e.Message, WifiRemote.LogType.Debug);
                        }
                    }
                }

                // Read ignored plugins
                // Ignored by default:
                //     -1:
                //      0: home
                //   3005: GUITopbar
                // 730716: fanart handler
                String[] ignoredPluginsString = reader.GetValueAsString(WifiRemote.PLUGIN_NAME, "ignoredPlugins", "-1|0|3005|730716").Split('|');
                ignoredPluginsList = new List <int>();

                foreach (String pluginId in ignoredPluginsString)
                {
                    int i;
                    if (int.TryParse(pluginId, out i))
                    {
                        try
                        {
                            ignoredPluginsList.Add(i);
                        }
                        catch (Exception e)
                        {
                            WifiRemote.LogMessage("Adding ignored plugin from config failed: " + e.Message, WifiRemote.LogType.Debug);
                        }
                    }
                }
            }

            // Test if Bonjour is installed
            try
            {
                Version bonjourVersion = ZeroconfService.NetService.DaemonVersion;
                buttonDownloadBonjour.Enabled  = false;
                checkBoxDisableBonjour.Enabled = false;
                buttonDownloadBonjour.Text     = "Bonjour already installed";
            }
            catch
            {
                if (Is64Bit() || Is32BitProcessOn64BitProcessor())
                {
                    // 64 bit windows
                    is64bit = true;
                    buttonDownloadBonjour.Enabled  = true;
                    checkBoxDisableBonjour.Enabled = true;
                    buttonDownloadBonjour.Text     = "Download and install Bonjour (64 bit)";
                }
                else
                {
                    // 32 bit windows
                    is64bit = false;
                    buttonDownloadBonjour.Enabled  = true;
                    checkBoxDisableBonjour.Enabled = true;
                    buttonDownloadBonjour.Text     = "Download and install Bonjour (32 bit)";
                }
            }

            // Setup plugins list
            availablePlugins      = new ArrayList();
            plugins               = new ArrayList();
            pluginIcons           = new ImageList();
            pluginIcons.ImageSize = new Size(20, 20);

            EnumerateWindowPlugins();
            LoadPlugins();
            LoadSettings();

            // Add saved plugins to list for ordering
            foreach (var aSavedPlugin in savedPlugins)
            {
                // Find saved plugin with this window id
                var query = from ItemTag p in plugins
                            where p.WindowId == aSavedPlugin.Key
                            select p;

                // Add the first found plugin to the list
                foreach (ItemTag plugin in query)
                {
                    if (plugin.IsEnabled)
                    {
                        pluginsDataSource.Add(new WindowPlugin(aSavedPlugin.Value,
                                                               aSavedPlugin.Key,
                                                               (plugin.ActiveImage != null)
                                                                    ? ImageHelper.imageToByteArray(plugin.ActiveImage, System.Drawing.Imaging.ImageFormat.Png)
                                                                    : ImageHelper.imageToByteArray(Properties.Resources.NoPluginImage, System.Drawing.Imaging.ImageFormat.Png),
                                                               !ignoredPluginsList.Contains(aSavedPlugin.Key)));
                    }
                    break;
                }
            }

            // Add rest of the plugins to the list
            foreach (ItemTag plugin in plugins)
            {
                if (!savedPlugins.ContainsKey(plugin.WindowId))
                {
                    addPluginToList(plugin);
                }
            }

            dataGridViewPluginList.AutoGenerateColumns           = false;
            dataGridViewPluginList.AutoSize                      = true;
            dataGridViewPluginList.DataSource                    = pluginsDataSource;
            dataGridViewPluginList.CurrentCellDirtyStateChanged += new EventHandler(dataGridViewPluginList_CurrentCellDirtyStateChanged);

            DataGridViewCheckBoxColumn displayColumn = new DataGridViewCheckBoxColumn();

            displayColumn.ReadOnly         = false;
            displayColumn.AutoSizeMode     = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
            displayColumn.DataPropertyName = "DisplayPlugin";
            displayColumn.Name             = "";
            dataGridViewPluginList.Columns.Add(displayColumn);

            DataGridViewImageColumn iconColumn = new DataGridViewImageColumn(false);

            iconColumn.ReadOnly         = true;
            iconColumn.ImageLayout      = DataGridViewImageCellLayout.Zoom;
            iconColumn.Width            = 20;
            iconColumn.DataPropertyName = "Icon";
            iconColumn.Name             = "";
            dataGridViewPluginList.Columns.Add(iconColumn);

            DataGridViewColumn nameColumn = new DataGridViewTextBoxColumn();

            nameColumn.ReadOnly         = false;
            nameColumn.MinimumWidth     = 200;
            nameColumn.AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            nameColumn.DataPropertyName = "Name";
            nameColumn.Name             = "Plugin";
            dataGridViewPluginList.Columns.Add(nameColumn);
        }