示例#1
0
        public void OpenStorage(string arg, bool online)
        {
            Cleanup();

            using (var initForm = new InitForm())
            {
                if (online)
                {
                    initForm.LoadOnlineStorage(arg);
                }
                else
                {
                    initForm.LoadLocalStorage(arg);
                }

                DialogResult res = initForm.ShowDialog();

                if (res != DialogResult.OK)
                {
                    return;
                }

                _casc = initForm.CASC;
                _root = initForm.Root;
            }

            Sorter.CASC = _casc;

            OnStorageChanged?.Invoke();
        }
        public void SetString(string key, string value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Key is null or empty");
            }

            using (var db = GetDb())
            {
                var collection = db.GetCollection <KeyValue>();
                var kv         = collection.Find(x => x.Key == key).FirstOrDefault();
                if (kv == null)
                {
                    collection.Insert(new KeyValue {
                        Key = key, Value = value
                    });
                }
                else
                {
                    kv.Value = value;
                    collection.Update(kv);
                }
            }

            OnStorageChanged?.Invoke(this, new StorageChangedEventArgs {
                Key = key, Value = value
            });
        }
        public void DeleteKeys(IEnumerable <string> keys)
        {
            using (var db = GetDb())
            {
                var collection = db.GetCollection <KeyValue>();
                collection.Delete(x => keys.Contains(x.Key));
            }

            foreach (var key in keys)
            {
                OnStorageChanged?.Invoke(this, new StorageChangedEventArgs {
                    Key = key, Value = null
                });
            }
        }
示例#4
0
        public void ChangeLocale(string locale)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            Settings.Default.LocaleFlags = (LocaleFlags)Enum.Parse(typeof(LocaleFlags), locale);

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
示例#5
0
        public void SetOverrideArchive(bool set)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            Settings.Default.OverrideArchive = set;

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.OverrideArchive);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
        public void SetStrings(List <string> keys, List <string> values)
        {
            if (keys.Count != values.Count)
            {
                throw new ArgumentException($"{nameof(keys)}.Count != {nameof(values)}.Count");
            }

            using (var db = GetDb())
            {
                var collection        = db.GetCollection <KeyValue>();
                var existingKeyValues = collection.Find(x => keys.Contains(x.Key)).ToDictionary(x => x.Key, x => x);
                var toInsert          = new List <KeyValue>();
                var toUpdate          = new List <KeyValue>();
                foreach (var(key, value) in keys.Zip(values, (k, v) => (k, v)))
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        throw new ArgumentException("Key is null or empty");
                    }

                    if (existingKeyValues.ContainsKey(key))
                    {
                        var kv = existingKeyValues[key];
                        kv.Value = value;
                        toUpdate.Add(kv);
                    }
                    else
                    {
                        toInsert.Add(new KeyValue {
                            Key = key, Value = value
                        });
                    }

                    OnStorageChanged?.Invoke(this, new StorageChangedEventArgs {
                        Key = key, Value = value
                    });
                }

                collection.InsertBulk(toInsert);
                collection.Update(toUpdate);
            }
        }
示例#7
0
        public void ChangeContentFlags(bool set)
        {
            if (_casc == null)
            {
                return;
            }

            OnCleanup?.Invoke();

            if (set)
            {
                Settings.Default.ContentFlags |= ContentFlags.LowViolence;
            }
            else
            {
                Settings.Default.ContentFlags &= ~ContentFlags.LowViolence;
            }

            _root = _casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
            _casc.Root.MergeInstall(_casc.Install);

            OnStorageChanged?.Invoke();
        }
示例#8
0
        public void OpenStorage(bool online, string path, string product)
        {
            Cleanup();

            using (var initForm = new InitForm())
            {
                initForm.LoadStorage((online, path, product));

                DialogResult res = initForm.ShowDialog();

                if (res != DialogResult.OK)
                {
                    return;
                }

                _casc = initForm.CASC;
                _root = initForm.Root;
            }

            Sorter.CASC = _casc;

            OnStorageChanged?.Invoke();
        }