diff --git a/AndroidLib/Classes/AndroidController/Adb.cs b/AndroidLib/Classes/AndroidController/Adb.cs index 939b7f2..a8fe90a 100644 --- a/AndroidLib/Classes/AndroidController/Adb.cs +++ b/AndroidLib/Classes/AndroidController/Adb.cs @@ -26,6 +26,7 @@ public static class Adb private static object _lock = "U is lawked"; internal const string ADB = "adb"; internal const string ADB_EXE = "adb.exe"; + internal const string ADB_VERSION = "1.0.31"; /// /// Forms an that is passed to Adb.ExecuteAdbCommand() diff --git a/AndroidLib/Classes/AndroidController/AndroidController.cs b/AndroidLib/Classes/AndroidController/AndroidController.cs index 0777efc..b87b98f 100644 --- a/AndroidLib/Classes/AndroidController/AndroidController.cs +++ b/AndroidLib/Classes/AndroidController/AndroidController.cs @@ -74,6 +74,7 @@ public sealed class AndroidController #region MEMBER VARIABLES private string resourceDirectory; private List connectedDevices; + private bool Extract_Resources = false; #endregion #region PROPERTIES @@ -126,25 +127,24 @@ private AndroidController() #region PRIVATE METHODS private void CreateResourceDirectories() { - if (!ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER)) + if (!Adb.ExecuteAdbCommand(new AdbCommand("version")).Contains(Adb.ADB_VERSION)) { - if (File.Exists(this.resourceDirectory + Adb.ADB_EXE) && Adb.ServerRunning) - { - Adb.KillServer(); - Thread.Sleep(1000); - } - + Adb.KillServer(); + Thread.Sleep(1000); ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER); + Extract_Resources = true; } - ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER); } private void ExtractResources() { - string[] res = new string[RESOURCES.Count]; - RESOURCES.Keys.CopyTo(res, 0); - Extract.Resources(this, this.resourceDirectory, "Resources.AndroidController", res); + if (this.Extract_Resources) + { + string[] res = new string[RESOURCES.Count]; + RESOURCES.Keys.CopyTo(res, 0); + Extract.Resources(this, this.resourceDirectory, "Resources.AndroidController", res); + } } #endregion @@ -160,8 +160,6 @@ public void Dispose() Adb.KillServer(); Thread.Sleep(1000); } - - ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER); AndroidController.instance = null; } @@ -300,19 +298,33 @@ public void UpdateDeviceList() } } + private bool _CancelRequest; + public bool CancelWait + { + get { return _CancelRequest; } + set { _CancelRequest = value; } + } + /// /// Pauses thread until 1 or more Android devices are connected /// /// Do Not Use in Windows Forms applications, as this method pauses the current thread. Works fine in Console Applications public void WaitForDevice() { - /* Entering an endless loop will exaust CPU. - * Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps, - * sleeping thread for 250 miliSecond (1/4 of a second) - * will be more friendly to the CPU. Nontheless checking 4 times for a connected device in each second is more than enough, - * and will not result in late response from the app if a device gets connected. - */ - while (!this.HasConnectedDevices) { Thread.Sleep(250); } + /* Entering an endless loop will exhaust CPU. + * Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps, + * sleeping thread for 250 miliSecond (1/4 of a second) + * will be more friendly to the CPU. Nonetheless checking 4 times for a connected device in each second is more than enough, + * and will not result in late response from the app if a device gets connected. + */ + while (!this.HasConnectedDevices) + { + if (this.CancelWait) + { + break; + } + Thread.Sleep(250); + } } #endregion } diff --git a/AndroidLib/Resources/AAPT/aapt.exe b/AndroidLib/Resources/AAPT/aapt.exe index d06ba93..c09720f 100644 Binary files a/AndroidLib/Resources/AAPT/aapt.exe and b/AndroidLib/Resources/AAPT/aapt.exe differ diff --git a/AndroidLib/Resources/AndroidController/adb.exe b/AndroidLib/Resources/AndroidController/adb.exe index 9678e99..f2715ff 100644 Binary files a/AndroidLib/Resources/AndroidController/adb.exe and b/AndroidLib/Resources/AndroidController/adb.exe differ diff --git a/AndroidLib/Resources/AndroidController/fastboot.exe b/AndroidLib/Resources/AndroidController/fastboot.exe index 00ecd2f..e150ca8 100644 Binary files a/AndroidLib/Resources/AndroidController/fastboot.exe and b/AndroidLib/Resources/AndroidController/fastboot.exe differ