Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
49baaf13
Commit
49baaf13
authored
Apr 03, 2023
by
David Kahurani
Committed by
Alexandre Julliard
May 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shlwapi: Implement StrFormatByteSizeEx.
Wine-Bug:
https://bugs.winehq.org/show_bug.cgi?id=54733
Signed-off-by:
David Kahurani
<
k.kahurani@gmail.com
>
parent
885d8dfa
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
6 deletions
+84
-6
shlwapi.spec
dlls/shlwapi/shlwapi.spec
+1
-0
string.c
dlls/shlwapi/string.c
+41
-6
string.c
dlls/shlwapi/tests/string.c
+35
-0
shlwapi.h
include/shlwapi.h
+7
-0
No files found.
dlls/shlwapi/shlwapi.spec
View file @
49baaf13
...
@@ -781,6 +781,7 @@
...
@@ -781,6 +781,7 @@
@ stdcall -import StrDupW (wstr)
@ stdcall -import StrDupW (wstr)
@ stdcall StrFormatByteSize64A(int64 ptr long)
@ stdcall StrFormatByteSize64A(int64 ptr long)
@ stdcall StrFormatByteSizeA(long ptr long)
@ stdcall StrFormatByteSizeA(long ptr long)
@ stdcall StrFormatByteSizeEx(int64 long ptr long)
@ stdcall StrFormatByteSizeW(int64 ptr long)
@ stdcall StrFormatByteSizeW(int64 ptr long)
@ stdcall StrFormatKBSizeA(int64 str long)
@ stdcall StrFormatKBSizeA(int64 str long)
@ stdcall StrFormatKBSizeW(int64 wstr long)
@ stdcall StrFormatKBSizeW(int64 wstr long)
...
...
dlls/shlwapi/string.c
View file @
49baaf13
...
@@ -841,6 +841,30 @@ typedef struct tagSHLWAPI_BYTEFORMATS
...
@@ -841,6 +841,30 @@ typedef struct tagSHLWAPI_BYTEFORMATS
*/
*/
LPWSTR
WINAPI
StrFormatByteSizeW
(
LONGLONG
llBytes
,
LPWSTR
lpszDest
,
UINT
cchMax
)
LPWSTR
WINAPI
StrFormatByteSizeW
(
LONGLONG
llBytes
,
LPWSTR
lpszDest
,
UINT
cchMax
)
{
{
HRESULT
hr
;
TRACE
(
"(0x%s,%p,%d)
\n
"
,
wine_dbgstr_longlong
(
llBytes
),
lpszDest
,
cchMax
);
if
(
!
lpszDest
||
!
cchMax
)
return
lpszDest
;
hr
=
StrFormatByteSizeEx
(
llBytes
,
SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS
,
lpszDest
,
cchMax
);
if
(
FAILED
(
hr
))
return
NULL
;
return
lpszDest
;
}
/*************************************************************************
* StrFormatByteSizeEx [SHLWAPI.@]
*
*/
HRESULT
WINAPI
StrFormatByteSizeEx
(
LONGLONG
llBytes
,
SFBS_FLAGS
flags
,
LPWSTR
lpszDest
,
UINT
cchMax
)
{
#define KB ((ULONGLONG)1024)
#define KB ((ULONGLONG)1024)
#define MB (KB*KB)
#define MB (KB*KB)
#define GB (KB*KB*KB)
#define GB (KB*KB*KB)
...
@@ -870,17 +894,17 @@ LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
...
@@ -870,17 +894,17 @@ LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
double
dBytes
;
double
dBytes
;
UINT
i
=
0
;
UINT
i
=
0
;
TRACE
(
"(0x%s,%
p,%d)
\n
"
,
wine_dbgstr_longlong
(
llBytes
)
,
lpszDest
,
cchMax
);
TRACE
(
"(0x%s,%
d,%p,%d)
\n
"
,
wine_dbgstr_longlong
(
llBytes
),
flags
,
lpszDest
,
cchMax
);
if
(
!
lpszDest
||
!
cchMax
)
if
(
!
cchMax
)
return
lpszDest
;
return
E_INVALIDARG
;
if
(
llBytes
<
1024
)
/* 1K */
if
(
llBytes
<
1024
)
/* 1K */
{
{
WCHAR
wszBytesFormat
[
64
];
WCHAR
wszBytesFormat
[
64
];
LoadStringW
(
shlwapi_hInstance
,
IDS_BYTES_FORMAT
,
wszBytesFormat
,
64
);
LoadStringW
(
shlwapi_hInstance
,
IDS_BYTES_FORMAT
,
wszBytesFormat
,
64
);
swprintf
(
lpszDest
,
cchMax
,
wszBytesFormat
,
(
int
)
llBytes
);
swprintf
(
lpszDest
,
cchMax
,
wszBytesFormat
,
(
int
)
llBytes
);
return
lpszDest
;
return
S_OK
;
}
}
/* Note that if this loop completes without finding a match, i will be
/* Note that if this loop completes without finding a match, i will be
...
@@ -903,13 +927,24 @@ LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
...
@@ -903,13 +927,24 @@ LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
else
else
dBytes
=
(
double
)
llBytes
+
0
.
00001
;
dBytes
=
(
double
)
llBytes
+
0
.
00001
;
switch
(
flags
)
{
case
SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT
:
dBytes
=
round
(
dBytes
/
bfFormats
[
i
].
dDivisor
)
/
bfFormats
[
i
].
dNormaliser
;
break
;
case
SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS
:
dBytes
=
floor
(
dBytes
/
bfFormats
[
i
].
dDivisor
)
/
bfFormats
[
i
].
dNormaliser
;
dBytes
=
floor
(
dBytes
/
bfFormats
[
i
].
dDivisor
)
/
bfFormats
[
i
].
dNormaliser
;
break
;
default:
return
E_INVALIDARG
;
}
if
(
!
FormatDouble
(
dBytes
,
bfFormats
[
i
].
nDecimals
,
lpszDest
,
cchMax
))
if
(
!
FormatDouble
(
dBytes
,
bfFormats
[
i
].
nDecimals
,
lpszDest
,
cchMax
))
return
NULL
;
return
E_FAIL
;
wszAdd
[
1
]
=
bfFormats
[
i
].
wPrefix
;
wszAdd
[
1
]
=
bfFormats
[
i
].
wPrefix
;
StrCatBuffW
(
lpszDest
,
wszAdd
,
cchMax
);
StrCatBuffW
(
lpszDest
,
wszAdd
,
cchMax
);
return
lpszDest
;
return
S_OK
;
}
}
/*************************************************************************
/*************************************************************************
...
...
dlls/shlwapi/tests/string.c
View file @
49baaf13
...
@@ -52,6 +52,7 @@ static DWORD (WINAPI *pStrCatChainW)(LPWSTR,DWORD,DWORD,LPCWSTR);
...
@@ -52,6 +52,7 @@ static DWORD (WINAPI *pStrCatChainW)(LPWSTR,DWORD,DWORD,LPCWSTR);
static
LPSTR
(
WINAPI
*
pStrCpyNXA
)(
LPSTR
,
LPCSTR
,
int
);
static
LPSTR
(
WINAPI
*
pStrCpyNXA
)(
LPSTR
,
LPCSTR
,
int
);
static
LPWSTR
(
WINAPI
*
pStrCpyNXW
)(
LPWSTR
,
LPCWSTR
,
int
);
static
LPWSTR
(
WINAPI
*
pStrCpyNXW
)(
LPWSTR
,
LPCWSTR
,
int
);
static
LPSTR
(
WINAPI
*
pStrFormatByteSize64A
)(
LONGLONG
,
LPSTR
,
UINT
);
static
LPSTR
(
WINAPI
*
pStrFormatByteSize64A
)(
LONGLONG
,
LPSTR
,
UINT
);
static
HRESULT
(
WINAPI
*
pStrFormatByteSizeEx
)(
LONGLONG
,
SFBS_FLAGS
,
LPWSTR
,
UINT
);
static
LPSTR
(
WINAPI
*
pStrFormatKBSizeA
)(
LONGLONG
,
LPSTR
,
UINT
);
static
LPSTR
(
WINAPI
*
pStrFormatKBSizeA
)(
LONGLONG
,
LPSTR
,
UINT
);
static
LPWSTR
(
WINAPI
*
pStrFormatKBSizeW
)(
LONGLONG
,
LPWSTR
,
UINT
);
static
LPWSTR
(
WINAPI
*
pStrFormatKBSizeW
)(
LONGLONG
,
LPWSTR
,
UINT
);
static
BOOL
(
WINAPI
*
pStrIsIntlEqualA
)(
BOOL
,
LPCSTR
,
LPCSTR
,
int
);
static
BOOL
(
WINAPI
*
pStrIsIntlEqualA
)(
BOOL
,
LPCSTR
,
LPCSTR
,
int
);
...
@@ -715,6 +716,38 @@ static void test_StrFormatByteSize64A(void)
...
@@ -715,6 +716,38 @@ static void test_StrFormatByteSize64A(void)
}
}
}
}
static
void
test_StrFormatByteSizeEx
(
void
)
{
WCHAR
szBuff
[
256
];
HRESULT
hr
;
LONGLONG
test_value
=
2147483647
;
if
(
!
pStrFormatByteSizeEx
)
{
win_skip
(
"StrFormatByteSizeEx is not available
\n
"
);
return
;
}
hr
=
pStrFormatByteSizeEx
(
0xdeadbeef
,
SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS
,
szBuff
,
0
);
ok
(
hr
==
E_INVALIDARG
,
"Unexpected hr: %#lx expected: %#lx
\n
"
,
hr
,
E_INVALIDARG
);
hr
=
pStrFormatByteSizeEx
(
0xdeadbeef
,
10
,
szBuff
,
256
);
ok
(
hr
==
E_INVALIDARG
,
"Unexpected hr: %#lx expected: %#lx
\n
"
,
hr
,
E_INVALIDARG
);
hr
=
pStrFormatByteSizeEx
(
test_value
,
SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT
,
szBuff
,
256
);
ok
(
hr
==
S_OK
,
"Invalid arguments
\n
"
);
ok
(
!
wcscmp
(
szBuff
,
L"2.00 GB"
),
"Formatted %s wrong: got %ls, expected 2.00 GB
\n
"
,
wine_dbgstr_longlong
(
test_value
),
szBuff
);
hr
=
pStrFormatByteSizeEx
(
test_value
,
SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS
,
szBuff
,
256
);
ok
(
hr
==
S_OK
,
"Invalid arguments
\n
"
);
ok
(
!
wcscmp
(
szBuff
,
L"1.99 GB"
),
"Formatted %s wrong: got %ls, expected 1.99 GB
\n
"
,
wine_dbgstr_longlong
(
test_value
),
szBuff
);
}
static
void
test_StrFormatKBSizeW
(
void
)
static
void
test_StrFormatKBSizeW
(
void
)
{
{
WCHAR
szBuffW
[
256
];
WCHAR
szBuffW
[
256
];
...
@@ -1680,6 +1713,7 @@ START_TEST(string)
...
@@ -1680,6 +1713,7 @@ START_TEST(string)
pStrCpyNXW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
(
LPSTR
)
400
);
pStrCpyNXW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
(
LPSTR
)
400
);
pStrChrNW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrChrNW"
);
pStrChrNW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrChrNW"
);
pStrFormatByteSize64A
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatByteSize64A"
);
pStrFormatByteSize64A
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatByteSize64A"
);
pStrFormatByteSizeEx
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatByteSizeEx"
);
pStrFormatKBSizeA
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatKBSizeA"
);
pStrFormatKBSizeA
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatKBSizeA"
);
pStrFormatKBSizeW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatKBSizeW"
);
pStrFormatKBSizeW
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrFormatKBSizeW"
);
pStrIsIntlEqualA
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrIsIntlEqualA"
);
pStrIsIntlEqualA
=
(
void
*
)
GetProcAddress
(
hShlwapi
,
"StrIsIntlEqualA"
);
...
@@ -1716,6 +1750,7 @@ START_TEST(string)
...
@@ -1716,6 +1750,7 @@ START_TEST(string)
if
(
is_lang_english
()
&&
is_locale_english
())
if
(
is_lang_english
()
&&
is_locale_english
())
{
{
test_StrFormatByteSize64A
();
test_StrFormatByteSize64A
();
test_StrFormatByteSizeEx
();
test_StrFormatKBSizeA
();
test_StrFormatKBSizeA
();
test_StrFormatKBSizeW
();
test_StrFormatKBSizeW
();
}
}
...
...
include/shlwapi.h
View file @
49baaf13
...
@@ -856,6 +856,13 @@ WINSHLWAPI HRESULT WINAPI SHStrDupW(LPCWSTR,WCHAR**);
...
@@ -856,6 +856,13 @@ WINSHLWAPI HRESULT WINAPI SHStrDupW(LPCWSTR,WCHAR**);
WINSHLWAPI
LPSTR
WINAPI
StrFormatByteSizeA
(
DWORD
,
LPSTR
,
UINT
);
WINSHLWAPI
LPSTR
WINAPI
StrFormatByteSizeA
(
DWORD
,
LPSTR
,
UINT
);
typedef
enum
{
SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT
=
0x1
,
SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS
=
0x2
,
}
SFBS_FLAGS
;
WINSHLWAPI
HRESULT
WINAPI
StrFormatByteSizeEx
(
LONGLONG
,
SFBS_FLAGS
,
LPWSTR
,
UINT
);
/* A/W Pairing is broken for this function */
/* A/W Pairing is broken for this function */
WINSHLWAPI
LPSTR
WINAPI
StrFormatByteSize64A
(
LONGLONG
,
LPSTR
,
UINT
);
WINSHLWAPI
LPSTR
WINAPI
StrFormatByteSize64A
(
LONGLONG
,
LPSTR
,
UINT
);
WINSHLWAPI
LPWSTR
WINAPI
StrFormatByteSizeW
(
LONGLONG
,
LPWSTR
,
UINT
);
WINSHLWAPI
LPWSTR
WINAPI
StrFormatByteSizeW
(
LONGLONG
,
LPWSTR
,
UINT
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment