Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
0f15c5eb
Commit
0f15c5eb
authored
Dec 01, 2019
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update dui and utf8
parent
fbe78c85
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
52 deletions
+79
-52
utf8.h
jlib/utf8.h
+0
-49
version.h
jlib/util/version.h
+24
-2
DeviceUniqueIdentifier.h
jlib/win32/DeviceUniqueIdentifier.h
+1
-1
UnicodeTool.h
jlib/win32/UnicodeTool.h
+53
-0
test_version.vcxproj
test/test_version/test_version.vcxproj
+1
-0
No files found.
jlib/utf8.h
View file @
0f15c5eb
...
@@ -45,55 +45,6 @@ namespace utf8 {
...
@@ -45,55 +45,6 @@ namespace utf8 {
utf8
::
utf8to16
(
a
.
begin
(),
a
.
end
(),
std
::
back_inserter
(
w
));
utf8
::
utf8to16
(
a
.
begin
(),
a
.
end
(),
std
::
back_inserter
(
w
));
return
w
;
return
w
;
}
}
inline
bool
mbcs_to_u16
(
const
char
*
mbcs
,
wchar_t
*
u16buffer
,
size_t
u16size
)
{
size_t
request_size
=
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
,
-
1
,
NULL
,
0
);
if
(
0
<
request_size
&&
request_size
<
u16size
)
{
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
,
-
1
,
u16buffer
,
request_size
);
return
true
;
}
return
false
;
};
inline
std
::
wstring
mbcs_to_u16
(
const
std
::
string
&
mbcs
)
{
std
::
wstring
res
=
L""
;
size_t
request_size
=
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
.
c_str
(),
-
1
,
NULL
,
0
);
if
(
0
<
request_size
)
{
auto
u16buffer
=
new
wchar_t
[
request_size
];
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
.
c_str
(),
-
1
,
u16buffer
,
request_size
);
res
=
u16buffer
;
delete
[]
u16buffer
;
}
return
res
;
}
inline
std
::
string
u16_to_mbcs
(
const
std
::
wstring
&
u16
)
{
std
::
string
res
=
""
;
size_t
request_size
=
WideCharToMultiByte
(
CP_ACP
,
0
,
u16
.
c_str
(),
-
1
,
0
,
0
,
0
,
0
);
if
(
0
<
request_size
)
{
auto
mbcs_buffer
=
new
char
[
request_size
];
WideCharToMultiByte
(
CP_ACP
,
0
,
u16
.
c_str
(),
-
1
,
mbcs_buffer
,
request_size
,
0
,
0
);
res
=
mbcs_buffer
;
delete
[]
mbcs_buffer
;
}
return
res
;
}
inline
std
::
string
mbcs_to_utf8
(
const
std
::
wstring
&
mbcs
)
{
std
::
string
res
=
""
;
size_t
request_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
mbcs
.
c_str
(),
-
1
,
0
,
0
,
0
,
0
);
if
(
0
<
request_size
)
{
auto
mbcs_buffer
=
new
char
[
request_size
];
WideCharToMultiByte
(
CP_UTF8
,
0
,
mbcs
.
c_str
(),
-
1
,
mbcs_buffer
,
request_size
,
0
,
0
);
res
=
mbcs_buffer
;
delete
[]
mbcs_buffer
;
}
return
res
;
}
}
}
#endif // header guard
#endif // header guard
jlib/util/version.h
View file @
0f15c5eb
...
@@ -41,7 +41,11 @@ struct Version {
...
@@ -41,7 +41,11 @@ struct Version {
std
::
to_string
(
build
);
std
::
to_string
(
build
);
}
}
bool
fromFile
(
const
std
::
string
&
path
)
{
template
<
typename
T
>
bool
fromFile
(
T
const
&
path
)
{
if
constexpr
(
std
::
is_convertible_v
<
T
,
std
::
string
>
);
else
if
constexpr
(
std
::
is_convertible_v
<
T
,
std
::
wstring
>
);
else
{
return
false
;
}
std
::
ifstream
in
(
path
);
if
(
!
in
)
return
false
;
std
::
ifstream
in
(
path
);
if
(
!
in
)
return
false
;
std
::
stringstream
is
;
is
<<
in
.
rdbuf
();
std
::
stringstream
is
;
is
<<
in
.
rdbuf
();
Version
file_ver
(
is
.
str
());
Version
file_ver
(
is
.
str
());
...
@@ -49,7 +53,11 @@ struct Version {
...
@@ -49,7 +53,11 @@ struct Version {
return
false
;
return
false
;
}
}
bool
toFile
(
const
std
::
string
&
path
)
{
template
<
typename
T
>
bool
toFile
(
T
const
&
path
)
{
if
constexpr
(
std
::
is_convertible_v
<
T
,
std
::
string
>
);
else
if
constexpr
(
std
::
is_convertible_v
<
T
,
std
::
wstring
>
);
else
{
return
false
;
}
std
::
ofstream
out
(
path
);
if
(
!
out
)
{
return
false
;
}
std
::
ofstream
out
(
path
);
if
(
!
out
)
{
return
false
;
}
auto
str
=
toString
();
out
.
write
(
str
.
data
(),
str
.
size
());
auto
str
=
toString
();
out
.
write
(
str
.
data
(),
str
.
size
());
return
true
;
return
true
;
...
@@ -79,6 +87,20 @@ struct Version {
...
@@ -79,6 +87,20 @@ struct Version {
if
(
this
->
operator
==
(
ver
))
return
false
;
if
(
this
->
operator
==
(
ver
))
return
false
;
return
true
;
return
true
;
}
}
bool
operator
<=
(
const
Version
&
ver
)
{
return
(
major
<=
ver
.
major
)
||
(
minor
<=
ver
.
minor
)
||
(
revision
<=
ver
.
revision
)
||
(
build
<=
ver
.
build
);
}
bool
operator
>=
(
const
Version
&
ver
)
{
return
(
major
>=
ver
.
major
)
||
(
minor
>=
ver
.
minor
)
||
(
revision
>=
ver
.
revision
)
||
(
build
>=
ver
.
build
);
}
};
};
struct
UpdateInfo
{
struct
UpdateInfo
{
...
...
jlib/win32/DeviceUniqueIdentifier.h
View file @
0f15c5eb
...
@@ -358,7 +358,7 @@ static bool query(const std::vector<QueryType>& queryTypes, QueryResults& result
...
@@ -358,7 +358,7 @@ static bool query(const std::vector<QueryType>& queryTypes, QueryResults& result
auto
rpos
=
index
.
find
(
L"
\\
Partition"
,
pos
);
auto
rpos
=
index
.
find
(
L"
\\
Partition"
,
pos
);
if
(
rpos
!=
index
.
npos
&&
rpos
-
pos
>
strlen
(
"Harddisk"
))
{
if
(
rpos
!=
index
.
npos
&&
rpos
-
pos
>
strlen
(
"Harddisk"
))
{
auto
n
=
index
.
substr
(
pos
+
strlen
(
"Harddisk"
),
rpos
-
pos
-
strlen
(
"Harddisk"
));
auto
n
=
index
.
substr
(
pos
+
strlen
(
"Harddisk"
),
rpos
-
pos
-
strlen
(
"Harddisk"
));
if
(
wmi
.
execute
(
L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = "
+
n
))
{
if
(
wmi
.
execute
(
L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = "
+
n
)
&&
!
values
.
empty
()
)
{
results
[
queryType
]
=
values
.
back
();
values
.
pop_back
();
results
[
queryType
]
=
values
.
back
();
values
.
pop_back
();
continue
;
continue
;
}
}
...
...
jlib/win32/UnicodeTool.h
View file @
0f15c5eb
#pragma once
#pragma once
#include <windows.h>
#include <windows.h>
#include <string>
namespace
jlib
namespace
jlib
{
{
namespace
win32
namespace
win32
{
{
inline
bool
mbcs_to_u16
(
const
char
*
mbcs
,
wchar_t
*
u16buffer
,
size_t
u16size
)
{
size_t
request_size
=
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
,
-
1
,
NULL
,
0
);
if
(
0
<
request_size
&&
request_size
<
u16size
)
{
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
,
-
1
,
u16buffer
,
request_size
);
return
true
;
}
return
false
;
};
inline
std
::
wstring
mbcs_to_u16
(
const
std
::
string
&
mbcs
)
{
std
::
wstring
res
=
L""
;
size_t
request_size
=
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
.
c_str
(),
-
1
,
NULL
,
0
);
if
(
0
<
request_size
)
{
auto
u16buffer
=
new
wchar_t
[
request_size
];
MultiByteToWideChar
(
CP_ACP
,
0
,
mbcs
.
c_str
(),
-
1
,
u16buffer
,
request_size
);
res
=
u16buffer
;
delete
[]
u16buffer
;
}
return
res
;
}
inline
std
::
string
u16_to_mbcs
(
const
std
::
wstring
&
u16
)
{
std
::
string
res
=
""
;
size_t
request_size
=
WideCharToMultiByte
(
CP_ACP
,
0
,
u16
.
c_str
(),
-
1
,
0
,
0
,
0
,
0
);
if
(
0
<
request_size
)
{
auto
mbcs_buffer
=
new
char
[
request_size
];
WideCharToMultiByte
(
CP_ACP
,
0
,
u16
.
c_str
(),
-
1
,
mbcs_buffer
,
request_size
,
0
,
0
);
res
=
mbcs_buffer
;
delete
[]
mbcs_buffer
;
}
return
res
;
}
inline
std
::
string
mbcs_to_utf8
(
const
std
::
wstring
&
mbcs
)
{
std
::
string
res
=
""
;
size_t
request_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
mbcs
.
c_str
(),
-
1
,
0
,
0
,
0
,
0
);
if
(
0
<
request_size
)
{
auto
mbcs_buffer
=
new
char
[
request_size
];
WideCharToMultiByte
(
CP_UTF8
,
0
,
mbcs
.
c_str
(),
-
1
,
mbcs_buffer
,
request_size
,
0
,
0
);
res
=
mbcs_buffer
;
delete
[]
mbcs_buffer
;
}
return
res
;
}
inline
bool
Utf16ToUtf8
(
const
wchar_t
*
utf16String
,
char
*
utf8Buffer
,
size_t
szBuff
)
inline
bool
Utf16ToUtf8
(
const
wchar_t
*
utf16String
,
char
*
utf8Buffer
,
size_t
szBuff
)
{
{
size_t
request_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
utf16String
,
-
1
,
NULL
,
0
,
0
,
0
);
size_t
request_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
utf16String
,
-
1
,
NULL
,
0
,
0
,
0
);
...
...
test/test_version/test_version.vcxproj
View file @
0f15c5eb
...
@@ -76,6 +76,7 @@
...
@@ -76,6 +76,7 @@
<Optimization>
Disabled
</Optimization>
<Optimization>
Disabled
</Optimization>
<SDLCheck>
true
</SDLCheck>
<SDLCheck>
true
</SDLCheck>
<ConformanceMode>
true
</ConformanceMode>
<ConformanceMode>
true
</ConformanceMode>
<LanguageStandard>
stdcpp17
</LanguageStandard>
</ClCompile>
</ClCompile>
<Link>
<Link>
<SubSystem>
Console
</SubSystem>
<SubSystem>
Console
</SubSystem>
...
...
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