Skip to content
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
21 changes: 17 additions & 4 deletions Files/Dialogs/RenameDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@
RequestedTheme="{x:Bind local2:ThemeHelper.RootTheme}">

<Grid MinWidth="300">
<TextBox x:Name="RenameInput"
x:Uid="RenameDialogInputText"
PlaceholderText="Enter an item name without an extension"
Height="35" />
<StackPanel
Orientation="Vertical"
Spacing="4">
<TextBox
x:Name="RenameInput"
x:Uid="RenameDialogInputText"
PlaceholderText="Enter an item name without an extension"
Height="35"
TextChanged="RenameInput_TextChanged" />
<TextBlock
x:Name="RenameDialogSymbolsTip"
x:Uid="RenameDialogSymbolsTip"
Margin="0,0,4,0"
TextWrapping="Wrap"
Opacity="0"/>
</StackPanel>

</Grid>
</ContentDialog>
26 changes: 26 additions & 0 deletions Files/Dialogs/RenameDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,31 @@ private void NameDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogBu
{
storedRenameInput = inputBox.Text;
}

private void RenameInput_TextChanged(object sender, TextChangedEventArgs e)
{
var textBox = sender as TextBox;

if (App.CurrentInstance.InteractionOperations.ContainsRestrictedCharacters(textBox.Text))
{
RenameDialogSymbolsTip.Opacity = 1;
IsPrimaryButtonEnabled = false;
return;
}
else
{
RenameDialogSymbolsTip.Opacity = 0;
IsPrimaryButtonEnabled = true;
}

if (App.CurrentInstance.InteractionOperations.ContainsRestrictedFileName(textBox.Text))
{
IsPrimaryButtonEnabled = false;
}
else
{
IsPrimaryButtonEnabled = true;
}
}
}
}
50 changes: 48 additions & 2 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
Expand Down Expand Up @@ -608,12 +609,54 @@ public void RenameItem_Click(object sender, RoutedEventArgs e)
}
}

public bool ContainsRestrictedCharacters(string input)
{
Regex regex = new Regex("\\\\|\\/|\\:|\\*|\\?|\\\"|\\<|\\>|\\|"); //restricted symbols for file names
MatchCollection matches = regex.Matches(input);
if (matches.Count > 0)
{
return true;
}
return false;
}

private static readonly List<string> RestrictedFileNames = new List<string>()
{
"CON", "PRN", "AUX",
"NUL", "COM1", "COM2",
"COM3", "COM4", "COM5",
"COM6", "COM7", "COM8",
"COM9", "LPT1", "LPT2",
"LPT3", "LPT4", "LPT5",
"LPT6", "LPT7", "LPT8", "LPT9"
};

public bool ContainsRestrictedFileName(string input)
{

foreach (var name in RestrictedFileNames)
{
Regex regex = new Regex($"^{name}($|\\.)(.+)?");
MatchCollection matches = regex.Matches(input.ToUpper());
if (matches.Count > 0)
{
return true;
}
}

return false;
}

public async Task<bool> RenameFileItem(ListedItem item, string oldName, string newName)
{
if (oldName == newName)
{
return true;
}

if (!string.IsNullOrWhiteSpace(newName))
if (!string.IsNullOrWhiteSpace(newName)
&& !ContainsRestrictedCharacters(newName)
&& !ContainsRestrictedFileName(newName))
{
try
{
Expand All @@ -629,7 +672,6 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
}
}
catch (Exception)

{
var ItemAlreadyExistsDialog = new ContentDialog()
{
Expand Down Expand Up @@ -673,6 +715,10 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
}
}
}
else
{
return false;
}

CurrentInstance.NavigationToolbar.CanGoForward = false;
return true;
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@
<source>Open With</source>
<target state="translated">Abrir con</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.nl-NL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.pl-PL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
21 changes: 16 additions & 5 deletions Files/MultilingualResources/Files.ru-RU.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@
</trans-unit>
<trans-unit id="SettingsOnStartupOpenASpecificPage.Content" translate="yes" xml:space="preserve">
<source>Open a specific page</source>
<target state="needs-review-translation">Открыть определенную страницу(ы)</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
<target state="translated">Открыть определенную страницу(ы)</target>
</trans-unit>
<trans-unit id="SettingsOnStartupTitle.Text" translate="yes" xml:space="preserve">
<source>On Startup</source>
Expand Down Expand Up @@ -765,15 +764,27 @@
</trans-unit>
<trans-unit id="SettingsOnStartupOpenASpecificPagePath.PlaceholderText" translate="yes" xml:space="preserve">
<source>New Tab</source>
<target state="new">New Tab</target>
<target state="translated">Новая вкладка</target>
</trans-unit>
<trans-unit id="ErrorDialogUnsupportedOperation" translate="yes" xml:space="preserve">
<source>The requested operation is not supported</source>
<target state="new">The requested operation is not supported</target>
<target state="translated">Запрошенная операция не поддерживается</target>
</trans-unit>
<trans-unit id="BaseLayoutItemContextFlyoutOpenItemWith.Text" translate="yes" xml:space="preserve">
<source>Open With</source>
<target state="new">Open With</target>
<target state="translated">Открыть с помощью</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="translated">Имя элемента не должно содержать следующих знаков: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="translated">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="translated">Имя элемента не должно содержать следующих знаков: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.ta.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
12 changes: 12 additions & 0 deletions Files/MultilingualResources/Files.tr-TR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
<source>Open With</source>
<target state="new">Open With</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="new">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="new">The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
21 changes: 16 additions & 5 deletions Files/MultilingualResources/Files.uk-UA.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@
</trans-unit>
<trans-unit id="SettingsOnStartupOpenASpecificPage.Content" translate="yes" xml:space="preserve">
<source>Open a specific page</source>
<target state="needs-review-translation">Відкрити певну сторінку або сторінки</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
<target state="translated">Відкрити певну сторінку або сторінки</target>
</trans-unit>
<trans-unit id="SettingsOnStartupTitle.Text" translate="yes" xml:space="preserve">
<source>On Startup</source>
Expand Down Expand Up @@ -765,15 +764,27 @@
</trans-unit>
<trans-unit id="SettingsOnStartupOpenASpecificPagePath.PlaceholderText" translate="yes" xml:space="preserve">
<source>New Tab</source>
<target state="new">New Tab</target>
<target state="translated">Нова вкладка</target>
</trans-unit>
<trans-unit id="ErrorDialogUnsupportedOperation" translate="yes" xml:space="preserve">
<source>The requested operation is not supported</source>
<target state="new">The requested operation is not supported</target>
<target state="translated">Дана операція не підтримується</target>
</trans-unit>
<trans-unit id="BaseLayoutItemContextFlyoutOpenItemWith.Text" translate="yes" xml:space="preserve">
<source>Open With</source>
<target state="new">Open With</target>
<target state="translated">Відкрити за допомогою</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.Subtitle" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="translated">Ім'я елемента не повинно містити таких знаків: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
<trans-unit id="FileNameTeachingTip.CloseButtonContent" translate="yes" xml:space="preserve">
<source>OK</source>
<target state="translated">OK</target>
</trans-unit>
<trans-unit id="RenameDialogSymbolsTip.Text" translate="yes" xml:space="preserve">
<source>The item name must not contain the following characters: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</source>
<target state="translated">Ім'я елемента не повинно містити таких знаків: \ / : * ? " <it id="1" pos="open">&lt; &gt;</it> |</target>
</trans-unit>
</group>
</body>
Expand Down
Loading