Hello. I want to make my portable app change ProgramExecutable based on the version of Windows. I tried to this in Custom.nsh
:
${SegmentFile}
${SegmentInit}
${If} ${AtLeastWin110}
${SetEnvironmentVariablesPath} FullAppDir $AppDirectory\PolyMC
${Else}
${SetEnvironmentVariablesPath} FullAppDir $AppDirectory\Legacy
${EndIf}
!macroend
But it seems I can't use the environment variable in ProgramExecutable. Any idea how I'd accomplish this? Thanks.
At the moment the AtLeastWinX variables don't work for Windows 10 and 11 in the PA.c Launcher, so you'll need to use custom code. For an example of this, check out the custom code in the current calibre Portable launcher. Here's a simplified version that should work for your use case:
Sometimes, the impossible can become possible, if you're awesome!
Hello. Thanks for the answer. Unfortunately, it would seem that I still can't use the FullAppDir variable in
ProgramExecutable
. It just tells me "App\%FullAppDir%\PolyMC.exe could not be found". So, environment variables don't seem to be expanded inProgramExecutable
. I get the same result if I try to put in a different variable, like%AppData%
(for testing). Looking at calibre's custom code, it looks like it's renaming the includedCalibre64
andCalibre32
directories toCalibre
and launching from theCalibre
directory. I did figure out a better solution, however. I can useStrCpy
to change$ProgramExecutable
in my code. However, if I change it inInit
, it's read from config afterwards inCore.nsh
. I had to change the variable inPre
. It's worth noting, however, that normallyProgramExecutable
is checked to make sure it exists duringInit
, so I just set the config to the Win10 version of my application and changed it to Legacy if needed.Ah right. I forgot you were using it for ProgamExecutable. That variable doesn't support environment variables within the PA.c Launcher at present. Your alternative would be to move either the EXE or the directories the way I do in calibre. Here's an example with PolyMC always being the directory and moving the legacy vs modern to it depending on OS:
Sometimes, the impossible can become possible, if you're awesome!
As I mentioned above, a better alternative is to change $ProgramExecutable in SegmentPre:
(For some reason, < and " are escaped in that code block when using Markdown)
Edit: If you do it in Init instead of Pre, it's read from the INI afterwards. I have the "Modern" version defined in the INI, because PA Launcher also checks to make sure the path exists during Init.
Ah, right, sorry about that. Yes, this solution should work.
Sometimes, the impossible can become possible, if you're awesome!