Index: src/OFWindowsRegistryKey.h ================================================================== --- src/OFWindowsRegistryKey.h +++ src/OFWindowsRegistryKey.h @@ -190,10 +190,42 @@ */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name type: (DWORD)type; +/** + * @brief Returns the DWORD for the specified value at the specified path. + * + * @param name The name of the value to return + * @return The DWORD for the specified value + */ +- (uint32_t)DWORDForValueNamed: (nullable OFString *)name; + +/** + * @brief Sets the DWORD for the specified value. + * + * @param dword The DWORD to set the value to + * @param name The name of the value to set + */ +- (void)setDWORD: (uint32_t)dword forValueNamed: (nullable OFString *)name; + +/** + * @brief Returns the QWORD for the specified value at the specified path. + * + * @param name The name of the value to return + * @return The QWORD for the specified value + */ +- (uint64_t)QWORDForValueNamed: (nullable OFString *)name; + +/** + * @brief Sets the QWORD for the specified value. + * + * @param qword The QWORD to set the value to + * @param name The name of the value to set + */ +- (void)setQWORD: (uint64_t)qword forValueNamed: (nullable OFString *)name; + /** * @brief Deletes the specified value. * * @param name The value to delete */ Index: src/OFWindowsRegistryKey.m ================================================================== --- src/OFWindowsRegistryKey.m +++ src/OFWindowsRegistryKey.m @@ -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; Index: src/exceptions/OFUndefinedKeyException.h ================================================================== --- src/exceptions/OFUndefinedKeyException.h +++ src/exceptions/OFUndefinedKeyException.h @@ -25,11 +25,11 @@ * Coding). */ @interface OFUndefinedKeyException: OFException { id _object; - OFString *_key; + OFString *_Nullable _key; id _Nullable _value; } /** * @brief The object on which the key is undefined. @@ -37,11 +37,11 @@ @property (readonly, nonatomic) id object; /** * @brief The key which is undefined. */ -@property (readonly, nonatomic) OFString *key; +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *key; /** * @brief The value for the undefined key */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id value; @@ -64,11 +64,11 @@ * @param value The value for the undefined key * * @return A new, autoreleased undefined key exception */ + (instancetype)exceptionWithObject: (id)object - key: (OFString *)key + key: (nullable OFString *)key value: (nullable id)value; + (instancetype)exception OF_UNAVAILABLE; /** @@ -89,12 +89,12 @@ * @param value The value for the undefined key * * @return An initialized undefined key exception */ - (instancetype)initWithObject: (id)object - key: (OFString *)key + key: (nullable OFString *)key value: (nullable id)value OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END