Skip to content

Commit 3d4c83a

Browse files
committed
display error message if install APK fails, add option to capture output from LaunchExe
1 parent a15f48f commit 3d4c83a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ private void ChkGetGitBranchRecursively_CheckedChanged(object sender, RoutedEven
15891589
return; // dont run code on window init
15901590

15911591
Settings.Default.searchGitFolderRecursivly = (bool)chkGetGitBranchRecursively.IsChecked;
1592-
Settings.Default.Save();
1592+
Settings.Default.Save();
15931593
RefreshRecentProjects();
15941594
}
15951595

@@ -3460,12 +3460,25 @@ private void menuInstallLastAPK_Click(object sender, RoutedEventArgs e)
34603460
pars += $" && adb shell monkey -p {packageName} 1";
34613461
}
34623462

3463-
// TODO start cmd minimized
3464-
Tools.LaunchExe(cmd, pars);
3465-
// get apk name from path
3466-
var apkName = Path.GetFileName(playerPath);
3467-
if (chkStreamerMode.IsChecked == true) apkName = " (hidden in streamermode)";
3468-
SetStatus("Installed APK:" + apkName);
3463+
//Tools.LaunchExe(cmd, pars);
3464+
var process = Tools.LaunchExe(cmd, pars, captureOutput: true);
3465+
var output = process.StandardOutput.ReadToEnd();
3466+
var errorOutput = process.StandardError.ReadToEnd().Replace("\r", "").Replace("\n", "");
3467+
3468+
process.WaitForExit();
3469+
3470+
// Console.WriteLine(output);
3471+
if (!string.IsNullOrEmpty(errorOutput))
3472+
{
3473+
SetStatus("Error installing APK: " + errorOutput);
3474+
}
3475+
else
3476+
{
3477+
// get apk name from path
3478+
var apkName = Path.GetFileName(playerPath);
3479+
if (chkStreamerMode.IsChecked == true) apkName = " (hidden in streamermode)";
3480+
SetStatus("Installed APK:" + apkName);
3481+
}
34693482
}
34703483

34713484
private void txtWebglPort_TextChanged(object sender, TextChangedEventArgs e)

Diff for: UnityLauncherPro/Tools.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public static bool LaunchExplorerSelectFile(string fileName)
488488
}
489489

490490
// run any exe, return process
491-
public static Process LaunchExe(string path, string param = null)
491+
public static Process LaunchExe(string path, string param = null, bool captureOutput=false)
492492
{
493493
if (string.IsNullOrEmpty(path)) return null;
494494

@@ -510,6 +510,12 @@ public static Process LaunchExe(string path, string param = null)
510510
newProcess = new Process();
511511
newProcess.StartInfo.FileName = "\"" + path + "\"";
512512
newProcess.StartInfo.Arguments = param;
513+
if (captureOutput)
514+
{
515+
newProcess.StartInfo.RedirectStandardError = true;
516+
newProcess.StartInfo.RedirectStandardOutput = true;
517+
newProcess.StartInfo.UseShellExecute = false;
518+
}
513519
newProcess.EnableRaisingEvents = true; // needed to get Exited event
514520
newProcess.Start();
515521
}

0 commit comments

Comments
 (0)