Release KSwitcher v0.6.106 with responsive Files operations
This commit is contained in:
1 parent
0addc663c2
commit
69e6aaeb0f
27 files changed
+1954
-542
No files matched your search
@@ -1,11 +1,27 @@
|
||||
#include "ocr.h"
|
||||
#include "app.h"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <tlhelp32.h>
|
||||
#include <iostream>
|
||||
namespace ks {
|
||||
struct InputRegressionAccess {
|
||||
static void scheduleOcr(App &app) { app.scheduleHistoryOcr(app.settings); }
|
||||
};
|
||||
}
|
||||
std::set<DWORD> historyImageHelpers()
|
||||
{
|
||||
const auto snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
if(snapshot==INVALID_HANDLE_VALUE) throw std::runtime_error("Cannot enumerate OCR fixtures");
|
||||
struct Cleanup {HANDLE handle;~Cleanup(){CloseHandle(handle);}} cleanup{snapshot};
|
||||
std::set<DWORD> children;
|
||||
PROCESSENTRY32W entry{sizeof(entry)};
|
||||
for(auto ok=Process32FirstW(snapshot,&entry);ok;ok=Process32NextW(snapshot,&entry))
|
||||
if(entry.th32ParentProcessID==GetCurrentProcessId() && lstrcmpiW(entry.szExeFile,L"KSwitcher.Screenshot.exe")==0)
|
||||
children.insert(entry.th32ProcessID);
|
||||
return children;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const bool tesseract = argc == 2 && std::string(argv[1]) == "--tesseract";
|
||||
@@ -52,6 +68,16 @@ int main(int argc, char **argv)
|
||||
throw std::runtime_error("OCR fixture was not recognized");
|
||||
if (tesseract && ks::lower(text).find(L"привіт") == std::wstring::npos)
|
||||
throw std::runtime_error("Ukrainian OCR fixture was not recognized");
|
||||
if (!tesseract)
|
||||
{
|
||||
constexpr UINT width=20000;
|
||||
ks::Pixels wideFixture{width,pixels.height,ks::Bytes(size_t(width)*pixels.height*4,255)};
|
||||
for(UINT y=0;y<pixels.height;++y)
|
||||
std::copy_n(pixels.bgra.data()+size_t(y)*pixels.width*4,pixels.width*4,
|
||||
wideFixture.bgra.data()+size_t(y)*width*4);
|
||||
if(ks::upper(ks::recognizeText(ks::Clip{{ks::imageDib(wideFixture)}},config)).find(L"HELLO")==std::wstring::npos)
|
||||
throw std::runtime_error("OCR did not recognize the downscaled wide image");
|
||||
}
|
||||
auto temp = std::filesystem::temp_directory_path() / (L"KSwitcher-auto-ocr-" + std::to_wstring(GetCurrentProcessId()));
|
||||
auto sequence = GetClipboardSequenceNumber();
|
||||
{
|
||||
@@ -61,6 +87,16 @@ int main(int argc, char **argv)
|
||||
auto id = app.history->entries().front().id;
|
||||
auto isolated = app.history->recognizeImage(id, config);
|
||||
if (isolated != text) throw std::runtime_error("Helper and in-process OCR results differ");
|
||||
const auto recognitionWorker=historyImageHelpers();
|
||||
if(recognitionWorker.size()!=1 || app.history->recognizeImage(id,config)!=text ||
|
||||
historyImageHelpers()!=recognitionWorker)
|
||||
throw std::runtime_error("Successive history requests did not reuse the OCR process");
|
||||
const auto thumbnail=app.history->thumbnail(id);
|
||||
const auto previewWorkers=historyImageHelpers();
|
||||
const auto repeated=app.history->thumbnail(id);
|
||||
if(previewWorkers.size()!=2 || historyImageHelpers()!=previewWorkers ||
|
||||
thumbnail.width!=repeated.width || thumbnail.height!=repeated.height || thumbnail.bgra!=repeated.bgra)
|
||||
throw std::runtime_error("Successive thumbnail requests did not reuse the independent preview worker");
|
||||
bool cancelled = false;
|
||||
try { app.history->recognizeImage(id, config, [] { return true; }); }
|
||||
catch (const std::exception &) { cancelled = true; }
|
||||
@@ -71,6 +107,16 @@ int main(int argc, char **argv)
|
||||
bool failed = false;
|
||||
try { app.history->recognizeImage(id, invalid); }
|
||||
catch (const std::exception &) { failed = true; }
|
||||
if(historyImageHelpers()!=previewWorkers || app.history->recognizeImage(id,config)!=text)
|
||||
throw std::runtime_error("An OCR job error ended the reusable helper");
|
||||
const auto child=OpenProcess(PROCESS_TERMINATE|SYNCHRONIZE,FALSE,*recognitionWorker.begin());
|
||||
if(!child) throw std::runtime_error("Cannot open OCR crash fixture");
|
||||
const auto terminated=TerminateProcess(child,ERROR_PROCESS_ABORTED) &&
|
||||
WaitForSingleObject(child,5000)==WAIT_OBJECT_0;
|
||||
CloseHandle(child);
|
||||
if(!terminated || app.history->recognizeImage(id,config)!=text || historyImageHelpers()==previewWorkers)
|
||||
throw std::runtime_error("History OCR did not restart its exited helper");
|
||||
std::cout << "PASS OCR and thumbnail process reuse and restart after worker exit\n";
|
||||
if (!failed || app.history->entries().front().ocrState != 1)
|
||||
throw std::runtime_error("Failed helper modified history metadata");
|
||||
for (const auto &file : std::filesystem::directory_iterator(temp / L"history"))
|
||||
@@ -98,6 +144,7 @@ int main(int argc, char **argv)
|
||||
throw std::runtime_error("Background OCR changed the clipboard");
|
||||
std::cout << "PASS automatic background OCR, persisted search and unchanged clipboard\n";
|
||||
}
|
||||
if(!historyImageHelpers().empty()) throw std::runtime_error("Closing history left OCR workers running");
|
||||
std::filesystem::remove_all(temp);
|
||||
std::cout << (tesseract ? "PASS optional Tesseract, mixed Ukrainian/English and cache migration\n" :
|
||||
"PASS native Windows OCR, DIB decoding and async result retrieval\n");
|
||||
|
||||
Reference in new issue
Block a user