<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Обновление скрипта AHK]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17110&amp;type=atom" />
	<updated>2022-05-08T19:38:47Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17110</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153143#p153143" />
			<content type="html"><![CDATA[<p>Хорошо, попробую.</p>]]></content>
			<author>
				<name><![CDATA[alexsokolin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42516</uri>
			</author>
			<updated>2022-05-08T19:38:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153143#p153143</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153142#p153142" />
			<content type="html"><![CDATA[<p><strong>alexsokolin</strong> Замени на msgbox и посмотри какую ошибку будет давать. И оба должны быть скомпилированны. Ну и версии должны отличаться, на гите более новая офк.</p>]]></content>
			<author>
				<name><![CDATA[Botsy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41069</uri>
			</author>
			<updated>2022-05-08T19:12:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153142#p153142</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153137#p153137" />
			<content type="html"><![CDATA[<p>Странно, сделал вроде бы все правильно. Первый скрипт запихнул в один файл, его закинул на github, второй также сделал со вторым кодом. <br />При запуске писало, что нет такой функции как &quot;OnException&quot;, поменял на &quot;Throw Exception&quot;, при запуске он запускается и выключается либо вообще не запускается.</p>]]></content>
			<author>
				<name><![CDATA[alexsokolin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42516</uri>
			</author>
			<updated>2022-05-08T11:43:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153137#p153137</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153132#p153132" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Botsy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41069</uri>
			</author>
			<updated>2022-05-08T02:37:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153132#p153132</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153128#p153128" />
			<content type="html"><![CDATA[<p>Для примера можно было бы просто два кода представить, так приходится запускать &#039;.exe&#039; для тестов, причём я так понял это разработка не публичная и защиты в ней нет.</p>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2022-05-07T23:47:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153128#p153128</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Обновление скрипта AHK]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=153121#p153121" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[alexsokolin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42516</uri>
			</author>
			<updated>2022-05-07T20:18:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=153121#p153121</id>
		</entry>
</feed>
