-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.pas
357 lines (264 loc) · 7.99 KB
/
Main.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
unit Main;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, ComCtrls, Edit, Config,
Help, ShellApi, FileCtrl;
type
TMainForm = class(TForm)
MainMenu: TMainMenu;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
FilePrintItem: TMenuItem;
FilePrintSetupItem: TMenuItem;
FileExitItem: TMenuItem;
EditUndoItem: TMenuItem;
EditCutItem: TMenuItem;
EditCopyItem: TMenuItem;
EditPasteItem: TMenuItem;
WindowTileItem: TMenuItem;
WindowCascadeItem: TMenuItem;
WindowArrangeItem: TMenuItem;
HelpContentsItem: TMenuItem;
HelpSearchItem: TMenuItem;
HelpHowToUseItem: TMenuItem;
HelpAboutItem: TMenuItem;
StatusLine: TStatusBar;
OpenDialog: TOpenDialog; { &About... }
procedure FormCreate(Sender: TObject);
procedure ShowHint(Sender: TObject);
// procedure FileNew(Sender: TObject);
procedure FileOpen(Sender: TObject);
procedure FileSave(Sender: TObject);
procedure FileExit(Sender: TObject);
procedure EditUndo(Sender: TObject);
procedure EditCut(Sender: TObject);
procedure EditCopy(Sender: TObject);
procedure EditPaste(Sender: TObject);
procedure WindowTile(Sender: TObject);
procedure WindowCascade(Sender: TObject);
procedure WindowArrange(Sender: TObject);
procedure HelpContents(Sender: TObject);
procedure HelpSearch(Sender: TObject);
procedure HelpHowToUse(Sender: TObject);
procedure HelpAbout(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure NewEditForm (is_php: boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
path: String;
ConfigForm: TConfigForm;
FormHelp: TFormHelp;
end;
var
MainForm: TMainForm;
implementation
{$r *.dfm}
procedure TMainForm.NewEditForm;
var
NewForm: TEditForm;
begin
Application.CreateForm (TEditForm, NewForm);
NewForm.Init (path, StatusLine, is_php);
NewForm.ConfigForm := ConfigForm;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnHint := ShowHint;
end;
procedure TMainForm.ShowHint(Sender: TObject);
begin
StatusLine.SimpleText := Application.Hint;
end;
//procedure TMainForm.FileNew(Sender: TObject);
//begin
// NewEditForm;
//end;
procedure TMainForm.FileOpen(Sender: TObject);
begin
if OpenDialog.Execute then
begin
{ Add code to open OpenDialog.FileName }
end;
end;
procedure TMainForm.FileSave(Sender: TObject);
begin
TEditForm (ActiveMDIChild).SaveFile;
end;
procedure TMainForm.FileExit(Sender: TObject);
begin
Close;
end;
procedure TMainForm.EditUndo(Sender: TObject);
begin
{ Add code to perform Edit Undo }
end;
procedure TMainForm.EditCut(Sender: TObject);
begin
{ Add code to perform Edit Cut }
end;
procedure TMainForm.EditCopy(Sender: TObject);
begin
{ Add code to perform Edit Copy }
end;
procedure TMainForm.EditPaste(Sender: TObject);
begin
{ Add code to perform Edit Paste }
end;
procedure TMainForm.WindowTile(Sender: TObject);
begin
Tile;
end;
procedure TMainForm.WindowCascade(Sender: TObject);
begin
Cascade;
end;
procedure TMainForm.WindowArrange(Sender: TObject);
begin
ArrangeIcons;
end;
procedure TMainForm.HelpContents(Sender: TObject);
begin
Application.HelpCommand(HELP_CONTENTS, 0);
end;
procedure TMainForm.HelpSearch(Sender: TObject);
const
EmptyString: PChar = '';
begin
Application.HelpCommand(HELP_PARTIALKEY, Longint(EmptyString));
end;
procedure TMainForm.HelpHowToUse(Sender: TObject);
begin
Application.HelpCommand(HELP_HELPONHELP, 0);
end;
procedure TMainForm.HelpAbout(Sender: TObject);
begin
{ Add code to show program's About Box }
end;
procedure TMainForm.FormShow(Sender: TObject);
var
p: integer;
is_php: boolean;
FileName: string;
ssh_file: textfile;
ssh_address: string;
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;
Drive: char;
DirPart, FilePart: string;
begin
case ParamCount of
0: begin
if not OpenDialog.Execute then begin
Close;
Exit;
end;
FileName := OpenDialog.FileName;
end;
1: begin
FileName := ParamStr (1);
end;
else begin
Application.MessageBox ('Only 0 or 1 parameters accepted', 'Wrong parameters', MB_OK);
Close;
Exit;
end;
end;
path := LowerCase(FileName);
if not FileExists (path) then begin
Application.MessageBox (PChar (path + ' not found' ), 'Wrong location', MB_OK);
Close;
Exit;
end;
p := pos ('.elnk', path);
ProcessPath (path, Drive, DirPart, FilePart);
ssh_address := '';
if p > 0 then begin
StartInString := Drive + ':\' + DirPart;
assignfile (ssh_file, path);
reset (ssh_file);
readln(ssh_file, ssh_address);
closefile (ssh_file);
ExecuteFile := 'c:\Program Files\Putty\pscp.exe';
ParamString := '-r -C -scp ' + ssh_address + '/lib ..';
FillChar (SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf (TShellExecuteInfo);
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar (ExecuteFile);
lpParameters := PChar (ParamString);
lpDirectory := PChar (StartInString);
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
Application.ProcessMessages;
GetExitCodeProcess (SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
end
else
begin
ShowMessage ('Can''t copy files with pscp!');
Close;
Exit;
end;
path := StringReplace (path, FilePart, 'config.pm', []);
FileName := 'config.pm';
if not fileexists(path) then begin
FileName := 'config.php';
StringReplace (path, FilePart, 'config.php', []);
end;
if not fileexists(path) then begin
ShowMessage ('Config.p[m|hp] not found');
Close;
Exit;
end;
end;
p := pos ('\config.pm', path);
is_php := false;
if p = 0 then begin
is_php := true;
p := pos ('\config.php', path);
end;
if p = 0 then begin
Application.MessageBox (PChar(path + ' is not Config.p[m|hp]'), 'Wrong file name', MB_OK);
Close;
Exit;
end;
path := copy (path, 1, p - 1);
if not DirectoryExists (path + '\Content') then begin
Application.MessageBox (PChar (path + '\Content not found' ), 'Wrong location', MB_OK);
Close;
Exit;
end;
if not DirectoryExists (path + '\Presentation') then begin
Application.MessageBox (PChar (path + '\Presentation not found' ), 'Wrong location', MB_OK);
Close;
Exit;
end;
Application.CreateForm (TConfigForm, ConfigForm);
ConfigForm.Init (FileName, StatusLine, is_php, ssh_address);
NewEditForm (is_php);
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Shift = [ssCtrl] then case Key of
ord ('S'): FileSave (nil);
end;
// if Shift = [] then case Key of
// VK_F1: FormHelp.ShowModal;
// end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
i: integer;
begin
for i := MDIChildCount - 1 downto 0 do self.MDIChildren [i].Close;
end;
end.