diff --git a/.gitignore b/.gitignore index 74b79ad..7180793 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ __recovery/ *.~dsk *.cbpr *.local -*.rc \ No newline at end of file +*.rc +*.dsv \ No newline at end of file diff --git a/AppUpgrade.cbproj b/AppUpgrade.cbproj index b66a326..98e8f3f 100644 --- a/AppUpgrade.cbproj +++ b/AppUpgrade.cbproj @@ -1,7 +1,7 @@  {4FDA74F8-059D-4F68-A028-A088D015B63F} - 20.4 + 20.5 VCL Application AppUpgrade.cpp diff --git a/AppUpgrade.cpp b/AppUpgrade.cpp index 4e026db..3606c6d 100644 --- a/AppUpgrade.cpp +++ b/AppUpgrade.cpp @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- #include #include @@ -15,9 +15,9 @@ String MAIN_APP_NAME; BOOL ImprovePrivilege() { HANDLE token; - //ÌáÉýȨÏÞ + //æ��å�‡æ�ƒé™� if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&token)){ - MessageBox(NULL,L"´ò¿ª½ø³ÌÁîÅÆÊ§°Ü...",L"´íÎó",MB_ICONSTOP); + MessageBox(NULL,L"打开进程令牌失败...",L"错误",MB_ICONSTOP); return FALSE; } @@ -28,7 +28,7 @@ BOOL ImprovePrivilege() tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(token,FALSE,&tkp,sizeof(tkp),NULL,NULL)){ - MessageBox(NULL,L"µ÷ÕûÁîÅÆÈ¨ÏÞʧ°Ü...",L"´íÎó",MB_ICONSTOP); + MessageBox(NULL,L"调整令牌æ�ƒé™�失败...",L"错误",MB_ICONSTOP); bRet = FALSE; } diff --git a/UpgradeThread.cpp b/UpgradeThread.cpp index 3d7b1db..96538f4 100644 --- a/UpgradeThread.cpp +++ b/UpgradeThread.cpp @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- #include #include #include @@ -88,18 +88,18 @@ DWORD WINAPI GetUrlProc(LPVOID args) ZeroMemory(szBuffer, sizeof(szBuffer)); ZeroMemory(param->dataOut, param->sizeOut); - // Ñ­»·¶ÁÈ¡»º³åÇøÄÚÈÝÖ±µ½½áÊø + // 循环读å�–缓冲区内容直到结æ�Ÿ while( InternetReadFile(param->hRequest, szBuffer, sizeof(szBuffer), &dwByteRead) && dwByteRead > 0){ if( pos + dwByteRead > param->sizeOut ){ param->errCode = ERROR_SIZE; break; } - // ¸´ÖÆÊä³öÊý¾Ý + // å¤�制输出数æ�® memcpy( param->dataOut+pos, szBuffer, dwByteRead ); pos += dwByteRead; - // Çå¿Õ»º³åÇøÒÔ±¸ÏÂÒ»´Î¶ÁÈ¡ + // 清空缓冲区以备下一次读å�– ZeroMemory(szBuffer, sizeof(szBuffer)); } @@ -140,18 +140,18 @@ DWORD WINAPI DownloadProc(LPVOID args) ZeroMemory(szBuffer, sizeof(szBuffer)); - // Ñ­»·¶ÁÈ¡»º³åÇøÄÚÈÝÖ±µ½½áÊø + // 循环读å�–缓冲区内容直到结æ�Ÿ while (InternetReadFile(param->hRequest, szBuffer, sizeof(szBuffer), &dwByteRead) && dwByteRead > 0){ fwrite( szBuffer, 1, dwByteRead, fp ); if( param->hWnd ){ - //ÏÔʾ½ø¶È + //显示进度 dwReceived += dwByteRead; int pos = (int)( dwReceived * 100.0 / dwAllBytes + 0.5 ); SendMessage( param->hWnd, UM_PROGRESS, 1, pos ); } - // Çå¿Õ»º³åÇøÒÔ±¸ÏÂÒ»´Î¶ÁÈ¡ + // 清空缓冲区以备下一次读å�– ZeroMemory(szBuffer, sizeof(szBuffer)); } @@ -207,11 +207,11 @@ void __fastcall TUpgradeThread::Cancel() void __fastcall TUpgradeThread::Execute() { int ret = 0; - //»ñÈ¡ÁбíÎļþ - //¶Ô±ÈÎļþMD5Âë=>¸üÐÂÁбí - //ÏÂÔØ¸üÐÂÁбíÖеÄÎļþ + //获å�–列表文件 + //对比文件MD5ç �=>更新列表 + //下载更新列表中的文件 if( m_iMode==3 ){ - Sleep(1000); //µÈ´ýappÍêÈ«Í˳ö + Sleep(1000); //等待app完全退出 if( UpdateFiles() ){ RegUpdateFlag( 0 ); RestartApp(); @@ -222,26 +222,26 @@ void __fastcall TUpgradeThread::Execute() } else{ String strText, strProg1, strProg2; - //Çå¿ÕĿ¼ + //清空目录 ClearUpdateDir(); Randomize(); if( m_hWnd ){ - strText = "ÕýÔÚ»ñÈ¡¸üÐÂÁбí"; + strText = "正在获å�–更新列表"; SendMessage( m_hWnd, UM_SHOWTEXT, 0, (LPARAM)strText.c_str() ); - strProg1 = L"¡ª¡ª"; + strProg1 = L"——"; SendMessage( m_hWnd, UM_SHOWTEXT, 1, (LPARAM)strProg1.c_str() ); - strProg2 = L"ÕýÔÚÏÂÔØÁбíÎļþ"; + strProg2 = L"正在下载列表文件"; SendMessage( m_hWnd, UM_SHOWTEXT, 2, (LPARAM)strProg2.c_str() ); } String umdfile = GetUpdateMD5File(); if( umdfile.Length()>0 && !Terminated ){ if( m_hWnd ){ - strText = "ÕýÔÚ¼ì²é¸üÐÂÁбí"; + strText = "正在检查更新列表"; SendMessage( m_hWnd, UM_SHOWTEXT, 0, (LPARAM)strText.c_str() ); } @@ -251,19 +251,19 @@ void __fastcall TUpgradeThread::Execute() int count = ufnLst->Count; if( count > 0 ){ if( m_hWnd ){ - strText = "ÕýÔÚÏÂÔØ¸üÐÂÎļþ"; + strText = "正在下载更新文件"; SendMessage( m_hWnd, UM_SHOWTEXT, 0, (LPARAM)strText.c_str() ); } for( int i=0; iCount && !Terminated; i++ ){ if( m_hWnd ){ - strProg1 = L"ÎļþÊý " + IntToStr( i ) + strProg1 = L"文件数 " + IntToStr( i ) + L"/" + IntToStr( m_lstFile->Count ); SendMessage( m_hWnd, UM_SHOWTEXT, 1, (LPARAM)strProg1.c_str() ); int pos = (int)( i*100.0/m_lstFile->Count + 0.5 ); SendMessage( m_hWnd, UM_PROGRESS, 0, pos ); - strProg2 = L"µ±Ç°Îļþ " + (*m_lstFile)[i]; + strProg2 = L"当å‰�文件 " + (*m_lstFile)[i]; SendMessage( m_hWnd, UM_SHOWTEXT, 2, (LPARAM)strProg2.c_str() ); } @@ -391,7 +391,7 @@ bool __fastcall TUpgradeThread::GenerateFileMD5( String fname, String& md5 ) pMD5->Update( buf, sizeBuf ); if( m_hWnd ){ - //ÏÔʾ½ø¶È + //显示进度 int pos = (int)( fs->Position * 100.0 / fs->Size + 0.5 ); SendMessage( m_hWnd, UM_PROGRESS, 1, pos ); } @@ -422,7 +422,7 @@ int __fastcall TUpgradeThread::DownloadFile( String url, String filename ) path += filename; - for( int i=0; i<3; i++ ){ //³¢ÊÔ3´Î + for( int i=0; i<3; i++ ){ //å°�试3次 TDownloadParam param; param.hWnd = m_hWnd; strcpy( param.url, ((AnsiString)url).c_str() ); @@ -442,9 +442,9 @@ int __fastcall TUpgradeThread::DownloadFile( String url, String filename ) WaitForSingleObject( hThread, 200 ); CloseHandle( hThread ); - if( dwRet==WAIT_OBJECT_0 ) //Óû§Í˳ö + if( dwRet==WAIT_OBJECT_0 ) //用户退出 break; - else if( dwRet==WAIT_OBJECT_0+1 ){ //Ïß³ÌÕý³£Í˳ö + else if( dwRet==WAIT_OBJECT_0+1 ){ //线程正常退出 if( param.errCode==0 ){ ret = 0; break; @@ -511,7 +511,7 @@ int __fastcall TUpgradeThread::GetServers( TStringList* pList ) // bool bSave = false; FILE* fp = NULL; - //¶ÁÈ¡ÎļþÅäÖà + //读å�–文件é…�ç½® fp = fopen( ((AnsiString)m_GlobalFile).c_str(), "rb" ); if( fp ){ TGVFHEADER header; @@ -586,9 +586,9 @@ String __fastcall TUpgradeThread::GetUpdateURL() WaitForSingleObject( hThread, 200 ); CloseHandle( hThread ); - if( dwRet==WAIT_OBJECT_0 ) //Óû§Í˳ö + if( dwRet==WAIT_OBJECT_0 ) //用户退出 break; - else if( dwRet==WAIT_OBJECT_0+1 && param.errCode==0 ){ //Ïß³ÌÕý³£Í˳ö + else if( dwRet==WAIT_OBJECT_0+1 && param.errCode==0 ){ //线程正常退出 if(dataOut[0]=='\"' && dataOut[param.sizeOut-1]=='\"') dataOut[param.sizeOut-1] = 0; @@ -690,13 +690,13 @@ int __fastcall TUpgradeThread::GetUpdateFileList( String ufile, TStringList* ufn int count = ufnLst->Count; for( int i=ufnLst->Count-1; i>=0; i-- ){ if( m_hWnd ){ - strProg1 = L"ÎļþÊý " + IntToStr( count-i-1 ) + L"/" + IntToStr(count); + strProg1 = L"文件数 " + IntToStr( count-i-1 ) + L"/" + IntToStr(count); SendMessage( m_hWnd, UM_SHOWTEXT, 1, (LPARAM)strProg1.c_str() ); int pos = (int)( (count-i-1)*100.0/count + 0.5 ); SendMessage( m_hWnd, UM_PROGRESS, 0, pos ); - strProg2 = L"µ±Ç°±È¶ÔÎļþ " + (*ufnLst)[i]; + strProg2 = L"当å‰�比对文件 " + (*ufnLst)[i]; SendMessage( m_hWnd, UM_SHOWTEXT, 2, (LPARAM)strProg2.c_str() ); } @@ -788,10 +788,10 @@ bool __fastcall TUpgradeThread::UpdateFiles() int iAttr = 0; String strPath = m_AppPath + L"upgrade\\"; - //ÏȹرÕÖ÷³ÌÐò + //先关闭主程åº� StopApp(); - Sleep(1000); //µÈ´ýappÍêÈ«Í˳ö + Sleep(1000); //等待app完全退出 if( FindFirst(strPath + L"*.*", iAttr, sr)==0 ){ do{ @@ -816,7 +816,7 @@ bool __fastcall TUpgradeThread::UpdateFiles() int __fastcall TUpgradeThread::RestartApp() { - //Æô¶¯Ö÷³ÌÐò + //å�¯åŠ¨ä¸»ç¨‹åº� HANDLE hToken = NULL, hTokenDup = NULL; if(OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken)){ @@ -847,31 +847,31 @@ int __fastcall TUpgradeThread::RestartApp() bool __fastcall TUpgradeThread::StopApp() { - HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS,0 ); //»ñÈ¡½ø³Ì¿ìÕÕ + HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS,0 ); //获å�–进程快照 if( hSnapshot ){ DWORD idProcess = 0; PROCESSENTRY32 pe32; pe32.dwSize = sizeof( PROCESSENTRY32 ); - if(!Process32First( hSnapshot, &pe32 )){ //Ö¸ÏòµÚÒ»¸ö½ø³Ì + if(!Process32First( hSnapshot, &pe32 )){ //指å�‘第一个进程 CloseHandle(hSnapshot); return false; } do{ - if( lstrcmpi( pe32.szExeFile, MAIN_APP_NAME.c_str() )==0 ){ //²éÕÒ½ø³Ì + if( lstrcmpi( pe32.szExeFile, MAIN_APP_NAME.c_str() )==0 ){ //查找进程 if( SameModulePath( pe32.th32ProcessID )){ idProcess = pe32.th32ProcessID; break; } } } - while( Process32Next(hSnapshot, &pe32) ); // Ñ­»·Ö±µ½È¡²»µ½½ø³Ì + while( Process32Next(hSnapshot, &pe32) ); // 循环直到å�–ä¸�到进程 if( idProcess ){ - HANDLE hApp= OpenProcess( PROCESS_ALL_ACCESS, FALSE, idProcess ); //¸ù¾Ý½ø³ÌID»ñÈ¡³ÌÐòµÄ¾ä±ú + HANDLE hApp= OpenProcess( PROCESS_ALL_ACCESS, FALSE, idProcess ); //æ ¹æ�®è¿›ç¨‹ID获å�–程åº�çš„å�¥æŸ„ if( hApp ){ - if( WaitForSingleObject( hApp, 2000 )==WAIT_TIMEOUT )// µÈ´ý³ÌÐò¹Ø±Õ2Ãë + if( WaitForSingleObject( hApp, 2000 )==WAIT_TIMEOUT )// 等待程åº�关闭2ç§’ TerminateProcess( hApp, 0 ); CloseHandle( hApp ); diff --git a/UpgradeThread.h b/UpgradeThread.h index da9cc75..7a3dc90 100644 --- a/UpgradeThread.h +++ b/UpgradeThread.h @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- #ifndef UpgradeThreadH #define UpgradeThreadH @@ -27,7 +27,7 @@ private: HWND m_hWnd; HANDLE m_hSema; TStringList* m_lstMD5; - bool m_bUpdateSelf; //ÊÇ·ñ¸üÐÂ×ÔÉí + bool m_bUpdateSelf; //是å�¦æ›´æ–°è‡ªèº« String m_AppPath, m_PathName, m_Server, diff --git a/UpgradeUnit.cpp b/UpgradeUnit.cpp index dedfa79..2168738 100644 --- a/UpgradeUnit.cpp +++ b/UpgradeUnit.cpp @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- #include #include @@ -44,10 +44,10 @@ void __fastcall TUpgradeForm::FormDestroy(TObject *Sender) void __fastcall TUpgradeForm::FormCloseQuery(TObject *Sender, bool &CanClose) { if( m_pThread ){ - String msg = m_iMode==1 ? L"ÕýÔÚ´¦ÀíÖУ¬È·ÈÏÍ˳ö³ÌÐò£¿" - : L"ÕýÔÚÉý¼¶ÖУ¬ÊÇ·ñÈ·¶¨ÖÐÖ¹£¿"; + String msg = m_iMode==1 ? L"正在处ç�†ä¸­ï¼Œç¡®è®¤é€€å‡ºç¨‹åº�?" + : L"正在å�‡çº§ä¸­ï¼Œæ˜¯å�¦ç¡®å®šä¸­æ­¢ï¼Ÿ"; - int mrRet = MessageBox(Handle, msg.c_str(), L"Í˳ö", + int mrRet = MessageBox(Handle, msg.c_str(), L"退出", MB_ICONQUESTION | MB_YESNO);; if( mrRet==mrNo ) @@ -58,8 +58,8 @@ void __fastcall TUpgradeForm::FormCloseQuery(TObject *Sender, bool &CanClose) void __fastcall TUpgradeForm::FormShow(TObject *Sender) { - Caption = m_iMode==0 ? L"×Ô¶¯Éý¼¶³ÌÐò" - : L"MD5Éú³É³ÌÐò"; + Caption = m_iMode==0 ? L"自动å�‡çº§ç¨‹åº�" + : L"MD5生æˆ�程åº�"; m_pThread = new TUpgradeThread(true, m_iMode, m_idSoft, m_sVar, Handle ); m_pThread->Start(); @@ -102,13 +102,13 @@ void __fastcall TUpgradeForm::UMComplete(TMessage &msg) if( m_iMode==0 ){ if( msg.WParam!=0 ) - ShowMessage( "±¾´Î¸üÐÂδÄÜÍê³É" ); + ShowMessage( "本次更新未能完æˆ�" ); } else if( m_iMode==1 ){ if( msg.WParam==0 ) - ShowMessage( "´¦ÀíÍê±Ï" ); + ShowMessage( "处ç�†å®Œæ¯•" ); else - ShowMessage( "Òì³£ÖÐÖ¹" ); + ShowMessage( "异常中止" ); } Close(); diff --git a/UpgradeUnit.h b/UpgradeUnit.h index f7a4f64..793b4b2 100644 --- a/UpgradeUnit.h +++ b/UpgradeUnit.h @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- #ifndef UpgradeUnitH #define UpgradeUnitH @@ -9,7 +9,7 @@ #include #include -#define APPNAME "APP×Ô¶¯Éý¼¶³ÌÐò\0" +#define APPNAME "APP自动å�‡çº§ç¨‹åº�\0" //--------------------------------------------------------------------------- class TUpgradeForm : public TForm diff --git a/res/upgrade.ico b/res/upgrade.ico new file mode 100644 index 0000000..ec55051 Binary files /dev/null and b/res/upgrade.ico differ