<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Обновление скрипта AHK]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=17110</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17110&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Обновление скрипта AHK».]]></description>
		<lastBuildDate>Sun, 08 May 2022 19:38:47 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153143#p153143</link>
			<description><![CDATA[<p>Хорошо, попробую.</p>]]></description>
			<author><![CDATA[null@example.com (alexsokolin)]]></author>
			<pubDate>Sun, 08 May 2022 19:38:47 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153143#p153143</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153142#p153142</link>
			<description><![CDATA[<p><strong>alexsokolin</strong> Замени на msgbox и посмотри какую ошибку будет давать. И оба должны быть скомпилированны. Ну и версии должны отличаться, на гите более новая офк.</p>]]></description>
			<author><![CDATA[null@example.com (Botsy)]]></author>
			<pubDate>Sun, 08 May 2022 19:12:32 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153142#p153142</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153137#p153137</link>
			<description><![CDATA[<p>Странно, сделал вроде бы все правильно. Первый скрипт запихнул в один файл, его закинул на github, второй также сделал со вторым кодом. <br />При запуске писало, что нет такой функции как &quot;OnException&quot;, поменял на &quot;Throw Exception&quot;, при запуске он запускается и выключается либо вообще не запускается.</p>]]></description>
			<author><![CDATA[null@example.com (alexsokolin)]]></author>
			<pubDate>Sun, 08 May 2022 11:43:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153137#p153137</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153132#p153132</link>
			<description><![CDATA[<p><strong>alexsokolin</strong> Отправляешь параметры запуска на апдейтер:<br /></p><div class="codebox"><pre><code>
auto_update()
{
	Current_version := 1.001
	name := &quot;test v1.1&quot;
	try {
		PID := DllCall(&quot;GetCurrentProcessId&quot;)
		URL := &quot;http://google.com/new_version.exe&quot;
		old_File_path := A_ScriptFullPath
		new_File_path := A_ScriptDir &quot;\&quot; name &quot;.exe&quot;
		link := &quot;http://google.com/update.txt&quot;

		http := ComObjCreate(&quot;WinHTTP.WinHTTPRequest.5.1&quot;)
		http.Open(&quot;GET&quot;, link, False)
		http.Send()
		http.WaitForResponse()
		Server_version := http.responseText
	}
	catch {
		OnException(&quot;Ошибка с подключением: 5&quot;)
		Exit
	}
	If (Server_version &gt; Current_version)
	{
		Progress, b CWFFFFFF CT000000 FM14,, Подождите... ,, Raleway
			Progress, 25
			Sleep, 250
		if !FileExist(&quot;test.exe&quot;)
			{
				Progress, OFF
				OnException(&quot;Не существует файла апдейтера: 3&quot;)
				Exit
			}
		try {
		UrlDownloadToFile, %URL%, %name%.exe
			sleep, 250
			Progress, 75
		}
		catch {
			OnException(&quot;Нет подключения к интернету: 4&quot;)
			Exit
		}
		Run, test_updater.exe &quot;%PID%&quot; &quot;%old_File_path%&quot; &quot;%new_File_path%&quot;
			Sleep, 250
			Progress, 99
			Sleep, 250
			Progress, OFF
		ExitApp
	}
	return
}
</code></pre></div><p>Сам апдейтер:<br /></p><div class="codebox"><pre><code>
#NoEnv
SetWorkingDir %A_ScriptDir%

if (A_IsCompiled != 1)
	ExitApp

if A_Args.Count() &gt; 3
	ExitApp
else if A_Args.Count() &gt; 0
{
	for index, element in A_Args
	{
		first_element := SubStr(element, 1, 1)
		if (first_element = &quot;-&quot;)
		{
			element := SubStr(element, 2)
		}
		input_parametrs%index% := element
	}
	;	input_parametrs1 = PID
	;	input_parametrs2 = old_File_path
	;	input_parametrs3 = new_File_path
	if !FileExist(input_parametrs2)
		ExitApp
	old_version(input_parametrs1, input_parametrs2)
	new_version(input_parametrs2, input_parametrs3)
	run %input_parametrs2%
}
else ExitApp

ExitApp

old_version(old_PID, old_File_path) 
{
	Process, Exist, %old_PID%
	if Errorlevel != 0
	{
		Process, Close, %old_PID%
		Process, WaitClose, %old_PID%, 1
		if ErrorLevel != 0
		{
			OnException(&quot;Err: 1&quot;)
			ExitApp
		}
	}

	if FileExist(old_File_path) 
	{
		FileDelete, %old_File_path%
		if ErrorLevel != 0
		{
			OnException(&quot;Err: 2&quot;)
			ExitApp
		}
	}
	return
}

new_version(old_File_path, new_File_path) 
{
	if FileExist(new_File_path)
	{
		FileMove, %new_File_path%, %old_File_path%, 1
		if ErrorLevel != 0
		{
			OnException(&quot;Err: 2&quot;)
			ExitApp
		}
	}
	return
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Botsy)]]></author>
			<pubDate>Sun, 08 May 2022 02:37:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153132#p153132</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153128#p153128</link>
			<description><![CDATA[<p>Для примера можно было бы просто два кода представить, так приходится запускать &#039;.exe&#039; для тестов, причём я так понял это разработка не публичная и защиты в ней нет.</p>]]></description>
			<author><![CDATA[null@example.com (__Михаил__)]]></author>
			<pubDate>Sat, 07 May 2022 23:47:31 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153128#p153128</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Обновление скрипта AHK]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=153121#p153121</link>
			<description><![CDATA[<p>Приветствую всех!<br />Столкнулся с проблемой, взял часть скрипта у одного человека в <a href="https://forum.script-coding.com/viewtopic.php?id=11689">этой теме</a>, что-то сделал под себя, но почему то скрипт работает не корректно.<br />При запуске если видит обновление, то он предлагает обновить, допустим мы соглашаемся, обновление проходит, скрипт скачивается в определенную папку и запускается, но он не копируется с помощью функции &quot;Update&quot; и собственно не удаляется уже скачанный файл через &quot;TempDelete&quot;.<br />Уже много чего перепробовал, ничего не получается. Надеюсь на помощь.<br /></p><div class="codebox"><pre><code>Loop %0%{
	ComParam%A_Index% := %A_Index%
}
#SingleInstance Force
#NoEnv

Version := 1.00

TrayTip, AHK MoH (%GuiVersion%), Скрипт успешно запущен.

If (ComParam1 = /Update){
	Update(ComParam2, ComParam3)
}
Else If (ComParam1 = /TempDelete){
	TempDelete(ComParam2, ComParam3)
}
Else{
	CheckUpdate(Version)
}
Return

CheckUpdate(Version) {
	NewVersionHTTP := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
	NewVersionHTTP.Open(&quot;GET&quot;, &quot;https://github.com/sokolin05/profile.moh/raw/master/version.profile.md&quot;, true)
	NewVersionHTTP.Send()
	NewVersionHTTP.WaitForResponse()
	NewVersion := NewVersionHTTP.ResponseText
	If (NewVersion &lt;= Version){
		; MsgBox, 16, Обновление, Новых версий скрипта не найдено.
		Gosub, NoUpdate
		Return
	}
	Else{
		MsgBox, % 4+64+256, Обновление, Найдена новая версия скрипта!`nОбновить с %Version% до %NewVersion%?
		IfMsgBox, No
		{
			Gosub, NoUpdate
			Return
		}
		IfMsgBox, Yes
		{
			URLDownloadToFile, https://github.com/sokolin05/profile.moh/raw/master/ahk.moh.exe, %A_Temp%\ahk.moh.exe
			PID := DllCall(&quot;GetCurrentProcessId&quot;)
			Run %A_Temp%\ahk.moh.exe, &quot;/Update&quot; &quot;%PID%&quot; &quot;%A_ScriptFullPath%&quot;
			ExitApp
		}
	}
}

Update(PID, Path) {
	Process, Close, %PID%
	Process, WaitClose, %PID%, 3
	If ErrorLevel
	{
		MsgBox, % 16, Обновление, Не удаётся закрыть процесс.
		ExitApp
	}
	Else{
		FileCopy, %A_ScriptFullPath%, %Path%, 1
		If ErrorLevel
		{
			MsgBox, % 16, Обновление, Не удалось копирование, возможно были запущены несколько экземпляров программы.
			ExitApp
		}
		Else{
			PID := DllCall(&quot;GetCurrentProcessId&quot;)
			Run %Path% &quot;/TempDelete&quot; &quot;%PID%&quot; &quot;%A_ScriptFullPath%&quot;
			ExitApp
		}
	}
}

TempDelete(PID, Path) {
	Process, Close, %PID%
	Process, WaitClose, %PID%, 2
	FileDelete, %Path%
}</code></pre></div><p>В самом скрипте есть и файл, с которого берется версия и сам AHK.</p>]]></description>
			<author><![CDATA[null@example.com (alexsokolin)]]></author>
			<pubDate>Sat, 07 May 2022 20:18:54 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=153121#p153121</guid>
		</item>
	</channel>
</rss>
