@@ -143,23 +143,17 @@ public void SetValueByKey(string key, object value)
143
143
/// <returns>Setting object (either existing or new).</returns>
144
144
public Setting GetByKey ( string key , object defaultValue , bool createKeyIfNotFound )
145
145
{
146
- foreach ( Setting setting in _settingList )
147
- {
148
- if ( setting . Key . Equals ( key ) )
149
- {
150
- return setting ;
151
- }
152
- }
146
+ Setting foundSetting = GetByKey ( key ) ;
153
147
154
- if ( createKeyIfNotFound )
148
+ if ( foundSetting == null && createKeyIfNotFound )
155
149
{
156
150
Setting newSetting = new Setting ( key , defaultValue ) ;
157
151
Add ( newSetting ) ;
158
152
159
153
return newSetting ;
160
154
}
161
155
162
- return null ;
156
+ return foundSetting ;
163
157
}
164
158
165
159
/// <summary>
@@ -173,6 +167,24 @@ public Setting GetByKey(string key, object defaultValue)
173
167
return GetByKey ( key , defaultValue , createKeyIfNotFound : true ) ;
174
168
}
175
169
170
+ /// <summary>
171
+ /// Gets a Setting by its unique key.
172
+ /// </summary>
173
+ /// <param name="key">The unique key of the Setting.</param>
174
+ /// <returns></returns>
175
+ public Setting GetByKey ( string key )
176
+ {
177
+ foreach ( Setting setting in _settingList )
178
+ {
179
+ if ( setting . Key . Equals ( key ) )
180
+ {
181
+ return setting ;
182
+ }
183
+ }
184
+
185
+ return null ;
186
+ }
187
+
176
188
/// <summary>
177
189
/// Checks if the setting key exists.
178
190
/// </summary>
@@ -191,6 +203,35 @@ public bool KeyExists(string key)
191
203
return false ;
192
204
}
193
205
206
+ /// <summary>
207
+ /// Renames an old key to a new key while retaining the value from the old key.
208
+ /// </summary>
209
+ /// <param name="oldKey">The name of the old key.</param>
210
+ /// <param name="newKey">The name of the new key.</param>
211
+ public void RenameKey ( string oldKey , string newKey )
212
+ {
213
+ if ( KeyExists ( oldKey ) )
214
+ {
215
+ Setting oldSetting = GetByKey ( oldKey ) ;
216
+
217
+ if ( oldSetting == null )
218
+ {
219
+ return ;
220
+ }
221
+
222
+ object value = oldSetting . Value ;
223
+
224
+ if ( value == null )
225
+ {
226
+ return ;
227
+ }
228
+
229
+ SetValueByKey ( newKey , value ) ;
230
+
231
+ RemoveByKey ( oldKey ) ;
232
+ }
233
+ }
234
+
194
235
/// <summary>
195
236
/// Loads the settings.
196
237
/// </summary>
@@ -335,7 +376,7 @@ public void Upgrade()
335
376
{
336
377
if ( ! Settings . VersionManager . IsOldAppVersion ( AppCodename , AppVersion ) ) return ;
337
378
338
- Log . WriteMessage ( "An old version of " + Settings . ApplicationName + " was detected. Attempting upgrade" ) ;
379
+ Log . WriteMessage ( "An old version or a fresh version of " + Settings . ApplicationName + " was detected. Attempting upgrade" ) ;
339
380
340
381
var oldUserSettings = ( SettingCollection ) this . MemberwiseClone ( ) ;
341
382
oldUserSettings . _settingList = new List < Setting > ( _settingList ) ;
@@ -379,89 +420,51 @@ public void Upgrade()
379
420
}
380
421
381
422
// Go through the old settings and get the old values from them to be used for the new settings.
382
- SetValueByKey ( "ScreenCaptureInterval" , Convert . ToInt32 ( GetByKey ( "Interval" , DefaultSettings . ScreenCaptureInterval , createKeyIfNotFound : true ) . Value ) ) ;
383
- SetValueByKey ( "ScreenCaptureInterval" , Convert . ToInt32 ( GetByKey ( "IntScreenCaptureInterval" , DefaultSettings . ScreenCaptureInterval , createKeyIfNotFound : true ) . Value ) ) ;
384
- SetValueByKey ( "CaptureLimit" , Convert . ToInt32 ( GetByKey ( "IntCaptureLimit" , DefaultSettings . CaptureLimit , createKeyIfNotFound : true ) . Value ) ) ;
385
- SetValueByKey ( "CaptureLimitCheck" , Convert . ToBoolean ( GetByKey ( "BoolCaptureLimit" , DefaultSettings . CaptureLimitCheck , createKeyIfNotFound : true ) . Value ) ) ;
386
- SetValueByKey ( "TakeInitialScreenshot" , Convert . ToBoolean ( GetByKey ( "BoolTakeInitialScreenshot" , DefaultSettings . TakeInitialScreenshot , createKeyIfNotFound : true ) . Value ) ) ;
387
- SetValueByKey ( "TakeInitialScreenshot" , Convert . ToBoolean ( GetByKey ( "TakeInitialScreenshotCheck" , DefaultSettings . TakeInitialScreenshot , createKeyIfNotFound : true ) . Value ) ) ;
388
- SetValueByKey ( "ShowSystemTrayIcon" , Convert . ToBoolean ( GetByKey ( "BoolShowSystemTrayIcon" , DefaultSettings . ShowSystemTrayIcon , createKeyIfNotFound : true ) . Value ) ) ;
389
- SetValueByKey ( "KeepScreenshotsForDays" , Convert . ToInt32 ( GetByKey ( "DaysOldWhenRemoveSlides" , DefaultSettings . KeepScreenshotsForDays , createKeyIfNotFound : true ) . Value ) ) ;
390
- SetValueByKey ( "KeepScreenshotsForDays" , Convert . ToInt32 ( GetByKey ( "IntKeepScreenshotsForDays" , DefaultSettings . KeepScreenshotsForDays , createKeyIfNotFound : true ) . Value ) ) ;
391
- SetValueByKey ( "ScreenshotLabel" , Convert . ToString ( GetByKey ( "StringScreenshotLabel" , DefaultSettings . ScreenshotLabel , createKeyIfNotFound : true ) . Value ) ) ;
392
- SetValueByKey ( "ApplyScreenshotLabel" , Convert . ToBoolean ( GetByKey ( "BoolApplyScreenshotLabel" , DefaultSettings . ApplyScreenshotLabel , createKeyIfNotFound : true ) . Value ) ) ;
393
- SetValueByKey ( "DefaultEditor" , Convert . ToString ( GetByKey ( "StringDefaultEditor" , DefaultSettings . DefaultEditor , createKeyIfNotFound : true ) . Value ) ) ;
394
- SetValueByKey ( "FirstRun" , Convert . ToBoolean ( GetByKey ( "BoolFirstRun" , DefaultSettings . FirstRun , createKeyIfNotFound : true ) . Value ) ) ;
395
- SetValueByKey ( "StartScreenCaptureCount" , Convert . ToInt32 ( GetByKey ( "IntStartScreenCaptureCount" , DefaultSettings . StartScreenCaptureCount , createKeyIfNotFound : true ) . Value ) ) ;
396
- SetValueByKey ( "ActiveWindowTitleCaptureCheck" , Convert . ToBoolean ( GetByKey ( "BoolActiveWindowTitleCaptureCheck" , DefaultSettings . ActiveWindowTitleCaptureCheck , createKeyIfNotFound : true ) . Value ) ) ;
397
- SetValueByKey ( "ActiveWindowTitleCaptureText" , Convert . ToString ( GetByKey ( "StringActiveWindowTitleCaptureText" , DefaultSettings . ActiveWindowTitleCaptureText , createKeyIfNotFound : true ) . Value ) ) ;
398
- SetValueByKey ( "AutoSaveFolder" , Convert . ToString ( GetByKey ( "StringAutoSaveFolder" , DefaultSettings . AutoSaveFolder , createKeyIfNotFound : true ) . Value ) ) ;
399
- SetValueByKey ( "AutoSaveMacro" , Convert . ToString ( GetByKey ( "StringAutoSaveMacro" , DefaultSettings . AutoSaveMacro , createKeyIfNotFound : true ) . Value ) ) ;
400
- SetValueByKey ( "UseKeyboardShortcuts" , Convert . ToBoolean ( GetByKey ( "BoolUseKeyboardShortcuts" , DefaultSettings . UseKeyboardShortcuts , createKeyIfNotFound : true ) . Value ) ) ;
401
- SetValueByKey ( "KeyboardShortcutStartScreenCaptureModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStartScreenCaptureModifier1" , DefaultSettings . KeyboardShortcutStartScreenCaptureModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
402
- SetValueByKey ( "KeyboardShortcutStartScreenCaptureModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStartScreenCaptureModifier2" , DefaultSettings . KeyboardShortcutStartScreenCaptureModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
403
- SetValueByKey ( "KeyboardShortcutStartScreenCaptureKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStartScreenCaptureKey" , DefaultSettings . KeyboardShortcutStartScreenCaptureKey , createKeyIfNotFound : true ) . Value ) ) ;
404
- SetValueByKey ( "KeyboardShortcutStopScreenCaptureModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStopScreenCaptureModifier1" , DefaultSettings . KeyboardShortcutStopScreenCaptureModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
405
- SetValueByKey ( "KeyboardShortcutStopScreenCaptureModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStopScreenCaptureModifier2" , DefaultSettings . KeyboardShortcutStopScreenCaptureModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
406
- SetValueByKey ( "KeyboardShortcutStopScreenCaptureKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutStopScreenCaptureKey" , DefaultSettings . KeyboardShortcutStopScreenCaptureKey , createKeyIfNotFound : true ) . Value ) ) ;
407
- SetValueByKey ( "KeyboardShortcutCaptureNowArchiveModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowArchiveModifier1" , DefaultSettings . KeyboardShortcutCaptureNowArchiveModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
408
- SetValueByKey ( "KeyboardShortcutCaptureNowArchiveModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowArchiveModifier2" , DefaultSettings . KeyboardShortcutCaptureNowArchiveModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
409
- SetValueByKey ( "KeyboardShortcutCaptureNowArchiveKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowArchiveKey" , DefaultSettings . KeyboardShortcutCaptureNowArchiveKey , createKeyIfNotFound : true ) . Value ) ) ;
410
- SetValueByKey ( "KeyboardShortcutCaptureNowEditModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowEditModifier1" , DefaultSettings . KeyboardShortcutCaptureNowEditModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
411
- SetValueByKey ( "KeyboardShortcutCaptureNowEditModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowEditModifier2" , DefaultSettings . KeyboardShortcutCaptureNowEditModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
412
- SetValueByKey ( "KeyboardShortcutCaptureNowEditKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutCaptureNowEditKey" , DefaultSettings . KeyboardShortcutCaptureNowEditKey , createKeyIfNotFound : true ) . Value ) ) ;
413
- SetValueByKey ( "KeyboardShortcutRegionSelectClipboardModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectClipboardModifier1" , DefaultSettings . KeyboardShortcutRegionSelectClipboardModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
414
- SetValueByKey ( "KeyboardShortcutRegionSelectClipboardModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectClipboardModifier2" , DefaultSettings . KeyboardShortcutRegionSelectClipboardModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
415
- SetValueByKey ( "KeyboardShortcutRegionSelectClipboardKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectClipboardKey" , DefaultSettings . KeyboardShortcutRegionSelectClipboardKey , createKeyIfNotFound : true ) . Value ) ) ;
416
- SetValueByKey ( "KeyboardShortcutRegionSelectAutoSaveModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier1" , DefaultSettings . KeyboardShortcutRegionSelectAutoSaveModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
417
- SetValueByKey ( "KeyboardShortcutRegionSelectAutoSaveModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier2" , DefaultSettings . KeyboardShortcutRegionSelectAutoSaveModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
418
- SetValueByKey ( "KeyboardShortcutRegionSelectAutoSaveKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectAutoSaveKey" , DefaultSettings . KeyboardShortcutRegionSelectAutoSaveKey , createKeyIfNotFound : true ) . Value ) ) ;
419
- SetValueByKey ( "KeyboardShortcutRegionSelectEditModifier1" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectEditModifier1" , DefaultSettings . KeyboardShortcutRegionSelectEditModifier1 , createKeyIfNotFound : true ) . Value ) ) ;
420
- SetValueByKey ( "KeyboardShortcutRegionSelectEditModifier2" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectEditModifier2" , DefaultSettings . KeyboardShortcutRegionSelectEditModifier2 , createKeyIfNotFound : true ) . Value ) ) ;
421
- SetValueByKey ( "KeyboardShortcutRegionSelectEditKey" , Convert . ToString ( GetByKey ( "StringKeyboardShortcutRegionSelectEditKey" , DefaultSettings . KeyboardShortcutRegionSelectEditKey , createKeyIfNotFound : true ) . Value ) ) ;
423
+ RenameKey ( "Interval" , "ScreenCaptureInterval" ) ;
424
+ RenameKey ( "IntScreenCaptureInterval" , "ScreenCaptureInterval" ) ;
425
+ RenameKey ( "IntCaptureLimit" , "CaptureLimit" ) ;
426
+ RenameKey ( "BoolCaptureLimit" , "CaptureLimitCheck" ) ;
427
+ RenameKey ( "BoolTakeInitialScreenshot" , "TakeInitialScreenshot" ) ;
428
+ RenameKey ( "TakeInitialScreenshotCheck" , "TakeInitialScreenshot" ) ;
429
+ RenameKey ( "BoolShowSystemTrayIcon" , "ShowSystemTrayIcon" ) ;
430
+ RenameKey ( "DaysOldWhenRemoveSlides" , "KeepScreenshotsForDays" ) ;
431
+ RenameKey ( "IntKeepScreenshotsForDays" , "KeepScreenshotsForDays" ) ;
432
+ RenameKey ( "StringPassphrase" , "Passphrase" ) ;
433
+ RenameKey ( "StringScreenshotLabel" , "ScreenshotLabel" ) ;
434
+ RenameKey ( "BoolApplyScreenshotLabel" , "ApplyScreenshotLabel" ) ;
435
+ RenameKey ( "StringDefaultEditor" , "DefaultEditor" ) ;
436
+ RenameKey ( "BoolFirstRun" , "FirstRun" ) ;
437
+ RenameKey ( "IntStartScreenCaptureCount" , "StartScreenCaptureCount" ) ;
438
+ RenameKey ( "BoolActiveWindowTitleCaptureCheck" , "ActiveWindowTitleCaptureCheck" ) ;
439
+ RenameKey ( "StringActiveWindowTitleCaptureText" , "ActiveWindowTitleCaptureText" ) ;
440
+ RenameKey ( "StringAutoSaveFolder" , "AutoSaveFolder" ) ;
441
+ RenameKey ( "StringAutoSaveMacro" , "AutoSaveMacro" ) ;
442
+ RenameKey ( "BoolUseKeyboardShortcuts" , "UseKeyboardShortcuts" ) ;
443
+
444
+ // Keyboard Shortcuts
445
+ RenameKey ( "StringKeyboardShortcutStartScreenCaptureModifier1" , "KeyboardShortcutStartScreenCaptureModifier1" ) ;
446
+ RenameKey ( "StringKeyboardShortcutStartScreenCaptureModifier2" , "KeyboardShortcutStartScreenCaptureModifier2" ) ;
447
+ RenameKey ( "StringKeyboardShortcutStartScreenCaptureKey" , "KeyboardShortcutStartScreenCaptureKey" ) ;
448
+ RenameKey ( "StringKeyboardShortcutStopScreenCaptureModifier1" , "KeyboardShortcutStopScreenCaptureModifier1" ) ;
449
+ RenameKey ( "StringKeyboardShortcutStopScreenCaptureModifier2" , "KeyboardShortcutStopScreenCaptureModifier2" ) ;
450
+ RenameKey ( "StringKeyboardShortcutStopScreenCaptureKey" , "KeyboardShortcutStopScreenCaptureKey" ) ;
451
+ RenameKey ( "StringKeyboardShortcutCaptureNowArchiveModifier1" , "KeyboardShortcutCaptureNowArchiveModifier1" ) ;
452
+ RenameKey ( "StringKeyboardShortcutCaptureNowArchiveModifier2" , "KeyboardShortcutCaptureNowArchiveModifier2" ) ;
453
+ RenameKey ( "StringKeyboardShortcutCaptureNowArchiveKey" , "KeyboardShortcutCaptureNowArchiveKey" ) ;
454
+ RenameKey ( "StringKeyboardShortcutCaptureNowEditModifier1" , "KeyboardShortcutCaptureNowEditModifier1" ) ;
455
+ RenameKey ( "StringKeyboardShortcutCaptureNowEditModifier2" , "KeyboardShortcutCaptureNowEditModifier2" ) ;
456
+ RenameKey ( "StringKeyboardShortcutCaptureNowEditKey" , "KeyboardShortcutCaptureNowEditKey" ) ;
457
+ RenameKey ( "StringKeyboardShortcutRegionSelectClipboardModifier1" , "KeyboardShortcutRegionSelectClipboardModifier1" ) ;
458
+ RenameKey ( "StringKeyboardShortcutRegionSelectClipboardModifier2" , "KeyboardShortcutRegionSelectClipboardModifier2" ) ;
459
+ RenameKey ( "StringKeyboardShortcutRegionSelectClipboardKey" , "KeyboardShortcutRegionSelectClipboardKey" ) ;
460
+ RenameKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier1" , "KeyboardShortcutRegionSelectAutoSaveModifier1" ) ;
461
+ RenameKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier2" , "KeyboardShortcutRegionSelectAutoSaveModifier2" ) ;
462
+ RenameKey ( "StringKeyboardShortcutRegionSelectAutoSaveKey" , "KeyboardShortcutRegionSelectAutoSaveKey" ) ;
463
+ RenameKey ( "StringKeyboardShortcutRegionSelectEditModifier1" , "KeyboardShortcutRegionSelectEditModifier1" ) ;
464
+ RenameKey ( "StringKeyboardShortcutRegionSelectEditModifier2" , "KeyboardShortcutRegionSelectEditModifier2" ) ;
465
+ RenameKey ( "StringKeyboardShortcutRegionSelectEditKey" , "KeyboardShortcutRegionSelectEditKey" ) ;
422
466
423
467
// Remove the old settings.
424
- RemoveByKey ( "StringPassphrase" ) ;
425
- RemoveByKey ( "Interval" ) ;
426
- RemoveByKey ( "IntScreenCaptureInterval" ) ;
427
- RemoveByKey ( "IntCaptureLimit" ) ;
428
- RemoveByKey ( "BoolCaptureLimit" ) ;
429
- RemoveByKey ( "BoolTakeInitialScreenshot" ) ;
430
- RemoveByKey ( "TakeInitialScreenshotCheck" ) ;
431
- RemoveByKey ( "BoolShowSystemTrayIcon" ) ;
432
- RemoveByKey ( "DaysOldWhenRemoveSlides" ) ;
433
- RemoveByKey ( "IntKeepScreenshotsForDays" ) ;
434
- RemoveByKey ( "StringScreenshotLabel" ) ;
435
- RemoveByKey ( "BoolApplyScreenshotLabel" ) ;
436
- RemoveByKey ( "StringDefaultEditor" ) ;
437
- RemoveByKey ( "BoolFirstRun" ) ;
438
- RemoveByKey ( "IntStartScreenCaptureCount" ) ;
439
- RemoveByKey ( "BoolActiveWindowTitleCaptureCheck" ) ;
440
- RemoveByKey ( "StringActiveWindowTitleCaptureText" ) ;
441
- RemoveByKey ( "StringAutoSaveFolder" ) ;
442
- RemoveByKey ( "StringAutoSaveMacro" ) ;
443
- RemoveByKey ( "BoolUseKeyboardShortcuts" ) ;
444
- RemoveByKey ( "StringKeyboardShortcutStartScreenCaptureModifier1" ) ;
445
- RemoveByKey ( "StringKeyboardShortcutStartScreenCaptureModifier2" ) ;
446
- RemoveByKey ( "StringKeyboardShortcutStartScreenCaptureKey" ) ;
447
- RemoveByKey ( "StringKeyboardShortcutStopScreenCaptureModifier1" ) ;
448
- RemoveByKey ( "StringKeyboardShortcutStopScreenCaptureModifier2" ) ;
449
- RemoveByKey ( "StringKeyboardShortcutStopScreenCaptureKey" ) ;
450
- RemoveByKey ( "StringKeyboardShortcutCaptureNowArchiveModifier1" ) ;
451
- RemoveByKey ( "StringKeyboardShortcutCaptureNowArchiveModifier2" ) ;
452
- RemoveByKey ( "StringKeyboardShortcutCaptureNowArchiveKey" ) ;
453
- RemoveByKey ( "StringKeyboardShortcutCaptureNowEditModifier1" ) ;
454
- RemoveByKey ( "StringKeyboardShortcutCaptureNowEditModifier2" ) ;
455
- RemoveByKey ( "StringKeyboardShortcutCaptureNowEditKey" ) ;
456
- RemoveByKey ( "StringKeyboardShortcutRegionSelectClipboardModifier1" ) ;
457
- RemoveByKey ( "StringKeyboardShortcutRegionSelectClipboardModifier2" ) ;
458
- RemoveByKey ( "StringKeyboardShortcutRegionSelectClipboardKey" ) ;
459
- RemoveByKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier1" ) ;
460
- RemoveByKey ( "StringKeyboardShortcutRegionSelectAutoSaveModifier2" ) ;
461
- RemoveByKey ( "StringKeyboardShortcutRegionSelectAutoSaveKey" ) ;
462
- RemoveByKey ( "StringKeyboardShortcutRegionSelectEditModifier1" ) ;
463
- RemoveByKey ( "StringKeyboardShortcutRegionSelectEditModifier2" ) ;
464
- RemoveByKey ( "StringKeyboardShortcutRegionSelectEditKey" ) ;
465
468
RemoveByKey ( "BoolLockScreenCaptureSession" ) ;
466
469
RemoveByKey ( "BoolCaptureStopAt" ) ;
467
470
RemoveByKey ( "BoolCaptureStartAt" ) ;
0 commit comments