Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - pncdaspropagandas

Pages: 1 2 [3] 4
51
Script / Go To Link Target v2
« on: August 02, 2017, 03:38:05 »
Hi,

As Mathias added new functions to MultiScript, I updated my script. Now it is much mor concise.

For the hardlink detection I use FindLinks from SysInternals on https://docs.microsoft.com/en-us/sysinternals/downloads/findlinks and put it on mcinstallpath\Tools\Links\Hardlinks

MultiScript:
// Junction, Symlink, MountPoint & Windows Shrtcut -> get link target with MultiComander - reliable
// Hardlink -> get link target with findlinks64.exe - communication via text file

@var $source_focus_path = GetSourceFocusPath();
@var $link_target;
@var $link_targets[];
@var $target_count;
@var $link_found;
@var $link_target_temp_file;
@var $temp_file_content;
@var $link_target_file_size;
@var $findlinks_path;
@var $aux[];
@var $aux2;
@var $n;
@var $mcinstallpath = GetTagValue("${mcinstallpath}");

//0 - Not a link (maybe a hardlink)
//1 - Junction
//2 - Symlink
//3 - MountPoint
@var $link_type = GetFSLinkType($source_focus_path);
if( $link_type == 0 )
{
   $link_target = GetWinShortcutTarget($source_focus_path);
   //LogAppInfo('shortcut to ' + $link_target);
   if( !($link_target == '') )
   {
      $link_found = 1;
      SetClipboardText($link_target);
   }
   else
   {
      // Hardlink
      $link_target_temp_file = $mcinstallpath ^ 'Tools\Links\Hardlink\link_target.txt';
      $findlinks_path = $mcinstallpath ^ 'Tools\Links\Hardlink\FindLinks.exe';
      
      if (FileExists($link_target_temp_file) == 1)
      {
         $aux = {"NOPROGRESS", "NODIALOG", "SILENT"};
         DeleteFile($link_target_temp_file, $aux);
      }
      
      LogAppInfo('C:\Windows\System32\wscript.exe "' + $mcinstallpath ^ 'Tools\run_invisible\run_invisible_bat_2_args.vbs" "' + $mcinstallpath ^ '\Tools\Links\Hardlink\bat_findlinks.bat" "' + $source_focus_path + '" "' + $link_target_temp_file + '"');
      MC.Run CMD={'C:\Windows\System32\wscript.exe'} ARG={'"' + $mcinstallpath ^ 'Tools\run_invisible\run_invisible_bat_2_args.vbs" "' + $mcinstallpath ^ '\Tools\Links\Hardlink\bat_findlinks.bat" "' + $source_focus_path + '" "' + $link_target_temp_file + '"'} STARTIN={$mcinstallpath ^ '\Tools\Links\Hardlink'} WAIT
      
      
      // Work on FindLinks' return
      if (FileExists($link_target_temp_file) == 1)
      {
         //Sleep(100);
         
         $link_target_file_size = GetFileSize($link_target_temp_file);
         if ($link_target_file_size > 0)
         {
            $temp_file_content = LoadStringFromFile($link_target_temp_file);
            //LogAppInfo($temp_file_content);
            
            // Delete temp file
            $aux = {"NOPROGRESS", "NODIALOG", "SILENT"};
            DeleteFile($link_target_temp_file, $aux);
            
            // Check/Parse link_target_temp_file content
            @var $temp_file_lines[] = StrLines2Array($temp_file_content);
            if( StrIsWildMatch($temp_file_lines[0], 'Error*') )
            {
               MessageBox('Resolve Link', 'Error logged by FindLinks.', 0);
               break;
            }
            else
            {
               $target_count = arrayCount($temp_file_lines);
               // 4 lines -> no links
               // 7 lines -> 1 link
               // 8 lines -> 2 links
               // etc
               if( $target_count >= 6 )
               {
                  $link_found = 1;
                  $link_target = $temp_file_lines[5];
                  
                  // More than 1 hardlink found
                  if( $target_count > 6 )
                  {
                     // Mount an array with all hardlinks targets, so the user can choose
                     for( $n=5; $n<$target_count; $n++ )
                     {
                        arrayAdd($link_targets, $temp_file_lines[$n]);
                     }
                     
                     // Ask user
                     @var $link_targets_answer = AskOption('Select target', $link_targets, 0);
                     if ($link_targets_answer == -1)
                     {
                        // User cancelled
                        break;
                     }
                     
                     $link_target = $link_targets[$link_targets_answer];
                  }
               }
            }
            
         }
         else
         {
            LogAppInfo('Error');
         }
   
      }
      else
      {
         MessageBox('Resolve Link', 'Operation timeout', 0);
         break;
      }
   }
}
else
{
   // Junction, Symlink or MountPoint
   $link_found = 1;
   $link_target = GetFSLinkTarget($source_focus_path);
}


