Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ;
- import flash.Lib;
- import flash.filesystem.File;
- import flash.desktop.NativeApplication;
- import flash.display.Sprite;
- import flash.Vector;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.events.InvokeEvent;
- import flash.events.ProgressEvent;
- import flash.media.Camera;
- import flash.events.NativeProcessExitEvent;
- import flash.filesystem.File;
- import flash.filesystem.FileMode;
- import flash.filesystem.FileStream;
- import flash.desktop.NativeProcess;
- import flash.desktop.NativeProcessStartupInfo;
- /**
- * ...
- * @author Jan_Flanders
- */
- class Main
- {
- static function main()
- {
- var app = NativeApplication.nativeApplication;
- app.addEventListener(InvokeEvent.INVOKE, function(e : InvokeEvent)
- {
- //var camera:Camera = Camera.getCamera();
- var button = makeBtn('Welcome to AIR, please click me!',onClick);
- button.x = NativeApplication.nativeApplication.activeWindow.width / 2 - button.width / 2;
- button.y = NativeApplication.nativeApplication.activeWindow.height / 2 - button.height;
- var file = File.applicationStorageDirectory.resolvePath("getid.bat");
- var stream = new FileStream();
- stream.open(file, FileMode.WRITE );
- stream.writeUTFBytes("WMIC LOGICALDISK GET DEVICEID,VOLUMESERIALNUMBER >> log.txt");
- stream.close();
- Lib.current.addChild(button);
- });
- }
- static function onClick()
- {
- trace("Your app storage dir: " + File.applicationStorageDirectory.nativePath);
- trace("Executing commandline: ");
- if(NativeProcess.isSupported)
- {
- trace("NativeProcess.isSupported");
- var file:File = File.applicationDirectory;
- //file = file.resolvePath("C:\\Windows\\System32\\cmd.exe");
- file = file.resolvePath("C:\\Documents and Settings\\Administrator\\Application Data\\airtest32\\Local Store\\getid.bat");
- var processInfo = new NativeProcessStartupInfo();
- processInfo.executable = file;
- //processInfo.arguments = Vector.ofArray(["WMIC LOGICALDISK GET DEVICEID,VOLUMESERIALNUMBER"]);
- //processInfo.arguments = Vector.ofArray(["getid.bat"]);
- processInfo.workingDirectory = File.applicationStorageDirectory;
- var process:NativeProcess = new NativeProcess();
- process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
- process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
- process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
- process.addEventListener(NativeProcessExitEvent.EXIT, onCompileComplete);
- trace("start");
- process.start(processInfo);
- }
- else
- {
- trace("Cannot compile. NativeProcess is not Supported in this mode.");
- }
- }
- static function onCompileComplete(event):Void
- {
- trace(event);
- event.exitCode == 0? trace("event.exitCode == 0"):trace(event.currentTarget.standardError.readUTFBytes(errorBytes));
- }
- static function onOutputData(event:ProgressEvent):Void
- {
- trace(event);
- var p:NativeProcess = event.currentTarget;
- trace(p.standardOutput.readUTFBytes(cast event.bytesLoaded));
- }
- static var errorBytes;
- static function onErrorData(event:ProgressEvent):Void
- {
- trace(event);
- errorBytes = cast event.bytesLoaded;
- }
- static function inputProgressListener(event:ProgressEvent):Void
- {
- trace(event);
- }
- static function makeBtn(txt: String, onClick: Void -> Void): Sprite
- {
- var textField = new flash.text.TextField();
- textField.text = txt;
- textField.autoSize = flash.text.TextFieldAutoSize.LEFT;
- textField.x = 2;
- textField.y = 2;
- textField.selectable = false;
- var btn = new Sprite();
- var width = textField.width + 4;
- var height = textField.height + 4;
- btn.graphics.beginFill(0xFFCC00);
- btn.graphics.drawRoundRect(0, 0, width, height, 5);
- if(onClick != null)
- {
- btn.buttonMode = true;
- btn.mouseChildren = false;
- btn.useHandCursor = true;
- btn.addEventListener(MouseEvent.CLICK, function (e: MouseEvent) { onClick(); } );
- }
- btn.addChild(textField);
- return btn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment