Пример #1
0
        public static string GenerateRandomPath(uint segmentCount)
        {
            if (segmentCount == 0)
            {
                return(null);
            }
            uint num  = 11 * segmentCount;
            uint num2 = (uint)Math.Ceiling((double)(num * 0.625));

            byte[] data = new byte[num2];
            new RNGCryptoServiceProvider().GetBytes(data);
            string str = Base32String.FromBytes(data);

            if (str.Length < num)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringTooShort"));
            }
            if (str.IndexOf('\\') >= 0)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
            }
            for (int i = ((int)segmentCount) - 1; i > 0; i--)
            {
                int startIndex = i * 11;
                if (startIndex >= str.Length)
                {
                    throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
                }
                str = str.Insert(startIndex, @"\");
            }
            string[] strArray = str.Split(new char[] { '\\' });
            if (strArray.Length < segmentCount)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
            }
            string str2 = null;

            for (uint j = 0; j < segmentCount; j++)
            {
                if (strArray[j].Length < 11)
                {
                    throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
                }
                string str3 = strArray[j].Substring(0, 11).Insert(8, ".");
                if (str2 == null)
                {
                    str2 = str3;
                }
                else
                {
                    str2 = Path.Combine(str2, str3);
                }
            }
            return(str2);
        }
Пример #2
0
        public static string GenerateRandomPath(uint segmentCount)
        {
            if ((int)segmentCount == 0)
            {
                return((string)null);
            }
            uint num = 11U * segmentCount;

            byte[] numArray = new byte[(int)(uint)Math.Ceiling((double)num * 0.625)];
            new RNGCryptoServiceProvider().GetBytes(numArray);
            string str = Base32String.FromBytes(numArray);

            if ((long)str.Length < (long)num)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringTooShort"));
            }
            if (str.IndexOf('\\') >= 0)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
            }
            for (int index = (int)segmentCount - 1; index > 0; --index)
            {
                int startIndex = index * 11;
                if (startIndex >= str.Length)
                {
                    throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
                }
                str = str.Insert(startIndex, "\\");
            }
            string[] strArray = str.Split('\\');
            if ((long)strArray.Length < (long)segmentCount)
            {
                throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
            }
            string path1 = (string)null;

            for (uint index = 0; index < segmentCount; ++index)
            {
                if (strArray[(int)index].Length < 11)
                {
                    throw new DeploymentException(Resources.GetString("Ex_TempPathRandomStringInvalid"));
                }
                string path2 = strArray[(int)index].Substring(0, 11).Insert(8, ".");
                path1 = path1 != null?Path.Combine(path1, path2) : path2;
            }
            return(path1);
        }