public static EnumerableStringSettingsVM Factory(FieldMeta fieldMeta, object?defaultVal)
        {
            Func <JsonElement, TryGet <IBasicSettingsNodeVM> > import = new((elem) =>
            {
                return(TryGet <IBasicSettingsNodeVM> .Succeed(
                           new ListElementWrapperVM <string, StringSettingsVM>(
                               new StringSettingsVM()
                {
                    Value = elem.GetString() ?? string.Empty
                })));
            });

            return(new EnumerableStringSettingsVM(
                       fieldMeta,
                       import,
                       (list) =>
            {
                list.Add(new ListElementWrapperVM <string, StringSettingsVM>(new StringSettingsVM()
                {
                    Value = string.Empty
                })
                {
                    IsSelected = true
                });
            },
                       defaultVal as IEnumerable <string> ?? Enumerable.Empty <string>()));
        }
 public InternalImmutableLoadOrderLinkCache(
     IEnumerable <IModGetter> loadOrder,
     GameCategory gameCategory,
     bool hasAny,
     bool simple,
     LinkCachePreferences?prefs)
 {
     prefs ??= LinkCachePreferences.Default;
     _listedOrder   = loadOrder.ToList();
     _priorityOrder = _listedOrder.Reverse().ToList();
     _formKeyCache  = new ImmutableLoadOrderLinkCacheCategory <FormKey>(
         gameCategory,
         hasAny: hasAny,
         simple: simple,
         listedOrder: _listedOrder,
         m => TryGet <FormKey> .Succeed(m.FormKey),
         f => f.IsNull);
     this._editorIdCache = new ImmutableLoadOrderLinkCacheCategory <string>(
         gameCategory,
         hasAny: hasAny,
         simple: simple,
         listedOrder: _listedOrder,
         m =>
     {
         var edid = m.EditorID;
         return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !));
     },
        public ImmutableModLinkCache(IModGetter sourceMod, LinkCachePreferences?prefs = null)
        {
            _sourceMod = sourceMod;
            var simple   = prefs is LinkCachePreferenceOnlyIdentifiers;
            var category = sourceMod.GameRelease.ToCategory();

            _cache           = new InternalImmutableModLinkCache(sourceMod, prefs);
            _formKeyContexts = new ImmutableModLinkCacheSimpleContextCategory <FormKey>(
                simple: simple,
                linkCache: this,
                category: category,
                contextEnumerable: sourceMod,
                keyGetter: m => TryGet <FormKey> .Succeed(m.FormKey),
                shortCircuit: f => f.IsNull);
            _editorIdContexts = new ImmutableModLinkCacheSimpleContextCategory <string>(
                simple: simple,
                linkCache: this,
                category: category,
                contextEnumerable: sourceMod,
                keyGetter: m =>
            {
                var edid = m.EditorID;
                return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !));
            },
                shortCircuit: e => e.IsNullOrWhitespace());
        }
