diff --git a/BackgroundLaunch/Runner.cs b/BackgroundLaunch/Runner.cs index 79db181..e9511be 100644 --- a/BackgroundLaunch/Runner.cs +++ b/BackgroundLaunch/Runner.cs @@ -74,13 +74,21 @@ public Runner(LaunchInfo item) } } - startInfo.WorkingDirectory = workingPath; startInfo.Verb = item.RunAsAdmin ? "runas" : "run"; - startInfo.ErrorDialog = true; // depending on item type, prepare executable and arguments if ((item.ItemType == ItemTypeEnum.Solution) || (item.ItemType == ItemTypeEnum.Project)) { + if (item.RunAsAdmin) + { + startInfo.UseShellExecute = true; + startInfo.ErrorDialog = true; + } + else + { + startInfo.WorkingDirectory = workingPath; + } + startInfo.FileName = GetTargetFilename(item); startInfo.Arguments = "\"" + item.Path + "\""; if (!string.IsNullOrEmpty(item.Commands)) diff --git a/VSLXshared/DataModel/VsFolder.cs b/VSLXshared/DataModel/VsFolder.cs index ea31e40..d027cbf 100644 --- a/VSLXshared/DataModel/VsFolder.cs +++ b/VSLXshared/DataModel/VsFolder.cs @@ -29,6 +29,19 @@ public VsFolder(string name, string path) : base(name, path, null) this.ItemType = ItemTypeEnum.Folder; } + /// + /// Initializes a new instance of the class. + /// + /// The single item. + public VsFolder(VsItem singleItem) + { + this.Items = new VsItemList(this) + { + singleItem + }; + this.ItemType = ItemTypeEnum.Folder; + } + /// /// Gets or sets a value indicating whether checked. /// diff --git a/VSLauncherX/ItemLauncher.cs b/VSLauncherX/ItemLauncher.cs index 8f0d609..7964160 100644 --- a/VSLauncherX/ItemLauncher.cs +++ b/VSLauncherX/ItemLauncher.cs @@ -24,9 +24,8 @@ public class ItemLauncher /// The target. public ItemLauncher(VsItem item, VisualStudioInstance target) { - this.Solution = new VsFolder(); - this.Solution.Items.Add(item); this.Target = target; + this.SingleItem = item; } /// @@ -43,7 +42,12 @@ public ItemLauncher(VsFolder item, VisualStudioInstance target) /// /// Gets the launch item. /// - public VsFolder Solution { get; } + public VsFolder? Solution { get; } + + /// + /// Gets the single item. + /// + public VsItem? SingleItem { get; } /// /// Gets the target. @@ -67,8 +71,12 @@ public Task Launch(bool bForceAdmin = false) string s = CreateLaunchInfoString(); Debug.WriteLine(s); + if(this.Solution is null && this.SingleItem is null) + { + throw new NullReferenceException(); + } - bool bRequireAdmin = (bForceAdmin | this.Solution.RunAsAdmin); + bool bRequireAdmin = bForceAdmin | (this.Solution is null ? this.SingleItem!.RunAsAdmin : this.Solution.RunAsAdmin); var psi = new System.Diagnostics.ProcessStartInfo { FileName = this.GetLauncherPath(), @@ -91,6 +99,10 @@ public Task Launch(bool bForceAdmin = false) }); } + /// + /// Gets the launcher path. + /// + /// A string. public string GetLauncherPath() { string env = Environment.CurrentDirectory; @@ -100,9 +112,18 @@ public string GetLauncherPath() return Path.Combine(current, "BackgroundLaunch.exe"); } + + /// + /// Creates the launch info string. + /// + /// A string. public string CreateLaunchInfoString() { - var li = new LaunchInfo() { Solution = this.Solution, Target = this.Target.Location }; + var li = new LaunchInfo() + { + Solution = this.Solution ?? new VsFolder(this.SingleItem ?? throw new NullReferenceException()), + Target = this.Target.Location + }; JsonSerializerSettings settings = new JsonSerializerSettings() { diff --git a/VSLauncherX/MainDialog.cs b/VSLauncherX/MainDialog.cs index 800f744..40fc89b 100644 --- a/VSLauncherX/MainDialog.cs +++ b/VSLauncherX/MainDialog.cs @@ -1055,7 +1055,7 @@ private void runToolStripMenuItem_Click(object sender, EventArgs e) { if (!Properties.Settings.Default.DontShowMultiplesWarning) { - var n = f.ContainedSolutionsCount()+f.ContainedProjectsCount(); + var n = f.ContainedSolutionsCount() + f.ContainedProjectsCount(); if (n > 3) { var dlg = new dlgWarnMultiple(n); @@ -1083,14 +1083,23 @@ private void runToolStripMenuItem_Click(object sender, EventArgs e) if (il != null) { + var vsi = item as VsItem; + this.mainStatusLabel.Text = $"Launching '{vsi.Name}'"; il.Launch().Wait(); if (il.LastException != null) { _ = MessageBox.Show(il.LastException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } + this.mainStatusLabel.Text = ""; } } + + /// + /// Handles the favorites menu item + /// + /// The sender. + /// The e. private void favoriteToolStripMenuItem_Click(object sender, EventArgs e) { // make the selected item a favorite and add to the taskbar