--[[
Вариант группирования файлов по длине и CRC, обхода файлов одной панели и поиска на другой
"парных" (совпадающих по длине и CRC).
--]]
--local F = far.Flags
--local DialogTools = require"BAX.DialogTools"
--local GetMsgEx = require"BAX.GetMsg"
local tin = table.insert
-- Сравнение панелей по содержимому.
-- Выделяются файлы, копия которых (безотносительно к имени) имеется на другой панели
----[[*D*]]local le = require"le"
-------------------------------------------------------------------------------------
--local function CmpDial()
-- local DlgItems = {}
-- local function Add(DItem) tin(DlgItems, DialogTools.DialogItem(DItem)) end
-- local h,w=13,70
-- Add{'DI_DOUBLEBOX',x1=0,y1=0,x2=w,y2=h,text='Сравнение панелей'}
-- Add{'DI_CHECKBOX', x1=3,y1=2,Text='При сравнении учитывать дату'; Checked=0}
-- Add{'DI_CHECKBOX', x1=3,y1=3,Text='Выделить одинаковые файлы на панелях'; Checked=1}
-- Add{'DI_TEXT', x1=1,x2=w-2,y1=5; Text='Выполнить сценарий для совпавших файлов:'; Flags='DIF_CENTERTEXT'}
-- Add{'DI_TEXT', x1=3;y1=6;Text='Для файлов с активной панели (%1 - имя файла)'}
-- Add{'DI_EDIT', x1=3,x2=w-4,y1=7}
-- Add{'DI_TEXT', x1=3;y1=8;Text='Для файлов с пассивной панели (%1 - имя файла)'}
-- Add{'DI_EDIT', x1=3,x2=w-4,y1=9}
-- Add{'DI_TEXT', x1=-1, y1=10, Flags='DIF_SEPARATOR'}
-- Add{'DI_BUTTON', y1=11, Flags='DIF_CENTERGROUP|DIF_DEFAULTBUTTON', Text='Ok'}
-- Add{'DI_BUTTON', y1=11, Flags='DIF_CENTERGROUP', Text='Cancel'}
-- far.Dialog('44C0A2E9-5F23-4E5C-9BE9-D94F3849D63B', -1,-1,w,h,nil,DlgItems, F.FDLG_SMALLDIALOG)
--end -- CmpDial
-------------------------------------------------------------------------------------
local function CmpFunc()
local function CreateList(_Panel, WhatPanel, whatpanel)
local Result ={}
local Path = _Panel.Path .. (_Panel.Path:sub(-1)=='\\' and '' or '\\')
local i1,i2,GetFun=1,_Panel.Selected and _Panel.SelCount or _Panel.ItemCount, _Panel.Selected and panel.GetSelectedPanelItem or panel.GetPanelItem
for i=i1,i2 do
if mf.waitkey(1,0) == 'Esc' and
far.Message('Вы действительно хотите прервать процесс сравнения файлов?', 'Сравнение панелей по содержимому', ';YesNo', 'w') == 1 then
break
end
local Item = GetFun(nil, whatpanel, i)
if not Item.FileAttributes:match"d" then
local FullName = Path .. Item.FileName
local sKey = ('%.10d;%s'):format(Item.FileSize, Item.FileSize == 0 and (' '):rep(128) or Plugin.SyncCall("E186306E-3B0D-48C1-9668-ED7CF64C0E65", "gethash", 'SHA-512', FullName, true))
if Result[sKey] == nil then Result[sKey] = {} end
tin(Result[sKey], Item.FileName)
end
end
return Result
end -- CreateList
--local tStart = Far.UpTime
local AList, PList = CreateList(APanel, 0,1), CreateList(PPanel,1,0)
--local ASelList, PSelList, KeyList = {}, {}, {}
local ASelList, PSelList = {}, {}
local i,v = next(AList)
while i do
if PList[i] then
--KeyList[i] = {v, PList[i]}
for _,w in ipairs(v) do tin(ASelList, w) end
for _,w in ipairs(PList[i]) do tin(PSelList, w) end
end
i,v = next(AList, i)
end
if #ASelList > 0 then
Panel.Select(0, 0)
Panel.Select(1, 0)
Panel.Select(0, 1, 2, table.concat(ASelList, '\n'))
Panel.Select(1, 1, 2, table.concat(PSelList, '\n'))
--CmpDial()
end
----[[*D*]]le({Time=Far.UpTime-tStart, AList=AList, PList=PList, ASelList=ASelList, PSelList=PSelList})
end -- CmpFunc
-------------------------------------------------------------------------
MenuItem {
description = "Сравнение панелей по содержимому";
menu = "Plugins";
area = "Shell";
guid = "C95988A8-E802-4541-A2F3-323D8FA89A12";
text = function(menu,area)
return "Сравнение панелей по содержимому"
end;
action = function(OpenFrom,Item)
CmpFunc()
end;
}
-------------------------------------------------------------------------
NoMacro{ -- Для активации уберите 'No' в начале строки
id="748A9A2C-1D4B-4A85-9B27-B881F98BAC90";
area="Shell";
key=""; -- Сюда свой хоткей вставить
description = "Сравнение панелей по содержимому";
flags="";
condition=function(key, data) return APanel.Visible and PPanel.Visible end;
action=function(data)
CmpFunc()
end;
}