-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement Windows Registry API #6698
Implement Windows Registry API #6698
Conversation
This is a prerequisite for registry's EXPAND_SZ data type.
This is a prerequisite for registry API.
# * `HKEY_LOCAL_MACHINE` | ||
# * `HKEY_USERS` | ||
# * `HKEY_CURRENT_CONFIG` | ||
module 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.
This should be in a Windows
namespace.
b9b2aec
to
94f3fbe
Compare
# Windows 2000: This flag is not supported. | ||
WOW64_64KEY = 0x00100 | ||
|
||
# Combines the STANDARD_RIGHTS_WRITE, `KEY_SET_VALUE`, and `KEY_CREATE_SUB_KEY` access rights. |
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.
` is missing around STANDARD_RIGHTS_WRITE
.
|
||
getter value_count : UInt32 | ||
# size of the key's longest value name, in Unicode characters, not including the terminating null byte. | ||
|
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.
Newline between comment and getter
Please make this a shard. A fully-featured registry wrapper shouldn't be required to access this for timezones, it should be possible to do this using a few raw libc calls. It'll be ugly but thats far better than implementing a purely windows API. After all, they do that in C. |
Yes, it should be possible. But including all error handling etc. around these libc calls, such a bare-bone implementation is far from trivial and would include most of the functionality proposed in this PR. Thus it seems much better to have a full-fledged and fully tested implementation than an ugly purpose-specific one. |
Whatever option gets chosen, I don't want a registry or anything 100% platform-specific exposed directly to the user. I'd even rather shell out to |
I'm fine with a If we only need to read from the registry to extract data in core/stdlib, then maybe we could have a stripped down Anyway, having a properly implemented and tested Registry class is a better idea than shelling out to |
@ysbaddaden i'm fine with whatever as long as it's in |
Or documented for us, but not public (please!) |
What about |
I'm fine with having a full binding to the windows registry in the std. It's not much code either, just 600 lines of code which include comments. |
@straight-shoota https://docs.microsoft.com/en-us/windows/desktop/ipc/named-pipes can substitute for unix sockets most of the time. Might be worth abstracting over both and removing unix sockets in name. |
|
@ysbaddaden thanks for the info! Nice to hear that supporting real unix sockets on windows is possible. However, that further underlines my point that bringing something as intensely platform specific as a user-visible registry implementation into the stdlib, let alone the prelude would be unprecedented and unnecessary. |
BINARY = 3 | ||
DWORD = 4 | ||
DWORD_LITTLE_ENDIAN = DWORD | ||
DWORD_BIG_ENDIAN = 5 |
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.
minor, but weird alignment here (though it's probably crystal tool format
)... the 4
is aligned different from the 5
, likely because the DWORD breaks up the 2 sequences.
# * `HKEY_CURRENT_CONFIG` | ||
module Registry | ||
# Information about file types and their properties. | ||
CLASSES_ROOT = Key.new(LibC::HKEY_CLASSES_ROOT, "HKEY_CLASSES_ROOT") |
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.
I'm curious why you removed the HKEY_ prefix on the const name? As a user of this module I'd expect to find it with the HKEY_ prefix
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.
Because they're redundant. There are no namespaces in C, hence constants and functions are often prefixed by a type/library identifier (like HKEY
). In Crystal it's obvious that they are registry constants because they're defined in the Registry
module.
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.
I can see your argument, but outside of the C-code context, the HKEY prefix has pervaded into everything. It's even in the GUI regedit to the point that that is the actual name of the key now. That was really the thought process behind my statement of "As a user of this module I'd expect to find it with the HKEY_ prefix"
Closing. If we decide to provide a public API for access to the Windows Registry in stdlib later, we can re-issue this implementation. Otherwise it may serve as a basis for a shard. |
This PR adds an API for accessing the Windows Registry.
Access to the Registry is required in the standard library to get proper time zone names (see
Crystal::System::Time.translate_zone_name
, included in this PR) and MIME type mappings (extension to #5765, not yet included).However, the Registry API is obviously only available on win32. Previous discussions (most recently in #6668) have manifested a common understanding that the Crystal standard library should be as much cross-platform as possible.
Having a highly platform-specific Registry API conflicts that proposition. Still, the stdlib needs that API to provide an implementation on win32 for cross-platform features.
I considered stripping down the implementation and moving it to the
Crystal::System
namespace. This would only contain the bare minimum required to implement the missing features for accessing the time and mime databases in the registry. But they already require a huge portion of the features and thus doesn't seem to make much sense as a stripped-down version.Looking at Go, they have the registry API in an external package
golang.org/x/sys/windows/registry
which needs to be imported to use it in user code. But, they also need the registry for the same stdlib implementations and thus provide a copy of that package ininternal/syscall/windows/registry
which is only used by the internal implementation.We could probably go a similar way, but I'm not too happy about maintaining the same code in two repositories.
Maybe it could be somewhat manageable using git subtrees or submodules, but I don't have a clear strategy in mind.
So, before reviewing the implementation of this PR, please consider options for how to include this into the stdlib.