Esempio n. 1
0
    static public object LoadFile(string fileName, Type type)
    {
        object t = null;

        try
        {
            if (File.Exists(Util.m_persistPath + "/" + fileName))
            {
                Stream s     = new FileStream(Util.m_persistPath + "/" + fileName, FileMode.OpenOrCreate);
                byte[] datas = new byte[s.Length];
                s.Read(datas, 0, datas.Length);
                int offset, length;
                if (HeadUtil.IsContains(datas, out offset, out length))
                {
                    var st = new MemoryStream(datas, offset, length);
                    t = ProtoBuf.Serializer.Deserialize(st, type);
                    st.Close();
                }
                s.Close();
            }
        }
        catch (Exception ex)
        {
            Debug.Log("SaveFile:" + ex);
        }
        return(t);
    }
Esempio n. 2
0
 static public void SaveFile(string fileName, object intance)
 {
     try
     {
         if (intance == null)
         {
             return;
         }
         Stream       s  = new FileStream(Util.m_persistPath + "/" + fileName, FileMode.Create);
         MemoryStream ms = new MemoryStream();
         ProtoBuf.Serializer.Serialize(ms, intance);
         HeadUtil.WriteStream(ms, s);
         s.Close();
         ms.Close();
     }
     catch (Exception ex)
     {
         Debug.Log("SaveFile:" + ex);
     }
 }