Skip to content

Commit b4948d8

Browse files
committed
Fixed Downloadables instances now being unloaded automatically.
1 parent 1225e42 commit b4948d8

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

addons/source-python/packages/source-python/plugins/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ def _remove_module(self, module):
187187
'''Removes a module and unloads any AutoUnload instances'''
188188

189189
# Loop through all items in the module
190-
for y in iter(sys.modules[module].__dict__):
190+
for name in dir(sys.modules[module]):
191191

192192
# Get the item's object
193-
instance = sys.modules[module].__dict__[y]
193+
instance = getattr(sys.modules[module], name)
194194

195195
# Is the object an AutoUnload instance
196196
if not isinstance(instance, AutoUnload):

addons/source-python/packages/source-python/stringtables/downloads.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
# =============================================================================
44
# >> IMPORTS
55
# =============================================================================
6+
# Python Imports
7+
# Inspect
8+
from inspect import stack
9+
610
# Source.Python Imports
7-
from stringtables import StringTables
811
from core import AutoUnload
12+
from paths import PLUGIN_PATH
913
# Events
1014
from events.manager import EventRegistry
15+
# Stringtables
16+
from stringtables import StringTables
1117

1218

1319
# =============================================================================
@@ -26,7 +32,21 @@ class Downloadables(AutoUnload, set):
2632
'''Class used to store downloadables for a script'''
2733

2834
def __init__(self):
29-
'''Add the instance to the downloadables list'''
35+
'''Sets the __module__ if called by a plugin and
36+
adds the instance to the downloadables list'''
37+
38+
# Get the file that called
39+
caller = stack()[1][1]
40+
41+
# Is the calling file in a plugin?
42+
if PLUGIN_PATH in caller:
43+
44+
# Set the module to the plugin's module so that
45+
# _unload_instance will fire when the plugin is unloaded
46+
self.__module__ = caller.replace(PLUGIN_PATH, '')[1:].replace(
47+
'/', '.').replace('\\', '.').rsplit('.', 1)[0]
48+
49+
# Add the instance to the downloadables list
3050
_DownloadablesListInstance.append(self)
3151

3252
def add(self, item):

0 commit comments

Comments
 (0)