Bearsampp 2026.7.11
Loading...
Searching...
No Matches
ActionCheckVersion Class Reference

Public Member Functions

 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)

Data Fields

const DISPLAY_OK = 'displayOk'

Private Member Functions

 showVersionOkMessageBox ($lang, $winbinder)
 showVersionUpdateWindow ($lang, $winbinder, $core, $githubLatestVersion)

Private Attributes

 $currentVersion
 $didStartLoading = false
 $githubLatestVersionUrl
 $latestVersion
 $wbBtnOk
 $wbImage
 $wbLinkChangelog
 $wbLinkFull
 $wbWindow

Detailed Description

Definition at line 20 of file class.action.checkVersion.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

Constructor for the ActionCheckVersion class.

Parameters
array$argsCommand line arguments passed to the script.

Definition at line 40 of file class.action.checkVersion.php.

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');
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
59 Log::debug('ActionCheckVersion: GitHub version data: ' . var_export($githubVersionData, true));
60
61 if ($githubVersionData != null && isset($githubVersionData['version'], $githubVersionData['html_url'])) {
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');
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) {
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) {
82 }
83 Log::debug('ActionCheckVersion: Showing error message box');
84 $bearsamppWinbinder->messageBoxError(
85 'Failed to retrieve version data from GitHub during manual check.',
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) {
95 }
96 }
97 }
98 }
global $bearsamppLang
global $githubVersionData
$githubLatestVersion
global $bearsamppCore
showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion)
showVersionOkMessageBox($lang, $winbinder)
static getLatestVersion($url)
const CHECK_VERSION_TITLE
static debug($data, $file=null)
static error($data, $file=null)
static startLoading()
static stopLoading()
const APP_GITHUB_LATEST_URL
Definition root.php:19

References $bearsamppCore, $bearsamppLang, $githubLatestVersion, $githubVersionData, APP_GITHUB_LATEST_URL, Lang\CHECK_VERSION_TITLE, Log\debug(), Log\error(), HttpClient\getLatestVersion(), showVersionOkMessageBox(), showVersionUpdateWindow(), Util\startLoading(), and Util\stopLoading().

Here is the call graph for this function:

Member Function Documentation

◆ processWindow()

processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes window events and handles user interactions.

Parameters
resource$windowThe window resource.
int$idThe control ID that triggered the event.
resource$ctrlThe control resource.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.

Definition at line 155 of file class.action.checkVersion.php.

156 {
157 global $bearsamppConfig, $bearsamppWinbinder;
158
159 switch ($id) {
160 case $this->wbLinkFull[WinBinder::CTRL_ID]:
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 }
global $bearsamppConfig
Definition homepage.php:41

References $bearsamppConfig, APP_GITHUB_LATEST_URL, WinBinder\CTRL_ID, Log\error(), and HttpClient\getLatestVersion().

Here is the call graph for this function:

◆ showVersionOkMessageBox()

showVersionOkMessageBox ( $lang,
$winbinder )
private

Displays a message box indicating that the current version is the latest.

Parameters
Lang$langLanguage processor instance.
WinBinder$winbinderWinBinder instance for creating windows and controls.

Definition at line 134 of file class.action.checkVersion.php.

135 {
136 Log::debug('ActionCheckVersion: Calling Util::stopLoading() in showVersionOkMessageBox');
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 }
const CHECK_VERSION_LATEST_TEXT

References Lang\CHECK_VERSION_LATEST_TEXT, Lang\CHECK_VERSION_TITLE, Log\debug(), and Util\stopLoading().

Referenced by __construct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showVersionUpdateWindow()

showVersionUpdateWindow ( $lang,
$winbinder,
$core,
$githubLatestVersion )
private

Displays a window with the latest version information.

Parameters
Lang$langLanguage processor instance.
WinBinder$winbinderWinBinder instance for creating windows and controls.
Core$coreCore instance for accessing application resources.
string$githubLatestVersionThe latest version available on GitHub.

Definition at line 108 of file class.action.checkVersion.php.

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
123 $winbinder->setHandler($this->wbWindow, $this, 'processWindow');
124 $winbinder->mainLoop();
125 $winbinder->reset();
126 }
const CHECK_VERSION_AVAILABLE_TEXT
const DOWNLOAD
const BUTTON_OK
static getImagesPath($aetrayPath=false)
const APP_TITLE
Definition root.php:13

References $githubLatestVersion, APP_TITLE, Lang\BUTTON_OK, Lang\CHECK_VERSION_AVAILABLE_TEXT, Lang\CHECK_VERSION_TITLE, Lang\DOWNLOAD, Path\getImagesPath(), and Util\stopLoading().

Referenced by __construct().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $currentVersion

$currentVersion
private

Definition at line 30 of file class.action.checkVersion.php.

◆ $didStartLoading

$didStartLoading = false
private

Definition at line 33 of file class.action.checkVersion.php.

◆ $githubLatestVersionUrl

$githubLatestVersionUrl
private

Definition at line 32 of file class.action.checkVersion.php.

◆ $latestVersion

$latestVersion
private

Definition at line 31 of file class.action.checkVersion.php.

◆ $wbBtnOk

$wbBtnOk
private

Definition at line 28 of file class.action.checkVersion.php.

◆ $wbImage

$wbImage
private

Definition at line 25 of file class.action.checkVersion.php.

◆ $wbLinkChangelog

$wbLinkChangelog
private

Definition at line 26 of file class.action.checkVersion.php.

◆ $wbLinkFull

$wbLinkFull
private

Definition at line 27 of file class.action.checkVersion.php.

◆ $wbWindow

$wbWindow
private

Definition at line 24 of file class.action.checkVersion.php.

◆ DISPLAY_OK

const DISPLAY_OK = 'displayOk'

Definition at line 22 of file class.action.checkVersion.php.

Referenced by TplApp\getSectionMenuRight().


The documentation for this class was generated from the following file: