Class: Mod

Inherits:
ActiveRecord::Base show all
Defined in:
lib/six-updater-web/app/models/mod.rb

Direct Known Subclasses

RvMod

Constant Summary collapse

OVERRIDE_MODEL =
Mod

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Instance Attribute Details

#aliasesObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def aliases
  @aliases
end

#authorObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def author
  @author
end

#changelogObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def changelog
  @changelog
end

#cpp_nameObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def cpp_name
  @cpp_name
end

#dependenciesObject

TODO

  • fix dependencies



19
20
21
# File 'lib/six-updater-web/app/models/mod.rb', line 19

def dependencies
  @dependencies
end

#descriptionObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def description
  @description
end

#detailsObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def details
  @details
end

#full_nameObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def full_name
  @full_name
end

#guidObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def guid
  @guid
end

#homepageObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def homepage
  @homepage
end

#licenseObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def license
  @license
end

#license_urlObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def license_url
  @license_url
end

#maxbuildObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def maxbuild
  @maxbuild
end

#minbuildObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def minbuild
  @minbuild
end

#mod_versionObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def mod_version
  @mod_version
end

#readmeObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def readme
  @readme
end

#repository_ymlObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def repository_yml
  @repository_yml
end

#size_wdObject

Workaround for missing db fields



22
23
24
# File 'lib/six-updater-web/app/models/mod.rb', line 22

def size_wd
  @size_wd
end

Class Method Details

.appsetObject



38
39
40
# File 'lib/six-updater-web/app/models/mod.rb', line 38

def self.appset
  Kernel.const_get(self.short+"Appsetting")
end

.labelObject

arma2 mod: works for all subclasses armaoa mod; works for arma2-oa-st, arma2-oa-



97
98
99
# File 'lib/six-updater-web/app/models/mod.rb', line 97

def self.label
  self.appset.label
end

.read_modfolders(setting) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/six-updater-web/app/models/mod.rb', line 236

def self.read_modfolders(setting)
  Dir.chdir setting.real_modpath.clone do
    Dir["@*"].each do |dir|
      next unless File.directory?(dir)
      m = Mod.find(:first, :conditions => ["name LIKE ?", dir])
      unless m
        m = Mod.new :name => dir
        m.save
      end
      logger.debug "#{m.inspect}"
    end
  end
end

.shortObject



101
102
103
# File 'lib/six-updater-web/app/models/mod.rb', line 101

def self.short
  self.to_s.sub("Mod", "")
end

.typesObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/six-updater-web/app/models/mod.rb', line 105

def self.types
  return [Arma2Mod] if self.class == Appsetting
  e = self
  types = []
  unless e.nil? || [Mod, ActiveRecord::Base].include?(e)
    types << e
    e = e.class
  end
  types
end

Instance Method Details

#all_dependentmods(mods = []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/six-updater-web/app/models/mod.rb', line 26

def all_dependentmods(mods = [])
  mods += [self]
  self.mods.each do |mod|
    next if mods.include?(mod)
    mods += mod.all_dependentmods(mods)
    mods << mod
  end
  mods -= [self]
  mods += [self]
  mods.uniq
end

#all_repositoriesObject



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/six-updater-web/app/models/mod.rb', line 188

def all_repositories
  rep = if self.networks.empty?
    Repository.find(:all)
  else
    repos = []
    self.networks.each { |net| repos += net.repositories unless net.disabled }
    repos
  end
  prio = nil
  rep.each {|e| unless e.priority.nil?; prio = true; break; end }
  prio ? rep.sort{|a, b| a.prio <=> b.prio} : rep.shuffle
end

#exists?(setting) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'lib/six-updater-web/app/models/mod.rb', line 145

def exists?(setting)
  path = self.my_path(setting)
  return false unless path
  File.exists?(path)
end

#has_rsync?(setting) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
154
155
# File 'lib/six-updater-web/app/models/mod.rb', line 151

def has_rsync?(setting)
  path = self.my_path(setting)
  return false unless path
  File.exists?(File.join(path, ".rsync"))
end

#installed?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/six-updater-web/app/models/mod.rb', line 136

def installed?
  self.version_local && !self.version_local.empty?
end

#my_path(setting) ⇒ Object



140
141
142
143
# File 'lib/six-updater-web/app/models/mod.rb', line 140

def my_path(setting)
  return nil if setting.real_modpath.nil? || self.real_name.nil?
  File.join(self.real_path(setting), self.real_name).gsub("\\", "/")
end

#process(setting, reset, autoskip, force = false) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/six-updater-web/app/models/mod.rb', line 42

def process(setting, reset, autoskip, force = false)
  self.update_version(setting) # TODO: this already runs in updater_yml, but there doesn't run if autoskip is disabled
  if reset && !autoskip
    self.skip = false
  else
    self.update_skip if autoskip
  end
  self.save unless self.new_record?

  unless force
    self.disabled = true if (!self.exists?(setting) || self.installed? || self.class.appset::SPECIFIC) && !self.version_match?(setting)
  end
  #self.skip = true if (self.exists?(setting) && !self.has_rsync?(setting))

