Skip to content

Commit f7bc172

Browse files
committed
projects: add context menu 'Install & Run latest APK", disable File.Exists check on LaunchExe (to run items from PATH)
1 parent 7fe567e commit f7bc172

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@
619619
<MenuItem x:Name="menuItemKillProcess" Header="Kill Process" Click="MenuItemKillProcess_Click" />
620620
<Separator/>
621621
<MenuItem x:Name="menuStartWebGLServer" Header="Start WebGL server" Click="MenuStartWebGLServer_Click" />
622+
<MenuItem x:Name="menuInstallLastAPK" Header="Install &amp; Run latest APK" Click="menuInstallLastAPK_Click" />
622623
<Separator/>
623624
<MenuItem Header="Build">
624625
<MenuItem x:Name="menuBatchBuildAndroid" Header="Android" Click="MenuBatchBuildAndroid_Click"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,13 +2843,89 @@ private void btnPatchHubConfig_Click(object sender, RoutedEventArgs e)
28432843
File.WriteAllText(configFile, json);
28442844
SetStatus("editors.json file saved");
28452845
}
2846+
else
2847+
{
2848+
SetStatus(configFile + " not found");
2849+
}
28462850
}
28472851
else
28482852
{
28492853
SetStatus("Cancelled");
28502854
}
28512855
}
28522856

2857+
private void menuInstallLastAPK_Click(object sender, RoutedEventArgs e)
2858+
{
2859+
var proj = GetSelectedProject();
2860+
2861+
var yamlFile = Path.Combine(proj.Path, "Library", "PlayerDataCache", "Android", "ScriptsOnlyCache.yaml");
2862+
if (File.Exists(yamlFile) == false)
2863+
{
2864+
SetStatus("No ScriptsOnlyCache.yaml file found");
2865+
return;
2866+
}
2867+
var yaml = File.ReadAllLines(yamlFile);
2868+
// loop rows until "playerPath:"
2869+
string playerPath = null;
2870+
foreach (var row in yaml)
2871+
{
2872+
if (row.IndexOf("playerPath:") > -1)
2873+
{
2874+
// get the player path
2875+
playerPath = row.Substring(row.IndexOf(":") + 1).Trim();
2876+
break;
2877+
}
2878+
}
2879+
2880+
if (playerPath == null)
2881+
{
2882+
SetStatus("No playerPath found in ScriptsOnlyCache.yaml");
2883+
return;
2884+
}
2885+
2886+
// install the apk using ADB using cmd (-r = replace app)
2887+
var cmd = "cmd.exe";// /C adb install -r \"{playerPath}\"";
2888+
var pars = $"/C adb install -r \"{playerPath}\"";
2889+
2890+
string packageName = null;
2891+
2892+
// get package name from ProjectSettings.asset
2893+
var psPath = Path.Combine(proj.Path, "ProjectSettings", "ProjectSettings.asset");
2894+
if (File.Exists(psPath) == true)
2895+
{
2896+
// read project settings
2897+
var rows = File.ReadAllLines(psPath);
2898+
2899+
// search applicationIdentifier, Android:
2900+
for (int i = 0, len = rows.Length; i < len; i++)
2901+
{
2902+
// skip rows until companyname
2903+
if (rows[i].Trim().IndexOf("applicationIdentifier:") > -1)
2904+
{
2905+
var temp = rows[i + 1].Trim();
2906+
if (temp.IndexOf("Android:") > -1)
2907+
{
2908+
// get package name
2909+
packageName = temp.Substring(temp.IndexOf(":") + 1).Trim();
2910+
break;
2911+
}
2912+
}
2913+
}
2914+
}
2915+
2916+
if (string.IsNullOrEmpty(packageName) == false)
2917+
{
2918+
pars += $" && adb shell monkey -p {packageName} 1";
2919+
}
2920+
2921+
// TODO start cmd minimized
2922+
Tools.LaunchExe(cmd, pars);
2923+
// get apk name from path
2924+
var apkName = Path.GetFileName(playerPath);
2925+
if (chkStreamerMode.IsChecked == true) apkName = " (hidden in streamermode)";
2926+
SetStatus("Installed APK:" + apkName);
2927+
}
2928+
28532929
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
28542930
//{
28552931
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

UnityLauncherPro/Tools.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ public static Process LaunchExe(string path, string param = null)
380380
{
381381
if (string.IsNullOrEmpty(path)) return null;
382382

383-
if (File.Exists(path) == true)
383+
// not needed for exe's in PATH
384+
//if (File.Exists(path) == true)
384385
{
385386
Process newProcess = null;
386387
if (string.IsNullOrEmpty(param) == true)
@@ -1646,6 +1647,7 @@ public static bool CreateDesktopShortCut(Project proj, string batchFolder)
16461647
return true;
16471648
}
16481649

1650+
16491651
internal static long GetFolderSizeInBytes(string currentBuildReportProjectPath)
16501652
{
16511653
if (Directory.Exists(currentBuildReportProjectPath) == false) return 0;

0 commit comments

Comments
 (0)