1
// ExtractArchiveAction.cs
3
// Copyright (C) 2008 [name of author]
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
using System.Collections.Generic;
24
using System.Diagnostics;
31
public class ExtractAction : AbstractAction {
33
public ExtractAction()
37
public override string Name {
38
get { return "Extract archive"; }
41
public override string Description {
42
get { return "Extract an archive to a given folder"; }
45
public override string Icon {
46
get { return "file-roller"; }
49
public override Type[] SupportedItemTypes {
57
public override bool SupportsItem (IItem item)
59
return IsArchive (item as IFileItem);
62
public override bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
64
return FileItem.IsDirectory (modItem as IFileItem);
67
public override Type[] SupportedModifierItemTypes {
75
public override bool ModifierItemsOptional {
79
public override IItem[] DynamicModifierItemsForItem (IItem item)
84
public override IItem[] Perform (IItem[] items, IItem[] modItems)
86
ExtractArchive ( (items[0] as IFileItem), (modItems[0] as IFileItem));
90
private bool IsArchive (IFileItem item)
92
return item.Path.EndsWith(".tar.gz") ||
93
item.Path.EndsWith (".tar.bz2") ||
94
item.Path.EndsWith (".tar") ;
98
private void ExtractArchive ( IFileItem archive, IFileItem where)
100
if ( archive.Name.EndsWith ("tar.gz"))
101
Process.Start (String.Format ("tar -xzf {0} -C {1}", EscapeString(archive.Path), EscapeString(where.Path)));
102
else if ( archive.Name.EndsWith ("tar.bz2"))
103
Process.Start (String.Format ("tar -xjf {0} -C {1}", EscapeString(archive.Path), EscapeString(where.Path)));
104
else if (archive.Name.EndsWith ("tar"))
105
Process.Start (String.Format ("tar -xf {0} -C {1}", EscapeString (archive.Path), EscapeString(where.Path)));
109
private string EscapeString (string str)
111
return str.Replace (" ", "\\ ")
112
.Replace ("'", "\\'");