497 lines
14 KiB
C++
497 lines
14 KiB
C++
// LicenseUpgrade.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "geomative.h"
|
|
#include "LicenseUpgrade.h"
|
|
#include <DbgHelp.h>
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLicenseUpgrade dialog
|
|
|
|
extern CGeoMativeApp theApp;
|
|
extern int g_iUILanguage;
|
|
|
|
CLicenseUpgrade::CLicenseUpgrade(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CLicenseUpgrade::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CLicenseUpgrade)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_bIsCrulInitaled = false;
|
|
}
|
|
|
|
|
|
void CLicenseUpgrade::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CLicenseUpgrade)
|
|
DDX_Control(pDX, IDC_PRG_LCI_UPG, m_proDownFile);
|
|
DDX_Control(pDX, IDC_COMBO_DEV_ONLINE, m_comDev);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CLicenseUpgrade, CDialog)
|
|
//{{AFX_MSG_MAP(CLicenseUpgrade)
|
|
ON_WM_TIMER()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLicenseUpgrade message handlers
|
|
|
|
BOOL CLicenseUpgrade::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
SetWindowText(_T("升级License"));
|
|
GetDlgItem(IDC_STATIC_DEVICE_NAME)->SetWindowText(_T("设备:"));
|
|
GetDlgItem(IDC_STATIC_DOWN_FILE)->SetWindowText(_T("进度:"));
|
|
GetDlgItem(IDOK)->SetWindowText(_T("升级"));
|
|
|
|
}
|
|
m_bIsCrulInitaled = false;
|
|
m_bIsUpdating = false;
|
|
int iIndex = (int)VAL_ZERO;
|
|
CPtrArray olDevList;
|
|
CDevice* pDev = NULL;
|
|
olDevList.RemoveAll();
|
|
theApp.m_pDevManager->GetOLDevList(&olDevList);
|
|
iIndex = (int)VAL_ZERO;
|
|
m_comDev.Clear();
|
|
while (iIndex < olDevList.GetSize())
|
|
{
|
|
pDev = NULL;
|
|
pDev = (CDevice*)olDevList.GetAt(iIndex);
|
|
|
|
if (PZ_STATE_NEW != pDev->m_uState)
|
|
{
|
|
m_comDev.AddString(pDev->m_szDevSN);
|
|
m_comDev.SetItemDataPtr(m_comDev.GetCount() - 1, pDev);
|
|
}
|
|
iIndex++;
|
|
}
|
|
if (0 == m_comDev.GetCount())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先连接主机设备!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("There is no online device,please connect to device!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return FALSE;
|
|
}
|
|
|
|
m_comDev.SetCurSel(0);
|
|
m_proDownFile.SetRange(0,100);
|
|
m_proDownFile.SetPos(0);
|
|
UpdateData(FALSE);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CLicenseUpgrade::OnOK()
|
|
{
|
|
// TODO: Add extra validation here
|
|
UpdateData(TRUE);
|
|
if (m_bIsUpdating)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("正在升级,请稍后..."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Now is updating, please wait...."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
|
|
CString strDevice = _T("");
|
|
if (m_comDev.GetCurSel() < 0)
|
|
{
|
|
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先选择设备."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please select device"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
m_comDev.GetLBText(m_comDev.GetCurSel(), strDevice);
|
|
if (strDevice.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("获取设备名失败!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("Get Device-Name failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
|
|
CDevice *pDev = (CDevice*)(m_comDev.GetItemDataPtr(m_comDev.GetCurSel()));
|
|
if (NULL == pDev)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("获取设备失败!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("Get Device-Ptr failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
|
|
m_bIsUpdating = true;
|
|
|
|
|
|
if (GetLicenseFile(strDevice))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("下载新License成功,正在将License升级到主机设备中,请等待."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Donwload new license successfully\r\nplease wait to upgrade the license of mainframe now."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
GetDlgItem(IDC_STATIC_DOWN_FILE)->SetWindowText(_T("Download complete!"));
|
|
GetDlgItem(IDC_STATIC_LCI_RATE)->SetWindowText(_T(""));
|
|
UpdateGD10Dev(&(pDev->m_sComPort));
|
|
//装载完成后删除文件
|
|
DeleteFile(".\\tools\\FACTORY");
|
|
DeleteFile(".\\tools\\LICENSE");
|
|
}
|
|
else
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("升级License失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Upgrade license failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
}
|
|
|
|
m_bIsUpdating = false;
|
|
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
bool CLicenseUpgrade::GetLicenseFile(CString strDev)
|
|
{
|
|
CString strFolderInfo = ".\\tools\\";
|
|
// bool bRes = false;
|
|
//首先检查是否创建用于存放更新文件的文件夹
|
|
if(!MakeSureDirectoryPathExists(strFolderInfo.GetBuffer(0)))
|
|
{
|
|
CString strShow = _T("");
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
strShow.Format(_T("创建文件夹更新失败! 错误码 = %d"), GetLastError());
|
|
AfxMessageBox(strShow.GetBuffer(0));
|
|
}
|
|
else
|
|
{
|
|
strShow.Format(_T("Create folder updats failed! errorcode = %d"), GetLastError());
|
|
MessageBoxEx(NULL, strShow, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
if (!m_FileTransfer.Inital())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("文件转发初始化失败!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("FileTransfer Initail Failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
|
|
// if (!m_bIsCrulInitaled)
|
|
// {
|
|
// if (!m_FileTransfer.Inital())
|
|
// {
|
|
// AfxMessageBox("FileTransfer Initail Failed!!!");
|
|
// return false;
|
|
// }
|
|
// m_bIsCrulInitaled = true;
|
|
// }
|
|
SetTimer(1,300,NULL);
|
|
|
|
std::vector<CString> vtDonwFileInfo;
|
|
vtDonwFileInfo.clear();
|
|
vtDonwFileInfo.push_back(_T("FACTORY.txt"));
|
|
vtDonwFileInfo.push_back(_T("LICENSE.txt"));
|
|
|
|
std::vector<CString> vtSaveFileInfo;
|
|
vtSaveFileInfo.clear();
|
|
vtSaveFileInfo.push_back(_T("FACTORY"));
|
|
vtSaveFileInfo.push_back(_T("LICENSE"));
|
|
|
|
m_FileTransfer.SetOption(OPT_TIMEOUT, "60");
|
|
m_FileTransfer.SetOption(OPT_NEED_PROGRESS, "", true);
|
|
m_FileTransfer.SetOption(OPT_DOWNLOAD_PATH, ".\\tools\\");
|
|
// m_FileTransfer.SetOption(OPT_HTTPS_ACCESS, "", true);
|
|
// m_FileTransfer.SetOption(OPT_SSL_CERTIFY, "", false);
|
|
|
|
for (int i = 0; i < vtDonwFileInfo.size(); i++)
|
|
{
|
|
/* m_bIsUpdating = true;*/
|
|
m_FileTransfer.SetOption(OPT_DOWNLOAD_NAME, vtDonwFileInfo[i]);
|
|
CString strUrl =_T("");
|
|
// strUrl.Format(_T("http://192.168.1.110:8080/liushq/%s"), strSrcFile.GetBuffer(0));
|
|
// strUrl.Format(_T("http://192.168.1.110:8080/liushq/%s/%s"), strDev.GetBuffer(0),vtDonwFileInfo[i].GetBuffer(0));
|
|
strUrl.Format(_T("%s%s/%s"), theApp.m_strUpgUrl,strDev.GetBuffer(0),vtDonwFileInfo[i].GetBuffer(0));
|
|
m_FileTransfer.SetOption(OPT_URL_ADDRESS, strUrl);
|
|
m_FileTransfer.SetOption(OPT_DOWNLOAD_NAME, vtSaveFileInfo[i]);
|
|
|
|
CString strTmp = _T("");
|
|
strTmp.Format(_T("Downloading %s..."), vtDonwFileInfo[i].GetBuffer(0));
|
|
GetDlgItem(IDC_STATIC_DOWN_FILE)->SetWindowText(strTmp.GetBuffer(0));
|
|
m_proDownFile.SetPos(0);
|
|
GetDlgItem(IDC_STATIC_LCI_RATE)->SetWindowText("0%");
|
|
if (!m_FileTransfer.DownloadFile())
|
|
{
|
|
// strTmp.Empty();
|
|
// strTmp.Format("DownLoadUpdateFiles %s_%s failed!!!", vtDonwFileInfo[i].GetBuffer(0));
|
|
//AfxMessageBox(strTmp);
|
|
// strTmp.Format(_T("[%d] download file failed!, index = %d, url = %s"),__LINE__, i+1, strUrl.GetBuffer(0));
|
|
//如果下载LICENSE失败,则需要删除FACTORY文件
|
|
if (1 == i)
|
|
{
|
|
DeleteFile(".\\tools\\FACTORY");
|
|
}
|
|
m_FileTransfer.UnInital();
|
|
KillTimer(1);
|
|
|
|
return false;
|
|
}
|
|
m_proDownFile.SetPos(100);
|
|
GetDlgItem(IDC_STATIC_LCI_RATE)->SetWindowText("100%");
|
|
}
|
|
|
|
m_FileTransfer.UnInital();
|
|
KillTimer(1);
|
|
return true;
|
|
/*
|
|
if (!m_bIsCrulInitaled)
|
|
{
|
|
if (!m_FileTransfer.Inital())
|
|
{
|
|
AfxMessageBox("FileTransfer Initail Failed!!!");
|
|
return false;
|
|
}
|
|
m_bIsCrulInitaled = true;
|
|
}
|
|
CString strDstUrl = _T("");
|
|
// CString strDstFileName = _T("LICENSE.bin");
|
|
strDstUrl.Format(_T("http://218.17.161.7:9520/liushq/%s/LICENSE.bin"),strDev.GetBuffer(0));
|
|
|
|
m_FileTransfer.SetOption(OPT_URL_ADDRESS, strDstUrl);
|
|
m_FileTransfer.SetOption(OPT_DOWNLOAD_PATH, ".\\tools\\");
|
|
m_FileTransfer.SetOption(OPT_DOWNLOAD_NAME, "LICENSE.bin");
|
|
m_FileTransfer.SetOption(OPT_TIMEOUT, "30");
|
|
m_FileTransfer.SetOption(OPT_NEED_PROGRESS, "", true);
|
|
return m_FileTransfer.DownloadFile();
|
|
*/
|
|
}
|
|
|
|
void CLicenseUpgrade::OnTimer(UINT nIDEvent)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
if (1 == nIDEvent)
|
|
{
|
|
// CString strTmp
|
|
// CString strDownFileName =_T("");
|
|
// m_FileTransfer.GetFileName(strDownFileName);
|
|
//当前下载文件的总大小
|
|
curl_off_t lFileTotalSize = m_FileTransfer.GetFileTotalSize();
|
|
//当前下载文件的大小
|
|
curl_off_t lCurFileSize = m_FileTransfer.GetCurDownloadSize();
|
|
CString strShow =_T("");
|
|
// strShow.Format(_T("update %s ...."), strDownFileName.GetBuffer(0));
|
|
// GetDlgItem(IDC_TITLE)->SetWindowText(strShow.GetBuffer(0));
|
|
if (lFileTotalSize > 0)
|
|
{
|
|
int nPos = 100 * lCurFileSize / lFileTotalSize;
|
|
strShow.Empty();
|
|
strShow.Format(_T("%d%%"), nPos);
|
|
GetDlgItem(IDC_STATIC_LCI_RATE)->SetWindowText(strShow.GetBuffer(0));
|
|
m_proDownFile.SetPos(nPos);
|
|
}
|
|
else
|
|
{
|
|
m_proDownFile.SetPos(0);
|
|
GetDlgItem(IDC_STATIC_LCI_RATE)->SetWindowText("0%");
|
|
}
|
|
|
|
}
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|
|
|
|
void CLicenseUpgrade::UpdateGD10Dev(CSComPort *pCom)
|
|
{
|
|
//刷固件:
|
|
// if(!MakeSureDirectoryPathExists(_T(".\\tools\\")))
|
|
// {
|
|
// hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
|
// AfxMessageBox("tools file had been miss please contact admimnistrator");
|
|
// return false;
|
|
// }
|
|
|
|
CString szFolderName = "tools";
|
|
CString szFilePath = ".//";
|
|
CString szBatPath;
|
|
|
|
CString szOrder = _T("");
|
|
szOrder = "isp()\r\n";
|
|
if (!pCom->ExecuteNoResOrder(szOrder))
|
|
{
|
|
//HOOKhHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("下发升级License命令(isp)失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Update license(isp) failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return ;
|
|
}
|
|
|
|
Sleep(5000);
|
|
|
|
char cReadBuff[1024]; int nLength = 0;
|
|
memset(cReadBuff, 0, 1024);
|
|
pCom->ReceiveDataDirectly(cReadBuff, &nLength);
|
|
|
|
//判断是否电量低
|
|
if (nLength != 0)
|
|
{
|
|
CString strRcv = cReadBuff;
|
|
//当找到Low字符时,认为此时的电量不足
|
|
if (strRcv.Find("Low") != -1)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("电量太低,请先充电."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Bettery is low, please charge"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return ;
|
|
}
|
|
}
|
|
|
|
szBatPath = ".\\tools\\License-GD20.bat";
|
|
|
|
PROCESS_INFORMATION ProcessInfo;
|
|
|
|
STARTUPINFO StartupInfo; //入口参数
|
|
memset(&ProcessInfo, 0, sizeof(ProcessInfo));
|
|
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
|
|
|
|
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
|
|
StartupInfo.wShowWindow = SW_SHOW;
|
|
//////////////////////////////////////////////////////////////////////////???
|
|
StartupInfo.cb = sizeof(StartupInfo); //分配大小
|
|
|
|
unsigned long nTime = 0;
|
|
int nAbandondeCount = 0;
|
|
int nTimeoutCount = 0;
|
|
bool bWriteFlash = false;
|
|
|
|
if(CreateProcess(szBatPath, NULL,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo))
|
|
{
|
|
while(TRUE)
|
|
{
|
|
//如果烧写成功,则烧写下一个
|
|
if (bWriteFlash)
|
|
{
|
|
break;
|
|
}
|
|
switch(WaitForSingleObject(ProcessInfo.hProcess,500))
|
|
{
|
|
case WAIT_ABANDONED:
|
|
nTime += 500;
|
|
if (nAbandondeCount++ > 200)
|
|
{
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
return ;
|
|
}
|
|
break;
|
|
case WAIT_TIMEOUT:
|
|
nTime += 500;
|
|
if (nTimeoutCount++ > 900)
|
|
{
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
return ;
|
|
}
|
|
break;
|
|
case WAIT_OBJECT_0:
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
if (nTime > 40000)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("更新License文件失败,请检查操作系统环境."));
|
|
else
|
|
MessageBoxEx(NULL, _T("UpDate License failed, please check operation system environment"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return ;
|
|
}
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("升级成功."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Upgrade success."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
bWriteFlash = true;
|
|
return;
|
|
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
|
|
szBatPath = ".\\tools\\LICENSE.bat";
|
|
memset(&ProcessInfo, 0, sizeof(ProcessInfo));
|
|
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
|
|
|
|
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
|
|
StartupInfo.wShowWindow = SW_SHOW;
|
|
StartupInfo.cb = sizeof(StartupInfo); //分配大小
|
|
nTime = 0;
|
|
nAbandondeCount = 0;
|
|
nTimeoutCount = 0;
|
|
|
|
if(CreateProcess(szBatPath, NULL,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo))
|
|
{
|
|
while(TRUE)
|
|
{
|
|
switch(WaitForSingleObject(ProcessInfo.hProcess,500))
|
|
{
|
|
case WAIT_ABANDONED:
|
|
nTime += 500;
|
|
if (nAbandondeCount++ > 200)
|
|
{
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
return ;
|
|
}
|
|
break;
|
|
case WAIT_TIMEOUT:
|
|
nTime += 500;
|
|
if (nTimeoutCount++ > 900)
|
|
{
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
return ;
|
|
}
|
|
break;
|
|
case WAIT_OBJECT_0:
|
|
CloseHandle(ProcessInfo.hThread);
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
if (nTime > 40000)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("更新License文件失败,请检查操作系统环境."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Update License failed, please check operation system environment"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return ;
|
|
}
|
|
return ;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ;
|
|
|
|
}
|