-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_INI.rb
74 lines (69 loc) · 2.35 KB
/
RS_INI.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#==============================================================================
# ** INI
# Author : biud436
# Date : 2015.01.30
# Version : 1.0
# Usage :
# INI
# write_string(app,key,str,file_name)
# read_string(app_name,key_name,file_name)
#
# Hash
# to_ini([file_name[,app_name]])
#
# Example
# Font.default_name = INI.read_string("Font","Name","Font.ini")
#
#==============================================================================
# ** Terms of Use
#==============================================================================
# Free for commercial and non-commercial use
#==============================================================================
$imported = {} if $imported.nil?
$imported["RS_INI"] = true
module Unicode
MultiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar','llpipi','i')
WideCharToMultiByte = Win32API.new('Kernel32','WideCharToMultiByte','llpipipp','i')
UTF_8 = 65001
def unicode!
buf = "\0" * (self.size * 2 + 1)
MultiByteToWideChar.call(UTF_8, 0, self, -1, buf, buf.size)
buf
end
def unicode_s
buf = "\0" * (self.size * 2 + 1)
WideCharToMultiByte.call(UTF_8, 0, self, -1, buf, buf.size, nil, nil)
buf.delete("\0")
end
end
class String
include Unicode
end
module INI
WritePrivateProfileStringW = Win32API.new('Kernel32','WritePrivateProfileStringW','pppp','s')
GetPrivateProfileStringW = Win32API.new('Kernel32','GetPrivateProfileStringW','ppppip','s')
extend self
def write_string(app,key,str,file_name)
path = ".\\" + file_name
(param = [app,key.to_s,str.to_s,path]).collect! {|i| i.unicode!}
success = WritePrivateProfileStringW.call(*param)
end
def read_string(app_name,key_name,file_name)
buf = "\0" * 256
path = ".\\" + file_name
(param = [app_name,key_name,path]).collect! {|x| x.unicode!}
GetPrivateProfileStringW.call(*param[0..1],0,buf,256,param[2])
buf.unicode_s.unpack('U*').pack('U*')
end
end
class Hash
def to_ini(file_name="Default.ini",app_name="Default")
self.each { |k, v| INI.write_string(app_name,k.to_s.dup,v.to_s.dup,file_name) }
end
end