Commit 10517a13 authored by captainwong's avatar captainwong

update

parent 8ca7061b
......@@ -43,7 +43,7 @@ public:
: microSecondsSinceEpoch_(microSecondsSinceEpoch)
{}
static const int MICRO_SECONDS_PER_SECOND = 1000 * 1000;
static constexpr int MICRO_SECONDS_PER_SECOND = 1000 * 1000;
void swap(Timestamp& rhs) {
std::swap(microSecondsSinceEpoch_, rhs.microSecondsSinceEpoch_);
......
......@@ -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<int>(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;
}
}
This diff is collapsed.
......@@ -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();
......
#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("\tFlags: 0x{:08x}", ptr->ai_flags);
JLOG_INFO("\tFamily: ");
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("\tIPv4 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("\tIPv6 address {}", ipstringbuffer);
break;
case AF_NETBIOS:
JLOG_INFO("AF_NETBIOS (NetBIOS)");
break;
default:
JLOG_INFO("Other {}", ptr->ai_family);
break;
}
JLOG_INFO("\tSocket 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("\tProtocol: ");
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("\tLength of this sockaddr: {}", ptr->ai_addrlen);
JLOG_INFO("\tCanonical name: {}", ptr->ai_canonname ? ptr->ai_canonname : "null");
if (ok) {
break;
}
}
freeaddrinfo(result);
if (ok) {
return ip;
}
} while (false);
return "";
}
}
// 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()
......
......@@ -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>
......
......@@ -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
#include <jlib/win32/DeviceUniqueIdentifier.h>
#include <stdio.h>
#include <algorithm>
#include <locale.h>
#include <locale>
int main()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment