You are not logged in.
Pages: 1
The following source code for testing. If 7z file exists, open it, otherwise create it:
var zipFileName: TFileName := MakePath([Executable.ProgramFilePath, 'TestDaten.7z']);
if FileExists(zipFileName) then
libWriter := New7zWriter(zipFileName, fh7z)
else
libWriter := New7zWriter(fh7z);
For it to work, function SaveToFile must be changed as follows:
begin
fFileName := DestName;
// f := TFileStreamEx.Create(DestName, fmCreate);
if fUpdateReader <> Nil then
f := TFileStreamEx.Create(DestName, fmOpenWrite or fmShareDenyNone)
else
f := TFileStreamEx.Create(DestName, fmCreate);
try
SaveToStream(f);
Without this change it makes no sense to open a file for editing because it cannot be saved with SaveToFile.
With best regards
Thomas
Offline
I am not sure it is possible to modify an archive in place, to be honest.
With my modification for function SaveToFile, it works for this test:
procedure SaveFolderTo7Zip(const pmcFolder, pmc7ZipFileName: TFileName;
const pmc7ZipInternalDir: TFileName = ''; const pmcFileMask: TFileName = '*';
pmNew7Zip: Boolean = False; const pmOnProgress: T7zProgressCallback = Nil);
var
libWriter: I7zWriter;
begin
if not pmNew7Zip
and FileExists(pmc7ZipFileName) then
begin
libWriter := New7zWriter(pmc7ZipFileName, fh7z)
end
else
libWriter := New7zWriter(fh7z);
libWriter.SetCompressionLevel(3);
if Assigned(pmOnProgress) then
libWriter.SetProgressCallback(pmOnProgress);
libWriter.AddFiles(pmcFolder, pmc7ZipInternalDir, pmcFileMask, True);
libWriter.SaveToFile(pmc7ZipFileName);
end;
Call then as follows:
var
zipFileName: TFileName;
begin
zipFileName := MakePath([Executable.ProgramFilePath, 'TestMultiData.7z']);
SaveFolderTo7Zip('c:\mORMot2\src\', zipFileName, 'mORMot_2023-05-01', '*.pas;*.inc', {pmNew7Zip=}False, ProgressCallback);
SaveFolderTo7Zip('c:\mORMot2\src\', zipFileName, 'mORMot_2023-05-02', '*.pas;*.inc', {pmNew7Zip=}False, ProgressCallback);
SaveFolderTo7Zip('c:\mORMot2\src\', zipFileName, 'mORMot_2023-05-03', '*.pas;*.inc', {pmNew7Zip=}False, ProgressCallback);
SaveFolderTo7Zip('c:\mORMot2\src\', zipFileName, 'mORMot_2023-05-04', '*.pas;*.inc', {pmNew7Zip=}False, ProgressCallback);
SaveFolderTo7Zip('c:\mORMot2\src\', zipFileName, 'mORMot_2023-05-05', '*.pas;*.inc', {pmNew7Zip=}False, ProgressCallback);
end;
The result in TestMultiData.7z file looks as expected:
mORMot_2023-05-01\app
mORMot_2023-05-01\core
...
mORMot_2023-05-02\...
mORMot_2023-05-03\...
mORMot_2023-05-04\...
mORMot_2023-05-05\...
I have checked with a tool that compares directories, everything is OK for me.
With best regards
Thomas
Last edited by tbo (2023-05-06 21:04:43)
Offline
Offline
Commit 5434 (e4a5ff6) works as expected. All my tests passed. Thanks for this.
With best regards
Thomas
Offline
Pages: 1