Example #1
0
 /// <summary>
 /// Gets a type of System.IO.BinaryWriter for the current drive
 /// </summary>
 /// <returns>Streams.Writer</returns>
 public Streams.Writer Writer()
 {
     if (thisWriter == null)
     {
         thisWriter = new CLKsFATXLib.Streams.Writer(Stream());
     }
     thisWriter.BaseStream.Position = 0;
     return(thisWriter);
 }
Example #2
0
 public void Close()
 {
     try
     {
         thisStream.Close();
     }
     catch { }
     thisReader = null;
     thisWriter = null;
     thisStream = null;
 }
 public long GetNewEntryOffset(Folder Destination)
 {
     // Go to the last block since we want to speed things up and not have to go
     // through all of them
     EntryData[] Entries = EntryDataFromBlock(Destination.BlocksOccupied[Destination.BlocksOccupied.Length - 1]);
     if (Entries.Length == 0)
     {
         return(Destination.StartingOffset);
     }
     // If there isn't the maximum amount of entries for a cluster...
     if (Entries.Length < Destination.PartitionInfo.ClusterSize / 0x40)
     {
         foreach (EntryData e in Entries)
         {
             if (e.NameSize == 0xE5)
             {
                 return(e.EntryOffset);
             }
         }
         return(Entries[Entries.Length - 1].EntryOffset + 0x40);
     }
     // Max amount of entries, let's add another cluster to our parent...
     else
     {
         uint[] NewBlocks = new uint[Destination.BlocksOccupied.Length + 1];
         Array.Copy(Destination.BlocksOccupied, NewBlocks, Destination.BlocksOccupied.Length);
         NewBlocks[NewBlocks.Length - 1] = Destination.Drive.GetFreeBlocks((Folder)Destination, 1, 0, 0, false)[0];
         byte[] FF = new byte[Destination.PartitionInfo.ClusterSize];
         for (int i = 0; i < FF.Length; i++)
         {
             FF[i] = 0xFF;
         }
         Streams.Writer w = Destination.Drive.Writer();
         w.BaseStream.Position = VariousFunctions.BlockToFATOffset(NewBlocks[NewBlocks.Length - 1], Destination);
         w.Write(FF);
         Destination.BlocksOccupied = NewBlocks;
         return(VariousFunctions.BlockToFATOffset(NewBlocks[NewBlocks.Length - 1], Destination));
     }
 }
 /// <summary>
 /// Gets a type of System.IO.BinaryWriter for the current drive
 /// </summary>
 /// <returns>Streams.Writer</returns>
 public Streams.Writer Writer()
 {
     if (thisWriter == null)
     {
         thisWriter = new CLKsFATXLib.Streams.Writer(Stream());
     }
     thisWriter.BaseStream.Position = 0;
     return thisWriter;
 }
 public void Close()
 {
     try
     {
         thisStream.Close();
     }
     catch { }
     thisReader = null;
     thisWriter = null;
     thisStream = null;
 }
 // Do not feel like recoding this function.
 public void CreateNewEntry(EntryData Edata)
 {
     Streams.Reader br = Parent.Drive.Reader();
     //Set our position so that we can read the entry location
     br.BaseStream.Position = VariousFunctions.DownToNearest200(Edata.EntryOffset);
     byte[] buffer = br.ReadBytes(0x200);
     //Create our binary writer
     Streams.Writer bw = new Streams.Writer(new System.IO.MemoryStream(buffer));
     //Set our position to where the entry is
     long EntryOffset = Edata.EntryOffset - VariousFunctions.DownToNearest200(Edata.EntryOffset);
     bw.BaseStream.Position = EntryOffset;
     //Write our entry
     bw.Write(Edata.NameSize);
     bw.Write(Edata.Flags);
     bw.Write(Encoding.ASCII.GetBytes(Edata.Name));
     if (Edata.NameSize != 0xE5)
     {
         int FFLength = 0x2A - Edata.NameSize;
         byte[] FF = new byte[FFLength];
         for (int i = 0; i < FFLength; i++)
         {
             FF[i] = 0xFF;
         }
         bw.Write(FF);
     }
     else
     {
         bw.BaseStream.Position += 0x2A - Edata.Name.Length;
     }
     //Right here, we need to make everything a byte array, as it feels like writing
     //everything in little endian for some reason...
     byte[] StartingCluster = BitConverter.GetBytes(Edata.StartingCluster);
     Array.Reverse(StartingCluster);
     bw.Write(StartingCluster);
     byte[] Size = BitConverter.GetBytes(Edata.Size);
     Array.Reverse(Size);
     bw.Write(Size);
     //Write ref the creation date/time 3 times
     byte[] CreationDate = BitConverter.GetBytes(Edata.CreationDate);
     byte[] CreationTime = BitConverter.GetBytes(Edata.CreationTime);
     byte[] AccessDate = BitConverter.GetBytes(Edata.AccessDate);
     byte[] AccessTime = BitConverter.GetBytes(Edata.AccessTime);
     byte[] ModifiedDate = BitConverter.GetBytes(Edata.ModifiedDate);
     byte[] ModifiedTime = BitConverter.GetBytes(Edata.ModifiedTime);
     Array.Reverse(CreationDate);
     Array.Reverse(CreationTime);
     Array.Reverse(AccessDate);
     Array.Reverse(AccessTime);
     Array.Reverse(ModifiedDate);
     Array.Reverse(ModifiedTime);
     bw.Write(CreationDate);
     bw.Write(CreationTime);
     bw.Write(AccessDate);
     bw.Write(AccessTime);
     bw.Write(ModifiedDate);
     bw.Write(ModifiedTime);
     //Close our writer
     bw.Close();
     //Get our IO
     bw = Parent.Drive.Writer();
     bw.BaseStream.Position = VariousFunctions.DownToNearest200(Edata.EntryOffset);
     //Write ref our buffer
     bw.Write(buffer);
 }
        // Do not feel like recoding this function.
        public void CreateNewEntry(EntryData Edata)
        {
            Streams.Reader br = Parent.Drive.Reader();
            //Set our position so that we can read the entry location
            br.BaseStream.Position = VariousFunctions.DownToNearest200(Edata.EntryOffset);
            byte[] buffer = br.ReadBytes(0x200);
            //Create our binary writer
            Streams.Writer bw = new Streams.Writer(new System.IO.MemoryStream(buffer));
            //Set our position to where the entry is
            long EntryOffset = Edata.EntryOffset - VariousFunctions.DownToNearest200(Edata.EntryOffset);

            bw.BaseStream.Position = EntryOffset;
            //Write our entry
            bw.Write(Edata.NameSize);
            bw.Write(Edata.Flags);
            bw.Write(Encoding.ASCII.GetBytes(Edata.Name));
            if (Edata.NameSize != 0xE5)
            {
                int    FFLength = 0x2A - Edata.NameSize;
                byte[] FF       = new byte[FFLength];
                for (int i = 0; i < FFLength; i++)
                {
                    FF[i] = 0xFF;
                }
                bw.Write(FF);
            }
            else
            {
                bw.BaseStream.Position += 0x2A - Edata.Name.Length;
            }
            //Right here, we need to make everything a byte array, as it feels like writing
            //everything in little endian for some reason...
            byte[] StartingCluster = BitConverter.GetBytes(Edata.StartingCluster);
            Array.Reverse(StartingCluster);
            bw.Write(StartingCluster);
            byte[] Size = BitConverter.GetBytes(Edata.Size);
            Array.Reverse(Size);
            bw.Write(Size);
            //Write ref the creation date/time 3 times
            byte[] CreationDate = BitConverter.GetBytes(Edata.CreationDate);
            byte[] CreationTime = BitConverter.GetBytes(Edata.CreationTime);
            byte[] AccessDate   = BitConverter.GetBytes(Edata.AccessDate);
            byte[] AccessTime   = BitConverter.GetBytes(Edata.AccessTime);
            byte[] ModifiedDate = BitConverter.GetBytes(Edata.ModifiedDate);
            byte[] ModifiedTime = BitConverter.GetBytes(Edata.ModifiedTime);
            Array.Reverse(CreationDate);
            Array.Reverse(CreationTime);
            Array.Reverse(AccessDate);
            Array.Reverse(AccessTime);
            Array.Reverse(ModifiedDate);
            Array.Reverse(ModifiedTime);
            bw.Write(CreationDate);
            bw.Write(CreationTime);
            bw.Write(AccessDate);
            bw.Write(AccessTime);
            bw.Write(ModifiedDate);
            bw.Write(ModifiedTime);
            //Close our writer
            bw.Close();
            //Get our IO
            bw = Parent.Drive.Writer();
            bw.BaseStream.Position = VariousFunctions.DownToNearest200(Edata.EntryOffset);
            //Write ref our buffer
            bw.Write(buffer);
        }