Пример #1
0
        //export translated for game
        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();

            if (s.ShowDialog() == DialogResult.OK)
            {
                FileStream           f    = File.Open(s.FileName, FileMode.OpenOrCreate, FileAccess.Write);
                TranslateableREader  r    = new TranslateableREader();
                List <Translateable> data = new List <Translateable>();

                //generate translateables from datagrid
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    Translateable newT = new Translateable();
                    newT.targetString = Convert.ToString(item.Cells[2].Value);
                    newT.sort         = Convert.ToInt32(item.Cells[0].Value.ToString());
                    newT.baseString   = Convert.ToString(item.Cells[1].Value);
                    data.Add(newT);
                }

                //convert translateables to bytes which can be write to file directly
                List <byte> buffer = r.translateableToByte(data);

                foreach (byte x in buffer)
                {
                    f.WriteByte(x);
                }

                f.Close();
            }
        }
Пример #2
0
        public List <Translateable> read(byte[] content)
        {
            int labelOffset = 0;
            int labelCount  = content.Length / blockSize;

            //every string has 4096 byte space so i can pre calculate count of total string
            //and iterate it
            List <Translateable> strings = new List <Translateable>();

            for (int i = 0; i < labelCount; i++)
            {
                //i should find the place of string in block so i check until i hit
                //something different than 0x00
                int limit = blockSize * (i + 1);
                labelOffset = blockSize * i;

                while (content[labelOffset] == 0x00)
                {
                    labelOffset++;
                }
                //if i reach to end or exceed it that means there is no string in block
                //but the order is import so i will add a empty row
                if (labelOffset >= limit)
                {
                    strings.Add(new Translateable());
                    continue;
                }

                //once i found the string i can extract the string for translate


                int sort = content[labelOffset + 1] << 8 | content[labelOffset];
                labelOffset += 2;
                Translateable translateable = new Translateable();
                List <byte>   s             = new List <byte>();
                while (content[labelOffset] != 0x00)
                {
                    s.Add(content[labelOffset]);
                    labelOffset++;
                }
                translateable.baseString   = Encoding.Default.GetString(s.ToArray());
                translateable.targetString = translateable.baseString;
                translateable.sort         = sort;
                strings.Add(translateable);
            }

            return(strings);
        }