Added x64 version (able to scan big lists of files); Fixed ScanDirectory function (now it properly scans big lists); Fixed StopScan button's behavior (now it able to stop multiple scan threads).

This commit is contained in:
meffi@lab313.ru
2014-04-10 11:15:02 +00:00
parent c062ecc92b
commit 0cf451dc17
9 changed files with 91 additions and 52 deletions

View File

@@ -21,6 +21,7 @@ function BrowseForFolderCallBack(Wnd: HWND; uMsg: UINT; lParam, lpData: lParam)
begin
if uMsg = BFFM_INITIALIZED then
SendMessage(Wnd, BFFM_SETSELECTION, 1, Integer(@lg_StartFolder[1]));
result := 0;
end;
@@ -52,7 +53,7 @@ begin
browse_info.pszDisplayName := @folder[0];
browse_info.lpszTitle := PChar(browseTitle);
browse_info.ulFlags := BIF_DONTGOBELOWDOMAIN or BIF_RETURNONLYFSDIRS or
BIF_STATUSTEXT or BIF_VALIDATE or BIF_USENEWUI or BIF_NONEWFOLDERBUTTON;
BIF_STATUSTEXT or BIF_VALIDATE {or BIF_USENEWUI} or BIF_NONEWFOLDERBUTTON;
browse_info.hwndOwner := appHWND;
if initialFolder <> '' then

View File

@@ -26,7 +26,6 @@ type
TBytesArray = array [0 .. cMaxFileSize - 1] of byte;
PBytesArray = ^TBytesArray;
function GetStartDir: string;
function GetFileSizeAPI(const FileName: string): Int64;
function CheckFileExists(const FileName: string): boolean;
// function cHex2Int( const Value : string) : Integer;
@@ -124,7 +123,7 @@ var
FindData: TWin32FindData;
hFind: THandle;
begin
Result := -1;
Result := 0;
hFind := FindFirstFile(PChar(FileName), FindData);
if hFind <> INVALID_HANDLE_VALUE then
@@ -137,21 +136,4 @@ begin
end;
function GetStartDir: string;
const
MAX_PATH = 260;
var
Buffer: array [0 .. MAX_PATH] of Char;
I: Integer;
begin
I := GetModuleFileName(0, Buffer, MAX_PATH);
for I := I downto 0 do
if Buffer[I] = '\' then
begin
Buffer[I + 1] := #0;
break;
end;
Result := Buffer;
end;
end.

View File

@@ -119,14 +119,14 @@ begin
IMAGE_DATA_POS := 0;
Transparent := TranspMode in [0, 1];
SemiTransparent := TranspMode in [0, 2];
R := 0;
G := 0;
B := 0;
STP := 0;
Transparent := TranspMode in [0, 1];
SemiTransparent := TranspMode in [0, 2];
for Y := 1 to RH do
for X := 1 to RW do
begin

View File

