⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elynxinstalldlg.cpp

📁 Wince下通过ndisuio使用wifi卡的示例. Wince下通过ndisuio使用wifi卡的示例
💻 CPP
字号:
// eLynxInstallDlg.cpp : implementation file
//

#include "stdafx.h"
#include "eLynxInstall.h"
#include "eLynxInstallDlg.h"
#include <TlHelp32.h>
#include <ShellAPI.h>

#pragma comment(lib, "Toolhelp.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CeLynxInstallDlg dialog

CeLynxInstallDlg::CeLynxInstallDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CeLynxInstallDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CeLynxInstallDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT1, m_display);
}

BEGIN_MESSAGE_MAP(CeLynxInstallDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
	ON_WM_SIZE()
#endif
	//}}AFX_MSG_MAP
    ON_BN_CLICKED(IDC_BUTTON1, &CeLynxInstallDlg::OnBnClickedButton1)
END_MESSAGE_MAP()

// CeLynxInstallDlg message handlers
BOOL CeLynxInstallDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CeLynxInstallDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
	if (AfxIsDRAEnabled())
	{
		DRA::RelayoutDialog(
			AfxGetResourceHandle(), 
			this->m_hWnd, 
			MAKEINTRESOURCE(IDD_ELYNXINSTALL_DIALOG));
	}
}
#endif

//////////////////////////////////////////////////////////////
//
void CeLynxInstallDlg::OnBnClickedButton1()
{

    // 1. Check & install .NET Compact Framework
    if(CheckNETFramework() == false) {
        AppendText(L"Install .NET Framework... ");
        if(InstallCAB(L"NETCFv2.ppc.armv4.cab", 60)) {
            AppendText(L"    [OK]\r\n");
        } else {
            AppendText(L"    [FAILED]\r\n");
        }
    }

    // 2. Install DataWedge
    AppendText(L"Install DateWedge...    [OK]\r\n");
    InstallDataWedge();

    // 3. Install eLynx
    AppendText(L"Install eLynx ...");
    if(InstallCAB(L"eLynx.cab", 60)) {
        AppendText(L"    [OK]\r\n");
    } else {
        AppendText(L"    [FAILED]\r\n");
    }

    // 4. Install language packages
    AppendText(L"Install translations ...");
    
    TCHAR lpSource[2 * MAX_PATH + 1];
    GetCurrentPath(lpSource);
    wcscat(lpSource, L"\\translations");

    std::wstring source(lpSource);
    std::wstring dest(L"\\Program Files\\eLynx\\translations");

    CopyDirectories(source, dest);

    AppendText(L"    [OK]\r\n");    
}

bool CeLynxInstallDlg::CheckNETFramework()
{
    // Check .NET Framework installation
    AppendText(_T("Check .NET Framework... "));

    HKEY hKey;
    if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\.NETCompactFramework"), NULL, NULL, &hKey)) {
        return false;
    }

    bool versionOK = false;
    int i = 0;
    TCHAR verName[1024];
    DWORD size = sizeof(verName);
    while(RegEnumValue(hKey, i++, verName, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
        if(wcsncmp(verName, _T("2.0"), 3) == 0) {
            versionOK = true;
            AppendText(verName);
        }
    }
    RegCloseKey(hKey);

    if(versionOK) {
        AppendText(_T("    [OK]"));
    } else {
        AppendText(_T("    [FAILED]"));
    }

    AppendText(_T("\r\n"));
    return versionOK;
}
    
// Install CAB
// lpszFile - the CAB file to be installed.
// timeout - Seconds to wait the installation to complete before timeout.
bool CeLynxInstallDlg::InstallCAB(LPCTSTR lpszFile, int timeout)
{
    TCHAR lpFolderName[MAX_PATH + 1];
    GetCurrentPath(lpFolderName);

    std::wstring cmdLine;
    cmdLine = L"/delete 0 \"" + std::wstring(lpFolderName) + std::wstring(lpszFile) + L"\"";
    LPCWSTR cmdtemp = cmdLine.c_str();

    // Run the installer process
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);

    // Create installer process
    if(!CreateProcessW(L"\\Windows\\wceload.exe", cmdtemp, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) {
        return false;
    }

    // Wait until the installation complete
    DWORD exitCode = STILL_ACTIVE;
    while(timeout > 0) {
        Sleep(1000);
        GetExitCodeProcess(pi.hProcess, &exitCode);
        if(STILL_ACTIVE != exitCode) break;
    }

    return timeout != 0;
}
    
