321 lines
12 KiB
C++
321 lines
12 KiB
C++
// CaptureDataDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "Mv_Util.h"
|
|
#include "CaptureDataDlg.h"
|
|
#include "afxdialogex.h"
|
|
#include "..\..\..\MicroVu\Mv_Proto.h"
|
|
|
|
extern CMv_Proto *m_pMv_Proto;
|
|
|
|
// CCaptureDataDlg dialog
|
|
|
|
IMPLEMENT_DYNAMIC(CCaptureDataDlg, CDialogEx)
|
|
|
|
CCaptureDataDlg::CCaptureDataDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialogEx(CCaptureDataDlg::IDD, pParent)
|
|
{
|
|
|
|
}
|
|
|
|
CCaptureDataDlg::~CCaptureDataDlg()
|
|
{
|
|
}
|
|
|
|
void CCaptureDataDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialogEx::DoDataExchange(pDX);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CCaptureDataDlg, CDialogEx)
|
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE_CONFIG, &CCaptureDataDlg::OnBnClickedButtonUpdateConfig)
|
|
ON_BN_CLICKED(IDC_BUTTON_BROWSE_LOG, &CCaptureDataDlg::OnBnClickedButtonBrowseLog)
|
|
ON_BN_CLICKED(IDC_BUTTON_GET_MV_CONFIG, &CCaptureDataDlg::OnBnClickedButtonGetMvConfig)
|
|
ON_BN_CLICKED(IDC_RADIO_CREATE_MV_CONFIG, &CCaptureDataDlg::OnBnClickedRadioCreateMvConfig)
|
|
ON_BN_CLICKED(IDC_RADIO_UPDATE_MV_CONFIG, &CCaptureDataDlg::OnBnClickedRadioUpdateMvConfig)
|
|
END_MESSAGE_MAP()
|
|
|
|
//=============================================================================
|
|
// CCaptureDataDlg message handlers
|
|
//=============================================================================
|
|
void CCaptureDataDlg::OnBnClickedButtonUpdateConfig()
|
|
{
|
|
char inBuff[MAX_LINE_LEN];
|
|
FILE* pOutFile;
|
|
FILE* pMvFile;
|
|
FILE* pExtractLogFile;
|
|
|
|
memset(_str_7000, 0, MAX_SHORT_LEN);
|
|
memset(_str_6f00, 0, MAX_SHORT_LEN);
|
|
memset(_str_4c02, 0, MAX_SHORT_LEN);
|
|
|
|
//==================================================================================
|
|
// Create condensed file first.
|
|
//==================================================================================
|
|
CMv_Proto_Dump* mv_proto_dump = new CMv_Proto_Dump;
|
|
int retStatus = mv_proto_dump->MainSnoopyFunction(m_SnoopyLogFile, OUT_CONDENSED, MACHINE_MICROVU);
|
|
delete mv_proto_dump;
|
|
if (retStatus == -1)
|
|
{
|
|
m_status_msg += _T("\r\nError: SnoopyLog not found or unable to create condensed file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
}
|
|
m_proto_filename = m_SnoopyLogFile + _T(".condensed.proto.txt");
|
|
m_status_msg = _T("\r\nStatus : Extract file created. - ") + m_proto_filename;
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
|
|
//==================================================================================
|
|
// Extract 7000/6f00/4c02 from the condensed files.
|
|
//==================================================================================
|
|
_wfopen_s(&pExtractLogFile, m_proto_filename, _T("r")); // open the condensed file
|
|
fgets((char *)inBuff, MAX_LINE_LEN, pExtractLogFile ); // pick up the first line
|
|
while (!feof(pExtractLogFile))
|
|
{
|
|
if (inBuff[0] != '>')
|
|
{
|
|
// dummy
|
|
}
|
|
else
|
|
if (!_strnicmp(inBuff+30, _6000_BUFF, 7))
|
|
{
|
|
// convert the ascii text into wchar_t code.
|
|
memset(_c_str_model, 0, MAX_SHORT_LEN*2);
|
|
memset(_c_str_serial_no, 0, MAX_SHORT_LEN*2);
|
|
memset(_str_model, 0, MAX_SHORT_LEN*2);
|
|
memset(_str_serial_no, 0, MAX_SHORT_LEN*2);
|
|
for (int i = 0; i<16; ++i)
|
|
{
|
|
_c_str_serial_no[i] = (unsigned char) (*(inBuff+37+i*2) - '0');
|
|
_c_str_serial_no[i] = (_c_str_serial_no[i] << 4) + (unsigned char) (*(inBuff+37+i*2+1) - '0');
|
|
_c_str_model[i] = (unsigned char) (*(inBuff+101+i*2) - '0');
|
|
_c_str_model[i] = (_c_str_model[i] << 4 ) + (unsigned char) (*(inBuff+101+i*2+1) - '0');
|
|
};
|
|
wcstombs(_str_serial_no, _wc_str_serial_no, 16);
|
|
wcstombs(_str_model, _wc_str_model, 16);
|
|
strcpy(_str_SerialNo, _STR_SerialNo_Label);
|
|
strcat(_str_SerialNo, _str_serial_no);
|
|
int i = (int) strlen(_str_SerialNo);
|
|
_str_SerialNo[i] = 0x0a;
|
|
_str_SerialNo[i+1] = 0;
|
|
strcpy(_str_Model, _STR_Model_Label);
|
|
strcat(_str_Model, _str_model);
|
|
i = (int) strlen(_str_Model);
|
|
_str_Model[i] = 0x0a;
|
|
_str_Model[i+1] = 0;
|
|
}
|
|
else
|
|
if (!(inBuff[40] == '1' && inBuff[41] == '0'))
|
|
{
|
|
}
|
|
else
|
|
if (!_strnicmp(inBuff+35, _7000_BUFF, 4))
|
|
{
|
|
strcpy(_str_7000, _STR_7000_Label);
|
|
strcat(_str_7000, inBuff+35);
|
|
strcpy(m_pMv_Proto->g_machine.s_machine_config._str_7000_signature, inBuff+35);
|
|
}
|
|
else
|
|
if (!_strnicmp(inBuff+35, _6f00_BUFF, 4))
|
|
{
|
|
strcpy(_str_6f00, _STR_6f00_Label);
|
|
strcat(_str_6f00, inBuff+35);
|
|
strcpy(m_pMv_Proto->g_machine.s_machine_config._str_6f00_signature, inBuff+35);
|
|
}
|
|
fgets((char *)inBuff, MAX_LINE_LEN, pExtractLogFile ); // pick up the first line
|
|
};
|
|
fclose(pExtractLogFile);
|
|
|
|
//==================================================================================
|
|
// Create a new mv_config file.
|
|
//==================================================================================
|
|
if (((CButton *)GetDlgItem(IDC_RADIO_CREATE_MV_CONFIG))->GetCheck())
|
|
{
|
|
m_status_msg += _T("\r\nStatus : Creating new mv_config file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
MvConfigNew();
|
|
return;
|
|
};
|
|
|
|
//==================================================================================
|
|
// Create the temp_mv_config_file from old mv_config.
|
|
//==================================================================================
|
|
_wfopen_s(&pMvFile, m_mv_config_full_path_name, _T("r")); // open the condensed file
|
|
|
|
if (pMvFile == NULL)
|
|
{
|
|
m_status_msg += _T("\r\nUnable to open mv_config file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
};
|
|
|
|
CString _temp_name = m_AppPath + _T("\\") + m_temp_mv_config_filename + _T(".") + _wc_str_serial_no + _T(".cfg");
|
|
_wfopen_s(&pOutFile, _temp_name, _T("w")); // open the condensed file
|
|
if (pOutFile == NULL)
|
|
{
|
|
m_status_msg += _T("\r\nUnable to create temp_mv_config file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
};
|
|
fputs(_str_SerialNo, pOutFile);
|
|
fputs(_str_Model, pOutFile);
|
|
fputs(_str_7000, pOutFile);
|
|
fputs(_str_6f00, pOutFile);
|
|
// fputs(_str_4c02, pOutFile);
|
|
|
|
fgets((char *)inBuff, MAX_LINE_LEN, pMvFile ); // pick up the first line
|
|
while (!feof(pMvFile))
|
|
{
|
|
if (!_strnicmp(inBuff, _STR_7000_Label, 9) ||
|
|
!_strnicmp(inBuff, _STR_6f00_Label, 9) ||
|
|
// !_strnicmp(inBuff, _STR_4c02_Label, 9) ||
|
|
!_strnicmp(inBuff, _STR_SerialNo_Label, 9) ||
|
|
!_strnicmp(inBuff, _STR_Model_Label, 6))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
fputs(inBuff, pOutFile);
|
|
};
|
|
fgets((char *)inBuff, MAX_LINE_LEN, pMvFile ); // pick up the first line
|
|
};
|
|
|
|
fclose(pMvFile);
|
|
fclose(pOutFile);
|
|
m_status_msg += _T("\r\nStatus : temp_mv_config created - \r\n ") + _temp_name;
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
}
|
|
|
|
//=======================================================================
|
|
// Defaults to c:\Windows\usbsnoop.log
|
|
// Use File Dialog to point to the log file.
|
|
// This file must exist.
|
|
void CCaptureDataDlg::OnBnClickedButtonBrowseLog()
|
|
{
|
|
CString strFilters = _T("All Files (*.*)|*.*||");
|
|
CString strExt = _T("log");
|
|
CFileDialog fileDlg(TRUE, strExt, (LPCTSTR) m_SnoopyLogFile, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, strFilters, this);
|
|
FILE* pLogFile;
|
|
INT_PTR nResult;
|
|
while (true) {
|
|
nResult = fileDlg.DoModal();
|
|
if (nResult == IDOK)
|
|
{
|
|
m_SnoopyLogFile = fileDlg.GetPathName();
|
|
_wfopen_s(&pLogFile, m_SnoopyLogFile, _T("r")); // see if we can read the file.
|
|
if (pLogFile == NULL)
|
|
{
|
|
m_status_msg += _T("\r\n Snoopy Input File not found.");
|
|
MessageBox( _T("UsbSnoop.log not found."), _T("Message"), MB_OK);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
((CEdit *)GetDlgItem(IDC_EDIT_SNOOP_LOG_FILE))->SetWindowText(m_SnoopyLogFile);
|
|
fclose(pLogFile);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
// Defaults to the current directory with a file called mv_config.cfg.
|
|
// This file may not exist.
|
|
void CCaptureDataDlg::OnBnClickedButtonGetMvConfig()
|
|
{
|
|
CString strFilters = _T("All Files (*.*)|*.*||");
|
|
CString strExt = _T("cfg");
|
|
CString csMvFile = _T("mv_config.cfg");
|
|
CFileDialog fileDlg(TRUE, strExt, (LPCTSTR) csMvFile, OFN_HIDEREADONLY, strFilters, this);
|
|
FILE* pMvFile;
|
|
INT_PTR nResult;
|
|
while (true) {
|
|
nResult = fileDlg.DoModal();
|
|
if (nResult == IDOK)
|
|
{
|
|
csMvFile = fileDlg.GetPathName();
|
|
_wfopen_s(&pMvFile, csMvFile, _T("r")); // see if we can read the file.
|
|
if (pMvFile == NULL)
|
|
{
|
|
m_status_msg += _T("\r\nmv_config.cfg file not found. Creating a new temp_mv_config.cfg without mv_config.cfg file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
m_mv_config_full_path_name = csMvFile;
|
|
fclose(pMvFile);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
}
|
|
|
|
//===========================================================================
|
|
BOOL CCaptureDataDlg::OnInitDialog()
|
|
{
|
|
m_status_msg = _T("System Ready.");
|
|
m_SnoopyLogFile = _T("C:\\Windows\\usbsnoop.log");
|
|
m_mv_config_filename = _T("mv_config.cfg");
|
|
m_temp_mv_config_filename = _T("temp_mv_config");
|
|
m_pMv_Proto->GetAppPath(m_AppPath);
|
|
((CEdit *)GetDlgItem(IDC_EDIT_SNOOP_LOG_FILE))->SetWindowText(m_SnoopyLogFile);
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
((CButton *)GetDlgItem(IDC_RADIO_CREATE_MV_CONFIG))->SetCheck(0);
|
|
((CButton *)GetDlgItem(IDC_RADIO_UPDATE_MV_CONFIG))->SetCheck(1);
|
|
CString strAppPath;
|
|
m_pMv_Proto->GetAppPath(strAppPath);
|
|
m_mv_config_full_path_name = strAppPath + _T("\\") + m_mv_config_filename;
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->EnableWindow(true);
|
|
((CEdit *)GetDlgItem(IDC_EDIT_MV_CONFIG_FILE))->SetWindowText(m_mv_config_full_path_name);
|
|
|
|
return TRUE;
|
|
};
|
|
|
|
//===========================================================================
|
|
void CCaptureDataDlg::MvConfigNew()
|
|
{
|
|
CString fn;
|
|
((CEdit *)GetDlgItem(IDC_EDIT_SNOOP_LOG_FILE))->GetWindowText(fn);
|
|
|
|
FILE* pOutFile;
|
|
CString _temp_name = m_AppPath + _T("\\") + m_temp_mv_config_filename + _T(".") + _wc_str_serial_no + _T(".cfg");
|
|
_wfopen_s(&pOutFile, _temp_name, _T("w")); // open the condensed file
|
|
if (pOutFile == NULL)
|
|
{
|
|
m_status_msg += _T("\r\nStatus : Unable to create temp_mv_config file.");
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
};
|
|
fputs(_str_SerialNo, pOutFile);
|
|
fputs(_str_Model, pOutFile);
|
|
fputs(_str_7000, pOutFile);
|
|
fputs(_str_6f00, pOutFile);
|
|
fputs(_str_4c02, pOutFile);
|
|
fclose(pOutFile);
|
|
m_status_msg += _T("\r\nTemp_mv_config created - \r\n ") + _temp_name;
|
|
((CEdit *)GetDlgItem(IDC_EDIT_STATUS_WINDOW))->SetWindowText(m_status_msg);
|
|
return;
|
|
}
|
|
|
|
//===========================================================================
|
|
void CCaptureDataDlg::OnBnClickedRadioCreateMvConfig()
|
|
{
|
|
((CEdit *)GetDlgItem(IDC_EDIT_MV_CONFIG_FILE))->EnableWindow(false);
|
|
((CEdit *)GetDlgItem(IDC_BUTTON_GET_MV_CONFIG))->EnableWindow(false);
|
|
}
|
|
|
|
//===========================================================================
|
|
void CCaptureDataDlg::OnBnClickedRadioUpdateMvConfig()
|
|
{
|
|
((CEdit *)GetDlgItem(IDC_EDIT_MV_CONFIG_FILE))->EnableWindow(true);
|
|
((CEdit *)GetDlgItem(IDC_BUTTON_GET_MV_CONFIG))->EnableWindow(true);
|
|
}
|