Skip to content

Commit ea9da2e

Browse files
authored
Handle update to unexpected version (#371)
1 parent 0872729 commit ea9da2e

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/update_zwift.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ is_wine_task_running() {
5858
get_current_version() {
5959
# if Zwift_ver_cur_filename.txt exists, it holds the true current version filename
6060
# if it does not exist, use Zwift_ver_cur.xml as fallback
61-
# if neither exist or contain a valid version, use 0.0.0 (Zwift not installed)
61+
# if neither exist or contain a valid version, use undefined (Zwift not installed)
6262

6363
local version_filename="Zwift_ver_cur.xml"
6464
if [[ -f Zwift_ver_cur_filename.txt ]]; then
6565
version_filename="$(tr '\0' '\n' < Zwift_ver_cur_filename.txt)"
6666
fi
6767

68-
grep -oP 'sversion="\K.*?(?=\s)' "${version_filename}" 2> /dev/null | cut -f 1 -d ' ' || echo "0.0.0"
68+
grep -oP 'sversion="\K.*?(?=\s)' "${version_filename}" 2> /dev/null | cut -f 1 -d ' ' || echo "undefined"
6969
}
7070

7171
get_latest_version() {
@@ -86,10 +86,10 @@ update_zwift_using_launcher() {
8686
if [[ ${zwift_current_version} == "${zwift_latest_version}" ]]; then
8787
msgbox ok "Nothing to do, already at latest version ${zwift_latest_version}"
8888
return 0
89-
else
90-
msgbox info "Updating Zwift from version ${zwift_current_version} to ${zwift_latest_version}"
9189
fi
9290

91+
msgbox info "Updating Zwift from version ${zwift_current_version} to ${zwift_latest_version}"
92+
9393
msgbox info "Starting Zwift launcher using wine"
9494
if ! wine start ZwiftLauncher.exe SilentLaunch; then
9595
msgbox error "Failed to start Zwift launcher using wine!"
@@ -99,9 +99,10 @@ update_zwift_using_launcher() {
9999

100100
local counter=1
101101
local max_iterations=60 # 60 * 5s = 5 minutes max
102+
local zwift_original_version="${zwift_current_version}"
102103

103104
# also stop if launcher exits before update finishes, so we don't hang forever
104-
while [[ ${zwift_current_version} != "${zwift_latest_version}" ]] && [[ ${counter} -le ${max_iterations} ]] && is_wine_task_running ZwiftLauncher.exe; do
105+
while [[ ${zwift_current_version} == "${zwift_original_version}" ]] && [[ ${counter} -le ${max_iterations} ]] && is_wine_task_running ZwiftLauncher.exe; do
105106
msgbox info "Updating Zwift... (${counter}/${max_iterations})"
106107
msgbox debug "Current version: ${zwift_current_version}; Latest version: ${zwift_latest_version}"
107108
sleep 5
@@ -110,7 +111,7 @@ update_zwift_using_launcher() {
110111
done
111112

112113
# if launcher exited unexpectedly or update timeout, Zwift is still at the old version
113-
if [[ ${zwift_current_version} != "${zwift_latest_version}" ]]; then
114+
if [[ ${zwift_current_version} == "${zwift_original_version}" ]]; then
114115
if [[ ${counter} -gt ${max_iterations} ]]; then
115116
msgbox error "Update timed out after $((counter * 5)) seconds"
116117
else
@@ -119,7 +120,13 @@ update_zwift_using_launcher() {
119120
return 1
120121
fi
121122

122-
msgbox ok "Zwift updated to version ${zwift_latest_version}"
123+
# zwift updated to unexpected version?
124+
if [[ ${zwift_current_version} != "${zwift_latest_version}" ]]; then
125+
msgbox error "Zwift updated to unexpected version (Expected: ${zwift_latest_version}, Actual: ${zwift_current_version}"
126+
return 1
127+
fi
128+
129+
msgbox ok "Zwift updated to version ${zwift_current_version}"
123130
}
124131

125132
install_zwift() {

0 commit comments

Comments
 (0)