// AutoUpdateEmmcNKDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "AutoUpdateEmmcNK.h"
#include "AutoUpdateEmmcNKDlg.h"
#include <ShellAPI.h>
//#include <shlwapi.h>
//#pragma comment(lib,"Shlwapi.lib") //如果没有这行,会出现li
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAutoUpdateEmmcNKDlg 对话框
CAutoUpdateEmmcNKDlg::CAutoUpdateEmmcNKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAutoUpdateEmmcNKDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAutoUpdateEmmcNKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
#define NETWORK_CARD_DEVICE_NAME _T("CPSW3G2")//网卡设备的名称
#define NETWORK_CARD_REGISTER_PARAM_PATH _T("Comm\\CPSW3G2\\Parms\\TcpIp")
#define NETWORK_CARD_REGISTER_IPADDRESS_PARAM _T("DhcpIPAddress")
BEGIN_MESSAGE_MAP(CAutoUpdateEmmcNKDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int ReadRegPath(LPCTSTR subKeyName,LPCTSTR valueName,WCHAR * buf)//
{
HKEY hk;
DWORD dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKeyName, 0, 0, &hk);
DWORD dwType=REG_SZ;
DWORD dwSize=200;
if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
{
dwStatus = RegQueryValueEx(hk, valueName, NULL, &dwType, (LPBYTE)buf, &dwSize);
//printf(">>>>>>>>>>>>>>>>>>>>dwSize:%d\n",dwSize);
if(dwStatus != ERROR_SUCCESS)
{
return -1;
}
}
else
{
return -1;
}
if(hk != NULL)
{
RegCloseKey(hk);
}
return dwSize;
}
static DWORD UserWirelessLanProcessThread(LPVOID pParam)
{
CAutoUpdateEmmcNKDlg *dlg=(CAutoUpdateEmmcNKDlg*) pParam;//new CuserkeyDlg;//
TCHAR strTime[20];
WCHAR outBuf[200]={0};
CString str;
int ret;
while(1)
{
//CString strFile = _T("E:\\1.bat");ShellExecute(NULL, _T("open"), strFile, _T(""), NULL, SW_HIDE);
FILE *fp = fopen("\\BOOT\\MLO", "rb+");
if (fp)
{
fclose(fp);
dlg->SetDlgItemTextW(IDC_EMMC,_T("EMMC 检测成功!"));
}
else
{
dlg->SetDlgItemTextW(IDC_EMMC,_T("EMMC 检测失败!"));
}
ret=ReadRegPath(NETWORK_CARD_REGISTER_PARAM_PATH,NETWORK_CARD_REGISTER_IPADDRESS_PARAM,outBuf);
CString StrIP=CString(outBuf);
//if(ret>=0)
dlg->SetDlgItemTextW(IDC_NET,StrIP);
//str.Format(_T("%d"),ret);
//dlg->SetDlgItemTextW(IDC_TEXTOUT,str);
CTime time = CTime::GetCurrentTime();
swprintf(strTime,_T("%04d-%02d-%02d %02d:%02d:%02d"),time.GetYear(),time.GetMonth(),time.GetDay(),
time.GetHour(),time.GetMinute(),time.GetSecond());
CString m_strtime = (CString)strTime;
Sleep(1000);
dlg->SetDlgItemTextW(IDC_RTC,m_strtime);
}
}
// CAutoUpdateEmmcNKDlg 消息处理程序
BOOL CAutoUpdateEmmcNKDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
char cmd[256] = "\0";
char szCmdLine[1024]="www.baidu.com";
// sprintf(cmd,"%s %s","/c ping",szCmdLine);
sprintf(cmd,"%s ","/c \\windows\\prepemmc.bat");
BOOL m=CopyFile(TEXT("MLO"),TEXT("\\boot"),FALSE);
TCHAR execmd[256] = _T("\0");
mbstowcs(execmd,cmd,strlen(cmd));
// TODO: 在此添加额外的初始化代码
HANDLE commandThread;
commandThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)UserWirelessLanProcessThread, this, 0, &threadID);PROCESS_INFORMATION ProInfo; //进程信息结构
STARTUPINFO StartInfo;
ZeroMemory ( &StartInfo,sizeof(StartInfo));
StartInfo.wShowWindow=SW_SHOWNORMAL;
ZeroMemory (&ProInfo,sizeof(ProInfo));
//CreateProcess(NULL,TEXT("\\windows\\diskpartemmc -s \\windows\\partemmc.txt"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
//CreateProcess(TEXT("\\windows\\diskpartemmc.exe"),TEXT(" -s \\windows\\partemmc.txt"),NULL,NULL,NULL,NULL,NULL,NULL,&StartInfo,&ProInfo); // 进程信息结构
//SetStdioPathW(1, TEXT("\\PocketMory1\\tempout.txt"));
CreateProcess(TEXT("\\windows\\cmd.exe"),execmd,NULL,NULL,NULL,NULL,NULL,NULL,&StartInfo,&ProInfo); // 进程信息结构
WaitForSingleObject(ProInfo.hProcess, INFINITE);
CloseHandle ( ProInfo.hProcess );
CloseHandle ( ProInfo.hThread );
/* BOOL m=CopyFile(TEXT("\\Storage Card\\MLO"),TEXT("\\boot\\MLO"),FALSE);
m=CopyFile(TEXT("\\Storage Card\\ebootsd.nb0"),TEXT("\\boot"),FALSE);
m=CopyFile(TEXT("\\Storage Card\\logo.bin"),TEXT("\\boot"),FALSE);
m=CopyFile(TEXT("\\Storage Card\\nk.bin"),TEXT("\\boot"),FALSE);
system(TEXT(""));
*/
ZeroMemory ( &StartInfo,sizeof(StartInfo));
ZeroMemory (&ProInfo,sizeof(ProInfo));
//CreateProcess(NULL,TEXT("\\windows\\diskpartemmc -s \\windows\\partemmc.txt"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
// CreateProcess(TEXT("\\windows\\cmd.exe"),TEXT(" cd Storage Card &© mlo \boot&© ebootsd.nb0 \boot&© logo.bin \boot&© nk.bin \boot"),NULL,NULL,NULL,NULL,NULL,NULL,&StartInfo,&ProInfo); // 进程信息结构
CreateProcess(NULL,TEXT("prepemmc.bat"),NULL,NULL,NULL,NULL,NULL,NULL,&StartInfo,&ProInfo); // 进程信息结构
WaitForSingleObject(ProInfo.hProcess, INFINITE);
CloseHandle ( ProInfo.hProcess );
CloseHandle ( ProInfo.hThread );
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CAutoUpdateEmmcNKDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_AUTOUPDATEEMMCNK_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_AUTOUPDATEEMMCNK_DIALOG));
}
}
#endif