コード例 #1
0
ファイル: String.cs プロジェクト: zrbruce/FlingOS
        public Collections.List Split(char splitChar)
        {
            Collections.List result = new Collections.List(1);

            int lastSplitIndex = 0;

            for (int i = 0; i < this.length; i++)
            {
                if (this[i] == splitChar)
                {
                    result.Add(this.Substring(lastSplitIndex, i - lastSplitIndex));
                    lastSplitIndex = i + 1;
                }
            }
            if (this.length - lastSplitIndex > 0)
            {
                result.Add(this.Substring(lastSplitIndex, this.length - lastSplitIndex));
            }

            return(result);
        }
コード例 #2
0
ファイル: MainShell.cs プロジェクト: rmhasan/FlingOS
        /// <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
ファイル: MainShell.cs プロジェクト: rmhasan/FlingOS
 /// <summary>
 /// Formats the specified disk.
 /// </summary>
 /// <param name="disk">The disk to format.</param>
 private void FormatDisk(Hardware.Devices.DiskDevice disk)
 {
     List newPartitionInfos = new List(1);
     
     console.WriteLine("Creating partition info...");
     newPartitionInfos.Add(FOS_System.IO.Disk.MBR.CreateFAT32PartitionInfo(disk, false));
     
     console.WriteLine("Done. Doing MBR format...");
     FOS_System.IO.Disk.MBR.FormatDisk(disk, newPartitionInfos);
     
     console.WriteLine("Done. Initialising disk...");
     FileSystemManager.InitDisk(disk);
     
     console.WriteLine("Done. Finding partition...");
     Partition thePart = null;
     for (int i = 0; i < FileSystemManager.Partitions.Count; i++)
     {
         Partition aPart = (Partition)FileSystemManager.Partitions[i];
         if(aPart.TheDiskDevice == disk)
         {
             thePart = aPart;
             break;
         }
     }
     if (thePart != null)
     {
         console.WriteLine("Done. Formatting as FAT32...");
         FOS_System.IO.FAT.FATFileSystem.FormatPartitionAsFAT32(thePart);
         
         console.WriteLine("Done.");
         console.WriteLine("Format completed successfully.");
     }
     else
     {
         console.WriteLine("Done. Partition not found.");
         console.WriteLine("Format failed.");
     }
 }
