10-19-2023, 09:44 PM
(This post was last modified: 10-19-2023, 09:50 PM by DerVVulfman.)
Anyone with a native version of RPGMaker that uses Ruby wanna try some code?
* by native, I mean official version that supports the Win32API
* by Ruby, I mean XP, VX or VXAce
Paste this above 'main' as usual, and run it.
When you execute it, you should receive a series of 'pop-up' notices, one for each drive on your PC. And it should tell you what 'kind' of drive you have for each, whether it is a HDD/SSD, an Optical (CD/DVD), or a flash. The code only suggests one of these three types (floppies not withstanding... assumed HDs). But it should work for original RPGMaker systems that have always supported the Win32API.
... not counting any 'virtual machine for Linux or MacOS'...
PS: Funny... Someone asked at StackOverflow if it were possible to get what kind of drives were on a PC with Ruby without installing/requiring the Win32OLE, and responses said ... Nope!
* by native, I mean official version that supports the Win32API
* by Ruby, I mean XP, VX or VXAce
Paste this above 'main' as usual, and run it.
Code:
#==============================================================================
# ** Registry
#------------------------------------------------------------------------------
# This module handles the registry by using Windows 32 API calls.
#==============================================================================
module Registry
module_function
# The Master HKeys in the Windows Registry
HKEYS = { 'HKEY_CLASSES_ROOT' => 0x80000000,
'HKEY_CURRENT_USER' => 0x80000001,
'HKEY_LOCAL_MACHINE' => 0x80000002,
'HKEY_USERS' => 0x80000003,
'HKEY_CURRENT_CONFIG' => 0x80000005 }
HEX_TRUE = 0x00000001
HEX_FALSE = 0x00000000
RegOpenKeyExA = Win32API.new('advapi32','RegOpenKeyExA', 'LPLLP', 'L')
RegQueryValueExA = Win32API.new('advapi32','RegQueryValueExA','LPLPPP','L')
RegCloseKey = Win32API.new('advapi32','RegCloseKey', 'L', 'L')
#-------------------------------------------------------------------------
# * Read Registry Data Value
# key : The master HKey and pathway to the list of entries
# entry : The entry where the data is stored
#-------------------------------------------------------------------------
def read_data(key, entry)
key.sub!(/(.*?)\\/, '')
return nil if HKEYS[$1].nil?
hkey = HKEYS[$1]
opened, type, size = [0].pack('V'), [0].pack('V'), [0].pack('V')
RegOpenKeyExA.call(hkey, key, 0, 131097, opened)
opened = (opened + [0].pack('V')).unpack('V')[0]
RegQueryValueExA.call(opened, entry, 0, type, 0, size)
data = ' ' * (size + [0].pack('V')).unpack('V')[0]
RegQueryValueExA.call(opened, entry, 0, type, data, size)
RegCloseKey.call(opened)
data = data[0, (size + [0].pack('V')).unpack('V')[0]]
type = (type += [0].pack('V')).unpack('V')[0]
case type
when 1; data.chop
when 2; data.chop.gsub(/%([^%]+)%/) { ENV[$1] || $& }
when 3; data
when 4; (data += [0].pack('V')).unpack('V')[0]
when 5; data.unpack('N')[0]
when 7; data.split(/\0/)
when 11; (data.unpack('VV')[1] << 32) | data[0]
else; nil
end
end
end
#==============================================================================
# ** Drive Detector
#------------------------------------------------------------------------------
# This module merely cycles through all available letters in the alphabet
# to see if you have any matching drives on the PC, and then determines if
# they are hard drives, CDs, or whatnot.
#==============================================================================
module Drive_Detector
#--------------------------------------------------------------------------
# * Methods/Functions Executable From Outside Call
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# * Object Execution
#--------------------------------------------------------------------------
def execute
#
#
# Cycle through all letters and put them in the Drive List array
drive_list = []
for i in 65..90
drive_letter = i.chr + ":"
next unless FileTest.directory?(drive_letter)
drive_list.push(drive_letter)
end
#
# Now, cycle through and test all gathered drives for the PC
drive_list.each {|drive_letter| test_drive(drive_letter) }
#
#
end
#--------------------------------------------------------------------------
# * Test each individual drive letter and find its type
# drive_letter : drive_letter
#--------------------------------------------------------------------------
def test_drive(drive_letter)
#
#
# This is the path to the mounted devices within the registry
# It holds the signatures of all the drives (HDD/SDD/CD/DVD).
key = 'HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices'
#
# Define from which Dos Device Drive we are getting data
# Ex: 'DosDevices\C:'
entry = '\DosDevices\@'.sub(/[@]/, drive_letter)
#
# Obtain the data from the registry with the 'read_data' method
# It is accessing the registry's mounted devices path for the
# specific entry for the defined drive.
drive_data = Registry.read_data(key, entry)
#
# We really just need the first character from the data and have
# it converted into a Hexadecimal character. For testing sake,
# we are having the test string itself UpperCase.
first_char = drive_data[0]
hex_sig_test = sprintf("%.x", first_char).upcase
#
# Now... just test the signature
case hex_sig_test
when '5C'
p "Drive " + drive_letter + " is an Optical Drive (CD/DVD/etc)"
when '5F'
p "Drive " + drive_letter + " is a Flash drive or related"
else
p "Drive " + drive_letter + " is any typical hard drive"
end
#
#
end
end
# This just runs the module
Drive_Detector.execute
When you execute it, you should receive a series of 'pop-up' notices, one for each drive on your PC. And it should tell you what 'kind' of drive you have for each, whether it is a HDD/SSD, an Optical (CD/DVD), or a flash. The code only suggests one of these three types (floppies not withstanding... assumed HDs). But it should work for original RPGMaker systems that have always supported the Win32API.
... not counting any 'virtual machine for Linux or MacOS'...
PS: Funny... Someone asked at StackOverflow if it were possible to get what kind of drives were on a PC with Ruby without installing/requiring the Win32OLE, and responses said ... Nope!