Skip to content

Commit 9a8b62c

Browse files
committed
Added UseRelativePath to Download
1 parent 05e8966 commit 9a8b62c

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

changelog.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
WIAPASCAL CHANGE LOG
22
======================
3-
2025/02/25 Tested and fixed user cancel operations;
3+
2025/02/
4+
28 Added UseRelativePath to Download
5+
25 Tested and fixed user cancel operations;
46
Fixed DownloadNativeUI missing ForceDirectories;
57

68
2024/12/06 Enabled Translation for Lazarus;

wia.pas

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ TWIADevice = class(TNoRefCountObject, IWiaTransferCallback)
305305
function Download(APath, AFileName, AExt: String): Integer; overload;
306306
function Download(APath, AFileName, AExt: String; AFormat: TWIAImageFormat): Integer; overload;
307307
function Download(APath, AFileName, AExt: String; AFormat: TWIAImageFormat;
308-
var DownloadedFiles: TStringArray): Integer; overload;
308+
var DownloadedFiles: TStringArray; UseRelativePath: Boolean=False): Integer; overload;
309309
(* // In Wia 2 the user must specify what to download from the feeder using the ADocHandling parameter,
310310
// the SettingsForm store DocHandling in Params so the user can use here.
311311
function Download(APath, AFileName, AExt: String; ADocHandling: TWIADocumentHandlingSet=[]): Integer; overload;
@@ -318,7 +318,7 @@ TWIADevice = class(TNoRefCountObject, IWiaTransferCallback)
318318
// The system dialog works at Device level, so the selected item is ignored
319319
function DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean;
320320
APath, AFileName: String;
321-
var DownloadedFiles: TStringArray): Integer;
321+
var DownloadedFiles: TStringArray; UseRelativePath: Boolean=False): Integer;
322322

323323
//Get Current Property Value and it's type given the ID
324324
function GetProperty(APropId: PROPID; var propType: TVarType;
@@ -724,6 +724,13 @@ procedure VersionStrToInt(const s: String; var Ver, VerSub: Integer);
724724
end;
725725
end;
726726

727+
function FullPathToRelativePath(const ABasePath: String; var APath: String): Boolean;
728+
begin
729+
Result:= (Pos(ABasePath, APath) = 1);
730+
if Result
731+
then APath:= '.'+DirectorySeparator+Copy(APath, Length(ABasePath)-1, MaxInt);
732+
end;
733+
727734
function WIAItemTypes(pItemType: LONG): TWIAItemTypes;
728735
begin
729736
Result :=[];
@@ -1298,7 +1305,7 @@ function TWIADevice.Download(APath, AFileName, AExt: String; AFormat: TWIAImageF
12981305
end;
12991306

13001307
function TWIADevice.Download(APath, AFileName, AExt: String; AFormat: TWIAImageFormat;
1301-
var DownloadedFiles: TStringArray): Integer;
1308+
var DownloadedFiles: TStringArray; UseRelativePath: Boolean): Integer;
13021309
var
13031310
i: Integer;
13041311

@@ -1312,16 +1319,24 @@ function TWIADevice.Download(APath, AFileName, AExt: String; AFormat: TWIAImageF
13121319
if (Result > 0 ) then
13131320
begin
13141321
SetLength(DownloadedFiles, Result);
1315-
DownloadedFiles[0]:= rDownload_Path+rDownload_FileName+rDownload_Ext;
1316-
for i:=1 to Result-1 do
1317-
DownloadedFiles[i]:= rDownload_Path+rDownload_FileName+
1318-
'-'+IntToStr(i)+rDownload_Ext;
1322+
1323+
if UseRelativePath
1324+
then begin
1325+
DownloadedFiles[0]:= rDownload_FileName+rDownload_Ext;
1326+
for i:=1 to Result-1 do
1327+
DownloadedFiles[i]:= rDownload_FileName+'-'+IntToStr(i)+rDownload_Ext;
1328+
end
1329+
else begin
1330+
DownloadedFiles[0]:= rDownload_Path+rDownload_FileName+rDownload_Ext;
1331+
for i:=1 to Result-1 do
1332+
DownloadedFiles[i]:= rDownload_Path+rDownload_FileName+'-'+IntToStr(i)+rDownload_Ext;
1333+
end;
13191334
end;
13201335
end;
13211336
end;
13221337

13231338
function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APath, AFileName: String;
1324-
var DownloadedFiles: TStringArray): Integer;
1339+
var DownloadedFiles: TStringArray; UseRelativePath: Boolean): Integer;
13251340
var
13261341
dlgFlags: LONG;
13271342
i: Integer;
@@ -1369,6 +1384,10 @@ function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APa
13691384
for i:=0 to rDownload_Count-1 do
13701385
begin
13711386
DownloadedFiles[i]:= filePaths^[i];
1387+
1388+
if UseRelativePath
1389+
then FullPathToRelativePath(rDownload_Path, DownloadedFiles[i]);
1390+
13721391
SysFreeString(filePaths^[i]);
13731392
end;
13741393

0 commit comments

Comments
 (0)