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 

Создание архивов с использованием wcx-плагинов

 
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander printer-friendly view
View previous topic :: View next topic  
Author Message
LonerD



Joined: 04 Jan 2011
Posts: 1168
Location: Донецк

Post (Separately) Posted: Mon May 04, 2015 05:49    Post subject: Создание архивов с использованием wcx-плагинов Reply with quote

Скрипт предназначен для быстрого создания архивов в заданном формате с заранее указанными настройками с помощью Тоталовского диалога архивирования (то есть с задействованием wcx-плагинов).
Типичный пример использования. Нужно получить список (структуру) выделенных файлов плагином DiskDirExtended и поместить его в заданный каталог. Мы нажимаем Alt+F5, выбираем тип архива из списка, вводим путь для "архивации", нажимаем клавишу ОК. С использованием скрипта вся эта процедура сводится к единственному нажатию кнопки на Панели инструментов (пункта в меню) или горячей клавиши.

Это реализация моего старого запроса, вначале сделал и выкладывал у себя на сайте vbs-скрипт (работающий через TCIMG), а сейчас наконец сделал полноценную реализацию на AutoHotkey.

Code:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Total Commander DreamLair
; Script: Archivate selected files and folders using WCX plugins TC
; Script: Архівація виділених файлів і папок за допомогою WCX плагінів TC
; Script: Архивация выделенных файлов и папок с помощью WCX плагинов TC
; Version: 1.0 (2015.05.04)
; Author: LonerD (dreamlair.net)
; Made in Donetsk People's Republic
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Parameters / Параметри / Параметры:
; 1: {archive extension}/{розширення архиву}/{расширение архива}
; 2: {target directory}/{каталог призначення}/{каталог назначения}
;    {if \ - then directory in target panel}
;    {якщо \ - каталог в протилежній панелі}
;    {если \ - каталог в противоположноей панели}
; 3: {archive name}/{ім'я файлу архіву}/{имя файла архива}
;    {if \ - then file under cursor name}
;    {якщо \ - береться ім'я файлу під курсором}
;    {если \ - берётся имя файла под курсором}
; 4: {move to archive: 0 - don't delete files | 1 - delete files}
;    {переміщати в архів: 0 - не видаляти файли | 1 - видаляти файли}
;    {перемещать в архив: 0 - не удалять файлы | 1 - удалять файлы}
; 5: {archive type: 0 - normal | 1 - SFX}
;    {тип архіву: 0 - звичайний | 1 - SFX}
;    {тип архива: 0 - обычный | 1 - SFX}
; 6: {1 - separate archives, one per selected file/dir}
;    (1 - архівувати кожен файл/каталог у окремий архів)
;    (1 - каждый файл/каталог помещается в отдельный архив)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#NoEnv
#NoTrayIcon
#SingleInstance force
SetBatchLines, -1
SetKeyDelay, 20, 20

If not ( WinExist("ahk_class TTOTAL_CMD") || WinActive("ahk_class TTOTAL_CMD") )
  ExitApp
WinGet, hw_TTOTAL_CMD, ID, A

SelCount := TC_Command(0x190, hw_TTOTAL_CMD, 0, 0)
CursorName := TC_SendData("SN")
if (( SelCount = 0 ) || (( SelCount = 1 ) && ( CursorName = ".." )))
  ExitApp

Arc = %1%
Path = %2%
Name = %3%
ArcMove = %5%
ArcExe = %4%
ArcSepar = %6%

If 0 < 6
  ArcSepar = 0
If 0 < 5
  ArcExe = 0
If 0 < 4
  ArcMove = 0
If 0 < 3
  Name := CursorName
If 0 < 2
  Path := TC_SendData("TP")
If 0 < 1
  Arc := "7z"

if ( Name = "\" )
  Name := CursorName
if (( Name = "" ) || ( Name = ".." ))
  Name := DreamLair
StringReplace, Name, Name, \, , All
if ( Path = "\" )
  Path := TC_SendData("TP")

WinGet, TCPID, PID, A
if ( A_Is64bitOS = 0 )
  DreamTCArch := 32
    else
      DreamTCArch := GetBitness(TCPID)

if ( DreamTCArch = 32 )
{
  TAltEdit1 := "TAltEdit1"
  TCheckBox5 := "TCheckBox5"
  TCheckBox4 := "TCheckBox4"
  TCheckBox2 := "TCheckBox2"
  TButton5 := "TButton5"
}
else
{
  TAltEdit1 := "Edit1"
  TCheckBox5 := "Button6"
  TCheckBox4 := "Button5"
  TCheckBox2 := "Button2"
  TButton5 := "Button21"
}

ArcLine := Arc . ":" . Path . Name . "." . Arc

PostMessage, 0x433, 508,,, % "ahk_id " hw_TTOTAL_CMD
WinWaitNotActive, % "ahk_id " hw_TTOTAL_CMD
Sleep, 200
WinGet, Style, Style, % "ahk_id " hw_TTOTAL_CMD
if (Style & 0x8000000)
  WinSet, Enable,, % "ahk_id " hw_TTOTAL_CMD

IfWinNotExist, ahk_class TDLGZIP
  ExitApp

Sleep, 50
ControlSetText, % TAltEdit1, % ArcLine, ahk_class TDLGZIP

Sleep, 50
if ( ArcExe = 1 )
{
 SendMessage, 0x201,,, % TCheckBox5, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBox5, ahk_class TDLGZIP
}
Sleep, 50
if ( ArcMove = 1 )
{
 SendMessage, 0x201,,, % TCheckBox4, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBox4, ahk_class TDLGZIP
}
Sleep, 50
if ( ArcSepar = 1 )
{
 SendMessage, 0x201,,, % TCheckBox2, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBox2, ahk_class TDLGZIP
}
Sleep, 50

SendMessage, 0x201,,, % TButton5, ahk_class TDLGZIP
SendMessage, 0x202,,, % TButton5, ahk_class TDLGZIP

ExitApp

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Total Commander SendMessage (author LonerD)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Author: LonerD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TC_Command(TCmessage, aControl, Param1, Param2)
{
  global hw_TTOTAL_CMD
  SendMessage, % TCmessage, % Param1, % Param2, % aControl, % "ahk_id " hw_TTOTAL_CMD
  return ErrorLevel
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Total Commander WM_COPYData (author artt)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TC_SendData(Cmd, CmdType="", msg="", hwnd="")
{
  Critical
  global hw_TTOTAL_CMD
  Static om := OnMessage(0x4a, "TC_SendData"), TC_ReceiveDataValue := "", TC_DataReceived := ""

  If ( (msg=0x4A) and (hwnd=A_ScriptHwnd) )
    Exit ( TC_ReceiveDataValue := StrGet(NumGet(CmdType + A_PtrSize * 2)), TC_DataReceived := "1" )

  VarSetCapacity(CopyDataStruct, A_PtrSize * 3), TC_ReceiveDataValue := 1, TC_DataReceived := ""
  If CmdType in LR,ST
  DirType := CmdType, CmdType := "CD"
  else if ( CmdType = "" )
    CmdType := ( A_IsUnicode ? "GW" : "GA" ), TC_ReceiveDataValue := ""

  If( A_IsUnicode )
  {
    VarSetCapacity(cmdA, StrPut(cmd, "cp0"), 0)
    Loop, % StrLen(cmd)
      NumPut( Asc(SubStr(cmd, A_Index, 1)), cmdA, A_Index - 1, "Char" )
  }
  NumPut( Asc(SubStr(CmdType, 1, 1)) + 256 * Asc(SubStr(CmdType, 2, 1)), CopyDataStruct, 0 )
  NumPut( StrLen(cmd) + (CmdType = "CD" ? 5 : 0), CopyDataStruct, A_PtrSize )
  NumPut( (A_IsUnicode ? &cmdA : &cmd), CopyDataStruct, A_PtrSize * 2 )
  Loop, % ( CmdType=="CD" ? 2 : 0 )
    NumPut( Asc(SubStr(DirType, A_Index, 1)), (A_IsUnicode ? cmdA : cmd), (StrLen(cmd) + A_Index), "Char" )

  SendMessage, 0x4A, %A_ScriptHwnd%, &CopyDataStruct,, % "ahk_id " hw_TTOTAL_CMD
;  SendMessage, 0x4A, %A_ScriptHwnd%, &CopyDataStruct,, ahk_class TTOTAL_CMD

  While ( TC_ReceiveDataValue = "" )
  {
    IfEqual, TC_DataReceived,    1, Break
    IfGreaterOrEqual, A_Index, 500, Break
    Sleep, 10
  }
  Return TC_ReceiveDataValue
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Total Commander architecture function (author YMP)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   WinGet, hw_TTOTAL_CMD, PID, ahk_class TTOTAL_CMD
;   MsgBox, % GetBitness(hw_TTOTAL_CMD)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GetBitness(Process) {
  Process, Exist, %Process%
  If !(PID := ErrorLevel)
    return 0
  hProcess := DllCall("OpenProcess", "uint", 0x400
                                   , "uint", 0, "uint", PID, "ptr")
  If (hProcess = 0)
    return 0
  res := DllCall("IsWow64Process", "ptr", hProcess, "int *", Wow64Process)
  If (res = 0)
    return 0
  DllCall("CloseHandle", "ptr", hProcess)
  return Wow64Process? 32:64
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

_________________
Win11 x64 Eng | TC DreamLair eternal pre-α
Back to top
View user's profile Send private message
LonerD



Joined: 04 Jan 2011
Posts: 1168
Location: Донецк

Post (Separately) Posted: Tue Sep 18, 2018 17:38    Post subject: Reply with quote

Обновлённый вариант.
Упрощён и значительно оптимизирован с учётом нововведений в TC 9.
Исправлены найденные ошибки и добавлены новые.
Параметры изменились по сравнению с первой версией.
Добавлена тихая архивация без отображения диалога.

Ссылка на полную версию скрипта.

Code:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Total Commander DreamLair                        ;
; Script: Archive files with using WCX plugins     ;
; Script: Архівація за допомогою WCX плагінів      ;
; Script: Архивация с помощью WCX плагинов         ;
; Script version: 2.0 (2018.09.18)                 ;
; Required: Total Commander 9.0+                   ;
; Tested on: Total Commander 9.21a                 ;
; Script author: LonerD                            ;
; Site: https://dreamlair.net                      ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Parameters / Параметры:
; 1: {archive extension}/{расширение архива}
; 2: {archive name}/{имя файла архива}
;    {if %P%N - then file under cursor name}
;    {если %P%N - берётся имя файла под курсором}
; 3: {target directory}/{каталог назначения}
;    {if %T - then directory in target panel}
;    {если %T - каталог в противоположноей панели}
; 4: {move to archive: 0 - don't delete files | 1 - delete files}
;    {перемещать в архив: 0 - не удалять файлы | 1 - удалять файлы}
; 5: {archive type: 0 - normal | 1 - SFX}
;    {тип архива: 0 - обычный | 1 - SFX}
; 6: {1 - separate archives, one per selected file/dir}
;    (1 - каждый файл/каталог помещать в отдельный архив)
; 7: {1 - archive silent, without confirmation dialog}
;    (1 - тихий процесс, скрыть диалог архивации)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

#NoEnv
#NoTrayIcon
#SingleInstance force
SetBatchLines, -1
SetKeyDelay, 20, 20
DetectHiddenWindows, on

if not ( WinExist("ahk_class TTOTAL_CMD") || WinActive("ahk_class TTOTAL_CMD") )
  ExitApp
WinGet, hw_TTOTAL_CMD, ID, ahk_class TTOTAL_CMD
  global hw_TTOTAL_CMD

TCAPanel := SendMessageTC(1074, 1000, 0, A)
SelItems := SendMessageTC(1074, 1004+TCAPanel, 0, A)
CaretPos := SendMessageTC(1074, 1006+TCAPanel, 0, A)
IsUpDir := SendMessageTC(1074, 1008+TCAPanel, 0, A)

if (( IsUpDir = 1 ) && ( CaretPos = 0 ) && ( SelItems = 0 ))
  ExitApp

hw_TCTPath := SendMessageTC(1074, 11-TCAPanel, 0, A)
ControlGetText, TCTPath,, % "ahk_id " hw_TCTPath
TCTPath := StrReplace(TCTPath, "\*.*", "\")

Arc = %1%
ArcName = %2%
ArcPath = %3%
ArcMove = %4%
ArcExe = %5%
ArcSepar = %6%
ArcSilent = %7%

if 0 < 7
  ArcSilent = 0
if 0 < 6
  ArcSepar = 0
if 0 < 5
  ArcExe = 0
if 0 < 4
  ArcMove = 0
if 0 < 3
  ArcPath := TCTPath
if 0 < 2
  ArcName := ""
if 0 < 1
  Arc := "7z"

if ArcMove not in 0,1
  ArcMove = 0
if ArcExe not in 0,1
  ArcExe = 0
if ArcSepar not in 0,1
  ArcSepar = 0
if ArcSilent not in 0,1
  ArcSilent = 0

if not InStr(FileExist(ArcPath), "D")
  ArcPath := TCTPath

if FileExist(ArcName)
{
  SplitPath, ArcName, FileName, FileDir, FileExt, FileNameNoExt
  if not InStr(FileExist(ArcName), "D")
   ArcName := FileNameNoExt
     else
       ArcName := FileName
}

if ( ArcName = "" )
{
  FormatTime, CurrentDate, , [yyyy.MM.dd-HH.mm.ss]
  ArcName := "DreamLair " CurrentDate
}

Gosub, SetTC3264

TAltEdit := TC3264 = 32 ? "TAltEdit1" : "Edit1"
TCheckBoxMove := TC3264 = 32 ? "TCheckBox5" : "Button6"
TCheckBoxExe := TC3264 = 32 ? "TCheckBox4" : "Button5"
TCheckBoxSep := TC3264 = 32 ? "TCheckBox2" : "Button2"
TButtonOK := TC3264 = 32 ? "TButton5" : "Button21"

ArcLine := Arc . ":" . ArcPath . ArcName . "." . Arc

PostMessage, 0x433, 508,,, % "ahk_id " hw_TTOTAL_CMD
if ( ArcSilent = 0 )
{
  WinWaitNotActive, % "ahk_id " hw_TTOTAL_CMD
  Sleep, 200
  WinGet, Style, Style, % "ahk_id " hw_TTOTAL_CMD
  if (Style & 0x8000000)
    WinSet, Enable,, % "ahk_id " hw_TTOTAL_CMD
}
else
{
  WinWait, ahk_class TDLGZIP
  WinSet, Transparent, 0, ahk_class TDLGZIP
}

IfWinNotExist, ahk_class TDLGZIP
  ExitApp

Sleep, 50
ControlSetText, % TAltEdit, % ArcLine, ahk_class TDLGZIP

Sleep, 50
if ( ArcMove = 1 )
{
 SendMessage, 0x201,,, % TCheckBoxMove, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBoxMove, ahk_class TDLGZIP
}

Sleep, 50
if ( ArcExe = 1 )
{
 SendMessage, 0x201,,, % TCheckBoxExe, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBoxExe, ahk_class TDLGZIP
}

Sleep, 50
if ( ArcSepar = 1 )
{
 SendMessage, 0x201,,, % TCheckBoxSep, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TCheckBoxSep, ahk_class TDLGZIP
}

if ( ArcSilent = 1 )
{
 Sleep, 50
 SendMessage, 0x201,,, % TButtonOK, ahk_class TDLGZIP
 SendMessage, 0x202,,, % TButtonOK, ahk_class TDLGZIP
}

Sleep, 50
ExitApp

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Total Commander Send Message function            ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
SendMessageTC(TCMsg, wParam, lParam, aControl)
{
  SendMessage, % TCMsg, % wParam, % lParam, % aControl, % "ahk_id " hw_TTOTAL_CMD
  return ErrorLevel
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Total Commander Architecture (32 or 64 bit)      ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
SetTC3264:
if ( A_Is64bitOS = 0 )
  TC3264 := 32
else
{
  WinGet, TCControls, ControlList, % "ahk_id " hw_TTOTAL_CMD
  Loop, Parse, TCControls, `n, `r
  {
    if ( A_LoopField ~= "ListBox(1|2|3)" )
    {
      TC3264 := A_LoopField ~= "TMyListBox(1|2|3)" ? 32 : 64
      break
    }
  }
}
Return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

_________________
Win11 x64 Eng | TC DreamLair eternal pre-α
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group