Author Topic: [solved] how to detect x64 system  (Read 1120 times)

Offline K4thos

  • Planewalker
  • *****
  • Posts: 110
[solved] how to detect x64 system
« 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:
Code: [Select]
::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
Code: [Select]
ECHO arch_var=%PROCESSOR_ARCHITECTURE% >EET\arch_var.txtseems 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:
Code: [Select]
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
« Last Edit: July 02, 2015, 11:59:24 AM by K4thos »

Offline Argent77

  • Planewalker
  • *****
  • Posts: 173
Re: [solved] how to detect x64 system
« Reply #1 on: July 05, 2015, 11:49:54 AM »
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 and tile2ee 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.
Code: [Select]
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
« Last Edit: July 05, 2015, 02:07:56 PM by Argent77 »

Offline Sam.

  • The moose man
  • Planewalker
  • *****
  • Posts: 81
  • Gender: Male
    • Classic Adventures Homepage
Re: [solved] how to detect x64 system
« Reply #2 on: July 05, 2015, 01:19:30 PM »
In windows, you can also use the registry to detect the processor architecture (independently of the process architecture that is calling the environmental variable):

Code: [Select]
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE
"Ok, I've just about had my FILL of riddle asking, quest assigning, insult throwing, pun hurling, hostage taking, iron mongering, smart-arsed fools, freaks, and felons that continually test my will, mettle, strength, intelligence, and most of all, patience! If you've got a straight answer ANYWHERE in that bent little head of yours, I want to hear it pretty damn quick or I'm going to take a large blunt object roughly the size of Elminster AND his hat, and stuff it lengthwise into a crevice of your being so seldom seen that even the denizens of the nine hells themselves wouldn't touch it with a twenty-foot rusty halberd! Have I MADE myself perfectly CLEAR?!"
-- <CHARNAME> to Portalbendarwinden

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: