'================== Путь к 7z.exe ==================
Const Z7 = """%COMMANDER_PATH%\Utils\7-Zip\7z.exe"""
'===================================================
Dim FSO, Ext, FileName, Strm, Stream, N, Reg,_
Enc, Content, Content1, Content2, Exec, Check
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim WSH : Set WSH = CreateObject("WScript.Shell")
Ext = FSO.GetExtensionName(FileName)
If Ext = "dz" Then
Ext = FSO.GetExtensionName(FSO.GetBaseName(FileName))
Set Strm = WSH.Exec("cmd /c chcp 1251&" &_
Z7 & " x """ & FileName & """ -so|more /c")
Set Stream = Strm.StdOut : Stream.SkipLine
Else : N = 0 : If Ext = "dsl" Then N = -1
Set Stream = FSO.OpenTextFile(FileName,,,N)
End If : Set Reg = New Regexp : Reg.IgnoreCase = True
If Ext = "dsl" Then
Call DSL("NAME", Content)_
("INDEX_LANGUAGE", Content1)("CONTENTS_LANGUAGE", Content2)
ElseIf Ext = "xdxf" Then
Reg.Pattern = ".*encoding=""(.*)"".*" : Check = 1
Enc = Reg.Execute(Stream.ReadLine)(0).Submatches(0)
Reg.Pattern = "^<xdxf lang_from=""(\w+)"" lang_to=""(\w+)"" "
Stream.SkipLine : Set Exec = Reg.Execute(Stream.ReadLine)(0)
Content1 = Exec.Submatches(0) : Content2 = Exec.Submatches(1)
Reg.Pattern = "^<full_name>(.+)</full_name>"
With CreateObject("ADODB.Stream")
.Open : .Charset = "windows-1251" : .WriteText Stream.ReadLine
.Position = 0 : .Charset = Enc
Content = Reg.Execute(.ReadText)(0).Submatches(0) : .Close
End With
End If: Stream.Close : Set Stream = Nothing : Set FSO = Nothing
If IsObject(Strm) Then Strm.StdIn.Write "q" :_
If Check Then WSH.Exec "taskkill /T /F /PID " & Strm.ProcessID
Function DSL(Ins, Cont)
Reg.Pattern = "^#" & Ins & "\s+""(.*)""$"
Cont = Reg.Execute(Stream.ReadLine)(0).Submatches(0)
Set DSL = GetRef("DSL")
End Function |