Skip to content

Commit c34308a

Browse files
Dan WagerDan Wager
authored andcommitted
Merge pull request regaw-leinad#10 from OmarBizreh/master
Some useful changes
2 parents 63672b5 + f136e1e commit c34308a

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

AndroidLib/Classes/AndroidController/Adb.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static class Adb
2626
private static object _lock = "U is lawked";
2727
internal const string ADB = "adb";
2828
internal const string ADB_EXE = "adb.exe";
29+
internal const string ADB_VERSION = "1.0.31";
2930

3031
/// <summary>
3132
/// Forms an <see cref="AdbCommand"/> that is passed to <c>Adb.ExecuteAdbCommand()</c>

AndroidLib/Classes/AndroidController/AndroidController.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public sealed class AndroidController
7474
#region MEMBER VARIABLES
7575
private string resourceDirectory;
7676
private List<string> connectedDevices;
77+
private bool Extract_Resources = false;
7778
#endregion
7879

7980
#region PROPERTIES
@@ -126,25 +127,24 @@ private AndroidController()
126127
#region PRIVATE METHODS
127128
private void CreateResourceDirectories()
128129
{
129-
if (!ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER))
130+
if (!Adb.ExecuteAdbCommand(new AdbCommand("version")).Contains(Adb.ADB_VERSION))
130131
{
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);
137134
ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER);
135+
Extract_Resources = true;
138136
}
139-
140137
ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER);
141138
}
142139

143140
private void ExtractResources()
144141
{
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+
}
148148
}
149149
#endregion
150150

@@ -160,8 +160,6 @@ public void Dispose()
160160
Adb.KillServer();
161161
Thread.Sleep(1000);
162162
}
163-
164-
ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER);
165163
AndroidController.instance = null;
166164
}
167165

@@ -300,19 +298,33 @@ public void UpdateDeviceList()
300298
}
301299
}
302300

301+
private bool _CancelRequest;
302+
public bool CancelWait
303+
{
304+
get { return _CancelRequest; }
305+
set { _CancelRequest = value; }
306+
}
307+
303308
/// <summary>
304309
/// Pauses thread until 1 or more Android devices are connected
305310
/// </summary>
306311
/// <remarks>Do Not Use in Windows Forms applications, as this method pauses the current thread. Works fine in Console Applications</remarks>
307312
public void WaitForDevice()
308313
{
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); }
314+
/* Entering an endless loop will exhaust CPU.
315+
* Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps,
316+
* sleeping thread for 250 miliSecond (1/4 of a second)
317+
* will be more friendly to the CPU. Nonetheless checking 4 times for a connected device in each second is more than enough,
318+
* and will not result in late response from the app if a device gets connected.
319+
*/
320+
while (!this.HasConnectedDevices)
321+
{
322+
if (this.CancelWait)
323+
{
324+
break;
325+
}
326+
Thread.Sleep(250);
327+
}
316328
}
317329
#endregion
318330
}

AndroidLib/Resources/AAPT/aapt.exe

30.5 KB
Binary file not shown.
4 KB
Binary file not shown.
3 KB
Binary file not shown.

0 commit comments

Comments
 (0)