ObjFW  Check-in [5586022d34]

Overview
Comment:Add OFWindowsRegistryKey
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5586022d34d3a2d1c26a825b37b18dfd8c7b591f8c8fd99f5b8ddb8913da3771
User & Date: js on 2018-07-09 00:22:04
Other Links: manifest | tags
Context
2018-07-10
20:44
OFWindowsRegistryKey: Allow retrieving the type check-in: e8ae6a2ca1 user: js tags: trunk
2018-07-09
00:22
Add OFWindowsRegistryKey check-in: 5586022d34 user: js tags: trunk
2018-07-08
19:42
OFDNSResolver: Paths for hosts file on more OSes check-in: 418965bae3 user: js tags: trunk
Changes

Modified configure.ac from [d04140f36d] to [67c3ea16a5].

89
90
91
92
93
94
95

96
97
98
99
100
101
102
		;;
	*-*-mingw*)
		LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
		LIBS="$LIBS -lversion"

		AC_SUBST(ALLOW_MULTIPLE_DEFINITION,
			[-Wl,--allow-multiple-definition])

		;;
	*-psp-*)
		AS_IF([test x"$DEVKITPSP" = x""], [
			AC_MSG_ERROR(
				[DEVKITPSP is not set! Please set DEVKITPSP.])
		])








>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
		;;
	*-*-mingw*)
		LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
		LIBS="$LIBS -lversion"

		AC_SUBST(ALLOW_MULTIPLE_DEFINITION,
			[-Wl,--allow-multiple-definition])
		AC_SUBST(USE_SRCS_WINDOWS, '${SRCS_WINDOWS}')
		;;
	*-psp-*)
		AS_IF([test x"$DEVKITPSP" = x""], [
			AC_MSG_ERROR(
				[DEVKITPSP is not set! Please set DEVKITPSP.])
		])

815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
		])
	])
	AC_MSG_RESULT($ac_cv_snprintf_useful_ret)
])
test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \
	AC_MSG_ERROR(No asprintf and no snprintf returning required space!)

case "$host_os" in
mingw*)
	AC_SUBST(OFSTDIOSTREAM_WIN32CONSOLE_M, "OFStdIOStream_Win32Console.m")
	;;
esac

AC_ARG_ENABLE(unicode-tables,
	AS_HELP_STRING([--disable-unicode-tables], [Disable Unicode tables]))
AS_IF([test x"$enable_unicode_tables" != x"no"], [
	AC_DEFINE(OF_HAVE_UNICODE_TABLES, 1,
		[Whether to build with Unicode tables])
	AC_SUBST(UNICODE_M, "unicode.m")
])







<
<
<
<
<
<







816
817
818
819
820
821
822






823
824
825
826
827
828
829
		])
	])
	AC_MSG_RESULT($ac_cv_snprintf_useful_ret)
])
test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \
	AC_MSG_ERROR(No asprintf and no snprintf returning required space!)







AC_ARG_ENABLE(unicode-tables,
	AS_HELP_STRING([--disable-unicode-tables], [Disable Unicode tables]))
AS_IF([test x"$enable_unicode_tables" != x"no"], [
	AC_DEFINE(OF_HAVE_UNICODE_TABLES, 1,
		[Whether to build with Unicode tables])
	AC_SUBST(UNICODE_M, "unicode.m")
])

Modified extra.mk.in from [b852bcbbd5] to [b30b9951cf].

78
79
80
81
82
83
84

85
86
TESTS_STATIC_LIB = @TESTS_STATIC_LIB@
UNICODE_M = @UNICODE_M@
USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@
USE_SRCS_FILES = @USE_SRCS_FILES@
USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@
USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@
USE_SRCS_THREADS = @USE_SRCS_THREADS@

WEAK_NSFOUNDATIONVERSIONNUMBER = @WEAK_NSFOUNDATIONVERSIONNUMBER@
WRAPPER = @WRAPPER@







>


78
79
80
81
82
83
84
85
86
87
TESTS_STATIC_LIB = @TESTS_STATIC_LIB@
UNICODE_M = @UNICODE_M@
USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@
USE_SRCS_FILES = @USE_SRCS_FILES@
USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@
USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@
USE_SRCS_THREADS = @USE_SRCS_THREADS@
USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@
WEAK_NSFOUNDATIONVERSIONNUMBER = @WEAK_NSFOUNDATIONVERSIONNUMBER@
WRAPPER = @WRAPPER@

