Rev 45 | Rev 61 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 45 | Rev 49 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | Windows, SysUtils, StrUtils, Dialogs, IniFiles, Classes, Forms, ShellAPI; |
6 | Windows, SysUtils, StrUtils, Dialogs, IniFiles, Classes, Forms, ShellAPI; |
7 | 7 | ||
8 | const |
8 | const |
9 | FASTPHP_GOTO_URI_PREFIX = 'fastphp://editor/gotoline/'; |
9 | FASTPHP_GOTO_URI_PREFIX = 'fastphp://editor/gotoline/'; |
10 | 10 | ||
11 | function FastPHPConfig: TMemIniFile; |
- | |
12 | function GetPHPExe: string; |
11 | function GetPHPExe: string; |
13 | function RunPHPScript(APHPFileName: string; lint: boolean=false; inConsole: boolean=False): string; |
12 | function RunPHPScript(APHPFileName: string; lint: boolean=false; inConsole: boolean=False): string; |
14 | function ParseCHM(const chmFile: TFileName): boolean; |
13 | function ParseCHM(const chmFile: TFileName): boolean; |
15 | function IsValidPHPExe(const exeFile: TFileName): boolean; |
14 | function IsValidPHPExe(const exeFile: TFileName): boolean; |
16 | 15 | ||
17 | implementation |
16 | implementation |
18 | 17 | ||
19 | uses |
18 | uses |
20 | Functions; |
- | |
21 | - | ||
22 | var |
- | |
23 | __FastPHPConfig: TMemIniFile; |
- | |
24 | - | ||
25 | function FastPHPConfig: TMemIniFile; |
- | |
26 | begin |
- | |
27 | if not Assigned(__FastPHPConfig) then |
- | |
28 | begin |
- | |
29 | __FastPHPConfig := TMemIniFile.Create(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + 'FastPHP.ini'); |
- | |
30 | end; |
- | |
31 | result := __FastPHPConfig; |
19 | Functions, FastPHPConfig; |
32 | end; |
- | |
33 | 20 | ||
34 | function GetPHPExe: string; |
21 | function GetPHPExe: string; |
35 | var |
22 | var |
36 | od: TOpenDialog; |
23 | od: TOpenDialog; |
37 | begin |
24 | begin |
38 | result := FastPHPConfig.ReadString('Paths', 'PHPInterpreter', ''); |
25 | result := TFastPHPConfig.PhpInterpreter; |
39 | if not FileExists(result) then |
26 | if not FileExists(result) then |
40 | begin |
27 | begin |
41 | od := TOpenDialog.Create(nil); |
28 | od := TOpenDialog.Create(nil); |
42 | try |
29 | try |
43 | od.DefaultExt := '.exe'; |
30 | od.DefaultExt := '.exe'; |
44 | od.FileName := 'php.exe'; |
31 | od.FileName := 'php.exe'; |
45 | od.Filter := 'Executable file (*.exe)|*.exe'; |
32 | od.Filter := 'Executable file (*.exe)|*.exe'; |
46 | od.Options := [ofReadOnly, ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]; |
33 | od.Options := [ofReadOnly, ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]; |
47 | od.Title := 'Please chose your PHP interpreter (php.exe)'; |
34 | od.Title := 'Please choose your PHP interpreter (php.exe)'; |
48 | 35 | ||
49 | if not od.Execute then exit; |
36 | if not od.Execute then exit; |
50 | if not FileExists(od.FileName) then exit; |
37 | if not FileExists(od.FileName) then exit; |
51 | result := od.FileName; |
38 | result := od.FileName; |
52 | finally |
39 | finally |
53 | od.Free; |
40 | od.Free; |
54 | end; |
41 | end; |
55 | 42 | ||
56 | if not IsValidPHPExe(result) then |
43 | if not IsValidPHPExe(result) then |
57 | begin |
44 | begin |
58 | ShowMessage('This is not a valid PHP executable.'); |
45 | MessageDlg('This is not a valid PHP executable.', mtError, [mbOk], 0); |
59 | exit; |
46 | exit; |
60 | end; |
47 | end; |
61 | 48 | ||
62 | FastPHPConfig.WriteString('Paths', 'PHPInterpreter', result); |
49 | TFastPHPConfig.PhpInterpreter := result; |
63 | FastPHPConfig.UpdateFile; |
- | |
64 | end; |
50 | end; |
65 | end; |
51 | end; |
66 | 52 | ||
67 | function RunPHPScript(APHPFileName: string; lint: boolean=false; inConsole: boolean=False): string; |
53 | function RunPHPScript(APHPFileName: string; lint: boolean=false; inConsole: boolean=False): string; |
68 | var |
54 | var |
Line 229... | Line 215... | ||
229 | cont := LoadFileToStr(exeFile); |
215 | cont := LoadFileToStr(exeFile); |
230 | result := (Pos('php://stdout', cont) >= 0) or |
216 | result := (Pos('php://stdout', cont) >= 0) or |
231 | (Pos('PHP_SELF', cont) >= 0); |
217 | (Pos('PHP_SELF', cont) >= 0); |
232 | end; |
218 | end; |
233 | 219 | ||
234 | initialization |
- | |
235 | finalization |
- | |
236 | if Assigned(__FastPHPConfig) then |
- | |
237 | begin |
- | |
238 | __FastPHPConfig.UpdateFile; |
- | |
239 | FreeAndNil(__FastPHPConfig); |
- | |
240 | end; |
- | |
241 | end. |
220 | end. |