A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Embed exe file from swf to write to local directory?

  1. #1
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15

    Embed exe file from swf to write to local directory?

    Hello Ladies & Sirs,

    I want to try to write embedded files from swf to real files like Installer or PackageInstaller.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    						xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute">
    	
    	<fx:Script>
    		<![CDATA[
    			
    			[Embed(source="../Assets/ExampleApp.exe", mimeType="application/octet-stream")]
    			private var _appBinary:Class;
    			private var _appFile:File
    			private var _installAppStream:FileStream;
    			
    			private var _appFolder:File;
    			private var _installDirectory:File
    			
    			private var timer:Timer;
    			
    			protected function btnCHoose_clickHandler(event:MouseEvent):void
    			{
    				_installDirectory = new File();
    				_installDirectory.addEventListener(Event.SELECT, installPathSelected);
    				_installDirectory.browseForDirectory("Choose an install directory");
    			}
    			
    			private function installPathSelected(evt:Event):void
    			{
    				txtChoose.text = _installDirectory.nativePath;
    				btnInstall.enabled = true;
    				pgbInstalling.enabled = true;
    				
    			}
    			
    			protected function onInstallProgress(event:MouseEvent):void
    			{
    				btnCHoose.enabled = false;
    				txtChoose.enabled = false;
    				btnInstall.enabled = false;
    				
    				timer = new Timer(10);
    				timer.addEventListener(TimerEvent.TIMER, timer_timer);
    			}
    			
    			private function timer_timer(evt:TimerEvent):void {
    				pgbInstalling.setProgress(pgbInstalling.value + 1, _appFile.size);
    			}
    			
    			
    			private function onCompleted(evt:Event):void
    			{
    				_appFolder = new File();
    				_appFolder = _installDirectory.resolvePath("Example Application");
    				if(_appFolder.exists)
    				{
    					_appFolder.createDirectory();
    				}
    				
    				_appFile = new File();
    				_appFile = _appFolder.resolvePath(_appFile.nativePath);
    				if(_appFile.exists)
    				{
    					_appFile = File.createTempFile();
    					_installAppStream = new FileStream();
    					_installAppStream.open(_appFile, FileMode.WRITE);
    					
    					var ba:ByteArray = new _appBinary();
    					_installAppStream.writeBytes(ba);
    					_installAppStream.close();
    				}
    				pgbInstalling.addEventListener(Event.COMPLETE, onCompleted);
    				
    				timer.stop();
    				pgbInstalling.enabled = false;
    				
    				btnClose.enabled = true;
    				btnRunApp.enabled = true;
    			}
    			
    		]]>
    	</fx:Script>
    	
    	<fx:Declarations>
    		<!-- Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
    	</fx:Declarations>
    	<mx:Label left="10" top="10" fontSize="20" text="Welcome Example Application Installer"/>
    	<mx:Label left="10" top="47" text="Path to Installation Directory"/>
    	<mx:TextInput id="txtChoose" left="10" right="88" top="76"/>
    	<mx:Button id="btnCHoose" right="10" top="77" label="Choose"
    			   click="btnCHoose_clickHandler(event)"/>
    	<mx:Label left="10" top="135" text="Progress of Installation"/>
    	<mx:ProgressBar id="pgbInstalling" left="10" right="88" top="164" height="22" enabled="false"
    					labelPlacement="center" source="ba"/>
    	<mx:Button id="btnInstall" right="10" top="165" label="Install"
    			   click="onInstallProgress(event)" enabled="false"/>
    	<mx:Label left="10" top="233" text="Finish can you close or start external Example Application"/>
    	<mx:Button id="btnClose" top="262" label="Close" enabled="false" horizontalCenter="-36"/>
    	<mx:Button id="btnRunApp" top="262" label="Run Application" enabled="false" horizontalCenter="59"/>
    </mx:WindowedApplication>
    But it doesn't show if i click and i wait for to write by ba with _appBinary:Class Why does it not work?

    Or how do i fix it?

    Click here Fxp for Flash Builder 4.6 / 4.7 via DropBox

    Thanks

  2. #2
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15
    Hello i have fixed it yeah i don't know becasue same xml, swf and pictures are different - it doesn't work for only class into ByteArray.

    Code solution:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
    						xmlns:mx="library://ns.adobe.com/flex/mx"
    						layout="absolute" showStatusBar="false">
    	 <fx:Script>
    		<![CDATA[
    			import mx.core.ByteArrayAsset;
    			
    			[Embed(source="../Assets/ExampleApp.exe", mimeType="application/octet-stream")]
    			private var _appBinary:Class;
    			
    			[Embed(source="../Assets/Adobe AIR.dll", mimeType="application/octet-stream")]
    			private var _appAdobeAirCaptive:Class;
    			
    			[Embed(source="../Assets/signatures.xml", mimeType="application/octet-stream")]
    			private var _appSignatures:Class;
    			
    			[Embed(source="../Assets/application.xml", mimeType="application/octet-stream")]
    			private var _appApplication:Class;
    			
    			private var _installAppStream:FileStream;
    			
    			private var _appFolder:File;
    			private var _appAdobeAirDirectory:File;
    			
    			private var _appAdobeAirCapLibrary:File;
    			private var _appFile:File;
    			private var _appSWFFile:File;
    			private var _installDirectory:File
    			
    			protected function btnCHoose_clickHandler(event:MouseEvent):void
    			{
    				_installDirectory = new File();
    				_installDirectory.addEventListener(Event.SELECT, installPathSelected);
    				_installDirectory.browseForDirectory("Choose an install directory");
    			}
    			
    			private function installPathSelected(evt:Event):void
    			{
    				txtChoose.text = _installDirectory.nativePath;
    				btnInstall.enabled = true;
    			}
    			
    			protected function onInstallProgress(event:MouseEvent):void
    			{
    				btnCHoose.enabled = false;
    				txtChoose.enabled = false;
    				btnInstall.enabled = false;
    				
    				_appFolder = new File();
    				_appFolder = _installDirectory.resolvePath("Example Application");
    				_appFolder.createDirectory();
    				if(_appFolder.exists)
    				{
    					_appFile = _appFolder.resolvePath("ExampleApp.exe");
    					_installAppStream = new FileStream();
    					_installAppStream.open(_appFile, FileMode.WRITE);
    
    					_installAppStream.writeBytes(new _appBinary());
    					_installAppStream.close();
    					
    					_appSWFFile = _appFolder.resolvePath("ExampleApp.swf");
    					_installAppStream.open(_appSWFFile, FileMode.WRITE);
    					
    					_installAppStream.writeBytes(new EmbedSWF());
    					_installAppStream.close();
    					
    					_appAdobeAirDirectory= new File();
    					_appAdobeAirDirectory = _appFolder.resolvePath("Adobe AIR\\Versions\\1.0");
    					_appAdobeAirDirectory.createDirectory();
    					if(_appAdobeAirDirectory.exists)
    					{
    						_appAdobeAirCapLibrary = _appAdobeAirDirectory.resolvePath("Adobe Air.dll");
    						_installAppStream.open(_appAdobeAirCapLibrary, FileMode.WRITE);
    						
    						_installAppStream.writeBytes(new _appAdobeAirCaptive());
    						_installAppStream.close();
    					}
    					
    					// Meta-INF Directory:
    					var md:File = _appFolder.resolvePath("META-INF");
    					md.createDirectory();
    					if(md.exists)
    					{
    						var signaturesFile:File = md.resolvePath("signatures.xml");
    						_installAppStream.open(signaturesFile, FileMode.WRITE);
    						
    						var signaturesXML:XML = new XML(new _appSignatures());
    						_installAppStream.writeUTFBytes(signaturesXML);
    						_installAppStream.close();
    						
    						// AIR Directory:
    						var ad:File = md.resolvePath("AIR");
    						ad.createDirectory();
    						if(ad.exists)
    						{
    							var applicationFile:File = ad.resolvePath("application.xml");
    							_installAppStream.open(applicationFile, FileMode.WRITE);
    							
    							var applicationXML:XML = new XML(new _appApplication());
    							_installAppStream.writeUTFBytes(applicationXML);
    							_installAppStream.close();
    						}
    					}
    					
    				}
    				
    				btnClose.enabled = true;
    				btnRunApp.enabled = true;
    			}
    			
    			protected function onClose(event:MouseEvent):void
    			{
    				this.nativeWindow.close();
    			}
    			
    			protected function onRunApp(event:MouseEvent):void
    			{
    				this.nativeWindow.close();
    				var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    				npsi.executable = _installDirectory.resolvePath("Example Application\\ExampleApp.exe");
    				
    				var np:NativeProcess = new NativeProcess();
    				np.start(npsi);
    			}
    			
    		]]>
    	</fx:Script>
    	
    	<fx:Declarations>
    		<!-- Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
    	</fx:Declarations>
    	<mx:Label left="10" top="10" fontSize="20" text="Welcome Example Application Installer"/>
    	<mx:Label left="10" top="47" text="Path to Installation Directory"/>
    	<mx:TextInput id="txtChoose" left="10" right="88" top="76"/>
    	<mx:Button id="btnCHoose" right="10" top="77" label="Choose"
    			   click="btnCHoose_clickHandler(event)"/>
    	<mx:Label left="10" top="135" text="Progress of Copy / Install"/>
    	<mx:Button id="btnInstall" right="10" top="165" label="Install"
    			   click="onInstallProgress(event)" enabled="false"/>
    	<mx:Label left="10" top="233" text="Finish can you close or start external Example Application"/>
    	<mx:Button id="btnClose" top="262" label="Close" click="onClose(event)"
    			   enabled="false" horizontalCenter="-36"/>
    	<mx:Button id="btnRunApp" top="262" label="Run Application" click="onRunApp(event)"
    			   enabled="false" horizontalCenter="59"/>
    	
    </mx:WindowedApplication>
    And i packed into BoxedApp Standalone Air Captive Application

    Select Install Directory


    Click Install it
    And It will write 5 files into Install Directory


    Close or Run an installed application?


    Hurry Air Captive Application was installed by BoxedApp-used Air Captive Application

    Bonus tip:
    We want build own custom installer like non Adobe Air Installer.

    PS: Don't forget to download BoxedApp Packer
    Important i will explain about BoxedApp Packer


    Input is Adobe Air Captive App ( as Custom Installer )
    Output is packed standalone Air Packed Application
    Directories and Files root directory of Adobe Air Captive Contents

    PS: Don't forget for Directory Adobe AIr/Versions/1.0/Adobe Air.dll used compressing upx by UPX Easy GUI Why do we need smallest file for Adobe Air.dll because Important for smallest download by Mobile Data like Surfstick or mobile. That is why i want support smallest file size.
    And Directory Resources don't need and remove it and after original copy of compressed dll like Adobe Air.dll~ you can delete.

    Url: BoxedApp Packer
    UPX Easy GUI

    Example Application by me

    PS: I forget for mnifest mt as access right as Administrator ( If you download and rightclick to "Run As Admin" if you have own partition "C:\" and it not readable. you need to run as administrator. Thanks!

    Good luck and enjoy happy coding as custom installation with Adobe Captive Air
    Last edited by SourceSKyBoxer; 08-30-2015 at 02:50 PM.

  3. #3
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15
    Where is install directory of Example Application?


    This is original Adobe Air Captive Content

    Happy coding and publish your own custom installer

    Good idea they are right that we need uninstaller? I must to build ane as registry to installpath was marked means uninstaller will find correct installpath.

    I found Adobe Air Registry Modifer like Net Framework Installer Preloader of Adobe Air Captive Custominstaller

    Air Registry Modifer

    Yeah i am very happy because they need custom installer with Key or Serial unlocker like own Software with correct key/Serial like custom installer

    Thanks for understanding and supporting
    Attached Images Attached Images

  4. #4
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15
    Updated: Adobe Air custom installer creates shortcut

    Full code if you understand how do you create

    P.S. Sorry for EmbedSWF i didn't add code that is why embedswf.as

    EmbedSWF.as
    Code:
    package
    {
    	import mx.core.ByteArrayAsset;
    	
    	[Embed(source="../Assets/ExampleApp.swf", mimeType="application/octet-stream")]
    	public class EmbedSWF extends ByteArrayAsset
    	{
    		public function EmbedSWF(){}
    	}
    }
    MainInstaller.mxml:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
    						xmlns:mx="library://ns.adobe.com/flex/mx"
    						layout="absolute" showStatusBar="false" creationComplete="onCreatingComplete(event)">
    	 <fx:Script>
    		<![CDATA[
    			import mx.core.ByteArrayAsset;
    			import mx.events.FlexEvent;
    			
    			[Embed(source="../Assets/ExampleApp.exe", mimeType="application/octet-stream")]
    			private var _appBinary:Class;
    			
    			[Embed(source="../Assets/Adobe AIR.dll", mimeType="application/octet-stream")]
    			private var _appAdobeAirCaptive:Class;
    			
    			[Embed(source="../Assets/signatures.xml", mimeType="application/octet-stream")]
    			private var _appSignatures:Class;
    			
    			[Embed(source="../Assets/application.xml", mimeType="application/octet-stream")]
    			private var _appApplication:Class;
    			
    			[Embed(source="../Assets/makeShortCut", mimeType="application/octet-stream")]
    			private var makeShortCutJS:Class;
    			
    			private var _installAppStream:FileStream;
    			
    			private var _appFolder:File;
    			private var _appAdobeAirDirectory:File;
    			
    			private var _appAdobeAirCapLibrary:File;
    			private var _appFile:File;
    			private var _appSWFFile:File;
    			private var _makeShortFile:File;
    			private var _installDirectory:File
    			
    			protected function btnCHoose_clickHandler(event:MouseEvent):void
    			{
    				_installDirectory = new File();
    				_installDirectory.addEventListener(Event.SELECT, installPathSelected);
    				_installDirectory.browseForDirectory("Choose an install directory");
    			}
    			
    			private function installPathSelected(evt:Event):void
    			{
    				txtChoose.text = _installDirectory.nativePath;
    				btnInstall.enabled = true;
    			}
    			
    			protected function onInstallProgress(event:MouseEvent):void
    			{
    				btnCHoose.enabled = false;
    				txtChoose.enabled = false;
    				btnInstall.enabled = false;
    				
    				_appFolder = new File();
    				_appFolder = _installDirectory.resolvePath("Example Application");
    				_appFolder.createDirectory();
    				if(_appFolder.exists)
    				{
    					_makeShortFile = LocalAppTempDirectory.resolvePath("temp.js");
    					_installAppStream = new FileStream();
    					_installAppStream.open(_makeShortFile, FileMode.WRITE);
    					
    					var makeShortJS:String = new String(new makeShortCutJS());
    					_installAppStream.writeUTFBytes(makeShortJS);
    					_installAppStream.close();
    					
    					_appFile = _appFolder.resolvePath("ExampleApp.exe");
    					_installAppStream.open(_appFile, FileMode.WRITE);
    
    					_installAppStream.writeBytes(new _appBinary());
    					_installAppStream.close();
    					
    					var __shortcut:File = File.desktopDirectory.resolvePath("Example Application");
    					createShortcut(_appFile, __shortcut);
    					
    					_appSWFFile = _appFolder.resolvePath("ExampleApp.swf");
    					_installAppStream.open(_appSWFFile, FileMode.WRITE);
    					
    					_installAppStream.writeBytes(new EmbedSWF());
    					_installAppStream.close();
    					
    					_appAdobeAirDirectory= new File();
    					_appAdobeAirDirectory = _appFolder.resolvePath("Adobe AIR\\Versions\\1.0");
    					_appAdobeAirDirectory.createDirectory();
    					if(_appAdobeAirDirectory.exists)
    					{
    						_appAdobeAirCapLibrary = _appAdobeAirDirectory.resolvePath("Adobe Air.dll");
    						_installAppStream.open(_appAdobeAirCapLibrary, FileMode.WRITE);
    						
    						_installAppStream.writeBytes(new _appAdobeAirCaptive());
    						_installAppStream.close();
    					}
    					
    					// Meta-INF Directory:
    					var md:File = _appFolder.resolvePath("META-INF");
    					md.createDirectory();
    					if(md.exists)
    					{
    						var signaturesFile:File = md.resolvePath("signatures.xml");
    						_installAppStream.open(signaturesFile, FileMode.WRITE);
    						
    						var signaturesXML:XML = new XML(new _appSignatures());
    						_installAppStream.writeUTFBytes(signaturesXML);
    						_installAppStream.close();
    						
    						// AIR Directory:
    						var ad:File = md.resolvePath("AIR");
    						ad.createDirectory();
    						if(ad.exists)
    						{
    							var applicationFile:File = ad.resolvePath("application.xml");
    							_installAppStream.open(applicationFile, FileMode.WRITE);
    							
    							var applicationXML:XML = new XML(new _appApplication());
    							_installAppStream.writeUTFBytes(applicationXML);
    							_installAppStream.close();
    						}
    					}
    				}
    				
    				btnClose.enabled = true;
    				btnRunApp.enabled = true;
    			}
    			
    			protected function onClose(event:MouseEvent):void
    			{
    				this.nativeWindow.close();
    				if(_makeShortFile.exists)
    				{
    					_makeShortFile.deleteFile();
    				}
    			}
    			
    			protected function onRunApp(event:MouseEvent):void
    			{
    				this.nativeWindow.close();
    				if(_makeShortFile.exists)
    				{
    					_makeShortFile.deleteFile();
    				}
    				var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    				npsi.executable = _installDirectory.resolvePath("Example Application\\ExampleApp.exe");
    				
    				var np:NativeProcess = new NativeProcess();
    				np.start(npsi);
    			}
    			
    			public function createShortcut(target:File, shortcut:File):void {
    				if (NativeProcess.isSupported) { // Note: this is only true under extendedDesktop profile
    					var shortcutInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    					
    					// Location of the Windows Scripting Host executable
    					shortcutInfo.executable = new File(System32Directory.nativePath+File.separator+"wscript.exe");
    					
    					// Argument 1: script to execute
    					shortcutInfo.arguments.push(LocalAppTempDirectory.resolvePath("temp.js").nativePath);
    					
    					// Argument 2: target
    					shortcutInfo.arguments.push("/target:" + target.nativePath);
    					
    					// Argument 3: shortcut
    					shortcutInfo.arguments.push("/shortcut:" + shortcut.nativePath);
    					
    					var mkShortcutProcess:NativeProcess = new NativeProcess();
    					mkShortcutProcess.start(shortcutInfo);
    					
    				}
    			}
    			
    			private function get System32Directory():File
    			{
    				var _sys32dir:File = File.desktopDirectory;
    				var _backToRootDir:String = File.desktopDirectory.nativePath.substr(0,3);
    				
    				var windowsPath:String = "Windows";
    				var system32Path:String = "System32";
    				
    				_sys32dir = _sys32dir.resolvePath(_backToRootDir+windowsPath+File.separator+system32Path);
    				
    				return _sys32dir;
    			}
    			
    			private function get LocalAppTempDirectory():File
    			{
    				var _locAppTempDir:File = File.userDirectory;
    				
    				var appDataPath:String = "AppData";
    				var localPath:String = "Local";
    				var tempPath:String = "Temp";
    				
    				_locAppTempDir = _locAppTempDir.resolvePath(appDataPath+File.separator+localPath+File.separator+tempPath);
    				
    				return _locAppTempDir
    			}
    			
    			protected function onCreatingComplete(event:FlexEvent):void
    			{
    				txtChoose.text = System32Directory.nativePath+File.separator+"wscript.exe"
    			}
    			
    		]]>
    	</fx:Script>
    	
    	<fx:Declarations>
    		<!-- Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
    	</fx:Declarations>
    	<mx:Label left="10" top="10" fontSize="20" text="Welcome Example Application Installer"/>
    	<mx:Label left="10" top="47" text="Path to Installation Directory"/>
    	<mx:TextInput id="txtChoose" left="10" right="88" top="76"/>
    	<mx:Button id="btnCHoose" right="10" top="77" label="Choose"
    			   click="btnCHoose_clickHandler(event)"/>
    	<mx:Label left="10" top="135" text="Progress of Copy / Install"/>
    	<mx:Button id="btnInstall" right="10" top="165" label="Install"
    			   click="onInstallProgress(event)" enabled="false"/>
    	<mx:Label left="10" top="233" text="Finish can you close or start external Example Application"/>
    	<mx:Button id="btnClose" top="262" label="Close" click="onClose(event)"
    			   enabled="false" horizontalCenter="-36"/>
    	<mx:Button id="btnRunApp" top="262" label="Run Application" click="onRunApp(event)"
    			   enabled="false" horizontalCenter="59"/>
    	
    </mx:WindowedApplication>
    makeShortCut ( without ending because Embed won't work that javascript error - just fix like linux binary or mac os x shell binary like mxmlc compiler doesn't recognize to fake binary.)
    Code:
    // makeShortCut
    
    var WshShell = new ActiveXObject("WScript.Shell");
    var oShellLink = WshShell.CreateShortcut(WScript.Arguments.Named("shortcut") + ".lnk");
    oShellLink.TargetPath = WScript.Arguments.Named("target");
    oShellLink.WindowStyle = 1;
    oShellLink.Save();
    And try again and it gets nice result


    Yeah it works like custom software installer
    Attached Images Attached Images

  5. #5
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15

  6. #6
    Junior Member
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    15
    Sorry my website was down and move d to my new website:
    http://sourceskyboxer.byethost16.com...er?ckattempt=1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center