Commit 16678535 authored by kravtsov's avatar kravtsov

[-] Исправлена ошибка удаления логов

parent eff65ccb
......@@ -7,13 +7,15 @@
*******************************************************************
OposShtrih_1.13_476.exe
19 февраля 2018 14:50
19 февраля 2018 17:50
[-] При ошибке загрузчи логотипа будет выдаваться ошибка
'Не удалось загрузить логотип'
[-] Изменено значение по умолчанию свойства PrintRecMessageMode
Теперь PrintRecMessageMode = PrintRecMessageModeBefore
[-] Исправлена ошибка удаления логов
*******************************************************************
......
......@@ -13,6 +13,7 @@ procedure WriteFileData(const FileName, Data: string);
function GetLongFileName(const FileName: string): string;
function GetSystemPath: string;
function CLSIDToFileName(const CLSID: TGUID): String;
procedure DeleteFiles(const FileMask: string);
implementation
......@@ -130,6 +131,38 @@ begin
end;
end;
procedure GetFileNames(const Mask: string; FileNames: TStrings);
var
F: TSearchRec;
Result: Integer;
FileName: string;
begin
Result := FindFirst(Mask, faAnyFile, F);
while Result = 0 do
begin
FileName := ExtractFilePath(Mask) + F.FindData.cFileName;
FileNames.Add(FileName);
Result := FindNext(F);
end;
FindClose(F);
end;
procedure DeleteFiles(const FileMask: string);
var
FileNames: TStringList;
begin
FileNames := TStringList.Create;
try
GetFileNames(FileMask, FileNames);
while FileNames.Count > 0 do
begin
DeleteFile(FileNames[0]);
FileNames.Delete(0);
end;
finally
FileNames.Free;
end;
end;
......
......@@ -29,6 +29,7 @@ type
procedure WriteRxData(Data: string);
procedure WriteTxData(Data: string);
procedure LogParam(const ParamName: string; const ParamValue: Variant);
procedure GetFileNames(const Mask: string; FileNames: TStrings);
function GetSeparator: string;
function GetMaxCount: Integer;
......@@ -45,6 +46,7 @@ type
function GetTimeStampEnabled: Boolean;
procedure SetTimeStampEnabled(const Value: Boolean);
procedure CloseFile;
procedure CheckFilesMaxCount;
property Enabled: Boolean read GetEnabled write SetEnabled;
property FilePath: string read GetFilePath write SetFilePath;
......@@ -372,7 +374,7 @@ var
begin
FileNames := TStringList.Create;
try
FileMask := IncludeTrailingBackSlash(FilePath) + '*.log';
FileMask := IncludeTrailingBackSlash(FilePath) + Format('*%s*.log', [DeviceName]);
GetFileNames(FileMask, FileNames);
FileNames.Sort;
while FileNames.Count > MaxCount do
......@@ -391,6 +393,7 @@ var
Result: Integer;
FileName: string;
begin
FileNames.Clear;
Result := FindFirst(Mask, faAnyFile, F);
while Result = 0 do
begin
......
......@@ -245,9 +245,9 @@ CheckPrintRecItemVoid=1
CheckSaveToXml=0
[GUITestRunner Config]
AutoSave=1
Left=493
Top=205
Width=1033
Left=215
Top=198
Width=1361
Height=808
Maximized=0
UseRegistry=0
......@@ -257,7 +257,7 @@ ErrorMessage.Visible=1
FailureList.ColumnWidth[0]=241
FailureList.ColumnWidth[1]=200
FailureList.ColumnWidth[2]=800
FailureList.ColumnWidth[3]=-236
FailureList.ColumnWidth[3]=92
HideTestNodesOnOpen=0
BreakOnFailures=1
SelectTestedNode=1
......@@ -588,3 +588,4 @@ CheckPing=1
CheckOpen=1
[Tests.SmFiscalPrinterTest.exe.TLogFileTest]
CheckDeleteFile=1
CheckMaxCount=1
......@@ -15,6 +15,7 @@ type
TLogFileTest = class(TTestCase)
published
procedure CheckMaxCount;
procedure CheckDeleteFile;
end;
......@@ -32,7 +33,7 @@ begin
try
Logger.MaxCount := 10;
Logger.Enabled := True;
Logger.FilePath := GetModulePath;
Logger.FilePath := GetModulePath + 'Logs\';
Logger.DeviceName := 'DeviceName1';
Logger.TimeStampEnabled := False;
......@@ -82,11 +83,63 @@ begin
CheckEquals('[ERROR] Line2', Lines[1], 'Lines[1]');
CheckEquals('[DEBUG] Line3', Lines[2], 'Lines[2]');
CheckEquals('[ERROR] Line4', Lines[3], 'Lines[3]');
Logger.CloseFile;
DeleteFiles(Logger.FilePath + '*.log');
finally
Lines.Free;
end;
end;
procedure TLogFileTest.CheckMaxCount;
var
Logger: ILogFile;
FilesPath: string;
FileNames: TStringList;
begin
FileNames := TStringList.Create;
try
Logger := TLogFile.Create;
Logger.MaxCount := 3;
Logger.Enabled := True;
Logger.FilePath := GetModulePath + 'Logs';
Logger.DeviceName := 'Device1';
FilesPath := GetModulePath + 'Logs\';
DeleteFiles(FilesPath + '*.log');
Logger.GetFileNames(FilesPath + '*.log', FileNames);
CheckEquals(0, FileNames.Count, 'FileNames.Count');
WriteFileData(FilesPath + 'Device1_2018.02.15.log', '');
WriteFileData(FilesPath +'Device1_2018.02.16.log', '');
WriteFileData(FilesPath +'Device1_2018.02.17.log', '');
WriteFileData(FilesPath +'Device1_2018.02.18.log', '');
WriteFileData(FilesPath +'Device1_2018.02.19.log', '');
WriteFileData(FilesPath +'Device2_2018.02.15.log', '');
WriteFileData(FilesPath +'Device2_2018.02.16.log', '');
WriteFileData(FilesPath +'Device2_2018.02.17.log', '');
WriteFileData(FilesPath +'Device2_2018.02.18.log', '');
WriteFileData(FilesPath +'Device2_2018.02.19.log', '');
Logger.GetFileNames(FilesPath + '*.log', FileNames);
CheckEquals(10, FileNames.Count, 'FileNames.Count');
Logger.CheckFilesMaxCount;
Logger.GetFileNames(FilesPath + '*.log', FileNames);
FileNames.Sort;
CheckEquals(8, FileNames.Count, 'FileNames.Count');
CheckEquals('Device1_2018.02.17.log', ExtractFileName(FileNames[0]), 'FileNames[0]');
CheckEquals('Device1_2018.02.18.log', ExtractFileName(FileNames[1]), 'FileNames[1]');
CheckEquals('Device1_2018.02.19.log', ExtractFileName(FileNames[2]), 'FileNames[2]');
CheckEquals('Device2_2018.02.15.log', ExtractFileName(FileNames[3]), 'FileNames[3]');
DeleteFiles(FilesPath + '*.log');
finally
FileNames.Free;
end;
end;
initialization
RegisterTest('', TLogFileTest.Suite);
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment