Skip to content

Commit b25e5be

Browse files
authored
Merge pull request #4526 from comintern/next
Cull build warnings
2 parents d0bcf61 + a0a59f5 commit b25e5be

File tree

105 files changed

+608
-146
lines changed

Some content is hidden

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

105 files changed

+608
-146
lines changed

Rubberduck.CodeAnalysis/Inspections/Inspector.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,25 @@ private bool IsDisabled(CodeInspectionSettings config, IInspection inspection)
250250

251251
public void Dispose()
252252
{
253+
Dispose(true);
254+
GC.SuppressFinalize(this);
255+
}
256+
257+
private bool _isDisposed;
258+
protected virtual void Dispose(bool disposing)
259+
{
260+
if (_isDisposed || !disposing)
261+
{
262+
return;
263+
}
264+
253265
if (_configService != null)
254266
{
255267
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
256268
}
257269

258-
_inspections.Clear();
270+
_inspections.Clear();
271+
_isDisposed = true;
259272
}
260273
}
261274
}

Rubberduck.Core/AppMenu.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public void Localize()
7171

7272
public void Dispose()
7373
{
74+
Dispose(true);
75+
GC.SuppressFinalize(this);
76+
}
77+
78+
private bool _isDisposed;
79+
protected virtual void Dispose(bool disposing)
80+
{
81+
if (_isDisposed || !disposing)
82+
{
83+
return;
84+
}
85+
_isDisposed = true;
86+
7487
_parser.State.StateChanged -= OnParserStateChanged;
7588
_selectionService.SelectedDeclarationChanged -= OnSelectedDeclarationChange;
7689

Rubberduck.Core/AutoComplete/Service/AutoCompleteService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ private void HandleKeyDown(object sender, AutoCompleteEventArgs e)
147147

148148
public void Dispose()
149149
{
150+
Dispose(true);
151+
GC.SuppressFinalize(this);
152+
}
153+
154+
private bool _isDisposed;
155+
protected virtual void Dispose(bool disposing)
156+
{
157+
if (_isDisposed || !disposing)
158+
{
159+
return;
160+
}
161+
_isDisposed = true;
162+
150163
Disable();
151164
if (_configService != null)
152165
{

Rubberduck.Core/CodeAnalysis/CodeMetrics/CodeMetricsViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList, IEnumer
120120

121121
public void Dispose()
122122
{
123+
Dispose(true);
124+
GC.SuppressFinalize(this);
125+
}
126+
127+
private bool _isDisposed;
128+
protected virtual void Dispose(bool disposing)
129+
{
130+
if (_isDisposed || !disposing)
131+
{
132+
return;
133+
}
134+
_isDisposed = true;
135+
123136
_state.StateChanged -= OnStateChanged;
124137
}
125138

Rubberduck.Core/Common/Hotkeys/Hotkey.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Hotkey(IntPtr hWndVbe, string key, CommandBase command, Keys secondKey =
3333
public Keys Combo { get; }
3434
public Keys SecondKey { get; }
3535
public bool IsTwoStepHotkey { get; }
36-
public bool IsAttached => HotkeyInfo.HookId != IntPtr.Zero;
36+
public bool IsAttached => HotkeyInfo.HookId != 0;
3737

3838
public event EventHandler<HookEventArgs> MessageReceived;
3939

@@ -69,9 +69,10 @@ public void Detach()
6969
return;
7070
}
7171

72-
if (!User32.UnregisterHotKey(_hWndVbe, HotkeyInfo.HookId))
72+
if (!User32.UnregisterHotKey(_hWndVbe, new IntPtr(HotkeyInfo.HookId)))
7373
{
74-
Logger.Warn($"Error calling UnregisterHotKey on hokey with id {HotkeyInfo.HookId} for command of type {Command.GetType()}; the error was {Marshal.GetLastWin32Error()}; going to delete the atom anyway... The memory may leak.");
74+
var error = Marshal.GetLastWin32Error();
75+
Logger.Warn($"Error calling UnregisterHotKey on hokey with id {HotkeyInfo.HookId} for command of type {Command.GetType()}; the error was {error}; going to delete the atom anyway... The memory may leak.");
7576
}
7677
Kernel32.SetLastError(Kernel32.ERROR_SUCCESS);
7778
Kernel32.GlobalDeleteAtom(HotkeyInfo.HookId);
@@ -81,7 +82,7 @@ public void Detach()
8182
Logger.Warn($"Error calling DeleteGlobalAtom; the error was {lastError}, the id {HotkeyInfo.HookId} and the type of the associated command {Command.GetType()}.");
8283
}
8384

84-
HotkeyInfo = new HotkeyInfo(IntPtr.Zero, Combo);
85+
HotkeyInfo = new HotkeyInfo(0, Combo);
8586
ClearCommandShortcutText();
8687
}
8788

@@ -92,14 +93,15 @@ private void HookKey(Keys key, uint shift)
9293
return;
9394
}
9495

