-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc1214a
commit e9b486f
Showing
10 changed files
with
327 additions
and
85 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/modules/previewpane/FileActionsMenu/FileActionsMenu.Ui/Actions/Hashes.cs
This file contains 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,97 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Controls; | ||
using Wpf.Ui.Controls; | ||
|
||
namespace FileActionsMenu.Ui.Actions | ||
{ | ||
internal static class Hashes | ||
{ | ||
internal static void GenerateHashes(object sender, string[] selectedItems) | ||
{ | ||
Func<string, string> hashGeneratorFunction; | ||
#pragma warning disable CS0219 // Variable is assigned but its value is never used | ||
string fileExtension; | ||
#pragma warning restore CS0219 // Variable is assigned but its value is never used | ||
|
||
switch (((System.Windows.Controls.MenuItem)sender).Name) | ||
{ | ||
case "Md5HashMenuItem": | ||
#pragma warning disable CA5351 | ||
hashGeneratorFunction = (string filename) => BitConverter.ToString(MD5.Create().ComputeHash(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))).Replace("-", string.Empty); | ||
#pragma warning restore CA5351 | ||
fileExtension = ".md5"; | ||
break; | ||
case "Sha1HashMenuItem": | ||
#pragma warning disable CA5350 | ||
hashGeneratorFunction = (string filename) => BitConverter.ToString(SHA1.Create().ComputeHash(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))).Replace("-", string.Empty); | ||
#pragma warning restore CA5350 | ||
fileExtension = ".sha1"; | ||
break; | ||
case "Sha256HashMenuItem": | ||
hashGeneratorFunction = (string filename) => BitConverter.ToString(SHA256.Create().ComputeHash(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))).Replace("-", string.Empty); | ||
fileExtension = ".sha256"; | ||
break; | ||
default: | ||
throw new InvalidOperationException("Unknown hash type"); | ||
} | ||
|
||
FluentWindow window = new FluentWindow(); | ||
window.Content = new ContentPresenter(); | ||
ContentDialog contentDialog = new ContentDialog((ContentPresenter)window.Content); | ||
contentDialog.Title = "Save hashes to ... file(s)?"; | ||
contentDialog.PrimaryButtonText = "Multiple"; | ||
contentDialog.SecondaryButtonText = "Single"; | ||
window.Width = 0; | ||
window.Height = 0; | ||
window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; | ||
try | ||
{ | ||
window.Show(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
// Ignore | ||
} | ||
|
||
window.Focus(); | ||
window.Activate(); | ||
contentDialog.ShowAsync().ContinueWith((task) => | ||
{ | ||
if (task.Result == ContentDialogResult.Primary) | ||
{ | ||
foreach (string filename in selectedItems) | ||
{ | ||
string hash = hashGeneratorFunction(filename); | ||
string hashFilename = filename + fileExtension; | ||
File.WriteAllText(hashFilename, hash); | ||
} | ||
} | ||
else if (task.Result == ContentDialogResult.Secondary) | ||
{ | ||
StringBuilder fileContent = new(); | ||
foreach (string filename in selectedItems) | ||
{ | ||
fileContent.Append(filename + ":\n" + hashGeneratorFunction(filename) + "\n\n"); | ||
} | ||
File.WriteAllText((Path.GetDirectoryName(selectedItems[0]) ?? throw new ArgumentNullException(nameof(selectedItems))) + "\\hashes" + fileExtension, fileContent.ToString()); | ||
} | ||
window.Dispatcher.Invoke(() => window.Close()); | ||
}); | ||
} | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/modules/previewpane/FileActionsMenu/FileActionsMenu.Ui/App.xaml
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
src/modules/previewpane/FileActionsMenu/FileActionsMenu.Ui/ExplorerHelper.cs
This file contains 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,36 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
|
||
namespace FileActionsMenu.Ui | ||
{ | ||
public sealed class ExplorerHelper | ||
{ | ||
// Source: https://stackoverflow.com/questions/14193388/how-to-get-windows-explorers-selected-files-from-within-c | ||
public static string[] GetSelectedItems() | ||
{ | ||
string filename; | ||
List<string> selected = []; | ||
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) | ||
{ | ||
filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(CultureInfo.InvariantCulture); | ||
if (filename.Equals("explorer", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); | ||
foreach (Shell32.FolderItem item in items) | ||
{ | ||
selected.Add(item.Path); | ||
} | ||
} | ||
} | ||
|
||
return selected.ToArray(); | ||
} | ||
} | ||
} |
This file contains 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
131 changes: 72 additions & 59 deletions
131
src/modules/previewpane/FileActionsMenu/FileActionsMenu.Ui/MainWindow.xaml
This file contains 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 |
---|---|---|
@@ -1,66 +1,79 @@ | ||
<Window x:Class="FileActionsMenu.MainWindow" | ||
<ui:FluentWindow x:Class="FileActionsMenu.Ui.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
mc:Ignorable="d" | ||
Name="_this" | ||
WindowStyle="None" | ||
Title="MainWindow" Height="0" Width="0" MinHeight="0" MinWidth="0" MaxHeight="0" MaxWidth="0" | ||
AllowsTransparency="True" WindowStyle="None" Background="Transparent"> | ||
<Window.Resources> | ||
<ContextMenu x:Key="Menu"> | ||
<MenuItem Header="PowerToys File actions" IsEnabled="False"></MenuItem> | ||
<Separator /> | ||
<Separator /> | ||
<MenuItem Header="Generate Checksum"> | ||
<MenuItem Header="Md5 hash" Click="GenerateHash" /> | ||
<MenuItem Header="Sha1 hash" Click="GenerateHashes"/> | ||
<MenuItem Header="Sha256 hash" /> | ||
</MenuItem> | ||
<Separator/> | ||
<ui:MenuItem Header="Copy to" Icon="{ui:FontIcon ''}"> | ||
</ui:MenuItem> | ||
<ui:MenuItem Header="Move to"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<MenuItem Header="New folder with selection"> | ||
<MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</MenuItem.Icon> | ||
</MenuItem> | ||
<Separator/> | ||
<MenuItem Header="Copy path of files sperated by"> | ||
<MenuItem Header='";"'/> | ||
<MenuItem Header='" "'/> | ||
<MenuItem Header='","'/> | ||
<MenuItem Header='Newline'/> | ||
<MenuItem Header='Custom...' /> | ||
</MenuItem> | ||
<Separator /> | ||
<MenuItem Header="Rename with PowerRename"> | ||
<MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</MenuItem.Icon> | ||
</MenuItem> | ||
<MenuItem Header="Transform images with Image Resizer"> | ||
<MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</MenuItem.Icon> | ||
</MenuItem> | ||
<Separator /> | ||
<MenuItem Header="Following items only apply to the first-selected file (test.txt)" IsEnabled="False"/> | ||
<MenuItem Header="What's using this file?"> | ||
<MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</MenuItem.Icon> | ||
</MenuItem> | ||
<MenuItem Header="Copy image to clipboard"> | ||
<MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</MenuItem.Icon> | ||
</MenuItem> | ||
</ContextMenu> | ||
</Window.Resources> | ||
</Window> | ||
ui:AllowsTransparency="True" Background="Transparent"> | ||
<ui:FluentWindow.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ui:ThemesDictionary Theme="Dark"></ui:ThemesDictionary> | ||
<ui:ControlsDictionary></ui:ControlsDictionary> | ||
</ResourceDictionary.MergedDictionaries> | ||
<ContextMenu x:Key="Menu"> | ||
<ui:MenuItem Header="PowerToys File actions" IsEnabled="False"></ui:MenuItem> | ||
<Separator/> | ||
<Separator/> | ||
<ui:MenuItem Header="Generate Checksum"> | ||
<ui:MenuItem x:Name="Md5HashMenuItem" Header="Md5 hash" Click="GenerateHashes"/> | ||
<ui:MenuItem x:Name="Sha1HashMenuItem" Header="Sha1 hash" Click="GenerateHashes"/> | ||
<ui:MenuItem x:Name="Sha256HashMenuItem" Header="Sha256 hash" Click="GenerateHashes"/> | ||
</ui:MenuItem> | ||
<Separator/> | ||
<ui:MenuItem Header="Copy to"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<ui:MenuItem Header="Move to"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<ui:MenuItem Header="New folder with selection"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<Separator/> | ||
<ui:MenuItem Header="Copy path of files sperated by"> | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
sperated is not a recognized word. (unrecognized-spelling)
|
||
<ui:MenuItem Header='";"' Click="CopyPath_Click"/> | ||
<ui:MenuItem Header='" "' Click="CopyPath_Click"/> | ||
<ui:MenuItem Header='","' Click="CopyPath_Click"/> | ||
<ui:MenuItem Header='Newline' Click="CopyPath_Click"/> | ||
<ui:MenuItem Header='Custom...' Click="CopyPath_Click"/> | ||
</ui:MenuItem> | ||
<Separator /> | ||
<ui:MenuItem Header="Rename with PowerRename"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<ui:MenuItem Header="Transform images with Image Resizer"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<Separator /> | ||
<ui:MenuItem Header="Following items only apply to the first-selected file" IsEnabled="False"/> | ||
<ui:MenuItem Tag="SingleItem" Header="What's using this file?"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<ui:MenuItem IsEnabled="{Binding SingleItem, RelativeSource={RelativeSource AncestorType=Window}}" Header="Copy image to clipboard"> | ||
<ui:MenuItem.Icon> | ||
<ui:FontIcon Glyph="" /> | ||
</ui:MenuItem.Icon> | ||
</ui:MenuItem> | ||
<Separator/> | ||
<ui:MenuItem Header="Close Menu"></ui:MenuItem> | ||
</ContextMenu> | ||
</ResourceDictionary> | ||
</ui:FluentWindow.Resources> | ||
</ui:FluentWindow> |
Oops, something went wrong.
e9b486f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (1)
sperated
Previously acknowledged words that are now absent
applicationframehost Kazakhstani lastbuildstate qps Tenge TKey toolkitcontrols TValue unescape 🫥Some files were automatically ignored 🙈
These sample patterns would exclude them:
You should consider adding them to:
File matching is via Perl regular expressions.
To check these files, more of their words need to be in the dictionary than not. You can use
patterns.txt
to exclude portions, add items to the dictionary (e.g. by adding them toallow.txt
), or fix typos.To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands
... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the
dev/aaron-junker/FileActionsMenu
branch (ℹ️ how do I use this?):Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary
This includes both expected items (1854) from .github/actions/spell-check/expect.txt and unrecognized words (1)
Consider adding them (in
.github/workflows/spelling2.yml
) foruses: check-spelling/[email protected]
in itswith
:To stop checking additional dictionaries, add (in
.github/workflows/spelling2.yml
) foruses: check-spelling/[email protected]
in itswith
:Errors (1)
See the 📜action log or 📝 job summary for details.
See ❌ Event descriptions for more information.
If the flagged items are 🤯 false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.