Module: Six::Arma::Builder

Defined in:
lib/six/arma/builder.rb,
lib/six/arma/builder-app.rb,
lib/six/arma/builder/mod.rb,
lib/six/arma/builder/options.rb

Defined Under Namespace

Classes: Mod

Constant Summary collapse

VERSION =
'0.1.8'
COMPONENT =
'six-arma-builder'
BASE_PATH =
Dir.pwd
TEST =

false #true

false
@@log =

Create loggers

Log4r::Logger.new(COMPONENT)

Class Method Summary collapse

Class Method Details

.initializeObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/six/arma/builder.rb', line 52

def initialize
  log.info "ArmA Git Builder (v#{VERSION}) by Sickboy <sb_at_dev-heaven.net>"
  log.info 'Run with --help for help'

  @config = Hash.new unless @config
  config = Hash.new

  @config_file = "#{COMPONENT}.yml"
  if ARGV[0]
    # FIXME: This is not a very good catch..
    if ARGV[0][/.*\..*/]
      if FileTest.exist?(ARGV[0])
        @config_file = ARGV[0]
      else
        log.warn "#{ARGV[0]} not found, trying #{@config_file}"
      end
    end
  end

  unless FileTest.exist?(@config_file)
    log.error "ERROR: #{@config_file} config missing!"
    wait
    Process.exit
  end

  File.open(@config_file) { |file| config.merge!(YAML::load(file)) }
  config.merge! @config
  @config = config
  FileUtils.rm_f(File.join(BASE_PATH, 'changelog.txt')) if File.exists?(File.join(BASE_PATH, 'changelog.txt'))
end

.logObject



87
88
89
# File 'lib/six/arma/builder.rb', line 87

def log
  @@log
end

.parse_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/six/arma/builder/options.rb', line 10

def parse_options
  # FIXME: DirectCopy from Updater ;)
  todo, general_todo, second_todo = [], [], []

  options = Hash.new
  options[:verbose] = true
  OptionParser.new do |opts|
    $0[/.*\/(.*)/]
    opts.banner = "Usage: #{$1} [config.yml] [options]"

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:verbose] = v
    end

    opts.on("-i", "--install", "Installs the mods, unless already installed") do |bool|
      todo << :install if bool
    end

    opts.on("-d", "--uninstall", "Uninstalls the mods, unless not installed") do |bool|
      todo << :uninstall if bool
    end

    opts.on("-u", "--update", "Updates each mod to latest version") do |bool|
      todo << :update if bool
    end

    opts.on("-r", "--reset", "Resets the modfolders to latest commit status. All modifications lost") do |bool|
      todo << :reset if bool
    end

    opts.on("-z", "--userconfig", "Processes the userconfigs of each mod. Makes backups of previous files") do |bool|
      todo << :userconfig if bool
    end

    opts.on("-l", "--changelog", "Display Changelog after update") do |bool|
      second_todo << :changelog if bool
    end

    opts.on("-c", "--cleanup", "Cleans up the modfolders git repositories") do |bool|
      second_todo << :cleanup if bool
    end

    opts.on("-s", "--createshortcut", "Creates shortcut to run the game with the mods, in installation folder") do |bool|
      general_todo << :createshortcut if bool
    end

    opts.on("-k", "--createdesktopshortcut", "Creates shortcut to run the game with the mods, on the desktop") do |bool|
      general_todo << :createdesktopshortcut if bool
    end

    opts.on("-g", "--startgame", "Starts the game with #{@config[:armaparams]} -mod=#{@mods}") do |bool|
      general_todo << :startgame if bool
    end

    opts.on("-w", "--wait", "Waits at the end for user pressing ENTER") do |bool|
      options[:wait] = bool
    end

    opts.on("-f", "--force", "Forces to run tasks even though no changes were detected") do |bool|
      options[:force] = bool
    end

    opts.on("--mods S", String, "Additional Mods") do |s|
      options[:mods] = s
    end

    opts.on("--armapath S", String, "Destination folder") do |s|
      options[:armapath] = s
    end

    opts.on("--gitpath S", String, "Git binary") do |s|
      options[:gitpath] = s
    end
  end.parse!

  default = if (todo + second_todo + general_todo).size > 0
    false
  else
    true
  end

  # TODO: Move this to Updater ?
  @todo = if todo.size > 0
    todo
  else
    log.info "No parameters given, running the default"
    options[:wait] = true
    if default
      @config[:defaultactions]
    else
      []
    end
  end
  @general_todo = if general_todo.size > 0
    general_todo
  else
    if default
      @config[:defaultgeneralactions]
    else
      []
    end
  end

  @second_todo = if second_todo.size > 0
    second_todo
  else
    if default
      @config[:defaultsecondactions]
    else
      []
    end
  end
  @config = @config.merge(options)
end

.saveObject



91
92
93
94
95
# File 'lib/six/arma/builder.rb', line 91

def save
  puts
  log.info "Saving stats..."
  File.open(File.join(BASE_PATH, @config_file), 'w') { |file| YAML.dump( @config, file ) }
end

.waitObject



83
84
85
# File 'lib/six/arma/builder.rb', line 83

def wait
  STDIN.gets
end