Monday, April 07, 2008

Blag's Flex 3 Compiler!!!


Luego de algunos cuantos ajustes...Mi compilador de Flex 3 está terminado...No como ejecutable -:( Pero de todos modos funciona bien -:D
Veamos el código fuente...

require 'rubygems'
require 'wx'

Btn_ChooseFolder = 1000
Btn_CompileSWF = 1001
Btn_TestAIR = 1002
Btn_CompileAIR = 1003
$config_file = File.dirname(__FILE__) << "\\Flex_Dir.txt"
$config = IO.readlines($config_file)
SWF = $config[0] + "amxmlc.bat"
AIRTest = $config[0] + "adl.exe"
AIR = $config[0] + "adt.bat"

$Files = Array.new
$Flex_Files = Array.new
$App_Files = Array.new
$XML_File = Array.new
$exits_xml = false

class Blag_Flex < Wx::Frame
def initialize(title)
super(nil, :title => title, :size => [ 400, 300 ])

panel = Wx::Panel.new(self)
m_Folder = Wx::StaticText.new(panel, -1, "Project Folder",Wx::Point.new(10, 12),Wx::Size.new(80, 20))
@mFolder = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 10),Wx::Size.new(170, 20))
#----------------------------------------------------------------------------------------------------------
m_Id = Wx::StaticText.new(panel, -1, "Id",Wx::Point.new(20, 32),Wx::Size.new(80, 20))
@mId = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 30),Wx::Size.new(170, 20))
m_Version = Wx::StaticText.new(panel, -1, "Version",Wx::Point.new(20, 52),Wx::Size.new(80, 20))
@mVersion = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 50),Wx::Size.new(170, 20))
m_Filename = Wx::StaticText.new(panel, -1, "FileName",Wx::Point.new(20, 72),Wx::Size.new(80, 20))
@mFilename = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 70),Wx::Size.new(170, 20))
m_Content = Wx::StaticText.new(panel, -1, "Content",Wx::Point.new(20, 92),Wx::Size.new(80, 20))
@mContent = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 90),Wx::Size.new(170, 20))
m_Visible = Wx::StaticText.new(panel, -1, "Visible",Wx::Point.new(20, 112),Wx::Size.new(80, 20))
@mVisible = Wx::TextCtrl.new(panel, -1, "true",Wx::Point.new(100, 110),Wx::Size.new(170, 20))
m_SystemChrome = Wx::StaticText.new(panel, -1, "SystemChrome",Wx::Point.new(20, 132),Wx::Size.new(80, 20))
@mSystemChrome = Wx::TextCtrl.new(panel, -1, "none",Wx::Point.new(100, 130),Wx::Size.new(170, 20))
m_Transparent = Wx::StaticText.new(panel, -1, "Transparent",Wx::Point.new(20, 152),Wx::Size.new(80, 20))
@mTransparent = Wx::TextCtrl.new(panel, -1, "true",Wx::Point.new(100, 150),Wx::Size.new(170, 20))
m_Width = Wx::StaticText.new(panel, -1, "Width",Wx::Point.new(20, 172),Wx::Size.new(80, 20))
@mWidth = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 170),Wx::Size.new(170, 20))
m_Height = Wx::StaticText.new(panel, -1, "height",Wx::Point.new(20, 192),Wx::Size.new(80, 20))
@mHeight = Wx::TextCtrl.new(panel, -1, "",Wx::Point.new(100, 190),Wx::Size.new(170, 20))
#----------------------------------------------------------------------------------------------------------
btnChooseFolder = Wx::Button.new(panel, Btn_ChooseFolder, "Choose", Wx::Point.new(280, 10),Wx::Size.new(80, 20))
btnCompileSWF = Wx::Button.new(panel, Btn_CompileSWF, "Compile SWF", Wx::Point.new(10, 220),Wx::Size.new(80, 20))
btnTestAIR = Wx::Button.new(panel, Btn_TestAIR, "Test AIR", Wx::Point.new(100, 220),Wx::Size.new(80, 20))
btnCompileAIR = Wx::Button.new(panel, Btn_CompileAIR, "Compile AIR", Wx::Point.new(190, 220),Wx::Size.new(80, 20))

evt_button(Btn_ChooseFolder) {|event| onChooseFolder(event,panel) }
evt_button(Btn_CompileSWF) {|event| onCompileSWF(event) }
evt_button(Btn_TestAIR) {|event| onTestAIR(event) }
evt_button(Btn_CompileAIR) {|event| onCompileAIR(event) }
end
end

