Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.checkVersion.php
Go to the documentation of this file.
1
<?php
2
/*
3
*
4
* * Copyright (c) 2022-2025 Bearsampp
5
* * License: GNU General Public License version 3 or later; see LICENSE.txt
6
* * Website: https://bearsampp.com
7
* * Github: https://github.com/Bearsampp
8
*
9
*/
10
20
class
ActionCheckVersion
21
{
23
const
DISPLAY_OK
=
'displayOk'
;
24
26
private
$wbWindow
;
28
private
$wbImage
;
30
private
$wbLinkChangelog
;
32
private
$wbLinkFull
;
34
private
$wbBtnOk
;
35
37
private
$currentVersion
;
39
private
$latestVersion
;
41
private
$githubLatestVersionUrl
;
43
private
$didStartLoading
=
false
;
44
50
public
function
__construct
($args)
51
{
52
global
$bearsamppCore
,
$bearsamppLang
, $bearsamppWinbinder, $appGithubHeader;
53
54
// Check if we're being called from the version check menu item
55
$isMenuCheck = !empty($args[0]) && $args[0] == self::DISPLAY_OK;
56
57
// Start loading only if the exec file doesn't exist or if we're doing a menu check
58
if
(!file_exists(
$bearsamppCore
->getExec()) || $isMenuCheck) {
59
if
($isMenuCheck) {
60
Log::debug
(
'ActionCheckVersion: Manual check detected, starting loading'
);
61
Util::startLoading
();
62
$this->didStartLoading =
true
;
63
}
64
$this->currentVersion =
$bearsamppCore
->getAppVersion();
65
Log::debug
(
'ActionCheckVersion: Current version: '
. $this->currentVersion);
66
67
// Assuming getLatestVersion now returns an array with version and URL
68
$githubVersionData
=
Util::getLatestVersion
(
APP_GITHUB_LATEST_URL
);
69
Log::trace
(
'ActionCheckVersion: GitHub version data: '
. var_export(
$githubVersionData
,
true
));
70
71
if
(
$githubVersionData
!=
null
&& isset(
$githubVersionData
[
'version'
],
$githubVersionData
[
'html_url'
])) {
72
$githubLatestVersion
=
$githubVersionData
[
'version'
];
73
$this->githubLatestVersionUrl =
$githubVersionData
[
'html_url'
];
// URL of the latest version
74
Log::debug
(
'ActionCheckVersion: GitHub latest version: '
.
$githubLatestVersion
);
75
if
(version_compare($this->currentVersion,
$githubLatestVersion
,
'<'
)) {
76
Log::debug
(
'ActionCheckVersion: Update available, showing update window'
);
77
$this->
showVersionUpdateWindow
($bearsamppLang, $bearsamppWinbinder,
$bearsamppCore
,
$githubLatestVersion
);
78
} elseif ($isMenuCheck) {
79
Log::debug
(
'ActionCheckVersion: Version is up to date, showing OK message box'
);
80
$this->
showVersionOkMessageBox
($bearsamppLang, $bearsamppWinbinder);
81
}
else
{
82
Log::debug
(
'ActionCheckVersion: Version is up to date (background check)'
);
83
if
($this->didStartLoading) {
84
Util::stopLoading
();
85
}
86
}
87
} elseif ($isMenuCheck) {
88
Log::debug
(
'ActionCheckVersion: Failed to retrieve version data during manual check'
);
89
// If it's a menu check but we couldn't get version data, we must stop loading
90
if
($this->didStartLoading) {
91
Util::stopLoading
();
92
}
93
Log::debug
(
'ActionCheckVersion: Showing error message box'
);
94
$bearsamppWinbinder->messageBoxError(
95
'Failed to retrieve version data from GitHub during manual check.'
,
96
$bearsamppLang
->getValue(
Lang::CHECK_VERSION_TITLE
)
97
);
98
Log::debug
(
'ActionCheckVersion: Error message box returned'
);
99
Log::error
(
'Failed to retrieve version data from GitHub during manual check.'
);
100
}
else
{
101
Log::debug
(
'ActionCheckVersion: Failed to retrieve version data (background check)'
);
102
// Not a menu check, only stop loading if we started it
103
if
($this->didStartLoading) {
104
Util::stopLoading
();
105
}
106
}
107
}
108
}
109
118
private
function
showVersionUpdateWindow
($lang, $winbinder, $core,
$githubLatestVersion
)
119
{
120
$labelFullLink = $lang->getValue(
Lang::DOWNLOAD
) .
' '
.
APP_TITLE
.
' '
.
$githubLatestVersion
;
121
122
$winbinder->reset();
123
$this->wbWindow = $winbinder->createAppWindow($lang->getValue(
Lang::CHECK_VERSION_TITLE
), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
124
125
$winbinder->createLabel($this->wbWindow, $lang->getValue(
Lang::CHECK_VERSION_AVAILABLE_TEXT
), 80, 35, 370, 120);
126
127
$this->wbLinkFull = $winbinder->createHyperLink($this->wbWindow, $labelFullLink, 80, 87, 200, 20, WBC_LINES | WBC_RIGHT);
128
129
$this->wbBtnOk = $winbinder->createButton($this->wbWindow, $lang->getValue(
Lang::BUTTON_OK
), 280, 103);
130
$this->wbImage = $winbinder->drawImage($this->wbWindow,
Path::getImagesPath
() .
'/about.bmp'
);
131
132
Util::stopLoading
();
133
$winbinder->setHandler($this->wbWindow, $this,
'processWindow'
);
134
$winbinder->mainLoop();
135
$winbinder->reset();
136
}
137
144
private
function
showVersionOkMessageBox
($lang, $winbinder)
145
{
146
Log::debug
(
'ActionCheckVersion: Calling Util::stopLoading() in showVersionOkMessageBox'
);
147
Util::stopLoading
();
148
Log::debug
(
'ActionCheckVersion: Calling messageBoxInfo'
);
149
$winbinder->messageBoxInfo(
150
$lang->getValue(
Lang::CHECK_VERSION_LATEST_TEXT
),
151
$lang->getValue(
Lang::CHECK_VERSION_TITLE
)
152
);
153
Log::debug
(
'ActionCheckVersion: messageBoxInfo returned'
);
154
}
155
165
public
function
processWindow
($window, $id, $ctrl, $param1, $param2)
166
{
167
global
$bearsamppConfig
, $bearsamppWinbinder;
168
169
switch
($id) {
170
case
$this->wbLinkFull[
WinBinder::CTRL_ID
]:
171
$latestVersionInfo =
Util::getLatestVersion
(
APP_GITHUB_LATEST_URL
);
172
if
($latestVersionInfo && isset($latestVersionInfo[
'html_url'
])) {
173
$browserPath =
$bearsamppConfig
->getBrowser();
174
if
(!$bearsamppWinbinder->exec($browserPath, $latestVersionInfo[
'html_url'
])) {
175
Log::error
(
"Failed to open browser at path: $browserPath with URL: "
. $latestVersionInfo[
'html_url'
]);
176
}
177
}
else
{
178
Log::error
(
"Failed to retrieve latest version info or 'html_url' not set."
);
179
}
180
break
;
181
case
IDCLOSE:
182
case
$this->wbBtnOk[
WinBinder::CTRL_ID
]:
183
$bearsamppWinbinder->destroyWindow($window);
184
break
;
185
default
:
186
Log::error
(
"Unhandled window control ID: $id"
);
187
}
188
}
189
}
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$githubVersionData
global $githubVersionData
Definition
ajax.latestversion.php:24
$githubLatestVersion
$githubLatestVersion
Definition
ajax.latestversion.php:67
$bearsamppCore
global $bearsamppCore
Definition
ajax.latestversion.php:24
ActionCheckVersion
Definition
class.action.checkVersion.php:21
ActionCheckVersion\$wbWindow
$wbWindow
Definition
class.action.checkVersion.php:26
ActionCheckVersion\$wbLinkFull
$wbLinkFull
Definition
class.action.checkVersion.php:32
ActionCheckVersion\__construct
__construct($args)
Definition
class.action.checkVersion.php:50
ActionCheckVersion\$latestVersion
$latestVersion
Definition
class.action.checkVersion.php:39
ActionCheckVersion\$didStartLoading
$didStartLoading
Definition
class.action.checkVersion.php:43
ActionCheckVersion\$wbLinkChangelog
$wbLinkChangelog
Definition
class.action.checkVersion.php:30
ActionCheckVersion\$wbBtnOk
$wbBtnOk
Definition
class.action.checkVersion.php:34
ActionCheckVersion\$githubLatestVersionUrl
$githubLatestVersionUrl
Definition
class.action.checkVersion.php:41
ActionCheckVersion\$wbImage
$wbImage
Definition
class.action.checkVersion.php:28
ActionCheckVersion\$currentVersion
$currentVersion
Definition
class.action.checkVersion.php:37
ActionCheckVersion\showVersionUpdateWindow
showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion)
Definition
class.action.checkVersion.php:118
ActionCheckVersion\showVersionOkMessageBox
showVersionOkMessageBox($lang, $winbinder)
Definition
class.action.checkVersion.php:144
ActionCheckVersion\processWindow
processWindow($window, $id, $ctrl, $param1, $param2)
Definition
class.action.checkVersion.php:165
ActionCheckVersion\DISPLAY_OK
const DISPLAY_OK
Definition
class.action.checkVersion.php:23
Lang\CHECK_VERSION_AVAILABLE_TEXT
const CHECK_VERSION_AVAILABLE_TEXT
Definition
class.lang.php:343
Lang\CHECK_VERSION_LATEST_TEXT
const CHECK_VERSION_LATEST_TEXT
Definition
class.lang.php:345
Lang\DOWNLOAD
const DOWNLOAD
Definition
class.lang.php:39
Lang\BUTTON_OK
const BUTTON_OK
Definition
class.lang.php:373
Lang\CHECK_VERSION_TITLE
const CHECK_VERSION_TITLE
Definition
class.lang.php:342
Log\debug
static debug($data, $file=null)
Definition
class.log.php:726
Log\trace
static trace($data, $file=null)
Definition
class.log.php:715
Log\error
static error($data, $file=null)
Definition
class.log.php:760
Path\getImagesPath
static getImagesPath($aetrayPath=false)
Definition
class.path.php:559
Util\getLatestVersion
static getLatestVersion($url)
Definition
class.util.php:898
Util\startLoading
static startLoading()
Definition
class.util.php:540
Util\stopLoading
static stopLoading()
Definition
class.util.php:562
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:46
APP_GITHUB_LATEST_URL
const APP_GITHUB_LATEST_URL
Definition
root.php:26
APP_TITLE
const APP_TITLE
Definition
root.php:19
sandbox
core
classes
actions
class.action.checkVersion.php
Generated by
1.17.0