Skip to content

Commit

Permalink
display error message if install APK fails, add option to capture out…
Browse files Browse the repository at this point in the history
…put from LaunchExe
  • Loading branch information
unitycoder committed Nov 8, 2024
1 parent a15f48f commit 3d4c83a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 20 additions & 7 deletions UnityLauncherPro/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ private void ChkGetGitBranchRecursively_CheckedChanged(object sender, RoutedEven
return; // dont run code on window init

Settings.Default.searchGitFolderRecursivly = (bool)chkGetGitBranchRecursively.IsChecked;
Settings.Default.Save();
Settings.Default.Save();
RefreshRecentProjects();
}

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

// TODO start cmd minimized
Tools.LaunchExe(cmd, pars);
// get apk name from path
var apkName = Path.GetFileName(playerPath);
if (chkStreamerMode.IsChecked == true) apkName = " (hidden in streamermode)";
SetStatus("Installed APK:" + apkName);
//Tools.LaunchExe(cmd, pars);
var process = Tools.LaunchExe(cmd, pars, captureOutput: true);
var output = process.StandardOutput.ReadToEnd();
var errorOutput = process.StandardError.ReadToEnd().Replace("\r", "").Replace("\n", "");

process.WaitForExit();

// Console.WriteLine(output);
if (!string.IsNullOrEmpty(errorOutput))
{
SetStatus("Error installing APK: " + errorOutput);
}
else
{
// get apk name from path
var apkName = Path.GetFileName(playerPath);
if (chkStreamerMode.IsChecked == true) apkName = " (hidden in streamermode)";
SetStatus("Installed APK:" + apkName);
}
}

private void txtWebglPort_TextChanged(object sender, TextChangedEventArgs e)
Expand Down
8 changes: 7 additions & 1 deletion UnityLauncherPro/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public static bool LaunchExplorerSelectFile(string fileName)
}

// run any exe, return process
public static Process LaunchExe(string path, string param = null)
public static Process LaunchExe(string path, string param = null, bool captureOutput=false)
{
if (string.IsNullOrEmpty(path)) return null;

Expand All @@ -510,6 +510,12 @@ public static Process LaunchExe(string path, string param = null)
newProcess = new Process();
newProcess.StartInfo.FileName = "\"" + path + "\"";
newProcess.StartInfo.Arguments = param;
if (captureOutput)
{
newProcess.StartInfo.RedirectStandardError = true;
newProcess.StartInfo.RedirectStandardOutput = true;
newProcess.StartInfo.UseShellExecute = false;
}
newProcess.EnableRaisingEvents = true; // needed to get Exited event
newProcess.Start();
}
Expand Down

0 comments on commit 3d4c83a

Please sign in to comment.