From f77259adebe64f2bbc5b7a5b51643973eab9bb1f Mon Sep 17 00:00:00 2001
From: d2dyno <53011783+d2dyno1@users.noreply.github.com>
Date: Sun, 13 Aug 2023 17:28:48 +0200
Subject: [PATCH] Fix: Fixed issue where items in the Tags widget were not
localized (#13149)
---
.../NativeStorage/NativeFile.cs | 8 +--
.../NativeStorage/NativeFolder.cs | 8 +--
.../NativeStorage/NativeStorable.cs | 8 +--
.../NativeStorage/NativeStorageService.cs | 27 ++++++++--
.../Content/Archives/DecompressArchive.cs | 1 +
.../Install/InstallCertificateAction.cs | 2 +-
.../Content/Install/InstallFontAction.cs | 2 +-
.../Content/Install/InstallInfDriverAction.cs | 2 +-
.../Actions/Content/PlayAllAction.cs | 2 +
.../Actions/Content/Run/RunAsAdminAction.cs | 2 +
.../Content/Run/RunAsAnotherUserAction.cs | 2 +
.../Content/Run/RunWithPowershellAction.cs | 2 +-
.../PropertiesNavigationViewItemFactory.cs | 1 +
src/Files.App/Data/Items/ListedItem.cs | 6 +--
src/Files.App/Data/Models/ItemViewModel.cs | 1 +
.../SelectedItemsPropertiesViewModel.cs | 1 +
.../Data/Models/SidebarPinnedModel.cs | 3 --
.../MenuFlyout/ContextFlyoutItemHelper.cs | 2 +
.../MenuFlyout/ShellContextMenuHelper.cs | 1 +
.../Helpers/Navigation/NavigationHelpers.cs | 14 +-----
src/Files.App/Program.cs | 1 +
.../Utils/Archives/ArchiveHelpers.cs | 2 +-
src/Files.App/Utils/Shell/LaunchHelper.cs | 1 +
.../Enumerators/UniversalStorageEnumerator.cs | 1 +
.../Enumerators/Win32StorageEnumerator.cs | 1 +
.../Storage/Helpers/FileOperationsHelpers.cs | 1 +
.../Storage/Helpers/FileThumbnailHelper.cs | 1 +
.../Utils/Storage/Helpers/StorageHelpers.cs | 1 +
.../Operations/FilesystemOperations.cs | 1 +
.../Storage/StorageItems/NativeStorageFile.cs | 1 +
.../Storage/StorageItems/ZipStorageFile.cs | 1 +
.../Storage/StorageItems/ZipStorageFolder.cs | 3 +-
.../Properties/Items/FileProperties.cs | 1 +
.../UserControls/PreviewPaneViewModel.cs | 1 +
.../UserControls/ToolbarViewModel.cs | 1 +
.../Widgets/FileTagsItemViewModel.cs | 10 ++--
.../Extensions/StorageExtensions.Storable.cs | 6 +--
src/Files.Core/Helpers/PathHelpers.cs | 38 --------------
.../FileTagsWidget/FileTagsItemViewModel.cs | 1 +
.../Helpers/FileExtensionHelpers.cs | 5 +-
src/Files.Shared/Helpers/PathHelpers.cs | 49 +++++++++++++++++++
41 files changed, 132 insertions(+), 90 deletions(-)
delete mode 100644 src/Files.Core/Helpers/PathHelpers.cs
rename src/{Files.Core => Files.Shared}/Helpers/FileExtensionHelpers.cs (99%)
diff --git a/src/Files.App.Storage/NativeStorage/NativeFile.cs b/src/Files.App.Storage/NativeStorage/NativeFile.cs
index a22e9b6eab57..bb8fbea713f7 100644
--- a/src/Files.App.Storage/NativeStorage/NativeFile.cs
+++ b/src/Files.App.Storage/NativeStorage/NativeFile.cs
@@ -15,13 +15,13 @@ namespace Files.App.Storage.NativeStorage
///
public class NativeFile : NativeStorable, ILocatableFile, IModifiableFile, IFileExtended, INestedFile
{
- public NativeFile(FileInfo fileInfo)
- : base(fileInfo)
+ public NativeFile(FileInfo fileInfo, string? name = null)
+ : base(fileInfo, name)
{
}
- public NativeFile(string path)
- : this(new FileInfo(path))
+ public NativeFile(string path, string? name = null)
+ : this(new FileInfo(path), name)
{
}
diff --git a/src/Files.App.Storage/NativeStorage/NativeFolder.cs b/src/Files.App.Storage/NativeStorage/NativeFolder.cs
index fedea9a05bfb..d59f2e02ef49 100644
--- a/src/Files.App.Storage/NativeStorage/NativeFolder.cs
+++ b/src/Files.App.Storage/NativeStorage/NativeFolder.cs
@@ -22,13 +22,13 @@ namespace Files.App.Storage.NativeStorage
///
public class NativeFolder : NativeStorable, ILocatableFolder, IModifiableFolder, IMutableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove
{
- public NativeFolder(DirectoryInfo directoryInfo)
- : base(directoryInfo)
+ public NativeFolder(DirectoryInfo directoryInfo, string? name = null)
+ : base(directoryInfo, name)
{
}
- public NativeFolder(string path)
- : this(new DirectoryInfo(path))
+ public NativeFolder(string path, string? name = null)
+ : this(new DirectoryInfo(path), name)
{
}
diff --git a/src/Files.App.Storage/NativeStorage/NativeStorable.cs b/src/Files.App.Storage/NativeStorage/NativeStorable.cs
index 1a8fbcc3ca7a..966dc97d3d32 100644
--- a/src/Files.App.Storage/NativeStorage/NativeStorable.cs
+++ b/src/Files.App.Storage/NativeStorage/NativeStorable.cs
@@ -17,19 +17,19 @@ public abstract class NativeStorable : ILocatableStorable, INestedStor
protected readonly TStorage storage;
///
- public virtual string Path { get; protected set; }
+ public string Path { get; protected set; }
///
- public virtual string Name { get; protected set; }
+ public string Name { get; protected set; }
///
public virtual string Id { get; }
- protected NativeStorable(TStorage storage)
+ protected NativeStorable(TStorage storage, string? name = null)
{
this.storage = storage;
Path = storage.FullName;
- Name = storage.Name;
+ Name = name ?? storage.Name;
Id = storage.FullName;
}
diff --git a/src/Files.App.Storage/NativeStorage/NativeStorageService.cs b/src/Files.App.Storage/NativeStorage/NativeStorageService.cs
index 7e2326325dce..5812862ba8a9 100644
--- a/src/Files.App.Storage/NativeStorage/NativeStorageService.cs
+++ b/src/Files.App.Storage/NativeStorage/NativeStorageService.cs
@@ -2,10 +2,12 @@
// Licensed under the MIT License. See the LICENSE.
using Files.Core.Storage;
-using Files.Core.Storage.LocatableStorage;
+using Files.Shared.Helpers;
+using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
+using Windows.Storage;
namespace Files.App.Storage.NativeStorage
{
@@ -22,12 +24,31 @@ public Task GetFileAsync(string id, CancellationToken cancellationToken =
}
///
- public Task GetFolderAsync(string id, CancellationToken cancellationToken = default)
+ public async Task GetFolderAsync(string id, CancellationToken cancellationToken = default)
{
if (!Directory.Exists(id))
throw new DirectoryNotFoundException();
- return Task.FromResult(new NativeFolder(id));
+ // A special folder should use the localized name
+ if (PathHelpers.IsSpecialFolder(id))
+ {
+ var storageFolder = await TryGetStorageFolderAsync(id);
+ return new NativeFolder(id, storageFolder?.DisplayName);
+ }
+
+ return new NativeFolder(id);
+
+ async Task TryGetStorageFolderAsync(string path)
+ {
+ try
+ {
+ return await StorageFolder.GetFolderFromPathAsync(path);
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
}
}
}
diff --git a/src/Files.App/Actions/Content/Archives/DecompressArchive.cs b/src/Files.App/Actions/Content/Archives/DecompressArchive.cs
index 23dbb1b5f816..d3a73c6e140d 100644
--- a/src/Files.App/Actions/Content/Archives/DecompressArchive.cs
+++ b/src/Files.App/Actions/Content/Archives/DecompressArchive.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using System.IO;
namespace Files.App.Actions
diff --git a/src/Files.App/Actions/Content/Install/InstallCertificateAction.cs b/src/Files.App/Actions/Content/Install/InstallCertificateAction.cs
index 1bd17ebe0476..7da225655641 100644
--- a/src/Files.App/Actions/Content/Install/InstallCertificateAction.cs
+++ b/src/Files.App/Actions/Content/Install/InstallCertificateAction.cs
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using Files.App.Utils.Shell;
+using Files.Shared.Helpers;
namespace Files.App.Actions
{
diff --git a/src/Files.App/Actions/Content/Install/InstallFontAction.cs b/src/Files.App/Actions/Content/Install/InstallFontAction.cs
index 66a7cf8ada86..f0df08623624 100644
--- a/src/Files.App/Actions/Content/Install/InstallFontAction.cs
+++ b/src/Files.App/Actions/Content/Install/InstallFontAction.cs
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using Files.App.Utils.Shell;
+using Files.Shared.Helpers;
namespace Files.App.Actions
{
diff --git a/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs b/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs
index 960f98d68b35..d2bbe004b551 100644
--- a/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs
+++ b/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using Files.App.Utils.Shell;
+using Files.Shared.Helpers;
namespace Files.App.Actions
{
diff --git a/src/Files.App/Actions/Content/PlayAllAction.cs b/src/Files.App/Actions/Content/PlayAllAction.cs
index 3d8a58d7f029..3fdfc3c872a8 100644
--- a/src/Files.App/Actions/Content/PlayAllAction.cs
+++ b/src/Files.App/Actions/Content/PlayAllAction.cs
@@ -1,6 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
+
namespace Files.App.Actions
{
internal class PlayAllAction : ObservableObject, IAction
diff --git a/src/Files.App/Actions/Content/Run/RunAsAdminAction.cs b/src/Files.App/Actions/Content/Run/RunAsAdminAction.cs
index 8facd2f3807b..5bd841d8a4c5 100644
--- a/src/Files.App/Actions/Content/Run/RunAsAdminAction.cs
+++ b/src/Files.App/Actions/Content/Run/RunAsAdminAction.cs
@@ -1,6 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
+
namespace Files.App.Actions
{
internal class RunAsAdminAction : ObservableObject, IAction
diff --git a/src/Files.App/Actions/Content/Run/RunAsAnotherUserAction.cs b/src/Files.App/Actions/Content/Run/RunAsAnotherUserAction.cs
index f3e7b97df0a4..4832eeb2005f 100644
--- a/src/Files.App/Actions/Content/Run/RunAsAnotherUserAction.cs
+++ b/src/Files.App/Actions/Content/Run/RunAsAnotherUserAction.cs
@@ -1,6 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
+
namespace Files.App.Actions
{
internal class RunAsAnotherUserAction : ObservableObject, IAction
diff --git a/src/Files.App/Actions/Content/Run/RunWithPowershellAction.cs b/src/Files.App/Actions/Content/Run/RunWithPowershellAction.cs
index 85f153f6802a..9cd6c2771455 100644
--- a/src/Files.App/Actions/Content/Run/RunWithPowershellAction.cs
+++ b/src/Files.App/Actions/Content/Run/RunWithPowershellAction.cs
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using Files.App.Utils.Shell;
+using Files.Shared.Helpers;
namespace Files.App.Actions
{
diff --git a/src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs b/src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs
index 853e0cc3cd78..4c5753bcb44d 100644
--- a/src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs
+++ b/src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs
@@ -4,6 +4,7 @@
using Files.Core.Helpers;
using Microsoft.UI.Xaml;
using Windows.Storage;
+using Files.Shared.Helpers;
namespace Files.App.Data.Factories
{
diff --git a/src/Files.App/Data/Items/ListedItem.cs b/src/Files.App/Data/Items/ListedItem.cs
index 01d3badddb8f..3da5ce0fc22e 100644
--- a/src/Files.App/Data/Items/ListedItem.cs
+++ b/src/Files.App/Data/Items/ListedItem.cs
@@ -1,14 +1,10 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using Files.App.Utils.Cloud;
using Files.App.ViewModels.Properties;
-using Files.Core.Helpers;
-using Files.Core.ViewModels.FileTags;
+using Files.Shared.Helpers;
using FluentFTP;
-using Microsoft.UI;
using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
using System.Text;
diff --git a/src/Files.App/Data/Models/ItemViewModel.cs b/src/Files.App/Data/Models/ItemViewModel.cs
index 0fbd16382b0a..6de883a990b0 100644
--- a/src/Files.App/Data/Models/ItemViewModel.cs
+++ b/src/Files.App/Data/Models/ItemViewModel.cs
@@ -3,6 +3,7 @@
using Files.App.ViewModels.Previews;
using Files.Core.Services.SizeProvider;
+using Files.Shared.Helpers;
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Data;
diff --git a/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs b/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs
index 4338dec67433..3dc8693ab0f0 100644
--- a/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs
+++ b/src/Files.App/Data/Models/SelectedItemsPropertiesViewModel.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License. See the LICENSE.
using Files.App.ViewModels.Properties;
+using Files.Shared.Helpers;
namespace Files.App.Data.Models
{
diff --git a/src/Files.App/Data/Models/SidebarPinnedModel.cs b/src/Files.App/Data/Models/SidebarPinnedModel.cs
index 7b0956fa5863..05003bf47e73 100644
--- a/src/Files.App/Data/Models/SidebarPinnedModel.cs
+++ b/src/Files.App/Data/Models/SidebarPinnedModel.cs
@@ -1,9 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using CommunityToolkit.WinUI;
-using Files.App.Data.Items;
-using Files.App.Services;
using Files.App.UserControls.Widgets;
using System.Collections.Specialized;
using System.IO;
diff --git a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
index 304123e568ef..f1f47994a8b6 100644
--- a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
+++ b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
@@ -1,6 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.App.ViewModels.LayoutModes;
+using Files.Shared.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ViewModels.LayoutModes;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs b/src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs
index d26cb5389846..06c36a3f3643 100644
--- a/src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs
+++ b/src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs
@@ -3,6 +3,7 @@
using CommunityToolkit.WinUI.UI;
using Files.App.Helpers.ContextFlyouts;
+using Files.Shared.Helpers;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs
index ae0a93c54dba..420cbf9ccf64 100644
--- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs
+++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs
@@ -1,20 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-using CommunityToolkit.Mvvm.DependencyInjection;
-using Files.App.Extensions;
-using Files.App.Utils;
-using Files.App.Utils.Shell;
-using Files.App.ViewModels;
-using Files.App.Views;
-using Files.Core.Helpers;
-using Files.Core.Services.Settings;
-using Files.Shared;
+using Files.Shared.Helpers;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.System;
diff --git a/src/Files.App/Program.cs b/src/Files.App/Program.cs
index 5c40f054606a..31fbf6c315fa 100644
--- a/src/Files.App/Program.cs
+++ b/src/Files.App/Program.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppLifecycle;
diff --git a/src/Files.App/Utils/Archives/ArchiveHelpers.cs b/src/Files.App/Utils/Archives/ArchiveHelpers.cs
index 1a3fb3e8e457..c76b86cddd31 100644
--- a/src/Files.App/Utils/Archives/ArchiveHelpers.cs
+++ b/src/Files.App/Utils/Archives/ArchiveHelpers.cs
@@ -2,8 +2,8 @@
// Licensed under the MIT License. See the LICENSE.
using Files.App.Dialogs;
-using Files.App.Utils.Archives;
using Files.App.ViewModels.Dialogs;
+using Files.Shared.Helpers;
using Microsoft.UI.Xaml.Controls;
using System.IO;
using System.Text;
diff --git a/src/Files.App/Utils/Shell/LaunchHelper.cs b/src/Files.App/Utils/Shell/LaunchHelper.cs
index 73b73027d640..7bb34a51c441 100644
--- a/src/Files.App/Utils/Shell/LaunchHelper.cs
+++ b/src/Files.App/Utils/Shell/LaunchHelper.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Text.RegularExpressions;
diff --git a/src/Files.App/Utils/Storage/Enumerators/UniversalStorageEnumerator.cs b/src/Files.App/Utils/Storage/Enumerators/UniversalStorageEnumerator.cs
index 38eb5ed0a56c..2e4e74f0f880 100644
--- a/src/Files.App/Utils/Storage/Enumerators/UniversalStorageEnumerator.cs
+++ b/src/Files.App/Utils/Storage/Enumerators/UniversalStorageEnumerator.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
diff --git a/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs b/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs
index 18e64dc353af..d7128fc14ef7 100644
--- a/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs
+++ b/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License. See the LICENSE.
using Files.Core.Services.SizeProvider;
+using Files.Shared.Helpers;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
using Vanara.PInvoke;
diff --git a/src/Files.App/Utils/Storage/Helpers/FileOperationsHelpers.cs b/src/Files.App/Utils/Storage/Helpers/FileOperationsHelpers.cs
index 13889e49319d..c5b41f4ca770 100644
--- a/src/Files.App/Utils/Storage/Helpers/FileOperationsHelpers.cs
+++ b/src/Files.App/Utils/Storage/Helpers/FileOperationsHelpers.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using System.Collections.Concurrent;
diff --git a/src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs b/src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
index aa674e2a1241..77ecda3ff4d3 100644
--- a/src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
+++ b/src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Windows.Storage;
using Windows.Storage.FileProperties;
diff --git a/src/Files.App/Utils/Storage/Helpers/StorageHelpers.cs b/src/Files.App/Utils/Storage/Helpers/StorageHelpers.cs
index 8f5ebf0fe114..4f9f89066ccb 100644
--- a/src/Files.App/Utils/Storage/Helpers/StorageHelpers.cs
+++ b/src/Files.App/Utils/Storage/Helpers/StorageHelpers.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using System.Runtime.InteropServices;
using Windows.Storage;
using Windows.Storage.FileProperties;
diff --git a/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs b/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
index 602cbb052a42..0742b8ab3882 100644
--- a/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
+++ b/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.UI.Xaml.Controls;
using System.IO;
using System.Text;
diff --git a/src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs b/src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs
index df396fef8352..df77aef87ebe 100644
--- a/src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs
+++ b/src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
diff --git a/src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs b/src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs
index 53fe4a91de1d..2796042daa45 100644
--- a/src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs
+++ b/src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using SevenZip;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
diff --git a/src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs b/src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs
index ee0af2d40221..8ecf249e11da 100644
--- a/src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs
+++ b/src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs
@@ -1,9 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using SevenZip;
-using SQLitePCL;
-using System;
using System.Collections.Concurrent;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
diff --git a/src/Files.App/ViewModels/Properties/Items/FileProperties.cs b/src/Files.App/ViewModels/Properties/Items/FileProperties.cs
index a346b83440dc..980c1651e2b8 100644
--- a/src/Files.App/ViewModels/Properties/Items/FileProperties.cs
+++ b/src/Files.App/ViewModels/Properties/Items/FileProperties.cs
@@ -1,6 +1,7 @@
// Copyright(c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using Files.Shared.Helpers;
using Microsoft.UI.Dispatching;
using System.IO;
diff --git a/src/Files.App/ViewModels/UserControls/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/PreviewPaneViewModel.cs
index 5e1aaa9d5a7f..f8de7b4e10f2 100644
--- a/src/Files.App/ViewModels/UserControls/PreviewPaneViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/PreviewPaneViewModel.cs
@@ -3,6 +3,7 @@
using Files.App.UserControls.FilePreviews;
using Files.App.ViewModels.Previews;
+using Files.Shared.Helpers;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Windows.Input;
diff --git a/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs
index 9fa14d384e6a..5e6f735852a7 100644
--- a/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License. See the LICENSE.
using CommunityToolkit.WinUI.UI;
+using Files.Shared.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/Files.App/ViewModels/Widgets/FileTagsItemViewModel.cs b/src/Files.App/ViewModels/Widgets/FileTagsItemViewModel.cs
index 5199b196e0b8..0c3f681efcd4 100644
--- a/src/Files.App/ViewModels/Widgets/FileTagsItemViewModel.cs
+++ b/src/Files.App/ViewModels/Widgets/FileTagsItemViewModel.cs
@@ -21,11 +21,11 @@ public sealed partial class FileTagsItemViewModel : WidgetCardItem
[ObservableProperty]
private string _Name;
- private string path;
+ private string _Path;
public override string Path
{
- get => path;
- set => SetProperty(ref path, value);
+ get => _Path;
+ set => SetProperty(ref _Path, value);
}
public bool IsFolder => _associatedStorable is IFolder;
@@ -35,8 +35,8 @@ public FileTagsItemViewModel(IStorable associatedStorable, Func op
_associatedStorable = associatedStorable;
_openAction = openAction;
_Icon = icon;
- _Name = PathHelpers.FormatName(associatedStorable.Id);
- Path = associatedStorable.TryGetPath();
+ _Name = associatedStorable.Name;
+ _Path = associatedStorable.TryGetPath();
Item = this;
}
diff --git a/src/Files.Core.Storage/Extensions/StorageExtensions.Storable.cs b/src/Files.Core.Storage/Extensions/StorageExtensions.Storable.cs
index 18d8fff10a86..405bb2f27afe 100644
--- a/src/Files.Core.Storage/Extensions/StorageExtensions.Storable.cs
+++ b/src/Files.Core.Storage/Extensions/StorageExtensions.Storable.cs
@@ -11,10 +11,10 @@ public static partial class StorageExtensions
/// Tries to obtain path from the storable.
///
/// The storable item to get the path from.
- /// A path pointing to the item, otherwise null.
- public static string? TryGetPath(this IStorable storable)
+ /// A path pointing to the item.
+ public static string TryGetPath(this IStorable storable)
{
- return (storable as ILocatableStorable)?.Path;
+ return (storable as ILocatableStorable)?.Path ?? storable.Id;
}
}
}
\ No newline at end of file
diff --git a/src/Files.Core/Helpers/PathHelpers.cs b/src/Files.Core/Helpers/PathHelpers.cs
deleted file mode 100644
index 057c45f9b288..000000000000
--- a/src/Files.Core/Helpers/PathHelpers.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2023 Files Community
-// Licensed under the MIT License. See the LICENSE.
-
-using System.IO;
-
-namespace Files.Core.Helpers
-{
- public static class PathHelpers
- {
- public static string FormatName(string path)
- {
- string fileName;
- string rootPath = Path.GetPathRoot(path) ?? string.Empty;
-
- if (rootPath == path && path.StartsWith(@"\\"))
- {
- // Network Share path
- fileName = path.Substring(path.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
- }
- else if (rootPath == path)
- {
- // Drive path
- fileName = path;
- }
- else
- {
- // Standard file name
- fileName = Path.GetFileName(path);
- }
-
- // Check for link file name
- if (FileExtensionHelpers.IsShortcutOrUrlFile(fileName))
- fileName = fileName.Remove(fileName.Length - 4);
-
- return fileName;
- }
- }
-}
diff --git a/src/Files.Core/ViewModels/Widgets/FileTagsWidget/FileTagsItemViewModel.cs b/src/Files.Core/ViewModels/Widgets/FileTagsWidget/FileTagsItemViewModel.cs
index 0a4058a68690..8a4f163ffa36 100644
--- a/src/Files.Core/ViewModels/Widgets/FileTagsWidget/FileTagsItemViewModel.cs
+++ b/src/Files.Core/ViewModels/Widgets/FileTagsWidget/FileTagsItemViewModel.cs
@@ -3,6 +3,7 @@
using Files.Core.Storage;
using Files.Core.Storage.Extensions;
+using Files.Shared.Helpers;
namespace Files.Core.ViewModels.Widgets.FileTagsWidget
{
diff --git a/src/Files.Core/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
similarity index 99%
rename from src/Files.Core/Helpers/FileExtensionHelpers.cs
rename to src/Files.Shared/Helpers/FileExtensionHelpers.cs
index f33470e59241..233b5f1f98fb 100644
--- a/src/Files.Core/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -1,7 +1,10 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
-namespace Files.Core.Helpers
+using System;
+using System.Linq;
+
+namespace Files.Shared.Helpers
{
///
/// Provides static extension for path extension.
diff --git a/src/Files.Shared/Helpers/PathHelpers.cs b/src/Files.Shared/Helpers/PathHelpers.cs
index d23d5c837ef3..97d6e675692e 100644
--- a/src/Files.Shared/Helpers/PathHelpers.cs
+++ b/src/Files.Shared/Helpers/PathHelpers.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
+using System;
using System.IO;
namespace Files.Shared.Helpers
@@ -14,5 +15,53 @@ public static string Combine(string folder, string name)
return folder.Contains('/') ? Path.Combine(folder, name).Replace('\\', '/') : Path.Combine(folder, name);
}
+
+ public static string FormatName(string path)
+ {
+ string fileName;
+ string rootPath = Path.GetPathRoot(path) ?? string.Empty;
+
+ if (rootPath == path && path.StartsWith(@"\\"))
+ {
+ // Network Share path
+ fileName = path.Substring(path.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
+ }
+ else if (rootPath == path)
+ {
+ // Drive path
+ fileName = path;
+ }
+ else
+ {
+ // Standard file name
+ fileName = Path.GetFileName(path);
+ }
+
+ // Check for link file name
+ if (FileExtensionHelpers.IsShortcutOrUrlFile(fileName))
+ fileName = fileName.Remove(fileName.Length - 4);
+
+ return fileName;
+ }
+
+ ///
+ /// Determines whether the points to any special system folders.
+ ///
+ ///
+ /// The term "Special folder" refers to any folders that may be natively supported by a certain platform (e.g. Libraries).
+ ///
+ /// The path to a folder to check.
+ /// If the path points to a special folder, returns true; otherwise false.
+ public static bool IsSpecialFolder(string path)
+ {
+ foreach (Environment.SpecialFolder specialFolder in Enum.GetValues(typeof(Environment.SpecialFolder)))
+ {
+ var specialFolderPath = Environment.GetFolderPath(specialFolder);
+ if (string.Equals(specialFolderPath, path, StringComparison.OrdinalIgnoreCase))
+ return true;
+ }
+
+ return false;
+ }
}
}