Skip to content

Commit

Permalink
Handle String values
Browse files Browse the repository at this point in the history
IB-7521

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored and mrts committed Sep 20, 2022
1 parent 4f65368 commit a0d9549
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/FirefoxAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static ActionResult ExtensionSettingsInstall(Session session)
session.Log("Begin ExtensionSettingsInstall " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
string[] value = (string[])firefox.GetValue("ExtensionSettings", new string[] { "{}" });
JObject json = JObject.Parse(string.Join("\n", value));
string value = firefox.GetStringValue("ExtensionSettings", "{}");
JObject json = JObject.Parse(value);
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "normal_installed",
Expand All @@ -59,10 +59,10 @@ public static ActionResult ExtensionSettingsRemove(Session session)
session.Log("Begin ExtensionSettingsRemove " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
string[] value = (string[])firefox.GetValue("ExtensionSettings");
string value = firefox.GetStringValue("ExtensionSettings");
if (value != null)
{
JObject json = JObject.Parse(string.Join("\n", value));
JObject json = JObject.Parse(value);
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "blocked"
Expand Down Expand Up @@ -98,5 +98,18 @@ internal static RegistryKey OpenOrCreateSubKey(this RegistryKey registryKey, str
{
return registryKey.OpenSubKey(name, writable) ?? registryKey.CreateSubKey(name);
}

internal static string GetStringValue(this RegistryKey registryKey, string name, string defaultValue = null)
{
switch (registryKey.GetValueKind(name))
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return (string)registryKey.GetValue(name, defaultValue);
case RegistryValueKind.MultiString:
return string.Join("\n", (string[])registryKey.GetValue(name));
default: return defaultValue;
}
}
}
}

0 comments on commit a0d9549

Please sign in to comment.