-
Notifications
You must be signed in to change notification settings - Fork 24
/
checkVersion.p
95 lines (77 loc) · 3.33 KB
/
checkVersion.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*------------------------------------------------------------------------
Name : checkVersion.p
Desc : Check if there is a new version
Notes:
The version nr is increased when it is ready for production, the
build nr is increased when something is ready for beta testing.
Parameters:
piChannel : 0=no check, 1=check stable, 2=check beta
plManualCheck : TRUE when user presses 'Check Now' button
----------------------------------------------------------------------*/
DEFINE INPUT PARAMETER piChannel AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER plManualCheck AS LOGICAL NO-UNDO.
{DataDigger.i}
DEFINE VARIABLE cLocalBuild AS CHARACTER NO-UNDO.
DEFINE VARIABLE cRemoteBuild AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNewVersionUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE lVisit AS LOGICAL NO-UNDO INITIAL TRUE.
DEFINE VARIABLE cStableBuild AS CHARACTER NO-UNDO.
&GLOBAL-DEFINE STABLE-RELEASES-URL https://github.com/patrickTingen/DataDigger/releases/latest
&GLOBAL-DEFINE BETA-RELEASES-URL https://github.com/patrickTingen/DataDigger/releases/
/* Might be spaces in the include file */
cLocalBuild = TRIM('{build.i}').
/* If channel is set to manual, but this is not a manual check then return. */
IF piChannel = {&CHECK-MANUAL} AND NOT plManualCheck THEN RETURN.
/* Get current stable build */
RUN getVersionInfo.p(INPUT 'master', OUTPUT cStableBuild).
/* Get proper version info, depending on channel */
IF piChannel = {&CHECK-MANUAL} OR piChannel = {&CHECK-STABLE} THEN
DO:
/* If local build is newer than stable, set update channel to BETA */
IF cLocalBuild > cStableBuild THEN
DO:
setRegistry("DataDigger:Update","UpdateChannel", "{&CHECK-BETA}").
piChannel = {&CHECK-BETA}.
END.
ELSE
cRemoteBuild = cStableBuild.
END.
IF piChannel = {&CHECK-BETA} THEN
RUN getVersionInfo.p(INPUT 'develop', OUTPUT cRemoteBuild).
/* If version cannot be determined then don't bother. Unless this is a manual check */
IF cRemoteBuild = '' OR cRemoteBuild = ? THEN
DO:
IF plManualCheck THEN MESSAGE 'Cannot reach the DataDigger website' VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
RETURN.
END.
/* Save remote version / build */
setRegistry('DataDigger:Update', 'RemoteBuildNr', cRemoteBuild).
/* Check build to detect new versions */
IF cRemoteBuild > cLocalBuild THEN
DO:
IF piChannel = {&CHECK-MANUAL} OR piChannel = {&CHECK-STABLE} THEN
cNewVersionUrl = '{&STABLE-RELEASES-URL}'.
ELSE
cNewVersionUrl = '{&BETA-RELEASES-URL}'.
IF plManualCheck THEN
DO:
MESSAGE 'A new version is available on the DataDigger website~n~nDo you want to check it?' VIEW-AS ALERT-BOX INFORMATION BUTTONS YES-NO-CANCEL UPDATE lVisit.
IF lVisit = TRUE THEN
DO:
CASE cNewVersionUrl:
WHEN '{&STABLE-RELEASES-URL}' THEN OS-COMMAND NO-WAIT "START {&STABLE-RELEASES-URL}".
WHEN '{&BETA-RELEASES-URL}' THEN OS-COMMAND NO-WAIT "START {&BETA-RELEASES-URL}".
END CASE.
END.
END.
ELSE
setRegistry('DataDigger:Update', 'NewVersionURL', cNewVersionUrl).
END.
ELSE
/* Up to date */
DO:
IF plManualCheck THEN
MESSAGE 'No new version available, you are up to date.' VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
ELSE
setRegistry('DataDigger:Update', 'NewVersionURL', '').
END.