View Issue Details

IDProjectCategoryView StatusLast Update
0006255JEDI VCL00 JVCL Componentspublic2020-05-19 09:39
ReporterZencodeAssigned Toobones 
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionsuspended 
Product VersionDaily / GIT 
Target VersionFixed in Version 
Summary0006255: Change TJvCABFile.ExtractFile to allow filename override
DescriptionThe current implementation of TJvCABFile.ExtractFile extracts a file into the destination path using the same relative path and name of the file in the CAB. I am requesting that ExtractFile be changed (or overloaded) to allow a filename override such that the file can be extracted to a specific path and different name regardless of the original.

Example:
- CAB file contains file "Path\SubPath\file.ext"
- invoke ExtractFile('Path\SubPath\file.ext', 'C:\dest')
- Assuming the directories exist the following file will be created:
    C:\dest\Path\SubPath\file.ext

However, what if the desired result is for the file to be named "C:\dest\file.ext" or "C:\dest\newfile.newext"? Currently, the only solution is to allow the file to be extracted to the full path and then moved to the new path and name. This isn't hard but it requires extra work and might not always be possible. Since the CAB extraction API already supports this functionality I think it would be nice if TJvCABFile can support it.
Additional InformationI modified the source to do what I am requesting. The full file with all modifications is attached. Here is an overview of the changes I made:

I added a variable 'FDestFileName', overloaded ExtractFile, and modified CExtract to use FDestFileName if present.

// Added private variable
  FDestFileName: string;

// Overloaded ExtractFile
  function ExtractFile(FileName: string; DestPath: string): Boolean; overload;
  function ExtractFile(FileName, DestPath, DestFileName: string): Boolean; overload;

// line 220: function CExtract. Inserted the following code before Path := Sender.FDestPath;
  if Length(Sender.FDestFileName) > 0 then
    Path := Sender.FDestFileName
  else

// Added new ExtractFile method
function TJvCABFile.ExtractFile(FileName, DestPath, DestFileName: string): Boolean;
begin
  if DestPath[Length(DestPath)] <> PathDelim then
    DestPath := DestPath + PathDelim;
  FDestFileName := DestPath + DestFileName;
  Result := ExtractFile(FileName, DestPath);
  FDestFileName := ''; // clean up
end;

------------------

An alternate approach would be to modify TOnExtractFile to make the FileName argument "var". The downside of this approach is that any existing event handler code would have the wrong signature.
TagsNo tags attached.

Activities

2014-02-28 20:05

 

JvCabFile.pas (10,036 bytes)

obones

2014-09-03 11:32

administrator   ~0021022

Please provide the zipped sources of a sample application showing the usage

obones

2020-05-19 09:39

administrator   ~0021881

No reply in a timely manner, suspending the issue

Issue History

Date Modified Username Field Change
2014-02-28 20:05 Zencode New Issue
2014-02-28 20:05 Zencode File Added: JvCabFile.pas
2014-09-03 11:32 obones Note Added: 0021022
2014-09-03 11:32 obones Status new => feedback
2020-05-19 09:39 obones Assigned To => obones
2020-05-19 09:39 obones Status feedback => resolved
2020-05-19 09:39 obones Resolution open => suspended
2020-05-19 09:39 obones Note Added: 0021881