Skip to content

Commit dae9d51

Browse files
authored
Feature: Increased maximum volume label length to 128 characters for UDF images (#12931)
1 parent 393c09b commit dae9d51

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

src/Files.App/Data/Items/DriveItem.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ public DriveItem()
157157
ItemType = NavigationControlItemType.CloudDrive;
158158
}
159159

160-
public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root, string deviceId, DriveType type, IRandomAccessStream imageStream = null)
160+
public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root, string deviceId, string label, DriveType type, IRandomAccessStream imageStream = null)
161161
{
162162
var item = new DriveItem();
163163

164164
if (imageStream is not null)
165165
item.IconData = await imageStream.ToByteArrayAsync();
166166

167-
item.Text = type is DriveType.Network ? $"{root.DisplayName} ({deviceId})" : root.DisplayName;
167+
item.Text = type switch
168+
{
169+
DriveType.Network => $"{root.DisplayName} ({deviceId})",
170+
DriveType.CDRom when !string.IsNullOrEmpty(label) => root.DisplayName.Replace(label.Left(32), label),
171+
_ => root.DisplayName
172+
};
168173
item.Type = type;
169174
item.MenuOptions = new ContextMenuOptions
170175
{
@@ -248,7 +253,7 @@ public async Task LoadThumbnailAsync(bool isSidebar = false)
248253
{
249254
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
250255
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);
251-
256+
252257
if (Root is not null)
253258
{
254259
using var thumbnail = await DriveHelpers.GetThumbnailAsync(Root);

src/Files.App/Files.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<ItemGroup>
7272
<PackageReference Include="ByteSize" Version="2.1.1" />
7373
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
74+
<PackageReference Include="DiscUtils.Udf" Version="0.16.13" />
7475
<PackageReference Include="FluentFTP" Version="43.0.1" />
7576
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
7677
<PackageReference Include="LibGit2Sharp" Version="0.27.2" />

src/Files.App/Helpers/Storage/DriveHelpers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Windows.Devices.Portable;
1717
using Windows.Storage;
1818
using Windows.Storage.FileProperties;
19+
using DiscUtils.Udf;
1920

2021
namespace Files.App.Helpers
2122
{
@@ -136,6 +137,21 @@ public static Data.Items.DriveType GetDriveType(System.IO.DriveInfo drive)
136137
};
137138
}
138139

140+
public static string GetExtendedDriveLabel(DriveInfo drive)
141+
{
142+
if (drive.DriveType is not System.IO.DriveType.CDRom || drive.DriveFormat is not "UDF")
143+
return drive.VolumeLabel;
144+
return SafetyExtensions.IgnoreExceptions(() =>
145+
{
146+
var dosDevicePath = Vanara.PInvoke.Kernel32.QueryDosDevice(drive.Name).FirstOrDefault();
147+
if (string.IsNullOrEmpty(dosDevicePath))
148+
return drive.VolumeLabel;
149+
using var driveStream = new FileStream(dosDevicePath.Replace(@"\Device\", @"\\.\"), FileMode.Open, FileAccess.Read);
150+
using var udf = new UdfReader(driveStream);
151+
return udf.VolumeLabel;
152+
}) ?? drive.VolumeLabel;
153+
}
154+
139155
public static async Task<StorageItemThumbnail> GetThumbnailAsync(StorageFolder folder)
140156
=> (StorageItemThumbnail)await FilesystemTasks.Wrap(()
141157
=> folder.GetThumbnailAsync(ThumbnailMode.SingleItem, 40, ThumbnailOptions.UseCurrentScale).AsTask()

src/Files.App/Services/RemovableDrivesService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
3838

3939
using var thumbnail = await DriveHelpers.GetThumbnailAsync(res.Result);
4040
var type = DriveHelpers.GetDriveType(drive);
41-
var driveItem = await DriveItem.CreateFromPropertiesAsync(res.Result, drive.Name.TrimEnd('\\'), type, thumbnail);
41+
var label = DriveHelpers.GetExtendedDriveLabel(drive);
42+
var driveItem = await DriveItem.CreateFromPropertiesAsync(res.Result, drive.Name.TrimEnd('\\'), label, type, thumbnail);
4243

4344
App.Logger.LogInformation($"Drive added: {driveItem.Path}, {driveItem.Type}");
4445

src/Files.App/Utils/WindowsStorageDeviceWatcher.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ private async void Win32_OnDeviceAdded(object? sender, DeviceEventArgs e)
6464
}
6565

6666
var type = DriveHelpers.GetDriveType(driveAdded);
67-
DriveItem driveItem = await DriveItem.CreateFromPropertiesAsync(rootAdded, e.DeviceId, type);
67+
var label = DriveHelpers.GetExtendedDriveLabel(driveAdded);
68+
DriveItem driveItem = await DriveItem.CreateFromPropertiesAsync(rootAdded, e.DeviceId, label, type);
6869

6970
DeviceAdded?.Invoke(this, driveItem);
7071
}
@@ -95,18 +96,21 @@ private async void Watcher_Added(DeviceWatcher sender, DeviceInformation args)
9596
}
9697

9798
Data.Items.DriveType type;
99+
string label;
98100
try
99101
{
100102
// Check if this drive is associated with a drive letter
101103
var driveAdded = new DriveInfo(root.Path);
102104
type = DriveHelpers.GetDriveType(driveAdded);
105+
label = DriveHelpers.GetExtendedDriveLabel(driveAdded);
103106
}
104107
catch (ArgumentException)
105108
{
106109
type = Data.Items.DriveType.Removable;
110+
label = string.Empty;
107111
}
108112

109-
var driveItem = await DriveItem.CreateFromPropertiesAsync(root, deviceId, type);
113+
var driveItem = await DriveItem.CreateFromPropertiesAsync(root, deviceId, label, type);
110114

111115
DeviceAdded?.Invoke(this, driveItem);
112116
}

0 commit comments

Comments
 (0)