-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUMake_FormMain.pas
1019 lines (813 loc) · 30.4 KB
/
UMake_FormMain.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit UMake_FormMain;
interface
uses
UMake_Configuration, UMake_Options,
Windows, Messages, SysUtils, SysTools, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, FileCtrl, RegExpr, Math;
(*****************************************************************************)
(* TInfoError
(*****************************************************************************)
type
TInfoError = class
private
FTextMessageFormatted: string;
FTextExplanation: string;
function GetTextMessageFormatted: string;
function GetTextExplanation: string;
public
IndexLine: Integer;
TextFile: string;
TextMessage: string;
property TextMessageFormatted: string read GetTextMessageFormatted;
property TextExplanation: string read GetTextExplanation;
end;
(*****************************************************************************)
(* TFormMain
(*****************************************************************************)
type
TFormMain = class(TForm)
ButtonAbort: TButton;
ButtonDetails: TButton;
ButtonErrorEdit: TButton;
ButtonOptions: TButton;
ButtonWarningEdit: TButton;
ButtonWarningNext: TButton;
ButtonWarningPrev: TButton;
ImageError: TImage;
ImageWarning: TImage;
LabelErrorLocation: TLabel;
LabelErrorTitle: TLabel;
LabelWarningLocation: TLabel;
LabelWarningNumber: TLabel;
LabelWarningTitle: TLabel;
PageControlDetails: TPageControl;
ProgressBar: TProgressBar;
RichEditError: TRichEdit;
RichEditMessages: TRichEdit;
RichEditWarning: TRichEdit;
StaticTextProgress: TStaticText;
TabSheetError: TTabSheet;
TabSheetMessages: TTabSheet;
TabSheetWarnings: TTabSheet;
ButtonRebuild: TButton;
procedure FormShow(Sender: TObject);
procedure ButtonAbortClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ButtonOptionsClick(Sender: TObject);
procedure ButtonDetailsClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure ButtonErrorEditClick(Sender: TObject);
procedure ButtonWarningPrevClick(Sender: TObject);
procedure ButtonWarningNextClick(Sender: TObject);
procedure TabSheetWarningsResize(Sender: TObject);
procedure TabSheetErrorResize(Sender: TObject);
private
Configuration: TConfiguration;
Options: TOptions;
IndexWarning: Integer;
InfoError: TInfoError;
ListInfoWarning: TList;
FlagClosing: Boolean;
PipedProcess: TPipedProcess;
RegExprClass: TRegExpr;
RegExprCompiling: TRegExpr;
RegExprCompleted: TRegExpr;
RegExprPackage: TRegExpr;
RegExprParsing: TRegExpr;
RegExprErrorCompile: TRegExpr;
RegExprErrorParse: TRegExpr;
RegExprWarningCompile: TRegExpr;
RegExprWarningParse: TRegExpr;
TextBufferPipe: string;
TextFilePackageBackup: string;
TextFilePackageOriginal: string;
procedure ErrorMessageBox(TextMessage: string; OptionsMessage: Integer = MB_ICONERROR);
procedure ErrorDetails(InfoError: TInfoError; LabelLocation: TLabel; RichEdit: TRichEdit);
procedure PipedProcessDebug(Sender: TObject; const DebugEvent: TDebugEvent; var ContinueStatus: Cardinal);
procedure PipedProcessOutput(Sender: TObject; const TextData: string; Pipe: TPipedOutput);
procedure PipedProcessTerminate(Sender: TObject);
procedure UpdateDetailsError;
procedure UpdateDetailsWarning;
procedure RichEditMessagesAppend(TextAppend: string; ColorAppend: TColor);
public
procedure Startup;
end;
var
FormMain: TFormMain;
implementation
uses
UMake_FormOptions, UMake_FormLaunch;
const
CRLF = #13#10;
{$R *.DFM}
(*****************************************************************************)
(* Global
(*****************************************************************************)
function JoinArray(TextSeparator: string; ArrayStrings: array of string): string;
var
IndexString: Integer;
begin
Result := '';
for IndexString := 0 to High(ArrayStrings) do
begin
AppendStr(Result, ArrayStrings[IndexString]);
if IndexString < High(ArrayStrings) then
AppendStr(Result, TextSeparator);
end;
end;
(*****************************************************************************)
(* TInfoError
(*****************************************************************************)
function TInfoError.GetTextMessageFormatted: string;
begin
if Length(FTextMessageFormatted) = 0 then
begin
FTextMessageFormatted := TextMessage;
FTextMessageFormatted := ReplaceRegExpr('\s+', FTextMessageFormatted, ' ');
FTextMessageFormatted := ReplaceRegExpr('^''|''$', FTextMessageFormatted, '');
FTextMessageFormatted := ReplaceRegExpr('(\W)''|''(\W)', FTextMessageFormatted, '$1$2', True);
FTextMessageFormatted := ReplaceRegExpr('([^.])$', FTextMessageFormatted, '$1.', True);
end;
Result := FTextMessageFormatted;
end;
var
StringListExplanations: TStringList = nil;
function TInfoError.GetTextExplanation: string;
var
IndexCharSeparator: Integer;
IndexExplanation: Integer;
RegExprExplanation: TRegExpr;
TextLineExplanation: string;
TextFileExplanations: string;
begin
if Length(FTextExplanation) = 0 then
begin
if not Assigned(StringListExplanations) then
begin
TextFileExplanations := ChangeFileExt(ParamStr(0), 'Explanations.txt');
StringListExplanations := TStringList.Create;
if FileExists(TextFileExplanations) then
StringListExplanations.LoadFromFile(TextFileExplanations);
end;
RegExprExplanation := TRegExpr.Create;
for IndexExplanation := 0 to StringListExplanations.Count - 1 do
begin
TextLineExplanation := StringListExplanations[IndexExplanation];
IndexCharSeparator := Pos(#9, TextLineExplanation);
if IndexCharSeparator = 0 then
Continue;
try
RegExprExplanation.Expression := Copy(TextLineExplanation, 1, IndexCharSeparator - 1);
if RegExprExplanation.Exec(TextMessageFormatted) then
begin
FTextExplanation := Copy(TextLineExplanation, IndexCharSeparator + 1, Length(TextLineExplanation));
FTextExplanation := ReplaceRegExpr('\\n', FTextExplanation, CRLF);
FTextExplanation := RegExprExplanation.Substitute(FTextExplanation);
Break;
end;
except
on ERegExpr do;
end;
end;
RegExprExplanation.Free;
if Length(FTextExplanation) = 0 then
FTextExplanation := 'Sorry, no further explanation available.';
end;
Result := FTextExplanation;
end;
(*****************************************************************************)
(* TFormMain
(*****************************************************************************)
procedure TFormMain.FormCreate(Sender: TObject);
begin
Options := TOptions.Create;
ImageError .Picture.Icon.Handle := LoadIcon(0, IDI_HAND);
ImageWarning.Picture.Icon.Handle := LoadIcon(0, IDI_EXCLAMATION);
PageControlDetails.ActivePage := TabSheetMessages;
TabSheetError .TabVisible := False;
TabSheetWarnings.TabVisible := False;
StaticTextProgress.DoubleBuffered := True;
ProgressBar .DoubleBuffered := True;
PageControlDetails.DoubleBuffered := True;
Constraints.MaxHeight := Constraints.MinHeight;
end;
procedure TFormMain.Startup;
var
CountFiles: Integer;
DateTimePackage: TDateTime;
DateTimeSource: TDateTime;
FlagAuto: Boolean;
FlagSetup: Boolean;
FlagUpdated: Boolean;
IndexPackage: Integer;
IndexParam: Integer;
IndexProject: Integer;
ResultFindDir: Integer;
ResultFindFile: Integer;
SearchRecDir: TSearchRec;
SearchRecFile: TSearchRec;
TextDirGame: string;
TextDirPackage: string;
TextDirPackageLatest: string;
TextFilePackage: string;
TextFileSource: string;
TextPackage: string;
begin
FlagAuto := False;
FlagSetup := False;
TextFileSource := EmptyStr;
for IndexParam := 1 to ParamCount do
begin
if AnsiSameText(ParamStr(IndexParam), '/setup') then FlagSetup := True
else if AnsiSameText(ParamStr(IndexParam), '/auto') then FlagAuto := True
else if (Length(ParamStr(IndexParam)) > 0) and (ParamStr(IndexParam)[1] <> '/') then
begin
if Length(TextFileSource) = 0 then
begin
TextFileSource := GetLongPath(ParamStr(IndexParam));
if DirectoryExists(TextFileSource) then
TextFileSource := IncludeTrailingBackslash(TextFileSource);
end;
end;
end;
if Length(TextFileSource) = 0 then
begin
if FlagSetup then
begin
FormOptions.Options := Options;
FormOptions.ShowModal;
Close;
end
else if FlagAuto then
begin
Application.MessageBox('Specify the base directory of a game along with the /auto switch to automatically compile the most recently modified project for that game.', PChar(Application.Title), MB_ICONINFORMATION);
Close;
end
else begin
FormLaunch.Options := Options;
if FormLaunch.ShowModal = mrOk
then Configuration := FormLaunch.Configuration
else Close;
end;
end
else begin
if FlagAuto then
begin
TextDirGame := GetLongPath(TextFileSource);
TextFileSource := EmptyStr;
if FileExists(IncludeTrailingBackslash(TextDirGame) + 'System\ucc.exe') then
begin
DateTimeSource := 0.0;
TextDirPackageLatest := EmptyStr;
try
ResultFindDir := FindFirst(IncludeTrailingBackslash(TextDirGame) + '*', faDirectory, SearchRecDir);
while ResultFindDir = 0 do
begin
TextDirPackage := IncludeTrailingBackslash(TextDirGame) + SearchRecDir.Name + '\';
if DirectoryExists(TextDirPackage + 'Classes') then
begin
ResultFindFile := FindFirst(TextDirPackage + 'Classes\*.uc', faAnyFile, SearchRecFile);
while ResultFindFile = 0 do
begin
if DateTimeSource < FileDateToDateTime(SearchRecFile.Time) then
begin
DateTimeSource := FileDateToDateTime(SearchRecFile.Time);
TextDirPackageLatest := TextDirPackage;
end;
ResultFindFile := FindNext(SearchRecFile);
end;
FindClose(SearchRecFile);
end;
ResultFindDir := FindNext(SearchRecDir);
end;
FindClose(SearchRecDir);
except
on EInOutError do;
end;
if Length(TextDirPackageLatest) = 0 then
begin
Application.MessageBox('No project directories with source files found in game directory.', PChar(Application.Title), MB_ICONINFORMATION);
Close;
end
else begin
TextFileSource := TextDirPackageLatest;
end;
end
else begin
Application.MessageBox('Invalid game directory given with /auto switch.', PChar(Application.Title), MB_ICONERROR);
Close;
end;
end;
if Length(TextFileSource) > 0 then
begin
TextDirPackage := ExcludeTrailingBackslash(ExtractFilePath(TextFileSource));
if AnsiSameText(ExtractFileName(TextDirPackage), 'Classes') then
TextDirPackage := ExcludeTrailingBackslash(ExtractFilePath(TextDirPackage));
try
Configuration := TConfiguration.Create(ExtractFileName(TextDirPackage), ExtractFilePath(TextDirPackage));
except
on EConfigurationGameDirNotFound do ErrorMessageBox('Game directory not found for the given file.');
on EConfigurationGameDirInvalid do ErrorMessageBox('UnrealScript project directories must be located directly below the game base directory.');
on EConfigurationPackageDirNotFound do ErrorMessageBox('Package directory not found for the given file.');
on EConfigurationPackageDirInvalid do ErrorMessageBox('UnrealScript project directories must contain a "Classes" subdirectory for UnrealScript source files.');
end;
end;
end;
if Assigned(Configuration) then
begin
try
Configuration.Read;
except
on EConfigurationGameIniNotFound do
begin
ErrorMessageBox('Unable to find the main game configuration file.');
Close;
Exit;
end;
end;
if FlagSetup then
begin
FormOptions.Configuration := Configuration;
FormOptions.Options := Options;
FormOptions.ShowModal;
Close;
end
else begin
Options.RegOptProjects.Value := Configuration.DirPackage;
IndexProject := 0;
while IndexProject < Options.RegOptProjects.ItemCount do
begin
if AnsiCompareText(Configuration.DirPackage, Options.RegOptProjects[IndexProject].Value) <= 0 then Break;
Inc(IndexProject);
end;
if (IndexProject >= Options.RegOptProjects.ItemCount) or not AnsiSameText(Configuration.DirPackage, Options.RegOptProjects[IndexProject].Value) then
begin
Options.RegOptProjects.ItemInsert(IndexProject);
Options.RegOptProjects[IndexProject].Value := Configuration.DirPackage;
end;
if not FileExists(IncludeTrailingBackslash(Configuration.DirGame) + Configuration.Package + '\make.ini') then
begin
FormOptions.Configuration := Configuration;
FormOptions.Options := Options;
if FormOptions.ShowModal <> mrOk then
begin
Close;
Exit;
end;
end;
FlagUpdated := False;
for IndexPackage := 0 to Configuration.StringListPackages.Count - 1 do
begin
TextPackage := Configuration.StringListPackages[IndexPackage];
TextFilePackage := Configuration.FindFilePackage(TextPackage);
if AnsiSameText(TextPackage, Configuration.Package) or (Length(TextFilePackage) = 0) then
begin
CountFiles := 0;
try
if FileExists(TextFilePackage)
then DateTimePackage := FileDateToDateTime(FileAge(TextFilePackage))
else DateTimePackage := 0.0;
ResultFindFile := FindFirst(IncludeTrailingBackslash(Configuration.DirGame) + TextPackage + '\Classes\*.uc', faAnyFile, SearchRecFile);
while ResultFindFile = 0 do
begin
DateTimeSource := FileDateToDateTime(SearchRecFile.Time);
if DateTimeSource > DateTimePackage then
FlagUpdated := True;
Inc(CountFiles);
ResultFindFile := FindNext(SearchRecFile);
end;
FindClose(SearchRecFile);
except
on EInOutError do;
end;
if CountFiles = 0 then
begin
ErrorMessageBox(Format('No valid project directory found for package %s (which requires recompilation).', [TextPackage]));
Close;
Exit;
end;
ProgressBar.Max := ProgressBar.Max + CountFiles * 2;
end
else begin
if not AnsiSameText(ExtractFileExt(TextFilePackage), '.u') then
begin
ErrorMessageBox(Format('Invalid dependency on non-code package %s.', [ExtractFileName(TextFilePackage)]));
Close;
Exit;
end;
ProgressBar.Max := ProgressBar.Max + 1;
end;
end;
if FlagUpdated or (MessageBox(Application.Handle, PChar(Format('Your project, %s, seems to be up to date. Compile anyway?', [Configuration.Package])), PChar(Application.Title), MB_ICONINFORMATION + MB_YESNO) = IDYES)
then Show
else Close;
end;
end
else begin
Close;
end;
end;
procedure TFormMain.ErrorMessageBox(TextMessage: string; OptionsMessage: Integer);
begin
Application.MessageBox(PChar(TextMessage), PChar(Application.Title), OptionsMessage);
end;
procedure TFormMain.ErrorDetails(InfoError: TInfoError; LabelLocation: TLabel; RichEdit: TRichEdit);
var
IndexParagraph: Integer;
RegExprParagraph: TRegExpr;
StringListParagraphs: TStringList;
begin
if Length(InfoError.TextFile) = 0 then
LabelLocation.Caption := 'Occurred before compilation'
else if InfoError.IndexLine = 0 then
LabelLocation.Caption := ExtractFileName(InfoError.TextFile)
else
LabelLocation.Caption := Format('%s (line %d)', [ExtractFileName(InfoError.TextFile), InfoError.IndexLine]);
RichEdit.Lines.BeginUpdate;
RichEdit.Clear;
RichEdit.SelAttributes.Size := RichEditError.Font.Size;
RichEdit.SelAttributes.Style := [];
RichEdit.Paragraph.FirstIndent := 2;
RichEdit.SelText := InfoError.TextMessageFormatted + CRLF;
if Length(InfoError.TextExplanation) > 0 then
begin
RichEdit.SelAttributes.Size := 6;
RichEdit.SelText := CRLF;
RichEdit.SelAttributes.Size := RichEditError.Font.Size;
RichEdit.SelAttributes.Style := [fsBold];
RichEdit.SelText := 'Explanation' + CRLF;
RichEdit.SelAttributes.Style := [];
StringListParagraphs := TStringList.Create;
RegExprParagraph := TRegExpr.Create;
RegExprParagraph.Expression := '(\r?\n)+';
RegExprParagraph.Split(InfoError.TextExplanation, StringListParagraphs);
for IndexParagraph := 0 to StringListParagraphs.Count - 1 do
begin
RichEdit.SelAttributes.Size := 3;
RichEdit.SelText := CRLF;
RichEdit.SelAttributes.Size := RichEditError.Font.Size;
RichEdit.SelText := StringListParagraphs[IndexParagraph];
if IndexParagraph < StringListParagraphs.Count - 1 then
RichEdit.SelText := CRLF;
end;
RichEdit.Perform(WM_VSCROLL, SB_TOP, 0);
StringListParagraphs.Free;
RegExprParagraph.Free;
end;
RichEditError.Lines.EndUpdate;
if ButtonDetails.Enabled then
ButtonDetailsClick(ButtonDetails);
end;
procedure TFormMain.FormShow(Sender: TObject);
var
TextCommand: string;
TextDirSystem: string;
begin
TextFilePackageOriginal := Configuration.FindFilePackage(Configuration.Package);
if Length(TextFilePackageOriginal) > 0 then
begin
TextFilePackageBackup := TextFilePackageOriginal + '.backup';
if FileExists(TextFilePackageBackup) then
DeleteFile(TextFilePackageBackup);
while not RenameFile(TextFilePackageOriginal, TextFilePackageBackup) do
begin
if Application.MessageBox(PChar(Format('UMake is unable to rename %s before recompiling it. Please make sure that the file isn''t loaded in UnrealEd or any other application at the moment.', [ExtractFileName(TextFilePackageOriginal)])), PChar(Application.Title), MB_ICONERROR + MB_RETRYCANCEL) <> IDRETRY then
begin
Close;
Exit;
end;
end;
end;
ButtonAbort.Caption := '&Abort';
ButtonAbort.Enabled := False;
ButtonAbort.Cancel := False;
RichEditMessages.Paragraph.FirstIndent := 2;
RichEditMessages.Paragraph.LeftIndent := 6;
RegExprClass := TRegExpr.Create;
RegExprPackage := TRegExpr.Create;
RegExprParsing := TRegExpr.Create;
RegExprCompiling := TRegExpr.Create;
RegExprCompleted := TRegExpr.Create;
RegExprErrorCompile := TRegExpr.Create;
RegExprErrorParse := TRegExpr.Create;
RegExprWarningCompile := TRegExpr.Create;
RegExprWarningParse := TRegExpr.Create;
RegExprClass .Expression := '^([^.]+\.)?(\w+)';
RegExprPackage .Expression := '^-+\s*(\w+)(\s*-\s*(\w+))?';
RegExprParsing .Expression := '^Parsing\s+(\w+)';
RegExprCompiling .Expression := '^Compiling\s+(\w+)';
RegExprCompleted .Expression := '^(Success|Failure) - \d+ error\(s\)';
RegExprErrorCompile .Expression := '^([A-Za-z]:\\.*?\\Classes\\\w+\.uc)\s*\((\d+)\)\s*:\s*Error,\s*(.*)';
RegExprErrorParse .Expression := '^Script vs. class name mismatch \((([^/]+))/[^)]+\)|^Bad class definition|^Superclass \S+ of class ((\S+)) not found|^([^:]+: )Unknown property|^ObjectProperty ([^.]+\.[^.]+\.)';
RegExprWarningCompile.Expression := '^([A-Za-z]:\\.*?\\Classes\\\w+\.uc)\s*\((\d+)\)\s*:\s*ExecWarning,\s*(.*)';
RegExprWarningParse .Expression := '^Failed loading\s+.*';
PageControlDetails.ActivePage := TabSheetMessages;
TabSheetError .TabVisible := False;
TabSheetWarnings.TabVisible := False;
InfoError := TInfoError.Create;
ListInfoWarning := TList.Create;
Configuration.Write;
TextDirSystem := IncludeTrailingBackslash(Configuration.DirGame) + 'System';
TextCommand := Format('%s make -fixcompat -silent ini=%s',
[GetQuotedParam(IncludeTrailingBackslash(TextDirSystem) + 'ucc.exe'),
GetQuotedParam(GetRelativePath(IncludeTrailingBackslash(Configuration.DirPackage) + 'make.ini', IncludeTrailingBackslash(TextDirSystem)))]);
ProgressBar.Position := 0;
PipedProcess := TPipedProcess.Create;
PipedProcess.Directory := TextDirSystem;
PipedProcess.Command := TextCommand;
PipedProcess.OnDebug := PipedProcessDebug;
PipedProcess.OnOutput := PipedProcessOutput;
PipedProcess.OnTerminate := PipedProcessTerminate;
PipedProcess.Debug;
if Options.RegOptDetails.Value And ButtonDetails.Enabled then
ButtonDetailsClick(ButtonDetails);
StaticTextProgress.SetFocus;
end;
procedure TFormMain.PipedProcessDebug(Sender: TObject; const DebugEvent: TDebugEvent; var ContinueStatus: Cardinal);
begin
// nothing
end;
procedure TFormMain.PipedProcessOutput(Sender: TObject; const TextData: string; Pipe: TPipedOutput);
function FormatError(TextType: string; InfoError: TInfoError): string;
begin
Result := Format('%s in %s (%d): %s', [TextType, ExtractFileName(InfoError.TextFile),
InfoError.IndexLine,
InfoError.TextMessage]);
end;
var
ColorLine: TColor;
IndexCharSeparator: Integer;
IndexCharSeparatorCR: Integer;
IndexCharSeparatorLF: Integer;
IndexMatch: Integer;
InfoWarning: TInfoError;
TextLine: string;
begin
if not FlagClosing then
ButtonAbort.Enabled := True;
RichEditMessages.Lines.BeginUpdate;
AppendStr(TextBufferPipe, TextData);
while Length(TextBufferPipe) > 0 do
begin
IndexCharSeparatorCR := Pos(#13, TextBufferPipe);
IndexCharSeparatorLF := Pos(#10, TextBufferPipe);
if IndexCharSeparatorCR = Length(TextBufferPipe) then
IndexCharSeparatorCR := 0;
if IndexCharSeparatorCR = 0 then IndexCharSeparator := IndexCharSeparatorLF
else if IndexCharSeparatorLF = 0 then IndexCharSeparator := IndexCharSeparatorCR
else begin
if IndexCharSeparatorCR < IndexCharSeparatorLF - 1
then IndexCharSeparator := IndexCharSeparatorCR
else IndexCharSeparator := IndexCharSeparatorLF;
end;
if IndexCharSeparator = 0 then
Break;
TextLine := TrimRight(Copy(TextBufferPipe, 1, IndexCharSeparator));
Delete(TextBufferPipe, 1, IndexCharSeparator);
ColorLine := RichEditMessages.Font.Color;
if RegExprPackage.Exec(TextLine) then
begin
TextLine := Format('----- %s', [RegExprPackage.Match[1]]);
if RegExprPackage.SubExprMatchCount > 1 then
AppendStr(TextLine, Format(' (%s)', [RegExprPackage.Match[3]]));
if not FlagClosing then
begin
if ProgressBar.Position < ProgressBar.Max then
ProgressBar.StepIt;
StaticTextProgress.Caption := Format('Reading %s', [RegExprPackage.Match[1]]);
end;
end
else if RegExprParsing.Exec(TextLine) then
begin
if not FlagClosing then
begin
if ProgressBar.Position < ProgressBar.Max then
ProgressBar.StepIt;
StaticTextProgress.Caption := Format('Parsing %s', [RegExprParsing.Match[1]]);
end;
end
else if RegExprCompiling.Exec(TextLine) then
begin
if not FlagClosing then
begin
if ProgressBar.Position < ProgressBar.Max then
ProgressBar.StepIt;
StaticTextProgress.Caption := Format('Compiling %s', [RegExprCompiling.Match[1]]);
end;
end
else if RegExprErrorParse.Exec(TextLine) then
begin
InfoError.TextFile := '';
InfoError.TextMessage := TextLine;
InfoError.IndexLine := 0;
for IndexMatch := 1 to RegExprErrorParse.SubExprMatchCount do
begin
if (RegExprErrorParse.MatchLen[IndexMatch] > 0) and RegExprClass.Exec(RegExprErrorParse.Match[IndexMatch]) then
begin
Delete(InfoError.TextMessage, RegExprErrorParse.MatchPos[IndexMatch], RegExprErrorParse.MatchLen[IndexMatch]);
Insert(RegExprErrorParse.Match[IndexMatch + 1], InfoError.TextMessage, RegExprErrorParse.MatchPos[IndexMatch]);
InfoError.TextFile := IncludeTrailingBackslash(Configuration.DirPackage) + 'Classes\' + RegExprClass.Match[2] + '.uc';
Break;
end;
end;
ColorLine := clRed;
end
else if RegExprErrorCompile.Exec(TextLine) then
begin
InfoError.TextFile := RegExprErrorCompile.Match[1];
InfoError.TextMessage := RegExprErrorCompile.Match[3];
InfoError.IndexLine := StrToInt(RegExprErrorCompile.Match[2]);
ColorLine := clRed;
TextLine := FormatError('Error', InfoError);
end
else if RegExprWarningParse.Exec(TextLine) then
begin
InfoWarning := TInfoError.Create;
ListInfoWarning.Add(InfoWarning);
InfoWarning.TextMessage := TextLine;
InfoWarning.TextFile := '';
InfoWarning.IndexLine := 0;
ColorLine := clRed;
end
else if RegExprWarningCompile.Exec(TextLine) then
begin
InfoWarning := TInfoError.Create;
ListInfoWarning.Add(InfoWarning);
InfoWarning.TextFile := RegExprWarningCompile.Match[1];
InfoWarning.TextMessage := RegExprWarningCompile.Match[3];
InfoWarning.IndexLine := StrToInt(RegExprWarningCompile.Match[2]);
ColorLine := clRed;
TextLine := FormatError('Warning', InfoWarning);
end
else if RegExprCompleted.Exec(TextLine) then
begin
StaticTextProgress.Caption := 'Finishing';
end;
RichEditMessagesAppend(TextLine, ColorLine);
end;
RichEditMessages.SelStart := RichEditMessages.Perform(EM_GETLIMITTEXT, 0, 0);
RichEditMessages.Perform(EM_SCROLLCARET, 0, 0);
RichEditMessages.Lines.EndUpdate;
end;
procedure TFormMain.PipedProcessTerminate(Sender: TObject);
begin
if not FileExists(TextFilePackageOriginal) and FileExists(TextFilePackageBackup) then
RenameFile(TextFilePackageBackup, TextFilePackageOriginal);
if FlagClosing then
begin
Close;
end
else begin
if PipedProcess.ExitCode = 0 then
begin
ProgressBar.Position := ProgressBar.Max;
StaticTextProgress.Caption := 'Done';
if ListInfoWarning.Count = 0 then
begin
Options.PerformAction(perfSuccess, Self, Configuration);
end
else begin
Options.PerformAction(perfFailure, Self, Configuration);
if Visible then
begin
UpdateDetailsWarning;
PageControlDetails.ActivePage := TabSheetWarnings;
end;
end;
end
else begin
StaticTextProgress.Caption := 'Failed';
Options.PerformAction(perfFailure, Self, Configuration);
if Visible then
begin
if Length(InfoError.TextMessage) > 0 then
begin
UpdateDetailsError;
if ListInfoWarning.Count > 0 then
UpdateDetailsWarning;
PageControlDetails.ActivePage := TabSheetError;
end
else if ListInfoWarning.Count > 0 then
begin
UpdateDetailsWarning;
PageControlDetails.ActivePage := TabSheetWarnings;
end
else begin
if ButtonDetails.Enabled then
ButtonDetailsClick(ButtonDetails);
end;
end;
end;
ButtonAbort.Caption := '&Close';
ButtonAbort.Enabled := True;
ButtonAbort.Cancel := True;
end;
end;
procedure TFormMain.RichEditMessagesAppend(TextAppend: string; ColorAppend: TColor);
begin
RichEditMessages.SelStart := $7fffffff;
RichEditMessages.SelAttributes.Color := ColorAppend;
RichEditMessages.SelText := TextAppend + CRLF;
end;
procedure TFormMain.UpdateDetailsError;
begin
ErrorDetails(InfoError, LabelErrorLocation, RichEditError);
ButtonErrorEdit.Enabled := Length(InfoError.TextFile) > 0;
TabSheetError.TabVisible := True;
end;
procedure TFormMain.UpdateDetailsWarning;
var
ControlFocused: TControl;
begin
ErrorDetails(ListInfoWarning[IndexWarning], LabelWarningLocation, RichEditWarning);
LabelWarningNumber.Caption := Format('(%d of %d)', [IndexWarning + 1, ListInfoWarning.Count]);
ControlFocused := ActiveControl;
ButtonWarningPrev.Enabled := IndexWarning > 0;
ButtonWarningNext.Enabled := IndexWarning < ListInfoWarning.Count - 1;
if Assigned(ControlFocused) and not ControlFocused.Enabled then
StaticTextProgress.SetFocus;
ButtonWarningEdit.Enabled := Length(TInfoError(ListInfoWarning[IndexWarning]).TextFile) > 0;
TabSheetWarnings.TabVisible := True;
end;
procedure TFormMain.ButtonWarningPrevClick(Sender: TObject);
begin
if IndexWarning > 0 then
begin
Dec(IndexWarning);
UpdateDetailsWarning;
end;
end;
procedure TFormMain.ButtonWarningNextClick(Sender: TObject);
begin
if IndexWarning < ListInfoWarning.Count - 1 then
begin
Inc(IndexWarning);
UpdateDetailsWarning;
end;
end;
procedure TFormMain.ButtonOptionsClick(Sender: TObject);
begin
FormOptions.Configuration := Configuration;
FormOptions.Options := Options;
FormOptions.ShowModal;
if not Visible then Close;
end;
procedure TFormMain.ButtonAbortClick(Sender: TObject);
begin
Close;
end;
procedure TFormMain.ButtonDetailsClick(Sender: TObject);
begin
Constraints.MaxWidth := 0;
Constraints.MaxHeight := 0;
ClientHeight := ClientHeight + 248;
Constraints.MinHeight := Constraints.MinHeight + 200;
PageControlDetails.Height := ClientHeight - PageControlDetails.Top - PageControlDetails.Left;
PageControlDetails.Enabled := True;
ButtonDetails.Enabled := False;
end;
procedure TFormMain.ButtonErrorEditClick(Sender: TObject);
begin
Options.PerformEdit(Configuration, InfoError.TextFile, InfoError.IndexLine);
Hide;
Close;
end;
procedure TFormMain.TabSheetErrorResize(Sender: TObject);
begin
RichEditError.Repaint;
end;
procedure TFormMain.TabSheetWarningsResize(Sender: TObject);
begin
RichEditWarning.Repaint;
end;
procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Assigned(PipedProcess) and PipedProcess.Executing then
begin
PipedProcess.Abort;
ButtonAbort.Enabled := False;
StaticTextProgress.Caption := 'Aborting';
FlagClosing := True;
CanClose := False;
end
else begin
CanClose := not FormOptions.Visible;
end;
end;