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

📄 mpdupdatedlg.cpp

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	    TerminateProcess(hProcess, -1);	    break;	}	if (num_read > 5)	    break;    }    CloseHandle(hIn);    CloseHandle(hOut);    CloseHandle(hErr);    if (WaitForSingleObject(hProcess, 1000) == WAIT_TIMEOUT)	TerminateProcess(hProcess, -1);    CloseHandle(hProcess);    version = mpd_version_string_to_int(line);    return (version != 0);}/*bool GetLocalVersion(const char *filename, unsigned int &version){    void (*pGetMPDVersion)(char *str, int length);    PROCESS_INFORMATION pInfo;    STARTUPINFO sInfo;    int error;    char err_msg[1024];    char version_str[100];    GetStartupInfo(&sInfo);    if (!CreateProcess(filename, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &sInfo, &pInfo))	return GetLocalVersionFromRun(filename, version);    OpenProcess(all, no, id);    pGetMPDVersion = (void (*)(char *, int))GetProcAddress((HINSTANCE)pInfo.hProcess, "GetMPDVersion");    if (pGetMPDVersion == NULL)    {	error = GetLastError();	// try to get the version by running "mpd -version"	if (!GetLocalVersionFromRun(filename, version))	{	    Translate_Error(error, err_msg, "GetProcAddress(\"GetMPDVersion\") failed, ");	    MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	    version = 0;	    return false;	}    }    else    {	pGetMPDVersion(version_str, 100);	//printf("%s\n", version);	version = mpd_version_string_to_int(version_str);    }    TerminateProcess(pInfo.hProcess, 0);    CloseHandle(pInfo.hProcess);    CloseHandle(pInfo.hThread);    return true;}*//*bool GetLocalVersion(const char *filename, unsigned int &version){    void (*pGetMPDVersion)(char *str, int length);    HMODULE hModule;    char err_msg[1024];    int error;    char version_str[100] = "";    hModule = LoadLibrary(filename);    if (hModule == NULL)    {	Translate_Error(GetLastError(), err_msg, "LoadLibrary(mpd.exe) failed, ");	MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	version = 0;	return false;    }    pGetMPDVersion = (void (*)(char *, int))GetProcAddress(hModule, "GetMPDVersion");    if (pGetMPDVersion == NULL)    {	error = GetLastError();	FreeLibrary(hModule);	// try to get the version by running "mpd -version"	if (!GetLocalVersionFromRun(filename, version))	{	    Translate_Error(error, err_msg, "GetProcAddress(\"GetMPDVersion\") failed, ");	    MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	    version = 0;	    return false;	}    }    else    {	pGetMPDVersion(version_str, 100);	//printf("%s\n", version);	FreeLibrary(hModule);	version = mpd_version_string_to_int(version_str);    }    return true;}*//*bool GetLocalVersion(const char *filename, unsigned int &version){    void (*pGetMPDVersionFoo)(int (* function)(char *, size_t, const char *, ...), char *str, int length);    HMODULE hModule;    char err_msg[1024];    int error;    char version_str[100] = "";    hModule = LoadLibrary(filename);    if (hModule == NULL)    {	Translate_Error(GetLastError(), err_msg, "LoadLibrary(mpd.exe) failed, ");	MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	version = 0;	return false;    }    pGetMPDVersionFoo = (void (*)(int (*)(char *, size_t, const char *, ...), char *, int))GetProcAddress(hModule, "GetMPDVersionFoo");    if (pGetMPDVersionFoo == NULL)    {	error = GetLastError();	FreeLibrary(hModule);	// try to get the version by running "mpd -version"	if (!GetLocalVersionFromRun(filename, version))	{	    Translate_Error(error, err_msg, "GetProcAddress(\"GetMPDVersionFoo\") failed, ");	    MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	    version = 0;	    return false;	}    }    else    {	pGetMPDVersionFoo(_snprintf, version_str, 100);	//printf("%s\n", version);	FreeLibrary(hModule);	version = mpd_version_string_to_int(version_str);    }    return true;}*/bool GetLocalVersion(const char *filename, unsigned int &version){    int *pRelease;    int *pMajor;    int *pMinor;    char *pDate;    HMODULE hModule;    char err_msg[1024];    int error;    char version_str[100] = "";    hModule = LoadLibrary(filename);    if (hModule == NULL)    {	Translate_Error(GetLastError(), err_msg, "LoadLibrary(mpd.exe) failed, ");	MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	version = 0;	return false;    }    pRelease = (int*)GetProcAddress(hModule, "mpdVersionRelease");    pMajor = (int*)GetProcAddress(hModule, "mpdVersionMajor");    pMinor = (int*)GetProcAddress(hModule, "mpdVersionMinor");    pDate = (char*)GetProcAddress(hModule, "mpdVersionDate");    if (pRelease == NULL || pMajor == NULL || pMinor == NULL || pDate == NULL)    {	error = GetLastError();	FreeLibrary(hModule);	// try to get the version by running "mpd -version"	if (!GetLocalVersionFromRun(filename, version))	{	    Translate_Error(error, err_msg, "GetProcAddress(\"mpdVersion...\") failed, ");	    MessageBox(NULL, err_msg, "Error in GetLocalVersion", MB_OK);	    version = 0;	    return false;	}    }    else    {	_snprintf(version_str, 100, "%d.%d.%d %s", *pRelease, *pMajor, *pMinor, pDate);	//printf("%s\n", version);	FreeLibrary(hModule);	version = mpd_version_string_to_int(version_str);    }    return true;}void CMPDUpdateDlg::OnUpdateOneBtn() {    SOCKET sock;    CString sHost;    int num_hosts;    bool bDeleteTmpMpd = false;    bool bDeleteTmpMPICH = false;    unsigned int version_new, version_old;    UpdateData();    m_results = "";    UpdateData(FALSE);    num_hosts = m_host_list.GetCount();    if (num_hosts == 0)    {	MessageBox("Please add a host to the list before selecting Update");	return;    }    int index = m_host_list.GetCurSel();    if (index == LB_ERR)    {	MessageBox("Please select a host from the list before selecting Update single");	return;    }    m_host_list.GetText(index, sHost);    if (!m_bUpdateMPD && !m_bUpdateMPICH)    {	MessageBox("Please check at least one of the update boxes before selecting Update");	return;    }    if (m_bNeedPassword)    {	if (m_bUseDefault)	    strcpy(m_pszPhrase, MPD_DEFAULT_PASSPHRASE);	else	    strcpy(m_pszPhrase, m_mpd_pwd);    }    if (m_cred_account.GetLength() < 1)    {	MessageBox("Please enter the account information before selecting Update");	m_cred_account_edit.SetFocus();	return;    }    HCURSOR hOldCursor = SetCursor( LoadCursor(NULL, IDC_WAIT) );        if (m_bUpdateMPD)    {	if (m_url_radio.GetCheck())	{	    if (!GetTmpMpdFromURL())	    {		SetCursor(hOldCursor);		if (m_bShowHostConfig)		    GetHostConfig(NULL);		m_results.Format("%s: failure", sHost);		UpdateData(FALSE);		return;	    }	    bDeleteTmpMpd = true;	}		if (!m_bForceUpdate)	{	    if (!GetLocalVersion(m_url_radio.GetCheck() ? m_localfile : m_filename, version_new))	    {		if (bDeleteTmpMpd)		    DeleteFile(m_localfile);		SetCursor(hOldCursor);		m_results.Format("%s: failure", sHost);		UpdateData(FALSE);		MessageBox("Unable to get the version of the new mpd", "Update aborted");		return;	    }	}		if (ConnectToHost(sHost, m_mpd_port, m_pszPhrase, &sock))	{	    char pszError[256];	    char str[256], str2[256];	    	    if (!m_bForceUpdate)	    {		WriteString(sock, "version");		ReadString(sock, str);	    }	    WriteString(sock, "done");	    easy_closesocket(sock);	    	    if (!m_bForceUpdate)	    {		version_old = mpd_version_string_to_int(str);		mpd_version_int_to_string(version_old, str);		mpd_version_int_to_string(version_new, str2);	    }	    if (m_bForceUpdate || (version_old < version_new))	    {		if (UpdateMPD(sHost, m_cred_account, m_cred_password, m_mpd_port, m_pszPhrase, 		    m_url_radio.GetCheck() ? m_localfile : m_filename, pszError, 256))		{		    m_results.Format("%s: success", sHost);		    UpdateData(FALSE);		}		else		{		    m_results.Format("%s: failure, %s", sHost, pszError);		    UpdateData(FALSE);		    MessageBox(pszError, "Unable to update mpd");		}	    }	    else	    {		CString s;		if (version_old == version_new)		{		    s.Format("Version <%s> is already installed on %s", str, sHost);		    MessageBox(s, "Update aborted");		}		else		{		    s.Format("Version <%s> on %s is newer than version <%s>", str, sHost, str2);		    MessageBox(s, "Update aborted");		}		m_results.Format("%s: no action\r\n%s", sHost, s);		UpdateData(FALSE);	    }	}	else	{	    CString str;	    str.Format("Connect to mpd on %s failed", sHost);	    m_results.Format("%s: failure", sHost);	    UpdateData(FALSE);	    MessageBox(str, "Unable to update mpd");	}		if (bDeleteTmpMpd)	{	    DeleteFile(m_localfile);	}    }    if (m_bUpdateMPICH)    {	if (m_mpich_url_radio.GetCheck())	{	    if (!GetTmpMPICHFromURL())	    {		SetCursor(hOldCursor);		if (m_bShowHostConfig)		    GetHostConfig(NULL);		m_results.Format("%s: failure", sHost);		UpdateData(FALSE);		return;	    }	    bDeleteTmpMPICH = true;	}		if (!m_bForceUpdate)	{	    if (!GetLocalMPICHVersion(m_mpich_url_radio.GetCheck() ? m_mpich_localfile : m_mpich_filename, version_new))	    {		if (bDeleteTmpMPICH)		{		    DeleteFile(m_mpich_localfile);		    DeleteFile(m_mpich_localfiled);		}		SetCursor(hOldCursor);		m_results.Format("%s: failure", sHost);		UpdateData(FALSE);		MessageBox("Unable to get the version of the new mpich dlls", "Update aborted");		return;	    }	}		if (ConnectToHost(sHost, m_mpd_port, m_pszPhrase, &sock))	{	    char pszError[256];	    char str[256] = "", str2[256];	    	    if (!m_bForceUpdate)	    {		WriteString(sock, "mpich version");		if (!ReadStringTimeout(sock, str, MPD_SHORT_TIMEOUT))		{		    MessageBox("MPD is unable to update the mpich dlls, please update mpd before attempting to update the mpich dlls", "Error");		    WriteString(sock, "done");		    easy_closesocket(sock);		    return;		}	    }	    WriteString(sock, "done");	    easy_closesocket(sock);	    	    if (!m_bForceUpdate)	    {		version_old = mpd_version_string_to_int(str);		mpd_version_int_to_string(version_old, str);		mpd_version_int_to_string(version_new, str2);	    }	    if (m_bForceUpdate || (version_old < version_new))	    {		if (UpdateMPICH(sHost, m_cred_account, m_cred_password, m_mpd_port, m_pszPhrase, 		    m_mpich_url_radio.GetCheck() ? m_mpich_localfile : m_mpich_filename, 		    m_mpich_url_radio.GetCheck() ? m_mpich_localfiled : m_mpich_filenamed, 		    pszError, 256))		{		    m_results.Format("%s: success", sHost);		    UpdateData(FALSE);		}		else		{		    m_results.Format("%s: failure, %s", sHost, pszError);		    UpdateData(FALSE);		    MessageBox(pszError, "Unable to update the mpich dlls");		}	    }	    else	    {		CString s;		if (version_old == version_new)		{		    s.Format("Version <%s> is already installed on %s", str, sHost);		    MessageBox(s, "Update aborted");		}		else		{		    s.Format("Version <%s> on %s is newer than version <%s>", str, sHost, str2);		    MessageBox(s, "Update aborted");		}		m_results.Format("%s: no action\r\n%s", sHost, s);		UpdateData(FALSE);	    }	}	else	{	    CString str;	    str.Format("Connect to mpd on %s failed", sHost);	    m_results.Format("%s: failure", sHost);	    UpdateData(FALSE);	    MessageBox(str, "Unable to update the mpich dlls");	}		if (bDeleteTmpMPICH)	{	    DeleteFile(m_mpich_localfile);	    DeleteFile(m_mpich_localfiled);	}    }    SetCursor(hOldCursor);    if (m_bShowHostConfig)	GetHostConfig(NULL);}LRESULT CMPDUpdateDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {    if (message == WM_USER + 2)    {	GetHostConfig(NULL);    }    if (message == WM_USER + 3)    {	m_update_btn.EnableWindow(FALSE);	m_update_one_btn.EnableWindow(FALSE);	m_edit_add_btn.EnableWindow(FALSE);	m_select_btn.EnableWindow(FALSE);    }    if (message == WM_USER + 4)    {	m_update_btn.EnableWindow();	m_update_one_btn.EnableWindow();	m_edit_add_btn.EnableWindow();	m_select_btn.EnableWindow();    }    if (message == WM_USER + 5)    {	UpdateData(FALSE);    }    return CDialog::WindowProc(message, wParam, lParam);}void CMPDUpdateDlg::OnEditAddBtn() {    // Add hostname to host list    UpdateData();        if (m_hostname.GetLength() != 0)    {		CString str;	int n = m_host_list.GetCount();	if (n != LB_ERR)	{	    bool bFound = false;	    for (int i=0; i<n; i++)	    {		m_host_list.GetText(i, str);		if (str.CompareNoCase(m_hostname) == 0)		{		    bFound = true;		    //break;		}	    }

⌨️ 快捷键说明

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