ObjFW  Diff

Differences From Artifact [752886f486]:

To Artifact [bed1fd3ca5]:


22
23
24
25
26
27
28

29
30
31
32
33
34
35

#include <windows.h>

#import "OFCreateWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"

#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"

@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <windows.h>

#import "OFCreateWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"

@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
}

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

	if ((status = RegCreateKeyExW(_hKey, path.UTF16String, 0,
	    NULL, options, securityAndAccessRights, securityAttributes,







|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
}

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

	if ((status = RegCreateKeyExW(_hKey, path.UTF16String, 0,
	    NULL, options, securityAndAccessRights, securityAttributes,
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

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

- (OFData *)dataForValue: (OFString *)value
		    type: (LPDWORD)type
{
	void *pool = objc_autoreleasePoolPush();
	BYTE stackBuffer[256], *buffer = stackBuffer;
	DWORD length = sizeof(stackBuffer);
	OFMutableData *ret = nil;
	LSTATUS status;








|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

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

- (OFData *)dataForValue: (OFString *)value
		    type: (DWORD *)type
{
	void *pool = objc_autoreleasePoolPush();
	BYTE stackBuffer[256], *buffer = stackBuffer;
	DWORD length = sizeof(stackBuffer);
	OFMutableData *ret = nil;
	LSTATUS status;

241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258



259
260
261
262
263
264
265
- (OFString *)stringForValue: (OFString *)value
{
	return [self stringForValue: value
			       type: NULL];
}

- (OFString *)stringForValue: (OFString *)value
			type: (LPDWORD)type
{
	void *pool = objc_autoreleasePoolPush();

	OFData *data = [self dataForValue: value
				     type: type];
	const of_char16_t *UTF16String;
	size_t length;
	OFString *ret;

	if (data == nil)
		return nil;




	UTF16String = data.items;
	length = data.count;

	if (data.itemSize != 1 || length % 2 == 1)
		@throw [OFInvalidFormatException exception];








|


>

|






>
>
>







242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
- (OFString *)stringForValue: (OFString *)value
{
	return [self stringForValue: value
			       type: NULL];
}

- (OFString *)stringForValue: (OFString *)value
			type: (DWORD *)typeOut
{
	void *pool = objc_autoreleasePoolPush();
	DWORD type;
	OFData *data = [self dataForValue: value
				     type: &type];
	const of_char16_t *UTF16String;
	size_t length;
	OFString *ret;

	if (data == nil)
		return nil;

	if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK)
		@throw [OFInvalidEncodingException exception];

	UTF16String = data.items;
	length = data.count;

	if (data.itemSize != 1 || length % 2 == 1)
		@throw [OFInvalidFormatException exception];

274
275
276
277
278
279
280



281
282
283
284
285
286
287
			length = i;
			break;
		}
	}

	ret = [[OFString alloc] initWithUTF16String: UTF16String
					     length: length];




	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (void)setString: (OFString *)string







>
>
>







279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
			length = i;
			break;
		}
	}

	ret = [[OFString alloc] initWithUTF16String: UTF16String
					     length: length];

	if (typeOut != NULL)
		*typeOut = type;

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (void)setString: (OFString *)string