-
Notifications
You must be signed in to change notification settings - Fork 585
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
Registry module #1909
Registry module #1909
Changes from 3 commits
5239f07
24176c1
d5d8261
594e3ca
d4358ae
982054e
9845eba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,6 +291,7 @@ let dotnetAssemblyInfos = | |
"Fake.Testing.Common", "Common testing data types" | ||
"Fake.Tracing.NAntXml", "NAntXml" | ||
"Fake.Windows.Chocolatey", "Running and packaging with Chocolatey" | ||
"Fake.Windows.Registry", "CRUD functionality for Windows registry" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add it to Just reference the API-Reference there (no need to add a new markdown documentation) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need help with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry you already added it. |
||
"Fake.Testing.SonarQube", "Analyzing your project with SonarQube" | ||
"Fake.Testing.ReportGenerator", "Convert XML coverage output to various formats" | ||
"Fake.DotNet.Testing.OpenCover", "Code coverage with OpenCover" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# CRUD functionality for Windows registry")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-beta025")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.0.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# CRUD functionality for Windows registry" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.0.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.0.0-beta025" | ||
let [<Literal>] AssemblyFileVersion = "5.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks> | ||
<AssemblyName>Fake.Windows.Registry</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);FX_NO_REMOTING;USE_ASYNC_LOCAL</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Registry.fs" /> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/// Contains functions which allow to read and write information from/to the registry. | ||
module Fake.Windows.Registry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a sample to the reference documentation. We would also like to add |
||
|
||
open Microsoft.Win32 | ||
|
||
/// Registry base keys. | ||
type RegistryBaseKey = | ||
| HKEYLocalMachine | ||
| HKEYClassesRoot | ||
| HKEYUsers | ||
| HKEYCurrentUser | ||
| HKEYCurrentConfig | ||
| HKEYPerformanceData | ||
|
||
/// Maps the RegistryBaseKey to a RegistryKey | ||
/// [omit] | ||
let getKey name = | ||
match name with | ||
| HKEYLocalMachine -> Registry.LocalMachine | ||
| HKEYClassesRoot -> Registry.ClassesRoot | ||
| HKEYUsers -> Registry.Users | ||
| HKEYCurrentUser -> Registry.CurrentUser | ||
| HKEYCurrentConfig -> Registry.CurrentConfig | ||
| HKEYPerformanceData -> Registry.PerformanceData | ||
|
||
/// Maps the RegistryBaseKey to a RegistryKey for a 64bit System | ||
/// [omit] | ||
let get64BitKey name = | ||
match name with | ||
| HKEYLocalMachine -> RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) | ||
| HKEYClassesRoot -> RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64) | ||
| HKEYUsers -> RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64) | ||
| HKEYCurrentUser -> RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64) | ||
| HKEYCurrentConfig -> RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry64) | ||
| HKEYPerformanceData -> RegistryKey.OpenBaseKey(RegistryHive.PerformanceData, RegistryView.Registry64) | ||
|
||
/// Maps the RegistryBaseKey to a RegistryKey for a 32bit System | ||
/// [omit] | ||
let get32BitKey name = | ||
match name with | ||
| HKEYLocalMachine -> RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) | ||
| HKEYClassesRoot -> RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry32) | ||
| HKEYUsers -> RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry32) | ||
| HKEYCurrentUser -> RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32) | ||
| HKEYCurrentConfig -> RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry32) | ||
| HKEYPerformanceData -> RegistryKey.OpenBaseKey(RegistryHive.PerformanceData, RegistryView.Registry32) | ||
|
||
/// Gets a 64-bit registry key | ||
let getRegistryKey64 baseKey subKey (writePermission : bool) = | ||
(get64BitKey baseKey).OpenSubKey(subKey, writePermission) | ||
|
||
/// Gets a registry key and falls back to 32 bit if the 64bit key is not there | ||
let getRegistryKey baseKey subKey (writePermission : bool) = | ||
let x64BitKey = (getKey baseKey).OpenSubKey(subKey, writePermission) | ||
if (isNull >> not) x64BitKey then x64BitKey else | ||
(get32BitKey baseKey).OpenSubKey(subKey, writePermission) // fall back to 32 bit | ||
|
||
/// Gets a registry value as string | ||
let getRegistryValue baseKey subKey name = | ||
use key = getRegistryKey baseKey subKey false | ||
if isNull key then | ||
failwithf "Registry subkey %s could not be found for key %A" subKey baseKey | ||
let value = key.GetValue name | ||
if isNull value then | ||
failwithf "Registry value is null for key %s" (key.ToString()) | ||
value.ToString() | ||
|
||
/// Gets a registry value as string | ||
let getRegistryValue64 baseKey subKey name = | ||
use key = getRegistryKey64 baseKey subKey false | ||
if isNull key then | ||
failwithf "Registry subkey %s could not be found for key %A" subKey baseKey | ||
let value = key.GetValue name | ||
if isNull value then | ||
failwithf "Registry value is null for key %s" (key.ToString()) | ||
value.ToString() | ||
|
||
/// Sets a registry value | ||
let setRegistryValue<'T> baseKey subKey name (value : 'T) = | ||
use key = getRegistryKey baseKey subKey true | ||
key.SetValue(name, value) | ||
|
||
/// Deletes the registry value from its key | ||
let deleteRegistryValue baseKey subKey name = | ||
use key = getRegistryKey baseKey subKey true | ||
key.DeleteValue name | ||
|
||
/// Returns all the value names of a registry key | ||
let getRegistryValueNames baseKey subKey = | ||
use key = getRegistryKey baseKey subKey false | ||
key.GetValueNames() | ||
|
||
/// Returns whether or not a registry value name exists for a key | ||
let valueExistsForKey = fun baseKey subKey name -> | ||
getRegistryValueNames baseKey subKey | ||
|> Seq.exists (fun n -> n = name) | ||
|
||
/// Create a registry subKey | ||
let createRegistrySubKey baseKey subKey = | ||
use key = getKey baseKey | ||
key.CreateSubKey subKey |> ignore | ||
|
||
/// Deletes a registry subKey | ||
let deleteRegistrySubKey baseKey subKey = | ||
use key = getKey baseKey | ||
key.DeleteSubKey subKey | ||
|
||
/// Returns all the subKey names of a registry key | ||
let getRegistrySubKeyNames baseKey subKey = | ||
use key = getRegistryKey baseKey subKey false | ||
key.GetSubKeyNames() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
group netcore | ||
|
||
FSharp.Core | ||
NETStandard.Library | ||
Microsoft.Win32.Registry |
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.
Can we remove this change?
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.
Yep, just autogenerated msvc stuff, didn't realize that was added in
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.
Oh actually, it looks like we need that. That's in the current master of fake.sln as well