<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Патчить все файлы в папке по расширению при нажатии хоткея.]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=13662</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=13662&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Патчить все файлы в папке по расширению при нажатии хоткея.».]]></description>
		<lastBuildDate>Mon, 30 Apr 2018 07:31:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Патчить все файлы в папке по расширению при нажатии хоткея.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=125010#p125010</link>
			<description><![CDATA[<p>В итоге.<br />Патчер не мой, оригинал патчера. <a href="http://forum.script-coding.com/viewtopic.php?id=3207">http://forum.script-coding.com/viewtopic.php?id=3207</a></p><p>Но прикрутил к нему умение <strong>патчить все файлы в папке по расширению при нажатии f6.<br /></strong><br />Сделан <strong>под файл менеджер Xplorer2</strong>, кто хочет может переделать под explorer.</p><div class="codebox"><pre><code>#if MouseIsOver(&quot;ahk_class ATL:ExplorerFrame&quot;) 
f6::
{
FileList =
WinGetTitle, Title, ahk_class ATL:ExplorerFrame
;var := RegExMatch(title, &quot;\-(.*)&quot;, match)
var := RegExMatch(title, &quot;(.*) - xplorer2&quot;, match)
var := match1
		path := var &quot;\&quot;
Loop, Files, %path%*.dng
   FileList = %FileList%%A_LoopFileLongPath%`n
Loop, Parse, FileList, `n
{
;MsgBox %FileList%%A_LoopFileLongPath%`n
ToolTip
FilePath = %A_LoopField% ; Путь к файлу.
If (FilePath != &quot;&quot;) 
{
;MsgBox, % FilePath
;FilePath = D:\Downloads_after_15.08.17\фотки\IMG_20180427_081748 - origcopy - Копия.dng
Offset = 0x34a      ; Смещение в файле, по которому писать.

Data =               ; Данные для записи. Пробелы необязательны.
(
10 27 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
10 27 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
10 27 00 00 10 27 00 00 10 27 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 10 27 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 10 27
)

Result := FilePatch(FilePath, Offset, Data)

tooltip, Записано байтов: %Result%


; ===================== Функция записи в файл. ======================

FilePatch(SrcFile, Offset, HexString) 
{
  If not FileExist(SrcFile) {
    MsgBox, 16, %A_ThisFunc%, Не найден файл:`n%SrcFile%
    Return 0
  }

  FileGetSize, FileSize, %SrcFile%

  If(Offset &gt;= FileSize) {
    MsgBox, 16, %A_ThisFunc%, Смещение за пределами файла.
    Return 0
  }

  If RegExMatch(HexString, &quot;i)0x&quot;) {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      Неверный формат данных: префикс &quot;0x&quot;.
      Функция не предназначена для записи чисел,
      только последовательностей байтов.
    )
    Return 0
  }

  HexString := RegExReplace(HexString, &quot;\s&quot;)

  If HexString is not xDigit
  {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      Строка данных содержит недопустимые символы.
      Допустимы только 0123456789ABCDEF.
    )
    Return 0
  }

  Len := StrLen(HexString)

  If Mod(Len, 2)
  {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      В строке данных нечётное количество символов.
      Каждый байт нужно обозначать двумя цифрами.
    )
    Return 0
  }

  cBytes := Len / 2

  VarSetCapacity(Buf, cBytes, 0)

  Pos = 1

  Loop, % cBytes
  {
    Byte := &quot;0x&quot; . SubStr(HexString, Pos, 2)
    Pos += 2
    NumPut(Byte, Buf, A_Index - 1, &quot;Char&quot;)
  }

  OPEN_EXISTING = 3
  FILE_WRITE_DATA = 2
  FILE_BEGIN = 0

  VarSetCapacity(BytesWritten, 4, 0)

  hFile := DllCall( &quot;CreateFile&quot;, &quot;Str&quot;,  SrcFile
                                , &quot;UInt&quot;, FILE_WRITE_DATA
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, OPEN_EXISTING
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, 0 )

  If(hFile = -1) {
    MsgBox, 16, %A_ThisFunc%, Не удалось открыть файл.
    Return 0
  }

  DllCall( &quot;SetFilePointer&quot;, &quot;UInt&quot;,  hFile
                           , &quot;UInt&quot;, Offset
                           , &quot;UInt&quot;, 0
                           , &quot;UInt&quot;, FILE_BEGIN )

  If(A_LastError) {
    DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )
    MsgBox, 16, %A_ThisFunc%
              , Ошибка при установке указателя файла: %A_LastError%
    Return 0
  }

  Ret := DllCall( &quot;WriteFile&quot;, &quot;UInt&quot;, hFile
                             , &quot;UInt&quot;, &amp;Buf
                             , &quot;UInt&quot;, cBytes
                             , &quot;UInt&quot;, &amp;BytesWritten
                             , &quot;UInt&quot;, 0 )

  If(Ret = 0) {
    DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )
    MsgBox, 16, %A_ThisFunc%, Не удалось записать в файл.
    Return 0
  }

  DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )

  Return NumGet(BytesWritten, 0, &quot;UInt&quot;)
}
}
}
}


