Exemple #1
0
        private static KeyCombo RetrieveKeyComboValue(SettingsRegKey key, string valueName, ref string member)
        {
            string   text      = SettingsRegKey.RetrieveStringValue(key, valueName, ref member);
            KeyCombo returnKey = null;

            // set default KeyCombo
            if (string.IsNullOrWhiteSpace(text))
            {
                if (valueName == _screenCaptureShortcutName)
                {
                    returnKey             = KeyCombo.ParseOrDefault("Snapshot");
                    ScreenCaptureShortcut = returnKey;
                }
                else if (valueName == _quickCaptureShortcutName)
                {
                    returnKey            = KeyCombo.ParseOrDefault("None");
                    QuickCaptureShortcut = returnKey;
                }
                else if (valueName == _libraryShortcutName)
                {
                    returnKey       = KeyCombo.ParseOrDefault("None");
                    LibraryShortcut = returnKey;
                }
            }
            else
            {
                returnKey = KeyCombo.ParseOrDefault(text);
            }

            return(returnKey);
        }
Exemple #2
0
        internal static int RetrieveNullableIntValue(SettingsRegKey key, string valueName, ref int?member)
        {
            try
            {
                int?value = GetValue(key, valueName, null) as int?;
                if (value == null)
                {
                    member = 0;
                    SetValue(key, valueName, 0);
                }
                else
                {
                    member = value.Value;
                }
            }
            catch
            {
            }

            if (member != null)
            {
                return(member.Value);
            }
            else
            {
                return(0);
            }
        }
Exemple #3
0
        internal static bool RetrieveNullableBoolValue(SettingsRegKey key, string valueName, ref bool?member, bool defaultValue = false)
        {
            try
            {
                int?value = GetValue(key, valueName, null) as int?;
                if (value == null)
                {
                    member = defaultValue;
                    SetValue(key, valueName, Convert.ToUInt32(member));
                }
                else
                {
                    member = value.Value != 0;
                }
            }
            catch
            {
            }

            if (member != null)
            {
                return(member.Value);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private static void UpdateKeyComboValue(SettingsRegKey key, string valueName, ref string member, KeyCombo value)
        {
            string text = _disableKeyCombo;

            if (value != null && value.IsValid)
            {
                text = value.ToString();
            }

            SettingsRegKey.UpdateStringValue(key, valueName, ref member, text);
        }
Exemple #5
0
        internal static object GetValue(SettingsRegKey key, string valueName, object defaultValue)
        {
            if (key == null)
            {
                return(defaultValue);
            }

            using (RegistryKey regKey = key.SettingsKey)
            {
                return(regKey == null ? defaultValue : regKey.GetValue(valueName, defaultValue)); // HKLM key may not exist
            }
        }
        /// <summary>
        /// Fetch API keys/endpoints for cognitive services
        /// </summary>
        /// <param name="keyName">Name of the service, whose value is fetched</param>
        /// <param name="defaultValue">if the key does not exist, use this default</param>
        /// <returns></returns>
        internal static string GetKey(string keyName, string defaultValue)
        {
            var value = SettingsRegKey.RetrieveStringValue(SettingsKey, keyName, ref _key);

            if (string.IsNullOrEmpty(value))
            {
                value = defaultValue;
                SetKey(keyName, value);
            }

            return(value);
        }
Exemple #7
0
 internal static void UpdateNullableIntValue(SettingsRegKey key, string valueName, ref int?member, int value)
 {
     try
     {
         if (member == null || member.Value != value)
         {
             member = value;
             SetValue(key, valueName, value);
         }
     }
     catch
     {
     }
 }
Exemple #8
0
 internal static void UpdateNullableBoolValue(SettingsRegKey key, string valueName, ref bool?member, bool value)
 {
     try
     {
         if (member == null || member.Value != value)
         {
             member = value;
             SetValue(key, valueName, value ? 1 : 0);
         }
     }
     catch
     {
     }
 }
Exemple #9
0
 internal static void UpdateStringValue(SettingsRegKey key, string valueName, ref string member, string value)
 {
     try
     {
         if (!string.Equals(member, value))
         {
             member = value;
             SetValue(key, valueName, value);
         }
     }
     catch
     {
     }
 }
Exemple #10
0
        /// <summary>
        /// Fetch API keys/endpoints for cognitive services
        /// </summary>
        /// <param name="keyName">Name of the service, whose value is fetched</param>
        /// <param name="defaultValue">if the key does not exist, use this default</param>
        /// <returns></returns>
        internal static string GetKey(string keyName, string defaultValue, bool createIfNew = false)
        {
            var value = SettingsRegKey.RetrieveStringValue(SettingsKey, keyName, ref _key);

            if (string.IsNullOrWhiteSpace(value))
            {
                value = defaultValue;
                if (createIfNew)
                {
                    SetKey(keyName, value);
                }
            }

            return(value);
        }
Exemple #11
0
        internal static void SetValue(SettingsRegKey key, string valueName, object value)
        {
            if (key == null)
            {
                return;
            }

            if (key.SettingsHive == RegistryHive.LocalMachine) // prevent writes to HKLM registry
            {
                return;
            }

            using (RegistryKey regKey = key.SettingsKey)
            {
                regKey.SetValue(valueName, value);
            }
        }
Exemple #12
0
        internal static string RetrieveStringValue(SettingsRegKey key, string valueName, ref string member)
        {
            try
            {
                member = GetValue(key, valueName, null) as string;
                if (member == null)
                {
                    member = string.Empty;
                    SetValue(key, valueName, member);
                }
            }
            catch
            {
            }

            if (member != null)
            {
                return(member);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemple #13
0
 /// <summary>
 /// Store the user entered API key.
 /// </summary>
 /// <param name="keyName">Name of the service, whose key is to be updated</param>
 /// <param name="keyValue">Updated key to be stored and used</param>
 internal static void SetKey(string keyName, string keyValue)
 {
     SettingsRegKey.UpdateStringValue(SettingsKey, keyName, ref _key, keyValue);
 }
Exemple #14
0
 /// <summary>
 /// Fetch API keys for cognitive services.
 /// </summary>
 /// <param name="keyName">Name of the service, whose key is fetched</param>
 /// <returns>Key</returns>
 internal static string GetKey(string keyName)
 {
     return(SettingsRegKey.RetrieveStringValue(SettingsKey, keyName, ref _key));
 }