class Mod < ActiveRecord::Base has_and_belongs_to_many :sixconfigs has_and_belongs_to_many :servers has_and_belongs_to_many :queryservers has_and_belongs_to_many :networks has_and_belongs_to_many :categories #has_many :dependentmods #has_many :depmods, :through => :dependentmods has_and_belongs_to_many :mods, :association_foreign_key => "depmod_id", :class_name => "Mod", :join_table => "dependentmods" has_and_belongs_to_many :depmods, :foreign_key => "depmod_id", :class_name => "Mod", :join_table => "dependentmods" six_guid 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.uniq end # arma2 mod: works for all subclasses # armaoa mod; works for arma2-oa-st, arma2-oa- def self.label self.to_s.sub("Mod", "") end def self.short self.to_s.sub("Mod", "") end def self.types return [Arma2Mod] if self.class == Appsetting e = self unless e.nil? || [Mod, ActiveRecord::Base].include?(e) types << e e = e.class end types end 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 def real_name return unless self.name case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ self.name else self.name.downcase end end def installed? self.version_local && !self.version_local.empty? end def exists?(setting) return false unless setting.real_modpath && self.real_name File.exists?(File.join(setting.real_modpath, self.real_name)) end def remote end def rema "mods/show" end def read_version(path) return unless path && self.real_name cfg = File.join(path, self.real_name, '.rsync', '.repository.yml') if File.exists?(cfg) conf = YAML::load_file(cfg) if conf begin conf[:version] rescue nil end else nil end else nil end end def update_version(path) self.version_local = self.read_version(path).to_s end def update_skip_by_version(path) self.update_version(path) self.update_skip end def real_path(appsetting) if self.path self.path else appsetting.real_modpath end end def all_repositories if self.networks.empty? Repository.find(:all) else repos = [] self.networks.each { |net| repos += net.repositories unless net.disabled } repos end end def update_skip self.skip = if self.new_record?; true ; else; ((self.version == self.version_local) && !self.version.nil?); end end 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 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 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 end