許多c艸的hxd想簡單滴實作下程式的更新,現在就由小編zfat來講解下思路
文章目錄
- 思路
- 1、實體
- 2.主要函式講解
- 其他的話
- 總結
- 我怎么一股營銷號味?!
思路
獲取網頁內容,與程式版本比較

提示:以下是本篇文章正文內容,下面案例可供參考
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 惡心的檔案與流 詳情看https://www.runoob.com/cplusplus/cpp-files-streams.html
其他的話
像網頁端可以嘗試下github.io或gitee博客
總結
一個簡單思路
我怎么一股營銷號味?!
by zfat 2021/1/24
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/252700.html
標籤:其他
