Skip to content

Commit 757f80b

Browse files
authored
Merge pull request #2 from zediious/mo2-plugin
Convert tool to a MO2 plugin
2 parents efdc8aa + 1e6b9db commit 757f80b

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
# Mod Organizer 2 - Un-ignore downloads
22

3-
This script will make all mods in a Mod Organizer list no longer ignore updates, after they have been told to do so via the context menu.
3+
This plugin will make all mods in a Mod Organizer list no longer ignore updates, after they have been told to do so via the context menu.
44

55
If you have done this to a lot of mods, this can help you quickly fix that up.
66

7-
## Instructions to run
7+
This exists as a Mod Organizer 2 plugin.
8+
9+
1) Download the [latest release](https://github.com/zediious/mo2-unignore-updates/releases).
10+
11+
2) Extract `UnignoreModUpdates.py` to the `plugins` directory in your Mod Organizer 2 instance. Restart Mod Organizer if it is not already closed.
12+
13+
3) Use the "Unignore Mod Updates" option under the puzzle piece icon at the top panel in Mod Organizer.
14+
15+
4) Any mods who have had their updates ignored will no longer ignore them. You may need to press F5 to refresh Mod Organizer to see this..
16+
17+
The standalone script is to be placed directly in your `mods` directory and ran by command line. It will print a log of unignored mods. An optional script exists to only list the mods, without making the changes.
18+
19+
## Instructions to run the standalone scripts
820

921
1) Download Python ([https://www.python.org/downloads/]
1022

environment.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: mo2-unignore-updates
2+
channels:
3+
- defaults
4+
dependencies:
5+
- python=3.8
6+
- pip
7+
- pip:
8+
- mobase-stubs
9+
- PyQt6
10+
- black
11+
- flake8-black

mo2-plugin/UnignoreModUpdates.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from os import chdir, listdir
2+
from re import compile, sub
3+
4+
from PyQt6.QtGui import QIcon
5+
from PyQt6 import QtWidgets
6+
import mobase
7+
8+
9+
def traverse_and_unignore(modsPath: str):
10+
"""
11+
Mark all mods that have their updates ignored as no longer ignored
12+
and return them in a list
13+
"""
14+
ignored_regex = compile("ignoredVersion=\S+")
15+
unignored_mods = []
16+
17+
# Iterate through mod directories
18+
for mod_dir in listdir(modsPath):
19+
20+
# Check for separators and files related to this program, and skip them
21+
if (str(mod_dir).__contains__('_separator')
22+
or str(mod_dir).__contains__('mo2-unignore.log')
23+
or str(mod_dir).__contains__('unignore.py')):
24+
continue
25+
26+
file_data: str
27+
changed_file_data: str
28+
try:
29+
with open(f"{modsPath}\\{mod_dir}\\meta.ini", "r", encoding='UTF-8') as read_file:
30+
file_data = read_file.read()
31+
changed_file_data = sub(
32+
ignored_regex, 'ignoredVersion=', file_data)
33+
34+
except FileNotFoundError:
35+
continue
36+
37+
# Write changed data from memory to meta.ini file if the data changed
38+
if file_data != changed_file_data:
39+
try:
40+
with open(f"{modsPath}\\{mod_dir}\\meta.ini", 'w', encoding="utf-8") as write_file:
41+
write_file.write(changed_file_data)
42+
unignored_mods.append(mod_dir)
43+
except FileNotFoundError:
44+
continue
45+
46+
return unignored_mods
47+
48+
49+
class UnignoreUpdates(mobase.IPluginTool):
50+
organizer: mobase.IOrganizer
51+
52+
def __init__(self):
53+
super().__init__()
54+
55+
def init(self, newOrganizer: mobase.IOrganizer):
56+
self.organizer = newOrganizer
57+
return True
58+
59+
def name(self) -> str:
60+
return "Unignore Mod Updates"
61+
62+
def author(self) -> str:
63+
return "Zediious"
64+
65+
def description(self) -> str:
66+
return "Un-ignore updates for all mods in the list."
67+
68+
def version(self) -> mobase.VersionInfo:
69+
return mobase.VersionInfo(1, 2, mobase.ReleaseType.FINAL)
70+
71+
def isActive(self) -> bool:
72+
return self.organizer.pluginSetting(self.name(), "enabled")
73+
74+
def settings(self):
75+
return [mobase.PluginSetting("Enabled", "Enable this plugin", True)]
76+
77+
def displayName(self) -> str:
78+
return "Unignore Mod Updates"
79+
80+
def tooltip(self) -> str:
81+
return "Un-ignore updates for all mods in the list."
82+
83+
def icon(self):
84+
return QIcon('null')
85+
86+
def display(self):
87+
"""
88+
Function called when tool is used in GUI
89+
"""
90+
updating_mods = traverse_and_unignore(self.organizer.modsPath())
91+
updating_mods_string = ""
92+
if updating_mods != []:
93+
for mod in updating_mods:
94+
updating_mods_string += f"{mod}\n"
95+
else:
96+
updating_mods_string = "No mods had their updates ignored."
97+
98+
QtWidgets.QMessageBox.information(
99+
self._parentWidget(), 'Mods who are now checking for updates', updating_mods_string)
100+
101+
102+
def createPlugin() -> mobase.IPlugin:
103+
return UnignoreUpdates()

0 commit comments

Comments
 (0)