MouseIsOver(WinTitle) {
MouseGetPos, , , Win
return WinExist(WinTitle . &quot; ahk_id &quot; . Win)
	
   }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (OmTatSat)]]></author>
			<pubDate>Mon, 30 Apr 2018 07:31:07 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=125010#p125010</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Патчить все файлы в папке по расширению при нажатии хоткея.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=125009#p125009</link>
			<description><![CDATA[<p>Разобрался, скобок {} после &quot;Loop, Parse, FileList, `n&quot; не хватало.</p>]]></description>
			<author><![CDATA[null@example.com (OmTatSat)]]></author>
			<pubDate>Mon, 30 Apr 2018 07:28:44 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=125009#p125009</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Патчить все файлы в папке по расширению при нажатии хоткея.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=125007#p125007</link>
			<description><![CDATA[<p>Здравствуйте, помогите пожалуйста разобраться, почему не присваивается переменная FilePath = %A_LoopField%. msgbox нормально показывает путь с %A_LoopField%</p><div class="codebox"><pre><code>FileList =
Loop, Files, *.dng
   FileList = %FileList%%A_LoopFileLongPath%`n
Loop, Parse, FileList, `n

MsgBox %A_LoopField%
FilePath = %A_LoopField% ; Путь к файлу.
;MsgBox, % FilePath
;FilePath = D:\Downloads_after_15.08.17\фотки\Новая папка\IMG_20180427_081748 - origcopy - Копия.dng
Offset = 0x34a      ; Смещение в файле, по которому писать.

Data =               ; Данные для записи. Пробелы необязательны.
(
10 27 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
10 27 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
10 27 00 00 10 27 00 00 10 27 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 10 27 00 00 10 27 00 00
00 00 00 00 10 27 00 00 00 00 00 00 10 27 00 00
00 00 00 00 10 27 00 00 10 27
)

Result := FilePatch(FilePath, Offset, Data)

MsgBox, Записано байтов: %Result%


; ===================== Функция записи в файл. ======================

FilePatch(SrcFile, Offset, HexString) 
{
  If not FileExist(SrcFile) {
    MsgBox, 16, %A_ThisFunc%, Не найден файл:`n%SrcFile%
    Return 0
  }

  FileGetSize, FileSize, %SrcFile%

  If(Offset &gt;= FileSize) {
    MsgBox, 16, %A_ThisFunc%, Смещение за пределами файла.
    Return 0
  }

  If RegExMatch(HexString, &quot;i)0x&quot;) {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      Неверный формат данных: префикс &quot;0x&quot;.
      Функция не предназначена для записи чисел,
      только последовательностей байтов.
    )
    Return 0
  }

  HexString := RegExReplace(HexString, &quot;\s&quot;)

  If HexString is not xDigit
  {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      Строка данных содержит недопустимые символы.
      Допустимы только 0123456789ABCDEF.
    )
    Return 0
  }

  Len := StrLen(HexString)

  If Mod(Len, 2)
  {
    MsgBox, 16, %A_ThisFunc%,
    (LTrim
      В строке данных нечётное количество символов.
      Каждый байт нужно обозначать двумя цифрами.
    )
    Return 0
  }

  cBytes := Len / 2

  VarSetCapacity(Buf, cBytes, 0)

  Pos = 1

  Loop, % cBytes
  {
    Byte := &quot;0x&quot; . SubStr(HexString, Pos, 2)
    Pos += 2
    NumPut(Byte, Buf, A_Index - 1, &quot;Char&quot;)
  }

  OPEN_EXISTING = 3
  FILE_WRITE_DATA = 2
  FILE_BEGIN = 0

  VarSetCapacity(BytesWritten, 4, 0)

  hFile := DllCall( &quot;CreateFile&quot;, &quot;Str&quot;,  SrcFile
                                , &quot;UInt&quot;, FILE_WRITE_DATA
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, OPEN_EXISTING
                                , &quot;UInt&quot;, 0
                                , &quot;UInt&quot;, 0 )

  If(hFile = -1) {
    MsgBox, 16, %A_ThisFunc%, Не удалось открыть файл.
    Return 0
  }

  DllCall( &quot;SetFilePointer&quot;, &quot;UInt&quot;,  hFile
                           , &quot;UInt&quot;, Offset
                           , &quot;UInt&quot;, 0
                           , &quot;UInt&quot;, FILE_BEGIN )

  If(A_LastError) {
    DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )
    MsgBox, 16, %A_ThisFunc%
              , Ошибка при установке указателя файла: %A_LastError%
    Return 0
  }

  Ret := DllCall( &quot;WriteFile&quot;, &quot;UInt&quot;, hFile
                             , &quot;UInt&quot;, &amp;Buf
                             , &quot;UInt&quot;, cBytes
                             , &quot;UInt&quot;, &amp;BytesWritten
                             , &quot;UInt&quot;, 0 )

  If(Ret = 0) {
    DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )
    MsgBox, 16, %A_ThisFunc%, Не удалось записать в файл.
    Return 0
  }

  DllCall( &quot;CloseHandle&quot;, &quot;UInt&quot;, hFile )

  Return NumGet(BytesWritten, 0, &quot;UInt&quot;)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (OmTatSat)]]></author>
			<pubDate>Sun, 29 Apr 2018 23:17:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=125007#p125007</guid>
		</item>
	</channel>
</rss>
