Skip to content

Commit

Permalink
Feature: Prompt when applying tag on non NTFS drive (files-community#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Dec 14, 2023
1 parent 609be42 commit f65c918
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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

0 comments on commit f65c918

Please sign in to comment.