Modified src/Makefile from [fe13b0fd2e] to [06e156b5d2].

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
       OFSHA224Or256Hash.m		\
       OFSHA256Hash.m			\
       OFSHA384Hash.m			\
       OFSHA384Or512Hash.m		\
       OFSHA512Hash.m			\
       OFSortedList.m			\
       OFStdIOStream.m			\
       ${OFSTDIOSTREAM_WIN32CONSOLE_M}	\
       OFStream.m			\
       OFString.m			\
       OFString+CryptoHashing.m		\
       OFString+JSONValue.m		\
       OFString+PropertyListValue.m	\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\







<







73
74
75
76
77
78
79

80
81
82
83
84
85
86
       OFSHA224Or256Hash.m		\
       OFSHA256Hash.m			\
       OFSHA384Hash.m			\
       OFSHA384Or512Hash.m		\
       OFSHA512Hash.m			\
       OFSortedList.m			\
       OFStdIOStream.m			\

       OFStream.m			\
       OFString.m			\
       OFString+CryptoHashing.m		\
       OFString+JSONValue.m		\
       OFString+PropertyListValue.m	\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\
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
       of_strptime.m			\
       pbkdf2.m				\
       scrypt.m				\
       ${UNICODE_M}			\
       ${USE_SRCS_FILES}		\
       ${USE_SRCS_PLUGINS}		\
       ${USE_SRCS_SOCKETS}		\
       ${USE_SRCS_THREADS}

SRCS_FILES = OFFile.m			\
	     OFFileManager.m		\
	     OFINICategory.m		\
	     OFINIFile.m		\
	     OFSettings.m		\
	     OFString+PathAdditions.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SOCKETS = OFDNSResolver.m			\
	       OFHTTPServer.m			\
	       OFStreamSocket.m			\
	       OFTCPSocket.m			\
	       OFUDPSocket.m			\
	       resolver.m			\
	       socket.m
SRCS_THREADS = OFCondition.m		\
	       OFMutex.m		\
	       OFRecursiveMutex.m	\
	       OFThreadPool.m		\
	       threading.m



INCLUDES_ATOMIC = atomic.h			\
		  atomic_builtins.h		\
		  atomic_no_threads.h		\
		  atomic_osatomic.h		\
		  atomic_powerpc.h		\
		  atomic_sync_builtins.h	\







|
>



















>
>







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
       of_strptime.m			\
       pbkdf2.m				\
       scrypt.m				\
       ${UNICODE_M}			\
       ${USE_SRCS_FILES}		\
       ${USE_SRCS_PLUGINS}		\
       ${USE_SRCS_SOCKETS}		\
       ${USE_SRCS_THREADS}		\
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFFile.m			\
	     OFFileManager.m		\
	     OFINICategory.m		\
	     OFINIFile.m		\
	     OFSettings.m		\
	     OFString+PathAdditions.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SOCKETS = OFDNSResolver.m			\
	       OFHTTPServer.m			\
	       OFStreamSocket.m			\
	       OFTCPSocket.m			\
	       OFUDPSocket.m			\
	       resolver.m			\
	       socket.m
SRCS_THREADS = OFCondition.m		\
	       OFMutex.m		\
	       OFRecursiveMutex.m	\
	       OFThreadPool.m		\
	       threading.m
SRCS_WINDOWS = OFStdIOStream_Win32Console.m	\
	       OFWindowsRegistryKey.m

INCLUDES_ATOMIC = atomic.h			\
		  atomic_builtins.h		\
		  atomic_no_threads.h		\
		  atomic_osatomic.h		\
		  atomic_powerpc.h		\
		  atomic_sync_builtins.h	\

Added src/OFWindowsRegistryKey.h version [428ab2c96c].















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"
#import "OFString.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFWindowsRegistryKey \
 *	  OFWindowsRegistryKey.h ObjFW/OFWindowsRegistryKey.h
 */
@interface OFWindowsRegistryKey: OFObject
{
	HKEY _hKey;
	bool _close;
}

