Repository navigation
Import wix-custom-action-firefox-extension-install and use built binary #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| bin/ | ||
| obj/ | ||
| packages/ | ||
| .vs/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <startup useLegacyV2RuntimeActivationPolicy="true"> | ||
|
|
||
| <!-- | ||
| Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that | ||
| the custom action should run on. If no versions are specified, the chosen version of the runtime | ||
| will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against. | ||
|
|
||
| WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility | ||
| problems with future versions of the .NET Framework runtime. It is highly recommended that you specify | ||
| only the version(s) of the .NET Framework runtime that you have tested against. | ||
|
|
||
| Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0. | ||
|
|
||
| In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies | ||
| by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true". | ||
|
|
||
| For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx | ||
| --> | ||
|
|
||
| <supportedRuntime version="v4.0" /> | ||
| <!--supportedRuntime version="v2.0.50727"/--> | ||
|
|
||
| </startup> | ||
|
|
||
| <!-- | ||
| Add additional configuration settings here. For more information on application config files, | ||
| see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx | ||
| --> | ||
|
|
||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * 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 | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| 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) | ||
| { | ||
| // Instead of catching and logging errors and returning ActionResult.Failure, | ||
| // we simply let all exceptions through. In both cases the installation fails | ||
| // 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 = session.GetExtensionSettings(); | ||
| session.Log("Begin ExtensionSettingsInstall " + extensionSettings.UUID); | ||
| using (RegistryKey firefox = Utils.FirefoxKey()) | ||
| { | ||
| var json = firefox.GetJSON(KEY_NAME, "{}"); | ||
| json[extensionSettings.UUID] = new JObject | ||
| { | ||
| ["installation_mode"] = "normal_installed", | ||
| ["install_url"] = extensionSettings.URL | ||
| }; | ||
| firefox.SetValue(KEY_NAME, json.ToString().Replace("\r\n", "\n").Split('\n')); | ||
| return ActionResult.Success; | ||
| } | ||
| } | ||
|
|
||
| [CustomAction] | ||
| public static ActionResult ExtensionSettingsRemove(Session session) | ||
| { | ||
| var extensionSettings = session.GetExtensionSettings(); | ||
| session.Log("Begin ExtensionSettingsRemove " + extensionSettings.UUID); | ||
| using (RegistryKey firefox = Utils.FirefoxKey()) | ||
| { | ||
| var json = firefox.GetJSON(KEY_NAME); | ||
| if (json != null) | ||
| { | ||
| json[extensionSettings.UUID] = new JObject | ||
| { | ||
| ["installation_mode"] = "blocked" | ||
| }; | ||
| firefox.SetValue(KEY_NAME, json.ToString().Replace("\r\n", "\n").Split('\n')); | ||
| } | ||
| } | ||
| 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. | ||
| return ( | ||
| session.CustomActionData["EXTENSIONSETTINGS_UUID"], | ||
| session.CustomActionData["EXTENSIONSETTINGS_URL"] | ||
| ); | ||
| } | ||
|
|
||
| internal static RegistryKey FirefoxKey() | ||
| { | ||
| using (RegistryKey mozilla = Registry.LocalMachine.OpenOrCreateSubKey(@"Software\Policies\Mozilla", true)) | ||
| { | ||
| return mozilla.OpenOrCreateSubKey(@"Firefox", true); | ||
| } | ||
| } | ||
|
|
||
| internal static RegistryKey OpenOrCreateSubKey(this RegistryKey registryKey, string name, bool writable = false) | ||
| { | ||
| return registryKey.OpenSubKey(name, writable) ?? registryKey.CreateSubKey(name); | ||
| } | ||
|
|
||
| internal static string GetStringValue(this RegistryKey registryKey, string name, string defaultValue = null) | ||
| { | ||
| if (!registryKey.GetValueNames().Any(name.Equals)) | ||
| return defaultValue; | ||
| 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; | ||
| } | ||
| } | ||
|
|
||
| internal static JObject GetJSON(this RegistryKey registryKey, string name, string defaultValue = null) | ||
| { | ||
| string value = registryKey.GetStringValue(name, defaultValue); | ||
| if (value == null) | ||
| { | ||
| return null; | ||
| } | ||
| try | ||
| { | ||
| return JObject.Parse(value); | ||
| } | ||
| catch (JsonReaderException) | ||
| { | ||
| return new JObject(); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net48</TargetFramework> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <Copyright>Copyright © 2019</Copyright> | ||
| <Company>RIA</Company> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Content Include="CustomAction.config" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> | ||
| <PackageReference Include="WixToolset.Dtf.CustomAction" Version="4.0.5" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2021-2023 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 | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # WiX custom action for installing a Firefox extension with enterprise policy | ||
|
|
||
| *FirefoxAction* is a custom action for WiX that installs the given Firefox | ||
| extension with the Firefox enterprise policy engine. | ||
|
|
||
| The custom action should be added to a WiX project as follows, it must be deferred | ||
| and not use impersonation (i.e. run in privileged mode for registry access): | ||
|
|
||
| <Binary Id="FirefoxAction.CA.dll" SourceFile="$(sys.SOURCEFILEDIR)FirefoxAction.CA.dll" /> | ||
| <CustomAction Id="ExtensionSettingsInstall" Return="check" Execute="deferred" Impersonate="no" | ||
| BinaryKey="FirefoxAction.CA.dll" DllEntry="ExtensionSettingsInstall" /> | ||
| <CustomAction Id="ExtensionSettingsRemove" Return="check" Execute="deferred" Impersonate="no" | ||
| BinaryKey="FirefoxAction.CA.dll" DllEntry="ExtensionSettingsRemove" /> | ||
|
|
||
| The Firefox extension UUID and AMO URL must be passed in via `CustomSettingsData` properties via | ||
| dedicated custom actions as follows: | ||
|
|
||
| <CustomAction Id="SetExtensionSettingsForInstall" Property="ExtensionSettingsInstall" | ||
| Value="EXTENSIONSETTINGS_UUID=$(var.FIREFOX_UUID);EXTENSIONSETTINGS_URL=$(var.FIREFOX_URL)" /> | ||
| <CustomAction Id="SetExtensionSettingsForRemove" Property="ExtensionSettingsRemove" | ||
| Value="EXTENSIONSETTINGS_UUID=$(var.FIREFOX_UUID);EXTENSIONSETTINGS_URL=$(var.FIREFOX_URL)" /> | ||
|
|
||
| The custom actions must be scheduled in `InstallExecuteSequence` as follows: | ||
|
|
||
| <InstallExecuteSequence> | ||
| <Custom Action="SetExtensionSettingsForInstall" Before="InstallInitialize" /> | ||
| <Custom Action="ExtensionSettingsInstall" Before="InstallFinalize"> | ||
| NOT REMOVE="ALL" | ||
| </Custom> | ||
| <Custom Action="SetExtensionSettingsForRemove" Before="InstallInitialize" /> | ||
| <Custom Action="ExtensionSettingsRemove" Before="InstallFinalize"> | ||
| REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE | ||
| </Custom> | ||
| </InstallExecuteSequence> | ||
|
|
||
| The code has been forked from the [OpenEID Windows installer project](https://github.com/open-eid/windows-installer/blob/master/FirefoxActionWix/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that FirefoxAction.csproj:3 changes net40 to net48, but Windows 8.1 ships with .NET 4.5.1. But as Windows 8.1 is not officially supported, this can remain as-is.