@@ -74,6 +74,7 @@ public sealed class AndroidController
74
74
#region MEMBER VARIABLES
75
75
private string resourceDirectory ;
76
76
private List < string > connectedDevices ;
77
+ private bool Extract_Resources = false ;
77
78
#endregion
78
79
79
80
#region PROPERTIES
@@ -126,25 +127,24 @@ private AndroidController()
126
127
#region PRIVATE METHODS
127
128
private void CreateResourceDirectories ( )
128
129
{
129
- if ( ! ResourceFolderManager . Register ( ANDROID_CONTROLLER_TMP_FOLDER ) )
130
+ if ( ! Adb . ExecuteAdbCommand ( new AdbCommand ( "version" ) ) . Contains ( Adb . ADB_VERSION ) )
130
131
{
131
- if ( File . Exists ( this . resourceDirectory + Adb . ADB_EXE ) && Adb . ServerRunning )
132
- {
133
- Adb . KillServer ( ) ;
134
- Thread . Sleep ( 1000 ) ;
135
- }
136
-
132
+ Adb . KillServer ( ) ;
133
+ Thread . Sleep ( 1000 ) ;
137
134
ResourceFolderManager . Unregister ( ANDROID_CONTROLLER_TMP_FOLDER ) ;
135
+ Extract_Resources = true ;
138
136
}
139
-
140
137
ResourceFolderManager . Register ( ANDROID_CONTROLLER_TMP_FOLDER ) ;
141
138
}
142
139
143
140
private void ExtractResources ( )
144
141
{
145
- string [ ] res = new string [ RESOURCES . Count ] ;
146
- RESOURCES . Keys . CopyTo ( res , 0 ) ;
147
- Extract . Resources ( this , this . resourceDirectory , "Resources.AndroidController" , res ) ;
142
+ if ( this . Extract_Resources )
143
+ {
144
+ string [ ] res = new string [ RESOURCES . Count ] ;
145
+ RESOURCES . Keys . CopyTo ( res , 0 ) ;
146
+ Extract . Resources ( this , this . resourceDirectory , "Resources.AndroidController" , res ) ;
147
+ }
148
148
}
149
149
#endregion
150
150
@@ -160,8 +160,6 @@ public void Dispose()
160
160
Adb . KillServer ( ) ;
161
161
Thread . Sleep ( 1000 ) ;
162
162
}
163
-
164
- ResourceFolderManager . Unregister ( ANDROID_CONTROLLER_TMP_FOLDER ) ;
165
163
AndroidController . instance = null ;
166
164
}
167
165
@@ -300,19 +298,34 @@ public void UpdateDeviceList()
300
298
}
301
299
}
302
300
301
+ private bool _CancelRequest ;
302
+ /// <summary>
303
+ /// Set to true to cancel a WaitForDevice() method call
304
+ /// </summary>
305
+ public bool CancelWait
306
+ {
307
+ get { return _CancelRequest ; }
308
+ set { _CancelRequest = value ; }
309
+ }
310
+
303
311
/// <summary>
304
312
/// Pauses thread until 1 or more Android devices are connected
305
313
/// </summary>
306
314
/// <remarks>Do Not Use in Windows Forms applications, as this method pauses the current thread. Works fine in Console Applications</remarks>
307
315
public void WaitForDevice ( )
308
316
{
309
- /* Entering an endless loop will exaust CPU.
310
- * Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps,
311
- * sleeping thread for 250 miliSecond (1/4 of a second)
312
- * will be more friendly to the CPU. Nontheless checking 4 times for a connected device in each second is more than enough,
313
- * and will not result in late response from the app if a device gets connected.
314
- */
315
- while ( ! this . HasConnectedDevices ) { Thread . Sleep ( 250 ) ; }
317
+ /* Entering an endless loop will exhaust CPU.
318
+ * Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps,
319
+ * sleeping thread for 250 miliSecond (1/4 of a second)
320
+ * will be more friendly to the CPU. Nonetheless checking 4 times for a connected device in each second is more than enough,
321
+ * and will not result in late response from the app if a device gets connected.
322
+ */
323
+ while ( ! this . HasConnectedDevices && ! this . CancelWait )
324
+ {
325
+ Thread . Sleep ( 250 ) ;
326
+ }
327
+
328
+ this . CancelWait = false ;
316
329
}
317
330
#endregion
318
331
}
0 commit comments