Skip to content

Commit be3f48a

Browse files
committed
Improve settings to check for null first
1 parent b92d7c1 commit be3f48a

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

Helpers/AppSettings.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public AppSettings() {
8080
appSettings = configFile.AppSettings.Settings;
8181

8282
try {
83-
string ActivateOnLaunchresult = appSettings[nameof(ActivateOnLaunch)].Value;
83+
KeyValueConfigurationElement ActivateOnLaunchSetting = appSettings[nameof(ActivateOnLaunch)];
84+
string ActivateOnLaunchresult = ActivateOnLaunchSetting == null ? "false" : ActivateOnLaunchSetting.Value;
8485
_activateOnLaunch = bool.Parse(ActivateOnLaunchresult);
8586
}
8687
catch (Exception) {
@@ -90,7 +91,8 @@ public AppSettings() {
9091
}
9192

9293
try {
93-
string AutomaticallyLaunchWithWindowsresult = appSettings[nameof(AutomaticallyLaunchWithWindows)].Value;
94+
KeyValueConfigurationElement AutomaticallyLaunchWithWindowsSetting = appSettings[nameof(AutomaticallyLaunchWithWindows)];
95+
string AutomaticallyLaunchWithWindowsresult = AutomaticallyLaunchWithWindowsSetting == null ? "false" : AutomaticallyLaunchWithWindowsSetting.Value;
9496
_automaticallyLaunchWithWindows = bool.Parse(AutomaticallyLaunchWithWindowsresult);
9597
}
9698
catch (Exception) {
@@ -100,7 +102,8 @@ public AppSettings() {
100102
}
101103

102104
try {
103-
string ShowMessageOnLaunchresult = appSettings[nameof(ShowMessageOnLaunch)].Value;
105+
KeyValueConfigurationElement ShowMessageOnLaunchSetting = appSettings[nameof(ShowMessageOnLaunch)];
106+
string ShowMessageOnLaunchresult = ShowMessageOnLaunchSetting == null ? "true" : ShowMessageOnLaunchSetting.Value;
104107
_showMessageOnLaunch = bool.Parse(ShowMessageOnLaunchresult);
105108
}
106109
catch (Exception) {
@@ -110,7 +113,8 @@ public AppSettings() {
110113
}
111114

112115
try {
113-
string DefaultDurationresult = appSettings[nameof(DefaultDuration)].Value;
116+
KeyValueConfigurationElement DefaultDurationSetting = appSettings[nameof(DefaultDuration)];
117+
string DefaultDurationresult = DefaultDurationSetting == null ? "0" : DefaultDurationSetting.Value;
114118
_defaultDuration = int.Parse(DefaultDurationresult);
115119
}
116120
catch (Exception) {
@@ -120,7 +124,8 @@ public AppSettings() {
120124
}
121125

122126
try {
123-
string Iconresult = appSettings[nameof(Icon)].Value;
127+
KeyValueConfigurationElement IconSetting = appSettings[nameof(Icon)];
128+
string Iconresult = IconSetting == null ? "default" : IconSetting.Value;
124129
switch (Iconresult) {
125130
case "Mug":
126131
_icon = TrayIcon.Mug;
@@ -140,7 +145,8 @@ public AppSettings() {
140145
}
141146

142147
try {
143-
string Durationsresult = appSettings[nameof(Durations)].Value;
148+
KeyValueConfigurationElement DurationsSetting = appSettings[nameof(Durations)];
149+
string Durationsresult = DurationsSetting == null ? "0,15,60,120,480" : DurationsSetting.Value;
144150
List<string> splitResult = Durationsresult.Split(',').ToList();
145151

146152
_durations = new ObservableCollection<int>();

0 commit comments

Comments
 (0)