95-
var hookId = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
96-
if (hookId == IntPtr.Zero)
97-
{
98-
Logger.Warn($"Error calling GlobalAddAtom; the error was {Marshal.GetLastWin32Error()}; aborting the HookKey operation...");
96+
var hookId = Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
97+
var error = Marshal.GetLastWin32Error();
98+
if (hookId == 0)
99+
{
100+
Logger.Warn($"Error calling GlobalAddAtom; the error was {error}; aborting the HookKey operation...");
99101
return;
100102
}
101103

102-
var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);
104+
var success = User32.RegisterHotKey(_hWndVbe, new IntPtr(hookId), shift, (uint)key);
103105
if (!success)
104106
{
105107
Logger.Debug(RubberduckUI.CommonHotkey_KeyNotRegistered, key);

Rubberduck.Core/Common/Hotkeys/HotkeyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public struct HotkeyInfo
99
{
1010
private const Keys Modifiers = Keys.Alt | Keys.Control | Keys.Shift;
1111

12-
public HotkeyInfo(IntPtr hookId, Keys keys)
12+
public HotkeyInfo(ushort hookId, Keys keys)
1313
{
1414
HookId = hookId;
1515
Keys = keys;
1616
}
1717

18-
public IntPtr HookId { get; }
18+
public ushort HookId { get; }
1919
public Keys Keys { get; }
2020

2121
public override string ToString()

Rubberduck.Core/Common/RubberduckHooks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private bool HandleHotkeyMessage(IntPtr wParam)
172172
var processed = false;
173173
try
174174
{
175-
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
175+
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == (ushort)wParam);
176176
if (hook != null)
177177
{
178178
hook.OnMessageReceived();

Rubberduck.Core/Common/WinAPI/Kernel32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class Kernel32
2828
/// <param name="nAtom">The atom and character string to be deleted.</param>
2929
/// <returns>The function always returns (ATOM) 0.</returns>
3030
[DllImport("kernel32.dll", SetLastError=true, ExactSpelling=true)]
31-
public static extern ushort GlobalDeleteAtom(IntPtr nAtom);
31+
public static extern ushort GlobalDeleteAtom(ushort nAtom);
3232

3333
/// <summary>
3434
/// Sets the last-error code for the calling thread.

Rubberduck.Core/UI/CodeExplorer/CodeExplorerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Rubberduck.UI.CodeExplorer
88
{
99
[ExcludeFromCodeCoverage]
10-
public partial class CodeExplorerWindow : UserControl, IDockableUserControl
10+
public sealed partial class CodeExplorerWindow : UserControl, IDockableUserControl
1111
{
1212
private const string ClassId = "C5318B59-172F-417C-88E3-B377CDA2D809";
1313
string IDockableUserControl.ClassId { get { return ClassId; } }

Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,20 @@ protected override void OnExecute(object parameter)
7272

7373
public void Dispose()
7474
{
75-
if (_saveFileDialog != null)
75+
Dispose(true);
76+
GC.SuppressFinalize(this);
77+
}
78+
79+
private bool _isDisposed;
80+
protected virtual void Dispose(bool disposing)
81+
{
82+
if (_isDisposed || !disposing)
7683
{
77-
_saveFileDialog.Dispose();
84+
return;
7885
}
86+
87+
_saveFileDialog?.Dispose();
88+
_isDisposed = true;
7989
}
8090
}
8191
}

0 commit comments

Comments
 (0)