/// <summary> /// Convert the aapt Command to the string value /// </summary> /// <param name="command">The command.</param> /// <returns></returns> private string AaptCommandToString( AaptCommand command ) { return command.ToString ( ).Replace ( "_", " " ).ToLower ( ); }
/// <summary> /// Runs the aapt command. /// </summary> /// <param name="command">The command.</param> /// <param name="args">The args.</param> /// <returns></returns> private string RunAaptCommand( AaptCommand command, string args ) { //string localPath = System.IO.Path.GetDirectoryName ( typeof ( CommandRunner ).Assembly.Location ); StringBuilder result = new StringBuilder ( ); Process proc = new Process ( ); StringBuilder commandArg = new StringBuilder ( AaptCommandToString ( command ) ); if ( !string.IsNullOrEmpty ( args ) ) { commandArg.AppendFormat ( " {0}", args ); } ProcessStartInfo psi = new ProcessStartInfo ( FolderManagement.GetSdkTool ( AAPT_COMMAND ), commandArg.ToString ( ) ); this.LogDebug ( "{0} {1}", System.IO.Path.GetFileName ( psi.FileName ), psi.Arguments ); psi.CreateNoWindow = true; psi.ErrorDialog = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo = psi; proc.OutputDataReceived += delegate ( object sender, DataReceivedEventArgs e ) { if ( !string.IsNullOrEmpty ( e.Data ) ) { result.AppendLine ( e.Data.Trim ( ) ); } }; proc.ErrorDataReceived += delegate ( object sender, DataReceivedEventArgs e ) { if ( !string.IsNullOrEmpty ( e.Data ) ) { result.AppendLine ( e.Data.Trim ( ) ); } }; proc.Exited += delegate ( object sender, EventArgs e ) { }; proc.Start ( ); proc.BeginOutputReadLine ( ); proc.BeginErrorReadLine ( ); proc.WaitForExit ( ); return result.ToString ( ); }
/// <summary> /// Aapts the command run. /// </summary> /// <param name="command">The command.</param> /// <param name="args">The args.</param> /// <returns></returns> private CommandResult AaptCommandRun( AaptCommand command, string args ) { switch ( command ) { case AaptCommand.Dump_Badging: return new AaptBrandingCommandResult ( RunAaptCommand ( command, args ) ); case AaptCommand.Dump_Permissions: return new AaptPermissionsCommandResult ( RunAaptCommand ( command, args ) ); case AaptCommand.Dump_Configuration: case AaptCommand.Dump_Resources: case AaptCommand.Dump_XmlStrings: case AaptCommand.Dump_XmlTree: case AaptCommand.List: case AaptCommand.Package: case AaptCommand.Remove: case AaptCommand.Add: case AaptCommand.Version: return new GenericCommandResult ( string.Format ( "{0} command not supported", AaptCommandToString ( command ) ) ); default: return new GenericCommandResult ( string.Format ( "unknown command ({0}) not supported", AaptCommandToString ( command ) ) ); } }