-- http://forum.ru-board.com/topic.cgi?forum=5&topic=49572&start=2290&limit=1&m=1#1 [?] -- Идея и основной автор Alexyz21 -- v1.1, Косметика, возможнсть выбора пути сохранения отчёта, "защита от дурака" -- VictorVG, 10.08.2019 09:10:38 +0300 -- v1.1.1, Fix typo -- 11.08.2019 17:46:55 +0300 local F = far.Flags local boom,Report = {},false local function process(f,t) -- utf32le,utf32be,utf16le,utf16be,utf8 local res,bom = 0,{'\255\254\0\0','\0\0\254\255','\255\254','\254\255','\239\187\191'} local h=io.open(f,"rb") if h then local s=h:read(4) or '' h:close() for x=#bom,2,-1 do if string.sub(s,1,#bom[x])==bom[x] then if x==3 and s==bom[1] then x=1 end if t[x] then res=x end if Report then table.insert(boom[x],f..'\n') end break end end end return res end local guid = win.Uuid("2180A62D-04B5-44D9-999E-3A3328D51B84") local Items = { --[[01]] {F.DI_DOUBLEBOX, 3,1, 27,10,0, 0,0, 0, "Select BOM"}, --[[02]] {F.DI_CHECKBOX, 5,2, 27,0, 0, 0,0, 0, "UTF-32 LE"}, --[[03]] {F.DI_CHECKBOX, 5,3, 27,0, 0, 0,0, 0, "UTF-32 BE"}, --[[04]] {F.DI_CHECKBOX, 5,4, 27,0, 0, 0,0, 0, "UTF-16 &LE"}, --[[05]] {F.DI_CHECKBOX, 5,5, 27,0, 0, 0,0, 0, "UTF-16 &BE"}, --[[06]] {F.DI_CHECKBOX, 5,6, 27,0, 0, 0,0, 0, "&UTF-8"}, --[[07]] {F.DI_CHECKBOX, 5,7, 12,0, 0, 0,0, 0, "&All"}, --[[08]] {F.DI_CHECKBOX, 15,7, 27,0, 0, 0,0, 0, "&Report"}, --[[09]] {F.DI_TEXT, -1,8, 0,0, 0, 0,0, F.DIF_SEPARATOR,""}, --[[10]] {F.DI_BUTTON, 0,9, 0,0, 0, 0,0, F.DIF_DEFAULTBUTTON+F.DIF_CENTERGROUP,"&Ok"}, --[[11]] {F.DI_BUTTON, 0,9, 0,0, 0, 0,0, F.DIF_CENTERGROUP,"Ca&ncel"} } local GFocus,ChkBOX = 6,{false,false,false,false,true,false} local function DlgProc(hDlg,Msg,Param1,Param2) if Msg==F.DN_INITDIALOG then for x=1,#ChkBOX do hDlg:send(F.DM_SETCHECK,x+1,ChkBOX[x] and F.BSTATE_CHECKED or F.BSTATE_UNCHECKED) end hDlg:send(F.DM_SETFOCUS,GFocus,0) elseif Msg==F.DN_BTNCLICK and Param1>1 and Param1<#Items-4 then ChkBOX[Param1-1]=Param2~=0 elseif Msg==F.DN_BTNCLICK and Param1==#Items-4 then for x=1,#ChkBOX do ChkBOX[x]=Param2~=0 hDlg:send(F.DM_SETCHECK,x+1,ChkBOX[x] and F.BSTATE_CHECKED or F.BSTATE_UNCHECKED) end elseif Msg==F.DN_BTNCLICK and Param1==#Items-3 then Report=Param2~=0 elseif Msg==F.DN_GOTFOCUS then if Param1>1 and Param1<#Items-2 then GFocus=Param1 end else return end return true end Macro { description="BOM: Files select"; name="BOM"; area="Shell"; key="AltShiftEnter"; action=function() if far.Dialog(guid,-1,-1,31,#Items+2,nil,Items,nil,DlgProc)==#Items-1 then --local s='' for x=1,#ChkBOX do s=s..(ChkBOX[x] and 1 or 0) end far.Message(s,'BOX') local itm0,itm1,head = {},{},{"UTF-32 LE","UTF-32 BE","UTF-16 LE","UTF-16 BE","UTF-8"} boom={} for x=1,#head do boom[x]={} end local ttime=far.FarClock() for Item=1,panel.GetPanelInfo(nil,1).ItemsNumber do local GPItem=panel.GetPanelItem(nil,1,Item) table.insert((GPItem.FileAttributes:find("d") or process(GPItem.FileName,ChkBOX)==0) and itm0 or itm1,Item) end ttime = far.FarClock()-ttime if Report then local f=win.GetEnv('TEMP')..'\\boom.txt' local k=mf.prompt("Input path to report as \'Disk:\\Dir\\FileName.Ext\'","Path:",5) if not mf.waitkey(0,0) == "Esc" then if mf.len(k) ~= 0 then f=k end end local h=io.open(f,'wb') if h then h:write('Time:\t'..ttime..' mcs\n') h:write('Path:\t'..APanel.Path..'\n\n') for x=#head,1,-1 do table.sort(boom[x],function(a,b) return win.CompareString(a,b,"u","c")==-1 end) for j=1,#boom[x] do h:write(head[x]..'\t'..boom[x][j]) end end end h:close() end panel.SetSelection(nil,1,itm0,false) panel.SetSelection(nil,1,itm1,true) panel.RedrawPanel(nil,1) end end } |