Example code is 7-zip itself.
So look 7-Zip source code.
7-zip uses "Update" function. You must send the list of files (list of UInt32 indexes) that must be copied from previous version of archive to new version of archive. Another files will be deleted.
Last edit: Igor Pavlov 2017-10-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello again. I'm trying to remove everything except file with index 0 from archive. But program is dying. Can you tell me what I'm doing wrong?
COutFileStream*outFileStreamSpec=newCOutFileStream;CMyComPtr<IOutStream>outFileStream=outFileStreamSpec;if(!outFileStreamSpec->Open((CFSTR)_root->_fullPath.utf16(),OPEN_EXISTING)){PrintError("can't create archive file");return;}if(createObjectFunc(&_archiveGUID,&IID_IOutArchive,(void**)&_outArchive)!=S_OK){PrintError("Can not get class object");return;}CArchiveUpdateCallback*updateCallbackSpec=newCArchiveUpdateCallback;CMyComPtr<IArchiveUpdateCallback2>updateCallback(updateCallbackSpec);QVector<int>items;items.append(0);updateCallbackSpec->Remove(items);HRESULTresult=_outArchive->UpdateItems(outFileStream,items.size(),updateCallback);updateCallbackSpec->Finilize();------------------------------------voidRemove(constQVector<int>newIndexes){_newIndexes=newIndexes;_removing=true;m_NeedBeClosed=false;FailedFiles.Clear();FailedCodes.Clear();}STDMETHODIMPCArchiveUpdateCallback::GetUpdateItemInfo(UInt32index,Int32*newData,Int32*newProperties,UInt32*indexInArchive){if(_removing){if(newData)*newData=BoolToInt(false);if(newProperties)*newProperties=BoolToInt(false);if(indexInArchive)*indexInArchive=(UInt32)(Int32)_newIndexes[index];}returnS_OK;}
Last edit: Dmitry Lodyakov 2017-10-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I was trying it was zip file, and it was crashing, but with 7z it's not crashing. Same code, but 7z instead of zip. I guess it's something with zip part of your lib.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
7-zip works with objects.
got updating you need:
1) create object
2) Open archive
3) request IOutArchive from same object
4) use IOutArchive interface.
You didn't do step 3.
Last edit: Igor Pavlov 2017-10-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've removed files from zip. Closed everything. And then I tried to remove it again with my soft, and I have #define E_NOTIMPL ((HRESULT)0x80004001L) error. And then when I'm trying to remove file with 7zFM I got error
7-Zip
Error Deleting File or Folder
Operation is not supported.
R:\Arc\Arc.zip
Read-only
OK
But before I've deleted files from this zip file I could remove files fith 7zFM.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
there is no remove operation in 7z.dll interface.
After YOUR "remove" code, you have:
1) a1.zip - old version of archive
2) a2.zip - new version of archive
so try to remove them.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello. Is it possible to delete and also insert files to archive with 7z sdk (I'm using C++)?
Yes, if 7-zip can do some operation with 7z archive, you can do same operation with SDK. 7-Zip uses same API from SDK.
Thank you. Where can I see example about deleting files from archive?
Example code is 7-zip itself.
So look 7-Zip source code.
7-zip uses "Update" function. You must send the list of files (list of UInt32 indexes) that must be copied from previous version of archive to new version of archive. Another files will be deleted.
Last edit: Igor Pavlov 2017-10-09
Thank you again.
And can I somehow add new file to archive?
yes, same
UpdateItems()
function.Look
as small example.
Hello again. I'm trying to remove everything except file with index 0 from archive. But program is dying. Can you tell me what I'm doing wrong?
Last edit: Dmitry Lodyakov 2017-10-12
Example:
you have archive with 3 files: 0, 1, 2.
you want to remove file=1.
then you need 2 files in new archive:
Igor, yes I did it as you said before, but program is crashing. Maybe I'm doing something wrong? Btw, can I build 7z in debug mode?
create small example archive with two items: 0 and 1.
and try different opeartions.
Add printf in callbacks.
When I was trying it was zip file, and it was crashing, but with 7z it's not crashing. Same code, but 7z instead of zip. I guess it's something with zip part of your lib.
7-zip works with objects.
got updating you need:
1) create object
2) Open archive
3) request IOutArchive from same object
4) use IOutArchive interface.
You didn't do step 3.
Last edit: Igor Pavlov 2017-10-13
You mean that's not enough? It's just like in example.
Think about case, if you want to update two archives from different threads.
There is no global object for update in 7-zip.
So Input archive and output archive interfaces must be from same object.
Igor, thank you, I did it. But there is a new problem. After I remove file from zip arhive it became readonly. What is it?
There is a1.zip.
When you remove file from a1.zip, you create a2.zip.
So what is readonly?
1) you create a2.zip,
2) close com interfaces to object (of a1.zip)
3) remove a1.zip.
4) rename a2.zip to a1.zip.
I've removed files from zip. Closed everything. And then I tried to remove it again with my soft, and I have #define E_NOTIMPL ((HRESULT)0x80004001L) error. And then when I'm trying to remove file with 7zFM I got error
7-Zip
Error Deleting File or Folder
Operation is not supported.
R:\Arc\Arc.zip
Read-only
OK
But before I've deleted files from this zip file I could remove files fith 7zFM.
there is no remove operation in 7z.dll interface.
After YOUR "remove" code, you have:
1) a1.zip - old version of archive
2) a2.zip - new version of archive
so try to remove them.
What does this error mean?
Error Deleting File or Folder
Operation is not supported.
R:\Arc\Arc.zip
Read-only
Btw, code words great with 7z archives
Yes, it's working now. I save contents in the another archive and then rename it. Thank you.