<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Внесенные изменения в файл]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8550&amp;type=atom" />
	<updated>2013-08-14T17:29:24Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8550</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74535#p74535" />
			<content type="html"><![CDATA[<p>Пожалуйста <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-08-14T17:29:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74535#p74535</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74532#p74532" />
			<content type="html"><![CDATA[<p><span style="color: #008800"><strong>sergeiplugatyr</strong>, избегайте бесполезного цитирования предыдущего поста. У нас есть кнопочка &quot;Ответить&quot;.</span></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2013-08-14T17:08:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74532#p74532</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74524#p74524" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-14T15:56:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74524#p74524</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74511#p74511" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-08-14T11:11:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74511#p74511</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74478#p74478" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-13T14:49:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74478#p74478</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74474#p74474" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-08-13T14:02:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74474#p74474</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74462#p74462" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><p>Понял, что нужно еще что-то сверх того, что написано в первом посте.<br />Что значит &quot;выдавала именно то что я ввел в данное время&quot;? То есть данные отредактированы в редакторе, но файл не сохранен, или что-то другое?</p></blockquote></div><p>Объясню по другому, я например вписываю строку в файл hosts: 123, скрипт мне выдает что я ввел 123, но когда я ввожу еще раз на следующую строчку например 321, то он мне выдает что я добавил 123 и ниже 321.То есть я хочу чтобы он выдавал мне строчку которую я ввел в данный момент, а так он просто запоминает те строчки которые я вводил ранее и выдает их мне в сообщении.</p>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-13T03:55:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74462#p74462</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74456#p74456" />
			<content type="html"><![CDATA[<p>Понял, что нужно еще что-то сверх того, что написано в первом посте.<br />Что значит &quot;выдавала именно то что я ввел в данное время&quot;? То есть данные отредактированы в редакторе, но файл не сохранен, или что-то другое?</p>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-08-12T17:38:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74456#p74456</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74454#p74454" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-12T16:03:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74454#p74454</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74423#p74423" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-08-12T08:37:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74423#p74423</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74421#p74421" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-08-12T07:12:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74421#p74421</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74397#p74397" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Я подумал вы про то, как вставить данные...<br />Приведите хотя бы конкретный пример. <br />Если текст не равен предыдущему, а изменения были в нескольких разных строках - <strong>то что?</strong></p></blockquote></div><p>Ладно, я делаю программу чтобы она следила за файлом hosts, и я хочу чтобы если ты записываешь данные сторонней программой в этот файл, то она бы выдавала какие именно данные были внесены.</p>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-11T07:58:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74397#p74397</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74387#p74387" />
			<content type="html"><![CDATA[<p>Я подумал вы про то, как вставить данные...<br />Приведите хотя бы конкретный пример. <br />Если текст не равен предыдущему, а изменения были в нескольких разных строках - <strong>то что?</strong></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-08-10T17:32:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74387#p74387</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74386#p74386" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[sergeiplugatyr]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30382</uri>
			</author>
			<updated>2013-08-10T17:26:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74386#p74386</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Внесенные изменения в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74380#p74380" />
			<content type="html"><![CDATA[<p>Вы шутите &gt;&gt;&gt; <a href="http://forum.script-coding.com/viewtopic.php?pid=73574#p73574">AHK:Удаление конкретной строчки из файла</a>?<br />И снова вопрос зачем?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-08-10T14:50:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74380#p74380</id>
		</entry>
</feed>
