static void Main( string[ ] args ) { using ( Stream stream = typeof ( Program ).Assembly.GetManifestResourceStream ( "DroidExplorer.Service.DroidExplorer.Service.log4net" ) ) { XmlConfigurator.Configure ( stream ); } DroidExplorer.Configuration.Settings.Instance.Loaded += delegate ( object sender, EventArgs e ) { SetSdkPath ( ); }; SetSdkPath ( ); Arguments arguments = new Arguments ( args ); Logger.Log = LogManager.GetLogger ( MethodBase.GetCurrentMethod ( ).DeclaringType ); Logger.Level = Logger.Levels.Info | Logger.Levels.Error | Logger.Levels.Warn; if ( arguments.Contains( "console" ,"c" ) ) { DevicesMonitor dm = new DevicesMonitor ( ); dm.Start ( ); Console.WriteLine ( "Press {ENTER} to exit" ); Console.ReadLine ( ); dm.Stop ( ); } else { try { // start the service. System.ServiceProcess.ServiceBase.Run ( new DeviceService ( ) ); } catch ( Exception ex ) { Logger.LogError ( typeof ( Program ), ex.Message, ex ); throw; } } }
public override void Execute(IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args) { Arguments arguments = new Arguments(args ?? new string[] { }); string mode = string.Empty; if(arguments.Contains("mode")) { mode = arguments["mode"]; } var form = new RebootForm( pluginHost ); form.Top = Screen.PrimaryScreen.WorkingArea.Top; form.Left = Screen.PrimaryScreen.WorkingArea.Left; if(pluginHost.GetHostWindow() != null) { form.Show(); } else { form.ShowInTaskbar = true; form.ShowDialog(); } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, DroidExplorer.Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { Arguments arguments = new Arguments ( args ?? new string[] { "/install" } ); string apkFile = string.Empty; var apkArg = arguments.Contains ( "apk" ) ? arguments["apk"] : string.Empty; // check that we have a file, and that it exists. if ( !string.IsNullOrWhiteSpace(apkArg) && System.IO.File.Exists(apkArg) ) { apkFile = apkArg; } else { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog ( ); ofd.Title = "Select Android Application"; ofd.Filter = "Android Applications|*.apk"; ofd.CheckFileExists = true; ofd.Multiselect = false; if ( ofd.ShowDialog ( ) == DialogResult.OK ) { apkFile = ofd.FileName; } else { return; } } if ( File.Exists ( apkFile ) ) { try { var apkInfo = this.PluginHost.CommandRunner.GetLocalApkInformation ( apkFile ); var id = new InstallDialog ( this.PluginHost, arguments.Contains( "uninstall" ) ? InstallDialog.InstallMode.Uninstall : InstallDialog.InstallMode.Install, apkInfo ); if ( pluginHost != null && pluginHost.GetHostWindow() != null ) { id.Show ( ); } else { id.ShowInTaskbar = true; id.ShowDialog ( ); } } catch ( Exception ex ) { MessageBox.Show ( ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); this.LogError ( ex.Message, ex ); } } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { try { var arguments = new Arguments ( args ); if ( !arguments.Contains ( "convert" ) ) { // invalid this.LogError ( "Missing required 'convert' argument" ); return; } var convertType = GetConvertType ( arguments["convert"] ); var file = System.IO.Path.GetFullPath ( arguments["b", "backup"] ); ConvertTo ( convertType, file ); } catch ( Exception ex ) { this.LogError ( ex.Message, ex ); } }
static void Main(string[] arguments) { try { using(Stream stream = typeof(Program).Assembly.GetManifestResourceStream("DroidExplorer.Runner.DroidExplorer.Runner.log4net")) { XmlConfigurator.Configure(stream); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandRunner.Settings = Settings.Instance; Settings.Instance.SystemSettings = RegistrySettings.Instance; string sdkPath = Settings.Instance.SystemSettings.SdkPath; if(String.IsNullOrEmpty(sdkPath)) { throw new ApplicationException("SDK was not successfully set during install."); } CommandRunner.Instance.SdkPath = sdkPath; CommandRunner.Instance.StartServer(); if(!FolderManagement.VerifyAndroidSdkTools ()) { throw new ApplicationException("Unable to locate the android SDK tools, please reinstall the application."); } Logger.LogDebug(typeof( RunnerPluginHost ), "Launching Runner with args: {0}", string.Join(" ", arguments)); Arguments args = new Arguments(arguments); // check if we need to know about a specific device var defDevice = String.Empty; if(!args.Contains("nodevice")) { Logger.LogDebug(typeof( RunnerPluginHost ), "Need Device"); var devices = CommandRunner.Instance.GetDevices().Select(d => d.SerialNumber).ToList(); if(devices.Count != 1) { GenericDeviceSelectionForm selectDevice = new GenericDeviceSelectionForm(); if(selectDevice.ShowDialog() == DialogResult.OK) { defDevice = selectDevice.SelectedDevice; CommandRunner.Instance.DefaultDevice = defDevice; Logger.LogDebug ( "Setting device to '{0}'", defDevice ); } else { return; } } else { defDevice = devices[0]; Logger.LogDebug ( "Setting device to '{0}'", defDevice ); } } var phost = new RunnerPluginHost(defDevice); string typeAssembly = string.Empty; if(!args.Contains("type", "t")) { SelectPluginDialog spd = new SelectPluginDialog(); if(spd.ShowDialog() == DialogResult.OK) { typeAssembly = spd.SelectedPlugin.Replace(" ", string.Empty); arguments = spd.CommandlineArguments; } else { return; } } else { typeAssembly = args["type", "t"]; } Logger.LogDebug(typeof( RunnerPluginHost ), "Launching Plugin {0}", typeAssembly); var plugin = DroidExplorer.Configuration.Settings.Instance.PluginSettings.GetPlugins(phost) .SingleOrDefault(m => String.Compare(typeAssembly, m.Id, true) == 0); if(plugin != null) { try { Logger.LogDebug ( typeof ( RunnerPluginHost ), "Initializing plugin: {0}", plugin.Name ); plugin.Initialize ( phost ); Logger.LogDebug(typeof( RunnerPluginHost ), "running plugin: {0} with args: {1}", plugin.Name, String.Join(" ", arguments)); plugin.Execute(phost, arguments); } catch(Exception ex) { plugin.LogError(ex.Message, ex); } } else { Logger.LogDebug(typeof( RunnerPluginHost ), "plugin '{0}' not found", typeAssembly); throw new ApplicationException("Error executing plugin, check the name to ensure it exists"); } } catch(Exception ex) { Logger.LogError(typeof( RunnerPluginHost ), ex.Message, ex); } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, DroidExplorer.Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { Arguments arguments = new Arguments ( args ?? new string[ ] { } ); string file = string.Empty; if ( arguments.Contains ( "file" ) ) { file = arguments[ "file" ]; } if ( string.IsNullOrEmpty ( file ) ) { DroidExplorer.Core.UI.OpenFileDialog ofd = new DroidExplorer.Core.UI.OpenFileDialog ( ); ofd.Title = "Select Recovery Image"; ofd.Filter = "Recovery Image|*.img|All Files (*.*)|*.*"; ofd.FilterIndex = 0; if ( ofd.ShowDialog ( ) == DialogResult.OK ) { file = ofd.FileName; } } if ( string.IsNullOrEmpty ( file ) ) { return; } else { CommandRunner.Instance.FlashImage ( file ); if ( PluginHost != null ) { int result = PluginHost.ShowCommandBox ( "Reboot Now?", "Recovery image has been flashed to the device.", string.Empty, string.Empty, string.Empty, string.Empty, "Reboot Device|Reboot Device in Recovery mode|Do not reboot device", false, MessageBoxIcon.Question, MessageBoxIcon.None ); switch ( result ) { case 0: // Reboot CommandRunner.Instance.Reboot ( ); break; case 1: // reboot recovery CommandRunner.Instance.RebootRecovery ( ); break; } } } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, DroidExplorer.Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { Arguments arguments = new Arguments ( args ?? new string[] { "/install" } ); string[] apkFiles = new string[] { }; if ( arguments.Contains ( "apk" ) ) { apkFiles = arguments["apk"].Split ( new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries ); } else { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog ( ); ofd.Title = "Select Android Applications"; ofd.Filter = "Android Applications|*.apk"; ofd.Multiselect = true; if ( ofd.ShowDialog ( ) == System.Windows.Forms.DialogResult.OK ) { apkFiles = ofd.FileNames; new BatchInstallerDialog ( DroidExplorer.Core.UI.InstallDialog.InstallMode.Install, new List<string> ( apkFiles ) ).ShowDialog ( ); } else { return; } } }
private bool HasRequiredArguments( Arguments args ) { return ( args.Contains ( "u", "unpack" ) && args.Contains ( "b", "backup" ) ) || ( args.Contains ( "p", "pack" ) && args.Contains ( "tar" ) ); }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { var arguments = new Arguments ( args ); if ( !HasRequiredArguments ( arguments ) ) { this.LogError ( "Missing required arguments" ); } // get password StringBuilder argumentBuilder = new StringBuilder ( ); var abe = System.IO.Path.Combine ( Settings.Instance.ToolsDirectory, "abe.jar" ); argumentBuilder.AppendFormat ( "-jar {0} ", abe.QuoteIfHasSpace ( ) ); bool isPack = false; var tar = String.Empty; var backup = String.Empty; var workingDir = String.Empty; if ( arguments.Contains ( "p", "pack" ) ) { argumentBuilder.Append ( "pack " ); tar = Path.GetFullPath ( arguments["tar"] ); workingDir = Path.GetFullPath ( Path.GetDirectoryName ( tar ) ); backup = Path.GetFullPath ( System.IO.Path.Combine ( workingDir, System.IO.Path.GetFileNameWithoutExtension ( tar ) + ".ab" ) ); isPack = true; } else if ( arguments.Contains ( "u", "unpack" ) ) { backup = Path.GetFullPath ( arguments["b", "backup"] ); var bc = new BackupConverter ( this.PluginHost ); if ( bc.IsExtendedBackup ( backup ) ) { argumentBuilder.Append ( "unpackex " ); } else { argumentBuilder.Append ( "unpack " ); } workingDir = Path.GetFullPath ( Path.GetDirectoryName ( backup ) ); tar = Path.GetFullPath ( System.IO.Path.Combine ( workingDir, System.IO.Path.GetFileNameWithoutExtension ( backup ) + ".tar" ) ); isPack = false; } argumentBuilder.AppendFormat ( "{0} {1} ", ( isPack ? tar : backup ).QuoteIfHasSpace ( ), ( isPack ? backup : tar ).QuoteIfHasSpace ( ) ); var password = String.Empty; if ( arguments.Contains ( "pass", "password" ) ) { password = arguments["pass", "password"]; } else { // show password dialog var ppf = new PackPasswordForm() { Text = isPack ? "Pack Password" : "Unpack Password" }; if ( ppf.ShowDialog() == DialogResult.OK ) { password = ppf.Password; } } if ( !String.IsNullOrEmpty ( password ) ) { argumentBuilder.Append( password ); } this.LogDebug ( "running: java.exe {0}", argumentBuilder.ToString ( ) ); var proc = new Process { StartInfo = new ProcessStartInfo { Arguments = argumentBuilder.ToString ( ).Trim ( ), WindowStyle = ProcessWindowStyle.Hidden, FileName = "java.exe", WorkingDirectory = Environment.CurrentDirectory, CreateNoWindow = true } }; proc.Start ( ); }
static void Main(string[] arguments) { try { using(var stream = typeof(Program).Assembly.GetManifestResourceStream(DroidExplorer.Resources.Strings.Log4NetDroidExplorer)) { XmlConfigurator.Configure(stream); } var errorMessages = new List<string>(); var args = new Arguments(arguments); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += (sender, e) => DroidExplorer.Core.Logger.LogError(typeof(Program), e.Exception.Message, e.Exception); // show the splash dialog Program.SplashManager.ShowSplashDialog(StartUpStepCount); // load settings Logger.LogDebug ( typeof ( Program ), "Loading Droid Explorer Settings" ); Program.SplashManager.SplashDialog.SetStepText("Loading Settings..."); CommandRunner.Settings = Settings.Instance; Settings.Instance.SystemSettings = RegistrySettings.Instance; Program.SplashManager.SplashDialog.IncrementLoadStep(1); // cleanup adb? should this be done? Application.ApplicationExit += delegate(object sender, EventArgs e) { //CommandRunner.Instance.AdbProcessCleanUp ( ); }; // locate sdk tools Logger.LogDebug ( typeof ( Program ), "Locating SDK Path" ); Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashLocatingSdk); var sdkPath = Settings.Instance.SystemSettings.SdkPath; Logger.LogDebug ( typeof ( Program ), "SDK Path Set to {0}", sdkPath ); if ( string.IsNullOrEmpty(sdkPath)) { throw new ApplicationException("Unable to locate the android SDK tools, please reinstall the application."); } Program.SplashManager.SplashDialog.IncrementLoadStep(1); // verify the sdk tools Logger.LogDebug ( typeof ( Program ), "Verifying SDK Tools" ); Program.SplashManager.SplashDialog.SetStepText("Verifying SDK Tools"); // verify the sdk tools. var valid = FolderManagement.VerifyAndroidSdkTools (); if(!valid){ // if not valid - lets ask the user where it is. Program.SplashManager.SplashDialog.HideExt(); Logger.LogWarn( typeof ( Program ), "Unable to verify the SDK tools" ); var browser = new FolderBrowserDialog(); browser.Description = "Unable to locate SDK tools path. Please select the location where you have the Android SDK installed."; browser.ShowNewFolderButton = false; var dResult = DialogResult.OK; do { dResult = browser.ShowDialog(); if(dResult == DialogResult.OK) { Settings.Instance.SystemSettings.SdkPath = browser.SelectedPath; valid = FolderManagement.VerifyAndroidSdkTools (); } // keep asking until the user selects a valid location, or they cancel. } while(!valid && dResult == DialogResult.OK); if(!valid) { // they canceled. we are out of here. throw new ApplicationException(DroidExplorer.Resources.Strings.SdkPathNotFoundMessage); } // bring it back. Program.SplashManager.SplashDialog.AsyncShow(); } Program.SplashManager.SplashDialog.IncrementLoadStep(1); // set the sdk path CommandRunner.Instance.SdkPath = sdkPath; Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashStartAdb); try { // start the adb server Logger.LogDebug ( typeof ( Program ), "Starting ADB Server" ); CommandRunner.Instance.StartServer(); Program.SplashManager.SplashDialog.IncrementLoadStep(1); } catch(AdbRootException arex) { Logger.LogWarn ( typeof ( Program ), arex.Message ); } // get the attached devices Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashGetDevices); // BUG: 15695 // fixed this. It was because adb root was disconnecting the device and restarting it. // adb root is now called when you connect to a device. Although, it can cause the device to // not be found... another bug... Logger.LogDebug ( typeof ( Program ), "Getting connected devices" ); var devices = CommandRunner.Instance.GetDevices().ToList(); Program.SplashManager.SplashDialog.IncrementLoadStep(1); new Thread(() => { // process the devices and send them off to the cloud Logger.LogDebug ( typeof ( Program ), "Registering anonymous statistics for device types" ); CloudStatistics.Instance.RegisterModels(devices); }).Start(); // we will increment even though the process is on a new thread. Program.SplashManager.SplashDialog.IncrementLoadStep(1); // pass in the initial path? // TODO: Not yet implemented. //var initialPath = "/"; //if ( args.Contains ( "p", "path" ) && !string.IsNullOrWhiteSpace ( args["p", "path"] ) ) { // initialPath = args["p", "path"]; //} // are we attaching to a specific device? if ( args.Contains("d", "device")) { CommandRunner.Instance.DefaultDevice = args["d", "device"]; Logger.LogDebug( typeof ( Program ), DroidExplorer.Resources.Strings.SplashConnectingDevice, CommandRunner.Instance.DefaultDevice); Application.Run(new MainForm( ) ); } else { // get the attached devices String selectedDevice = null; if(devices.Count() != 1) { // we have 0 or > 1 so we need to display the "selection dialog" var dsf = new GenericDeviceSelectionForm(); Program.SplashManager.SplashDialog.HideExt(); if(dsf.ShowDialog(null) == DialogResult.OK) { CommandRunner.Instance.DefaultDevice = dsf.SelectedDevice; Logger.LogDebug ( typeof ( Program ), DroidExplorer.Resources.Strings.SplashConnectingDevice, CommandRunner.Instance.DefaultDevice ); selectedDevice = dsf.SelectedDevice; } else { Program.SplashManager.CloseSplashDialog(); return; } Program.SplashManager.SplashDialog.AsyncShow(); } else { selectedDevice = devices[0].SerialNumber; CommandRunner.Instance.DefaultDevice = selectedDevice; } // try to run adb as root: try { Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashRunAdbAsRoot); Logger.LogDebug ( typeof ( Program ), DroidExplorer.Resources.Strings.SplashRunAdbAsRoot ); CommandRunner.Instance.StartAdbAsRoot(selectedDevice); // sleep a half second to let it start up. Thread.Sleep ( 500 ); } catch(AdbRootException are) { Logger.LogDebug ( typeof ( Program ), "Unable to launch ADB as root" ); // if we are unable to run as adb root if ( Settings.Instance.WarnWhenNoAdbRoot) { SplashManager.SplashDialog.Invoke((Action)(() => { SplashManager.SplashDialog.Visible = false; })); //NoAdbRootCommands Continue|Show more information|Exit var result = TaskDialog.ShowCommandBox( DroidExplorer.Resources.Strings.NoAdbRootTitle, are.Message, DroidExplorer.Resources.Strings.NoAdbRootMessage, string.Empty, string.Empty, DroidExplorer.Resources.Strings.NoAdbRootCheckboxText, DroidExplorer.Resources.Strings.NoAdbRootCommands, false, SysIcons.Warning, SysIcons.Warning); switch(TaskDialog.CommandButtonResult) { case 0: // Continue // continue if(TaskDialog.VerificationChecked) { // do not warn again. Settings.Instance.WarnWhenNoAdbRoot = false; } break; case 1: // continue and get more info : http://android.stackexchange.com/a/96066/1951 // android enthusiasts CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.AdbRootQAUrl, string.Empty, true); if(TaskDialog.VerificationChecked) { // do not warn again. Settings.Instance.WarnWhenNoAdbRoot = false; } break; case 2: // link to adbd insecure by chainfire on google play CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.AdbdInsecureAppUrl, string.Empty, true); Application.Exit(); return; default: // 3 Application.Exit(); return; } SplashManager.SplashDialog.Invoke((Action)(() => { SplashManager.SplashDialog.Visible = true; })); } } // increment for adb root Program.SplashManager.SplashDialog.IncrementLoadStep(1); // minor hackory for getting the device for cloud stats var d = new Core.Adb.Device(selectedDevice, Core.Adb.DeviceState.Online); // get the device properties for registration foreach(var i in CommandRunner.Instance.GetProperties(selectedDevice)) { d.Properties.Add(i.Key, i.Value); } if(!Settings.Instance.SystemSettings.RecordDeviceInformationToCloud) { Program.SplashManager.SplashDialog.SetStepText( String.Format(DroidExplorer.Resources.Strings.SplashRegisterDevice, KnownDeviceManager.Instance.GetDeviceFriendlyName(selectedDevice) ) ); // register the device CloudStatistics.Instance.RegisterDevice(d, devices.Single(x => x.SerialNumber == d.SerialNumber)); Program.SplashManager.SplashDialog.IncrementLoadStep(1); } else { // we have to increment but nothing else here Program.SplashManager.SplashDialog.IncrementLoadStep(1); } Logger.LogDebug ( typeof ( Program ), "Launching Main UI" ); // connect to device Program.SplashManager.SplashDialog.SetStepText(string.Format(DroidExplorer.Resources.Strings.SplashConnectingDevice, KnownDeviceManager.Instance.GetDeviceFriendlyName(CommandRunner.Instance.DefaultDevice))); Application.Run(new MainForm( ) ); } } catch(Exception ex) { var result = TaskDialog.ShowCommandBox(DroidExplorer.Resources.Strings.ErrorUncaughtTitle, ex.Message, DroidExplorer.Resources.Strings.ErrorUncaughtMessage, ex.ToString(), string.Empty, string.Empty, DroidExplorer.Resources.Strings.ErrorUncaughtCommands, false, SysIcons.Error, SysIcons.Error); switch(TaskDialog.CommandButtonResult) { case 1: // continue break; case 2: // android enthusiasts CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.SupportUrl, string.Empty, true); break; case 3: // report bug CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.IssueTrackerCreateUrl, string.Empty, true); break; default: // 0 Application.Restart(); break; } } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, DroidExplorer.Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { Arguments arguments = new Arguments ( args ?? new string[] { } ); string file = string.Empty; if ( arguments.Contains( "file" ) ) { file = arguments[ "file" ]; } ShellConsole console = new ShellConsole ( pluginHost ); console.Top = Screen.PrimaryScreen.WorkingArea.Top; console.Left = Screen.PrimaryScreen.WorkingArea.Left; if ( !string.IsNullOrEmpty ( file ) ) { console.Run ( file ); } if(pluginHost != null && pluginHost.GetHostWindow() != null) { console.Show(); } else { console.ShowInTaskbar = true; console.ShowDialog(); } }