/// <summary>
        /// Function to generate first time usage settings for the application.
        /// </summary>
        private void InitializeIni()
        {
            // This is the guid of the default power safe profile in Windows
            const string defaultPowerSafeProfile = "a1841308-3541-4fab-bc81-f71556f20b4a";

            _settingsIniFile.Write("LockProfileGuid", defaultPowerSafeProfile, "Program");
            _settingsIniFile.Write("UnlockProfileGuid", PowerFunctions.GetActiveGuid().ToString(), "Program");

            foreach (IPlugin plugin in _pluginService.GetAllPlugins())
            {
                _settingsIniFile.Write(plugin.Name, false.ToString(), "Plugins");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to change to the locked power plan.
        /// </summary>
        public void ChangeToLockPlan()
        {
            Guid activePolicyGuid = _settingsService.CurrentSettings.LockPowerPlan.Guid;

            PowerFunctions.PowerSetActiveScheme(IntPtr.Zero, ref activePolicyGuid);
            foreach (IPlugin plugin in _pluginService.GetEnabledPlugins())
            {
                try
                {
                    plugin.OnLock();
                }
                catch (Exception e)
                {
                    LoggerService.Instance.AddLog(
                        $"Error applying lock plan in plugin {e.Message}. Plugin name: {plugin.Name}");
                }
            }
        }
        internal SettingsForm(
            SettingsService settingsService, PluginService pluginService)
        {
            InitializeComponent();
            _settingsModel = settingsService.CurrentSettings;

            _settingsService = settingsService;
            _pluginService   = pluginService;
            LoggerService.Instance.AddObserver(UpdateLogger);

            IEnumerable <Guid> guidPlans = PowerFunctions.GetAll();

            foreach (Guid guidPlan in guidPlans)
            {
                PowerPlanModel p = new PowerPlanModel(guidPlan);
                lockedProfileComboBox.Items.Add(p);
                unlockProfileComboBox.Items.Add(p);
                if (_settingsModel.LockPowerPlan.Equals(p))
                {
                    lockedProfileComboBox.SelectedIndex = lockedProfileComboBox.Items.IndexOf(p);
                }
                if (_settingsModel.UnlockPowerPlan.Equals(p))
                {
                    unlockProfileComboBox.SelectedIndex = unlockProfileComboBox.Items.IndexOf(p);
                }
            }

            pluginListBox.DisplayMember = "Name";

            foreach (IPlugin plugin in _pluginService.GetAllPlugins())
            {
                pluginListBox.Items.Add(plugin, _settingsModel.Plugins.ContainsKey(plugin) && _settingsModel.Plugins[plugin]);
            }

            pluginListBox.SelectedValueChanged += PluginListBoxOnSelectedValueChanged;
            pluginDescription.Text              = string.Empty;
        }
Exemplo n.º 4
0
 public PowerPlanModel(Guid guid)
 {
     Guid = guid;
     // Set the name based on the given guid
     Name = PowerFunctions.ReadFriendlyName(guid);
 }