예제 #4
0
        public IEnumerable <T> ParseParallel(
            MutagenFrame frame,
            RecordType triggeringRecord,
            BinaryMasterParseDelegate <T> transl,
            RecordTypeConverter?recordTypeConverter = null)
        {
            var frames = new List <MutagenFrame>();

            triggeringRecord = recordTypeConverter.ConvertToCustom(triggeringRecord);
            while (!frame.Complete && !frame.Reader.Complete)
            {
                var header = frame.MetaData.Constants.GetNextRecordVariableMeta(frame.Reader);
                if (header.RecordType != triggeringRecord)
                {
                    break;
                }
                if (!IsLoqui)
                {
                    throw new NotImplementedException();
                }
                var totalLen = header.TotalLength;
                var subFrame = new MutagenFrame(frame.ReadAndReframe(checked ((int)totalLen)));
                frames.Add(subFrame);
            }
            var ret = new TryGet <T> [frames.Count];

            Parallel.ForEach(frames, (subFrame, state, count) =>
            {
                if (transl(subFrame, out var subItem, recordTypeConverter))
                {
                    ret[count] = TryGet <T> .Succeed(subItem);
                }
        public static TryGet <object> Instantiate(string name, object[] args)
        {
            TryGet <Type> tGet = TryGetType(name);

            if (tGet.Failed)
            {
                return(tGet.BubbleFailure <object>());
            }
            return(TryGet <object> .Succeed(Activator.CreateInstance(tGet.Value, args)));
        }
예제 #6
0
        public async Task <TryGet <T> > Parse(
            MutagenFrame frame,
            RecordTypeConverter?recordTypeConverter)
        {
            var item = await CREATE(
                reader : frame,
                recordTypeConverter : recordTypeConverter).ConfigureAwait(false);

            return(TryGet <T> .Succeed(item));
        }
예제 #7
0
        public async Task <TryGet <T> > Parse(
            MutagenFrame frame,
            TypedParseParams?parseParams)
        {
            var item = await CREATE(
                reader : frame,
                parseParams : parseParams).ConfigureAwait(false);

            return(TryGet <T> .Succeed(item));
        }
예제 #8
0
        public static IObservable <IChangeSet <LoadOrderListing> > GetLiveLoadOrder(
            FilePath cccFilePath,
            DirectoryPath dataFolderPath,
            out IObservable <ErrorResponse> state,
            bool orderListings = true)
        {
            var raw = ObservableExt.WatchFile(cccFilePath.Path)
                      .StartWith(Unit.Default)
                      .Select(_ =>
            {
                try
                {
                    return(GetResponse <IObservable <IChangeSet <ModKey> > > .Succeed(
                               File.ReadAllLines(cccFilePath.Path)
                               .Select(x => ModKey.FromNameAndExtension(x))
                               .AsObservableChangeSet()));
                }
                catch (Exception ex)
                {
                    return(GetResponse <IObservable <IChangeSet <ModKey> > > .Fail(ex));
                }
            })
                      .Replay(1)
                      .RefCount();

            state = raw
                    .Select(r => (ErrorResponse)r);
            var ret = ObservableListEx.And(
                raw
                .Select(r =>
            {
                return(r.Value ?? Observable.Empty <IChangeSet <ModKey> >());
            })
                .Switch(),
                ObservableExt.WatchFolderContents(dataFolderPath.Path)
                .Transform(x =>
            {
                if (ModKey.TryFromNameAndExtension(Path.GetFileName(x), out var modKey))
                {
                    return(TryGet <ModKey> .Succeed(modKey));
                }
                return(TryGet <ModKey> .Failure);
            })
                .Filter(x => x.Succeeded)
                .Transform(x => x.Value)
                .RemoveKey())
                      .Transform(x => new LoadOrderListing(x, true));

            if (orderListings)
            {
                ret = ret.OrderListings();
            }
            return(ret);
        }
예제 #9
0
        private static TryGet <string> AdditionalParam(
            ObjectGeneration objGen,
            TypeGeneration typeGen)
        {
            var floatType = typeGen as Mutagen.Bethesda.Generation.FloatType;

            if (floatType.IntegerType == null &&
                !floatType.Multiplier.EqualsWithin(1))
            {
                return(TryGet <string> .Succeed($"multiplier: {(float)floatType.Multiplier}f"));
            }
            return(TryGet <string> .Failure);
        }
예제 #10
0
 public TryGet <string> Parse(XElement root, bool doMasks, out object maskObj)
 {
     if (!root.Name.LocalName.Equals(ElementName))
     {
         maskObj = new ArgumentException($"Skipping field Version that did not match proper type. Type: {root.Name.LocalName}, expected: {ElementName}.");
         return(TryGet <string> .Failure);
     }
     maskObj = null;
     if (root.TryGetAttribute(XmlConstants.VALUE_ATTRIBUTE, out XAttribute val))
     {
         return(TryGet <string> .Succeed(val.Value));
     }
     return(TryGet <string> .Succeed(null));
 }
예제 #11
0
 public ImmutableModLinkCache(IModGetter sourceMod, LinkCachePreferences?prefs = null)
 {
     _sourceMod    = sourceMod;
     Category      = sourceMod.GameRelease.ToCategory();
     _simple       = prefs is LinkCachePreferenceOnlyIdentifiers;
     _formKeyCache = new ImmutableModLinkCacheCategory <FormKey>(
         this,
         x => TryGet <FormKey> .Succeed(x.FormKey),
         x => x.IsNull);
     _editorIdCache = new ImmutableModLinkCacheCategory <string>(
         this,
         m =>
     {
         var edid = m.EditorID;
         return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !));
     },
예제 #12
0
 public static void WriteToFile(string path, IModGetter mod)
 {
     WriteToFile(
         path,
         mod.NextFormID,
         mod.EnumerateMajorRecords()
         .SelectWhere(m =>
     {
         var edid = m.EditorID;
         if (edid == null)
         {
             return(TryGet <KeyValuePair <string, FormKey> > .Failure);
         }
         return(TryGet <KeyValuePair <string, FormKey> > .Succeed(
                    new KeyValuePair <string, FormKey>(edid, m.FormKey)));
     }));
 }
예제 #13
0
 public EnumerableFormKeySettingsVM(
     FieldMeta fieldMeta,
     IEnumerable <FormKey> defaultVal)
     : base(
         fieldMeta,
         get: e => TryGet <IBasicSettingsNodeVM> .Succeed(
             new ListElementWrapperVM <FormKey, FormKeySettingsVM>(new FormKeySettingsVM()
 {
     Value = FormKeySettingsVM.Import(e)
 })),
         add: coll => coll.Add(new ListElementWrapperVM <FormKey, FormKeySettingsVM>(new FormKeySettingsVM()
 {
     Value = FormKey.Null
 })
 {
     IsSelected = true
 }))
 {
     _defaultVal = defaultVal.ToArray();
 }
        public static EnumerableNumericSettingsVM Factory <TItem, TWrapper>(FieldMeta fieldMeta, object?defaultVal, TWrapper prototype)
            where TWrapper : BasicSettingsVM <TItem>, new()
        {
            Func <JsonElement, TryGet <IBasicSettingsNodeVM> > import = new((elem) =>
            {
                return(TryGet <IBasicSettingsNodeVM> .Succeed(
                           new ListElementWrapperVM <TItem, TWrapper>(
                               new TWrapper()
                {
                    Value = prototype.Get(elem)
                })));
            });

            return(new EnumerableNumericSettingsVM(
                       fieldMeta,
                       import,
                       (list) =>
            {
                list.Add(new ListElementWrapperVM <TItem, TWrapper>(new TWrapper()
                {
                    Value = prototype.GetDefault()
                })
                {
                    IsSelected = true
                });
            },
                       (list, def) =>
            {
                if (def is IEnumerable <TItem> items)
                {
                    list.SetTo(items.Select(x =>
                    {
                        return new ListElementWrapperVM <TItem, TWrapper>(new TWrapper()
                        {
                            Value = x
                        });
                    }));
                }
            },
                       defaultVal));
        }
        public IObservable <IChangeSet <ModKey, ModKey> > Get()
        {
            if (!_fileSystem.Directory.Exists(DataDirectory.Path))
            {
                return(Observable.Empty <IChangeSet <ModKey, ModKey> >());
            }
            return(ObservableExt
                   .WatchFolderContents(DataDirectory.Path, fileSystem: _fileSystem)
                   .Transform(x =>
            {
                if (ModKey.TryFromNameAndExtension(Path.GetFileName(x), out var modKey))
                {
                    return TryGet <ModKey> .Succeed(modKey);
                }

                return TryGet <ModKey> .Failure;
            })
                   .Filter(x => x.Succeeded)
                   .Transform(x => x.Value)
                   .ChangeKey(x => x)
                   .Catch <IChangeSet <ModKey, ModKey>, DirectoryNotFoundException>(_ => Observable.Empty <IChangeSet <ModKey, ModKey> >()));
        }
예제 #16
0
 public BooleanBinaryTranslationGeneration()
     : base(expectedLen: 1)
 {
     this.AdditionalCopyInParams.Add((o, t) =>
     {
         BoolType b = t as BoolType;
         if (b.ByteLength != 1)
         {
             return(TryGet <string> .Succeed($"byteLength: {b.ByteLength}"));
         }
         return(TryGet <string> .Failure);
     });
     this.AdditionalWriteParams.Add((o, t) =>
     {
         BoolType b = t as BoolType;
         if (b.ByteLength != 1)
         {
             return(TryGet <string> .Succeed($"byteLength: {b.ByteLength}"));
         }
         return(TryGet <string> .Failure);
     });
 }
예제 #17
0
 private TryGet <T?> Parse_Internal(XElement root, bool nullable, bool doMasks, out object maskObj)
 {
     if (!root.Name.LocalName.Equals(nullable ? ElementName : NullLessName))
     {
         var ex = new ArgumentException($"Skipping field Version that did not match proper type. Type: {root.Name.LocalName}, expected: {ElementName}.");
         if (doMasks)
         {
             maskObj = ex;
             return(TryGet <T?> .Failure);
         }
         else
         {
             throw ex;
         }
     }
     maskObj = null;
     if (!root.TryGetAttribute(XmlConstants.VALUE_ATTRIBUTE, out XAttribute val) ||
         string.IsNullOrEmpty(val.Value))
     {
         return(TryGet <T?> .Succeed(null));
     }
     return(TryGet <T?> .Succeed(ParseNonNullString(val.Value)));
 }
        public ImmutableLoadOrderLinkCache(
            IEnumerable <IModGetter> loadOrder,
            GameCategory?gameCategory,
            LinkCachePreferences?prefs)
        {
            var loadOrderArr = loadOrder.ToArray();
            var firstMod     = loadOrderArr.FirstOrDefault();

            _hasAny = firstMod != null;
            var simple = prefs is LinkCachePreferenceOnlyIdentifiers;

            gameCategory ??= firstMod?.GameRelease.ToCategory() ?? throw new ArgumentException($"Could not get {nameof(GameCategory)} via generic type or first mod");
            _cache = new InternalImmutableLoadOrderLinkCache(
                loadOrderArr,
                gameCategory.Value,
                hasAny: _hasAny,
                simple: simple,
                prefs);
            _formKeyContexts = new ImmutableLoadOrderLinkCacheSimpleContextCategory <FormKey>(
                gameCategory.Value,
                simple: simple,
                hasAny: _hasAny,
                this,
                loadOrderArr,
                m => TryGet <FormKey> .Succeed(m.FormKey),
                f => f.IsNull);
            _editorIdContexts = new ImmutableLoadOrderLinkCacheSimpleContextCategory <string>(
                gameCategory.Value,
                simple: simple,
                hasAny: _hasAny,
                this,
                loadOrderArr,
                m =>
            {
                var edid = m.EditorID;
                return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !));
            },
예제 #19
0
        TryGet <T> IXmlTranslation <T> .Parse(XElement root, bool doMasks, out object maskObj)
        {
            var parse = this.Parse_Internal(root, nullable: false, doMasks: doMasks, maskObj: out maskObj);

            if (parse.Failed)
            {
                return(parse.BubbleFailure <T>());
            }
            if (parse.Value.HasValue)
            {
                return(TryGet <T> .Succeed(parse.Value.Value));
            }
            var ex = new ArgumentException("Value was unexpectedly null.");

            if (doMasks)
            {
                maskObj = ex;
                return(TryGet <T> .Failure);
            }
            else
            {
                throw ex;
            }
        }
예제 #20
0
 public TryGet <IEnumerable <T> > Parse(XElement root, bool doMasks, out object maskObj)
 {
     return(TryGet <IEnumerable <T> > .Succeed(Parse_Internal(root, doMasks, out maskObj)));
 }