module AsProject class FlashPlayerError < StandardError; end class FlashPlayer < RemoteFileTask attr_accessor :version, :name, :swf def initialize(name=:flash_player) @name = name @version = 9 super(name) end def remote_task_name return "flash_player-#{version}" end #TODO: Add urls and locations for versions and osx def define_user_task if(version == 7) @win_url = nil @win_extracted_file = nil @osx_url = nil @osx_extracted_file = nil @unix_url = nil @unix_extracted_file = nil elsif(version == 8) @win_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip" @win_extracted_file = "/Players/Debug/SAFlashPlayer.exe" @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/sa_flashplayer_8_all_debug.dmg" @osx_mounted_path = "Adobe Flash Standalone Players" @osx_extracted_file = "en/SAFlashPlayer" @unix_url = nil @unix_extracted_file = nil elsif(version == 9) @win_url = nil @win_extracted_file = nil @osx_url = nil @osx_extracted_file = nil @unix_url = nil @unix_extracted_file = nil else raise FlashPlayerError.new("It seems you are trying to use a Flash Player version (#{version}) that is not yet supported...") end super end def define super desc "Run #{@swf} file using Flash Player #{version}" task @name => [@swf] task @name do log_file = FlashLog.new.get_file begin # Don't let trust file failures break other features... FlashPlayerTrust.new(user, File.dirname(@swf)) rescue puts 'Warning, was unable to update the FlashPlayerTrust file' end File.open(log_file, 'w') do |f| f.write('') end thread = nil if(Logger.debug) thread = ThreadMock.new elsif(@user_task.is_a?(OSXRemoteFileTask) && !Logger.debug) thread = run_osx else thread = run_other end read_log(thread, log_file) end def run_osx Thread.new { system(%{open "#{clean_path(extracted_file_path)}" ./#{clean_path(@swf)}}) } # return OSXPlayerThread.new end def run_other Thread.new { sh("./#{@swf}") } end def read_log(player_thread, log_file) index = 0 if(!File.exists?(log_file)) raise UsageError.new('Unable to find the trace output log file in the expected location: ' + log_file) end while(player_thread.alive?) sleep(0.2) incr = 0 File.open(log_file, 'r') do |file| file.readlines.each do |line| incr = incr + 1 if(incr > index) puts "[trace] #{line}" index = index + 1 end end end end end end end class ThreadMock def alive? return false end end class OSXPlayerThread def initialize @alive = true end # def begin_listening # while(alive?) # sleep(0.4) # result = sh "ps -A" # end # end def alive? return @alive end end end