end

#read_version(setting) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/six-updater-web/app/models/mod.rb', line 165

def read_version(setting)
  path = self.my_path(setting)
  return unless path
  cfg = File.join(path, '.rsync', '.repository.yml')
  return nil unless File.exists?(cfg)
  conf = YAML::load_file(cfg)
  return nil unless conf
  begin; conf[:version]; rescue; nil; end
end

#real_nameObject



126
127
128
129
130
131
132
133
134
# File 'lib/six-updater-web/app/models/mod.rb', line 126

def real_name
  return unless self.name
  case RUBY_PLATFORM
    when /-mingw32$/, /-mswin32$/
      self.name
    else
      self.name.downcase
  end
end

#real_path(setting) ⇒ Object



184
185
186
# File 'lib/six-updater-web/app/models/mod.rb', line 184

def real_path(setting)
  self.path.nil? || self.path.empty? ? setting.real_modpath : self.path
end

#remaObject



161
162
163
# File 'lib/six-updater-web/app/models/mod.rb', line 161

def rema
  "mods/show"
end

#remoteObject



157
158
159
# File 'lib/six-updater-web/app/models/mod.rb', line 157

def remote
  
end

#specialObject



205
206
207
# File 'lib/six-updater-web/app/models/mod.rb', line 205

def special
  self.incl && !self.incl.empty?
end

#status(setting = Appsetting.new) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/six-updater-web/app/models/mod.rb', line 85

def status(setting = Appsetting.new)
  return :special if self.special
  return :disabled if self.disabled
  if self.installed? || self.exists?(setting)
    self.skip ? :skip : :check
  else
    :install
  end    
end

#to_updater_ymlObject



209
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
# File 'lib/six-updater-web/app/models/mod.rb', line 209

def to_updater_yml
  return unless self.real_name
  hash = Hash.new
  hash[:folder] = self.real_name
  hash[:repository] = []
  hash[:skip] = self.skip
  # TODO: Enable once proper processing is implemented
  #hash[:path] = self.path
  hash[:disabled] = self.disabled
  if self.incl
    hash[:include] = self.incl.split(";")
    hash[:force] = true unless hash[:include].empty?
  end
  if self.excl
    hash[:exclude] = self.excl.split(";")
  end
  hash[:priority] = self.priority
  name = self.real_name.clone
  name.gsub!("@", '')
  unless self.new_record?
    self.all_repositories.each do |rep|
      hash[:repository] << "#{rep.to_updater_yml}/rel/#{name.downcase}/." unless rep.disabled
    end
  end
  hash
end

#uconfig_nameObject



58
59
60
# File 'lib/six-updater-web/app/models/mod.rb', line 58

def uconfig_name
  self.real_name.sub(/^@/, "")
end

#update_skipObject



201
202
203
# File 'lib/six-updater-web/app/models/mod.rb', line 201

def update_skip
  self.skip = if self.new_record?; true ; else; ((self.version == self.version_local) && !self.version.nil?); end
end

#update_skip_by_version(setting) ⇒ Object



179
180
181
182
# File 'lib/six-updater-web/app/models/mod.rb', line 179

def update_skip_by_version(setting)
  self.update_version(setting)
  self.update_skip
end

#update_version(setting) ⇒ Object



175
176
177
# File 'lib/six-updater-web/app/models/mod.rb', line 175

def update_version(setting)
  self.version_local = self.read_version(setting).to_s
end

#userconfig(setting = Appsetting.new) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/six-updater-web/app/models/mod.rb', line 62

def userconfig(setting = Appsetting.new)
  # Packs everything that matches Find.find('tests')
  #File.open('test.tar', 'wb') { |tar| Archive::Tar::Minitar.pack('tests', tar) }
  # Unpacks 'test.tar' to 'x', creating 'x' if necessary.
  # Archive::Tar::Minitar.unpack('test.tar', 'x')
  rpath = self.real_path(setting)

  path = File.join(rpath, 'store', 'userconfig.tar')
  path = File.join(rpath, 'store', 'userconfig') unless File.exists?(path)
  path = File.join(rpath, 'userconfig') unless File.exists?(path)
  if File.exists?(path)
    #f = .clone
    #f.gsub!('@', '')
    #uconfig = File.join(setting.real_path, 'userconfig')
    #uconfigpath = File.join(uconfig, self.uconfig_name)
    if File.directory? path

    else
      #Archive::Tar::Minitar.unpack('test.tar', 'x')
    end
  end
end

#version_match?(setting) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
# File 'lib/six-updater-web/app/models/mod.rb', line 116

def version_match?(setting)
  # setting.type == "ArmA2OaSt" (Arma2Oa, ArmA2)
  # self.type == "ArmA2"

  # setting.type == "ArmA2OaSt" (ArmA2Oa, ArmA2)
  # self.type == "ArmA2Oa"
  return nil if setting.nil?
  self.type.nil? ? true : setting.found_types.map{|e| e.short }.include?(self.class.short)
end