Bearsampp 2025.8.29
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
21{
22 const DISPLAY_OK = 'displayOk';
23
24 private $wbWindow;
25 private $wbImage;
27 private $wbLinkFull;
28 private $wbBtnOk;
29
33
39 public function __construct($args)
40 {
41 global $bearsamppCore, $bearsamppLang, $bearsamppWinbinder, $appGithubHeader;
42
43 // Check if we're being called from the version check menu item
44 $isMenuCheck = !empty($args[0]) && $args[0] == self::DISPLAY_OK;
45
46 // Start loading only if the exec file doesn't exist or if we're doing a menu check
47 if (!file_exists($bearsamppCore->getExec()) || $isMenuCheck) {
49 $this->currentVersion = $bearsamppCore->getAppVersion();
50
51 // Assuming getLatestVersion now returns an array with version and URL
53
54 if ($githubVersionData != null && isset($githubVersionData['version'], $githubVersionData['html_url'])) {
56 $this->githubLatestVersionUrl = $githubVersionData['html_url']; // URL of the latest version
57 if (version_compare($this->currentVersion, $githubLatestVersion, '<')) {
58 $this->showVersionUpdateWindow($bearsamppLang, $bearsamppWinbinder, $bearsamppCore, $githubLatestVersion);
59 } elseif ($isMenuCheck) {
60 $this->showVersionOkMessageBox($bearsamppLang, $bearsamppWinbinder);
61 }
62 }
63 }
64 }
65
74 private function showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion)
75 {
76 $labelFullLink = $lang->getValue(Lang::DOWNLOAD) . ' ' . APP_TITLE . ' ' . $githubLatestVersion;
77
78 $winbinder->reset();
79 $this->wbWindow = $winbinder->createAppWindow($lang->getValue(Lang::CHECK_VERSION_TITLE), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
80
81 $winbinder->createLabel($this->wbWindow, $lang->getValue(Lang::CHECK_VERSION_AVAILABLE_TEXT), 80, 35, 370, 120);
82
83 $this->wbLinkFull = $winbinder->createHyperLink($this->wbWindow, $labelFullLink, 80, 87, 200, 20, WBC_LINES | WBC_RIGHT);
84
85 $this->wbBtnOk = $winbinder->createButton($this->wbWindow, $lang->getValue(Lang::BUTTON_OK), 280, 103);
86 $this->wbImage = $winbinder->drawImage($this->wbWindow, $core->getImagesPath() . '/about.bmp');
87
89 $winbinder->setHandler($this->wbWindow, $this, 'processWindow');
90 $winbinder->mainLoop();
91 $winbinder->reset();
92 }
93
100 private function showVersionOkMessageBox($lang, $winbinder)
101 {
103 $winbinder->messageBoxInfo(
104 $lang->getValue(Lang::CHECK_VERSION_LATEST_TEXT),
105 $lang->getValue(Lang::CHECK_VERSION_TITLE)
106 );
107 }
108
118 public function processWindow($window, $id, $ctrl, $param1, $param2)
119 {
120 global $bearsamppConfig, $bearsamppWinbinder;
121
122 switch ($id) {
123 case $this->wbLinkFull[WinBinder::CTRL_ID]:
124 $latestVersionInfo = Util::getLatestVersion(APP_GITHUB_LATEST_URL);
125 if ($latestVersionInfo && isset($latestVersionInfo['html_url'])) {
126 $browserPath = $bearsamppConfig->getBrowser();
127 if (!$bearsamppWinbinder->exec($browserPath, $latestVersionInfo['html_url'])) {
128 Util::logError("Failed to open browser at path: $browserPath with URL: " . $latestVersionInfo['html_url']);
129 }
130 } else {
131 Util::logError("Failed to retrieve latest version info or 'html_url' not set.");
132 }
133 break;
134 case IDCLOSE:
135 case $this->wbBtnOk[WinBinder::CTRL_ID]:
136 $bearsamppWinbinder->destroyWindow($window);
137 break;
138 default:
139 Util::logError("Unhandled window control ID: $id");
140 }
141 }
142}
global $bearsamppLang
global $githubVersionData
$githubLatestVersion
global $bearsamppCore
showVersionUpdateWindow($lang, $winbinder, $core, $githubLatestVersion)
showVersionOkMessageBox($lang, $winbinder)
processWindow($window, $id, $ctrl, $param1, $param2)
const CHECK_VERSION_AVAILABLE_TEXT
const CHECK_VERSION_LATEST_TEXT
const DOWNLOAD
const BUTTON_OK
const CHECK_VERSION_TITLE
static logError($data, $file=null)
static getLatestVersion($url)
static startLoading()
static stopLoading()
global $bearsamppConfig
Definition homepage.php:27
const APP_GITHUB_LATEST_URL
Definition root.php:19
const APP_TITLE
Definition root.php:13