Пример #1
0
 /// <summary>
 /// Gets the listing for the specified file or directory.
 /// </summary>
 /// <param name="aName">The full path to the file or directory.</param>
 /// <returns>The listing or null if not found.</returns>
 public override Base GetListing(FOS_System.String aName)
 {
     if (aName == "")
     {
         return RootDirectory_FAT32;
     }
     else
     {
         List nameParts = aName.Split(FileSystemManager.PathDelimiter);
         List listings = GetRootDirectoryListings();
         return GetListingFromListings(nameParts, null, listings);
     }
 }
Пример #2
0
        /// <summary>
        /// Splits the input string into commands including handling quoted parts.
        /// </summary>
        /// <param name="input">The input to split.</param>
        /// <returns>The list of command parts.</returns>
        private List SplitCommand(FOS_System.String input)
        {
            //This method splits the input into parts separated by spaces
            //  However, it must then also search for grouped parts which
            //  are indicated by start and end quote marks (").

            //Split the input by space
            List parts = input.Split(' ');
            //Create a list for the result - capacity 4 is the usual maximum we expect so this just
            //  optimises the internal array creation a bit.
            List result = new List(4);
            //Stores the current part being constructed.
            FOS_System.String currPart = "";
            //Indicates whether we are constructing a grouped part or not.
            bool waitingForCloseQuote = false;
            //Loop through all parts
            for(int i = 0; i < parts.Count; i++)
            {
                //If we are constructing a grouped part
                if (waitingForCloseQuote)
                {
                    //Add the part (including the space which was removed by split)
                    //  to the currently constructing part
                    currPart += " " + (FOS_System.String)parts[i];

                    //If the part ends with a quote, then we have found our closing quote
                    //  which terminates the group part
                    if(currPart.EndsWith("\""))
                    {
                        //Remove the closing quote
                        currPart = currPart.Substring(0, currPart.length - 1);
                        //End the search
                        waitingForCloseQuote = false;
                        //Add the part to the result
                        result.Add(currPart.ToLower());
                    }
                }
                else
                {
                    //Set the current part
                    currPart = (FOS_System.String)parts[i];

                    //If it starts with a quote, it is the start of a group part
                    if(currPart.StartsWith("\""))
                    {
                        //If it ends with a quote, it is also the end of the group part
                        //  so essentially the user grouped something which didn't 
                        //  actually contain any spaces.
                        if (currPart.EndsWith("\""))
                        {
                            //Remove the start and end quotes
                            currPart = currPart.Substring(1, currPart.length - 2);
                            //Add the part to the result
                            result.Add(currPart.ToLower());
                        }
                        else
                        {
                            //Remove the start quote
                            currPart = currPart.Substring(1, currPart.length - 1);
                            //Begin the search for the end of the group part
                            waitingForCloseQuote = true;
                        }
                    }
                    else
                    {
                        //This is a normal, ungrouped part so just add it to
                        //  the result
                        result.Add(currPart.ToLower());
                    }
                }
            }
            return result;
        }
Пример #3
0
 /// <summary>
 /// Gets the short name for the specified long name.
 /// </summary>
 /// <param name="longName">The long name to shorten.</param>
 /// <param name="isDirectory">Whether the long name is for a directory or not.</param>
 /// <returns>The short name parts. Directory=1 part, file=2 parts (name + extension).</returns>
 private static List GetShortName(FOS_System.String longName, bool isDirectory)
 {
     if (isDirectory)
     {
         List result = new List(1);
         result.Add(longName.Substring(0, 8).PadRight(11, ' '));
         return result;
     }
     else
     {
         List result = new List(2);
         List nameParts = longName.Split('.');
         if (nameParts.Count > 1)
         {
             result.Add(((FOS_System.String)nameParts[0]).Substring(0, 8).PadRight(8, ' '));
             result.Add(((FOS_System.String)nameParts[1]).Substring(0, 3).PadRight(3, ' '));
         }
         else
         {
             result.Add(longName.Substring(0, 8).PadRight(8, ' '));
             result.Add(((FOS_System.String)"").PadRight(3, ' '));
         }
         return result;
     }
 }