require 'player_fetcher' require 'ftools' module AsProject class PathFinder < TemplateResolver attr_accessor :execution_dir def initialize(execution_dir=nil) super() if(execution_dir.nil?) @execution_dir = Dir.pwd else @execution_dir = execution_dir end @current_project = nil @user = create_user end def flash_player_home return @user.flash_player_home end def flash_player_log return @user.flash_player_log end def flash_player_config return @user.flash_player_config end def flash_player_config_content return @user.flash_player_config_content end def flash_player_debug(version) return @user.flash_player_debug(version) end def flash_player_trust return @user.flash_player_trust end def gem_asproject_home parent = File.dirname(File.dirname(__FILE__)) return File.expand_path(parent) end def user_library return @user.library end def user_home return @user.home end def user_asproject_home return @user.asproject_home end def current_project=(dir) @current_project = dir end # Don't store the 'inspected' current_project # Only store it if the value was set from # outside def current_project if(@current_project.nil?) return find_project(@execution_dir) else return @current_project end end def get_children(dir) list = [] if(dir.nil?) return list end Dir.open(dir).each do |child| if(!AsProject.ignore_file? child) list << child end end return list end # Collect and return all available templates from: # (PROJECT_PATH)/config/templates/(TYPE)/ # (USER_HOME)/(ASPROJECT_HOME)/templates/ # (ASPROJECT_GEM_HOME)/templates def get_available_templates(type) project_templates = get_children(get_project_template(type, '')) user_templates = get_children(get_user_template(type, '')) gem_templates = get_children(get_gem_template(type, '')) result = [] project_templates.each do |template| result << template end user_templates.each do |template| if(!result.index(template)) result << template end end gem_templates.each do |template| if(!result.index(template)) result << template end end return result end # @type: 'class' or 'project' # @name: 'as3', 'mxml', 'fb2', or user-created folder name # Represents folders inside of the appropriate template type dir def get_template(type, name) template = get_project_template(type, name) if(template.nil?) template = get_user_template(type, name) end if(template.nil?) template = get_gem_template(type, name) end return template end def get_project_template(type, name) begin if(@execution_dir.nil?) dir = Dir.pwd else dir = @execution_dir end project = find_project(dir) template = File.join(project, 'config', 'templates', type, name) if(File.exists? template) return template else return nil end rescue return nil end end def get_user_template(type, name) template = File.expand_path(File.join(user_asproject_home, 'templates', type, name)) if(File.exists? template) return template else return nil end end def get_gem_template(type, name) template = File.expand_path(File.join(gem_asproject_home, 'templates', type, name)) if(File.exists? template) return template end raise ProjectError.new('Requested template not found at ' + template) end private def find_project(dir) if(is_project? dir) return dir elsif(File.dirname(dir) == dir) raise ProjectError.new('AsProject::PathFinder reached the root of the file system without finding a valid project.') else find_project(File.dirname(dir)) end end # Why wouldn't RDT let me spread this if statement # Over multiple lines? private def is_project?(dir) return (has_config_yaml?(dir) || has_eclipse_project?(dir) || has_src_eclipse_project?(dir) || has_src_and_test?(dir)) end def has_config_yaml?(dir) return File.exists?(File.join(dir, 'config', 'asproject.yaml')) end def has_eclipse_project?(dir) return File.exists?(File.join(dir, '.project')) end def has_src_eclipse_project?(dir) return File.exists?(File.join(dir, 'src', '.project')) end def has_src_and_test?(dir) return File.directory?(File.join(dir, 'src')) && File.directory?(File.join(dir, 'test')) end private def create_user os = Platform::OS impl = Platform::IMPL if(os == :win32 && impl == :vista) @user = VistaUser.new elsif(os == :win32) @user = WinUser.new elsif(os == :unix && impl == :cygwin) @user = CygwinUser.new elsif(os == :unix && impl == :macosx) @user = OSXUser.new else @user = User.new end end end ############################# # User class class User def initialize @flash_player_7_url = nil @flash_player_8_url = nil @flash_player_9_url = nil @zip_target = "" @default_asproject = '.asproject' @flash_log_file_name = 'flashlog.txt' end def asproject_home return get_or_create(File.join(home, @default_asproject)) end def library return home end def flash_player_config return File.join(home, 'mm.cfg') end def flash_player_config_content return < ex if File::ALT_SEPARATOR "C:\\" else "/" end end end def flash_player_home raise UsageError.new('Not sure where flash_player_home should be on systems other than Win/Mac - please let us know so that we can update this script...') end def file_exists?(file) return File.exists?(file) end def get_or_create dir if(!file_exists? dir) Dir.mkdir dir end return dir end end class OSXUser < User @@LIBRARY = 'Library' def initialize super @flash_player_7_url = "/pub/flashplayer/updaters/7/sa_flashplayer_7_all_debug.dmg" @flash_player_8_url = "/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip" @flash_player_9_url = "/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg" @zip_target = File.join('Players', 'Debug', 'SAFlashPlayer.dmg') @flash_player_8_target = File.join('Players', 'Debug', 'SAFlashPlayer.exe') @osx_asproject = 'AsProject' end def flash_player_home return File.join(library, 'Preferences', 'Macromedia', 'Flash Player') end def library lib = File.join(home, @@LIBRARY) if(File.exists?(lib)) return lib else return super end end def asproject_home if(library == home) return super end ap_home = File.join(library, @osx_asproject) get_or_create(ap_home) end end class WinUser < User @@LOCAL_SETTINGS = "Local\ Settings" @@APPLICATION_DATA = "Application\ Data" def initialize super @flash_player_7_url = "/pub/flashplayer/updaters/7/flash_player_update3_mx2004_win.zip" @flash_player_8_url = "/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip" @flash_player_9_url = "/pub/flashplayer/updaters/9/sa_flashplayer_9_debug.exe" @zip_target = File.join('Players', 'Debug', 'SAFlashPlayer.exe') @win_asproject = 'AsProject' end def home usr = super if(usr.index "My Documents") usr = File.dirname(usr) end return usr end def flash_player_home return File.join(home, @@APPLICATION_DATA, 'Macromedia', 'Flash Player') end def flash_player_path(version) return File.join(asproject_home, 'players', 'FlashPlayer' + version.to_s + '.exe') end def flash_player_trust return File.join(flash_player_home, '#Security', 'FlashPlayerTrust') end def library # For some reason, my homepath returns inside 'My Documents'... application_data = File.join(home, @@LOCAL_SETTINGS, @@APPLICATION_DATA) if(File.exists?(application_data)) return application_data else return super end end def asproject_home if(library == home) return super end ap_home = File.join(library, @win_asproject); return get_or_create(ap_home) end end class CygwinUser < WinUser def flash_player_config_content content = super windowized = File.join("#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}", 'Application Data', 'Macromedia', 'Flash Player', 'Logs', 'flashlog.txt') content.gsub!(flash_player_log, windowized) end end class VistaUser < WinUser def home profile = ENV['USERPROFILE'] if(profile) return profile end return super end end end