Winrar portable context script

Discuss and share scripts and script files...
Post Reply
eil
Posts: 1802
Joined: 13 Jan 2011 19:44

Winrar portable context script

Post by eil »

i'm trying Winrar portable from PoratbleApps. i can easily set it as an archive viewer in XY, but can anyone give me a script, that will make same thing as if i select files and use "Add to archive" from context menu(with installed Winrar)?
Win 7 SP1 x64 100% 1366x768|1900x1080

xman
Posts: 133
Joined: 28 Nov 2009 22:57

Re: Winrar portable context script

Post by xman »

I use the following to handle compressing files with both Winrar and 7zip portable (inluding "Add files to archive..."). Just remove parts you don't need and elsewhere just search & replace paths for either winrar or 7zip. Some of it is my work, other stuff is taken from this forum, so if you deserve credit, let me know, I will add it to the top.

Code: Select all

 "_get_item_basename"
    // Get a full path in $param_item_path, and returne base in $out_item_name
    // ex: c:\dir1\dir2\base.ext => base
    //      c:\dir1\dir2\ => dir2
    global $param_item_path;
    global $out_item_name;

    $out_item_name = $param_item_path;
    
    // Detect folder path. Folder path ends with "\" so we have to find if the path ends with a "\"
    // No reverse find for now, so we add a special character to do the trick
    $out_item_name = $out_item_name . "{";
    strpos $is_folder, $out_item_name, "\{";
    if ($is_folder >= 0) {
        $is_folder = 1;
        // Remove special char with last "\"
        replace $out_item_name, $out_item_name, "\{";
    } 
    else {
        $is_folder = 0;
        // Remove special char
        replace $out_item_name, $out_item_name, "{";
    }
    
    strpos $last_slash_index, $out_item_name, "\";
    $last = $last_slash_index;
    while ($last_slash_index >= 0 && $last_slash_index < strlen($out_item_name)) {
        strpos $last_slash_index, $out_item_name, "\", $last_slash_index + 1;
        if ($last_slash_index != -1) {
            $last = $last_slash_index;
        }
    }
    $last_slash_index = $last;
    
    if ($last_slash_index != -1) {
        substr $out_item_name, $out_item_name, $last_slash_index + 1;
    }
    
    if ($is_folder == 0) {
        // Folder -> Do nothings
        // File -> Remove extension
        strpos $last_dot_index, $out_item_name, ".";
        $last = $last_dot_index;
        while ($last_dot_index >= 0 && $last_dot_index < strlen($out_item_name)) {
            strpos $last_dot_index, $out_item_name, ".", $last_dot_index + 1;
            if ($last_dot_index != -1) {
                $last = $last_dot_index;
            }
        }
        $last_dot_index = $last;
        
        if ($last_dot_index >= 0) {
            strlen $length, $out_item_name;
            $last_dot_right = $last_dot_index - $length;
            substr $out_item_name, $out_item_name, 0, $last_dot_right;
        }
    }

"_is_folder"
   global $param_item_path;
   global $is_folder;

   $attr = property("Attributes", $file);
   $len = strlen($attr);
   $counter = 0;
   $is_folder = 0;
   
   while ($counter < $len)
   {
    if (substr($attr, $counter, 1) == "D")
    {
      $is_folder = 1;
      break;
    }
   
     $counter++;
   }

 //--------------------------------------------------------------------------
"Compress to 7z (Ultra)|?:\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".7z";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"" a -t7z -mtc=on -mx=9 -mmt -- ""$archive_name"" ""$filelist""";

 //--------------------------------------------------------------------------
"Compress to 7z (Ultra, Text)|?:\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".7z";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"" a -t7z -mtc=on -mx=9 -m0=PPMd -mmt -- ""$archive_name"" ""$filelist""";

 //--------------------------------------------------------------------------

"Compress to RAR (Maximum)|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".rar";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -s- -ep1 -r0 -ts -scul -iext -- ""$archive_name"" ""$filelist""";

 //--------------------------------------------------------------------------

"Compress to RAR (Maximum, Solid)|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".rar";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -s -ep1 -r0 -ts -scul -iext -- ""$archive_name"" ""$filelist""";

 //--------------------------------------------------------------------------

"Compress to ZIP (Maximum)|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".zip";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -ep1 -r0 -ts -iext -- ""$archive_name"" ""$filelist""";


-

 //--------------------------------------------------------------------------

"Compress using WinRAR...|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"
 global $param_item_path, $out_item_name, $is_folder;
 
 $filelist = getinfo('SelectedItemsPathNames', '" "');
 $sel_num = getinfo("CountSelected");
 $ext = ".rar";
 $archive_name = "";

 if ($sel_num == 0)
 {
  break;
 }

 if ($sel_num == 1)
 {
  $param_item_path = <curitem>;
  sub "_is_folder";

  if (($is_folder == 1) || (compare($ext, "." . <curext>, "i") == 0))
  {
   $archive_name = <curitem> . $ext;
  }
  else
  {
   $archive_name = <curbase> . $ext;
  }
 }

 elseif ($sel_num >= 1)
 {
  $archive_name = <curfolder> . $ext;
 }

 run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -s -ep1 -ts -r0 -scul -iext -- . ""$filelist""";

-
 //--------------------------------------------------------------------------
"Compress to 7z (Ultra, 1 Archive/Item)|?:\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"

 global $param_item_path, $out_item_name, $is_folder;

 $filelist = getinfo('SelectedItemsPathNames', '|');
 $sel_num = getinfo("CountSelected");
 $ext = ".7z";
 $archive_name = "";

 $count = 1;

 while(1)
 {
  $file=gettoken($filelist,$count,"|");

  $param_item_path = $file;
  sub "_is_folder";

  $count++;
  if("$file"==""){break;}
  $attr = property("Attributes", $file);

  if (($is_folder == 1) || ((strlen($file) >= 3) && (compare($ext, substr($file, -3, 3), "i") == 0)))
  {
   $archive_name = $file . $ext;
  }
  else
  {
   sub "_get_item_basename";
   $archive_name = $out_item_name . $ext;
  }

  run """<xydrive>\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"" a -t7z -mtc=on -mx=9 -mmt -- ""$archive_name"" ""$file""";
 }

 //--------------------------------------------------------------------------
"Compress to 7z (Ultra, Text, 1 Archive/Item)|?:\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"

 global $param_item_path, $out_item_name, $is_folder;

 $filelist = getinfo('SelectedItemsPathNames', '|');
 $sel_num = getinfo("CountSelected");
 $ext = ".7z";
 $archive_name = "";

 $count = 1;

 while(1)
 {
  $file=gettoken($filelist,$count,"|");

  $param_item_path = $file;
  sub "_is_folder";

  $count++;
  if("$file"==""){break;}
  $attr = property("Attributes", $file);

  if (($is_folder == 1) || ((strlen($file) >= 3) && (compare($ext, substr($file, -3, 3), "i") == 0)))
  {
   $archive_name = $file . $ext;
  }
  else
  {
   sub "_get_item_basename";
   $archive_name = $out_item_name . $ext;
  }

  run """<xydrive>\Apps\System\_Archives\7-Zip\7-ZipCmdPortable.exe"" a -t7z -mtc=on -mx=9 -m0=PPMd -mmt -- ""$archive_name"" ""$file""";
 }

 //--------------------------------------------------------------------------
"Compress to RAR (Maximum, Solid, 1 Archive/Item)|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"

 global $param_item_path, $out_item_name, $is_folder;

 $filelist = getinfo('SelectedItemsPathNames', '|');
 $sel_num = getinfo("CountSelected");
 $ext = ".rar";
 $archive_name = "";

 $count = 1;

 while(1)
 {
  $file=gettoken($filelist,$count,"|");

  $param_item_path = $file;
  sub "_is_folder";

  $count++;
  if("$file"==""){break;}
  $attr = property("Attributes", $file);

  if (($is_folder == 1) || ((strlen($file) >= 4) && (compare($ext, substr($file, -4, 4), "i") == 0)))
  {
   $archive_name = $file . $ext;
  }
  else
  {
   sub "_get_item_basename";
   $archive_name = $out_item_name . $ext;
  }

  run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -s -ep1 -ts -r0 -scul -iext -- ""$archive_name"" ""$file""";
 }

 //--------------------------------------------------------------------------
"Compress to ZIP (Maximum, 1 Archive/Item)|?:\Apps\System\_Archives\WinRAR\WinRARPortable.exe"

 global $param_item_path, $out_item_name, $is_folder;

 $filelist = getinfo('SelectedItemsPathNames', '|');
 $sel_num = getinfo("CountSelected");
 $ext = ".zip";
 $archive_name = "";

 $count = 1;

 while(1)
 {
  $file=gettoken($filelist,$count,"|");

  $param_item_path = $file;
  sub "_is_folder";

  $count++;
  if("$file"==""){break;}
  $attr = property("Attributes", $file);

  if (($is_folder == 1) || ((strlen($file) >= 4) && (compare($ext, substr($file, -4, 4), "i") == 0)))
  {
   $archive_name = $file . $ext;
  }
  else
  {
   sub "_get_item_basename";
   $archive_name = $out_item_name . $ext;
  }

  run """<xydrive>\Apps\System\_Archives\WinRAR\WinRARPortable.exe"" a -ep1 -ts -r0 -scul -iext -- ""$archive_name"" ""$file""";
 }

eil
Posts: 1802
Joined: 13 Jan 2011 19:44

Re: Winrar portable context script

Post by eil »

thanks for example, xman, but that's not quite what i meant.

developer of WinRar provided me with syntax, but i still can't make it work truly. :(
winrar a . path\file
winrar x arcname ?destdir\
Win 7 SP1 x64 100% 1366x768|1900x1080

Post Reply