天天看點

c語言軟體自動更新,C++簡單實作程式自動更新

許多c艹的hxd想簡單滴實作下程式的更新,現在就由小編zfat來講解下思路

思路

擷取網頁内容,與程式版本比較

c語言軟體自動更新,C++簡單實作程式自動更新

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

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