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
10517a13
Commit
10517a13
authored
Sep 09, 2019
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8ca7061b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
209 additions
and
137 deletions
+209
-137
timestamp.h
jlib/base/timestamp.h
+1
-1
space.h
jlib/space.h
+6
-4
DeviceUniqueIdentifier.cpp
jlib/win32/DeviceUniqueIdentifier.cpp
+41
-41
FileOper.h
jlib/win32/mfc/FileOper.h
+2
-2
resolve.h
jlib/win32/resolve.h
+156
-0
test.cpp
test/test/test.cpp
+1
-1
test.vcxproj
test/test/test.vcxproj
+1
-22
test.vcxproj.filters
test/test/test.vcxproj.filters
+0
-65
test.cpp
test/testDeviceUniqueIdentifier/test.cpp
+1
-1
No files found.
jlib/base/timestamp.h
View file @
10517a13
...
...
@@ -43,7 +43,7 @@ public:
:
microSecondsSinceEpoch_
(
microSecondsSinceEpoch
)
{}
static
const
int
MICRO_SECONDS_PER_SECOND
=
1000
*
1000
;
static
const
expr
int
MICRO_SECONDS_PER_SECOND
=
1000
*
1000
;
void
swap
(
Timestamp
&
rhs
)
{
std
::
swap
(
microSecondsSinceEpoch_
,
rhs
.
microSecondsSinceEpoch_
);
...
...
jlib/space.h
View file @
10517a13
...
...
@@ -24,12 +24,14 @@ static std::string human_readable_byte_count(uintmax_t bytes, size_t precision =
auto
unit
=
po
==
PositionalNotation
::
Binary
?
1024
:
1000
;
if
(
bytes
<
unit
)
{
return
std
::
to_string
(
bytes
)
+
"B"
;
}
auto
exp
=
static_cast
<
in
t
>
(
std
::
log
(
bytes
)
/
std
::
log
(
unit
));
auto
exp
=
static_cast
<
size_
t
>
(
std
::
log
(
bytes
)
/
std
::
log
(
unit
));
auto
pre
=
std
::
string
(
"KMGTPEZYBND"
).
at
(
exp
-
1
)
+
std
::
string
(
po
==
PositionalNotation
::
Binary
?
"i"
:
""
);
auto
var
=
bytes
/
std
::
pow
(
unit
,
exp
);
std
::
stringstream
ss
;
ss
<<
std
::
fixed
<<
std
::
setprecision
(
1
)
<<
var
<<
pre
<<
"B"
;
return
ss
.
str
();
//std::stringstream ss;
//ss << std::fixed << std::setprecision(1) << var << pre << "B";
char
buf
[
64
]
=
{
0
};
snprintf
(
buf
,
sizeof
(
buf
),
"%.1lf%sB"
,
var
,
pre
.
data
());
return
buf
;
}
}
jlib/win32/DeviceUniqueIdentifier.cpp
View file @
10517a13
This diff is collapsed.
Click to expand it.
jlib/win32/mfc/FileOper.h
View file @
10517a13
...
...
@@ -259,7 +259,7 @@ public:
LPCTSTR
szNewName
=
newFileName
.
GetBuffer
(
newFileName
.
GetLength
());
newFileName
.
ReleaseBuffer
();
MoveFile
(
szOldName
,
szNewName
);
TRACE
(
_T
(
"movefile %s to %s
\n
"
),
fileName
,
newFileName
);
TRACE
(
_T
(
"movefile %s to %s
\n
"
),
(
LPCWSTR
)
fileName
,
(
LPCWSTR
)
newFileName
);
return
TRUE
;
}
...
...
@@ -271,7 +271,7 @@ public:
CString
filter
=
_T
(
""
);
filter
.
Format
(
_T
(
"%s
\\
%s"
),
lpszFolder
,
lpszFilter
);
BOOL
bFound
=
find
.
FindFile
(
filter
);
TRACE
(
_T
(
"CFileOper::DeleteFilesInFolder find path %s
\n
"
),
filter
);
TRACE
(
_T
(
"CFileOper::DeleteFilesInFolder find path %s
\n
"
),
(
LPCWSTR
)
filter
);
CString
filepath
=
_T
(
""
);
while
(
bFound
){
bFound
=
find
.
FindNextFile
();
...
...
jlib/win32/resolve.h
0 → 100644
View file @
10517a13
#
pragma
once
#include <Windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <string>
#include "../log2.h"
namespace
jlib
{
//! get first ipv4 of domain
static
std
::
string
resolve
(
const
std
::
string
&
domain
)
{
AUTO_LOG_FUNCTION
;
struct
addrinfo
*
result
=
nullptr
;
struct
addrinfo
*
ptr
=
nullptr
;
struct
addrinfo
hints
;
struct
sockaddr_in
*
sockaddr_ipv4
;
// struct sockaddr_in6 *sockaddr_ipv6;
LPSOCKADDR
sockaddr_ip
;
char
ipstringbuffer
[
46
];
DWORD
ipbufferlength
=
46
;
//--------------------------------
// Setup the hints address info structure
// which is passed to the getaddrinfo() function
ZeroMemory
(
&
hints
,
sizeof
(
hints
));
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_protocol
=
IPPROTO_TCP
;
std
::
string
ip
;
do
{
//--------------------------------
// Call getaddrinfo(). If the call succeeds,
// the result variable will hold a linked list
// of addrinfo structures containing response
// information
DWORD
dwRetval
=
getaddrinfo
(
domain
.
c_str
(),
"0"
,
&
hints
,
&
result
);
if
(
dwRetval
!=
0
)
{
JLOG_INFO
(
"getaddrinfo failed with error: {}"
,
dwRetval
);
break
;
}
JLOG_INFO
(
"getaddrinfo returned success"
);
// Retrieve each address and print out the hex bytes
int
i
=
0
;
int
iRetval
=
0
;
bool
ok
=
false
;
for
(
ptr
=
result
;
ptr
!=
nullptr
;
ptr
=
ptr
->
ai_next
)
{
JLOG_INFO
(
"getaddrinfo response {}"
,
i
++
);
JLOG_INFO
(
"
\t
Flags: 0x{:08x}"
,
ptr
->
ai_flags
);
JLOG_INFO
(
"
\t
Family: "
);
switch
(
ptr
->
ai_family
)
{
case
AF_UNSPEC
:
JLOG_INFO
(
"Unspecified"
);
break
;
case
AF_INET
:
JLOG_INFO
(
"AF_INET (IPv4)"
);
sockaddr_ipv4
=
(
struct
sockaddr_in
*
)
ptr
->
ai_addr
;
ip
=
inet_ntoa
(
sockaddr_ipv4
->
sin_addr
);
JLOG_INFO
(
"
\t
IPv4 address {}"
,
ip
);
ok
=
true
;
break
;
case
AF_INET6
:
JLOG_INFO
(
"AF_INET6 (IPv6)"
);
// the InetNtop function is available on Windows Vista and later
// sockaddr_ipv6 = (struct sockaddr_in6 *) ptr->ai_addr;
// printf("\tIPv6 address %s",
// InetNtop(AF_INET6, &sockaddr_ipv6->sin6_addr, ipstringbuffer, 46) );
// We use WSAAddressToString since it is supported on Windows XP and later
sockaddr_ip
=
(
LPSOCKADDR
)
ptr
->
ai_addr
;
// The buffer length is changed by each call to WSAAddresstoString
// So we need to set it for each iteration through the loop for safety
ipbufferlength
=
46
;
iRetval
=
WSAAddressToStringA
(
sockaddr_ip
,
(
DWORD
)
ptr
->
ai_addrlen
,
nullptr
,
ipstringbuffer
,
&
ipbufferlength
);
if
(
iRetval
)
JLOG_INFO
(
"WSAAddressToString failed with {}"
,
WSAGetLastError
());
else
JLOG_INFO
(
"
\t
IPv6 address {}"
,
ipstringbuffer
);
break
;
case
AF_NETBIOS
:
JLOG_INFO
(
"AF_NETBIOS (NetBIOS)"
);
break
;
default
:
JLOG_INFO
(
"Other {}"
,
ptr
->
ai_family
);
break
;
}
JLOG_INFO
(
"
\t
Socket type: "
);
switch
(
ptr
->
ai_socktype
)
{
case
0
:
JLOG_INFO
(
"Unspecified"
);
break
;
case
SOCK_STREAM
:
JLOG_INFO
(
"SOCK_STREAM (stream)"
);
break
;
case
SOCK_DGRAM
:
JLOG_INFO
(
"SOCK_DGRAM (datagram) "
);
break
;
case
SOCK_RAW
:
JLOG_INFO
(
"SOCK_RAW (raw) "
);
break
;
case
SOCK_RDM
:
JLOG_INFO
(
"SOCK_RDM (reliable message datagram)"
);
break
;
case
SOCK_SEQPACKET
:
JLOG_INFO
(
"SOCK_SEQPACKET (pseudo-stream packet)"
);
break
;
default
:
JLOG_INFO
(
"Other {}
\n
"
,
ptr
->
ai_socktype
);
break
;
}
JLOG_INFO
(
"
\t
Protocol: "
);
switch
(
ptr
->
ai_protocol
)
{
case
0
:
JLOG_INFO
(
"Unspecified"
);
break
;
case
IPPROTO_TCP
:
JLOG_INFO
(
"IPPROTO_TCP (TCP)"
);
break
;
case
IPPROTO_UDP
:
JLOG_INFO
(
"IPPROTO_UDP (UDP)"
);
break
;
default
:
JLOG_INFO
(
"Other {}"
,
ptr
->
ai_protocol
);
break
;
}
JLOG_INFO
(
"
\t
Length of this sockaddr: {}"
,
ptr
->
ai_addrlen
);
JLOG_INFO
(
"
\t
Canonical name: {}"
,
ptr
->
ai_canonname
?
ptr
->
ai_canonname
:
"null"
);
if
(
ok
)
{
break
;
}
}
freeaddrinfo
(
result
);
if
(
ok
)
{
return
ip
;
}
}
while
(
false
);
return
""
;
}
}
test/test/test.cpp
View file @
10517a13
// test.cpp : Defines the entry point for the console application.
//
#define _CRT_SECURE_NO_WARNINGS
#include "jlib/chrono_wrapper.h"
#include "jlib/dp.h"
#include "jlib/log2.h"
...
...
@@ -14,7 +15,6 @@
#include "jlib/vs_ver.h"
#include "jlib/win32.h"
#include <jlib/3rdparty/win32/Registry.hpp>
#include <jlib/win32/mfc/FileOper.h>
int
main
()
...
...
test/test/test.vcxproj
View file @
10517a13
...
...
@@ -101,7 +101,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<PrecompiledHeader>
Use
</PrecompiledHeader>
<PrecompiledHeader>
NotUsing
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<Optimization>
Disabled
</Optimization>
<PreprocessorDefinitions>
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
...
...
@@ -155,27 +155,6 @@
<ItemGroup>
<ClCompile
Include=
"test.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\..\jlib\chrono_wrapper.h"
/>
<ClInclude
Include=
"..\..\jlib\dp.h"
/>
<ClInclude
Include=
"..\..\jlib\log.h"
/>
<ClInclude
Include=
"..\..\jlib\log2.h"
/>
<ClInclude
Include=
"..\..\jlib\mem_tool.h"
/>
<ClInclude
Include=
"..\..\jlib\micro_getter_setter.h"
/>
<ClInclude
Include=
"..\..\jlib\net.h"
/>
<ClInclude
Include=
"..\..\jlib\space.h"
/>
<ClInclude
Include=
"..\..\jlib\utf8.h"
/>
<ClInclude
Include=
"..\..\jlib\version_no.h"
/>
<ClInclude
Include=
"..\..\jlib\win32.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\clipboard.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\DeviceUniqueIdentifierHeaderOnly.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\file_op.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\memory_micros.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\MtVerify.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\MyWSAError.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\path_op.h"
/>
<ClInclude
Include=
"..\..\jlib\win32\UnicodeTool.h"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
...
...
test/test/test.vcxproj.filters
View file @
10517a13
...
...
@@ -13,75 +13,10 @@
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
<Filter
Include=
"Header Files\JLIB"
>
<UniqueIdentifier>
{b07730c2-1faa-4cf8-bdd5-69236acd73c0}
</UniqueIdentifier>
</Filter>
<Filter
Include=
"Header Files\JLIB\win32"
>
<UniqueIdentifier>
{eb85af39-9206-4efd-9502-a8769c529014}
</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"test.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\..\jlib\chrono_wrapper.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\dp.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\log.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\log2.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\mem_tool.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\micro_getter_setter.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\net.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\space.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\utf8.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\version_no.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32.h"
>
<Filter>
Header Files\JLIB
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\clipboard.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\file_op.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\memory_micros.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\MtVerify.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\MyWSAError.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\path_op.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\UnicodeTool.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\jlib\win32\DeviceUniqueIdentifierHeaderOnly.h"
>
<Filter>
Header Files\JLIB\win32
</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
test/testDeviceUniqueIdentifier/test.cpp
View file @
10517a13
#include <jlib/win32/DeviceUniqueIdentifier.h>
#include <stdio.h>
#include <algorithm>
#include <locale
.h
>
#include <locale>
int
main
()
{
...
...
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