ObjFW  Check-in [deb57aa653]

Overview
Comment:Clean up OFWindowsRegistryKey API
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: deb57aa653e34c473bf345bc4d23f1d25d61aa0ee01a2a1b6fc4b4ab766c89c4
User & Date: js on 2022-09-11 11:46:16
Other Links: manifest | tags
Context
2022-09-12
08:52
Restrict subclassing on more classes check-in: 1038191a03 user: js tags: trunk
2022-09-11
11:46
Clean up OFWindowsRegistryKey API check-in: deb57aa653 user: js tags: trunk
2022-09-10
09:24
Don't install OFWin32ConsoleStdIOStream.h check-in: daa3e3177a user: js tags: trunk
Changes

Modified src/OFDNSResolverSettings.m from [204140ead1] to [27f5b4db4d].

619
620
621
622
623
624
625
626


627
628
629
630
631
632
633
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633
634







-
+
+







	[self setDefaults];

#if defined(OF_WINDOWS)
# ifdef OF_HAVE_FILES
	OFWindowsRegistryKey *key = [[OFWindowsRegistryKey localMachineKey]
		   openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\"
				     @"Tcpip\\Parameters"
	    securityAndAccessRights: KEY_QUERY_VALUE];
		       accessRights: KEY_QUERY_VALUE
			    options: 0];
	path = [[[key stringForValueNamed: @"DataBasePath"]
	    stringByAppendingPathComponent: @"hosts"]
	    stringByExpandingWindowsEnvironmentStrings];

	if (path != nil)
		[self parseHosts: path];
# endif

Modified src/OFWindowsRegistryKey.h from [c114c8ff33] to [ad68073b0d].

70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118

119
120
121



122

123
124
125
126
127
128

129
130
131
132




133
134
135
136
137
138
139
70
71
72
73
74
75
76


77
78









79
80


81
82
83
84

85


86
87
88
89
90













91



92
93
94
95
96
97
98

99
100
101
102
103
104

105




106
107
108
109
110
111
112
113
114
115
116







-
-
+
+
-
-
-
-
-
-
-
-
-


-
-



+
-
+
-
-





-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+



+
+
+
-
+





-
+
-
-
-
-
+
+
+
+








- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Opens the subkey at the specified path.
 *
 * @param path The path of the subkey to open
 * @param securityAndAccessRights Please refer to the `RegOpenKeyEx()`
 *				  documentation for `samDesired`
 * @param accessRights Please refer to the `RegOpenKeyEx()` documentation for
 *		       `samDesired`
 * @return The subkey with the specified path
 */
- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
		   securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @brief Opens the subkey at the specified path.
 *
 * @param path The path of the subkey to open
 * @param options Please refer to the `RegOpenKeyEx()` documentation for
 *		  `ulOptions`. Usually 0.
 * @param securityAndAccessRights Please refer to the `RegOpenKeyEx()`
 *				  documentation for `samDesired`
 * @return The subkey with the specified path
 */
- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
			      accessRights: (REGSAM)accessRights
				   options: (DWORD)options
				   options: (DWORD)options;
		   securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @brief Creates a subkey at the specified path or opens it if it already
 *	  exists.
 *
 * @param path The path of the subkey to create
 * @param securityAndAccessRights Please refer to the `RegCreateKeyEx()`
 *				  documentation for `samDesired`
 * @return The subkey with the specified path
 */
- (OFWindowsRegistryKey *)createSubkeyAtPath: (OFString *)path
		     securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @brief Creates a subkey at the specified path or opens it if it already
 *	  exists.
 *
 * @param path The path of the subkey to create
 * @param options Please refer to the `RegCreateKeyEx()` documentation.
 * @param accessRights Please refer to the `RegCreateKeyEx()` documentation for
 *		  Usually 0.
 * @param securityAndAccessRights Please refer to the `RegCreateKeyEx()`
 *				  documentation for `samDesired`
 *		       `samDesired`
 * @param securityAttributes Please refer to the `RegCreateKeyEx()`
 *			     documentation for `lpSecurityAttributes`. Usually
 *			     NULL.
 * @param options Please refer to the `RegCreateKeyEx()` documentation for
 *		  `dwOptions`. Usually 0.
 * @param disposition A pointer to a variable that will be set to whether the
 * @param disposition Whether the key was created or already existed. Please
 *		      key was created or already existed, or `NULL`. Please
 *		      refer to the `RegCreateKeyEx()` documentation for
 *		      `lpdwDisposition`.
 * @return The subkey with the specified path
 */
