-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.rb
79 lines (62 loc) · 1.52 KB
/
config.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
75
76
77
78
79
#!/env/bin/ruby
# encoding: utf-8
require 'json'
require 'nkf'
class ConfigManager
@@Default_setting_path = File.dirname(__FILE__) + "/conf/preferences-default.json"
@@User_setting_path = File.dirname(__FILE__) + "/preferences-user.json"
def self.User_setting_path
@@User_setting_path
end
def user_conf_exist?
begin
f = open @@User_setting_path
f.close
rescue
return false
end
return true
end
def make_user_conf
fr = open @@Default_setting_path, "rb"
default_setting = fr.read
fr.close
fw = open @@User_setting_path, "wb"
fw.write default_setting
fw.close
end
def format_user_conf
fr = open @@User_setting_path, "rb"
user_setting = fr.read
fr.close
# remove BOM & add CR
# refer to: http://blog.sina.com.cn/s/blog_63eb3eec01015yk1.html
user_setting = NKF.nkf("-w -c", user_setting)
fw = open @@User_setting_path, "wb"
fw.write user_setting
fw.close
end
def get_default_json
fr = open @@Default_setting_path, "rb"
setting = JSON.parse fr.read
fr.close
return setting
end
def get_user_json
fr = open @@User_setting_path, "rb"
setting = JSON.parse fr.read
fr.close
return setting
end
def get_settings item
default_setting = get_default_json
user_setting = get_user_json
return user_setting[item] != nil ? user_setting[item] : default_setting[item]
end
def refresh
load File.dirname(__FILE__) + '/comm.rb'
make_size
make_GUI
$tk_root.update
end
end