Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: скрипт для кодирования(декодирования) нескольких файлов b64 
Author Message
Flasher



PostPosted: Sun Jul 29, 2012 20:56    Post subject: Reply with quote

Тут был запрос.

Code:
'================================================================
' 1) Получение в текущей папке файла из кодированного текста
' буфера обмена вида B64/MIME/UUE/XXE/BinHex
' 2) Если в буфере нет соотв. кода,
'    то кодировать/декодировать выбранные файлы в панели

' Условие: путь запуска - пустой

' Параметры: %WL <расширение кодировки> <флаг упаковки в zip: 1>

' Возможные расширения кодирования: b64, xxe, uue

' Автор - Flasher ©
'======================= Путь к UUDeView ========================
UUDev = """%COMMANDER_PATH%\Utils\uudeview\uudeview.exe"""
'======================= Путь к UUEnView ========================
UUEnv = """%COMMANDER_PATH%\Utils\uudeview\uuenview.exe"""
'======================== Путь к TCFS2 ==========================
TCFS2 = """%COMMANDER_PATH%\Utils\TCFS2\TCFS2.exe"""
'================================================================
L = vbNewLine
Set SHA = CreateObject("Shell.Application")
Dim WSH : Set WSH = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
P = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407"
A = WSH.RegRead(P) : If A > 0 Then WSH.RegWrite P, 0, "REG_DWORD"
Clip = Trim(CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text"))
Temp = SHA.NameSpace(WSH.ExpandEnvironmentStrings("%TEMP%")).Self.Path
If Clip <> "" Then
  Clip = Replace(Replace(Clip, " " & L, L), L & " ", L) : Search = InStr(Clip, "begin ")
  If (Search And IsNumeric(Mid(Clip, Search + 8, 2))) Or InStr(Clip, L & "Content-Transfer-Encoding:") Then
    File = Temp & "\" & FSO.GetTempName
    Set F = FSO.OpenTextFile(File, 2, True) : F.Write Trim(Clip) : Set SHA = Nothing : F.Close
    WSH.Run UUDev & " -i -m +o -c """ & File & """", 0, True : WSH.Exec(TCFS2 & " /ef tcm(540)")
    With CreateObject("InternetExplorer.Application")
      .Navigate("about:blank") : .document.parentWindow.clipboardData.setData "text", ""
      .ExecWB 45, 2 : .Quit
    End With : If A > 0 Then WSH.RegWrite P, A, "REG_DWORD"
    Quit
  End If
End If
With WScript.Arguments
  C = .Count : If C = 0 Then Quit
  List = .Item(0) : If C > 1 Then Ext = .Item(1) Else Ext = " "
End With
Do Until Ext = "b64" Or Ext = "xxe" Or Ext = "uue"
  Ext = InputBox(L & "Введите одно из расширений формата возможного кодирования:" & L & _
  "b64, uue, xxe","Кодирование") : If Trim(Ext) = "" Then Quit
Loop : E = "7z|7zip|zip|rar|arc|cab|nz|pea|bz|bzip|bz2|bzip2|arj|tar|gz|gza|gzi|pzip|tgz|ace|uc2"
Select Case Ext
  Case "b64" : Code = " -b " : Case "uue" : Code = " -u " : Case "xxe" : Code = " -x "
End Select
For Each F in Split(FSO.GetFile(List).OpenAsTextStream(1, -1).ReadAll, L)
  If FSO.FileExists(F) Then
    Set File = FSO.GetFile(F).OpenAsTextStream(1, -2) : RF = File.ReadAll
    If InStr(RF, L & "begin ") Or InStr(RF, L & "Content-Transfer-Encoding:") Or _
    InStr(RF, L & "_=_ Part ") Then
      WSH.Run UUDev & " -i -m +o """ & F & """", 0, True
    Else
      If C = 3 Then
        If InStr(E, LCase(FSO.GetExtensionName(F))) = 0 Then
          NF = Temp & "\" & FSO.GetBaseName(F) & ".zip" : Set ZIP = FSO.CreateTextFile(NF)
          ZIP.Close : Set ZIP = Nothing
          Set ArchDir = SHA.NameSpace(NF) : ArchDir.CopyHere F, 20
          Size = 0 : Set AF = ArchDir.ParseName(FSO.GetFileName(F))
          On Error Resume Next : Err.Number = 424
          Do While Err.Number = 424 And Size <> FSO.GetFile(F).Size : Err.Number = 0
            Set AF = ArchDir.ParseName(FSO.GetFileName(F)) : Size = AF.Size
          Loop : On Error Goto 0
          WScript.Sleep 10 : Set AF = Nothing : Set ArchDir = Nothing : F = NF
        End If
      End If : WSH.Run UUEnv & Code & "-o """ & F & """", 0, True
      N = FSO.GetFileName(F) : BN = FSO.GetBaseName(F) : NF = BN & "." & Ext
      If Not FSO.FileExists(NF) Then FSO.GetFile(BN & ".001").Name = NF
      If Ext = "b64" Then
        FN = WSH.CurrentDirectory & "\" & NF : Set CF = FSO.OpenTextFile(FN) : CF.SkipLine
        If CF.ReadLine = "_=_ " Then
          Base = CF.ReadAll : CF.Close : Set CF = Nothing : Set CF = FSO.OpenTextFile(FN, 2)
          CF.Write "MIME-Version: 1.0" & L & _
          "Content-Type: application/octet-stream; name=""" & N & """" & L & _
          "Content-Transfer-Encoding: base64" & L & _
          "Content-Disposition: attachment; filename=""" & N & """" & L & L & _
          Mid(Base, InStr(Base, L & L) + 4)
        End If : CF.Close : Set CF = Nothing : If C = 3 Then FSO.DeleteFile F
      End If
    End If : File.Close : Set File = Nothing : RF = ""
  End If : WSH.Exec(TCFS2 & " /ef tcm(540)")
Next : If A > 0 Then WSH.RegWrite P, A, "REG_DWORD" : Quit
Sub Quit : Set FSO = Nothing : Set WSH = Nothing : Set SHA = Nothing : WScript.Quit : End Sub

UUDeview + UUEnview
View user's profile Send private message


Powered by phpBB © 2001, 2005 phpBB Group