Bearsampp
2026.7.11
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
{
22
const
DISPLAY_OK
=
'displayOk'
;
23
24
private
$wbWindow
;
25
private
$wbImage
;
26
private
$wbLinkChangelog
;
27
private
$wbLinkFull
;
28
private
$wbBtnOk
;
29
30
private
$currentVersion
;
31
private
$latestVersion
;
32
private
$githubLatestVersionUrl
;
33
private
$didStartLoading
=
false
;
34
40
public
function
__construct
($args)
41
{
42
global
$bearsamppCore
,
$bearsamppLang
, $bearsamppWinbinder, $appGithubHeader;
43
44
// Check if we're being called from the version check menu item
45
$isMenuCheck = !empty($args[0]) && $args[0] == self::DISPLAY_OK;
46
47
// Start loading only if the exec file doesn't exist or if we're doing a menu check
48
if
(!file_exists(
$bearsamppCore
->getExec()) || $isMenuCheck) {
49
if
($isMenuCheck) {
50
Log::debug
(
'ActionCheckVersion: Manual check detected, starting loading'
);
51
Util::startLoading
();
52
$this->didStartLoading =
true
;
53
}
54
$this->currentVersion =
$bearsamppCore
->getAppVersion();
55
Log::debug
(
'ActionCheckVersion: Current version: '
. $this->currentVersion);
56
57
// Assuming getLatestVersion now returns an array with version and URL
58
$githubVersionData
=
HttpClient::getLatestVersion
(
APP_GITHUB_LATEST_URL
);
59
Log::debug
(
'ActionCheckVersion: GitHub version data: '
. var_export(
$githubVersionData
,
true
));
60
61
if
(
$githubVersionData
!=
null
&& isset(
$githubVersionData
[
'version'
],
$githubVersionData
[
'html_url'
])) {
62
$githubLatestVersion
=
$githubVersionData
[
'version'
];
63
$this->githubLatestVersionUrl =
$githubVersionData
[
'html_url'
];
// URL of the latest version
64
Log::debug
(
'ActionCheckVersion: GitHub latest version: '
.
$githubLatestVersion
);
65
if
(version_compare($this->currentVersion,
$githubLatestVersion
,
'<'
)) {
66
Log::debug
(
'ActionCheckVersion: Update available, showing update window'
);
67
$this->
showVersionUpdateWindow
($bearsamppLang, $bearsamppWinbinder,
$bearsamppCore
,
$githubLatestVersion
);
68
} elseif ($isMenuCheck) {
69
Log::debug
(
'ActionCheckVersion: Version is up to date, showing OK message box'
);
70
$this->
showVersionOkMessageBox
($bearsamppLang, $bearsamppWinbinder);
71
}
else
{
72
Log::debug
(
'ActionCheckVersion: Version is up to date (background check)'
);
73
if
($this->didStartLoading) {
74
Util::stopLoading
();
75
}
76
}
77
} elseif ($isMenuCheck) {
78
Log::debug
(
'ActionCheckVersion: Failed to retrieve version data during manual check'
);
79
// If it's a menu check but we couldn't get version data, we must stop loading
80
if
($this->didStartLoading) {
81
Util::stopLoading
();
82
}
83
Log::debug
(
'ActionCheckVersion: Showing error message box'
);
84
$bearsamppWinbinder->messageBoxError(
85
'Failed to retrieve version data from GitHub during manual check.'
,
86
$bearsamppLang
->getValue(
Lang::CHECK_VERSION_TITLE
)
87
);
88
Log::debug
(
'ActionCheckVersion: Error message box returned'
);
89
Log::error
(
'Failed to retrieve version data from GitHub during manual check.'
);
90
}
else
{
91
Log::debug
(
'ActionCheckVersion: Failed to retrieve version data (background check)'
);
92
// Not a menu check, only stop loading if we started it
93
if
($this->didStartLoading) {
94
Util::stopLoading
();
95
}
96
}
97
}
98
}
99
108
private
function
showVersionUpdateWindow
($lang, $winbinder, $core,
$githubLatestVersion
)
109
{
110
$labelFullLink = $lang->getValue(
Lang::DOWNLOAD
) .
' '
.
APP_TITLE
.
' '
.
$githubLatestVersion
;
111
112
$winbinder->reset();
113
$this->wbWindow = $winbinder->createAppWindow($lang->getValue(
Lang::CHECK_VERSION_TITLE
), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
114
115
$winbinder->createLabel($this->wbWindow, $lang->getValue(
Lang::CHECK_VERSION_AVAILABLE_TEXT
), 80, 35, 370, 120);
116
117
$this->wbLinkFull = $winbinder->createHyperLink($this->wbWindow, $labelFullLink, 80, 87, 200, 20, WBC_LINES | WBC_RIGHT);
118
119
$this->wbBtnOk = $winbinder->createButton($this->wbWindow, $lang->getValue(
Lang::BUTTON_OK
), 280, 103);
120
$this->wbImage = $winbinder->drawImage($this->wbWindow,
Path::getImagesPath
() .
'/about.bmp'
);
121
122
Util::stopLoading
();
123
$winbinder->setHandler($this->wbWindow, $this,
'processWindow'
);
124
$winbinder->mainLoop();
125
$winbinder->reset();
126
}
127
134
private
function
showVersionOkMessageBox
($lang, $winbinder)
135
{
136
Log::debug
(
'ActionCheckVersion: Calling Util::stopLoading() in showVersionOkMessageBox'
);
137
Util::stopLoading
();
138
Log::debug
(
'ActionCheckVersion: Calling messageBoxInfo'
);
139
$winbinder->messageBoxInfo(
140
$lang->getValue(
Lang::CHECK_VERSION_LATEST_TEXT
),
141
$lang->getValue(
Lang::CHECK_VERSION_TITLE
)
142
);
143
Log::debug
(
'ActionCheckVersion: messageBoxInfo returned'
);
144
}
145
155
public
function
processWindow
($window, $id, $ctrl, $param1, $param2)
156
{
157
global
$bearsamppConfig
, $bearsamppWinbinder;
158
159
switch
($id) {
160
case
$this->wbLinkFull[
WinBinder::CTRL_ID
]:
161
$latestVersionInfo =
HttpClient::getLatestVersion
(
APP_GITHUB_LATEST_URL
);
162
if
($latestVersionInfo && isset($latestVersionInfo[
'html_url'
])) {
163
$browserPath =
$bearsamppConfig
->getBrowser();
164
if
(!$bearsamppWinbinder->exec($browserPath, $latestVersionInfo[
'html_url'
])) {
165
Log::error
(
"Failed to open browser at path: $browserPath with URL: "
. $latestVersionInfo[
'html_url'
]);
166
}
167
}
else
{
168
Log::error
(
"Failed to retrieve latest version info or 'html_url' not set."
);
169
}
170
break
;
171
case
IDCLOSE:
172
case
$this->wbBtnOk[
WinBinder::CTRL_ID
]:
173
$bearsamppWinbinder->destroyWindow($window);
174
break
;
175
default
:
176
Log::error
(
"Unhandled window control ID: $id"
);
177
}
178
}
179
}
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$githubVersionData
global $githubVersionData
Definition
ajax.latestversion.php:24
$githubLatestVersion
$githubLatestVersion
Definition
ajax.latestversion.php:66
$bearsamppCore
global $bearsamppCore
Definition
ajax.latestversion.php:24
ActionCheckVersion
Definition
class.action.checkVersion.php:21
ActionCheckVersion\$wbWindow
$wbWindow
Definition
class.action.checkVersion.php:24
ActionCheckVersion\$wbLinkFull
$wbLinkFull
Definition
class.action.checkVersion.php:27
ActionCheckVersion\__construct
__construct($args)
Definition
class.action.checkVersion.php:40
ActionCheckVersion\$latestVersion
$latestVersion
Definition
class.action.checkVersion.php:31
ActionCheckVersion\$didStartLoading
$didStartLoading
Definition
class.action.checkVersion.php:33
ActionCheckVersion\$wbLinkChangelog
$wbLinkChangelog
Definition
class.action.checkVersion.php:26
ActionCheckVersion\$wbBtnOk
$wbBtnOk
Definition
class.action.checkVersion.php:28
ActionCheckVersion\$githubLatestVersionUrl
$githubLatestVersionUrl
Definition
class.action.checkVersion.php:32
ActionCheckVersion\$wbImage
$wbImage
Definition
class.action.checkVersion.php:25
ActionCheckVersion\$currentVersion
$currentVersion
Definition
class.action.checkVersion.php:30
ActionCheckVersion\showVersionUpdateWindow
showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion)
Definition
class.action.checkVersion.php:108
ActionCheckVersion\showVersionOkMessageBox
showVersionOkMessageBox($lang, $winbinder)
Definition
class.action.checkVersion.php:134
ActionCheckVersion\processWindow
processWindow($window, $id, $ctrl, $param1, $param2)
Definition
class.action.checkVersion.php:155
ActionCheckVersion\DISPLAY_OK
const DISPLAY_OK
Definition
class.action.checkVersion.php:22
HttpClient\getLatestVersion
static getLatestVersion($url)
Definition
class.httpclient.php:336
Lang\CHECK_VERSION_AVAILABLE_TEXT
const CHECK_VERSION_AVAILABLE_TEXT
Definition
class.lang.php:342
Lang\CHECK_VERSION_LATEST_TEXT
const CHECK_VERSION_LATEST_TEXT
Definition
class.lang.php:344
Lang\DOWNLOAD
const DOWNLOAD
Definition
class.lang.php:40
Lang\BUTTON_OK
const BUTTON_OK
Definition
class.lang.php:366
Lang\CHECK_VERSION_TITLE
const CHECK_VERSION_TITLE
Definition
class.lang.php:341
Log\debug
static debug($data, $file=null)
Definition
class.log.php:616
Log\error
static error($data, $file=null)
Definition
class.log.php:650
Path\getImagesPath
static getImagesPath($aetrayPath=false)
Definition
class.path.php:527
Util\startLoading
static startLoading()
Definition
class.util.php:530
Util\stopLoading
static stopLoading()
Definition
class.util.php:550
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:41
APP_GITHUB_LATEST_URL
const APP_GITHUB_LATEST_URL
Definition
root.php:19
APP_TITLE
const APP_TITLE
Definition
root.php:13
sandbox
core
classes
actions
class.action.checkVersion.php
Generated by
1.17.0