200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > c语言软件自动更新 C++简单实现程序自动更新

c语言软件自动更新 C++简单实现程序自动更新

时间:2019-05-16 07:18:23

相关推荐

c语言软件自动更新 C++简单实现程序自动更新

许多c艹的hxd想简单滴实现下程序的更新,现在就由小编zfat来讲解下思路

思路

获取网页内容,与程序版本比较

提示:以下是本篇文章正文内容,下面案例可供参考

1、实例

代码如下(示例):

string xiaves;

cout << "是否下载beta版(1/2)";

int betayes;

cin >> betayes;

if (betayes == 1) {

xiaves = "beta.html";

}

else {

xiaves = "update.html";

}

string wangye = "http://******/update/" + xiaves;

LPCSTR wangzhi = wangye.c_str();

HRESULT dyes;

cout << "检查中" << endl;

dyes = URLDownloadToFile(0, _T(wangzhi), _T("C:\\bugfixed_update.txt"), 0, NULL); //下载检测文件

if (dyes == S_OK) //下载成功

{

string temp; //读取文件

ifstream infile;

infile.open("C:\\bugfixed_update.txt",ios::in | ios::trunc);

ifstream readFile("C:\\bugfixed_update.txt");

readFile >> temp;

cout << temp << endl;

readFile.close();

if (temp == "0.4") { //==后为当前版本 //诺后端与前端相同

cout << "无版本更新";

Sleep(100000);

return 0;

}

else {

cout << "检测到新版本" << endl; //不同

cout << "是否立即安装(1/2)";

cin >> betayes;

if (betayes == 1) {

string down = "http://****/download/" + xiaves;

LPCSTR download = down.c_str();

dyes = URLDownloadToFile(0, _T(download), _T("C:\\update.msi"), 0, NULL);

if (dyes == S_OK) {

system("start c:\\update.msi");

system("del c:\\update.msi");

return 0;

}

else {

cout << "下载失败" << endl;

}

else {

return 0;

}

}

}

else {

cout << "检测失败" << endl;

}

}

2.主要函数讲解

URLDownloadToFile 保存网页内容 不支持重定向(容易报毒

ifstream 恶心的文件与流 详情看/cplusplus/cpp-files-streams.html

其他的话

像网页端可以尝试下github.io或gitee博客

总结

一个简单思路

我怎么一股营销号味?!

by zfat /1/24

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。