Skip to content

Commit c008210

Browse files
committed
2.3.3.1 - Fixed bug with upgrade path
1 parent 705ca1c commit c008210

File tree

4 files changed

+119
-95
lines changed

4 files changed

+119
-95
lines changed

settings/SettingCollection.cs

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,17 @@ public void SetValueByKey(string key, object value)
143143
/// <returns>Setting object (either existing or new).</returns>
144144
public Setting GetByKey(string key, object defaultValue, bool createKeyIfNotFound)
145145
{
146-
foreach (Setting setting in _settingList)
147-
{
148-
if (setting.Key.Equals(key))
149-
{
150-
return setting;
151-
}
152-
}
146+
Setting foundSetting = GetByKey(key);
153147

154-
if (createKeyIfNotFound)
148+
if (foundSetting == null && createKeyIfNotFound)
155149
{
156150
Setting newSetting = new Setting(key, defaultValue);
157151
Add(newSetting);
158152

159153
return newSetting;
160154
}
161155

162-
return null;
156+
return foundSetting;
163157
}
164158

165159
/// <summary>
@@ -173,6 +167,24 @@ public Setting GetByKey(string key, object defaultValue)
173167
return GetByKey(key, defaultValue, createKeyIfNotFound: true);
174168
}
175169

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+
176188
/// <summary>
177189
/// Checks if the setting key exists.
178190
/// </summary>
@@ -191,6 +203,35 @@ public bool KeyExists(string key)
191203
return false;
192204
}
193205

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+
194235
/// <summary>
195236
/// Loads the settings.
196237
/// </summary>
@@ -335,7 +376,7 @@ public void Upgrade()
335376
{
336377
if (!Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) return;
337378

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");
339380

340381
var oldUserSettings = (SettingCollection)this.MemberwiseClone();
341382
oldUserSettings._settingList = new List<Setting>(_settingList);
@@ -379,89 +420,51 @@ public void Upgrade()
379420
}
380421

381422
// 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");
422466

423467
// 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");
465468
RemoveByKey("BoolLockScreenCaptureSession");
466469
RemoveByKey("BoolCaptureStopAt");
467470
RemoveByKey("BoolCaptureStartAt");

settings/Settings.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ public static class Settings
3838
public static readonly string ApplicationVersion = DefaultSettings.ApplicationVersion;
3939

4040
// The major versions of Auto Screen Capture.
41-
// Any version that is older than "Clara" is considered as "Clara".
42-
private const string CODENAME_CLARA = "Clara"; // Clara introduced the Macro field for customizing the filename pattern of image files when writing them to disk.
41+
42+
/// <summary>
43+
/// Any version that is older than "Clara" or a version cannot be determined is considered as "Clara".
44+
/// </summary>
45+
public const string CODENAME_CLARA = "Clara"; // Clara introduced the Macro field for customizing the filename pattern of image files when writing them to disk.
46+
47+
/// <summary>
48+
/// The version number of any version old than "Clara" or a version that cannot be determined.
49+
/// </summary>
50+
public const string CODEVERSION_CLARA = "2.1.8.2";
51+
4352
private const string CODENAME_DALEK = "Dalek"; // Dalek made it possible to have an unlimited number of screens, apply labels to screenshots, and create user-defined macro tags.
4453

4554
// The current major version.

0 commit comments

Comments
 (0)