Skip to content

Commit

Permalink
added MO v2.5 rudimentary support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezyma committed Dec 13, 2021
1 parent 6206ecd commit b261870
Show file tree
Hide file tree
Showing 73 changed files with 1,045 additions and 193 deletions.
23 changes: 23 additions & 0 deletions readme/reinstaller/reinstaller.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Name": "Reinstaller",
"Author": "Kezyma",
"Description": "Reinstaller allows you to conveninetly backup mod installers to re-run later, without risk of them cluttering up your downloads section in Mod Organizer 2.",
"NexusUrl": "https://www.nexusmods.com/skyrimspecialedition/mods/59292",
"GithubUrl": "https://github.com/Kezyma/ModOrganizer-Plugins",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/Current/reinstaller.zip",
"PluginPath": [ "reinstaller" ],
"LocalePath": [],
"DataPath": [ "data/reinstaller" ],
"Versions": [
{
"Version": "1.0.6",
"Released": "2021-12-13",
"MinSupport": "2.4.2",
"MaxSupport": "2.5.0",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/reinstaller-1.0.6/reinstaller.zip",
"PluginPath": [ "reinstaller" ],
"LocalePath": [],
"DataPath": [ "data/reinstaller" ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
"GithubUrl": "https://github.com/Kezyma/ModOrganizer-Plugins",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/Current/rootbuilder.zip",
"PluginPath": [ "rootbuilder" ],
"LocalePath": [ ],
"LocalePath": [],
"DataPath": [ "data/rootbuilder" ],
"Versions": [
{
"Version": "",
"Released": "",
"MinSupport": "",
"MaxSupport": "",
"DownloadUrl": "",
"PluginPath": [],
"Version": "4.2.7",
"Released": "2021-12-13",
"MinSupport": "2.4.2",
"MaxSupport": "2.5.0",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/rootbuilder-4.2.7/rootbuilder.4.2.7.zip",
"PluginPath": [ "rootbuilder" ],
"LocalePath": [],
"DataPath": []
"DataPath": [ "data/rootbuilder" ]
}
]
}
23 changes: 23 additions & 0 deletions readme/shortcutter/shortcutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Name": "Shortcutter",
"Author": "Kezyma",
"Description": "Shortcutter gives you the option of quickly creating instance and profile specific desktop shortcuts, allowing you to quickly launch your game without having to manually switch inside Mod Organizer.",
"NexusUrl": "https://www.nexusmods.com/skyrimspecialedition/mods/59827",
"GithubUrl": "https://github.com/Kezyma/ModOrganizer-Plugins",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/Current/shortcutter.zip",
"PluginPath": [ "shortcutter" ],
"LocalePath": [],
"DataPath": [ "data/shortcutter" ],
"Versions": [
{
"Version": "1.0.4",
"Released": "2021-12-13",
"MinSupport": "2.4.2",
"MaxSupport": "2.5.0",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/shortcutter-1.0.4/shortcutter.zip",
"PluginPath": [ "shortcutter" ],
"LocalePath": [],
"DataPath": [ "data/shortcutter" ]
}
]
}
85 changes: 85 additions & 0 deletions release/pluginfinder/pluginfinder/models/plugin_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import mobase, os
from plugin_version import PluginVersion

class PluginData(self):

def __init__(self, jsonObject=dict):
self.json = jsonObject
super().__init__()

def getJsonProperty(self, key=str):
if key in self.json.keys():
return self.json[key]
else:
return None

def getJsonArray(self, key=str):
data = self.getJsonProperty(key)
res = []
if data:
try:
for val in data:
res.append(data)
return res
except:
return None
else:
return None

def identifier(self):
return str(self.getJsonProperty("Identifier"))

def name(self):
return str(self.getJsonProperty("Name"))

def description(self):
return str(self.getJsonProperty("Description"))

def nexusUrl(self):
return str(self.getJsonProperty("NexusUrl"))

def githubUrl(self):
return str(self.getJsonProperty("GithubUrl"))

def downloadUrl(self):
return str(self.getJsonProperty("DownloadUrl"))

def pluginPaths(self):
paths = []
data = self.getJsonArray("PluginPath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None

def localePaths(self):
paths = []
data = self.getJsonArray("LocalePath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None

def dataPaths(self):
paths = []
data = self.getJsonArray("DataPath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None

def versions():
versions = []
data = self.getJsonArray("Versions")
if data:
for version in data:
versions.append(PluginVersion(version))
return versions
else:
return None
71 changes: 71 additions & 0 deletions release/pluginfinder/pluginfinder/models/plugin_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import mobase, os

class PluginVersion(self):

def __init__(self, jsonObject=dict):
self.json = jsonObject
super().__init__()

def getJsonProperty(self, key=str):
if key in self.json.keys():
return self.json[key]
else:
return None

def getJsonArray(self, key=str):
data = self.getJsonProperty(key)
res = []
if data:
try:
for val in data:
res.append(data)
return res
except:
return None
else:
return None

def released(self):
return str(self.getJsonProperty("Released"))

def minSupport(self):
return str(self.getJsonProperty("MinSupport"))

def maxSupport(self):
return str(self.getJsonProperty("MaxSupport"))

def version(self):
return str(self.getJsonProperty("Version"))

def downloadUrl(self):
return str(self.getJsonProperty("DownloadUrl"))

def pluginPaths(self):
paths = []
data = self.getJsonArray("PluginPath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None

def localePaths(self):
paths = []
data = self.getJsonArray("LocalePath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None

def dataPaths(self):
paths = []
data = self.getJsonArray("DataPath")
if data:
for path in data:
paths.append(str(path))
return paths
else:
return None
39 changes: 29 additions & 10 deletions release/pluginfinder/pluginfinder/modules/pluginfinder_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ class PluginFinderPaths(SharedPaths):

def __init__(self, organiser=mobase.IOrganizer):
super().__init__("PluginFinder", organiser)

_directoryJsonPath = str()
def directoryJsonPath(self):
if self._directoryJsonPath == str():
self._directoryJsonPath = str(self.pluginDataPath() / "pluginfinder_directory.json")
return Path(self._directoryJsonPath)

githubDirectoryUrl = "https://raw.githubusercontent.com/Kezyma/ModOrganizer-Plugins/main/src/pluginfinder/pluginfinder_directory.json"


_modOrganizerPluginPath = str()
def modOrganizerPluginPath(self):
if self._modOrganizerPluginPath == str():
Expand All @@ -40,4 +32,31 @@ def pluginStageTempPath(self):
self._pluginStageTempPath = self.pluginDataPath() / "DownloadedPlugin"
if not Path(self._pluginStageTempPath).exists():
os.makedirs(self._pluginStageTempPath)
return Path(self._pluginStageTempPath)
return Path(self._pluginStageTempPath)


_pluginDirectoryUrl = "https://raw.githubusercontent.com/Kezyma/ModOrganizer-Plugins/main/src/pluginfinder/plugin_directory.json"
def pluginDirectoryUrl(self):
""" Url to the directory json for updating. """
return self._pluginDirectoryUrl

_initialDirectoryPath = str()
def initialDirectoryPath(self):
""" Path to the initial directory json to be deployed during install. """
if self._initialDirectoryPath == str():
self._initialDirectoryPath = str(Path(__file__).parent.parent / "plugin_directory.json")
return self._initialDirectoryPath;

_directoryJsonPath = str()
def directoryJsonPath(self):
""" Path to the current plugin directory json file. """
if self._directoryJsonPath == str():
self._directoryJsonPath = str(self.pluginDataPath() / "plugin_directory.json")
return Path(self._directoryJsonPath)

_pluginDataCachePath = str()
def pluginDataCachePath(self, pluginId=str):
""" Gets the location of the current plugin json file. """
if self._pluginDataCachePath == str():
self._pluginDataCachePath = self.pluginDataPath() / "directory"
return self._pluginDataCachePath / (str(pluginId) + ".json")
92 changes: 92 additions & 0 deletions release/pluginfinder/pluginfinder/modules/pluginfinder_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import mobase, os, urllib, json
from pathlib import Path
from datetime import datetime, timedelta
from itertools import islice
from pluginfinder_paths import PluginFinderPaths
from pluginfinder_files import PluginFinderFiles
from ...shared.shared_utilities import SharedUtilities
from ..models.plugin_data import PluginData

class PluginFinderSearch():

def __init__(self, organiser=mobase.IOrganizer, paths=PluginFinderPaths, files=PluginFinderFiles):
self.organiser = organiser
self.paths = paths
self.files = files
self.utilities = SharedUtilities()
super().__init__()

def deployInitialDirectory(self):
""" Deploys the initial directory file, only happens on first run. """
if Path(self.paths.initialDirectoryPath()).exists():
self.utilities.moveTo(self.paths.initialDirectoryPath(), self.paths.directoryJsonPath())

def updateDirectory(self):
""" Attempt to download a directory update from Github. """
try:
data = json.loads(urllib.request.urlopen(self.paths.pluginDirectoryUrl()).read())
with open(self.paths.directoryJsonPath(), "w") as rcJson:
json.dump(data, rcJson)
except:
qInfo("Could not download update.")
urllib.request.urlcleanup()

def directory(self):
""" Get the directory as json. """
# Deploy if it's first run.
self.deployInitialDirectory()
# If the file is missing or old, update it.
if not Path(self.paths.directoryJsonPath()).exists():
if datetime.fromtimestamp(os.path.getmtime(str(self.paths.directoryJsonPath()))) < (datetime.today() - timedelta(days=1)):
self.updateDirectory()
# Load the directory file.
directory = json.load(open(self.paths.directoryJsonPath()))
return directory

def searchDirectory(self, searchTerms=str):
""" Searches the directory by plugin name. """
results = []
for plugin in self.directory():
if "Name" in plugin:
if searchTerms in plugin["Name"]:
results.append(plugin)
return results

def updatePluginData(self, pluginId=str):
""" Gets the json file for the current plugin. """
for plugin in self.directory():
if plugin["Identifier"] == str(pluginId):
url = plugin["Manifest"]
try:
data = json.loads(urllib.request.urlopen(str(url)).read())
with open(self.paths.pluginDataCachePath(pluginId) "w") as rcJson:
json.dump(data, rcJson)
except:
qInfo("Could not download update.")
urllib.request.urlcleanup()

def pluginData(self, pluginId=str):
""" Loads the data for a plugin. """
# If the file is missing or old, update it.
if not Path(self.paths.pluginDataCachePath(pluginId)).exists() or datetime.fromtimestamp(os.path.getmtime(str(self.paths.pluginDataCachePath(pluginId)))) < (datetime.today() - timedelta(days=1)):
self.updatePluginData(pluginId)
# If the file now exists (it should), load it.
if Path(self.paths.pluginDataCachePath(pluginId)).exists():
try:
data = json.load(open(self.paths.pluginDataCachePath(pluginId)))
data["Identifier"] = str(pluginId)
return PluginData(data)
except:
return None
# Return an null if we can't load the file.
return None

def pagedPluginData(self, searchTerms=str, page=int, pageSize=int):
""" Get a paged list of plugin data. """
manifestSearch = self.searchDirectory(searchTerms)
pagedList = list(islice(manifestSearch, ((page-1)*pageSize), ((page-1)*pageSize) + pageSize))
results = []
for item in pagedList:
if "Identifier" in item:
results.append(self.pluginData(str(item["Identifier"])))
return results
Loading

0 comments on commit b261870

Please sign in to comment.