|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace VoidEngine;
|
|
4
|
|
|
|
|
5
|
|
|
use VoidBuilder\Builder;
|
|
6
|
|
|
|
|
7
|
|
|
class VoidStudioBuilder
|
|
8
|
|
|
{
|
|
9
|
|
|
public static function compileProject (string $save, string $enteringPoint, array $references, array $settings = [], bool $printSuccessCompile = false, bool $debug = false): array
|
|
10
|
|
|
{
|
|
11
|
|
|
$savePath = dirname ($save) .'/'. basenameNoExt ($save);
|
|
|
|
|
|
|
12
|
|
|
$globalCode = file_get_contents (APP_DIR .'/system/presets/compile_parser_preset.cs') ."\n\n";
|
|
13
|
|
|
$objectsCode = '';
|
|
14
|
|
|
$forms = [];
|
|
15
|
|
|
|
|
16
|
|
|
for ($i = 0; $i < 5; ++$i)
|
|
17
|
|
|
if (!isset ($settings[$i]) || !strlen (trim ($settings[$i])))
|
|
18
|
|
|
$settings[$i] = null;
|
|
19
|
|
|
|
|
20
|
|
|
$settings = array_slice ($settings, 0, 5);
|
|
21
|
|
|
|
|
22
|
|
|
foreach (VoidStudioAPI::getObjects ('main')['Designer__FormsList']->items->names as $id => $item)
|
|
23
|
|
|
{
|
|
24
|
|
|
$designer = VoidStudioAPI::getObjects ('main')['Designer__'. $item .'Designer'];
|
|
|
|
|
|
|
25
|
|
|
$globalCode .= self::appendDesignerData ($designer->getSharpCode ($item), $designer);
|
|
26
|
|
|
|
|
27
|
|
|
$forms[] = $item;
|
|
28
|
|
|
|
|
29
|
|
|
if (!isset (VoidStudioAPI::$events[$item]))
|
|
30
|
|
|
VoidStudioAPI::$events[$item] = "class $item extends Form\n{}\n";
|
|
31
|
|
|
|
|
32
|
|
|
if (isset (VoidStudioAPI::$events[$item]))
|
|
33
|
|
|
$objectsCode .= ClassWorker::applyClass (VoidStudioAPI::$events[$item], $item, substr ($voidCode = $designer->getVoidCode ($item, false), $pos = strpos ($voidCode, '{') + 1, strrpos ($voidCode, '}') - $pos - 1) ."\n") ."\n\n";
|
|
34
|
|
|
}
|
|
35
|
|
|
|
|
36
|
|
|
dir_clean ($savePath);
|
|
|
|
|
|
|
37
|
|
|
dir_copy (CORE_DIR, $savePath);
|
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
unlink ($savePath .'/script.php');
|
|
40
|
|
|
unlink ($savePath .'/VoidCore.exe');
|
|
41
|
|
|
|
|
42
|
|
|
$errors = EngineAdditions::compile ($savePath .'/'. basename ($save), APP_DIR .'/system/icons/Icon.ico', self::optimizeCode (str_replace_assoc (file_get_contents (APP_DIR .'/system/presets/compile_main_preset.php'), [
|
|
|
|
|
|
|
43
|
|
|
'%VoidEngine%' => self::generateCode ($references),
|
|
44
|
|
|
|
|
45
|
|
|
'%modules%' => (file_exists ($modulesFile = VoidStudioProjectManager::$projectPath .'/modules/Qero.json') && sizeof ($modules = json_decode (file_get_contents ($modulesFile))) ? "require 'qero-packages/autoload.php';\n\n" : "\n\n") . implode ("\n", array_map (function ($module)
|
|
|
|
|
|
|
46
|
|
|
{
|
|
47
|
|
|
$module = trim (file_get_contents ($module));
|
|
48
|
|
|
|
|
49
|
|
|
if (substr ($module, 0, 2) == '<?')
|
|
50
|
|
|
$module = substr ($module, 2);
|
|
51
|
|
|
|
|
52
|
|
|
if (substr ($module, 0, 3) == 'php')
|
|
53
|
|
|
$module = substr ($module, 3);
|
|
54
|
|
|
|
|
55
|
|
|
if (substr ($module, -2) == '?>')
|
|
56
|
|
|
$module = substr ($module, 0, -2);
|
|
57
|
|
|
|
|
58
|
|
|
return "\$module = <<<'__MODULE'\n". self::optimizeCode ($module) ."\n__MODULE;\n\neval (\$module);";
|
|
59
|
|
|
}, array_merge (glob (VoidStudioProjectManager::$projectPath .'/modules/*.php'), $debug ? [APP_DIR .'/system/debug/DebugHook.php'] : []))),
|
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
'%objects%' => trim ($objectsCode),
|
|
62
|
|
|
'%forms%' => join ('\', \'', $forms),
|
|
63
|
|
|
'%entering_point%' => $enteringPoint,
|
|
64
|
|
|
'%author_id%' => sha1 (shell_exec ('wmic csproduct'))
|
|
65
|
|
|
])), $settings[0], $settings[1], $settings[2], $settings[3], $settings[4], /*str_replace_assoc (file_get_contents (APP_DIR .'/system/presets/compile_main_preset.cs'), [
|
|
66
|
|
|
'%forms%' => join ('", "', $forms)
|
|
67
|
|
|
])*/'', $globalCode);
|
|
68
|
|
|
|
|
69
|
|
|
if (isset ($modules) && sizeof ($modules) > 0)
|
|
70
|
|
|
{
|
|
71
|
|
|
dir_delete (APP_DIR .'/Qero/qero-packages');
|
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$manager = new \Qero\PackagesManager\PackagesManager;
|
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
foreach ($modules as $package)
|
|
76
|
|
|
$manager->installPackage ($package);
|
|
77
|
|
|
|
|
78
|
|
|
dir_copy (APP_DIR .'/Qero/qero-packages', $savePath .'/qero-packages');
|
|
79
|
|
|
dir_delete (APP_DIR .'/Qero/qero-packages');
|
|
80
|
|
|
}
|
|
81
|
|
|
|
|
82
|
|
|
// pre ($errors);
|
|
83
|
|
|
// pre ($globalCode->toString ());
|
|
84
|
|
|
|
|
85
|
|
|
$log = VoidStudioAPI::getObjects ('main')['ToolsPanel__LogList'];
|
|
86
|
|
|
$log->items->add ('Проект скомпилирован по пути "'. $save .'". '. (($errorsCount = sizeof ($errors)) > 0 ? ('Обнаружено '. $errorsCount .' ошибок') : 'Ошибок не обнаружено'));
|
|
87
|
|
|
|
|
88
|
|
|
if ($errorsCount > 0)
|
|
89
|
|
|
{
|
|
90
|
|
|
$log->items->addRange (array_map (function ($error)
|
|
91
|
|
|
{
|
|
92
|
|
|
return "\t". $error;
|
|
93
|
|
|
}, $errors));
|
|
94
|
|
|
|
|
95
|
|
|
messageBox ('Обнаружено '. $errorsCount .' ошибок', 'Ошибка компиляции', enum ('System.Windows.Forms.MessageBoxButtons.OK'), enum ('System.Windows.Forms.MessageBoxIcon.Error'));
|
|
|
|
|
|
|
96
|
|
|
}
|
|
97
|
|
|
|
|
98
|
|
|
elseif ($printSuccessCompile)
|
|
99
|
|
|
messageBox ('Проект успешно скомпилирован', 'Успешная компиляция', enum ('System.Windows.Forms.MessageBoxButtons.OK'), enum ('System.Windows.Forms.MessageBoxIcon.Information'));
|
|
100
|
|
|
|
|
101
|
|
|
return $errors;
|
|
102
|
|
|
}
|
|
103
|
|
|
|
|
104
|
|
|
public static function appendDesignerData (string $code, VoidDesigner $designer): string
|
|
|
|
|
|
|
105
|
|
|
{
|
|
106
|
|
|
$offset = 0;
|
|
107
|
|
|
|
|
108
|
|
|
while (($pos = strpos ($code, ')(resources.GetObject("', $offset)) !== false)
|
|
109
|
|
|
{
|
|
110
|
|
|
$offset = $pos + 23;
|
|
111
|
|
|
$property = explode ('.', substr ($code, $offset, ($end = strpos ($code, '")));', $offset)) - $offset));
|
|
112
|
|
|
|
|
113
|
|
|
$object = $property[0] == '$this' ?
|
|
114
|
|
|
$designer->form->selector :
|
|
115
|
|
|
$designer->getComponentByName ($property[0]);
|
|
116
|
|
|
|
|
117
|
|
|
foreach (array_slice ($property, 1) as $path)
|
|
118
|
|
|
$object = \VoidCore::getProperty ($object, $path);
|
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
$code = str_replace (substr ($code, $pos + 2, $end - $pos), 'WinForms_PHP.ZendProgram.getResource ("'. \VoidCore::exportObject ($object) .'")', $code);
|
|
121
|
|
|
}
|
|
122
|
|
|
|
|
123
|
|
|
return $code;
|
|
124
|
|
|
}
|
|
125
|
|
|
|
|
126
|
|
|
public static function generateCode (array $references, bool $removeNamespaces = true): string
|
|
127
|
|
|
{
|
|
128
|
|
|
return Builder::generateCode ($references, $removeNamespaces);
|
|
129
|
|
|
}
|
|
130
|
|
|
|
|
131
|
|
|
public static function getReferences (string $file, bool $parseExtensions = true): array
|
|
132
|
|
|
{
|
|
133
|
|
|
return Builder::getReferences ($file, $parseExtensions);
|
|
134
|
|
|
}
|
|
135
|
|
|
|
|
136
|
|
|
public static function optimizeCode (string $code): string
|
|
137
|
|
|
{
|
|
138
|
|
|
return Builder::optimizeCode ($code);
|
|
139
|
|
|
}
|
|
140
|
|
|
}
|
|
141
|
|
|
|