Exemple #1
0
        public override bool LoadRes()
        {
            if (ResourceLocation != null)
            {
                StringTable data = new StringTableCsfFormat().Load(ResourceLocation);

                List <Entry> list = new List <Entry>(data.Count);

                foreach (KeyValuePair <string, KeyValuePair <string, string> > entry in data)
                {
                    Entry ent = new Entry(this);
                    ent.name  = entry.Key;
                    ent.text  = entry.Value.Value;
                    ent.extra = entry.Value.Key;
                    ent.cate  = GetCategory(ent.name);

                    list.Add(ent);
                }
                list.Sort(this.Comparsion);
                list.Add(new Entry(this));

                fileData = new List <Category>();

                if (list.Count > 0)
                {
                    Category currentCate = new Category();
                    currentCate.data = new List <Entry>();
                    currentCate.name = list[0].cate;

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].cate != currentCate.name)
                        {
                            fileData.Add(currentCate);

                            currentCate      = new Category();
                            currentCate.name = list[i].cate;
                            currentCate.data = new List <Entry>();
                        }

                        list[i].parent = currentCate;
                        currentCate.data.Add(list[i]);
                    }
                }
                ListCategory();

                fileData.Sort(new CategoryComparer());
                Saved = true;
                return(true);
            }
            fileData = new List <Category>();
            Saved    = true;
            return(true);
        }
Exemple #2
0
        public override bool SaveRes()
        {
            if (ResourceLocation.IsReadOnly)
            {
                throw new InvalidOperationException();
            }

            Dictionary <string, KeyValuePair <string, string> > data = new Dictionary <string, KeyValuePair <string, string> >();

            //List<KeyValuePair<string, KeyValuePair<string, string>>> sounds =
            //    new List<KeyValuePair<string, KeyValuePair<string, string>>>();

            for (int i = 0; i < fileData.Count; i++)
            {
                for (int j = 0; j < fileData[i].data.Count; j++)
                {
                    data.Add(fileData[i].data[j].name,
                             new KeyValuePair <string, string>(fileData[i].data[j].extra, fileData[i].data[j].text));
                }
            }
            //for (int i = 0; i < fileData.Count; i++)
            //    for (int j = 0; j < fileData[i].sounds.Count; j++)
            //        sounds.Add(
            //            new KeyValuePair<string, KeyValuePair<string, string>>(
            //                fileData[i].sounds[j].name,
            //                new KeyValuePair<string, string>(fileData[i].sounds[j].extra, fileData[i].sounds[j].text)));


            //FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
            Stream stm = ResourceLocation.GetStream;

            try
            {
                stm.SetLength(0);
            }
            catch (NotSupportedException)
            {
            }

            StringTableCsfFormat fmt = new StringTableCsfFormat();

            fmt.Write(data, stm);

            //BinaryWriter bw = new BinaryWriter(stm);

            //bw.Write((int)FileID.Csf);
            //bw.Write((int)3);
            //bw.Write(sounds.Count);
            //bw.Write(sounds.Count);
            //bw.Write((int)0);
            //bw.Write((int)0);

            //for (int i = 0; i < sounds.Count; i++)
            //{
            //    string key = sounds[i].Key;
            //    string text = sounds[i].Value.Value;
            //    string ext = sounds[i].Value.Key;

            //    bw.Write((int)CsfHeader.LabelID);

            //    if (text != string.Empty | ext != string.Empty)
            //    {
            //        bw.Write((int)1);

            //        bw.Write(key.Length);
            //        bw.Write(key.ToCharArray());

            //        bool hasExtra = !string.IsNullOrEmpty(ext);

            //        if (hasExtra)
            //            bw.Write((int)CsfHeader.WStringID);
            //        else
            //            bw.Write((int)CsfHeader.StringID);

            //        bw.Write(text.Length);

            //        for (int j = 0; j < text.Length; j++)
            //        {
            //            ushort v = (ushort)text[j];

            //            bw.Write((byte)~(v & 255));
            //            bw.Write((byte)~(v >> 8));
            //        }

            //        if (hasExtra)
            //        {
            //            bw.Write(ext.Length);
            //            bw.Write(ext.ToCharArray());
            //        }
            //    }
            //    else
            //    {
            //        bw.Write((int)0);
            //        bw.Write(key.Length);
            //        bw.Write(key.ToCharArray());
            //    }

            //}

            //bw.Close();

            data.Clear();

            Saved = true;
            return(true);
            //throw new NotImplementedException();
        }