Author Topic: Select / deselect switch fault?  (Read 43585 times)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Select / deselect switch fault?
« on: June 03, 2014, 14:52:22 »
I'm trying to do a MS that will
  • select any zips
  • extract (& overwrite if req'd)
  • deselect
  • run a new function - eg new selection, rename & move on the extracted file
However the select / deselect command seems to malfunction.
Using the debugger to step through, this works:-

Code: [Select]
MC.Explorer.Select FILTER="*.zip"
MC.Explorer.Deselect FILTER="*.zip"

MC selects then deselects the zip(s)

However when I add an Unpack command:-

Code: [Select]
MC.Explorer.Select FILTER="*.zip"
MC.Filesystem.Unpack TARGET=${sourcepath} FILTER="*.*"
MC.Explorer.Deselect FILTER="*.zip"

MC reselects the zip at the end of the unpack routine. 
If it is a multi-part zip, MC will only select part 1, not the whole *.zip set at the end of the routine.

This means my next script commands do not get processed.
I also tried using MC.Explorer.Selection.Unselect & MC.Explorer.SetItemFocus but couldn't get away from the initial zip selection.

Also wondering about an 'overwrite' switch for the unpacker.  Can't find anything on MC.Filesystem.Unpack in the docs.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #1 on: June 03, 2014, 15:06:41 »
MC.Filesystem.Unpack do not call the Menu option.. it is calling the under laying code for unpack.

You need to specify that file to unpack. It will not take all files that exists

Code: [Select]
MC.Filesystem.Unpack FILE="C:\my.zip" TARGET="C:\UnPacked\"

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #2 on: June 03, 2014, 15:09:32 »
If you want to run an internal command, Like the one that are menu option and such.. then you need to call MC.RunCmd Cmd="",
use the Customized keyboard dialog to find the internal command id. Looks like "Core.1234" and such..

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #3 on: June 03, 2014, 16:20:13 »
Thanks Mathias.

Unfortunately I am most concerned about the deselection process.
MC leaves the hi-light/selection on zip#1.
I have discovered that if the .. at the top of the folder is hi-lited after each operation the script will run as I intended.  (I need to manually confirm overwrite etc during the process of course).

Can I make the selection move to the .. after a process?

if I have -
Code: [Select]
..
xyz.zip
-> extract *.*

I then get -
Code: [Select]
..
1.jpg
2.txt
3.exe
xyz.zip

& xyz.zip is still selected after the unpack

So with
Code: [Select]
MC.Explorer.Select FILTER="*.zip"
MC.Filesystem.Unpack TARGET=${sourcepath} FILTER="*.*"
MC.Explorer.Deselect FILTER="*.*"
MC.Explorer.Select FILTER="*.txt"
// ...This would then be followed by a rename function.

Sometimes only .zip is renamed or both txt & zip are renamed depending on how the selection bar behaves.  ??? 
Pic 3 was only achieved by selecting .. first, 1 & 2 are before & after the above script was run with no file selected.

If I do this process in steps & select the .. between the steps it will function correctly.  So I'd like to force deselect or selection of .. with hi-lite bar in active pane between each operation. 
Is that possible?

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #4 on: June 04, 2014, 09:02:43 »
I find I need the script command for what happens when pressing the <home> key. 
Perhaps - go to top ExplorerPanel.41075
Will see if I can make it work later.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #5 on: June 04, 2014, 09:05:59 »
Thanks Mathias.

Unfortunately I am most concerned about the deselection process.
MC leaves the hi-light/selection on zip#1.
I have discovered that if the .. at the top of the folder is hi-lited after each operation the script will run as I intended.  (I need to manually confirm overwrite etc during the process of course).

Can I make the selection move to the .. after a process?

if I have -
Code: [Select]
..
xyz.zip
-> extract *.*

I then get -
Code: [Select]
..
1.jpg
2.txt
3.exe
xyz.zip

& xyz.zip is still selected after the unpack

So with
Code: [Select]
MC.Explorer.Select FILTER="*.zip"
MC.Filesystem.Unpack TARGET=${sourcepath} FILTER="*.*"
MC.Explorer.Deselect FILTER="*.*"
MC.Explorer.Select FILTER="*.txt"
// ...This would then be followed by a rename function.

Sometimes only .zip is renamed or both txt & zip are renamed depending on how the selection bar behaves.  ??? 
Pic 3 was only achieved by selecting .. first, 1 & 2 are before & after the above script was run with no file selected.

If I do this process in steps & select the .. between the steps it will function correctly.  So I'd like to force deselect or selection of .. with hi-lite bar in active pane between each operation. 
Is that possible?


The Custom Commands are not really made to be run after each other.. they are used for simple action.
And calling them from a MultiScript is a "workaround" to be able to send dynamic parameters to it.
CustomCommands simulates that the user did the action from the UI. most of the time.. but sometimes not.
However many action in MC are done in the background or async and CustomCommand have no idea of that and will not wait.
So if you run multiple custom commands they can be called out of order. And since customcommand are sent via the UI layer (mostly) other change
that normally happens when the user do the action them self are also done. like it might change focus or selection and other stuff,
Unpack for example will unselect (v4.3,  did not before. but copy did) all and set focus item back to some item.
Since Custom Command goes via UI layer,  UI settings you have might also affect what is happening.

MultiScript commands are bypassing the UI layer. and act on core function directly as if there was no UI at all.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #6 on: June 04, 2014, 09:28:10 »
It think it would work better if you use MultiScript to find all files matching *.zip and then call unpack with all the zip files to unpack

Code: [Select]
@var $arrFiles = FindFiles("R:\\zipfiles\\*.zip");
@var $count = arrayCount($arrFiles);
@var $zipFiles = "";
@var $zip;
@var $n;
// Create ; separated list with all zip files to unpack
for( $n = 0; $n < $count ; $n++ )
{
 $zip = $arrFiles[ $n ];
 $zipFiles += $zip;
 $zipFiles += ";";
}

MC.Filesystem.Unpack FILE="{$zipFiles}" TARGET="r:\unp"



Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #7 on: June 04, 2014, 12:44:53 »
Sorry for giving you a lot of work explaining this!   

I can see now why sometimes my script could work & others not.  I think it did it perfectly once then went back to variable & jumbled....
But I was able to use MC.RunCmd ID="ExplorerPanel.41075" to get to the ..   :)  :)