// Install DataWedge software
bool CeLynxInstallDlg::InstallDataWedge()
{
    // Create startup shotcut
    SHCreateShortcut(L"\\Windows\\Startup\\DataWedge.lnk", L"\\Windows\\DataWedge.exe");

    // Copy DataWedge to Winodws directory
    TCHAR wsFile[2 * MAX_PATH + 1];
    GetCurrentPath(wsFile);
    wcscat(wsFile, L"DataWedge.exe");
    CopyFile(wsFile, L"\\Windows\\DataWedge.exe", FALSE);

    // Create DataWedge Process
    if(!FindProcess(L"DataWedge.exe")){
        AppendText(L"Start DataWedge ...");

        PROCESS_INFORMATION pi;
        STARTUPINFO si;
        memset(&si, 0, sizeof(si));
        si.cb = sizeof(si);

        if(!CreateProcessW(L"\\Windows\\DataWedge.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
            AppendText(L"    [FAILED]\r\n");
        } else {
            AppendText(L"    [OK]\r\n");
        }
    }
    return true;
}
    
void CeLynxInstallDlg::AppendText(LPCTSTR lpszMsg)
{
    m_display.SetSel(-1,-1);
    m_display.ReplaceSel(lpszMsg);
}

// Get current running application path
void CeLynxInstallDlg::GetCurrentPath(LPTSTR OUT lpszPath)
{
    using namespace std;

    TCHAR lpFolderName[MAX_PATH + 1] = L"";

    GetModuleFileName(NULL, lpFolderName, sizeof(lpFolderName));

    wstring str(lpFolderName);
    wstring::size_type index;
    index = str.find_last_of(L"\\", str.length()-1);
    wstring path_str = str.substr(0, index);
    LPCTSTR path = (path_str + L"\\").c_str();
    // Copy the path back to buffer
    wcscpy(lpszPath, path);
}
    
// Find a running process according process name
bool CeLynxInstallDlg::FindProcess(LPCTSTR lpszProcessName)
{
    HANDLE hSnapshot;
    PROCESSENTRY32 procEntry;
    if(INVALID_HANDLE_VALUE == (hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0))) {
        return false;
    }

    memset(&procEntry, 0, sizeof(PROCESSENTRY32));
    procEntry.dwSize = sizeof(PROCESSENTRY32);
    BOOL bRet = Process32First(hSnapshot, &procEntry);
    while(bRet)
    {
        std::wstring processName(procEntry.szExeFile);
        
        if(std::wstring::npos != processName.find(lpszProcessName)) {
            return true;
        }

        bRet = Process32Next(hSnapshot, &procEntry);
    }
    CloseToolhelp32Snapshot(hSnapshot);

    return false;
}
    
// Copy files between two folders, this includes their sub-folders
void CeLynxInstallDlg::CopyDirectories(const std::wstring& source, const std::wstring& dest)
{
    using namespace std;

    WIN32_FIND_DATA fd;

    LPCTSTR sourceFiles = (source + L"\\*").c_str();

    HANDLE hFind = FindFirstFile(sourceFiles, &fd);

    // Create dest directory if the source directory is not empty
    if(INVALID_HANDLE_VALUE != hFind) {
        CreateDirectory(dest.c_str(), NULL);
    } else {
        return;
    }

    // Copy files between two folders and call CopyDirectories for folders.
    do{
        wstring mySource = source + L"\\" + fd.cFileName;
        wstring myDest = dest + L"\\" + fd.cFileName;

        if((FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes) == fd.dwFileAttributes) {
            CopyDirectories(mySource, myDest);
        } else {
            CopyFile(mySource.c_str(), myDest.c_str(), FALSE);
        }
    }while(FindNextFile(hFind, &fd));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -