Class: Appsetting
Constant Summary
collapse
- FOLDER =
/(.*)\/(.*)/
- SPECIFIC =
false
- FRIENDLY_NAME =
"ArmA 2 (Any)"
- FAMILY =
TODO: Auto enumurate from model properties? folders: expansion, common, addons files: arma2.exe, arma2server.exe (-.exe for linux), arma2oa.exe, arma2oaserver.exe, addons/chernarus.pbo
Hash.new
- DEFAULT_EXE =
"arma2.exe"
- DEFAULT_EXE_PATH =
""
- DEFAULT_BETA_EXE =
"arma2.exe"
- DEFAULT_BETA_EXE_PATH =
"beta"
- DEFAULT_SERVER_EXE =
"arma2server.exe"
- DEFAULT_SERVER_EXE_PATH =
DEFAULT_EXE_PATH
- DEFAULT_PARAMS =
TODO: Auto beta mod even?
"-showScriptErrors -noSplash -noFilePatching"
- DEFAULT_MODS_PARAM =
"-mod="
- DEFAULT_BETA_MODS =
["beta"]
- REGKEYS =
{"Arma2Oa" => ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA', 'MAIN'], "Arma2" => ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2', 'MAIN']}
- DEFAULT_PATH =
path
Class Method Summary
collapse
Instance Method Summary
collapse
#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?
Class Method Details
65
66
67
68
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 65
def self.label
self::FRIENDLY_NAME
end
|
70
71
72
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 70
def self.short
self.to_s.sub("Appsetting", "")
end
|
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 293
def self.types
return [Arma2Appsetting] if self == Appsetting
t = []
e = self
until e.nil? || [Appsetting, ActiveRecord::Base].include?(e) do
t << e
e = e.superclass
end
t
end
|
Instance Method Details
#allowance(signatures) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 153
def allowance(signatures)
signatures = signatures.map{|e| e.downcase}
allowed, disallowed, garbage = [], [], []
path = self.real_path.gsub("\\", "/")
pbos = Dir[File.join(path, "**", "*.pbo")]
pbos.each do |p|
inter = p.sub("#{path}/", "")
unless inter =~ /\/(addons|dta)\//i || inter =~ /^common\//i || inter =~ /^(addons|dta)\//i
garbage << inter
next
end
if signatures.empty?
allowed << inter
next
end
sigs = Dir["#{p}*.bisign"]
found = false
sigs.each do |s|
sig = s.sub("#{p}.", "").sub(".bisign", "").downcase
if signatures.include?(sig)
found = true
allowed << inter
break
end
end
unless found
disallowed << inter
end
end
[allowed, disallowed, garbage]
end
|
#detect_edition ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 210
def detect_edition
return self.class if self.class::SPECIFIC
return nil unless self.real_path
game = nil
cond = nil
ed = nil
self.class::FAMILY.each_pair do |key, value|
found = false
value[0].each do |e|
case e
when /\/$/
found = File.directory?(File.join(self.real_path, e))
else
case RUBY_PLATFORM
when /-mingw32$/, /-mswin32$/
else
e = e.clone
e.sub!(/\.exe$/, "")
end
found = File.exists?(File.join(self.real_path, e))
end
break if found
end
next unless found
game = key
found = nil
cond = true
ed = nil
value[1].each_pair do |edition, conditions|
ed = edition
conditions.each do |condition|
c = condition.clone
reverse = c.sub!(/^!/, "")
case c
when /\/$/
found = File.directory?(File.join(self.real_path, c))
else
case RUBY_PLATFORM
when /-mingw32$/, /-mswin32$/
else
c = c.clone
c.sub!(/\.exe$/, "")
end
found = File.exists?(File.join(self.real_path, c))
end
cond = reverse ? !found : found
break if cond
end
game = ed if cond
next unless cond
end
end
return nil unless game
Object.const_get("#{game}Appsetting")
end
|
#found_type ⇒ Object
276
277
278
279
280
281
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 276
def found_type
return self.class unless self.real_path
self.detect_edition
end
|
#found_types ⇒ Object
283
284
285
286
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 283
def found_types
t = self.found_type
t ? t.types : []
end
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 74
def get_exe
edition = self.detect_edition
if self.server
if self.beta
edition::DEFAULT_BETA_EXE_PATH.size == 0 ? edition::DEFAULT_SERVER_EXE : "#{edition::DEFAULT_BETA_EXE_PATH}/#{edition::DEFAULT_SERVER_EXE}"
else
edition::DEFAULT_SERVER_EXE_PATH.size == 0 ? edition::DEFAULT_SERVER_EXE : "#{edition::DEFAULT_SERVER_EXE_PATH}/#{edition::DEFAULT_SERVER_EXE}"
end
else
if self.beta
edition::DEFAULT_BETA_EXE_PATH.size == 0 ? edition::DEFAULT_BETA_EXE : "#{edition::DEFAULT_BETA_EXE_PATH}/#{edition::DEFAULT_BETA_EXE}"
else
edition::DEFAULT_EXE_PATH.size == 0 ? edition::DEFAULT_EXE : "#{edition::DEFAULT_EXE_PATH}/#{edition::DEFAULT_EXE}"
end
end
end
|
193
194
195
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 193
def kill!
Six::Appmanager.kill_by_name(process_name, self.real_path)
end
|
57
58
59
60
61
62
63
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 57
def label
ar = []
return self.name unless self.beta || self.server
ar << "Beta" if self.beta
ar << "Server" if self.server
"#{self.name} (#{ar.join(", ")})"
end
|
202
203
204
205
206
207
208
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 202
def logfile
if FileTest.directory? real_logpath
File.join(real_logpath, rpt) if FileTest.exist?(File.join(real_logpath, rpt))
else
nil
end
end
|
#nice_found_type ⇒ Object
288
289
290
291
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 288
def nice_found_type
t = self.found_type
t ? t.label : nil
end
|
#path_by_registry ⇒ Object
91
92
93
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 91
def path_by_registry
self.class::DEFAULT_PATH
end
|
#process_name ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 141
def process_name
if self.exe
if self.exe[FOLDER]
$2
else
self.exe
end
else
self.get_exe
end
end
|
#processes ⇒ Object
185
186
187
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 185
def processes
Six::Appmanager.find_process(process_name, self.real_path)
end
|
#read_logfile ⇒ Object
189
190
191
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 189
def read_logfile
Six::Appmanager.read_logfile logfile unless logfile.nil?
end
|
95
96
97
98
99
100
101
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 95
def real_exe
if self.exe.nil?
self.get_exe
else
self.exe
end
end
|
#real_logpath ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 112
def real_logpath
if self.logpath.nil?
case RUBY_PLATFORM
when /-mingw32$/, /-mswin32$/
"#{File.join(ENV['USERPROFILE'], 'appdata', 'local', 'arma 2')}"
else
nil
end
else
self.logpath
end
end
|
#real_modpath ⇒ Object
133
134
135
136
137
138
139
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 133
def real_modpath
if self.modpath.nil?
self.real_path
else
self.modpath
end
end
|
#real_params ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 103
def real_params
if self.params.nil?
edition = self.detect_edition
edition ? edition::DEFAULT_PARAMS : nil
else
self.params
end
end
|
#real_path ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 125
def real_path
if self.path.nil?
self.path_by_registry
else
self.path
end
end
|
197
198
199
200
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 197
def rpt
process_name[/(.*)\./]
"#{$1}.rpt"
end
|
#to_updater_yml ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/six-updater-web/app/models/appsetting.rb', line 41
def to_updater_yml
hash = Hash.new
attribute_names.each do |at|
i = at.to_s
i = "app_#{i}"
value = eval(at)
hash[i.to_sym] = value unless value.nil? || value.to_s.size == 0
end
hash[:app_path] = self.real_path unless hash[:app_path]
hash[:app_exe] = self.real_exe unless hash[:app_exe]
if self.beta
hash[:mods] = self.found_type::DEFAULT_BETA_MODS.map{|e| e.gsub("/", "\\")}.join(";")
end
hash
end
|