예제 #1
0
        /// <summary>
        /// Attempts to parse an entry from a raw input.
        /// The input is expected to be in [path]:[hash]:[size] format.
        /// </summary>
        /// <returns><c>true</c>, if the input was successfully parse, <c>false</c> otherwise.</returns>
        /// <param name="rawInput">Raw input.</param>
        /// <param name="inEntry">The resulting entry.</param>
        public static bool TryParse(string rawInput, out ManifestEntry inEntry)
        {
            //clear out the entry for the new data
            inEntry = new ManifestEntry();

            if (!String.IsNullOrEmpty(rawInput))
            {
                //remove any and all bad characters from the input string,
                //such as \0, \n and \r.
                string cleanInput = CleanInput(rawInput);

                //split the string into its three components - file, hash and size
                string[] entryElements = cleanInput.Split(':');

                //if we have three elements (which we should always have), set them in the provided entry
                if (entryElements.Length == 3)
                {
                    //clean the manifest path, converting \ to / on unix and / to \ on Windows.
                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        inEntry.RelativePath = entryElements[0].Replace("\\", "/");
                    }
                    else
                    {
                        inEntry.RelativePath = entryElements[0].Replace("/", "\\");
                    }

                    //set the hash to the second element
                    inEntry.Hash = entryElements[1];

                    //attempt to parse the final element as a long-type byte count.
                    long parsedSize;
                    if (long.TryParse(entryElements[2], out parsedSize))
                    {
                        inEntry.Size = parsedSize;
                        return(true);
                    }
                    else
                    {
                        //could not parse the size, parsing has failed.
                        return(false);
                    }
                }
                else
                {
                    //wrong number of raw entry elements, parsing has failed.
                    return(false);
                }
            }
            else
            {
                //no input, parsing has failed
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Attempts to parse an entry from a raw input.
        /// The input is expected to be in [path]:[hash]:[size] format.
        /// </summary>
        /// <returns><c>true</c>, if the input was successfully parse, <c>false</c> otherwise.</returns>
        /// <param name="rawInput">Raw input.</param>
        /// <param name="inEntry">The resulting entry.</param>
        public static bool TryParse(string rawInput, out ManifestEntry inEntry)
        {
            // Clear out the entry for the new data
            inEntry = new ManifestEntry();

            if (!string.IsNullOrEmpty(rawInput))
            {
                // Remove any and all bad characters from the input string,
                // such as \0, \n and \r.
                string cleanInput = rawInput.RemoveLineSeparatorsAndNulls();

                // Split the string into its three components - file, hash and size
                string[] entryElements = cleanInput.Split(':');

                // If we have three elements (which we should always have), set them in the provided entry
                if (entryElements.Length == 3)
                {
                    // Normalize the manifest path, converting \ to / on unix and / to \ on Windows.
                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        inEntry.RelativePath = entryElements[0].Replace("\\", "/");
                    }
                    else
                    {
                        inEntry.RelativePath = entryElements[0].Replace("/", "\\");
                    }

                    // Set the hash to the second element
                    inEntry.Hash = entryElements[1];

                    // Attempt to parse the final element as a long-type byte count.
                    long parsedSize;
                    if (!long.TryParse(entryElements[2], out parsedSize))
                    {
                        // Oops. The parsing failed, so this entry is invalid.
                        return(false);
                    }

                    inEntry.Size = parsedSize;
                    return(true);
                }
            }

            return(false);
        }