-
Notifications
You must be signed in to change notification settings - Fork 3
/
BiliConfig.rb
70 lines (51 loc) · 1.3 KB
/
BiliConfig.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
module BiliConfig
require_relative 'BiliFile'
class BiliConf
include BiliFile
$userHome = `echo $HOME`.gsub(/\n/,"")
$configPath = File.join($userHome,".config/BiliGui")
$playlistPath = File.join($configPath,"playlist")
def initialize(name="biligui.conf", path=$configPath)
@name = name
@path = path
unless Dir.exist?(@path) then
Dir.mkdir @path
end
unless Dir.exist?(File.join(@path,"playlist")) then
Dir.mkdir(File.join(@path,"playlist"))
end
@config = File.join(path, name)
@configEntries = {}
unless File.exist?(@config) then
biliTouch(@config)
else
io = File.open(@config, "r")
io.each_line do |line|
line.chomp!
key = line.gsub(/=.*/,"")
if line.index("mpvflags") then
value = line.gsub(/mpvflags=/,"")
elsif line.index("danmaku2assflags") then
value = line.gsub(/danmaku2assflags=/,"")
else
value = line.gsub(/.+=/,"")
end
@configEntries[key] = value
end
io.close
end
end
def put(key, value)
# if Key exists, then we should delete
if @configEntries.key?(key) then
biliMove(@config,"! line.index('" + key + "')")
end
io = File.open(@config, "a")
io.puts("#{key}=#{value}")
io.close
end
def load
return @configEntries
end
end
end