def GenerateXML()
$XML_File.push("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
$XML_File.push("<application xmlns=\"http://ns.adobe.com/air/application/1.0\">")
$XML_File.push("<id>" + @mId.get_value + "</id>")
$XML_File.push("<version>" + @mVersion.get_value + "</version>")
$XML_File.push("<filename>" + @mFilename.get_value + "</filename>")
$XML_File.push("<initialWindow>")
$XML_File.push("<content>" + @mContent.get_value + ".swf</content>")
$XML_File.push("<visible>" + @mVisible.get_value + "</visible>")
$XML_File.push("<systemChrome>" + @mSystemChrome.get_value + "</systemChrome>")
$XML_File.push("<transparent>" + @mTransparent.get_value + "</transparent>")
$XML_File.push("<width>" + @mWidth.get_value + "</width>")
$XML_File.push("<height>" + @mHeight.get_value + "</height>")
$XML_File.push("</initialWindow>")
$XML_File.push("</application>")

$Dir_Text = @mFolder.get_value
$Dir_Text = $Dir_Text << "\\" << @mFilename.get_value << "-app.xml"

$output = File.new($Dir_Text,"w")

$XML_File.each {|line| $output.write("#{line}\n")}
$output.close
end

def onChooseFolder(event,panel)
dir_home = Wx::get_home_dir()

dialog = Wx::DirDialog.new(panel, "Choose a folder", dir_home)

if dialog.show_modal() == Wx::ID_OK
@mFolder.set_value(dialog.get_path())
end
end

def onCompileSWF(event)
$Dir_Text = @mFolder.get_value
Dir.foreach($Dir_Text) {|x| $Files.push(x)}

for $file in $Files
$long = $file.length - 4
$long_xml = $file.length - 8
if($file[$long,4] == 'mxml')
$file = $Dir_Text << "\\" << $file
$Dir_Text = @mFolder.get_value
$Flex_Files.push($file)
end
if($file[$long_xml,8] == '-app.xml')
$Dir_Text = @mFolder.get_value
$file = $Dir_Text << "\\" << $file
$Dir_Text = @mFolder.get_value
$App_Files.push($file)
$exits_xml = true
end
end

$Cert = @mFolder.get_value
$Cert = $Cert << "\\sampleCert.pfx"
system(AIR,"-certificate","-cn","SelfSigned","1024-RSA",$Cert,"samplePassword")

for $flex_file in $Flex_Files
system(SWF,"-use-network=false",$flex_file)
end

if($exits_xml == false)
GenerateXML()
end
end

def onTestAIR(event)
if($App_Files.empty? != true)
for $app_file in $App_Files
system(AIRTest,$app_file)
end
else
$Dir_Text = @mFolder.get_value
Dir.foreach($Dir_Text) {|x| $Files.push(x)}

for $file in $Files
$long_xml = $file.length - 8
if($file[$long_xml,8] == '-app.xml')
$App_Name = $file[$long_xml,8]
$Dir_Text = @mFolder.get_value
$file = $Dir_Text << "\\" << $file
$Dir_Text = @mFolder.get_value
$App_Files.push($file)
end
end
for $app_file in $App_Files
system(AIRTest,$app_file)
end
end
end

def onCompileAIR(event)
if(@mFilename.empty? == true)
$Dir_Text = @mFolder.get_value
Dir.foreach($Dir_Text) {|x| $Files.push(x)}

for $file in $Files
$long_xml = $file.length - 8
if($file[$long_xml,8] == '-app.xml')
$App_Name = $file[$long_xml,8]
$Dir_Text = @mFolder.get_value
$file = $Dir_Text << "\\" << $file
$Dir_Text = @mFolder.get_value
$App_Files.push($file)
end
end
for $app_file in $App_Files
$file = IO.readlines($app_file)
$pos = $file[4].rindex("<") - 1
$str_file = $file[4]
$str_file = $str_file[10..$pos]
$FileName = $str_file

$App_Name_AIR = $FileName + ".air"
$Dir_Text = $FileName + "-app.xml"
$App_Name_SWF = $FileName + ".swf"

$Cert = @mFolder.get_value
$Cert = $Cert << "\\sampleCert.pfx"
Dir.chdir(@mFolder.get_value)
system(AIR,"-package","-storetype","pkcs12","-storepass","samplePassword","-keystore",$Cert,$App_Name_AIR,
$Dir_Text,$App_Name_SWF)
end
else
$App_Name_AIR = @mFilename.get_value + ".air"
$Dir_Text = @mFilename.get_value + "-app.xml"
$App_Name_SWF = @mFilename.get_value + ".swf"
$Cert = @mFolder.get_value
$Cert = $Cert << "\\sampleCert.pfx"
Dir.chdir(@mFolder.get_value)
system(AIR,"-package","-storetype","pkcs12","-storepass","samplePassword","-keystore",$Cert,$App_Name_AIR,
$Dir_Text,$App_Name_SWF)
end
end

Wx::App.run do
frame = Blag_Flex.new("Blag's Flex 3 Compiler")
frame.show
end


El programa necesita de una archivo llamado Flex_Dir que contenga la ruta de instalación del Flex 3 SDK


C:\\Programacion\\flex_sdk_3\\bin\\


Ahora, las imágenes -:)







Saludos,

Blag.

No comments: