/** Reads the next OUT report from the host from the OUT endpoint, if one has been sent. */ void ReceiveNextReport(void) { static struct { struct { unsigned char type; unsigned char length; } header; unsigned char buffer[EPSIZE]; } packet = { .header.type = BYTE_OUT_REPORT }; uint16_t length = 0; /* Select the OUT Report Endpoint */ Endpoint_SelectEndpoint(OUT_EPNUM); /* Check if OUT Endpoint contains a packet */ if (Endpoint_IsOUTReceived()) { /* Check to see if the packet contains data */ if (Endpoint_IsReadWriteAllowed()) { /* Read OUT Report Data */ uint8_t ErrorCode = Endpoint_Read_Stream_LE(packet.buffer, sizeof(packet.buffer), &length); if(ErrorCode == ENDPOINT_RWSTREAM_NoError) { length = sizeof(packet.buffer); } } /* Handshake the OUT Endpoint - clear endpoint and ready for next report */ Endpoint_ClearOUT(); if(length) { packet.header.length = length & 0xFF; Serial_SendData(&packet, sizeof(packet.header) + packet.header.length); } } } /** Function to manage HID report generation and transmission to the host, when in report mode. */ void HID_Task(void) { /* Device must be connected and configured for the task to run */ if (USB_DeviceState != DEVICE_STATE_Configured) return; /* Send the next keypress report to the host */ SendNextReport(); /* Process the LED report sent from the host */ ReceiveNextReport(); }
void CResendDlg::DoProgressTimer() { // Get current progress int nProgressPct = 0; std::vector<CString> messages; g_ErrorReportSender.GetStatus(nProgressPct, messages); // Update progress bar m_dlgActionProgress.m_prgProgress.SetPos(nProgressPct); int nCurItem = FindListItemByReportIndex(m_nCurReport); unsigned i; for(i=0; i<messages.size(); i++) { m_dlgActionProgress.m_statActionDesc.SetWindowText(messages[i]); if(m_fileLog) { strconv_t strconv; LPCSTR szLine = strconv.t2utf8(messages[i]); fprintf(m_fileLog, szLine); fprintf(m_fileLog, "\n"); } if(messages[i].CompareNoCase(_T("[status_success]"))==0) { m_listReports.SetItemText(nCurItem, 2, Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ResendDlg"), _T("StatusSucceeded"))); SendNextReport(); } else if(messages[i].CompareNoCase(_T("[status_failed]"))==0) { m_bErrors = TRUE; m_listReports.SetItemText(nCurItem, 2, Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ResendDlg"), _T("StatusFailed"))); SendNextReport(); } else if(messages[i].CompareNoCase(_T("[exit_silently]"))==0) { m_bErrors = TRUE; SendNextReport(); } else if(messages[i].CompareNoCase(_T("[cancelled_by_user]"))==0) { /*m_bErrors = TRUE; m_listReports.SetItemText(nCurItem, 2, Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ResendDlg"), _T("StatusFailed"))); SendNextReport(); */ } else if(messages[i].CompareNoCase(_T("[confirm_launch_email_client]"))==0) { KillTimer(0); if(!g_CrashInfo.m_bSilentMode) { if(m_MailClientConfirm==NOT_CONFIRMED_YET) { BOOL bVisible = IsWindowVisible(); ShowWindow(SW_SHOW); SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); SetFocus(); RedrawWindow(0, 0, RDW_ERASE|RDW_FRAME|RDW_INVALIDATE); m_listReports.RedrawWindow(0, 0, RDW_ERASE|RDW_FRAME|RDW_INVALIDATE); DWORD dwFlags = 0; CString sRTL = Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("Settings"), _T("RTLReading")); if(sRTL.CompareNoCase(_T("1"))==0) dwFlags = MB_RTLREADING; CString sMailClientName; CMailMsg::DetectMailClient(sMailClientName); CString msg; msg.Format(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ProgressDlg"), _T("ConfirmLaunchEmailClient")), sMailClientName); CString sCaption = Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ProgressDlg"), _T("DlgCaption")); CString sTitle; sTitle.Format(sCaption, g_CrashInfo.m_sAppName); INT_PTR result = MessageBox(msg, sTitle, MB_OKCANCEL|MB_ICONQUESTION|dwFlags); RedrawWindow(); if(result==IDOK) m_MailClientConfirm = ALLOWED; else m_MailClientConfirm = NOT_ALLOWED; g_ErrorReportSender.FeedbackReady(result==IDOK?0:1); ShowWindow(bVisible?SW_SHOW:SW_HIDE); } else { g_ErrorReportSender.FeedbackReady(m_MailClientConfirm==ALLOWED?0:1); } } else { // In silent mode, assume user provides his/her consent g_ErrorReportSender.FeedbackReady(0); } } } }
LRESULT CResendDlg::OnSendNow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { if(!m_bSendingNow) { int i; for(i=0; i<m_listReports.GetItemCount(); i++) { BOOL bSelected = m_listReports.GetCheckState(i); if(bSelected) { int nReport = (int)m_listReports.GetItemData(i); if(g_CrashInfo.GetReport(nReport).m_DeliveryStatus == PENDING) { m_listReports.SetItemText(i, 2, Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ResendDlg"), _T("StatusPending"))); } } } m_bSendingNow = TRUE; m_bCancelled = FALSE; m_bErrors = FALSE; m_ActionOnClose = HIDE; m_statText.SetWindowText( Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ResendDlg"), _T("DeliveryingReports"))); m_statSize.ShowWindow(SW_HIDE); m_statConsent.ShowWindow(SW_HIDE); m_linkPrivacyPolicy.ShowWindow(SW_HIDE); m_btnOtherActions.ShowWindow(SW_HIDE); m_btnShowLog.ShowWindow(SW_HIDE); m_dlgActionProgress.ShowWindow(SW_SHOW); m_btnSendNow.SetWindowText( Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("ProgressDlg"), _T("Cancel"))); SetTimer(1, 250); // Update this dialog every 250 ms SetTimer(2, 3000); // Hide this dialog in 3 sec. // Open log file Utility::RecycleFile(m_sLogFile, true); CString sCurTime; Utility::GetSystemTimeUTC(sCurTime); sCurTime.Replace(':', '-'); m_sLogFile.Format(_T("%s\\CrashRpt-Log-%s.txt"), g_CrashInfo.m_sUnsentCrashReportsFolder, sCurTime); #if _MSC_VER<1400 m_fileLog = _tfopen(m_sLogFile, _T("wt")); #else _tfopen_s(&m_fileLog, m_sLogFile.GetBuffer(0), _T("wt")); #endif fprintf(m_fileLog, "%c%c%c", 0xEF, 0xBB, 0xBF); // UTF-8 signature SendNextReport(); } else { m_bCancelled = TRUE; m_btnSendNow.EnableWindow(0); KillTimer(2); // Don't hide window g_ErrorReportSender.Cancel(); } return 0; }