// Go to target
if( $link_found )
{
   // Clear selected files in the case of the link target being on the same folder
   arrayAdd($aux, '');
   SetSourceSelected($aux, 1);
   
   SetClipboardText($link_target);
   
   // As Mathias said here http://forum.multicommander.com/forum/index.php/topic,1929.0.html
   // "the UI can't be updated until the script is finished since the script is running in the same thread"
   // So there's no way to break going to the folder, then selecting the file in 2 operations
   // We can do it in 1 go using MC.RunCmd ID="Core.1312" that is CTRL+V with the target path on the clipboard
   
   // Go To Link Target
   MC.RunCmd ID="Core.1312"
   
}
else
{
   MessageBox('Resolve Link', 'Not a link.', 0);
}


bat_findlinks.bat file:
FindLinks.exe %1 > %2

52
Feature Requests and Suggestions / Re: Sync Panels Navigation
« on: August 02, 2017, 03:29:53 »
Ok, in the meantime I will make a script!

Many thanks!

53
Script / Load file content to clipboard
« on: August 01, 2017, 18:46:30 »
In my PC, if I try to use the internal function to load file content to clipboard on a rather large file, MC hangs. So I created a script that decides when to use the built in function and when to use clip.exe

MC Script:
@var $focused_file = GetSourceFocusPath();
@var $focused_file_size = GetFileSize($focused_file);
@var $mcinstallpath = GetTagValue("${mcinstallpath}");

// MultiCommander doesn't support files bigger than ???KB, so we have to use window's clip.exe program
if ($focused_file_size > 307200)
{
   //LogAppInfo('C:\Windows\System32\wscript.exe "'  + $mcinstallpath ^ '\Tools\run_invisible\run_invisible_bat_1_arg.vbs" "' + $mcinstallpath ^ '\Tools\run_invisible\load_file_content_to_clipboard.bat" "' + $focused_file + '"');
   MC.Run CMD={'C:\Windows\System32\wscript.exe'} ARG={'"' + $mcinstallpath ^ '\Tools\run_invisible\run_invisible_bat_1_arg.vbs" "' + $mcinstallpath ^ '\Tools\run_invisible\load_file_content_to_clipboard.bat" "' + $focused_file + '"'}
}
else
{
   @var $focused_file_content = LoadStringFromFile($focused_file);
   SetClipboardText($focused_file_content);
}

run_invisible_bat_1_arg.vbs
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
'MsgBox(WScript.Arguments(0))
WshShell.Run """" & WScript.Arguments(0) & """ """ & WScript.Arguments(1) & """",0,true

load_file_content_to_clipboard.bat
clip < %1


The reason to use a bat file instead of just running clip < %1 is that when you execute a command line with no visible cmd, the stdout doen't work.

54
Feature Requests and Suggestions / Re: Sync Panels Navigation
« on: August 01, 2017, 15:33:35 »
Hi Mathias

Any thoughts on this?

Thanks

55
User Contributed Content / Re: Notepad++ MCS Language Support
« on: August 01, 2017, 13:29:20 »
Hi mgoodwin,

Yes, there is a separator between keywors. I Don't know why it didn't go right in the first time. I modified my post and pasted again.

Thanks

56
Feature Requests and Suggestions / Sync Panels Navigation
« on: July 25, 2017, 13:15:37 »
Hi Mathias,

I wonder if its viable to have the option to sync the navigation on both panels:

Left panel is at C:\My Documents
Right panels is at external drive D:\Backup\My Documents

When entering a subfolder in any panel, the other panel also enter the same folder

Left panel is at C:\My Documents\Office
Right panels is at external drive D:\Backup\My Documents\Office

