|
4 | 4 | using Files.Core.Storage;
|
5 | 5 | using Files.Core.Storage.Extensions;
|
6 | 6 | using Microsoft.Extensions.Logging;
|
| 7 | +using Microsoft.Win32; |
7 | 8 | using System.IO;
|
8 | 9 | using System.Runtime.InteropServices;
|
9 | 10 | using System.Runtime.InteropServices.ComTypes;
|
@@ -612,8 +613,8 @@ public async Task<ReturnResult> CreateShortcutFromClipboard(DataPackageView pack
|
612 | 613 | progress.ProgressChanged += (s, e) => returnStatus = returnStatus < ReturnResult.Failed ? e.Status!.Value.ToStatus() : returnStatus;
|
613 | 614 |
|
614 | 615 | source = source.Where(x => !string.IsNullOrEmpty(x.Path));
|
615 |
| - var dest = source.Select(x => Path.Combine(destination, |
616 |
| - string.Format("ShortcutCreateNewSuffix".GetLocalizedResource(), x.Name) + ".lnk")); |
| 616 | + |
| 617 | + var dest = source.Select(x => Path.Combine(destination, FilesystemHelpers.GetShortcutNamingPreference(x.Name))); |
617 | 618 |
|
618 | 619 | source = await source.ToListAsync();
|
619 | 620 | dest = await dest.ToListAsync();
|
@@ -671,8 +672,8 @@ public static bool IsValidForFilename(string name)
|
671 | 672 | if (string.IsNullOrEmpty(item.src.Path) || item.src.Path != item.dest)
|
672 | 673 | {
|
673 | 674 | // Same item names in both directories
|
674 |
| - if (StorageHelpers.Exists(item.dest) || |
675 |
| - (FtpHelpers.IsFtpPath(item.dest) && |
| 675 | + if (StorageHelpers.Exists(item.dest) || |
| 676 | + (FtpHelpers.IsFtpPath(item.dest) && |
676 | 677 | await Ioc.Default.GetRequiredService<IFtpStorageService>().TryGetFileAsync(item.dest) is not null))
|
677 | 678 | {
|
678 | 679 | (incomingItems[item.index] as FileSystemDialogConflictItemViewModel)!.ConflictResolveOption = FileNameConflictResolveOptionType.GenerateNewName;
|
@@ -797,7 +798,7 @@ public static async Task<IEnumerable<IStorageItemWithPath>> GetDraggedStorageIte
|
797 | 798 | catch (COMException)
|
798 | 799 | {
|
799 | 800 | }
|
800 |
| - |
| 801 | + |
801 | 802 | if (bytesRead > 0)
|
802 | 803 | {
|
803 | 804 | IntPtr dropStructPointer = Marshal.AllocHGlobal(dropBytes!.Length);
|
@@ -867,12 +868,34 @@ public static bool ContainsRestrictedFileName(string input)
|
867 | 868 | return false;
|
868 | 869 | }
|
869 | 870 |
|
| 871 | + |
| 872 | + /// <summary> |
| 873 | + /// Gets the shortcut naming template from File Explorer |
| 874 | + /// </summary> |
| 875 | + public static string GetShortcutNamingPreference(string itemName) |
| 876 | + { |
| 877 | + var keyName = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates"; |
| 878 | + var value = Registry.GetValue(keyName, "ShortcutNameTemplate", null); |
| 879 | + |
| 880 | + if (value is null) |
| 881 | + return string.Format("ShortcutCreateNewSuffix".GetLocalizedResource(), itemName) + ".lnk"; |
| 882 | + else |
| 883 | + { |
| 884 | + // Trim the quotes and the "%s" from the string |
| 885 | + value = value?.ToString()?.TrimStart(['"', '%', 's']); |
| 886 | + value = value?.ToString()?.TrimEnd(['"']); |
| 887 | + |
| 888 | + return itemName + value; |
| 889 | + } |
| 890 | + } |
| 891 | + |
| 892 | + |
870 | 893 | public void Dispose()
|
871 | 894 | {
|
872 | 895 | filesystemOperations?.Dispose();
|
873 | 896 |
|
874 | 897 | // SUPPRESS: Cannot convert null literal to non-nullable reference type.
|
875 |
| - #pragma warning disable CS8625 |
| 898 | +#pragma warning disable CS8625 |
876 | 899 | associatedInstance = null;
|
877 | 900 | filesystemOperations = null;
|
878 | 901 | }
|
|
0 commit comments