Example #1
0
 private static void LoadD2I()
 {
     using (_br = new BinaryReader(File.Open(_pather, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
     {
         //Get the total size
         _myD2I.SizeOfD2I = _br.BaseStream.Length;
         //Get the data size
         _myD2I.SizeOfData = ReadInt();
         //Load the data
         while (_br.BaseStream.Position < _myD2I.SizeOfData)
         {
             //Store the current data
             var temp = new DataD2I
             {
                 StrIndex = _br.BaseStream.Position,
                 StrSize  = ReadShort()
             };
             temp.Str = ReadUtf8(temp.StrSize);
             //Add the data to the list
             _myD2I.DataList.Add(temp);
         }
         //Get indexes size
         _myD2I.SizeOfIndex = ReadInt();
         //Load indexes
         while (_br.BaseStream.Position - _myD2I.SizeOfData < _myD2I.SizeOfIndex)
         {
             //Store the current read index
             var temp = new Index
             {
                 IStrKey   = ReadInt(),
                 IDiaExist = ReadBool(),
                 IStrIndex = ReadInt()
             };
             //Check if Dia exists
             if (temp.IDiaExist)
             {
                 temp.IDiaIndex = ReadInt();
             }
             //Add it to the list
             _myD2I.IndexList.Add(temp);
         }
         _br.Dispose();
         GC.Collect();
     }
 }
Example #2
0
        public string GetUi(string mySearch)
        {
            var uiResult = "No Result";

            using (_br = new BinaryReader(File.Open(_pather, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                _br.BaseStream.Position = 0;
                _myD2I.SizeOfD2I        = _br.BaseStream.Length;
                _myD2I.SizeOfData       = ReadInt();
                _br.BaseStream.Position = _myD2I.SizeOfData;
                _myD2I.SizeOfIndex      = ReadInt();
                _br.BaseStream.Position = _br.BaseStream.Position + _myD2I.SizeOfIndex;
                _myD2I.SizeOfUi         = ReadInt();
                try
                {
                    while (_br.BaseStream.Position < _br.BaseStream.Length)
                    {
                        var myUi = new UI {
                            UStrIndex = ReadShort()
                        };
                        myUi.UStr     = ReadUtf8(myUi.UStrIndex);
                        myUi.UPointer = ReadInt();
                        if (string.Compare(mySearch, myUi.UStr, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }
                        _br.BaseStream.Position = myUi.UPointer;
                        var myResult = new DataD2I
                        {
                            StrIndex = myUi.UPointer,
                            StrSize  = ReadShort()
                        };
                        myResult.Str = ReadUtf8(myResult.StrSize);
                        uiResult     = myResult.Str;
                        break; // TODO: might not be correct. Was : Exit While
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            return(uiResult);
        }
Example #3
0
        /// <summary>
        ///     Fetch the text associated with the ID
        /// </summary>
        /// <param name="toSearch">ID of the text to get</param>
        /// <param name="versionDiacritique">Choose if you prefer the diacritical value or not, by default it's set to True.</param>
        /// <remarks></remarks>
        public string GetText <T>(T toSearch, bool versionDiacritique = false)
        {
            var myId   = default(uint);
            var result = new DataD2I {
                Str = ""
            };

            if (typeof(T) == typeof(string))
            {
                myId = Convert.ToUInt32(toSearch);
            }
            else if (IsNumeric(toSearch.ToString()))
            {
                var convert = uint.TryParse(toSearch.ToString(), out myId);
            }
            if (_isFastLoad == false)
            {
                try
                {
                    if (versionDiacritique)
                    {
                        uint pointer;
                        try
                        {
                            pointer = _myD2I.IndexList.First(n => (n.IStrKey == myId) & n.IDiaExist).IDiaIndex;
                        }
                        catch (Exception)
                        {
                            pointer = _myD2I.IndexList.First(n => n.IStrKey == myId).IStrIndex;
                        }

                        result.Str = _myD2I.DataList.First(m => m.StrIndex == pointer).Str;
                    }
                    else
                    {
                        var pointer = _myD2I.IndexList.First(n => n.IStrKey == myId).IStrIndex;
                        result.Str = _myD2I.DataList.First(m => m.StrIndex == pointer).Str;
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            else
            {
                using (_br = new BinaryReader(File.Open(_pather, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    _myD2I.SizeOfD2I        = _br.BaseStream.Length;
                    _myD2I.SizeOfData       = ReadInt();
                    _br.BaseStream.Position = _myD2I.SizeOfData;
                    _myD2I.SizeOfIndex      = ReadInt();
                    try
                    {
                        while (_br.BaseStream.Position - _myD2I.SizeOfData < _myD2I.SizeOfIndex)
                        {
                            var temp  = new Index();
                            var temp2 = ReadInt();
                            if (temp2 == myId)
                            {
                                temp.IStrKey   = temp2;
                                temp.IDiaExist = ReadBool();
                                temp.IStrIndex = ReadInt();
                                if (temp.IDiaExist)
                                {
                                    temp.IDiaIndex = ReadInt();
                                }
                                var pointer = versionDiacritique ? temp.IDiaIndex : temp.IStrIndex;
                                _br.BaseStream.Position = pointer;
                                result.StrIndex         = pointer;
                                result.StrSize          = ReadShort();
                                result.Str = ReadUtf8(result.StrSize);
                                break; // TODO: might not be correct. Was : Exit While
                            }
                            temp.IDiaExist = ReadBool();
                            temp.IStrIndex = ReadInt();
                            if (temp.IDiaExist)
                            {
                                temp.IDiaIndex = ReadInt();
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }
            //Return the result
            return(result.Str);
        }