Thanks

PS: I'm amazed of how many features MC has!

57
Support and Feedback / Re: Image dimensions
« on: July 19, 2017, 14:20:27 »
Ohh I see. It worked. Thanks  :D

58
Support and Feedback / Image dimensions
« on: July 18, 2017, 15:39:13 »
Hi,

I was working with images on detailed view. I added the column dimension but it didn't show anything on bmp, jpg and png files. I tried refreshing, going to parent folder and back, but nothing happened. I have Picture tools plugin enabled.

What am I doing wrong?

Thanks

59
Support and Feedback / Buttons and tab focus
« on: July 18, 2017, 15:27:28 »
Hi,

When I click a button on the button bar, let's say to select files with same extension, then the files are selected but the tab/panel looses focus.

I have to carefully click on a grey area to focus the tab/panel again and then, let's say delete the files pressing del on the keyboard.

Is there a way not to loose focus?

Thanks

60
Documentation / Re: Go To Link Target
« on: July 18, 2017, 14:06:26 »
Hi Mathias,

I just want to inform that the documentation is misspelled.

The function GetLinkTarget is actually GetFSLinkTarget

And the
<num> GetFSLinkType( <str> path, <str> fileProp );
should be
<num> GetFSLinkType( <str> path );
I think (as it seems a copy paste from the function above)

61
Script / Re: Go To Link Target
« on: March 13, 2017, 14:34:49 »
This is great! It will make things way more simple and realiable! Thanks Mathias!

62
Support and Feedback / Re: Selecting files
« on: February 27, 2017, 21:08:44 »
Ok, thanks AlanJB!

63
Support and Feedback / Re: Selecting files
« on: February 27, 2017, 19:19:36 »
Did you get the same results?

64
Support and Feedback / Re: Selecting files
« on: February 22, 2017, 11:58:45 »
I did further testing and using a fresh install with explorer style. You can reproduce the problem doing:

- Press END
- Hold SHIFT
- Press UP
- Release SHIFT
- Press UP
- Press END
- Hold SHIFT
- Press UP

The second time you hold shift and press up to select the last 2 files, MC gets crazy and select the 2 files before the last.

Thanks

65
Script / Go To Link Target
« on: February 10, 2017, 19:22:28 »
I did a script that when focusing on a Shortcut / Symbolic Link / Hardlink / Junction it navigates to it's target.

It's a mix of MC Script, Python and an executable (because it seems no one care about enumerating hardlinks targets)

If there's more than 2 instances of a hardlink or junction, the script asks the user witch one he likes.

I'm posting the main Python code (I used some custom libs I did). If people get interested I can post the full code.

MC Script:
@var $source_focus_path = '"' + GetSourceFocusPath() + '"';
@var $python_script_path;
@var $link_target;
@var $link_target_temp_file;
@var $link_target_file_size;
@var $findlinks_path;
@var $aux[];
@var $aux2;

$python_script_path = '"' + GetTagValue("${mcinstallpath}") ^ 'Tools\Links\Resolve Link.py' + '"';
$link_target_temp_file = GetTagValue("${mcinstallpath}") ^ 'Tools\Links\link_target.txt';
$findlinks_path = '"' + GetTagValue("${mcinstallpath}") ^ 'Tools\Links\Hardlink\FindLinks.exe' + '"';


if (FileExists($link_target_temp_file) == 1)
{
   $aux = {"NOPROGRESS", "NODIALOG", "SILENT"};
   DeleteFile($link_target_temp_file, $aux);
}

// There's a bug in StrReplace when using ^ in parameter
$aux2 = '^"';
$python_script_path    = StrReplace($python_script_path, '"', $aux2);
$source_focus_path     = StrReplace($source_focus_path, '"', $aux2);
$findlinks_path        = StrReplace($findlinks_path, '"', $aux2);
$link_target_temp_file = StrReplace($link_target_temp_file, '"', $aux2);
// Run Python script to get link target and store it in a temp file
LogAppInfo('"H:\Programas\MultiCommander - Projetos\Tools\Command Line Utilities\nircmd\nircmd_x64.exe" execmd "^"C:\Python35\python.exe^" ' + $python_script_path + ' ' + $source_focus_path + ' ^"' + $link_target_temp_file + '^" ' + $findlinks_path + '"');
MC.Run CMD='"H:\Programas\MultiCommander - Projetos\Tools\Command Line Utilities\nircmd\nircmd_x64.exe"' ARG={'execmd "^"C:\Python35\python.exe^" ' + $python_script_path + ' ' + $source_focus_path + ' ^"' + $link_target_temp_file + '^" ' + $findlinks_path + '"'} WAIT

