jan_flanders

Untitled

May 24th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ;
  2.  
  3. import flash.Lib;
  4. import flash.filesystem.File;
  5. import flash.desktop.NativeApplication;
  6. import flash.display.Sprite;
  7. import flash.Vector;
  8. import flash.events.Event;
  9. import flash.events.MouseEvent;
  10. import flash.events.InvokeEvent;
  11. import flash.events.ProgressEvent;
  12. import flash.media.Camera;
  13. import flash.events.NativeProcessExitEvent;
  14. import flash.filesystem.File;
  15. import flash.filesystem.FileMode;
  16. import flash.filesystem.FileStream;
  17. import flash.desktop.NativeProcess;
  18. import flash.desktop.NativeProcessStartupInfo;
  19. /**
  20.  * ...
  21.  * @author Jan_Flanders
  22.  */
  23.  
  24. class Main
  25. {
  26.     static function main()
  27.     {
  28.         var app = NativeApplication.nativeApplication;
  29.        
  30.         app.addEventListener(InvokeEvent.INVOKE, function(e : InvokeEvent)
  31.         {
  32.             //var camera:Camera = Camera.getCamera();
  33.             var button = makeBtn('Welcome to AIR, please click me!',onClick);
  34.             button.x = NativeApplication.nativeApplication.activeWindow.width / 2 - button.width / 2;
  35.             button.y = NativeApplication.nativeApplication.activeWindow.height / 2 - button.height;
  36.            
  37.             var file = File.applicationStorageDirectory.resolvePath("getid.bat");
  38.        
  39.             var stream = new FileStream();
  40.             stream.open(file, FileMode.WRITE );
  41.             stream.writeUTFBytes("WMIC LOGICALDISK GET DEVICEID,VOLUMESERIALNUMBER >> log.txt");
  42.             stream.close();
  43.        
  44.             Lib.current.addChild(button);          
  45.         });
  46.     }
  47.     static function onClick()
  48.     {
  49.         trace("Your app storage dir: " + File.applicationStorageDirectory.nativePath);
  50.         trace("Executing commandline: ");
  51.  
  52.         if(NativeProcess.isSupported)
  53.         {
  54.             trace("NativeProcess.isSupported");
  55.             var file:File = File.applicationDirectory;
  56.             //file = file.resolvePath("C:\\Windows\\System32\\cmd.exe");
  57.             file = file.resolvePath("C:\\Documents and Settings\\Administrator\\Application Data\\airtest32\\Local Store\\getid.bat");
  58.            
  59.             var processInfo = new NativeProcessStartupInfo();
  60.             processInfo.executable = file;
  61.             //processInfo.arguments = Vector.ofArray(["WMIC LOGICALDISK GET DEVICEID,VOLUMESERIALNUMBER"]);
  62.             //processInfo.arguments = Vector.ofArray(["getid.bat"]);
  63.             processInfo.workingDirectory = File.applicationStorageDirectory;
  64.            
  65.             var process:NativeProcess = new NativeProcess();
  66.             process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
  67.             process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
  68.             process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
  69.             process.addEventListener(NativeProcessExitEvent.EXIT, onCompileComplete);
  70.             trace("start");
  71.             process.start(processInfo);        
  72.         }
  73.         else
  74.         {
  75.             trace("Cannot compile. NativeProcess is not Supported in this mode.");
  76.         }
  77.     }
  78.     static function onCompileComplete(event):Void
  79.     {
  80.         trace(event);
  81.         event.exitCode == 0? trace("event.exitCode == 0"):trace(event.currentTarget.standardError.readUTFBytes(errorBytes));
  82.     }
  83.     static function onOutputData(event:ProgressEvent):Void
  84.     {
  85.         trace(event);
  86.         var p:NativeProcess = event.currentTarget;
  87.         trace(p.standardOutput.readUTFBytes(cast event.bytesLoaded));
  88.     }
  89.     static var errorBytes;
  90.     static function onErrorData(event:ProgressEvent):Void
  91.     {
  92.         trace(event);
  93.         errorBytes  = cast event.bytesLoaded;
  94.     }
  95.     static function inputProgressListener(event:ProgressEvent):Void
  96.     {
  97.         trace(event);
  98.     }
  99.     static function makeBtn(txt: String, onClick: Void -> Void): Sprite
  100.     {
  101.         var textField = new flash.text.TextField();
  102.         textField.text = txt;
  103.         textField.autoSize = flash.text.TextFieldAutoSize.LEFT;
  104.  
  105.         textField.x = 2;
  106.         textField.y = 2;       
  107.         textField.selectable = false;
  108.  
  109.         var btn = new Sprite();
  110.         var width = textField.width + 4;
  111.         var height = textField.height + 4;
  112.        
  113.         btn.graphics.beginFill(0xFFCC00);
  114.         btn.graphics.drawRoundRect(0, 0, width, height, 5);
  115.        
  116.         if(onClick != null)
  117.         {
  118.             btn.buttonMode = true;
  119.             btn.mouseChildren = false;
  120.             btn.useHandCursor = true;
  121.             btn.addEventListener(MouseEvent.CLICK, function (e: MouseEvent) { onClick(); } );
  122.         }
  123.        
  124.         btn.addChild(textField);
  125.  
  126.         return btn;
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment