Class: AsProject::FlashPlayer

Inherits:
RemoteFileTask show all
Defined in:
lib/tasks/flash_player.rb

Instance Attribute Summary collapse

Attributes inherited from RemoteFileTask

#osx_extracted_file, #osx_mounted_path, #osx_url, #unix_extracted_file, #unix_url, #user_task, #win_extracted_file, #win_url

Instance Method Summary collapse

Methods inherited from RemoteFileTask

#clean_path, #execute, #extracted_file_path, #user

Constructor Details

#initialize(name = :flash_player) ⇒ FlashPlayer

Returns a new instance of FlashPlayer.



11
12
13
14
15
# File 'lib/tasks/flash_player.rb', line 11

def initialize(name=:flash_player)
  @name = name
  @version = 9
  super(name)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/tasks/flash_player.rb', line 7

def name
  @name
end

#swfObject

Returns the value of attribute swf.



7
8
9
# File 'lib/tasks/flash_player.rb', line 7

def swf
  @swf
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/tasks/flash_player.rb', line 7

def version
  @version
end

Instance Method Details

#defineObject



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
124
125
126
127
128
129
# File 'lib/tasks/flash_player.rb', line 55

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 or log file failures break other features...
      FlashPlayerTrust.new(user, File.dirname(@swf))
    rescue
      puts 'Warning, was unable to update the FlashPlayerTrust file'
    end

    if(File.exists?(log_file))
      File.open(log_file, 'w') do |f|
        f.write('')
      end
    end
    
    thread = nil
    if(Logger.debug)
      thread = ThreadMock.new
    elsif(@user_task.is_a?(OSXRemoteFileTask))
      thread = run_osx
    else
      thread = run_other
    end
    read_log(thread, log_file)
  end
  
  def run_osx
    player = extracted_file_path + '/Contents/MacOS/standalone'
    swf = clean_path(@swf)

    t = Thread.new {
      IO.popen("'#{player}'") do |p|
          sleep(1.0)
          IO.popen("open #{swf}")
      end
    }
  end
  
  def run_other
    Thread.new {
      execute("./#{@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}"
            $stdout.flush
            index = index + 1
          end
        end
      end
    end
  end
end

#define_user_taskObject

TODO: Add urls and locations for versions and osx



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
# File 'lib/tasks/flash_player.rb', line 22

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/9/sa_flashplayer_9_all_debug_ub.dmg"
    @osx_mounted_path = "Adobe Flash Player Standalone"
    @osx_extracted_file = "Flash\ Player.app"
#        @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 = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_debug.exe"
    @win_extracted_file = "sa_flashplayer_9_debug.exe"
    @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg"
    @osx_mounted_path = "Adobe Flash Player Standalone"
    @osx_extracted_file = "Flash\ Player.app"
    @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

#read_log(player_thread, log_file) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/tasks/flash_player.rb', line 106

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}"
          $stdout.flush
          index = index + 1
        end
      end
    end
  end
end

#remote_task_nameObject



17
18
19
# File 'lib/tasks/flash_player.rb', line 17

def remote_task_name
  return "flash_player-#{version}"
end

#run_osxObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/tasks/flash_player.rb', line 88

def run_osx
  player = extracted_file_path + '/Contents/MacOS/standalone'
  swf = clean_path(@swf)

  t = Thread.new {
    IO.popen("'#{player}'") do |p|
        sleep(1.0)
        IO.popen("open #{swf}")
    end
  }
end

#run_otherObject



100
101
102
103
104
# File 'lib/tasks/flash_player.rb', line 100

def run_other
  Thread.new {
    execute("./#{@swf}")
  }
end