Skip to content

Commit

Permalink
Moving the function to utilities class
Browse files Browse the repository at this point in the history
  • Loading branch information
reddyashish committed Dec 4, 2018
1 parent 827b090 commit d055de4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ You can always redownload the package.</value>
</data>
<data name="MessageCustomNodeNameInvalid" xml:space="preserve">
<value>Custom Node name cannot contain any of the following special characters:
# % * [] {} ? \ : ` ~ or any of the non-printable characters.</value>
# % * ? \ : or any of the non-printable characters.</value>
</data>
<data name="MessageErrorOpeningFileGeneral" xml:space="preserve">
<value>Error Opening File</value>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ You can always redownload the package.</value>
</data>
<data name="MessageCustomNodeNameInvalid" xml:space="preserve">
<value>Custom Node name cannot contain any of the following special characters:
# % * [] {} ? \ : ` ~ or any of the non-printable characters.</value>
# % * ? \ : or any of the non-printable characters.</value>
</data>
<data name="MessageFailedToDownloadPackage" xml:space="preserve">
<value>Failed to download package with id: {0}. Please try again and report the package if you continue to have problems.</value>
Expand Down
17 changes: 2 additions & 15 deletions src/DynamoCoreWpf/UI/Prompts/FunctionNamePrompt.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System.Windows;
using Dynamo.Controls;
using Dynamo.Utilities;
using System.IO;
using System;
using DynamoUtilities;

namespace Dynamo.Nodes
{
Expand Down Expand Up @@ -39,7 +38,7 @@ void OK_Click(object sender, RoutedEventArgs e)
Dynamo.Wpf.Properties.Resources.CustomNodePropertyErrorMessageBoxTitle,
MessageBoxButton.OK, MessageBoxImage.Error);
}
else if (!IsFileNameValid(Text))
else if (PathHelper.IsFileNameInValid(Text))
{
MessageBox.Show(Dynamo.Wpf.Properties.Resources.MessageCustomNodeNameInvalid,
Dynamo.Wpf.Properties.Resources.CustomNodePropertyErrorMessageBoxTitle,
Expand All @@ -57,18 +56,6 @@ void OK_Click(object sender, RoutedEventArgs e)
}
}

// Check if the file name contains any special non-printable chatacters.
bool IsFileNameValid(string fileName)
{
// Some other extra characters that are to be checked.
char[] invalidCharactersFileName = { '#', '%', '&', '.', ' ' };

if (fileName.Any(f => Path.GetInvalidFileNameChars().Contains(f)) || fileName.IndexOfAny(invalidCharactersFileName) > -1)
return false;

return true;
}

void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
Expand Down
13 changes: 13 additions & 0 deletions src/DynamoUtilities/PathHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Xml;
using Newtonsoft.Json;
Expand Down Expand Up @@ -146,5 +147,17 @@ public static bool isValidJson(string path, out string fileContents, out Excepti
return false;
}
}

// Check if the file name contains any special non-printable chatacters.
public static bool IsFileNameInValid(string fileName)
{
// Some other extra characters that are to be checked.
char[] invalidCharactersFileName = { '#', '%', '&', '.', ' ' };

if (fileName.Any(f => Path.GetInvalidFileNameChars().Contains(f)) || fileName.IndexOfAny(invalidCharactersFileName) > -1)
return true;

return false;
}
}
}

0 comments on commit d055de4

Please sign in to comment.