-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Feature: Added support for creating alternate data streams #16438
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
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac460e5
POC
yaira2 31e17fe
Fix
yaira2 eeb4e2e
Cleanup
yaira2 b37788e
Update CreateAlternateDataStreamAction.cs
yaira2 c931d2f
Update CreateAlternateDataStreamAction.cs
yaira2 2f5a7ec
Update Resources.resw
yaira2 ab27dc3
Update DynamicDialogFactory.cs
yaira2 7a937fc
Improve refresh logic
yaira2 c79b02f
Update CreateAlternateDataStreamAction.cs
yaira2 801a858
Requested changes
yaira2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
src/Files.App/Actions/FileSystem/CreateAlternateDataStreamAction.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright (c) 2024 Files Community | ||
| // Licensed under the MIT License. See the LICENSE. | ||
|
|
||
| using Microsoft.UI.Xaml.Controls; | ||
| using System.IO; | ||
| using Windows.Foundation.Metadata; | ||
|
|
||
| namespace Files.App.Actions | ||
| { | ||
| internal sealed class CreateAlternateDataStreamAction : BaseUIAction, IAction | ||
| { | ||
| private readonly IContentPageContext context; | ||
|
|
||
| private static readonly IFoldersSettingsService FoldersSettingsService = Ioc.Default.GetRequiredService<IFoldersSettingsService>(); | ||
|
|
||
| public string Label | ||
| => "CreateAlternateDataStream".GetLocalizedResource(); | ||
|
|
||
| public string Description | ||
| => "CreateAlternateDataStreamDescription".GetLocalizedResource(); | ||
|
|
||
| public override bool IsExecutable => | ||
| context.HasSelection && | ||
| context.CanCreateItem && | ||
| (context.ShellPage?.ShellViewModel.WorkingDirectory != Path.GetPathRoot(context.ShellPage?.ShellViewModel.WorkingDirectory)) && | ||
| UIHelpers.CanShowDialog; | ||
|
|
||
| public CreateAlternateDataStreamAction() | ||
| { | ||
| context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
|
||
| context.PropertyChanged += Context_PropertyChanged; | ||
| } | ||
|
|
||
| public async Task ExecuteAsync(object? parameter = null) | ||
| { | ||
| var nameDialog = DynamicDialogFactory.GetFor_CreateAlternateDataStreamDialog(); | ||
| await nameDialog.TryShowAsync(); | ||
|
|
||
| if (nameDialog.DynamicResult != DynamicDialogResult.Primary) | ||
| return; | ||
|
|
||
| var userInput = nameDialog.ViewModel.AdditionalData as string; | ||
| await Task.WhenAll(context.SelectedItems.Select(async selectedItem => | ||
| { | ||
| var isDateOk = Win32Helper.GetFileDateModified(selectedItem.ItemPath, out var dateModified); | ||
| var isReadOnly = Win32Helper.HasFileAttribute(selectedItem.ItemPath, System.IO.FileAttributes.ReadOnly); | ||
|
|
||
| // Unset read-only attribute (#7534) | ||
| if (isReadOnly) | ||
| Win32Helper.UnsetFileAttribute(selectedItem.ItemPath, System.IO.FileAttributes.ReadOnly); | ||
|
|
||
| if (!Win32Helper.WriteStringToFile($"{selectedItem.ItemPath}:{userInput}", "")) | ||
| { | ||
| var dialog = new ContentDialog | ||
| { | ||
| Title = Strings.ErrorCreatingDataStreamTitle.GetLocalizedResource(), | ||
| Content = Strings.ErrorCreatingDataStreamDescription.GetLocalizedResource(), | ||
| PrimaryButtonText = "Ok".GetLocalizedResource() | ||
| }; | ||
|
|
||
| if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) | ||
| dialog.XamlRoot = MainWindow.Instance.Content.XamlRoot; | ||
|
|
||
| await dialog.TryShowAsync(); | ||
| } | ||
|
|
||
| // Restore read-only attribute (#7534) | ||
| if (isReadOnly) | ||
| Win32Helper.SetFileAttribute(selectedItem.ItemPath, System.IO.FileAttributes.ReadOnly); | ||
|
|
||
| // Restore date modified | ||
| if (isDateOk) | ||
| Win32Helper.SetFileDateModified(selectedItem.ItemPath, dateModified); | ||
| })); | ||
|
|
||
| if (context.ShellPage is null) | ||
| return; | ||
|
|
||
| if (FoldersSettingsService.AreAlternateStreamsVisible) | ||
| await context.ShellPage.Refresh_Click(); | ||
| else | ||
| { | ||
| var dialog = new ContentDialog | ||
| { | ||
| Title = Strings.DataStreamsAreHiddenTitle.GetLocalizedResource(), | ||
| Content = Strings.DataStreamsAreHiddenDescription.GetLocalizedResource(), | ||
| PrimaryButtonText = Strings.Yes.GetLocalizedResource(), | ||
| SecondaryButtonText = Strings.No.GetLocalizedResource() | ||
| }; | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) | ||
| dialog.XamlRoot = MainWindow.Instance.Content.XamlRoot; | ||
|
|
||
| var result = await dialog.TryShowAsync(); | ||
| if (result == ContentDialogResult.Primary) | ||
| { | ||
| FoldersSettingsService.AreAlternateStreamsVisible = true; | ||
| await context.ShellPage.Refresh_Click(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
| { | ||
| switch (e.PropertyName) | ||
| { | ||
| case nameof(IContentPageContext.HasSelection): | ||
| case nameof(IContentPageContext.CanCreateItem): | ||
| OnPropertyChanged(nameof(IsExecutable)); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.