forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
uMainForm.pas
233 lines (206 loc) · 5.79 KB
/
uMainForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
unit uMainForm;
{$I 'sDef.inc'}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExeMod, EncdDecd, mdsUtils,
ZENDTypes, zendAPI , System.NetEncoding
{$IFDEF ADD_CHROMIUM},guiChromium{$ENDIF}
{$IFDEF ADD_SKINS}
,sSkinProvider, sSkinManager,
sSpeedButton, sBitBtn, acProgressBar, sTrackBar, sBevel, sLabel
{$ENDIF};
type
T__mainForm = class(TForm)
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMHotKey(var Msg: TMessage); message WM_HOTKEY;
procedure WndProc(var Msg: TMessage); message WM_COPYDATA;
end;
var
__mainForm: T__mainForm;
selfScript: zend_ustr = '';
selfConfig: zend_ustr = '';
selfFinalize: boolean = False;
selfEnabled: boolean = False;
dllPHPPath: zend_ustr = '';
implementation
uses uMain, uPHPMod;
{$R *.dfm}
{
procedure parse_ini();
var
x, rreal: string;
key, value: zend_ustr;
function parseval(val: string):string;
begin
Result := val;
if Result.Contains(';') then
Result := Result.Substring(0, val.IndexOf(';'));
if Result.ToLower.Trim = 'on' then
Result := '1'
else if Result.ToLower.Trim = 'off' then
Result := '0';
end;
begin
for x in selfConfig.Split([#10]) do
begin
rreal := x.Replace(' ', '');
if rreal.IsEmpty or ( rreal.Chars[0] = ';')
or (rreal.Chars[0] = '[') then continue;
key := zend_ustr(rreal.Substring( 0, rreal.IndexOf('=') ));
value := zend_ustr(parseval(
rreal.Substring(rreal.IndexOf('=')+1).DeQuotedString('"').DeQuotedString('''')
));
zend_alter_ini_entry(
zend_pchar(key), Length(key),
zend_pchar(value), Length(value),
ZEND_INI_ALL, ZEND_INI_STAGE_RUNTIME);
end;
end;}
procedure T__mainForm.FormActivate(Sender: TObject);
var
f: string;
begin
if appShow then
exit;
appShow := True;
{$IFDEF LOAD_DS}
f := ExtractFilePath(ParamStr(0)) + 'system\include.pse';
{$ELSE}
f := ParamStr(1);
{$ENDIF}
if selfEnabled then
begin
__fMain.n.Destroy;
__fMain.b_R0.Destroy;
__fMain.b_R1.Destroy;
__fMain.fr.Destroy;
__fMain.sd.Destroy;
__fMain.od.Destroy;
__fMain.M1.Destroy;
__fMain.Width := 0;
__fMain.Height := 0;
__fMain.BorderStyle := bsNone;
phpMOD.RunCode(selfScript);
if selfConfig <> '' then
selfEnabled := True;
appShow := True;
end
else if ExtractFileExt(f) = '.pse' then
begin
phpMOD.RunFile(f);
end
else if
((ParamStr(1) = '-t') or (ParamStr(1) = '-test'))
and
(selfScript = '')
and
FileExists(ExtractFilePath(ParamStr(0)) + '/tests/-t.php')
then
begin
phpMOD.RunFile(ExtractFilePath(ParamStr(0)) + '/tests/-t.php');
Application.Terminate;
end
else if ParamStr(1) <> '-run' then
begin
uPHPMod.SetAsMainForm(__fMain);
Application.ShowMainForm := True;
Application.MainFormOnTaskBar := True;
end
else
phpMOD.RunFile(ParamStr(2));
appShow := True;
end;
procedure extractPHPEngine(EM: TExeStream;salt:string);
label 1;
begin
if (selfConfig <> '') then
begin
selfFinalize := True;
iniDir := AnsiString(String(TempDir) + '\PSE30\' + salt + '\');
if FileExists(string(iniDir) + 'php.ini') then
if (File2String(zend_ustr(string(iniDir) + 'php.ini')) = selfConfig) then goto 1;
ForceDirectories(String(iniDir));
String2File2(selfConfig, zend_ustr(iniDir + 'php.ini'));
1:
selfConfig := '';
end;
end;
procedure T__mainForm.FormCreate(Sender: TObject);
var
f: string;
EM: TExeStream;
begin
Self.Left := -999;
{$IFDEF LOAD_DS}
f := ExtractFilePath(ParamStr(0)) + 'system\include.pse';
{$ELSE}
f := ParamStr(1);
{$ENDIF}
selfScript := '';
EM := TExeStream.Create(ParamStr(0));
progDir := AnsiString(ExtractFilePath(Application.ExeName));
moduleDir := progDir + 'ext\';
if DirectoryExists(string(progDir) + 'core\') then
engineDir := progDir + 'core\';
selfScript := zend_ustr(EM.ExtractToString('$PHPSOULENGINE\inc.php'));
if (selfScript <> '') then
begin
selfConfig := zend_ustr(EM.ExtractToString('$PHPSOULENGINE\php.ini'));
selfEnabled := True;
extractPHPEngine(EM
, EncodeString( ExtractFileName(Application.ExeName).Replace('.', '', [rfReplaceAll])
+ 'erkr') );
end;
if (ExtractFileExt(f) = '.pse') and (selfScript = '') then
begin
if pos(':', f) > 0 then
progDir := AnsiString(ExtractFilePath(f))
else
progDir := progDir + AnsiString(ExtractFilePath(f));
end
else if selfScript <> '' then
progDir := AnsiString(ExtractFilePath(ParamStr(0)));
EM.Destroy;
{$IFDEF ADD_CHROMIUM}
LoadChromium;
{$ENDIF}
end;
procedure T__mainForm.FormDestroy(Sender: TObject);
begin
if FileExists(String(iniDir) + 'php.ini') and selfFinalize then
begin
DeleteFile(String(iniDir) + 'php.ini');
RemoveDir(String(iniDir));
RemoveDir(String(TempDir) + '\PSE30\');
end;
end;
procedure T__mainForm.WndProc(var Msg: TMessage);
var
pcd: PCopyDataStruct;
s: zend_ustr;
begin
inherited;
pcd := PCopyDataStruct(Msg.LParam);
s := zend_pchar(pcd.lpData);
phpMOD.RunCode('Receiver::event(' + zend_ustr(IntToStr(Msg.WParam)) + ',''' +
AddSlashesA(s) + ''');');
end;
procedure T__mainForm.WMHotKey(var Msg: TMessage);
var
fuModifiers: word;
uVirtKey: word;
begin
fuModifiers := LOWORD(Msg.LParam);
uVirtKey := HIWORD(Msg.LParam);
phpMOD.RunCode(zend_ustr('HotKey::event(' + IntToStr(fuModifiers) + ',' +
IntToStr(uVirtKey) + ');'));
inherited;
end;
end.