void RestoreBackup()
        {
            BinaryReader r = new BinaryReader(Stream);

            BackupEntry[] entries;

            //Read header
            int version = r.ReadInt32();        //File version

            r.ReadInt32();                      //Reserved
            r.ReadInt32();                      //Reserved
            int countOfEntries = r.ReadInt32(); //Count of BackupEntries

            entries = new BackupEntry[countOfEntries];

            //Read entries
            for (int i = 0; i < countOfEntries; i++)
            {
                entries[i] = ReadEntry(r);
            }

            //Read files
            if (version == 0)
            {
                foreach (BackupEntry e in entries)
                {
                    RestoreFile(r, e, Destination);
                }
            }
        }
        /// <summary>
        /// Writes file
        /// </summary>
        /// <param name="e">Entry containing informations about file</param>
        /// <param name="w">Stream</param>
        void WriteFile(BackupEntry e, BinaryWriter w)
        {
            FileStream s = new FileStream(e.FullName, FileMode.Open);

            byte[] File = new byte[s.Length];

            //Get file content
            for (int i = 0; i < s.Length; i++)
            {
                //Read byte
                int b = s.ReadByte();

                //If end of stream, break loop
                if (b == -1)
                {
                    break;
                }

                //Add byte
                File[i] = (byte)b;
            }

            //Write file
            foreach (byte b in File)
            {
                w.Write(b);
            }

            //Close and dispose stream
            s.Close();
            s.Dispose();
        }
        BackupEntry ReadEntry(BinaryReader r)
        {
            //Read entry
            BackupEntry entry = new BackupEntry();

            entry.FileName = r.ReadString();
            entry.Length   = r.ReadInt32();
            entry.Offset   = r.ReadInt32();

            //Return entry
            return(entry);
        }
        /// <summary>
        /// Creates entries
        /// </summary>
        /// <param name="FileNames">Names of files to backup</param>
        /// <returns></returns>
        List <BackupEntry> CreateEntries(List <string> FileNames)
        {
            List <BackupEntry> entries = new List <BackupEntry>();

            //Create entries
            foreach (string filename in FileNames)
            {
                //Get informations about file
                FileInfo    f = new FileInfo(filename);
                BackupEntry e = new BackupEntry();
                //Set values
                e.FileName = f.Name;
                e.FullName = f.FullName;
                e.Length   = (int)f.Length;

                //Add entry
                entries.Add(e);
            }

            return(entries);
        }
        /// <summary>
        /// Restores file from backup
        /// </summary>
        /// <param name="r">BinaryReader of backup file</param>
        /// <param name="e">BackupEntry used to get informations about file</param>
        /// <param name="directory">Destination directory of file</param>
        void RestoreFile(BinaryReader r, BackupEntry e, string directory)
        {
            string filename = Path.Combine(directory, e.FileName);

            using (FileStream fs = new FileStream(filename, FileMode.Create))
            {
                using (BinaryWriter w = new BinaryWriter(fs))
                {
                    //Set offset [Skipped]
                    //Reason: Unnecessary
                    //r.BaseStream.Position = e.Offset;

                    //Read bytes
                    byte[] data = r.ReadBytes(e.Length);

                    //Write data
                    foreach (byte b in data)
                    {
                        w.Write(b);
                    }
                }
            }
        }
 /// <summary>
 /// Writes entry
 /// </summary>
 /// <param name="e">Entry to write</param>
 /// <param name="w">Stream</param>
 void WriteEntry(BackupEntry e, BinaryWriter w)
 {
     w.Write(e.FileName);
     w.Write(e.Length);
     w.Write(e.Offset);
 }