POChecker: moved log handling code to TPOFamilyList class, where it really belongs to

git-svn-id: trunk@62030 -
This commit is contained in:
maxim 2019-10-10 22:08:41 +00:00
parent d24501ac43
commit 04138e9fe7
2 changed files with 61 additions and 66 deletions

View File

@ -73,8 +73,8 @@ type
procedure SetTestTypeCheckBoxes(TestTypes: TPoTestTypes);
procedure ShowError(const Msg: string);
procedure ScanDirectory(ADir: String);
function TryCreatepoFamilyList(var MasterList, SL: TStringList; const LangID: TLangID): Boolean;
procedure RunSelectedTests(var SL, StatL, DupL: TStringList);
function TryCreatepoFamilyList(var MasterList: TStringList; const LangID: TLangID): Boolean;
procedure RunSelectedTests;
procedure ClearStatusBar;
procedure UpdateGUI(HasSelection: Boolean);
function GetSelectedMasterFiles: TStringList;
@ -216,25 +216,19 @@ end;
procedure TPoCheckerForm.RunToolButtonClick(Sender: TObject);
var
AMasterList, SL, StatL, DupL: TStringList;
AMasterList: TStringList;
LangIdx: Integer;
ALangID: TLangID;
begin
LangIdx := LangFilter.ItemIndex;
ALangID := LangFilterIndexToLangID(LangIdx);
SL := TStringList.Create;
StatL := TStringList.Create;
DupL := TStringList.Create;
AMasterList := GetSelectedMasterFiles;
try
if TryCreatePoFamilyList(AMasterList, SL, ALangID) then
RunSelectedTests(SL, StatL, DupL)
if TryCreatePoFamilyList(AMasterList, ALangID) then
RunSelectedTests
else
ShowError(sSelectedTranslationsAreNotAvailable);
finally
SL.Free;
StatL.Free;
DupL.Free;
AMasterList.Free;
end;
end;
@ -398,22 +392,14 @@ begin
end;
function TPoCheckerForm.TryCreatepoFamilyList(var MasterList, SL: TStringList;
function TPoCheckerForm.TryCreatepoFamilyList(var MasterList: TStringList;
const LangID: TLangID): Boolean;
var
FamilyMsg: String;
begin
Result := False;
try
if Assigned(PoFamilyList) then
PoFamilyList.Free;
PoFamilyList := TPoFamilyList.Create(MasterList, LangID, FamilyMsg);
if FamilyMsg <> '' then
begin
FamilyMsg := Format(sFilesNotFoundAndRemoved,[FamilyMsg]);
SL.AddText(FamilyMsg);
SL.Add('');
end;
PoFamilyList := TPoFamilyList.Create(MasterList, LangID);
PoFamilyList.OnTestStart := @OnTestStart;
PoFamilyList.OnTestEnd := @OnTestEnd;
Result := PoFamilyList.Count <> 0;
@ -423,11 +409,10 @@ begin
end;
procedure TPoCheckerForm.RunSelectedTests(var SL, StatL, DupL: TStringList);
procedure TPoCheckerForm.RunSelectedTests;
var
TestTypes: TPoTestTypes;
TestOptions: TPoTestOptions;
ErrorCount, NonFuzzyErrorCount, WarningCount: integer;
TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer;
TotalPercTranslated: Double;
ResultDlg: TResultDlgForm;
@ -446,37 +431,14 @@ begin
PoFamilyList.TestTypes := TestTypes;
PoFamilyList.TestOptions := TestOptions;
PoFamilyList.RunTests(ErrorCount, NonFuzzyErrorCount, WarningCount, TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount, SL, StatL, DupL);
//debugln('RunSelectedTests: ', Format(sTotalErrors, [ErrorCount]));
//debugln(' ', Format(sTotalWarnings, [WarningCount]));
TotalPercTranslated := 100 * TotalTranslatedCount / (TotalTranslatedCount + TotalUntranslatedCount + TotalFuzzyCount);
PoFamilyList.RunTests(TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount, TotalPercTranslated);
SL.Insert(0, sLastSearchPath);
SL.Insert(1, SelectDirectoryDialog.FileName);
SL.Insert(2, '');
SL.Insert(3, sLanguage);
SL.Insert(4, LangFilter.Text);
SL.Insert(5, '');
if NonFuzzyErrorCount > 0 then
SL.Add(Format(sTotalErrorsNonFuzzy, [ErrorCount, NonFuzzyErrorCount]))
else
SL.Add(Format(sTotalErrors, [ErrorCount]));
if not (ptoFindAllChildren in TestOptions) then
begin
SL.Add(Format(sTotalUntranslatedStrings, [IntToStr(TotalUntranslatedCount)]));
SL.Add(Format(sTotalFuzzyStrings, [IntToStr(TotalFuzzyCount)]));
SL.Add('');
SL.Add(Format(sTotalTranslatedStrings, [IntToStr(TotalTranslatedCount), TotalPercTranslated]));
StatL.Add(Format(sTotalUntranslatedStrings, [IntToStr(TotalUntranslatedCount)]));
StatL.Add(Format(sTotalFuzzyStrings, [IntToStr(TotalFuzzyCount)]));
StatL.Add('');
StatL.Add(Format(sTotalTranslatedStrings, [IntToStr(TotalTranslatedCount), TotalPercTranslated]));
end;
DupL.Add(Format(sTotalWarnings, [WarningCount]));
PoFamilyList.InfoLog.Insert(0, sLastSearchPath);
PoFamilyList.InfoLog.Insert(1, SelectDirectoryDialog.FileName);
PoFamilyList.InfoLog.Insert(2, '');
PoFamilyList.InfoLog.Insert(3, sLanguage);
PoFamilyList.InfoLog.Insert(4, LangFilter.Text);
PoFamilyList.InfoLog.Insert(5, '');
ResultDlg := TResultDlgForm.Create(nil);
try
@ -485,10 +447,10 @@ begin
ResultDlg.FTotalUntranslated := TotalUntranslatedCount;
ResultDlg.FTotalFuzzy := TotalFuzzyCount;
ResultDlg.FTotalPercTranslated := TotalPercTranslated;
ResultDlg.Log.Assign(SL);
ResultDlg.StatLog.Assign(StatL);
ResultDlg.Log.Assign(PoFamilyList.InfoLog);
ResultDlg.StatLog.Assign(PoFamilyList.StatLog);
ResultDlg.DupLog.Assign(DupL);
ResultDlg.DupLog.Assign(PoFamilyList.DupLog);
ResultDlg.PoFamilyList := PoFamilyList;
ResultDlg.PoFamilyStats := PoFamilyList.PoFamilyStats;

View File

@ -28,13 +28,14 @@ type
procedure DoTestStart(const ATestName, APoFileName: String);
procedure DoTestEnd(const ATestName: String; const ErrorCount: Integer);
public
constructor Create(AMasterList: TStrings; ALangID: TLangID; out Msg: String);
InfoLog: TStringList;
StatLog: TStringList;
DupLog: TStringList;
constructor Create(AMasterList: TStrings; ALangID: TLangID);
destructor Destroy; override;
procedure Add(PoFamily: TPofamily);
function Count: Integer;
procedure RunTests(out ErrorCount, NonFuzzyErrorCount, WarningCount,
TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer;
ErrorLog, StatLog, DupLog: TStringList);
procedure RunTests(out TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer; out TotalPercTranslated: Double);
property Items[Index: Integer]: TPoFamily read GetItem; // write SetItem;
property PoFamilyStats: TPoFamilyStats read FPoFamilyStats;
property TestTypes: TPoTestTypes read FTestTypes write FTestTypes;
@ -63,12 +64,15 @@ begin
if Assigned(FOnTestEnd) then FOnTestEnd(ATestName, ErrorCount);
end;
constructor TPoFamilyList.Create(AMasterList: TStrings; ALangID: TLangID; out Msg: String);
constructor TPoFamilyList.Create(AMasterList: TStrings; ALangID: TLangID);
var
i: Integer;
MasterName, ChildName, MasterMsg, ChildMsg: String;
APoFamily: TPoFamily;
begin
InfoLog := TStringList.Create;
StatLog := TStringList.Create;
DupLog := TStringList.Create;
FList := TFPObjectList.Create(True);
MasterMsg := '';
ChildMsg := '';
@ -95,15 +99,22 @@ begin
else
MasterMsg := MasterMsg + Format('"%s"',[MasterName]) + LineEnding;
end;
if (MasterMsg <> '') and (ChildMsg <> '') then
if MasterMsg <> '' then
MasterMsg := MasterMsg + LineEnding;
Msg := MasterMsg + ChildMsg;
if ChildMsg <> '' then
ChildMsg := ChildMsg + LineEnding;
MasterMsg := MasterMsg + ChildMsg;
if MasterMsg <> '' then
InfoLog.AddText(Format(sFilesNotFoundAndRemoved,[MasterMsg]));
end;
destructor TPoFamilyList.Destroy;
begin
//debugln('TPoFamilyList.Destroy: FList.Count = ',DbgS(FList.Count));
PoFamilyStats.Free;
InfoLog.Free;
StatLog.Free;
DupLog.Free;
FList.Free;
inherited Destroy;
end;
@ -118,9 +129,9 @@ begin
Result := FList.Count;
end;
procedure TPoFamilyList.RunTests(out ErrorCount, NonFuzzyErrorCount, WarningCount, TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer;
ErrorLog, StatLog, DupLog: TStringList);
procedure TPoFamilyList.RunTests(out TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer; out TotalPercTranslated: Double);
var
ErrorCount, NonFuzzyErrorCount, WarningCount: Integer;
Index, ThisErrorCount, ThisNonFuzzyErrorCount, ThisWarningCount: Integer;
ThisTranslatedCount, ThisUntranslatedCount, ThisFuzzyCount: Integer;
PoFamily: TPoFamily;
@ -143,7 +154,7 @@ begin
PoFamily.OnTestEnd := FOnTestEnd;
PoFamily.TestTypes := FTesttypes;
PoFamily.TestOptions := FTestOptions;
PoFamily.RunTests(ThisErrorCount, ThisNonFuzzyErrorCount, ThisWarningCount, ThisTranslatedCount, ThisUntranslatedCount, ThisFuzzyCount, ErrorLog, StatLog, DupLog);
PoFamily.RunTests(ThisErrorCount, ThisNonFuzzyErrorCount, ThisWarningCount, ThisTranslatedCount, ThisUntranslatedCount, ThisFuzzyCount, InfoLog, StatLog, DupLog);
PoFamily.PoFamilyStats.AddItemsTo(FPoFamilyStats);
ErrorCount := ErrorCount + ThisErrorCount;
NonFuzzyErrorCount := NonFuzzyErrorCount + ThisNonFuzzyErrorCount;
@ -152,6 +163,28 @@ begin
TotalUntranslatedCount := TotalUntranslatedCount + ThisUntranslatedCount;
TotalFuzzyCount := TotalFuzzyCount + ThisFuzzyCount;
end;
TotalPercTranslated := 100 * TotalTranslatedCount / (TotalTranslatedCount + TotalUntranslatedCount + TotalFuzzyCount);
if NonFuzzyErrorCount > 0 then
InfoLog.Add(Format(sTotalErrorsNonFuzzy, [ErrorCount, NonFuzzyErrorCount]))
else
InfoLog.Add(Format(sTotalErrors, [ErrorCount]));
if not (ptoFindAllChildren in TestOptions) then
begin
InfoLog.Add(Format(sTotalUntranslatedStrings, [IntToStr(TotalUntranslatedCount)]));
InfoLog.Add(Format(sTotalFuzzyStrings, [IntToStr(TotalFuzzyCount)]));
InfoLog.Add('');
InfoLog.Add(Format(sTotalTranslatedStrings, [IntToStr(TotalTranslatedCount), TotalPercTranslated]));
StatLog.Add(Format(sTotalUntranslatedStrings, [IntToStr(TotalUntranslatedCount)]));
StatLog.Add(Format(sTotalFuzzyStrings, [IntToStr(TotalFuzzyCount)]));
StatLog.Add('');
StatLog.Add(Format(sTotalTranslatedStrings, [IntToStr(TotalTranslatedCount), TotalPercTranslated]));
end;
DupLog.Add(Format(sTotalWarnings, [WarningCount]));
end;
end.