Exemplo n.º 1
0
        public StringList(string language)
        {
            m_Language = language;
            m_Table    = new Hashtable();
            m_EntTable = new Hashtable();

            string path = Client.GetFilePath(String.Format("cliloc.{0}", language));

            if (path == null || !File.Exists(path))
            {
                Console.WriteLine("Error! Unable to open {0}!", path);
                m_Entries = new StringEntry[0];
                return;
            }

            ArrayList list = new ArrayList();

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.UTF8))
            {
                bin.ReadInt32();
                bin.ReadInt16();

                try
                {
                    while (true)
                    {
                        int number = bin.ReadInt32();
                        bin.ReadByte();
                        int length = bin.ReadInt16();

                        if (length > m_Buffer.Length)
                        {
                            m_Buffer = new byte[(length + 1023) & ~1023];
                        }

                        bin.Read(m_Buffer, 0, length);

                        try
                        {
                            StringEntry ent;
                            string      text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                            ent = new StringEntry(number, text);
                            list.Add(ent);
                            m_EntTable[number] = ent;
                            m_Table[number]    = text;
                        }
                        catch
                        {
                        }
                    }
                }
                catch (System.IO.EndOfStreamException)
                {
                    // end of file.  stupid C#.
                }
            }

            m_Entries = (StringEntry[])list.ToArray(typeof(StringEntry));
        }
Exemplo n.º 2
0
        public StringList( string language )
        {
            m_Language = language;
            m_Table = new Hashtable();
            m_EntTable = new Hashtable();

            string path = Client.GetFilePath( String.Format( "cliloc.{0}", language ) );

            if ( path == null || !File.Exists( path ) )
            {
                Console.WriteLine("Error! Unable to open {0}!", path);
                m_Entries = new StringEntry[0];
                return;
            }

            ArrayList list = new ArrayList();

            using ( BinaryReader bin = new BinaryReader( new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ), Encoding.UTF8 ) )
            {
                bin.ReadInt32();
                bin.ReadInt16();

                try
                {
                    while ( true )
                    {
                        int number = bin.ReadInt32();
                        bin.ReadByte();
                        int length = bin.ReadInt16();

                        if ( length > m_Buffer.Length )
                            m_Buffer = new byte[(length + 1023) & ~1023];

                        bin.Read( m_Buffer, 0, length );

                        try
                        {
                            StringEntry ent;
                            string text = Encoding.UTF8.GetString( m_Buffer, 0, length );

                            ent = new StringEntry(number, text);
                            list.Add( ent );
                            m_EntTable[number] = ent;
                            m_Table[number] = text;
                        }
                        catch
                        {
                        }
                    }
                }
                catch ( System.IO.EndOfStreamException )
                {
                    // end of file.  stupid C#.
                }
            }

            m_Entries = (StringEntry[])list.ToArray( typeof( StringEntry ) );
        }
Exemplo n.º 3
0
        public string GetText(int number)
        {
            StringEntry entry = GetEntry(number);

            string text = null;

            if (entry != null)
            {
                text = entry.Text;
            }

            return(text);
        }
Exemplo n.º 4
0
        public string SplitFormat(int num, string argstr)
        {
            StringEntry ent = m_EntTable[num] as StringEntry;

            if (ent != null)
            {
                return(ent.SplitFormat(argstr));
            }
            else
            {
                return(String.Format("CliLoc string {0}/{1} not found!", num, m_EntTable.Count));
            }
        }
Exemplo n.º 5
0
        public string Format(int num, params object[] args)
        {
            StringEntry ent = m_EntTable[num] as StringEntry;

            if (ent != null)
            {
                return(ent.Format(args));
            }
            else
            {
                return(String.Format("CliLoc string {0}/{1} not found!", num, m_EntTable.Count));
            }
        }
Exemplo n.º 6
0
        internal static string ParseSubCliloc(string arg)
        {
            if (arg == null)
            {
                return(null);
            }

            string result = "";

            List <string> elements = arg.Split('\t').ToList <string>();

            foreach (string element in elements)
            {
                if (element.Length > 1 && element[0] == '#')
                {
                    int value = Int32.MinValue;
                    Int32.TryParse(element.Substring(1, element.Length - 1), out value);
                    if (value != Int32.MinValue)
                    {
                        Ultima.StringEntry se = m_CliLoc.GetEntry(value);
                        if (se != null && se.Text != null)
                        {
                            result += se.Text + '\t';
                        }
                        else
                        {
                            result += element + '\t';
                        }
                    }
                    else
                    {
                        result += element + '\t';
                    }
                }
                else
                {
                    result += element + '\t';
                }
            }

            return(result[result.Length - 1] == '\t' ? result.Substring(0, result.Length - 1) : result);
        }
Exemplo n.º 7
0
        private void LoadEntry(string path)
        {
            if (path == null)
            {
                Entries = new List <StringEntry>(0);
                return;
            }

            Entries       = new List <StringEntry>();
            m_StringTable = new Dictionary <int, string>();
            m_EntryTable  = new Dictionary <int, StringEntry>();

            using (BinaryReader bin =
                       new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                m_Header1 = bin.ReadInt32();
                m_Header2 = bin.ReadInt16();

                while (bin.BaseStream.Length != bin.BaseStream.Position)
                {
                    int  number = bin.ReadInt32();
                    byte flag   = bin.ReadByte();
                    int  length = bin.ReadInt16();

                    if (length > m_Buffer.Length)
                    {
                        m_Buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(m_Buffer, 0, length);
                    string text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                    StringEntry se = new StringEntry(number, text, flag);
                    Entries.Add(se);

                    m_StringTable[number] = text;
                    m_EntryTable[number]  = se;
                }
            }
        }