Beispiel #1
0
    // Update the filesystem if a mod has been added or removed.
    // Save it, if the mod directory has been moved, since this will change the save format.
    private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo?oldPath, DirectoryInfo?newPath)
    {
        switch (type)
        {
        case ModPathChangeType.Added:
            var originalName = mod.Name.Text.FixName();
            var name         = originalName;
            var counter      = 1;
            while (Find(name, out _))
            {
                name = $"{originalName} ({++counter})";
            }

            CreateLeaf(Root, name, mod);
            break;

        case ModPathChangeType.Deleted:
            var leaf = Root.GetAllDescendants(SortMode.Lexicographical).OfType <Leaf>().FirstOrDefault(l => l.Value == mod);
            if (leaf != null)
            {
                Delete(leaf);
            }

            break;

        case ModPathChangeType.Moved:
            Save();
            break;

        case ModPathChangeType.Reloaded:
            // Nothing
            break;
        }
    }
Beispiel #2
0
        // Add new mods to NewMods and remove deleted mods from NewMods.
        private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo?oldDirectory,
                                     DirectoryInfo?newDirectory)
        {
            switch (type)
            {
            case ModPathChangeType.Added:
                NewMods.Add(mod);
                break;

            case ModPathChangeType.Deleted:
                NewMods.Remove(mod);
                break;
            }
        }
Beispiel #3
0
        // A changed mod path forces changes for all collections, active and inactive.
        private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo?oldDirectory,
                                     DirectoryInfo?newDirectory)
        {
            switch (type)
            {
            case ModPathChangeType.Added:
                foreach (var collection in this)
                {
                    collection.AddMod(mod);
                }

                OnModAddedActive(mod);
                break;

            case ModPathChangeType.Deleted:
                OnModRemovedActive(mod);
                foreach (var collection in this)
                {
                    collection.RemoveMod(mod, mod.Index);
                }

                break;

            case ModPathChangeType.Moved:
                OnModMovedActive(mod);
                foreach (var collection in this.Where(collection => collection.Settings[mod.Index] != null))
                {
                    collection.Save();
                }

                break;

            case ModPathChangeType.StartingReload:
                OnModRemovedActive(mod);
                break;

            case ModPathChangeType.Reloaded:
                OnModAddedActive(mod);
                break;

            default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }