void cupdatedlg::onbuttondoupdate()
{
// 读取升级文件
cfilestatus rstatus;
cstring szinidata;
cstring infile;
cstring tmp;
infile=m_szpath+"//update.ini";
cfile updatefile;
updatefile.open( infile, cfile::moderead);
updatefile.getstatus(infile,rstatus);
updatefile.read(szinidata.getbuffer(rstatus.m_size),rstatus.m_size);
updatefile.close();
cstringarray artype;
cstringarray arversion;
for(int i=1;i<=27;i+=2){
afxextractsubstring(tmp,szinidata,i,'/n');
tmp.trimright();
tmp.trimright();
artype.add(tmp);
}
for(int j=2;j<=28;j+=2){
afxextractsubstring(tmp,szinidata,j,'/n');
tmp.trimright();
tmp.trimright();
arversion.add(tmp);
}
getdlgitem(idc_button_doupdate)->enablewindow(false);
cprogressctrl* pbar = (cprogressctrl*)getdlgitem(idc_progress_update);
pbar->setpos(5);
m_szeditmessage = "/r/n取得网络升级地址/r/n"+serverurl;
updatedata(false);
cinternetsession mysession(null,0);
chttpfile* myhttpfile=null;
bool bisnewer = false;
cstring mydata;
cstring myurl;
cstring m_siterec;
myurl = serverurl+"?pro=update";
myhttpfile=(chttpfile*)mysession.openurl(myurl);
while(myhttpfile->readstring(mydata)){m_siterec = mydata;}
myhttpfile->close();
mysession.close();
if(m_siterec=="ok"){
pbar->setpos(10);
m_szeditmessage = "/r/n已经连通....../r/n"+m_szeditmessage;
updatedata(false);
for(int k=0;k<14;k++){
cinternetsession mysession(null,0);
chttpfile* myhttpfile=null;
m_siterec.empty();
myurl = serverurl+"?pro=update&module="+artype[k]+"&version="+arversion[k];
myhttpfile=(chttpfile*)mysession.openurl(myurl);
while(myhttpfile->readstring(mydata)){m_siterec += mydata;}
if(m_siterec != "ok"){
cstring infile;
infile=m_szpath+"//data//"+artype[k];
cfile netfile;
netfile.open( infile, cfile::modecreate | cfile::modewrite);
netfile.write( m_siterec, m_siterec.getlength());
netfile.close();
bisnewer = true;
}
pbar->setpos((k+1)*(100-10)+10);
m_szeditmessage = "/r/n检查"+artype[k]+"文件... 成功!/r/n"+m_szeditmessage;
updatedata(false);
myhttpfile->close();
mysession.close();
}
if(bisnewer){
::messagebox(null,"文件已经更新成功!",null,mb_iconasterisk);
}else{
::messagebox(null,"您的数据文件已经是最新版本了!",null,mb_iconasterisk);
}
}else{
::messagebox(null,"没有连接网络或者找不到升级服务器,请检查",null,mb_iconasterisk);
pbar->setpos(100);
}
// 下面是完成了.
getdlgitem(idcancel)->showwindow(sw_hide);
getdlgitem(idok)->showwindow(sw_show);
getdlgitem(idok)->setfocus();
}
闽公网安备 35060202000074号