Exemplo n.º 1
0
 // Token: 0x06000AC6 RID: 2758 RVA: 0x00039D5C File Offset: 0x00037F5C
 public string TransformFile(string name)
 {
     if (name != null)
     {
         string text = name.ToLower();
         if (this.trimPrefix_ != null && text.IndexOf(this.trimPrefix_) == 0)
         {
             name = name.Substring(this.trimPrefix_.Length);
         }
         name = name.Replace("\\", "/");
         name = WindowsPathUtils.DropPathRoot(name);
         while (name.Length > 0)
         {
             if (name[0] != '/')
             {
                 break;
             }
             name = name.Remove(0, 1);
         }
         while (name.Length > 0 && name[name.Length - 1] == '/')
         {
             name = name.Remove(name.Length - 1, 1);
         }
         for (int i = name.IndexOf("//"); i >= 0; i = name.IndexOf("//"))
         {
             name = name.Remove(i, 1);
         }
         name = ZipNameTransform.MakeValidName(name, '_');
     }
     else
     {
         name = string.Empty;
     }
     return(name);
 }
Exemplo n.º 2
0
 public string TransformFile(string name)
 {
     if (name != null)
     {
         string text = name.ToLower();
         if (trimPrefix_ != null && text.IndexOf(trimPrefix_) == 0)
         {
             name = name.Substring(trimPrefix_.get_Length());
         }
         name = name.Replace("\\", "/");
         name = WindowsPathUtils.DropPathRoot(name);
         while (name.get_Length() > 0 && name.get_Chars(0) == '/')
         {
             name = name.Remove(0, 1);
         }
         while (name.get_Length() > 0 && name.get_Chars(name.get_Length() - 1) == '/')
         {
             name = name.Remove(name.get_Length() - 1, 1);
         }
         for (int num = name.IndexOf("//"); num >= 0; num = name.IndexOf("//"))
         {
             name = name.Remove(num, 1);
         }
         name = MakeValidName(name, '_');
     }
     else
     {
         name = string.Empty;
     }
     return(name);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Transform a windows file name according to the Zip file naming conventions.
        /// </summary>
        /// <param name="name">The file name to transform.</param>
        /// <returns>The transformed name.</returns>
        public string TransformFile(string name)
        {
            if (name != null)
            {
                // Put separators in the expected format.
                name = name.Replace(@"\", "/");

                // Remove the path root.
                name = WindowsPathUtils.DropPathRoot(name);

                // Drop any leading and trailing slashes.
                name = name.Trim('/');

                // Convert consecutive // characters to /
                int index = name.IndexOf("//", StringComparison.Ordinal);
                while (index >= 0)
                {
                    name  = name.Remove(index, 1);
                    index = name.IndexOf("//", StringComparison.Ordinal);
                }
            }
            else
            {
                name = string.Empty;
            }

            return(name);
        }
        /// <summary>
        /// Force a name to be valid by replacing invalid characters with a fixed value
        /// </summary>
        /// <param name="name">The name to make valid</param>
        /// <param name="replacement">The replacement character to use for any invalid characters.</param>
        /// <returns>Returns a valid name</returns>
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            name = WindowsPathUtils.DropPathRoot(name.Replace("/", @"\"));

            // Drop any leading slashes.
            while ((name.Length > 0) && (name[0] == '\\'))
            {
                name = name.Remove(0, 1);
            }

            // Drop any trailing slashes.
            while ((name.Length > 0) && (name[name.Length - 1] == '\\'))
            {
                name = name.Remove(name.Length - 1, 1);
            }

            // Convert consecutive \\ characters to \
            int index = name.IndexOf(@"\\");

            while (index >= 0)
            {
                name  = name.Remove(index, 1);
                index = name.IndexOf(@"\\");
            }

            // Convert any invalid characters using the replacement one.
            index = name.IndexOfAny(InvalidEntryChars);
            if (index >= 0)
            {
                StringBuilder builder = new StringBuilder(name);

                while (index >= 0)
                {
                    builder[index] = replacement;

                    if (index >= name.Length)
                    {
                        index = -1;
                    }
                    else
                    {
                        index = name.IndexOfAny(InvalidEntryChars, index + 1);
                    }
                }
                name = builder.ToString();
            }

            // Check for names greater than MaxPath characters.
            // TODO: Were is CLR version of MaxPath defined?  Can't find it in Environment.
            //if ( name.Length > MaxPath ) {
            //    throw new Alphaleonis.Win32.Filesystem. .PathTooLongException();
            //}

            return(name);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Transform a windows file name according to the Zip file naming conventions.
        /// </summary>
        /// <param name="name">The file name to transform.</param>
        /// <returns>The transformed name.</returns>
        public string TransformFile(string name)
        {
            if (name != null)
            {
                string lowerName = name.ToLower();
                if ((trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_, StringComparison.Ordinal) == 0))
                {
                    name = name.Substring(trimPrefix_.Length);
                }

                name = name.Replace(@"\", "/");
                name = WindowsPathUtils.DropPathRoot(name);

                // Drop any leading and trailing slashes.
                name = name.Trim('/');

                // Convert consecutive // characters to /
                int index = name.IndexOf("//", StringComparison.Ordinal);
                while (index >= 0)
                {
                    name  = name.Remove(index, 1);
                    index = name.IndexOf("//", StringComparison.Ordinal);
                }

                name = MakeValidName(name, '_');
            }
            else
            {
                name = string.Empty;
            }
            return(name);
        }
Exemplo n.º 6
0
 public string TransformFile(string name)
 {
     if (name != null)
     {
         string str = name.ToLower();
         if ((_trimPrefix != null) && (str.IndexOf(_trimPrefix, StringComparison.Ordinal) == 0))
         {
             name = name.Substring(_trimPrefix.Length);
         }
         name = name.Replace(@"\", "/");
         name = WindowsPathUtils.DropPathRoot(name);
         while ((name.Length > 0) && (name[0] == '/'))
         {
             name = name.Remove(0, 1);
         }
         while ((name.Length > 0) && (name[name.Length - 1] == '/'))
         {
             name = name.Remove(name.Length - 1, 1);
         }
         for (int i = name.IndexOf("//", StringComparison.Ordinal); i >= 0; i = name.IndexOf("//",
                                                                                             StringComparison.Ordinal))
         {
             name = name.Remove(i, 1);
         }
         name = MakeValidName(name, '_');
         return(name);
     }
     name = string.Empty;
     return(name);
 }
Exemplo n.º 7
0
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            name = WindowsPathUtils.DropPathRoot(name.Replace("/", @"\"));


            while ((name.Length > 0) && (name[0] == '\\'))
            {
                name = name.Remove(0, 1);
            }


            while ((name.Length > 0) && (name[name.Length - 1] == '\\'))
            {
                name = name.Remove(name.Length - 1, 1);
            }


            int index = name.IndexOf(@"\\");

            while (index >= 0)
            {
                name  = name.Remove(index, 1);
                index = name.IndexOf(@"\\");
            }


            index = name.IndexOfAny(InvalidEntryChars);
            if (index >= 0)
            {
                StringBuilder builder = new StringBuilder(name);

                while (index >= 0)
                {
                    builder[index] = replacement;

                    if (index >= name.Length)
                    {
                        index = -1;
                    }
                    else
                    {
                        index = name.IndexOfAny(InvalidEntryChars, index + 1);
                    }
                }
                name = builder.ToString();
            }


            if (name.Length > MaxPath)
            {
                throw new PathTooLongException();
            }

            return(name);
        }
Exemplo n.º 8
0
 public string TransformFile(string name)
 {
     if (name != null)
     {
         string text = name.ToLower();
         if (trimPrefix_ != null && text.IndexOf(trimPrefix_, StringComparison.Ordinal) == 0)
         {
             name = name.Substring(trimPrefix_.Length);
         }
         name = name.Replace("\\", "/");
         name = WindowsPathUtils.DropPathRoot(name);
         while (name.Length > 0 && name[0] == '/')
         {
             name = name.Remove(0, 1);
         }
         while (name.Length > 0 && name[name.Length - 1] == '/')
         {
             name = name.Remove(name.Length - 1, 1);
         }
         for (int num = name.IndexOf("//", StringComparison.Ordinal); num >= 0; num = name.IndexOf("//", StringComparison.Ordinal))
         {
             name = name.Remove(num, 1);
         }
         name = MakeValidName(name, '_');
     }
     else
     {
         name = string.Empty;
     }
     return(name);
 }
Exemplo n.º 9
0
        // Token: 0x06000900 RID: 2304 RVA: 0x000330D8 File Offset: 0x000312D8
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = WindowsPathUtils.DropPathRoot(name.Replace("/", "\\"));
            while (name.Length > 0)
            {
                if (name[0] != '\\')
                {
                    break;
                }
                name = name.Remove(0, 1);
            }
            while (name.Length > 0 && name[name.Length - 1] == '\\')
            {
                name = name.Remove(name.Length - 1, 1);
            }
            int i;

            for (i = name.IndexOf("\\\\"); i >= 0; i = name.IndexOf("\\\\"))
            {
                name = name.Remove(i, 1);
            }
            i = name.IndexOfAny(WindowsNameTransform.InvalidEntryChars);
            if (i >= 0)
            {
                StringBuilder stringBuilder = new StringBuilder(name);
                while (i >= 0)
                {
                    stringBuilder[i] = replacement;
                    if (i >= name.Length)
                    {
                        i = -1;
                    }
                    else
                    {
                        i = name.IndexOfAny(WindowsNameTransform.InvalidEntryChars, i + 1);
                    }
                }
                name = stringBuilder.ToString();
            }
            if (name.Length > 260)
            {
                throw new PathTooLongException();
            }
            return(name);
        }
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = WindowsPathUtils.DropPathRoot(name.Replace("/", Path.DirectorySeparatorChar.ToString()));
            while (name.Length > 0 && name[0] == Path.DirectorySeparatorChar)
            {
                name = name.Remove(0, 1);
            }
            while (name.Length > 0 && name[name.Length - 1] == Path.DirectorySeparatorChar)
            {
                name = name.Remove(name.Length - 1, 1);
            }
            int i;

            for (i = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal); i >= 0; i = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal))
            {
                name = name.Remove(i, 1);
            }
            i = name.IndexOfAny(WindowsNameTransform.InvalidEntryChars);
            if (i >= 0)
            {
                StringBuilder stringBuilder = new StringBuilder(name);
                while (i >= 0)
                {
                    stringBuilder[i] = replacement;
                    if (i >= name.Length)
                    {
                        i = -1;
                    }
                    else
                    {
                        i = name.IndexOfAny(WindowsNameTransform.InvalidEntryChars, i + 1);
                    }
                }
                name = stringBuilder.ToString();
            }
            if (name.Length > 260)
            {
                throw new PathTooLongException();
            }
            return(name);
        }
Exemplo n.º 11
0
 public string TransformFile(string name)
 {
     if (name == null)
     {
         name = string.Empty;
     }
     else
     {
         string str = name.ToLower();
         if ((this.trimPrefix_ != null) && (str.IndexOf(this.trimPrefix_) == 0))
         {
             name = name.Substring(this.trimPrefix_.Length);
         }
         name = name.Replace(@"\", "/");
         name = WindowsPathUtils.DropPathRoot(name);
         while (true)
         {
             if ((name.Length <= 0) || (name[0] != '/'))
             {
                 while (true)
                 {
                     if ((name.Length <= 0) || (name[name.Length - 1] != '/'))
                     {
                         int index = name.IndexOf("//");
                         while (true)
                         {
                             if (index < 0)
                             {
                                 name = MakeValidName(name, '_');
                                 break;
                             }
                             name  = name.Remove(index, 1);
                             index = name.IndexOf("//");
                         }
                         break;
                     }
                     name = name.Remove(name.Length - 1, 1);
                 }
                 break;
             }
             name = name.Remove(0, 1);
         }
     }
     return(name);
 }
Exemplo n.º 12
0
        public static string MakeValidName(string name, char replacement)
        {
            //IL_0008: Unknown result type (might be due to invalid IL or missing references)
            //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
            //IL_00b2: Expected O, but got Unknown
            //IL_00f1: Unknown result type (might be due to invalid IL or missing references)
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = WindowsPathUtils.DropPathRoot(name.Replace("/", "\\"));
            while (name.get_Length() > 0 && name.get_Chars(0) == '\\')
            {
                name = name.Remove(0, 1);
            }
            while (name.get_Length() > 0 && name.get_Chars(name.get_Length() - 1) == '\\')
            {
                name = name.Remove(name.get_Length() - 1, 1);
            }
            int num;

            for (num = name.IndexOf("\\\\"); num >= 0; num = name.IndexOf("\\\\"))
            {
                name = name.Remove(num, 1);
            }
            num = name.IndexOfAny(InvalidEntryChars);
            if (num >= 0)
            {
                StringBuilder val = new StringBuilder(name);
                while (num >= 0)
                {
                    val.set_Chars(num, replacement);
                    num = ((num < name.get_Length()) ? name.IndexOfAny(InvalidEntryChars, num + 1) : (-1));
                }
                name = ((object)val).ToString();
            }
            if (name.get_Length() > 260)
            {
                throw new PathTooLongException();
            }
            return(name);
        }
Exemplo n.º 13
0
        public static string MakeValidName(string name, char replacement)
        {
            int num;

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = WindowsPathUtils.DropPathRoot(name.Replace("/", Path.DirectorySeparatorChar.ToString()));
            while ((name.Length > 0) && (name[0] == Path.DirectorySeparatorChar))
            {
                name = name.Remove(0, 1);
            }
            while ((name.Length > 0) && (name[name.Length - 1] == Path.DirectorySeparatorChar))
            {
                name = name.Remove(name.Length - 1, 1);
            }
            for (num = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar)); num >= 0; num = name.IndexOf(Path.DirectorySeparatorChar))
            {
                name = name.Remove(num, 1);
            }
            num = name.IndexOfAny(InvalidEntryChars);
            if (num >= 0)
            {
                StringBuilder builder = new StringBuilder(name);
                while (true)
                {
                    if (num < 0)
                    {
                        name = builder.ToString();
                        break;
                    }
                    builder[num] = replacement;
                    num          = (num < name.Length) ? name.IndexOfAny(InvalidEntryChars, num + 1) : -1;
                }
            }
            if (name.Length > 260)
            {
                throw new PathTooLongException();
            }
            return(name);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Transform a windows file name according to the Zip file naming conventions.
        /// </summary>
        /// <param name="name">The file name to transform.</param>
        /// <returns>The transformed name.</returns>
        public string TransformFile(string name)
        {
            if (name != null)
            {
                var lowerName = name.ToLower();
                if ((trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0))
                {
                    name = name.Substring(trimPrefix_.Length);
                }

                name = name.Replace(@"\", "/");
                name = WindowsPathUtils.DropPathRoot(name);

                // Drop any leading slashes.
                while ((name.Length > 0) && (name[0] == '/'))
                {
                    name = name.Remove(0, 1);
                }

                // Drop any trailing slashes.
                while ((name.Length > 0) && (name[name.Length - 1] == '/'))
                {
                    name = name.Remove(name.Length - 1, 1);
                }

                // Convert consecutive // characters to /
                var index = name.IndexOf("//");
                while (index >= 0)
                {
                    name  = name.Remove(index, 1);
                    index = name.IndexOf("//");
                }

                name = MakeValidName(name, '_');
            }
            else
            {
                name = string.Empty;
            }
            return(name);
        }
Exemplo n.º 15
0
        public string TransformFile(string name)
        {
            if (name != null)
            {
                string lowerName = name.ToLower();
                if ((trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0))
                {
                    name = name.Substring(trimPrefix_.Length);
                }

                name = name.Replace(@"\", "/");
                name = WindowsPathUtils.DropPathRoot(name);


                while ((name.Length > 0) && (name[0] == '/'))
                {
                    name = name.Remove(0, 1);
                }


                while ((name.Length > 0) && (name[name.Length - 1] == '/'))
                {
                    name = name.Remove(name.Length - 1, 1);
                }


                int index = name.IndexOf("//");
                while (index >= 0)
                {
                    name  = name.Remove(index, 1);
                    index = name.IndexOf("//");
                }

                name = MakeValidName(name, '_');
            }
            else
            {
                name = string.Empty;
            }
            return(name);
        }
Exemplo n.º 16
0
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = WindowsPathUtils.DropPathRoot(name.Replace("/", "\\"));
            while (name.Length > 0 && name[0] == '\\')
            {
                name = name.Remove(0, 1);
            }
            while (name.Length > 0 && name[name.Length - 1] == '\\')
            {
                name = name.Remove(name.Length - 1, 1);
            }
            int num;

            for (num = name.IndexOf("\\\\"); num >= 0; num = name.IndexOf("\\\\"))
            {
                name = name.Remove(num, 1);
            }
            num = name.IndexOfAny(InvalidEntryChars);
            if (num >= 0)
            {
                StringBuilder stringBuilder = new StringBuilder(name);
                while (num >= 0)
                {
                    stringBuilder[num] = replacement;
                    num = ((num < name.Length) ? name.IndexOfAny(InvalidEntryChars, num + 1) : (-1));
                }
                name = stringBuilder.ToString();
            }
            if (name.Length > 260)
            {
                throw new PathTooLongException();
            }
            return(name);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Force a name to be valid by replacing invalid characters with a fixed value
        /// </summary>
        /// <param name="name">The name to make valid</param>
        /// <param name="replacement">The replacement character to use for any invalid characters.</param>
        /// <returns>Returns a valid name</returns>
        public static string MakeValidName(string name, char replacement)
        {
            if (name == null)
            {
                throw new ArgumentNullException();
            }

            name = WindowsPathUtils.DropPathRoot(name.Replace("/", Path.DirectorySeparatorChar.ToString()));

            // Drop any leading slashes.
            while ((name.Length > 0) && (name[0] == Path.DirectorySeparatorChar))
            {
                name = name.Remove(0, 1);
            }

            // Drop any trailing slashes.
            while ((name.Length > 0) && (name[name.Length - 1] == Path.DirectorySeparatorChar))
            {
                name = name.Remove(name.Length - 1, 1);
            }

            // Convert consecutive \\ characters to \
            int index = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal);

            while (index >= 0)
            {
                name  = name.Remove(index, 1);
                index = name.IndexOf(string.Format("{0}{0}", Path.DirectorySeparatorChar), StringComparison.Ordinal);
            }

            // Convert any invalid characters using the replacement one.
            index = name.IndexOfAny(InvalidEntryChars);
            if (index >= 0)
            {
                var builder = new StringBuilder(name);

                while (index >= 0)
                {
                    builder[index] = replacement;

                    if (index >= name.Length)
                    {
                        index = -1;
                    }
                    else
                    {
                        index = name.IndexOfAny(InvalidEntryChars, index + 1);
                    }
                }
                name = builder.ToString();
            }

            // Check for names greater than MaxPath characters.
            // TODO: Were is CLR version of MaxPath defined?  Can't find it in Environment.
            if (name.Length > MaxPath)
            {
                throw new PathTooLongException();
            }

            return(name);
        }