- (OFWindowsRegistryKey *)
	 createSubkeyAtPath: (OFString *)path
    createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes
		disposition: (nullable DWORD *)disposition;
	  accessRights: (REGSAM)accessRights
    securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes
	       options: (DWORD)options
	   disposition: (nullable DWORD *)disposition;

/**
 * @brief Returns the data for the specified value at the specified path.
 *
 * @param name The name of the value to return
 * @param type A pointer to store the type of the value, or NULL
 * @return The data for the specified value

Modified src/OFWindowsRegistryKey.m from [d93d6521e9] to [bf1674ca4d].

89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117

118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149




150
151
152
153
154
155
156
157
158


159
160
161
162

163
164
165
166
167
168
169
170

171

172
173
174
175
176
177
178
89
90
91
92
93
94
95

96







97

98
99
100
101
102
103
104

105
106
107
108

109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125










126

127




128
129
130
131
132
133
134
135
136
137
138


139
140
141
142
143

144

145
146
147
148
149


150
151
152
153
154
155
156
157
158
159







-
+
-
-
-
-
-
-
-

-







-
+



-
+





+

-









-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
+
+
+
+







-
-
+
+



-
+
-





-
-
+

+







	if (_close)
		RegCloseKey(_hKey);

	[super dealloc];
}

- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
		   securityAndAccessRights: (REGSAM)securityAndAccessRights
			      accessRights: (REGSAM)accessRights
{
	return [self openSubkeyAtPath: path
			      options: 0
	      securityAndAccessRights: securityAndAccessRights];
}

- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
				   options: (DWORD)options
		   securityAndAccessRights: (REGSAM)securityAndAccessRights
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;
	HKEY subKey;

	if ([OFSystemInfo isWindowsNT])
		status = RegOpenKeyExW(_hKey, path.UTF16String, options,
		    securityAndAccessRights, &subKey);
		    accessRights, &subKey);
	else
		status = RegOpenKeyExA(_hKey,
		    [path cStringWithEncoding: [OFLocale encoding]], options,
		    securityAndAccessRights, &subKey);
		    accessRights, &subKey);

	if (status != ERROR_SUCCESS)
		@throw [OFOpenWindowsRegistryKeyFailedException
		    exceptionWithRegistryKey: self
					path: path
				accessRights: accessRights
				     options: options
		     securityAndAccessRights: securityAndAccessRights
				      status: status];

	objc_autoreleasePoolPop(pool);

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];
}

- (OFWindowsRegistryKey *)createSubkeyAtPath: (OFString *)path
		     securityAndAccessRights: (REGSAM)securityAndAccessRights
{
	return [self createSubkeyAtPath: path
				options: 0
		securityAndAccessRights: securityAndAccessRights
		     securityAttributes: NULL
			    disposition: NULL];
}

- (OFWindowsRegistryKey *)
	 createSubkeyAtPath: (OFString *)path
    createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		disposition: (DWORD *)disposition
	  accessRights: (REGSAM)accessRights
    securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
	       options: (DWORD)options
	   disposition: (DWORD *)disposition
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;
	HKEY subKey;

	if ([OFSystemInfo isWindowsNT])
		status = RegCreateKeyExW(_hKey, path.UTF16String, 0,
		    NULL, options, securityAndAccessRights, securityAttributes,
		    &subKey, NULL);
		    NULL, options, accessRights, securityAttributes, &subKey,
		    NULL);
	else
		status = RegCreateKeyExA(_hKey,
		    [path cStringWithEncoding: [OFLocale encoding]], 0, NULL,
		    options, securityAndAccessRights, securityAttributes,
		    options, accessRights, securityAttributes, &subKey, NULL);
		    &subKey, NULL);

	if (status != ERROR_SUCCESS)
		@throw [OFCreateWindowsRegistryKeyFailedException
		    exceptionWithRegistryKey: self
					path: path
				     options: options
		     securityAndAccessRights: securityAndAccessRights
				accessRights: accessRights
			  securityAttributes: securityAttributes
				     options: options
				      status: status];

	objc_autoreleasePoolPop(pool);

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];

Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.h from [f321fddf5e] to [10755ff9ec].

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59

60
61
62
63
64
65
66





67
68
69
70
71
72
73
74
75
76
77
78

79
80

81
82

83
84
85
86
87
88
89
90

91

92
93
94
95
96
97
98
99
100
101
102

103
104

105
106

107
108
109
110
111
112
113
114

115

116
117
118
119
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50






51

52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77


78
79
80
81
82
83
84
85
86
87


88
89
90
91
92
93
94
95
96
97
98
99
100

101


102
103
104
105
106
107
108
109
110
111


112
113
114
115
116
117
118







-
+















-
-
-
-
-
-
+
-

-
+







+
+
+
+
+











-
+
-
-
+


+






-
-
+

+










-
+
-
-
+


+






-
-
+

+




 * @brief An exception indicating that creating a Windows registry key failed.
 */
