Smart archive extraction (enhanced)

Do I see it right that files and folders inside of an archive have th attribute "e"?
Then one idea would be to check for this attribute inside of the archives.

Depending on how the archive was created, it may fail to list entirely without a password. It's optional whether the file list and data are both encrypted, or only the data and not the list.

But that gives also a hint. If the content cannot be listed the archive is encrypted (or damaged).

So perhaps that is the solution? I list internally the content of the archive. If the listing fails or there is a file/folder inside with attribute "e" the archive will not be deleted.
I only have to check how to do that. :slight_smile:

Edit: Ah, when the archive itself is encrypted (created a 7z) the extract fails and the archive will not be deleted (with the new beta-version).

1 Like

With this code snippet I can check if a file inside of the archive is encrypted:

var folderEnum = fsu.ReadDir(item);
var folderItem = folderEnum.Next();

	if (folderItem.fileattr.e) {
		DOpus.Output("Encrypted")
	}
	else {
		DOpus.Output("Not Encrypted" + folderItem.fileattr)
	}

But when I run this on an archive where the file list is also encrypted I get the error message:

'fileattr.e' is null or no object (0x800a138f)

So I added a check if the folderEnum is successful:

if (folderEnum.error === "0"){
	if (folderItem.fileattr.e) {
		DOpus.Output("Encrypted")
	}
	else {
		DOpus.Output("Not Encrypted" + folderItem.fileattr)
	}
}
else {
	DOpus.Output(folderEnum.error)
}

folderEnum.error is "5" in this case (only for information).

But for not encrypted archives (or archives with encrypted files inside) the error code is 18 and not 0. Why is the enumeration not successfull in this case?

Seems that I have to avoid to check for folderItem.fileattr.e if the file list is also encrypted.

The error number should usually only be checked if there's actually an error (i.e. if something fails, it tells you more about why, but otherwise its value doesn't mean much and could even indicate the most recent failure, not the result of the last request if the last request succeeded).

