<?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>https://forum.script-coding.com/viewtopic.php?id=8550</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8550&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Внесенные изменения в файл».]]></description>
		<lastBuildDate>Wed, 14 Aug 2013 17:29:24 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74535#p74535</link>
			<description><![CDATA[<p>Пожалуйста <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Wed, 14 Aug 2013 17:29:24 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74535#p74535</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74532#p74532</link>
			<description><![CDATA[<p><span style="color: #008800"><strong>sergeiplugatyr</strong>, избегайте бесполезного цитирования предыдущего поста. У нас есть кнопочка &quot;Ответить&quot;.</span></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Wed, 14 Aug 2013 17:08:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74532#p74532</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74524#p74524</link>
			<description><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><div class="codebox"><pre><code>#NoEnv
#Persistent
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
IfNotExist, %file2%    
   FileCopy, %file1%, %file2%,1
if ErrorLevel {
   MsgBox Невозможно скопировать файл.
   ExitApp
}
SetTimer, Check, 10000 ; 10 секунд
Return

Check:
   FileGetTime, time1, %file1%
   FileGetTime, time2, %file2%
   if (time1 = time2)
      Return
   Loop 2 {
      J := A_Index, Arr%J% := []
      Loop, Read, % file%J%
         Arr%J%.Insert(A_LoopReadLine . &quot;`n&quot;, &quot;&quot;)
   }
   loop 2 {
      A:=3-A_Index
      Str_%A% =
      for Key in Arr%A_Index%
         Str_%A% .=  Arr%A%.HasKey(Key) ? &quot;&quot; : Key
   }
   if (Str_2 || Str_1) {
      MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_2 . &quot;`n`n&quot;
             . &quot;Убрано: `n_____________`n`n&quot; . Str_1 . &quot;`n&quot;
   }
   FileCopy, %file1%, %file2%, 1
   if ErrorLevel {
      MsgBox Невозможно скопировать файл.
      ExitApp
   }
Return</code></pre></div><p>Вместо таймера лучше использовать уведомления, как например в <a href="http://forum.script-coding.com/viewtopic.php?pid=51839#p51839">этом примере</a>, но пока пусть так.</p></blockquote></div><p>Прям то что нужно, спасибо вам.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Wed, 14 Aug 2013 15:56:27 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74524#p74524</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74511#p74511</link>
			<description><![CDATA[<div class="codebox"><pre><code>#NoEnv
#Persistent
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
IfNotExist, %file2%    
   FileCopy, %file1%, %file2%,1
if ErrorLevel {
   MsgBox Невозможно скопировать файл.
   ExitApp
}
SetTimer, Check, 10000 ; 10 секунд
Return

Check:
   FileGetTime, time1, %file1%
   FileGetTime, time2, %file2%
   if (time1 = time2)
      Return
   Loop 2 {
      J := A_Index, Arr%J% := []
      Loop, Read, % file%J%
         Arr%J%.Insert(A_LoopReadLine . &quot;`n&quot;, &quot;&quot;)
   }
   loop 2 {
      A:=3-A_Index
      Str_%A% =
      for Key in Arr%A_Index%
         Str_%A% .=  Arr%A%.HasKey(Key) ? &quot;&quot; : Key
   }
   if (Str_2 || Str_1) {
      MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_2 . &quot;`n`n&quot;
             . &quot;Убрано: `n_____________`n`n&quot; . Str_1 . &quot;`n&quot;
   }
   FileCopy, %file1%, %file2%, 1
   if ErrorLevel {
      MsgBox Невозможно скопировать файл.
      ExitApp
   }
Return</code></pre></div><p>Вместо таймера лучше использовать уведомления, как например в <a href="http://forum.script-coding.com/viewtopic.php?pid=51839#p51839">этом примере</a>, но пока пусть так.</p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Wed, 14 Aug 2013 11:11:52 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74511#p74511</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74478#p74478</link>
			<description><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><p>После показа измененых строк появляется диалог с запросом: &quot;Зафиксировать изменения?&quot; и двумя вариантами ответа.<br />Нажми &quot;Да&quot; и запусти скрипт еще раз.</p><p>Я внес изменения в <a href="http://forum.script-coding.com/viewtopic.php?pid=74423#p74423">пост #12</a>, чтобы в случае невозможности копирования обновленного файла hosts, скрипт сообщал бы об ошибке. Это может быть, если скрипту не хватает прав для копирования файла в папку, откуда он запущен, например из папки с ОС.</p></blockquote></div><p>Проблема в том что нужно постоянно перезапускать скрипт, тогда он будет работать исправно, а мне нужно чтобы он как то обновлялся чтобы можно было обойтись без перезапуска скрипта.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Tue, 13 Aug 2013 14:49:49 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74478#p74478</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74474#p74474</link>
			<description><![CDATA[<p>После показа измененых строк появляется диалог с запросом: &quot;Зафиксировать изменения?&quot; и двумя вариантами ответа.<br />Нажми &quot;Да&quot; и запусти скрипт еще раз.</p><p>Я внес изменения в <a href="http://forum.script-coding.com/viewtopic.php?pid=74423#p74423">пост #12</a>, чтобы в случае невозможности копирования обновленного файла hosts, скрипт сообщал бы об ошибке. Это может быть, если скрипту не хватает прав для копирования файла в папку, откуда он запущен, например из папки с ОС.</p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Tue, 13 Aug 2013 14:02:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74474#p74474</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74462#p74462</link>
			<description><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><p>Понял, что нужно еще что-то сверх того, что написано в первом посте.<br />Что значит &quot;выдавала именно то что я ввел в данное время&quot;? То есть данные отредактированы в редакторе, но файл не сохранен, или что-то другое?</p></blockquote></div><p>Объясню по другому, я например вписываю строку в файл hosts: 123, скрипт мне выдает что я ввел 123, но когда я ввожу еще раз на следующую строчку например 321, то он мне выдает что я добавил 123 и ниже 321.То есть я хочу чтобы он выдавал мне строчку которую я ввел в данный момент, а так он просто запоминает те строчки которые я вводил ранее и выдает их мне в сообщении.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Tue, 13 Aug 2013 03:55:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74462#p74462</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74456#p74456</link>
			<description><![CDATA[<p>Понял, что нужно еще что-то сверх того, что написано в первом посте.<br />Что значит &quot;выдавала именно то что я ввел в данное время&quot;? То есть данные отредактированы в редакторе, но файл не сохранен, или что-то другое?</p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Mon, 12 Aug 2013 17:38:37 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74456#p74456</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74454#p74454</link>
			<description><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><p>Скрипт показывает, какие строки были удалены и/или добавлены со времени последней проверки.<br />При этом порядок строк и их расположение в исходных файлах неважны, дубликаты строк тоже не учитываются.<br />Если файл <strong>file2</strong> отсутствует при первом запуске, он будет создан при подтверждении замены.<br /></p><div class="codebox"><pre><code>#NoEnv
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
Loop 2 {
   Iter := A_Index, Arr%Iter% := []
   Loop, Read, % file%Iter%
      Arr%Iter%.Insert(A_LoopReadLine, &quot;&quot;)
}
for Key in Arr1
   Str_add .=  Arr2.HasKey(Key) ? &quot;&quot; : Key . &quot;`n&quot;
for Key in Arr2
   Str_del .=  Arr1.HasKey(Key) ? &quot;&quot; : Key . &quot;`n&quot;
MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_Add . &quot;`n`n&quot;
       . &quot;Убрано: `n_____________`n`n&quot; . Str_Del . &quot;`n&quot;
if (Str_Del || Str_Add) {
   MsgBox,4,, Зафиксировать изменения ?`n`nФайл &quot;%file2%&quot; будет заменен`nфайлом &quot;%file1%&quot;
   IfMsgBox Yes
      FileCopy, %file1%, %file2%,1
}
return</code></pre></div><br /><p>Если нужны номера строк с изменениями:</p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Показать</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#NoEnv
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
Loop 2 {
   Iter := A_Index, Arr%Iter% := []
   Loop, Read, % file%Iter%
      Arr%Iter%.Insert(A_LoopReadLine, A_Index)
}
for Key, V in Arr1
   Str_add .=  Arr2.HasKey(Key) ? &quot;&quot; : &quot;строка № &quot; . V . &quot;  -&gt; &quot; . Key . &quot;`n&quot;
for Key, V in Arr2
   Str_del .=  Arr1.HasKey(Key) ? &quot;&quot; : &quot;строка № &quot; . V . &quot; -&gt; &quot; . Key . &quot;`n&quot;
MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_Add . &quot;`n`n&quot;
       . &quot;Убрано: `n_____________`n`n&quot; . Str_Del . &quot;`n&quot;
if (Str_Del || Str_Add) {
   MsgBox,4,, Зафиксировать изменения ?`n`nФайл &quot;%file2%&quot; будет заменен`nфайлом &quot;%file1%&quot;
   IfMsgBox Yes
      FileCopy, %file1%, %file2%,1
}
return</code></pre></div></div></div></blockquote></div><p>Работает, а вот как сделать чтобы он перезаписывал данные, этот код запоминает данные которые я вводил ранее.Можно как то сделать чтобы она обновляла свои данные, и при нахождении какой либо строчки которую я вписал в файл hosts, выдавала именно то что я ввел в данное время.Надеюсь суть вы поняли.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Mon, 12 Aug 2013 16:03:03 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74454#p74454</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74423#p74423</link>
			<description><![CDATA[<p>Скрипт показывает, какие строки были удалены и/или добавлены со времени последней проверки.<br />При этом порядок строк и их расположение в исходных файлах неважны, дубликаты строк тоже не учитываются.<br />Если файл <strong>file2</strong> отсутствует при первом запуске, он будет создан при подтверждении замены.<br /></p><div class="codebox"><pre><code>#NoEnv
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
Loop 2 {
   Iter := A_Index, Arr%Iter% := []
   Loop, Read, % file%Iter%
      Arr%Iter%.Insert(A_LoopReadLine, &quot;&quot;)
}
for Key in Arr1
   Str_add .=  Arr2.HasKey(Key) ? &quot;&quot; : Key . &quot;`n&quot;
for Key in Arr2
   Str_del .=  Arr1.HasKey(Key) ? &quot;&quot; : Key . &quot;`n&quot;
MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_Add . &quot;`n`n&quot;
       . &quot;Убрано: `n_____________`n`n&quot; . Str_Del . &quot;`n&quot;
if (Str_Del || Str_Add) {
   MsgBox,4,, Зафиксировать изменения ?`n`nФайл &quot;%file2%&quot; будет заменен`nфайлом &quot;%file1%&quot;
   IfMsgBox Yes
   {
      FileCopy, %file1%, %file2%,1
         if ErrorLevel
         MsgBox Невозможно скопировать файл.
   }
}
return</code></pre></div><br /><p>Если нужны номера строк с изменениями:</p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Показать</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#NoEnv
file1 = c:\Windows\SYSTEM32\drivers\etc\hosts
file2 = %A_ScriptDir%\hosts.old
Loop 2 {
   Iter := A_Index, Arr%Iter% := []
   Loop, Read, % file%Iter%
      Arr%Iter%.Insert(A_LoopReadLine, A_Index)
}
for Key, V in Arr1
   Str_add .=  Arr2.HasKey(Key) ? &quot;&quot; : &quot;строка № &quot; . V . &quot;  -&gt; &quot; . Key . &quot;`n&quot;
for Key, V in Arr2
   Str_del .=  Arr1.HasKey(Key) ? &quot;&quot; : &quot;строка № &quot; . V . &quot; -&gt; &quot; . Key . &quot;`n&quot;
MsgBox % &quot;Добавлено: `n_____________`n`n&quot; . Str_Add . &quot;`n`n&quot;
       . &quot;Убрано: `n_____________`n`n&quot; . Str_Del . &quot;`n&quot;
if (Str_Del || Str_Add) {
   MsgBox,4,, Зафиксировать изменения ?`n`nФайл &quot;%file2%&quot; будет заменен`nфайлом &quot;%file1%&quot;
   IfMsgBox Yes
   {
      FileCopy, %file1%, %file2%,1
         if ErrorLevel
         MsgBox Невозможно скопировать файл.
   }
}
return</code></pre></div></div></div>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Mon, 12 Aug 2013 08:37:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74423#p74423</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74421#p74421</link>
			<description><![CDATA[<div class="quotebox"><cite>sergeiplugatyr пишет:</cite><blockquote><p>Ладно</p></blockquote></div><p>Спасибо большое за раскрытие секрета, я никому не расскажу.<br />Попробуй так:<br /></p><div class="codebox"><pre><code>FileHost = C:\Users\sergey\Desktop\hosts
FileBackUp = %A_ScriptDir%\BackUp
FileRead, LastText, %FileBackUp% ; Перед первым стартом должен быть BackUp файла hosts
Return

1:: ; Проверка изменений
    FileRead, NowFileHost, %FileHost% 
    NewStr := DelStr := &quot;&quot;
    
    Loop, Read, %FileHost%
    {
        If !RegExMatch( LastText, &quot;m`a)^\Q&quot; A_LoopReadLine &quot;\E$&quot;) ; Сравнение целых строк
        {
            NewStr .= A_LoopReadLine &quot;`n&quot;
            FileReadLine, ReadLine, %FileBackUp%, %A_Index% ; Если надо знать что изменено или удалено
            DelStr .= ReadLine &quot;`n&quot; ; Если надо знать что изменено или удалено
        }
    }
    
    LastText := NowFileHost
    FileDelete, %FileBackUp%
    FileAppend, %NowFileHost%, %FileBackUp% 
    MsgBox,, Новые строки, % NewStr 
    MsgBox,, Удалённые строки, % DelStr ; Если надо знать что изменено или удалено
    Return
    
; Если надо знать что изменено или удалено,     
; в случае если в итоге строк может стать больше по количеству    
;  в результате смещения старой строки &quot;вниз&quot;     
; из-за возможности записи данных не только в конец файла,    
;  то нужно ещё допилить.</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 12 Aug 2013 07:12:40 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74421#p74421</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74397#p74397</link>
			<description><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Я подумал вы про то, как вставить данные...<br />Приведите хотя бы конкретный пример. <br />Если текст не равен предыдущему, а изменения были в нескольких разных строках - <strong>то что?</strong></p></blockquote></div><p>Ладно, я делаю программу чтобы она следила за файлом hosts, и я хочу чтобы если ты записываешь данные сторонней программой в этот файл, то она бы выдавала какие именно данные были внесены.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Sun, 11 Aug 2013 07:58:36 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74397#p74397</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74387#p74387</link>
			<description><![CDATA[<p>Я подумал вы про то, как вставить данные...<br />Приведите хотя бы конкретный пример. <br />Если текст не равен предыдущему, а изменения были в нескольких разных строках - <strong>то что?</strong></p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 10 Aug 2013 17:32:52 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74387#p74387</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74386#p74386</link>
			<description><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Вы шутите &gt;&gt;&gt; <a href="http://forum.script-coding.com/viewtopic.php?pid=73574#p73574">AHK:Удаление конкретной строчки из файла</a>?<br />И снова вопрос зачем?</p></blockquote></div><p>И что?Там я спрашивал как удалить строчку из файла, а тут я спрашиваю как узнать какие данные были внесены сторонней программой.</p>]]></description>
			<author><![CDATA[null@example.com (sergeiplugatyr)]]></author>
			<pubDate>Sat, 10 Aug 2013 17:26:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74386#p74386</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=74380#p74380</link>
			<description><![CDATA[<p>Вы шутите &gt;&gt;&gt; <a href="http://forum.script-coding.com/viewtopic.php?pid=73574#p73574">AHK:Удаление конкретной строчки из файла</a>?<br />И снова вопрос зачем?</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 10 Aug 2013 14:50:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=74380#p74380</guid>
		</item>
	</channel>
</rss>
