예제 #1
0
        protected bool MldbRead(FileStream stream)
        {
            stream.Seek(4, SeekOrigin.Begin);
            try
            {
                while (true)
                {
                    Int32 categoryID = 0;
                    if (!this.MldbReadInteger(stream, ref categoryID))
                    {
                        return(false);
                    }

                    if (categoryID == 0)
                    {
                        this._isLoaded = true;
                        return(true);
                    }

                    MdbCategory category = this.GetCategory(categoryID);
                    if (category == null)
                    {
                        category = new MdbCategory(categoryID, 0);
                        this._categories.Add(category);
                    }

                    Int32 entryID = 0;
                    if (!this.MldbReadInteger(stream, ref entryID))
                    {
                        return(false);
                    }

                    Int32 size = 0;
                    if (!this.MldbReadInteger(stream, ref size))
                    {
                        return(false);
                    }

                    byte[] buffer = new byte[size];
                    stream.Read(buffer, 0, buffer.Length);
                    string message = Encoding.UTF8.GetString(buffer);

                    MdbEntry entry = new MdbEntry(entryID, 0, message);
                    category.Add(entry);
                }
            }
            catch { }
            return(false);
        }
예제 #2
0
        public MdbEntry GetEntry(Int32 categoryID, Int32 entryID)
        {
            if (!this._isLoaded)
            {
                return(this.SpeedRead(categoryID, entryID));
            }

            MdbCategory category = this.GetCategory(categoryID);

            if (category == null)
            {
                return(null);
            }

            return(category.GetEntry(entryID));
        }
예제 #3
0
        protected bool MmdbRead(FileStream stream)
        {
            // Go to start position
            stream.Seek(8, SeekOrigin.Begin);
            try
            {
                // Read categories
                Int32 currentLocation       = 8;
                bool  notFinishedCategories = true;
                while (notFinishedCategories)
                {
                    Int32 categoryID = 0;
                    Int32 offset     = 0;

                    if (!this.MmdbReadKey(stream, ref categoryID, ref offset))
                    {
                        throw new Exception();
                    }

                    currentLocation += 8;

                    if (categoryID == -1)
                    {
                        this._endOfCategories = currentLocation;
                        this._endOfEntries    = offset;
                        notFinishedCategories = false;
                    }
                    else
                    {
                        MdbCategory category = new MdbCategory(categoryID, offset);
                        this._categories.Add(category);
                    }
                }

                // Read Entries
                bool notFinishedEntries = true;
                while (notFinishedEntries)
                {
                    stream.Seek(currentLocation, SeekOrigin.Begin);

                    Int32  entryID = 0;
                    Int32  offset  = 0;
                    string message = String.Empty;

                    if (!this.MmdbReadKey(stream, ref entryID, ref offset))
                    {
                        throw new Exception();
                    }

                    if (!this.MmdbReadString(stream, offset, ref message))
                    {
                        throw new Exception();
                    }

                    MdbEntry entry = new MdbEntry(entryID, offset, message);

                    MdbCategory category = null;
                    foreach (MdbCategory cat in this._categories)
                    {
                        if (cat.Offset > currentLocation)
                        {
                            break;
                        }
                        category = cat;
                    }
                    if (category != null)
                    {
                        category.Add(entry);
                    }

                    currentLocation += 8;
                    if (currentLocation >= this._endOfEntries)
                    {
                        break;
                    }
                }
            }
            catch
            {
                Console.WriteLine("ERROR: Error during reading " + this._file);
                return(false);
            }
            if (stream != null)
            {
                stream.Close();
            }

            this._isLoaded = true;
            return(true);
        }