Skip to content

Commit

Permalink
Update MauiSettingsGeneric.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasReitberger committed Apr 4, 2024
1 parent 100426f commit 9d685d5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/MauiSettings/MauiSettingsGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> TryLoadSettingsAsync(string? key = null)
public static Task<bool> 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<bool> TryLoadSettingsAsync(object settings, string? key = null)
public static Task<bool> 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)
Expand All @@ -135,7 +135,7 @@ public static Task LoadSettingsAsync(Dictionary<string, Tuple<object, Type>> dic
await LoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, save: save, key: key);
});

public static Task<bool> TryLoadSettingsAsync(Dictionary<string, Tuple<object, Type>> dictionary, string? key = null)
public static Task<bool> TryLoadSettingsAsync(Dictionary<string, Tuple<object, Type>> dictionary, string? key = null, bool justTryLoading = true)
=> Task.Run(async delegate
{
return await TryLoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, key: key);
Expand All @@ -147,10 +147,10 @@ public static Task LoadSettingsAsync(string settingsKey, Tuple<object, Type> dat
await LoadSettingsAsync(settings: SettingsObject, dictionary: new() { { settingsKey, data } }, save: save, key: key);
});

public static Task<bool> TryLoadSettingsAsync(string settingsKey, Tuple<object, Type> data, string? key = null)
public static Task<bool> TryLoadSettingsAsync(string settingsKey, Tuple<object, Type> 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<string, Tuple<object, Type>> dictionary, bool save = true, string? key = null)
Expand All @@ -160,10 +160,11 @@ public static Task LoadSettingsAsync(object settings, Dictionary<string, Tuple<o
// Save the restored settings right away
if (save) await SaveSettingsAsync(settings: settings, key: key);
});
public static Task<bool> TryLoadSettingsAsync(object settings, Dictionary<string, Tuple<object, Type>> dictionary, string? key = null)
public static Task<bool> TryLoadSettingsAsync(object settings, Dictionary<string, Tuple<object, Type>> 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
Expand Down Expand Up @@ -718,8 +719,10 @@ List<MauiSettingAttribute> 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);
}
Expand Down Expand Up @@ -960,8 +963,10 @@ List<MauiSettingAttribute> 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)
Expand Down

0 comments on commit 9d685d5

Please sign in to comment.