From 86600554b45f77ec6f747709f8bba7d17b9ea6e4 Mon Sep 17 00:00:00 2001 From: dexterdreeeam Date: Mon, 10 Apr 2023 02:47:38 +0800 Subject: [PATCH] 1 --- WinTesterApp/function/runner.cpp | 17 +++++++-- WinTesterApp/function/runner.hpp | 2 + WinTesterApp/loop.hpp | 10 ----- WinTesterApp/loop_gui.cpp | 10 ++--- WinTesterSdk/platform/platform.cpp | 61 ++++++++++++++++++++++++++---- WinTesterSdk/platform/platform.hpp | 2 + 6 files changed, 76 insertions(+), 26 deletions(-) diff --git a/WinTesterApp/function/runner.cpp b/WinTesterApp/function/runner.cpp index 9d061d0..92e8b4d 100644 --- a/WinTesterApp/function/runner.cpp +++ b/WinTesterApp/function/runner.cpp @@ -145,7 +145,7 @@ bool runner::_RunScope(const vector>& va, int start, int end) else { // normal action - if (_Act(ac)) + if (_ActWithRetry(ac)) { ++idx; } @@ -237,13 +237,24 @@ int runner::_RunLoop(const vector>& va, int loop_start) return idx - loop_start; } -bool runner::_Act(shared_ptr ac) +bool runner::_ActWithRetry(shared_ptr ac) { + const int retry = 5; + int times = 0; + Sleep(ac->wait_time_ms); + while (times < retry && !_Act(ac)) + { + Sleep(1000); + ++times; + } + return times < retry; +} +bool runner::_Act(shared_ptr ac) +{ switch (ac->type) { - case action_type::APP_LAUNCH_PATH: return LaunchShellFilePath(ac->parameter["path"]); diff --git a/WinTesterApp/function/runner.hpp b/WinTesterApp/function/runner.hpp index 6dd326c..716d3c7 100644 --- a/WinTesterApp/function/runner.hpp +++ b/WinTesterApp/function/runner.hpp @@ -31,6 +31,8 @@ class runner : public xref int _RunLoop(const vector>& va, int start); + bool _ActWithRetry(shared_ptr ac); + bool _Act(shared_ptr ac); bool _ActElement(shared_ptr ac); diff --git a/WinTesterApp/loop.hpp b/WinTesterApp/loop.hpp index e485b98..075b191 100644 --- a/WinTesterApp/loop.hpp +++ b/WinTesterApp/loop.hpp @@ -62,16 +62,6 @@ struct GlobalInfo return false; } - static const vector Consoles() - { - return slim::platform::Consoles(); - } - - static void ClearConsole() - { - slim::platform::ClearConsole(); - } - volatile GlobalState state; bool exiting; bool fast_mode; diff --git a/WinTesterApp/loop_gui.cpp b/WinTesterApp/loop_gui.cpp index 450b4c9..6e0f93f 100644 --- a/WinTesterApp/loop_gui.cpp +++ b/WinTesterApp/loop_gui.cpp @@ -172,7 +172,7 @@ bool GuiLoop(ImGuiWindowFlags window_flags, bool& done) { if (GlobalInfo::I()->console_window) { - GlobalInfo::I()->ClearConsole(); + // GlobalInfo::I()->ClearConsole(); } GlobalInfo::I()->console_window = !GlobalInfo::I()->console_window; moved = true; @@ -189,10 +189,10 @@ bool GuiLoop(ImGuiWindowFlags window_flags, bool& done) if (GlobalInfo::I()->console_window) { ImGui::BeginChild("Console", ImVec2(620, 500)); - for (auto& c : GlobalInfo::I()->Consoles()) - { - ImGui::Text(c.c_str()); - } + //for (auto& c : GlobalInfo::I()->Consoles()) + //{ + // ImGui::Text(c.c_str()); + //} ImGui::EndChild(); } else diff --git a/WinTesterSdk/platform/platform.cpp b/WinTesterSdk/platform/platform.cpp index 6b34ca3..a7a7463 100644 --- a/WinTesterSdk/platform/platform.cpp +++ b/WinTesterSdk/platform/platform.cpp @@ -51,17 +51,41 @@ mutex& platform::Mutex(const string& name) WndInfo platform::GetWndInfo(HWND wnd) { - char ch_win[256]; - int winNameLen = GetWindowTextA(wnd, ch_win, 255); - ch_win[winNameLen] = 0; + string win, cls; - char ch_cls[256] = {}; - int classNameLen = GetClassNameA(wnd, ch_cls, 255); - ch_cls[classNameLen] = 0; + try + { + char ch_cls[256] = {}; + int classNameLen = GetClassNameA(wnd, ch_cls, 255); + ch_cls[classNameLen] = 0; + cls = ch_cls; + + //char ch_win[256]; + //int winNameLen = GetWindowTextA(wnd, ch_win, 255); + //ch_win[winNameLen] = 0; + //win = ch_win; + + WCHAR wstr[256]; + int winNameLen = InternalGetWindowText(wnd, wstr, 255); + wstr[winNameLen] = '\0'; + + wstring win_wstr = wstr; + std::transform( + win_wstr.begin(), win_wstr.end(), + std::back_inserter(win), + [](wchar_t c) + { + return (char)c; + }); + } + catch (...) + { + ; + } WndInfo ret; - ret.cls = ch_cls; - ret.win = ch_win; + ret.cls = cls; + ret.win = win; ret.wnd = wnd; return ret; } @@ -79,8 +103,13 @@ WndInfo platform::GetCurrentWndInfo() BOOL CALLBACK platform::_EnumWindowsCb(HWND wnd, LPARAM par) { + if (!wnd) + { + return FALSE; + } auto info = platform::GetWndInfo(wnd); I()->_desktop_wnds[info.cls].push_back(info); + cout << info.cls << " - " << info.win << endl; return TRUE; // continue } @@ -91,6 +120,22 @@ void platform::UpdateDesktopWnds() EnumWindows(_EnumWindowsCb, NULL); } +void platform::UpdateDesktopWnds2() +{ + guard __g(Mutex("_desktop_wnds")); + I()->_desktop_wnds.clear(); + HWND w = GetTopWindow(GetDesktopWindow()); // GetForegroundWindow(); + while (w) + { + cout << " 1) " << w; + auto info = platform::GetWndInfo(w); + cout << " 2) "; + I()->_desktop_wnds[info.cls].push_back(info); + cout << " 3) " << endl; + w = GetWindow(w, GW_HWNDNEXT); + } +} + bool platform::UpdateDesktopWnds(const WndInfo& wndInfo) { guard __g(Mutex("_desktop_wnds")); diff --git a/WinTesterSdk/platform/platform.hpp b/WinTesterSdk/platform/platform.hpp index ed04567..5968db1 100644 --- a/WinTesterSdk/platform/platform.hpp +++ b/WinTesterSdk/platform/platform.hpp @@ -48,6 +48,8 @@ class platform : public xref static void UpdateDesktopWnds(); + static void UpdateDesktopWnds2(); + static bool UpdateDesktopWnds(const WndInfo& wndInfo); static vector GetWnds();