Beispiel #1
0
        // Rename/Move a mod directory.
        // Updates all collection settings and sort order settings.
        public void MoveModDirectory(int idx, string newName)
        {
            var mod          = this[idx];
            var oldName      = mod.Name;
            var oldDirectory = mod.ModPath;

            switch (NewDirectoryValid(oldDirectory.Name, newName, out var dir))
            {
            case NewDirectoryState.NonExisting:
                // Nothing to do
                break;

            case NewDirectoryState.ExistsEmpty:
                try
                {
                    Directory.Delete(dir !.FullName);
                }
                catch (Exception e)
                {
                    PluginLog.Error($"Could not delete empty directory {dir!.FullName} to move {mod.Name} to it:\n{e}");
                    return;
                }

                break;

            // Should be caught beforehand.
            case NewDirectoryState.ExistsNonEmpty:
            case NewDirectoryState.ExistsAsFile:
            case NewDirectoryState.ContainsInvalidSymbols:
            // Nothing to do at all.
            case NewDirectoryState.Identical:
            default:
                return;
            }

            try
            {
                Directory.Move(oldDirectory.FullName, dir !.FullName);
            }
            catch (Exception e)
            {
                PluginLog.Error($"Could not move {mod.Name} from {oldDirectory.Name} to {dir!.Name}:\n{e}");
                return;
            }

            dir.Refresh();
            mod.ModPath = dir;
            if (!mod.Reload(out var metaChange))
            {
                PluginLog.Error($"Error reloading moved mod {mod.Name}.");
                return;
            }

            ModPathChanged.Invoke(ModPathChangeType.Moved, mod, oldDirectory, BasePath);
            if (metaChange != MetaChangeType.None)
            {
                ModMetaChanged?.Invoke(metaChange, mod, oldName);
            }
        }
Beispiel #2
0
        public void ChangeModWebsite(Index idx, string newWebsite)
        {
            var mod = this[idx];

            if (mod.Website != newWebsite)
            {
                mod.Website = newWebsite;
                mod.SaveMeta();
                ModMetaChanged?.Invoke(MetaChangeType.Website, mod, null);
            }
        }
Beispiel #3
0
        public void ChangeModVersion(Index idx, string newVersion)
        {
            var mod = this[idx];

            if (mod.Version != newVersion)
            {
                mod.Version = newVersion;
                mod.SaveMeta();
                ModMetaChanged?.Invoke(MetaChangeType.Version, mod, null);
            }
        }
Beispiel #4
0
        public void ChangeModAuthor(Index idx, string newAuthor)
        {
            var mod = this[idx];

            if (mod.Author != newAuthor)
            {
                mod.Author = newAuthor;
                mod.SaveMeta();
                ModMetaChanged?.Invoke(MetaChangeType.Author, mod, null);
            }
        }
Beispiel #5
0
        public void ChangeModName(Index idx, string newName)
        {
            var mod = this[idx];

            if (mod.Name != newName)
            {
                var oldName = mod.Name;
                mod.Name = newName;
                mod.SaveMeta();
                ModMetaChanged?.Invoke(MetaChangeType.Name, mod, oldName.Text);
            }
        }
Beispiel #6
0
        // Reload a mod without changing its base directory.
        // If the base directory does not exist anymore, the mod will be deleted.
        public void ReloadMod(int idx)
        {
            var mod     = this[idx];
            var oldName = mod.Name;

            ModPathChanged.Invoke(ModPathChangeType.StartingReload, mod, mod.ModPath, mod.ModPath);
            if (!mod.Reload(out var metaChange))
            {
                PluginLog.Warning(mod.Name.Length == 0
                    ? $"Reloading mod {oldName} has failed, new name is empty. Deleting instead."
                    : $"Reloading mod {oldName} failed, {mod.ModPath.FullName} does not exist anymore or it ha. Deleting instead.");

                DeleteMod(idx);
                return;
            }

            ModPathChanged.Invoke(ModPathChangeType.Reloaded, mod, mod.ModPath, mod.ModPath);
            if (metaChange != MetaChangeType.None)
            {
                ModMetaChanged?.Invoke(metaChange, mod, oldName);
            }
        }