Example #1
0
        /// <summary>
        /// Main Entry Point
        /// </summary>
        /// <param name="args">Don't care (Yet)</param>
        /// <returns>0 on success</returns>
        static int Main(string[] args)
        {
            const int    RET_OK   = 0;
            const int    RET_FAIL = 1;
            const string IMAGE    = @"S:\Backup\Floppy_Images\Eliza.ima";

            if (!File.Exists(IMAGE))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine("The Image {0} was not found. Change Program.cs to fit your needs.", IMAGE);
                Console.ResetColor();
                return(RET_FAIL);
            }
            using (var FS = File.OpenRead(IMAGE))
            {
                //Read File as FAT12 Image
                var FAT = new FatPartition(FS);

                //Show Map
                ShowMapUnscaled(FAT.ClusterMap.Select(m => m.Status).ToArray());

                //If you want to test this with your own image, change the name to a valid root directory entry.
                var Entry = FAT.RootDirectory.FirstOrDefault(m => m.FullName.ToLower() == "eliza.dat");
                if (Entry != null)
                {
                    var Data = Encoding.Default.GetString(FAT.ReadFile(Entry, FS));
                    Console.Error.WriteLine(Data);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("Specified file not found in the image. Change Program.cs to fit your needs.");
                    Console.ResetColor();
                    return(RET_FAIL);
                }
                //Show FAT Directory recursively
                ShowDirectory(FAT.RootDirectory, FAT, FS);
                return(RET_OK);
            }
#if DEBUG
            Console.Error.WriteLine("#END");
            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }
            Console.ReadKey(true);
#endif
        }
Example #2
0
 /// <summary>
 /// Shows a Directory Entry recursively
 /// </summary>
 /// <param name="Entries">Directory Entries</param>
 /// <param name="FAT">FAT Partition of given Entries</param>
 /// <param name="FATStream">Stream for given FAT Partition</param>
 /// <param name="Parent">Parent Directory Path</param>
 private static void ShowDirectory(FatDirectoryEntry[] Entries, FatPartition FAT, Stream FATStream, string Parent = "")
 {
     if (Entries == null)
     {
         Entries = FAT.RootDirectory;
     }
     Console.WriteLine("Directory: {0}", string.IsNullOrEmpty(Parent) ? "\\" : Parent);
     foreach (var Entry in Entries.Where(m => m.EntryStatus == DirectoryEntryStatus.InUse))
     {
         Console.WriteLine("NAME={0,-12} TYPE={1,-15} SIZE={2,-10} START={3}", Entry.FullName, Entry.Attributes, Entry.FileSize, Entry.FirstCluster);
         //Recursively enter directories if the name is not "parent" or "current"
         if (Entry.Attributes.HasFlag(DirectoryEntryAttribute.Directory) && Entry.FullName != ".." && Entry.FullName != ".")
         {
             //- Reads cluster chain of given Directory
             //- Reads directory from given Chain
             //- Recursively enters function to show directory listing
             ShowDirectory(FatPartition.ReadDirectory(FAT.ReadClusters(FAT.GetClusterChain(Entry.FirstCluster), FATStream)), FAT, FATStream, Parent + "\\" + Entry.FullName);
         }
     }
 }