convert utf8

This commit is contained in:
2026-10-13 11:20:08 +08:00
parent e73ef3aac0
commit bd3861f7e0
8 changed files with 61 additions and 60 deletions
+41 -41
View File
@@ -1,4 +1,4 @@
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#include <System.Hash.hpp>
#include <System.IOUtils.hpp>
@@ -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; i<count && !Terminated; i++ ){
if( m_hWnd ){
strProg1 = L"文件数 " + IntToStr( i ) + L"/" + IntToStr( count );
strProg1 = L"文件数 " + IntToStr( i ) + L"/" + IntToStr( count );
SendMessage( m_hWnd, UM_SHOWTEXT, 1, (LPARAM)strProg1.c_str() );
int pos = (int)( i*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() );
}
@@ -298,7 +298,7 @@ void __fastcall TUpgradeThread::Execute()
}
else{
if( m_hWnd ){
strText = "未发现需要更新的文件";
strText = "未发现需要更新的文件";
SendMessage( m_hWnd, UM_SHOWTEXT, 0, (LPARAM)strText.c_str() );
}
}
@@ -320,7 +320,7 @@ bool __fastcall TUpgradeThread::MakeMD5File()
String strText, strProg1, strProg2;
if( m_hWnd ){
strText = "正在生成MD5校验文件";
strText = "正在生成MD5校验文件";
SendMessage( m_hWnd, UM_SHOWTEXT, 0, (LPARAM)strText.c_str() );
}
@@ -333,14 +333,14 @@ bool __fastcall TUpgradeThread::MakeMD5File()
if( fp ){
for( int i=0; i<m_lstFile->Count && !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 );