@@ -342,7 +342,7 @@ begin
TIM_NAME := Format(cAutoExtractionTimFormat, [ExtractJustName(FName), I, BIT_MODE]);
Path := IncludeTrailingPathDelimiter(GetStartDir + cExtractedTimsDir);
Path := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + cExtractedTimsDir);
CreateDir(Path);
Path := IncludeTrailingPathDelimiter(Path + ExtractFileName(FName));
CreateDir(Path);
@@ -403,6 +403,7 @@ begin
begin
ScanPath(SelectedDir);
LastDir := SelectedDir;
Settings.LastDir := LastDir;
end;
end;
@@ -500,10 +501,20 @@ begin
end;
procedure TfrmMain.btnStopScanClick(Sender: TObject);
var
I: Integer;
begin
if ScanThreads.Count = 0 then Exit;
ScanThreads.First.StopScan := True;
for I := 1 to ScanThreads.Count do
ScanThreads[I - 1].StopScan := True;
ScanThreads.Clear;
StartedScans := 0;
btnStopScan.Tag := NativeInt(True);
ScanFinished(nil);
actReturnFocusExecute(Self);
end;
@@ -676,6 +687,7 @@ begin
actStretch.Checked := Settings.StretchMode;
cbbTranspMode.ItemIndex := Settings.TranspMode;
LastDir := Settings.LastDir;
hGridRect.Top := -1;
hGridRect.Left := -1;
@@ -690,7 +702,7 @@ begin
StartedScans := 0;
New(PNG);
PNG^ := nil;
LastDir := GetStartDir;
SetCLUTListToNoCLUT;
Caption := Format('%s v%s', [cProgramName, cProgramVersion]);
DragAcceptFiles(Handle, True);
@@ -792,14 +804,15 @@ var
Dir: string;
begin
Dir := IncludeTrailingPathDelimiter(Directory);
isFound := FindFirst(Dir + '*.*', faAnyFile, sRec) = 0;
isFound := FindFirst(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 + sRec.Name);
ScanPath(Dir + sRec.Name);
ScanDirectory(Dir + sRec.Name)
else
ScanFile(Dir + sRec.Name);
end;
Application.ProcessMessages;
isFound := FindNext(sRec) = 0;
@@ -867,19 +880,23 @@ begin
begin
cbbFiles.ItemIndex := cbbFiles.Items.IndexOf(FileName);
btnStopScan.Enabled := False;
btnStopScan.Tag := NativeInt(True);
CheckButtonsAndMainMenu;
Exit;
end;
ScanThreads.Add(TScanThread.Create(FileName, GetImageScan(FileName)));
ScanThreads.Last.FreeOnTerminate := True;
ScanThreads.Last.Priority := tpNormal;
ScanThreads.Last.OnTerminate := ScanFinished;
if StartedScans < GetCoreCount then
if not Boolean(btnStopScan.Tag) then
begin
ScanThreads.Last.Start;
Inc(StartedScans);
ScanThreads.Add(TScanThread.Create(FileName, GetImageScan(FileName)));
ScanThreads.Last.FreeOnTerminate := True;
ScanThreads.Last.Priority := tpNormal;
ScanThreads.Last.OnTerminate := ScanFinished;
if StartedScans < GetCoreCount then
begin
ScanThreads.Last.Start;
Inc(StartedScans);
end;
end;
end;
@@ -893,7 +910,7 @@ begin
if ScanThreads.Count <> 0 then
begin
for I := 1 to ScanThreads.Count do
if ScanThreads[I - 1].Suspended then
if ScanThreads[I - 1].Suspended and (not ScanThreads[I - 1].StopScan) then
begin
ScanThreads[I - 1].Start;
Inc(StartedScans);
@@ -913,12 +930,16 @@ begin
end;
btnStopScan.Enabled := False;
btnStopScan.Tag := NativeInt(True);
end;
procedure TfrmMain.ScanPath(const Path: string);
begin
if Path = '' then Exit;
btnStopScan.Enabled := True;
btnStopScan.Tag := NativeInt(False);
if CheckFileExists(Path) then
ScanFile(Path)
else

View File

@@ -29,7 +29,7 @@ type
public
constructor Create(const FileToScan: string; ImageScan: boolean);
//property Started: boolean read pStarted write pStarted;
property StopScan: boolean write pStopScan;
property StopScan: boolean read pStopScan write pStopScan;
end;
implementation
@@ -115,7 +115,8 @@ begin
pScanFinished := False;
pTIMNumber := 0;
repeat
while not pStopScan do
begin
if LoadTimFromBuf(ClearBuffer, TIM, pClearBufferPosition) then
begin
if pScanResult.IsImage then
@@ -158,12 +159,13 @@ begin
ClearSectorBuffer(SectorBuffer, ClearBuffer);
end;
until pStopScan;
end;
FreeTIM(TIM);
FreeMemory(SectorBuffer);
FreeMemory(ClearBuffer);
pSrcFileStream.Free;
pStopScan := True;
pFilePos := 0;
pStatusText := '';
@@ -197,7 +199,6 @@ end;
procedure TScanThread.StartScan;
begin
frmMain.btnStopScan.Enabled := True;
frmMain.cbbFiles.Enabled := False;
frmMain.lvList.Enabled := False;
frmMain.actExtractList.Enabled := False;

View File

@@ -19,11 +19,13 @@ unit uSettings;
private
FTranspMode: Integer;
FStretchMode: Boolean;
FLastDir: string;
public
constructor Create;
published
property TranspMode: Integer read FTranspMode write FTranspMode;
property StretchMode: Boolean read FStretchMode write FStretchMode;
property LastDir: string read FLastDir write FLastDir;
end;
var