I wonder if it would be possible to force custom commands to run in a sequence? 
Perhaps you could see a simple way to implement what is perhaps a kind of 'macro' function for Custom Commands.  (Maybe they are too exclusive in terms of environment to do this?) 
This makes me wonder about a plugin that would batch run Custom Commands + variables, in the GUI frontend.
e.g. Effectively if you had 3 virtual buttons with MC.Commands assigned, the 'macro' would run them in an assigned sequence.
This is a bit ambitious for me to try right now tho!!  ;)

I do not know how much work that entails or whether it is worth considering given your full road-map....

Thank you very much for the script I can use that to start over & work towards a real result! ;)
I will post back what I end up with.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #8 on: June 04, 2014, 13:02:42 »
I wonder if it would be possible to force custom commands to run in a sequence? 
You can.. But the order is not guaranteed. and not recommended, All depend on the command used.
If you need to do more then 1 thing.  then use MultiScript as much as possible.
CustomCommand are only there so minor things can be done simply. if you need complex tasks.  MultiScript should be used.

Perhaps you could see a simple way to implement what is perhaps a kind of 'macro' function for Custom Commands.  (Maybe they are too exclusive in terms of environment to do this?) 
This makes me wonder about a plugin that would batch run Custom Commands + variables, in the GUI frontend.
e.g. Effectively if you had 3 virtual buttons with MC.Commands assigned, the 'macro' would run them in an assigned sequence.
This is a bit ambitious for me to try right now tho!!  ;)
No Do not think it is possible. many custom commands are async.. You Fire them off and then continue without waiting.

But if you find a user case of something you want to automate/script. Then we can see if some script function might be needed.
to be able to do that.  Also plugin have full access to everything inside MC. and can do even more. But that require C++ knowledge :)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #9 on: June 04, 2014, 20:04:57 »
My plans have hit a snag...

Your script works perfectly (obviously!), but I don't seem to be able to give it the source path.
The GetSelectedPaths(); & GetSourcePath(); commands don't seem to be able to be used with my existing syntax.
I know the path can be seen as an array so I tried various versions of
Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $arrFiles = FindFiles("{$arr}\*.zip");
& also as a string
Code: [Select]
@var $path = GetSourcePath();
@var $arrFiles = FindFiles("{$path}\*.zip");

After a lot of attempts & variations I still cannot see how to pass the path to the FindFiles command
I am missing variables &/or syntax, & just cannot see how to implement something like ${source}

I feel I should be able to figure this out but I am struggling  :-[  (& I am reading the online docs)

I appreciate you taking time to explain how the command system works.
I would like to gain some more coding knowledge.  C++ has interested me in the past, & if I get time for this I will try & get into it.  Would be nice to make a contribution to MC that is useful!!

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #10 on: June 04, 2014, 22:23:32 »
No you are mixing up stuff

FindFiles(...) are a MultiScript function..

CustomCommand Script is one line script. And they do not support variables and expression or other programing stuff.
MultiScript does support all that. BUT MultiScript can also call CustomCommand commands. But they are run by the CustomCommand engine.
So if you want to include a parameter that you use in a MultiScript on a line that is a CustomCommand. Then the Engine must first preprocces the parameter. and to be able to do that it must be encapselated inside a { }, 

Example
@var $file = GetMyFile();
MC.FileSystem.UnPack FILE="{$file}"

Everything inside the { } on the CustomCommand line is preprocces by the MultiScript engine
and the result of it is the inserted in that place before the CustomCommand is called.

In normal MultiScript functions you should not use { } around variable
They are used to define scope.. like the BEGIN , END of blocks for loops and expressions like IF, WHILE, FOR


Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #11 on: June 05, 2014, 22:08:50 »
OK I see that I am confusing things....  I am gradually getting the topology now though, thanks.

I wasn't sure how to use the path variable, I tried with & without various {}, //, /, ", & nothing seemed to work when it came to giving the path to the command.
I am thinking I must need to process more @var, I can get the path shown but not correctly passed to the FindFiles.
All the array functions seem to include a file selection, & a plain string is rejected.

So I must need to define something else so that the $CurrentNameFullPath is able to be used.....  Few hours in I don't see it.

Code: [Select]
@var $root = GetSourcePath();
@var $path = PathGetParts( $root );
@var $items = arrayCount($path);
@var $CurrentNameFullPath;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $path[ $n ];
  }


@var $arrFiles = FindFiles( $CurrentNameFullPath *.zip"); 
Crashes here - Script engine error => Failed to process token - "$CurrentNameFullPath"

 --- can I restrict $path to the parts before the <blank> item $array [2]?  I unsuccessfully tried to trim element 2 with
Code: [Select]
{
arrayRemove($path, 2);
}

So I'm still missing something.  I will keep trying....

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #12 on: June 05, 2014, 22:41:02 »
Quote
@var $arrFiles = FindFiles( $CurrentNameFullPath *.zip");   
You are missing a quotes and also you need to append the "*.zip" with the variable. for strings that is done with "+"

Code: [Select]
@var $arrFiles = FindFiles( $CurrentNameFullPath + "*.zip");
Quote
arrayRemove($path, 2);
Works for me.. $path is an array (list) with 3 items. and arrayRemove( ..., 2 ) will remove the last one.

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #13 on: June 06, 2014, 12:08:32 »
 :)
My code deployment & running low on caffeine obviously getting in the way!
I have managed to finally get the path into the query  ;)

Code: [Select]
@var $root = GetSourcePath();
@var $path = PathGetParts( $root );
@var $items = arrayCount($path);
@var $CurrentNameFullPath;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )

{
  $CurrentNameFullPath = $path[1];
  arrayRemove($path, 2);
  }


