six-updater-web 0.22.3 → 0.22.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'six-updater-web'
10
- s.version = '0.22.3'
10
+ s.version = '0.22.4'
11
11
  s.has_rdoc = false
12
12
  #s.extra_rdoc_files = ['README', 'LICENSE']
13
13
  s.summary = 'Your summary here'
@@ -229,13 +229,13 @@ class MainController < ApplicationController
229
229
  if setting
230
230
  setting.beta = @beta unless @beta.nil?
231
231
  setting.server = @server_bool unless @server_bool.nil?
232
- @msg << "Override settings profile: <a href='/appsettings/edit/#{setting.id}' title='#{setting.real_exe} #{setting.real_params} (#{setting.real_path})'>#{setting.label}</a>"
232
+ @msg << "Override settings profile: <a href='/appsettings/edit/#{setting.id}' title='#{setting.class.short}: #{setting.real_exe} #{setting.real_params} (#{setting.real_path})'>#{setting.label}</a>"
233
233
  else
234
234
  if preset.appsetting
235
235
  setting = preset.appsetting
236
236
  setting.beta = @beta unless @beta.nil?
237
237
  setting.server = @server_bool unless @server_bool.nil?
238
- @msg << "Preset settings profile: <a href='/appsettings/edit/#{setting.id}' title='#{setting.real_exe} #{setting.real_params} (#{setting.real_path})'>#{setting.label}</a>"
238
+ @msg << "Preset settings profile: <a href='/appsettings/edit/#{setting.id}' title='#{setting.class.short}: #{setting.real_exe} #{setting.real_params} (#{setting.real_path})'>#{setting.label}</a>"
239
239
  end
240
240
  end
241
241
 
@@ -248,13 +248,7 @@ class MainController < ApplicationController
248
248
  end
249
249
  end
250
250
 
251
- if setting
252
- if setting.type.nil? || setting.type.empty? || setting.type == "Appsetting"
253
- setting.type = "Arma2Appsetting"
254
- setting.save
255
- setting = Appsetting.find(setting.id)
256
- end
257
- else
251
+ unless setting
258
252
  setting = Arma2Appsetting.new(:beta => @beta, :server => @server_bool)
259
253
  end
260
254
 
@@ -8,13 +8,6 @@ class Appsetting < ActiveRecord::Base
8
8
  SPECIFIC = false
9
9
  FRIENDLY_NAME = "ArmA 2 (Any)"
10
10
 
11
- # TODO: Auto enumurate from model properties?
12
- # folders: expansion, common, addons
13
- # files: arma2.exe, arma2server.exe (-.exe for linux), arma2oa.exe, arma2oaserver.exe, addons/chernarus.pbo
14
- FAMILY = Hash.new
15
- FAMILY["Arma2"] = [["arma2.exe", "arma2server.exe"], {"Arma2St" => []}]
16
- FAMILY["Arma2Oa"] = [["arma2oa.exe", "arma2oaserver.exe"], {"Arma2OaCo" => ["addons/"], "Arma2OaSt" => ["!addons/"]}]
17
-
18
11
  DEFAULT_EXE = "arma2.exe"
19
12
  DEFAULT_EXE_PATH = ""
20
13
  DEFAULT_BETA_EXE = "arma2.exe"
@@ -27,16 +20,15 @@ class Appsetting < ActiveRecord::Base
27
20
  DEFAULT_MODS_PARAM = "-mod=" # TODO
28
21
  DEFAULT_BETA_MODS = ["beta"]
29
22
 
23
+ # TODO: Auto enumurate from model properties?
24
+ # folders: expansion, common, addons
25
+ # files: arma2.exe, arma2server.exe (-.exe for linux), arma2oa.exe, arma2oaserver.exe, addons/chernarus.pbo
26
+ FAMILY = Hash.new
27
+ FAMILY["Arma2"] = [[DEFAULT_EXE, DEFAULT_SERVER_EXE, "#{DEFAULT_BETA_EXE_PATH}/#{DEFAULT_BETA_EXE}"], {"Arma2St" => []}]
28
+ FAMILY["Arma2Oa"] = [[Arma2OaAppsetting::DEFAULT_EXE, Arma2OaAppsetting::DEFAULT_SERVER_EXE, "#{Arma2OaAppsetting::DEFAULT_BETA_EXE_PATH}/#{Arma2OaAppsetting::DEFAULT_BETA_EXE}"], {"Arma2OaCo" => ["addons/"], "Arma2OaSt" => ["!addons/"]}]
29
+
30
30
  # TODO: Windows-only
31
31
  REGKEYS = {"Arma2Oa" => ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA', 'MAIN'], "Arma2" => ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2', 'MAIN']}
32
- path = nil
33
-
34
- self::REGKEYS.each_pair do |k, v|
35
- path = begin; Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, v[0])[v[1]]; rescue; nil; end
36
- break if path
37
- end
38
- DEFAULT_PATH = path
39
-
40
32
 
41
33
  def to_updater_yml
42
34
  hash = Hash.new
@@ -49,7 +41,7 @@ class Appsetting < ActiveRecord::Base
49
41
  hash[:app_path] = self.real_path unless hash[:app_path]
50
42
  hash[:app_exe] = self.real_exe unless hash[:app_exe]
51
43
  if self.beta
52
- hash[:mods] = self.found_type::DEFAULT_BETA_MODS.map{|e| e.gsub("/", "\\")}.join(";")
44
+ hash[:mods] = self.edition::DEFAULT_BETA_MODS.map{|e| e.gsub("/", "\\")}.join(";")
53
45
  end
54
46
  hash
55
47
  end
@@ -71,170 +63,120 @@ class Appsetting < ActiveRecord::Base
71
63
  self.to_s.sub("Appsetting", "")
72
64
  end
73
65
 
74
- def get_exe
75
- edition = self.class::SPECIFIC ? self.class : self.detect_edition
76
- return nil unless edition
77
- if self.server
78
- if self.beta
79
- edition::DEFAULT_BETA_EXE_PATH.size == 0 ? edition::DEFAULT_SERVER_EXE : "#{edition::DEFAULT_BETA_EXE_PATH}/#{edition::DEFAULT_SERVER_EXE}"
80
- else
81
- edition::DEFAULT_SERVER_EXE_PATH.size == 0 ? edition::DEFAULT_SERVER_EXE : "#{edition::DEFAULT_SERVER_EXE_PATH}/#{edition::DEFAULT_SERVER_EXE}"
82
- end
83
- else
84
- if self.beta
85
- edition::DEFAULT_BETA_EXE_PATH.size == 0 ? edition::DEFAULT_BETA_EXE : "#{edition::DEFAULT_BETA_EXE_PATH}/#{edition::DEFAULT_BETA_EXE}"
86
- else
87
- edition::DEFAULT_EXE_PATH.size == 0 ? edition::DEFAULT_EXE : "#{edition::DEFAULT_EXE_PATH}/#{edition::DEFAULT_EXE}"
88
- end
66
+ def self.types
67
+ return [Arma2Appsetting] if self == Appsetting
68
+ t, e = [], self
69
+ until e.nil? || [Appsetting, ActiveRecord::Base].include?(e) do
70
+ t << e
71
+ e = e.superclass
89
72
  end
73
+ t
90
74
  end
91
75
 
92
- def path_by_registry
93
- self.class::DEFAULT_PATH
76
+ def self.default_path
77
+ return @mpath unless @mpath.nil?
78
+ @mpath = nil
79
+ self::REGKEYS.each_pair do |k, v|
80
+ @mpath = begin; Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, v[0])[v[1]]; rescue; nil; end
81
+ break if @mpath
82
+ end
83
+ @mpath
94
84
  end
95
85
 
96
- def real_exe
97
- if self.exe.nil?
98
- self.get_exe
99
- else
100
- self.exe
101
- end
86
+ def edition(force = true)
87
+ ed = self.detect_edition
88
+ ed = self.class if ed.nil? && force
89
+ ed
102
90
  end
103
91
 
104
- def real_params
105
- if self.params.nil?
106
- edition = self.detect_edition
107
- edition ? edition::DEFAULT_PARAMS : nil
108
- else
109
- self.params
110
- end
92
+ def nice_edition
93
+ t = self.edition(false)
94
+ t ? t.label : "ERROR: None detected"
111
95
  end
112
96
 
113
- def real_logpath
114
- if self.logpath.nil?
115
- case RUBY_PLATFORM
116
- when /-mingw32$/, /-mswin32$/
117
- "#{File.join(ENV['USERPROFILE'], 'appdata', 'local', 'arma 2')}"
118
- else
119
- nil
120
- end
121
- else
122
- self.logpath
123
- end
97
+ def found_types
98
+ t = self.edition(false)
99
+ t ? t.types : []
124
100
  end
125
101
 
126
- def real_path
127
- if self.path.nil?
128
- self.path_by_registry
129
- else
130
- self.path
131
- end
102
+ # TODO: Linux auto cut of '.exe' ?
103
+ def self.beta_server_exe()
104
+ self::DEFAULT_BETA_EXE_PATH.empty? ? self::DEFAULT_SERVER_EXE : "#{self::DEFAULT_BETA_EXE_PATH}/#{self::DEFAULT_SERVER_EXE}"
132
105
  end
133
106
 
134
- def real_modpath
135
- if self.modpath.nil?
136
- self.real_path
137
- else
138
- self.modpath
139
- end
107
+ def self.server_exe()
108
+ self::DEFAULT_SERVER_EXE_PATH.empty? ? self::DEFAULT_SERVER_EXE : "#{self::DEFAULT_SERVER_EXE_PATH}/#{self::DEFAULT_SERVER_EXE}"
140
109
  end
141
110
 
142
- def process_name
143
- if self.exe
144
- if self.exe[FOLDER]
145
- $2
146
- else
147
- self.exe
148
- end
149
- else
150
- self.get_exe
151
- end
111
+ def self.beta_exe()
112
+ self::DEFAULT_BETA_EXE_PATH.empty? ? self::DEFAULT_BETA_EXE : "#{self::DEFAULT_BETA_EXE_PATH}/#{self::DEFAULT_BETA_EXE}"
152
113
  end
153
114
 
154
- def allowance(signatures)
155
- signatures = signatures.map{|e| e.downcase}
156
- allowed, disallowed, garbage = [], [], []
157
- path = self.real_path.gsub("\\", "/")
158
- pbos = Dir[File.join(path, "**", "*.pbo")]
159
- pbos.each do |p|
160
- inter = p.sub("#{path}/", "")
161
- unless inter =~ /\/(addons|dta)\//i || inter =~ /^common\//i || inter =~ /^(addons|dta)\//i
162
- garbage << inter
163
- next
164
- end
165
- if signatures.empty?
166
- allowed << inter
167
- next
168
- end
169
- sigs = Dir["#{p}*.bisign"]
170
- found = false
171
- sigs.each do |s|
172
- sig = s.sub("#{p}.", "").sub(".bisign", "").downcase
173
- if signatures.include?(sig)
174
- found = true
175
- allowed << inter
176
- break
177
- end
178
- end
179
- unless found
180
- disallowed << inter
181
- end
115
+ def self.normal_exe()
116
+ self::DEFAULT_EXE_PATH.empty? ? self::DEFAULT_EXE : "#{self::DEFAULT_EXE_PATH}/#{self::DEFAULT_EXE}"
117
+ end
118
+
119
+ def any_exe?
120
+ ed = self.class::SPECIFIC ? self.class : self.edition
121
+ (!self.exe.nil? && File.exists?(File.join(self.real_path, self.exe))) || File.exists?(File.join(self.real_path, ed.normal_exe)) || File.exists?(File.join(self.real_path, ed.server_exe)) || File.exists?(File.join(self.real_path, ed.beta_exe)) || File.exists?(File.join(self.real_path, ed.beta_server_exe))
122
+ end
123
+
124
+ def real_exe
125
+ return self.exe unless self.exe.nil?
126
+ return nil unless self.edition()
127
+ if self.server
128
+ self.beta ? self.edition.beta_server_exe : self.edition.server_exe
129
+ else
130
+ self.beta ? self.edition.beta_exe : self.edition.normal_exe
182
131
  end
