Another option for #Includes + Extra!

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Another option for #Includes + Extra!

11 Jul 2018, 18:39

So my main question is there another option than #Include for a list of variables. I update these variables on a regular basis when someone finds a character that cannot be represented. I currently use a #Includes at the beginning of the script however some have asked for an offline version of the script. The issue comes in when they are offline they don't have access to the server files, which is where I store the variables so everyone is using the same ones.

Variable Code

Code: Select all

a := ["111", "112", "113"]
b := ["211", "212"]
c := ["311", "312", "313"]

Letters := a|b|c
Main Code

Code: Select all

For x, y in Letters
	NewString := StrReplace(Input, x, A_LoopField)
Then also I would like to include a check at the beginning to determine if the code is connected to the server. The best way I can think of is to do something like this

Code: Select all

if !FileExist("C:\FileLocation")
{
   MsgBox, 36, Unable to locate Server, The server is either not connected or you are running on offline mode`, please choose yes to continue in offline mode (will look for files in a different location) or no to exit the script.
   	IfMsgBox Yes
   	 	MsgBox You pressed Yes. ;Temp
	else
  	 	 MsgBox You pressed No. ;Temp
}
Then I would like to be able to look in a different location for the files if they are running in offline mode. Also would it be possible to disable a gosub label this way as well because with every button press I run a label to check for an update on the current version of the script. As since the file they check is only available when they are connected to the server they won't see the new version or the file that has that value in it.
Thanks!
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Another option for #Includes + Extra!

12 Jul 2018, 08:01

1) Create a text (.txt) file with the latest version code. Possibly even a timestamp. Upload to a web server or network location.
2) Create a variable in the script containing this version code.
3) When you add new variables to your script, update the version code in the text file.
4) Each time the script starts, have it compare the text file version code with the version code variable to see if it's a match or not.
5) If not a match, download the new script. If match, do nothing. You can warn users that the script is outdated if they decline the update, etc.
6) If there is no result when checking the web server because of no internet connection (blank variable return, etc.) you can also warn that the script "may" be outdated.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Another option for #Includes + Extra!

12 Jul 2018, 08:54

So what you are saying is something similar to this?

Code: Select all

If !FileExist(M:\AppData.ini)
{
	MsgBox, 20, Error in Connection, There was an error connecting to the server. Would you like to run in offline mode?
		IfMsgBox Yes
			Continue
		IfMsgBox No
			ExitApp
}
Else If FileExist(M:\AppData.ini)
{
	IniRead, Script, M:\AppData.ini, Versions, Script
	If (Script != Version)
	{
		MsgBox, 52, New Version Available!, A new version of the Script is available for download!`r`nWould you like to downlaod it now?
			IfMsgBox Yes
				GoSub Update
			IfMsgBox No
				Continue	;Not needed but included it for looks
	}
}
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Another option for #Includes + Extra!

12 Jul 2018, 09:18

Code: Select all

#SingleInstance, Force

Version := "0.2"

WebVersion := CheckVersion()

If (WebVersion = "") {
	MsgBox, You appear to be offline, or can't reach the update server.`n`nPlease be aware that you may be using an outdated version.
} Else If (WebVersion <> Version) {
	MsgBox, 4, Update, Your script is outdated.`nThe latest version is %WebVersion%, but you are running %Version%.`n`nWould you like to update?
	
	IfMsgBox Yes
		Update()
} Else {
	MsgBox,, Success, You have the latest version! Congratulations!
}

CheckVersion() {
	HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpRequest.Open("GET", "https://pastebin.com/raw/VSemjLGC", true)
	HttpRequest.Send()
	HttpRequest.WaitForResponse()
	return HttpRequest.ResponseText
}

Update() {
	HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpRequest.Open("GET", "https://pastebin.com/raw/5amYKcr0", true)
	HttpRequest.Send()
	HttpRequest.WaitForResponse()
	FileOpen(A_ScriptFullPath, "w").Write(HttpRequest.ResponseText)
	Run, % A_ScriptFullPath
}
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Another option for #Includes + Extra!

12 Jul 2018, 11:03

Ah I see. You are just using pastebin as the example for where the code and version number is located.
What about with external variables? Could the user grab the variable information and be able to access it in a similar way like so?

Code: Select all

#SingleInstance, Force

Version := "0.2"

WebVersion := CheckVersion()

If (WebVersion = "") {
	MsgBox, You appear to be offline, or can't reach the update server.`n`nPlease be aware that you may be using an outdated version.
} Else If (WebVersion <> Version) {
	MsgBox, 4, Update, Your script is outdated.`nThe latest version is %WebVersion%, but you are running %Version%.`n`nWould you like to update?
	
	IfMsgBox Yes
		Update()
} Else {
	MsgBox,, Success, You have the latest version! Congratulations!
	ObtainData()	;<----- This would be where the user could download the data if they needed to
}

CheckVersion() {
	HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpRequest.Open("GET", "https://pastebin.com/raw/VSemjLGC", true)
	HttpRequest.Send()
	HttpRequest.WaitForResponse()
	return HttpRequest.ResponseText
}

Update() {
	HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpRequest.Open("GET", "https://pastebin.com/raw/5amYKcr0", true)
	HttpRequest.Send()
	HttpRequest.WaitForResponse()
	FileOpen(A_ScriptFullPath, "w").Write(HttpRequest.ResponseText)
	Run, % A_ScriptFullPath
}

ObtainData() {
	Lib := A_ScriptFullPath\Lib\DataFile.ahk
	HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	HttpRequest.Open("GET", "https://pastebin.com/raw/*InsertPastbinNumberHere", true)
	HttpRequest.Send()
	HttpRequest.WaitForResponse()
	FileOpen(Lib, "w").Write(HttpRequest.ResponseText)
}
What would be needed to use the variables from that list?
Example of what the variables look like

Code: Select all

a := ["111", "112", "113"]
b := ["211", "212"]
c := ["311", "312", "313"]

Letters := a|b|c
So that way the user can have the updated data of that list when it changes. The main reason why I am curious about external variables is because I don't want a user to have to update every time I update 1 or 2 characters for a variable for the main code, plus it helps to clean up the code by not having an entire list of arrays/objects that require more updating than the main code.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], joefiesta and 281 guests