diff --git a/.gitignore b/.gitignore index b3057df5..76581373 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .clangd .vscode +.VSCodeCounter bin build cmake_modules diff --git a/README.md b/README.md index 20ec5812..c65d7e26 100644 --- a/README.md +++ b/README.md @@ -61,16 +61,16 @@ If you want to know the details, refer to setup_win-vind_4.0.1_32bit.exe -- win-vind_4.0.1_32bit.zip +- setup_win-vind_4.1.0_32bit.exe +- win-vind_4.1.0_32bit.zip #### 64bit -- setup_win-vind_4.0.1_64bit.exe -- win-vind_4.0.1_64bit.zip +- setup_win-vind_4.1.0_64bit.exe +- win-vind_4.1.0_64bit.zip ## Usage You can refer to the installation and quick tutorial in [Usage - win-vind](https://pit-ray.github.io/win-vind/usage/). diff --git a/build.bat b/build.bat index 8a8d1d63..2a383b85 100644 --- a/build.bat +++ b/build.bat @@ -1,12 +1,10 @@ @chcp 65001 @echo Usage: build.bat [-debug/-release] [-msvc/-mingw] [32/64] -@if %1 == -help ( - exit -) - @if "%1" == "" ( @set build_type=-debug +) else if "%1" == "-help" ( + @ exit ) else ( @set build_type=%1 ) @@ -42,12 +40,12 @@ cmake -B release_32 -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 16 2019" -A win32 -DBIT_TYPE=32 . cmake --build release_32 --config Release xcopy /e /Y ".\\release_32\\coregui\\Release\\*.exe" "release_32" - @rem xcopy /e /Y ".\\release_32\\wxgui\\Release\\*.exe" "release" + @rem xcopy /e /Y ".\\release_32\\wxgui\\Release\\*.exe" "release_32" ) else ( cmake -B release_64 -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 16 2019" -A x64 -DBIT_TYPE=64 . cmake --build release_64 --config Release xcopy /e /Y ".\\release_64\\coregui\\Release\\*.exe" "release_64" - @rem xcopy /e /Y ".\\release_64\\wxgui\\Release\\*.exe" "release" + @rem xcopy /e /Y ".\\release_64\\wxgui\\Release\\*.exe" "release_64" ) ) else ( if %3 == 32 ( diff --git a/build_resources/resource.rc b/build_resources/resource.rc index 584e74d1..b780396f 100644 --- a/build_resources/resource.rc +++ b/build_resources/resource.rc @@ -14,11 +14,11 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "CompanyName", "pit-ray\0" - VALUE "FileDescription", "win-vind (64-bit)\0" + VALUE "FileDescription", "win-vind (32-bit)\0" VALUE "LegalCopyright", "Copyright (c) 2020 pit-ray\0" - VALUE "InternalName", "win-vind (64-bit)\0" + VALUE "InternalName", "win-vind (32-bit)\0" VALUE "OriginalFilename", "win-vind.exe\0" - VALUE "ProductName", "win-vind (64bit)\0" + VALUE "ProductName", "win-vind (32bit)\0" VALUE "ProductVersion", "4.1.0\0" END END diff --git a/core/include/bind/mode/change_mode.hpp b/core/include/bind/mode/change_mode.hpp index c4fc7648..6ad87806 100644 --- a/core/include/bind/mode/change_mode.hpp +++ b/core/include/bind/mode/change_mode.hpp @@ -2,6 +2,7 @@ #define _CHANGE_MODE_HPP #include "bind/binded_func_creator.hpp" +#include "bind/mode/text_area_scanner.hpp" namespace vind { @@ -26,7 +27,11 @@ namespace vind static void sprocess(const CharLogger& parent_lgr) ; } ; - struct ToEdiNormal : public BindedFuncCreator { + class ToEdiNormal : public BindedFuncCreator { + private: + static TextAreaScanner scanner_ ; + + public: explicit ToEdiNormal() ; static void sprocess(bool vclmodeout=true) ; static void sprocess(NTypeLogger& parent_lgr) ; diff --git a/core/src/bind/mode/change_mode.cpp b/core/src/bind/mode/change_mode.cpp index 33620e37..3262b86a 100644 --- a/core/src/bind/mode/change_mode.cpp +++ b/core/src/bind/mode/change_mode.cpp @@ -112,10 +112,16 @@ namespace vind sprocess(true) ; } + + // All instances share TextAreaScanner to keep staticity of sprocess. + TextAreaScanner ToEdiNormal::scanner_ ; + //ToEdiNormal ToEdiNormal::ToEdiNormal() : BindedFuncCreator("to_edi_normal") - {} + { + AsyncUIACacheBuilder::register_properties(scanner_.get_properties()) ; + } void ToEdiNormal::sprocess(bool vclmodeout) { using namespace mode ; auto mode = get_global_mode() ; @@ -149,13 +155,7 @@ namespace vind throw RUNTIME_EXCEPT("Could not get the cursor position.") ; } - // All instances share TextAreaScanner to keep staticity of sprocess. - static auto scanner = [] { - TextAreaScanner walker ; - AsyncUIACacheBuilder::register_properties(walker.get_properties()) ; - return walker ; - }() ; - options::focus_nearest_textarea(hwnd, pos, scanner) ; + options::focus_nearest_textarea(hwnd, pos, scanner_) ; } } void ToEdiNormal::sprocess(NTypeLogger& parent_lgr) { diff --git a/core/src/bind/mode/options.cpp b/core/src/bind/mode/options.cpp index 85c7b6be..7764332e 100644 --- a/core/src/bind/mode/options.cpp +++ b/core/src/bind/mode/options.cpp @@ -52,13 +52,11 @@ namespace vind for(auto& elem : editables) { // scan GUI objects only at leaves in tree. - RECT rect ; - if(util::is_failed(elem->get_CachedBoundingRectangle(&rect))) { + Box2D box ; + if(util::is_failed(elem->get_CachedBoundingRectangle(&box.data()))) { throw RUNTIME_EXCEPT("Could not get the a rectangle of a element.") ; } - Box2D box(std::move(rect)) ; - auto distance = util::l2_distance_nosq( point.x(), point.y(), box.center_x(), box.center_y()) / 100 ; diff --git a/core/src/opt/async_uia_cache_builder.cpp b/core/src/opt/async_uia_cache_builder.cpp index 206a6bde..e1598491 100644 --- a/core/src/opt/async_uia_cache_builder.cpp +++ b/core/src/opt/async_uia_cache_builder.cpp @@ -35,6 +35,10 @@ namespace end_ = std::chrono::system_clock::now() ; } + bool has_stamp() const noexcept { + return end_.time_since_epoch().count() != 0 ; + } + auto elapsed() noexcept { using namespace std::chrono ; return duration_cast(system_clock::now() - begin_) ; @@ -83,8 +87,26 @@ namespace } bool is_valid() { + if(!time_.has_stamp()) return false ; return time_.elapsed().count() \ - < gparams::get_i("uiacachebuild_validperiod") ; + < gparams::get_i("uiacachebuild_lifetime") ; + } + + void create_thread() { + ft_ = std::async(std::launch::async, [this] { + time_.stamp_begin() ; + + auto updated = uiauto::update_element(root_, g_cache_request) ; + + time_.stamp_end() ; + time_.update_average() ; + return updated ; + }) ; + } + + bool check_if_finished() { + using namespace std::chrono ; + return ft_.wait_for(1us) != std::future_status::timeout ; } void update() { @@ -99,12 +121,9 @@ namespace } if(ft_.valid()) { - util::debug::bench_start() ; - using namespace std::chrono ; - // This checks the shared state, // but it takes several tens of milliseconds to see the shared state. - if(ft_.wait_for(1us) != std::future_status::timeout) { + if(check_if_finished()) { root_ = ft_.get() ; } @@ -114,40 +133,22 @@ namespace return ; } - ft_ = std::async(std::launch::async, [this] { - time_.stamp_begin() ; - - auto updated = uiauto::update_element(root_, g_cache_request) ; - - time_.stamp_end() ; - time_.update_average() ; - return updated ; - }) ; + create_thread() ; } const SmartElement& latest() { - if(!root_) { - update() ; - if(ft_.valid()) { - ft_.wait() ; - root_ = ft_.get() ; - } - return root_ ; - } - if(is_valid()) { return root_ ; } if(ft_.valid()) { - using namespace std::chrono ; - if(ft_.wait_for(1us) != std::future_status::timeout) { + if(check_if_finished()) { root_ = ft_.get() ; return root_ ; } } else { - update() ; + create_thread() ; } ft_.wait() ; @@ -157,6 +158,9 @@ namespace } ; std::unordered_map g_caches{} ; + inline auto has_cache(HWND hwnd) noexcept { + return g_caches.find(hwnd) != g_caches.end() ; + } } @@ -218,7 +222,7 @@ namespace vind return ; } - if(g_caches.find(hwnd) == g_caches.end()) { + if(!has_cache(hwnd)) { g_caches[hwnd].initialize(hwnd) ; } g_caches[hwnd].update() ; @@ -229,7 +233,7 @@ namespace vind } SmartElement AsyncUIACacheBuilder::get_root_element(HWND hwnd) { - if(g_caches.find(hwnd) == g_caches.end()) { + if(!has_cache(hwnd)) { g_caches[hwnd].initialize(hwnd) ; } return g_caches[hwnd].latest() ; diff --git a/default_config/settings.json b/default_config/settings.json index e0323bf3..bce89827 100644 --- a/default_config/settings.json +++ b/default_config/settings.json @@ -312,7 +312,7 @@ "en": "Build UI Automation cache asynchronously", "ja": "非同期UI Automationキャッシュ生成" }, - "uiacachebuild_validperiod": { + "uiacachebuild_lifetime": { "value": 1500, "en": "Valid period of UI Automation cache(ms)", "ja": "非同期UI Automationキャッシュの有効期間(ms)" diff --git a/scripts/setup_libs.bat b/scripts/setup_libs.bat index 8e0dfb00..1f16dc64 100644 --- a/scripts/setup_libs.bat +++ b/scripts/setup_libs.bat @@ -1,10 +1,6 @@ @chcp 65001 @echo Usage: setup_libs.bat [-msvc/-mingw] [32/64] [-update (optional)] -@if %1 == -help ( - @exit -) - @if not defined NUMBER_OF_PROCESSORS ( @echo Error: This script will not work with powershell. @exit @@ -15,6 +11,8 @@ @echo Error: Please pass your compiler type -mingw or -msvc as the first argument. @echo. @exit +) else if "%1" == "-help" ( + @exit ) @echo The number of processors is %NUMBER_OF_PROCESSORS%.