move notifyCloseCancel invoking to eventProcess - we trust that the eventProcess always called when show setting UI

This commit is contained in:
gb 2023-05-23 09:13:55 +08:00
parent 1185413876
commit a8718596c2
3 changed files with 42 additions and 4 deletions

View File

@ -22,13 +22,13 @@ namespace load_sane_util
int move_file(const wchar_t* from, const wchar_t* to); int move_file(const wchar_t* from, const wchar_t* to);
template<typename ... Args> template<typename ... Args>
void to_log(const wchar_t* fmt, Args ... args) void to_log(int level, const wchar_t* fmt, Args ... args)
{ {
size_t size = swprintf(nullptr, 0, fmt, args ...) + 2; size_t size = swprintf(nullptr, 0, fmt, args ...) + 2;
std::unique_ptr<wchar_t[]> buf(new wchar_t[size]); std::unique_ptr<wchar_t[]> buf(new wchar_t[size]);
swprintf(buf.get(), size, fmt, args ...); swprintf(buf.get(), size, fmt, args ...);
log_info(buf.get(), 0); log_info(buf.get(), level);
} }
}; };

View File

@ -918,6 +918,16 @@ Result huagao_ds::eventProcess(const Identity&, Event& event)
// if(ev) // if(ev)
// handle_scanner_event(ev); // handle_scanner_event(ev);
//} //}
/*if (xfer_ready_)
{
notifyXferReady();
xfer_ready_ = false;
}
else*/ if (notfify_close_)
{
notifyCloseCancel();
notfify_close_ = false;
}
event.setMessage(Msg::Null); event.setMessage(Msg::Null);
@ -1102,6 +1112,7 @@ Result huagao_ds::userInterfaceDisable(const Identity&, UserInterface& ui)
} }
Result huagao_ds::userInterfaceEnable(const Identity&, UserInterface& ui) Result huagao_ds::userInterfaceEnable(const Identity&, UserInterface& ui)
{ {
notfify_close_ = false;
bUiOnly_ = false; bUiOnly_ = false;
show_setting_ = false; show_setting_ = false;
if (!ui.showUi()) if (!ui.showUi())
@ -1377,8 +1388,10 @@ Result huagao_ds::imageNativeXferGet(const Identity& id, ImageNativeXfer& data)
{ {
if (!scanner_.get()) if (!scanner_.get())
return seqError(); return seqError();
else if(get_scanned_image_count(-1) == 0) else if (get_scanned_image_count(-1) == 0)
{
return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) }; return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) };
}
IScanImg* img = scanner_->take_first_image(TWAIN_XFER_Native); IScanImg* img = scanner_->take_first_image(TWAIN_XFER_Native);
@ -1638,21 +1651,29 @@ Result huagao_ds::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, v
load_sane_util::log_info(buf, 7); load_sane_util::log_info(buf, 7);
if ((int)rt.returnCode() && rt.returnCode() != ReturnCode::NotDsEvent) if ((int)rt.returnCode() && rt.returnCode() != ReturnCode::NotDsEvent)
{ {
bool changed = false;
if (dat == Dat::PendingXfers && Msg::Reset == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // PurvarScannerForHomework.exe - move modifying from EndXfer to xfer::Reset if (dat == Dat::PendingXfers && Msg::Reset == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // PurvarScannerForHomework.exe - move modifying from EndXfer to xfer::Reset
{
changed = true;
rt = success(); rt = success();
}
else if (rt.status() == ConditionCode::SeqError) else if (rt.status() == ConditionCode::SeqError)
{ {
if (dat == Dat::ImageInfo && Msg::Get == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // for demo.exe if (dat == Dat::ImageInfo && Msg::Get == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // for demo.exe
{ {
changed = true;
rt = { ReturnCode::Success, ConditionCode::Bummer }; rt = { ReturnCode::Success, ConditionCode::Bummer };
} }
else if (dat == Dat::PendingXfers && Msg::EndXfer == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // for photoshop.exe else if (dat == Dat::PendingXfers && Msg::EndXfer == msg && scanner_status_ == SCANNER_STATUS_STOPPED) // for photoshop.exe
{ {
// PendingXfers& data // PendingXfers& data
(static_cast<PendingXfers*>(data))->setCount(0); (static_cast<PendingXfers*>(data))->setCount(0);
changed = true;
rt = { ReturnCode::Success, ConditionCode::Success }; rt = { ReturnCode::Success, ConditionCode::Success };
} }
} }
if(changed)
load_sane_util::to_log(7, L" modify result to {%s, %s}.\r\n", desc_return_code(rt, rcs), desc_condition_code((ConditionCode)(Status)rt, cs));
} }
} }
@ -3607,7 +3628,23 @@ int huagao_ds::handle_scanner_event(int ev, bool from_event_proc)
break; break;
case SANE_EVENT_UI_CLOSE_SETTING: case SANE_EVENT_UI_CLOSE_SETTING:
scanner_->ui_hide(); scanner_->ui_hide();
rc = notifyCloseCancel(); notfify_close_ = true;
//if(main_thread_id_ == GetCurrentThreadId())
//rc = notifyCloseCancel();
//else
//{
// HANDLE thrd = OpenThread(THREAD_ALL_ACCESS, FALSE, main_thread_id_);
// int err = -1;
// if (thrd)
// {
// if (QueueUserAPC(&huagao_ds::notify_close, thrd, (ULONG_PTR)this))
// err = 0;
// else
// err = GetLastError();
// CloseHandle(thrd);
// }
// load_sane_util::to_log(3, L"Notify close setting UI in different thread(%x), invoke 'notifyCloseCancel' in enable-thread %x(%x), result %d\r\n", GetCurrentThreadId(), main_thread_id_, thrd, err);
//}
//if (!Twpp::success(rc)) //if (!Twpp::success(rc))
//{ //{
// rc = notifyXferReady(); // 好分数需要再通知 FAINT :( - modified on 2022-10-20 // rc = notifyXferReady(); // 好分数需要再通知 FAINT :( - modified on 2022-10-20

View File

@ -58,6 +58,7 @@ class huagao_ds : public Twpp::SourceFromThis<huagao_ds> {
bool show_setting_; bool show_setting_;
int count_; int count_;
volatile bool is_getting_count_; volatile bool is_getting_count_;
volatile bool notfify_close_ = false;
static std::string get_hidedlg_path(void); static std::string get_hidedlg_path(void);
static void showmsg(const char* msg, int err); static void showmsg(const char* msg, int err);
static int __stdcall on_scanner_event(int ev, void* param); static int __stdcall on_scanner_event(int ev, void* param);