Skip to content

Commit 1c25322

Browse files
committed
Correct non-existent normalization of path strings
1 parent 0d90f42 commit 1c25322

13 files changed

+108
-129
lines changed

Files UWP/App.xaml.cs

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Windows.UI.Core;
3030
using Windows.Storage.Search;
3131
using Windows.UI.Xaml.Input;
32+
using Windows.UI.Xaml.Controls.Primitives;
3233

3334
namespace Files
3435
{
@@ -42,6 +43,7 @@ public App()
4243
{
4344
this.InitializeComponent();
4445
exceptionDialog = new Dialogs.ExceptionDialog();
46+
consentDialog = new Dialogs.ConsentDialog();
4547
this.Suspending += OnSuspending;
4648
this.UnhandledException += App_UnhandledException;
4749

@@ -131,29 +133,39 @@ public void PopulateDrivesListWithLocalDisks()
131133
if (!(await KnownFolders.RemovableDevices.GetFoldersAsync()).Select(x => x.Path).ToList().Contains(roots.Name))
132134
{
133135
// TODO: Display Custom Names for Local Disks as well
134-
content = $"Local Disk ({roots.Name.TrimEnd('\\')})";
135-
icon = "\uEDA2";
136+
if(InstanceTabsView.NormalizePath(roots.Name) != InstanceTabsView.NormalizePath("A:")
137+
&& InstanceTabsView.NormalizePath(roots.Name) != InstanceTabsView.NormalizePath("B:"))
138+
{
139+
content = $"Local Disk ({roots.Name.TrimEnd('\\')})";
140+
icon = "\uEDA2";
141+
}
142+
else
143+
{
144+
content = $"Floppy Disk ({roots.Name.TrimEnd('\\')})";
145+
icon = "\uE74E";
146+
}
147+
136148

137149
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
138150
async () =>
139151
{
140-
StorageFolder drive = await StorageFolder.GetFolderFromPathAsync(roots.Name);
141-
var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
142-
152+
Visibility capacityBarVis = Visibility.Visible;
143153
ulong totalSpaceProg = 0;
144154
ulong freeSpaceProg = 0;
145155
string free_space_text = "Unknown";
146156
string total_space_text = "Unknown";
147-
Visibility capacityBarVis = Visibility.Visible;
157+
148158
try
149159
{
160+
StorageFolder drive = await StorageFolder.GetFolderFromPathAsync(roots.Name);
161+
var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
162+
150163
var sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).GigaBytes;
151164
freeSpaceProg = Convert.ToUInt64(sizeAsGBString);
152165

153166
sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).GigaBytes;
154167
totalSpaceProg = Convert.ToUInt64(sizeAsGBString);
155168

156-
157169
free_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).ToString();
158170
total_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).ToString();
159171
}
@@ -193,8 +205,16 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
193205

194206
private async void Watcher_EnumerationCompleted(DeviceWatcher sender, object args)
195207
{
196-
PopulateDrivesListWithLocalDisks();
208+
try
209+
{
210+
PopulateDrivesListWithLocalDisks();
211+
}
212+
catch (UnauthorizedAccessException)
213+
{
214+
await consentDialog.ShowAsync();
215+
}
197216
DeviceAdded(sender, null);
217+
198218
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
199219
() =>
200220
{
@@ -241,14 +261,12 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
241261
{
242262
try
243263
{
244-
//var device = StorageDevice.FromId(args.Id);
245264
var devices = (await KnownFolders.RemovableDevices.GetFoldersAsync()).OrderBy(x => x.Path);
246-
foreach(StorageFolder device in devices)
265+
foreach (StorageFolder device in devices)
247266
{
248267
var letter = device.Path;
249-
if(!foundDrives.Any(x => x.tag == letter))
268+
if (!foundDrives.Any(x => x.tag == letter))
250269
{
251-
//if (roots.Name == @"C:\") return;
252270
var content = device.DisplayName;
253271
string icon = null;
254272
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
@@ -263,23 +281,22 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
263281
icon = "\uE88E";
264282
}
265283

266-
StorageFolder drive = await StorageFolder.GetFolderFromPathAsync(letter);
267-
var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
268-
269284
ulong totalSpaceProg = 0;
270285
ulong freeSpaceProg = 0;
271286
string free_space_text = "Unknown";
272287
string total_space_text = "Unknown";
273288
Visibility capacityBarVis = Visibility.Visible;
274289
try
275290
{
291+
StorageFolder drive = await StorageFolder.GetFolderFromPathAsync(letter);
292+
var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
293+
276294
var sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).GigaBytes;
277295
freeSpaceProg = Convert.ToUInt64(sizeAsGBString);
278296

279297
sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).GigaBytes;
280298
totalSpaceProg = Convert.ToUInt64(sizeAsGBString);
281299

282-
283300
free_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).ToString();
284301
total_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).ToString();
285302
}
@@ -306,33 +323,25 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
306323
});
307324
}
308325
});
309-
326+
310327
}
311328
}
312329
}
313-
catch (UnauthorizedAccessException e)
330+
catch (UnauthorizedAccessException)
314331
{
315-
Debug.WriteLine(e.Message);
332+
await consentDialog.ShowAsync();
316333
}
317334
}
318335

