123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- // DownloadShell.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "DownloadShell.h"
- #include "DownloadShellDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- int fun(CONST TCHAR* lpCurrentDirecotry)
- {
- INT nRet = 0;
- TCHAR szFile[MAX_PATH] = { 0 };
- sprintf(szFile, _T("%s\\DownloadTool.exe"), lpCurrentDirecotry);
- nRet = UpdateFile(DownloadTool, _T("EXE"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\gpsvc.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(gpsvc, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\ieshims.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(ieshims, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\libapr-1.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(libapr1, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\libaprutil-1.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(libaprutil1, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\libcurl.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(libcurl, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\libeay32.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(libeay32, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\MSVCP71.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(MSVCP71, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\msvcr71.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(msvcr71, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\mxml1.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(mxml1, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\ssleay32.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(ssleay32, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- sprintf(szFile, _T("%s\\zlib1.dll"), lpCurrentDirecotry);
- nRet = UpdateFile(zlib1, _T("DLL"), szFile);
- if (nRet != 0)
- return nRet;
- return 0;
- }
- /************************************************************************/
- /* 函数:[1/26/2018 Jeff];
- /* 描述:删除自己;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:使用_pgmptr与使用GetModuleFileName(NULL, szExePath, MAX_PATH);来得到程序的路径是等效的。但是,绝对要加上""双引号后才能作参数传给批处理程序,不然会出错。;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void DeleteApplicationSelf()
- {
- TCHAR szCommandLine[MAX_PATH + 10];
- //_pgmptr;
- //TCHAR *pModel;
- //_get_pgmptr(&pModel);
- //设置本程序进程基本为实时执行,快速退出。
- SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
- //通知资源管理器不显示本程序,当然如果程序没有真正的删除,刷新资源管理器后仍会显示出来的。
- SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, _pgmptr, NULL);
- //调用cmd传入参数以删除自己
- TCHAR szFilePath[MAX_PATH];
- sprintf(szFilePath, _T("\"%s\""), _pgmptr);
- sprintf(szCommandLine, _T("/c del /q %s"), szFilePath);
- ShellExecute(NULL, "open", "cmd.exe", szCommandLine, NULL, SW_HIDE);
- // 这里不用再退出进程;
- //ExitProcess(0);
- }
- // CDownloadShellApp 初始化
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadShellApp
- BEGIN_MESSAGE_MAP(CDownloadShellApp, CWinApp)
- //{{AFX_MSG_MAP(CDownloadShellApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadShellApp construction
- CDownloadShellApp::CDownloadShellApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CDownloadShellApp object
- CDownloadShellApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadShellApp initialization
- BOOL CDownloadShellApp::InitInstance()
- {
- AfxEnableControlContainer();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- // 获取当前目录;
- TCHAR szCurrentDirectory[MAX_PATH] = { 0 };
- DWORD dwRet = GetCurrentDirectory(MAX_PATH, szCurrentDirectory);
- if (dwRet == 0 || dwRet > MAX_PATH)
- return FALSE;
- // 获取文件名;
- TCHAR szExeName[MAX_PATH] = {0};
- _splitpath(_pgmptr, NULL, NULL, szExeName, NULL);
- CString strTaskInfo = szExeName;
- #ifdef _DEBUG
- strTaskInfo = "DownloadShell#CAEE47E897AA4728F710627B386394C3#E81011415491848821#";
- #endif
- int nStart = strTaskInfo.Find("#") + 1;
- int nEndof = strTaskInfo.ReverseFind('#');
- strTaskInfo = strTaskInfo.Mid(nStart, nEndof - nStart);
-
- // 创建TaskInfo文件;
- sprintf(szExeName, "%s\\task.Info", szCurrentDirectory);
- CFile cf;
- if ( cf.Open(szExeName, CFile::modeCreate|CFile::modeWrite))
- {
- cf.Write(strTaskInfo, strTaskInfo.GetLength());
- cf.Close();
- }
- if (fun(szCurrentDirectory) != 0)
- {
- MessageBox(NULL, _T("文件错误,无法运行"), _T("错误"), MB_ICONERROR);
- return FALSE;
- }
-
- TCHAR szFile[MAX_PATH] = { 0 };
- sprintf(szFile, _T("%s\\DownloadTool.exe"), szCurrentDirectory);
- if (PathFileExists(szFile))
- {
- // 运行程序;
- if (WinExec(szFile, SW_SHOWNORMAL) > 31)
- {// 运行成功;
- DeleteApplicationSelf();
- return FALSE;
- }
- }
- CDownloadShellDlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- // TODO: Place code here to handle when the dialog is
- // dismissed with OK
- }
- else if (nResponse == IDCANCEL)
- {
- // TODO: Place code here to handle when the dialog is
- // dismissed with Cancel
- }
- // Since the dialog has been closed, return FALSE so that we exit the
- // application, rather than start the application's message pump.
- return FALSE;
- }
|