Class: Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/six/launcher-app.rb

Overview

require ‘singleton’

Constant Summary collapse

RUBY =
"tools/ruby/bin/ruby.exe"
GEM =
"tools/ruby/bin/gem"
VERSION =
"0.1.2"
BASE_PATH =

include Singleton

if ENV['OCRA_EXECUTABLE']
  if ENV['OCRA_EXECUTABLE'][/(.*)[\/|\\].*/]
    p = $1
    p.gsub!('\\', '/')
    p
  else
    p = Dir.pwd
    p.gsub!('\\', '/')
    p
  end
elsif defined?(TAR2RUBYSCRIPT)
  if oldlocation
    oldlocation
  else
    Dir.pwd
  end
else
  p = Dir.pwd
  p.gsub!('\\', '/')
  p
end
TOOL_PATH =
File.join(BASE_PATH, 'tools')
RUBY_PATH =
File.join(TOOL_PATH, 'ruby')

Instance Method Summary collapse

Constructor Details

#initialize(b = nil) ⇒ Setup

Returns a new instance of Setup.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/six/launcher-app.rb', line 39

def initialize(b = nil)
  Dir.chdir BASE_PATH
  options
  if b
    action(b)
  else
    while ((code = gets.strip) != "exit")
      action(code)
      options
    end
  end
end

Instance Method Details

#action(code) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/six/launcher-app.rb', line 115

def action(code)
  case code
  when "100"
    update_ruby
  when "101"
    update_gems
  when "1"
    start_updater_web
  when "2"
    start_updater
  when "21"
    start_updater("--install --startgame")
  when "22"
    start_updater("--install --join")
  when "23"
    start_updater("--startgame")
  when "24"
    start_updater("--join")
  when "51"
    start_updater_web("--bind 0.0.0.0")
  end
  bla
end

#blaObject



56
57
58
59
60
# File 'lib/six/launcher-app.rb', line 56

def bla
  puts
  puts "Please press enter to continue"
  STDIN.gets
end

#detached(app, cl, path) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/six/launcher-app.rb', line 96

def detached(app, cl, path)
  begin
    app.gsub!("/", "\\")
    cl = "/C \"#{app}\" #{cl}"
    struct = Process.create(
      :app_name         => File.join(ENV['WINDIR'], 'system32', 'cmd.exe'),
      :command_line     => cl,
      :creation_flags   => Process::DETACHED_PROCESS,
      :process_inherit  => false,
      :thread_inherit   => false,
      :cwd              => path,
      :inherit          => false
      #:environment      => ""
    )
  rescue
    puts "WARNING: Something went wrong starting the app: #{app}"
  end
end

#optionsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/six/launcher-app.rb', line 139

def options
  puts
  puts "Launcher application v\#{VERSION} by Sickboy\nWARNING: If you use Windows Vista/7 with UAC,\nplease make sure you run this program 'As Administrator'\n-----\n1 - Start updater-web\n2 - Start updater\n-----\n21 - Start updater, --install --startgame\n22 - Start updater, --install --join\n23 - Start updater, --startgame\n24 - Start updater, --join\n-----\n51 - Start updater-web on public interface\n-----\n100 - Install/Update Ruby\n101 - Install/Update Ruby Gems\n\nPlease enter your choice and press enter. Or press CTRL+C to abort\n"
end

#rubycheckObject



52
53
54
# File 'lib/six/launcher-app.rb', line 52

def rubycheck
  update_ruby unless File.exists?(File.join(RUBY_PATH, 'bin', 'ruby.exe'))
end

#start_updater(params = nil) ⇒ Object



89
90
91
92
93
94
# File 'lib/six/launcher-app.rb', line 89

def start_updater(params = nil)
  rubycheck
  update_gems
  puts "Starting Updater..."
  detached(File.join(RUBY_PATH, 'bin', 'ruby.exe'), "-U -rubygems six-updater.rb #{params}", BASE_PATH)
end

#start_updater_web(cl = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/six/launcher-app.rb', line 76

def start_updater_web(cl = nil)
  rubycheck
  update_gems
  puts "Starting Updater-web..."
  b = "-U -rubygems six-updater-web.rb"
  cl = if cl
    "#{b} #{cl}"
  else
    b
  end
  detached(File.join(RUBY_PATH, 'bin', 'ruby.exe'), cl, BASE_PATH)
end

#update_gemsObject



68
69
70
71
72
73
74
# File 'lib/six/launcher-app.rb', line 68

def update_gems
  rubycheck
  puts "Updating Ruby Gems"
  system "#{RUBY} #{GEM} install *.gem" if Dir["*.gem"].size > 0
  system "#{RUBY} #{GEM} update"
  system "#{RUBY} #{GEM} clean"
end

#update_rubyObject



62
63
64
65
66
# File 'lib/six/launcher-app.rb', line 62

def update_ruby
  puts "Updating Ruby"
  system "#{RUBY} tools/six-downloader.rb tools/six-downloader_ruby.yml"
  system "tools/7z.exe x -y tools/ruby.7z -otools"
end