# encoding: utf-8 case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ gem 'win32-process' require 'win32/registry' require "win32/process" require 'win32ole' end require 'open3' module SixUpdaterWeb VERSION = "0.12.3" COMPONENT = "six-updater-web" SIX_PORT = 3000 unless defined?(SIX_PORT) # Determine by commandline etc. Can actually be done by intepreting argv manually in init #LOCAL_URL = "http://localhost" LOCAL_URL = "http://127.0.0.1" ARMA2 = ['SOFTWARE\\Bohemia Interactive Studio\\ArmA 2', 'MAIN'] ARMA2_ALT = ['SOFTWARE\\Bohemia Interactive\\ArmA 2', 'InstallPath'] ARMA2_STEAM = ['SOFTWARE\\Valve\\Steam\\Common\\ARMA 2', 'InstallPath'] bpath = if ENV['BASE_PATH'] OLDLOCATION = ENV['BASE_PATH'] unless defined?(OLDLOCATION) ENV['BASE_PATH'] elsif defined?(OLDLOCATION) OLDLOCATION else Dir.pwd end bpath.gsub!("\\", "/") BASE_PATH = bpath TOOL_PATH = File.join(BASE_PATH, 'tools') RUBY_PATH = File.join(TOOL_PATH, "ruby", "bin") #RUB_PATH = "tools/ruby/bin" ENV['PATH'] = "#{RUBY_PATH};#{TOOL_PATH};".gsub("/", "\\") + ENV['PATH'] args = ARGV.join(" ") if args[/RAILS_ENV=(\w)/] ENV["RAILS_ENV"] = $1 else if ENV['RAILS_ENV'] ENV["RAILS_ENV"] = "development" if ENV["RAILS_ENV"].empty? else ENV["RAILS_ENV"] = "development" end end #case RUBY_VERSION # when /1\.8\.[0-9]/ # begin # reg_path = Win32::Registry::HKEY_CURRENT_USER.open("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")['AppData'] # rescue # end #end case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ TEMP_PATH = if ENV['TEMP'] if ENV['TEMP'].size > 0 File.directory?(ENV['TEMP']) ? ENV['TEMP'] : BASE_PATH else BASE_PATH end else BASE_PATH end HOME_PATH = File.exists?(File.join(ENV['APPDATA'])) ? File.join(ENV['APPDATA']) : TEMP_PATH CMD_EXE = File.join(ENV['WINDIR'], 'system32', 'cmd.exe') # TODO: Deprecated; This has moved to the six-updater-web.rb included in the windows suite # But requires everyone to update to it, unless we do it for them :D path = File.join(BASE_PATH, "tools") rubypath = File.join(path, 'ruby', 'bin') rubypath.gsub!("/", "\\") tpath = "#{path};#{File.join(path, 'bin')};#{rubypath}" tpath.gsub!('/', '\\') ENV['PATH'] = "" unless ENV['PATH'] ENV['PATH'] = "#{tpath};#{ENV['PATH']}" unless ENV['PATH'].include?(tpath) else HOME_PATH = ENV['HOME'] TEMP_PATH = '/tmp' end DATA_PATH = File.join(File.exists?(File.join(BASE_PATH, "legacy.txt")) ? BASE_PATH : HOME_PATH, "six-updater") # COMPONENT) rpath = nil begin rpath = Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, ARMA2_STEAM[0])[ARMA2_STEAM[1]] DISTRO = "STEAM" rescue begin rpath = Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, ARMA2_ALT[0])[ARMA2_ALT[1]] DISTRO = "ALT" rescue begin rpath = Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, ARMA2[0])[ARMA2[1]] DISTRO = "STANDARD" rescue DISTRO = nil end end end ARMA_PATH = rpath module_function def logger; ActiveRecord::Base.logger; end def initialize(config) if defined?(OLDLOCATION) config.log_path = File.join(DATA_PATH, 'logs', 'six-updater-web.log') end end def after_initialize if defined?(OLDLOCATION) #(TAR2RUBYSCRIPT) #|| RUBYSCRIPT2EXE.is_compiling? # Migrate the database to current version if required Six::Dbmanager.migrate_data Six::Dbmanager.migrate_system if defined?(SPECIAL) case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ file_to_use = "#{LOCAL_URL}:#{SIX_PORT}/main" arguments = nil directory = nil operation = "OPEN" show = nil begin shell = WIN32OLE.new('Shell.Application') shell.ShellExecute(file_to_use, arguments, directory, operation, show) rescue #logger.warn "Unable to open browser: #{$!}" end end end end #Six::Dbmanager.check end def run_program(path, app_path, startpath, cl) logger.info "Current Path: #{Dir.pwd}, BASE_PATH: #{BASE_PATH}, DATA_PATH: #{DATA_PATH}" logger.info "Starting with #{cl} from #{startpath}" #, with #{path}" begin case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ cl = "\"#{app_path}\" #{cl}" cl = "/C #{cl}" logger.info "#{CMD_EXE} #{cl}" struct = Process.create( :app_name => CMD_EXE, :command_line => cl, :creation_flags => Process::DETACHED_PROCESS, :process_inherit => false, :thread_inherit => false, :cwd => startpath, :inherit => false #:environment => "" ) else Dir.chdir(startpath) do p = Process.fork do logger.info "#{app_path} #{cl}" system "#{app_path} #{cl}" end end #logger.info "Unimplemented on current platform: #{RUBY_PLATFORM}" end rescue logger.info "WARNING: Something went wrong starting the app" logger.info "#{$!}" end end end case RUBY_VERSION when /1\.8\.[0-9]/ class Array def to_s "[#{self.join(', ')}]" end end end puts "Six Updater Web (GUI) #{SixUpdaterWeb::VERSION}, by Sickboy" puts "BASE: #{SixUpdaterWeb::BASE_PATH}" puts "DATA: #{SixUpdaterWeb::DATA_PATH}" puts "ARMA: #{SixUpdaterWeb::DISTRO} PATH: #{SixUpdaterWeb::ARMA_PATH}" if defined?(SixUpdaterWeb::OLDLOCATION) # Arrange appdata! lf = File.join(SixUpdaterWeb::DATA_PATH, "logs") FileUtils.mkdir_p(lf) unless File.directory?(lf) df = File.join(SixUpdaterWeb::DATA_PATH, "db") FileUtils.mkdir_p(df) unless File.directory?(df) db = File.join(SixUpdaterWeb::DATA_PATH, "db", "production.sqlite3") FileUtils.cp(File.join(SixUpdaterWeb::BASE_PATH, "db", "production.sqlite3"), db) unless File.exists?(db) end if defined?(SixUpdaterWeb::OLDLOCATION) module Rails class Configuration def database_configuration conf = File.open(database_configuration_file, 'r') {|file| YAML::load(file)} conf.each do |k, v| if v["adapter"] =~ /^sqlite/ v["database"] = File.join(SixUpdaterWeb::DATA_PATH, v["database"]) if v.include?("database") v["dbfile"] = File.join(SixUpdaterWeb::DATA_PATH, v["dbfile"]) if v.include?("dbfile") end end conf end end end end