diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9429307..b7c846a 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -4,12 +4,12 @@ jobs:
build:
runs-on: windows-2019
steps:
- - uses: actions/checkout@v3
- - uses: microsoft/setup-msbuild@v1.1
- - uses: NuGet/setup-nuget@v1
- - run: nuget restore src/FirefoxAction.sln
- - run: msbuild src/FirefoxAction.sln -t:rebuild -property:Configuration=Release
- - uses: actions/upload-artifact@v3
+ - uses: actions/checkout@v4
+ - uses: microsoft/setup-msbuild@v2
+ - uses: NuGet/setup-nuget@v2
+ - run: nuget restore FirefoxAction.csproj
+ - run: msbuild FirefoxAction.csproj -t:rebuild -property:Configuration=Release
+ - uses: actions/upload-artifact@v4
with:
name: dll
- path: ./src/bin/Release/FirefoxAction.CA.dll
\ No newline at end of file
+ path: ./bin/Release/net40/FirefoxAction.CA.dll
\ No newline at end of file
diff --git a/src/CustomAction.config b/CustomAction.config
similarity index 100%
rename from src/CustomAction.config
rename to CustomAction.config
diff --git a/src/FirefoxAction.cs b/FirefoxAction.cs
similarity index 68%
rename from src/FirefoxAction.cs
rename to FirefoxAction.cs
index 109c0f1..e757ca6 100644
--- a/src/FirefoxAction.cs
+++ b/FirefoxAction.cs
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2023 Estonian Information System Authority
+ * Copyright (c) 2019-2024 Estonian Information System Authority
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -20,14 +20,18 @@
* SOFTWARE.
*/
-using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;
+using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using System;
+using WixToolset.Dtf.WindowsInstaller;
namespace FirefoxAction
{
public class FirefoxActions
{
+ const string KEY_NAME = "ExtensionSettings";
+
[CustomAction]
public static ActionResult ExtensionSettingsInstall(Session session)
{
@@ -36,18 +40,17 @@ public static ActionResult ExtensionSettingsInstall(Session session)
// with error status 1603, but when letting exceptions through the raw exception
// stack trace will be logged in installer log which gives more information.
- var extensionSettings = GetExtensionSettingsFromSession(session);
+ var extensionSettings = session.GetExtensionSettings();
session.Log("Begin ExtensionSettingsInstall " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
- string value = firefox.GetStringValue("ExtensionSettings", "{}");
- JObject json = JObject.Parse(value);
+ var json = firefox.GetJSON(KEY_NAME, "{}");
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "normal_installed",
["install_url"] = extensionSettings.URL
};
- firefox.SetValue("ExtensionSettings", json.ToString().Split('\n'));
+ firefox.SetValue(KEY_NAME, json.ToString().Split('\n'));
return ActionResult.Success;
}
}
@@ -55,25 +58,49 @@ public static ActionResult ExtensionSettingsInstall(Session session)
[CustomAction]
public static ActionResult ExtensionSettingsRemove(Session session)
{
- var extensionSettings = GetExtensionSettingsFromSession(session);
+ var extensionSettings = session.GetExtensionSettings();
session.Log("Begin ExtensionSettingsRemove " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
- string value = firefox.GetStringValue("ExtensionSettings");
- if (value != null)
+ var json = firefox.GetJSON(KEY_NAME);
+ if (json != null)
{
- JObject json = JObject.Parse(value);
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "blocked"
};
- firefox.SetValue("ExtensionSettings", json.ToString().Split('\n'));
+ firefox.SetValue(KEY_NAME, json.ToString().Split('\n'));
}
- return ActionResult.Success;
}
+ return ActionResult.Success;
}
- private static (string UUID, string URL) GetExtensionSettingsFromSession(Session session)
+ [CustomAction]
+ public static ActionResult ExtensionSettingsFix(Session session)
+ {
+ session.Log("Begin ExtensionSettingsFix");
+ using (RegistryKey firefox = Utils.FirefoxKey())
+ {
+ string value = firefox.GetStringValue(KEY_NAME);
+ if (value != null)
+ {
+ try
+ {
+ JObject.Parse(value);
+ }
+ catch (JsonReaderException)
+ {
+ firefox.DeleteSubKey(KEY_NAME);
+ }
+ }
+ }
+ return ActionResult.Success;
+ }
+ }
+
+ internal static class Utils
+ {
+ internal static (string UUID, string URL) GetExtensionSettings(this Session session)
{
// Deferred custom actions cannot directly access installer properties from session,
// only the CustomActionData property is available, see README how to populate it.
@@ -82,10 +109,7 @@ private static (string UUID, string URL) GetExtensionSettingsFromSession(Session
session.CustomActionData["EXTENSIONSETTINGS_URL"]
);
}
- }
- internal static class Utils
- {
internal static RegistryKey FirefoxKey()
{
using (RegistryKey mozilla = Registry.LocalMachine.OpenOrCreateSubKey(@"Software\Policies\Mozilla", true))
@@ -101,7 +125,7 @@ internal static RegistryKey OpenOrCreateSubKey(this RegistryKey registryKey, str
internal static string GetStringValue(this RegistryKey registryKey, string name, string defaultValue = null)
{
- if (!registryKey.ContainsName(name))
+ if (Array.IndexOf(registryKey.GetValueNames(), name) < 0)
return defaultValue;
switch (registryKey.GetValueKind(name))
{
@@ -114,14 +138,21 @@ internal static string GetStringValue(this RegistryKey registryKey, string name,
}
}
- internal static bool ContainsName(this RegistryKey key, string name)
+ internal static JObject GetJSON(this RegistryKey registryKey, string name, string defaultValue = null)
{
- foreach (string value in key.GetValueNames())
+ string value = registryKey.GetStringValue(name, defaultValue);
+ if (value == null)
+ {
+ return null;
+ }
+ try
+ {
+ return JObject.Parse(value);
+ }
+ catch (JsonReaderException)
{
- if (value == name)
- return true;
+ return new JObject();
}
- return false;
}
}
}
diff --git a/FirefoxAction.csproj b/FirefoxAction.csproj
new file mode 100644
index 0000000..a67b55e
--- /dev/null
+++ b/FirefoxAction.csproj
@@ -0,0 +1,14 @@
+
+
+ net40
+ false
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
similarity index 100%
rename from src/Properties/AssemblyInfo.cs
rename to Properties/AssemblyInfo.cs
diff --git a/src/FirefoxAction.csproj b/src/FirefoxAction.csproj
deleted file mode 100644
index a21ea55..0000000
--- a/src/FirefoxAction.csproj
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-
- Debug
- x86
- 8.0.30703
- 2.0
- {95939208-FE4A-4150-8C6A-DB2B210410FF}
- Library
- Properties
- FirefoxAction
- FirefoxAction
- v4.0
- 512
- Client
-
-
- true
- bin\Debug\
- DEBUG;TRACE
- full
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
- bin\Release\
- TRACE
- true
- pdbonly
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
-
- True
-
-
- packages\Newtonsoft.Json.13.0.1\lib\net40\Newtonsoft.Json.dll
-
-
- packages\System.ValueTuple.4.5.0\lib\portable-net40+sl4+win8+wp8\System.ValueTuple.dll
-
-
-
-
-
-
- Designer
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/FirefoxAction.sln b/src/FirefoxAction.sln
deleted file mode 100644
index a64a565..0000000
--- a/src/FirefoxAction.sln
+++ /dev/null
@@ -1,25 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28307.852
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FirefoxAction", "FirefoxAction.csproj", "{95939208-FE4A-4150-8C6A-DB2B210410FF}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {95939208-FE4A-4150-8C6A-DB2B210410FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {95939208-FE4A-4150-8C6A-DB2B210410FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {95939208-FE4A-4150-8C6A-DB2B210410FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {95939208-FE4A-4150-8C6A-DB2B210410FF}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {3A40CE65-B7CD-4F33-9BA8-CC121ED01543}
- EndGlobalSection
-EndGlobal
diff --git a/src/packages.config b/src/packages.config
deleted file mode 100644
index 669a10a..0000000
--- a/src/packages.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file