Extract path helper for reuse

This commit is contained in:
jlewin 2019-05-28 14:43:05 -07:00
parent 2626ed2ec9
commit 1ea582e9df
2 changed files with 15 additions and 13 deletions

View file

@ -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; }

View file

@ -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, "_");
}
}
}