(In this case 18 comes from the API itself, and is ERROR_NO_MORE_FILES which is a Windows error code that means the underlying operation succeed and has run out of files to give back. Keep in mind that ERROR_SUCCESS is also an "error" code. While most of the codes indicate errors, it's more a result or state than an error in general.)

ok. thank you.

The idea behing was: When the file list is encrypted the enumeration will fail. So I can avoid that the script tries to check for folderItem.fileattr.e.

Changed the code line in a first step to

if (folderEnum.error == "0" || folderEnum.error == "18") {

But is perhaps not the best solution.

If you're getting an error that fileattr is null, why not check for that?

1 Like

That does not work. It does not matter if I check for "0", 0, Null or "Null" I get for this line the error message that folderItem.fileattr.e is Null or no object.

if (folderItem.fileattr.e != "0") {

According to the manual "folderItem.fileattr.e" should be true or false. So "Null" seems to be an error which cannot be checked for?!

Same error for if (folderItem.fileattr.e == true || folderItem.fileattr.e == false)

You're testing if fileattr.e is null when you should be testing fileattr itself.

(Testing folderItem first may also make sense, if that's the thing that's null in the situation you're trying to detect.)

fileattr itself does not cause the error regarding "Null", but has also not this value.
fileattr itself is "undefined" for a fully encrypted archive (At least for my test archive).
So I can check it like this:

if (folderItem.fileattr != undefined) {
	if (folderItem.fileattr.e) {
		DOpus.Output("Encrypted");
	}
	else {
		DOpus.Output("Not Encrypted" + folderItem.fileattr);
	}
}
1 Like

Attached a new version for testing.
When the extraction fails the archive will never be deleted (the delete dialog will not be shown) and if the archive is encrypted it gets only deleted when you choose in the separate delete dialog yes. If "yes for all" is chosen or in the dual display dialog the radio button was set to "delete all archives" such an archive will not be deleted.

Extract.dcf (39.8 KB)

1 Like

I want to differentiate between encrypted archives and damaged archives. But in both cases the fileattr is undefined.
Difference is that the enum error code for encrypted archives is 5 and for damaged -12 (at least for my test archives) Is there somewhere an overview what the error codes means?
Or I need another idea how to differentiate them.

Background: Idea is to write into a text file a list which archives were password protected, which one failed during extraction, which folders were renamed, etc. (instead of a dialog at the end).
In general it works, but this check adds at the moment also damages archives to the encrypted archives list:

if (folderItem.fileattr != undefined) {
	if (folderItem.fileattr.e) {
		DOpus.Output("Content of archive is encrypted\n");
		enc = true;
		confenc = true;
		enclis += item.name + ",";
		}
	else {
		DOpus.Output("Content of archive is not encrypted\n");
		enc = false;
		}
	}
	else if (folderItem.fileattr == undefined) {
		DOpus.Output("Enumeration Error code: " +folderEnum.error);
		DOpus.Output("Content and file list of archive is encrypted\n");
		enc = true;
		confenc = true;
		enclis += item.name + ",";
		}

If I use for the code line with "else if" else if (folderItem.fileattr == undefined && folderEnum.error == 5) { I get the result I want, but I do not know if the error code is always 5 for archives with encrypted file list.

Info:
If also the file list of an archive is encrypted and you cancel the password promt the extraction fails and cmd.files(0).failed is true. Here you get only the choise between ok and cancel in the password promt.
If only the files are encrypted cmd.files(0).failed is false. But in the password promt is also the choise "skip".

Positive error values are standard Windows error codes. Negative ones are Opus-specific errors.

Error 5 is ERROR_ACCESS_DENIED.

There are websites with the Windows error codes, although I couldn't find one that was very easy to read/search with everything on one page. I made a tool which lets you type in a number or string to find the meaning, which is what I tend to use: Find Error (find Win32 errors by name, number or description)

Error -12 is VFSERR_BADZIPFILE ("The archive appears to be invalid or damaged.")

The vfs plugins.h from the plugin SDK lists them, but I'll just paste them here for you:

// Custom Directory Opus file errors
#define VFSERR_COPY_INTO_ITSELF			-2		// You can't copy or move a folder into itself.
#define VFSERR_NOT_SUPPORTED			-3		// The operation is not supported by this VFS.
#define VFSERR_MOVE_INTO_SAMEDIR		-4		// Source and destination must be different to move files.
#define VFSERR_DIR_ALREADY_EXISTS		-5		// Cannot create a folder when that folder already exists.
#define VFSERR_FILE_IS_DIR				-6		// File is really a folder.
#define VFSERR_BADLINK					-7		// Link does not point to a valid file.
#define VFSERR_NOTEXPORTFILE			-8		// File is not a valid exported Preferences file.
#define VFSERR_NORECYCLEBIN				-9		// Object cannot be placed in the recycle bin and will be permanently deleted.
#define VFSERR_RECYCLETOOBIG			-10		// Object is too large to be placed in the recycle bin and will be permanently deleted.
#define VFSERR_NOPRINTHANDLER			-11		// File does not have a registered Print handler.
#define VFSERR_BADZIPFILE				-12		// The archive appears to be invalid or damaged.
#define VFSERR_GENERALERRMSG			-13		// General error.
#define VFSERR_WRITEPROTECTED			-14		// The disk is write protected.
#define VFSERR_WRITEPROTECTEDZIP		-15		// The archive is write protected.
#define VFSERR_ZIPISDIR					-16		// A folder already exists by that name.
#define VFSERR_CANTRENAMEFOLDERS		-17		// Folders within the archive cannot be renamed unless they are empty.
#define VFSERR_SHARINGVIOLATION			-18		// The file that you are trying to copy to is in use by another process. Select the Schedule option to schedule the file copy to take place automatically the next time you restart your computer.
#define VFSERR_ALREADYINCOLL			-19		// The item is already in the collection.
#define VFSERR_CANTCOPYTOCOLLROOT		-20		// Files cannot be added to the File Collections root folder.
#define VFSERR_NOMOVETOCOLLECTION		-21		// Files cannot be moved into a collection.
#define VFSERR_NOJOINTOCOLLECTION		-22		// Files cannot be joined into a collection.
#define VFSERR_NODROPDATATOCOLLECTION	-23		// Data-only files cannot be added to a collection.
#define VFSERR_NOCOLLINCOLL				-24		// Collections cannot be added to other collections.
#define VFSERR_FEATURENOTENABLED		-25		// The feature is not enabled.
#define VFSERR_UNKNOWNERROR				-26		// An unknown error occurred.
#define VFSERR_CANTCOPYFILEOVERITSELF	-27		// You can't copy a file over itself.
#define VFSERR_CANTCHANGEZIPCASE		-28		// Unable to change the case of filenames within the archive. You must first move the file out of the archive, rename it on disk, then add it back to the archive.
#if ( VFSPLUGINVERSION >= 2 )
#define VFSERR_NOT_EXTRACTABLE			-29		// The file is not extractable.
#endif
#if (VFSPLUGINVERSION >= 4 )
#define VFSERR_NOBITMAP					-30		// Unable to get image to save.
#define VFSERR_MULTIVOLUMEZIP			-31		// Unable to perform the operation on the particular archive. For example, there is only limited support for modifying multi-volume and solid archives.
#define VFSERR_ZIPFILELOCKED			-32		// The archive is locked.
#define VFSERR_LIBRARY_EMPTY			-33		// The library does not contain any member folders.
#define VFSERR_NOCOPYTOFINDRESULTS		-34		// Cannot add items to Search Results.
#define VFSERR_ARCTYPEISREADONLY		-35		// Unable to create or modify archives of this type.
#define VFSERR_WINRARLIMITATION			-36		// Unable to perform the operation due to limitations of WinRAR. For example, files cannot be renamed while being added and all added items must be below a common folder.
#define VFSERR_WINRARNOTFOUND			-37		// WinRAR v4.00 or above is required to modify RAR archives. You can set the WinRAR.exe path in the RAR VFS Plugin configuration if you have WinRAR but it was not found automatically.
#define VFSERR_WINRARFAILED				-38		// WinRAR reported failure updating the archive.
#define VFSERR_PASSWORDCONFLICT			-39		// The password specified for new files is not the same as the password for existing files in the archive.
#define VFSERR_BADMULTIVOLARCHIVE		-40		// The archive is an incomplete multi-volume set. (This can happen if parts are missing or if you try to open anything but the first part.)
#endif

(PS: It'd probably make sense to ask these questions in their own threads, as the thread for the actual script is quite hard to read now.)

1 Like

Here a new version for testing (according to my testing it works fine):
Extract.dcf (44.3 KB)

Changes compared to V1.0.224:

  • the button script checks now if the archive is encrypted (only the files or also the file list)
  • the button script recognizes now if the extraction was successful (but cannot detect a failed extraction due to a cancelation of a password dialog of an encrypted archive)
  • Encrypted archives and archives where the extraction failed will not be deleted (automatically) if the extraction setting was set to "delete all archives" or "yes for all" was chosen in the delete dialog box. Only if you choose "yes" in this dialog box the archive will be deleted.
  • The information dialog box which informed the user about skipped items or changed folders is replaced by the creation of a text file, which will be opened by the script and deleted automatically after 10 minutes. Added here information about not deleted encrypted archives or archives where the extration failed. The text file will only be created if necessary - so if everything worked fine it does not exist.

@onedot3 / @khalidhosain : Feel free to test this version if you like to and give feedback (e.g. about the text file).

@Mosed
Button stays greyed out no matter how many archives are selected
Commented out //@disablenosel:type=grp:Archive
And it worked
Had a look at V1.0.224
and first line is @disablenosel:type=grp:Archives
Added the "s" to Archive and button now shows
If I remember right its something to do with language
Now to do some testing
How long is the password cached

To make a corrupt archive make an archive then edit it with note pad and delete some of the first characters then save.
Testing with password and corrupt files Delete All Selected
With just password and normal All Ok
With just corrupt and normal All Ok
With password corrupt and normal files
Extraction and deletions All OK
But the text file that reports result does not always show what has happened
Examples
Files selected in this order
Password, Normal, Corrupt.
Message only mentions Password

Corrupt, Normal, Password
Message mentions Password and Corrupt

Password, Corrupt, Normal, Corrupt, Normal. Corrupt, Normal, Password, Corrupt
Message mentions 2 Password and 2 Corrupt
The one after the 1st password and the one after the last password are not mentioned.
Not much of a problem for me as they are still highlighted in the Source lister.
A suggestion don't know if it is possible could the source files be renamed with corrupt or password

1 Like

@onedot3 Thank you. You are right - I forgot to add the "s". My system language is German, so I have to change this every time I want to upload the button script... :slight_smile:

Successully extracted archives are not mentioned in the text file. Or do you think I should add them for the case that the text file is created to give there the full overview?
I think when everything worked fine the text file is not necessary.

I think I found the mistake. The variable which is set to true for encrypted archives was not set back to false when the next archive has an undefined file attribute, but is not an encrypted archive. So one case was missing in the check for encrypted archives which is added now.

It would be possible to rename source files, but I do not know if other people would like that.

Here a corrected version, were I got correct results now in the text file.
Extract.dcf (44.5 KB)

@Mosed Yes that has fixed it

Also did the same files and got the renamed folder list as well.
I only mentioned the renaming if you could not figure out how to fix the text list
Once you have the text list it's easy enough to mark the password and corrupt files your self
Cannot remember the last time I had a corrupt archive
Not sure about adding successful extracted. If only doing a few would be OK
But as khalidhosain said he was doing 100+ then list would be quite large.
Is it some thing that could be an option, I'm happy as it is.

1 Like

Hi there, is it also possible to use this script as event for zip file type? I want to avoid having an additional button in any toolbar and i tried as event but doesn't work and i get errors.


2nd question: Is it possible to only use smart extract function without prompt/pop up window to delete archive!?

Remove the @disa... line and start the script with

@script JScript