示例#1
0
        public bool Save(string key)
        {
            if (!ExistsKey(key))
            {
                return(false);
            }

            string filePath = $"{ fullPath }/{ key }.{ extension }";

            string json = JsonUtility.ToJson(bank[key]);

            byte[] data = Encoding.UTF8.GetBytes(json);
            data = Compressor.Compress(data);
            data = Cryptor.Encrypt(data);

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            using (FileStream fileStream = File.Create(filePath))
            {
                fileStream.Write(data, 0, data.Length);
            }

            return(true);
        }
示例#2
0
        public bool Load <DataType>(string key)
        {
            string filePath = $"{ fullPath }/{ key }.{ extension }";

            if (!File.Exists(filePath))
            {
                return(false);
            }

            byte[] data = null;
            using (FileStream fileStream = File.OpenRead(filePath))
            {
                data = new byte[fileStream.Length];
                fileStream.Read(data, 0, data.Length);
            }

            data = Cryptor.Decrypt(data);
            data = Compressor.Decompress(data);

            string json = Encoding.UTF8.GetString(data);

            bank[key] = JsonUtility.FromJson <DataType>(json);

            return(true);
        }