Beispiel #1
0
        public static void Save(ElementToStorage newElment, string filePath, string key, bool encrypted)
        {
            Dictionary <string, ElementToStorage> dict = null;

            AssetManager.CreateSubDirectoriesForPath(filePath);
            string JSONstring;

            try
            {
                if (encrypted)
                {
                    JSONstring = Encrypted.Decrypt(filePath, StorageManager.Key);
                }
                else
                {
                    JSONstring = File.ReadAllText(filePath);
                }
                dict = JsonConvert.DeserializeObject <Dictionary <string, ElementToStorage> >(JSONstring);
            }
            catch (Exception)
            {
            }

            if (dict == null)
            {
                dict = new Dictionary <string, ElementToStorage>();
            }

            dict.Update(key, newElment);
            JSONstring = JsonConvert.SerializeObject(dict);

            if (encrypted)
            {
                Encrypted.Encrypt(filePath, StorageManager.Key, JSONstring, out _);
            }
            else
            {
                File.WriteAllText(filePath, JSONstring);
            }
        }
Beispiel #2
0
        public static void Save(string key, object value, string filePath, bool encrypted)
        {
            var newElment = new ElementToStorage(value);

            Save(newElment, filePath, key, encrypted);
        }