Pocket Plane Group
Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: K4thos on July 02, 2015, 10:09:35 AM
-
I'm trying to assign different versions of tools based on operating system, either 32 or 64bits. Things that normally works within windows like:
::32/64Bit Switch
ECHO %PROCESSOR_ARCHITECTURE%|FINDSTR AMD64>NUL && SET arch_var=AMD64 || SET arch_var=x86
ECHO %arch_var%>arch_var.txt
or simply
ECHO arch_var=%PROCESSOR_ARCHITECTURE% >EET\arch_var.txt
seems to return x86 instead of AMD64 when used in weidu with AT_NOW command. I could look for "Program Files (x86)" directory but it's not good enough evidence of anything as bad software can easily create this directory on a 32-bit machine.
Thanks in advance.
edit: I think this code is reliable and works within 32-bit weidu. %PROCESSOR_ARCHITEW6432% variable works correctly. Only %PROCESSOR_ARCHITECTURE% can't be used within 32-bit environment. Leaving the code here in case someone needs it too:
OUTER_SPRINT arch_var ~~
ACTION_IF ~%WEIDU_OS%~ STRING_EQUAL_CASE ~win32~ BEGIN
OUTER_SPRINT os_slash ~\~
OUTER_SPRINT exe ~.exe~
<<<<<<<< .../arch_var.bat
::32/64Bit Switch
ECHO %PROCESSOR_ARCHITEW6432%|FINDSTR AMD64>NUL && SET arch_var=AMD64 || SET arch_var=x86
ECHO %arch_var%>EET\arch_var.txt
>>>>>>>>
COPY ~.../arch_var.bat~ ~EET/arch_var.bat~
AT_NOW ~CALL EET\arch_var.bat~
COPY - ~EET/arch_var.txt~ ~EET~
REPLACE_EVALUATE CASE_INSENSITIVE ~AMD64~ BEGIN
SPRINT arch_var ~x86_64\~
PATCH_PRINT ~arch_var = %arch_var%~
END ~~
END ELSE BEGIN //osx and linux
OUTER_SPRINT os_slash ~/~
OUTER_SPRINT exe ~~
END
ACTION_FOR_EACH tool IN tile2ee tileconv BEGIN
OUTER_SPRINT EVAL ~%tool%~ ~EET%os_slash%bin%os_slash%%WEIDU_OS%%os_slash%%arch_var%%tool%%exe%~
PRINT ~%tool% path assigned to EET%os_slash%bin%os_slash%%WEIDU_OS%%os_slash%%arch_var%%tool%%exe%~
END
-
To complement K4thos' code snippets I have put together a WeiDU function that may help modders when working with external tools for multiple systems and architectures. I'll post it here for demonstration purposes. I'm also planning to add it along with more functions into future releases of my tileconv (http://www.shsforums.net/topic/57588-tileconv-a-mostis-compressor/) and tile2ee (http://www.shsforums.net/topic/58219-tile2ee-a-mos-and-tis-converter/) tools.
GET_SYSTEM_ARCH: Attempts to detect the system architecture Weidu is currently running on (in contrast to WEIDU_ARCH, which only detects the architecture of the WeiDU binary). Returns either "amd64" for 64-bit environments or "x86" for true 32-bit environments. Falls back to %WEIDU_ARCH% in case of problems.
DEFINE_ACTION_FUNCTION GET_SYSTEM_ARCH
RET
SYSTEM_ARCH
BEGIN
ACTION_MATCH "%WEIDU_OS%" WITH
win32
BEGIN
<<<<<<<< .../a7#inlined/a7arch.bat
@echo off
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto AMD64
if /i "%PROCESSOR_ARCHITEW6432%"=="AMD64" goto AMD64
SET a7arch=x86
goto OUT
:AMD64
SET a7arch=amd64
:OUT
echo %a7arch%>override/a7arch.txt
>>>>>>>>
COPY ~.../a7#inlined/a7arch.bat~ ~override/a7arch.bat~
AT_NOW ~call override\a7arch.bat~
DELETE + ~override/a7arch.bat~
COPY - ~override/a7arch.txt~ ~override~
REPLACE_EVALUATE CASE_INSENSITIVE ~amd64~ BEGIN
SPRINT SYSTEM_ARCH ~amd64~
END ~~
DELETE + ~override/a7arch.txt~
END
osx unix
BEGIN
OUTER_SPRINT SYSTEM_ARCH ~x86~
AT_NOW ~echo $(uname -m) >override/a7arch.txt~
COPY - ~override/a7arch.txt~ ~override~
REPLACE_EVALUATE CASE_INSENSITIVE ~x86_64~ BEGIN
SPRINT SYSTEM_ARCH ~amd64~
END ~~
DELETE + ~override/a7arch.txt~
END
DEFAULT
END
ACTION_IF (~%SYSTEM_ARCH%~ STRING_EQUAL ~~) BEGIN
OUTER_SPRINT SYSTEM_ARCH ~%WEIDU_ARCH%~
END
END
// Patch version of GET_SYSTEM_ARCH.
DEFINE_PATCH_FUNCTION GET_SYSTEM_ARCH
RET
SYSTEM_ARCH
BEGIN
INNER_PATCH ~foo~ BEGIN
LPF GET_SYSTEM_ARCH RET SYSTEM_ARCH END
END
END
-
In windows, you can also use the registry to detect the processor architecture (independently of the process architecture that is calling the environmental variable):
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE