From 9d685d5e41c94390f4bd051a40fe62ab5ea17767 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 4 Apr 2024 15:25:10 +0200 Subject: [PATCH] Update MauiSettingsGeneric.cs --- src/MauiSettings/MauiSettingsGeneric.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/MauiSettings/MauiSettingsGeneric.cs b/src/MauiSettings/MauiSettingsGeneric.cs index d4419ab..d7e5aff 100644 --- a/src/MauiSettings/MauiSettingsGeneric.cs +++ b/src/MauiSettings/MauiSettingsGeneric.cs @@ -105,16 +105,16 @@ public static Task LoadSettingsAsync(object settings, string? key = null) await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Load, key: key); }); - public static Task TryLoadSettingsAsync(string? key = null) + public static Task TryLoadSettingsAsync(string? key = null, bool justTryLoading = true) => Task.Run(async delegate { - return await TryLoadSettingsAsync(settings: SettingsObject, key: key); + return await TryLoadSettingsAsync(settings: SettingsObject, key: key, justTryLoading: justTryLoading); }); - public static Task TryLoadSettingsAsync(object settings, string? key = null) + public static Task TryLoadSettingsAsync(object settings, string? key = null, bool justTryLoading = true) => Task.Run(async delegate { - return await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Load, key: key, justTryLoading: true); + return await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Load, key: key, justTryLoading: justTryLoading); }); public static Task LoadSecureSettingsAsync(string? key = null) @@ -135,7 +135,7 @@ public static Task LoadSettingsAsync(Dictionary> dic await LoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, save: save, key: key); }); - public static Task TryLoadSettingsAsync(Dictionary> dictionary, string? key = null) + public static Task TryLoadSettingsAsync(Dictionary> dictionary, string? key = null, bool justTryLoading = true) => Task.Run(async delegate { return await TryLoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, key: key); @@ -147,10 +147,10 @@ public static Task LoadSettingsAsync(string settingsKey, Tuple dat await LoadSettingsAsync(settings: SettingsObject, dictionary: new() { { settingsKey, data } }, save: save, key: key); }); - public static Task TryLoadSettingsAsync(string settingsKey, Tuple data, string? key = null) + public static Task TryLoadSettingsAsync(string settingsKey, Tuple data, string? key = null, bool justTryLoading = true) => Task.Run(async delegate { - return await TryLoadSettingsAsync(settings: SettingsObject, dictionary: new() { { settingsKey, data } }, key: key); + return await TryLoadSettingsAsync(settings: SettingsObject, dictionary: new() { { settingsKey, data } }, key: key, justTryLoading: justTryLoading); }); public static Task LoadSettingsAsync(object settings, Dictionary> dictionary, bool save = true, string? key = null) @@ -160,10 +160,11 @@ public static Task LoadSettingsAsync(object settings, Dictionary TryLoadSettingsAsync(object settings, Dictionary> dictionary, string? key = null) + public static Task TryLoadSettingsAsync(object settings, Dictionary> dictionary, string? key = null, bool justTryLoading = true) => Task.Run(async delegate { - return await GetMetaFromDictionaryAsync(settings: settings, dictionary: dictionary, mode: MauiSettingsActions.Load, secureOnly: false, key: key, justTryLoading: true); + return await GetMetaFromDictionaryAsync( + settings: settings, dictionary: dictionary, mode: MauiSettingsActions.Load, secureOnly: false, key: key, justTryLoading: justTryLoading); }); #endregion @@ -718,8 +719,10 @@ List settingBaseAttributes { string decryptedString = EncryptionManager.DecryptStringFromBase64String(secureString, key); // Throw on key missmatch + /* if (string.IsNullOrEmpty(decryptedString) && !string.IsNullOrEmpty(secureString)) throw new Exception($"The secure string is not empty, but the decrypted string is. This indicates a key missmatch!"); + */ if (!justTryLoading) MauiSettingsObjectHelper.SetSettingValue(settingsObjectInfo.Info, settingsObjectInfo.OrignalSettingsObject, decryptedString, settingsInfo.SettingsType); } @@ -960,8 +963,10 @@ List settingBaseAttributes { string decryptedString = EncryptionManager.DecryptStringFromBase64String(secureString, key); // Throw on key missmatch + /* if (string.IsNullOrEmpty(decryptedString) && !string.IsNullOrEmpty(secureString)) throw new Exception($"The secure string is not empty, but the decrypted string is. This indicates a key missmatch!"); + */ settingsInfo.Value = decryptedString; } catch (Exception ex)