FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SFTPplug/src/cunicode.cpp at dev · remittor/SFTPplug · GitHub
remittor
/
SFTPplug
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
5
Code
Issues
1
Pull requests
0
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
SFTPplug
/
src
/
cunicode.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
227 lines (198 loc) · 7.96 KB
Breadcrumbs
SFTPplug
/
src
/
cunicode.cpp
Copy path
File metadata and controls
227 lines (198 loc) · 7.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#
include
"
cunicode.h
"
#
include
"
shellapi.h
"
extern
tProgressProcW ProgressProcW;
extern
tLogProcW LogProcW;
extern
tRequestProcW RequestProcW;
LPSTR
walcopy
(
LPSTR
outname,
LPCWSTR
inname,
size_t
maxlen)
noexcept
{
return
walcopyCP
(
CP_ACP
, outname, inname, maxlen);
}
LPSTR
walcopyCP
(
int
codepage,
LPSTR
outname,
LPCWSTR
inname,
size_t
maxlen)
noexcept
{
if
(inname) {
WideCharToMultiByte
(codepage,
0
, inname, -
1
, outname, (
int
)maxlen,
NULL
,
NULL
);
outname[maxlen] =
0
;
return
outname;
}
return
NULL
;
}
LPWSTR
awlcopy
(
LPWSTR
outname,
LPCSTR
inname,
size_t
maxlen)
noexcept
{
return
awlcopyCP
(
CP_ACP
, outname, inname, maxlen);
}
LPWSTR
awlcopyCP
(
int
codepage,
LPWSTR
outname,
LPCSTR
inname,
size_t
maxlen)
noexcept
{
if
(inname) {
MultiByteToWideChar
(codepage,
0
, inname, -
1
, outname, (
int
)maxlen);
outname[maxlen] =
0
;
return
outname;
}
return
NULL
;
}
int
ConvUTF16toUTF8
(
LPCWSTR
inbuf,
size_t
inlen,
LPSTR
outbuf,
size_t
outmax,
bool
nullterm)
noexcept
{
if
(nullterm)
outbuf[
0
] =
0
;
if
(inlen ==
0
)
inlen =
wcslen
(inbuf);
if
(inlen ==
0
)
return
0
;
if
(outmax <
2
)
return
-
1
;
UTF16
* source = (
UTF16
*)inbuf;
UTF8
* target = (
UTF8
*)outbuf;
int
rc =
ConvertUTF16toUTF8
(&source, (
const
UTF16
*)(inbuf + inlen), &target, (
const
UTF8
*)(outbuf + outmax -
1
));
size_t
outlen = (
size_t
)target - (
size_t
)outbuf;
if
(nullterm)
outbuf[outlen] =
0
;
return
(rc ==
CVT_OK
) ? (
int
)outlen : -
1
;
}
int
ConvUTF8toUTF16
(
LPCSTR
inbuf,
size_t
inlen,
LPWSTR
outbuf,
size_t
outmax,
bool
nullterm)
noexcept
{
if
(nullterm)
outbuf[
0
] =
0
;
if
(inlen ==
0
)
inlen =
strlen
(inbuf);
if
(inlen ==
0
)
return
0
;
if
(outmax <
2
)
return
-
1
;
UTF8
* source = (
UTF8
*)inbuf;
UTF16
* target = (
UTF16
*)outbuf;
int
rc =
ConvertUTF8toUTF16
(&source, (
UTF8
*)(inbuf + inlen), &target, (
const
UTF16
*)(outbuf + outmax -
1
));
size_t
outlen = ((
size_t
)target - (
size_t
)outbuf) /
sizeof
(
WCHAR
);
if
(nullterm)
outbuf[outlen] =
0
;
return
(rc ==
CVT_OK
) ? (
int
)outlen : -
1
;
}
//
return true if name wasn't cut
static
bool
MakeExtraLongNameW
(
LPWSTR
outbuf,
LPCWSTR
inbuf,
size_t
maxlen)
noexcept
{
if
(
wcslen
(inbuf) >=
MAX_PATH
) {
wcslcpy
(outbuf,
L"
\\\\
?
\\
"
, maxlen);
wcslcat
(outbuf, inbuf, maxlen);
}
else
{
wcslcpy
(outbuf, inbuf, maxlen);
}
return
wcslen
(inbuf) +
4
<= maxlen;
}
/*
*********************************************************************************************
*/
void
copyfinddatawa
(
LPWIN32_FIND_DATA
lpFindFileDataA,
LPWIN32_FIND_DATAW
lpFindFileDataW)
noexcept
{
walcopy
(lpFindFileDataA->
cAlternateFileName
, lpFindFileDataW->
cAlternateFileName
,
sizeof
(lpFindFileDataW->
cAlternateFileName
)-
1
);
walcopy
(lpFindFileDataA->
cFileName
, lpFindFileDataW->
cFileName
,
sizeof
(lpFindFileDataW->
cFileName
)-
1
);
lpFindFileDataA->
dwFileAttributes
= lpFindFileDataW->
dwFileAttributes
;
lpFindFileDataA->
ftCreationTime
= lpFindFileDataW->
ftCreationTime
;
lpFindFileDataA->
ftLastAccessTime
= lpFindFileDataW->
ftLastAccessTime
;
lpFindFileDataA->
ftLastWriteTime
= lpFindFileDataW->
ftLastWriteTime
;
lpFindFileDataA->
nFileSizeHigh
= lpFindFileDataW->
nFileSizeHigh
;
lpFindFileDataA->
nFileSizeLow
= lpFindFileDataW->
nFileSizeLow
;
lpFindFileDataA->
dwReserved0
= lpFindFileDataW->
dwReserved0
;
lpFindFileDataA->
dwReserved1
= lpFindFileDataW->
dwReserved1
;
}
void
copyfinddataaw
(
LPWIN32_FIND_DATAW
lpFindFileDataW,
LPWIN32_FIND_DATA
lpFindFileDataA)
noexcept
{
awlcopy
(lpFindFileDataW->
cAlternateFileName
, lpFindFileDataA->
cAlternateFileName
,
countof
(lpFindFileDataW->
cAlternateFileName
)-
1
);
awlcopy
(lpFindFileDataW->
cFileName
, lpFindFileDataA->
cFileName
,
countof
(lpFindFileDataW->
cFileName
)-
1
);
lpFindFileDataW->
dwFileAttributes
= lpFindFileDataA->
dwFileAttributes
;
lpFindFileDataW->
ftCreationTime
= lpFindFileDataA->
ftCreationTime
;
lpFindFileDataW->
ftLastAccessTime
= lpFindFileDataA->
ftLastAccessTime
;
lpFindFileDataW->
ftLastWriteTime
= lpFindFileDataA->
ftLastWriteTime
;
lpFindFileDataW->
nFileSizeHigh
= lpFindFileDataA->
nFileSizeHigh
;
lpFindFileDataW->
nFileSizeLow
= lpFindFileDataA->
nFileSizeLow
;
lpFindFileDataW->
dwReserved0
= lpFindFileDataA->
dwReserved0
;
lpFindFileDataW->
dwReserved1
= lpFindFileDataA->
dwReserved1
;
}
/*
*********************************************************************************************
*/
int
ProgressProcT
(
int
PluginNr,
LPCWSTR
SourceName,
LPCWSTR
TargetName,
int
PercentDone)
noexcept
{
if
(ProgressProcW)
return
ProgressProcW
(PluginNr, SourceName, TargetName, PercentDone);
return
0
;
}
void
LogProcT
(
int
PluginNr,
int
MsgType,
LPCWSTR
LogString)
noexcept
{
if
(LogProcW)
LogProcW
(PluginNr, MsgType, LogString);
}
bool
RequestProcT
(
int
PluginNr,
int
RequestType,
LPCWSTR
CustomTitle,
LPCWSTR
CustomText,
LPWSTR
ReturnedText,
size_t
maxlen)
noexcept
{
if
(RequestProcW) {
BOOL
retval =
RequestProcW
(PluginNr, RequestType, CustomTitle, CustomText, ReturnedText, (
int
)maxlen);
return
retval ?
true
:
false
;
}
return
false
;
}
BOOL
CopyFileT
(
LPCWSTR
lpExistingFileName,
LPCWSTR
lpNewFileName,
BOOL
bFailIfExists)
noexcept
{
WCHAR
wbuf1[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf1, lpExistingFileName, wdirtypemax -
1
))
return
FALSE
;
WCHAR
wbuf2[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf2, lpNewFileName, wdirtypemax -
1
))
return
FALSE
;
return
CopyFileW
(wbuf1, wbuf2, bFailIfExists);
}
BOOL
CreateDirectoryT
(
LPCWSTR
lpPathName,
LPSECURITY_ATTRIBUTES
lpSecurityAttributes)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpPathName, wdirtypemax -
1
))
return
FALSE
;
return
CreateDirectoryW
(wbuf, lpSecurityAttributes);
}
BOOL
RemoveDirectoryT
(
LPCWSTR
lpPathName)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpPathName, wdirtypemax -
1
))
return
FALSE
;
return
RemoveDirectoryW
(wbuf);
}
BOOL
DeleteFileT
(
LPCWSTR
lpFileName)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpFileName, wdirtypemax -
1
))
return
FALSE
;
return
DeleteFileW
(wbuf);
}
BOOL
MoveFileT
(
LPCWSTR
lpExistingFileName,
LPCWSTR
lpNewFileName)
noexcept
{
WCHAR
wbuf1[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf1, lpExistingFileName, wdirtypemax -
1
))
return
FALSE
;
WCHAR
wbuf2[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf2, lpNewFileName, wdirtypemax -
1
))
return
FALSE
;
return
MoveFileW
(wbuf1, wbuf2);
}
BOOL
SetFileAttributesT
(
LPCWSTR
lpFileName,
DWORD
dwFileAttributes)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpFileName, wdirtypemax -
1
))
return
FALSE
;
return
SetFileAttributesW
(wbuf, dwFileAttributes);
}
HANDLE
CreateFileT
(
LPCWSTR
lpFileName,
DWORD
dwDesiredAccess,
DWORD
dwShareMode,
LPSECURITY_ATTRIBUTES
lpSecurityAttributes,
DWORD
dwCreationDisposition,
DWORD
dwFlagsAndAttributes,
HANDLE
hTemplateFile)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpFileName, wdirtypemax -
1
))
return
INVALID_HANDLE_VALUE
;
return
CreateFileW
(wbuf, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
UINT
ExtractIconExT
(
LPCWSTR
lpszFile,
int
nIconIndex,
HICON
* phiconLarge,
HICON
* phiconSmall,
UINT
nIcons)
noexcept
{
//
Unfortunately this function cannot handle names longer than 259 characters
return
ExtractIconExW
(lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
}
HANDLE
FindFirstFileT
(
LPCWSTR
lpFileName,
LPWIN32_FIND_DATAW
lpFindFileData)
noexcept
{
WCHAR
wbuf[wdirtypemax];
if
(!
MakeExtraLongNameW
(wbuf, lpFileName, wdirtypemax -
1
))
return
INVALID_HANDLE_VALUE
;
return
FindFirstFileW
(wbuf, lpFindFileData);
}
BOOL
FindNextFileT
(
HANDLE
hFindFile,
LPWIN32_FIND_DATAW
lpFindFileData)
noexcept
{
return
FindNextFileW
(hFindFile, lpFindFileData);
}
Back
|
FazBrowse Home
|
New Git URL