public static void SetIcon(LoadedEnvironments currentLoadedEnvironment, LoadedSettings loadedSettings, NotifyIcon icon) { if (currentLoadedEnvironment.LoadIcon && File.Exists(currentLoadedEnvironment.IconFileLocation) && currentLoadedEnvironment.IconFileLocation.Contains(Constants.FileExtensions.IconExtension, StringComparison.OrdinalIgnoreCase)) { try { var iconFromFile = new Icon(currentLoadedEnvironment.IconFileLocation, 16, 16); icon.Icon = iconFromFile; } catch (Exception ex) { MessageBox.Show(Constants.IconMessages.ErrorLoadingIcon + ex, Constants.IconMessages.ErrorLoadingIconCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); icon.Icon = Resources.Exit_16; } } else { Font font = new Font(loadedSettings.General.IconFont, loadedSettings.General.IconFontSize); Bitmap bmp = new Bitmap(16, 16, PixelFormat.Format32bppRgb); using (Graphics g = Graphics.FromImage(bmp)) { Rectangle rectangle = new Rectangle(0, 0, 16, 16); g.FillEllipse(currentLoadedEnvironment.IconBackgroundColor.ToSolidBrush(), rectangle); g.DrawString(currentLoadedEnvironment.IconLabel, font, currentLoadedEnvironment.IconTextColor.ToSolidBrush(), 0, 1); } icon.Icon = Converter.BitmapToIcon(bmp); } }
private void EnvironmentClicked(object sender, EventArgs e) { if (_allowFeatureUseLogging) { ExceptionlessClient.Default.SubmitFeatureUsage(Constants.FeatureUsages.EnvironmentChanged); } _currentLoadedEnvironment = _loadedSettings.Environments.Find(env => env.Name == sender.ToString().Replace("&", "")); SetRegistry(); }
private void OnRegChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(_loadedSettings.MonitoredRegistryKey.Root)) { return; } _currentLoadedEnvironment = _loadedSettings.Environments.Find(env => env.SubkeyValue == (string)Registry.GetValue(_loadedSettings.MonitoredRegistryKey.Root, _loadedSettings.MonitoredRegistryKey.Subkey, "")); SetIcon(); ShowEnvironmentChangedBalloonTip(); }
private void LoadRegistryMonitor() { _currentLoadedEnvironment = _loadedSettings.Environments.Find(env => env.SubkeyValue == (string)Registry.GetValue(_loadedSettings.MonitoredRegistryKey.Root, _loadedSettings.MonitoredRegistryKey.Subkey, "")); SetIcon(); _registryMonitor = new RegistryUtils.RegistryMonitor(_loadedSettings.MonitoredRegistryKey.Root) { RegChangeNotifyFilter = RegChangeNotifyFilter.Value }; _registryMonitor.RegChanged += OnRegChanged; _registryMonitor.Error += OnError; _registryMonitor.Start(); _currentMonitoredRegistryKey = _loadedSettings.MonitoredRegistryKey; }
private static LoadedEnvironments AddPropertyToEnvironment(LoadedEnvironments loadedEnvironment, string propertyName, string propertyValue) { switch (propertyName) { case FileConstants.Environments.ID: loadedEnvironment.ID = Guid.Parse(propertyValue); break; case FileConstants.Environments.NAME: loadedEnvironment.Name = propertyValue; break; case FileConstants.Environments.SUBKEY_VALUE: loadedEnvironment.SubkeyValue = propertyValue; break; case FileConstants.Environments.HOTKEY: loadedEnvironment.HotKey = propertyValue; break; case FileConstants.Environments.ICON_LABEL: loadedEnvironment.IconLabel = propertyValue; break; case FileConstants.Environments.ICON_TEXT_COLOR: loadedEnvironment.IconTextColor = propertyValue; break; case FileConstants.Environments.ICON_BACKGROUND_COLOR: loadedEnvironment.IconBackgroundColor = propertyValue; break; case FileConstants.Environments.LOAD_ICON: loadedEnvironment.LoadIcon = bool.Parse(propertyValue); break; case FileConstants.Environments.ICON_FILE_LOCATION: loadedEnvironment.IconFileLocation = propertyValue; break; case FileConstants.Environments.DISPLAY_ON_MENU: loadedEnvironment.DisplayOnMenu = bool.Parse(propertyValue); break; } return(loadedEnvironment); }
public static List <LoadedEnvironments> ReadEnvironmentsSettings() { var environments = new List <LoadedEnvironments>(); string environmnentJsonFile = Path.Combine(Directory.GetCurrentDirectory(), ENVIRONMENT_FILE_NAME); if (!File.Exists(environmnentJsonFile)) { environments = GetGenericEnvironments(); WriteEnvironmentSettings(environments); } else { try { using (StreamReader file = File.OpenText(environmnentJsonFile)) using (JsonTextReader reader = new JsonTextReader(file)) { var env = new LoadedEnvironments(); reader.SupportMultipleContent = true; while (reader.Read()) { JObject o3 = (JObject)JToken.ReadFrom(reader); foreach (var child in o3.Children()) { AddPropertyToEnvironment(env, child.Path, child.First.ToString()); } environments.Add(env); env = new LoadedEnvironments(); } } } catch (Exception ex) { MessageBox.Show($"{Constants.EnvironmentMessages.ErrorReadingFile}{ex}", Constants.EnvironmentMessages.ErrorReadingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } return(environments); }