目录
2、将xnwlive/updateVer.exe 解压到 系统下载目录
这是我实际中使用的一种更新思路,整体思路如下:
1)、主程序负责下载更新包、并记录路径,及解压updata.exe程序
主程序负责下载更新包,下载到系统download目录下,并解压其中的updata.exe 也是解压在系统download目录下,主程序,下载更新包时,将更新包的版本信息,以及主程序路径,存放在系统%appdata%中。
之所以下载到系统download下,主要是考虑,若是安装在无写权限路径时,最起码系统download是可写的。
2)、更新程序updata.exe负责将zip包解压到 主程序目录下
将本程序路径 记录在APPDATA中
- cef_control_->AttachUpdateXnwVerCallback([](){
-
- //更新的包 下载到 系统downloads\xnw下,
-
- std::wstring xnwDownloadPath = GetXnwAppdataOrthersetPathW(); //保存到系统 Ortherset下
- WriteIniFileW(L"Ver", L"AppPath", appFolderW+L"\\", xnwDownloadPath);
- }); //有此回调 则说明 下载文件时,不需要跳出选择对话框来
下载到系统downloads目录下


- std::wstring zipDir = GetXnwSysMyDownloadDirW() + L"\\";
- SetCurrentDirectoryW(zipDir.c_str());
-
- HZIP hz = OpenZip(m_zipFile.c_str(), "");
- if (hz != NULL)
- {
- ZIPENTRY ze;
- GetZipItem(hz, -1, &ze);
- int numitems = ze.index;
- int nFindItemIndex = 0;
- FindZipItem(hz, L"xnwlive/updateVer.exe", false, &nFindItemIndex, &ze);
-
-
- if (nFindItemIndex != -1)
- {
- UnzipItem(hz, nFindItemIndex, ze.name);
- }
- CloseZip(hz);
- }
-
- std::wstring exefilePath = zipDir;
- exefilePath.append(L"xnwlive/updateVer.exe");
-
- SHELLEXECUTEINFO shExInfo = { 0 };
- shExInfo.cbSize = sizeof(shExInfo);
- shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- shExInfo.hwnd = 0;
- shExInfo.lpVerb = _T("runas"); // Operation to perform
- shExInfo.lpFile = exefilePath.c_str(); // Application to start
- shExInfo.lpParameters = L""; // Additional parameters
- shExInfo.lpDirectory = 0;
- shExInfo.nShow = SW_SHOW;
- shExInfo.hInstApp = 0;
-
- if (ShellExecuteEx(&shExInfo))
- {
- CloseBtn(false); //关闭主程序
-
- WaitForSingleObject(shExInfo.hProcess, INFINITE);
- CloseHandle(shExInfo.hProcess);
- }
- std::wstring dir;
-
- GetPrivateProfileString(L"Ver", L"AppPath", NULL, szPathW, 255, iniFile.c_str());
-
- if (wcslen(szPathW) > 0)
- {
- dir = szPathW; //客户端路径
- }
- SetCurrentDirectoryW(zipDir.c_str());
-
- HZIP hz = OpenZip(path.c_str(), "");
- ZIPENTRY ze;
- GetZipItem(hz, -1, &ze);
- int numitems = ze.index;
-
- std::wstring name;
-
- for (int i = 0; i < numitems; i++)
- {
- GetZipItem(hz, i, &ze);
-
- name = ze.name;
-
- std::wstring zipName;//去除 xnwlive/ 直接装在现有目录下
- std::wstring xnwliveS = L"xnwlive/";
- zipName = name.substr(xnwliveS.length());
-
- UnzipItem(hz, i, zipName.c_str());
-
- }
-
- CloseZip(hz);