Exemplo n.º 1
0
        private static VocalIndexObject SerializeFrom(string FilePath)
        {
            VocalIndexObject ret = null;

            try
            {
                FileStream msObj = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                ICSharpCode.SharpZipLib.BZip2.BZip2InputStream biz = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(msObj);
                string toDes = "";
                using (StreamReader sr = new StreamReader(biz))
                {
                    try
                    {
                        toDes = sr.ReadToEnd();
                    }
                    catch {; }
                }
                using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(toDes)))
                {
                    try
                    {
                        DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(typeof(VocalIndexObject));
                        VocalIndexObject           model       = (VocalIndexObject)(deseralizer.ReadObject(ms));
                        if (model != null)
                        {
                            ret = model;
                        }
                    }
                    catch {; }
                }
                msObj.Close();
            }
            catch {; }
            return(ret);
        }
Exemplo n.º 2
0
        public static VocalIndexObject Deseralize(string Folder)
        {
            VocalIndexObject ret = null;

            if (System.IO.File.Exists(Folder + "\\voicedbi.dat"))
            {
                ret = SerializeFrom(Folder + "\\voicedbi.dat");
                if (ret != null)
                {
                    string NewHash = CalcHash(ret.HashFiles, Folder);
                    if (NewHash != ret.HashValue)
                    {
                        ret = null;
                    }
                }
            }
            if (ret == null)
            {
                ret = new VocalIndexObject();
                ret.BasicData.IntroduceText = "Chorista Voice Index Cache File";
                ret.HashFiles.Add("character.txt");
                ret.CharacertData = CharacterSerializer.DeSerialize(Folder + "\\character.txt");
                ret.SndAtomList   = OtoSerializer.DeSerialize(Folder, ret.HashFiles);
                ret.HashFiles.Add("prefix.map");
                if (System.IO.File.Exists(Folder + "\\prefix.map"))
                {
                    ret.PrefixAtomList = PrefixMapSerialzier.DeSerialize(Folder + "\\prefix.map");
                }
                SplitDictionary sdlib = null;
                if (System.IO.File.Exists(Folder + "\\splitdic.json"))
                {
                    sdlib = SplitDictionary.SerializeFrom(Folder + "\\splitdic.json");
                    if (ret != null)
                    {
                        ret.HashFiles.Add("splitdic.json");
                    }
                }
                if (sdlib == null && System.IO.File.Exists(Folder + "\\presamp.ini"))
                {
                    sdlib = Presamp2DictSerializer.DeSerialize(Folder + "\\presamp.ini");
                    if (sdlib != null)
                    {
                        ret.HashFiles.Add("presamp.ini");
                    }
                }
                if (sdlib != null)
                {
                    ret.SplitDictionary = sdlib;
                }
                else
                {
                    ret.SplitDictionary = new SplitDictionary();
                }
                ret.SplitDictionary.MapSndList(ret.SndAtomList, ret.PrefixAtomList);
                ret.HashValue = CalcHash(ret.HashFiles, Folder);
                SerializeTo(ret, Folder + "\\voicedbi.dat");
            }
            return(ret);
        }
Exemplo n.º 3
0
        private static void SerializeTo(VocalIndexObject Object, string FilePath)
        {
            FileStream msObj = new FileStream(FilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream boz = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(msObj);
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(VocalIndexObject));

            js.WriteObject(boz, Object);
            boz.Flush();
            boz.Close();
            msObj.Close();
        }