/*!
 * @brief Returns the OFWindowsRegistryKey for the HKEY_CLASSES_ROOT key.
 *
 * @return The OFWindowsRegistryKey for the HKEY_CLASSES_ROOT key
 */
+ (instancetype)classesRootKey;

/*!
 * @brief Returns the OFWindowsRegistryKey for the HKEY_CURRENT_CONFIG key.
 *
 * @return The OFWindowsRegistryKey for the HKEY_CURRENT_CONFIG key
 */
+ (instancetype)currentConfigKey;

/*!
 * @brief Returns the OFWindowsRegistryKey for the HKEY_CURRENT_USER key.
 *
 * @return The OFWindowsRegistryKey for the HKEY_CURRENT_USER key
 */
+ (instancetype)currentUserKey;

/*!
 * @brief Returns the OFWindowsRegistryKey for the HKEY_LOCAL_MACHINE key.
 *
 * @return The OFWindowsRegistryKey for the HKEY_LOCAL_MACHINE key
 */
+ (instancetype)localMachineKey;

/*!
 * @brief Returns the OFWindowsRegistryKey for the HKEY_USERS key.
 *
 * @return The OFWindowsRegistryKey for the HKEY_USERS key
 */
+ (instancetype)usersKey;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Opens the sub key at the specified path.
 *
 * @param path The path of the sub key to open
 * @param options Please refer to the `RegOpenKeyEx()` documentation
 * @param securityAndAccessRights Please refer to the `RegOpenKeyEx()`
 *				  documentation
 * @return The sub key with the specified path, or nil if it does not exist
 */
- (nullable OFWindowsRegistryKey *)
	 openSubKeyWithPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights;

/*!
 * @brief Creates a sub key at the specified path or opens it if it already
 *	  exists.
 *
 * @param path The path of the sub key to create
 * @param options Please refer to the `RegCreateKeyEx()` documentation
 * @param securityAndAccessRights Please refer to the `RegCreateKeyEx()`
 *				  documentation
 * @param securityAttributes Please refer to the `RegCreateKeyEx()`
 *			     documentation
 * @param disposition Please refer to the `RegCreateKeyEx()` documentation
 * @return The sub key with the specified path
 */
- (OFWindowsRegistryKey *)
       createSubKeyWithPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes
		disposition: (nullable LPDWORD)disposition;

/*!
 * @brief Returns the string for the specified value at the specified path.
 *
 * @param value The name of the value to return
 * @param subKeyPath The path of the key from which to retrieve the value
 * @param flags Extra flags for `RegGetValue()`. Usually 0.
 * @return The string for the specified value
 */
- (nullable OFString *)stringForValue: (nullable OFString *)value
			   subKeyPath: (nullable OFString *)subKeyPath
				flags: (DWORD)flags;
@end

OF_ASSUME_NONNULL_END

Added src/OFWindowsRegistryKey.m version [8b00d015e4].

















































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <windows.h>

#import "OFWindowsRegistryKey.h"

#import "OFCreateWindowsRegistryKeyFailedException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFReadWindowsRegistryValueFailedException.h"

@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey
			  close: (bool)close;
@end

@implementation OFWindowsRegistryKey
+ (instancetype)classesRootKey
{
	return [[[self alloc] of_initWithHKey: HKEY_CLASSES_ROOT
					close: false] autorelease];
}

+ (instancetype)currentConfigKey
{
	return [[[self alloc] of_initWithHKey: HKEY_CURRENT_CONFIG
					close: false] autorelease];
}

+ (instancetype)currentUserKey
{
	return [[[self alloc] of_initWithHKey: HKEY_CURRENT_USER
					close: false] autorelease];
}

+ (instancetype)localMachineKey
{
	return [[[self alloc] of_initWithHKey: HKEY_LOCAL_MACHINE
					close: false] autorelease];
}

+ (instancetype)usersKey
{
	return [[[self alloc] of_initWithHKey: HKEY_USERS
					close: false] autorelease];
}

- (instancetype)of_initWithHKey: (HKEY)hKey
			  close: (bool)close
{
	self = [super init];

	_hKey = hKey;
	_close = close;

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	if (_close)
		RegCloseKey(_hKey);

	[super dealloc];
}

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

	if ((status = RegOpenKeyExW(_hKey, [path UTF16String], options,
	    securityAndAccessRights, &subKey)) != 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];
}

- (OFWindowsRegistryKey *)
       createSubKeyWithPath: (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,
	    &subKey, NULL)) != ERROR_SUCCESS)
		@throw [OFCreateWindowsRegistryKeyFailedException
		    exceptionWithRegistryKey: self
					path: path
				     options: options
		     securityAndAccessRights: securityAndAccessRights
			  securityAttributes: securityAttributes
				      status: status];

	objc_autoreleasePoolPop(pool);

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

- (OFString *)stringForValue: (OFString *)value
		  subKeyPath: (OFString *)subKeyPath
		       flags: (DWORD)flags
{
	void *pool = objc_autoreleasePoolPush();
	of_char16_t stackBuffer[256], *buffer = stackBuffer;
	DWORD length = sizeof(stackBuffer);
	LSTATUS status;
	OFString *ret;

	if ((status = RegGetValueW(_hKey, [subKeyPath UTF16String],
	    [value UTF16String], flags | RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ,
	    NULL, buffer, &length)) != ERROR_SUCCESS) {
		OFObject *tmp;

		if (status == ERROR_FILE_NOT_FOUND) {
			objc_autoreleasePoolPop(pool);
			return nil;
		}

		if (status != ERROR_MORE_DATA)
			@throw [OFReadWindowsRegistryValueFailedException
			    exceptionWithRegistryKey: self
					       value: value
					  subKeyPath: subKeyPath
					       flags: flags
					      status: status];

		tmp = [[[OFObject alloc] init] autorelease];
		buffer = [tmp allocMemoryWithSize: length];

		if ((status = RegGetValueW(_hKey, [subKeyPath UTF16String],
		    [value UTF16String], flags | RRF_RT_REG_SZ |
		    RRF_RT_REG_EXPAND_SZ, NULL, buffer, &length)) !=
		    ERROR_SUCCESS)
			@throw [OFReadWindowsRegistryValueFailedException
			    exceptionWithRegistryKey: self
					       value: value
					  subKeyPath: subKeyPath
					       flags: flags
					      status: status];
	}

	/*
	 * We do not specify a length, as the length returned by RegGetValue()
	 * sometimes seems to be larger than the string.
	 */
	ret = [[OFString alloc] initWithUTF16String: buffer];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end

Modified src/ObjFW.h from [e64e015cee] to [292fadcf99].

119
120
121
122
123
124
125




126
127
128
129
130
131
132
#import "OFApplication.h"
#import "OFSystemInfo.h"
#import "OFLocalization.h"
#import "OFOptionsParser.h"
#import "OFTimer.h"
#import "OFRunLoop.h"
#import "OFSandbox.h"





#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAddressTranslationFailedException.h"
# import "OFAlreadyConnectedException.h"







>
>
>
>







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#import "OFApplication.h"
#import "OFSystemInfo.h"
#import "OFLocalization.h"
#import "OFOptionsParser.h"
#import "OFTimer.h"
#import "OFRunLoop.h"
#import "OFSandbox.h"

#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif

#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAddressTranslationFailedException.h"
# import "OFAlreadyConnectedException.h"
142
143
144
145
146
147
148



149
150
151
152
153
154
155
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFConnectionFailedException.h"
#endif
#import "OFCopyItemFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFCreateSymbolicLinkFailedException.h"



#import "OFEnumerationMutationException.h"
#ifdef OF_HAVE_FILES
# import "OFGetCurrentDirectoryPathFailedException.h"
#endif
#import "OFGetOptionFailedException.h"
#import "OFHashAlreadyCalculatedException.h"
#ifdef OF_HAVE_SOCKETS







>
>
>







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFConnectionFailedException.h"
#endif
#import "OFCopyItemFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFCreateSymbolicLinkFailedException.h"
#ifdef OF_WINDOWS
# import "OFCreateWindowsRegistryKeyFailedException.h"
#endif
#import "OFEnumerationMutationException.h"
#ifdef OF_HAVE_FILES
# import "OFGetCurrentDirectoryPathFailedException.h"
#endif
#import "OFGetOptionFailedException.h"
#import "OFHashAlreadyCalculatedException.h"
#ifdef OF_HAVE_SOCKETS
174
175
176
177
178
179
180



181
182
183
184



185
186
187
188
189
190
191
#import "OFMoveItemFailedException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFObserveFailedException.h"
#endif
#import "OFOpenItemFailedException.h"



#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFReadOrWriteFailedException.h"



#import "OFRemoveItemFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFSandboxActivationFailedException.h"
#import "OFSeekFailedException.h"
#import "OFSetItemAttributesFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFStillLockedException.h"







>
>
>




>
>
>







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#import "OFMoveItemFailedException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFObserveFailedException.h"
#endif
#import "OFOpenItemFailedException.h"
#ifdef OF_WINDOWS
# import "OFOpenWindowsRegistryKeyFailedException.h"
#endif
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFReadOrWriteFailedException.h"
#ifdef OF_WINDOWS
# import "OFReadWindowsRegistryValueFailedException.h"
#endif
#import "OFRemoveItemFailedException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFSandboxActivationFailedException.h"
#import "OFSeekFailedException.h"
#import "OFSetItemAttributesFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFStillLockedException.h"

Modified src/exceptions/Makefile from [dcb34a8da1] to [a44622c32c].

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
       OFUndefinedKeyException.m			\
       OFUnknownXMLEntityException.m			\
       OFUnlockFailedException.m			\
       OFUnsupportedProtocolException.m			\
       OFUnsupportedVersionException.m			\
       OFWriteFailedException.m				\
       ${USE_SRCS_FILES}				\

       ${USE_SRCS_SOCKETS}				\
       ${USE_SRCS_THREADS}				\
       ${USE_SRCS_PLUGINS}
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m

SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAddressTranslationFailedException.m	\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\
	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m	\
	       OFConditionSignalFailedException.m	\
	       OFConditionStillWaitingException.m	\
	       OFConditionWaitFailedException.m		\
	       OFThreadJoinFailedException.m		\
	       OFThreadStartFailedException.m		\
	       OFThreadStillRunningException.m

SRCS_PLUGINS = OFLoadPluginFailedException.m


INCLUDES = ${SRCS:.m=.h}

include ../../buildsys.mk

CPPFLAGS += -I. -I.. -I../.. -I../runtime







>


|

>















>
|
>






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
       OFUndefinedKeyException.m			\
       OFUnknownXMLEntityException.m			\
       OFUnlockFailedException.m			\
       OFUnsupportedProtocolException.m			\
       OFUnsupportedVersionException.m			\
       OFWriteFailedException.m				\
       ${USE_SRCS_FILES}				\
       ${USE_SRCS_PLUGINS}				\
       ${USE_SRCS_SOCKETS}				\
       ${USE_SRCS_THREADS}				\
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAddressTranslationFailedException.m	\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\
	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m	\
	       OFConditionSignalFailedException.m	\
	       OFConditionStillWaitingException.m	\
	       OFConditionWaitFailedException.m		\
	       OFThreadJoinFailedException.m		\
	       OFThreadStartFailedException.m		\
	       OFThreadStillRunningException.m
SRCS_WINDOWS = OFCreateWindowsRegistryKeyFailedException.m	\
	       OFOpenWindowsRegistryKeyFailedException.m	\
	       OFReadWindowsRegistryValueFailedException.m

INCLUDES = ${SRCS:.m=.h}

include ../../buildsys.mk

CPPFLAGS += -I. -I.. -I../.. -I../runtime

Added src/exceptions/OFCreateWindowsRegistryKeyFailedException.h version [d7c616a090].



















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
120
121
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"
#import "OFWindowsRegistryKey.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

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

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

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

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

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

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

/*!
 * @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 sub key failed
 * @param path The path for the sub key that could not be created
 * @param options The options for the sub key that could not be created
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 * @param securityAttributes The security options for the sub key 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
	  securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes
		      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 sub key failed
 * @param path The path for the sub key that could not be created
 * @param options The options for the sub key that could not be created
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 * @param securityAttributes The security options for the sub key 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
	 securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes
		     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Added src/exceptions/OFCreateWindowsRegistryKeyFailedException.m version [fb03c698ad].















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFCreateWindowsRegistryKeyFailedException.h"

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

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

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

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

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

	return self;
}

- (void)dealloc
{
	[_registryKey release];
	[_path release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to create sub key at path %@: Status code %u!",
	    _path, _status];
}
@end

Added src/exceptions/OFOpenWindowsRegistryKeyFailedException.h version [310f6c7355].



























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"
#import "OFWindowsRegistryKey.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

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

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

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

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

/*!
 * @brief The security and access rights for the sub key 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 sub key failed
 * @param path The path for the sub key that could not be opened
 * @param options The options for the sub key 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
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		      status: (LSTATUS)status;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated open Windows registry key failed
 *	  exception.
 *
 * @param registryKey The registry key on which opening the sub key failed
 * @param path The path for the sub key that could not be opened
 * @param options The options for the sub key 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
    securityAndAccessRights: (REGSAM)securityAndAccessRights
		     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Added src/exceptions/OFOpenWindowsRegistryKeyFailedException.m version [432f5fa483].







































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFOpenWindowsRegistryKeyFailedException.h"

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

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

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

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

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

	return self;
}

- (void)dealloc
{
	[_registryKey release];
	[_path release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to open sub key at path %@: Status code %u!",
	    _path, _status];
}
@end

Added src/exceptions/OFReadWindowsRegistryValueFailedException.h version [30c678aff0].



















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"
#import "OFWindowsRegistryKey.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFReadWindowsRegistryValueFailedException \
 *	  OFReadWindowsRegistryValueFailedException.h \
 *	  ObjFW/OFReadWindowsRegistryValueFailedException.h
 *
 * @brief An exception indicating that reading a Windows registry value failed.
 */
@interface OFReadWindowsRegistryValueFailedException: OFException
{
	OFWindowsRegistryKey *_registryKey;
	OFString *_Nullable _value, *_Nullable _subKeyPath;
	DWORD _flags;
	LSTATUS _status;
}

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

/*!
 * @brief The value for which reading failed.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *value;

/*!
 * @brief The sub key path at which reading the value failed.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *subKeyPath;

/*!
 * @brief The flags with which reading the value failed.
 */
@property (readonly, nonatomic) DWORD flags;

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

/*!
 * @brief Creates a new, autoreleased read Windows registry value failed
 *	  exception.
 *
 * @param registryKey The registry key on which reading the value at the sub
 *		      key path failed
 * @param value The value for which reading failed
 * @param subKeyPath The sub key path at which reading the value failed
 * @param flags The flags with which reading the value failed
 * @param status The status returned by RegGetValueEx()
 * @return A new, autoreleased read Windows registry value failed exception
 */
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				   value: (nullable OFString *)value
			      subKeyPath: (nullable OFString *)subKeyPath
				   flags: (DWORD)flags
				  status: (LSTATUS)status;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated read Windows registry value failed
 *	  exception.
 *
 * @param registryKey The registry key on which reading the value at the sub
 *		      key path failed
 * @param value The value for which reading failed
 * @param subKeyPath The sub key path at which reading the value failed
 * @param flags The flags with which reading the value failed
 * @param status The status returned by RegGetValueEx()
 * @return An initialized read Windows registry value failed exception
 */
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			      value: (nullable OFString *)value
			 subKeyPath: (nullable OFString *)subKeyPath
			      flags: (DWORD)flags
			     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Added src/exceptions/OFReadWindowsRegistryValueFailedException.m version [0f275b7b06].



































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
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
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFReadWindowsRegistryValueFailedException.h"

@implementation OFReadWindowsRegistryValueFailedException
@synthesize registryKey = _registryKey, value = _value;
@synthesize subKeyPath = _subKeyPath, flags = _flags, status = _status;

+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				   value: (nullable OFString *)value
			      subKeyPath: (nullable OFString *)subKeyPath
				   flags: (DWORD)flags
				  status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					    value: value
				       subKeyPath: subKeyPath
					    flags: flags
					   status: status] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			      value: (nullable OFString *)value
			 subKeyPath: (nullable OFString *)subKeyPath
			      flags: (DWORD)flags
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_value = [value copy];
		_subKeyPath = [subKeyPath copy];
		_flags = flags;
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_registryKey release];
	[_value release];
	[_subKeyPath release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to read value %@ at sub key path %@: Status code %u!",
	    _value, _subKeyPath, _status];
}
@end