コード例 #1
0
        private static bool IsConflicting(IModelRepositoryMod origin, IModelRepositoryMod otherMod,
                                          IModelStorageMod selected)
        {
            if (origin.State == LoadingState.Loading || otherMod.State == LoadingState.Loading ||
                selected.GetState() == StorageModStateEnum.Loading)
            {
                return(false);
            }

            if (otherMod.GetVersionHash().IsMatch(origin.GetVersionHash()))
            {
                return(false); // that's fine, won't break anything
            }
            if (!otherMod.GetMatchHash().IsMatch(selected.GetMatchHash()))
            {
                return(false); // unrelated mod, we don't care
            }
            var actionType = GetModAction(origin, selected);

            if (actionType == ModActionEnum.Use)
            {
                return(false);                                 // not our problem. only show conflict when we're trying to change something
            }
            return(true);
        }
コード例 #2
0
        public static IEnumerable <IModelRepositoryMod> GetUsedBy(IModelStorageMod storageMod, IEnumerable <IModelRepositoryMod> allRepositoryMods)
        {
            var result = new List <IModelRepositoryMod>();

            foreach (var repositoryMod in allRepositoryMods)
            {
                var selection = repositoryMod.GetCurrentSelection();
                if (selection is ModSelectionStorageMod mod && mod.StorageMod == storageMod)
                {
                    result.Add(repositoryMod);
                }
            }

            return(result);
        }
コード例 #3
0
 internal SelectMod(IModelStorageMod storageMod, ModActionEnum actionType)
 {
     StorageMod = storageMod;
     ActionType = actionType;
     Name       = storageMod.GetTitle();
 }
コード例 #4
0
 public ModSelectionStorageMod(IModelStorageMod storageMod)
 {
     StorageMod = storageMod;
 }
コード例 #5
0
        private static List <IModelRepositoryMod> GetConflictsUsingMod(IModelRepositoryMod repoMod, IModelStorageMod storageMod, IEnumerable <IModelRepositoryMod> allRepoMods)
        {
            var result = new List <IModelRepositoryMod>();

            foreach (var mod in allRepoMods)
            {
                if (mod == repoMod)
                {
                    continue;
                }
                if (mod.GetCurrentSelection() is not ModSelectionStorageMod otherMod || otherMod.StorageMod != storageMod)
                {
                    continue;
                }
                if (IsConflicting(repoMod, mod, storageMod))
                {
                    result.Add(mod);
                }
            }

            return(result);
        }
コード例 #6
0
        // TODO: create more tests. especially for loading/error handling
        // TODO: split up. need to figure out how tho..

        internal static ModActionEnum GetModAction(IModelRepositoryMod repoMod,
                                                   IModelStorageMod storageMod)
        {
            if (repoMod.State == LoadingState.Loading || storageMod.GetState() == StorageModStateEnum.Loading)
            {
                return(ModActionEnum.Loading);
            }

            if (repoMod.State == LoadingState.Error || storageMod.GetState() == StorageModStateEnum.Error)
            {
                return(ModActionEnum.Unusable);
            }

            bool CheckMatch() => repoMod.GetMatchHash().IsMatch(storageMod.GetMatchHash());
            bool CheckVersion() => repoMod.GetVersionHash().IsMatch(storageMod.GetVersionHash());

            switch (storageMod.GetState())
            {
            case StorageModStateEnum.CreatedWithUpdateTarget:
            {
                if (CheckVersion())
                {
                    return(ModActionEnum.ContinueUpdate);
                }
                if (CheckMatch())
                {
                    return(ModActionEnum.AbortAndUpdate);
                }
                return(ModActionEnum.Unusable);
            }

            case StorageModStateEnum.Created:
            {
                if (!CheckMatch())
                {
                    return(ModActionEnum.Unusable);
                }
                if (CheckVersion())
                {
                    return(ModActionEnum.Use);
                }
                return(storageMod.CanWrite ? ModActionEnum.Update : ModActionEnum.UnusableSteam);
            }

            case StorageModStateEnum.Updating:
            {
                if (CheckVersion())
                {
                    return(ModActionEnum.Await);
                }
                if (CheckMatch())
                {
                    return(ModActionEnum.AbortActiveAndUpdate);
                }
                return(ModActionEnum.Unusable);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #7
0
 private void AddStorageMod(IModelStorageMod mod)
 {
     _logger.Trace($"Added storage mod {mod.ParentStorage.Name}/{mod.Identifier}");
     mod.StateChanged += _ => OnAnyChange();
     OnAnyChange();
 }