2024.8.23
Loading...
Searching...
No Matches
class.action.rebuildIni.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Handles the action of rebuilding the bearsampp.ini file within the application.
12 *
13 * This class is responsible for deleting the existing bearsampp.ini file and creating a new one
14 * with the specified configuration content.
15 */
17{
18 /**
19 * Constructor for the ActionRebuildini class.
20 *
21 * Upon instantiation, it deletes the existing bearsampp.ini file and creates a new one with
22 * the specified configuration content.
23 *
24 * @param array $args Arguments that might be used for further extension of constructor functionality.
25 * @throws Exception If the bearsampp.ini file cannot be written.
26 */
27 public function __construct($args)
28 {
30
31 // Step 0: Delete the existing bearsampp.ini file
32 $iniFilePath = $bearsamppRoot->getIniFilePath();
33
34 if (file_exists($iniFilePath)) {
35 unlink($iniFilePath);
36 }
37
38 // Process and update the bearsampp.ini file
39 // Step 1: Prepare the configuration content
40 $configContent = <<<EOD
41[Config]
42ImageList=sprites.dat
43ServiceCheckInterval=1
44TrayIconAllRunning=16
45TrayIconSomeRunning=17
46TrayIconNoneRunning=18
47ID={Bearsampp}
48AboutHeader=Bearsampp
49AboutVersion=Version @RELEASE_VERSION@
50
51[Services]
52Name: bearsamppapache
53
54[Messages]
55AllRunningHint=All services running
56SomeRunningHint=%n of %t services running
57NoneRunningHint=None of %t services running
58
59[StartupAction]
60Action: run; FileName: "%AeTrayMenuPath%core/libs/php/php-win.exe"; Parameters: "root.php startup"; WorkingDir: "%AeTrayMenuPath%core"; Flags: waituntilterminated
61Action: run; FileName: "%AeTrayMenuPath%core/libs/php/php-win.exe"; Parameters: "root.php reload"; WorkingDir: "%AeTrayMenuPath%core"; Flags: waituntilterminated
62Action: resetservices
63Action: readconfig
64Action: run; FileName: "%AeTrayMenuPath%core/libs/php/php-win.exe"; Parameters: "root.php checkVersion"; WorkingDir: "%AeTrayMenuPath%core"; Flags: waituntilterminated
65Action: run; FileName: "%AeTrayMenuPath%core/libs/php/php-win.exe"; Parameters: "root.php exec"; WorkingDir: "%AeTrayMenuPath%core"
66EOD;
67
68 // Step 2: Write to the file
69 if (file_put_contents($iniFilePath, $configContent) === false) {
70 throw new Exception("Failed to write to bearsampp.ini file.");
71 }
72
73 // Trigger the reload action
74 new ActionReload($args);
75
76 // Get the action reload string and output it
77 $callReload = TplAppReload::getActionReload();
78 echo $callReload;
79 }
80}
global $bearsamppRoot
global $bearsamppCore