Throw a warning if running 2.0 ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Throw a warning if running 2.0 ?

29 Mar 2024, 10:35

A group of about 40 people use an autohotkey 1.1 script that I've got up on a Discord forum. It's about 10,000 lines long. I love to migrate it to 2.0, but I don't even know where to start in terms of that as it seems quite a big task!
They said "I got an error message reading "Error: PCRE execution error."" and it turns out they had installed 2.0

So, is there a way that my 1.1 script can throw an error if is attempted to be run under 2.0 so that I can show and information page telling people to uninstall 2.0 and install 1.1 ?
User avatar
gregster
Posts: 9224
Joined: 30 Sep 2013, 06:48

Re: Throw a warning if running 2.0 ?  Topic is solved

29 Mar 2024, 11:24

Afaik, this specific error message was caused by a bug in the v2 Launcher (including v2.0.11) - and should be fixed in the newest version
(lexikos stated: "v2.0.12 fixes this, and/or at least handles PCRE execution errors better.")
Otherwise, the AHK v2 Launcher already takes care of choosing or suggesting the correct AHK version, or it shows a dialog to let the user choose.

But in your case, I would simply put #Requires AutoHotkey v1.1 (or even more specific) at the top of your script. That should avoid the bug.
Anyway, there is no need to uninstall v2 in order to run a v1 script.
https://www.autohotkey.com/docs/v2/Program.htm#launcher wrote:The launcher enables the use of v1 and v2 scripts on one system, with a single filename extension, without necessarily giving preference to one version or requiring different methods of launching scripts. It does this by checking the script for clues about which version it requires, and then locating an appropriate exe to run the script.

If the script contains the #Requires directive, the launcher looks for an exe that satisfies the requirement. Otherwise, the launcher optionally checks syntax.
[...]

In any case where detection fails, by default a menu is shown for the user to select a version. This default can be changed to instead launch either v1 or v2.
[...]
Note: Declaring the required version with #Requires at the top of the main file eliminates any ambiguity.
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: Throw a warning if running 2.0 ?

31 Mar 2024, 06:36

That all sounds very well thought out, though just on managing this, when I install v2.0, I presume that it does not also create the latest v1.1 executable (or am I wrong?), so I should make a point of downloading both executables and putting them in the same folder (that should be on the path) and then it will intelligently run with the most appropriate version of AutoHotkey (I'm curious how it hands that off, as it has to start with one executable, presumably v2.0, and then it says "ah, wait, this looks like v1.1, so I'm going to run it using the v1.1 .exe instead, if I can find that on the path...")?
User avatar
gregster
Posts: 9224
Joined: 30 Sep 2013, 06:48

Re: Throw a warning if running 2.0 ?

31 Mar 2024, 08:35

No, not in the same subdirectory - I guess that would mess things up. just let the installer do its thing.
The folder structure seems to depend on which version was installed first:
https://www.autohotkey.com/docs/v2/Program.htm#install_v1 wrote:Installing with v1

There are two methods of installing v1 and v2 together:

1. Install v1 first, and then v2. In that case, the v1 files are left in the root of the installation directory, to avoid breaking any external tools or shortcuts that rely on their current path.
2. Install v1 as an additional version. Running a v1.1.34.03 or later installer gives this option. Alternatively, use the /install switch described below. Each version installs into its own subdirectory.

Running a v1.1.34.02 or older installer (or a custom install with v1.1.34.03 or newer) will overwrite some of the values set in the registry by the v2 installer, such as the version number, uninstaller entry and parts of the file type registration. It will also register the v1 uninstaller, which is not capable of correctly uninstalling both versions. To re-register v2, re-run any v2 installer or run UX\install.ahk using AutoHotkey32.exe or AutoHotkey64.exe.
I can't say that I have much experience with installing both at the same time. On one computer, I had v1 installed first and later added v2 (see case 1 above). On another computer, I first installed v2, and then added v1 (case 2). It both works, although the folder structure is different (but not arbitrary).

lexikos also said in the topic already quoted above:
One important feature of the launcher is that it can often identify when the user is trying to run a script with a version of AutoHotkey that is not installed. In such a case, it can usually install the appropriate version automatically (after confirmation by the user).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Bing [Bot] and 147 guests