forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CosmosDebugEnginePackage.cs
79 lines (66 loc) · 3.05 KB
/
CosmosDebugEnginePackage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using Cosmos.VS.DebugEngine.Commands;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
[assembly: ProvideBindingRedirection(
AssemblyName = "SQLitePCLRaw.batteries_v2",
NewVersion = "2.0.6.1341",
OldVersionLowerBound = "1.0.0.0",
OldVersionUpperBound = "2.0.6.1341")]
[assembly: ProvideBindingRedirection(
AssemblyName = "SQLitePCLRaw.core",
NewVersion = "2.0.6.1341",
OldVersionLowerBound = "1.0.0.0",
OldVersionUpperBound = "2.0.6.1341")]
[assembly: ProvideBindingRedirection(
AssemblyName = "SQLitePCLRaw.provider.e_sqlite3",
NewVersion = "2.0.6.1341",
OldVersionLowerBound = "1.0.0.0",
OldVersionUpperBound = "2.0.6.1341")]
namespace Cosmos.VS.DebugEngine
{
[Guid(Guids.guidPackageString)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
internal sealed class CosmosDebugEnginePackage : AsyncPackage, IOleCommandTarget
{
private IOleCommandTarget packageCommandTarget;
private DebugCommandHandler packageCommandHandler;
protected override async Task InitializeAsync(
CancellationToken cancellationToken,
IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
var xDir = IntPtr.Size == 4 ? "x86" : "x64";
Environment.SetEnvironmentVariable("PATH", // add path so that it finds SQLitePCLRaw.nativelibrary
String.Join(";", Environment.GetEnvironmentVariable("PATH"),
Path.Combine(Path.GetDirectoryName(typeof(CosmosDebugEnginePackage).Assembly.Location), xDir)));
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
packageCommandTarget = await GetServiceAsync(typeof(IOleCommandTarget)).ConfigureAwait(true) as IOleCommandTarget;
packageCommandHandler = new DebugCommandHandler(this);
}
int IOleCommandTarget.Exec(ref Guid cmdGroup, uint nCmdID, uint nCmdExecOpt, IntPtr pvaIn, IntPtr pvaOut)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (cmdGroup == Guids.DebugEngineCmdSetGuid)
{
return packageCommandHandler.Execute(nCmdID, nCmdExecOpt, pvaIn, pvaOut);
}
return packageCommandTarget.Exec(ref cmdGroup, nCmdID, nCmdExecOpt, pvaIn, pvaOut);
}
int IOleCommandTarget.QueryStatus(ref Guid cmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (cmdGroup == Guids.DebugEngineCmdSetGuid)
{
return packageCommandHandler.Query(cCmds, prgCmds, pCmdText);
}
return packageCommandTarget.QueryStatus(ref cmdGroup, cCmds, prgCmds, pCmdText);
}
}
}