Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Security.Cryptography;
- using System.IO;
- using System.Collections.Generic;
- namespace NovelScript
- {
- public class SettingManager : VariableManager
- {
- public new static readonly SettingManager Instance = new SettingManager();
- protected string saveFilePath = string.Format("{0}/settingsData.Ubinary", Application.persistentDataPath);
- private BinaryFormatter formatter = new BinaryFormatter();
- private DESCryptoServiceProvider DesSerivice = new DESCryptoServiceProvider();
- /*public new string Set(string key, string value)
- { //TODO : fileWrite
- return base.Set(key, value);
- }*/
- public bool Save()
- {
- using (FileStream file = File.Create(saveFilePath))
- using (Stream cryptoStream = new CryptoStream(file, DesSerivice.CreateEncryptor(), CryptoStreamMode.Write))
- {
- formatter.Serialize(cryptoStream, base.__storage);
- return true;
- }
- return false;
- //base.__storage = loadedData;
- }
- public bool Load()
- {
- if (File.Exists(saveFilePath))
- {
- using (Stream innerStream = File.Open(saveFilePath, FileMode.Open))
- // 2. create a CryptoStream in read mode
- using (Stream cryptoStream = new CryptoStream(innerStream, DesSerivice.CreateDecryptor(), CryptoStreamMode.Read))
- {
- // 3. read from the cryptoStream
- base.__storage = (Dictionary<string, Variable>)formatter.Deserialize(cryptoStream);
- return true;
- }
- }
- return false;
- }
- public new string Set(string key,string value)
- {
- this.Save();
- return base.Set(key, value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement