-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
40 lines (38 loc) · 1.32 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
DEFAULT_CONFIG = {
'hash_server' => 'http://173.13.157.10:81/hashes.txt',
'max_files_removed_without_warning' => 50,
's3' => {
'id_key' => 'id key goes here',
'secret_key' => 'secret key goes here',
'bucket' => 'ns2build'
},
'local_directory' => 'E:\\Natural Selection 2',
'max_concurrency' => 48,
'max_speed' => -1
}
def load_config
contents = File.read('config.yml')
if contents =~ /^local_directory:\s+".+"\s*$/
log :yellow, 'Rewriting config.yml file after correcting quotation marks (do not use double quotes around your path)'
contents.gsub!(/^(local_directory:\s+)"(.+)"\s*$/) { "#$1'#$2'" }
open('config.yml', 'w') {|f| f << contents }
end
if contents =~ /^hash_server:\s+http:\/\/67\.164\.96\.34:81\/hashes\.txt\s*$/
log :yellow, 'Rewriting config.yml file after updating outdated hashes server address'
contents.gsub!(/http:\/\/67\.164\.96\.34:81\/hashes\.txt\s*$/, DEFAULT_CONFIG.hash_server)
open('config.yml', 'w') {|f| f << contents }
end
YAML.load(contents)
rescue Exception => ex
fail "Unable to parse config file: #{ex.message}"
end
def initialize_config
$config = DEFAULT_CONFIG
if File.exists?('config.yml')
$config.rmerge!(load_config)
else
open('config.yml', 'w') do |file|
YAML.dump(DEFAULT_CONFIG, file)
end
end
end