183
- [allowed, disallowed, garbage]
184
132
  end
185
133
 
186
- def processes
187
- Six::Appmanager.find_process(process_name, self.real_path)
134
+ def real_path
135
+ self.path.nil? ? self.class.default_path : self.path
188
136
  end
189
137
 
190
- def read_logfile
191
- Six::Appmanager.read_logfile logfile unless logfile.nil?
138
+ def default_params
139
+ self.edition.nil? ? nil : self.edition::DEFAULT_PARAMS
192
140
  end
193
141
 
194
- def kill!
195
- Six::Appmanager.kill_by_name(process_name, self.real_path)
142
+ def real_params
143
+ self.params.nil? ? self.default_params : self.params
196
144
  end
197
145
 
198
- def rpt
199
- process_name[/(.*)\./]
200
- "#{$1}.rpt"
146
+ def real_modpath
147
+ self.modpath.nil? ? self.real_path : self.modpath
201
148
  end
202
149
 
203
- def logfile
204
- if FileTest.directory? real_logpath
205
- File.join(real_logpath, rpt) if FileTest.exist?(File.join(real_logpath, rpt))
150
+ def real_logpath
151
+ if self.logpath.nil?
152
+ case RUBY_PLATFORM
153
+ when /-mingw32$/, /-mswin32$/
154
+ "#{File.join(ENV['USERPROFILE'], 'appdata', 'local', 'arma 2')}"
155
+ else
156
+ nil
157
+ end
206
158
  else
207
- nil
159
+ self.logpath
208
160
  end
209
161
  end
210
162
 
211
163
  def detect_edition
212
164
  # TODO: Read the appsetting.exe to figure out an edition, as a static setting by the user?
213
-
165
+ return @det_ed unless @det_ed.nil?
214
166
  return nil if self.real_path.nil?
215
167
  return nil unless File.directory?(self.real_path)
216
168
  if self.class::SPECIFIC
217
- if File.exists?(File.join(self.real_path, self.real_exe))
218
- return self.class
219
- elsif File.exists?(File.join(self.real_path, self.class::DEFAULT_EXE)) || File.exists?(File.join(self.real_path, self.class::DEFAULT_SERVER_EXE))
220
- return self.class
221
- else
222
- return nil
223
- end
169
+ return self.any_exe? ? self.class : nil
224
170
  end
225
171
  game = nil
226
- cond = nil
227
- ed = nil
228
172
  self.class::FAMILY.each_pair do |key, value|
229
173
  found = false
230
174
  # Find game
231
175
  value[0].each do |e|
232
176
  case e
233
- when /\/$/
234
- # folder
177
+ when /\/$/ # folder
235
178
  found = File.directory?(File.join(self.real_path, e))
236
- else
237
- # file
179
+ else # file
238
180
  case RUBY_PLATFORM
239
181
  when /-mingw32$/, /-mswin32$/
240
182
  else
@@ -249,26 +191,22 @@ class Appsetting < ActiveRecord::Base
249
191
  game = key
250
192
 
251
193
  # Find edition
252
- found = nil
253
- cond = true
254
- ed = nil
194
+ ed, found, cond = nil, nil, true
255
195
  value[1].each_pair do |edition, conditions|
256
196
  ed = edition
257
197
  conditions.each do |condition|
258
198
  c = condition.clone
259
199
  reverse = c.sub!(/^!/, "")
260
200
  case c
261
- when /\/$/
262
- # folder
201
+ when /\/$/ # folder
263
202
  found = File.directory?(File.join(self.real_path, c))
264
- else
203
+ else # file
265
204
  case RUBY_PLATFORM
266
205
  when /-mingw32$/, /-mswin32$/
267
206
  else
268
207
  c = c.clone
269
208
  c.sub!(/\.exe$/, "")
270
209
  end
271
- # file
272
210
  found = File.exists?(File.join(self.real_path, c))
273
211
  end
274
212
  cond = reverse ? !found : found
@@ -280,34 +218,68 @@ class Appsetting < ActiveRecord::Base
280
218
  end
281
219
 
282
220
  return nil unless game
283
- Object.const_get("#{game}Appsetting")
221
+ @det_ed = Object.const_get("#{game}Appsetting")
222
+ @det_ed
284
223
  end
285
224
 
286
- def found_type
287
- #Arma2StAppsetting
288
- # TODO: Add detection support based on user settings (exe/path)
289
- return self.class unless self.real_path
290
- self.detect_edition
225
+ def allowance(signatures)
226
+ signatures = signatures.map{|e| e.downcase}
227
+ allowed, disallowed, garbage = [], [], []
228
+ path = self.real_path.gsub("\\", "/")
229
+ pbos = Dir[File.join(path, "**", "*.pbo")]
230
+ pbos.each do |p|
231
+ inter = p.sub("#{path}/", "")
232
+ unless inter =~ /\/(addons|dta)\//i || inter =~ /^common\//i || inter =~ /^(addons|dta)\//i
233
+ garbage << inter
234
+ next
235
+ end
236
+ if signatures.empty?
237
+ allowed << inter
238
+ next
239
+ end
240
+ sigs = Dir["#{p}*.bisign"]
241
+ found = false
242
+ sigs.each do |s|
243
+ sig = s.sub("#{p}.", "").sub(".bisign", "").downcase
244
+ if signatures.include?(sig)
245
+ found = true
246
+ allowed << inter
247
+ break
248
+ end
249
+ end
250
+ disallowed << inter unless found
251
+ end
252
+ [allowed, disallowed, garbage]
291
253
  end
292
254
 
293
- def found_types
294
- t = self.found_type
295
- t ? t.types : []
255
+ def process_name
256
+ ex = self.real_exe
257
+ return nil unless ex
258
+ File.basename(ex)
296
259
  end
297
260
 
298
- def nice_found_type
299
- t = self.found_type
300
- t ? t.label : nil
261
+ def processes
262
+ Six::Appmanager.find_process(process_name, self.real_path)
301
263
  end
302
264
 
303
- def self.types
304
- return [Arma2Appsetting] if self == Appsetting
305
- t = []
306
- e = self
307
- until e.nil? || [Appsetting, ActiveRecord::Base].include?(e) do
308
- t << e
309
- e = e.superclass
265
+ def read_logfile
266
+ Six::Appmanager.read_logfile logfile unless logfile.nil?
267
+ end
268
+
269
+ def kill!
270
+ Six::Appmanager.kill_by_name(process_name, self.real_path)
271
+ end
272
+
273
+ def rpt
274
+ process_name[/(.*)\./]
275
+ "#{$1}.rpt"
276
+ end
277
+
278
+ def logfile
279
+ if File.directory?(real_logpath)
280
+ File.join(real_logpath, rpt) if File.exists?(File.join(real_logpath, rpt))
281
+ else
282
+ nil
310
283
  end
311
- t
312
- end
284
+ end
313
285
  end
@@ -1,7 +1,2 @@
1
1
  class Arma2Appsetting < Appsetting
2
-
3
- # Default game (Appsetting) is atm arma2
4
- #def found_type
5
- # Arma2StAppsetting
6
- #end
7
2
  end