319336
public static List<string> LinesToRemoveFromFile = new List<string>();
320337

321338
public async void PopulatePinnedSidebarItems()
322339
{
323-
324340
AddDefaultLocations();
325341

326342
StorageFile ListFile;
327343
StorageFolder cacheFolder = ApplicationData.Current.LocalCacheFolder;
328-
try
329-
{
330-
ListFile = await cacheFolder.GetFileAsync("PinnedItems.txt");
331-
}
332-
catch (FileNotFoundException)
333-
{
334-
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt");
335-
}
344+
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt", CreationCollisionOption.OpenIfExists);
336345

337346
if (ListFile != null)
338347
{
@@ -399,14 +408,7 @@ public static async void RemoveStaleSidebarItems()
399408
{
400409
StorageFile ListFile;
401410
StorageFolder cacheFolder = ApplicationData.Current.LocalCacheFolder;
402-
try
403-
{
404-
ListFile = await cacheFolder.GetFileAsync("PinnedItems.txt");
405-
}
406-
catch (FileNotFoundException)
407-
{
408-
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt");
409-
}
411+
ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt", CreationCollisionOption.OpenIfExists);
410412

411413
if (ListFile != null)
412414
{
@@ -464,17 +466,32 @@ public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
464466
public static Windows.UI.Xaml.UnhandledExceptionEventArgs exceptionInfo { get; set; }
465467
public static string exceptionStackTrace { get; set; }
466468
public Dialogs.ExceptionDialog exceptionDialog;
469+
public static Dialogs.ConsentDialog consentDialog { get; set; }
467470

468471
private async void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
469472
{
470473
e.Handled = true;
471-
if(exceptionDialog.Visibility == Visibility.Visible)
472-
exceptionDialog.Hide();
473-
474474
exceptionInfo = e;
475475
exceptionStackTrace = e.Exception.StackTrace;
476-
await exceptionDialog.ShowAsync();
476+
await exceptionDialog.ShowAsync();
477+
}
477478

479+
public static IReadOnlyList<ContentDialog> FindDisplayedContentDialogs<T>()
480+
{
481+
var popupElements = VisualTreeHelper.GetOpenPopupsForXamlRoot(Window.Current.Content.XamlRoot);
482+
List<ContentDialog> dialogs = new List<ContentDialog>();
483+
List<ContentDialog> openDialogs = new List<ContentDialog>();
484+
Interaction.FindChildren<ContentDialog>(dialogs, Window.Current.Content.XamlRoot.Content as DependencyObject);
485+
foreach(var dialog in dialogs)
486+
{
487+
var popups = new List<Popup>();
488+
Interaction.FindChildren<Popup>(popups, dialog);
489+
if (popups.First().IsOpen && popups.First() is T)
490+
{
491+
openDialogs.Add(dialog);
492+
}
493+
}
494+
return openDialogs;
478495
}
479496

480497
public static PasteState PS { get; set; } = new PasteState();

Files UWP/FilesUWP.csproj

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,36 +304,31 @@
304304
<Version>1.3.0</Version>
305305
</PackageReference>
306306
<PackageReference Include="Microsoft.AppCenter.Analytics">
307-
<Version>2.1.1</Version>
307+
<Version>2.6.1</Version>
308308
</PackageReference>
309309
<PackageReference Include="Microsoft.AppCenter.Crashes">
310-
<Version>2.1.1</Version>
311-
</PackageReference>
312-
<PackageReference Include="Microsoft.Net.Compilers">
313-
<Version>3.3.1</Version>
314-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
315-
<PrivateAssets>all</PrivateAssets>
310+
<Version>2.6.1</Version>
316311
</PackageReference>
317312
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
318313
<Version>6.2.9</Version>
319314
</PackageReference>
320315
<PackageReference Include="Microsoft.Toolkit.Uwp">
321-
<Version>5.1.1</Version>
316+
<Version>6.0.0</Version>
322317
</PackageReference>
323318
<PackageReference Include="Microsoft.Toolkit.Uwp.DeveloperTools">
324-
<Version>5.1.1</Version>
319+
<Version>6.0.0</Version>
325320
</PackageReference>
326321
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
327-
<Version>5.1.1</Version>
322+
<Version>6.0.0</Version>
328323
</PackageReference>
329324
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
330-
<Version>5.1.1</Version>
325+
<Version>6.0.0</Version>
331326
</PackageReference>
332327
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
333-
<Version>5.1.1</Version>
328+
<Version>6.0.0</Version>
334329
</PackageReference>
335330
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.DataGrid">
336-
<Version>5.1.0</Version>
331+
<Version>6.0.0</Version>
337332
</PackageReference>
338333
<PackageReference Include="Microsoft.UI.Xaml">
339334
<Version>2.2.190917002</Version>

Files UWP/Filesystem/ItemViewModel.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,6 @@ public static T GetCurrentSelectedTabInstance<T>()
443443
return default;
444444
}
445445

446-
public async void DisplayConsentDialog()
447-
{
448-
await App.selectedTabInstance.consentDialog.ShowAsync();
449-
}
450446
bool isLoadingItems = false;
451447
public async void AddItemsToCollectionAsync(string path)
452448
{
@@ -618,19 +614,9 @@ public async void AddItemsToCollectionAsync(string path)
618614
Debug.WriteLine("Loading of items in " + Universal.path + " completed in " + stopwatch.ElapsedMilliseconds + " milliseconds.\n");
619615
App.selectedTabInstance.RefreshButton.IsEnabled = true;
620616
}
621-
catch (UnauthorizedAccessException e)
617+
catch (UnauthorizedAccessException)
622618
{
623-
if (path.Contains(@"C:\"))
624-
{
625-
DisplayConsentDialog();
626-
}
627-
else
628-
{
629-
MessageDialog unsupportedDevice = new MessageDialog("This device may be unsupported. Please file an issue report containing what device we couldn't access. Technical information: " + e, "Unsupported Device");
630-
await unsupportedDevice.ShowAsync();
631-
isLoadingItems = false;
632-
return;
633-
}
619+
await App.consentDialog.ShowAsync();
634620
}
635621
catch (COMException e)
636622
{

Files UWP/InstanceTabsView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</Grid.ColumnDefinitions>
125125
<ContentPresenter Background="{StaticResource ApplicationPageBackgroundThemeBrush}" x:Name="ContentPresenter" Grid.Row="1" Grid.ColumnSpan="2" Content="{x:Bind ((uilib:TabViewItem)(local:InstanceTabsView).TabStrip.SelectedItem).Content, Mode=OneWay}"/>
126126

127-
<uilib:TabView Grid.Row="0" AddTabButtonClick="TabStrip_AddTabButtonClick" Style="{ThemeResource TabViewStyleFixed}" SelectionChanged="TabStrip_SelectionChanged" TabCloseRequested="TabStrip_TabCloseRequested" Name="TabStrip" TabWidthMode="Equal" VerticalAlignment="Stretch">
127+
<uilib:TabView Grid.Row="0" AddTabButtonClick="TabStrip_AddTabButtonClick" Style="{ThemeResource TabViewStyleFixed}" SelectionChanged="TabStrip_SelectionChanged" TabCloseRequested="TabStrip_TabCloseRequested" x:Name="TabStrip" TabWidthMode="Equal" VerticalAlignment="Stretch">
128128

129129
</uilib:TabView>
130130
<Grid Grid.Column="1" Background="{ThemeResource TabViewBackground}"/>

Files UWP/InstanceTabsView.xaml.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Collections.ObjectModel;
66
using System.IO;
7+
using System.Linq;
78
using Windows.ApplicationModel.Core;
89
using Windows.Foundation;
910
using Windows.Storage;
@@ -236,35 +237,58 @@ public async void SetSelectedTabInfo(string text, string currentPathForTabIcon =
236237
else
237238
{
238239
// If path is a drive's root
239-
if(Path.GetPathRoot(currentPathForTabIcon) == currentPathForTabIcon && currentPathForTabIcon == @"C:\")
240+
if (NormalizePath(Path.GetPathRoot(currentPathForTabIcon)) == NormalizePath(currentPathForTabIcon))
240241
{
241-
tabLocationHeader = @"Local Disk (C:\)";
242-
fontIconSource.Glyph = "\xEDA2";
243-
}
244-
else if (Path.GetPathRoot(currentPathForTabIcon) == currentPathForTabIcon && currentPathForTabIcon != @"C:\")
245-
{
246-
tabLocationHeader = currentPathForTabIcon;
247-
if (await KnownFolders.RemovableDevices.TryGetItemAsync(currentPathForTabIcon) == null)
242+
if (NormalizePath(currentPathForTabIcon) != NormalizePath("A:") && NormalizePath(currentPathForTabIcon) != NormalizePath("B:"))
248243
{
249-
fontIconSource.Glyph = "\xEDA2";
244+
var remDriveNames = (await KnownFolders.RemovableDevices.GetFoldersAsync()).Select(x => x.DisplayName);
245+
246+
if (!remDriveNames.Contains(NormalizePath(currentPathForTabIcon)))
247+
{
248+
fontIconSource.Glyph = "\xEDA2";
249+
tabLocationHeader = "Local Disk (" + NormalizePath(currentPathForTabIcon) + ")";
250+
}
251+
else
252+
{
253+
fontIconSource.Glyph = "\xE88E";
254+
tabLocationHeader = (await KnownFolders.RemovableDevices.GetFolderAsync(currentPathForTabIcon)).DisplayName;
255+
}
250256
}
251257
else
252258
{
253-
fontIconSource.Glyph = "\xE88E";
259+
fontIconSource.Glyph = "\xE74E";
260+
tabLocationHeader = "Floppy Disk (" + NormalizePath(currentPathForTabIcon) + ")";
254261
}
255262
}
256263
else
257264
{
258-
tabLocationHeader = currentPathForTabIcon.Split("\\", StringSplitOptions.RemoveEmptyEntries)[currentPathForTabIcon.Split("\\", StringSplitOptions.RemoveEmptyEntries).Length - 1];
259265
fontIconSource.Glyph = "\xE8B7";
266+
tabLocationHeader = currentPathForTabIcon.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Split('\\', StringSplitOptions.RemoveEmptyEntries).Last();
260267
}
261-
268+
262269
}
263270
tabIcon = fontIconSource;
264271
(tabView.SelectedItem as TabViewItem).Header = tabLocationHeader;
265272
(tabView.SelectedItem as TabViewItem).IconSource = tabIcon;
266273
}
267274

275+
public static string NormalizePath(string path)
276+
{
277+
if (path.Contains('\\'))
278+
{
279+
return Path.GetFullPath(new Uri(path).LocalPath)
280+
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
281+
.ToUpperInvariant();
282+
}
283+
else
284+
{
285+
return Path.GetFullPath(path)
286+
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
287+
.ToUpperInvariant();
288+
}
289+
290+
}
291+
268292
private void DragArea_Loaded(object sender, RoutedEventArgs e)
269293
{
270294
Window.Current.SetTitleBar(sender as Grid);

Files UWP/ProHome.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@
777777
</StackPanel>
778778
</Custom:TabViewItem>
779779
<Custom:TabView.Resources>
780-
<uilib:TeachingTip Loaded="RibbonTip_Loaded" Target="{x:Bind Ribbon}" x:Key="RibbonTipKey" Name="RibbonTip" PreferredPlacement="Bottom" Subtitle="Access different commands faster than ever from their new location." Title="Meet the Ribbon">
780+
<uilib:TeachingTip Loaded="RibbonTip_Loaded" Target="{x:Bind Ribbon}" x:Key="RibbonTipKey" x:Name="RibbonTip" PreferredPlacement="Bottom" Subtitle="Access different commands faster than ever from their new location." Title="Meet the Ribbon">
781781
<uilib:TeachingTip.IconSource>
782782
<uilib:SymbolIconSource Symbol="Help"/>
783783
</uilib:TeachingTip.IconSource>

Files UWP/ProHome.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public sealed partial class ProHome : Page
6060
public AddItemDialog addItemDialog = new AddItemDialog();
6161
public LayoutDialog layoutDialog = new LayoutDialog();
6262
public PropertiesDialog propertiesDialog = new PropertiesDialog();
63-
public ConsentDialog consentDialog = new ConsentDialog();
6463
public ListView accessiblePathListView;
6564
public ObservableCollection<PathBoxItem> pathBoxItems = new ObservableCollection<PathBoxItem>();
6665
private ItemViewModel _instanceViewModel;

0 commit comments

Comments
 (0)