09-08-2019, 06:33 PM
(This post was last modified: 09-08-2019, 06:34 PM by DerVVulfman.)
Well... guess I'd have to provide an answer.
For those thinking that RUBY_PLATFORM would do the trick, nope. It falters when Java is in use, returning 'Java' even if the PC itself was Windows, Mac or Linux. So I had to dig further.
The main consensus is the use of RbConfig. Unfortunately, RPGMaker XP (or any) do not come supplied with it, and there are various versions as there are various versions of Ruby. But after examining various versions of RbConfig from versions 1.8.5 through to more modern 2., I determined that I had need of only a handful of lines.
Below is a scriptette that can determine what Operating System your PC is using, returning something like :windows, :linux, :unix or :macosx.
You can replace the returned values (like :windows) with numeric values if it helps
This will prove useful if one wishes to permit Win32DLL applications to run in their game for Windows Users, and perhaps have a workaround for those without.
For those thinking that RUBY_PLATFORM would do the trick, nope. It falters when Java is in use, returning 'Java' even if the PC itself was Windows, Mac or Linux. So I had to dig further.
The main consensus is the use of RbConfig. Unfortunately, RPGMaker XP (or any) do not come supplied with it, and there are various versions as there are various versions of Ruby. But after examining various versions of RbConfig from versions 1.8.5 through to more modern 2., I determined that I had need of only a handful of lines.
Below is a scriptette that can determine what Operating System your PC is using, returning something like :windows, :linux, :unix or :macosx.
Code:
#==============================================================================
# ** OS Detection via Ruby
#------------------------------------------------------------------------------
# by DerVVulfman (09/08/2019) MM/DD/YYYY
# based on the work of Thomas Enebo (11/27/2012) MM/DD/YYYY
#==============================================================================
#==============================================================================
# ** RbConfig
#------------------------------------------------------------------------------
# This module holds Configuration settings for Ruby Operations.
# THIS IS NOT COMPLETE, BUT A BAREBONES EXERPT. VARIOUS RBCONFIGS EXIST
# BASED ON VERSION NUMBERS
#==============================================================================
module RbConfig
CONFIG = {}
CONFIG["host_os"] = "mingw32msvc"
end
#==============================================================================
# ** Operating System Detection
#------------------------------------------------------------------------------
# This module actively uses the RbConfig system to detect what operating
# system is in use. The below code is sound, the RbConfig used above is
# merely a snippet of the whole.
#
# Refer to OS_Detect::execute to perform the operation
#==============================================================================
module OS_Detect
#--------------------------------------------------------------------------
# * Methods/Functions Executable From Outside Call
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# * Object Execution
#--------------------------------------------------------------------------
def execute
@os ||= (
host_os = RbConfig::CONFIG['host_os']
case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
:windows
when /darwin|mac os/
:macosx
when /linux/
:linux
when /solaris|bsd/
:unix
else
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
end
)
end
end
# THIS prints the version
p OS_Detect::execute
You can replace the returned values (like :windows) with numeric values if it helps
This will prove useful if one wishes to permit Win32DLL applications to run in their game for Windows Users, and perhaps have a workaround for those without.