Orion9

|
Posted: Mon Dec 08, 2025 00:41 Post subject: |
|
|
| A55555 wrote: | Можно ли прописать не одно, а например 2 места, где лежат мои .torrent
файлы? |
Можно, конечно, это напрашивалось сразу. Казалось бы мелочь, но кода получилось бы в два раза больше. В тот момент не мог себе это позволить, т.к. параллельно скрипты собирал и не хотел отвлекаться. Функция была только для теста, я даже команду не стал регистрировать. Вы, кстати, сами можете это сделать, если вам привычнее назначать горячие клавиши через wincmd.ini.
| A55555 wrote: | | Под более сложным вариантом это вы имеете ввиду, чтоб и для частично скачанных находило их .torrent файл? |
Да, и сначала я подумал, что кода получится строк на 300, помня о функции FindTorrentParts, которая чем-то в этом смысле похожа, но можно сделать и проще, правда с некоторыми ограничениями.
 Hidden text | Code: | SetHotkeyAction /K:A /H:9 SearchForTorrents
Func SearchForTorrents()
Local sTorDirs = COMMANDER_PATH & "\Ini\Torrent.txt"
Local sPath = RequestCopyDataInfo("SP")
Local sName = RequestCopyDataInfo("SN")
Local sFile = sPath & sName
If Not FileExist(sFile) Then
ShowHint("Файл не существует " & sFile)
Return
EndIf
If Not FileExist(sTorDirs) Then
ShowHint("Файл не существует " & sTorDirs)
Return
EndIf
Static aTorDirs = List()
aTorDirs.Count = 0
aTorDirs.LoadFromFile(sTorDirs)
If aTorDirs.Count = 0 Then
MsgBox("Файл не содержит данных." & auCRLF & auCRLF & sTorDirs, "Autorun", 48)
Return
EndIf
Local sLegit, sIgnore
For i = 0 To aTorDirs.Count - 1
sDir = aTorDirs[i]
If FileExist(sDir) And StrPos(FileGetAttr(sDir), "D") Then
sLegit &= sDir & auCRLF
Else
sIgnore &= sDir & auCRLF
EndIf
Next
sLegit = StrTrim(sLegit)
sIgnore = StrTrim(sIgnore)
If sLegit = "" Then
MsgBox("Нет существующих путей." & auCRLF & auCRLF & sTorDirs, "Autorun", 48)
Return
EndIf
Local sTorrs
aTorDirs.Count = 0
aTorDirs.Text = sLegit
For i = 0 To aTorDirs.Count - 1
sTorrs &= StrTrim(FileFind(aTorDirs[i], "*.torrent", 0)) & auCRLF
Next
sTorrs = StrTrim(sTorrs)
If sTorrs = "" Then
sTorrs = "Каталоги поиска: " & auCRLF & sLegit & auCRLF & auCRLF & _
(sIgnore = "" ? "" : "Не существуют: " & auCRLF & sIgnore)
MsgBox("Не найдены .torrent файлы." & auCRLF & auCRLF & sTorrs, "Autorun", 48)
Return
EndIf
Local obj = Plugin("TCTorrent")
If ERROR <> 0 Then
MsgBox("TCTorrent.wdx plugin error " & ERROR, "Autorun", 48)
Return
Endif
Local lst = List(), sFound = ""
lst.Text = sTorrs
WinFindTorrentData(0)
Local size
If StrPos(FileGetAttr(sFile), "D") Then
Sleep(10)
WinSetText("Подсчёт размера...", h_WinFindTorr)
size = FileFind(sFile, "*.*", 1, 0, "TotalSize")
Else
size = FileGetSize(sFile)
EndIf
For i = 0 To lst.Count - 1
WinSetText(lst[i], h_WinFindTorr)
obj.FileName = lst[i]
If size = obj.GetValue(2,0) Then
sFound = lst[i]
Break
EndIf
If g_FindTorrTask = 0 Then Break
Next
Free(lst, obj)
If g_FindTorrTask = 0 Then
MsgBox("Операция прервана", "Autorun", 48)
Return
EndIf
g_FindTorrTask = 0
SendMessage(h_WinFindTorr, 0x0010, 0, 0)
If sFound = "" Then
MsgBox("Не найдено." & auCRLF & auCRLF & _
"Каталоги поиска: " & auCRLF & sLegit & auCRLF & auCRLF & _
(sIgnore = "" ? "" : "Не существуют: " & auCRLF & sIgnore & auCRLF & auCRLF) & _
"Файлов .torrent: " & i & auCRLF & auCRLF & _
"Искомый объект: " & auCRLF & sFile & auCRLF & _
"Размер: " & size & " байт" & auCRLF & auCRLF & _
"Искать по имени и размеру?", "Autorun", 3+0+48)
If EXTENDED <> 6 Then Return
If StrPos(FileGetAttr(sFile), "D") Then
MsgBox("Объект является каталогом. Поиск по имени и размеру доступен только для файлов.", "Autorun", 48)
Return
EndIf
sFound = DeepSearchForTorrents(sFile, sTorrs)
If sFound = "" Then Return
EndIf
Local bUseEm = 1
ShowRedHint("Автопереход к найденному")
If bUseEm Then
SetEnv("COMMANDER_GOTO", sFound)
CommandExec("em_torrents_goto")
#CommandExec("em_torrents_goto", sFound)
Else
GoToPathFromMsg(sFound)
If FileExist(sFound) Then SendCommand(2002)
EndIf
EndFunc
Func DeepSearchForTorrents(sFile, sTorrs)
Static sLibName = "TCTorrent.wlx" & (auX64 ? "64" : "")
Static sLibPath = COMMANDER_PATH & "\Plugins\wlx\TCTorrent\" & sLibName
Local hDll = DllCall("LoadLibrary", "wstr", sLibPath, "handle")
If hDll = 0 Then
MsgBox("Can't load " & sLibPath, "Autorun", 48)
Return
EndIf
WinFindTorrentData(0)
Local nSkip = 0, nError = 0, sName, sSize, sLog
Local i, j, ht, sTorr, sFound, lst = List(), nCount = 0
Local name = FileGetName(sFile), size = FileGetSize(sFile)
lst.Text = sTorrs
For i = 0 To lst.Count - 1
sTorr = lst[i]
#OutputDebugString(sTorr)
WinSetText(sTorr, h_WinFindTorr)
ht = DllCall(sLibName & "\TorrentOpen", "wstr", sTorr, "handle")
If ht = 0 Then
nSkip += 1
nError += 1
sLog &= "Can't open " & sTorr & auCRLF
Continue
EndIf
nCount = DllCall(sLibName & "\TorrentCountGet", "handle", ht, "wstr", "File", "uint")
If nCount < 2 Then
nSkip += 1
If nCount < 1 Then
nError += 1
sLog &= "Corrupt " & sTorr & auCRLF
Else
sLog &= "Single " & sTorr & auCRLF
EndIf
DllCall(sLibName & "\TorrentClose", "handle", ht)
Continue
EndIf
For j = 0 To nCount - 1
sName = DllCall(sLibName & "\TorrentGet", "handle", ht, "wstr", "File", "int", j, "wstr")
sSize = DllCall(sLibName & "\TorrentGet", "handle", ht, "wstr", "FileSize", "int", j, "wstr")
If name = FileGetName(sName) And size = sSize Then
sFound = sTorr
Break
EndIf
If g_FindTorrTask = 0 Then Break
Next
DllCall(sLibName & "\TorrentClose", "handle", ht)
If sFound <> "" Then Break
If g_FindTorrTask = 0 Then Break
Next
Free(lst)
If g_FindTorrTask = 0 Then
DllCall("FreeLibrary", "handle", hDll)
MsgBox("Операция прервана", "Autorun", 48)
Return
EndIf
g_FindTorrTask = 0
SendMessage(h_WinFindTorr, 0x0010, 0, 0)
DllCall("FreeLibrary", "handle", hDll)
If sFound = "" Then
MsgBox("Не найдено." & auCRLF & auCRLF & _
"Файлов: " & i & auCRLF & _
"Пропущено: " & nSkip & auCRLF & _
"Ошибок: " & nError & auCRLF & auCRLF & _
"Искомый файл: " & auCRLF & sFile & auCRLF & _
"Размер: " & size & " байт" & auCRLF & auCRLF & _
"Показать пропущенные?", "Autorun", 3+0+48)
If EXTENDED <> 6 Then Return
If sLog = "" Then
MsgBox("Нет пропущенных", "Autorun", 64)
Else
MsgBox(sLog, "Autorun", 64)
EndIf
Return
EndIf
Return sFound
EndFunc |
В usercmd.ini нужно добавить пару команд чтобы избавиться временно от входа в torrent-файлы как архивы при автопереходе.
| Code: | [em_torrents_goto]
cmd=cm_FocusTrg,em_commander_cd
[em_commander_cd_param]
cmd=CD
param=?%A0
[em_commander_cd]
cmd=CD %COMMANDER_GOTO% |
Это временное решение, нужно поинтересоваться у автора плагина, как сделать, чтобы команда CommandExec /CD %'Target' не заходила в файл при переходе и чтобы не было необходимости посылать вслед SendCommand(2002). А также заодно спросить, почему CommandExec("em_torrents_goto", sFound) теряет юникод.
Но это потом.
В общем, создайте файл COMMANDER_PATH & "\Ini\Torrent.txt" с путями. Например:
| Code: | d:\Portable\uTorrent\torrents
d:\Temp\Test
d:\Temp
d:\Temp\Software
d:\Test\TorrentData |
Глубина каталогов не учитывается. Попробуйте, как все работает. Думаю, смысла нет подробно описывать работу функционала, там вроде все прозрачно. |
|