<commit_before>﻿//******************************************************************************************************
//  FilePath.cs - Gbtc
//
//  Copyright © 2012, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  02/05/2003 - <NAME>
//       Generated original version of source code.
//  12/29/2005 - <NAME>
//       Migrated 2.0 version of source code from 1.1 source (GSF.Shared.FilePath).
//  08/22/2007 - <NAME>
//       Edited code comments.
//  09/19/2008 - <NAME>
//       Converted to C#.
//  10/24/2008 - <NAME>
//       Edited code comments.
//  12/17/2008 - <NAME>
//       Fixed issue in GetFilePatternRegularExpression().
//  06/30/2009 - <NAME>
//       Removed FilePathHasFileName() since the result was error prone.
//  09/14/2009 - <NAME>
//       Added new header and license agreement.
//  09/17/2009 - <NAME>
//       Modified GetAbsolutePath() to remove dependency on HttpContext.Current.
//  04/19/2010 - <NAME>
//       Added GetApplicationDataFolder() method.
//  04/21/2010 - <NAME>
//       Updated GetApplicationDataFolder() to include the company name if available.
//  01/28/2011 - <NAME>
//       Added IsValidFileName function.
//  02/14/2011 - <NAME>
//       Fixed issue in GetDirectoryName where last directory was being truncated as a file name.
//  06/06/2011 - <NAME>
//       Fixed issue in GetFileName where path suffix was being removed before extracting the file name.
//  07/29/2011 - <NAME>
//       Updated GetApplicationDataFolder() to use the TEMP directory for web applications.
//  12/14/2012 - <NAME>
//       Modified Header.
//
//******************************************************************************************************

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.Hosting;
using GSF.Identity;
using GSF.Interop;
using GSF.Reflection;

namespace GSF.IO
{
    /// <summary>
    /// Contains File and Path manipulation methods.
    /// </summary>
    public static class FilePath
    {
        #region [ Members ]

        // Nested Types

        // ReSharper disable MemberCanBePrivate.Local
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        private struct NETRESOURCE
        {
            public readonly int dwScope;
            public int dwType;
            public readonly int dwDisplayType;
            public readonly int dwUsage;
            public readonly string lpLocalName;
            public string lpRemoteName;
            public readonly string lpComment;
            public readonly string lpProvider;
        }

        // Constants
        private const int RESOURCETYPE_DISK = 0x1;

        // Fields
        private static readonly string s_fileNameCharPattern;

        #endregion

        #region [ Constructor ]

        static FilePath()
        {
            StringBuilder pattern = new StringBuilder();
            HashSet<char> invalidPathChars = new HashSet<char>();

            // Defines a regular expression pattern for a valid file name character. We do this by
            // allowing any characters except those that would not be valid as part of a filename.
            // This essentially builds the "?" wildcard pattern match.
            invalidPathChars.Add(Path.DirectorySeparatorChar);
            invalidPathChars.Add(Path.AltDirectorySeparatorChar);
            invalidPathChars.Add(Path.PathSeparator);
            invalidPathChars.Add(Path.VolumeSeparatorChar);

            foreach (char c in Path.GetInvalidPathChars())
                invalidPathChars.Add(c);

            pattern.Append("[^");

            foreach (char c in invalidPathChars)
                pattern.Append(c.RegexEncode());

            pattern.Append("]");

            s_fileNameCharPattern = pattern.ToString();<commit_msg>GSF.Core: In FilePath.cs, modified file pattern search to use Path.GetInvalidFileNameChars() for building the regular expressions for wildcards.<commit_after>﻿//******************************************************************************************************
//  FilePath.cs - Gbtc
//
//  Copyright © 2012, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  02/05/2003 - <NAME>
//       Generated original version of source code.
//  12/29/2005 - <NAME>
//       Migrated 2.0 version of source code from 1.1 source (GSF.Shared.FilePath).
//  08/22/2007 - <NAME>
//       Edited code comments.
//  09/19/2008 - <NAME>
//       Converted to C#.
//  10/24/2008 - <NAME>
//       Edited code comments.
//  12/17/2008 - <NAME>
//       Fixed issue in GetFilePatternRegularExpression().
//  06/30/2009 - <NAME>
//       Removed FilePathHasFileName() since the result was error prone.
//  09/14/2009 - <NAME>
//       Added new header and license agreement.
//  09/17/2009 - <NAME>
//       Modified GetAbsolutePath() to remove dependency on HttpContext.Current.
//  04/19/2010 - <NAME>
//       Added GetApplicationDataFolder() method.
//  04/21/2010 - <NAME>
//       Updated GetApplicationDataFolder() to include the company name if available.
//  01/28/2011 - <NAME>
//       Added IsValidFileName function.
//  02/14/2011 - <NAME>
//       Fixed issue in GetDirectoryName where last directory was being truncated as a file name.
//  06/06/2011 - <NAME>
//       Fixed issue in GetFileName where path suffix was being removed before extracting the file name.
//  07/29/2011 - <NAME>
//       Updated GetApplicationDataFolder() to use the TEMP directory for web applications.
//  12/14/2012 - <NAME>
//       Modified Header.
//
//******************************************************************************************************

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.Hosting;
using GSF.Identity;
using GSF.Interop;
using GSF.Reflection;

namespace GSF.IO
{
    /// <summary>
    /// Contains File and Path manipulation methods.
    /// </summary>
    public static class FilePath
    {
        #region [ Members ]

        // Nested Types

        // ReSharper disable MemberCanBePrivate.Local
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        private struct NETRESOURCE
        {
            public readonly int dwScope;
            public int dwType;
            public readonly int dwDisplayType;
            public readonly int dwUsage;
            public readonly string lpLocalName;
            public string lpRemoteName;
            public readonly string lpComment;
            public readonly string lpProvider;
        }

        // Constants
        private const int RESOURCETYPE_DISK = 0x1;

        // Fields
        private static readonly string s_fileNameCharPattern;

        #endregion

        #region [ Constructor ]

        static FilePath()
        {
            StringBuilder pattern = new StringBuilder();

            // Defines a regular expression pattern for a valid file name character. We do this by
            // allowing any characters except those that would not be valid as part of a filename.
            // This essentially builds the "?" wildcard pattern match.
            pattern.Append("[^");

            foreach (char c in Path.GetInvalidFileNameChars())
                pattern.Append(c.RegexEncode());

            pattern.Append("]");

            s_fileNameCharPattern = pattern.ToString();
{'fraction_non_alphanumeric': 0.15325177076625884, 'fraction_numerical': 0.02962009014810045, 'mean_word_length': 2.338946614116804, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5550350', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2269, 'n_words': 839}