Skip to content

Commit ab840f1

Browse files
authored
Fix warnings (#8032)
1 parent a30cf0a commit ab840f1

26 files changed

+409
-435
lines changed

src/Files.Launcher/ContextMenu.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using System.IO;
77
using System.Linq;
88
using System.Runtime.InteropServices;
9+
using System.Runtime.Versioning;
910
using Vanara.InteropServices;
1011
using Vanara.PInvoke;
1112
using Vanara.Windows.Shell;
1213

1314
namespace FilesFullTrust
1415
{
16+
[SupportedOSPlatform("Windows10.0.10240")]
1517
public class ContextMenu : Win32ContextMenu, IDisposable
1618
{
1719
private Shell32.IContextMenu cMenu;
@@ -36,9 +38,11 @@ public bool InvokeVerb(string verb)
3638
try
3739
{
3840
var currentWindows = Win32API.GetDesktopWindows();
39-
var pici = new Shell32.CMINVOKECOMMANDINFOEX();
40-
pici.lpVerb = new SafeResourceId(verb, CharSet.Ansi);
41-
pici.nShow = ShowWindowCommand.SW_SHOWNORMAL;
41+
var pici = new Shell32.CMINVOKECOMMANDINFOEX
42+
{
43+
lpVerb = new SafeResourceId(verb, CharSet.Ansi),
44+
nShow = ShowWindowCommand.SW_SHOWNORMAL,
45+
};
4246
pici.cbSize = (uint)Marshal.SizeOf(pici);
4347
cMenu.InvokeCommand(pici);
4448
Win32API.BringToForeground(currentWindows);
@@ -63,9 +67,11 @@ public void InvokeItem(int itemID)
6367
try
6468
{
6569
var currentWindows = Win32API.GetDesktopWindows();
66-
var pici = new Shell32.CMINVOKECOMMANDINFOEX();
67-
pici.lpVerb = Macros.MAKEINTRESOURCE(itemID);
68-
pici.nShow = ShowWindowCommand.SW_SHOWNORMAL;
70+
var pici = new Shell32.CMINVOKECOMMANDINFOEX
71+
{
72+
lpVerb = Macros.MAKEINTRESOURCE(itemID),
73+
nShow = ShowWindowCommand.SW_SHOWNORMAL,
74+
};
6975
pici.cbSize = (uint)Marshal.SizeOf(pici);
7076
cMenu.InvokeCommand(pici);
7177
Win32API.BringToForeground(currentWindows);

src/Files.Launcher/DeviceWatcher.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
using Microsoft.Management.Infrastructure;
44
using System;
55
using System.IO.Pipes;
6+
using System.Runtime.Versioning;
67
using System.Threading.Tasks;
78
using Windows.Foundation.Collections;
89

910
namespace FilesFullTrust
1011
{
12+
[SupportedOSPlatform("Windows10.0.10240")]
1113
public class DeviceWatcher : IDisposable
1214
{
1315
private ManagementEventWatcher insertWatcher, removeWatcher, modifyWatcher;

src/Files.Launcher/FilePermissions.cs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Linq;
6+
using System.Runtime.Versioning;
67
using System.Security.AccessControl;
78
using System.Security.Principal;
89
using System.Threading.Tasks;
@@ -11,6 +12,7 @@
1112

1213
namespace FilesFullTrust
1314
{
15+
[SupportedOSPlatform("Windows10.0.10240")]
1416
public class FilePermissions
1517
{
1618
public string FilePath { get; set; }
@@ -216,48 +218,7 @@ public static async Task<string> OpenObjectPicker(long hwnd)
216218
});
217219
}
218220

219-
private IEnumerable<string> SearchForUserOrGroup(string userName, string domain = "")
220-
{
221-
try
222-
{
223-
using var session = CimSession.Create(null);
224-
var users = session
225-
.QueryInstances(@"root\cimv2", "WQL", $"select * from Win32_Account where Name like '%{userName}%' and Domain like '%{domain}%'");
226-
227-
return users.Select(x => x.CimInstanceProperties["SID"].Value as string);
228-
}
229-
catch
230-
{
231-
return null;
232-
}
233-
}
234-
235-
private IEnumerable<string> GetGroupsForUser(string sid)
236-
{
237-
try
238-
{
239-
using var session = CimSession.Create(null);
240-
var user = session
241-
.QueryInstances(@"root\cimv2", "WQL", $"select * from Win32_UserAccount where SID='{sid}'")
242-
.FirstOrDefault();
243-
244-
if (user != null)
245-
{
246-
var groups = session.EnumerateAssociatedInstances(@"root\cimv2", user, "Win32_GroupUser", "Win32_Group", null, null);
247-
return groups.Select(x => x.CimInstanceProperties["SID"].Value as string);
248-
}
249-
return null;
250-
}
251-
catch
252-
{
253-
return null;
254-
}
255-
}
256-
257-
public bool HasPermission(FileSystemRights perm)
258-
{
259-
return GetEffectiveRights().HasFlag(perm);
260-
}
221+
public bool HasPermission(FileSystemRights perm) => GetEffectiveRights().HasFlag(perm);
261222

262223
public FileSystemRights GetEffectiveRights()
263224
{
@@ -298,6 +259,7 @@ public FileSystemRights GetEffectiveRights()
298259
}
299260
}
300261

262+
[SupportedOSPlatform("Windows")]
301263
public class FileSystemAccessRule2
302264
{
303265
public AccessControlType AccessControlType { get; set; }

src/Files.Launcher/Helpers/CloudDrivesDetector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.Versioning;
78
using System.Threading.Tasks;
89

910
namespace FilesFullTrust.Helpers
1011
{
12+
[SupportedOSPlatform("Windows10.0.10240")]
1113
public class CloudDrivesDetector
1214
{
1315
public static async Task<List<CloudProvider>> DetectCloudDrives()

src/Files.Launcher/Helpers/DisposableDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace FilesFullTrust.Helpers
55
{
66
public class DisposableDictionary : IDisposable
77
{
8-
private ConcurrentDictionary<string, object> dict;
8+
private readonly ConcurrentDictionary<string, object> dict;
99

1010
public DisposableDictionary()
1111
{

src/Files.Launcher/Helpers/RemoteDataObject.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,36 @@
44
using System.Reflection;
55
using System.Runtime.InteropServices;
66
using System.Runtime.InteropServices.ComTypes;
7+
using System.Runtime.Versioning;
78
using System.Windows.Forms;
89
using Vanara.PInvoke;
910
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
1011

1112
namespace FilesFullTrust.Helpers
1213
{
1314
// Class taken from Rx-Explorer (https://github.com/zhuxb711/RX-Explorer)
15+
[SupportedOSPlatform("Windows")]
1416
public class RemoteDataObject
1517
{
1618
/// <summary>
1719
/// Holds the <see cref="System.Windows.IDataObject"/> that this class is wrapping
1820
/// </summary>
19-
private System.Windows.Forms.IDataObject underlyingDataObject;
21+
private readonly System.Windows.Forms.IDataObject underlyingDataObject;
2022

2123
/// <summary>
2224
/// Holds the <see cref="System.Runtime.InteropServices.ComTypes.IDataObject"/> interface to the <see cref="System.Windows.IDataObject"/> that this class is wrapping.
2325
/// </summary>
24-
private System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
26+
private readonly System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
2527

2628
/// <summary>
2729
/// Holds the internal ole <see cref="System.Windows.IDataObject"/> to the <see cref="System.Windows.IDataObject"/> that this class is wrapping.
2830
/// </summary>
29-
private System.Windows.Forms.IDataObject oleUnderlyingDataObject;
31+
private readonly System.Windows.Forms.IDataObject oleUnderlyingDataObject;
3032

3133
/// <summary>
3234
/// Holds the <see cref="MethodInfo"/> of the "GetDataFromHGLOBAL" method of the internal ole <see cref="System.Windows.IDataObject"/>.
3335
/// </summary>
34-
private MethodInfo getDataFromHGLOBALMethod;
36+
private readonly MethodInfo getDataFromHGLOBALMethod;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the class.

src/Files.Launcher/Helpers/ShellNewMenuHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.Versioning;
78
using System.Security;
89
using System.Text;
910
using System.Threading.Tasks;
1011
using Windows.Storage;
1112

1213
namespace FilesFullTrust.Helpers
1314
{
15+
[SupportedOSPlatform("Windows10.0.10240")]
1416
public static class ShellNewMenuHelper
1517
{
1618
public static async Task<List<ShellNewEntry>> GetNewContextMenuEntries()

src/Files.Launcher/Helpers/ThreadWithMessageQueue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Runtime.Versioning;
34
using System.Threading;
45
using System.Threading.Tasks;
56

67
namespace FilesFullTrust.Helpers
78
{
9+
[SupportedOSPlatform("Windows")]
810
public class ThreadWithMessageQueue<T> : IDisposable
911
{
1012
private readonly BlockingCollection<Internal> messageQueue;

src/Files.Launcher/LogWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using Files.Common;
22
using System;
33
using System.Diagnostics;
4+
using System.Runtime.Versioning;
45
using System.Text;
56
using System.Threading.Tasks;
67
using Windows.Storage;
78
using static Vanara.PInvoke.Kernel32;
89

910
namespace FilesFullTrust
1011
{
12+
[SupportedOSPlatform("Windows10.0.10240")]
1113
internal class LogWriter : ILogWriter
1214
{
1315
private string logFilePath;

src/Files.Launcher/MessageHandlers/ApplicationLaunchHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Files.Common;
2-
using Newtonsoft.Json;
32
using System;
43
using System.Collections;
54
using System.Collections.Generic;
@@ -8,6 +7,7 @@
87
using System.IO;
98
using System.IO.Pipes;
109
using System.Linq;
10+
using System.Runtime.Versioning;
1111
using System.Text.RegularExpressions;
1212
using System.Threading.Tasks;
1313
using Vanara.PInvoke;
@@ -16,6 +16,7 @@
1616

1717
namespace FilesFullTrust.MessageHandlers
1818
{
19+
[SupportedOSPlatform("Windows10.0.10240")]
1920
public class ApplicationLaunchHandler : IMessageHandler
2021
{
2122
public void Initialize(PipeStream connection)

0 commit comments

Comments
 (0)