sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Determine OS bit version with ruby

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 3.5k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      Pout
      last edited by

      Is there a way to determine wether the OS where Sketchup is installed on is 32 or 64 bit?
      puts RUBY_PLATFORM gives me i386-mswin32 (which is probably the ruby version since i am working on 64 bit)

      machine_bytes = ['foo'].pack('p').size
      machine_bits = machine_bytes * 8
      Also gives me 32, again probably because ruby/SU is 32 bit

      Is there another way?

      Thx!

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        why do you need that in the first place ?

        for me (OSX), the ruby command 1.size is

        • 4 -> 32 bit SU Ruby
        • 8 -> 64 bit command line Ruby

        on Windows you can check for GetSystemWow64Directory as it is not present on 32bit version

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          # define these methods within your module or class
          
          def is_windows_32bit?
            ( not is_windows_64bit? )
          end
          
          def is_windows_64bit?
            ENV.has_key?('ProgramFiles(x86)')
          end
          

          Note: ENV['PROCESSOR_ARCHITECTURE'] may return a label for a 64bit CPU (like "AMD64",) but still could have a 32bit Windows OS installed.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • P Offline
            Pout
            last edited by

            thx TBD and Dan

            I need it to determine where certain file are located.
            For now i have used a similuar aproach as Dan suggested in which you look if Program Files(x86) 'exists'
            But i think his method is better.

            1 Reply Last reply Reply Quote 0
            • tbdT Offline
              tbd
              last edited by

              as I dont have 64bit Windows to test it up, take in account this as well - "The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit"

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                And some versions of Windows doesn't even have folders names "ProgramFiles" but instead a localized version. Hard coded paths are not reliable, they should be requested from the system.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  The NAMES of the environment vars should NOT change, and their VALUES should be the localized language folder names.

                  So it is much safer to test FIRST if ENV.has_key? THEN use the value of the varible (IF it is present,) to check if the folder exists using:

                  if ENV.has_key?('ProgramFiles(x86)') &&
                     File.exist?(ENV['ProgramFiles(x86)']) &&
                     File.directory?(['ProgramFiles(x86)'])
                    # safe to access directory
                  end
                  

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @unknownuser said:

                    as I dont have 64bit Windows to test it up, take in account this as well - "The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit"

                    %ProgramFiles% = ENV['ProgramFiles']

                    But I told him to use %ProgramFiles(x86)% (which is ENV['ProgramFiles(x86)'],) and should not be present on 32bit systems.

                    On a 64bit system, running a 32bit process (in this case 32bit Sketchup, running 32bit Ruby as a subprocess,) a copy of the enviroment is created for the process. Both the vars ENV['ProgramFiles'] and ENV['ProgramFiles(x86)'] should contain a pathstring that points at the same 32bit localized "program files" directory.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement