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 76% rename from src/FirefoxAction.cs rename to FirefoxAction.cs index 109c0f1..3e12e41 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.Linq; +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,27 @@ 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) + 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 +87,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 +103,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 (!registryKey.GetValueNames().Any(name.Equals)) return defaultValue; switch (registryKey.GetValueKind(name)) { @@ -114,14 +116,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..8a0f19e --- /dev/null +++ b/FirefoxAction.csproj @@ -0,0 +1,15 @@ + + + net40 + Copyright © 2019 + RIA + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index f191874..6dacc49 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,11 @@ The custom actions must be scheduled in `InstallExecuteSequence` as follows: - NOT ((REMOVE="ALL") AND (NOT UPGRADINGPRODUCTCODE)) + NOT REMOVE="ALL" - (REMOVE="ALL") AND (NOT UPGRADINGPRODUCTCODE) + REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE 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/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs deleted file mode 100644 index a0d6e06..0000000 --- a/src/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("FirefoxAction")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyCompany("RIA")] -[assembly: AssemblyProduct("FirefoxAction")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("95939208-fe4a-4150-8c6a-db2b210410ff")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] 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