Exemple #1
0
 private static void LoadD2I()
 {
     using (_br = new BinaryReader(File.Open(_pather, FileMode.Open, FileAccess.Read)))
     {
         //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();
     }
 }
Exemple #2
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 ex)
                    {
                        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 ex)
            {
            }
        }
        else
        {
            using (_br = new BinaryReader(File.Open(_pather, FileMode.Open, FileAccess.Read)))
            {
                _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 ex)
                {
                    // ignored
                }
            }
        }
        //Return the result
        return(result.Str);
    }