private void LoadProperties() { //TODO: Change the place to get and set user settings, because when the app update it change to default. if (Settings.Default.PcName == string.Empty) { ChangePcName(Environment.UserName); } else { Voice?.ChangePcName(Settings.Default.PcName); } NotifyWind = Settings.Default.NotifyWind; NotifyVoice = Settings.Default.NotifyVoice; Battery.ChangeHighBatteryLvl(Settings.Default.BatteryHigh); Battery.ChangeLowBatteryLvl(Settings.Default.BatteryLow); Battery.ChangeAlertStatus(Array.ConvertAll(Settings.Default.AlertStatus.Split(','), bool.Parse)); PcIdle.ChangeMaxIdleTime(Settings.Default.PcIdleTime); TimeBatteryCheck = Settings.Default.TimeBattChk; AuxTimeBatteryCheck = Settings.Default.TimeAuxBattChk; Voice?.ChangeNotVolume(Settings.Default.VolNot); if (Settings.Default.VoiceName != string.Empty) { Voice?.ChangeCurrentVoice(Settings.Default.VoiceName); } else { Settings.Default.VoiceName = Voice?.CurrentVoice; Settings.Default.Save(); } }
private void SettingsToolStripMenuItem_Click(object sender, EventArgs e) { //TODO: Fix the way to pass parameters. using (var formSettings = new FormSettings(TimeBatteryCheck, AuxTimeBatteryCheck, PcIdle.MaxIdleTime, Battery.LowBatteryLvl, Battery.HighBatteryLvl, Voice, NotifyWind, NotifyVoice, Battery.AlertStatus)) { //Recall for check if there is an installed voice. Voice.GetVoices(); // SHOW Form formSettings.ShowDialog(); // Check if the user make any change. if (!formSettings.HasChanges) { return; } #region Notification //Stop timers. // Save the Status of the Timer. //var isTmCheckPowerEnabled = TmCheckPower.Enabled; AlertChecked(false); TmCheckPower.Stop(); TmWaitForResp.Stop(); // Battery.ChangeAlertStatus(new[] { formSettings.ChBoxLowBat, formSettings.ChBoxHighBat }); Battery.ChangePrevAlert(Any); Battery.ResetAlert(); //Get formSettings values. NotifyWind = formSettings.NotifyWind; NotifyVoice = formSettings.NotifyVoice; TimeBatteryCheck = formSettings.TimeBatChk; AuxTimeBatteryCheck = formSettings.AuxTimeBatChk; Battery.ChangeLowBatteryLvl(formSettings.LowBattery); Battery.ChangeHighBatteryLvl(formSettings.HighBattery); PcIdle.ChangeMaxIdleTime(formSettings.IdleTime); //Save in properties Settings.Default.BatteryHigh = Battery.HighBatteryLvl; Settings.Default.BatteryLow = Battery.LowBatteryLvl; Settings.Default.PcIdleTime = PcIdle.MaxIdleTime; Settings.Default.TimeBattChk = TimeBatteryCheck; Settings.Default.TimeAuxBattChk = AuxTimeBatteryCheck; Settings.Default.NotifyWind = NotifyWind; Settings.Default.NotifyVoice = NotifyVoice; Settings.Default.AlertStatus = string.Join(",", Battery.AlertStatus); //Changes timer intervals. TmCheckPower.Interval = (int)TimeBatteryCheck * 1000; AuxAlertTime = (int)(AuxTimeBatteryCheck * 60); ProgBarNextAlert.Maximum = AuxAlertTime; //Restart timers. //TmCheckPower.Enabled = isTmCheckPowerEnabled; TmCheckPower.Start(); #endregion #region Voz try { Settings.Default.VoiceName = formSettings.CurrentVoice; Settings.Default.VolNot = formSettings.NotifyVolume; Voice.ChangeCurrentVoice(formSettings.CurrentVoice); Voice.ChangeNotVolume(formSettings.NotifyVolume); } catch (Exception exc) { MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion Voice?.ChangePcName(formSettings.PcName); Settings.Default.PcName = formSettings.PcName; Settings.Default.Save(); } }