Skip to content

Commit

Permalink
added status bar info
Browse files Browse the repository at this point in the history
fixed an admin execution bug
  • Loading branch information
Andreas Saurwein committed Sep 7, 2023
1 parent 33c1e3f commit 07a9e46
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
12 changes: 10 additions & 2 deletions BackgroundLaunch/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions VSLXshared/DataModel/VsFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public VsFolder(string name, string path) : base(name, path, null)
this.ItemType = ItemTypeEnum.Folder;
}

/// <summary>
/// Initializes a new instance of the <see cref="VsFolder"/> class.
/// </summary>
/// <param name="singleItem">The single item.</param>
public VsFolder(VsItem singleItem)
{
this.Items = new VsItemList(this)
{
singleItem
};
this.ItemType = ItemTypeEnum.Folder;
}

/// <summary>
/// Gets or sets a value indicating whether checked.
/// </summary>
Expand Down
31 changes: 26 additions & 5 deletions VSLauncherX/ItemLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public class ItemLauncher
/// <param name="target">The target.</param>
public ItemLauncher(VsItem item, VisualStudioInstance target)
{
this.Solution = new VsFolder();
this.Solution.Items.Add(item);
this.Target = target;
this.SingleItem = item;
}

/// <summary>
Expand All @@ -43,7 +42,12 @@ public ItemLauncher(VsFolder item, VisualStudioInstance target)
/// <summary>
/// Gets the launch item.
/// </summary>
public VsFolder Solution { get; }
public VsFolder? Solution { get; }

/// <summary>
/// Gets the single item.
/// </summary>
public VsItem? SingleItem { get; }

/// <summary>
/// Gets the target.
Expand All @@ -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(),
Expand All @@ -91,6 +99,10 @@ public Task Launch(bool bForceAdmin = false)
});
}

/// <summary>
/// Gets the launcher path.
/// </summary>
/// <returns>A string.</returns>
public string GetLauncherPath()
{
string env = Environment.CurrentDirectory;
Expand All @@ -100,9 +112,18 @@ public string GetLauncherPath()

return Path.Combine(current, "BackgroundLaunch.exe");
}

/// <summary>
/// Creates the launch info string.
/// </summary>
/// <returns>A string.</returns>
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()
{
Expand Down
11 changes: 10 additions & 1 deletion VSLauncherX/MainDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = "";
}
}

/// <summary>
/// Handles the favorites menu item
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void favoriteToolStripMenuItem_Click(object sender, EventArgs e)
{
// make the selected item a favorite and add to the taskbar
Expand Down

0 comments on commit 07a9e46

Please sign in to comment.