diff --git a/addon.xml b/addon.xml index 3adb65b..6d46913 100644 --- a/addon.xml +++ b/addon.xml @@ -1,9 +1,9 @@ - + - - + + diff --git a/resources/arts.py b/resources/arts.py index da47582..ed1c039 100644 --- a/resources/arts.py +++ b/resources/arts.py @@ -98,4 +98,14 @@ def delete_cache(): """ Deletes the cache containing the data about which art types are available or not """ - os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite") + # If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves + try: + cached_requests.cache.clear() + except Exception: + log('Failed to clear cache. Attempting manual deletion') + try: + os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite") + except: + log('Failed to delete cache file') + cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'responses', fast_save=True) + cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'urls') diff --git a/resources/main.py b/resources/main.py index 71a920a..9a22983 100644 --- a/resources/main.py +++ b/resources/main.py @@ -232,6 +232,22 @@ def main(): # first time run, store version __addon__.setSetting('version', __addon__.getAddonInfo('version')) + else: + previous_version= __addon__.getSetting('version').split(".") + previous_version= list(map(int, previous_version)) + + new_version= __addon__.getSetting('version').split(".") + new_version= list(map(int,new_version)) + + if previous_version[0] == 0 & previous_version[1] < 8: + #Starting with 0.8.0, the cache encoding changed and previous caches needs to be reset. + delete_cache() + + # Insert version upgrade mechanisms here before the following call + + __addon__.setSetting('version', __addon__.getAddonInfo('version')) + + # prompt the user to configure the plugin with their steam details if not all_required_credentials_available(): __addon__.openSettings() diff --git a/resources/steam.py b/resources/steam.py index cfc58a0..539a1ca 100644 --- a/resources/steam.py +++ b/resources/steam.py @@ -20,7 +20,7 @@ STEAM_GAMES_CACHE_FILE = xbmc.translatePath(os.path.join(addonUserDataFolder, 'requests_cache_games')) # cache expires after: 86400=1 day 604800=7 days -cached_requests = requests_cache.core.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite', +cached_requests = requests_cache.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite', expire_after=60 * minutesBeforeGamesListsExpiration, old_data_on_error=True) @@ -106,4 +106,18 @@ def get_user_games(steam_api_key, steam_user_id, recent_only=False): def delete_cache(): - os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite") + """ + Deletes the cache containing the data about which games are owned or not + """ + # If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves + try: + cached_requests.cache.clear() + except Exception: + log('Failed to clear cache. Attempting manual deletion') + try: + os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite") + except: + log('Failed to delete & recreate cache') + cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'responses', fast_save=True) + cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'urls') + \ No newline at end of file