Skip to content

Commit

Permalink
Elevate privileges when required. Version up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaliszko committed Apr 2, 2014
1 parent 4801b62 commit 3f0de96
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
42 changes: 33 additions & 9 deletions src/Resurrect/AttachCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using EnvDTE80;
using EnvDTE90;
Expand All @@ -21,7 +22,7 @@ public class AttachCenter
private OleMenuCommand _command;

private static AttachCenter _instance;
private static readonly object _locker = new object();
private static readonly object _locker = new object();

private AttachCenter(IServiceProvider provider, Debugger3 dteDebugger)
{
Expand Down Expand Up @@ -136,19 +137,42 @@ private void AttachToProcesses(object sender, EventArgs e)
}
}
}
foreach (var process in processes)
{
process.Attach2(engines.Any() ? engines.ToArray() : new[] { transport.Engines.Item("Managed/Native") });
}

PerformAttachOperation(processes, engines, transport);
}
else
{
ShowMessage("No historic processes found alive. Debug session cannot be resurrected.");
ShowMessage("No historic processes found alive. Debug session cannot be resurrected.", OLEMSGICON.OLEMSGICON_INFO);
}
}
}

private void ShowMessage(string message)
private void PerformAttachOperation(IList<Process3> processes, IList<Engine> engines, Transport transport)
{
try
{
foreach (var process in processes)
{
process.Attach2(engines.Any() ? engines.ToArray() : new[] {transport.Engines.Item("Managed/Native")});
}
}
catch (COMException ex)
{
ThrowElevationRequired();
}
catch (Exception ex)
{
ShowMessage(string.Format("Unexpected problem: {0}.", ex.Message), OLEMSGICON.OLEMSGICON_CRITICAL);
}
}

private void ThrowElevationRequired()
{
const int ERROR_ELEVATION_REQUIRED = unchecked((int)0x800702E4);
Marshal.ThrowExceptionForHR(ERROR_ELEVATION_REQUIRED);
}

private void ShowMessage(string message, OLEMSGICON type)
{
var shell = (IVsUIShell)_provider.GetService(typeof(SVsUIShell));
var clsid = Guid.Empty;
Expand All @@ -163,7 +187,7 @@ private void ShowMessage(string message)
0,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
OLEMSGICON.OLEMSGICON_INFO,
type,
0, // false
out pnResult);
}
Expand All @@ -187,6 +211,6 @@ private int AskQuestion(string message)
0, // false
out pnResult);
return pnResult;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Resurrect/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]



2 changes: 1 addition & 1 deletion src/Resurrect/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Identifier Id="ae98c9e5-8e14-4c92-b45a-c4fd24a498ef">
<Name>Resurrect</Name>
<Author>Jaroslaw Waliszko</Author>
<Version>1.2</Version>
<Version>1.3</Version>
<Description xml:space="preserve">Resurrects debugging session with previously attached processes.</Description>
<MoreInfoUrl>https://github.com/JaroslawWaliszko/Resurrect</MoreInfoUrl>
<License>LICENSE.txt</License>
Expand Down

0 comments on commit 3f0de96

Please sign in to comment.