コード例 #4
0
ファイル: FATFileSystem.cs プロジェクト: rmhasan/FlingOS
        /// <summary>
        /// Parses the specified directory file data for its listings.
        /// </summary>
        /// <param name="xData">The directory data.</param>
        /// <param name="xDataLength">The directory data length.</param>
        /// <param name="thisDir">
        /// The FAT directory the FAT data is from. 
        /// Used when creating listings as the parent directory.
        /// </param>
        /// <returns>The directory listings.</returns>
        public List ParseDirectoryTable(byte[] xData, int xDataLength, FATDirectory thisDir)
        {
            List xResult = new List();

            //BasicConsole.WriteLine("Parsing listings...");

            FOS_System.String xLongName = "";
            for (UInt32 i = 0; i < xDataLength; i = i + 32)
            {
                byte xAttrib = xData[i + 11];
                if (xAttrib == ListingAttribs.LongName)
                {
                    byte xType = xData[i + 12];
                    if (xType == 0)
                    {
                        byte xOrd = xData[i];
                        if ((xOrd & 0x40) > 0)
                        {
                            xLongName = "";
                        }
                        //TODO: Check LDIR_Ord for ordering and throw exception
                        // if entries are found out of order.
                        // Also save buffer and only copy name if a end Ord marker is found.
                        FOS_System.String xLongPart = ByteConverter.GetASCIIStringFromUTF16(xData, i + 1, 5);
                        //BasicConsole.WriteLine("xLongPart1: " + xLongPart);
                        // We have to check the length because 0xFFFF is a valid Unicode codepoint.
                        // So we only want to stop if the 0xFFFF is AFTER a 0x0000. We can determine
                        // this by also looking at the length. Since we short circuit the or, the length
                        // is rarely evaluated.
                        if (xLongPart.length == 5)
                        {
                            xLongPart = xLongPart + ByteConverter.GetASCIIStringFromUTF16(xData, i + 14, 6);
                            //BasicConsole.WriteLine("xLongPart2: " + xLongPart);
                            if (xLongPart.length == 11)
                            {
                                xLongPart = xLongPart + ByteConverter.GetASCIIStringFromUTF16(xData, i + 28, 2);
                                //BasicConsole.WriteLine("xLongPart3: " + xLongPart);
                            }
                        }
                        xLongName = xLongPart + xLongName;
                        //BasicConsole.WriteLine("xLongName: " + xLongName);
                        //TODO: LDIR_Chksum 
                    }
                }
                else
                {
                    byte xStatus = xData[i];
                    if (xStatus == 0x00)
                    {
                        // Empty slot, and no more entries after this
                        break;
                    }
                    else if (xStatus == 0x05)
                    {
                        // Japanese characters - We dont handle these
                    }
                    else if (xStatus == 0xE5)
                    {
                        // Empty slot, skip it
                    }
                    else if (xStatus >= 0x20)
                    {
                        FOS_System.String xName;

                        int xTest = xAttrib & (ListingAttribs.Directory | ListingAttribs.VolumeID);

                        if (xLongName.length > 0)
                        {
                            // Leading and trailing spaces are to be ignored according to spec.
                            // Many programs (including Windows) pad trailing spaces although it 
                            // it is not required for long names.
                            xName = xLongName.Trim();

                            // As per spec, ignore trailing periods
                            //If there are trailing periods
                            int nameIndex = xName.length - 1;
                            if (xName[nameIndex] == '.')
                            {
                                //Search backwards till we find the first non-period character
                                for (; nameIndex > -1; nameIndex--)
                                {
                                    if (xName[nameIndex] != '.')
                                    {
                                        break;
                                    }
                                }
                                //Substring to remove the periods
                                xName = xName.Substring(0, nameIndex + 1);
                            }
                        }
                        else
                        {
                            FOS_System.String xEntry = ByteConverter.GetASCIIStringFromASCII(xData, i, 11);
                            //Volume ID does not have same format as file-name.
                            if (xTest == ListingAttribs.VolumeID)
                            {
                                xName = xEntry;
                            }
                            else
                            {
                                //Attempt to apply original spec:
                                // - 8 chars for filename
                                // - 3 chars for extension
                                if (xEntry.length >= 8)
                                {
                                    xName = xEntry.Substring(0, 8).TrimEnd();

                                    if (xEntry.length >= 11)
                                    {
                                        FOS_System.String xExt = xEntry.Substring(8, 3).TrimEnd();
                                        if (xExt.length > 0)
                                        {
                                            xName += "." + xExt;
                                        }
                                    }
                                }
                                else
                                {
                                    xName = xEntry;
                                }
                            }
                        }

                        UInt32 xFirstCluster = (UInt32)(ByteConverter.ToUInt16(xData, i + 20) << 16 | ByteConverter.ToUInt16(xData, i + 26));

                        xName = xName.ToUpper();

                        //TODO: Store attributes in the listings

                        if (xTest == 0)
                        {
                            if (xName[xName.length - 1] != '~')
                            {
                                UInt32 xSize = ByteConverter.ToUInt32(xData, i + 28);
                                xResult.Add(new FATFile(this, thisDir, xName, xSize, xFirstCluster));
                            }
                            else
                            {
                                //BasicConsole.WriteLine("Ignoring file: " + xName);
                            }
                        }
                        else if (xTest == ListingAttribs.VolumeID)
                        {
                            thePartition.VolumeID = xName;
                        }
                        else if (xTest == ListingAttribs.Directory)
                        {
                            xResult.Add(new FATDirectory(this, thisDir, xName, xFirstCluster));
                        }
                        xLongName = "";
                    }
                }
            }

            return xResult;
        }
コード例 #5
0
ファイル: FATFileSystem.cs プロジェクト: rmhasan/FlingOS
 /// <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;
     }
 }
コード例 #6
0
ファイル: String.cs プロジェクト: sramos30/FlingOS
        public Collections.List Split(char splitChar)
        {
            Collections.List result = new Collections.List(1);

            int lastSplitIndex = 0;
            for (int i = 0; i < this.length; i++)
            {
                if (this[i] == splitChar)
                {
                    result.Add(this.Substring(lastSplitIndex, i - lastSplitIndex));
                    lastSplitIndex = i + 1;
                }
            }
            if (this.length - lastSplitIndex > 0)
            {
                result.Add(this.Substring(lastSplitIndex, this.length - lastSplitIndex));
            }

            return result;
        }
コード例 #7
0
ファイル: CommandHelp.cs プロジェクト: zrbruce/FlingOS
        /// <summary>
        /// CommandHelp constructor
        /// </summary>
        static CommandHelp()
        {
            #region ExInfo
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "ExInfo",
                CommandNameLower = "exinfo",
                Description      = "Provides you all the cached exception details."
            });
            #endregion

            #region Halt
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Halt",
                CommandNameLower = "halt",
                Description      = "Shuts down the system."
            });
            #endregion

            #region Init
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Init",
                CommandNameLower = "init",
                Description      = @"Init { ALL / PCI / ATA / USB / FS }
To initialize an individual sub-system or group of sub-systems, call 'init <option>'.

