Skip to content

Commit a2f44ff

Browse files
committed
.net 6, bump v1.1.0
1 parent 4f67ad1 commit a2f44ff

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

CatalogTcx.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<RootNamespace>catalog_tcx</RootNamespace>
77
<Authors>Steven M. Cohn</Authors>
88
<Company>River Software</Company>
@@ -12,6 +12,9 @@
1212
<PackageIcon>Garmin.ico</PackageIcon>
1313
<PackageIconUrl />
1414
<ApplicationIcon>assets\Garmin.ico</ApplicationIcon>
15+
<AssemblyVersion>1.1.0</AssemblyVersion>
16+
<FileVersion>$(AssemblyVersion)</FileVersion>
17+
<Version>$(AssemblyVersion)</Version>
1518
</PropertyGroup>
1619

1720
<ItemGroup>

GlobalSuppressions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:CatalogTcx.UsbFactory.GetAvailableDisks~System.Collections.Generic.List{CatalogTcx.UsbDisk}")]
9+
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:CatalogTcx.WmiExtensions.First(System.Management.ManagementObjectSearcher)~System.Management.ManagementObject")]
10+
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:CatalogTcx.UsbFactory.GetAvailableDisks~System.Collections.Generic.IEnumerable{CatalogTcx.UsbDisk}")]

Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ where e.Attribute("StartTime") != null
132132
private static int ScanGarmin (string path)
133133
{
134134
int count = 0;
135-
List<UsbDisk> disks = null;
135+
IEnumerable<UsbDisk> disks = null;
136136

137137
try
138138
{
@@ -144,7 +144,7 @@ private static int ScanGarmin (string path)
144144
return count;
145145
}
146146

147-
if ((disks != null) && (disks.Count > 0))
147+
if ((disks != null) && (disks.Any()))
148148
{
149149
var disk = disks.FirstOrDefault(
150150
e => e.Model.StartsWith("Garmin", StringComparison.InvariantCulture));

UsbFactory.cs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,40 @@ internal class UsbFactory
2020
/// </summary>
2121
/// <returns>A List of UsbDisk instances.</returns>
2222

23-
public List<UsbDisk> GetAvailableDisks ()
23+
public IEnumerable<UsbDisk> GetAvailableDisks()
2424
{
25-
var disks = new List<UsbDisk>();
25+
using var searcher = new ManagementObjectSearcher(
26+
"select DeviceID, Model from Win32_DiskDrive where InterfaceType='USB'").Get();
2627

27-
using (var searcher = new ManagementObjectSearcher(
28-
"select DeviceID, Model from Win32_DiskDrive where InterfaceType='USB'").Get())
28+
// browse all USB WMI physical disks
29+
foreach (var o in searcher)
2930
{
30-
// browse all USB WMI physical disks
31-
foreach (var o in searcher)
32-
{
33-
var drive = (ManagementObject) o;
34-
// associate physical disks with partitions
35-
using (var partition = new ManagementObjectSearcher(
36-
$"associators of {{Win32_DiskDrive.DeviceID='{drive["DeviceID"]}'}} where AssocClass = Win32_DiskDriveToDiskPartition").First())
37-
{
38-
if (partition == null) continue;
31+
var drive = (ManagementObject)o;
3932

40-
// associate partitions with logical disks (drive letter volumes)
41-
using (var logical = new ManagementObjectSearcher(
42-
$"associators of {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} where AssocClass = Win32_LogicalDiskToPartition").First())
43-
{
44-
if (logical == null) continue;
33+
// associate physical disks with partitions
34+
using var partition = new ManagementObjectSearcher(
35+
$"associators of {{Win32_DiskDrive.DeviceID='{drive["DeviceID"]}'}} where AssocClass = Win32_DiskDriveToDiskPartition").First();
4536

46-
// finally find the logical disk entry to determine the volume name
47-
using (var volume = new ManagementObjectSearcher(
48-
$"select FreeSpace, Size, VolumeName from Win32_LogicalDisk where Name='{logical["Name"]}'").First())
49-
{
50-
var disk = new UsbDisk(logical["Name"].ToString())
51-
{
52-
Model = drive["Model"].ToString(),
53-
Volume = volume["VolumeName"].ToString(),
54-
FreeSpace = (ulong) volume["FreeSpace"],
55-
Size = (ulong) volume["Size"]
56-
};
37+
if (partition == null) continue;
5738

58-
disks.Add(disk);
59-
}
60-
}
61-
}
62-
}
63-
}
39+
// associate partitions with logical disks (drive letter volumes)
40+
using var logical = new ManagementObjectSearcher(
41+
$"associators of {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} where AssocClass = Win32_LogicalDiskToPartition").First();
42+
43+
if (logical == null) continue;
6444

65-
return disks;
45+
// finally find the logical disk entry to determine the volume name
46+
using var volume = new ManagementObjectSearcher(
47+
$"select FreeSpace, Size, VolumeName from Win32_LogicalDisk where Name='{logical["Name"]}'").First();
48+
49+
yield return new UsbDisk(logical["Name"].ToString())
50+
{
51+
Model = drive["Model"].ToString(),
52+
Volume = volume["VolumeName"].ToString(),
53+
FreeSpace = (ulong)volume["FreeSpace"],
54+
Size = (ulong)volume["Size"]
55+
};
56+
}
6657
}
6758
}
6859
}

0 commit comments

Comments
 (0)