diff --git a/lazarus/lib/x86_64-linux/phpgui.o b/lazarus/lib/x86_64-linux/phpgui.o
index c4ead83..4c692ee 100644
Binary files a/lazarus/lib/x86_64-linux/phpgui.o and b/lazarus/lib/x86_64-linux/phpgui.o differ
diff --git a/lazarus/lib/x86_64-linux/phpgui.or b/lazarus/lib/x86_64-linux/phpgui.or
index 5b9e7a0..c63151a 100644
Binary files a/lazarus/lib/x86_64-linux/phpgui.or and b/lazarus/lib/x86_64-linux/phpgui.or differ
diff --git a/lazarus/lib/x86_64-linux/unit1.ppu b/lazarus/lib/x86_64-linux/unit1.ppu
index 1a7f3e7..38b002b 100644
Binary files a/lazarus/lib/x86_64-linux/unit1.ppu and b/lazarus/lib/x86_64-linux/unit1.ppu differ
diff --git a/lazarus/lib/x86_64-linux/unitipcthread.o b/lazarus/lib/x86_64-linux/unitipcthread.o
index 647c641..87f5af8 100644
Binary files a/lazarus/lib/x86_64-linux/unitipcthread.o and b/lazarus/lib/x86_64-linux/unitipcthread.o differ
diff --git a/lazarus/lib/x86_64-linux/unitipcthread.ppu b/lazarus/lib/x86_64-linux/unitipcthread.ppu
index 8b51f9e..e6962cf 100644
Binary files a/lazarus/lib/x86_64-linux/unitipcthread.ppu and b/lazarus/lib/x86_64-linux/unitipcthread.ppu differ
diff --git a/lazarus/phpgui-i386-darwin b/lazarus/phpgui-i386-darwin
index 556d221..7fc9bc0 100755
Binary files a/lazarus/phpgui-i386-darwin and b/lazarus/phpgui-i386-darwin differ
diff --git a/lazarus/phpgui-i386-freebsd b/lazarus/phpgui-i386-freebsd
new file mode 100644
index 0000000..f3a777d
Binary files /dev/null and b/lazarus/phpgui-i386-freebsd differ
diff --git a/lazarus/phpgui-i386-linux b/lazarus/phpgui-i386-linux
new file mode 100644
index 0000000..b8477a9
Binary files /dev/null and b/lazarus/phpgui-i386-linux differ
diff --git a/lazarus/phpgui-i386-win32.exe b/lazarus/phpgui-i386-win32.exe
index e1bb661..a0086fd 100644
Binary files a/lazarus/phpgui-i386-win32.exe and b/lazarus/phpgui-i386-win32.exe differ
diff --git a/lazarus/phpgui-x86_64-darwin b/lazarus/phpgui-x86_64-darwin
new file mode 100644
index 0000000..22e2ba7
Binary files /dev/null and b/lazarus/phpgui-x86_64-darwin differ
diff --git a/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist b/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist
new file mode 100644
index 0000000..3dee426
--- /dev/null
+++ b/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist
@@ -0,0 +1,45 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ phpgui-x86_64-darwin
+ CFBundleName
+ phpgui
+ CFBundleIdentifier
+ com.company.phpgui-x86_64-darwin
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ APPL
+ CFBundleSignature
+ phpg
+ CFBundleShortVersionString
+ 0.1
+ CFBundleVersion
+ 1
+ CSResourcesFileMapped
+
+ CFBundleDocumentTypes
+
+
+ CFBundleTypeRole
+ Viewer
+ CFBundleTypeExtensions
+
+ *
+
+ CFBundleTypeOSTypes
+
+ fold
+ disk
+ ****
+
+
+
+ NSHighResolutionCapable
+
+
+
diff --git a/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo b/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo
new file mode 100644
index 0000000..6f749b0
--- /dev/null
+++ b/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo
@@ -0,0 +1 @@
+APPL????
diff --git a/lazarus/phpgui-x86_64-freebsd b/lazarus/phpgui-x86_64-freebsd
index a889850..2048a67 100755
Binary files a/lazarus/phpgui-x86_64-freebsd and b/lazarus/phpgui-x86_64-freebsd differ
diff --git a/lazarus/phpgui-x86_64-linux b/lazarus/phpgui-x86_64-linux
index 19a61a4..01128ac 100755
Binary files a/lazarus/phpgui-x86_64-linux and b/lazarus/phpgui-x86_64-linux differ
diff --git a/lazarus/phpgui-x86_64-win64.exe b/lazarus/phpgui-x86_64-win64.exe
index af742d0..127a981 100644
Binary files a/lazarus/phpgui-x86_64-win64.exe and b/lazarus/phpgui-x86_64-win64.exe differ
diff --git a/lazarus/phpgui.lpi b/lazarus/phpgui.lpi
index 692b577..fba1686 100644
--- a/lazarus/phpgui.lpi
+++ b/lazarus/phpgui.lpi
@@ -1,10 +1,12 @@
-
+
+
+
+
-
@@ -13,19 +15,66 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
diff --git a/lazarus/phpgui.lps b/lazarus/phpgui.lps
index a2fff4a..1d13e67 100644
--- a/lazarus/phpgui.lps
+++ b/lazarus/phpgui.lps
@@ -1,15 +1,327 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
@@ -20,7 +332,7 @@
-
+
@@ -30,9 +342,9 @@
-
-
-
+
+
+
@@ -44,11 +356,10 @@
-
+
-
@@ -76,14 +387,14 @@
-
+
-
+
@@ -118,17 +429,32 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -154,32 +480,32 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
+
+ -
-
+
diff --git a/lazarus/phpgui.res b/lazarus/phpgui.res
index 1c1de50..ec1c7cc 100644
Binary files a/lazarus/phpgui.res and b/lazarus/phpgui.res differ
diff --git a/lazarus/unitipcthread.pas b/lazarus/unitipcthread.pas
index 89c12b2..efbccf1 100644
--- a/lazarus/unitipcthread.pas
+++ b/lazarus/unitipcthread.pas
@@ -53,6 +53,27 @@ TEventHandler = class(TObject)
implementation
+function Escape(input: string): string;
+var
+ output: string;
+ i: integer;
+begin
+ output := '';
+ i := 0;
+
+ while(i < Length(input)) do
+ begin
+ if (input[i+1] <> '"') AND (input[i+1] <> '\') then
+ begin
+ output := output + input[i+1];
+ end else begin
+ output := output + '\' + input[i+1];
+ end;
+ i := i + 1;
+ end;
+ Escape := output;
+end;
+
procedure TIpcThread.CreateObject;
var obj: TControl;
objClass: TPersistentClass;
@@ -464,7 +485,7 @@ procedure TIpcThread.CallObjectMethod;
end;
messageId := jData.FindPath('id').AsInteger;
- Output('{"id": ' + IntToStr(messageId) + ', "result": "' + strCtrl[0] + '"}');
+ Output('{"id": ' + IntToStr(messageId) + ', "result": "' + Escape(strCtrl[0]) + '"}');
sent := true;
end;
diff --git a/src/Application.php b/src/Application.php
index 23712a3..ff6523b 100644
--- a/src/Application.php
+++ b/src/Application.php
@@ -9,6 +9,7 @@
use Gui\Ipc\Receiver;
use Gui\Ipc\Sender;
use Gui\OsDetector;
+use http\Exception\RuntimeException;
use React\ChildProcess\Process;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
@@ -267,33 +268,13 @@ public function run()
$application = $this;
- if (OsDetector::isMacOS()) {
- $processName = './phpgui-i386-darwin';
- $processPath = __DIR__ . '/../lazarus/phpgui-i386-darwin.app/Contents/MacOS/';
- } elseif (OsDetector::isFreeBSD()) {
- $processName = './phpgui-x86_64-freebsd';
- $processPath = __DIR__ . '/../lazarus/';
- } elseif (OsDetector::isUnix()) {
- switch(OsDetector::systemArchitecture()) {
- case 'x86_64':
- $processName = './phpgui-x86_64-linux';
- break;
- case 'i686':
- case 'i586':
- case 'i386':
- $processName = './phpgui-i386-linux';
- break;
- default:
- throw new \RuntimeException('Operational System architecture not identified by PHP-GUI.');
- break;
- }
- $processPath = __DIR__ . '/../lazarus/';
- } elseif (OsDetector::isWindows()) {
- $processName = '.\\phpgui-x86_64-win64';
- $processPath = __DIR__ . '\\..\\lazarus\\';
- } else {
- throw new \RuntimeException('Operational System not identified by PHP-GUI.');
- }
+ $processName = $this->getProcessName();
+ $processPath = $this->getProcessPath();
+
+ $binPath = rtrim($processPath, "/\\") . DIRECTORY_SEPARATOR . ltrim($processName, ".\\/");
+ if (!file_exists(realpath($binPath))) {
+ throw new \RuntimeException("Correct binary cannot be found (checked $binPath) by PHP-GUI.");
+ }
$this->process = $process = new Process($processName, $processPath);
@@ -487,4 +468,67 @@ public function isRunning()
return $this->running;
}
+
+ /**
+ * Returns Lazarus process path, using correct slashes for current platform.
+ *
+ * @return string
+ */
+ private function getProcessPath()
+ {
+ if (OsDetector::isWindows()) {
+ return __DIR__ . '\\..\\lazarus\\';
+ } elseif (OsDetector::isMacOS()) {
+ return __DIR__ . '/../lazarus/phpgui-' . $this->getProcessArchId() .'-darwin.app/Contents/MacOS/';
+ } else {
+ return __DIR__ . '/../lazarus/';
+ }
+ }
+
+ /**
+ * Returns Lazarus process name, selecting current platform.
+ *
+ * @return string
+ */
+ private function getProcessName()
+ {
+ $arch = $this->getProcessArchId();
+ $proc = "phpgui-" . $arch . "-";
+ // mac, bsd, unix, windows
+ if (OsDetector::isMacOS()) {
+ return $proc . "darwin";
+ } elseif (OsDetector::isFreeBSD()) {
+ return $proc . "freebsd";
+ } elseif (OsDetector::isUnix()) {
+ return $proc . "linux";
+ } elseif (OsDetector::isWindows()) {
+ if ($arch === "x86_64") {
+ return $proc . "win64.exe";
+ } else {
+ return $proc . "win32.exe";
+ }
+ } else {
+ throw new \RuntimeException('Operational System not identified by PHP-GUI.');
+ }
+ }
+
+ /**
+ * Returns processor architecture in such manner, that it fits file names (returns 'x86_64' or 'i386')
+ *
+ * @return string
+ */
+ private function getProcessArchId()
+ {
+ switch (OsDetector::systemArchitecture()) {
+ case 'AMD64':
+ case 'x86_64':
+ return 'x86_64';
+ case 'i686':
+ case 'i586':
+ case 'i386':
+ return 'i386';
+ default:
+ throw new \RuntimeException('Operational System architecture not identified by PHP-GUI.');
+ }
+ }
}