Example #1
0
        internal void Init()
        {
            if (_init)
            {
                return;
            }
            _lock.EnterWriteLock();
            if (_init)
            {
                _lock.ExitWriteLock();
                return;
            }

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

            var path = Path;

            if (File.Exists(path))
            {
                var json = File.ReadAllText(path);
                var map  = (Dictionary <string, object>)Json.Deserialize(json);
                _map = map["map"] as Dictionary <string, object>;
                if (map.ContainsKey("meta"))
                {
                    var meta = map["meta"] as Dictionary <string, object>;
                    if (meta == null)
                    {
                        Debug.LogWarning($"Could not read meta info: {map["meta"]}");
                    }
                    else
                    {
                        foreach (var kv in meta)
                        {
                            var pmeta = PrefMetadata.FromDict(kv.Value as Dictionary <string, object>);
                            if (pmeta.HasValue)
                            {
                                _meta[kv.Key] = pmeta.Value;
                            }
                        }
                    }
                }
            }

            _init = true;
            _lock.ExitWriteLock();

            ResetButton.OnGlobalReset += (sender, args) => ClearAll();
        }
        private PrefMetadata UpdateMeta(string key)
        {
            if (_meta == null)
            {
                throw new Exception("Metadata is turned off. How did you even get here.");
            }

            _lock.EnterWriteLock();
            PrefMetadata meta;

            _meta.TryGetValue(key, out meta);
            meta = new PrefMetadata
            {
                Expiration = null,
                LastUpdate = DateTime.Now
            };
            _meta[key] = meta;
            _lock.ExitWriteLock();
            return(meta);
        }
 public PrefInsertion(Prefs parent, string key, PrefMetadata metadata)
 {
     Parent   = parent;
     Key      = key;
     Metadata = metadata;
 }
 public PrefInsertion(Prefs parent, string key)
 {
     Parent   = parent;
     Key      = key;
     Metadata = default(PrefMetadata);
 }