Skip to content

Commit 7c7bd25

Browse files
authored
Merge pull request #4475 from bclothier/FixStubBase
Update Stubs & Fakes to use VBERuntime class
2 parents 4c06388 + e7e27d4 commit 7c7bd25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+520
-308
lines changed

Rubberduck.Core/AutoComplete/Service/AutoCompleteService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ private void Enable()
5757

5858
if (!_enabled)
5959
{
60-
VBENativeServices.KeyDown += HandleKeyDown;
61-
VBENativeServices.IntelliSenseChanged += HandleIntelliSenseChanged;
60+
VbeNativeServices.KeyDown += HandleKeyDown;
61+
VbeNativeServices.IntelliSenseChanged += HandleIntelliSenseChanged;
6262
_enabled = true;
6363
}
6464
}
@@ -67,8 +67,8 @@ private void Disable()
6767
{
6868
if (_enabled && _initialized)
6969
{
70-
VBENativeServices.KeyDown -= HandleKeyDown;
71-
VBENativeServices.IntelliSenseChanged -= HandleIntelliSenseChanged;
70+
VbeNativeServices.KeyDown -= HandleKeyDown;
71+
VbeNativeServices.IntelliSenseChanged -= HandleIntelliSenseChanged;
7272
_enabled = false;
7373
_popupShown = false;
7474
}

Rubberduck.Core/UI/Command/ReparseCommand.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
using Rubberduck.Settings;
1010
using Rubberduck.SettingsProvider;
1111
using Rubberduck.Resources;
12-
using Rubberduck.UI.CodeExplorer.Commands;
1312
using Rubberduck.VBEditor.ComManagement.TypeLibsAPI;
1413
using Rubberduck.VBEditor.SafeComWrappers;
1514
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
16-
using Rubberduck.VBEditor.VBERuntime.Settings;
15+
using Rubberduck.VBEditor.VbeRuntime.Settings;
1716

1817
namespace Rubberduck.UI.Command
1918
{
@@ -22,12 +21,12 @@ public class ReparseCommand : CommandBase
2221
{
2322
private readonly IVBE _vbe;
2423
private readonly IVBETypeLibsAPI _typeLibApi;
25-
private readonly IVBESettings _vbeSettings;
24+
private readonly IVbeSettings _vbeSettings;
2625
private readonly IMessageBox _messageBox;
2726
private readonly RubberduckParserState _state;
2827
private readonly GeneralSettings _settings;
2928

30-
public ReparseCommand(IVBE vbe, IConfigProvider<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IVBESettings vbeSettings, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
29+
public ReparseCommand(IVBE vbe, IConfigProvider<GeneralSettings> settingsProvider, RubberduckParserState state, IVBETypeLibsAPI typeLibApi, IVbeSettings vbeSettings, IMessageBox messageBox) : base(LogManager.GetCurrentClassLogger())
3130
{
3231
_vbe = vbe;
3332
_vbeSettings = vbeSettings;

Rubberduck.Core/UI/SelectionChangeService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public SelectionChangeService(IVBE vbe, IParseCoordinator parser)
3030
{
3131
_parser = parser;
3232
_vbe = vbe;
33-
VBENativeServices.SelectionChanged += OnVbeSelectionChanged;
34-
VBENativeServices.WindowFocusChange += OnVbeFocusChanged;
33+
VbeNativeServices.SelectionChanged += OnVbeSelectionChanged;
34+
VbeNativeServices.WindowFocusChange += OnVbeFocusChanged;
3535
}
3636

3737
private void OnVbeSelectionChanged(object sender, EventArgs e)
@@ -69,7 +69,7 @@ private void OnVbeFocusChanged(object sender, WindowChangedEventArgs e)
6969
//Caret changed in a code pane.
7070
Task.Run(() =>
7171
{
72-
using (var pane = VBENativeServices.GetCodePaneFromHwnd(e.Hwnd))
72+
using (var pane = VbeNativeServices.GetCodePaneFromHwnd(e.Hwnd))
7373
{
7474
DispatchSelectedDeclaration(
7575
new DeclarationChangedEventArgs(_vbe, _parser.State.FindSelectedDeclaration(pane)));
@@ -186,8 +186,8 @@ private bool DeclarationChanged(Declaration current)
186186

187187
public void Dispose()
188188
{
189-
VBENativeServices.SelectionChanged -= OnVbeSelectionChanged;
190-
VBENativeServices.WindowFocusChange -= OnVbeFocusChanged;
189+
VbeNativeServices.SelectionChanged -= OnVbeSelectionChanged;
190+
VbeNativeServices.WindowFocusChange -= OnVbeFocusChanged;
191191
}
192192
}
193193

Rubberduck.Core/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using NLog;
99
using Rubberduck.SettingsProvider;
1010
using Rubberduck.UI.Command;
11-
using Rubberduck.VBEditor.VBERuntime.Settings;
11+
using Rubberduck.VBEditor.VbeRuntime.Settings;
1212
using Rubberduck.Resources;
1313

1414
namespace Rubberduck.UI.Settings
@@ -23,12 +23,12 @@ public class GeneralSettingsViewModel : SettingsViewModelBase, ISettingsViewMode
2323
{
2424
private readonly IOperatingSystem _operatingSystem;
2525
private readonly IMessageBox _messageBox;
26-
private readonly IVBESettings _vbeSettings;
26+
private readonly IVbeSettings _vbeSettings;
2727

2828
private bool _indenterPrompted;
2929
private readonly ReadOnlyCollection<Type> _experimentalFeatureTypes;
3030

31-
public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem, IMessageBox messageBox, IVBESettings vbeSettings, IEnumerable<Type> experimentalFeatureTypes)
31+
public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem, IMessageBox messageBox, IVbeSettings vbeSettings, IEnumerable<Type> experimentalFeatureTypes)
3232
{
3333
_operatingSystem = operatingSystem;
3434
_messageBox = messageBox;

Rubberduck.Core/UI/Settings/SettingsForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Rubberduck.Settings;
33
using Rubberduck.Common;
44
using Rubberduck.Interaction;
5-
using Rubberduck.VBEditor.VBERuntime.Settings;
5+
using Rubberduck.VBEditor.VbeRuntime.Settings;
66
using System.Collections.Generic;
77
using System;
88

@@ -21,7 +21,7 @@ public SettingsForm()
2121
InitializeComponent();
2222
}
2323

24-
public SettingsForm(IGeneralConfigService configService, IOperatingSystem operatingSystem, IMessageBox messageBox, IVBESettings vbeSettings, SettingsViews activeView = SettingsViews.GeneralSettings) : this()
24+
public SettingsForm(IGeneralConfigService configService, IOperatingSystem operatingSystem, IMessageBox messageBox, IVbeSettings vbeSettings, SettingsViews activeView = SettingsViews.GeneralSettings) : this()
2525
{
2626
var config = configService.LoadConfiguration();
2727

Rubberduck.Deployment/Rubberduck.Deployment.csproj

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<None Include="BuildRegistryScript.ps1" />
1818
<None Include="Licenses\License.rtf" />
1919
<None Include="PreInnoSetupConfiguration.ps1" />
20+
<Content Include="..\packages\EasyHook.2.7.6684\content\net40\**" CopyToPublishDirectory="PreserveNewest" Link="%(Filename)%(Extension)" />
2021
</ItemGroup>
2122
<ItemGroup>
2223
<ProjectReference Include="..\Rubberduck.API\Rubberduck.API.csproj" />
@@ -36,7 +37,19 @@
3637
<HintPath>OleWoo\olewoo_interop.dll</HintPath>
3738
</Reference>
3839
</ItemGroup>
39-
40+
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
41+
<Copy SourceFiles="%(Content.Identity)"
42+
DestinationFiles="$(OutputPath)\%(Content.Link)"
43+
SkipUnchangedFiles="true"
44+
OverwriteReadOnlyFiles="true" />
45+
</Target>
46+
<Target Name="InnoSetupConfig" BeforeTargets="PreBuildEvent">
47+
<CreateProperty Value="&amp; '$(ProjectDir)PreInnoSetupConfiguration.ps1' -WorkingDir '$(ProjectDir)'">
48+
<Output TaskParameter="Value" PropertyName="PowershellCommand" />
49+
</CreateProperty>
50+
<Exec Command="%25SystemRoot%25\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -command &quot;$(PowershellCommand)&quot;" ConsoleToMsBuild="true" />
51+
<Message Text="Ran InnoSetupConfig" Importance="normal" />
52+
</Target>
4053
<Target Name="Register" AfterTargets="PostBuildEvent">
4154
<GetFrameworkSdkPath>
4255
<Output TaskParameter="Path" PropertyName="SdkPath" />
@@ -50,11 +63,4 @@
5063
<Exec Command="%25SystemRoot%25\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -command &quot;$(PowershellCommand)&quot;" ConsoleToMsBuild="true" />
5164
<Message Text="Ran Registration script" Importance="normal" />
5265
</Target>
53-
<Target Name="InnoSetupConfig" BeforeTargets="PreBuildEvent">
54-
<CreateProperty Value="&amp; '$(ProjectDir)PreInnoSetupConfiguration.ps1' -WorkingDir '$(ProjectDir)'">
55-
<Output TaskParameter="Value" PropertyName="PowershellCommand" />
56-
</CreateProperty>
57-
<Exec Command="%25SystemRoot%25\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -command &quot;$(PowershellCommand)&quot;" ConsoleToMsBuild="true" />
58-
<Message Text="Ran InnoSetupConfig" Importance="normal" />
59-
</Target>
6066
</Project>

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/CurDir.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class CurDir : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDir");
10-
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDirBstr");
11-
129
public CurDir()
1310
{
14-
InjectDelegate(new CurDirStringDelegate(CurDirStringCallback), ProcessAddressString);
15-
InjectDelegate(new CurDirVariantDelegate(CurDirVariantCallback), ProcessAddressVariant);
11+
var processAddressVariant = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcCurrentDir");
12+
var processAddressString = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcCurrentDirBstr");
13+
14+
InjectDelegate(new CurDirStringDelegate(CurDirStringCallback), processAddressString);
15+
InjectDelegate(new CurDirVariantDelegate(CurDirVariantCallback), processAddressVariant);
1616
}
1717

1818
public override bool PassThrough

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Date.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Rubberduck.UnitTesting.Fakes
55
{
66
internal class Date : FakeBase
77
{
8-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetDateVar");
9-
108
public Date()
119
{
12-
InjectDelegate(new DateDelegate(DateCallback), ProcessAddress);
13-
}
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcGetDateVar");
1411

15-
[DllImport(TargetLibrary, SetLastError = true)]
16-
private static extern void rtcGetDateVar(out object retVal);
12+
InjectDelegate(new DateDelegate(DateCallback), processAddress);
13+
}
1714

1815
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
1916
private delegate void DateDelegate(IntPtr retVal);
@@ -28,7 +25,7 @@ public void DateCallback(IntPtr retVal)
2825
if (PassThrough)
2926
{
3027
object result;
31-
rtcGetDateVar(out result);
28+
VbeProvider.VbeRuntime.GetDateVar(out result);
3229
Marshal.GetNativeVariantForObject(result, retVal);
3330
return;
3431
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/DoEvents.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using Rubberduck.UnitTesting.ComClientHelpers;
2-
using System;
32
using System.Runtime.InteropServices;
43

54
namespace Rubberduck.UnitTesting.Fakes
65
{
76
internal class DoEvents : FakeBase
87
{
9-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcDoEvents");
10-
118
public DoEvents()
129
{
13-
InjectDelegate(new DoEventsDelegate(DoEventsCallback), ProcessAddress);
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcDoEvents");
11+
12+
InjectDelegate(new DoEventsDelegate(DoEventsCallback), processAddress);
1413
}
1514

1615
private readonly ValueTypeConverter<int> _converter = new ValueTypeConverter<int>();
@@ -20,10 +19,6 @@ public override void Returns(object value, int invocation = FakesProvider.AllInv
2019
base.Returns((int)_converter.Value, invocation);
2120
}
2221

23-
[DllImport(TargetLibrary, SetLastError = true)]
24-
[return: MarshalAs(UnmanagedType.I4)]
25-
private static extern int rtcDoEvents();
26-
2722
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
2823
[return: MarshalAs(UnmanagedType.I4)]
2924
private delegate int DoEventsDelegate();
@@ -34,7 +29,7 @@ public int DoEventsCallback()
3429

3530
if (PassThrough)
3631
{
37-
return rtcDoEvents();
32+
return VbeProvider.VbeRuntime.DoEvents();
3833
}
3934
return (int)(ReturnValue ?? 0);
4035
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Environ.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class Environ : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironBstr");
10-
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironVar");
11-
129
public Environ()
1310
{
14-
InjectDelegate(new EnvironStringDelegate(EnvironStringCallback), ProcessAddressString);
15-
InjectDelegate(new EnvironVariantDelegate(EnvironVariantCallback), ProcessAddressVariant);
11+
var processAddressString = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcEnvironBstr");
12+
var processAddressVariant = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcEnvironVar");
13+
14+
InjectDelegate(new EnvironStringDelegate(EnvironStringCallback), processAddressString);
15+
InjectDelegate(new EnvironVariantDelegate(EnvironVariantCallback), processAddressVariant);
1616
}
1717

1818
public override bool PassThrough

0 commit comments

Comments
 (0)