Skip to content

Feature: Prompt when applying tag on non NTFS drive #14202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3638,6 +3638,12 @@
<data name="Login" xml:space="preserve">
<value>Login</value>
</data>
<data name="ErrorApplyingTagContent" xml:space="preserve">
<value>Tags are currently only compatible on drives formatted as NTFS.</value>
</data>
<data name="ErrorApplyingTagTitle" xml:space="preserve">
<value>There was an error applying this tag</value>
</data>
<data name="DecompressArchiveHereSmartDescription" xml:space="preserve">
<value>Extract items from selected archive(s) to current folder for single-item archive, or to new folder for multi-item archive</value>
</data>
Expand Down
26 changes: 18 additions & 8 deletions src/Files.App/Utils/FileTags/FileTagsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Helpers;
using Files.App.Utils.Shell;
using Files.Shared.Extensions;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation.Metadata;
using Windows.Storage;
using Windows.Storage.FileProperties;
using IO = System.IO;
Expand All @@ -27,7 +23,7 @@ public static string[] ReadFileTag(string filePath)
return tagString?.Split(',', StringSplitOptions.RemoveEmptyEntries);
}

public static void WriteFileTag(string filePath, string[] tag)
public static async void WriteFileTag(string filePath, string[] tag)
{
var isDateOk = NativeFileOperationsHelper.GetFileDateModified(filePath, out var dateModified); // Backup date modified
var isReadOnly = NativeFileOperationsHelper.HasFileAttribute(filePath, IO.FileAttributes.ReadOnly);
Expand All @@ -41,7 +37,21 @@ public static void WriteFileTag(string filePath, string[] tag)
}
else if (ReadFileTag(filePath) is not string[] arr || !tag.SequenceEqual(arr))
{
NativeFileOperationsHelper.WriteStringToFile($"{filePath}:files", string.Join(',', tag));
var result = NativeFileOperationsHelper.WriteStringToFile($"{filePath}:files", string.Join(',', tag));
if (result == false)
{
ContentDialog dialog = new()
{
Title = "ErrorApplyingTagTitle".GetLocalizedResource(),
Content = "ErrorApplyingTagContent".GetLocalizedResource(),
PrimaryButtonText = "Ok".GetLocalizedResource()
};

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
dialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;

await dialog.TryShowAsync();
}
}
if (isReadOnly) // Restore read-only attribute (#7534)
{
Expand Down