Skip to content

Commit

Permalink
Bug: 修复了部分特殊网络环境下自动更新包有可能损坏导致程序无法打开的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shc0743 committed Sep 17, 2024
1 parent e5c9c88 commit cd9675b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
Binary file modified .vs/MyPN532/v17/.suo
Binary file not shown.
12 changes: 6 additions & 6 deletions .vs/MyPN532/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 5,
"SelectedChildIndex": 4,
"Children": [
{
"$type": "Bookmark",
Expand All @@ -52,10 +52,6 @@
"$type": "Bookmark",
"Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}"
},
{
"$type": "Document",
"DocumentIndex": 0,
Expand All @@ -64,11 +60,15 @@
"RelativeDocumentMoniker": "MyPN532\\updater.cpp",
"ToolTip": "D:\\software\\Program\\source\\VSProjects\\MyPN532\\MyPN532\\updater.cpp",
"RelativeToolTip": "MyPN532\\updater.cpp",
"ViewState": "AQIAAKgAAAAAAAAAAAAQwK8AAAAKAAAA",
"ViewState": "AQIAAJYAAAAAAAAAAAAQwKQAAAAjAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-09-16T16:55:10.815Z",
"EditorCaption": ""
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}"
},
{
"$type": "Document",
"DocumentIndex": 2,
Expand Down
Binary file modified .vs/MyPN532/v17/fileList.bin
Binary file not shown.
31 changes: 29 additions & 2 deletions MyPN532/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,34 @@ int UpdaterEntry(CmdLineW& cl) {
hPipe = CreateFileW(pipe.c_str(), GENERIC_ALL, 0, 0, OPEN_EXISTING, 0, 0);

SetCurrentDirectoryW(GetProgramPathW().c_str());
begin_download:
size_t download_retry_count = 0;
int err = download_main(download_url, L"update.pkg", L"MyPN532 Updater Version/1.2.0.0", true);
if (!err) {
// 校验
FreeResFile(IDR_BIN_7z_x64, L"BIN", L"x.exe");
auto pi = Process.Start_HiddenWindow(L"x t update.pkg");
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitcode = 0;
GetExitCodeProcess(pi.hProcess, &exitcode);
Process.CloseProcessHandle(pi);

if (exitcode) {
if (download_retry_count++ < 5) {
string str = "0";
DWORD toW = (DWORD)str.size(), Wd = 0;
(void)WriteFile(hPipe, str.data(), toW, &Wd, 0);
goto begin_download;
}
err = 1;
string str = "FAIL";
DWORD toW = (DWORD)str.size(), Wd = 0;
(void)WriteFile(hPipe, str.data(), toW, &Wd, 0);
str = "FAIL=Update package is corrupt";
toW = (DWORD)str.size(), Wd = 0;
(void)WriteFile(hPipe, str.data(), toW, &Wd, 0);
}
}
if (err) {
string str = "FAIL";
DWORD toW = (DWORD)str.size(), Wd = 0;
Expand Down Expand Up @@ -135,10 +162,10 @@ int UpdaterEntry(CmdLineW& cl) {
HMPRGOBJ hObj = CreateMprgObject();
HMPRGWIZ hWiz = CreateMprgWizard(hObj, MPRG_CREATE_PARAMS{
.szTitle = L"MyPN532 Standard Updater",
.szText = L"Applying updates..."
.szText = L"Applying updates...",
.max = size_t(-1),
});
OpenMprgWizard(hWiz);
FreeResFile(IDR_BIN_7z_x64, L"BIN", L"x.exe");
MoveFileW(L"../config/userconfig.json", L"../config/U");
FileDeleteTreeW(L"../webroot");
SetCurrentDirectoryW(L"../../");
Expand Down
Binary file modified bin/MyPN532_x64.exe
Binary file not shown.
Binary file modified bin/MyPN532_x64.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion latest-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.4
v1.2.5
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32
33

0 comments on commit cd9675b

Please sign in to comment.