@@ -12,10 +12,5 @@ class Arma2OaAppsetting < Arma2Appsetting
12
12
  REGKEYS = {"Arma2Oa" => ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA', 'MAIN']}
13
13
 
14
14
  FAMILY = Hash.new
15
- FAMILY["Arma2Oa"] = [["arma2oa.exe", "arma2oaserver.exe"], {"Arma2OaCo" => ["addons/"], "Arma2OaSt" => ["!addons/"]}]
16
-
17
- # def found_type
18
- # return self.class unless self.real_path
19
- # self.detect_edition
20
- # end
15
+ FAMILY["Arma2Oa"] = [[DEFAULT_EXE, DEFAULT_SERVER_EXE, "#{DEFAULT_BETA_EXE_PATH}/#{DEFAULT_BETA_EXE}"], {"Arma2OaCo" => ["addons/"], "Arma2OaSt" => ["!addons/"]}]
21
16
  end
@@ -6,9 +6,4 @@ class Arma2OaCoAppsetting < Arma2OaAppsetting
6
6
  # Perhaps look at adding a boolean: specific, so when it is enabled, non of the inherited editions can be used?
7
7
  # Since Arma2 standalone addons should work on OaCo, yet you would loose the specific 'arma2standalone only' option
8
8
 
9
- =begin
10
- def found_types
11
- [Arma2OaCoAppsetting, Arma2OaAppsetting, Arma2StAppsetting, Arma2Appsetting]
12
- end
13
- =end
14
9
  end
@@ -3,6 +3,6 @@ class Arma2OaStAppsetting < Arma2OaAppsetting
3
3
  SPECIFIC = true
4
4
 
5
5
  FAMILY = Hash.new
6
- FAMILY["Arma2Oa"] = [["arma2oa.exe", "arma2oaserver.exe"], {"Arma2OaSt" => ["!addons/"]}]
6
+ FAMILY["Arma2Oa"] = [[DEFAULT_EXE, DEFAULT_SERVER_EXE, "#{DEFAULT_BETA_EXE_PATH}/#{DEFAULT_BETA_EXE}"], {"Arma2OaSt" => ["!addons/"]}]
7
7
  #Code here
8
8
  end
@@ -19,7 +19,7 @@ class Sixconfig < ActiveRecord::Base
19
19
  m += srv.mods if srv
20
20
  self.mods.each { |mod| m << mod unless m.include?(mod) }
21
21
  if setting.beta
22
- t = setting.found_type
22
+ t = setting.edition
23
23
  if t
24
24
  t::DEFAULT_BETA_MODS.each do |mf|
25
25
  mod = Mod.find_by_name(mf)
@@ -1,8 +1,7 @@
1
1
  %table{ :border => 1, :cellpadding => "5", :width => "100%"}
2
2
  %tr
3
3
  %td
4
- - t = @current_setting.nice_found_type
5
- Edition: #{link_to t ? t : "ERROR: None detected", nil, :title => "Supports mods for: #{@current_setting.found_types.map{|e| e.label}.join(", ")}" }
4
+ Edition: #{link_to @current_setting.nice_edition, nil, :title => "Supports mods for: #{@current_setting.found_types.map{|e| e.label}.join(", ")}" }
6
5
  %br
7
6
  Last sync #{@system_setting.synchronized_at ? time_ago_in_words(@system_setting.synchronized_at) + " ago" : "never"}
8
7
  Gamespy #{@system_setting.gamespied_at ? time_ago_in_words(@system_setting.gamespied_at) + " ago" : "never"}
@@ -22,7 +22,7 @@ case RUBY_VERSION
22
22
  end
23
23
 
24
24
  module SixUpdaterWeb
25
- VERSION = "0.22.3"
25
+ VERSION = "0.22.4"
26
26
  COMPONENT = "six-updater-web"
27
27
 
28
28
  DEFAULT_IP = "127.0.0.1" unless defined?(DEFAULT_IP)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 22
8
- - 3
9
- version: 0.22.3
8
+ - 4
9
+ version: 0.22.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sickboy
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-24 00:00:00 +02:00
17
+ date: 2010-07-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency