Extract path helper for reuse
This commit is contained in:
parent
2626ed2ec9
commit
1ea582e9df
2 changed files with 15 additions and 13 deletions
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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, "_");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue