48 Util::logTrace(
'ActionLoading constructor started - PID: ' . $currentPid);
50 $bearsamppWinbinder->reset();
54 Util::logTrace(
'Loading PID added to tracking file: ' . $currentPid);
59 $screenWidth = intval($screenArea[2]);
60 $screenHeight = intval($screenArea[3]);
61 $xPos = $screenWidth - self::WINDOW_WIDTH;
62 $yPos = $screenHeight - self::WINDOW_HEIGHT - 5;
63 Util::logTrace(
'Screen dimensions: ' . $screenWidth .
'x' . $screenHeight .
', Window position: (' . $xPos .
',' . $yPos .
')');
67 $this->wbWindow = $bearsamppWinbinder->createWindow(
null, ToolDialog,
null, $xPos, $yPos, self::WINDOW_WIDTH, self::WINDOW_HEIGHT, WBC_TOP,
null);
70 if ($this->wbWindow ===
false || $this->wbWindow ===
null) {
71 Util::logError(
'CRITICAL: Failed to create loading window - window handle is: ' . var_export($this->wbWindow,
true));
72 Util::logError(
'WinBinder extension loaded: ' . (extension_loaded(
'winbinder') ?
'YES' :
'NO'));
73 Util::logError(
'wb_create_window function exists: ' . (function_exists(
'wb_create_window') ?
'YES' :
'NO'));
77 Util::logTrace(
'Loading window created successfully - handle: ' . $this->wbWindow);
82 wb_set_visible($this->wbWindow,
true);
86 $this->wbLabel = $bearsamppWinbinder->createLabel($this->wbWindow,
$bearsamppLang->getValue(
Lang::LOADING), 42, 2, 295,
null, WBC_LEFT);
87 Util::logTrace(
'Label created: ' . var_export($this->wbLabel,
true));
90 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE, 42, 20, 290, 15);
91 Util::logTrace(
'Progress bar created: ' . var_export($this->wbProgressBar,
true));
95 $bearsamppWinbinder->setHandler($this->wbWindow, $this,
'processLoading', 10);
97 $bearsamppWinbinder->mainLoop();
110 for ($i = 0; $i < $nb; $i++) {
111 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
112 $bearsamppWinbinder->drawImage($this->wbWindow,
$bearsamppCore->getImagesPath() .
'/bearsampp.bmp', 4, 2, 32, 32);
115 $bearsamppWinbinder->wait();
116 $bearsamppWinbinder->wait($this->wbWindow);
143 $startTime = microtime(
true);
144 $maxLoadingTime = 15;
146 while ($iterations < $maxIterations && (microtime(
true) - $startTime) < $maxLoadingTime) {
148 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
152 for ($i = 0; $i < self::GAUGE && (microtime(
true) - $startTime) < $maxLoadingTime; $i++) {
163 if ($allServicesStarted) {
169 Util::logTrace(
'Loading iteration ' . $iterations .
' completed, checking services again');
172 if ($iterations >= $maxIterations) {
173 Util::logTrace(
'Maximum iterations reached (' . $maxIterations .
'), some services may not have started properly');
176 if ((microtime(
true) - $startTime) >= $maxLoadingTime) {
177 Util::logTrace(
'Loading timeout reached (' . $maxLoadingTime .
' seconds), some services may not have started properly');
208 $statusFile =
$bearsamppCore->getTmpPath() .
'/loading_status.txt';
210 if (file_exists($statusFile)) {
211 $content = @file_get_contents($statusFile);
212 if ($content !==
false && !empty($content)) {
213 $status = @json_decode($content,
true);
214 if ($status && isset($status[
'text']) && !empty($status[
'text'])) {
217 $bearsamppWinbinder->refresh($this->wbWindow);
232 Util::logTrace(
'Checking if all services have started successfully');
237 if (!$service->isEnable()) {
238 Util::logTrace(
'Service ' . $sName .
' is disabled, skipping check');
243 $serviceName = $service->getName();
247 $checkStartTime = microtime(
true);
249 $serviceRunning =
false;
253 $tempFile =
$bearsamppCore->getTmpPath() .
'/service_check_' . uniqid() .
'.tmp';
256 $checkCmd =
'php -r "' .
257 'require \'' .
$bearsamppRoot->getLibsPath() .
'/classes/class.win32service.php\'; ' .
258 '$service = new Win32Service(\'' . $service->getName() .
'\');
' .
259 '$status = $service->status();
' .
260 'file_put_contents(\
'' . $tempFile .
'\', $status == Win32Service::STATE_RUNNING ? \
'1\' : \'0\'); ' .
261 'exit(0);" > nul 2>&1';
264 pclose(popen(
'start /B ' . $checkCmd,
'r'));
267 $startWait = microtime(
true);
268 while (!file_exists($tempFile) && (microtime(
true) - $startWait < $checkTimeout)) {
273 if (file_exists($tempFile)) {
274 $result = file_get_contents($tempFile);
275 $serviceRunning = (
$result ===
'1');
277 Util::logTrace(
'Service ' . $sName .
' status check: ' . ($serviceRunning ?
'running' :
'not running'));
280 $serviceRunning =
false;
282 }
catch (\Exception $e) {
283 Util::logTrace(
'Exception during service status check for ' . $sName .
': ' . $e->getMessage());
284 $serviceRunning =
false;
287 if (!$serviceRunning) {
294 Util::logTrace(
'All services started check result: ' . ($allStarted ?
'true' :
'false'));