From 1ea582e9dfd87af2af29a096c09f9eeed24af7c8 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 28 May 2019 14:43:05 -0700 Subject: [PATCH] Extract path helper for reuse --- .../ApplicationView/ApplicationController.cs | 14 ++++++++++++++ MatterControlLib/Utilities/AuthenticationData.cs | 14 +------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 3c7aa4e34..3f00bc268 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -56,6 +56,7 @@ namespace MatterHackers.MatterControl using System.Net.Http; using System.Reflection; using System.Text; + using System.Text.RegularExpressions; using System.Threading; using Agg.Font; using Agg.Image; @@ -2965,6 +2966,19 @@ Support and tutorials: } } + public string MakeValidFileName(string name, string replacementCharacter = "_") + { + if (string.IsNullOrEmpty(name)) + { + return name; + } + + string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars())); + string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars); + + return Regex.Replace(name, invalidRegStr, replacementCharacter); + } + public class CloudSyncEventArgs : EventArgs { public bool IsAuthenticated { get; set; } diff --git a/MatterControlLib/Utilities/AuthenticationData.cs b/MatterControlLib/Utilities/AuthenticationData.cs index 7233eb253..6bee10259 100644 --- a/MatterControlLib/Utilities/AuthenticationData.cs +++ b/MatterControlLib/Utilities/AuthenticationData.cs @@ -145,19 +145,7 @@ namespace MatterHackers.MatterControl } [JsonIgnore] - public string FileSystemSafeUserName => MakeValidFileName(this.ActiveSessionUsername); + public string FileSystemSafeUserName => ApplicationController.Instance.MakeValidFileName(this.ActiveSessionUsername); - private static string MakeValidFileName(string name) - { - if (string.IsNullOrEmpty(name)) - { - return name; - } - - string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars())); - string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars); - - return Regex.Replace(name, invalidRegStr, "_"); - } } } \ No newline at end of file