Esempio n. 1
0
 /*
  * Encode db file to memory and return it as a byte array.
  */
 public static byte[] Encode(DBFile file)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         Encode(stream, file);
         return(stream.ToArray());
     }
 }
Esempio n. 2
0
        public static void Encode(Stream stream, DBFile file)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            file.Header.EntryCount = (uint)file.Entries.Count;
            WriteHeader(writer, file.Header);
            file.Entries.ForEach(delegate(DBRow e) { WriteEntry(writer, e); });
            writer.Flush();
        }
Esempio n. 3
0
        private static DataTable GetDataTable(String tableKey)
        {
            PackedFile currentPackedFile     = currentPackFile.Files[0];
            PackedFile replacementPackedFile = currentPackedFile;

            DBFile test = PackedFileDbCodec.Decode(currentPackedFile);

            test.Entries[0][0].Value = "dicks and or butts";

            Encode(new MemoryStream(replacementPackedFile.Data), test);

            //currentPackFile.Files[0] = currentPackedFile;

            //currentPackFile.Files[0] = null;

            currentPackFile.Files.Remove(currentPackedFile);
            currentPackFile.Files.Add(replacementPackedFile);

            return(new DataTable());
        }
Esempio n. 4
0
        /*
         * Add data contained in the given db file to this one.
         */
        public void Import(DBFile file)
        {
            if (CurrentType.Name != file.CurrentType.Name)
            {
                throw new DBFileNotSupportedException
                          ("File type of imported DB doesn't match that of the currently opened one", this);
            }
            // check field type compatibility
            for (int i = 0; i < file.CurrentType.Fields.Count; i++)
            {
                if (file.CurrentType.Fields [i].TypeCode != CurrentType.Fields [i].TypeCode)
                {
                    throw new DBFileNotSupportedException
                              ("Data structure of imported DB doesn't match that of currently opened one at field " + i, this);
                }
            }
            DBFileHeader h = file.Header;

            Header      = new DBFileHeader(h.GUID, h.Version, h.EntryCount, h.HasVersionMarker);
            CurrentType = file.CurrentType;
            // this.entries = new List<List<FieldInstance>> ();
            entries.AddRange(file.entries);
            Header.EntryCount = (uint)entries.Count;
        }
Esempio n. 5
0
 /*
  * Create copy of the given db file.
  */
 public DBFile(DBFile toCopy) : this(toCopy.Header, toCopy.CurrentType)
 {
     Header = new DBFileHeader(toCopy.Header.GUID, toCopy.Header.Version, toCopy.Header.EntryCount, toCopy.Header.HasVersionMarker);
     // we need to create a new instance for every field so we don't write through to the old data
     toCopy.entries.ForEach(entry => entries.Add(new DBRow(toCopy.CurrentType, entry)));
 }
 public DBFileNotSupportedException(string message, DBFile file) : base(message)
 {
     DbFile = file;
 }
 public DBFileNotSupportedException(DBFile file) : this("DB File not supported", file)
 {
 }
 public DbException(string message, DBFile file) : base(message)
 {
     DbFile = file;
 }