@@ -29,10 +29,11 @@ #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 @@ -362,10 +363,77 @@ [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) + /* TODO: This exception is not ideal. */ + @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) + /* TODO: This exception is not ideal. */ + @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;