Ejemplo n.º 1
0
        /// <summary>
        /// Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.
        /// </summary>
        public static string GetString(string key, string defaultValue = "", bool?useSecurePrefs = null)
        {
            // if not using secure prefs, or we provide an override then just fall through to standard call.
            if ((!UseSecurePrefs && !useSecurePrefs.HasValue) || (useSecurePrefs.HasValue && useSecurePrefs.Value == false))
            {
                return(JSONPrefs.GetString(key, defaultValue));
            }

            // using secure prefs.
            var prefsEntryBytes = GetDecryptedPrefsEntry(key, ItemType.String);

            if (prefsEntryBytes != null)
            {
                return(Encoding.UTF8.GetString(prefsEntryBytes, 0, prefsEntryBytes.Length));
            }

            // if the prefs entry was not found and we are auto converting then try and get and replace any unencrypted value.
            if (AutoConvertUnsecurePrefs && JSONPrefs.HasKey(key))
            {
                var value = JSONPrefs.GetString(key, defaultValue);
                SetString(key, value);
                JSONPrefs.DeleteKey(key);
                return(value);
            }

            // nothing found so return the default value
            return(defaultValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.
        /// </summary>
        public static bool HasKey(string key, bool?useSecurePrefs = null)
        {
            // if not using secure prefs, or we provide an override then just fall through to standard call.
            if ((!UseSecurePrefs && !useSecurePrefs.HasValue) || (useSecurePrefs.HasValue && useSecurePrefs.Value == false))
            {
                return(JSONPrefs.HasKey(key));
            }

            var hasEncryptedKey = JSONPrefs.HasKey(EncryptKey(key));

            if (hasEncryptedKey || !AutoConvertUnsecurePrefs)
            {
                return(hasEncryptedKey);
            }

            return(JSONPrefs.HasKey(key));
        }