class MainController < ApplicationController def index @msg = [] @skip, @install, @check, @disabled = [], [], [], [] preset, queryserver, server, action, setting, reset, ok = nil, nil, nil, nil, nil, false, true grab = false save_fav = true @system_setting = SystemSetting.singleton @autoskip = @system_setting.autoskip @autoskip = true if @autoskip.nil? @inweb = @system_setting.inweb @queryserver = nil if @system_setting.synchronized_at ok = false if @system_setting.synchronized_at > 30.minutes.ago end if ok @msg << "Auto Synchronize: " + begin @system_setting.sync rescue "FAILURE: #{$!}" end + "
" end gs_ok, gs_geo = true, true if @system_setting.gamespied_at gs_ok = false if @system_setting.gamespied_at > 30.minutes.ago end params["commit"] = "synchronize" if params["portalsync"] params["commit"] = "update_gamespy" if params["serversync"] unless params["commit"] params["commit"] = if gs_ok gs_geo = false "update_gamespy" else "none" end end case params["commit"].downcase when "none" grab = true save_fav = false when "exec" save_fav = false params["commit"] = "execute" when "synchronize" if !ok @msg << @system_setting.sync + "
" end grab = true when "show status" grab = true params["all"] = "" when "reset skip status" reset = true when "reset all mods skip status" reset = true grab = true params["all"] = "" when "update_gamespy" gslist_installed = begin %x[gslist -h] $? == 0 rescue false end if gslist_installed @msg << "Updating Gamespy...This will take a while, please wait until done!
" if gs_geo @system_setting.update_gamespy else @system_setting.update_gamespy_nogeo end else @msg << "ERROR: gslist tool is missing!
Please download from Six Updater Wagn, and put in #{SixUpdaterWeb::TOOL_PATH}
" end when "prune_gamespy" @msg << "Pruning Gamespy" Queryserver.prune when "clean_gamespy" @msg << "Cleaning Gamespy" Queryserver.clean when "purge_gamespy" d = false if params["really"] if params["really"]["sure"] == "1" Queryserver.purge @msg << "Purged Gamespy...
" d = true end end @msg << "ERROR: Please confirm by checking the checkbox
" if !d end begin preset = Sixconfig.find(@system_setting.favorite_preset) rescue # preset = Sixconfig.find(:first) # Auto select preset? end begin queryserver = Queryserver.find(@system_setting.favorite_server) #server = Server.find(@system_setting.favorite_server) rescue end begin setting = Appsetting.find(@system_setting.favorite_settings_profile) rescue end begin action = Action.find(@system_setting.favorite_action) rescue end preset = fetch_param([:config], Sixconfig, preset) #server = fetch_param([:server], Server, server) action = fetch_param([:act], Action, action) setting = fetch_param([:setting], Appsetting, setting) queryserver = fetch_param([:gamespy], Queryserver, queryserver) if queryserver @queryserver = queryserver.id server = queryserver.dynamic_server end if params[:system] @autoskip = (params[:system][:autoskip] == "1") @inweb = (params[:system][:inweb] == "1") end if save_fav @system_setting.favorite_server = if queryserver #server queryserver.id unless queryserver.new_record? else nil end @system_setting.favorite_preset = if preset preset.id unless preset.new_record? else nil end @system_setting.favorite_action = if action action.id unless action.new_record? else nil end @system_setting.favorite_settings_profile = if setting setting.id unless setting.new_record? else nil end @system_setting.autoskip = @autoskip @system_setting.inweb = @inweb @system_setting.save end if grab if params["all"] preset = Sixconfig.new preset.name = "Dynamic" preset.mods += Mod.find(:all) elsif preset else @msg << "No preset selected!" act return end @msg << "Using preset: #{preset.name}" if preset unless params["all"] if server @msg << "Override server: #{server.name}" else if preset if preset.server server = preset.server @msg << "Preset server: #{server.name}" end end end end else # TODO: Automatically handle all this stuff better :) if preset @msg << "Using preset: #{preset.name}" else @msg << "No preset selected!" act return end if server @msg << "Override server: #{server.name}" else if preset.server server = preset.server @msg << "Preset server: #{server.name}" end end unless reset if setting @msg << "Override settings profile: #{setting.name}" else if preset.appsetting setting = preset.appsetting @msg << "Preset settings profile: #{setting.name}" end end if action @msg << "Override action: #{action.name}" else if preset.action action = preset.action @msg << "Preset action: #{action.name}" end end end end @msg << "Resetting skip status." if reset setting = Appsetting.new unless setting preset.all_mods(server).each do |mod| mod.update_version(setting.real_path) # TODO: this already runs in updater_yml, but there doesn't run if autoskip is disabled if reset && !@autoskip mod.skip = false else mod.update_skip if @autoskip end mod.save unless mod.new_record? if mod.disabled @disabled << mod next end if mod.installed? || mod.exists?(setting) if mod.skip @skip << mod else @check << mod end else @install << mod end end case params["commit"].downcase when "edit" redirect_to "/sixconfigs/edit/#{params[:config]}" return when "show" redirect_to "/queryservers/show/#{params[:gamespy]}" return when "save" preset.output_yml(setting, server) @msg << "
Saved six-updater.yml!" when "execute" preset.execute(action, setting, server, @autoskip, @inweb) if @inweb sleep 1 redirect_to :action => 'logoutput' return end @msg << "
Saved six-updater.yml!
A window should open displaying the update process progress" procs = setting.processes unless procs.empty? @msg << "
WARNING: There seem to be open arma processes: #{procs}" end when "stop game" setting.processes.each { |entry| @msg << "Process to be killed: #{entry}" } setting.kill! when "read mods" Mod.read_modfolders(setting) end @skip.sort! {|a, b| a.name <=> b.name} @check.sort! {|a, b| a.name <=> b.name} @install.sort! {|a, b| a.name <=> b.name} @disabled.sort! {|a, b| a.name <=> b.name} act end def fetch @system_setting = SystemSetting.singleton setting = nil setting = Sixconfig.find(@system_setting.favorite_preset).appsetting unless @system_setting.favorite_preset.empty? setting = Appsetting.new unless setting @msg = [] case params["commit"].downcase when "rpt" lf = setting.logfile if lf.nil? @msg << "No logfile found!" else send_file(lf, {:filename => "#{setting.rpt}_#{Time.now.to_i}.log"}) end when "updater" f = "six-updater.log" lf = File.join(SixUpdaterWeb::DATA_PATH, "logs", f) if File.exists?(lf) send_file(lf, {:filename => "#{f}_#{Time.now.to_i}.log"}) else @msg << "No logfile found!" end when "updater-web" f = "six-updater-web.log" lf = File.join(SixUpdaterWeb::DATA_PATH, "logs", f) if File.exists?(lf) send_file(lf, {:filename => "#{f}_#{Time.now.to_i}.log"}) else @msg << "No logfile found!" end end end def reset @system_setting = SystemSetting.singleton @content = "" if params["system_setting"] @system_setting.server_username = params["system_setting"]["server_username"].strip @system_setting.server_password = params["system_setting"]["server_password"].strip @system_setting.save @content = @system_setting.sync end end def reset_act @msg = "" if params[:configuration] if params[:configuration][:reset] == "1" logger.info "Reloading configuration data!" @msg << "Reloaded configuration data!" Six::Dbmanager.reload_data end end if params[:system] if params[:system][:reset] == "1" logger.info "Reloading system data!" @msg << "Reloaded system data!" Six::Dbmanager.reload_system end end end def modlogs path = Appsetting.find(:first).real_modpath @cloghash = Hash.new Mod.find(:all).each do |mod| clog = File.join(path, mod.real_name, "changelog.txt") @cloghash[mod.real_name] = File.open(clog) {|f| f.readlines } if File.exists?(clog) end end def logoutput end private def act @preset = if @system_setting.favorite_preset @system_setting.favorite_preset.to_s end @server = if @system_setting.favorite_server @system_setting.favorite_server.to_s end @action = if @system_setting.favorite_action @system_setting.favorite_action.to_s end @setting = if @system_setting.favorite_settings_profile @system_setting.favorite_settings_profile.to_s end end def fetch_param(ar, ty, default = nil) a = params ar.each do |e| if a[e] a = a[e] else a = nil break end end if a if a.empty? return nil else begin return ty.find(a) rescue return default end end else return default end end end