* @class elFinder command "extract"
* Extract files from archive
* @author Dmitry (dio) Levashov
elFinder.prototype.commands.extract = function() {
filter = function(files) {
return $.grep(files, function(file) {
fres = fres && file.read && $.inArray(file.mime, mimes) !== -1 ? true : false;
this.disableOnSearch = true;
// Update mimes list on open/reload
fm.bind('open reload', function() {
mimes = fm.option('archivers')['extract'] || [];
self.variants = [[{makedir: true}, fm.i18n('cmdmkdir')], [{}, fm.i18n('btnCwd')]];
self.variants = [[{}, fm.i18n('btnCwd')]];
this.getstate = function(select) {
var sel = this.files(select),
if (!cnt || filter(sel).length != cnt) {
} else if (fm.searchStatus.state > 0) {
cwdHash = this.fm.cwd().hash;
$.each(sel, function(i, file) {
cwdChk = (file.phash === cwdHash);
return this.fm.cwd().write? 0 : -1;
this.exec = function(hashes, opts) {
var files = this.files(hashes),
makedir = opts && opts.makedir ? 1 : 0,
siblings = fm.files(files[0].phash),
$.each(siblings, function(id, file) {
var decide = function(decision) {
var unpack = function(file) {
if (!(file.read && fm.file(file.phash).write)) {
error = ['errExtract', file.name, 'errPerm'];
} else if ($.inArray(file.mime, mimes) === -1) {
error = ['errExtract', file.name, 'errNoArchive'];
data:{cmd:'extract', target:file.hash, makedir:makedir},
notify:{type:'extract', cnt:1},
incwd : {msg: fm.i18n(['complete', fm.i18n('cmdextract')]), action: {cmd: 'open', msg: 'cmdopen'}},
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmdextract')]), action: {cmd: 'open', msg: 'cmdopen'}}
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmdextract')])}
if (dfrd.state() != 'rejected') {
var confirm = function(files, index) {
name = fm.splitFileExtention(file.name)[0],
existed = ($.inArray(name, names) >= 0),
if (!makedir && existed && map[name].mime != 'directory') {
title : fm.i18n('ntfextract'),
text : ['errExists', name, 'confirmRepl'],
callback:function (all) {
decision = all ? 'overwrite_all' : 'overwrite';
if(!overwriteAll && !omitAll) {
if('overwrite' == decision) {
} else if(overwriteAll) {
for (i = index; i < cnt; i++) {
callback:function (all) {
decision = all ? 'omit_all' : 'omit';
if(!overwriteAll && !omitAll && (index+1) < cnt) {
title : fm.i18n('cmdextract'),
text : [fm.i18n('cmdextract')+' "'+file.name+'"', 'confirmRepl'],
callback:function (all) {
callback:function (all) {
(mkdirAll > 0) && unpack(file);
if (!(this.enabled() && cnt && mimes.length)) {