Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterDreeeam committed Apr 9, 2023
1 parent e500e66 commit 8660055
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 26 deletions.
17 changes: 14 additions & 3 deletions WinTesterApp/function/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool runner::_RunScope(const vector<shared_ptr<action>>& va, int start, int end)
else
{
// normal action
if (_Act(ac))
if (_ActWithRetry(ac))
{
++idx;
}
Expand Down Expand Up @@ -237,13 +237,24 @@ int runner::_RunLoop(const vector<shared_ptr<action>>& va, int loop_start)
return idx - loop_start;
}

bool runner::_Act(shared_ptr<action> ac)
bool runner::_ActWithRetry(shared_ptr<action> 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<action> ac)
{
switch (ac->type)
{

case action_type::APP_LAUNCH_PATH:
return LaunchShellFilePath(ac->parameter["path"]);

Expand Down
2 changes: 2 additions & 0 deletions WinTesterApp/function/runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class runner : public xref<runner>

int _RunLoop(const vector<shared_ptr<action>>& va, int start);

bool _ActWithRetry(shared_ptr<action> ac);

bool _Act(shared_ptr<action> ac);

bool _ActElement(shared_ptr<action> ac);
Expand Down
10 changes: 0 additions & 10 deletions WinTesterApp/loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ struct GlobalInfo
return false;
}

static const vector<string> Consoles()
{
return slim::platform::Consoles();
}

static void ClearConsole()
{
slim::platform::ClearConsole();
}

volatile GlobalState state;
bool exiting;
bool fast_mode;
Expand Down
10 changes: 5 additions & 5 deletions WinTesterApp/loop_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
61 changes: 53 additions & 8 deletions WinTesterSdk/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
}

Expand All @@ -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"));
Expand Down
2 changes: 2 additions & 0 deletions WinTesterSdk/platform/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class platform : public xref<platform>

static void UpdateDesktopWnds();

static void UpdateDesktopWnds2();

static bool UpdateDesktopWnds(const WndInfo& wndInfo);

static vector<WndInfo> GetWnds();
Expand Down

0 comments on commit 8660055

Please sign in to comment.