Commit e561276a authored by captainwong's avatar captainwong

update

parent e5bd9695
......@@ -45,6 +45,55 @@ namespace utf8 {
utf8::utf8to16(a.begin(), a.end(), std::back_inserter(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
#pragma once
#include <string>
#include <algorithm>
#include <cctype>
#include <locale>
namespace jlib
{
// Taken from https://stackoverflow.com/a/217605/2963736
// Thanks https://stackoverflow.com/users/13430/evan-teran
//************ string **************//
// trim from start (in place)
inline void ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch); }));
}
// trim from end (in place)
inline void rtrim(std::string& s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch); }).base(), s.end());
}
// trim from both ends (in place)
inline void trim(std::string& s) {
ltrim(s); rtrim(s);
}
// trim from start (copying)
inline std::string ltrim_copy(std::string s) {
ltrim(s); return s;
}
// trim from end (copying)
inline std::string rtrim_copy(std::string s) {
rtrim(s); return s;
}
// trim from both ends (copying)
inline std::string trim_copy(std::string s) {
trim(s); return s;
}
//************ wstring **************//
// trim from start (in place)
inline void ltrim(std::wstring& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch); }));
}
// trim from end (in place)
inline void rtrim(std::wstring& s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch); }).base(), s.end());
}
// trim from both ends (in place)
inline void trim(std::wstring& s) {
ltrim(s); rtrim(s);
}
// trim from start (copying)
inline std::wstring ltrim_copy(std::wstring s) {
ltrim(s); return s;
}
// trim from end (copying)
inline std::wstring rtrim_copy(std::wstring s) {
rtrim(s); return s;
}
// trim from both ends (copying)
inline std::wstring trim_copy(std::wstring s) {
trim(s); return s;
}
} // namespace jlib
......@@ -6,16 +6,19 @@
#include <fstream>
#include <vector>
namespace jlib {
namespace jlib
{
struct version_no {
struct Version {
int major = 0;
int minor = 0;
int revision = 0;
int build = 0;
version_no& from_string(const std::string& s) {
std::sscanf(s.c_str(), "%d.%d.%d.%d", &major, &minor, &revision, &build);
Version& fromString(const std::string& s) {
if (std::sscanf(s.c_str(), "%d.%d.%d.%d", &major, &minor, &revision, &build) != 4) {
reset(); return *this;
}
if (major < 0) major = 0;
if (minor < 0) minor = 0;
if (revision < 0) revision = 0;
......@@ -23,10 +26,11 @@ struct version_no {
return *this;
}
std::string to_string() const {
std::stringstream ss;
ss << major << "." << minor << "." << revision << "." << build;
return ss.str();
std::string toString() const {
return std::to_string(major) + "."
+ std::to_string(minor) + "."
+ std::to_string(revision) + "."
+ std::to_string(build);
}
bool valid() {
......@@ -37,14 +41,14 @@ struct version_no {
major = minor = revision = build = 0;
}
bool operator == (const version_no& ver) {
bool operator == (const Version& ver) {
return major == ver.major
&& minor == ver.minor
&& revision == ver.revision
&& build == ver.build;
}
bool operator < (const version_no& ver) {
bool operator < (const Version& ver) {
if (major > ver.major) return false;
if (minor > ver.minor) return false;
if (revision > ver.revision) return false;
......@@ -52,30 +56,28 @@ struct version_no {
if (this->operator==(ver)) return false;
return true;
}
};
struct update_info_json {
version_no ver;
std::string change;
std::vector<std::string> dllinks;
struct UpdateInfo {
Version version = {};
std::string change = {};
std::vector<std::string> dllinks = {};
};
struct update_info_text {
version_no ver;
std::string dllink;
struct UpdateInfoText {
Version version = {};
std::string dllink = {};
};
inline bool get_version_no_from_file(version_no& ver, const std::string& file_path) {
inline bool getVersionFromFile(const std::string& file_path, Version& version) {
std::ifstream in(file_path);
if (!in)return false;
std::stringstream is;
is << in.rdbuf();
version_no file_ver;
file_ver.from_string(is.str());
Version file_ver;
file_ver.fromString(is.str());
if (file_ver.valid()) {
ver = file_ver;
version = file_ver;
return true;
}
return false;
......
#pragma once
#include <windows.h>
#include <objbase.h>
#include <Shobjidl.h>
#include <string>
#include <vector>
#include "base/noncopyable.h"
#include "utf8.h"
#include "win32/MyWSAError.h"
......@@ -14,267 +9,6 @@
#endif
#include "win32/memory_micros.h"
#include "win32/clipboard.h"
#include "win32/process.h"
#include "win32/window.h"
namespace utf8 {
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;
}
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
namespace jlib {
inline DWORD daemon(const std::wstring& path, bool wait_app_exit = true, bool show = true) {
STARTUPINFOW si = { 0 };
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = show ? SW_SHOW : SW_HIDE;
PROCESS_INFORMATION pi;
DWORD dwCreationFlags = show ? 0 : CREATE_NO_WINDOW;
BOOL bRet = CreateProcessW(NULL, (LPWSTR)(path.c_str()), NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi);
if (bRet) {
WaitForSingleObject(pi.hProcess, wait_app_exit ? INFINITE : 0);
DWORD dwExit;
::GetExitCodeProcess(pi.hProcess, &dwExit);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return dwExit;
}
return 0xFFFFFFFF;
}
inline DWORD daemon(const std::string& path, bool wait_app_exit = true, bool show = true) {
return daemon(utf8::a2w(path), wait_app_exit, show);
}
inline BOOL Win32CenterWindow(HWND hwndWindow)
{
HWND hwndParent;
RECT rectWindow, rectParent;
if ((hwndParent = GetParent(hwndWindow)) == NULL) {
hwndParent = GetDesktopWindow();
}
// make the window relative to its parent
if (hwndParent != NULL) {
GetWindowRect(hwndWindow, &rectWindow);
GetWindowRect(hwndParent, &rectParent);
int nWidth = rectWindow.right - rectWindow.left;
int nHeight = rectWindow.bottom - rectWindow.top;
int nX = ((rectParent.right - rectParent.left) - nWidth) / 2 + rectParent.left;
int nY = ((rectParent.bottom - rectParent.top) - nHeight) / 2 + rectParent.top;
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
// make sure that the dialog box never moves outside of the screen
if (nX < 0) nX = 0;
if (nY < 0) nY = 0;
if (nX + nWidth > nScreenWidth) nX = nScreenWidth - nWidth;
if (nY + nHeight > nScreenHeight) nY = nScreenHeight - nHeight;
MoveWindow(hwndWindow, nX, nY, nWidth, nHeight, FALSE);
return TRUE;
}
return FALSE;
}
class auto_timer : public noncopyable
{
private:
int m_timer_id;
DWORD m_time_out;
HWND m_hWnd;
public:
auto_timer(HWND hWnd, int timerId, DWORD timeout) : m_hWnd(hWnd), m_timer_id(timerId), m_time_out(timeout)
{
KillTimer(hWnd, m_timer_id);
}
~auto_timer()
{
SetTimer(m_hWnd, m_timer_id, m_time_out, nullptr);
}
};
namespace rc_detail {
inline long Width(::LPCRECT rc) {
return rc->right - rc->left;
}
inline long Height(::LPCRECT rc) {
return rc->bottom - rc->top;
}
inline void DeflateRect(::LPRECT rc, int l, int t, int r, int b) {
rc->left += l;
rc->top += t;
rc->right -= r;
rc->bottom -= b;
}
inline void InflateRect(::LPRECT rc, int l, int t, int r, int b) {
rc->left -= l;
rc->top -= t;
rc->right += r;
rc->bottom += b;
}
}
// 将矩形平均分割成n份,间距2*gap, n is x^2, x={1,2,3...}
inline std::vector<::RECT> split_rect(::LPCRECT rc, int n, int gap = 50) {
using namespace rc_detail;
std::vector<::RECT> v;
for (int i = 0; i < n; i++) {
v.push_back(*rc);
}
double l = sqrt(n);
int line = int(l);
int col_step = (int)(Width(rc) / line);
int row_step = (int)(Height(rc) / line);
for (int i = 0; i < n; i++) {
v[i].left = rc->left + (i % line) * col_step;
v[i].right = v[i].left + col_step;
v[i].top = rc->top + (i / line) * row_step;
v[i].bottom = v[i].top + row_step;
DeflateRect(&v[i], gap, gap, gap, gap);
}
return v;
};
// 将矩形水平平均分割为n份矩形, 当hgap==-1时,分割出的矩形与源矩形保持比例
inline std::vector<::RECT> split_rect_horizontal(::LPCRECT rc, int n, int wgap = 50, int hgap = -1) {
using namespace rc_detail;
std::vector<::RECT> v;
int w = (Width(rc) - (n + 1) * wgap) / n;
if (hgap == -1) {
double ratio = (rc->right - rc->left) * 1.0 / (rc->bottom - rc->top);
int h = static_cast<int>(w / ratio);
hgap = (Height(rc) - h) / 2;
}
for (int i = 0; i < n; i++) {
::RECT r = *rc;
r.left += i*w + (i + 1)*wgap;
r.right = r.left + w;
r.top = rc->top + hgap;
r.bottom = rc->bottom - hgap;
v.push_back(r);
}
return v;
}
// rc's width / spliter = (rc's width - hexagon's side length) / 2
inline std::vector<::POINT> get_hexagon_vertexes_from_rect(::LPCRECT rc, float spliter = 3.0) {
if (!rc) {
return std::vector<::POINT>();
}
if (spliter == 0.0) {
spliter = 3.0;
}
std::vector<::POINT> v;
auto w = rc->right - rc->left;
auto h = rc->bottom - rc->top;
auto ww = static_cast<int>(w / spliter);
auto hh = static_cast<int>(h / spliter);
::POINT pt;
pt.x = rc->left;
pt.y = rc->top + hh;
v.push_back(pt);
pt.x = rc->left + ww;
pt.y = rc->top;
v.push_back(pt);
pt.x = rc->right - ww;
v.push_back(pt);
pt.x = rc->right;
pt.y = rc->top + hh;
v.push_back(pt);
pt.y = rc->bottom - hh;
v.push_back(pt);
pt.x = rc->right - ww;
pt.y = rc->bottom;
v.push_back(pt);
pt.x = rc->left + ww;
v.push_back(pt);
pt.x = rc->left;
pt.y = rc->bottom - hh;
v.push_back(pt);
return v;
}
};
......@@ -348,11 +348,21 @@ static bool query(const std::vector<QueryType>& queryTypes, QueryResults& result
if (queryType == BOOTABLE_HARDDISK_SERIAL) {
auto sz = values.size();
if (wmi.execute(L"SELECT DiskIndex FROM Win32_DiskPartition WHERE Bootable = TRUE") && values.size() == sz + 1) {
// possible value:
// Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk4\Partition4
if (wmi.execute(L"Select Name from Win32_OperatingSystem") && values.size() == sz + 1) {
auto index = values.back(); values.pop_back();
if (wmi.execute(L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = " + index)) {
results[queryType] = values.back(); values.pop_back();
continue;
auto pos = index.find(L"Harddisk");
if (pos != index.npos) {
auto rpos = index.find(L"\\Partition", pos);
if (rpos != index.npos && 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)) {
results[queryType] = values.back(); values.pop_back();
continue;
}
}
}
}
} else {
......
#pragma once
#include <Windows.h>
#include <ShlObj.h>
#include <string>
#pragma comment(lib, "Shell32.lib")
namespace jlib
{
namespace win32
{
inline bool get_file_open_dialog_result(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& default_folder = L"",
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC * rgFilterSpec = nullptr)
/**
example of COMDLG_FILTERSPEC:
COMDLG_FILTERSPEC cf[2] = {};
cf[0].pszName = L"Text Files";
cf[0].pszSpec = L"*.txt";
cf[1].pszName = L"All Files";
cf[1].pszSpec = L"*.*";
*/
inline bool getOpenFileDialogResult(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& default_folder = L"",
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC* filter = nullptr)
{
bool ok = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
......@@ -27,11 +40,6 @@ inline bool get_file_open_dialog_result(std::wstring& path,
if (SUCCEEDED(hr)) {
if (!default_folder.empty()) {
IShellItem* psiFolder;
//LPCWSTR szFilePath = SysAllocStringLen(default_folder.data(), default_folder.size());
//hr = SHCreateItemFromParsingName(szFilePath, NULL, IID_PPV_ARGS(&psiFolder));
//if (SUCCEEDED(hr))
// hr = pFileOpen->SetDefaultFolder(psiFolder);
PIDLIST_ABSOLUTE pidl;
hr = SHParseDisplayName(default_folder.data(), 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hr)) {
......@@ -47,8 +55,8 @@ inline bool get_file_open_dialog_result(std::wstring& path,
pFileOpen->SetDefaultExtension(ext.data());
}
if (cFileTypes != 0 && rgFilterSpec) {
pFileOpen->SetFileTypes(cFileTypes, rgFilterSpec);
if (cFileTypes != 0 && filter) {
pFileOpen->SetFileTypes(cFileTypes, filter);
}
if (!hWnd) {
......@@ -84,13 +92,13 @@ inline bool get_file_open_dialog_result(std::wstring& path,
return ok;
}
inline bool get_save_as_dialog_path(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& default_folder = L"",
const std::wstring& default_name = L"",
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC * rgFilterSpec = nullptr)
inline bool getSaveAsDialogPath(std::wstring& path,
HWND hWnd = nullptr,
const std::wstring& default_folder = L"",
const std::wstring& default_name = L"",
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC* filter = nullptr)
{
bool ok = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
......@@ -105,11 +113,6 @@ inline bool get_save_as_dialog_path(std::wstring& path,
if (SUCCEEDED(hr)) {
if (!default_folder.empty()) {
IShellItem* psiFolder;
//LPCWSTR szFilePath = SysAllocStringLen(default_folder.data(), default_folder.size());
//hr = SHCreateItemFromParsingName(szFilePath, NULL, IID_PPV_ARGS(&psiFolder));
//if (SUCCEEDED(hr))
// hr = pFileSave->SetDefaultFolder(psiFolder);
PIDLIST_ABSOLUTE pidl;
hr = SHParseDisplayName(default_folder.data(), 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hr)) {
......@@ -129,8 +132,8 @@ inline bool get_save_as_dialog_path(std::wstring& path,
pFileSave->SetDefaultExtension(ext.data());
}
if (cFileTypes != 0 && rgFilterSpec) {
pFileSave->SetFileTypes(cFileTypes, rgFilterSpec);
if (cFileTypes != 0 && filter) {
pFileSave->SetFileTypes(cFileTypes, filter);
}
if (!hWnd) {
......
#pragma once
#include <string>
#include <algorithm>
#include <Windows.h>
#include <ShlObj.h>
#include <string>
#include <algorithm>
#pragma comment(lib, "Shell32.lib")
namespace jlib {
namespace win32 {
inline std::wstring get_exe_path()
inline std::wstring getExePath()
{
wchar_t path[1024] = { 0 };
GetModuleFileNameW(nullptr, path, 1024);
......@@ -17,7 +19,7 @@ inline std::wstring get_exe_path()
return std::wstring(path).substr(0, pos);
}
inline std::string get_exe_path_a()
inline std::string getExePathA()
{
char path[1024] = { 0 };
GetModuleFileNameA(nullptr, path, 1024);
......@@ -25,8 +27,10 @@ inline std::string get_exe_path_a()
return std::string(path).substr(0, pos);
}
inline std::wstring integrate_path(const std::wstring& path, wchar_t replace_by = L'_') {
static const wchar_t filter[] = L"\\/:*?\"<>| ";
static constexpr wchar_t* DEFAULT_PATH_FILTERW = L"\\/:*?\"<>| ";
static constexpr char* DEFAULT_PATH_FILTER = "\\/:*?\"<>| ";
inline std::wstring integratePath(const std::wstring& path, const std::wstring& filter = DEFAULT_PATH_FILTERW, wchar_t replace_by = L'_') {
auto ret = path;
for (auto c : filter) {
std::replace(ret.begin(), ret.end(), c, replace_by);
......@@ -34,8 +38,7 @@ inline std::wstring integrate_path(const std::wstring& path, wchar_t replace_by
return ret;
}
inline std::string integrate_path(const std::string& path, char replace_by = '_') {
static const char filter[] = "\\/:*?\"<>| ";
inline std::string integratePath(const std::string& path, const std::string& filter = DEFAULT_PATH_FILTER, char replace_by = '_') {
auto ret = path;
for (auto c : filter) {
std::replace(ret.begin(), ret.end(), c, replace_by);
......@@ -43,16 +46,15 @@ inline std::string integrate_path(const std::string& path, char replace_by = '_'
return ret;
}
inline std::wstring get_special_folder(int csidl) {
inline std::wstring getSpecialFolder(int csidl) {
wchar_t path[MAX_PATH] = { 0 };
if (SHGetSpecialFolderPathW(nullptr, path, csidl, false)) {
return std::wstring(path);
}
return std::wstring();
}
inline std::string get_special_folder_a(int csidl) {
inline std::string getSpecialFolderA(int csidl) {
char path[MAX_PATH] = { 0 };
if (SHGetSpecialFolderPathA(nullptr, path, csidl, false)) {
return std::string(path);
......
#pragma once
#include <Windows.h>
#include <string>
#include "../utf8.h"
namespace jlib
{
namespace win32
{
inline DWORD daemon(const std::wstring& path, bool wait_app_exit = true, bool show = true) {
STARTUPINFOW si = { 0 };
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = show ? SW_SHOW : SW_HIDE;
PROCESS_INFORMATION pi;
DWORD dwCreationFlags = show ? 0 : CREATE_NO_WINDOW;
BOOL bRet = CreateProcessW(NULL, (LPWSTR)(path.c_str()), NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi);
if (bRet) {
WaitForSingleObject(pi.hProcess, wait_app_exit ? INFINITE : 0);
DWORD dwExit;
::GetExitCodeProcess(pi.hProcess, &dwExit);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return dwExit;
}
return 0xFFFFFFFF;
}
inline DWORD daemon(const std::string& path, bool wait_app_exit = true, bool show = true) {
return daemon(utf8::a2w(path), wait_app_exit, show);
}
} // namespace win32
} // namespace jlib
#pragma once
#include <Windows.h>
#include <vector>
namespace jlib
{
namespace win32
{
inline long width(::LPCRECT rc) {
return rc->right - rc->left;
}
inline long height(::LPCRECT rc) {
return rc->bottom - rc->top;
}
inline void deflateRect(::LPRECT rc, int l, int t, int r, int b) {
rc->left += l;
rc->top += t;
rc->right -= r;
rc->bottom -= b;
}
inline void inflateRect(::LPRECT rc, int l, int t, int r, int b) {
rc->left -= l;
rc->top -= t;
rc->right += r;
rc->bottom += b;
}
//! 将矩形平均分割成 n 份,间距 2*gap, n 必须是平方数 x^2, x={1,2,3...}
inline std::vector<::RECT> splitRect(::LPCRECT rc, int n, int gap = 50) {
std::vector<::RECT> v;
for (int i = 0; i < n; i++) {
v.push_back(*rc);
}
double l = sqrt(n);
int line = int(l);
int col_step = (int)(Width(rc) / line);
int row_step = (int)(Height(rc) / line);
for (int i = 0; i < n; i++) {
v[i].left = rc->left + (i % line) * col_step;
v[i].right = v[i].left + col_step;
v[i].top = rc->top + (i / line) * row_step;
v[i].bottom = v[i].top + row_step;
deflateRect(&v[i], gap, gap, gap, gap);
}
return v;
};
//! 将矩形水平平均分割为 n 份矩形, 当 hgap == -1 时,分割出的矩形与源矩形保持比例
inline std::vector<::RECT> split_rect_horizontal(::LPCRECT rc, int n, int wgap = 50, int hgap = -1) {
std::vector<::RECT> v;
int w = (width(rc) - (n + 1) * wgap) / n;
if (hgap == -1) {
double ratio = (rc->right - rc->left) * 1.0 / (rc->bottom - rc->top);
int h = static_cast<int>(w / ratio);
hgap = (height(rc) - h) / 2;
}
for (int i = 0; i < n; i++) {
::RECT r = *rc;
r.left += i * w + (i + 1) * wgap;
r.right = r.left + w;
r.top = rc->top + hgap;
r.bottom = rc->bottom - hgap;
v.push_back(r);
}
return v;
}
/**
* @brief 从矩形内获取六边形顶点
* @param rc 矩形
* @param spliter 六边形的边长是矩形边长的 1/spliter
* @note rc's width / spliter = (rc's width - hexagon's side length) / 2
* @return 六边形的六个顶点坐标,从上边左侧点顺时针排列
*/
inline std::vector<::POINT> getHexagonVertexesFromRect(::LPCRECT rc, float spliter = 3.0) {
if (!rc) { return std::vector<::POINT>(); }
if (spliter == 0.0) { spliter = 3.0; }
std::vector<::POINT> v;
auto w = rc->right - rc->left;
auto h = rc->bottom - rc->top;
auto ww = static_cast<int>(w / spliter);
auto hh = static_cast<int>(h / spliter);
::POINT pt;
pt.x = rc->left;
pt.y = rc->top + hh;
v.push_back(pt);
pt.x = rc->left + ww;
pt.y = rc->top;
v.push_back(pt);
pt.x = rc->right - ww;
v.push_back(pt);
pt.x = rc->right;
pt.y = rc->top + hh;
v.push_back(pt);
pt.y = rc->bottom - hh;
v.push_back(pt);
pt.x = rc->right - ww;
pt.y = rc->bottom;
v.push_back(pt);
pt.x = rc->left + ww;
v.push_back(pt);
pt.x = rc->left;
pt.y = rc->bottom - hh;
v.push_back(pt);
return v;
}
}
}
#pragma once
#include <Windows.h>
#include "../base/noncopyable.h"
namespace jlib
{
namespace win32
{
inline BOOL centerWindow(HWND hwnd)
{
HWND hwndParent = GetParent(hwnd);
if (hwndParent == NULL) {
hwndParent = GetDesktopWindow();
}
// make the window relative to its parent
if (hwndParent != NULL) {
RECT rectWindow, rectParent;
GetWindowRect(hwnd, &rectWindow);
GetWindowRect(hwndParent, &rectParent);
int nWidth = rectWindow.right - rectWindow.left;
int nHeight = rectWindow.bottom - rectWindow.top;
int nX = ((rectParent.right - rectParent.left) - nWidth) / 2 + rectParent.left;
int nY = ((rectParent.bottom - rectParent.top) - nHeight) / 2 + rectParent.top;
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
// make sure that the dialog box never moves outside of the screen
if (nX < 0) nX = 0;
if (nY < 0) nY = 0;
if (nX + nWidth > nScreenWidth) nX = nScreenWidth - nWidth;
if (nY + nHeight > nScreenHeight) nY = nScreenHeight - nHeight;
MoveWindow(hwnd, nX, nY, nWidth, nHeight, FALSE);
return TRUE;
}
return FALSE;
}
class AutoReopenTimer : public noncopyable
{
private:
HWND hWnd_ = NULL;
int timerId_ = 0;
DWORD timeOut_ = 0;
public:
explicit AutoReopenTimer(HWND hWnd, int timerId, DWORD timeout) : hWnd_(hWnd), timerId_(timerId), timeOut_(timeout)
{
KillTimer(hWnd, timerId_);
}
~AutoReopenTimer()
{
SetTimer(hWnd_, timerId_, timeOut_, NULL);
}
};
}
}
......@@ -17,13 +17,21 @@
#pragma comment (lib, "wbemuuid.lib")
#if !defined(UNICODE) && !defined(_UNICODE)
#error wmi only works with unicode!
#error jlib::win32::wmi only works with unicode!
#endif
#define OUTPUT_ERROR_AND_BREAK(hr, errorFunc) if (errorFunc) { \
std::wstring msg = _com_error(hr).ErrorMessage(); \
msg += L" "; msg += __FILEW__; msg += L":"; msg += std::to_wstring(__LINE__); \
errorFunc(hr, msg); \
} \
break;
#define JLIB_CHECK_HR(hr) if (FAILED(hr)) break;
#define JLIB_CHECK_HR2(hr, errorFunc) if (FAILED(hr)) { if (errorFunc) { errorFunc(hr, _com_error(hr).ErrorMessage()); } break; }
#define JLIB_CHECK_HR2(hr, errorFunc) if (FAILED(hr)) { OUTPUT_ERROR_AND_BREAK(hr, errorFunc); }
#define JLIB_CHECK_WMI_HR(hr) if ((hr) != WBEM_S_NO_ERROR) break;
#define JLIB_CHECK_WMI_HR2(hr, errorFunc) if ((hr) != WBEM_S_NO_ERROR) { if (errorFunc) { errorFunc(hr, _com_error(hr).ErrorMessage()); }break; }
#define JLIB_CHECK_WMI_HR2(hr, errorFunc) if ((hr) != WBEM_S_NO_ERROR) { OUTPUT_ERROR_AND_BREAK(hr, errorFunc); }
namespace jlib
{
......@@ -100,8 +108,9 @@ public:
while (pEnumerator) {
CComPtr<IWbemClassObject> object = NULL;
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &object, &uReturn);
hr = pEnumerator->Next(WBEM_INFINITE, 1, &object, &uReturn);
if (0 == uReturn) { break; }
JLIB_CHECK_WMI_HR2(hr, errorFunc_);
parseIWbemClassObject(object);
}
......@@ -235,7 +244,9 @@ protected:
break;
default:
ATLASSERT(FALSE);
//if(value.vt)
//ATLASSERT(FALSE);
Value = L"Failed with vt=" + std::to_wstring(value.vt);
break;
}
......
#include <jlib/win32/DeviceUniqueIdentifier.h>
#include <jlib/util/str_util.h>
#include <stdio.h>
#include <algorithm>
#include <locale.h>
#include <jlib/win32/wmi.h>
#include <unordered_set>
using namespace jlib;
using namespace jlib::win32::wmi;
struct disk {
std::wstring DiskIndex = {};
std::wstring BootPartition = {};
};
disk d;
std::unordered_map<std::wstring, std::wstring> disks;
void out2(const std::wstring& key, const std::wstring& value)
{
static int i = 0;
if (key == L"DiskIndex") {
d.DiskIndex = value;
} else {
d.BootPartition = value;
}
if (++i % 2 == 0) {
auto iter = disks.find(d.DiskIndex);
if (iter != disks.end()) {
if (iter->second != L"TRUE") {
iter->second = d.BootPartition;
}
} else {
disks[d.DiskIndex] = d.BootPartition;
}
}
}
void out3(const std::wstring& key, const std::wstring& value)
{
auto s = value; trim(s);
wprintf(L"%s \t = %s\n", key.data(), s.data());
}
void err(HRESULT hr, const std::wstring& msg)
{
wprintf(L"Error 0x%08X, %s\n", hr, msg.data());
}
// won't work if more than one disk is "Active"
int main()
{
{
WmiBase wmi(L"root\\CIMV2", out2, err);
wmi.prepare();
wmi.execute(L"SELECT DiskIndex,BootPartition FROM Win32_DiskPartition");
}
{
WmiBase wmi(L"root\\CIMV2", out3, err);
wmi.prepare();
std::vector<std::wstring> dup;
for (auto r : disks) {
dup.push_back(r.first);
}
std::sort(dup.begin(), dup.end());
for (auto index : dup) {
printf("\nDiskIndex\t = %ls ", index.data());
if (disks[index] == L"TRUE") {
printf(" <- BootPartition");
}
printf("\n");
wmi.execute(L"SELECT Caption, SerialNumber FROM Win32_DiskDrive WHERE Index = " + index);
}
}
system("pause");
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
......@@ -19,10 +19,9 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>testwin32</RootNamespace>
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{42F7EE20-C9AC-49CE-9D92-479576295810}</ProjectGuid>
<RootNamespace>hds</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
......@@ -43,14 +42,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
......@@ -70,102 +69,63 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(DEVLIBS)/Global;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>$(DEVLIBS)/jlib;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(DEVLIBS)/jlib;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(BOOST);$(DEVLIBS)\jlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="test_win32.cpp" />
<ClCompile Include="hds.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -15,15 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="test_win32.cpp">
<ClCompile Include="hds.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
......@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29209.62
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_win32", "test_win32\test_win32.vcxproj", "{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_qt", "test_qt\test_qt.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_json", "test_json\test_json.vcxproj", "{8A39D7AF-50AF-43BD-8CC6-DA20B6349F03}"
......@@ -20,7 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "jlib", "jlib", "{42703978-A
..\jlib\log2.h = ..\jlib\log2.h
..\jlib\net.h = ..\jlib\net.h
..\jlib\utf8.h = ..\jlib\utf8.h
..\jlib\win32.h = ..\jlib\win32.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3rdparty", "3rdparty", "{5A2CA1BE-5A4B-41B0-B74A-F86AB433F4A5}"
......@@ -56,9 +53,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "win32", "win32", "{B5D9E71E
..\jlib\win32\MyWSAError.h = ..\jlib\win32\MyWSAError.h
..\jlib\win32\odbccp32.lib = ..\jlib\win32\odbccp32.lib
..\jlib\win32\path_op.h = ..\jlib\win32\path_op.h
..\jlib\win32\process.h = ..\jlib\win32\process.h
..\jlib\win32\rect.h = ..\jlib\win32\rect.h
..\jlib\win32\registry.h = ..\jlib\win32\registry.h
..\jlib\win32\resolve.h = ..\jlib\win32\resolve.h
..\jlib\win32\UnicodeTool.h = ..\jlib\win32\UnicodeTool.h
..\jlib\win32\window.h = ..\jlib\win32\window.h
..\jlib\win32\wmi.h = ..\jlib\win32\wmi.h
EndProjectSection
EndProject
......@@ -89,6 +89,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{E13021FA-C
..\jlib\util\rand.h = ..\jlib\util\rand.h
..\jlib\util\space.h = ..\jlib\util\space.h
..\jlib\util\std_util.h = ..\jlib\util\std_util.h
..\jlib\util\str_util.h = ..\jlib\util\str_util.h
..\jlib\util\version_no.h = ..\jlib\util\version_no.h
EndProjectSection
EndProject
......@@ -223,6 +224,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util_tests", "util_tests",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_rand", "test_rand\test_rand.vcxproj", "{4AB0552E-F2D7-4FF0-B019-90D83847A25C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hds", "hds\hds.vcxproj", "{42F7EE20-C9AC-49CE-9D92-479576295810}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_file_op", "test_file_op\test_file_op.vcxproj", "{82EF7CB9-D551-43FC-A2A5-485C37C7895B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
......@@ -239,14 +244,6 @@ Global
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x64.Build.0 = Release|x64
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x86.ActiveCfg = Release|Win32
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5}.Release|x86.Build.0 = Release|Win32
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x64.ActiveCfg = Debug|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x64.Build.0 = Debug|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x86.ActiveCfg = Debug|Win32
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Debug|x86.Build.0 = Debug|Win32
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Release|x64.ActiveCfg = Release|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Release|x64.Build.0 = Release|x64
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Release|x86.ActiveCfg = Release|Win32
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB}.Release|x86.Build.0 = Release|Win32
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|Win32
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x86.ActiveCfg = Debug|Win32
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x86.Build.0 = Debug|Win32
......@@ -341,13 +338,28 @@ Global
{4AB0552E-F2D7-4FF0-B019-90D83847A25C}.Release|x64.Build.0 = Release|x64
{4AB0552E-F2D7-4FF0-B019-90D83847A25C}.Release|x86.ActiveCfg = Release|Win32
{4AB0552E-F2D7-4FF0-B019-90D83847A25C}.Release|x86.Build.0 = Release|Win32
{42F7EE20-C9AC-49CE-9D92-479576295810}.Debug|x64.ActiveCfg = Debug|x64
{42F7EE20-C9AC-49CE-9D92-479576295810}.Debug|x64.Build.0 = Debug|x64
{42F7EE20-C9AC-49CE-9D92-479576295810}.Debug|x86.ActiveCfg = Debug|Win32
{42F7EE20-C9AC-49CE-9D92-479576295810}.Debug|x86.Build.0 = Debug|Win32
{42F7EE20-C9AC-49CE-9D92-479576295810}.Release|x64.ActiveCfg = Release|x64
{42F7EE20-C9AC-49CE-9D92-479576295810}.Release|x64.Build.0 = Release|x64
{42F7EE20-C9AC-49CE-9D92-479576295810}.Release|x86.ActiveCfg = Release|Win32
{42F7EE20-C9AC-49CE-9D92-479576295810}.Release|x86.Build.0 = Release|Win32
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Debug|x64.ActiveCfg = Debug|x64
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Debug|x64.Build.0 = Debug|x64
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Debug|x86.ActiveCfg = Debug|Win32
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Debug|x86.Build.0 = Debug|Win32
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Release|x64.ActiveCfg = Release|x64
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Release|x64.Build.0 = Release|x64
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Release|x86.ActiveCfg = Release|Win32
{82EF7CB9-D551-43FC-A2A5-485C37C7895B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{155F525A-FA2F-471F-A2DF-9B77E7CCCFA5} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{A4B1CDB2-7325-4E22-AD0A-1D2907924CDB} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{B12702AD-ABFB-343A-A199-8E24837244A3} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{8A39D7AF-50AF-43BD-8CC6-DA20B6349F03} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{372670F2-83A5-4058-B93C-BB0DCC1521ED} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F}
......@@ -381,6 +393,8 @@ Global
{CA7812A3-9E48-4A94-B39A-32EED587E38A} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{ABCB8CF8-5E82-4C47-A0FC-E82DF105DF99} = {21DC893D-AB0B-48E1-9E23-069A025218D9}
{4AB0552E-F2D7-4FF0-B019-90D83847A25C} = {ABCB8CF8-5E82-4C47-A0FC-E82DF105DF99}
{42F7EE20-C9AC-49CE-9D92-479576295810} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{82EF7CB9-D551-43FC-A2A5-485C37C7895B} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D}
......
......@@ -3,10 +3,30 @@
#include <algorithm>
#include <locale.h>
using namespace jlib::win32::DeviceUniqueIdentifier;
void test()
{
const int TIMES = 100;
printf("\n\nTest %d times on RecommendedQueryTypes...\n", TIMES);
for (int i = 0; i < TIMES; i++) {
printf("\r%d/%d", i+1, TIMES);
QueryResults results;
bool ok = query(RecommendedQueryTypes, results);
if (!ok) {
printf("Error on #%d\n", i);
for (auto iter = results.begin(); iter != results.end(); iter++) {
printf("%ls: %ls\n", queryTypeString(iter->first), iter->second.data());
}
return;
}
}
printf("\nDone!\n");
}
int main()
{
std::locale::global(std::locale(""));
using namespace jlib::win32::DeviceUniqueIdentifier;
QueryResults results;
printf("Query RecommendedQueryTypes:\n");
......@@ -24,5 +44,7 @@ int main()
//IOCTL_NDIS_QUERY_GLOBAL_STATS
printf("\nJoined results:\n%ls\n", join_result(results, L",").data());
test();
system("pause");
}
\ No newline at end of file
......@@ -78,7 +78,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(DEVLIBS)/Global;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(DEVLIBS)/jlib;$(BOOST);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
......
#include <iostream>
#include "../../jlib/win32/file_op.h"
int main()
{
std::wstring path;
COMDLG_FILTERSPEC cf[2] = {};
cf[0].pszName = L"Text Files";
cf[0].pszSpec = L"*.txt";
cf[1].pszName = L"All Files";
cf[1].pszSpec = L"*.*";
jlib::win32::getOpenFileDialogResult(path, nullptr, L"", L"txt", 2, cf);
std::wcout << path << std::endl;
system("pause");
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{82EF7CB9-D551-43FC-A2A5-485C37C7895B}</ProjectGuid>
<RootNamespace>testfileop</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="test_file_op.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="test_file_op.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
// pch.cpp: source file corresponding to pre-compiled header; necessary for compilation to succeed
#include "pch.h"
// In general, ignore this file, but keep it around if you are using pre-compiled headers.
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#ifndef PCH_H
#define PCH_H
// TODO: add headers that you want to pre-compile here
#endif //PCH_H
// test_win32.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <jlib/win32.h>
int main()
{
std::wstring path;
COMDLG_FILTERSPEC cf[2] = {};
cf[0].pszName = L"Text Files";
cf[0].pszSpec = L"*.txt";
cf[1].pszName = L"All Files";
cf[1].pszSpec = L"*.*";
jlib::get_file_open_dialog_result(path, nullptr, L"", L"txt", 2, cf);
std::wcout << path << std::endl;
system("pause");
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
......@@ -14,18 +14,23 @@ void err(HRESULT hr, const std::wstring& msg)
int main()
{
{
/*{
WmiBase wmi(L"root\\CIMV2", out, err);
wmi.prepare();
wmi.execute(L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = 4");
wmi.execute(L"SELECT * FROM Win32_Processor");
}
}*/
{
WmiBase wmi(L"root\\CIMV2", out, err);
wmi.prepare();
wmi.execute(L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = 4");
wmi.execute(L"SELECT * FROM Win32_Processor");
//wmi.execute(L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = 4");
//wmi.execute(L"SELECT * FROM Win32_DiskPartition");
//wmi.execute(L"SELECT Caption FROM Win32_BootConfiguration");
wmi.execute(L"Select Name from Win32_OperatingSystem");
//wmi.execute(L"SELECT PNPDeviceID FROM Win32_LogicalDisk WHERE NAME = 'C:'");
}
system("pause");
}
......@@ -36,7 +36,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
......
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