Commit 56bec381 authored by captainwong's avatar captainwong

update

parent d8c34b99
...@@ -101,7 +101,7 @@ inline void dump_hex(const void* buff, size_t buff_len) ...@@ -101,7 +101,7 @@ inline void dump_hex(const void* buff, size_t buff_len)
return; return;
} }
char output[4096] = { 0 }; char output[MAX_OUT_BUFF_LEN] = { 0 };
char c[128] = { 0 }; char c[128] = { 0 };
std::sprintf(c, "dump_hex: buff 0x%p, buff_len %zu\n", buff, buff_len); std::sprintf(c, "dump_hex: buff 0x%p, buff_len %zu\n", buff, buff_len);
...@@ -124,7 +124,7 @@ inline void dump_hex(const void* buff, size_t buff_len) ...@@ -124,7 +124,7 @@ inline void dump_hex(const void* buff, size_t buff_len)
JLOG_WARN(output); JLOG_WARN(output);
} }
inline void dump_asc(const void* buff, size_t buff_len) inline void dump_asc(const void* buff, size_t buff_len, bool seperate_with_space = true, bool force_new_line = true)
{ {
size_t output_len = buff_len * 6 + 64; size_t output_len = buff_len * 6 + 64;
if (output_len > MAX_OUT_BUFF_LEN) { if (output_len > MAX_OUT_BUFF_LEN) {
...@@ -132,22 +132,30 @@ inline void dump_asc(const void* buff, size_t buff_len) ...@@ -132,22 +132,30 @@ inline void dump_asc(const void* buff, size_t buff_len)
return; return;
} }
char output[4096] = { 0 }; char output[MAX_OUT_BUFF_LEN] = { 0 };
char c[128] = { 0 }; char c[128] = { 0 };
std::sprintf(c, "dump_asc: buff 0x%p, buff_len %zu\n", buff, buff_len); std::sprintf(c, "dump_asc: buff 0x%p, buff_len %zu\n", buff, buff_len);
std::strcat(output, c); std::strcat(output, "\n");
for (size_t i = 0; i < 16; i++) { if (force_new_line) {
char tmp[4]; for (size_t i = 0; i < 16; i++) {
std::sprintf(tmp, "%02zX ", i); char tmp[4];
std::strcat(c, tmp); std::sprintf(tmp, "%02zX", i);
std::strcat(c, tmp);
if (seperate_with_space) {
std::strcat(c, " ");
}
}
std::strcat(output, c); std::strcat(output, "\n");
} }
std::strcat(output, c); std::strcat(output, "\n");
for (size_t i = 0; i < buff_len; i++) { for (size_t i = 0; i < buff_len; i++) {
std::sprintf(c, "%c ", reinterpret_cast<const char*>(buff)[i]); std::sprintf(c, "%c", reinterpret_cast<const char*>(buff)[i]);
if (seperate_with_space) {
std::strcat(c, " ");
}
std::strcat(output, c); std::strcat(output, c);
if (i > 0 && (i + 1) % 16 == 0) { if (force_new_line && i > 0 && (i + 1) % 16 == 0) {
std::strcat(output, "\n"); std::strcat(output, "\n");
} }
} }
......
#pragma once #pragma once
namespace jlib { namespace jlib {
inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr) { inline bool get_file_open_dialog_result(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC *rgFilterSpec = nullptr) {
bool ok = false; bool ok = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
...@@ -16,6 +20,18 @@ inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr) ...@@ -16,6 +20,18 @@ inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr)
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
if (!ext.empty()) {
pFileOpen->SetDefaultExtension(ext.c_str());
}
if (cFileTypes != 0 && rgFilterSpec) {
pFileOpen->SetFileTypes(cFileTypes, rgFilterSpec);
}
if (!hWnd) {
hWnd = ::GetDesktopWindow();
}
// Show the Open dialog box. // Show the Open dialog box.
hr = pFileOpen->Show(hWnd); hr = pFileOpen->Show(hWnd);
...@@ -45,12 +61,11 @@ inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr) ...@@ -45,12 +61,11 @@ inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr)
return ok; return ok;
} }
inline bool get_save_as_dialog_path(std::wstring& path, inline bool get_save_as_dialog_path(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& ext = L"", const std::wstring& ext = L"",
UINT cFileTypes = 0, UINT cFileTypes = 0,
const COMDLG_FILTERSPEC *rgFilterSpec = nullptr, const COMDLG_FILTERSPEC *rgFilterSpec = nullptr) {
HWND hWnd = nullptr) {
bool ok = false; bool ok = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
......
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