27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
+
|
#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"
#import "OFUndefinedKeyException.h"
OF_DIRECT_MEMBERS
@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close;
@end
@implementation OFWindowsRegistryKey
|
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
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
-
+
-
-
-
-
-
-
|
status = RegOpenKeyExW(_hKey, path.UTF16String, options,
securityAndAccessRights, &subKey);
else
status = RegOpenKeyExA(_hKey,
[path cStringWithEncoding: [OFLocale encoding]], options,
securityAndAccessRights, &subKey);
if (status != ERROR_SUCCESS) {
if (status != ERROR_SUCCESS)
if (status == ERROR_FILE_NOT_FOUND) {
objc_autoreleasePoolPop(pool);
return nil;
}
@throw [OFOpenWindowsRegistryKeyFailedException
exceptionWithRegistryKey: self
path: path
options: options
securityAndAccessRights: securityAndAccessRights
status: status];
}
objc_autoreleasePoolPop(pool);
return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
close: true]
autorelease];
}
|
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
data = [OFData dataWithItems: cString count: length + 1];
}
[self setData: data forValueNamed: name type: type];
objc_autoreleasePoolPop(pool);
}
- (uint32_t)DWORDForValueNamed: (OFString *)name
{
void *pool = objc_autoreleasePoolPush();
DWORD type, ret;
OFData *data = [self dataForValueNamed: name type: &type];
if (data == nil)
@throw [OFUndefinedKeyException exceptionWithObject: self
key: name
value: nil];
if (type != REG_DWORD)
@throw [OFInvalidEncodingException exception];
if (data.count != sizeof(ret) || data.itemSize != 1)
@throw [OFInvalidFormatException exception];
memcpy(&ret, data.items, sizeof(ret));
objc_autoreleasePoolPop(pool);
return ret;
}
- (void)setDWORD: (uint32_t)dword forValueNamed: (OFString *)name
{
void *pool = objc_autoreleasePoolPush();
OFData *data = [OFData dataWithItems: &dword count: sizeof(dword)];
[self setData: data forValueNamed: name type: REG_DWORD];
objc_autoreleasePoolPop(pool);
}
- (uint64_t)QWORDForValueNamed: (OFString *)name
{
void *pool = objc_autoreleasePoolPush();
DWORD type;
uint64_t ret;
OFData *data = [self dataForValueNamed: name type: &type];
if (data == nil)
@throw [OFUndefinedKeyException exceptionWithObject: self
key: name
value: nil];
if (type != REG_QWORD)
@throw [OFInvalidEncodingException exception];
if (data.count != sizeof(ret) || data.itemSize != 1)
@throw [OFInvalidFormatException exception];
memcpy(&ret, data.items, sizeof(ret));
objc_autoreleasePoolPop(pool);
return ret;
}
- (void)setQWORD: (uint64_t)qword forValueNamed: (OFString *)name
{
void *pool = objc_autoreleasePoolPush();
OFData *data = [OFData dataWithItems: &qword count: sizeof(qword)];
[self setData: data forValueNamed: name type: REG_QWORD];
objc_autoreleasePoolPop(pool);
}
- (void)deleteValueNamed: (OFString *)name
{
void *pool = objc_autoreleasePoolPush();
LSTATUS status;
if ([OFSystemInfo isWindowsNT])
|