Fixed filelists scanning and file closing.

This commit is contained in:
Vladimir Kryvian
2015-08-10 19:27:43 +03:00
parent 04544b6da1
commit 99b04e5885
7 changed files with 126 additions and 97 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -27,7 +27,7 @@
<AutoIncrementBuild Value="True"/> <AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="1"/> <MajorVersionNr Value="1"/>
<RevisionNr Value="90"/> <RevisionNr Value="90"/>
<BuildNr Value="79"/> <BuildNr Value="84"/>
<StringTable CompanyName="Lab 313" FileDescription="The best TIMs tool ever!:)" ProductVersion=""/> <StringTable CompanyName="Lab 313" FileDescription="The best TIMs tool ever!:)" ProductVersion=""/>
</VersionInfo> </VersionInfo>
<BuildModes Count="6"> <BuildModes Count="6">

View File

@@ -596,7 +596,7 @@ object frmMain: TfrmMain
TitleFont.Name = 'Tahoma' TitleFont.Name = 'Tahoma'
ColWidths = ( ColWidths = (
102 102
133 150
) )
Cells = ( Cells = (
10 10

219
umain.pas
View File

@@ -174,9 +174,10 @@ type
function FGetSelectedTim: PTIM; function FGetSelectedTim: PTIM;
property SelectedTimInMode: PTIM read FGetSelectedTim; //Tim, selected in list property SelectedTimInMode: PTIM read FGetSelectedTim; //Tim, selected in list
procedure GetFilesList(const FileList: TStringList; const Directory: string);
procedure ScanList(const FileList: TStringList);
procedure ScanPath(const Path: string); procedure ScanPath(const Path: string);
procedure ScanFile(const FileName: string); procedure ScanFile(const FileName: string);
procedure ScanDirectory(const Directory: string);
procedure CheckButtonsAndMainMenu; procedure CheckButtonsAndMainMenu;
procedure ScanFinished(Sender: TObject); procedure ScanFinished(Sender: TObject);
procedure BeforeScan(MaxProgress: Integer); procedure BeforeScan(MaxProgress: Integer);
@@ -217,11 +218,17 @@ uses ucdimage, ucpucount, lcltype, ucommon, LCLIntf, uexportimport,
procedure TfrmMain.actScanFileExecute(Sender: TObject); procedure TfrmMain.actScanFileExecute(Sender: TObject);
var var
I: Integer; I: Integer;
List: TStringList;
begin begin
if not dlgOpenFile.Execute then Exit; if not dlgOpenFile.Execute then Exit;
List := TStringList.Create;
for I := 1 to dlgOpenFile.Files.Count do for I := 1 to dlgOpenFile.Files.Count do
ScanPath(dlgOpenFile.Files.Strings[I - 1]); List.Add(dlgOpenFile.Files.Strings[I - 1]);
ScanList(List);
List.Free;
end; end;
procedure TfrmMain.actShowFileInfoExecute(Sender: TObject); procedure TfrmMain.actShowFileInfoExecute(Sender: TObject);
@@ -239,11 +246,11 @@ begin
for I := 1 to ScanThreads.Count do for I := 1 to ScanThreads.Count do
ScanThreads[I - 1].StopScan := True; ScanThreads[I - 1].StopScan := True;
ScanThreads.Clear; while (StartedScans > 0) do
StartedScans := 0; Application.ProcessMessages;
actStopScan.Tag := NativeInt(True);
ScanFinished(nil); ScanThreads.Clear;
actStopScan.Tag := NativeInt(True);
actReturnFocus.Execute; actReturnFocus.Execute;
end; end;
@@ -305,15 +312,36 @@ begin
end; end;
procedure TfrmMain.actChangeFileExecute(Sender: TObject); procedure TfrmMain.actChangeFileExecute(Sender: TObject);
var
I: Integer;
W, H: Word;
begin begin
SetTimsListCount(SelectedScanResult.Count); SetTimsListCount(SelectedScanResult.Count);
actReturnFocus.Execute; actReturnFocus.Execute;
if grdTimsList.RowCount = 1 then Exit; if grdTimsList.RowCount = 1 then Exit;
if (ScanResults.Count = 0) then Exit;
grdTimsList.BeginUpdate;
for I := 1 to ScanResults.Last.Count do
begin
W := TimInfoByIdx[I - 1].Width;
H := TimInfoByIdx[I - 1].Height;
grdTimsList.Cells[0, I] := Format('%.6d', [I]);
grdTimsList.Cells[1, I] := Format('%.2d', [TimInfoByIdx[I - 1].BitMode]);
grdTimsList.Cells[2, I] := Format('%.2d', [TimInfoByIdx[I - 1].Cluts]);
grdTimsList.Cells[3, I] := Format('%s', [AnsiUpperCase(TIMTypeStr(TimInfoByIdx[I - 1].Magic))]);
grdTimsList.Cells[4, I] := Format('%.3dx%.3d', [W, H]);
end;
grdTimsList.EndUpdate;
grdTimsList.Row := 1; grdTimsList.Row := 1;
grdTimsListSelection(Self, 0, 1); grdTimsListSelection(Self, 0, 1);
grdTimsList.SetFocus; grdTimsList.SetFocus;
CheckButtonsAndMainMenu;
end; end;
procedure TfrmMain.actAboutExecute(Sender: TObject); procedure TfrmMain.actAboutExecute(Sender: TObject);
@@ -692,10 +720,10 @@ end;
procedure TfrmMain.FormDropFiles(Sender: TObject; procedure TfrmMain.FormDropFiles(Sender: TObject;
const FileNames: array of string); const FileNames: array of string);
var var
i: Integer; I: Integer;
begin begin
for i := 1 to Length(FileNames) do for I := 1 to Length(FileNames) do
ScanPath(FileNames[i - 1]); ScanPath(FileNames[I - 1]);
end; end;
procedure TfrmMain.grdClutDblClick(Sender: TObject); procedure TfrmMain.grdClutDblClick(Sender: TObject);
@@ -906,17 +934,68 @@ begin
Result^.OverBpp := Integer(cbbBitMode.Tag); Result^.OverBpp := Integer(cbbBitMode.Tag);
end; end;
procedure TfrmMain.ScanPath(const Path: string); procedure TfrmMain.GetFilesList(const FileList: TStringList; const Directory: string);
var
sRec: TSearchRec;
isFound: boolean;
Dir: string;
begin begin
if Path = '' then Exit; Dir := IncludeTrailingPathDelimiter(Directory);
isFound := FindFirst(UTF8ToSys(Dir + '*'), faAnyFile, sRec) = 0;
while isFound do
begin
if (sRec.Name <> '.') and (sRec.Name <> '..') then
begin
if (sRec.Attr and faDirectory) = faDirectory then
GetFilesList(FileList, Dir + SysToUTF8(sRec.Name))
else
FileList.Add(Dir + SysToUTF8(sRec.Name));
end;
Application.ProcessMessages;
isFound := FindNext(sRec) = 0;
end;
FindClose(sRec);
end;
procedure TfrmMain.ScanList(const FileList: TStringList);
var
I: Integer;
begin
actStopScan.Enabled := True; actStopScan.Enabled := True;
actStopScan.Tag := NativeInt(False); actStopScan.Tag := NativeInt(False);
for I := 1 to FileList.Count do
ScanFile(FileList[I - 1]);
while (StartedScans > 0) do
Application.ProcessMessages;
actStopScan.Enabled := False;
actStopScan.Tag := NativeInt(True);
CheckButtonsAndMainMenu;
if cbbFiles.Enabled then
begin
cbbFiles.ItemIndex := cbbFiles.Items.Count - 1;
actChangeFile.Execute;
end;
end;
procedure TfrmMain.ScanPath(const Path: string);
var
FileList: TStringList;
begin
if Path = '' then Exit;
FileList := TStringList.Create;
if FileExistsUTF8(Path) then if FileExistsUTF8(Path) then
ScanFile(Path) FileList.Add(Path)
else else
ScanDirectory(Path); GetFilesList(FileList, Path);
ScanList(FileList);
FileList.Free;
end; end;
procedure TfrmMain.ScanFile(const FileName: string); procedure TfrmMain.ScanFile(const FileName: string);
@@ -928,9 +1007,6 @@ begin
begin begin
cbbFiles.ItemIndex := cbbFiles.Items.IndexOf(FileName); cbbFiles.ItemIndex := cbbFiles.Items.IndexOf(FileName);
actChangeFile.Execute; actChangeFile.Execute;
actStopScan.Enabled := False;
actStopScan.Tag := NativeInt(True);
CheckButtonsAndMainMenu;
Exit; Exit;
end; end;
@@ -946,106 +1022,59 @@ begin
BeforeScan(ScanThreads.Last.FileLength); BeforeScan(ScanThreads.Last.FileLength);
ScanThreads.Last.Start; ScanThreads.Last.Start;
Inc(StartedScans); Inc(StartedScans);
end; end
else
while (StartedScans > 0) do
Application.ProcessMessages;
end; end;
end; end;
procedure TfrmMain.ScanDirectory(const Directory: string);
var
sRec: TSearchRec;
isFound: boolean;
Dir: string;
begin
Dir := IncludeTrailingPathDelimiter(Directory);
isFound := FindFirst(UTF8ToSys(Dir + '*'), faAnyFile, sRec) = 0;
while isFound do
begin
if (sRec.Name <> '.') and (sRec.Name <> '..') then
begin
if (sRec.Attr and faDirectory) = faDirectory then
ScanDirectory(Dir + SysToUTF8(sRec.Name))
else
ScanFile(Dir + SysToUTF8(sRec.Name));
end;
Application.ProcessMessages;
isFound := FindNext(sRec) = 0;
end;
FindClose(sRec);
end;
procedure TfrmMain.CheckButtonsAndMainMenu; procedure TfrmMain.CheckButtonsAndMainMenu;
var
Enable: Boolean;
begin begin
RemoveGridSelection; RemoveGridSelection;
cbbFiles.Enabled := (cbbFiles.Items.Count <> 0); Enable := (cbbFiles.Items.Count <> 0);
actExtractTimsAll.Enabled := cbbFiles.Enabled; cbbFiles.Enabled := Enable;
actExtractPngsAll.Enabled := cbbFiles.Enabled; actExtractTimsAll.Enabled := Enable;
actExtractPngsAll.Enabled := Enable;
pnlList.Enabled := cbbFiles.Enabled; pnlList.Enabled := Enable;
actCloseFile.Enabled := cbbFiles.Enabled; actCloseFile.Enabled := Enable;
actCloseFiles.Enabled := cbbFiles.Enabled; actCloseFiles.Enabled := Enable;
actScanFile.Enabled := ScanThreads.Count = 0; Enable := (StartedScans = 0);
actScanDir.Enabled := ScanThreads.Count = 0; actScanFile.Enabled := Enable;
actScanDir.Enabled := Enable;
actReplaceTim.Enabled := not (grdTimsList.Row < 1); Enable := not (grdTimsList.Row < 1);
actReplaceTim.Enabled := Enable;
actPngExport.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled; actPngExport.Enabled := (Surf^ <> nil) and Enable;
actPngImport.Enabled := actReplaceTim.Enabled; actPngImport.Enabled := Enable;
actExtractTim.Enabled := actReplaceTim.Enabled; actExtractTim.Enabled := Enable;
actExtractTims.Enabled := actReplaceTim.Enabled; actExtractTims.Enabled := Enable;
actExtractPngs.Enabled := actReplaceTim.Enabled; actExtractPngs.Enabled := Enable;
pnlImageOptions.Enabled := actReplaceTim.Enabled; pnlImageOptions.Enabled := Enable;
end; end;
procedure TfrmMain.ScanFinished(Sender: TObject); procedure TfrmMain.ScanFinished(Sender: TObject);
var var
I: Integer; I: Integer;
W, H: Word;
begin begin
ScanThreads.Remove(Sender as TScanThread); ScanThreads.Remove(Sender as TScanThread);
Dec(StartedScans); Dec(StartedScans);
if ScanThreads.Count <> 0 then for I := 1 to ScanThreads.Count do
begin if ScanThreads[I - 1].Suspended and (not ScanThreads[I - 1].StopScan) then
for I := 1 to ScanThreads.Count do begin
if ScanThreads[I - 1].Suspended and (not ScanThreads[I - 1].StopScan) then BeforeScan(ScanThreads[I - 1].FileLength);
begin ScanThreads[I - 1].Start;
BeforeScan(ScanThreads[I - 1].FileLength); Inc(StartedScans);
ScanThreads[I - 1].Start; Exit;
Inc(StartedScans); end;
Exit;
end;
Exit;
end;
CheckButtonsAndMainMenu;
if cbbFiles.Enabled then
begin
cbbFiles.ItemIndex := cbbFiles.Items.Count - 1;
actChangeFile.Execute;
end;
if (ScanResults.Count = 0) then Exit;
grdTimsList.BeginUpdate;
for I := 1 to ScanResults.Last.Count do
begin
W := TimInfoByIdx[I - 1].Width;
H := TimInfoByIdx[I - 1].Height;
grdTimsList.Cells[0, I] := Format('%.6d', [I]);
grdTimsList.Cells[1, I] := Format('%.2d', [TimInfoByIdx[I - 1].BitMode]);
grdTimsList.Cells[2, I] := Format('%.2d', [TimInfoByIdx[I - 1].Cluts]);
grdTimsList.Cells[3, I] := Format('%s', [AnsiUpperCase(TIMTypeStr(TimInfoByIdx[I - 1].Magic))]);
grdTimsList.Cells[4, I] := Format('%.3dx%.3d', [W, H]);
end;
grdTimsList.EndUpdate;
actStopScan.Enabled := False;
actStopScan.Tag := NativeInt(True);
end; end;
procedure TfrmMain.BeforeScan(MaxProgress: Integer); procedure TfrmMain.BeforeScan(MaxProgress: Integer);