@interface OFCreateWindowsRegistryKeyFailedException: OFException
{
	OFWindowsRegistryKey *_registryKey;
	OFString *_path;
	DWORD _options;
	REGSAM _securityAndAccessRights;
	REGSAM _accessRights;
	LPSECURITY_ATTRIBUTES _Nullable _securityAttributes;
	LSTATUS _status;
}

/**
 * @brief The registry key on which creating the subkey failed.
 */
@property (readonly, nonatomic) OFWindowsRegistryKey *registryKey;

/**
 * @brief The path for the subkey that could not be created.
 */
@property (readonly, nonatomic) OFString *path;

/**
 * @brief The options for the subkey that could not be created.
 */
@property (readonly, nonatomic) DWORD options;

/**
 * @brief The security and access rights for the subkey that could not be
 * @brief The access rights for the subkey that could not be created.
 *	  created.
 */
@property (readonly, nonatomic) REGSAM securityAndAccessRights;
@property (readonly, nonatomic) REGSAM accessRights;

/**
 * @brief The security options for the subkey that could not be created.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    LPSECURITY_ATTRIBUTES securityAttributes;

/**
 * @brief The options for the subkey that could not be created.
 */
@property (readonly, nonatomic) DWORD options;

/**
 * @brief The status returned by RegCreateKeyEx().
 */
@property (readonly, nonatomic) LSTATUS status;

/**
 * @brief Creates a new, autoreleased create Windows registry key failed
 *	  exception.
 *
 * @param registryKey The registry key on which creating the subkey failed
 * @param path The path for the subkey that could not be created
 * @param options The options for the subkey that could not be created
 * @param accessRights The access rights for the sub key that could not be
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 *		       created
 * @param securityAttributes The security options for the subkey that could
 *			     not be created
 * @param options The options for the subkey that could not be created
 * @param status The status returned by RegCreateKeyEx()
 * @return A new, autoreleased creates Windows registry key failed exception
 */
+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		accessRights: (REGSAM)accessRights
	  securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes
		     options: (DWORD)options
		      status: (LSTATUS)status;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated create Windows registry key failed
 *	  exception.
 *
 * @param registryKey The registry key on which creating the subkey failed
 * @param path The path for the subkey that could not be created
 * @param options The options for the subkey that could not be created
 * @param accessRights The access rights for the sub key that could not be
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 *		       created
 * @param securityAttributes The security options for the subkey that could
 *			     not be created
 * @param options The options for the subkey that could not be created
 * @param status The status returned by RegCreateKeyEx()
 * @return An initialized create Windows registry key failed exception
 */
- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	       accessRights: (REGSAM)accessRights
	 securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes
		    options: (DWORD)options
		     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.m from [661d98b08e] to [3f8a5e58b7].

14
15
16
17
18
19
20
21
22
23




24
25
26
27
28
29

30

31
32
33
34
35
36

37

38
39
40
41
42
43
44
45
46
47
48


49
50
51
52




53
54
55
56
57
58
59
60

61

62
63
64
65
66
67
68
14
15
16
17
18
19
20



21
22
23
24
25
26
27
28


29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
45
46



47
48




49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66
67
68







-
-
-
+
+
+
+




-
-
+

+




-
-
+

+








-
-
-
+
+
-
-
-
-
+
+
+
+






-
-
+

+







 */

#include "config.h"

#import "OFCreateWindowsRegistryKeyFailedException.h"

@implementation OFCreateWindowsRegistryKeyFailedException
@synthesize registryKey = _registryKey, path = _path, options = _options;
@synthesize securityAndAccessRights = _securityAndAccessRights;
@synthesize securityAttributes = _securityAttributes, status = _status;
@synthesize registryKey = _registryKey, path = _path;
@synthesize accessRights = _accessRights;
@synthesize securityAttributes = _securityAttributes, options = _options;
@synthesize status = _status;

+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		accessRights: (REGSAM)accessRights
	  securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		     options: (DWORD)options
		      status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					     path: path
					  options: options
			  securityAndAccessRights: securityAndAccessRights
				     accessRights: accessRights
			       securityAttributes: securityAttributes
					  options: options
					   status: status] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		     status: (LSTATUS)status
		       accessRights: (REGSAM)accessRights
		 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
			    options: (DWORD)options
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_path = [path copy];
		_options = options;
		_securityAndAccessRights = securityAndAccessRights;
		_accessRights = accessRights;
		_securityAttributes = securityAttributes;
		_options = options;
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;

Modified src/exceptions/OFGetWindowsRegistryValueFailedException.h from [733c657ffd] to [15ecc19a56].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40







-







 *
 * @brief An exception indicating that getting a Windows registry value failed.
 */
@interface OFGetWindowsRegistryValueFailedException: OFException
{
	OFWindowsRegistryKey *_registryKey;
	OFString *_Nullable _valueName;
	DWORD _flags;
	LSTATUS _status;
}

/**
 * @brief The registry key on which getting the value at the key path failed.
 */
@property (readonly, nonatomic) OFWindowsRegistryKey *registryKey;

Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.h from [5fb8a73f7a] to [883198f087].

27
28
29
30
31
32
33
34
35

36

37
38
39
40
41
42
43
44
45
46
47
48
49





50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


72
73
74
75
76
77
78
79
80
81




82
83

84
85
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102




103
104

105
106
107
108
109
27
28
29
30
31
32
33


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59






60
61
62
63
64
65
66
67
68
69
70
71
72
73


74
75
76




77
78
79
80


81
82
83
84
85
86
87
88
89
90
91
92
93


94
95
96




97
98
99
100


101
102
103
104
105
106







-
-
+

+













+
+
+
+
+





-
-
-
-
-
-











+
+

-
-



-
-
-
-
+
+
+
+
-
-
+









+
+

-
-



-
-
-
-
+
+
+
+
-
-
+





 *
 * @brief An exception indicating that opening a Windows registry key failed.
 */
@interface OFOpenWindowsRegistryKeyFailedException: OFException
{
	OFWindowsRegistryKey *_registryKey;
	OFString *_path;
	DWORD _options;
	REGSAM _securityAndAccessRights;
	REGSAM _accessRights;
	LPSECURITY_ATTRIBUTES _Nullable _securityAttributes;
	DWORD _options;
	LSTATUS _status;
}

/**
 * @brief The registry key on which opening the subkey failed.
 */
@property (readonly, nonatomic) OFWindowsRegistryKey *registryKey;

/**
 * @brief The path for the subkey that could not be opened.
 */
@property (readonly, nonatomic) OFString *path;

/**
 * @brief The access rights for the subkey that could not be opened.
 */
@property (readonly, nonatomic) REGSAM accessRights;

/**
 * @brief The options for the subkey that could not be opened.
 */
@property (readonly, nonatomic) DWORD options;

/**
 * @brief The security and access rights for the subkey that could not be
 *	  opened.
 */
@property (readonly, nonatomic) REGSAM securityAndAccessRights;

/**
 * @brief The status returned by RegOpenKeyEx().
 */
@property (readonly, nonatomic) LSTATUS status;

/**
 * @brief Creates a new, autoreleased open Windows registry key failed
 *	  exception.
 *
 * @param registryKey The registry key on which opening the subkey failed
 * @param path The path for the subkey that could not be opened
 * @param accessRights The access rights for the sub key that could not be
 *		       opened
 * @param options The options for the subkey that could not be opened
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be opened
 * @param status The status returned by RegOpenKeyEx()
 * @return A new, autoreleased open Windows registry key failed exception
 */
+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				    path: (OFString *)path
			    accessRights: (REGSAM)accessRights
				 options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		      status: (LSTATUS)status;
				  status: (LSTATUS)status;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated open Windows registry key failed
 *	  exception.
 *
 * @param registryKey The registry key on which opening the subkey failed
 * @param path The path for the subkey that could not be opened
 * @param accessRights The access rights for the sub key that could not be
 *		       opened
 * @param options The options for the subkey that could not be opened
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be opened
 * @param status The status returned by RegOpenKeyEx()
 * @return An initialized open Windows registry key failed exception
 */
- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
		    options: (DWORD)options
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		       accessRights: (REGSAM)accessRights
			    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
		     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
			     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.m from [52118b22c0] to [64b24e1261].

14
15
16
17
18
19
20
21

22
23

24
25
26
27
28




29
30

31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47




48
49

50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
14
15
16
17
18
19
20

21


22
23




24
25
26
27


28
29
30
31
32
33

34
35
36
37
38
39
40
41




42
43
44
45


46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61







-
+
-
-
+

-
-
-
-
+
+
+
+
-
-
+



+

-








-
-
-
-
+
+
+
+
-
-
+






+

-







 */

#include "config.h"

#import "OFOpenWindowsRegistryKeyFailedException.h"

@implementation OFOpenWindowsRegistryKeyFailedException
@synthesize registryKey = _registryKey, path = _path, options = _options;
@synthesize registryKey = _registryKey, path = _path;
@synthesize securityAndAccessRights = _securityAndAccessRights;
@synthesize status = _status;
@synthesize accessRights = _accessRights, options = _options, status = _status;

+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				    path: (OFString *)path
			    accessRights: (REGSAM)accessRights
				 options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		      status: (LSTATUS)status
				  status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					     path: path
				     accessRights: accessRights
					  options: options
			  securityAndAccessRights: securityAndAccessRights
					   status: status] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
		    options: (DWORD)options
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		       accessRights: (REGSAM)accessRights
			    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
		     status: (LSTATUS)status
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_path = [path copy];
		_accessRights = accessRights;
		_options = options;
		_securityAndAccessRights = securityAndAccessRights;
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;

Modified tests/OFWindowsRegistryKeyTests.m from [60470d17f4] to [ddf274227c].

38
39
40
41
42
43
44
45

46
47
48



49
50

51
52
53
54



55
56


57
58




59
60
61
62
63
64
65
38
39
40
41
42
43
44

45
46


47
48
49
50

51
52
53


54
55
56
57

58
59
60

61
62
63
64
65
66
67
68
69
70
71







-
+

-
-
+
+
+

-
+


-
-
+
+
+

-
+
+

-
+
+
+
+








	TEST(@"+[OFWindowsRegistryKey localMachineKey]",
	    [OFWindowsRegistryKey localMachineKey])

	TEST(@"+[OFWindowsRegistryKey usersKey]",
	    [OFWindowsRegistryKey usersKey])

	TEST(@"-[openSubkeyAtPath:securityAndAccessRights:] #1",
	    TEST(@"-[openSubkeyAtPath:accessRights:options:] #1",
	    (softwareKey = [[OFWindowsRegistryKey currentUserKey]
		   openSubkeyAtPath: @"Software"
	    securityAndAccessRights: KEY_ALL_ACCESS]))
		openSubkeyAtPath: @"Software"
		    accessRights: KEY_ALL_ACCESS
			 options: 0]))

	EXPECT_EXCEPTION(@"-[openSubkeyAtPath:securityAndAccessRights:] #2",
	EXPECT_EXCEPTION(@"-[openSubkeyAtPath:accessRights:options:] #2",
	    OFOpenWindowsRegistryKeyFailedException,
	    [[OFWindowsRegistryKey currentUserKey]
		   openSubkeyAtPath: @"nonexistent"
	    securityAndAccessRights: KEY_ALL_ACCESS])
		openSubkeyAtPath: @"nonexistent"
		    accessRights: KEY_ALL_ACCESS
			 options: 0])

	TEST(@"-[createSubkeyAtPath:securityAndAccessRights:]",
	TEST(@"-[createSubkeyAtPath:accessRights:securityAttributes:options:"
	    @"disposition:]",
	    (objFWKey = [softwareKey createSubkeyAtPath: @"ObjFW"
				securityAndAccessRights: KEY_ALL_ACCESS]))
					   accessRights: KEY_ALL_ACCESS
				     securityAttributes: NULL
						options: 0
					    disposition: NULL]))

	TEST(@"-[setData:forValueNamed:type:]",
	    R([objFWKey setData: data forValueNamed: @"data" type: REG_BINARY]))

	TEST(@"-[dataForValueNamed:subkeyPath:flags:type:]",
	    [[objFWKey dataForValueNamed: @"data" type: &type] isEqual: data] &&
	    type == REG_BINARY)