@var $arrFiles = FindFiles( $CurrentNameFullPath + "*.zip");
@var $count = arrayCount($arrFiles);
@var $zipFiles = "";
@var $zip;
@var $n1;


// Create ; separated list with all zip files to unpack
for( $n1 = 0; $n1 < $count ; $n1++ )
{
 $zip = $arrFiles[ $n1 ];
 $zipFiles += $zip;
 $zipFiles += ";";
}

MC.Filesystem.Unpack FILE="{$zipFiles}" TARGET="{$folder}"

But I have hit a curious snag.  See attached. 
Line 27 hangs the debugger & I must force MC to shut-down.  :o

Code: [Select]
Description:
  A problem caused this program to stop interacting with Windows.

Problem signature:
  Problem Event Name: AppHangB1
  Application Name: MultiCommander.exe
  Application Version: 4.3.0.1694
  Application Timestamp: 538b2aaf
  Hang Signature: b3ef
  Hang Type: 0
  OS Version: 6.1.7601.2.1.0.256.1
  Locale ID: 2057
  Additional Hang Signature 1: b3ef002d84fb7e8c44004ed0fea8ce18
  Additional Hang Signature 2: bee0
  Additional Hang Signature 3: bee08592e35171afe9c215ff30dafcb5
  Additional Hang Signature 4: b3ef
  Additional Hang Signature 5: b3ef002d84fb7e8c44004ed0fea8ce18
  Additional Hang Signature 6: bee0
  Additional Hang Signature 7: bee08592e35171afe9c215ff30dafcb5

Now I have to do some ''real'' work  :( 
I will come back to this later & look for the reason tho...
Thanks Mathias.
« Last Edit: June 06, 2014, 12:10:43 by Ulfhednar »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #14 on: June 06, 2014, 12:52:51 »
I don't know why it crash I have not had time to test it

But ...
Code: [Select]
for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $path[1];
  arrayRemove($path, 2);
 }
Why are you doing this ? You are looping around the number of times there are items the $path list. but on every loop you do the same thing to same items in the list.
And you remove item from the $path list but you never use the path list again.


Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #15 on: June 06, 2014, 20:38:23 »
 ???
That was the only way I found to make the FindFiles function accept the path.
[$n] left the value $CurrentNameFullPath as 'unknown'.

Running this on the source dir seems to work 100%, the debug shows what I think it should (but I am  still a newb) so which component is introducing the loop?
$CurrentNameFullPath = $path[1]; ?
I thought I needed $n++ (like regex) to make sure the path was fully scanned.

Code: [Select]
@var $root = GetSourcePath();
@var $path = PathGetParts( $root );
@var $items = arrayCount($path);
@var $CurrentNameFullPath;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )

{
  $CurrentNameFullPath = $path[1];
  arrayRemove($path, 2);
  }


@var $arrFiles = FindFiles( $CurrentNameFullPath + "*.zip");
@var $count = arrayCount($arrFiles);
@var $zipFiles = "";
@var $zip;
@var $n1;


// Create ; separated list with all zip files to unpack
for( $n1 = 0; $n1 < $count ; $n1++ )
{
 $zip = $arrFiles[ $n1 ];
 $zipFiles += $zip;
 $zipFiles += ";";
}

MC.Filesystem.Unpack FILE="{$zipFiles}" TARGET="${sourcepath}"

Thanks so much for fixing the debugger in the latest release 4.3 b1698, it has made my many critical  errors easier to handle!  :)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #16 on: June 06, 2014, 21:11:30 »
It might work but you are doing crazy things that does not make sense.

The path you set at
Code: [Select]
$CurrentNameFullPath = $path[1]; is the same as you get from the start
Code: [Select]
@var $root = GetSourcePath();
Also the first "for" loop is messed up and is not running so not sure what you are doing with that..

Also for source path you are using the MultiTags that are for simple customcommands. but this is a MultiScript so even thought it works it is not very "good" code.
There is MultiScript functions for it that you already are using.
Code: [Select]
@var $root = GetSourcePath();Just send $root to it.
« Last Edit: June 06, 2014, 21:16:18 by Mathias (Author) »

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #17 on: June 07, 2014, 00:00:11 »
Ahh I see.
I had initially made a mistake with the
Code: [Select]
@var $arrFiles = FindFiles( <Path> + "*.zip");line that led me to seek an array, which it then eventually accepted.

But if I had had that line correct my thought of GetSourcePath(); would have been accepted.  My syntax errors blocked that.
So one syntax error led to a flood of 'patches'  until it eventually worked.
Maybe I should apply for jobs in the PC game software industry, I've seen this kind of thing there more than once.  :P
I can see why it would make you mad....  it only needed to be -

Code: [Select]
@var $root = GetSourcePath();
@var $arrFiles = FindFiles( $root + "*.zip");
@var $count = arrayCount($arrFiles);
@var $zipFiles = "";
@var $zip;
@var $n1;


// Create ; separated list with all zip files to unpack
for( $n1 = 0; $n1 < $count ; $n1++ )
{
 $zip = $arrFiles[ $n1 ];
 $zipFiles += $zip;
 $zipFiles += ";";
}

MC.Filesystem.Unpack FILE="{$zipFiles}" TARGET="${sourcepath}"

The upside is I have learnt good some new things.  My redundant code did get me to experiment with functions I didn't follow before.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #18 on: June 07, 2014, 01:23:24 »
I can see why it would make you mad....  it only needed to be -
Not mad, I was just confused and wonder if there was some reason behind it that I did not see.

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #19 on: June 07, 2014, 13:27:34 »
OK I didn't want you to feel you were wasting your time.  ;)

I did wonder why I had to define so many elements to get it to recognize & accept the path - took me back to Basic - but it started to do other things so it became a challenge/game to find more functions & get different results output to the debugger.

I can now start looking at making a more complex script with multiple tasks - my original ideas may yet be possible!   :o

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #20 on: June 08, 2014, 15:43:57 »
I am still wondering about moving the selection bar.
MC.Explorer.Select doesn't work mid script... So I thought maybe adding findfiles would. 
Also wondered if I can use findfiles with multiple exts?
e.g.
Code: [Select]
$xx = FindFiles( $root + "*.gif" + "*.jpg" + "*.txt");Syntax?

Can I pass the result to
Code: [Select]
MC.Explorer.Select = "{ $xx}"
Haven't found correct way yet (if it's possible).  Or is there a better option?

I wanted to run an extract followed by a select & rename op.  As it is I cannot get the selection bar to where I want it...


Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Re: Select / deselect switch fault?
« Reply #21 on: June 08, 2014, 16:13:05 »
I am still wondering about moving the selection bar.
MC.Explorer.Select doesn't work mid script... So I thought maybe adding findfiles would. 
Also wondered if I can use findfiles with multiple exts?
e.g.
Code: [Select]
$xx = FindFiles( $root + "*.gif" + "*.jpg" + "*.txt");Syntax?
No, multiple patters are not supported. It takes a path with a pattern.
You can run FindFiles multiple times or do "*.*" and then remove the files you do not want your self.

Can I pass the result to
Code: [Select]
MC.Explorer.Select = "{ $xx}"
There is no command named that..  maybe you mean MC.Explorer.Selection.Select , but no.. it takes a text filter of what to match.
and $xx from FindFiles is an array ( list of many text strings )

But As I said before. mixing CustomCommands and MultiScript in that way is not good. The work on different level.
Why not use the MultiScript rename function.. no need to select files..
CustomCommands are not made to be used as automation.

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Select / deselect switch fault?
« Reply #22 on: June 08, 2014, 19:19:49 »
Thanks Mathias.  I am trying to avoid mixing command types & thought multiple findfiles operations would probably be the best way, wanted to be sure.
I was thinking in steps
  • extract
  • select by .ext
  • rename
so have not thought of 'jumping' straight to rename, but if I can define what is renamed then that makes more sense.
If I can put in a mask, such as "*.jpg", it would solve my problem.
I will see how far I can get...  :)