Esempio n. 1
0
        public bool Read(ref T t, SaveSetting saveSetting)
        {
            FileInfo fileInfo;

            fileInfo = new FileInfo(string.Format("{0}/{1}.json", saveSetting.DataPath, saveSetting.DataName));

            if (!fileInfo.Exists)
            {
                return(false);
            }

            using (FileStream stream = fileInfo.OpenRead())
            {
                try
                {
                    if (stream.Length <= 0)
                    {
                        stream.Close();
                        return(false);
                    }

                    byte[] byteData = new byte[stream.Length];

                    stream.Read(byteData, 0, byteData.Length);

                    string context = UTF8Encoding.UTF8.GetString(byteData);

                    stream.Close();

                    if (string.IsNullOrEmpty(context))
                    {
                        return(false);
                    }


                    switch (saveSetting.EncryptType)
                    {
                    case EncryptType.None:
                        break;

                    case EncryptType.AES:
                        context = EncryptUtil.UnAesStr(context, "nfsqyddbhhszd", "bpnmawsdssh");
                        break;
                    }

                    t = JsonConvert.DeserializeObject <T>(context);
                    Log.I(string.Format("{0}:{1}", t.GetType().Name, "Load Success"));
                }
                catch (Exception e)
                {
                    Log.I(string.Format("{0}:{1}", t.GetType().Name, e));
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
 public void WriteAsyn(Object t, SaveSetting saveSetting)
 {
 }
Esempio n. 3
0
 public void Write(Object t, SaveSetting saveSetting)
 {
     Write(t, saveSetting.DataPath);
 }
Esempio n. 4
0
 public bool ReadAsyn(ref T t, SaveSetting saveSetting)
 {
     return(true);
 }
Esempio n. 5
0
        public void Write(T t, SaveSetting saveSetting)
        {
            string jsonValue = null;

            try
            {
                jsonValue = JsonConvert.SerializeObject(t);
                switch (saveSetting.EncryptType)
                {
                case EncryptType.None:
                    break;

                case EncryptType.AES:
                    jsonValue = EncryptUtil.AesStr(jsonValue, SaveSetting.m_AESKeyValue, SaveSetting.m_AESIvValue);
                    break;
                }
            }
            catch (Exception e)
            {
                Log.I(string.Format("{0}{1}:{2}", t.GetType().Name, "写入失败", e));
                return;
            }

            FileInfo fileInfo;

            fileInfo = new FileInfo(string.Format("{0}/{1}.json", saveSetting.DataPath, saveSetting.DataName));

            if (!Directory.Exists(saveSetting.DataPath))
            {
                Directory.CreateDirectory(saveSetting.DataPath);
            }
            if (!fileInfo.Exists)
            {
                fileInfo.Create().Dispose();
            }
            using (FileStream fs = fileInfo.OpenWrite())
            {
                fs.SetLength(0);
                byte[] writeDataArray = UTF8Encoding.UTF8.GetBytes(jsonValue);
                fs.Write(writeDataArray, 0, writeDataArray.Length);
                fs.Flush();
                Log.I(string.Format("{0}:{1}", t.GetType().Name, "Write Success"));
            }

#if UNITY_EDITOR
            #region //保险起见,persistentDataPath路径也做存储
            FileInfo fileInfo1;
            fileInfo1 = new FileInfo(string.Format("{0}/{1}.json", Application.persistentDataPath, saveSetting.DataName));

            if (!fileInfo1.Exists)
            {
                fileInfo1.Delete();
            }
            else
            {
                fileInfo1.Create().Dispose();
            }
            using (FileStream fs = fileInfo1.OpenWrite())
            {
                byte[] writeDataArray = UTF8Encoding.UTF8.GetBytes(jsonValue);
                fs.Write(writeDataArray, 0, writeDataArray.Length);
                fs.Flush();
            }
            #endregion
#endif
        }
Esempio n. 6
0
 public void WriteAsyn(T t, SaveSetting saveSetting)
 {
 }
Esempio n. 7
0
        // public void SetSaveSetting(SaveSetting saveSetting)
        // {
        //     m_SaveSetting = saveSetting;

        //     return;
        //     int index;
        //     SaveSetting temp = DataSavePathConfig.S.GetSaveSettingPath(m_SaveSetting.DataName, out index);
        //     if (temp != null)
        //     {
        //         DataSavePathConfig.S.saveSettingList[index] = m_SaveSetting;
        //         Log.I(Data.GetType().Name + ":数据覆盖");
        //     }
        //     else
        //         DataSavePathConfig.S.saveSettingList.Add(m_SaveSetting);
        // }

        public void SetSaveSetting(string name, string path = "", EncryptType encryptType = EncryptType.AES)
        {
            m_SaveSetting = new SaveSetting(name, path, encryptType);
        }