修复读取不存在文件时的BUG
This commit is contained in:
parent
403092a2bf
commit
6fadf97d3e
|
@ -880,7 +880,8 @@ usb_monitor::usb_monitor() : wnd_monitor_(NULL), handle_msg_id_(0), run_(true)
|
|||
{
|
||||
thread_handle_device_change_msg();
|
||||
};
|
||||
handle_msg_.start(tf, "usb_monitor::thread_handle_device_change_msg");
|
||||
void(usb_monitor:: * pnp)(void) = &usb_monitor::thread_handle_device_change_msg;
|
||||
handle_msg_.start(tf, "usb_monitor::thread_handle_device_change_msg", *(void**)&pnp);
|
||||
#else
|
||||
handle_msg_.reset(new std::thread(&usb_monitor::thread_handle_device_change_msg, this));
|
||||
#endif
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <direct.h>
|
||||
#include <file/file_util.h>
|
||||
#include <coding/coding.h>
|
||||
#include <json/gb_json.h>
|
||||
#include <sane_opt_json/device_opt.h>
|
||||
#include <huagao/hgscanner_error.h>
|
||||
|
@ -956,11 +957,18 @@ int CDlgScanner::refresh_bulk_status(bool en_dev_log)
|
|||
|
||||
return err;
|
||||
}
|
||||
static DWORD cf_id = 0;
|
||||
static DWORD WINAPI clean_file(LPVOID lp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void CDlgScanner::thread_auto_tx_file(void)
|
||||
{
|
||||
char loc[256] = { 0 },
|
||||
remt[256] = { 0 };
|
||||
uint32_t ind = 0, err = 0;
|
||||
char chk0[40] = { 0 }, chk[40] = { 0 };
|
||||
SYSTEMTIME tm0 = { 0 }, tmn = { 0 };
|
||||
uint32_t ind = 0, err = 0, cleanid = 2;
|
||||
std::string file(""), prev(""), ext("");
|
||||
std::wstring oper(L"");
|
||||
chronograph watch;
|
||||
|
@ -982,6 +990,7 @@ void CDlgScanner::thread_auto_tx_file(void)
|
|||
prev.insert(ind, "\\tx");
|
||||
|
||||
ind = 0;
|
||||
coding_util::md5(usb::a2u(file.c_str()).c_str(), chk0);
|
||||
while (auto_tx_)
|
||||
{
|
||||
double *prog = NULL, prevg = .0f;
|
||||
|
@ -1060,7 +1069,37 @@ void CDlgScanner::thread_auto_tx_file(void)
|
|||
}
|
||||
if (err)
|
||||
break;
|
||||
Sleep(1000);
|
||||
|
||||
bool go = true;
|
||||
if (ind == 1)
|
||||
{
|
||||
usb::get_file_time(file.c_str(), NULL, &tm0, NULL);
|
||||
}
|
||||
else if(cleanid + 100 < ind)
|
||||
{
|
||||
// clean ...
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "xxx --- Delete receied files ...\r\n");
|
||||
for (; cleanid < ind - 1; ++cleanid)
|
||||
{
|
||||
std::string f(prev + std::to_string(cleanid) + ext);
|
||||
|
||||
coding_util::md5(usb::a2u(f.c_str()).c_str(), chk);
|
||||
if (stricmp(chk0, chk))
|
||||
{
|
||||
go = false;
|
||||
MessageBoxA(m_hWnd, ("MD5 check failure at: " + std::to_string(cleanid)).c_str(), "Fatal", MB_OK);
|
||||
break;
|
||||
}
|
||||
usb::get_file_time(f.c_str(), NULL, &tmn, NULL);
|
||||
if (!(tmn.wHour == tm0.wHour && tmn.wMinute == tm0.wMinute))
|
||||
file_util::force_delete_file(usb::a2u(f.c_str()).c_str());
|
||||
}
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "xxx --- Delete receied files OVER.\r\n");
|
||||
}
|
||||
if (go)
|
||||
Sleep(1000);
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (auto_tx_ != (FILE_TX_RECEIVE | FILE_TX_SEND))
|
||||
break;
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace usb
|
|||
const wchar_t* error_name(int err, wchar_t* unk = NULL);
|
||||
std::wstring a2u(const char* ansi);
|
||||
std::string u2a(const wchar_t* unic);
|
||||
bool get_file_time(const char* file, LPSYSTEMTIME pcreate, LPSYSTEMTIME pmodify, LPSYSTEMTIME paccess);
|
||||
void enum_endpoints(libusb_device* device, std::vector<USBEP>& eps);
|
||||
const wchar_t* ep_type(BYTE type);
|
||||
BYTE ep_type(const wchar_t* str);
|
||||
|
|
|
@ -273,6 +273,53 @@ namespace usb
|
|||
return std::move(a);
|
||||
}
|
||||
|
||||
bool get_file_time(const char* file, LPSYSTEMTIME pcreate, LPSYSTEMTIME pmodify, LPSYSTEMTIME paccess)
|
||||
{
|
||||
bool ret = false;
|
||||
HANDLE h = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
while (h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FILETIME c = { 0 }, m = { 0 }, a = { 0 }, l = { 0 };
|
||||
if (GetFileTime(h, &c, &a, &m))
|
||||
{
|
||||
if (pcreate)
|
||||
{
|
||||
if (FileTimeToLocalFileTime(&c, &l))
|
||||
{
|
||||
ret = FileTimeToSystemTime(&l, pcreate) == TRUE;
|
||||
if (!ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pmodify)
|
||||
{
|
||||
if (FileTimeToLocalFileTime(&m, &l))
|
||||
{
|
||||
ret = FileTimeToSystemTime(&l, pmodify) == TRUE;
|
||||
if (!ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (paccess)
|
||||
{
|
||||
if (FileTimeToLocalFileTime(&a, &l))
|
||||
{
|
||||
ret = FileTimeToSystemTime(&l, paccess) == TRUE;
|
||||
if (!ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(h);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void register_tray(HWND owner, HICON icon, bool reg)
|
||||
{
|
||||
if(reg)
|
||||
|
@ -531,7 +578,8 @@ void CusbtoolsDlg::remove_pnp_que(ONLNSCANNER* pnp)
|
|||
close_device(pnp_que_[i]);
|
||||
if (pnp)
|
||||
{
|
||||
pnp_que_.erase(pnp_que_.begin() + i);
|
||||
if(pnp_que_[i].dlg == NULL)
|
||||
pnp_que_.erase(pnp_que_.begin() + i);
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue