Smart archive extraction

A prompt afterwards would be better. But I don’t have time for now take care of it. If someone else want to add this feature and share, I will update my first post including it. Just be sure that if multiple archives are extracted, only one final prompt pops up to send all of them to the bin.

The function "Skips selected item if it’s not an archive and warns user later" does only work partially. The item is skipped, but there is no warning.

I tried another improvement and it seems to work: If nothing is selected I do not want to get a warning, I want that the button is disabled.

Therefore I added this command in first line:

@disablenosel:files

Better would be something related to archives, but until now I did not find a solution therefore beside adding every possible archive file ending to the command @disablenosel:type=*.zip
Has someone an idea?

And I removed the If / else loop for the warning if no file is selected or process the data. So, I deleted the if loop and removed the else {}. The content of the else-loop is still there.

@disablenosel:files
function OnClick(clickData) {
	var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
	var isDual = clickData.func.command.IsSet("DUAL=on");
	var fsu = DOpus.FSUtil();
	var Dlg = DOpus.Dlg;
	var selWarning = false;
	var isTargetSet = false;
	var canceled = false;
	cmd.deselect = false;
	cmd.SetDestTab(tab);

	// cmd.RunCommand('Set UTILITY=otherlog');
	DOpus.ClearOutput();
	DOpus.Output("SMART EXTRACT STARTS\n");
	DOpus.Output("is dual : " + isDual);


		DOpus.Output("Enumerating...\n");

		for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
			var item = e.item();

			if (!canceled) {
				// Skips selected item if it’s not an archive and warns user later.
				if (!item.InGroup("Archives")) {
					DOpus.Output("Error (not an archive file) : '" + item.name + "'");
					selWarning = true;
					continue;
				}

				// If it’s dual display, ask user where to extract
				if (isDual && !isTargetSet) {
					isTargetSet = true;
					Dlg.window = tab;
					Dlg.icon = "question";
					Dlg.top = true;
					Dlg.template = "destination";
					var retVal = Dlg.Show();
					// DOpus.Output("pressed button : "+retVal);

					switch (retVal) {
						case 1: // source
							// instruction
							DOpus.Output("pressed button : source");
							break;

						case 2: // destination
							DOpus.Output("pressed button : destination");
							cmd.SetDestTab(clickData.func.desttab);
							break;

						default:
							// cancel
							DOpus.Output("pressed button : cancel");
							canceled = true;
							DOpus.Output("\nSMART EXTRACT END\n");
							continue;
							break;
					}
				}

				var folderEnum = fsu.ReadDir(item);
				var folderItem = folderEnum.Next();
				if (folderItem.is_dir && folderEnum.complete) {
					var cmdLine = 'Copy FILE="' + item + '" WHENEXISTS=rename EXTRACT';
				} else {
					var cmdLine = 'Copy FILE="' + item + '" WHENEXISTS=rename EXTRACT=sub';
				}
				DOpus.Output(cmdLine);
				cmd.RunCommand(cmdLine);
			}

			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Show;
			}
			DOpus.Output("\nSMART EXTRACT END\n");
		}
	
}

Regarding deleting lxp wrote something in the original topic:

So we have to implement this with a promt.

1 Like

OK. I managed to add a dialog which ask if the archive shall be deleted.

				Dlg.window = tab;
					Dlg.icon = "question";
					Dlg.top = true;
					Dlg.template = "delete";
					var retVal2 = Dlg.Show();
					// DOpus.Output("pressed button : "+retVal2);

					switch (retVal2) {
						case 1: // yes
							// instruction
							DOpus.Output("pressed button : yes");
							cmd.RunCommand('Delete FILE="' + item + '" QUIET');
							break;

						case 2: // no
							DOpus.Output("pressed button : no");
							break;

					}

I want to make some more improvements. Then I can share the changed button.

EDIT: Another option is to use simply cmd.RunCommand('Delete FILE="' + item + '"'); Then Opus asks if the file shall be deleted.
But I have to check more in details the options...

I think I found the mistake.
The } in row 93 must be moved to row 84

So at the end. Instead:

				DOpus.Output(cmdLine);
				cmd.RunCommand(cmdLine);
			}

			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Show;
			}
			DOpus.Output("\nSMART EXTRACT END\n");
		}
	}
}

it must be:

				DOpus.Output(cmdLine);
				cmd.RunCommand(cmdLine);
			}
			}
			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Show;
			}
			DOpus.Output("\nSMART EXTRACT END\n");
		}
	
}

Now the script does not terminate after the "Skips selected item if it’s not an archive and warns user later" area when only e.g. a txt file is selected and you get the warning message.

Now I can work on the delete-function. I'm thinking about radio buttons in the source/destination dialog with a standard setting for delete or no delete. :slight_smile:

And do I see it right that the break; in row 60 (switch --> default) is not necessary, because the last option in a switch does this automatically.

The correct button disable-command for archive-files is @disablenosel:type=grp:Archives for English language. For some reason it is language-sensitive. in German it is @disablenosel:type=grp:Archive.

It's good form to include the break after the last item, else you'll create a bug when you add a new item after it without noticing it was missing.

The first version is available for testing. It seems to work fine, but I tried only dual-lister right now.
But this is the simple one which ask for each archive if it should be deleted.
I want to improve this further.

Changes compared to original script:

  • Removed check and message for the case, that nothing is selected at all
  • Added the function that the button is disabled as long as no archive file is selected
  • Fixed the issue that the warning "Some selected files were not archives." did not appear (relevant if you select more then one file)
  • Added a dialog which asks for each archive if it should be deleted. The dialog shows the archive name
  • Added German translation (the new delete-dialog does not have Frensh translation until version v2022.02.12b)

v2022.02.12a
Extract V2.dcf (13.3 KB)

v2022.02.12b
Extract V2.dcf (13.5 KB)

  • Fix: Warning regarding selected files is shown up now.

v2022.02.14a
Extract V2.dcf (17.4 KB)

  • Added possibility to choose "yes for all" and "no for all" in the delete-dialog (so the delete-dialog will only show up once when multiple files are selected for extracting)
  • Added Frensh translation for the delete-dialog (via google translate :crazy_face: )

v2022.02.14b
Extract V2.dcf (21.1 KB)

  • added in the target lister dialog (only for dual display mode) radio buttons to choose between "delete all archives"; " delete-query for each Archive" and "delete no archive". Standard setting is "delete all archives" - can be changed via dialog editor.
    Targetlister
  • separate delete dialog is only displayed now in single display mode or when you chose "delete-query for each archive" in the target lister dialog.

.
.
Important: The @disablenosel command is language sensitive. (Would be nice if this will be fixed). So the user has to adapt the first line of the script to the display language for the Archives file group.
e.g.:
English: @disablenosel:type=grp:Archives
German: @disablenosel:type=grp:Archive

@Mosed
Have just tried out V2 tried dual and single lister both work OK for everything
Except

  • Fixed the issue that the warning "Some selected files were not archives." did not appear (relevant if you select more then one file)
    Which only displays the Some selected files were not archives when the Cancel button is pressed

@onedot3: You are right. Thank you. The warning does not appear at all according my testing now.

But I do not know why. I have a similar variant with the primary difference, that I use "Dlg.show" instead of "Dlg.RunDlg.
Do I have to add something due to Dlg.RunDlg?
The relevant variable has the value "true" directly before the dialog code, so the dialog should appear.

This button works as written regarding the warning, but does not display the item name in the delete dialog:
Extract V2a.dcf (12.9 KB)

Left the V2a, right the V2. That is the only difference in the code.

EDIT: ok, its related to the Dlg.RunDlg.

For the warning I used Dlg.Show, but I have to use also Dlg.RunDlg there.

So instead of

			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Show;
			}

It must be:

			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Create();
				var x = Dlg.RunDlg;
			}

But why? The Dlg.Create(); from the delete dialog seems to "break" Dlg.Show for the subsequent script.
EDIT: ok, the "var x =" is not necessary before the "Dlg.RunDlg".

Mit geändertem Code:
Extract V2.dcf (13.5 KB)

@Mosed That was quick
Tried V2a Just seen your edit
New V2 better

Noticed
If extracting Dual Lister to Destination and I delete then the only files left selected are the non archive so do not really need the "Some selected files were not archives". Without delete all files are left Selected
If extracting Dual Lister to Source with or without delete then all files a deselected straight away, also Single Lister they are all deselected, if only it worked the same as Dual Lister to Destination.
This is the same as V2

As I always work from Right Source to Left Destination
Having the Source button on the left and the Destination button on the right feels all wrong to me.
Just before you posted V2 was trying to work out how to swap them but could not get it to work.
Would it be easy to show me what to change

I think the warning is more an information that a non-archive file was selected, but it was ignored.

You can easily change it. Choose customize for the button. Choose the ressource-tab. Choose from the menu the dialog "destination" and change the button position.

@Mosed I'd been trying to change button position by opening Extract V2.dcf in note pad. As others have said you learn something new everyday, that was a lot easier.
Thanks

@onedot3: I added a new version. See Smart archive extraction - #10 by Mosed

Perhaps you want to test the improvement. :slight_smile:

Edit: And I also added my target solution. If you use dual display you can choose in the target lister dialog if the Archives shall be deleted via radio buttons with a standard setting. So in general you only have to choose the target lister and only if necessary you have to choose another delete-setting. :slight_smile:

But would be nice if someone would look over the code and says if improvements are necessary. :slight_smile:

@Mosed Have downloaded V2022.02.14b have tested every combination I think as there are a lot.
The only thing is if you don't delete the archive and then extract the same archive and if just files in the archive, there is no warning and the files are extracted into the folder and (2) added at end, if there is a folder it brings up the Confirrn Folder Merge

ok. thank you.

But this behavior is identical to the original button I think. But I can check if this can be improved. (Its my first button / script change I do, so also for me it is learning by doing).

EDIT: @onedot3 In a first step you can replace the "rename" (2x) in the script with one of the parameters available here for "whenexists" if you like to have another behavior: http://127.0.0.1:36787/v12.26/index.html#!Documents/Copy.htm

I'm thinking about adding an option to choose this also in the destination dialog.

@Mosed Have been testing with changing whenexists to ask , skip etc which do work.
But would it be better if when creating the folder it checked if there was already a folder maybe easier to say than do.

I do not understand this sentence. What do you want to say? :slight_smile:

@Mosed I was thinking you could do a whenexists when creating the folder but I don't think it is possible. So the 2 changes are possibly the best

Ah ok. In general this seems to be possible. I have to check if it works also for this script.

But as first step I added a new version where you can choose the "whenexists" value in the destination dialog. For single display there is no dialog, but the default value can be changed in the script (for both).

@Mosed If archive has a folder inside it does not matter which of the "Ask what to do" you pick you always get asked to rename the Folder.

Yes. I recognized now that it does not work when you have an archive with a folder inside. At least for the subfolders Opus ask to skip or replace.
But that behavior is identical to the original button. There you get also the prompt that the subfolder already exists.

I removed the new version. Has to be corrected somehow. I think it makes more sense to check if the root folder exist and to decide then to skip or overwrite everything or to rename the root folder.