internal ushort ConvertToBinary(cFAT FAT, ushort SupSector)
        {
            ushort FirstSector;

            if (IsDirectory())
            {
                ushort[] BinDataTemp = new ushort[(this.Items.Count + 1) * Metadata.GetBinaryEntrySize()];
                ushort[] Temp;
                int      TempIndex = 0;
                FirstSector = FAT.RegisterSectors(this.GetSizeInSectors(FAT.GetSectorSize(), false));
                cFileFlags Flags = new cFileFlags();
                Flags.ReadOnly  = true;
                Flags.Directory = true;
                cFileSystemItem DirUp = new cFileSystemItem("..", "", Flags, false);
                Temp = DirUp.Metadata.GetDirectoryBinData(SupSector, 0);
                for (int i = 0; i < Temp.Length; i++)
                {
                    BinDataTemp[TempIndex] = Temp[i];
                    TempIndex++;
                }
                foreach (cFileSystemItem Item in this.Items)
                {
                    Temp = Item.Metadata.GetDirectoryBinData(Item.ConvertToBinary(FAT, FirstSector), Item.GetSizeInWordsForDirEntry());
                    for (int i = 0; i < Temp.Length; i++)
                    {
                        BinDataTemp[TempIndex] = Temp[i];
                        TempIndex++;
                    }
                }
                FAT.WriteData(BinDataTemp, FirstSector);
            }
            else
            {
                FirstSector = FAT.RegisterSectors(this.GetSizeInSectors(FAT.GetSectorSize(), false));
                FAT.WriteData(this.File.GetData(), FirstSector);
            }
            return(FirstSector);
        }
Example #2
0
 private bool ConvertEntrys(ushort SectorNumber, cFileSystemItem ItemToFill, uint Size)
 {
     if (ItemToFill.IsDirectory())
     {
         //ignore the first Entry, as it is isn't displayed in the logical structure
         int  SubIndex = ItemToFill.Metadata.GetBinaryEntrySize();
         bool run      = true;
         while (run)
         {
             if (HeaderVerifier.IsValidDirectoryEntry(InputFloppy.Sectors[SectorNumber], SubIndex, SectorNumber, InputFAT))
             {
                 //TODO: Read/write the datetimes
                 cFileFlags Flags = new cFileFlags();
                 Flags.ReadFromBinary((byte)InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 5]);
                 ushort[] Data = new ushort[4];
                 Data[0] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 0];
                 Data[1] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 1];
                 Data[2] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 2];
                 Data[3] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 3];
                 string Name = cFileSigConverter.ConvertToFileName(Data);
                 Data    = new ushort[2];
                 Data[0] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 4];
                 Data[1] = InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 5];
                 string          Extention = cFileSigConverter.ConvertToFileExtention(Data);
                 cFileSystemItem NewItem   = new cFileSystemItem(Name, Extention, Flags, false);
                 Size = (uint)((uint)InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 13] << 16 |
                               (uint)InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 12]);
                 if (ConvertEntrys(InputFloppy.Sectors[SectorNumber].Memory[SubIndex + 14], NewItem, Size))
                 {
                     ItemToFill.AddItem(NewItem);
                 }
                 SubIndex += ItemToFill.Metadata.GetBinaryEntrySize();
                 if (SubIndex >= InputFAT.GetSectorSize())
                 {
                     SubIndex     = 0;
                     SectorNumber = InputFAT.NextSector(SectorNumber);
                     if (SectorNumber >= 0xFFF0)
                     {
                         run = false;
                     }
                 }
             }
             else
             {
                 run = false;
             }
         }
         return(true);
     }
     else
     {
         List <ushort> Data = new List <ushort>();
         bool          run  = true;
         uint          i    = 0;
         while (run)
         {
             int subIndex = 0;
             while (subIndex < 512 && i < Size)
             {
                 Data.Add(InputFloppy.Sectors[SectorNumber].Memory[subIndex]);
                 i++;
                 subIndex++;
             }
             SectorNumber = InputFAT.NextSector(SectorNumber);
             if (SectorNumber >= 0xFFF0)
             {
                 run = false;
             }
         }
         cFile Newfile = new cFile();
         Newfile.SetFileData(Data);
         ItemToFill.SetFile(Newfile);
         return(true);
     }
 }