Possible options: 
    All => (group) Initializes all the sub-systems in the correct order. 
    PCI => Initialize PCI devices.
    ATA => Initialize ATA/PATA/SATA devices.
    USB => Initialize USB sub-system (EHCI, USB and USB MSDs). Dependent upon PCI sub-system. PCI must be initialised first.
    FS  => Initialize partitions and file systems. Dependent upon ATA or USB sub-systems. One or more must be initialised prior to calling this."
            });
            #endregion

            #region Output
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Output",
                CommandNameLower = "output",
                Description      = @"Output { PCI / ATA / USB / FS / Memory }
Displays the status of an individual sub-system. To get the status of an individual sub-system, call 'output <option>'.

Possible options:
    PCI => Output information about PCI devices,
    ATA => Output information about ATA/PATA/SATA device,
    USB => Output information about USB interfaces and USB devices,
    FS  => Output partition and file system statuses,
    Memory = > Output Heap memory and GC status.",
            });
            #endregion

            #region CheckDisk
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "CheckDisk",
                CommandNameLower = "checkdisk",
                Description      = @"CheckDisk/ChkD  { Drive# }
Check disks passed in option for errors.
",
            });
            #endregion

            #region chkd
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Chkd",
                CommandNameLower = "chkd",
                Description      = @"CheckDisk/ChkD  { Drive# }
Alias for CheckDisk commmand.
",
            });
            #endregion

            #region FormatDisk
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "FormatDisk",
                CommandNameLower = "formatdisk",
                Description      = @"FormatDisk/FmtD { Drive# }
Formats a disk passed in option in FAT 32 format.
",
            });
            #endregion

            #region Fmtd
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Fmtd",
                CommandNameLower = "fmtd",
                Description      = @"FormatDisk/FmtD { Drive# }
Alias for FormatDisk.
",
            });
            #endregion

            #region Dir
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Dir",
                CommandNameLower = "dir",
                Description      = @"Dir  { List / Open / New / Delete / Copy }
Dir List <Path> : List files/directories in the path specified.
Dir Open <Path> : Open specified directory.
Dir New <Path>  : Create a new directory.
Dir Delete <Path>: Delete specified directory.
Dir Copy <SrcPath> <DestPath> : Copy specified directory in SrcPath to DestPath.
On changing directory, it will set ./ to current directory.
To refer current directory, you can use ./ and for the parent directory, use ../
",
            });
            #endregion

            #region File
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "File",
                CommandNameLower = "file",
                Description      = @"File { Open/Delete/Copy }
File Open <File> : Open a file  and outputs its content.
File Delete <File> : Delete a specified File.
File Copy <SrcFile> <DestFile>  : Copies specified source file <SrcFile> to destination.
",
            });
            #endregion

            #region GC
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "GC",
                CommandNameLower = "gc",
                Description      = @"GC { [Cleanup] }
Calls garbage collection and performs memory clean up.
Cleanup: This argument is optional and doesn't modify the behaviour.
",
            });
            #endregion

            #region Clear
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Clear",
                CommandNameLower = "clear",
                Description      = @"Clear
Clears the command shell and displays the empty prompt.",
            });
            #endregion

            #region Show
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Show",
                CommandNameLower = "show",
                Description      = @"Show {w/c}
Show: Show the License information.
Show w: Show the license warnings.
Show c: Show the license conditions."
            });
            #endregion

            #region Reboot
            CommandDescriptions.Add(new CommandDescription()
            {
                CommandName      = "Reboot",
                CommandNameLower = "reboot",
                Description      = @"Reboot
Safely reboots the computer."
            });
            #endregion
        }
コード例 #8
0
ファイル: ISO9660Directory.cs プロジェクト: rmhasan/FlingOS
        public override List GetListings()
        {
            if (_cachedlistings == null)
            {
                Get_FileStream();
                byte[] data = new byte[(uint)_theFile.Size];
                _fileStream.Position = 0;
                int actuallyRead = _fileStream.Read(data, 0, (int)data.Length);
                _cachedlistings = new List(10);

                uint position = 0;
                Disk.ISO9660.DirectoryRecord newRecord;
                do
                {
                    newRecord = new Disk.ISO9660.DirectoryRecord(data, position);
#if ISO9660DIR_TRACE
                    BasicConsole.WriteLine(newRecord.ConvertToString());
#endif
                    if (newRecord.RecordLength > 0)
                    {
                        if ((newRecord.TheFileFlags & Disk.ISO9660.DirectoryRecord.FileFlags.Directory) != 0)
                        {
                            // Directory
                            _cachedlistings.Add(new ISO9660Directory((ISO9660FileSystem)TheFileSystem, this, newRecord));
                        }
                        else
                        {
                            // File
                            _cachedlistings.Add(new ISO9660File((ISO9660FileSystem)TheFileSystem, this, newRecord));
                        }

                        position += newRecord.RecordLength;
                    }
                }
                while (position < data.Length && newRecord.RecordLength > 0);
            }
            return _cachedlistings;
        }