// Clear selected files in the case of the link target being on the same folder
arrayAdd($aux, '');
SetSourceSelected($aux, 1);

// Ao rodar o nircmd ele retorna o sinal de terminado para o MultiComander antes de o Python ter terminado de rodar
// Então temos que esperar manualmente até o Python ter terminado de rodar
// A cada 50ms checamos se o arquivo $link_target_temp_file foi criado, até um timeout de 1s
@var $n;
for ($n = 0; $n < 20; $n++)
{
   if (FileExists($link_target_temp_file) == 1)
   {
      break;
   }
   Sleep(50);
}

// Go to target
if (FileExists($link_target_temp_file) == 1)
{
   Sleep(100);
   
   //LogAppInfo($link_target_temp_file);
   $link_target_file_size = GetFileSize($link_target_temp_file);
   if ($link_target_file_size > 0)
   {
      $link_target = LoadStringFromFile($link_target_temp_file);
      //LogAppInfo($link_target);
      
      // Delete temp file
      $aux = {"NOPROGRESS", "NODIALOG", "SILENT"};
      //DeleteFile($link_target_temp_file, $aux);
      
      // Clear selected files in the case of the link target being on the same folder
      arrayAdd($aux, '');
      SetSourceSelected($aux, 1);
      
      // As Mathias said here http://forum.multicommander.com/forum/index.php/topic,1929.0.html
      // "the UI can't be updated until the script is finished since the script is running in the same thread"
      // So there's no way to break going to the folder, then selecting the file in 2 operations
      // We can do it in 1 go using MC.RunCmd ID="Core.1312" that is CTRL+V with the target path on the clipboard
      // The ony downside is that we loose the clipboard content
      SetClipboardText($link_target);
      
      // Check if there's more than 1 link target (hardlinks and junctions)
      @var $link_targets[] = StrLines2Array($link_target);
      // If more than 1, ask the user
      if (arrayCount($link_targets) > 1)
      {
         @var $link_targets_answer = AskOption('Select target', $link_targets, 0);
         if ($link_targets_answer == -1)
         {
            // User cancelled
            break;
         }
         SetClipboardText($link_targets[$link_targets_answer]);
      }
      
      // Go To Link Target
      MC.RunCmd ID="Core.1312"
   }
   else
   {
      LogAppInfo('Error');
   }

}
else
{
   MessageBox('Resolve Link', 'Operation timeout', 0);
}


Python:

# -*- coding: utf-8 -*-

# argv[1] = link file/folder path
# argv[2] = path to exchange text file with Multi Commander
# argv[3] = path to FindLinks.exe

# argv[1] can't end with /
# Doesn't work when running inside Multi Commander and argv[1] is a symbolic link inside a junction (but it works inside cmd for example)

import sys
import os
import win32com.client
import mylib.windows.windows as lib_windows
import mylib.files.file_handling as lib_file_handling

file = open(sys.argv[2], 'w')

if sys.argv[1][-3:].lower() == 'lnk':
    print('Shortcut detected')
    shell = win32com.client.Dispatch("WScript.Shell")
    shortcut = shell.CreateShortCut(sys.argv[1])
    print(shortcut.Targetpath)
    file.write(shortcut.Targetpath)

elif os.path.islink(sys.argv[1]):
    print('Symbolic Link detected')
    link_target = lib_file_handling.get_symlink_target(sys.argv[1])
    if link_target is not None:
        print(link_target)
        file.write(link_target)

elif lib_file_handling.is_junction(sys.argv[1]):
    print('Junction detected')
    link_target = lib_file_handling.get_junction_target(sys.argv[1])
    print(link_target)
    file.write(link_target)

elif os.stat(sys.argv[1]).st_nlink > 1:
    print('Hard Link detected')
    stdout, stderr, returncode = lib_windows.run_command_line('"' + sys.argv[3] + '" "' + sys.argv[1] + '"')
    findlinks_return = stdout.splitlines()
    if int(findlinks_return[7][8:]) > 0:
        for line in range(10, len(findlinks_return)):
            if findlinks_return[line].lower() != sys.argv[1].lower():
                print(findlinks_return[line])
                file.write(findlinks_return[line] + '\n')

file.close()

And the executable is here https://technet.microsoft.com/en-us/sysinternals/hh290814

66
Support and Feedback / Re: AutoResize column
« on: February 09, 2017, 18:25:22 »
Not all columns, just the name (as it's the only information on List view).

It's the same way as Windows Explorer works on List View.

67
Support and Feedback / Re: AutoResize column
« on: February 08, 2017, 11:08:10 »
Ok. Is there a option to automatically stretch/shrink name column on entering a folder?

68
Support and Feedback / AutoResize column
« on: February 07, 2017, 18:45:32 »
I am using Explorer Style along with List View.

I click on the name column header with the right mouse button and click on AutoResize columns but there's no effect. I'd like the name column size to adjust to the biggest filename so I see the whole filename and no waste on space with a too big column.

Is it possible?

Thanks

69
Script / Re: Select Same Name (Selected Files)
« on: February 06, 2017, 16:31:45 »
wow, dind't see that... I thought == would work just like StrIsEqual. That's why I was having a headache with the code lol.

Thanks Mathias

70
Script / Re: Select Same Name (Selected Files)
« on: February 06, 2017, 11:21:43 »
Thanks Mathias. I chose #1 and wrote the code:

@var $selected_files[] = GetSourceSelectedFileNames();
@var $all_files[] = GetSourceItems();
@var $same_name_files[];

@var $n;
@var $i;
@var $aux;
@var $aux2;
@var $selected_file_name_no_ext;

for($n = 0; $n < arrayCount($selected_files); $n++)
{
    $selected_file_name_no_ext = PathGetNamePart($selected_files[$n], 1);
    //LogAppInfo($selected_file_name_no_ext);
    for($i = 0; $i < arrayCount($all_files); $i++)
    {
        $aux = $all_files[$i];
        $aux2 = PathGetNamePart($aux, 0);
        //LogAppInfo('is ' + $aux2 + ' equal to ' + $selected_file_name_no_ext + ' ?');
      // For some reason if we compare using == instead of StrIsWildMatchNoCase, it always enters the if
        if (StrIsWildMatchNoCase($aux2, $selected_file_name_no_ext + '.*') == 1)
        {
            //LogAppInfo('equals');
            arrayAdd($same_name_files, $aux2);
        }
    }
   
}

 ;)
SetSourceSelected($same_name_files, 1);

71
Script / Re: Select Same Name (Selected Files)
« on: February 03, 2017, 11:17:08 »
Did't think about that. That is way better indeed.

Thanks!

72
Support and Feedback / Re: StrReplace
« on: February 03, 2017, 10:56:27 »
Yes, it worked when I defined to a variable.
I'm using this way.

Thanks!

73
Support and Feedback / Re: Selecting files
« on: February 03, 2017, 10:50:58 »
I'm using the Windows Explorer Style.

I downloaded a fresh portable and repeated the process and it worked (selected only the 2 last files).

So I must have changed some setting that is causing this behavior but don't know what setting is. I'll check if I can find.

Thanks

74
Support and Feedback / Re: StrReplace
« on: February 02, 2017, 19:53:01 »
I tried to use
$python_script_path = StrReplace($python_script_path, "\"", "^\"");

but the Log Window reports:
2017-02-02 16:55:30.623 Script engine error - Line : 18, Error : -1 => Code : "$python_script_path = StrReplace($python_script_path, "\"", "^\"")"

75
Support and Feedback / StrReplace
« on: February 02, 2017, 18:46:49 »
In a MultiScript when I run

$python_script_path = StrReplace($python_script_path, '"', 'x');
it runs fine

but if I run
$python_script_path = StrReplace($python_script_path, '"', '^"');
it reports an error to Log Window

further, If I create a var with '^"' and use it like
$python_script_path = StrReplace($python_script_path, '"', $aux);
it runs fine also

I think there's something wrong there

Pages: 1 2 [3] 4