Skip to content

Commit

Permalink
maybe a fix for PS (but probably not)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezyma committed May 10, 2024
1 parent 6b76dfe commit 6933539
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
61 changes: 35 additions & 26 deletions archive/src/profilesync/profilesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,37 @@ def getProfileGroup(self, profileName=str):
return ""

def syncFromCurrent(self):
profile = self.organiser.profile()
group = self.getProfileGroup(profile.name())
if group != "":
qInfo("Sync from Profile " + profile.name() + " to Group " + group)
mods = self.organiser.modList().allModsByProfilePriority(profile)
modNl = []
for m in mods:
modNl.append(m + "\n")
self.setGroupModlist(group, modNl)
try:
profile = self.organiser.profile()
group = self.getProfileGroup(profile.name())
if group != "":
qInfo("Sync from Profile " + profile.name() + " to Group " + group)
mods = self.organiser.modList().allModsByProfilePriority(profile)
modNl = []
for m in mods:
modNl.append(m + "\n")
self.setGroupModlist(group, modNl)
except:
qInfo("Profile Sync failed to synchronise from the current profile.")

def groupToProfile(self, groupName=str, profileName=str):
if groupName != "":
qInfo("Sync from Group " + groupName + " to Profile " + profileName)
groupList = self.getGroupModlist(groupName)
mods, enabled = self.profileModlist(profileName)
results = []
for mod in groupList:
if mod in enabled:
results.append("+" + mod)
else:
results.append("-" + mod)
results.reverse()
path = self.paths.profileModlistPath(profileName)
with open(str(path), "w", encoding="utf-8") as w:
w.writelines(results)
try:
groupList = self.getGroupModlist(groupName)
mods, enabled = self.profileModlist(profileName)
results = []
for mod in groupList:
if mod in enabled:
results.append("+" + mod)
else:
results.append("-" + mod)
results.reverse()
path = self.paths.profileModlistPath(profileName)
with open(str(path), "w", encoding="utf-8") as w:
w.writelines(results)
except:
qInfo("Failed to sync from " + groupName + " to Profile " + profileName)

def removeProfileFromGroup(self, groupName=str, profileName=str):
groups = self.getSyncGroups()
Expand Down Expand Up @@ -148,11 +154,14 @@ def getGroupModlist(self, groupName=str):
return []

def setGroupModlist(self, groupName, modList):
groupList = self.paths.profileSyncGroupModlist(groupName)
if not groupList.exists():
groupList.touch()
with open(str(groupList), "w", encoding="utf-8") as w:
w.writelines(modList)
try:
groupList = self.paths.profileSyncGroupModlist(groupName)
if not groupList.exists():
groupList.touch()
with open(str(groupList), "w", encoding="utf-8") as w:
w.writelines(modList)
except:
qInfo("Profile Sync failed to save group modlist.")

def profileModlist(self, profileName):
path = self.paths.profileModlistPath(profileName)
Expand Down
9 changes: 5 additions & 4 deletions directory/plugins/profilesync.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
"DataPath": [ "data/profilesync" ]
},
{
"Version": "2.0.1",
"Released": "2024-01-14",
"Version": "2.0.2",
"Released": "2024-05-10",
"MinSupport": "2.4.0",
"MaxSupport": "2.5.0",
"MinWorking": "2.4.0",
"ReleaseNotes": [
"(2.0.0) New state groups allow synchronising the enabled state of specific separators.",
"(2.0.1) Added retries for updating modlists to prevent issues where lists wouldn't synchronise."
"(2.0.1) Added retries for updating modlists to prevent issues where lists wouldn't synchronise.",
"(2.0.2) Added try/except blocks to try and stop MO2 from unloading the plugin whenever it errors."
],
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/profilesync/profilesync.2.0.1.zip",
"DownloadUrl": "https://github.com/Kezyma/ModOrganizer-Plugins/releases/download/profilesync/profilesync.2.0.2.zip",
"PluginPath": [
"profilesync"
],
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/profilesync/core/profilesync_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProfileSyncPlugin(BasePlugin):
"""Base Profile Sync plugin, to be inherited by all other plugins."""

def __init__(self):
super().__init__("ProfileSync", "Profile Sync", mobase.VersionInfo(2, 0, 1))
super().__init__("ProfileSync", "Profile Sync", mobase.VersionInfo(2, 0, 2))

def init(self, organiser:mobase.IOrganizer):
self._profileSync = ProfileSync(organiser)
Expand Down

0 comments on commit 6933539

Please sign in to comment.