2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: BtrFS FSD for ReactOS
4 * FILE: dll/shellext/shellbtrfs/reactos.cpp
5 * PURPOSE: ReactOS glue for Win8.1
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
12 #include <ndk/rtlfuncs.h>
17 /* So that we can link */
18 DEFINE_GUID(CLSID_WICImagingFactory
, 0xcacaf262,0x9370,0x4615,0xa1,0x3b,0x9f,0x55,0x39,0xda,0x4c,0x0a);
20 /* Copied from ntoskrnl_vista */
21 NTSTATUS WINAPI
RtlUTF8ToUnicodeN(PWSTR uni_dest
, ULONG uni_bytes_max
,
22 PULONG uni_bytes_written
,
23 PCCH utf8_src
, ULONG utf8_bytes
)
29 ULONG utf8_trail_bytes
;
34 return STATUS_INVALID_PARAMETER_4
;
35 if (!uni_bytes_written
)
36 return STATUS_INVALID_PARAMETER
;
39 status
= STATUS_SUCCESS
;
41 for (i
= 0; i
< utf8_bytes
; i
++)
43 /* read UTF-8 lead byte */
44 ch
= (BYTE
)utf8_src
[i
];
49 status
= STATUS_SOME_NOT_MAPPED
;
68 /* overlong or trail byte */
70 status
= STATUS_SOME_NOT_MAPPED
;
73 /* read UTF-8 trail bytes */
74 if (i
+ utf8_trail_bytes
< utf8_bytes
)
76 for (j
= 0; j
< utf8_trail_bytes
; j
++)
78 if ((utf8_src
[i
+ 1] & 0xc0) == 0x80)
81 ch
|= utf8_src
[i
+ 1] & 0x3f;
88 status
= STATUS_SOME_NOT_MAPPED
;
97 status
= STATUS_SOME_NOT_MAPPED
;
101 /* encode ch as UTF-16 */
102 if ((ch
> 0x10ffff) ||
103 (ch
>= 0xd800 && ch
<= 0xdfff) ||
104 (utf8_trail_bytes
== 2 && ch
< 0x00800) ||
105 (utf8_trail_bytes
== 3 && ch
< 0x10000))
107 /* invalid codepoint or overlong encoding */
108 utf16_ch
[0] = 0xfffd;
109 utf16_ch
[1] = 0xfffd;
110 utf16_ch
[2] = 0xfffd;
111 utf16_ch_len
= utf8_trail_bytes
;
112 status
= STATUS_SOME_NOT_MAPPED
;
114 else if (ch
>= 0x10000)
118 utf16_ch
[0] = 0xd800 + (ch
>> 10 & 0x3ff);
119 utf16_ch
[1] = 0xdc00 + (ch
>> 0 & 0x3ff);
131 written
+= utf16_ch_len
;
135 for (j
= 0; j
< utf16_ch_len
; j
++)
137 if (uni_bytes_max
>= sizeof(WCHAR
))
139 *uni_dest
++ = utf16_ch
[j
];
140 uni_bytes_max
-= sizeof(WCHAR
);
146 status
= STATUS_BUFFER_TOO_SMALL
;
151 *uni_bytes_written
= written
* sizeof(WCHAR
);
155 /* Quick and dirty table for conversion */
156 FILE_INFORMATION_CLASS ConvertToFileInfo
[MaximumFileInfoByHandlesClass
] =
158 FileBasicInformation
, FileStandardInformation
, FileNameInformation
, FileRenameInformation
,
159 FileDispositionInformation
, FileAllocationInformation
, FileEndOfFileInformation
, FileStreamInformation
,
160 FileCompressionInformation
, FileAttributeTagInformation
, FileIdBothDirectoryInformation
, (FILE_INFORMATION_CLASS
)-1,
161 FileIoPriorityHintInformation
, FileRemoteProtocolInformation
164 /* Taken from kernel32 */
166 BaseSetLastNTError(IN NTSTATUS Status
)
169 dwErrCode
= RtlNtStatusToDosError(Status
);
170 SetLastError(dwErrCode
);
174 /* Quick implementation, still going farther than Wine implementation */
177 SetFileInformationByHandle(HANDLE hFile
,
178 FILE_INFO_BY_HANDLE_CLASS FileInformationClass
,
179 LPVOID lpFileInformation
,
183 IO_STATUS_BLOCK IoStatusBlock
;
184 FILE_INFORMATION_CLASS FileInfoClass
;
186 FileInfoClass
= (FILE_INFORMATION_CLASS
)-1;
188 /* Attempt to convert the class */
189 if (FileInformationClass
< MaximumFileInfoByHandlesClass
)
191 FileInfoClass
= ConvertToFileInfo
[FileInformationClass
];
194 /* If wrong, bail out */
195 if (FileInfoClass
== -1)
197 SetLastError(ERROR_INVALID_PARAMETER
);
201 /* And set the information */
202 Status
= NtSetInformationFile(hFile
, &IoStatusBlock
, lpFileInformation
,
203 dwBufferSize
, FileInfoClass
);
205 if (!NT_SUCCESS(Status
))
207 BaseSetLastNTError(Status
);